| | |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.jetbrains.annotations.NotNull; |
| | | import org.springblade.core.log.exception.ServiceException; |
| | | import org.springblade.core.mp.base.BizEntity; |
| | | import org.springblade.core.mp.base.BizServiceImpl; |
| | | import org.springblade.core.mp.support.Condition; |
| | |
| | | |
| | | import java.io.*; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.Optional; |
| | | import java.util.*; |
| | | import java.util.zip.ZipEntry; |
| | | import java.util.zip.ZipOutputStream; |
| | | |
| | |
| | | private final NcNodeService ncNodeService; |
| | | private final OssTemplate ossTemplate; |
| | | private final FlowProgramFileService flowProgramFileService; |
| | | private final ProgramAnnotationService programAnnotationService; |
| | | //public static final String PROGRAM_JSON_FILE = "exp_mdm_nc_program.json"; |
| | | //public static final String NODE_JSON_FILE = "exp_mdm_nc_node.json"; |
| | | //public static final String APPROVE_RECORD_JSON_FILE = "exp_mdm_approve_record.json"; |
| | |
| | | */ |
| | | public void exportDnc(Long[] approvedIdArray, OutputStream os) throws IOException { |
| | | //FileOutputStream fos = new FileOutputStream("d:/exportDnc.zip"); |
| | | try (ZipOutputStream zipOut = new ZipOutputStream(os);) {//os |
| | | |
| | | //ArrayList<Long> programPackageNodeIdList = new ArrayList<Long>(); |
| | | try (ZipOutputStream zipOut = new ZipOutputStream(os);os) {//os |
| | | |
| | | for (Long approvedId : approvedIdArray) { |
| | | NcProgramApproved approved = approvedService.getById(approvedId); |
| | | //programPackageNodeIdList.add(approved.getNcNodeId()); |
| | | |
| | | addProgramPackageToZip(zipOut,approved); |
| | | |
| | | approved.setStatus(NcProgramApproved.STATUS_EXPORTED); |
| | | approvedService.updateById(approved); |
| | | } |
| | | |
| | | //状态修改为已导出 |
| | | approvedService.lambdaUpdate().in(NcProgramApproved::getId, approvedIdArray) |
| | | .set(NcProgramApproved::getStatus,NcProgramApproved.STATUS_EXPORTED).update(); |
| | | //addDataJson(zipOut, programPackageNodeIdList); |
| | | /* |
| | | approvedService.lambdaUpdate().in(NcProgramApproved::getId, Arrays.asList(approvedIdArray)) |
| | | .set(NcProgramApproved::getStatus,NcProgramApproved.STATUS_EXPORTED).update();*/ |
| | | }catch(Exception e){ |
| | | Throwable [] err = e.getSuppressed(); |
| | | throw new ServiceException("导出工控网错误"+e.getMessage()); |
| | | } |
| | | |
| | | os.close(); |
| | | |
| | | } |
| | | |
| | |
| | | }else if(programPackageNode.hasCured()){ |
| | | status = "GH"; |
| | | } |
| | | List<Dict> annotationList = getAnnotionList(); |
| | | List<Dict> annotationList = programAnnotationService.getAnnotionList(); |
| | | for (NcNode node : programNodes) { |
| | | String filePathInZip = packageFolder + node.getName(); |
| | | programFile = this.flowProgramFileService.getById(node.getFlowProgramFileId()); |
| | | |
| | | InputStream inputStream = ossTemplate.statFileStream(programFile.getOssName()); |
| | | Machine machine = machineService.getByCode(node.getMachineCode()); |
| | | InputStream addedIns1 = addSendDirAnnotation(inputStream,machine,annotationList); |
| | | InputStream addedIns2 = addProgramStatusAnnotation(addedIns1,status,machine,annotationList); |
| | | this.addInputStreamToZip(zipOut,addedIns2,filePathInZip); |
| | | if(programFile.isProgram()) {//程序文件,才会加入压缩包 |
| | | InputStream inputStream = ossTemplate.statFileStream(programFile.getOssName()); |
| | | Machine machine = machineService.getByCode(node.getMachineCode()); |
| | | InputStream addedIns1 = addSendDirAnnotation(inputStream, machine, annotationList); |
| | | InputStream addedIns2 = addProgramStatusAnnotation(addedIns1, status, machine, annotationList); |
| | | this.addInputStreamToZip(zipOut, addedIns2, filePathInZip); |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 获取字典中配置的注释 |
| | | * @return 字典项列表 |
| | | */ |
| | | List<Dict> getAnnotionList(){ |
| | | List<Dict> annotationList; |
| | | R<List<Dict>> dictsResult = dictClient.getList(ANNOTATION_DICT); |
| | | if(dictsResult.isSuccess()) { |
| | | annotationList = dictsResult.getData(); |
| | | }else{ |
| | | annotationList = Collections.emptyList(); |
| | | } |
| | | |
| | | return annotationList; |
| | | } |
| | | /** |
| | | * 加入机床下发路径和程序状态的注释 |
| | | * @param inputStream |
| | |
| | | */ |
| | | InputStream addSendDirAnnotation(InputStream inputStream,Machine machine,List<Dict> annotationList) throws IOException { |
| | | //检测第二行是否是路径 |
| | | String annotationText = generateAnnotation(machine.getProgSendDir()==null? StringUtil.EMPTY:machine.getProgSendDir(),machine.getMachineGroupCode(),annotationList); |
| | | String annotationText = programAnnotationService.generateAnnotation(machine.getProgSendDir()==null? StringUtil.EMPTY:machine.getProgSendDir(),machine.getMachineGroupCode(),annotationList); |
| | | |
| | | //TODO 改判断行内容 |
| | | return FileContentUtil.insertLine(inputStream,1,annotationText); |
| | |
| | | * @throws IOException |
| | | */ |
| | | InputStream addProgramStatusAnnotation(InputStream inputStream,String status,Machine machine,List<Dict> annotationList) throws IOException { |
| | | return FileContentUtil.insertLine(inputStream,2,generateAnnotation(status,machine.getMachineGroupCode(),annotationList)); |
| | | String annoText= programAnnotationService.generateAnnotation(status,machine.getMachineGroupCode(),annotationList); |
| | | |
| | | return FileContentUtil.insertLine(inputStream,2,annoText); |
| | | } |
| | | |
| | | /** |
| | | * 判断一行文本是否是注释 |
| | | * @param line |
| | | * @param annotationList |
| | | * @return |
| | | */ |
| | | boolean isAnnotation(String line,List<Dict> annotationList){ |
| | | boolean isAnno = false; |
| | | |
| | | return isAnno; |
| | | } |
| | | |
| | | |
| | | |
| | | String generateAnnotation(String oriTest,String machineGroupCode,List<Dict> annotationList) { |
| | | R<List<Dict>> dictsResult = dictClient.getList(ANNOTATION_DICT); |
| | | String annotation = oriTest; |