| | |
| | | import org.springblade.mdm.basesetting.machine.entity.Machine; |
| | | import org.springblade.mdm.basesetting.machine.service.MachineService; |
| | | import org.springblade.mdm.commons.contants.RegExpConstants; |
| | | import org.springblade.mdm.commons.service.MachineDirTranslator; |
| | | import org.springblade.mdm.commons.service.ParamService; |
| | | import org.springblade.mdm.gkw.programnode.vo.ProgramNameVO; |
| | | import org.springblade.mdm.gkw.task.entity.MachineBackTask; |
| | | import org.springblade.mdm.gkw.task.service.MachineBackTaskService; |
| | | import org.springblade.mdm.machinefile.entity.FileSendRecord; |
| | | import org.springblade.mdm.machinefile.entity.MachineFile; |
| | | import org.springblade.mdm.program.entity.ProgramOnMachine; |
| | |
| | | @Autowired |
| | | private AnnotationProcessorHelper annoProcessHelper; |
| | | @Autowired |
| | | private ProgramAnnotationService programAnnotationService; |
| | | |
| | | private MachineDirTranslator machineDirTranslator; |
| | | @Autowired |
| | | private MachineBackTaskService machineBackTaskService; |
| | | /** |
| | | * 文件合法性检查 |
| | | * @param machineFile |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void check(MachineFile machineFile,List<MachineFile> allFilesInDir,Machine machine) throws IOException { |
| | | |
| | | String srcFilepath = MachineFileService.getBasePath(machine,machineFile.getDirType())+ File.separator+machineFile.getName(); |
| | | String srcFilepath = machineDirTranslator.trans(MachineFileService.getBasePath(machine,machineFile.getDirType())+ File.separator+machineFile.getName()); |
| | | log.info("开始检查文件{}",srcFilepath); |
| | | Path checkFilePath = Paths.get(srcFilepath); |
| | | if(!checkFilePath.toFile().exists()){ |
| | |
| | | if(matchCount != progNameVO.getSegmentCount()){//文件段数缺失 |
| | | excepType = MachineFile.EXCEPTION_LOST_FILES; |
| | | }else{ |
| | | //检查是否匹配机床回传任务? |
| | | //检查是否匹配机床回传任务 |
| | | byteStream.reset(); |
| | | AnnotationProcessor annoProcessor = this.annoProcessHelper.getProcessor(machine.getControlSystem()); |
| | | AnnotationData annoData = annoProcessor.readAnnotationData(byteStream); |
| | | Optional<MachineBackTask> taskOpt = backTaskForFile(machineFile,annoData); |
| | | |
| | | //检查是否匹配下发记录的段数 |
| | | /* |
| | | String nameLikeStr; |
| | | if(StringUtils.isNotBlank(progNameVO.getLgPart())){ |
| | | nameLikeStr = prefix +"%P%"; |
| | |
| | | .eq(FileSendRecord::getMachineCode,machineFile.getMachineCode()) |
| | | .likeRight(FileSendRecord::getName,nameLikeStr).last("limit 1") |
| | | .orderByDesc(FileSendRecord::getCreateTime).oneOpt(); |
| | | |
| | | boolean matchSendRecord;//文件是否有下发记录 |
| | | if(optFile.isPresent()){ |
| | | matchSendRecord = true; |
| | | //确实下发过,比对总段数是否相同 |
| | | FileSendRecord sendFile = optFile.get(); |
| | | ProgramNameVO sendProgNameVO = ProgramFileNameParser.parseProgramName(sendFile.getName()); |
| | | if(progNameVO.getSegmentCount() != sendProgNameVO.getSegmentCount()){ |
| | | //段数不匹配下发记录 |
| | | excepType = MachineFile.EXCEPTION_NOT_MATCH_SEND_SEG_COUNT; |
| | | }else if(!StringUtils.equals(sendProgNameVO.getLgPart(),progNameVO.getLgPart())){ |
| | | excepType = MachineFile.EXCEPTION_NOT_MATCH_SEND_LG; |
| | | */ |
| | | //boolean matchSendRecord;//文件是否有下发记录 |
| | | if(taskOpt.isPresent()){ |
| | | //有任务,比对总段数是否相同 |
| | | MachineBackTask backTask = taskOpt.get(); |
| | | //FileSendRecord sendFile = optFile.get(); |
| | | //ProgramNameVO sendProgNameVO = ProgramFileNameParser.parseProgramName(sendFile.getName()); |
| | | if(!backTask.isProgramOnMachineTask() ){//工艺编制 |
| | | if(progNameVO.getSegmentCount() != backTask.getSegCount()) { |
| | | //段数不匹配下发记录 |
| | | excepType = MachineFile.EXCEPTION_NOT_MATCH_SEND_SEG_COUNT; |
| | | } |
| | | }else{ |
| | | //现场编程,检查更改单序号 |
| | | if(StringUtils.isNotBlank(backTask.getDeviationSerial()) && !StringUtils.equals(backTask.getDeviationSerial(),progNameVO.lgSerial())){ |
| | | excepType = MachineFile.EXCEPTION_NOT_MATCH_SEND_LG; |
| | | } |
| | | } |
| | | |
| | | }else{ |
| | | matchSendRecord = false; |
| | | excepType = MachineFile.EXCEPTION_NOT_MATCH_RECORD; |
| | | } |
| | | |
| | | /* |
| | | if(!matchSendRecord){//如果文件未下发过,查看是否有现场编程记录 |
| | | byteStream.reset(); |
| | | |
| | | String devSerial = null; |
| | | if(StringUtils.isNotBlank(progNameVO.getLgPart())){ |
| | | devSerial = progNameVO.getLgPart().substring(1); |
| | |
| | | } |
| | | |
| | | } |
| | | |
| | | */ |
| | | } |
| | | } |
| | | } |
| | |
| | | machineFileService.updateById(machineFile); |
| | | } |
| | | } |
| | | |
| | | Optional<MachineBackTask> backTaskForFile(MachineFile machineFile,AnnotationData annoData){ |
| | | ProgramNameVO progNameVO = ProgramFileNameParser.parseProgramName(machineFile.getName()); |
| | | |
| | | return machineBackTaskService.lambdaQuery() |
| | | .eq(MachineBackTask::getStatus,MachineBackTask.STATUS_PENDING) |
| | | .eq(MachineBackTask::getMachineCode,machineFile.getMachineCode()) |
| | | .eq(MachineBackTask::getProgramName,progNameVO.logicProgramName()) |
| | | .eq(progNameVO.lgSerial()!=null,MachineBackTask::getDeviation,annoData.getDeviation()) |
| | | .eq(progNameVO.lgSerial()!=null,MachineBackTask::getDeviationSerial,progNameVO.lgSerial()) |
| | | .last("limit 1").oneOpt(); |
| | | } |
| | | } |