houzhongyi
2024-07-11 e7c1260db32209a078a962aaa0ad5492c35774fb
提交 | 用户 | 时间
e7c126 1 package com.iailab.module.bpm.service.message;
H 2
3 import com.iailab.framework.web.config.WebProperties;
4 import com.iailab.module.bpm.convert.message.BpmMessageConvert;
5 import com.iailab.module.bpm.enums.message.BpmMessageEnum;
6 import com.iailab.module.bpm.service.message.dto.BpmMessageSendWhenProcessInstanceApproveReqDTO;
7 import com.iailab.module.bpm.service.message.dto.BpmMessageSendWhenProcessInstanceRejectReqDTO;
8 import com.iailab.module.bpm.service.message.dto.BpmMessageSendWhenTaskCreatedReqDTO;
9 import com.iailab.module.system.api.sms.SmsSendApi;
10 import lombok.extern.slf4j.Slf4j;
11 import org.springframework.stereotype.Service;
12 import org.springframework.validation.annotation.Validated;
13
14 import javax.annotation.Resource;
15 import java.util.HashMap;
16 import java.util.Map;
17
18 /**
19  * BPM 消息 Service 实现类
20  *
21  * @author iailab
22  */
23 @Service
24 @Validated
25 @Slf4j
26 public class BpmMessageServiceImpl implements BpmMessageService {
27
28     @Resource
29     private SmsSendApi smsSendApi;
30
31     @Resource
32     private WebProperties webProperties;
33
34     @Override
35     public void sendMessageWhenProcessInstanceApprove(BpmMessageSendWhenProcessInstanceApproveReqDTO reqDTO) {
36         Map<String, Object> templateParams = new HashMap<>();
37         templateParams.put("processInstanceName", reqDTO.getProcessInstanceName());
38         templateParams.put("detailUrl", getProcessInstanceDetailUrl(reqDTO.getProcessInstanceId()));
39         smsSendApi.sendSingleSmsToAdmin(BpmMessageConvert.INSTANCE.convert(reqDTO.getStartUserId(),
40                 BpmMessageEnum.PROCESS_INSTANCE_APPROVE.getSmsTemplateCode(), templateParams));
41     }
42
43     @Override
44     public void sendMessageWhenProcessInstanceReject(BpmMessageSendWhenProcessInstanceRejectReqDTO reqDTO) {
45         Map<String, Object> templateParams = new HashMap<>();
46         templateParams.put("processInstanceName", reqDTO.getProcessInstanceName());
47         templateParams.put("reason", reqDTO.getReason());
48         templateParams.put("detailUrl", getProcessInstanceDetailUrl(reqDTO.getProcessInstanceId()));
49         smsSendApi.sendSingleSmsToAdmin(BpmMessageConvert.INSTANCE.convert(reqDTO.getStartUserId(),
50                 BpmMessageEnum.PROCESS_INSTANCE_REJECT.getSmsTemplateCode(), templateParams));
51     }
52
53     @Override
54     public void sendMessageWhenTaskAssigned(BpmMessageSendWhenTaskCreatedReqDTO reqDTO) {
55         Map<String, Object> templateParams = new HashMap<>();
56         templateParams.put("processInstanceName", reqDTO.getProcessInstanceName());
57         templateParams.put("taskName", reqDTO.getTaskName());
58         templateParams.put("startUserNickname", reqDTO.getStartUserNickname());
59         templateParams.put("detailUrl", getProcessInstanceDetailUrl(reqDTO.getProcessInstanceId()));
60         smsSendApi.sendSingleSmsToAdmin(BpmMessageConvert.INSTANCE.convert(reqDTO.getAssigneeUserId(),
61                 BpmMessageEnum.TASK_ASSIGNED.getSmsTemplateCode(), templateParams));
62     }
63
64     private String getProcessInstanceDetailUrl(String taskId) {
65         return webProperties.getAdminUi().getUrl() + "/bpm/process-instance/detail?id=" + taskId;
66     }
67
68 }