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;
|
}
|
}
|