潘志宝
9 天以前 6b13839488edcd06046e26a41fe897358176689c
提交 | 用户 | 时间
e7c126 1 package com.iailab.module.bpm.service.task;
H 2
3 import cn.hutool.core.util.ObjectUtil;
4 import com.iailab.framework.common.pojo.PageResult;
5 import com.iailab.module.bpm.controller.admin.task.vo.instance.BpmProcessInstanceCopyPageReqVO;
6 import com.iailab.module.bpm.dal.dataobject.task.BpmProcessInstanceCopyDO;
7 import com.iailab.module.bpm.dal.mysql.task.BpmProcessInstanceCopyMapper;
8 import com.iailab.module.bpm.enums.ErrorCodeConstants;
9 import com.iailab.module.bpm.service.definition.BpmProcessDefinitionService;
10 import lombok.extern.slf4j.Slf4j;
11 import org.flowable.engine.repository.ProcessDefinition;
12 import org.flowable.engine.runtime.ProcessInstance;
13 import org.flowable.task.api.Task;
14 import org.springframework.context.annotation.Lazy;
15 import org.springframework.stereotype.Service;
16 import org.springframework.validation.annotation.Validated;
17
18 import javax.annotation.Resource;
19 import java.util.Collection;
20 import java.util.List;
21
22 import static com.iailab.framework.common.exception.util.ServiceExceptionUtil.exception;
23 import static com.iailab.framework.common.util.collection.CollectionUtils.convertList;
24
bb2880 25
e7c126 26 /**
H 27  * 流程抄送 Service 实现类
28  *
29  * @author kyle
30  */
31 @Service
32 @Validated
33 @Slf4j
34 public class BpmProcessInstanceCopyServiceImpl implements BpmProcessInstanceCopyService {
35
36     @Resource
37     private BpmProcessInstanceCopyMapper processInstanceCopyMapper;
38
39     @Resource
40     @Lazy // 延迟加载,避免循环依赖
41     private BpmTaskService taskService;
42
43     @Resource
44     @Lazy // 延迟加载,避免循环依赖
45     private BpmProcessInstanceService processInstanceService;
46     @Resource
47     @Lazy // 延迟加载,避免循环依赖
48     private BpmProcessDefinitionService processDefinitionService;
49
50     @Override
bb2880 51     public void createProcessInstanceCopy(Collection<Long> userIds, String reason, String taskId) {
e7c126 52         Task task = taskService.getTask(taskId);
H 53         if (ObjectUtil.isNull(task)) {
54             throw exception(ErrorCodeConstants.TASK_NOT_EXISTS);
55         }
bb2880 56         // 执行抄送
H 57         createProcessInstanceCopy(userIds, reason,
58                 task.getProcessInstanceId(), task.getTaskDefinitionKey(), task.getId(), task.getName());
59     }
60
61     @Override
62     public void createProcessInstanceCopy(Collection<Long> userIds, String reason, String processInstanceId,
63                                           String activityId, String activityName, String taskId) {
64         // 1.1 校验流程实例存在
e7c126 65         ProcessInstance processInstance = processInstanceService.getProcessInstance(processInstanceId);
H 66         if (processInstance == null) {
67             throw exception(ErrorCodeConstants.PROCESS_INSTANCE_NOT_EXISTS);
68         }
bb2880 69         // 1.2 校验流程定义存在
e7c126 70         ProcessDefinition processDefinition = processDefinitionService.getProcessDefinition(
H 71                 processInstance.getProcessDefinitionId());
72         if (processDefinition == null) {
73             throw exception(ErrorCodeConstants.PROCESS_DEFINITION_NOT_EXISTS);
74         }
75
76         // 2. 创建抄送流程
77         List<BpmProcessInstanceCopyDO> copyList = convertList(userIds, userId -> new BpmProcessInstanceCopyDO()
bb2880 78                 .setUserId(userId).setReason(reason).setStartUserId(Long.valueOf(processInstance.getStartUserId()))
e7c126 79                 .setProcessInstanceId(processInstanceId).setProcessInstanceName(processInstance.getName())
bb2880 80                 .setCategory(processDefinition.getCategory()).setTaskId(taskId)
H 81                 .setActivityId(activityId).setActivityName(activityName));
e7c126 82         processInstanceCopyMapper.insertBatch(copyList);
H 83     }
84
85     @Override
86     public PageResult<BpmProcessInstanceCopyDO> getProcessInstanceCopyPage(Long userId,
87                                                                            BpmProcessInstanceCopyPageReqVO pageReqVO) {
88         return processInstanceCopyMapper.selectPage(userId, pageReqVO);
89     }
90
bb2880 91
e7c126 92 }