|
|
@@ -12,8 +12,10 @@ import java.util.regex.Matcher;
|
|
12
|
12
|
import cn.hutool.core.collection.CollUtil;
|
|
13
|
13
|
import cn.hutool.core.util.ObjectUtil;
|
|
14
|
14
|
import com.sundot.airport.common.core.domain.entity.SysDept;
|
|
|
15
|
+import com.sundot.airport.common.core.domain.entity.SysRole;
|
|
15
|
16
|
import com.sundot.airport.common.enums.RoleTypeEnum;
|
|
16
|
17
|
import com.sundot.airport.system.service.ISysDeptService;
|
|
|
18
|
+import com.sundot.airport.system.service.ISysUserService;
|
|
17
|
19
|
import org.slf4j.Logger;
|
|
18
|
20
|
import org.slf4j.LoggerFactory;
|
|
19
|
21
|
import com.sundot.airport.common.utils.DateUtils;
|
|
|
@@ -72,6 +74,8 @@ public class ApprovalEngineServiceImpl implements IApprovalEngineService {
|
|
72
|
74
|
|
|
73
|
75
|
@Autowired
|
|
74
|
76
|
private ISysDeptService sysDeptService;
|
|
|
77
|
+ @Autowired
|
|
|
78
|
+ private ISysUserService iSysUserService;
|
|
75
|
79
|
|
|
76
|
80
|
|
|
77
|
81
|
/**
|
|
|
@@ -114,6 +118,7 @@ public class ApprovalEngineServiceImpl implements IApprovalEngineService {
|
|
114
|
118
|
instanceMapper.insertApprovalInstance(instance);
|
|
115
|
119
|
|
|
116
|
120
|
// 3. 获取第一个节点
|
|
|
121
|
+ boolean isAutoPass = false;// 是否自动审批通过
|
|
117
|
122
|
ApprovalNodeDefinition firstNode = nodeDefinitionMapper.selectFirstNodeByWorkflowId(workflow.getId());
|
|
118
|
123
|
if (firstNode != null) {
|
|
119
|
124
|
instance.setCurrentNodeId(firstNode.getId());
|
|
|
@@ -124,7 +129,7 @@ public class ApprovalEngineServiceImpl implements IApprovalEngineService {
|
|
124
|
129
|
createTasksForNode(instance, firstNode, formData, null);
|
|
125
|
130
|
} else {
|
|
126
|
131
|
// 开始节点,直接流转到下一个节点
|
|
127
|
|
- moveToNextNode(instance, firstNode, submitterId, submitterName, "提交", formData, null);
|
|
|
132
|
+ isAutoPass = moveToNextNode(instance, firstNode, submitterId, submitterName, "提交", formData, null);
|
|
128
|
133
|
}
|
|
129
|
134
|
}
|
|
130
|
135
|
|
|
|
@@ -133,6 +138,14 @@ public class ApprovalEngineServiceImpl implements IApprovalEngineService {
|
|
133
|
138
|
|
|
134
|
139
|
// 执行业务处理逻辑
|
|
135
|
140
|
executeBusinessLogic(instance, "APPROVED");
|
|
|
141
|
+
|
|
|
142
|
+ // 自动审批通过
|
|
|
143
|
+ if (isAutoPass) {
|
|
|
144
|
+ firstNode.setSortOrder(firstNode.getSortOrder() + 1);
|
|
|
145
|
+ moveToNextNode(instance, firstNode, submitterId, submitterName, "自动审批通过", formData, null);
|
|
|
146
|
+ recordHistory(instance.getId(), null, null, null, "AUTO_APPROVE", submitterId, submitterName, "自动审批通过", formData);
|
|
|
147
|
+ executeBusinessLogic(instance, "APPROVED");
|
|
|
148
|
+ }
|
|
136
|
149
|
return instance;
|
|
137
|
150
|
}
|
|
138
|
151
|
|
|
|
@@ -735,8 +748,8 @@ public class ApprovalEngineServiceImpl implements IApprovalEngineService {
|
|
735
|
748
|
/**
|
|
736
|
749
|
* 流转到下一节点
|
|
737
|
750
|
*/
|
|
738
|
|
- private void moveToNextNode(ApprovalInstance instance, ApprovalNodeDefinition currentNode,
|
|
739
|
|
- Long operatorId, String operatorName, String comment, Map<String, Object> formData, ApprovalTask currentTask) {
|
|
|
751
|
+ private boolean moveToNextNode(ApprovalInstance instance, ApprovalNodeDefinition currentNode,
|
|
|
752
|
+ Long operatorId, String operatorName, String comment, Map<String, Object> formData, ApprovalTask currentTask) {
|
|
740
|
753
|
// 查找下一个节点
|
|
741
|
754
|
ApprovalNodeDefinition nextNode = nodeDefinitionMapper.selectNextNodeByOrder(
|
|
742
|
755
|
instance.getWorkflowId(), currentNode.getSortOrder());
|
|
|
@@ -774,8 +787,17 @@ public class ApprovalEngineServiceImpl implements IApprovalEngineService {
|
|
774
|
787
|
if (ObjectUtil.isNotEmpty(currentTask) && ObjectUtil.isNotEmpty(currentTask.getAssigneeId())) {
|
|
775
|
788
|
submitterId = currentTask.getAssigneeId();
|
|
776
|
789
|
}
|
|
777
|
|
- // 违禁品审批流程:根据提交人角色分配给其主管
|
|
778
|
|
- createTasksForNodeWithKeZhang(instance, nextNode, formData, null, submitterId);
|
|
|
790
|
+ SysUser sysUser = iSysUserService.selectUserById(submitterId);
|
|
|
791
|
+ List<String> roleKeyList = sysUser.getRoles().stream().map(SysRole::getRoleKey).collect(Collectors.toList());
|
|
|
792
|
+ boolean isAutoPass = roleKeyList.contains(RoleTypeEnum.kezhang.getCode());
|
|
|
793
|
+ if (isAutoPass) {
|
|
|
794
|
+ // 违禁品审批流程:根据提交人角色为主管则自动审批通过
|
|
|
795
|
+ createTasksForNodeWithKeZhangAutoPass(instance, nextNode, formData, null, submitterId);
|
|
|
796
|
+ return true;
|
|
|
797
|
+ } else {
|
|
|
798
|
+ // 违禁品审批流程:根据提交人角色分配给其主管
|
|
|
799
|
+ createTasksForNodeWithKeZhang(instance, nextNode, formData, null, submitterId);
|
|
|
800
|
+ }
|
|
779
|
801
|
} else if (isSeizureReportWorkflow(instance) && ("GROUP_LEADER".equals(nextNode.getApproverType()) || "SECTION_LEADER".equals(nextNode.getApproverType()))) {
|
|
780
|
802
|
Long submitterId = instance.getSubmitterId();
|
|
781
|
803
|
if ("SECTION_LEADER".equals(nextNode.getApproverType()) && ObjectUtil.isNotEmpty(currentTask) && ObjectUtil.isNotEmpty(currentTask.getAssigneeId())) {
|
|
|
@@ -805,6 +827,7 @@ public class ApprovalEngineServiceImpl implements IApprovalEngineService {
|
|
805
|
827
|
// 没有下一节点,完成流程
|
|
806
|
828
|
completeProcess(instance, operatorId, operatorName);
|
|
807
|
829
|
}
|
|
|
830
|
+ return false;
|
|
808
|
831
|
}
|
|
809
|
832
|
|
|
810
|
833
|
/**
|
|
|
@@ -1844,4 +1867,49 @@ public class ApprovalEngineServiceImpl implements IApprovalEngineService {
|
|
1844
|
1867
|
logger.error("创建经理1审批任务失败", e);
|
|
1845
|
1868
|
}
|
|
1846
|
1869
|
}
|
|
|
1870
|
+
|
|
|
1871
|
+ /**
|
|
|
1872
|
+ * 为违禁品审批节点创建任务(根据提交人角色为主管则自动审批通过)
|
|
|
1873
|
+ */
|
|
|
1874
|
+ private void createTasksForNodeWithKeZhangAutoPass(ApprovalInstance instance, ApprovalNodeDefinition node, Map<String, Object> formData, String remark, Long submitterId) {
|
|
|
1875
|
+ try {
|
|
|
1876
|
+ SysUser user = sysUserMapper.selectUserById(submitterId);
|
|
|
1877
|
+ if (user != null) {
|
|
|
1878
|
+ ApprovalTask task = new ApprovalTask();
|
|
|
1879
|
+ task.setTaskNo(taskMapper.generateTaskNo());
|
|
|
1880
|
+ task.setInstanceId(instance.getId());
|
|
|
1881
|
+ task.setNodeId(node.getId());
|
|
|
1882
|
+ task.setTaskName(node.getNodeName());
|
|
|
1883
|
+ task.setAssigneeId(user.getUserId());
|
|
|
1884
|
+ task.setAssigneeName(user.getNickName());
|
|
|
1885
|
+ task.setAssignTime(DateUtils.getNowDate());
|
|
|
1886
|
+ task.setStatus("APPROVED");
|
|
|
1887
|
+ task.setCompleteTime(DateUtils.getNowDate());
|
|
|
1888
|
+
|
|
|
1889
|
+ // 设置表单数据 - 如果formData为空,使用当前实例的formData
|
|
|
1890
|
+ try {
|
|
|
1891
|
+ if (formData != null) {
|
|
|
1892
|
+ task.setFormData(objectMapper.writeValueAsString(formData));
|
|
|
1893
|
+ } else {
|
|
|
1894
|
+ task.setFormData(instance.getFormData());
|
|
|
1895
|
+ }
|
|
|
1896
|
+ } catch (Exception e) {
|
|
|
1897
|
+ // 序列化失败时使用实例的formData
|
|
|
1898
|
+ task.setFormData(instance.getFormData());
|
|
|
1899
|
+ }
|
|
|
1900
|
+
|
|
|
1901
|
+ // 设置超时时间
|
|
|
1902
|
+ if (node.getTimeoutHours() != null && node.getTimeoutHours() > 0) {
|
|
|
1903
|
+ task.setTimeoutTime(DateUtils.addHours(DateUtils.getNowDate(), node.getTimeoutHours()));
|
|
|
1904
|
+ }
|
|
|
1905
|
+
|
|
|
1906
|
+ task.setCreateBy(SecurityUtils.getUsername());
|
|
|
1907
|
+ task.setCreateTime(DateUtils.getNowDate());
|
|
|
1908
|
+
|
|
|
1909
|
+ taskMapper.insertApprovalTask(task);
|
|
|
1910
|
+ }
|
|
|
1911
|
+ } catch (Exception e) {
|
|
|
1912
|
+ throw new RuntimeException("创建违禁品审批任务失败:" + e.getMessage(), e);
|
|
|
1913
|
+ }
|
|
|
1914
|
+ }
|
|
1847
|
1915
|
}
|