db/lxzn_qlj_nc.sql | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/lxzn/config/WebServiceConfig.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/lxzn/framework/domain/webservice/request/ThirdDeProgramSource.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/lxzn/nc/service/IDocRelativeService.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/lxzn/nc/service/impl/DocRelativeServiceImpl.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/lxzn/webservice/DncWebService.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/lxzn/webservice/controller/DncWebController.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/java/com/lxzn/webservice/impl/DncWebServiceImpl.java | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 | |
src/main/resources/application.yml | ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史 |
db/lxzn_qlj_nc.sql
ÎļþÌ«´ó src/main/java/com/lxzn/config/WebServiceConfig.java
@@ -1,62 +1,62 @@ package com.lxzn.config; import com.lxzn.webservice.DncWebService; import org.apache.cxf.Bus; import org.apache.cxf.bus.spring.SpringBus; import org.apache.cxf.jaxws.EndpointImpl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import javax.xml.ws.Endpoint; /** * @Description: * @Author: zhangherong * @Date: Created in 2020/12/24 17:09 * @Version: 1.0 * @Modified By: */ @Configuration public class WebServiceConfig { @Autowired private DncWebService dncWebService; /** * Apache CXF æ ¸å¿æ¶ææ¯ä»¥BUSä¸ºæ ¸å¿ï¼æ´åå ¶ä»ç»ä»¶ã * Busæ¯CXFç主干, ä¸ºå ±äº«èµæºæä¾ä¸ä¸ªå¯é ç½®çåºæï¼ä½ç¨ç±»ä¼¼äºSpringçApplicationContextï¼è¿äºå ±äº«èµæºå æ¬ * WSDl管çå¨ãç»å®å·¥åçãéè¿å¯¹BUSè¿è¡æ©å±ï¼å¯ä»¥æ¹ä¾¿å°å®¹çº³èªå·±çèµæºï¼æè æ¿æ¢ç°æçèµæºãé»è®¤Buså®ç°åºäºSpringæ¶æï¼ * éè¿ä¾èµæ³¨å ¥ï¼å¨è¿è¡æ¶å°ç»ä»¶ä¸²èèµ·æ¥ãBusFactoryè´è´£Busçå建ãé»è®¤çBusFactoryæ¯SpringBusFactoryï¼å¯¹åºäºé»è®¤ * çBuså®ç°ã卿é è¿ç¨ä¸ï¼SpringBusFactoryä¼æç´¢META-INF/cxfï¼å å«å¨ CXF çjarä¸ï¼ä¸çææbeané ç½®æä»¶ã * æ ¹æ®è¿äºé ç½®æä»¶æå»ºä¸ä¸ªApplicationContextãå¼åè ä¹å¯ä»¥æä¾èªå·±çé ç½®æä»¶æ¥å®å¶Busã */ @Bean(name = Bus.DEFAULT_BUS_ID) public SpringBus springBus() { return new SpringBus(); } /** * æ¤æ¹æ³ä½ç¨æ¯æ¹å项ç®ä¸æå¡åçåç¼åï¼æ¤å¤127.0.0.1æè localhostä¸è½è®¿é®æ¶ï¼è¯·ä½¿ç¨ipconfigæ¥çæ¬æºipæ¥è®¿é® * æ¤æ¹æ³è¢«æ³¨éå, å³ä¸æ¹ååç¼å(é»è®¤æ¯services), wsdl访é®å°å为 http://127.0.0.1:8080/services/ws/api?wsdl * å»ææ³¨éåwsdl访é®å°å为ï¼http://127.0.0.1:8080/soap/ws/api?wsdl * http://127.0.0.1:8080/soap/ååºæå¡å表 æ http://127.0.0.1:8080/soap/ws/api?wsdl æ¥çå®é çæå¡ * æ°å»ºServletè®°å¾éè¦å¨å¯å¨ç±»æ·»å 注解ï¼@ServletComponentScan * * 妿å¯å¨æ¶åºç°é误ï¼not loaded because DispatcherServlet Registration found non dispatcher servlet dispatcherServlet * å¯è½æ¯springbootä¸cfxçæ¬ä¸å ¼å®¹ã * åæ¶å¨spring boot2.0.6ä¹åççæ¬ä¸xcféæï¼ä¸éè¦å¨å®ä¹ä»¥ä¸æ¹æ³ï¼ç´æ¥å¨application.propertiesé ç½®æä»¶ä¸æ·»å ï¼ * cxf.path=/serviceï¼é»è®¤æ¯servicesï¼ */ //@Bean //public ServletRegistrationBean dispatcherServlet() { // return new ServletRegistrationBean(new CXFServlet(), "/soap/*"); //} @Bean public Endpoint endpoint() { EndpointImpl endpoint = new EndpointImpl(springBus(), dncWebService); endpoint.publish("/ws/dnc"); return endpoint; } } //package com.lxzn.config; // //import com.lxzn.webservice.DncWebService; //import org.apache.cxf.Bus; //import org.apache.cxf.bus.spring.SpringBus; //import org.apache.cxf.jaxws.EndpointImpl; //import org.springframework.beans.factory.annotation.Autowired; //import org.springframework.context.annotation.Bean; //import org.springframework.context.annotation.Configuration; // //import javax.xml.ws.Endpoint; // ///** // * @Description: // * @Author: zhangherong // * @Date: Created in 2020/12/24 17:09 // * @Version: 1.0 // * @Modified By: // */ //@Configuration //public class WebServiceConfig { // // @Autowired // private DncWebService dncWebService; // // /** // * Apache CXF æ ¸å¿æ¶ææ¯ä»¥BUSä¸ºæ ¸å¿ï¼æ´åå ¶ä»ç»ä»¶ã // * Busæ¯CXFç主干, ä¸ºå ±äº«èµæºæä¾ä¸ä¸ªå¯é ç½®çåºæï¼ä½ç¨ç±»ä¼¼äºSpringçApplicationContextï¼è¿äºå ±äº«èµæºå æ¬ // * WSDl管çå¨ãç»å®å·¥åçãéè¿å¯¹BUSè¿è¡æ©å±ï¼å¯ä»¥æ¹ä¾¿å°å®¹çº³èªå·±çèµæºï¼æè æ¿æ¢ç°æçèµæºãé»è®¤Buså®ç°åºäºSpringæ¶æï¼ // * éè¿ä¾èµæ³¨å ¥ï¼å¨è¿è¡æ¶å°ç»ä»¶ä¸²èèµ·æ¥ãBusFactoryè´è´£Busçå建ãé»è®¤çBusFactoryæ¯SpringBusFactoryï¼å¯¹åºäºé»è®¤ // * çBuså®ç°ã卿é è¿ç¨ä¸ï¼SpringBusFactoryä¼æç´¢META-INF/cxfï¼å å«å¨ CXF çjarä¸ï¼ä¸çææbeané ç½®æä»¶ã // * æ ¹æ®è¿äºé ç½®æä»¶æå»ºä¸ä¸ªApplicationContextãå¼åè ä¹å¯ä»¥æä¾èªå·±çé ç½®æä»¶æ¥å®å¶Busã // */ // @Bean(name = Bus.DEFAULT_BUS_ID) // public SpringBus springBus() { // return new SpringBus(); // } // // /** // * æ¤æ¹æ³ä½ç¨æ¯æ¹å项ç®ä¸æå¡åçåç¼åï¼æ¤å¤127.0.0.1æè localhostä¸è½è®¿é®æ¶ï¼è¯·ä½¿ç¨ipconfigæ¥çæ¬æºipæ¥è®¿é® // * æ¤æ¹æ³è¢«æ³¨éå, å³ä¸æ¹ååç¼å(é»è®¤æ¯services), wsdl访é®å°å为 http://127.0.0.1:8080/services/ws/api?wsdl // * å»ææ³¨éåwsdl访é®å°å为ï¼http://127.0.0.1:8080/soap/ws/api?wsdl // * http://127.0.0.1:8080/soap/ååºæå¡å表 æ http://127.0.0.1:8080/soap/ws/api?wsdl æ¥çå®é çæå¡ // * æ°å»ºServletè®°å¾éè¦å¨å¯å¨ç±»æ·»å 注解ï¼@ServletComponentScan // * // * 妿å¯å¨æ¶åºç°é误ï¼not loaded because DispatcherServlet Registration found non dispatcher servlet dispatcherServlet // * å¯è½æ¯springbootä¸cfxçæ¬ä¸å ¼å®¹ã // * åæ¶å¨spring boot2.0.6ä¹åççæ¬ä¸xcféæï¼ä¸éè¦å¨å®ä¹ä»¥ä¸æ¹æ³ï¼ç´æ¥å¨application.propertiesé ç½®æä»¶ä¸æ·»å ï¼ // * cxf.path=/serviceï¼é»è®¤æ¯servicesï¼ // */ // //@Bean // //public ServletRegistrationBean dispatcherServlet() { // // return new ServletRegistrationBean(new CXFServlet(), "/soap/*"); // //} // // @Bean // public Endpoint endpoint() { // EndpointImpl endpoint = new EndpointImpl(springBus(), dncWebService); // endpoint.publish("/ws/dnc"); // return endpoint; // } //} src/main/java/com/lxzn/framework/domain/webservice/request/ThirdDeProgramSource.java
¶Ô±ÈÐÂÎļþ @@ -0,0 +1,89 @@ package com.lxzn.framework.domain.webservice.request; import com.baomidou.mybatisplus.annotation.*; import lombok.Data; import org.apache.commons.io.FilenameUtils; import java.io.Serializable; import java.util.ArrayList; import java.util.List; import java.util.Map; /** * éæ3DE * @author clown * * @date 2022/9/19 */ @Data public class ThirdDeProgramSource implements Serializable { @TableId(value = "id") private String id; /*é¶ä»¶åç§°*/ @TableField(value = "part_name") private String partName; /*é¶ä»¶å¾å·*/ @TableField(value = "part_no") private String partNo; /*çæ¬å·(å·¥èºè§ç¨çæ¬å·)*/ @TableField(value = "revision_no") private String revisionNo; /*车é´åç§°*/ @TableField(value = "nc_plant_name") private String ncPlantName; /*车é´ç¼å·*/ @TableField(value = "nc_plant_no") private String ncPlantNo; /*å·¥åºç¼å·*/ @TableField(value = "skgx_id") private String skgxId; /*å·¥åºåç§°*/ @TableField(value = "skgx_name") private String skgxName; /*æºåºåå· nc_jcid*/ @TableField(value = "nc_jcid") private String ncJcid; /*æºåºæä½ç³»ç»*/ @TableField(value = "nc_os") private String ncOs; /*设å¤ç¼å·*/ @TableField(value = "equipment_id") private String equipmentId; /*ç¨åºæä»¶åï¼å¯è½å¤ä¸ªï¼*/ @TableField(value = "nc_file_name") private String ncFileName; private transient Map<String, byte[]> ncFiles; // ä¿®å¤æä»¶åæ®µå®ä¹ private List<FileInfo> files; // æ·»å æä»¶ä¿¡æ¯ç±» @Data public static class FileInfo { private String file_name; // æ·»å å ¶ä»å¯è½å段 private String file_type; private Long file_size; } // æ·»å æä»¶è·¯å¾ååç§°åæ®µ private String filePath; private String fileName; // æ·»å 设置NCæä»¶çæ¹æ³ public void setNcFiles(Map<String, byte[]> ncFiles) { this.ncFiles = ncFiles; this.files = new ArrayList<>(); for (Map.Entry<String, byte[]> entry : ncFiles.entrySet()) { FileInfo fileInfo = new FileInfo(); fileInfo.setFile_name(entry.getKey()); fileInfo.setFile_size((long) entry.getValue().length); fileInfo.setFile_type(FilenameUtils.getExtension(entry.getKey())); this.files.add(fileInfo); } } } src/main/java/com/lxzn/nc/service/IDocRelativeService.java
@@ -47,4 +47,14 @@ * @return */ List<DeviceInfo> findDeviceByDocId(String docId); /** * æ¥è¯¢å ³èå ³ç³» * @param docId * @param classificationId * @param attributionType * @param attributionId * @return */ DocRelative findDocRelative(String docId, String classificationId, Integer attributionType, String attributionId); } src/main/java/com/lxzn/nc/service/impl/DocRelativeServiceImpl.java
@@ -157,4 +157,22 @@ ExceptionCast.cast(CommonCode.INVALID_PARAM); return super.getBaseMapper().findDeviceByDocId(docId); } /** * æ¥è¯¢å ³èå ³ç³» * @param docId * @param classificationId * @param attributionType * @param attributionId * @return */ @Override public DocRelative findDocRelative(String docId, String classificationId, Integer attributionType, String attributionId){ LambdaQueryWrapper<DocRelative> lambdaQueryWrapper = Wrappers.lambdaQuery(); lambdaQueryWrapper.eq(DocRelative::getDocId, docId); lambdaQueryWrapper.eq(DocRelative::getAttributionType, attributionType); lambdaQueryWrapper.eq(DocRelative::getAttributionId, attributionId); lambdaQueryWrapper.eq(DocRelative::getClassificationId, classificationId); return super.getOne(lambdaQueryWrapper); } } src/main/java/com/lxzn/webservice/DncWebService.java
@@ -3,6 +3,7 @@ import com.lxzn.framework.domain.webservice.PlmProgramSourceInfo; import com.lxzn.framework.domain.webservice.ProcedureFinish; import com.lxzn.framework.domain.webservice.request.PlmProgramSource; import com.lxzn.framework.domain.webservice.request.ThirdDeProgramSource; import com.lxzn.webservice.ext.MesResultModel; import javax.jws.WebMethod; @@ -14,7 +15,7 @@ * @CreateTime: 2025-02-27 * @Description: */ @WebService(name = "DncWebService", targetNamespace = "http://lxzn.webservice.com") //@WebService(name = "DncWebService", targetNamespace = "http://lxzn.webservice.com") public interface DncWebService { /** @@ -26,32 +27,20 @@ @WebMethod MesResultModel syncPlmNcLogProgram(@WebParam(name = "msg") String msg); public MesResultModel setTree(PlmProgramSource plmProgramSource); /** * NCç¨åºé½å¥æ¥å£ï¼MESï¼-DNCç³»ç»æ¥æ¶å°PLMä¼ çNCç¨åºï¼å°ç¨åºå 对åºçé¶ä»¶å·ãå·¥åºå·ã设å¤ç¼å·ä¼ ç»MESç³»ç» * 宿¶æ«æPlmProgramSourceInfo表ä¸çæ°æ®ï¼è¿è¡æ°æ®åæ¥ï¼æ¯åé忥䏿¬¡ * éæPLMææ * @param plmProgramSource * @return */ void syncWorkmanship(); public MesResultModel setPlmTree(PlmProgramSource plmProgramSource); /** * 派工任å¡ä¸åæ¥å£(MES) * * @param msg * éæ3DEææ * @param thirdDeProgramSource * @return */ @WebMethod String issuedDispatchTask(@WebParam(name = "msg") String msg); public MesResultModel processThirdDEProgram(ThirdDeProgramSource thirdDeProgramSource); /** * å®å·¥æ¥å£(MES) * * @param msg * @return */ @WebMethod String issuedProcedureFinish(@WebParam(name = "msg") String msg); String readFileName(String itemCode); String readFileName(String itemCode); } src/main/java/com/lxzn/webservice/controller/DncWebController.java
@@ -1,11 +1,14 @@ package com.lxzn.webservice.controller; import com.lxzn.framework.domain.webservice.request.ThirdDeProgramSource; import com.lxzn.framework.domain.webservice.request.PlmProgramSource; import com.lxzn.webservice.DncWebService; import com.lxzn.webservice.ext.MesResultModel; import lombok.extern.slf4j.Slf4j; import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; import org.apache.commons.compress.archivers.zip.ZipFile; import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.IOUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.transaction.annotation.Transactional; @@ -17,7 +20,6 @@ import java.nio.charset.StandardCharsets; import java.nio.file.*; import java.util.*; import java.util.stream.Collectors; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; @@ -29,16 +31,22 @@ @Autowired private DncWebService dncWebService; @Value("${ncPdm.file_path}") @Value("${fileHomePath}") private String filePath; // å®ä¹å ³é®æä»¶ç±»å private static final String INNER_ZIP_PREFIX = "ãå ¬å¼ãNCç¨åºæä»¶ "; private static final String JSON_EXT = ".json"; private static final String TXT_EXT = ".txt"; /** * éæplmæ°æ®ï¼å缩å ï¼é颿¯NCå缩å ä¸JSONæä»¶ï¼ * @param file * @return */ @PostMapping(value = "/syncPlmNcLogProgram", consumes = "multipart/form-data") @Transactional public String processNcPackage(MultipartFile file) { Path workDir = null; try { if (file == null || file.isEmpty()) { log.error("æ¥æ¶å°çå缩æä»¶ä¸ºç©º"); @@ -47,7 +55,7 @@ // å建临æ¶ç®å½ String timestamp = String.valueOf(System.currentTimeMillis()); Path workDir = Paths.get(filePath, timestamp); workDir = Paths.get(filePath, "plm_" + timestamp); Files.createDirectories(workDir); // ä¿ååå§æä»¶ @@ -92,7 +100,6 @@ for (Map.Entry<String, byte[]> entry : ncFiles.entrySet()) { String fileName = entry.getKey(); if (allNcFiles.containsKey(fileName)) { // ä¿®æ¹ç¹5ï¼è®°å½éå¤è¦åï¼å®é ä¸å¡ä¸å¯è½éè¦æ´ä¸¥æ ¼å¤çï¼ log.warn("æ£æµå°éå¤NCæä»¶å: {}", fileName); } allNcFiles.put(fileName, entry.getValue()); @@ -108,19 +115,183 @@ // ä¸å¡å¤ç return JSONObject.toJSONString( dncWebService.setTree(plmPrograms) dncWebService.setPlmTree(plmPrograms) ); } catch (Exception e) { log.error("å¤çNCæä»¶å 失败", e); return MesResultModel.error("æä»¶å¤ç失败: " + e.getMessage()); } finally { // æ¸ çä¸´æ¶æä»¶ if (workDir != null) { deleteDirectory(workDir.toFile()); } } } /** * éæ3DEæ°æ®,å缩å ï¼å个å缩å å å«å¤ä¸ªNCæä»¶ãä¸ä¸ªå·¥èºæ°æ®.TXTï¼ * @param file ä¸ä¼ çåç¼©å æä»¶ * @return å¤çç»æ */ @PostMapping(value = "/integration3DEData", consumes = "multipart/form-data") @Transactional public String integration3DEData(MultipartFile file) { Path workDir = null; try { if (file == null || file.isEmpty()) { log.error("æ¥æ¶å°ç3DEå缩æä»¶ä¸ºç©º"); return MesResultModel.error("æ¥æ¶å°ç3DEå缩æä»¶ä¸ºç©º"); } // å建临æ¶å·¥ä½ç®å½ String timestamp = String.valueOf(System.currentTimeMillis()); workDir = Paths.get(filePath, "3de_" + timestamp); Files.createDirectories(workDir); // ä¿ååå§æä»¶ Path originalPath = workDir.resolve( Objects.requireNonNull(file.getOriginalFilename()) ); Files.copy(file.getInputStream(), originalPath, StandardCopyOption.REPLACE_EXISTING); log.info("3DEåå§æä»¶å·²ä¿å: {} (大å°: {} åè)", originalPath, Files.size(originalPath)); // è§£åZIPå è·åæææä»¶ Map<String, byte[]> packageContents = extractOuterZipContents(originalPath); log.info("3DEå缩å è§£ææåï¼å å« {} 个æä»¶", packageContents.size()); // æ¥æ¾å·¥èºæ°æ®TXTæä»¶ byte[] processData = findFileByExtension(packageContents, TXT_EXT); if (processData == null) { return MesResultModel.error("æªæ¾å°å·¥èºæ°æ®TXTæä»¶"); } // è§£æå·¥èºæ°æ®TXTæä»¶ ThirdDeProgramSource thirdDeProgramSource = parseProcessTxtFile(processData); if (thirdDeProgramSource == null) { return MesResultModel.error("è§£æå·¥èºæ°æ®TXTæä»¶å¤±è´¥"); } // æåææNCæä»¶ Map<String, byte[]> ncFiles = extractNcFiles(packageContents); if (ncFiles.isEmpty()) { return MesResultModel.error("æªæ¾å°NCç¨åºæä»¶"); } log.info("æ¾å° {} 个NCç¨åºæä»¶", ncFiles.size()); // 设置NCæä»¶éååæä»¶è·¯å¾ä¿¡æ¯ thirdDeProgramSource.setNcFiles(ncFiles); thirdDeProgramSource.setFilePath(workDir.toString()); thirdDeProgramSource.setFileName(originalPath.getFileName().toString()); // è°ç¨æå¡å¤ç3DEæ°æ® return JSONObject.toJSONString( dncWebService.processThirdDEProgram(thirdDeProgramSource) ); } catch (Exception e) { log.error("å¤ç3DEæ°æ®å 失败", e); return MesResultModel.error("3DEæä»¶å¤ç失败: " + e.getMessage()); } finally { // æ¸ çä¸´æ¶æä»¶ if (workDir != null) { deleteDirectory(workDir.toFile()); } } } /** * è§£æå·¥èºæ°æ®TXTæä»¶ * @param txtData TXTæä»¶å 容 * @return ThirdDeProgramSource对象 */ private ThirdDeProgramSource parseProcessTxtFile(byte[] txtData) { try { String content = new String(txtData, StandardCharsets.UTF_8); log.info("å·¥èºæ°æ®TXTå 容:\n{}", content); // 使ç¨FastJSONè§£æJSONæ ¼å¼çTXT JSONObject json = JSONObject.parseObject(content); if (json == null) { log.error("è§£æå·¥èºæ°æ®å¤±è´¥: 䏿¯ææçJSONæ ¼å¼"); return null; } // åå»ºå¯¹è±¡å¹¶è®¾ç½®å±æ§ ThirdDeProgramSource programSource = new ThirdDeProgramSource(); programSource.setPartName(json.getString("part_name")); programSource.setPartNo(json.getString("part_no")); programSource.setRevisionNo(json.getString("revision_no")); programSource.setSkgxId(json.getString("skgx_id")); programSource.setSkgxName(json.getString("skgx_name")); programSource.setNcJcid(json.getString("nc_jcid")); programSource.setNcOs(json.getString("nc_os")); programSource.setEquipmentId(json.getString("equipment_id")); programSource.setNcFileName(json.getString("nc_file_name")); programSource.setNcPlantNo(json.getString("nc_plant_no")); programSource.setNcPlantName(json.getString("nc_plant_name")); log.debug("è§£æçå·¥èºæ°æ®: partName={}, partNo={}, revisionNo={}, skgxId={}, skgxName={}, " + "ncJcid={}, ncOs={}, equipmentId={}, ncFileName={}, ncPlantNo={}, ncPlantName={}", programSource.getPartName(), programSource.getPartNo(), programSource.getRevisionNo(), programSource.getSkgxId(), programSource.getSkgxName(), programSource.getNcJcid(), programSource.getNcOs(), programSource.getEquipmentId(), programSource.getNcFileName(), programSource.getNcPlantNo(), programSource.getNcPlantName()); return programSource; } catch (Exception e) { log.error("è§£æå·¥èºæ°æ®TXTæä»¶å¤±è´¥", e); return null; } } /** * è§£æé®å¼å¯¹æ ¼å¼çTXTæä»¶ * @param content TXTæä»¶å 容 * @return é®å¼å¯¹æ å° */ private Map<String, String> parseKeyValueTxt(String content) { Map<String, String> result = new HashMap<>(); String[] lines = content.split("\\r?\\n"); for (String line : lines) { line = line.trim(); if (line.isEmpty() || line.startsWith("#") || line.startsWith("//")) { continue; // è·³è¿ç©ºè¡å注é } int separatorIndex = line.indexOf('='); if (separatorIndex > 0) { String key = line.substring(0, separatorIndex).trim(); String value = line.substring(separatorIndex + 1).trim(); result.put(key, value); } } return result; } /** * 仿件å 容䏿åNCæä»¶ * @param packageContents å å 容æ å° * @return NCæä»¶æ å° */ private Map<String, byte[]> extractNcFiles(Map<String, byte[]> packageContents) { Map<String, byte[]> ncFiles = new HashMap<>(); for (Map.Entry<String, byte[]> entry : packageContents.entrySet()) { String fileName = entry.getKey(); String fileExt = FilenameUtils.getExtension(fileName).toLowerCase(); if (fileExt.equals("nc")) { ncFiles.put(fileName, entry.getValue()); log.debug("æ¾å°NCæä»¶: {}", fileName); } } return ncFiles; } // ä¼ååçè§£åæ¹æ³ï¼ä½¿ç¨commons-compressï¼ private Map<String, byte[]> extractOuterZipContents(Path filePath) throws IOException { Map<String, byte[]> contents = new HashMap<>(); log.info("å¼å§è§£æZIPæä»¶: {}", filePath); try { try (ZipFile zipFile = new ZipFile(filePath.toFile())) { log.info("ZIPæä»¶æ ¼å¼æ£æµ: {}", zipFile.getEncoding()); @@ -131,17 +302,9 @@ if (entry.isDirectory()) continue; try (InputStream is = zipFile.getInputStream(entry)) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); byte[] buffer = new byte[8192]; int len; while ((len = is.read(buffer)) > 0) { baos.write(buffer, 0, len); } // ä¿çåå§æä»¶å String name = entry.getName(); contents.put(name, baos.toByteArray()); log.debug("æåæä»¶: {} ({} åè)", name, baos.size()); byte[] data = IOUtils.toByteArray(is); contents.put(entry.getName(), data); log.debug("æåæä»¶: {} ({} åè)", entry.getName(), data.length); } } } @@ -175,14 +338,15 @@ private List<byte[]> findAllFilesByExtension(Map<String, byte[]> contents, String extension) { String extLower = extension.toLowerCase(); return contents.entrySet().stream() .filter(e -> { String fileName = e.getKey(); // 使ç¨å°åæ¯è¾é¿å 大å°åææé®é¢ return fileName.toLowerCase().endsWith(extLower); }) .map(Map.Entry::getValue) .collect(Collectors.toList()); List<byte[]> result = new ArrayList<>(); for (Map.Entry<String, byte[]> entry : contents.entrySet()) { String fileName = entry.getKey().toLowerCase(); if (fileName.endsWith(extLower)) { result.add(entry.getValue()); } } return result; } // å é¨ZIPè§£ææ¹æ³ @@ -213,57 +377,25 @@ * æ ¹æ®æ©å±åæ¥æ¾æä»¶ */ private byte[] findFileByExtension(Map<String, byte[]> contents, String extension) { return contents.entrySet().stream() .filter(e -> e.getKey().toLowerCase().endsWith(extension)) .map(Map.Entry::getValue) .findFirst() .orElse(null); String extLower = extension.toLowerCase(); for (Map.Entry<String, byte[]> entry : contents.entrySet()) { if (entry.getKey().toLowerCase().endsWith(extLower)) { return entry.getValue(); } } return null; } /** * è·åæä»¶åï¼æ ¹æ®æ©å±åï¼ */ private String getFileNameByExtension(Map<String, byte[]> contents) { return contents.keySet().stream() .filter(k -> k.toLowerCase().endsWith(DncWebController.JSON_EXT)) .findFirst() .orElse("Unknown"); } /** * æ¥æ¾ä¸æå®åç¼å¹é çæä»¶å 容 * @param contents æä»¶å 容æ å°ï¼æä»¶å -> æä»¶å å®¹ï¼ * @param prefix è¦å¹é çæä»¶ååç¼ * @return å¹é ç第ä¸ä¸ªæä»¶å å®¹ï¼æªæ¾å°è¿å null */ private byte[] findFileByPrefix(Map<String, byte[]> contents, String prefix) { if (prefix == null || prefix.isEmpty()) { log.warn("æä»¶åç¼ä¸è½ä¸ºç©º"); return null; for (String key : contents.keySet()) { if (key.toLowerCase().endsWith(JSON_EXT)) { return key; } } return contents.entrySet().stream() .filter(entry -> { String fileName = entry.getKey(); // è·¯å¾è§èåå¤ç String normalizedKey = fileName.replace('\\', '/'); // è·å纯æä»¶å int lastSlash = normalizedKey.lastIndexOf('/'); String pureFileName = (lastSlash >= 0) ? normalizedKey.substring(lastSlash + 1) : normalizedKey; // è°è¯æ¥å¿ log.debug("æ£æ¥æä»¶: [åå§: {}], [纯æä»¶å: {}], åç¼: {}", fileName, pureFileName, prefix); return pureFileName.contains("NC"); }) .map(Map.Entry::getValue) .findFirst() .orElse(null); return "Unknown"; } /** @@ -274,4 +406,26 @@ return JSONObject.parseObject(json, PlmProgramSource.class); } /** * éå½å é¤ç®å½ */ private void deleteDirectory(File directory) { if (!directory.exists()) return; File[] files = directory.listFiles(); if (files != null) { for (File file : files) { if (file.isDirectory()) { deleteDirectory(file); } else { if (!file.delete()) { log.warn("æ æ³å 餿件: {}", file.getAbsolutePath()); } } } } if (!directory.delete()) { log.warn("æ æ³å é¤ç®å½: {}", directory.getAbsolutePath()); } } } src/main/java/com/lxzn/webservice/impl/DncWebServiceImpl.java
@@ -8,14 +8,14 @@ import com.baomidou.mybatisplus.core.toolkit.IdWorker; import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.lxzn.activiti.service.IAssignFileStreamService; import com.lxzn.framework.domain.activiti.response.ActivitiCode; import com.lxzn.framework.domain.filesystem.response.FileUploadResult; import com.lxzn.framework.domain.nc.*; import com.lxzn.framework.domain.nc.response.DocumentCode; import com.lxzn.framework.domain.webservice.DispatchInfo; import com.lxzn.framework.domain.webservice.PlmProgramSourceInfo; import com.lxzn.framework.domain.webservice.ProcedureFinish; import com.lxzn.framework.domain.webservice.request.NcProgramInfo; import com.lxzn.framework.domain.webservice.request.PlmProgramSource; import com.lxzn.framework.domain.webservice.request.*; import com.lxzn.framework.exception.ExceptionCast; import com.lxzn.framework.model.response.CommonCode; import com.lxzn.framework.utils.CxfClientUtil; @@ -24,9 +24,8 @@ import com.lxzn.framework.utils.ZipUtil; import com.lxzn.framework.utils.file.FileUtil; import com.lxzn.nc.service.*; import com.lxzn.nc.service.impl.DeviceInfoServiceImpl; import com.lxzn.webservice.DncWebService; import com.lxzn.framework.domain.webservice.request.WsDispatch; import com.lxzn.framework.domain.webservice.request.WsProcedureFinish; import com.lxzn.webservice.ext.MesResultModel; import com.lxzn.webservice.service.IDispatchInfoService; import com.lxzn.webservice.service.IPlmProgramSourceInfoService; @@ -62,40 +61,12 @@ * @Description: */ @Service @WebService(name = "DncWebService", targetNamespace = "http://lxzn.webservice.com", endpointInterface = "com.lxzn.webservice.DncWebService" ) //@WebService(name = "DncWebService", // targetNamespace = "http://lxzn.webservice.com", // endpointInterface = "com.lxzn.webservice.DncWebService" //) @Slf4j public class DncWebServiceImpl implements DncWebService { @Value("${ncPdm.file_path}") private String filePath; /** * url */ @Value("${webservice.url}") private String url; /** * namespace */ @Value("${webservice.namespace}") private String namespace; /** * method */ @Value("${webservice.method}") private String method; @Resource private IDispatchInfoService dispatchInfoService; @Resource private IProcedureFinishService procedureFinishService; @Resource private IDeviceInfoService deviceInfoService; @Resource private IAssignFileStreamService assignFileStreamService; @Resource private IPlmProgramSourceInfoService iPlmProgramSourceInfoService; @Autowired @@ -126,112 +97,10 @@ private IDocClassificationService docClassificationService; @Autowired private IDeviceManagementService deviceManagementService; /** * 派工任å¡ä¸åæ¥å£ * @param msg * @return */ @Override public String issuedDispatchTask(@WebParam(name = "msg") String msg){ log.info("MES派工任å¡ä¸ååå§æ°æ® === {}", msg); List<WsDispatch> wsDispatchList = JSONObject.parseArray(msg, WsDispatch.class); for (WsDispatch wsDispatch : wsDispatchList) { DispatchInfo dispatchInfo = new DispatchInfo(); BeanUtils.copyProperties(wsDispatch, dispatchInfo); dispatchInfoService.save(dispatchInfo); Map<Boolean,String> ncResult = disPatchTaskNc(dispatchInfo); if (ncResult.containsKey(false)) { // è¿åå ·ä½çéè¯¯ä¿¡æ¯ return MesResultModel.error("NCä»»å¡ä¸å失败: " + ncResult.get(false)); } } return MesResultModel.success("æå"); } /** * ä¸åç¨åº */ public Map<Boolean,String> disPatchTaskNc(DispatchInfo dispatchInfo) { String processCode = dispatchInfo.getOperationSeqNo() + "_" + dispatchInfo.getEquipmentId(); return assignFileStreamService.disPatchTaskNc(dispatchInfo.getEquipmentId(), dispatchInfo.getWorkshop(),dispatchInfo.getMdsItemCode(),processCode,dispatchInfo.getRevisionNo(),dispatchInfo.getId()); } /** * å®å·¥ * * @param msg * @return */ @Override public String issuedProcedureFinish(String msg) { log.info("MESå®å·¥åå§æ°æ® === {}", msg); List<WsProcedureFinish> wsProcedureFinishList = JSONObject.parseArray(msg, WsProcedureFinish.class); if (CollectionUtils.isEmpty(wsProcedureFinishList)) { return MesResultModel.error("MesResultModel"); } List<ProcedureFinish> procedureFinishList = wsProcedureFinishList.stream() .map(source -> { ProcedureFinish target = new ProcedureFinish(); BeanUtils.copyProperties(source, target); return target; }) .collect(Collectors.toList()); procedureFinishService.saveBatch(procedureFinishList); //DNCç³»ç»ä¾æ®å·¥åå·å é¤è®¾å¤ç»ææ ä¸å¯¹åºçNCç¨åºåå·¥æ§ç½NCç¨åº for (ProcedureFinish procedureFinish : procedureFinishList) { //DNCç³»ç»ä¾æ®å·¥åå·å é¤è®¾å¤ç»ææ ä¸å¯¹åºçNCç¨åºåå·¥æ§ç½NCç¨åº if (procedureFinish.getEndineStatus().equals("3")){ //å é¤è®¾å¤ç»ææ ä¸å¯¹åºçNCç¨åºåå·¥æ§ç½NCç¨åº ProductInfo productInfo = productInfoService.getByProductNo("PLM"); if (productInfo == null) { log.error("======= 产åå±çº§å¼å¸¸,请èç³»å¼å人å======="); return MesResultModel.error("产åå±çº§å¼å¸¸,请èç³»å¼å人å"); } List<ComponentInfo> componentInfoList = componentInfoService.getByProductId(productInfo.getProductId()); List<String > comlist = new ArrayList<>(); if (componentInfoList != null && !componentInfoList.isEmpty()) { for (ComponentInfo cc : componentInfoList) { comlist.add(cc.getComponentId()); } } else { return MesResultModel.error("æ é¨ä»¶ä¿¡æ¯,请èç³»å¼å人å"); } String processCode=procedureFinish.getMdsItemCode(); PartsInfo part = partsInfoService.getByCodeAndComIdList(procedureFinish.getMdsItemCode(),comlist); if (part == null) { return MesResultModel.error("æ æ¤é¶ä»¶ä¿¡æ¯"+"__" + processCode+",请èç³»å¼å人å"); } processCode = processCode.split("_")[0]; //å·¥åº ProcessStream stream = processStreamService.findByProcessEquipment(procedureFinish.getEquipmentId(), processCode,procedureFinish.getRevisionNo(),productInfo.getProductId(),part.getPartsId()); if (stream == null) { return MesResultModel.error("æ æ¤å·¥åºä¿¡æ¯"+"__" + processCode+",请èç³»å¼å人å"); } //æ¥è¯¢å¯¹åºNCç¨åº List<ProcessStream> processStreamList = new ArrayList<>(); processStreamList.add(stream); List<DocInfo> docFileList = docInfoService.getByProcessIds(processStreamList); if (docFileList == null || docFileList.isEmpty()) { return MesResultModel.error("æ æ¤NCç¨åº" + "__" + processCode + ",请èç³»å¼å人å"); } docFileList.forEach(docFile -> { docInfoService.deleteDocInfo(docFile.getDocId()); }); } } log.info("æ¥æ¶MESå®å·¥åå§æ°æ®æåï¼"); return MesResultModel.success("æå"); } @Autowired private DeviceInfoServiceImpl deviceInfoService; @Autowired private IDeviceGroupService deviceGroupService; /** * è·åNCæä»¶å屿§ä¿¡æ¯(éæPLM) * @@ -246,7 +115,7 @@ List<PlmProgramSource> plmProgramSourceList = JSONObject.parseArray(msg, PlmProgramSource.class); AtomicReference<MesResultModel> mesResultModel= new AtomicReference<>(new MesResultModel()); plmProgramSourceList.forEach(item -> { mesResultModel.set(setTree(item)); mesResultModel.set(setPlmTree(item)); }); return mesResultModel.get(); } @@ -262,7 +131,7 @@ * @param plmProgramSource * @return */ public MesResultModel setTree(PlmProgramSource plmProgramSource) { public MesResultModel setPlmTree(PlmProgramSource plmProgramSource) { MesResultModel model = new MesResultModel(); model.setSuccFlag("æå"); PlmProgramSourceInfo plmProgramSourceInfo = new PlmProgramSourceInfo(); @@ -485,76 +354,407 @@ return model; } /** * å°è£ æ ç»æ * 1. 产å éææ°æ® * 2ãé¨ä»¶ æç §é¨é¨ï¼è½¦é´ nc_plant_name ï¼ç»´åº¦å»ºç« * 3ãé¶ä»¶ å¾å·ï¼é¶ä»¶å·ãé¶ä»¶åç§°ï¼ part_no * 4ãå·¥åº å·¥èºIDï¼å·¥èºè§ç¨ç¼å·/临è§ç¼å·ï¼ * 5. ncæä»¶ ï¼å·¥åºä¸ï¼ * 6.æºåºåå·ä¸æºåºæä½ç³»ç»ç»æè®¾å¤ç±»ä¸å·¥åºè¿è¡ç»å® * éæ3DEææ * @param thirdDeProgramSource * @return */ @Override @Transactional public MesResultModel processThirdDEProgram(ThirdDeProgramSource thirdDeProgramSource) { MesResultModel model = new MesResultModel(); model.setSuccFlag("æå"); try { log.info("3DE NCæä»¶å屿§ä¿¡æ¯åå§æ°æ® === {}", JSONObject.toJSONString(thirdDeProgramSource)); // 产å - 使ç¨é»è®¤ç3DE产å ProductInfo productInfo = productInfoService.getByProductNo("3DE"); if (productInfo == null) { return createErrorModel(model, "3DE产åå±çº§å¼å¸¸,请èç³»å¼å人å"); } // é¨ä»¶ - æç §è½¦é´ç»´åº¦å»ºç« ComponentInfo componentInfo = componentInfoService.getByCode(thirdDeProgramSource.getNcPlantNo()); if (componentInfo == null) { componentInfo = new ComponentInfo(); componentInfo.setComponentId(IdWorker.getIdStr()); componentInfo.setComponentCode(thirdDeProgramSource.getNcPlantNo()); componentInfo.setComponentName(thirdDeProgramSource.getNcPlantName()); componentInfo.setComponentStatus(1); componentInfo.setRankLevel(1); componentInfo.setParentId(productInfo.getProductId()); componentInfo.setProductId(productInfo.getProductId()); if (!componentInfoService.save(componentInfo)) { return createErrorModel(model, "æ·»å 3DEé¨ä»¶å±çº§å¤±è´¥,请èç³»å¼å人å"); } if (!savePermissionList(componentInfo, productInfo.getProductId())) { return createErrorModel(model, "æ·»å 3DEé¨ä»¶æé失败,请èç³»å¼å人å"); } } // é¶ä»¶ - å¾å·ï¼é¶ä»¶å·ãé¶ä»¶åç§°ï¼ PartsInfo partsInfo = partsInfoService.getByCode(thirdDeProgramSource.getPartNo()); if (partsInfo == null) { partsInfo = new PartsInfo(); partsInfo.setPartsId(IdWorker.getIdStr()); partsInfo.setComponentId(componentInfo.getComponentId()); partsInfo.setProductId(productInfo.getProductId()); partsInfo.setPartsStatus(1); partsInfo.setPartsCode(thirdDeProgramSource.getPartNo()); partsInfo.setPartsName(thirdDeProgramSource.getPartName()); partsInfo.setPartsModel(thirdDeProgramSource.getPartNo()); if (!partsInfoService.save(partsInfo)) { return createErrorModel(model, "æ·»å 3DEé¶ä»¶å±çº§å¤±è´¥,请èç³»å¼å人å"); } // æ·»å é¶ä»¶æé if (!savePartsPermission(partsInfo, productInfo.getProductId())) { return createErrorModel(model, "æ·»å 3DEé¶ä»¶æé失败,请èç³»å¼å人å"); } } // å·¥åº - å·¥èºIDï¼å·¥èºè§ç¨ç¼å·/临è§ç¼å·ï¼ ProcessStream processStream = processStreamService.findByProcessNoAndPartsId( thirdDeProgramSource.getSkgxId(), partsInfo.getPartsId()); List<ProcessStream> addProcessList = new ArrayList<>(); List<ProcessStream> updateProcessList = new ArrayList<>(); if (processStream == null) { processStream = new ProcessStream(); processStream.setProcessId(IdWorker.getIdStr()); processStream.setProductId(productInfo.getProductId()); processStream.setComponentId(componentInfo.getComponentId()); processStream.setPartsId(partsInfo.getPartsId()); processStream.setProcessCode(thirdDeProgramSource.getSkgxId()); processStream.setProcessName(thirdDeProgramSource.getSkgxName()); processStream.setCraftVersion(thirdDeProgramSource.getRevisionNo()); // 设置工èºçæ¬ // 设å¤ä¿¡æ¯å¤ç DeviceManagement deviceManagement = deviceManagementService.findEquipmentIdsFromEqId( thirdDeProgramSource.getNcPlantName(), thirdDeProgramSource.getEquipmentId()); if (deviceManagement != null && StringUtils.isNotEmpty(deviceManagement.getEquipmentIds())) { processStream.setProcessingEquipmentCode(deviceManagement.getEquipmentIds()); } else { processStream.setProcessingEquipmentCode(thirdDeProgramSource.getEquipmentId()); } processStream.setProcessingEquipmentOs(thirdDeProgramSource.getNcOs()); processStream.setProcessingEquipmentModel(thirdDeProgramSource.getNcJcid()); addProcessList.add(processStream); } else { // æ´æ°æ¶æ£æ¥çæ¬æ¯å¦åæ´ if (!Objects.equals(processStream.getCraftVersion(), thirdDeProgramSource.getRevisionNo())) { processStream.setCraftVersion(thirdDeProgramSource.getRevisionNo()); } processStream.setProcessName(thirdDeProgramSource.getSkgxName()); updateProcessList.add(processStream); } if (!addProcessList.isEmpty() && !processStreamService.saveBatch(addProcessList)) { return createErrorModel(model, "æ·»å 3DEå·¥åºå¤±è´¥,请èç³»å¼å人å"); } if (!updateProcessList.isEmpty() && !processStreamService.updateBatchById(updateProcessList)) { return createErrorModel(model, "æ´æ°3DEå·¥åºå¤±è´¥,请èç³»å¼å人å"); } // ææ¡£åç±» DocClassification ncDocClass = docClassificationService.getByCode("NC"); if (ncDocClass == null) { return createErrorModel(model, "NCææ¡£åç±»ä¸åå¨,请èç³»å¼å人å"); } // sendææ¡£åç±» DocClassification sendDocClass = docClassificationService.getByCode("SEND"); if (sendDocClass == null) { return createErrorModel(model, "SENDææ¡£åç±»ä¸åå¨,请èç³»å¼å人å"); } // å¤çNCæä»¶ if (thirdDeProgramSource.getNcFiles() != null && !thirdDeProgramSource.getNcFiles().isEmpty()) { for (Map.Entry<String, byte[]> entry : thirdDeProgramSource.getNcFiles().entrySet()) { String fileName = entry.getKey(); byte[] fileContent = entry.getValue(); String suffix = FileUtil.getFileSuffix(fileName); String baseName = FileUtil.getFilenameNonSuffix(fileName); // æ¥æ¾ç°æææ¡£ DocInfo docInfo = docInfoService.findByAttrAndDocName(baseName, 5, processStream.getProcessId(), suffix); FileUploadResult fileUploadResult = FileUtil.uploadFileByFileNameAndFis( fileName, new ByteArrayInputStream(fileContent)); if (fileUploadResult == null) { return createErrorModel(model, "ä¸ä¼ 3DE NCæä»¶å¤±è´¥"); } boolean success; if (docInfo == null) { // æ°å¢ææ¡£ docInfo = new DocInfo(); String docId = IdWorker.getIdStr(); docInfo.setDocId(docId); docInfo.setDocName(fileUploadResult.getFileName()); docInfo.setDocSuffix(fileUploadResult.getFileSuffix()); docInfo.setDocStatus(5); // åå»ºææ¡£å ³è DocRelative docRelative = new DocRelative(); docRelative.setAttributionId(processStream.getProcessId()); docRelative.setDocId(docInfo.getDocId()); docRelative.setAttributionType(5); docRelative.setClassificationId(ncDocClass.getClassificationId()); if (!docRelativeService.save(docRelative)) { return createErrorModel(model, "å建3DEææ¡£å ³è失败"); } // ä¿åææ¡£æä»¶ if (getFile(docInfo, fileUploadResult, docFileService)) { return createErrorModel(model, "ä¿å3DEææ¡£æä»¶å¤±è´¥"); } success = docInfoService.save(docInfo); // è·åææ°ææ¡£æä»¶ DocFile docFile = docFileService.getDocFileNearest(docId); // æ·»å å°è®¾å¤ if (!linkToDevice(thirdDeProgramSource.getEquipmentId(), docInfo.getDocId(), docFile, sendDocClass)) { return createErrorModel(model, "æ·»å è®¾å¤ææ¡£å ³è失败"); } } else { // æ´æ°ææ¡£ - å¤ççæ¬æ§å¶ if (StringUtils.isNotEmpty(processStream.getCraftVersion()) && StringUtils.isNotEmpty(thirdDeProgramSource.getRevisionNo())) { // çæ¬åæ´ï¼ä¿åæ§çæ¬æä»¶ if (!Objects.equals(processStream.getCraftVersion(), thirdDeProgramSource.getRevisionNo())) { this.createFileOldNcPathAndCopyFor3DE(docInfo, thirdDeProgramSource); } } DocFile docFile = getDocFile(docInfo, fileUploadResult); success = docFileService.addDocFile(docFile); if (success) { docInfo.setPublishVersion(docFile.getDocVersion()); docInfo.setPublishFileId(docFile.getFileId()); success = docInfoService.updateById(docInfo); // æ´æ°è®¾å¤å ³è if (!updateDeviceLink(thirdDeProgramSource.getEquipmentId(), docInfo.getDocId(), sendDocClass)) { return createErrorModel(model, "æ´æ°è®¾å¤ææ¡£å ³è失败"); } } } if (!success) { return createErrorModel(model, "å¤ç3DE NCæä»¶å¤±è´¥"); } } } return model; } catch (Exception e) { log.error("å¤ç3DEç¨åºæ°æ®å¼å¸¸: {}", e.getMessage(), e); return createErrorModel(model, "å¤ç3DEç¨åºæ°æ®å¼å¸¸: " + e.getMessage()); } } /** * æ·»å å°è®¾å¤ */ private boolean linkToDevice(String equipmentId, String docId, DocFile docFile, DocClassification sendDocClass) { try { DeviceInfo deviceInfo = deviceInfoService.getByDeviceNo(equipmentId); if (deviceInfo == null) { log.error("DNCä¸è®¾å¤ä¸åå¨: {}", equipmentId); return false; } DocRelative deviceDocRelative = new DocRelative(); deviceDocRelative.setAttributionId(deviceInfo.getDeviceId()); deviceDocRelative.setDocId(docId); deviceDocRelative.setAttributionType(4); deviceDocRelative.setClassificationId(sendDocClass.getClassificationId()); boolean saved = docRelativeService.save(deviceDocRelative); if (!saved) { log.error("ä¿åè®¾å¤ææ¡£å ³è失败: device={}, doc={}", equipmentId, docId); return false; } // å¤å¶æä»¶å°è®¾å¤è·¯å¾ List<String> groupPaths = deviceGroupService.findListParentTreeAll(deviceInfo.getGroupId()); if (groupPaths != null && !groupPaths.isEmpty()) { String devicePath = String.join("/", groupPaths) + "/" + deviceInfo.getDeviceNo(); // å¤å¶æä»¶ boolean copySuccess = FileUtil.copyFileNc( docFile.getFilePath(), devicePath, docFile.getFileEncodeName(), docFile.getFileName(), docFile.getFileSuffix()); if (!copySuccess) { log.error("æä»¶å¤å¶å¤±è´¥: {} -> {}", docFile.getFilePath(), devicePath); return false; } // å 餿§çæ¬æä»¶ FileUtil.deleteZipFromToSend( devicePath, docFile.getFileName(), docFile.getFileSuffix()); } return true; } catch (Exception e) { log.error("æ·»å è®¾å¤ææ¡£å ³èå¼å¸¸: {}", e.getMessage(), e); return false; } } /** * æ´æ°è®¾å¤å ³è */ private boolean updateDeviceLink(String equipmentId, String docId, DocClassification sendDocClass) { try { DeviceInfo deviceInfo = deviceInfoService.getByDeviceNo(equipmentId); if (deviceInfo == null) { log.error("DNCä¸è®¾å¤ä¸åå¨: {}", equipmentId); return false; } // æ£æ¥å ³èæ¯å¦å·²åå¨ DocRelative existingRel = docRelativeService.findDocRelative(docId,sendDocClass.getClassificationId(), 4,deviceInfo.getDeviceId()); if (existingRel == null) { // å建æ°å ³è DocRelative deviceDocRelative = new DocRelative(); deviceDocRelative.setAttributionId(deviceInfo.getDeviceId()); deviceDocRelative.setDocId(docId); deviceDocRelative.setAttributionType(4); deviceDocRelative.setClassificationId(sendDocClass.getClassificationId()); return docRelativeService.save(deviceDocRelative); } return true; } catch (Exception e) { log.error("æ´æ°è®¾å¤å ³èå¼å¸¸: {}", e.getMessage(), e); return false; } } /** * 为3DEæ°æ®å建æ§çæ¬NCæä»¶å¤ä»½ */ private boolean createFileOldNcPathAndCopyFor3DE(DocInfo docInfo, ThirdDeProgramSource thirdDeProgramSource) { DocFile docFile = docFileService.getDocFileNearest(docInfo.getDocId()); if (docFile == null) { log.error("æªæ¾å°æè¿çæ¬ç3DEææ¡£æä»¶ï¼docId: {}", docInfo.getDocId()); return false; } String directoryPath = String.join(File.separator, "3de_bak", thirdDeProgramSource.getNcPlantName(), thirdDeProgramSource.getPartNo(), thirdDeProgramSource.getSkgxId(), ""); File directory = new File(directoryPath); if (!directory.exists() && !directory.mkdirs()) { log.error("å建3DEç®å½å¤±è´¥: {}", directoryPath); return false; } // æå»ºç®æ æä»¶è·¯å¾ String targetFileName = buildTargetFileName(docFile); String targetFilePath = directoryPath + targetFileName; try { Path sourcePath = Paths.get(docFile.getFilePath()); Path targetPath = Paths.get(targetFilePath); Files.copy(sourcePath, targetPath, StandardCopyOption.REPLACE_EXISTING); log.info("3DEæä»¶å¤å¶æå: {} -> {}", docFile.getFilePath(), targetFilePath); return true; } catch (IOException e) { log.error("3DEæä»¶å¤å¶å¤±è´¥: {}", e.getMessage(), e); if (directory.exists() && isDirectoryEmpty(directory)) { directory.delete(); } return false; } } /** * ä¿åé¶ä»¶æé */ private boolean savePartsPermission(PartsInfo partsInfo, String productId) { List<PermissionStream> oldPermissionList = permissionStreamService.getAllByProductId(productId); if (CollectionUtils.isEmpty(oldPermissionList)) { return true; } List<PartsDepartment> partsDepartPermList = new ArrayList<>(); List<PermissionStream> partsPermList = new ArrayList<>(); List<PartsPermission> partsUserPermList = new ArrayList<>(); for (PermissionStream p : oldPermissionList) { if (ValidateUtil.validateString(p.getUserId())) { // ç¨æ·æé PartsPermission permission = new PartsPermission(); permission.setPartsId(partsInfo.getPartsId()); permission.setUserId(p.getUserId()); partsUserPermList.add(permission); PermissionStream stream = new PermissionStream(); stream.setUserId(p.getUserId()); stream.setProductId(partsInfo.getProductId()); stream.setComponentId(partsInfo.getComponentId()); stream.setPartsId(partsInfo.getPartsId()); partsPermList.add(stream); } if (ValidateUtil.validateString(p.getDepartId())) { // é¨é¨æé PartsDepartment department = new PartsDepartment(); department.setPartsId(partsInfo.getPartsId()); department.setDepartId(p.getDepartId()); partsDepartPermList.add(department); PermissionStream stream = new PermissionStream(); stream.setProductId(partsInfo.getProductId()); stream.setComponentId(partsInfo.getComponentId()); stream.setPartsId(partsInfo.getPartsId()); stream.setDepartId(p.getDepartId()); partsPermList.add(stream); } } boolean success = true; if (!partsUserPermList.isEmpty()) { success = success && partsPermissionService.saveBatch(partsUserPermList); } if (!partsDepartPermList.isEmpty()) { success = success && partsDepartmentService.saveBatch(partsDepartPermList); } if (!partsPermList.isEmpty()) { success = success && permissionStreamService.saveBatch(partsPermList); } return success; } private MesResultModel createErrorModel(MesResultModel model, String errorMsg) { model.setSuccFlag("失败"); model.setError(errorMsg); return model; } /** * * NCç¨åºé½å¥æ¥å£ï¼MESï¼-DNCç³»ç»æ¥æ¶å°PLMä¼ çNCç¨åºï¼å°ç¨åºå 对åºçé¶ä»¶å·ãå·¥åºå·ã设å¤ç¼å·ä¼ ç»MESç³»ç» * 宿¶æ«æPlmProgramSourceInfo表ä¸çæ°æ®ï¼è¿è¡æ°æ®åæ¥ï¼æ¯åé忥䏿¬¡ */ @Scheduled(cron = "0 0/1 * * * ?") @Transactional(rollbackFor = Exception.class) public void syncWorkmanship() { // è·åææéè¦åæ¥çæ°æ® List<PlmProgramSourceInfo> plmProgramSourceInfos = iPlmProgramSourceInfoService.list( new LambdaQueryWrapper<PlmProgramSourceInfo>() .eq(PlmProgramSourceInfo::getMesStatus, "0") .orderByAsc(PlmProgramSourceInfo::getId) ); if (plmProgramSourceInfos.isEmpty()) { log.info("æ å¾ åæ¥æ°æ®ï¼è·³è¿å¤ç"); return; } List<NcProgramInfo> ncProgramInfos = plmProgramSourceInfos.stream().map(item -> { NcProgramInfo ncProgramInfo = new NcProgramInfo(); ncProgramInfo.setMdsItemCode(item.getCzkAe8nPartNo()); ncProgramInfo.setRevisionNo(item.getRevisionNo()); ncProgramInfo.setNcProgramName(item.getFileName()); ncProgramInfo.setOpreationSeqNo(item.getCzkAe8nOpNo()); ncProgramInfo.setEquipmentId(item.getCzkAe8nEquipNo()); ncProgramInfo.setWorkshop(item.getCzkAe8nDivision()); // ncProgramInfo.setMesId(item.getId()); // ç¡®ä¿çæç¬¦åè¦æ±çmesId // ncProgramInfo.setOperFlag(); return ncProgramInfo; }).collect(Collectors.toList()); log.info("WebService-NCç¨åºé½å¥æ¥å£ï¼MESï¼åæ¥å¼å§ï¼æ¶é´: {}", new Date()); try { String jsonPayload = JSONObject.toJSONString(ncProgramInfos); log.debug("䏿¥æ°æ®: {}", jsonPayload); // è°ç¨WebServiceå¹¶è·å详ç»ååº String result = CxfClientUtil.invokeService(url, jsonPayload, namespace, method); log.info("æ¥å£ååº: {}", result); // è§£æååºç»æï¼åªä¼ææåå失败 if (result.contains("æå")) { List<PlmProgramSourceInfo> toUpdate = new ArrayList<>(); plmProgramSourceInfos.forEach(item -> { item.setMesStatus("1"); toUpdate.add(item); }); // æ¹éæ´æ°ç¶æ if (!toUpdate.isEmpty()) { iPlmProgramSourceInfoService.updateBatchById(toUpdate); log.info("æåæ´æ°{}æ¡æ°æ®ç¶æ", toUpdate.size()); } }else { log.error("忥MESç³»ç»å¤±è´¥: {}", result); } } catch (Exception e) { log.error("忥MESç³»ç»å¤±è´¥: {}", e.getMessage(), e); // ä» æ è®°å¤ç失败çè®°å½ plmProgramSourceInfos.forEach(item -> item.setMesStatus("0")); iPlmProgramSourceInfoService.updateBatchById(plmProgramSourceInfos); throw new RuntimeException("åæ¥å¤±è´¥ï¼å·²åæ»ç¶æ", e); // 触åäºå¡åæ» } } /** @@ -644,17 +844,6 @@ } String[] files = directory.list(); return files == null || files.length == 0; } private static String buildRequestBody(NcProgramInfo ncProgramInfo) { StringBuilder body = new StringBuilder(); body.append("mesId=").append(ncProgramInfo.getMesId()) .append("&mdsItemCode=").append(ncProgramInfo.getMdsItemCode()) .append("&revisionNo=").append(ncProgramInfo.getRevisionNo()) .append("&opreationSeqNo=").append(ncProgramInfo.getOpreationSeqNo()) .append("&equipmentId=").append(ncProgramInfo.getEquipmentId()) .append("&workshop=").append(ncProgramInfo.getWorkshop()); return body.toString(); } src/main/resources/application.yml
@@ -118,9 +118,6 @@ dnc: server: url: http://localhost:8199 ncPdm: file_path: d://lxzn_storage/plm fileOldNcPath: dnc//plm_bak #æ§æä»¶è®°å½å°å webservice: url: http://20.10.193.21:9308/webservice/mes/eqiupment/v1/mdc2mes.asmx?wsdl