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
package com.qianwen.smartman.modules.notify.service.impl;
 
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.qianwen.core.log.exception.ServiceException;
import com.qianwen.core.mp.base.BaseServiceImpl;
import com.qianwen.core.notify.template.TemplateProvider;
import com.qianwen.core.tool.metadata.ConfigMetadata;
import com.qianwen.core.tool.metadata.ConfigPropertyMetadata;
import com.qianwen.core.tool.metadata.types.StringType;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.smartman.modules.notify.entity.BusinessNotify;
import com.qianwen.smartman.modules.notify.entity.NotifyTemplateEntity;
import com.qianwen.smartman.modules.notify.enums.NotifyTemplateExpandEnum;
import com.qianwen.smartman.modules.notify.mapper.BusinessNotifyMapper;
import com.qianwen.smartman.modules.notify.mapper.NotifyTemplateMapper;
import com.qianwen.smartman.modules.notify.service.INotifyTemplateService;
 
import cn.hutool.core.convert.Convert;
 
@Service
public class NotifyTemplateServiceImpl extends BaseServiceImpl<NotifyTemplateMapper, NotifyTemplateEntity> implements INotifyTemplateService {
    private static final Logger log = LoggerFactory.getLogger(NotifyTemplateServiceImpl.class);
    @Autowired
    private BusinessNotifyMapper businessNotifyMapper;
 
    @Override // org.springblade.modules.notify.service.INotifyTemplateService
    public boolean checkUsedByBusinessNotify(String id) {
        Long count = this.businessNotifyMapper.selectCount(Wrappers.<BusinessNotify>lambdaQuery()
                .eq(BusinessNotify::getNotifyTemplateId, id));
        /*
        Long count = this.businessNotifyMapper.selectCount((Wrapper) Wrappers.lambdaQuery().eq((v0) -> {
            return v0.getNotifyTemplateId();
        }, id));*/
        if (count.longValue() > 0) {
            throw new ServiceException("当前通知模板正在被业务使用,无法删除");
        }
        return true;
    }
 
    @Override // org.springblade.modules.notify.service.INotifyTemplateService
    public ConfigMetadata getAllTypes(String type, String provider, List<TemplateProvider> providers) {
        NotifyTemplateExpandEnum[] values;
        ConfigMetadata result = null;
        List<TemplateProvider> providerList = providers.stream().filter(prov -> {
            return prov.getType().getId().equalsIgnoreCase(type) && prov.getProvider().getId().equalsIgnoreCase(provider);
        }).collect(Collectors.toList());
        if (Func.isNotEmpty(providerList)) {
            result = providerList.get(0).getTemplateConfigMetadata();
        }
        if (result != null) {
            for (NotifyTemplateExpandEnum expandEnum : NotifyTemplateExpandEnum.values()) {
                setExpands(result, type, provider, expandEnum);
            }
        }
        return result;
    }
 
    private void setExpands(ConfigMetadata configMetadata, String type, String provider, NotifyTemplateExpandEnum expandEnum) {
        List<ConfigPropertyMetadata> properties = configMetadata.getProperties();
        if (type.equals(expandEnum.getType()) && provider.equals(expandEnum.getProvider())) {
            Optional<ConfigPropertyMetadata> metadata = properties.stream().filter(prop -> {
                return expandEnum.getProperty().equals(prop.getProperty());
            }).findFirst();
            metadata.ifPresent(configPropertyMetadata -> {
                StringType stringType = (StringType) Convert.convert(StringType.class, configPropertyMetadata.getType());
                stringType.getExpands().put(expandEnum.getKey(), expandEnum.getValue());
            });
        }
    }
}