| | |
| | | package org.springblade.mdm.flow.service; |
| | | |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.flowable.engine.HistoryService; |
| | | import org.flowable.engine.IdentityService; |
| | | import org.flowable.engine.RuntimeService; |
| | | import org.flowable.engine.TaskService; |
| | | 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.program.entity.NcProgram; |
| | | import org.springblade.mdm.program.service.NcProgramService; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | 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.program.entity.NcNode; |
| | | import org.springblade.mdm.program.service.NcNodeService; |
| | | import org.springblade.mdm.program.service.NodeDeptQueryService; |
| | | 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 MachineService machineService; |
| | | /** |
| | | * 固化流程的key |
| | | */ |
| | | private static final String PROCESS_KEY = "program-cure"; |
| | | private final IdentityService identityService; |
| | | private final NodeDeptQueryService nodeDeptQueryService; |
| | | private final NcNodeService ncNodeService; |
| | | |
| | | private final FlowProgramFileService flowProgramFileService; |
| | | private final ProduceDivisionService produceDivisionService; |
| | | private final MachineService machineService; |
| | | private final FlowCommonService flowCommonService; |
| | | |
| | | /** |
| | | * 启动固化流程 |
| | | * @param programId 程序id |
| | | */ |
| | | public void start(long programId){ |
| | | Map<String, Object> vars = new HashMap<>(); |
| | | NcProgram prog = ncProgramService.getById(programId); |
| | | Machine machine = machineService.getByCode(prog.getMachineCode()); |
| | | vars.put("machineCode",machine.getCode()); |
| | | vars.put("machineMode",machine.getName()); |
| | | vars.put("processEdition",prog.getProcessEdition()); |
| | | vars.put("programId",prog.getProcessEdition()); |
| | | vars.put("program",prog); |
| | | |
| | | |
| | | //vars.put("processNo",startVO.getProcessNo());prog.getProcessEdition() |
| | | //vars.put("processName",startVO.getProcessName()); |
| | | /* |
| | | Map<String,Object> preAssignee = autoAssignUsersService.autoAssignUsers(startVO.getProducePlanId()); |
| | | Map<String, Object> vars = new HashMap<>(preAssignee); |
| | | |
| | | vars.put("machineCode",startVO.getMachineCode()); |
| | | vars.put("machineMode",startVO.getMachineMode()); |
| | | |
| | | vars.put("processNo",startVO.getProcessNo()); |
| | | vars.put("processName",startVO.getProcessName()); |
| | | vars.put("processEdition",startVO.getProcessEdition()); |
| | | |
| | | vars.put("craftEdition",startVO.getCraftEdition()); |
| | | vars.put("planStartTime",startVO.getPlanStartTime()); |
| | | vars.put("drawingNo",startVO.getDrawingNo()); |
| | | vars.put("drawingNoEdition",startVO.getDrawingNoEdition()); |
| | | vars.put("planLockDays",startVO.getPlanLockDays()); |
| | | |
| | | //零组件代码 |
| | | String partNo = generatePartNo(startVO); |
| | | vars.put("partNo",partNo); |
| | | |
| | | NcProgram curedNcProgram = ncProgramService.getCuredNcProgram(partNo,startVO.getMachineCode()); |
| | | vars.put("curedNcProgram",curedNcProgram); |
| | | |
| | | //设置是否有固化程序标记 |
| | | vars.put("hasCuredProgram",curedNcProgram != null ? "Y":"N"); |
| | | */ |
| | | 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 |
| | | * 启动一调程序的固化流程 |
| | | * @param nodeId |
| | | * @param fileList |
| | | */ |
| | | private void startOneNew(Long nodeId, List<FlowProgramFile> fileList) { |
| | | Map<String, Object> vars = new HashMap<>(); |
| | | NcNode programPackage = this.ncNodeService.getById(nodeId); |
| | | vars.put(FlowContants.NODE_ID,programPackage.getId()); |
| | | vars.put(FlowContants.MACHINE_CODE,programPackage.getMachineCode()); |
| | | |
| | | //机床型号 |
| | | Machine machine = machineService.getByCode(programPackage.getMachineCode()); |
| | | if(machine != null) { |
| | | vars.put(FlowContants.MACHINE_MODE,machine.getName()); |
| | | } |
| | | |
| | | String workshop = nodeDeptQueryService.getWorkshopNameByMachineCode(programPackage.getMachineCode()); |
| | | vars.put(FlowContants.WORKSHOP,workshop); |
| | | |
| | | vars.put(FlowContants.PROCESS_NO,programPackage.getProcessNo()); |
| | | vars.put(FlowContants.PROCESS_NAME,programPackage.getProcessName()); |
| | | vars.put(FlowContants.PROCESS_EDITION,programPackage.getProcessEdition()); |
| | | vars.put(FlowContants.CRAFT_EDITION, programPackage.getCraftEdition()); |
| | | vars.put(FlowContants.DRAWING_NO,programPackage.getDrawingNo()); |
| | | vars.put(FlowContants.DRAWING_NO_EDITION,programPackage.getDrawingNoEdition()); |
| | | |
| | | vars.put(FlowContants.PRODUCT_MODEL,programPackage.getProductModel()); |
| | | |
| | | vars.put(FlowContants.PROGRAM_PACKAGE_NAME,programPackage.getName()); |
| | | |
| | | flowCommonService.putDefaultAssignees(vars,programPackage.getDrawingNo(),null); |
| | | //ProduceDivision div = produceDivisionService.getByDrawingNoWithQinzhe(programPackage.getDrawingNo()); |
| | | vars.put(FlowContants.ASSIGNEE,vars.get(FlowContants.PROGRAMMER)); |
| | | |
| | | |
| | | identityService.setAuthenticatedUserId(String.valueOf(AuthUtil.getUserId()));//设置流程发起人 |
| | | |
| | | vars.put(FlowContants.LAST_STEP_USER_NICKNAME, AuthUtil.getNickName()); |
| | | vars.put(FlowContants.TITLE,programPackage.getName()+"-固化");//自动增加标题 |
| | | |
| | | if(programPackage.getDeviation() != null) { |
| | | vars.put(FlowContants.MY_PROCESS_NAME, "偏离回传"); |
| | | }else { |
| | | vars.put(FlowContants.MY_PROCESS_NAME, "固化流程"); |
| | | } |
| | | ProcessInstance inst = runtimeService.startProcessInstanceByKey(FlowContants.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); |
| | | |
| | | log.info("启动固化流程完成,实例id={}", inst.getId()); |
| | | } |
| | | /** |
| | | * 将程序按照机器代码分组 |
| | | * @param ncProgramIdList |
| | | * @return |
| | | */ |
| | | 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()); |
| | | } |
| | | /* |
| | | Map<String,List<NcProgram>> groupProgramsByMachineCode(List<Long> ncProgramIdList){ |
| | | List<NcProgram> programs = ncProgramService.listByIds(ncProgramIdList); |
| | | return programs.stream().collect(Collectors.groupingBy(NcProgram::getMachineCode)); |
| | | }*/ |
| | | } |