| | |
| | | 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); |
| | | } |
| | | |
| | | /** |