yangys
2024-04-02 6bed83e92f67954cd2135071133329f2205efe4f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package com.qianwen.smartman.modules.notify.controller;
 
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
 
import javax.validation.Valid;
 
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.qianwen.core.boot.ctrl.BladeController;
import com.qianwen.core.cache.utils.CacheUtil;
import com.qianwen.core.mp.support.Condition;
import com.qianwen.core.mp.support.Query;
import com.qianwen.core.notify.template.TemplateProvider;
import com.qianwen.core.scanner.modular.annotation.DeleteResource;
import com.qianwen.core.scanner.modular.annotation.GetResource;
import com.qianwen.core.scanner.modular.annotation.PutResource;
import com.qianwen.core.scanner.modular.stereotype.ApiResource;
import com.qianwen.core.secure.BladeUser;
import com.qianwen.core.tool.api.R;
import com.qianwen.core.tool.metadata.ConfigMetadata;
import com.qianwen.core.tool.tuple.NameValue;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.smartman.common.cache.RegionCache;
import com.qianwen.smartman.modules.notify.convert.NotifyTemplateConvert;
import com.qianwen.smartman.modules.notify.dto.NotifyTemplateDTO;
import com.qianwen.smartman.modules.notify.dto.NotifyTemplateQueryDTO;
import com.qianwen.smartman.modules.notify.dto.NotifyTemplateResponseDTO;
import com.qianwen.smartman.modules.notify.entity.NotifyConfigEntity;
import com.qianwen.smartman.modules.notify.entity.NotifyTemplateEntity;
import com.qianwen.smartman.modules.notify.service.INotifyConfigService;
import com.qianwen.smartman.modules.notify.service.INotifyTemplateService;
import com.qianwen.smartman.modules.notify.wrapper.NotifyTemplateWrapper;
 
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
 
@ApiResource({"blade-notify/notifier/template"})
@Api(value = "消息通知模版", tags = {"消息通知模版"})
@RestController
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/notify/controller/NotifierTemplateController.class */
public class NotifierTemplateController extends BladeController {
    private final INotifyTemplateService templateService;
    private final INotifyConfigService notifyConfigService;
    private final List<TemplateProvider> providers;
 
 
    public NotifierTemplateController(final INotifyTemplateService templateService, final INotifyConfigService notifyConfigService, final List<TemplateProvider> providers) {
        this.templateService = templateService;
        this.notifyConfigService = notifyConfigService;
        this.providers = providers;
    }
 
    @ApiOperationSupport(order = 1)
    @GetResource({"/{type}/{provider}/config/metadata"})
    @ApiOperation("获取指定类型和服务商所需模版配置定义")
    public R<ConfigMetadata> getAllTypes(@PathVariable("type") String type, @PathVariable("provider") String provider) {
        return R.data(this.templateService.getAllTypes(type, provider, this.providers));
    }
 
    @ApiOperationSupport(order = 2)
    @PutResource
    @ApiOperation(value = "新增或修改", notes = "传入模板信息")
    public R<NotifyTemplateEntity> submit(@Valid @RequestBody NotifyTemplateDTO notifyTemplateDTO, BladeUser bladeUser) {
        if (Func.isNotEmpty(notifyTemplateDTO.getId())) {
            CacheUtil.evict("blade:notify", "template:id:", notifyTemplateDTO.getId(), false);
        }
        NotifyTemplateEntity notifyTemplateEntity = NotifyTemplateConvert.INSTANCE.convertToEntity(notifyTemplateDTO.setTenantId(bladeUser.getTenantId()));
        this.templateService.saveOrUpdate(notifyTemplateEntity);
        return R.data(notifyTemplateEntity);
    }
 
    @ApiOperationSupport(order = 3)
    @DeleteResource({"/{id}"})
    @ApiOperation(value = "删除", notes = "传入id")
    public R<String> remove(@PathVariable("id") @ApiParam(value = "主键", required = true) String id, BladeUser bladeUser) {
        CacheUtil.evict("blade:notify", "template:id:", id, false);
        this.templateService.checkUsedByBusinessNotify(id);
        return R.status(this.templateService
                .remove(Wrappers.<NotifyTemplateEntity>query().lambda()
                  .eq(NotifyTemplateEntity::getId, id).eq(NotifyTemplateEntity::getTenantId, bladeUser.getTenantId())));
        /*
        return R.status(this.templateService.remove((Wrapper) ((LambdaQueryWrapper) Wrappers.query().lambda().eq((v0) -> {
            return v0.getId();
        }, id)).eq((v0) -> {
            return v0.getTenantId();
        }, bladeUser.getTenantId())));*/
    }
 
    @ApiOperationSupport(order = 4)
    @GetResource({"/list"})
    @ApiOperation(value = "通知模板列表", notes = "传入模板")
    public R<IPage<NotifyTemplateResponseDTO>> configPageList(NotifyTemplateQueryDTO notifyTemplateQueryDTO, Query query, BladeUser bladeUser) {
        LambdaQueryWrapper<NotifyTemplateEntity> lambdaQueryWrapper = Wrappers.<NotifyTemplateEntity>lambdaQuery()
                .eq(NotifyTemplateEntity::getTenantId, bladeUser.getTenantId());
        /*
        Wrapper wrapper = (LambdaQueryWrapper) Wrappers.lambdaQuery().eq((v0) -> {
            return v0.getTenantId();
        }, bladeUser.getTenantId());*/
        if (Func.isNotEmpty(notifyTemplateQueryDTO)) {
            lambdaQueryWrapper.like(Func.isNotEmpty(notifyTemplateQueryDTO.getName()), NotifyTemplateEntity::getName, notifyTemplateQueryDTO.getName())
                    .in(Func.isNotEmpty(notifyTemplateQueryDTO.getType()), NotifyTemplateEntity::getType, Arrays.asList(notifyTemplateQueryDTO.getType().split(",")))
                    .eq(Func.isNotEmpty(notifyTemplateQueryDTO.getBusinessKey()), NotifyTemplateEntity::getBusiness, notifyTemplateQueryDTO.getBusinessKey())
                    .eq(Func.isNotEmpty(notifyTemplateQueryDTO.getProvider()), NotifyTemplateEntity::getProvider, notifyTemplateQueryDTO.getProvider()); 
            /*
            wrapper.like(Func.isNotEmpty(notifyTemplateQueryDTO.getName()), (v0) -> {
                return v0.getName();
            }, notifyTemplateQueryDTO.getName()).in(Func.isNotEmpty(notifyTemplateQueryDTO.getType()), (v0) -> {
                return v0.getType();
            }, Arrays.asList(notifyTemplateQueryDTO.getType().split(","))).eq(Func.isNotEmpty(notifyTemplateQueryDTO.getBusinessKey()), (v0) -> {
                return v0.getBusiness();
            }, notifyTemplateQueryDTO.getBusinessKey()).eq(Func.isNotEmpty(notifyTemplateQueryDTO.getProvider()), (v0) -> {
                return v0.getProvider();
            }, notifyTemplateQueryDTO.getProvider());*/
        }
        IPage<NotifyTemplateEntity> list = this.templateService.page(Condition.getPage(query), lambdaQueryWrapper);
        return R.data(NotifyTemplateWrapper.build().pageVO(NotifyTemplateConvert.INSTANCE.convertToPage(list)));
    }
 
    @ApiOperationSupport(order = RegionCache.VILLAGE_LEVEL)
    @GetResource({"/detail/{templateId}"})
    @ApiOperation(value = "详情", notes = "传入模板配置Id")
    public R<NotifyTemplateDTO> detail(@PathVariable("templateId") String templateId) {
        NotifyTemplateEntity detail = (NotifyTemplateEntity) this.templateService.getById(templateId);
        return R.data(NotifyTemplateConvert.INSTANCE.convertToDto(detail));
    }
 
    @ApiOperationSupport(order = 6)
    @GetResource({"/select"})
    @ApiOperation(value = "业务通知可用的通知模板", notes = "传入通知类型")
    public R<List<NameValue<String>>> getCanUseNotifyConfig(@RequestParam(value = "notifyId", required = true) String notifyId, @RequestParam(value = "businessKey", required = true) String businessKey, BladeUser bladeUser) {
        List<NameValue<String>> result = new ArrayList<>();
        NotifyConfigEntity notifyConfigEntity = (NotifyConfigEntity) this.notifyConfigService.getById(notifyId);
        if (Func.isNotEmpty(notifyConfigEntity)) {
            result = this.templateService.list(Wrappers.<NotifyTemplateEntity>lambdaQuery()
                    .in(NotifyTemplateEntity::getTenantId, Arrays.asList(new String[] { bladeUser.getTenantId(), "000000" }))
                    .eq(NotifyTemplateEntity::getType, notifyConfigEntity.getType())
                    .eq(NotifyTemplateEntity::getBusiness, businessKey)
                    .eq(NotifyTemplateEntity::getProvider, notifyConfigEntity.getProvider())
                    .select(NotifyTemplateEntity::getId, NotifyTemplateEntity::getName ))
                    .stream().map(x -> new NameValue<String>(x.getName(), x.getId().toString())).collect(Collectors.toList()); 
            /*
            result = (List) this.templateService.list(((LambdaQueryWrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) ((LambdaQueryWrapper) Wrappers.lambdaQuery().in((v0) -> {
                return v0.getTenantId();
            }, Arrays.asList(bladeUser.getTenantId(), "000000"))).eq((v0) -> {
                return v0.getType();
            }, notifyConfigEntity.getType())).eq((v0) -> {
                return v0.getBusiness();
            }, businessKey)).eq((v0) -> {
                return v0.getProvider();
            }, notifyConfigEntity.getProvider())).select(new SFunction[]{(v0) -> {
                return v0.getId();
            }, (v0) -> {
                return v0.getName();
            }})).stream().map(x -> {
                return new NameValue(x.getName(), x.getId().toString());
            }).collect(Collectors.toList());*/
        }
        return R.data(result);
    }
}