package org.springblade.mdm.flow.service.execute;
|
|
import org.apache.commons.lang3.StringUtils;
|
import org.flowable.task.api.Task;
|
import org.springblade.core.log.exception.ServiceException;
|
import org.springblade.core.secure.utils.AuthUtil;
|
import org.springblade.core.tool.api.R;
|
import org.springblade.core.tool.support.Kv;
|
import org.springblade.core.tool.utils.Func;
|
import org.springblade.core.tool.utils.StringUtil;
|
import org.springblade.mdm.flow.constants.FlowContants;
|
import org.springblade.mdm.flow.service.FlowCommonService;
|
import org.springblade.mdm.flow.service.FlowProgramFileService;
|
import org.springblade.mdm.flow.service.FlowProgramProperties;
|
import org.springblade.mdm.program.entity.NcNode;
|
import org.springblade.mdm.program.service.NcNodeAutoCreateService;
|
import org.springblade.mdm.program.service.NcNodeService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import java.util.Map;
|
|
/**
|
* 试切流程完成任务的实现
|
*/
|
@Service("tryFlowCompleteService")
|
public class TryFlowCompleteService extends AbstractFlowCompleteService {
|
@Autowired
|
private FlowProgramFileService flowProgramFileService;
|
@Autowired
|
private NcNodeService ncNodeService;
|
@Autowired
|
private NcNodeAutoCreateService ncNodeAutoCreateService;
|
@Autowired
|
private FlowCommonService flowCommonService;
|
|
@Transactional
|
@Override
|
public void completeTask(String taskId, String processInstanceId, String comment, Map<String, Object> variables) {
|
Task task = currentTask(taskId);
|
String operateResult = this.getApproveResult(variables);
|
|
if(task.getTaskDefinitionKey().equals("programmingTask")) {//编制节点
|
flowProgramFileService.checkProgramFiles(processInstanceId,"Y".equals(operateResult));
|
}
|
if (StringUtil.isNoneBlank(processInstanceId, comment)) {
|
taskService.addComment(taskId, processInstanceId, comment);
|
}
|
// 非空判断
|
if (Func.isEmpty(variables)) {
|
variables = Kv.create();
|
}
|
variables.put(FlowContants.LAST_STEP_USER_NICKNAME, AuthUtil.getNickName());
|
|
if(!variables.containsKey("assignee")) {
|
throw new ServiceException("请指定流程下一步处理人");
|
}
|
addApproveRecord(taskId,comment,variables);
|
|
//在编制任务时,创建节点(没有节点则创建,有就直接使用
|
if(task.getTaskDefinitionKey().equals("programmingTask") && FlowContants.Y.equals(operateResult)) {
|
FlowProgramProperties progProperties = flowCommonService.getProgramProperties(processInstanceId);
|
ncNodeAutoCreateService.createNodeTreeWithProgram(progProperties);
|
//原来版次的程序,此时应该清除,是不是要挪过来呢?版次已经不对了
|
//TODO 老节点清除吗
|
|
//走到编制节点,如果是有固化程序且通过了,说明需要升版(重新编写),将固化的原来的程序设置lastEdition=0
|
if(FlowContants.Y.equals(progProperties.getHasCuredProgram())) {
|
NcNode curedProgramPackage = ncNodeService.getById(Func.toLong(progProperties.getCuredNodeId()));
|
curedProgramPackage.setIsLastEdition(0);
|
curedProgramPackage.setIsLocked(1);
|
ncNodeService.updateById(curedProgramPackage);
|
}
|
|
}
|
variables.remove(FlowContants.PROCESS_EDITION);//不要升版了
|
//if(!"confirmIsUseableTask".equals(task.getTaskDefinitionKey())){
|
if("confirmIsUseableTask".equals(task.getTaskDefinitionKey())){
|
//工序版次不一致,并且审核通过(可用)是,才更新为新的versionNumber
|
FlowProgramProperties progProperties = flowCommonService.getProgramProperties(processInstanceId);
|
|
if(FlowContants.Y.equals(operateResult)) {
|
|
if(FlowContants.N.equals(progProperties.getIsProcessEditionSame())) {
|
//确认程序可用 且 工序版次不一致,进入校对。这里需要升级程序的版本号
|
Long curedNodeId = progProperties.getCuredNodeId();
|
ncNodeService.upgradeVersionNumber(curedNodeId);
|
}
|
|
}
|
}
|
taskService.complete(taskId, variables);
|
}
|
}
|