提交 | 用户 | 时间
|
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 |
|
|
25 |
/** |
|
26 |
* 流程抄送 Service 实现类 |
|
27 |
* |
|
28 |
* @author kyle |
|
29 |
*/ |
|
30 |
@Service |
|
31 |
@Validated |
|
32 |
@Slf4j |
|
33 |
public class BpmProcessInstanceCopyServiceImpl implements BpmProcessInstanceCopyService { |
|
34 |
|
|
35 |
@Resource |
|
36 |
private BpmProcessInstanceCopyMapper processInstanceCopyMapper; |
|
37 |
|
|
38 |
@Resource |
|
39 |
@Lazy // 延迟加载,避免循环依赖 |
|
40 |
private BpmTaskService taskService; |
|
41 |
|
|
42 |
@Resource |
|
43 |
@Lazy // 延迟加载,避免循环依赖 |
|
44 |
private BpmProcessInstanceService processInstanceService; |
|
45 |
@Resource |
|
46 |
@Lazy // 延迟加载,避免循环依赖 |
|
47 |
private BpmProcessDefinitionService processDefinitionService; |
|
48 |
|
|
49 |
@Override |
|
50 |
public void createProcessInstanceCopy(Collection<Long> userIds, String taskId) { |
|
51 |
// 1.1 校验任务存在 |
|
52 |
Task task = taskService.getTask(taskId); |
|
53 |
if (ObjectUtil.isNull(task)) { |
|
54 |
throw exception(ErrorCodeConstants.TASK_NOT_EXISTS); |
|
55 |
} |
|
56 |
// 1.2 校验流程实例存在 |
|
57 |
String processInstanceId = task.getProcessInstanceId(); |
|
58 |
ProcessInstance processInstance = processInstanceService.getProcessInstance(processInstanceId); |
|
59 |
if (processInstance == null) { |
|
60 |
throw exception(ErrorCodeConstants.PROCESS_INSTANCE_NOT_EXISTS); |
|
61 |
} |
|
62 |
// 1.3 校验流程定义存在 |
|
63 |
ProcessDefinition processDefinition = processDefinitionService.getProcessDefinition( |
|
64 |
processInstance.getProcessDefinitionId()); |
|
65 |
if (processDefinition == null) { |
|
66 |
throw exception(ErrorCodeConstants.PROCESS_DEFINITION_NOT_EXISTS); |
|
67 |
} |
|
68 |
|
|
69 |
// 2. 创建抄送流程 |
|
70 |
List<BpmProcessInstanceCopyDO> copyList = convertList(userIds, userId -> new BpmProcessInstanceCopyDO() |
|
71 |
.setUserId(userId).setStartUserId(Long.valueOf(processInstance.getStartUserId())) |
|
72 |
.setProcessInstanceId(processInstanceId).setProcessInstanceName(processInstance.getName()) |
|
73 |
.setCategory(processDefinition.getCategory()).setTaskId(taskId).setTaskName(task.getName())); |
|
74 |
processInstanceCopyMapper.insertBatch(copyList); |
|
75 |
} |
|
76 |
|
|
77 |
@Override |
|
78 |
public PageResult<BpmProcessInstanceCopyDO> getProcessInstanceCopyPage(Long userId, |
|
79 |
BpmProcessInstanceCopyPageReqVO pageReqVO) { |
|
80 |
return processInstanceCopyMapper.selectPage(userId, pageReqVO); |
|
81 |
} |
|
82 |
|
|
83 |
} |