From b508ec38ddf9ed93d4435e8f1e3c4effef798aaa Mon Sep 17 00:00:00 2001
From: lyh <925863403@qq.com>
Date: 星期一, 15 九月 2025 17:18:04 +0800
Subject: [PATCH] 起落架DNC项目更改sql 更改yml配置 集成3DE接口

---
 src/main/java/com/lxzn/webservice/impl/DncWebServiceImpl.java |  631 +++++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 410 insertions(+), 221 deletions(-)

diff --git a/src/main/java/com/lxzn/webservice/impl/DncWebServiceImpl.java b/src/main/java/com/lxzn/webservice/impl/DncWebServiceImpl.java
index 80739b1..d442bd3 100644
--- a/src/main/java/com/lxzn/webservice/impl/DncWebServiceImpl.java
+++ b/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")){
-                //鍒犻櫎璁惧缁撴瀯鏍戜笂瀵瑰簲鐨凬C绋嬪簭鍙婂伐鎺х綉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);
+
+                        // 鑾峰彇鏈�鏂版枃妗f枃浠�
+                        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鏁版嵁鍒涘缓鏃х増鏈琋C鏂囦欢澶囦唤
+     */
+    private boolean createFileOldNcPathAndCopyFor3DE(DocInfo docInfo, ThirdDeProgramSource thirdDeProgramSource) {
+        DocFile docFile = docFileService.getDocFileNearest(docInfo.getDocId());
+        if (docFile == null) {
+            log.error("鏈壘鍒版渶杩戠増鏈殑3DE鏂囨。鏂囦欢锛宒ocId: {}", 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绋嬪簭榻愬鎺ュ彛锛圡ES锛�-DNC绯荤粺鎺ユ敹鍒癙LM浼犵殑NC绋嬪簭锛屽皢绋嬪簭鍖呭搴旂殑闆朵欢鍙枫�佸伐搴忓彿銆佽澶囩紪鍙蜂紶缁橫ES绯荤粺
-     * 瀹氭椂鎵弿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()); // 纭繚鐢熸垚绗﹀悎瑕佹眰鐨刴esId
-//            ncProgramInfo.setOperFlag();
-            return ncProgramInfo;
-        }).collect(Collectors.toList());
-
-        log.info("WebService-NC绋嬪簭榻愬鎺ュ彛锛圡ES锛夊悓姝ュ紑濮嬶紝鏃堕棿: {}", new Date());
-        try {
-            String jsonPayload = JSONObject.toJSONString(ncProgramInfos);
-            log.debug("涓婃姤鏁版嵁: {}", jsonPayload);
-
-            // 璋冪敤WebService骞惰幏鍙栬缁嗗搷搴�
-            String result = CxfClientUtil.invokeService(url, jsonPayload, namespace, method);
-            log.info("鎺ュ彛鍝嶅簲: {}", result);
-
-            // 瑙f瀽鍝嶅簲缁撴灉锛屽彧浼氭湁鎴愬姛鍜屽け璐�
-            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();
     }
 
 

--
Gitblit v1.9.3