| | |
| | | import org.springblade.mdm.basesetting.machine.vo.MachineSaveVO; |
| | | import org.springblade.mdm.basesetting.machine.vo.MachineVO; |
| | | import org.springblade.mdm.basesetting.producedivision.service.MdmDeptService; |
| | | import org.springblade.mdm.commons.service.MachineDirTranslator; |
| | | import org.springblade.mdm.commons.service.ParamService; |
| | | import org.springblade.mdm.machinefile.entity.MachineFile; |
| | | import org.springblade.mdm.machinefile.filewatch.DynamicDirectoryWatcher; |
| | |
| | | import java.nio.file.Path; |
| | | import java.nio.file.Paths; |
| | | import java.util.List; |
| | | import java.util.Optional; |
| | | |
| | | @Service |
| | | public class MachineService extends BizServiceImpl<MachineMapper, Machine> { |
| | |
| | | private DynamicDirectoryWatcher dynamicDirectoryWatcher; |
| | | @Autowired |
| | | private ParamService paramService; |
| | | @Autowired |
| | | private MachineDirTranslator machineDirTranslator; |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void saveMachine(MachineSaveVO vo) throws IOException { |
| | | checkMachine(vo); |
| | |
| | | void makeMachineDirs(Machine machine) throws IOException { |
| | | Path dir; |
| | | if(StringUtils.isNotBlank(machine.getProgSendDir())){ |
| | | createDirIsNotExists(machine.getProgSendDir()); |
| | | createDirIsNotExists(machineDirTranslator.trans(machine.getProgSendDir())); |
| | | } |
| | | |
| | | if(StringUtils.isNotBlank(machine.getProgReceiveDir())){ |
| | | createDirIsNotExists(machine.getProgReceiveDir()); |
| | | if(StringUtils.isNotBlank(machineDirTranslator.trans(machine.getProgReceiveDir()))){ |
| | | createDirIsNotExists(machineDirTranslator.trans(machine.getProgReceiveDir())); |
| | | } |
| | | |
| | | if(StringUtils.isNotBlank(machine.getProgTempDir())){ |
| | | createDirIsNotExists(machine.getProgTempDir()); |
| | | if(StringUtils.isNotBlank(machineDirTranslator.trans(machine.getProgTempDir()))){ |
| | | createDirIsNotExists(machineDirTranslator.trans(machine.getProgTempDir())); |
| | | } |
| | | } |
| | | |
| | |
| | | ProgramAnnotationService annoService = SpringUtil.getBean(ProgramAnnotationService.class); |
| | | |
| | | if(StringUtils.isNotBlank(machine.getProgSendDir())) { |
| | | |
| | | String sendDir = machineDirTranslator.trans(machine.getProgSendDir()); |
| | | |
| | | WatchInfo watchInfoSend = new WatchInfo(); |
| | | watchInfoSend.setMachine(machine); |
| | | watchInfoSend.setDirType(MachineFile.DIR_TYPE_SEND); |
| | | watchInfoSend.setPath(machine.getProgSendDir()); |
| | | watchInfoSend.setPath(sendDir); |
| | | |
| | | if(!dynamicDirectoryWatcher.containsPath(Paths.get(machine.getProgSendDir()))) { |
| | | dynamicDirectoryWatcher.addDirectory(Paths.get(machine.getProgSendDir()), |
| | | Path path = Paths.get(sendDir); |
| | | if(!dynamicDirectoryWatcher.containsPath(path)) { |
| | | dynamicDirectoryWatcher.addDirectory(path, |
| | | new MachineFileChangeListener(machineFileService, |
| | | annoService, |
| | | watchInfoSend)); |
| | |
| | | } |
| | | |
| | | if(StringUtils.isNotBlank(machine.getProgReceiveDir())) { |
| | | |
| | | String recDir = machineDirTranslator.trans(machine.getProgReceiveDir()); |
| | | |
| | | WatchInfo watchInfoRec = new WatchInfo(); |
| | | watchInfoRec.setMachine(machine); |
| | | watchInfoRec.setDirType(MachineFile.DIR_TYPE_REC); |
| | | watchInfoRec.setPath(machine.getProgReceiveDir()); |
| | | if(!dynamicDirectoryWatcher.containsPath(Paths.get(machine.getProgReceiveDir()))) { |
| | | dynamicDirectoryWatcher.addDirectory(Paths.get(machine.getProgReceiveDir()), |
| | | watchInfoRec.setPath(recDir); |
| | | Path path = Paths.get(recDir); |
| | | if(!dynamicDirectoryWatcher.containsPath(path)) { |
| | | dynamicDirectoryWatcher.addDirectory(path, |
| | | new MachineFileChangeListener(machineFileService, |
| | | annoService, |
| | | watchInfoRec)); |
| | |
| | | } |
| | | |
| | | if(StringUtils.isNotBlank(machine.getProgTempDir())) { |
| | | String tempDir = machineDirTranslator.trans(machine.getProgTempDir()); |
| | | WatchInfo watchInfoTemp = new WatchInfo(); |
| | | watchInfoTemp.setMachine(machine); |
| | | watchInfoTemp.setDirType(MachineFile.DIR_TYPE_TEMP); |
| | | watchInfoTemp.setPath(machine.getProgTempDir()); |
| | | if(!dynamicDirectoryWatcher.containsPath(Paths.get(machine.getProgTempDir()))) { |
| | | dynamicDirectoryWatcher.addDirectory(Paths.get(machine.getProgTempDir()), |
| | | watchInfoTemp.setPath(tempDir); |
| | | Path path = Paths.get(machine.getProgTempDir()); |
| | | if(!dynamicDirectoryWatcher.containsPath(path)) { |
| | | dynamicDirectoryWatcher.addDirectory(path, |
| | | new MachineFileChangeListener(machineFileService, |
| | | annoService, |
| | | watchInfoTemp)); |
| | |
| | | return null; |
| | | } |
| | | //廿æ«å°¾æ¬å·(åé£ç§) ,æ«å°¾è·¯å¾åé符 |
| | | String tempPath = StringUtils.removeEnd(StringUtils.removeEnd(StringUtils.removeEnd(sendPathLine,")"),"/"),"\\"); |
| | | //廿å2ä½å¯è½ç注é(*-)ã |
| | | String sendPath = escapeSqlWildcard(StringUtils.trim(StringUtils.substring(tempPath,2))); |
| | | String oriPath = StringUtils.removeEnd(StringUtils.removeEnd(StringUtils.removeEnd(sendPathLine,")"),"/"),"\\"); |
| | | |
| | | List<Machine> machines = lambdaQuery().eq(Machine::getStatus,Machine.STATUS_ENABLE).like(Machine::getProgSendDir,sendPath).list(); |
| | | if(machines.isEmpty()){ |
| | | return null; |
| | | }else{ |
| | | return machines.get(0); |
| | | } |
| | | String tempPathRepl1 = StringUtils.replace(oriPath,"/","\\");//åææ çæ¬çè·¯å¾ |
| | | String tempPathRepl2 = StringUtils.replace(oriPath,"\\","/");//æ£ææ çæ¬çè·¯å¾ |
| | | |
| | | //廿å2ä½å¯è½ç注é(*-)ã |
| | | String sendPath1 = escapeSqlWildcard(StringUtils.trim(StringUtils.substring(tempPathRepl1,2))); |
| | | String sendPath2 = escapeSqlWildcard(StringUtils.trim(StringUtils.substring(tempPathRepl2,2))); |
| | | |
| | | Optional<Machine> machineOpt = lambdaQuery().eq(Machine::getStatus,Machine.STATUS_ENABLE).and(w -> { |
| | | w.like(Machine::getProgSendDir,sendPath1).or().like(Machine::getProgSendDir,sendPath2); |
| | | }).last("limit 1").oneOpt(); |
| | | |
| | | return machineOpt.orElse(null); |
| | | } |
| | | |
| | | /** |
| | |
| | | */ |
| | | public static final Pattern PROGRAM_FILE_PATTERN = Pattern.compile("^([\\u4e00-\\u9fa5\\w\\-]+)-([0-9a-zA-Z]+)-([\\u4e00-\\u9fa5a-zA-Z0-9]+)-(\\d+)-(\\d+)-?([Pp]\\d+)?(\\.[a-zA-Z]+)?$"); |
| | | |
| | | //public static final Pattern PROGRAM_PACKAGE_PATTERN = Pattern.compile("[\\w\\-]+\\-\\w+\\-\\w+"); |
| | | |
| | | public static final Pattern PROGRAM_PACKAGE_PATTERN = Pattern.compile("([\\u4e00-\\u9fa5\\w\\-]+)-[0-9a-zA-Z]+-[\\u4e00-\\u9fa5a-zA-Z0-9]+"); |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.springblade.mdm.commons.service; |
| | | |
| | | import lombok.Data; |
| | | import org.springframework.boot.context.properties.ConfigurationProperties; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | @Component |
| | | @ConfigurationProperties(prefix = "dirtrans") |
| | | @Data |
| | | public class DirTransProperties { |
| | | private String oriDirPrefix; |
| | | private String targetDirPrefix; |
| | | |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.springblade.mdm.commons.service; |
| | | |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | /** |
| | | * æºåºè·¯å¾è½¬æ¢å¨ï¼ä»Zçè¿ç§ç®å½è½¬æ¢ä¸ºç½ç»ç®å½æ ¼å¼å
¥:\\192.168.233.2\Workshop |
| | | */ |
| | | @Component |
| | | public class MachineDirTranslator { |
| | | @Autowired |
| | | private DirTransProperties transProperties; |
| | | |
| | | public String trans(String path){ |
| | | if(StringUtils.isBlank(transProperties.getTargetDirPrefix()) || !StringUtils.startsWithIgnoreCase(path,transProperties.getOriDirPrefix())){ |
| | | return path; |
| | | } |
| | | |
| | | String finalDir = transProperties.getTargetDirPrefix()+StringUtils.removeStartIgnoreCase(path,transProperties.getOriDirPrefix()); |
| | | return finalDir; |
| | | } |
| | | } |
| | |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springblade.mdm.basesetting.machine.service.MachineService; |
| | | import org.springblade.mdm.basesetting.machine.entity.Machine; |
| | | import org.springblade.mdm.commons.service.MachineDirTranslator; |
| | | import org.springblade.mdm.commons.service.ParamService; |
| | | import org.springblade.mdm.flow.service.TaskDispatchService; |
| | | import org.springblade.mdm.machinefile.entity.MachineFile; |
| | |
| | | private final ProgramAnnotationService annotationService; |
| | | private final MachineFileScanService machineFileScanService; |
| | | private final TaskDispatchService taskDispatchService; |
| | | |
| | | //@Value("${task.file_scan_on_start:true}") |
| | | //@Value("${task.fileScanOnStart:true}") |
| | | //public boolean fileScanOnStart; |
| | | private final MachineDirTranslator dirTranslator; |
| | | private final TaskPropertieBean taskPropertieBean; |
| | | @PostConstruct |
| | | public void init() { |
| | |
| | | log.info("å·¥æ§ç½å¯å¨æä»¶çæ§"); |
| | | initMachineDirMonitor(); |
| | | }else{ |
| | | |
| | | //æ¶å¯ç½ |
| | | taskDispatchService.resetDrawingNos(); |
| | | } |
| | |
| | | machineList.forEach(m -> { |
| | | addToWatchDirList(monitorInfoList,m); |
| | | }); |
| | | |
| | | for (WatchInfo info : monitorInfoList) { |
| | | try { |
| | | Path dirPath = Paths.get(info.getPath()); |
| | |
| | | String dir; |
| | | //å å
¥sendæä»¶å¤¹ |
| | | if (StringUtils.isNotEmpty(machine.getProgSendDir())) { |
| | | dir = StringUtils.removeEnd(StringUtils.removeEnd(machine.getProgSendDir(), "/"), "\\"); |
| | | //dir = dirTranslator.trans(StringUtils.removeEnd(StringUtils.removeEnd(machine.getProgSendDir(), "/"), "\\")); |
| | | dir = fixMachineDir(machine.getProgSendDir()); |
| | | WatchInfo watchInfo = new WatchInfo(); |
| | | watchInfo.setMachine(machine); |
| | | watchInfo.setDirType(MachineFile.DIR_TYPE_SEND); |
| | |
| | | |
| | | //å å
¥recæä»¶å¤¹ |
| | | if (StringUtils.isNotEmpty(machine.getProgReceiveDir())) { |
| | | dir = StringUtils.removeEnd(StringUtils.removeEnd(machine.getProgReceiveDir(), "/"), "\\"); |
| | | //dir = StringUtils.removeEnd(StringUtils.removeEnd(machine.getProgReceiveDir(), "/"), "\\"); |
| | | dir = fixMachineDir(machine.getProgReceiveDir()); |
| | | WatchInfo watchInfo = new WatchInfo(); |
| | | watchInfo.setMachine(machine); |
| | | watchInfo.setDirType(MachineFile.DIR_TYPE_REC); |
| | |
| | | |
| | | //å å
¥tempæä»¶å¤¹ |
| | | if (StringUtils.isNotEmpty(machine.getProgTempDir())) { |
| | | dir = StringUtils.removeEnd(StringUtils.removeEnd(machine.getProgTempDir(), "/"), "\\"); |
| | | //dir = StringUtils.removeEnd(StringUtils.removeEnd(machine.getProgTempDir(), "/"), "\\"); |
| | | dir = fixMachineDir(machine.getProgTempDir()); |
| | | WatchInfo watchInfo = new WatchInfo(); |
| | | watchInfo.setMachine(machine); |
| | | watchInfo.setDirType(MachineFile.DIR_TYPE_TEMP); |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * ç¿»è¯å
±äº«æä»¶å¤¹è·¯å¾å° æ åç½ç»è·¯å¾ï¼å»ææ«å°¾è·¯å¾åå²ä¸ |
| | | * @param dirpath åå§è·¯å¾ |
| | | * @return 转æ¢åçè·¯å¾ |
| | | */ |
| | | String fixMachineDir(String dirpath){ |
| | | return dirTranslator.trans(StringUtils.removeEnd(StringUtils.removeEnd(dirpath, "/"), "\\")); |
| | | } |
| | | |
| | | FileWatcherService.FileChangeListener getListener(WatchInfo info) { |
| | | return new MachineFileChangeListener(machineFileService,annotationService,info); |
| | | } |
| | |
| | | import jakarta.annotation.PreDestroy; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springblade.mdm.machinefile.filewatch.DirectorLockService; |
| | | import org.springblade.mdm.machinefile.filewatch.FileWatcherService; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | @AllArgsConstructor |
| | | @Component |
| | | public class ShutdownHook { |
| | | private final DirectorLockService directorLockService; |
| | | private final FileWatcherService fileWatcherService; |
| | | @PreDestroy |
| | | public void onExit() { |
| | | System.out.println("æ§è¡éåºåæ¸
çæä½..."); |
| | | // 1. å
³éæä»¶çæ§ |
| | | // 2. éæ¾èµæº |
| | | // 3. ä¿åç¶æ |
| | | // 4. éç¥å
¶ä»æå¡ |
| | | directorLockService.releaseLock(); |
| | | |
| | | fileWatcherService.shutdown(); |
| | | } |
| | | } |
| | |
| | | import io.swagger.v3.oas.annotations.Parameter; |
| | | import io.swagger.v3.oas.annotations.tags.Tag; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.flowable.engine.HistoryService; |
| | | import org.flowable.engine.TaskService; |
| | | import org.flowable.task.api.history.HistoricTaskInstance; |
| | | import org.springblade.core.mp.support.Condition; |
| | | import org.springblade.core.mp.support.Query; |
| | | import org.springblade.core.tool.api.R; |
| | |
| | | import org.springblade.mdm.basesetting.producedivision.service.MdmUserService; |
| | | import org.springblade.mdm.flow.service.DoneQueryService; |
| | | import org.springblade.mdm.flow.service.FlowBusinessService; |
| | | import org.springblade.mdm.flow.service.FlowCommonService; |
| | | import org.springblade.mdm.flow.service.FlowTransferService; |
| | | import org.springblade.mdm.flow.vo.DoneQueryVO; |
| | | import org.springblade.mdm.flow.vo.FlowVO; |
| | | import org.springblade.mdm.flow.vo.TodoQueryVO; |
| | | import org.springblade.mdm.gkw.programnode.vo.ProgramNodeVO; |
| | | import org.springblade.system.feign.IUserSearchClient; |
| | | import org.springblade.system.pojo.entity.User; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.format.annotation.DateTimeFormat; |
| | | import org.springframework.web.bind.annotation.*; |
| | |
| | | @Autowired |
| | | private FlowBusinessService businessService; |
| | | @Autowired |
| | | private IUserSearchClient userSearchClient; |
| | | |
| | | @Autowired |
| | | private FlowTransferService flowTransferService; |
| | | @Autowired |
| | | private FlowCommonService flowCommonService; |
| | | |
| | | @Autowired |
| | | private DoneQueryService doneQueryService; |
| | | /** |
| | |
| | | package org.springblade.mdm.flow.excution.append; |
| | | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.flowable.engine.RuntimeService; |
| | | import org.flowable.engine.delegate.DelegateExecution; |
| | | import org.springblade.core.tool.utils.DateUtil; |
| | | import org.springblade.mdm.flow.entity.FlowProgramFile; |
| | |
| | | tempProgramNode.setName(newFlowFile.getName()); |
| | | |
| | | tempProgramNode.setParentId(tempPkgNode.getId()); |
| | | tempProgramNode.setParentIds(tempPkgNode.getParentIds()+","+tempPkgNode.getId()); |
| | | tempProgramNode.setParentIds(tempPkgNode.subNodeParentIds()); |
| | | tempProgramNode.setProcessInstanceId(props.getProcessInstanceId()); |
| | | tempProgramNode.setFlowProgramFileId(newFlowFile.getId()); |
| | | |
| | |
| | | EntityUtil.clearBaseProperties(newPkgNode); |
| | | newPkgNode.setIsLastEdition(1); |
| | | newPkgNode.upgradeVersionNumber(); |
| | | |
| | | nodeService.save(newPkgNode); |
| | | |
| | | copyNonProgramNodes(pkgNode,newPkgNode); |
| | | |
| | | //copyNonProgramNodes(pkgNode,newPkgNode); |
| | | addNewProgramNode(newPkgNode,props.getProcessInstanceId()); |
| | | |
| | | log.info("ä¸´æ¶æ´æ¹ååä¼ Listener宿"); |
| | |
| | | * @param oriPkgNode å¾
åºåèç¹ |
| | | * @param cureNode åºåèç¹ |
| | | */ |
| | | /* |
| | | void copyNonProgramNodes(NcNode oriPkgNode,NcNode cureNode){ |
| | | //å¤çç¨åºå
ä¸å±çç¨åºèç¹1 |
| | | List<NcNode> oriProgramNodes = nodeService.lambdaQuery().eq(NcNode::getParentId,oriPkgNode.getId()).list(); |
| | |
| | | } |
| | | |
| | | } |
| | | } |
| | | }*/ |
| | | |
| | | /** |
| | | * å å
¥æ°çç¨åºæä»¶èç¹ |
| | |
| | | oldProgramNode.setIsLastEdition(0); |
| | | //å½ååºåç¨åºå
åä¸çâå
¶ä»æä»¶âéç¨åºæä»¶ãä¸è®¾ç½®ä¸ºèçæ¬ï¼ç´æ¥æªå°åºåæ ä¸,两个ç½ç»ä¹é´åªäº¤æ¢ç¨åºæä»¶ï¼å
¶ä»æä»¶åªè½ä¿ç |
| | | //å
¶ä»æä»¶ï¼éè¦å¤å¶å°æ°å»ºçåºåèç¹ä¸ï¼ç¨åºæä»¶ä¸å¤å¶ï¼ |
| | | /* |
| | | pfile = flowProgramFileService.getById(oldProgramNode.getFlowProgramFileId()); |
| | | if(!pfile.isProgram()) { |
| | | NcNode newFileNode = new NcNode(); |
| | |
| | | newFileNode.setIsLastEdition(1); |
| | | nodeService.save(newFileNode); |
| | | } |
| | | |
| | | */ |
| | | } |
| | | nodeService.updateBatchById(oriProgramNodes); |
| | | } |
| | | |
| | | /** |
| | | * å å
¥æ°çç¨åºèç¹ |
| | | * @param cureNode åºåèç¹ |
| | | * @param processInstanceId æµç¨å®ä¾id |
| | | * @throws IOException |
| | | */ |
| | | void addNewProgramNode(NcNode cureNode,String processInstanceId) throws IOException { |
| | | Machine machine = machineService.getByCode(cureNode.getMachineCode()); |
| | | List<DictBiz> annoDicts = programAnnotationService.getAnnotionDictList(); |
| | |
| | | import org.flowable.engine.RuntimeService; |
| | | import org.flowable.engine.runtime.ProcessInstance; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | import org.springblade.mdm.basesetting.machine.service.MachineService; |
| | | import org.springblade.mdm.basesetting.producedivision.service.ProduceDivisionService; |
| | | import org.springblade.mdm.flow.constants.FlowConstant; |
| | | import org.springblade.mdm.flow.constants.FlowVariableConstant; |
| | | 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.springblade.mdm.utils.EntityUtil; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | |
| | | private final RuntimeService runtimeService; |
| | | |
| | | 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; |
| | | |
| | | /** |
| | |
| | | vars.put(FlowConstant.NODE_ID,programPackage.getId()); |
| | | |
| | | flowCommonService.putFlowVariablesByNode(vars,programPackage); |
| | | /* |
| | | vars.put(FlowVariableContants.MACHINE_CODE,programPackage.getMachineCode()); |
| | | |
| | | //æºåºåå· |
| | | Machine machine = machineService.getByCode(programPackage.getMachineCode()); |
| | | if(machine != null) { |
| | | vars.put(FlowVariableContants.MACHINE_MODE,machine.getName()); |
| | | } |
| | | |
| | | String workshop = nodeDeptQueryService.getWorkshopNameByMachineCode(programPackage.getMachineCode()); |
| | | vars.put(FlowVariableContants.WORKSHOP,workshop); |
| | | |
| | | vars.put(FlowContants.NODE_ID, Func.toStr(nodeId)); |
| | | vars.put(FlowVariableContants.PROCESS_NO,programPackage.getProcessNo()); |
| | | vars.put(FlowVariableContants.PROCESS_NAME,programPackage.getProcessName()); |
| | | vars.put(FlowVariableContants.PROCESS_EDITION,programPackage.getProcessEdition()); |
| | | vars.put(FlowVariableContants.CRAFT_EDITION, programPackage.getCraftEdition()); |
| | | vars.put(FlowVariableContants.DRAWING_NO,programPackage.getDrawingNo()); |
| | | vars.put(FlowVariableContants.DRAWING_NO_EDITION,programPackage.getDrawingNoEdition()); |
| | | |
| | | vars.put(FlowVariableContants.PRODUCT_MODEL,programPackage.getProductModel()); |
| | | vars.put(FlowVariableContants.PROGRAM_PACKAGE_NAME,programPackage.getName()); |
| | | */ |
| | | |
| | | flowCommonService.putDefaultAssignees(vars,programPackage.getDrawingNo(),null); |
| | | vars.put(FlowVariableConstant.ASSIGNEE,vars.get(FlowVariableConstant.PROGRAMMER)); |
| | | |
| | | identityService.setAuthenticatedUserId(String.valueOf(AuthUtil.getUserId()));//设置æµç¨å起人 |
| | | |
| | | vars.put(FlowVariableConstant.LAST_STEP_USER_NICKNAME, AuthUtil.getNickName()); |
| | | |
| | | |
| | | if(programPackage.getDeviation() != null) { |
| | | vars.put(FlowVariableConstant.MY_PROCESS_NAME, "ä¸´æ¶æ´æ¹ååä¼ "); |
| | |
| | | } |
| | | this.flowProgramFileService.saveBatch(fileList); |
| | | |
| | | addPreviousOtherFiles(programPackage.getId(),inst.getProcessInstanceId()); |
| | | |
| | | log.info("å¯å¨åºåæµç¨å®æï¼å®ä¾id={}", inst.getId()); |
| | | } |
| | | |
| | | /** |
| | | * å°ç¨åºæç
§æºå¨ä»£ç åç» |
| | | * @param ncProgramIdList |
| | | * @return |
| | | * å¤å¶è¯åé¶æ®µçå
¶ä»æä»¶ç»åºåæµç¨ |
| | | * @param previousNodeId è¯åé¶æ®µçèç¹id |
| | | * @param newProcessInstanceId æ°çåºåæµç¨å®ä¾id |
| | | */ |
| | | /* |
| | | Map<String,List<NcProgram>> groupProgramsByMachineCode(List<Long> ncProgramIdList){ |
| | | List<NcProgram> programs = ncProgramService.listByIds(ncProgramIdList); |
| | | return programs.stream().collect(Collectors.groupingBy(NcProgram::getMachineCode)); |
| | | }*/ |
| | | void addPreviousOtherFiles(Long previousNodeId,String newProcessInstanceId) { |
| | | List<NcNode> previousFileNodes = ncNodeService.getProgramFilesByPackageId(previousNodeId); |
| | | for(NcNode fileNode : previousFileNodes){ |
| | | |
| | | FlowProgramFile progFile = flowProgramFileService.getById(fileNode.getFlowProgramFileId()); |
| | | if(!progFile.isProgram()){ |
| | | FlowProgramFile newProgFile = new FlowProgramFile(); |
| | | BeanUtils.copyProperties(progFile,newProgFile); |
| | | EntityUtil.clearBaseProperties(newProgFile); |
| | | newProgFile.setProcessInstanceId(newProcessInstanceId); |
| | | |
| | | flowProgramFileService.save(newProgFile); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | package org.springblade.mdm.gkw.programnode.vo; |
| | | |
| | | import com.alibaba.excel.util.StringUtils; |
| | | import lombok.Data; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | |
| | | /** |
| | | * è£
è½½ç¨åºåç»æ |
| | |
| | | } |
| | | |
| | | /** |
| | | * è·åä¸´æ¶æ´æ¹ååºå· |
| | | * @return æ´æ¹ååºå· |
| | | */ |
| | | public String lgSerial(){ |
| | | if(StringUtils.startsWithIgnoreCase(lgPart,"P")){ |
| | | return lgPart.substring(1); |
| | | }else{ |
| | | return null; |
| | | } |
| | | } |
| | | /** |
| | | * æä»¶åæ¯å¦ææ |
| | | * @return |
| | | */ |
| | |
| | | */ |
| | | private String deviation; |
| | | /** |
| | | * ä¸´æ¶æ´æ¹ååºå· |
| | | */ |
| | | private String deviationSerial; |
| | | /** |
| | | * ç¨åºæ»æ®µæ°/ç°åºç¼å¶ç=0 |
| | | */ |
| | | private int segCount; |
| | |
| | | private int taskType; |
| | | |
| | | private Date finishTime; |
| | | |
| | | public boolean isProgramOnMachineTask(){ |
| | | return taskType == TASK_TYPE_ON_MACHINE; |
| | | } |
| | | } |
| | |
| | | <!--æä»¶è®°å½æ¥è¯¢--> |
| | | |
| | | <select id="pageQuery" resultType="org.springblade.mdm.gkw.task.vo.MachineBackTaskVO"> |
| | | select t.id,t.program_name,t.machine_code,t.task_type,t.deviation,t.seg_count,t.finish_time,t.create_time,t.status,t.update_time,u.name create_user_name |
| | | select t.id,t.program_name,t.machine_code,t.task_type,t.deviation,t.deviation_serial,t.seg_count,t.finish_time,t.create_time,t.status,t.update_time,u.name create_user_name |
| | | from mdm_machine_back_task t left join blade_user u on t.create_user=u.id |
| | | <where> |
| | | t.is_deleted=0 |
| | |
| | | @Schema(description = "æºåºç¼å·") |
| | | private String machineCode; |
| | | |
| | | @Schema(description = "æ´æ¹åå·") |
| | | private String deviation; |
| | | @Schema(description = "æ´æ¹ååºå·") |
| | | private String deviationSerial; |
| | | |
| | | @Schema(description = "ä»»å¡ç±»å") |
| | | private int taskType; |
| | | |
| | | @Schema(description = "ç¨åºæ®µæ°") |
| | | private int segCount; |
| | | } |
| | |
| | | } |
| | | |
| | | @PostMapping("/change-file-name") |
| | | @Operation(summary = "ä¿åæºåºæä»¶", description = "ä¿åæºåºæä»¶å°ç£ç") |
| | | @Operation(summary = "SENDæä»¶éå½å", description = "SENDæä»¶éå½å") |
| | | public R<Void> changeFileName(Long id,String name) { |
| | | try { |
| | | machineFileService.changeName(id,name); |
| | | } catch (Exception e) { |
| | | log.error(e.getMessage()); |
| | | log.error("æä»¶éå½åå¼å¸¸",e); |
| | | return R.fail(e.getMessage()); |
| | | } |
| | | return R.success(); |
| | |
| | | private String programStatus; |
| | | |
| | | /** |
| | | * ä¸´æ¶æ´æ¹åå· |
| | | * ä¸´æ¶æ´æ¹åå·,éæä¹
å屿§ |
| | | */ |
| | | //private String deviation; |
| | | transient private String deviation; |
| | | |
| | | /** |
| | | * ä¸´æ¶æ´æ¹ååºå·,éæä¹
å屿§ |
| | | */ |
| | | transient private String deviationSerial; |
| | | /** |
| | | * çææä»¶å¤§å°çæ¾ç¤ºææ¬ |
| | | * @return æ¾ç¤ºææ¬ |
| | |
| | | */ |
| | | public static boolean isFileComplete(Path file) throws IOException, InterruptedException { |
| | | long initialSize = Files.size(file); |
| | | Thread.sleep(3000); // çå¾
1ç§ |
| | | Thread.sleep(1000); // çå¾
1ç§ |
| | | long currentSize = Files.size(file); |
| | | return initialSize == currentSize; |
| | | } |
| | |
| | | private final ExecutorService executor = Executors.newCachedThreadPool(); |
| | | private final Map<Path, WatchService> watchServices = new HashMap<>(); |
| | | private final Map<Path, FileChangeListener> listeners = new HashMap<>(); |
| | | private final Map<Path, FileState> fileStatesOld = new HashMap<>(); |
| | | |
| | | Cache<Path, FileState> fileStates = CacheBuilder.newBuilder() |
| | | .maximumSize(10) // æå¤§å®¹é3 |
| | | .build(); |
| | |
| | | |
| | | FileState currentState = fileStates.getIfPresent(fullPath); |
| | | currentState = (currentState == null) ? FileState.STABLE : currentState; |
| | | |
| | | //FileState currentState = fileStates.getOrDefault(fullPath, FileState.STABLE); |
| | | |
| | | FileChangeListener currentListener = listeners.get(directory); |
| | | if (currentListener == null) break; |
| | |
| | | package org.springblade.mdm.machinefile.filewatch; |
| | | |
| | | import com.alibaba.excel.util.StringUtils; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springblade.core.tool.utils.SpringUtil; |
| | | import org.springblade.mdm.basesetting.machine.entity.Machine; |
| | |
| | | import org.springblade.mdm.machinefile.service.MachineFileService; |
| | | import org.springblade.mdm.program.service.ProgramAnnotationService; |
| | | |
| | | import java.io.FileInputStream; |
| | | import java.io.IOException; |
| | | import java.nio.file.Path; |
| | | import java.util.Date; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | | |
| | | @Slf4j |
| | | public class MachineFileChangeListener implements FileWatcherService.FileChangeListener{ |
| | | |
| | | |
| | | private final MachineFileService machineFileService; |
| | | ProgramAnnotationService programAnnotationService; |
| | | private final Machine machine; |
| | | private final String dirType; |
| | | |
| | | |
| | | |
| | | |
| | | public MachineFileChangeListener(MachineFileService aMachineFileService, ProgramAnnotationService annotationService, WatchInfo info) { |
| | |
| | | |
| | | try { |
| | | log.info("æä»¶å建{},mcode={},dieType={}",filePath,machine.getCode(),dirType); |
| | | if(FileLockChecker.isFileComplete(filePath)){ |
| | | |
| | | if(this.waitingForFileComplete(filePath)){ |
| | | log.info("{}ä¼ è¾å®æCreate,å¼å§å¤ç",filePath); |
| | | MachineFileScanService fileScanService = SpringUtil.getBean(MachineFileScanService.class); |
| | | MachineFile mf = fileScanService.readFileToMachineFile(filePath,this.machine,this.dirType,programAnnotationService.getAnnotionDictList()); |
| | | MachineFile mf = fileScanService.readFileToMachineFile(filePath,this.machine,this.dirType); |
| | | machineFileService.refreshFileData(mf); |
| | | }else{ |
| | | //0928æ°å¢ï¼æä»¶ä¼ è¾æ²¡å®æ |
| | | log.info("{}ä¼ è¾æªå®æCreated,ä¸å¤ç",filePath); |
| | | } |
| | | saveMonitor(filePath,FileMonitorRecord.EVENT_CREATE); |
| | | } catch (InterruptedException e) { |
| | |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * çå¾
æä»¶ä¼ è¾å®æï¼æ£æµ20æ¬¡ï¼ |
| | | * @param filePath æä»¶Path对象 |
| | | * @return æç»æ¯å¦ä¼ è¾å®æ |
| | | * @throws IOException æä»¶æ£æµé®é¢ |
| | | * @throws InterruptedException 线ç¨çå¾
å¯è½å¼åçå¼å¸¸ |
| | | */ |
| | | boolean waitingForFileComplete(Path filePath) throws IOException, InterruptedException { |
| | | final int maxWaitTimes = 20; //æä»¶ä¼ è¾å®ææ£æµæ¬¡æ° |
| | | boolean isCompleted = false; |
| | | for(int i=0;i<maxWaitTimes;i++){ |
| | | isCompleted = FileLockChecker.isFileComplete(filePath); |
| | | if(isCompleted){ |
| | | break; |
| | | } |
| | | } |
| | | return isCompleted; |
| | | } |
| | | |
| | | @Override |
| | | public void onFileModified(Path filePath) { |
| | | //æä»¶ä¿®æ¹ |
| | | log.info("æä»¶ä¿®æ¹:{}",filePath); |
| | | try { |
| | | if(FileLockChecker.isFileComplete(filePath)){ |
| | | log.info("æä»¶ä¼ è¾å®æ{}",filePath); |
| | | if(waitingForFileComplete(filePath)){ |
| | | log.info("æä»¶ä¼ è¾å®æModify{}",filePath); |
| | | MachineFileScanService fileScanService = SpringUtil.getBean(MachineFileScanService.class); |
| | | MachineFile mf = fileScanService.readFileToMachineFile(filePath,this.machine,this.dirType,programAnnotationService.getAnnotionDictList()); |
| | | MachineFile mf = fileScanService.readFileToMachineFile(filePath,this.machine,this.dirType); |
| | | machineFileService.refreshFileData(mf); |
| | | }else{ |
| | | log.warn("æä»¶ä¼ è¾ä¸ï¼åç»åæä½{}",filePath); |
| | |
| | | import java.util.Optional; |
| | | |
| | | /** |
| | | * åºåæµç¨æ§è¡å®æåï¼éè¦å¤ççäºä»¶ï¼å
¥åºmesåæ¥è¡¨ |
| | | * è§æ
åµå°å·²ç»å¯¼åºçç°åºç¼ç¨æä»¶ï¼ä¿åå°PROGRAMæä»¶å¤¹ |
| | | */ |
| | | @Slf4j |
| | | @Component |
| | |
| | | --> |
| | | <!--æºåºåä¼ ç¨åºå¤çå页--> |
| | | <select id="handlePageQuery" resultType="org.springblade.mdm.machinefile.vo.MachineAcceptedFileVO"> |
| | | select f.id,f.name,f.oss_name,f.create_time,m.code machine_code, m.name machine_name,f.status,f.create_time,mf.program_status,mf.file_create_time,f.export_time,f.create_time |
| | | select f.id,f.name,f.oss_name,m.code machine_code, m.name machine_name,f.status,f.create_time,mf.program_status,mf.file_create_time,f.export_time,f.create_time |
| | | from mdm_machine_accepted_file f |
| | | left join mdm_machine_file mf on f.machine_file_id=mf.id |
| | | left join mdm_machine m on mf.machine_code=m.code |
| | |
| | | and m.confirm_time$lt;#{query.confirmTimeEnd} |
| | | </if> |
| | | </where> |
| | | order by f.export_time desc,f.create_time desc |
| | | </select> |
| | | |
| | | |
| | |
| | | */ |
| | | IPage<MachineFile> exceptionFilePageQuery(IPage<Object> page,@Param("query") MachineFileExceptionQueryVO query); |
| | | |
| | | /** |
| | | * å 餿 ç¨æä»¶å éè·¯ |
| | | */ |
| | | void deleteNotUseRecords(); |
| | | } |
| | |
| | | <result column="is_deleted" property="isDeleted"/> |
| | | </resultMap> |
| | | |
| | | <!--å 餿²¡æå¼ç¨çï¼ä¸æ 记为å é¤çæä»¶è®°å½--> |
| | | <delete id="deleteNotUseRecords"> |
| | | delete from mdm_machine_file_change_his where machine_file_id in (select id mdm_machine_file where id not in (select machine_file_id from mdm_machine_accepted_file) and status=4); |
| | | delete from mdm_machine_file where id not in (select machine_file_id from mdm_machine_accepted_file) and status=4; |
| | | </delete> |
| | | |
| | | <!--å¾
æ¥æ¶æºåºæä»¶å页æ¥è¯¢--> |
| | | <select id="filePageForAccept" resultType="org.springblade.mdm.machinefile.entity.MachineFile"> |
| | | select f.id,f.name,f.machine_code,f.file_create_time,f.md5,f.file_size,f.dir_type,f.program_status |
| | |
| | | import java.nio.file.Files; |
| | | import java.nio.file.Paths; |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | |
| | | |
| | | //ç°åºç¼ç¨çä»»å¡éå |
| | | //List<MachineBackTask> onMachineTasks1 = machineBackTaskService.lambdaQuery().in(MachineBackTask::getId, backTaskIds).list(); |
| | | if(backTaskIds.isEmpty()){ |
| | | return Collections.emptyList(); |
| | | } |
| | | List<MachineBackTask> onMachineTasks = machineBackTaskService.lambdaQuery() |
| | | .eq(MachineBackTask::getTaskType,MachineBackTask.TASK_TYPE_ON_MACHINE) |
| | | .in(MachineBackTask::getId, backTaskIds).list(); |
| | | .list(); |
| | | |
| | | List<Long> onMachineFileIds = new ArrayList<>(); |
| | | for(MachineAcceptedFile accFile : acceptedFiles){ |
| | |
| | | } |
| | | } |
| | | } |
| | | if(onMachineFileIds.isEmpty()){ |
| | | return Collections.emptyList(); |
| | | } |
| | | |
| | | return machineFileService.lambdaQuery().in(MachineFile::getId,onMachineFileIds).list(); |
| | | } |
| | | |
| | | public List<MachineAcceptedFile> listByBackTaskId(Long backTaskId) { |
| | | return lambdaQuery().eq(MachineAcceptedFile::getBackTaskId,backTaskId).list(); |
| | | } |
| | | } |
| | |
| | | import org.springblade.core.log.exception.ServiceException; |
| | | import org.springblade.mdm.basesetting.machine.service.MachineService; |
| | | import org.springblade.mdm.basesetting.machine.entity.Machine; |
| | | 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.machinefile.entity.MachineFile; |
| | | import org.springblade.mdm.machinefile.mapper.MachineFileMapper; |
| | | import org.springblade.mdm.program.service.ProgramAnnotationService; |
| | | import org.springblade.mdm.program.service.programannotation.*; |
| | | import org.springblade.mdm.utils.FileContentUtil; |
| | |
| | | @Autowired |
| | | private MachineService machineService; |
| | | @Autowired |
| | | private ProgramAnnotationService programAnnotationService; |
| | | @Autowired |
| | | private MachineAnnotationConfig annoConfig; |
| | | @Autowired |
| | | private AnnotationProcessorHelper annotationProcessorHelper; |
| | | /** |
| | | * æ«ææææºåºçé
ç½®ç®å½ |
| | | */ |
| | | @Autowired |
| | | private MachineDirTranslator machineDirTranslator; |
| | | @Autowired |
| | | private MachineFileMapper machineFileMapper; |
| | | @Async |
| | | public void scanMachineFile() { |
| | | List<Machine> machines = machineService.getEnableMachines(); |
| | |
| | | } |
| | | } |
| | | |
| | | machineFileMapper.deleteNotUseRecords(); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * æ«æç®å½ |
| | | * @param machine æºåºä¿¡æ¯ |
| | | * @param dirType ç®å½ç±»å |
| | | * @throws IOException |
| | | * @throws IOException æä»¶æä½å¯è½å¯¼è´çå¼å¸¸ |
| | | */ |
| | | public void scanDir(Machine machine,String dirType) throws IOException { |
| | | String basePath = MachineFileService.getBasePath(machine,dirType); |
| | | String basePath = machineDirTranslator.trans(MachineFileService.getBasePath(machine,dirType)); |
| | | if(basePath == null) { |
| | | log.warn("ç®å½ç±»åä¸å¹é
:{}",dirType); |
| | | return; |
| | |
| | | .filter(Files::isRegularFile).toList(); |
| | | |
| | | //byte[] buffer = new byte[2048]; |
| | | List<DictBiz> annotatiionList = programAnnotationService.getAnnotionDictList(); |
| | | //List<DictBiz> annotatiionList = programAnnotationService.getAnnotionDictList(); |
| | | //boolean exists;//æä»¶æ¯å¦åå¨äºæ°æ®åºä¸ |
| | | for (Path filePath : files) { |
| | | try { |
| | | MachineFile mf = readFileToMachineFile(filePath,machine,dirType,annotatiionList); |
| | | MachineFile mf = readFileToMachineFile(filePath,machine,dirType); |
| | | |
| | | machineFileService.refreshFileData(mf); |
| | | |
| | |
| | | * @param filePath æä»¶è·¯å¾ |
| | | * @param machine æºå¨ |
| | | * @param dirType ç®å½ç±»å |
| | | * @param annotatiionList 注解é
ç½®åå
¸ ç¨äºè¯»åç¨åºç¶æ |
| | | * @return MachineFile å®ä¾ |
| | | * @throws IOException |
| | | */ |
| | | public MachineFile readFileToMachineFile(Path filePath,Machine machine,String dirType,List<DictBiz> annotatiionList) throws IOException { |
| | | public MachineFile readFileToMachineFile(Path filePath,Machine machine,String dirType) throws IOException { |
| | | MachineFile mf = new MachineFile(); |
| | | |
| | | mf.setTenantId("000000"); |
| | | mf.setName(filePath.toFile().getName()); |
| | | mf.setDirType(dirType); |
| | | mf.setMachineCode(machine.getCode()); |
| | | |
| | | |
| | | BasicFileAttributes attrs = Files.readAttributes( |
| | | filePath, |
| | |
| | | } |
| | | return mf; |
| | | } |
| | | /** |
| | | * 读åæä»¶ä¸çç¨åºç¶æ |
| | | * @param filePath æä»¶è·¯å¾ |
| | | * @param controlSystem |
| | | * @param annotatiionList 注éé
ç½®åå
¸ |
| | | * @return ç¶æçæ´æ°ä¹å |
| | | * @throws IOException |
| | | */ |
| | | public int readProgramStatus(Path filePath,String controlSystem,List<DictBiz> annotatiionList) throws IOException { |
| | | int programStatus = MachineFile.PROGRAM_STATUS_UNKNOWN; |
| | | try(InputStream ins = Files.newInputStream(filePath); |
| | | BufferedInputStream byteInsStream = new BufferedInputStream(ins)){ |
| | | |
| | | boolean isText= FileContentUtil.isTextFile(byteInsStream); |
| | | if(!isText){ |
| | | return MachineFile.PROGRAM_STATUS_UNKNOWN; |
| | | } |
| | | byteInsStream.reset(); |
| | | |
| | | AnnotationProcessor annoProcessor = ProcessorHelper.getProcessor(controlSystem,annoConfig); |
| | | String statusLine = FileContentUtil.readLineAt(byteInsStream, annoProcessor.getAnnotationProperties().getStatusLineIndex()); |
| | | if(AnnotationUtil.isAnnotation(statusLine,controlSystem,annotatiionList)){ |
| | | String progStatusTxt = AnnotationUtil.removeAnnotation(controlSystem,statusLine,annotatiionList); |
| | | if(AnnotationUtil.SQ.equals(progStatusTxt)){ |
| | | programStatus = MachineFile.PROGRAM_STATUS_TRY; |
| | | }else if(AnnotationUtil.GH.equals(progStatusTxt)){ |
| | | programStatus = MachineFile.PROGRAM_STATUS_CURED; |
| | | }else if(AnnotationUtil.LG.equals(progStatusTxt)){ |
| | | programStatus = MachineFile.PROGRAM_STATUS_DIVIASTION; |
| | | } |
| | | } |
| | | } |
| | | |
| | | return programStatus; |
| | | } |
| | | |
| | | /** |
| | | * æ¸
çå·²ç»å é¤äºæä»¶çè®°å½ |
| | | * @param machine |
| | | * @param dirType |
| | | * @param machine æºåº |
| | | * @param dirType ç®å½ç±»å |
| | | * @throws IOException |
| | | */ |
| | | void clearDeletedRecords(Machine machine,String dirType) throws IOException { |
| | | List<MachineFile> machineFiles = this.machineFileService.lambdaQuery().eq(MachineFile::getDirType,dirType) |
| | | .eq(MachineFile::getMachineCode,machine.getCode()).list(); |
| | | |
| | | String basePath = MachineFileService.getBasePath(machine,dirType); |
| | | String basePath = machineDirTranslator.trans(MachineFileService.getBasePath(machine,dirType)); |
| | | if(basePath == null) { |
| | | log.warn("ç®å½ç±»åä¸å¹é
:{}",dirType); |
| | | return; |
| | |
| | | import org.springblade.core.oss.model.BladeFile; |
| | | import org.springblade.mdm.basesetting.machine.service.MachineService; |
| | | import org.springblade.mdm.basesetting.machine.entity.Machine; |
| | | import org.springblade.mdm.commons.service.MachineDirTranslator; |
| | | import org.springblade.mdm.machinefile.entity.MachineFile; |
| | | import org.springblade.mdm.machinefile.entity.MachineFileChangeHis; |
| | | import org.springblade.mdm.machinefile.mapper.MachineFileMapper; |
| | |
| | | import org.springblade.mdm.program.vo.CompareDataVO; |
| | | import org.springblade.mdm.statreport.vo.MachineFileExceptionQueryVO; |
| | | import org.springblade.mdm.utils.FileContentUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | |
| | | private final MachineService machineService; |
| | | private final MachineFileChangeHisService machineFileChangeHisService; |
| | | private final OssTemplate ossTemplate; |
| | | |
| | | private MachineDirTranslator machineDirTranslator; |
| | | /** |
| | | * è·åæä»¶å
¨è·¯å¾ |
| | | * @param id æ°æ®id |
| | |
| | | |
| | | /** |
| | | * è·ååºæ¬è·¯å¾ |
| | | * @param machine |
| | | * @param dirType |
| | | * @return |
| | | * @param machine æºåº |
| | | * @param dirType ç®å½ç±»å |
| | | * @return ç®å½åºæ¬è·¯å¾ |
| | | */ |
| | | public static String getBasePath(Machine machine,String dirType){ |
| | | String dirPath; |
| | |
| | | existFileInDb.setProgramStatus(mf.getProgramStatus()); |
| | | existFileInDb.setFileCreateTime(mf.getFileCreateTime()); |
| | | existFileInDb.setFileModifyTime(mf.getFileModifyTime()); |
| | | existFileInDb.setStatus(MachineFile.STATUS_NORMAL); |
| | | if(!com.alibaba.excel.util.StringUtils.equals(existFileInDb.getMd5(),mf.getMd5())){ |
| | | //æä»¶å
容åçååäº,è®¾ç½®ç¶æä¸ºåå§ç¶æ |
| | | existFileInDb.setStatus(MachineFile.STATUS_NORMAL); |
| | |
| | | } |
| | | |
| | | /** |
| | | * ä¿®æ¹æä»¶åæ |
| | | * ä¿®æ¹æä»¶åç§° |
| | | * @param id æä»¶id |
| | | * @param name æ°åç§° |
| | | */ |
| | | public void changeName(Long id, String name) { |
| | | public void changeName(Long id, String name) throws IOException { |
| | | MachineFile machineFile = getById(id); |
| | | if(machineFile.getName().equals(name)) { |
| | | return; |
| | | } |
| | | Machine machine = machineService.getByCode(machineFile.getMachineCode()); |
| | | String baseDir = machineDirTranslator.trans(getBasePath(machine,machineFile.getDirType())); |
| | | String targetFilePath = baseDir + File.separator + name; |
| | | Path filePath = Paths.get(targetFilePath); |
| | | |
| | | if(filePath.toFile().exists()) { |
| | | throw new ServiceException("ååæä»¶å·²åå¨ï¼"+name); |
| | | } |
| | | Files.move(Paths.get(baseDir+File.separator+machineFile.getName()),filePath); |
| | | baseMapper.deleteById(id); |
| | | } |
| | | |
| | | public MachineFile getByNameAndMachineInDir(String name, String machineCode, String dirType) { |
| | |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | 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; |
| | |
| | | private final MachineBackTaskService machineBackTaskService; |
| | | /** |
| | | * 导åºå°æ¶å¯ç½ |
| | | * @param acceptedFileIds |
| | | * @param os |
| | | * @throws IOException |
| | | * @param acceptedFileIds æ¥åçæä»¶id离äºå§ |
| | | * @param os è¾åºæµ |
| | | * @throws IOException æä½zipå¯è½å¯¼è´çIOå¼å¸¸ |
| | | */ |
| | | @Transactional |
| | | public void exportToInner(List<Long> acceptedFileIds, ServletOutputStream os) throws IOException { |
| | |
| | | try (ZipOutputStream zipOut = new ZipOutputStream(os);) {//os |
| | | Map<String,List<MachineAcceptedFile>> map = acceptedFiles.stream() |
| | | .collect(Collectors.groupingBy(s -> ProgramFileNameParser.parseProgramName(s.getName()).logicProgramName())); |
| | | |
| | | this.createFoldersInZip(zipOut,map.keySet()); |
| | | |
| | | for (Map.Entry<String, List<MachineAcceptedFile>> entry : map.entrySet()) { |
| | | String programName = entry.getKey(); |
| | |
| | | acceptedFile.setExportTime(DateUtil.now()); |
| | | acceptedFile.setStatus(MachineAcceptedFile.STATUS_EXPORTED); |
| | | } |
| | | |
| | | } |
| | | |
| | | machineAcceptedService.updateBatchById(acceptedFiles); |
| | |
| | | |
| | | } |
| | | |
| | | /** |
| | | * å建左å³çç¨åºå
åæä»¶å¤¹ |
| | | * @param zipOut zipè¾åºæµ |
| | | * @param folderSet ç¨åºæ¥åæä»¶å¤¹éå |
| | | * @throws IOException zipIOæä½å¼å¸¸ |
| | | */ |
| | | void createFoldersInZip(ZipOutputStream zipOut,Set<String> folderSet) throws IOException { |
| | | for(String folderName : folderSet){ |
| | | ZipEntry zipEntry = new ZipEntry(folderName+"/");// "/"ç»å°¾è¡¨ç¤ºæä»¶å¤¹ |
| | | zipOut.putNextEntry(zipEntry); |
| | | zipOut.closeEntry(); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | 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()); |
| | | for(Long backTaskId : backTaskIdList){ |
| | | MachineBackTask backTask = machineBackTaskService.getById(backTaskId); |
| | | List<MachineAcceptedFile> acceptedFiles = machineAcceptedService.listByBackTaskId(backTaskId); |
| | | |
| | | machineBackTaskService.updateById(backTask); |
| | | if(acceptedFiles.size() == backTask.getSegCount()) { |
| | | backTask.setStatus(MachineBackTask.STATUS_FINISHED); |
| | | backTask.setFinishTime(new Date()); |
| | | |
| | | machineBackTaskService.updateById(backTask); |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | 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(); |
| | | } |
| | | } |
| | |
| | | @Slf4j |
| | | public class MdmProgramImportController { |
| | | |
| | | //private final DncSendBackService dncSendBackService; |
| | | private final MdmProgramImportService mdmProgramImportService; |
| | | /** |
| | | * ä¸ä¼ DNCåä¼ æä»¶ |
| | |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springblade.core.excel.util.ExcelUtil; |
| | | import org.springblade.core.tenant.annotation.NonDS; |
| | | import org.springblade.core.tool.api.R; |
| | | import org.springblade.mdm.flow.vo.ProgramOnMachineExcel; |
| | | import org.springblade.mdm.flow.vo.ProgramOnMachineQueryVO; |
| | | import org.springblade.mdm.program.service.MdmProgramImportService; |
| | | import org.springblade.mdm.program.service.ProgramOnMachineService; |
| | | import org.springblade.mdm.program.vo.*; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * mdm导å
¥æ¥å£ï¼å·¥æ§ç½åè½ |
| | |
| | | public class ProgramOnMachineImportController { |
| | | |
| | | private final ProgramOnMachineService programOnMachineService; |
| | | /** |
| | | * ä¸ä¼ DNCåä¼ æä»¶ |
| | | * |
| | | * @param file dncç¨åºæå
æä»¶ |
| | | */ |
| | | |
| | | @PostMapping("import-prog-on-machine") |
| | | @ApiOperationSupport(order = 1) |
| | | @Operation(summary = "MDMç¨åºå¯¼å
¥", description = "å·¥æ§ç½mdmç¨åºå¯¼å
¥") |
| | | @Operation(summary = "å·¥æ§ç½å¯¼å
¥ç°åºç¼å¶æ°æ®", description = "å·¥æ§ç½å¯¼å
¥ç°åºç¼å¶æ°æ®") |
| | | public R<Integer> upload(@RequestParam MultipartFile file) { |
| | | if(file == null || file.isEmpty() || file.getOriginalFilename() ==null){ |
| | | return R.fail("æä»¶ä¸è½ä¸ºç©º"); |
| | |
| | | @Operation(summary = "å·¥æ§ç½ä¸åºç¼ç¨è®°å½å页æ¥è¯¢", description = "å·¥æ§ç½ä¸åºç¼ç¨è®°å½å页æ¥è¯¢") |
| | | @GetMapping("/program-on-machine-page") |
| | | public R<IPage<ProgramOnMachineVO>> page(ProgramOnMachineRecordQueryVO queryVO) { |
| | | |
| | | return R.data(programOnMachineService.pageQuery(queryVO)); |
| | | } |
| | | |
| | |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * DNCåä¼ æä»¶,æ°æ®éè¿çæ§ç®å½è·åæä»¶å¹¶å
¥åº |
| | | * å·¥æ§ç½ï¼åä¼ æä»¶è®°å½ |
| | | */ |
| | | @Setter |
| | | @Getter |
| | | @TableName("mdm_dnc_back_file") |
| | | public class DncBackFile extends BizEntity { |
| | | public static int STATUS_ACCEPTED = 2; |
| | | public static int STATUS_REJECTED = 3; |
| | | |
| | | /** |
| | | * ç¨åºå
å èç¹ çid |
| | |
| | | * å离åæä»¶æ«å°¾ç模å¼ï¼P+æ°å |
| | | */ |
| | | private static final String P_NUMBER_PATTERN = "(?i)P\\d+"; |
| | | //static String[] encodings = {"UTF-8","GBK", "GB2312", "ISO-8859-1"}; |
| | | private String getFileKey(){ |
| | | return "dncimpfile-"+ AuthUtil.getUserId(); |
| | | } |
| | |
| | | result = parseProgramListByCharset(byteInsStream,Charset.forName(encoding)); |
| | | log.error("使ç¨ç¼ç {} è§£ææå ",encoding); |
| | | break; |
| | | }catch (ServiceException se) { |
| | | log.error("æ°æ®ä¸æ£ç¡®å¼å¸¸:",se); |
| | | break; |
| | | } catch (Exception e) { |
| | | byteInsStream.reset(); |
| | | log.error("使ç¨ç¼ç {} è§£æå¤±è´¥: ",encoding,e); |
| | | log.error("使ç¨ç¼ç {} è§£æå¤±è´¥:",encoding,e); |
| | | } |
| | | } |
| | | if(result != null) { |
| | |
| | | @Transactional |
| | | public void dncFileAccept(String ids) throws IOException { |
| | | List<Long> acceptIdList = Func.toLongList(ids); |
| | | // |
| | | NcProgramExchange exchange; |
| | | |
| | | String filekey = getFileKey(); |
| | | String zipFileName = bladeRedis.get(filekey); |
| | | log.info("filekey={},æä»¶å={}",filekey,zipFileName); |
| | |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.flowable.engine.HistoryService; |
| | | import org.flowable.engine.ProcessEngine; |
| | | import org.springblade.core.log.exception.ServiceException; |
| | | import org.springblade.core.mp.base.BizServiceImpl; |
| | | import org.springblade.core.mp.support.Condition; |
| | | import org.springblade.core.oss.OssTemplate; |
| | | import org.springblade.core.oss.model.BladeFile; |
| | | import org.springblade.core.tool.utils.FileUtil; |
| | | import org.springblade.mdm.flow.entity.FlowProgramFile; |
| | | import org.springblade.mdm.flow.service.FlowBusinessService; |
| | | import org.springblade.mdm.program.entity.DncBackFile; |
| | | import org.springblade.mdm.program.entity.NcNode; |
| | |
| | | import org.springblade.mdm.program.vo.DncBackFileQueryVO; |
| | | import org.springblade.mdm.program.vo.DncBackFileVO; |
| | | import org.springblade.mdm.program.vo.DncSendBackFile; |
| | | import org.springblade.mdm.utils.FileContentUtil; |
| | | import org.springblade.mdm.utils.ZipTextFileContentUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import java.io.ByteArrayInputStream; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.nio.file.Files; |
| | |
| | | import java.util.ArrayList; |
| | | import java.util.Enumeration; |
| | | import java.util.List; |
| | | import java.util.Optional; |
| | | import java.util.zip.ZipEntry; |
| | | |
| | | /** |
| | |
| | | |
| | | package org.springblade.mdm.program.service; |
| | | |
| | | import jodd.util.annotation.AnnotationParser; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.codec.digest.DigestUtils; |
| | | import org.apache.commons.io.FileUtils; |
| | | import org.apache.commons.io.FilenameUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springblade.core.log.exception.ServiceException; |
| | | import org.springblade.core.mp.base.BizServiceImpl; |
| | |
| | | import org.springblade.core.tool.utils.Func; |
| | | import org.springblade.mdm.basesetting.machine.service.MachineService; |
| | | import org.springblade.mdm.basesetting.machine.entity.Machine; |
| | | import org.springblade.mdm.commons.contants.RegExpConstants; |
| | | import org.springblade.mdm.commons.contants.ZipConstants; |
| | | import org.springblade.mdm.gkw.programnode.vo.ProgramNameVO; |
| | | import org.springblade.mdm.gkw.task.entity.MachineBackTask; |
| | |
| | | import java.time.Duration; |
| | | import java.util.*; |
| | | import java.nio.file.*; |
| | | import java.util.regex.Matcher; |
| | | import java.util.stream.Stream; |
| | | import java.util.zip.ZipEntry; |
| | | import java.util.zip.ZipInputStream; |
| | |
| | | MdmProgramImportVO vo = new MdmProgramImportVO(); |
| | | vo.setFilename(path.getFileName().toString()); |
| | | |
| | | ProgramNameVO pnmameVO = tryParseProgramName(vo.getFilename()); |
| | | vo.setDrawingNo(pnmameVO.getDrawingNo()); |
| | | ProgramNameVO progNmameVO = tryParseProgramName(vo.getFilename()); |
| | | vo.setDrawingNo(progNmameVO.getDrawingNo()); |
| | | |
| | | try (InputStream inputStream = Files.newInputStream(path)) { |
| | | // 使ç¨è¾å
¥æµè¯»åæä»¶å
容 |
| | |
| | | Machine matchedMachine = machineService.getMachineBySendPathAnnotation(sendPathLine); |
| | | |
| | | if (matchedMachine != null) { |
| | | vo.setName(pnmameVO.logicProgramName()); |
| | | vo.setName(progNmameVO.logicProgramName()); |
| | | vo.setMachineCode(matchedMachine.getCode()); |
| | | |
| | | vo.setFullPath(path.toString());//æä»¶å°å |
| | |
| | | } |
| | | return vo; |
| | | } |
| | | /** |
| | | * è§£æåºé¶ç»ä»¶å¥½ |
| | | * @param filename |
| | | * @return |
| | | */ |
| | | /* |
| | | String parseDrawingNo(String filename){ |
| | | |
| | | /* |
| | | String drawingNo = ""; |
| | | int idx = filename.lastIndexOf("-"); |
| | | String temp; |
| | | if(idx != -1){ |
| | | temp = filename.substring(0,idx); |
| | | |
| | | idx = temp.lastIndexOf("-"); |
| | | if(idx != -1){ |
| | | temp = temp.substring(0,idx); |
| | | |
| | | //廿工åºç次 |
| | | idx = temp.lastIndexOf("-"); |
| | | if(idx != -1){ |
| | | temp = temp.substring(0,idx); |
| | | |
| | | //廿工åºå· |
| | | idx = temp.lastIndexOf("-"); |
| | | if(idx != -1){ |
| | | drawingNo = temp.substring(0,idx); |
| | | } |
| | | } |
| | | } |
| | | //以ä¸å»æäºæå2段段æ°åæ®µå· |
| | | |
| | | |
| | | } |
| | | return drawingNo; |
| | | |
| | | |
| | | } |
| | | |
| | | String parseProgramName(String filename){ |
| | | String programName = ""; |
| | | int idx = filename.lastIndexOf("-"); |
| | | String temp; |
| | | if(idx != -1){ |
| | | temp = filename.substring(0,idx); |
| | | |
| | | idx = temp.lastIndexOf("-"); |
| | | if(idx != -1){ |
| | | temp = temp.substring(0,idx); |
| | | |
| | | //廿工åºç次 |
| | | idx = temp.lastIndexOf("-"); |
| | | if(idx != -1){ |
| | | programName = temp.substring(0,idx); |
| | | } |
| | | } |
| | | //以ä¸å»æäºæå2段段æ°åæ®µå· |
| | | } |
| | | return programName; |
| | | } |
| | | */ |
| | | /** |
| | | * å
¥åºmdmæ¶å¯ç½æä»¶ |
| | | * @param ids idå表éå·åé |
| | |
| | | Path extractDir = Paths.get(dictStr); |
| | | List<MdmProgramImportVO> list = readTempDir(extractDir); |
| | | |
| | | List<DictBiz> annoDictList = programAnnotationService.getAnnotionDictList(); |
| | | //List<DictBiz> annoDictList = programAnnotationService.getAnnotionDictList(); |
| | | String destFileFull; |
| | | for(String str : idList){ |
| | | Optional<MdmProgramImportVO> optVO = list.stream().filter(vo -> vo.getId().equals(str)).findFirst(); |
| | |
| | | |
| | | destFileFull = vo.getSendPath()+File.separator+vo.getFilename(); |
| | | File destFile = new File(destFileFull); |
| | | |
| | | FileUtils.forceMkdirParent(destFile); |
| | | FileUtils.copyFile(new File(str),destFile); |
| | | |
| | |
| | | Machine machine = this.machineService.getByCode(record.getMachineCode()); |
| | | AnnotationProcessor processor = annotationProcessorHelper.getProcessor(machine.getControlSystem()); |
| | | AnnotationData annotationData = processor.readAnnotationData(inputStream); |
| | | /* |
| | | |
| | | record.setDeviation(annotationData.getDeviation()); |
| | | ProgramNameVO nameVO = ProgramFileNameParser.parseProgramName(record.getName()); |
| | | if(StringUtils.isNotBlank(nameVO.getLgPart())) { |
| | | record.setDeviation(annotationData.getDeviation()); |
| | | }*/ |
| | | record.setDeviationSerial(nameVO.lgSerial()); |
| | | |
| | | record.setProgramStatus(annotationData.getProgramStatus()); |
| | | } |
| | | fileSendRecordService.save(record); |
| | |
| | | |
| | | /** |
| | | * å建æºåºåä¼ ä»»å¡ |
| | | * @param importedRecords |
| | | * @param importedRecords 导å
¥è®°å½å表 |
| | | */ |
| | | List<MachineBackTask> parseMachineBackTask(List<FileSendRecord> importedRecords){ |
| | | List<FileSendRecord> recList = importedRecords.stream().filter(r ->{ |
| | | return AnnotationUtil.SQ.equals(r.getProgramStatus()) |
| | | || AnnotationUtil.LG.equals(r.getProgramStatus());}).toList(); |
| | | List<FileSendRecord> recList = importedRecords.stream().filter(r -> AnnotationUtil.SQ.equals(r.getProgramStatus()) |
| | | || AnnotationUtil.LG.equals(r.getProgramStatus())).toList(); |
| | | |
| | | Map<String,FileSendRecord> map = new HashMap<>(); |
| | | for(FileSendRecord record : recList){ |
| | | ProgramNameVO nameVO = ProgramFileNameParser.parseProgramName(record.getName()); |
| | | String key = record.getMachineCode()+","+nameVO.logicProgramName(); |
| | | |
| | | map.put(key,record); |
| | | } |
| | | |
| | |
| | | task.setMachineCode(record.getMachineCode()); |
| | | |
| | | ProgramNameVO nameVO = ProgramFileNameParser.parseProgramName(record.getName()); |
| | | task.setDeviation(record.getDeviation()); |
| | | task.setDeviationSerial(record.getDeviationSerial()); |
| | | |
| | | task.setProgramName(nameVO.logicProgramName()); |
| | | task.setSegCount(nameVO.getSegmentCount()); |
| | | backTasks.add(task); |
| | |
| | | * @return ææ°çæ¬ç¨åºæ¥åèç¹ |
| | | */ |
| | | public NcNode getLastEditionTryingProgramPackage(String name){ |
| | | //.or(NcNode::getIsCured,0) |
| | | List<NcNode> pkgList = lambdaQuery().eq(NcNode::getNodeType,NcNode.TYPE_PROGRAM_PACKAGE) |
| | | .eq(NcNode::getName, name).and(i->{ |
| | | i.eq(NcNode::getIsCured, 0).or().isNull(NcNode::getIsCured); |
| | |
| | | private final FlowProgramFileService flowProgramFileService; |
| | | private final HistoryService historyService; |
| | | private final TaskDispatchService taskDispatchService; |
| | | private final MachineAnnotationConfig annotationConfig; |
| | | |
| | | private final AnnotationProcessorHelper annotationProcessorHelper; |
| | | /** |
| | | * 导åºdncå缩å
|
| | |
| | | |
| | | /** |
| | | * å°ç¨åºå
åä¸å±æä»¶å å
¥å缩å
|
| | | * @param zipOut |
| | | * @param approved |
| | | * @param zipOut zipæä»¶è¾åºæµ |
| | | * @param approved 审æ¹å®æè®°å½ |
| | | */ |
| | | private void addProgramPackageToZip(ZipOutputStream zipOut, NcProgramApproved approved) throws IOException{ |
| | | NcNodeHis packageNodeHis = ncNodeHisService.getById(approved.getNcNodeId()); |
| | |
| | | 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.setDeviation(programPackageNode.getDeviation()); |
| | | annoData.setFilename(programFile.getName()); |
| | | |
| | | InputStream addedInsFinal = annoProcessor.putAnnotation(annoData,inputStream); |
| | | if(StringUtils.startsWith(programPackageNode.getParentIds(),"0,4")) { |
| | | //è¯åè¡¥å
,ç¹æ®æ è®°ç¶æ |
| | | annoData.setProgramStatus(AnnotationUtil.TMP); |
| | | } |
| | | InputStream addedInsFinal = annoProcessor.putAnnotation(annoData, inputStream); |
| | | addedInsFinal.reset(); |
| | | |
| | | this.addInputStreamToZip(zipOut, addedInsFinal, filePathInZip); |
| | | } |
| | | } |
| | |
| | | private ProgramAnnotationService programAnnotationService; |
| | | |
| | | protected AnnotationProperties annotationProperties; |
| | | |
| | | protected List<DictBiz> getAnnotationDictList(){ |
| | | return programAnnotationService.getAnnotionDictList(); |
| | | } |
| | | |
| | | @Override |
| | | public InputStream putSendPathAnnotation(String sendPath, InputStream inputStream,List<DictBiz> annoDicts) throws IOException{ |
| | | String sendPathRepl = StringUtils.replace(sendPath,"\\","/"); |
| | | InputStream finishedStream; |
| | | try(inputStream){ |
| | | ByteArrayInputStream byteInputStream = new ByteArrayInputStream(IOUtils.toByteArray(inputStream)); |
| | | |
| | | //1å å
¥åéè·¯å¾ç注é |
| | | String sendPathAnnotation = AnnotationUtil.generateAnnotation(sendPath,getControlSystem(),annoDicts);//å äºæ³¨éä¹åçææ¬ |
| | | String sendPathAnnotation = AnnotationUtil.generateAnnotation(sendPathRepl,getControlSystem(),annoDicts);//å äºæ³¨éä¹åçææ¬ |
| | | |
| | | String sendDirLine = FileContentUtil.readLineAt(byteInputStream,annotationProperties.getSendPathLineIndex());//第2è¡æ¯åéè·¯å¾ |
| | | String sendPathLine = FileContentUtil.readLineAt(byteInputStream,annotationProperties.getSendPathLineIndex());//第2è¡æ¯åéè·¯å¾ |
| | | byteInputStream.reset(); |
| | | |
| | | if(AnnotationUtil.isAnnotation(sendDirLine,getControlSystem(),annoDicts)){ |
| | | String planText = AnnotationUtil.removeAnnotation(getControlSystem(),sendDirLine,annoDicts); |
| | | if(!planText.equals(sendPath)) { |
| | | if(AnnotationUtil.isAnnotation(sendPathLine,getControlSystem(),annoDicts)){ |
| | | String planText = AnnotationUtil.removeAnnotation(getControlSystem(),sendPathLine,annoDicts); |
| | | //String planTextRepl = StringUtils.replace(planText,"\\","/"); |
| | | if(!planText.equals(sendPath) && !planText.equals(sendPathRepl)) { |
| | | //éè·¯å¾ç注éï¼æå
¥ |
| | | finishedStream = FileContentUtil.insertLine(byteInputStream,annotationProperties.getSendPathLineIndex(),sendPathAnnotation); |
| | | }else{ |
| | | //æ¯è·¯å¾ï¼ä¸å¤çç´æ¥è¿ååè¾å
¥æµ |
| | | finishedStream = inputStream; |
| | | } |
| | | //finishedStream = FileContentUtil.replaceAtLine(byteInputStream,annotationProperties.getSendPathLineIndex(),sendPathAnnotation); |
| | | }else{ |
| | | finishedStream = FileContentUtil.insertLine(byteInputStream,annotationProperties.getSendPathLineIndex(),sendPathAnnotation); |
| | | } |
| | |
| | | //éæ³¨éï¼æå
¥ç¶æ |
| | | insAfterProgramName = FileContentUtil.insertLine(byteStream,annotationProperties.getProgramNameLineIndex(),proNameAnnotation); |
| | | } |
| | | /* |
| | | if(isAnnotation){ |
| | | insAfter = FileContentUtil.replaceAtLine(bais, annotationProperties.getProgramNameLineIndex(),proNameLine); |
| | | }else{ |
| | | insAfter = FileContentUtil.insertLine(bais, annotationProperties.getProgramNameLineIndex(),proNameLine); |
| | | }*/ |
| | | |
| | | return insAfterProgramName; |
| | | } |
| | | |
| | |
| | | |
| | | //1å å
¥åéè·¯å¾ç注é |
| | | InputStream insAfterSetSendDir = putSendPathAnnotation(annoData.getSendPath(),byteInputStream,annoDicts); |
| | | /* |
| | | String statusLine = FileContentUtil.readLineAt(insAfterSetSendDir,annotationProperties.getStatusLineIndex());//ç¶ææ³¨é |
| | | insAfterSetSendDir.reset(); |
| | | |
| | | //å å
¥ç¶ææ³¨éè¡ |
| | | InputStream insAfterStatus; |
| | | String statusAnnotation = AnnotationUtil.generateAnnotation(annoData.getProgramStatus(),getControlSystem(),annoDicts);//注éåçç¶æææ¬ |
| | | if(AnnotationUtil.isAnnotation(statusLine,getControlSystem(),annoDicts)){ |
| | | insAfterStatus = FileContentUtil.replaceAtLine(insAfterSetSendDir,annotationProperties.getStatusLineIndex(),statusAnnotation); |
| | | }else{ |
| | | insAfterStatus = FileContentUtil.insertLine(insAfterSetSendDir,annotationProperties.getStatusLineIndex(),statusAnnotation); |
| | | }*/ |
| | | InputStream insAfterStatus = putStatusAnnotation(annoData.getProgramStatus(),insAfterSetSendDir,annoDicts); |
| | | |
| | | if(StringUtils.isNotBlank(annoData.getDeviation())){ |
| | |
| | | String statusText = AnnotationUtil.removeAnnotation(this.getControlSystem(),statusLine,annoDictList); |
| | | if(AnnotationUtil.isStatusContent(statusText)){ |
| | | data.setProgramStatus(statusText); |
| | | } |
| | | |
| | | data.setDeviation(AnnotationUtil.removeAnnotation(this.getControlSystem(),devLine,annoDictList)); |
| | | if(AnnotationUtil.LG.equals(statusText)) { |
| | | data.setDeviation(AnnotationUtil.removeAnnotation(this.getControlSystem(), devLine, annoDictList)); |
| | | } |
| | | } |
| | | |
| | | } catch (IOException e) { |
| | | throw new RuntimeException(e); |
| | |
| | | * @return 读åçæ°æ® |
| | | */ |
| | | AnnotationData readAnnotationData(InputStream inputStream); |
| | | //InputStream puttSendPathAnnotation(String programName, InputStream inputStream) throws IOException; |
| | | } |
| | |
| | | public static final String SQ = "SQ"; |
| | | public static final String GH = "GH"; |
| | | public static final String LG = "LG"; |
| | | |
| | | public static final String TMP = "TMP"; |
| | | /** |
| | | * 夿æ¯å¦æ¯æ³¨éè¡ |
| | | * @param text æå |
| | |
| | | package org.springblade.mdm.program.service.programannotation; |
| | | |
| | | import org.apache.commons.io.FilenameUtils; |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springblade.mdm.program.service.ProgramAnnotationService; |
| | | import org.springblade.mdm.utils.FileContentUtil; |
| | | import org.springblade.system.pojo.entity.DictBiz; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.io.ByteArrayInputStream; |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.util.List; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | |
| | | |
| | | @Component("defaultProcessor") |
| | | public class DefaultProcessor extends AbstractProcessor{ |
| | | |
| | | @Autowired |
| | | private ProgramAnnotationService programAnnotationService; |
| | | //@Autowired |
| | | //private ProgramAnnotationService programAnnotationService; |
| | | private String controlSystem; |
| | | |
| | | |
| | | @Override |
| | | public InputStream putAnnotation(AnnotationData annoData, InputStream inputStream) throws IOException { |
| | | InputStream insAfter = super.putFilenameAnnotation(annoData.getFilename(),inputStream); |
| | | InputStream insAfter = putFilenameAnnotation(annoData.getFilename(),inputStream); |
| | | |
| | | return super.putAnnotation(annoData, insAfter); |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public InputStream putFilenameAnnotation(String fileName, InputStream inputStream) throws IOException { |
| | | List<DictBiz> annoDicts = getAnnotationDictList(); |
| | | ByteArrayInputStream byteStream = new ByteArrayInputStream(IOUtils.toByteArray(inputStream)); |
| | | |
| | | String programNameLine = FileContentUtil.readLineAt(byteStream, annotationProperties.getProgramNameLineIndex()); |
| | | byteStream.reset(); |
| | | boolean isAnnotation = AnnotationUtil.isAnnotation(programNameLine,this.getControlSystem(),annoDicts); |
| | | InputStream insAfterProgramName; |
| | | //å å
¥ç¨åºå注éè¡ |
| | | String programNameStr = genProgramNameText(FilenameUtils.removeExtension(fileName)); |
| | | |
| | | String proNameAnnotation = AnnotationUtil.generateAnnotation(programNameStr,getControlSystem(),annoDicts); |
| | | |
| | | if(isAnnotation){//æ¯æ³¨é |
| | | //æå注éå
æå |
| | | String programName = FilenameUtils.removeExtension(fileName); |
| | | String progNameLineWithoutAnno = AnnotationUtil.removeAnnotation(this.getControlSystem(),programNameLine,annoDicts); |
| | | if(!isCurrentProgramNameAnnotation(progNameLineWithoutAnno,programName)) { |
| | | //注é䏿¯ç¨åºåï¼å·¥èºåèªå·±åçæ³¨éï¼ï¼æå
¥ |
| | | insAfterProgramName = FileContentUtil.insertLine(byteStream,annotationProperties.getProgramNameLineIndex(),proNameAnnotation); |
| | | }else{ |
| | | //æ¯ç¨åºå注éï¼ä¸å¤çï¼è¿ååstream |
| | | insAfterProgramName = byteStream; |
| | | } |
| | | }else{ |
| | | //éæ³¨éï¼æå
¥ç¶æ |
| | | insAfterProgramName = FileContentUtil.insertLine(byteStream,annotationProperties.getProgramNameLineIndex(),proNameAnnotation); |
| | | } |
| | | return insAfterProgramName; |
| | | } |
| | | |
| | | /** |
| | | * æ¯å¦ä¸ºå½åç¨åºç注é |
| | | * @param lineTextWithoutAnno 注éè¡çæå |
| | | * @param programName ç¨åºåç§° |
| | | * @return æ¯å¦æ¶ç¨åºæ³¨éè¡ï¼å¦æä¸å½åç¨åºåå¹é
åtrue |
| | | */ |
| | | boolean isCurrentProgramNameAnnotation(String lineTextWithoutAnno,String programName){ |
| | | Pattern pattern = Pattern.compile("^\\((.+)\\)"); |
| | | Matcher matcher = pattern.matcher(lineTextWithoutAnno); |
| | | if(matcher.find()){ |
| | | String findText = matcher.group(1); |
| | | return findText.equals(programName); |
| | | }else{ |
| | | return false; |
| | | } |
| | | } |
| | | /** |
| | | * çæç¨åºåæçè¡ å å
¥ (pname=[ç¨åºåç§°]) |
| | | * @param proggramName |
| | | * @return æ¥è£
åçç¨åºåç§° |
| | | */ |
| | | private String genProgramNameText(String proggramName) { |
| | | return String.format("(%s)",proggramName); |
| | | } |
| | | |
| | | @Override |
| | | public void setControlSystem(String controlSystemDictVal) { |
| | |
| | | import jakarta.xml.soap.SOAPException; |
| | | import jakarta.xml.ws.WebServiceContext; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.apache.commons.io.FileUtils; |
| | | import org.springblade.core.tool.api.R; |
| | | 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.commons.service.InternalEmailService; |
| | | import org.springblade.mdm.commons.service.MachineDirTranslator; |
| | | import org.springblade.mdm.flow.entity.MesSync; |
| | | import org.springblade.mdm.flow.excution.events.CureFinishedEvent; |
| | | import org.springblade.mdm.flow.service.MesSyncService; |
| | |
| | | private NcNodeHisService nodeHisService; |
| | | @Autowired |
| | | private FileSendRecordService fileSendRecordService; |
| | | @Autowired |
| | | private MachineDirTranslator transDir; |
| | | |
| | | /** |
| | | * æ°å¢ |
| | | */ |
| | |
| | | |
| | | return optFile.get(); |
| | | } |
| | | |
| | | @GetMapping("/transdir") |
| | | public Object transdir(String path){ |
| | | return transDir.trans(path); |
| | | } |
| | | |
| | | @GetMapping("/sendfile") |
| | | public Object sendfile() throws IOException { |
| | | FileUtils.copyFile(new java.io.File("d:/a.txt"),(new java.io.File("\\\\192.168.233.2\\Workshop\\testMachine\\at.txt"))); |
| | | return "OK"; |
| | | } |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.springblade.mdm.gkw.programnode.vo; |
| | | |
| | | import org.junit.jupiter.api.Assertions; |
| | | import org.junit.jupiter.api.Test; |
| | | |
| | | public class ProgramNameVOTest { |
| | | |
| | | @Test |
| | | public void testLgSerial(){ |
| | | ProgramNameVO vo = new ProgramNameVO(); |
| | | |
| | | vo.setLgPart(null); |
| | | Assertions.assertNull(vo.lgSerial()); |
| | | |
| | | vo.setLgPart(""); |
| | | Assertions.assertNull(vo.lgSerial()); |
| | | |
| | | vo.setLgPart("X1");//éPxç»å°¾ |
| | | Assertions.assertNull(vo.lgSerial()); |
| | | |
| | | vo.setLgPart("P1"); |
| | | Assertions.assertEquals("1",vo.lgSerial()); |
| | | |
| | | vo.setLgPart("p2");//å°åpï¼ä¹åºè¯¥å¯ä»¥ |
| | | Assertions.assertEquals("2",vo.lgSerial()); |
| | | } |
| | | } |
| ¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.springblade.mdm.program.service.programannotation; |
| | | |
| | | import com.baomidou.mybatisplus.core.toolkit.Assert; |
| | | import org.junit.jupiter.api.Assertions; |
| | | import org.junit.jupiter.api.Test; |
| | | |
| | | public class DefaultProcessorTest { |
| | | |
| | | @Test |
| | | public void testIsCurrentProgramNameAnnotation(){ |
| | | DefaultProcessor processor = new DefaultProcessor(); |
| | | |
| | | String programName = "CP3-1-1-1"; |
| | | boolean result = processor.isCurrentProgramNameAnnotation("{NOTeprogram}",programName); |
| | | Assertions.assertFalse(result); |
| | | |
| | | result = processor.isCurrentProgramNameAnnotation("(CP3-1-1-1)",programName); |
| | | Assertions.assertTrue(result); |
| | | |
| | | } |
| | | } |
| | |
| | | Assertions.assertEquals("CS",vo.getDrawingNo()); |
| | | Assertions.assertEquals("æ ",vo.getProcessEdition()); |
| | | |
| | | |
| | | ProgramNameVO pnmame1 = ProgramFileNameParser.parseProgramName("CP3-2-1-æ -1-1.txt"); |
| | | Assertions.assertEquals("æ ",pnmame1.getProcessEdition()); |
| | | } |