Commit d8bc3a46e58c70fc24a5c457dd0d65a1c6548377
1 parent
f486790d
feat: BPM-更多设置-自动去重
Showing
4 changed files
with
89 additions
and
4 deletions
yudao-module-bpm/yudao-module-bpm-api/src/main/java/cn/iocoder/yudao/module/bpm/enums/definition/BpmAutoApproveType.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.bpm.enums.definition; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.core.IntArrayValuable; | |
| 4 | +import lombok.AllArgsConstructor; | |
| 5 | +import lombok.Getter; | |
| 6 | + | |
| 7 | +import java.util.Arrays; | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * BPM 自动去重的类型的枚举 | |
| 11 | + * | |
| 12 | + * @author Lesan | |
| 13 | + */ | |
| 14 | +@Getter | |
| 15 | +@AllArgsConstructor | |
| 16 | +public enum BpmAutoApproveType implements IntArrayValuable { | |
| 17 | + | |
| 18 | + NONE(1, "不自动通过"), | |
| 19 | + APPROVE_ALL(2, "仅审批一次,后续重复的审批节点均自动通过"), | |
| 20 | + APPROVE_SEQUENT(3, "仅针对连续审批的节点自动通过"); | |
| 21 | + | |
| 22 | + public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BpmAutoApproveType::getType).toArray(); | |
| 23 | + | |
| 24 | + private final Integer type; | |
| 25 | + private final String name; | |
| 26 | + | |
| 27 | + @Override | |
| 28 | + public int[] array() { | |
| 29 | + return ARRAYS; | |
| 30 | + } | |
| 31 | + | |
| 32 | +} | |
| 0 | 33 | \ No newline at end of file | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/definition/vo/model/BpmModelMetaInfoVO.java
| 1 | 1 | package cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.validation.InEnum; |
| 4 | +import cn.iocoder.yudao.module.bpm.enums.definition.BpmAutoApproveType; | |
| 4 | 5 | import cn.iocoder.yudao.module.bpm.enums.definition.BpmModelFormTypeEnum; |
| 5 | 6 | import cn.iocoder.yudao.module.bpm.enums.definition.BpmModelTypeEnum; |
| 6 | 7 | import io.swagger.v3.oas.annotations.media.Schema; |
| ... | ... | @@ -69,6 +70,10 @@ public class BpmModelMetaInfoVO { |
| 69 | 70 | @Schema(description = "流程 ID 规则", example = "{}") |
| 70 | 71 | private ProcessIdRule processIdRule; |
| 71 | 72 | |
| 73 | + @Schema(description = "自动去重类型", example = "1") | |
| 74 | + @InEnum(BpmAutoApproveType.class) | |
| 75 | + private Integer autoApprovalType; | |
| 76 | + | |
| 72 | 77 | @Schema(description = "流程 ID 规则") |
| 73 | 78 | @Data |
| 74 | 79 | @Valid | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/dal/dataobject/definition/BpmProcessDefinitionInfoDO.java
| ... | ... | @@ -162,4 +162,9 @@ public class BpmProcessDefinitionInfoDO extends BaseDO { |
| 162 | 162 | @TableField(typeHandler = JacksonTypeHandler.class) |
| 163 | 163 | private BpmModelMetaInfoVO.ProcessIdRule processIdRule; |
| 164 | 164 | |
| 165 | + /** | |
| 166 | + * 自动去重类型 | |
| 167 | + */ | |
| 168 | + private Integer autoApprovalType; | |
| 169 | + | |
| 165 | 170 | } | ... | ... |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java
| ... | ... | @@ -13,6 +13,7 @@ import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils; |
| 13 | 13 | import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task.*; |
| 14 | 14 | import cn.iocoder.yudao.module.bpm.convert.task.BpmTaskConvert; |
| 15 | 15 | import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmFormDO; |
| 16 | +import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmProcessDefinitionInfoDO; | |
| 16 | 17 | import cn.iocoder.yudao.module.bpm.enums.definition.*; |
| 17 | 18 | import cn.iocoder.yudao.module.bpm.enums.task.BpmCommentTypeEnum; |
| 18 | 19 | import cn.iocoder.yudao.module.bpm.enums.task.BpmReasonEnum; |
| ... | ... | @@ -33,10 +34,7 @@ import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; |
| 33 | 34 | import jakarta.annotation.Resource; |
| 34 | 35 | import jakarta.validation.Valid; |
| 35 | 36 | import lombok.extern.slf4j.Slf4j; |
| 36 | -import org.flowable.bpmn.model.BpmnModel; | |
| 37 | -import org.flowable.bpmn.model.EndEvent; | |
| 38 | -import org.flowable.bpmn.model.FlowElement; | |
| 39 | -import org.flowable.bpmn.model.UserTask; | |
| 37 | +import org.flowable.bpmn.model.*; | |
| 40 | 38 | import org.flowable.engine.HistoryService; |
| 41 | 39 | import org.flowable.engine.ManagementService; |
| 42 | 40 | import org.flowable.engine.RuntimeService; |
| ... | ... | @@ -1174,6 +1172,51 @@ public class BpmTaskServiceImpl implements BpmTaskService { |
| 1174 | 1172 | log.error("[processTaskAssigned][taskId({}) 没有找到流程实例]", task.getId()); |
| 1175 | 1173 | return; |
| 1176 | 1174 | } |
| 1175 | + // 自动去重 TODO @芋艿 驳回的情况得考虑一下 | |
| 1176 | + BpmProcessDefinitionInfoDO processDefinitionInfo = bpmProcessDefinitionService.getProcessDefinitionInfo(task.getProcessDefinitionId()); | |
| 1177 | + if (processDefinitionInfo == null) { | |
| 1178 | + log.error("[processTaskAssigned][taskId({}) 没有找到流程定义]", task.getId()); | |
| 1179 | + return; | |
| 1180 | + } | |
| 1181 | + if (processDefinitionInfo.getAutoApprovalType() != null) { | |
| 1182 | + HistoricTaskInstanceQuery query = historyService.createHistoricTaskInstanceQuery() | |
| 1183 | + .processInstanceId(task.getProcessInstanceId()) | |
| 1184 | + .taskAssignee(task.getAssignee()) | |
| 1185 | + .taskVariableValueEquals(BpmnVariableConstants.TASK_VARIABLE_STATUS, | |
| 1186 | + BpmTaskStatusEnum.APPROVE.getStatus()) | |
| 1187 | + .finished(); | |
| 1188 | + if (BpmAutoApproveType.APPROVE_ALL.getType().equals(processDefinitionInfo.getAutoApprovalType())){ | |
| 1189 | + long count = query.count(); | |
| 1190 | + if (count > 0) { | |
| 1191 | + // 自动通过 | |
| 1192 | + getSelf().approveTask(Long.valueOf(task.getAssignee()), new BpmTaskApproveReqVO().setId(task.getId()) | |
| 1193 | + .setReason(BpmReasonEnum.APPROVE_TYPE_AUTO_APPROVE.getReason())); | |
| 1194 | + return; | |
| 1195 | + } | |
| 1196 | + } | |
| 1197 | + if (BpmAutoApproveType.APPROVE_SEQUENT.getType().equals(processDefinitionInfo.getAutoApprovalType())) { | |
| 1198 | + BpmnModel bpmnModel = modelService.getBpmnModelByDefinitionId(processInstance.getProcessDefinitionId()); | |
| 1199 | + if (bpmnModel == null) { | |
| 1200 | + log.error("[processTaskAssigned][taskId({}) 没有找到流程模型]", task.getId()); | |
| 1201 | + return; | |
| 1202 | + } | |
| 1203 | + FlowNode taskElement = (FlowNode) BpmnModelUtils.getFlowElementById(bpmnModel, task.getTaskDefinitionKey()); | |
| 1204 | + List<SequenceFlow> incomingFlows = taskElement.getIncomingFlows(); | |
| 1205 | + List<String> sourceTaskIds = new ArrayList<>(); | |
| 1206 | + if (incomingFlows != null && !incomingFlows.isEmpty()) { | |
| 1207 | + incomingFlows.forEach(flow -> { | |
| 1208 | + sourceTaskIds.add(flow.getSourceRef()); | |
| 1209 | + }); | |
| 1210 | + } | |
| 1211 | + long count = query.taskDefinitionKeys(sourceTaskIds).count(); | |
| 1212 | + if (count > 0) { | |
| 1213 | + // 自动通过 | |
| 1214 | + getSelf().approveTask(Long.valueOf(task.getAssignee()), new BpmTaskApproveReqVO().setId(task.getId()) | |
| 1215 | + .setReason(BpmReasonEnum.APPROVE_TYPE_AUTO_APPROVE.getReason())); | |
| 1216 | + return; | |
| 1217 | + } | |
| 1218 | + } | |
| 1219 | + } | |
| 1177 | 1220 | // 审批人与提交人为同一人时,根据 BpmUserTaskAssignStartUserHandlerTypeEnum 策略进行处理 |
| 1178 | 1221 | if (StrUtil.equals(task.getAssignee(), processInstance.getStartUserId())) { |
| 1179 | 1222 | // 判断是否为退回或者驳回:如果是退回或者驳回不走这个策略 | ... | ... |