| | |
| | | import org.flowable.engine.runtime.ProcessInstance; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | import org.springblade.core.tool.utils.Func; |
| | | import org.springblade.mdm.basesetting.producedivision.entity.ProduceDivision; |
| | | import org.springblade.mdm.basesetting.producedivision.service.ProduceDivisionService; |
| | | import org.springblade.mdm.flow.constants.FlowContants; |
| | | import org.springblade.mdm.flow.entity.FlowProgramFile; |
| | | import org.springblade.mdm.flow.service.FlowCommonService; |
| | | import org.springblade.mdm.flow.service.FlowProgramFileService; |
| | | import org.springblade.mdm.flow.vo.TaskAssignVO; |
| | | import org.springblade.mdm.program.entity.NcNode; |
| | |
| | | |
| | | private final FlowProgramFileService flowProgramFileService; |
| | | private final NodeDeptQueryService nodeDeptQueryService; |
| | | //public static final String PROCESS_KEY = "dispatch"; |
| | | private final ProduceDivisionService produceDivisionService; |
| | | private final FlowCommonService flowCommonService; |
| | | |
| | | /** |
| | | * 启动派工流程 |
| | |
| | | */ |
| | | @Transactional |
| | | public String start(TaskAssignVO startVO){ |
| | | Map<String, Object> vars = new HashMap<>(); |
| | | |
| | | Map<String,Object> preAssignee = autoAssignUsersService.autoAssignUsers(startVO); |
| | | Map<String, Object> vars = new HashMap<>(preAssignee); |
| | | vars.put(FlowContants.ASSIGNEE,preAssignee.get(FlowContants.TEAM_LEADER));//第一个审批用户:组长 |
| | | |
| | | ProduceDivision div = flowCommonService.putDefaultAssignees(vars,startVO.getDrawingNo(),null); |
| | | vars.put(FlowContants.ASSIGNEE,div.getTeamLeaderId());//第一个用户组长 |
| | | vars.put(FlowContants.TITLE,startVO.getTitle()); |
| | | |
| | | //临时流程标志,明确指定Y,属于临时流程 |
| | | vars.put(FlowContants.IS_TEMP_FLOW,FlowContants.Y.equals(startVO.getIsTempFlow())?FlowContants.Y:FlowContants.N); |
| | | //机床编号 |
| | | vars.put(FlowContants.MACHINE_CODE,startVO.getMachineCode()); |
| | | String workshop = nodeDeptQueryService.getWorkshopNameByMachineCode(startVO.getMachineCode()); |
| | | vars.put("workshop",workshop); |
| | | vars.put(FlowContants.WORKSHOP,workshop); |
| | | //机床型号 |
| | | vars.put(FlowContants.MACHINE_MODE,startVO.getMachineMode()); |
| | | |
| | | |
| | | vars.put(FlowContants.PROCESS_NO,startVO.getProcessNo()); |
| | | vars.put(FlowContants.PROCESS_NAME,startVO.getProcessName()); |
| | |
| | | String programPkgName = NcNodeService.genProgramName(startVO.getDrawingNo(),startVO.getProcessNo()); |
| | | vars.put(FlowContants.PROGRAM_PACKAGE_NAME,programPkgName); |
| | | |
| | | //TODO 查询固化程序是,应该去掉有偏离单的? |
| | | NcNode curedProgramPackage = ncNodeService.getLastEditionCuredProgramPackage(programPkgName); |
| | | NcNode curedProgramPackage = ncNodeService.getCuredProgramPackage(programPkgName,startVO.getMachineCode()); |
| | | //设置是否有固化程序标记 |
| | | vars.put(FlowContants.HAS_CURED_PROGRAM,curedProgramPackage != null ? FlowContants.Y:FlowContants.N); |
| | | //工序版次是否一致,是否在有效期内 |
| | |
| | | vars.put(FlowContants.IS_PROCESS_EDITION_SAME, FlowContants.Y); |
| | | vars.put(FlowContants.VALIDITY_PERIOD, FlowContants.Y); |
| | | } |
| | | String myProcessName = "试切下发流程"; |
| | | if(vars.getOrDefault(FlowContants.HAS_CURED_PROGRAM,FlowContants.N).equals(FlowContants.Y)){ |
| | | myProcessName = "固化下发流程"; |
| | | } |
| | | if(StringUtils.isNotBlank(startVO.getDeviation()) ){ |
| | | myProcessName = "偏离单"; |
| | | } |
| | | vars.put(FlowContants.MY_PROCESS_NAME, myProcessName); |
| | | |
| | | String businessKey = "0";//业务表key |
| | | identityService.setAuthenticatedUserId(String.valueOf(AuthUtil.getUserId()));//设置流程发起人 |
| | | ProcessInstance inst = runtimeService.startProcessInstanceByKey(FlowContants.TRY_PROCESS_KEY,businessKey,vars); |
| | | |
| | | if(curedProgramPackage != null) {//存在已固化程序,复制原来的程序文件。创建节点仍然在编程人员提交以后 |
| | | copyFlowProgramFiles(curedProgramPackage.getProcessInstanceId(),inst.getProcessInstanceId()); |
| | | if(curedProgramPackage != null) {//存在已固化程序,复制原来的程序文件。 |
| | | copyFlowProgramFiles(curedProgramPackage.getId(),inst.getProcessInstanceId()); |
| | | |
| | | curedProgramPackage.setProcessInstanceId(inst.getProcessInstanceId()); |
| | | ncNodeService.updateById(curedProgramPackage); |
| | | } |
| | | |
| | | |
| | | return inst.getProcessInstanceId(); |
| | | } |
| | | |
| | | /** |
| | | * 根据原有固化程序包名节点,复制一个,赋予新的流程实例id |
| | | * @param programPkg 原有固化的程序包名节点 |
| | | * @param processInstanceId 流程实例id |
| | | */ |
| | | |
| | | void cloneNodes(NcNode programPkg,String processInstanceId){ |
| | | NcNode newProgramPkg = new NcNode(); |
| | | BeanUtils.copyProperties(programPkg,newProgramPkg); |
| | | EntityUtil.clearBaseProperties(newProgramPkg); |
| | | |
| | | newProgramPkg.setProcessInstanceId(processInstanceId); |
| | | this.ncNodeService.save(newProgramPkg); |
| | | } |
| | | |
| | | /** |
| | | * 复制流程程序文件 |
| | | * @param processInstanceId 新启动的流程id |
| | | */ |
| | | private void copyFlowProgramFiles(String oldProcessInstanceId,String processInstanceId) { |
| | | List<FlowProgramFile> fileList = flowProgramFileService.lambdaQuery() |
| | | .eq(FlowProgramFile::getProcessInstanceId,oldProcessInstanceId).list(); |
| | | private void copyFlowProgramFiles(long packageNameNodeId,String processInstanceId) { |
| | | List<Long> fileIds = ncNodeService.getProgramFilesByPackageId(packageNameNodeId).stream().map(NcNode::getFlowProgramFileId).toList(); |
| | | if(!fileIds.isEmpty()) { |
| | | List<FlowProgramFile> fileList = flowProgramFileService.lambdaQuery().in(FlowProgramFile::getId, fileIds).list(); |
| | | |
| | | for (FlowProgramFile file : fileList) { |
| | | FlowProgramFile newFile = new FlowProgramFile(); |
| | | BeanUtils.copyProperties(file, newFile); |
| | | EntityUtil.clearBaseProperties(newFile); |
| | | for (FlowProgramFile file : fileList) { |
| | | FlowProgramFile newFile = new FlowProgramFile(); |
| | | BeanUtils.copyProperties(file, newFile); |
| | | EntityUtil.clearBaseProperties(newFile); |
| | | |
| | | newFile.setProcessInstanceId(processInstanceId); |
| | | newFile.setProcessInstanceId(processInstanceId); |
| | | |
| | | this.flowProgramFileService.save(newFile); |
| | | this.flowProgramFileService.save(newFile); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 生成零组件编号 |
| | | * 图号、图号版次、工序号、工序名称、工艺版次、工序版次 组合起来获得零组件号 |
| | | * @param startVO |
| | | * @return |
| | | */ |
| | | /* |
| | | String generatePartNo(TaskAssignVO startVO){ |
| | | //TODO 这个格式未确定,需要确认 |
| | | return String.format("%s-%s-%s-%s-%s-%s", |
| | | startVO.getPartNo(), |
| | | startVO.getPartNoEdition(), |
| | | startVO.getProcessNo(), |
| | | startVO.getProcessName(), |
| | | startVO.getCraftEdition(), |
| | | startVO.getProcessEdition()); |
| | | }*/ |
| | | |
| | | } |