| | |
| | | |
| | | import org.apache.commons.io.monitor.FileAlterationListener; |
| | | import org.apache.commons.io.monitor.FileAlterationObserver; |
| | | import org.jeecg.common.util.FileUtil; |
| | | import org.jeecg.modules.dnc.service.IDocInfoService; |
| | | import org.jeecg.modules.dnc.utils.file.FileUtilS; |
| | | import org.jeecg.modules.dnc.dto.TransferPackage; |
| | | import org.jeecg.modules.dnc.service.impl.DataImportService; |
| | | import org.jeecg.modules.dnc.service.impl.FileFerryService; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.io.File; |
| | | import java.util.Objects; |
| | | |
| | | @Component |
| | | public class FileListener implements FileAlterationListener { |
| | | private static final Logger log = LoggerFactory.getLogger(FileListener.class); |
| | | |
| | | @Autowired |
| | | private IDocInfoService docInfoService; // 文档服务 |
| | | private FileFerryService fileFerryService; |
| | | |
| | | @Autowired |
| | | private DataImportService dataImportService; |
| | | |
| | | @Override |
| | | public void onStart(FileAlterationObserver observer) { |
| | |
| | | public void onFileCreate(File file) { |
| | | String filePath = file.getAbsolutePath(); |
| | | log.info("[新建]: {}", filePath); |
| | | if (filePath.endsWith(".ferry")){ |
| | | TransferPackage data = fileFerryService.importData(filePath); |
| | | dataImportService.importTransferPackage(data); |
| | | log.info("文件导入完成"); |
| | | } |
| | | } |
| | | @Override |
| | | public void onFileChange(File file) { |
| | |
| | | public void onStop(FileAlterationObserver observer) { |
| | | // log.info("结束监听目录: {}", observer.getDirectory().getAbsolutePath()); |
| | | } |
| | | |
| | | /** |
| | | * 工控网解析涉密网传过来的NC文件与nc文件进行解析 |
| | | * @param file |
| | | */ |
| | | private void handleIndustrialDocFile(File file) { |
| | | log.info("工控网解析涉密网传过来的NC文件与nc文件进行解析: {}", file.getAbsolutePath()); |
| | | try { |
| | | if (Objects.equals(FileUtil.getFileSuffix(file.getName()), "nc")) { |
| | | boolean success = docInfoService.addDocInfoAnalysisGwNcService(file.getAbsolutePath(), file); |
| | | if (success) { |
| | | FileUtilS.copyFileRec(file.getAbsolutePath()); |
| | | FileUtilS.fileRecDelete(file.getAbsolutePath()); |
| | | } |
| | | }else if (Objects.equals(FileUtil.getFileSuffix(file.getName()), "txt")) { |
| | | //todo 是否解析工作流操作 |
| | | |
| | | } |
| | | } catch (Exception e) { |
| | | log.error("工控网解析涉密网传过来的NC文件与nc文件进行解析: {}", e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 涉密网解析工控网传过来的NC文件与nc文件进行解析(程序回传) |
| | | * @param file |
| | | */ |
| | | private void handleSecretDocFile(File file) { |
| | | log.info("涉密网解析工控网传过来的NC文件与nc文件进行解析: {}", file.getAbsolutePath()); |
| | | try { |
| | | boolean b= docInfoService.addDocInfoAnalysisSmwNcService(file.getAbsolutePath(), file); |
| | | |
| | | }catch (Exception e) { |
| | | log.error("涉密网解析工控网传过来的NC文件与nc文件进行解析: {}", e.getMessage()); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |