feat(REQ-4418) - 自动过审添加日志
This commit is contained in:
parent
ffb288ca83
commit
dfc0f92417
@ -1,5 +1,6 @@
|
|||||||
package cn.axzo.workflow.server.controller.listener.task.service.impl;
|
package cn.axzo.workflow.server.controller.listener.task.service.impl;
|
||||||
|
|
||||||
|
import cn.axzo.framework.jackson.utility.JSON;
|
||||||
import cn.axzo.workflow.common.enums.BpmnButtonEnum;
|
import cn.axzo.workflow.common.enums.BpmnButtonEnum;
|
||||||
import cn.axzo.workflow.common.enums.BpmnFlowNodeType;
|
import cn.axzo.workflow.common.enums.BpmnFlowNodeType;
|
||||||
import cn.axzo.workflow.common.model.request.bpmn.BpmnButtonConf;
|
import cn.axzo.workflow.common.model.request.bpmn.BpmnButtonConf;
|
||||||
@ -12,6 +13,7 @@ import cn.axzo.workflow.core.repository.entity.ExtAxHiTaskInst;
|
|||||||
import cn.axzo.workflow.core.service.ExtAxHiTaskInstService;
|
import cn.axzo.workflow.core.service.ExtAxHiTaskInstService;
|
||||||
import cn.axzo.workflow.server.controller.listener.task.service.CheckApproverService;
|
import cn.axzo.workflow.server.controller.listener.task.service.CheckApproverService;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
|
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
|
||||||
import org.flowable.bpmn.model.FlowElement;
|
import org.flowable.bpmn.model.FlowElement;
|
||||||
import org.flowable.bpmn.model.Process;
|
import org.flowable.bpmn.model.Process;
|
||||||
@ -45,6 +47,7 @@ import static cn.axzo.workflow.common.enums.BpmnProcessInstanceResultEnum.APPROV
|
|||||||
* b. 连续节点
|
* b. 连续节点
|
||||||
* c. 当前节点有同意按钮
|
* c. 当前节点有同意按钮
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class CheckApproverServiceImpl implements CheckApproverService {
|
public class CheckApproverServiceImpl implements CheckApproverService {
|
||||||
@ -58,74 +61,84 @@ public class CheckApproverServiceImpl implements CheckApproverService {
|
|||||||
//业务节点,指定业务审批人,或者业务设置了审批人,也要参与自动过审,node_type为NODE_BUSINESS,节点元素类型为UserTask
|
//业务节点,指定业务审批人,或者业务设置了审批人,也要参与自动过审,node_type为NODE_BUSINESS,节点元素类型为UserTask
|
||||||
//业务节点审批人为空,或者人员未指定,此时不进行自动过审操作,需要再业务指定审批人后,再做自动过审动作
|
//业务节点审批人为空,或者人员未指定,此时不进行自动过审操作,需要再业务指定审批人后,再做自动过审动作
|
||||||
if (!(Objects.equals(currentNodeType, NODE_TASK) || Objects.equals(currentNodeType, NODE_BUSINESS)) ||
|
if (!(Objects.equals(currentNodeType, NODE_TASK) || Objects.equals(currentNodeType, NODE_BUSINESS)) ||
|
||||||
!StringUtils.hasText(delegateTask.getAssignee()) ||
|
!StringUtils.hasText(delegateTask.getAssignee()) ||
|
||||||
delegateTask.getAssignee().equals(NO_ASSIGNEE)) {
|
delegateTask.getAssignee().equals(NO_ASSIGNEE)) {
|
||||||
|
log.info("CheckApproverServiceImpl#checkApproverExists...节点类型:{},审批人:{}", currentNodeType, delegateTask.getAssignee());
|
||||||
return exists.get();
|
return exists.get();
|
||||||
}
|
}
|
||||||
Optional<BpmnButtonConf> optConfig = BpmnMetaParserHelper.getButtonConfig(mainProcess, delegateTask.getTaskDefinitionKey());
|
Optional<BpmnButtonConf> optConfig = BpmnMetaParserHelper.getButtonConfig(mainProcess, delegateTask.getTaskDefinitionKey());
|
||||||
if (!optConfig.isPresent()) {
|
if (!optConfig.isPresent()) {
|
||||||
|
log.info("CheckApproverServiceImpl#checkApproverExists...节点未配置按钮,节点ID:{}", delegateTask.getTaskDefinitionKey());
|
||||||
return exists.get();
|
return exists.get();
|
||||||
}
|
}
|
||||||
BpmnButtonConf bpmnButtonConf = optConfig.get();
|
BpmnButtonConf bpmnButtonConf = optConfig.get();
|
||||||
List<BpmnButtonMetaInfo> currentButtons = bpmnButtonConf.getCurrent();
|
List<BpmnButtonMetaInfo> currentButtons = bpmnButtonConf.getCurrent();
|
||||||
if (CollectionUtils.isEmpty(currentButtons)) {
|
if (CollectionUtils.isEmpty(currentButtons)) {
|
||||||
|
log.info("CheckApproverServiceImpl#checkApproverExists...节点按钮配置为空,节点ID:{}", delegateTask.getTaskDefinitionKey());
|
||||||
return exists.get();
|
return exists.get();
|
||||||
}
|
}
|
||||||
Optional<BpmnButtonMetaInfo> agreeButton = currentButtons.stream()
|
Optional<BpmnButtonMetaInfo> agreeButton = currentButtons.stream()
|
||||||
.filter(button -> button.getType().equals("SYSTEM") //系统按钮
|
.filter(button -> button.getType().equals("SYSTEM") //系统按钮
|
||||||
&& button.getChecked() != null && button.getChecked() //选中
|
&& button.getChecked() != null && button.getChecked() //选中
|
||||||
&& (button.getDisabled() == null || !button.getDisabled()) //没用禁用
|
&& (button.getDisabled() == null || !button.getDisabled()) //没用禁用
|
||||||
&& button.getBtnKey().equals(BpmnButtonEnum.BPMN_APPROVE.getBtnKey())) //类型为同意
|
&& button.getBtnKey().equals(BpmnButtonEnum.BPMN_APPROVE.getBtnKey())) //类型为同意
|
||||||
.findFirst();
|
.findFirst();
|
||||||
//不存在同意按钮
|
//不存在同意按钮
|
||||||
if (!agreeButton.isPresent()) {
|
if (!agreeButton.isPresent()) {
|
||||||
|
log.info("CheckApproverServiceImpl#checkApproverExists...节点未配置同意按钮,节点ID:{}", delegateTask.getTaskDefinitionKey());
|
||||||
return exists.get();
|
return exists.get();
|
||||||
}
|
}
|
||||||
ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration();
|
ProcessEngineConfigurationImpl processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration();
|
||||||
processEngineConfiguration.getActivityInstanceEntityManager()
|
processEngineConfiguration.getActivityInstanceEntityManager()
|
||||||
.findActivityInstancesByProcessInstanceId(delegateTask.getProcessInstanceId(), false)
|
.findActivityInstancesByProcessInstanceId(delegateTask.getProcessInstanceId(), false)
|
||||||
.stream()
|
.stream()
|
||||||
.filter(i -> !Objects.equals(i.getActivityId(), userTask.getId()))
|
.filter(i -> !Objects.equals(i.getActivityId(), userTask.getId()))
|
||||||
.filter(i -> !Objects.equals(i.getActivityType(), "exclusiveGateway"))
|
.filter(i -> !Objects.equals(i.getActivityType(), "exclusiveGateway"))
|
||||||
.filter(i -> !Objects.equals(i.getActivityType(), "sequenceFlow"))
|
.filter(i -> !Objects.equals(i.getActivityType(), "sequenceFlow"))
|
||||||
.max(Comparator.comparing(ActivityInstanceEntity::getStartTime))
|
.max(Comparator.comparing(ActivityInstanceEntity::getStartTime))
|
||||||
.ifPresent(i -> {
|
.ifPresent(i -> {
|
||||||
// 与发起人比对
|
log.info("CheckApproverServiceImpl#checkApproverExists...上一个节点ID:{},类型:{}", i.getActivityId(), i.getActivityType());
|
||||||
if (Objects.equals(NODE_STARTER.getType(), i.getActivityId())) {
|
// 与发起人比对
|
||||||
BpmnTaskDelegateAssigner initiator = BpmnTaskDelegateAssigner.toObjectCompatible(delegateTask.getVariable(INTERNAL_INITIATOR));
|
if (Objects.equals(NODE_STARTER.getType(), i.getActivityId())) {
|
||||||
if (Objects.nonNull(initiator) && initiator.comparePersonIdToOther(delegateTask.getAssignee())) {
|
log.info("CheckApproverServiceImpl#checkApproverExists...与发起人比对");
|
||||||
exists.compareAndSet(false, true);
|
BpmnTaskDelegateAssigner initiator = BpmnTaskDelegateAssigner.toObjectCompatible(delegateTask.getVariable(INTERNAL_INITIATOR));
|
||||||
}
|
if (Objects.nonNull(initiator) && initiator.comparePersonIdToOther(delegateTask.getAssignee())) {
|
||||||
} else {
|
exists.compareAndSet(false, true);
|
||||||
FlowElement flowElement = mainProcess.getFlowElement(i.getActivityId());
|
|
||||||
BpmnMetaParserHelper.getNodeType(flowElement).ifPresent(j -> {
|
|
||||||
//上一节点如果是业务节点,但是是人员审批,也需要加入到自动过审
|
|
||||||
if (Objects.equals(NODE_TASK, j) || (Objects.equals(NODE_BUSINESS, j) && flowElement.getClass().isAssignableFrom(UserTask.class))) {
|
|
||||||
ExtHiTaskSearchDTO searchDTO = new ExtHiTaskSearchDTO();
|
|
||||||
searchDTO.setProcessInstanceId(delegateTask.getProcessInstanceId());
|
|
||||||
List<ExtAxHiTaskInst> extAxHiTaskInsts = extAxHiTaskInstService.queryList(searchDTO);
|
|
||||||
extAxHiTaskInsts.sort(Comparator.comparing(ExtAxHiTaskInst::getCreateAt));
|
|
||||||
List<ExtAxHiTaskInst> previousTasks = new ArrayList<>();
|
|
||||||
for (int k = extAxHiTaskInsts.size() - 1; k > 0; k--) {
|
|
||||||
ExtAxHiTaskInst extAxHiTaskInst = extAxHiTaskInsts.get(k);
|
|
||||||
if (!extAxHiTaskInst.getTaskDefinitionKey().equals(i.getActivityId()) && !CollectionUtils.isEmpty(previousTasks)) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (extAxHiTaskInst.getTaskDefinitionKey().equals(i.getActivityId())) {
|
|
||||||
previousTasks.add(extAxHiTaskInst);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
previousTasks.stream()
|
|
||||||
.filter(e -> Objects.equals(e.getStatus(), APPROVED.getStatus()))
|
|
||||||
.map(ExtAxHiTaskInst::getAssignee)
|
|
||||||
.filter(Objects::nonNull)
|
|
||||||
.filter(StringUtils::hasText)
|
|
||||||
.filter(k -> specialApproverComparison(k, delegateTask.getAssignee()))
|
|
||||||
.findAny().ifPresent(k -> exists.compareAndSet(false, true));
|
|
||||||
}
|
}
|
||||||
});
|
} else {
|
||||||
}
|
log.info("CheckApproverServiceImpl#checkApproverExists...与历史审批人比对, 上节点ID:{}", i.getActivityId());
|
||||||
});
|
FlowElement flowElement = mainProcess.getFlowElement(i.getActivityId());
|
||||||
|
BpmnMetaParserHelper.getNodeType(flowElement).ifPresent(j -> {
|
||||||
|
log.info("CheckApproverServiceImpl#checkApproverExists...上一个节点类型:{}", j);
|
||||||
|
//上一节点如果是业务节点,但是是人员审批,也需要加入到自动过审
|
||||||
|
if (Objects.equals(NODE_TASK, j) || (Objects.equals(NODE_BUSINESS, j) && flowElement.getClass().isAssignableFrom(UserTask.class))) {
|
||||||
|
ExtHiTaskSearchDTO searchDTO = new ExtHiTaskSearchDTO();
|
||||||
|
searchDTO.setProcessInstanceId(delegateTask.getProcessInstanceId());
|
||||||
|
List<ExtAxHiTaskInst> extAxHiTaskInsts = extAxHiTaskInstService.queryList(searchDTO);
|
||||||
|
extAxHiTaskInsts.sort(Comparator.comparing(ExtAxHiTaskInst::getCreateAt));
|
||||||
|
log.info("CheckApproverServiceImpl#checkApproverExists...历史审批任务列表:{}", JSON.toJSONString(extAxHiTaskInsts));
|
||||||
|
List<ExtAxHiTaskInst> previousTasks = new ArrayList<>();
|
||||||
|
for (int k = extAxHiTaskInsts.size() - 1; k > 0; k--) {
|
||||||
|
ExtAxHiTaskInst extAxHiTaskInst = extAxHiTaskInsts.get(k);
|
||||||
|
if (!extAxHiTaskInst.getTaskDefinitionKey().equals(i.getActivityId()) && !CollectionUtils.isEmpty(previousTasks)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (extAxHiTaskInst.getTaskDefinitionKey().equals(i.getActivityId())) {
|
||||||
|
previousTasks.add(extAxHiTaskInst);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.info("CheckApproverServiceImpl#checkApproverExists...待比对的历史审批任务列表:{}", JSON.toJSONString(previousTasks));
|
||||||
|
previousTasks.stream()
|
||||||
|
.filter(e -> Objects.equals(e.getStatus(), APPROVED.getStatus()))
|
||||||
|
.map(ExtAxHiTaskInst::getAssignee)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.filter(StringUtils::hasText)
|
||||||
|
.filter(k -> specialApproverComparison(k, delegateTask.getAssignee()))
|
||||||
|
.findAny().ifPresent(k -> exists.compareAndSet(false, true));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
return exists.get();
|
return exists.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user