流程消息推送修改

This commit is contained in:
furongxin 2024-04-09 22:02:33 +08:00
parent 442685e8d9
commit 1693bb20d0
5 changed files with 76 additions and 95 deletions

View File

@ -68,7 +68,8 @@ public class BpmTaskCurrentAssignLeaderScript extends BpmTaskAssignLeaderAbstrac
for (int i = 0; i < dept.getLevel(); i++) {
if (i == 0) { //第一次查找 判断审批人是否为发起人部门负责人
if (!dept.getLeaderUserId().toString().equals(processInstance.getStartUserId())){ //如果发起人不是所在部门负责人时
if (assigneeUserId.toString().equals(processInstance.getStartUserId())
&& !dept.getLeaderUserId().toString().equals(processInstance.getStartUserId())){ //如果发起人不是所在部门负责人时
count = 1;
break;

View File

@ -4,7 +4,6 @@ import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.module.bpm.dal.dataobject.task.BpmTaskExtDO;
import cn.iocoder.yudao.module.bpm.service.task.BpmActivityService;
import cn.iocoder.yudao.module.bpm.service.task.BpmProcessInstanceService;
import cn.iocoder.yudao.module.bpm.service.task.BpmTaskService;
import com.google.common.collect.ImmutableSet;
import lombok.extern.slf4j.Slf4j;
@ -38,10 +37,6 @@ public class BpmTaskEventListener extends AbstractFlowableEngineEventListener {
@Lazy // 解决循环依赖
private BpmActivityService activityService;
@Resource
@Lazy // 解决循环依赖
private BpmProcessInstanceService processInstanceService;
public static final Set<FlowableEngineEventType> TASK_EVENTS = ImmutableSet.<FlowableEngineEventType>builder()
.add(FlowableEngineEventType.TASK_CREATED)
.add(FlowableEngineEventType.TASK_ASSIGNED)
@ -57,9 +52,6 @@ public class BpmTaskEventListener extends AbstractFlowableEngineEventListener {
protected void taskCreated(FlowableEngineEntityEvent event) {
Task task = (Task) event.getEntity();
taskService.createTaskExt(task);
//在TASK创建时 监听审批人是否时发起人
taskService.approveAuto(task);
}
@Override

View File

@ -93,7 +93,7 @@ public class BpmMessageServiceImpl implements BpmMessageService {
if (ccOpenId != null) {
subscribeMessageSendApi.sendApprovalResultNotification(
BpmMessageConvert.INSTANCE.convertApprovalResultNotification(
openId, reqDTO.getProcessInstanceName(), reqDTO.getCreateTime(), "抄送", reqDTO.getReason(),
ccOpenId, reqDTO.getProcessInstanceName(), reqDTO.getCreateTime(), "抄送", reqDTO.getReason(),
reqDTO.getProcessInstanceId(),
/**
* 跳转小程序类型developer为开发版trial为体验版formal为正式版默认为正式版
@ -150,9 +150,10 @@ public class BpmMessageServiceImpl implements BpmMessageService {
//站内信
notifyMessageSendApi.sendSingleMessageToAdmin(BpmMessageConvert.INSTANCE.convert1(
reqDTO.getAssigneeUserId(), BpmMessageEnum.TASK_ASSIGNED.getSmsTemplateCode(), templateParams));
//微信小程序订阅消息
//发送OA流程待办提醒
String openId = getUserOpenId(reqDTO.getStartUserId()); //只有在微信小程序登陆过用户才会有openid
String openId = getUserOpenId(assigneeUserId); //只有在微信小程序登陆过用户才会有openid
if (openId != null) {
subscribeMessageSendApi.sendProcessToDoReminder(BpmMessageConvert.INSTANCE.convertProcessToDoReminder(
openId, reqDTO.getProcessInstanceName(), reqDTO.getStartUserNickname(), reqDTO.getCreateTime(), reqDTO.getSchedule(),
@ -172,7 +173,7 @@ public class BpmMessageServiceImpl implements BpmMessageService {
private String getUserOpenId(Long userId) {
AdminUserRespDTO adminUserRespDTO = adminUserApi.getUser(userId).getData();
String openId = adminUserRespDTO.getOpenId();
return openId;
return adminUserRespDTO.getOpenId();
}
}

View File

@ -196,11 +196,4 @@ public interface BpmTaskService {
* @return 当前任务的taskId
*/
String getCurrentTaskIdByProcessInstanceId(String processInstanceId) ;
/**
* 监听 判断流程审批人是否是发起人
* @param task
*/
void approveAuto(Task task);
}

View File

@ -66,7 +66,6 @@ import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.*;
/**
* 流程任务实例 Service 实现类
*
* @author jason
*/
@Slf4j
@ -153,7 +152,6 @@ public class BpmTaskServiceImpl implements BpmTaskService {
}
// 执行查询
List<Task> tasks = taskQuery.listPage(PageUtils.getStart(pageVO), pageVO.getPageSize());
if (CollUtil.isEmpty(tasks)) {
@ -721,26 +719,60 @@ public class BpmTaskServiceImpl implements BpmTaskService {
@Override
public void updateTaskExtAssign(Task task) {
BpmTaskExtDO taskExtDO =
new BpmTaskExtDO().setAssigneeUserId(NumberUtils.parseLong(task.getAssignee())).setTaskId(task.getId());
taskExtMapper.updateByTaskId(taskExtDO);
// BpmTaskExtDO taskExtDO =
// new BpmTaskExtDO().setAssigneeUserId(NumberUtils.parseLong(task.getAssignee())).setTaskId(task.getId());
// taskExtMapper.updateByTaskId(taskExtDO);
// 发送通知在事务提交时批量执行操作所以直接查询会无法查询到 ProcessInstance所以这里是通过监听事务的提交来实现
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
@Override
public void afterCommit() {
if (StrUtil.isNotEmpty(task.getAssignee())) {
ProcessInstance processInstance =
processInstanceService.getProcessInstance(task.getProcessInstanceId());
ProcessInstance processInstance = processInstanceService.getProcessInstance(task.getProcessInstanceId());
if (processInstance != null) {
// 获得任务列表
List<BpmTaskRespVO> BpmTaskRespVOs = getTaskListByProcessInstanceId(processInstance.getProcessInstanceId());
AdminUserRespDTO startUser = adminUserApi.getUser(Long.valueOf(processInstance.getStartUserId())).getCheckedData();
//发送信息通知
messageService.sendMessageWhenTaskAssigned(
BpmTaskConvert.INSTANCE.convert(processInstance, startUser, task, BpmTaskRespVOs));
}
}
}
@Override
public void afterCompletion(int status) {
if(TransactionSynchronization.STATUS_COMMITTED == status){
ProcessInstance processInstance = processInstanceService.getProcessInstance(task.getProcessInstanceId());
//如果当前审批人是流程发起人则自动通过当前审批节点
if (processInstance.getStartUserId().equals(task.getAssignee())) {
BpmTaskApproveReqVO reqVO = new BpmTaskApproveReqVO();
reqVO.setId(task.getId());
reqVO.setReason(BpmConstants.AUTO_APPRAVAL);
approveTask(Long.valueOf(task.getAssignee()), reqVO);
} else {
//判断 当前审批人是否在该流程中 已通过审批
//如果有则自动审批通过该审批人节点
Long count = taskExtMapper.selectListCount(Long.valueOf(task.getAssignee()), task.getProcessInstanceId());
if (count > 0L) {
BpmTaskApproveReqVO reqVO = new BpmTaskApproveReqVO();
reqVO.setId(task.getId());
reqVO.setReason(BpmConstants.AUTO_APPRAVAL);
approveTask(Long.valueOf(task.getAssignee()), reqVO);
}
}
}
}
});
}
@ -1083,6 +1115,7 @@ public class BpmTaskServiceImpl implements BpmTaskService {
/**
* 判断当前类型是否为加签
*
* @param scopeType 任务的 scopeType
* @return 当前 scopeType 为加签则返回 true
*/
@ -1185,43 +1218,4 @@ public class BpmTaskServiceImpl implements BpmTaskService {
throw exception(TASK_NOT_EXISTS);
}
}
/**
* 监听 判断流程审批人是否是发起人
* @param task
*/
@Override
public void approveAuto(Task task) {
//在事务提交后 进行判断
TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization() {
@Override
public void afterCommit() {
ProcessInstance processInstance = processInstanceService.getProcessInstance(task.getProcessInstanceId());
//如果当前审批人是流程发起人则自动通过当前审批节点
if (processInstance.getStartUserId().equals(task.getAssignee())) {
BpmTaskApproveReqVO reqVO = new BpmTaskApproveReqVO();
reqVO.setId(task.getId());
reqVO.setReason(BpmConstants.AUTO_APPRAVAL);
approveTask(Long.valueOf(task.getAssignee()), reqVO);
}else {
//判断 当前审批人是否在该流程中 已通过审批
//如果有则自动审批通过该审批人节点
Long count = taskExtMapper.selectListCount(Long.valueOf(task.getAssignee()), task.getProcessInstanceId());
if (count > 0L) {
BpmTaskApproveReqVO reqVO = new BpmTaskApproveReqVO();
reqVO.setId(task.getId());
reqVO.setReason(BpmConstants.AUTO_APPRAVAL);
approveTask(Long.valueOf(task.getAssignee()), reqVO);
}
}
}
});
}
}