|
|
@@ -32,12 +32,22 @@ import org.springframework.validation.annotation.Validated;
|
|
|
import cn.iocoder.yudao.module.system.api.notify.dto.NotifySendSingleToUserReqDTO;
|
|
|
import cn.iocoder.yudao.module.system.api.bpm.vo.ElderlyInfoReqVO;
|
|
|
import cn.iocoder.yudao.module.system.enums.notice.NotieBusinessTypeEnum;
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
+import cn.iocoder.yudao.framework.common.util.corp.CorpMsgUtil;
|
|
|
+import cn.iocoder.yudao.module.system.api.tenant.TenantApi;
|
|
|
+import cn.iocoder.yudao.module.system.api.tenant.TenantRespDTO;
|
|
|
+import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
|
|
|
+import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
|
|
|
+import cn.iocoder.yudao.module.system.api.wechat.dto.CorpSendMessage;
|
|
|
+import cn.iocoder.yudao.module.system.api.wechat.dto.CorpWechatMiniProgramNotice;
|
|
|
+import cn.iocoder.yudao.module.system.api.wechat.dto.WechatMessageSaveReq;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.util.*;
|
|
|
|
|
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
|
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
|
|
|
+import static cn.iocoder.yudao.module.system.enums.oauth2.EnterpriseWeChatConstants.MINI_PROGRAM_DETAIL_PAGE;
|
|
|
|
|
|
/**
|
|
|
* 流程抄送 Service 实现类
|
|
|
@@ -66,6 +76,12 @@ public class BpmProcessInstanceCopyServiceImpl implements BpmProcessInstanceCopy
|
|
|
@Resource
|
|
|
private NotifyMessageSendApi notifyMessageSendApi;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private AdminUserApi adminUserApi;
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private TenantApi tenantApi;
|
|
|
+
|
|
|
@Resource
|
|
|
private BpmBusinessFormMapper bpmBusinessFormMapper;
|
|
|
|
|
|
@@ -150,6 +166,11 @@ public class BpmProcessInstanceCopyServiceImpl implements BpmProcessInstanceCopy
|
|
|
templateParams.put("elderName", elderlyInfo.getElderName());
|
|
|
break;
|
|
|
|
|
|
+ case FEE_ITEM_CHANGE:
|
|
|
+ elderlyInfo = bpmElderlyChangeApi.getElderlyInfoByChangeId(businessFormDO.getBusinessId());
|
|
|
+ templateParams.put("elderName", elderlyInfo.getElderName());
|
|
|
+ break;
|
|
|
+
|
|
|
case PRICE_CHANGE:
|
|
|
elderlyInfo = bpmElderlyChangeApi.getElderlyInfoByChangeId(businessFormDO.getBusinessId());
|
|
|
templateParams.put("elderName", elderlyInfo.getElderName());
|
|
|
@@ -173,6 +194,76 @@ public class BpmProcessInstanceCopyServiceImpl implements BpmProcessInstanceCopy
|
|
|
copyNotifyList.add(copyDO);
|
|
|
}
|
|
|
notifyMessageSendApi.sendSingleMessageToAdminByList(copyNotifyList);
|
|
|
+ // 3. 发送企微抄送消息:站内信之外,抄送人同样需要收到企微通知
|
|
|
+ sendCorpCopyMessage(copyList, copyNotifyList, processInstanceId, businessFormDO);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 给抄送人发送企微通知。
|
|
|
+ * <p>
|
|
|
+ * 抄送人由 {@link cn.iocoder.yudao.module.bpm.framework.flowable.core.listener.BpmCopyTaskDelegate}
|
|
|
+ * 在流程执行到【抄送节点】时动态计算得出,支持全部候选策略(指定成员、部门负责人、表单用户等),
|
|
|
+ * 因此只能在运行时逐个解析企微账号,无法在部署时预先落库。
|
|
|
+ *
|
|
|
+ * @param copyList 抄送记录
|
|
|
+ * @param copyNotifyList 站内信请求(复用其模板与参数)
|
|
|
+ * @param processInstanceId 流程实例编号
|
|
|
+ * @param businessFormDO 业务表单,可能为 null
|
|
|
+ */
|
|
|
+ private void sendCorpCopyMessage(List<BpmProcessInstanceCopyDO> copyList,
|
|
|
+ List<NotifySendSingleToUserReqDTO> copyNotifyList,
|
|
|
+ String processInstanceId, BpmBusinessFormDO businessFormDO) {
|
|
|
+ if (CollUtil.isEmpty(copyList) || CollUtil.isEmpty(copyNotifyList)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ Long tenantId = TenantContextHolder.getTenantId();
|
|
|
+ if (tenantId == null && copyList.get(0).getTenantId() != null) {
|
|
|
+ tenantId = copyList.get(0).getTenantId();
|
|
|
+ }
|
|
|
+ TenantRespDTO tenant = tenantId == null ? null : tenantApi.getTenant(tenantId);
|
|
|
+ String tenantName = tenant == null ? "" : tenant.getAbbreviation();
|
|
|
+
|
|
|
+ List<CorpSendMessage> corpList = new ArrayList<>();
|
|
|
+ for (BpmProcessInstanceCopyDO copy : copyList) {
|
|
|
+ // 抄送人可能跨租户,必须忽略租户过滤;未绑定企微账号的跳过,绝不能中断其余抄送人
|
|
|
+ AdminUserRespDTO user = adminUserApi.getUserTenantIgnore(copy.getUserId());
|
|
|
+ if (user == null || user.getCorpUserId() == null
|
|
|
+ || user.getCorpUserId().toString().isEmpty()) {
|
|
|
+ log.warn("[sendCorpCopyMessage][抄送用户({})未绑定企微账号,跳过]", copy.getUserId());
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String corpUserId = user.getCorpUserId().toString();
|
|
|
+
|
|
|
+ CorpWechatMiniProgramNotice notice = new CorpWechatMiniProgramNotice();
|
|
|
+ notice.setTitle(CorpMsgUtil.TITLE_COPY);
|
|
|
+ notice.setPage(String.format(MINI_PROGRAM_DETAIL_PAGE, processInstanceId, 4,
|
|
|
+ businessFormDO == null || businessFormDO.getStatus() == null
|
|
|
+ ? "" : String.valueOf(businessFormDO.getStatus()),
|
|
|
+ copy.getUserId() == null ? "" : String.valueOf(copy.getUserId())));
|
|
|
+
|
|
|
+ WechatMessageSaveReq req = new WechatMessageSaveReq();
|
|
|
+ req.setTitle(CorpMsgUtil.TITLE_COPY);
|
|
|
+ req.setTenantName(tenantName);
|
|
|
+ req.setPkMessage(processInstanceId);
|
|
|
+ req.setPkMessage2("");
|
|
|
+ req.setCorpUserId(corpUserId);
|
|
|
+ req.setStartTenantId(tenantId);
|
|
|
+
|
|
|
+ CorpSendMessage corpSendMessage = new CorpSendMessage();
|
|
|
+ corpSendMessage.setTouser(corpUserId);
|
|
|
+ corpSendMessage.setMiniProgramNotice(notice);
|
|
|
+ corpSendMessage.setWechatMessageSaveReq(req);
|
|
|
+ corpList.add(corpSendMessage);
|
|
|
+ }
|
|
|
+ if (CollUtil.isEmpty(corpList)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ notifyMessageSendApi.sendCorpMessageList(corpList, copyNotifyList.get(0));
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 消息发送失败不能阻断流程推进:本方法在 Flowable 事务内执行,异常会导致整个流程回滚
|
|
|
+ log.error("[sendCorpCopyMessage][流程实例({}) 抄送企微消息发送失败]", processInstanceId, e);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -258,6 +349,11 @@ public class BpmProcessInstanceCopyServiceImpl implements BpmProcessInstanceCopy
|
|
|
templateParams.put("elderName", elderlyInfo.getElderName());
|
|
|
break;
|
|
|
|
|
|
+ case FEE_ITEM_CHANGE:
|
|
|
+ elderlyInfo = bpmElderlyChangeApi.getElderlyInfoByChangeId(businessFormDO.getBusinessId());
|
|
|
+ templateParams.put("elderName", elderlyInfo.getElderName());
|
|
|
+ break;
|
|
|
+
|
|
|
case PRICE_CHANGE:
|
|
|
elderlyInfo = bpmElderlyChangeApi.getElderlyInfoByChangeId(businessFormDO.getBusinessId());
|
|
|
templateParams.put("elderName", elderlyInfo.getElderName());
|
|
|
@@ -277,6 +373,8 @@ public class BpmProcessInstanceCopyServiceImpl implements BpmProcessInstanceCopy
|
|
|
copyNotifyList.add(copyDO);
|
|
|
}
|
|
|
notifyMessageSendApi.sendSingleMessageToAdminByList(copyNotifyList);
|
|
|
+ // 3. 发送企微抄送消息:站内信之外,抄送人同样需要收到企微通知
|
|
|
+ sendCorpCopyMessage(copyList, copyNotifyList, processInstanceId, businessFormDO);
|
|
|
}
|
|
|
|
|
|
@Override
|