| | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.io.FilenameUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.flowable.engine.HistoryService; |
| | | import org.flowable.engine.history.HistoricProcessInstance; |
| | | import org.springblade.core.log.exception.ServiceException; |
| | | import org.springblade.core.mp.base.BizServiceImpl; |
| | | import org.springblade.core.oss.OssTemplate; |
| | | import org.springblade.mdm.basesetting.machine.service.MachineService; |
| | | import org.springblade.mdm.basesetting.machine.entity.Machine; |
| | | import org.springblade.mdm.flow.constants.FlowConstant; |
| | | import org.springblade.mdm.flow.entity.FlowProgramFile; |
| | | import org.springblade.mdm.flow.service.FlowProgramFileService; |
| | | import org.springblade.mdm.flow.service.TaskDispatchService; |
| | | import org.springblade.mdm.program.entity.NcNode; |
| | | import org.springblade.mdm.program.entity.NcNodeHis; |
| | | import org.springblade.mdm.program.entity.NcProgramApproved; |
| | | import org.springblade.mdm.program.entity.NcProgramExchange; |
| | | import org.springblade.mdm.program.mapper.NcProgramExchangeMapper; |
| | | import org.springblade.mdm.program.service.programannotation.AnnotationData; |
| | | import org.springblade.mdm.program.service.programannotation.AnnotationProcessor; |
| | | import org.springblade.mdm.program.service.programannotation.MachineAnnotationConfig; |
| | | import org.springblade.mdm.program.service.programannotation.ProcessorHelper; |
| | | import org.springblade.mdm.program.service.programannotation.*; |
| | | import org.springblade.system.feign.IDictClient; |
| | | import org.springblade.system.pojo.entity.DictBiz; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import java.io.*; |
| | |
| | | private final NcNodeHisService ncNodeHisService; |
| | | private final OssTemplate ossTemplate; |
| | | private final FlowProgramFileService flowProgramFileService; |
| | | private final ProgramAnnotationService programAnnotationService; |
| | | |
| | | private final MachineAnnotationConfig annotationConfig; |
| | | private final HistoryService historyService; |
| | | private final TaskDispatchService taskDispatchService; |
| | | private final AnnotationProcessorHelper annotationProcessorHelper; |
| | | /** |
| | | * 导出dnc压缩包 |
| | | * @param approvedIdArray 待导出审批表id数组 |
| | |
| | | |
| | | approved.setStatus(NcProgramApproved.STATUS_EXPORTED); |
| | | approvedService.updateById(approved); |
| | | |
| | | NcNodeHis pkgNodeHis = this.ncNodeHisService.getById(approved.getNcNodeId()); |
| | | if(pkgNodeHis.isDeviationProgram()){ |
| | | //偏离单的程序,如果审批导出记录是解锁形成的,还是需要锁定;普通试切过的,不锁定 |
| | | HistoricProcessInstance hisInst = historyService.createHistoricProcessInstanceQuery().processInstanceId(approved.getProcessInstanceId()).singleResult(); |
| | | if(hisInst != null && hisInst.getProcessDefinitionKey().equals(FlowConstant.UNLOCK_PROCESS_KEY)){ |
| | | NcNode pkgNode = this.ncNodeService.getById(approved.getNcNodeId()); |
| | | if(pkgNode != null) { |
| | | pkgNode.lock("下发导出锁定"); |
| | | ncNodeService.updateById(pkgNode); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | }catch(Exception e){ |
| | |
| | | |
| | | /** |
| | | * 将程序包和下属文件加入压缩包 |
| | | * @param zipOut |
| | | * @param approved |
| | | * @param zipOut zip文件输出流 |
| | | * @param approved 审批完成记录 |
| | | */ |
| | | private void addProgramPackageToZip(ZipOutputStream zipOut, NcProgramApproved approved) throws IOException{ |
| | | NcNodeHis packageNodeHis = ncNodeHisService.getById(approved.getNcNodeId()); |
| | |
| | | |
| | | Machine machine = machineService.getByCode(packageNodeHis.getMachineCode());//程序包节点,获取注释用 |
| | | |
| | | //List<NcNode> programNodes = ncNodeService.lambdaQuery().eq(NcNode::getIsLastEdition,1).eq(NcNode::getParentId, approved.getNcNodeId()).list(); |
| | | //需要增加版本号的过滤 |
| | | List<NcNodeHis> programNodes = ncNodeHisService.lambdaQuery().eq(NcNodeHis::getParentId, approved.getNcNodeId()).list(); |
| | | |
| | | FlowProgramFile programFile; |
| | | NcNodeHis programPackageNode = this.ncNodeHisService.getById(approved.getNcNodeId()); |
| | | String status = "SQ"; |
| | | String status = AnnotationUtil.SQ; |
| | | if(programPackageNode.isDeviationProgram()){ |
| | | status = "PL"; |
| | | status = AnnotationUtil.LG; |
| | | }else if(programPackageNode.hasCured()){ |
| | | status = "GH"; |
| | | status = AnnotationUtil.GH; |
| | | } |
| | | long deviationSerial = -1;//偏离单序号 ,-1为非偏离单,不需要加入 |
| | | if(packageNodeHis.isDeviationProgram()) { |
| | | deviationSerial = ncNodeHisService.getDeviationSerialForNode(packageNodeHis); |
| | | deviationSerial = taskDispatchService.getDeviationSerial(packageNodeHis.getProgramNo()); |
| | | } |
| | | |
| | | //List<DictBiz> annotationDictList= programAnnotationService.getAnnotionDictList(); |
| | | for (NcNodeHis node : programNodes) { |
| | | String filePathInZip = genFilePathInZip(packageFolder,node,deviationSerial); |
| | | programFile = this.flowProgramFileService.getById(node.getFlowProgramFileId()); |
| | |
| | | InputStream inputStream = ossTemplate.statFileStream(programFile.getOssName()); |
| | | String sendDir = machine.getProgSendDir()==null? StringUtil.EMPTY:machine.getProgSendDir(); |
| | | |
| | | AnnotationProcessor annoProcessor = ProcessorHelper.getProcessor(machine.getControlSystem(),annotationConfig); |
| | | AnnotationProcessor annoProcessor = this.annotationProcessorHelper.getProcessor(machine.getControlSystem()); |
| | | AnnotationData annoData = new AnnotationData(); |
| | | annoData.setSendPath(sendDir); |
| | | annoData.setProgramStatus(status); |
| | | annoData.setDeviation(programPackageNode.getDeviation()); |
| | | annoData.setFilename(programFile.getName()); |
| | | InputStream addedInsFinal = annoProcessor.setAnnotation(annoData,inputStream); |
| | | |
| | | if(StringUtils.startsWith(programPackageNode.getParentIds(),"0,4")) { |
| | | //试切补充,特殊标记状态 |
| | | annoData.setProgramStatus(AnnotationUtil.TMP); |
| | | } |
| | | InputStream addedInsFinal = annoProcessor.putAnnotation(annoData, inputStream); |
| | | addedInsFinal.reset(); |
| | | /* |
| | | InputStream addedInsFinal; |
| | | InputStream addedIns2 = programAnnotationService.setSendDirAndStatusAnnotation(sendDir,status,inputStream,machine.getControlSystem()); |
| | | if(StringUtils.isNotBlank(programPackageNode.getDeviation())) { |
| | | //偏离单,增加偏离单号 |
| | | addedInsFinal = programAnnotationService.setPldAnnotation(programPackageNode.getDeviation(),addedIns2, machine.getControlSystem(), annotationDictList);; |
| | | }else{ |
| | | addedInsFinal = addedIns2; |
| | | }*/ |
| | | this.addInputStreamToZip(zipOut, addedInsFinal, filePathInZip); |
| | | } |
| | | } |
| | |
| | | * 生成在zip中的文件路径 |
| | | * @param packageFolder zip中的文件夹 |
| | | * @param programNode 程序节点 |
| | | * @param deviationSerial 偏离单序号 |
| | | * @param deviationSerial 临时更改单序号 |
| | | * @return zip中的文件路径 |
| | | */ |
| | | String genFilePathInZip(String packageFolder,NcNodeHis programNode,long deviationSerial){ |
| | |
| | | * @param zipOut zip输出流 |
| | | * @param inputStream 输入流 |
| | | * @param entryName 文件名 |
| | | * @throws IOException |
| | | * @throws IOException 写文件异常 |
| | | */ |
| | | void addInputStreamToZip(ZipOutputStream zipOut, InputStream inputStream, String entryName) |
| | | throws IOException { |