From 67ac603f410319a0d999e5f493c8ef2d74163fe1 Mon Sep 17 00:00:00 2001
From: Houjie <714924425@qq.com>
Date: 星期一, 15 九月 2025 19:44:47 +0800
Subject: [PATCH] 保养标准:点检标准导入 点检名称修改/ 设备台账导入

---
 src/main/java/org/jeecg/modules/mes/service/impl/MesProductionOrderServiceImpl.java |  107 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 106 insertions(+), 1 deletions(-)

diff --git a/src/main/java/org/jeecg/modules/mes/service/impl/MesProductionOrderServiceImpl.java b/src/main/java/org/jeecg/modules/mes/service/impl/MesProductionOrderServiceImpl.java
index ed8e452..495ac47 100644
--- a/src/main/java/org/jeecg/modules/mes/service/impl/MesProductionOrderServiceImpl.java
+++ b/src/main/java/org/jeecg/modules/mes/service/impl/MesProductionOrderServiceImpl.java
@@ -1,18 +1,123 @@
 package org.jeecg.modules.mes.service.impl;
 
+import cn.hutool.core.collection.CollectionUtil;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.jeecg.common.constant.CommonConstant;
+import org.jeecg.common.exception.JeecgBootException;
 import org.jeecg.modules.mes.entity.MesProductionOrder;
 import org.jeecg.modules.mes.mapper.MesProductionOrderMapper;
 import org.jeecg.modules.mes.service.IMesProductionOrderService;
+import org.jeecg.modules.sap.dto.ProductionOrderDTO;
+import org.jeecg.modules.sap.request.ProductionOrderSyncRequest;
+import org.jeecg.modules.sap.service.ProductionOrderSync;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 /**
  * @Description: SAP鐢熶骇璁㈠崟
  * @Author: jeecg-boot
- * @Date:   2025-07-04
+ * @Date: 2025-07-04
  * @Version: V1.0
  */
 @Service
 public class MesProductionOrderServiceImpl extends ServiceImpl<MesProductionOrderMapper, MesProductionOrder> implements IMesProductionOrderService {
+    //宸ュ巶缂栫爜(鏂扮伀鐐� 2301)
+    @Value("${xhj.factoryCode:2301}")
+    private String FACTORY_CODE;
 
+    @Autowired
+    private ProductionOrderSync productionOrderSync;
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public Map<String, MesProductionOrder> saveOrUpdateProductionOrder(List<ProductionOrderDTO> productionOrderDTOList) {
+        Map<String, MesProductionOrder> resultMap = new HashMap<>();
+        for (ProductionOrderDTO productionOrderDTO : productionOrderDTOList) {
+            MesProductionOrder updated = getByOrderCode(productionOrderDTO.getAUFNR());
+            if (updated == null) {
+                updated = new MesProductionOrder(productionOrderDTO);
+                resultMap.put(updated.getOrderCode(), updated);
+                this.getBaseMapper().insert(updated);
+            } else {
+                updated.updateEntity(productionOrderDTO);
+                resultMap.put(updated.getOrderCode(), updated);
+                this.getBaseMapper().updateById(updated);
+            }
+        }
+        return resultMap;
+    }
+
+    @Override
+    public MesProductionOrder getByOrderCode(String orderCode) {
+        LambdaQueryWrapper<MesProductionOrder> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.eq(MesProductionOrder::getOrderCode, orderCode);
+        queryWrapper.eq(MesProductionOrder::getDelFlag, CommonConstant.DEL_FLAG_0);
+        List<MesProductionOrder> list = super.list(queryWrapper);
+        if (CollectionUtil.isNotEmpty(list)) {
+            return list.get(0);
+        }
+        return null;
+    }
+
+    @Override
+    public String getLastSyncCreateDate() {
+        String lastSyncDate = this.getBaseMapper().getLastSyncCreateDate();
+        if (lastSyncDate == null) {
+            return null;
+        }
+        return lastSyncDate.replaceAll("-", "");
+    }
+
+    @Override
+    public String getLastSyncUpdateDate() {
+        String lastSyncDate = this.getBaseMapper().getLastSyncUpdateDate();
+        if (lastSyncDate == null) {
+            return null;
+        }
+        return lastSyncDate.replaceAll("-", "");
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public boolean syncSapProductionOrder(String id) {
+        MesProductionOrder entity = super.getById(id);
+        if (entity == null) {
+            throw new JeecgBootException("鐢熶骇璁㈠崟涓嶅瓨鍦紝璇峰埛鏂伴噸缃紒");
+        }
+        ProductionOrderSyncRequest request = new ProductionOrderSyncRequest();
+        request.setOrderCode(entity.getOrderCode());
+        request.setFactoryCode(FACTORY_CODE);
+        try {
+            Map<String, Object> resultMap = productionOrderSync.syncProductionOrder(request);
+            if (resultMap == null) {
+                throw new JeecgBootException("鍝嶅簲缁撴灉涓虹┖锛�");
+            }
+            if (!CommonConstant.SAP_SUCCESS_CODE.equals(resultMap.get("ztype"))) {
+                throw new JeecgBootException(resultMap.get("zmess").toString());
+            }
+            //璋冪敤鎴愬姛锛岃幏鍙栬繑鍥炴暟鎹�
+            Object result = resultMap.get("result");
+            boolean b = result instanceof List;
+            if (!b) {
+                throw new JeecgBootException("杩斿洖缁撴灉鏍煎紡閿欒锛�");
+            }
+            List<ProductionOrderDTO> productionOrderDTOList = (List<ProductionOrderDTO>) result;
+            if (CollectionUtil.isEmpty(productionOrderDTOList)) {
+                throw new JeecgBootException("SAP鏈煡璇㈠埌鐢熸垚璁㈠崟锛�");
+            }
+            ProductionOrderDTO dto = productionOrderDTOList.get(0);
+            entity.updateEntity(dto);
+            super.updateById(entity);
+        } catch (Exception e) {
+            throw new JeecgBootException("璇锋眰SAP澶辫触锛�" + e.getMessage());
+        }
+        return true;
+    }
 }

--
Gitblit v1.9.3