| | |
| | | package org.springblade.mdm.flow.service; |
| | | |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.flowable.engine.IdentityService; |
| | | import org.flowable.engine.RuntimeService; |
| | | import org.flowable.engine.runtime.ProcessInstance; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | import org.springblade.mdm.basesetting.machine.MachineService; |
| | | import org.springblade.mdm.basesetting.machine.entity.Machine; |
| | | import org.springblade.mdm.flow.excution.AutoAssignUsersService; |
| | | import org.springblade.mdm.flow.vo.TaskAssignVO; |
| | | import org.springblade.mdm.flow.constants.FlowConstant; |
| | | import org.springblade.mdm.flow.constants.FlowVariableConstant; |
| | | import org.springblade.mdm.flow.entity.FlowProgramFile; |
| | | import org.springblade.mdm.program.entity.NcNode; |
| | | import org.springblade.mdm.program.entity.NcProgram; |
| | | import org.springblade.mdm.program.service.NcNodeService; |
| | | import org.springblade.mdm.program.service.NcProgramService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springblade.mdm.utils.EntityUtil; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 固化流程服务 |
| | | */ |
| | | @Slf4j |
| | | @Service |
| | | @AllArgsConstructor |
| | | public class CureFlowService { |
| | | |
| | | @Autowired |
| | | private RuntimeService runtimeService; |
| | | @Autowired |
| | | private AutoAssignUsersService autoAssignUsersService; |
| | | @Autowired |
| | | private IdentityService identityService; |
| | | private final RuntimeService runtimeService; |
| | | |
| | | @Autowired |
| | | private NcProgramService ncProgramService; |
| | | @Autowired |
| | | private NcNodeService ncNodeService; |
| | | @Autowired |
| | | private MachineService machineService; |
| | | /** |
| | | * 固化流程的key |
| | | */ |
| | | private static final String PROCESS_KEY = "program-cure"; |
| | | private final IdentityService identityService; |
| | | private final NcNodeService ncNodeService; |
| | | |
| | | private final FlowProgramFileService flowProgramFileService; |
| | | private final FlowCommonService flowCommonService; |
| | | |
| | | /** |
| | | * 启动固化流程 |
| | | * @param programId 程序id |
| | | */ |
| | | public void start(long programId){ |
| | | Map<String, Object> vars = new HashMap<>(); |
| | | //NcProgram prog = ncProgramService.getById(programId); |
| | | NcNode progNode = ncNodeService.getById(programId); |
| | | Machine machine = machineService.getByCode(progNode.getMachineCode()); |
| | | vars.put("machineCode",machine.getCode()); |
| | | vars.put("machineMode",machine.getName()); |
| | | vars.put("processEdition",progNode.getProcessEdition()); |
| | | vars.put("programId",programId); |
| | | vars.put("program",progNode); |
| | | |
| | | |
| | | String businessKey = "0";//业务表key |
| | | |
| | | identityService.setAuthenticatedUserId(String.valueOf(AuthUtil.getUserId()));//设置流程发起人 |
| | | ProcessInstance pinst = runtimeService.startProcessInstanceByKey(PROCESS_KEY,businessKey,vars); |
| | | |
| | | int a=1; |
| | | //log.info() |
| | | @Transactional |
| | | public void startCureNew(Map<Long, List<FlowProgramFile>> pkgIdFileMap) { |
| | | pkgIdFileMap.forEach(this::startOneNew); |
| | | } |
| | | |
| | | /** |
| | | * 生成零组件编号 |
| | | * 图号、图号版次、工序号、工序名称、工艺版次、工序版次 组合起来获得零组件号 |
| | | * @param startVO |
| | | * @return |
| | | * 启动一调程序的固化流程 |
| | | * @param nodeId |
| | | * @param fileList |
| | | */ |
| | | String generatePartNo(TaskAssignVO startVO){ |
| | | //TODO 这个格式未确定,需要确认 |
| | | return String.format("%s-%s-%s-%s-%s-%s", |
| | | startVO.getDrawingNo(), |
| | | startVO.getDrawingNoEdition(), |
| | | startVO.getProcessNo(), |
| | | startVO.getProcessName(), |
| | | startVO.getCraftEdition(), |
| | | startVO.getProcessEdition()); |
| | | private void startOneNew(Long nodeId, List<FlowProgramFile> fileList) { |
| | | Map<String, Object> vars = new HashMap<>(); |
| | | NcNode programPackage = this.ncNodeService.getById(nodeId); |
| | | vars.put(FlowConstant.NODE_ID,programPackage.getId()); |
| | | |
| | | flowCommonService.putFlowVariablesByNode(vars,programPackage); |
| | | |
| | | flowCommonService.putDefaultAssignees(vars,programPackage.getDrawingNo(),null); |
| | | vars.put(FlowVariableConstant.ASSIGNEE,vars.get(FlowVariableConstant.PROGRAMMER)); |
| | | identityService.setAuthenticatedUserId(String.valueOf(AuthUtil.getUserId()));//设置流程发起人 |
| | | vars.put(FlowVariableConstant.LAST_STEP_USER_NICKNAME, AuthUtil.getNickName()); |
| | | |
| | | if(programPackage.getDeviation() != null) { |
| | | vars.put(FlowVariableConstant.MY_PROCESS_NAME, "临时更改单回传"); |
| | | vars.put(FlowVariableConstant.TITLE,programPackage.getName()+"-临时更改单回传");//自动增加标题 |
| | | }else { |
| | | vars.put(FlowVariableConstant.MY_PROCESS_NAME, "固化流程"); |
| | | vars.put(FlowVariableConstant.TITLE,programPackage.getName()+"-"+programPackage.getProcessEdition()+"-固化");//自动增加标题 |
| | | } |
| | | ProcessInstance inst = runtimeService.startProcessInstanceByKey(FlowConstant.CURE_PROCESS_KEY,"0",vars); |
| | | |
| | | //更新程序包名节点的流程实例id |
| | | programPackage.setProcessInstanceId(inst.getProcessInstanceId()); |
| | | ncNodeService.updateById(programPackage); |
| | | |
| | | for(FlowProgramFile flowProgramFile : fileList){ |
| | | flowProgramFile.setProcessInstanceId(inst.getProcessInstanceId()); |
| | | } |
| | | this.flowProgramFileService.saveBatch(fileList); |
| | | |
| | | addPreviousOtherFiles(programPackage.getId(),inst.getProcessInstanceId()); |
| | | |
| | | log.info("启动固化流程完成,实例id={}", inst.getId()); |
| | | } |
| | | |
| | | /** |
| | | * 复制试切阶段的其他文件给固化流程 |
| | | * @param previousNodeId 试切阶段的节点id |
| | | * @param newProcessInstanceId 新的固化流程实例id |
| | | */ |
| | | void addPreviousOtherFiles(Long previousNodeId,String newProcessInstanceId) { |
| | | List<NcNode> previousFileNodes = ncNodeService.getProgramFilesByPackageId(previousNodeId); |
| | | for(NcNode fileNode : previousFileNodes){ |
| | | |
| | | FlowProgramFile progFile = flowProgramFileService.getById(fileNode.getFlowProgramFileId()); |
| | | if(!progFile.isProgram()){ |
| | | FlowProgramFile newProgFile = new FlowProgramFile(); |
| | | BeanUtils.copyProperties(progFile,newProgFile); |
| | | EntityUtil.clearBaseProperties(newProgFile); |
| | | newProgFile.setProcessInstanceId(newProcessInstanceId); |
| | | |
| | | flowProgramFileService.save(newProgFile); |
| | | } |
| | | } |
| | | } |
| | | } |