yangys
2024-04-04 ed4a5236bab800094be4a8378f5098eebe3de6ac
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
package com.qianwen.smartman.modules.notify.manager;
 
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.stream.Collectors;
 
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
 
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.qianwen.core.log.exception.ServiceException;
import com.qianwen.core.log.utils.LogTraceUtil;
import com.qianwen.core.notify.DefaultNotifyType;
import com.qianwen.core.notify.NotifyType;
import com.qianwen.core.notify.notifier.Notifier;
import com.qianwen.core.notify.notifier.NotifierManager;
import com.qianwen.core.tool.metadata.Values;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.smartman.modules.cps.entity.Employee;
import com.qianwen.smartman.modules.cps.service.IEmployeeService;
import com.qianwen.smartman.modules.notify.api.DingTalkApi;
import com.qianwen.smartman.modules.notify.dto.NotifySendMethodDTO;
import com.qianwen.smartman.modules.system.service.IUserOauthService;
 
@Component
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/notify/manager/NotifyBusinessManager.class */
public class NotifyBusinessManager {
    private static final Logger log = LoggerFactory.getLogger(NotifyBusinessManager.class);
    private final NotifierManager notifierManager;
    private final DingTalkApi dingTalkApi;
    private final IEmployeeService employeeService;
    private final IUserOauthService userOauthService;
 
 
    public NotifyBusinessManager(final NotifierManager notifierManager, final DingTalkApi dingTalkApi, final IEmployeeService employeeService, final IUserOauthService userOauthService) {
        this.notifierManager = notifierManager;
        this.dingTalkApi = dingTalkApi;
        this.employeeService = employeeService;
        this.userOauthService = userOauthService;
    }
 
    public void send(List<NotifySendMethodDTO> methodDTOS, List<Long> empIds, Map<String, Object> data) {
        for (NotifySendMethodDTO notifyDTO : methodDTOS) {
            try {
                String notifyId = notifyDTO.getNotifyId();
                String templateId = notifyDTO.getTemplateId();
                String notifyType = notifyDTO.getNotifyType();
                Notifier notifier = (Notifier) Optional.ofNullable(this.notifierManager.getNotifier((NotifyType) null, notifyId)).orElseThrow(() -> {
                    return new ServiceException("通知器[" + notifyId + "]不存在");
                });
                List<String> providerName = getProviderName(notifyType, empIds);
                if (!Func.isEmpty(providerName)) {
                    notifier.send(templateId, LogTraceUtil.getTraceId(), Values.of(data), providerName);
                }
            } catch (Exception e) {
                log.error(e.getMessage());
            }
        }
    }
 
    private List<String> getProviderName(String providerName, List<Long> empIds) {
        List<Employee> employees = this.employeeService.list(Wrappers.<Employee>lambdaQuery().in(Employee::getId, empIds));
        /*
        List<Employee> employees = this.employeeService.list((Wrapper) Wrappers.lambdaQuery().in((v0) -> {
            return v0.getId();
        }, empIds));*/
        if (Func.isEmpty(employees)) {
            return null;
        }
        List<String> tels = employees.stream().map((v0) -> {
            return v0.getTel();
        }).filter((v0) -> {
            return Func.isNotEmpty(v0);
        }).collect(Collectors.toList());
        List<String> ids =  employees.stream().map((v0) -> {
            return v0.getUserId();
        }).filter((v0) -> {
            return Func.isNotEmpty(v0);
        }).collect(Collectors.toList());
        List<String> notifiedParty = new ArrayList<>();
        if (Func.equals(DefaultNotifyType.internalMessage.name(), providerName)) {
            if (Func.isNotEmpty(ids)) {
                notifiedParty = ids;
            }
        } else if (Func.equals(DefaultNotifyType.email.name(), providerName)) {
            notifiedParty = employees.stream().map((v0) -> {
                return v0.getEmail();
            }).collect(Collectors.toList());
        } else if (Func.equals(DefaultNotifyType.dingTalk.name(), providerName)) {
            for (String tel : tels) {
                String userId = this.dingTalkApi.getUserIdByMobile(tel);
                notifiedParty.add(userId);
            }
        } else if (Func.equals(DefaultNotifyType.weiXinQY.name(), providerName) && Func.isNotEmpty(tels)) {
            notifiedParty = tels;
        }
        return notifiedParty;
    }
}