提交 | 用户 | 时间
|
e7c126
|
1 |
package com.iailab.module.bpm.service.definition; |
H |
2 |
|
|
3 |
import cn.hutool.core.util.StrUtil; |
|
4 |
import com.iailab.framework.common.pojo.PageResult; |
|
5 |
import com.iailab.framework.common.util.object.BeanUtils; |
|
6 |
import com.iailab.module.bpm.controller.admin.definition.vo.listener.BpmProcessListenerPageReqVO; |
|
7 |
import com.iailab.module.bpm.controller.admin.definition.vo.listener.BpmProcessListenerSaveReqVO; |
|
8 |
import com.iailab.module.bpm.dal.dataobject.definition.BpmProcessListenerDO; |
|
9 |
import com.iailab.module.bpm.dal.mysql.definition.BpmProcessListenerMapper; |
|
10 |
import com.iailab.module.bpm.enums.definition.BpmProcessListenerType; |
|
11 |
import com.iailab.module.bpm.enums.definition.BpmProcessListenerValueType; |
|
12 |
import org.flowable.engine.delegate.JavaDelegate; |
|
13 |
import org.flowable.engine.delegate.TaskListener; |
|
14 |
import org.springframework.stereotype.Service; |
|
15 |
import org.springframework.validation.annotation.Validated; |
|
16 |
|
|
17 |
import javax.annotation.Resource; |
|
18 |
|
|
19 |
import static com.iailab.framework.common.exception.util.ServiceExceptionUtil.exception; |
|
20 |
import static com.iailab.module.bpm.enums.ErrorCodeConstants.*; |
|
21 |
|
|
22 |
/** |
|
23 |
* BPM 流程监听器 Service 实现类 |
|
24 |
* |
|
25 |
* @author iailab |
|
26 |
*/ |
|
27 |
@Service |
|
28 |
@Validated |
|
29 |
public class BpmProcessListenerServiceImpl implements BpmProcessListenerService { |
|
30 |
|
|
31 |
@Resource |
|
32 |
private BpmProcessListenerMapper processListenerMapper; |
|
33 |
|
|
34 |
@Override |
|
35 |
public Long createProcessListener(BpmProcessListenerSaveReqVO createReqVO) { |
|
36 |
// 校验 |
|
37 |
validateCreateProcessListenerValue(createReqVO); |
|
38 |
// 插入 |
|
39 |
BpmProcessListenerDO processListener = BeanUtils.toBean(createReqVO, BpmProcessListenerDO.class); |
|
40 |
processListenerMapper.insert(processListener); |
|
41 |
return processListener.getId(); |
|
42 |
} |
|
43 |
|
|
44 |
@Override |
|
45 |
public void updateProcessListener(BpmProcessListenerSaveReqVO updateReqVO) { |
|
46 |
// 校验存在 |
|
47 |
validateProcessListenerExists(updateReqVO.getId()); |
|
48 |
validateCreateProcessListenerValue(updateReqVO); |
|
49 |
// 更新 |
|
50 |
BpmProcessListenerDO updateObj = BeanUtils.toBean(updateReqVO, BpmProcessListenerDO.class); |
|
51 |
processListenerMapper.updateById(updateObj); |
|
52 |
} |
|
53 |
|
|
54 |
private void validateCreateProcessListenerValue(BpmProcessListenerSaveReqVO createReqVO) { |
|
55 |
// class 类型 |
|
56 |
if (createReqVO.getValueType().equals(BpmProcessListenerValueType.CLASS.getType())) { |
|
57 |
try { |
|
58 |
Class<?> clazz = Class.forName(createReqVO.getValue()); |
|
59 |
if (createReqVO.getType().equals(BpmProcessListenerType.EXECUTION.getType()) |
|
60 |
&& !JavaDelegate.class.isAssignableFrom(clazz)) { |
|
61 |
throw exception(PROCESS_LISTENER_CLASS_IMPLEMENTS_ERROR, createReqVO.getValue(), |
|
62 |
JavaDelegate.class.getName()); |
|
63 |
} else if (createReqVO.getType().equals(BpmProcessListenerType.TASK.getType()) |
|
64 |
&& !TaskListener.class.isAssignableFrom(clazz)) { |
|
65 |
throw exception(PROCESS_LISTENER_CLASS_IMPLEMENTS_ERROR, createReqVO.getValue(), |
|
66 |
TaskListener.class.getName()); |
|
67 |
} |
|
68 |
} catch (ClassNotFoundException e) { |
|
69 |
throw exception(PROCESS_LISTENER_CLASS_NOT_FOUND, createReqVO.getValue()); |
|
70 |
} |
|
71 |
return; |
|
72 |
} |
|
73 |
// 表达式 |
|
74 |
if (!StrUtil.startWith(createReqVO.getValue(), "${") || !StrUtil.endWith(createReqVO.getValue(), "}")) { |
|
75 |
throw exception(PROCESS_LISTENER_EXPRESSION_INVALID, createReqVO.getValue()); |
|
76 |
} |
|
77 |
} |
|
78 |
|
|
79 |
@Override |
|
80 |
public void deleteProcessListener(Long id) { |
|
81 |
// 校验存在 |
|
82 |
validateProcessListenerExists(id); |
|
83 |
// 删除 |
|
84 |
processListenerMapper.deleteById(id); |
|
85 |
} |
|
86 |
|
|
87 |
private void validateProcessListenerExists(Long id) { |
|
88 |
if (processListenerMapper.selectById(id) == null) { |
|
89 |
throw exception(PROCESS_LISTENER_NOT_EXISTS); |
|
90 |
} |
|
91 |
} |
|
92 |
|
|
93 |
@Override |
|
94 |
public BpmProcessListenerDO getProcessListener(Long id) { |
|
95 |
return processListenerMapper.selectById(id); |
|
96 |
} |
|
97 |
|
|
98 |
@Override |
|
99 |
public PageResult<BpmProcessListenerDO> getProcessListenerPage(BpmProcessListenerPageReqVO pageReqVO) { |
|
100 |
return processListenerMapper.selectPage(pageReqVO); |
|
101 |
} |
|
102 |
|
|
103 |
} |