yangys
2024-03-27 e48aa2ac8dea1be5db11c63edf0b912c4ad5ce65
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
package com.qianwen.smartman.modules.notify.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import java.lang.invoke.SerializedLambda;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Collectors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.qianwen.core.context.task.TaskExecutionContext;
import com.qianwen.core.context.task.TaskExecutorTypeEnum;
import com.qianwen.core.notify.DefaultNotifyType;
import com.qianwen.core.notify.executor.INotifyTaskService;
import com.qianwen.core.notify.executor.NotifyDirectSendInfo;
import com.qianwen.core.notify.executor.NotifyExecutionContext;
import com.qianwen.core.notify.executor.RuleNotifierProperties;
import com.qianwen.core.tool.utils.BeanUtil;
import com.qianwen.core.tool.utils.Func;
import com.qianwen.smartman.modules.cps.service.IEmployeeService;
import com.qianwen.smartman.modules.notify.convert.BusinessNotifyConvert;
import com.qianwen.smartman.modules.notify.dto.BusinessNotifyDTO;
import com.qianwen.smartman.modules.notify.dto.NotifyUserDTO;
import com.qianwen.smartman.modules.notify.mapper.BusinessNotifyMapper;
import com.qianwen.smartman.modules.notify.service.IBusinessNotifyService;
import com.qianwen.smartman.modules.system.service.IUserOauthService;
import com.qianwen.smartman.modules.system.service.IUserService;
import org.springframework.stereotype.Service;
 
@Service
/* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/notify/service/impl/NotifyTaskServiceImpl.class */
public class NotifyTaskServiceImpl implements INotifyTaskService {
    private static final Logger log = LoggerFactory.getLogger(NotifyTaskServiceImpl.class);
    private final IBusinessNotifyService businessNotifyService;
    private final BusinessNotifyMapper businessNotifyMapper;
    private final IUserService userService;
    private final IUserOauthService userOauthService;
    private final IEmployeeService employeeService;
 
    private static /* synthetic */ Object $deserializeLambda$(SerializedLambda lambda) {
        String implMethodName = lambda.getImplMethodName();
        boolean z = true;
        switch (implMethodName.hashCode()) {
            case 584947017:
                if (implMethodName.equals("getBusinessKey")) {
                    z = false;
                    break;
                }
                break;
            case 771206363:
                if (implMethodName.equals("getTenantId")) {
                    z = true;
                    break;
                }
                break;
        }
        switch (z) {
            case false:
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/modules/notify/entity/BusinessNotify") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
                    return (v0) -> {
                        return v0.getBusinessKey();
                    };
                }
                break;
            case true:
                if (lambda.getImplMethodKind() == 5 && lambda.getFunctionalInterfaceClass().equals("com/baomidou/mybatisplus/core/toolkit/support/SFunction") && lambda.getFunctionalInterfaceMethodName().equals("apply") && lambda.getFunctionalInterfaceMethodSignature().equals("(Ljava/lang/Object;)Ljava/lang/Object;") && lambda.getImplClass().equals("org/springblade/core/tenant/mp/TenantEntity") && lambda.getImplMethodSignature().equals("()Ljava/lang/String;")) {
                    return (v0) -> {
                        return v0.getTenantId();
                    };
                }
                break;
        }
        throw new IllegalArgumentException("Invalid lambda deserialization");
    }
 
    public NotifyTaskServiceImpl(final IBusinessNotifyService businessNotifyService, final BusinessNotifyMapper businessNotifyMapper, final IUserService userService, final IUserOauthService userOauthService, final IEmployeeService employeeService) {
        this.businessNotifyService = businessNotifyService;
        this.businessNotifyMapper = businessNotifyMapper;
        this.userService = userService;
        this.userOauthService = userOauthService;
        this.employeeService = employeeService;
    }
 
    private List<NotifyUserDTO> getNotifySubscriberList(List<String> notifySubscriberList, TaskExecutorTypeEnum taskExecutorTypeEnum) {
        List<NotifyUserDTO> result;
        switch (AnonymousClass1.$SwitchMap$org$springblade$core$context$task$TaskExecutorTypeEnum[taskExecutorTypeEnum.ordinal()]) {
            case 1:
                result = this.employeeService.getNotifySubscriberList(notifySubscriberList);
                break;
            case 2:
            default:
                result = this.userService.getNotifySubscriberList(notifySubscriberList);
                break;
        }
        return result;
    }
 
    public List<String> getNotifiedPartyList(String tenantId, String businessKey, String defaultNotifyType, List<String> notifySubscriberList, TaskExecutorTypeEnum taskExecutorTypeEnum) {
        List<String> result = new ArrayList<>();
        if (Func.isNotEmpty(notifySubscriberList)) {
            List<NotifyUserDTO> notifyUserDTOS = getNotifySubscriberList(notifySubscriberList, taskExecutorTypeEnum);
            switch (AnonymousClass1.$SwitchMap$org$springblade$core$notify$DefaultNotifyType[DefaultNotifyType.of(defaultNotifyType).ordinal()]) {
                case 1:
                    result.addAll((Collection) notifyUserDTOS.stream().map((v0) -> {
                        return v0.getEmail();
                    }).filter((v0) -> {
                        return Func.isNotEmpty(v0);
                    }).collect(Collectors.toList()));
                    break;
                case 2:
                    result.addAll((Collection) notifyUserDTOS.stream().map((v0) -> {
                        return v0.getPhone();
                    }).filter((v0) -> {
                        return Func.isNotEmpty(v0);
                    }).collect(Collectors.toList()));
                    break;
                case 3:
                    result.addAll((Collection) notifyUserDTOS.stream().map((v0) -> {
                        return v0.getWeiXinMiniUserId();
                    }).filter((v0) -> {
                        return Func.isNotEmpty(v0);
                    }).collect(Collectors.toList()));
                case 4:
                    result.addAll((Collection) notifyUserDTOS.stream().map((v0) -> {
                        return v0.getUserId();
                    }).map((v0) -> {
                        return Func.toStr(v0);
                    }).collect(Collectors.toList()));
                    break;
            }
        }
        result.removeAll(Collections.singleton(null));
        return result;
    }
 
    /* JADX INFO: Access modifiers changed from: package-private */
    /* renamed from: org.springblade.modules.notify.service.impl.NotifyTaskServiceImpl$1  reason: invalid class name */
    /* loaded from: blade-api.jar:BOOT-INF/classes/org/springblade/modules/notify/service/impl/NotifyTaskServiceImpl$1.class */
    public static /* synthetic */ class AnonymousClass1 {
        static final /* synthetic */ int[] $SwitchMap$org$springblade$core$context$task$TaskExecutorTypeEnum;
        static final /* synthetic */ int[] $SwitchMap$org$springblade$core$notify$DefaultNotifyType = new int[DefaultNotifyType.values().length];
 
        static {
            try {
                $SwitchMap$org$springblade$core$notify$DefaultNotifyType[DefaultNotifyType.email.ordinal()] = 1;
            } catch (NoSuchFieldError e) {
            }
            try {
                $SwitchMap$org$springblade$core$notify$DefaultNotifyType[DefaultNotifyType.sms.ordinal()] = 2;
            } catch (NoSuchFieldError e2) {
            }
            try {
                $SwitchMap$org$springblade$core$notify$DefaultNotifyType[DefaultNotifyType.weiXinMini.ordinal()] = 3;
            } catch (NoSuchFieldError e3) {
            }
            try {
                $SwitchMap$org$springblade$core$notify$DefaultNotifyType[DefaultNotifyType.internalMessage.ordinal()] = 4;
            } catch (NoSuchFieldError e4) {
            }
            $SwitchMap$org$springblade$core$context$task$TaskExecutorTypeEnum = new int[TaskExecutorTypeEnum.values().length];
            try {
                $SwitchMap$org$springblade$core$context$task$TaskExecutorTypeEnum[TaskExecutorTypeEnum.EMPLOYEE.ordinal()] = 1;
            } catch (NoSuchFieldError e5) {
            }
            try {
                $SwitchMap$org$springblade$core$context$task$TaskExecutorTypeEnum[TaskExecutorTypeEnum.USER.ordinal()] = 2;
            } catch (NoSuchFieldError e6) {
            }
        }
    }
 
    public List<NotifyExecutionContext> createNotifyExecutionContext(TaskExecutionContext taskExecutionContext) {
        List<NotifyExecutionContext> result = new CopyOnWriteArrayList<>();
        List<BusinessNotifyDTO> finallyBusiness = BusinessNotifyConvert.INSTANCE.convertToDTOList(this.businessNotifyService.list((Wrapper) ((LambdaQueryWrapper) Wrappers.query().lambda().eq((v0) -> {
            return v0.getBusinessKey();
        }, taskExecutionContext.getBusiness())).eq((v0) -> {
            return v0.getTenantId();
        }, taskExecutionContext.getTenantId())));
        if (Func.isNotEmpty(finallyBusiness)) {
            finallyBusiness.forEach(notify -> {
                List<String> notifiedPartys = getNotifiedPartyList(taskExecutionContext.getTenantId(), taskExecutionContext.getBusiness(), notify.getNotifyType(), taskExecutionContext.getRelatedPersonals(), taskExecutionContext.getTaskExecutorTypeEnum());
                Object sendInfo = taskExecutionContext.getExtendInfo().get("notify_direct_address");
                if (Func.isNotEmpty(sendInfo)) {
                    List<NotifyDirectSendInfo> sendInfoList = new ArrayList<>();
                    List<Map<String, Object>> data = (List) sendInfo;
                    data.forEach(x -> {
                        NotifyDirectSendInfo notifyDirectSendInfo = (NotifyDirectSendInfo) BeanUtil.toBean(x, NotifyDirectSendInfo.class);
                        notifyDirectSendInfo.setNotifyType(DefaultNotifyType.of(x.get("notifyType").toString()));
                        sendInfoList.add(notifyDirectSendInfo);
                    });
                    ((List) sendInfoList.stream().filter(x2 -> {
                        return notify.getNotifyType().equals(x2.getNotifyType().getId());
                    }).collect(Collectors.toList())).forEach(x3 -> {
                        notifiedPartys.addAll(x3.getDirectSendAddress());
                    });
                }
                if (Func.isNotEmpty(notifiedPartys)) {
                    NotifyExecutionContext notifyExecutionContext = new NotifyExecutionContext();
                    notifyExecutionContext.setContextId(taskExecutionContext.getContextId());
                    notifyExecutionContext.setTenantId(taskExecutionContext.getTenantId());
                    notifyExecutionContext.setData(taskExecutionContext.getData() != null ? taskExecutionContext.getData() : new HashMap());
                    notifyExecutionContext.setNotifiedParty(notifiedPartys);
                    RuleNotifierProperties ruleNotifierProperties = new RuleNotifierProperties().setNotifierId(notify.getNotifyId()).setNotifyType(DefaultNotifyType.of(notify.getNotifyType())).setTemplateId(notify.getNotifyTemplateId());
                    notifyExecutionContext.setConfiguration(ruleNotifierProperties);
                    result.add(notifyExecutionContext);
                }
            });
        }
        return result;
    }
}