| | |
| | | import org.springblade.core.mp.base.BizServiceImpl; |
| | | import org.springblade.core.oss.OssTemplate; |
| | | import org.springblade.core.tool.utils.DateUtil; |
| | | import org.springblade.core.tool.utils.SpringUtil; |
| | | import org.springblade.mdm.basesetting.machine.entity.Machine; |
| | | import org.springblade.mdm.basesetting.machine.service.MachineService; |
| | | import org.springblade.mdm.flow.excution.events.CureFinishedEvent; |
| | | import org.springblade.mdm.gkw.task.entity.MachineBackTask; |
| | | import org.springblade.mdm.gkw.task.service.MachineBackTaskService; |
| | | import org.springblade.mdm.machinefile.entity.MachineAcceptedFile; |
| | | import org.springblade.mdm.machinefile.entity.MachineFile; |
| | | import org.springblade.mdm.machinefile.events.ExportedToInnerEvent; |
| | | import org.springblade.mdm.program.entity.NcProgramExchange; |
| | | import org.springblade.mdm.program.mapper.NcProgramExchangeMapper; |
| | | import org.springblade.mdm.program.service.ProgramAnnotationService; |
| | |
| | | private final OssTemplate ossTemplate; |
| | | private final MachineFileService machineFileService; |
| | | private final MachineService machineService; |
| | | private final MachineAnnotationConfig annoConfig; |
| | | private final AnnotationProcessorHelper annotationProcessorHelper; |
| | | private final ProgramAnnotationService programAnnotationService; |
| | | |
| | | private final MachineBackTaskService machineBackTaskService; |
| | | /** |
| | | * 导出到涉密网 |
| | | * @param acceptedFileIds |
| | |
| | | @Transactional |
| | | public void exportToInner(List<Long> acceptedFileIds, ServletOutputStream os) throws IOException { |
| | | |
| | | List<MachineAcceptedFile> acceptedFiles = machineAcceptedService.lambdaQuery().in(MachineAcceptedFile::getId,acceptedFileIds).list(); |
| | | try (ZipOutputStream zipOut = new ZipOutputStream(os);) {//os |
| | | |
| | | List<MachineAcceptedFile> acceptedFiles = machineAcceptedService.lambdaQuery().in(MachineAcceptedFile::getId,acceptedFileIds).list(); |
| | | Map<String,List<MachineAcceptedFile>> map = acceptedFiles.stream() |
| | | .collect(Collectors.groupingBy(s -> ProgramFileNameParser.parseProgramName(s.getName()).logicProgramName())); |
| | | |
| | |
| | | } |
| | | |
| | | machineAcceptedService.updateBatchById(acceptedFiles); |
| | | |
| | | //更新任务状态 |
| | | List<Long> backTaskIdList = acceptedFiles.stream().map(MachineAcceptedFile::getBackTaskId).filter(Objects::nonNull).toList(); |
| | | this.finishTask(backTaskIdList); |
| | | |
| | | SpringUtil.publishEvent(new ExportedToInnerEvent("exportToInner",acceptedFiles)); |
| | | } |
| | | |
| | | os.close(); |
| | | |
| | | |
| | | } |
| | | |
| | | void finishTask(List<Long> backTaskIdList){ |
| | | if(backTaskIdList.isEmpty()){ |
| | | return; |
| | | } |
| | | List<MachineBackTask> tasks = machineBackTaskService.lambdaQuery().in(MachineBackTask::getId,backTaskIdList).list(); |
| | | for(MachineBackTask backTask : tasks){ |
| | | backTask.setStatus(MachineBackTask.STATUS_FINISHED); |
| | | backTask.setFinishTime(new Date()); |
| | | |
| | | machineBackTaskService.updateById(backTask); |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * j将输入流加入zip |
| | | * @param zipOut zip文件输出里路 |
| | | * @param inputStream 文件的输入流 |
| | | * @param entryName entryName |
| | | * @param filename 原始文件名 |
| | | * @param machineCode 机床代码 |
| | | * @throws IOException 异常 |
| | | */ |
| | | public void addInputStreamToZip(ZipOutputStream zipOut, InputStream inputStream, String entryName,String filename,String machineCode) |
| | | throws IOException { |
| | | // 创建新的 ZIP 条目 |
| | |
| | | */ |
| | | InputStream setAnnotations(InputStream inputStream,String filename,String machineCode) throws IOException { |
| | | Machine machine = this.machineService.getByCode(machineCode); |
| | | AnnotationProcessor annoProcessor = ProcessorHelper.getProcessor(machine.getControlSystem(),annoConfig); |
| | | AnnotationProcessor annoProcessor = annotationProcessorHelper.getProcessor(machine.getControlSystem()); |
| | | |
| | | AnnotationData annoData = new AnnotationData(); |
| | | annoData.setFilename(filename); |
| | |
| | | |
| | | AnnotationProperties annoProps = annoProcessor.getAnnotationProperties(); |
| | | |
| | | ByteArrayInputStream bais = new ByteArrayInputStream(IOUtils.toByteArray(inputStream)); |
| | | String statusLine = FileContentUtil.readLineAt(bais,annoProps.getStatusLineIndex()); |
| | | ByteArrayInputStream byteInsStream = new ByteArrayInputStream(IOUtils.toByteArray(inputStream)); |
| | | String statusLine = FileContentUtil.readLineAt(byteInsStream,annoProps.getStatusLineIndex()); |
| | | String text = programAnnotationService.removeAnnotation(machine.getControlSystem(),statusLine); |
| | | |
| | | if(AnnotationUtil.isStatusContent(text)){ |
| | |
| | | //没有按试切处理 |
| | | annoData.setProgramStatus(AnnotationUtil.SQ); |
| | | } |
| | | bais.reset(); |
| | | byteInsStream.reset(); |
| | | // |
| | | return annoProcessor.putAnnotation(annoData,bais); |
| | | return annoProcessor.putAnnotation(annoData,byteInsStream); |
| | | } |
| | | } |
| | | |