From 12d9f4e03c0331efc9a656356e78b9f314639707 Mon Sep 17 00:00:00 2001
From: 1 <1@123>
Date: 星期三, 18 三月 2026 17:07:57 +0800
Subject: [PATCH] lsh#

---
 rsf-open-api/src/main/java/com/vincent/rsf/openApi/service/phyz/impl/ErpReportServiceImpl.java |  248 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 244 insertions(+), 4 deletions(-)

diff --git a/rsf-open-api/src/main/java/com/vincent/rsf/openApi/service/phyz/impl/ErpReportServiceImpl.java b/rsf-open-api/src/main/java/com/vincent/rsf/openApi/service/phyz/impl/ErpReportServiceImpl.java
index 4d823a4..d982b35 100644
--- a/rsf-open-api/src/main/java/com/vincent/rsf/openApi/service/phyz/impl/ErpReportServiceImpl.java
+++ b/rsf-open-api/src/main/java/com/vincent/rsf/openApi/service/phyz/impl/ErpReportServiceImpl.java
@@ -11,8 +11,7 @@
 import com.vincent.rsf.openApi.config.PlatformProperties;
 import com.vincent.rsf.openApi.entity.constant.WmsConstant;
 import com.vincent.rsf.openApi.entity.dto.CommonResponse;
-import com.vincent.rsf.openApi.entity.phyz.ErpReportParams;
-import com.vincent.rsf.openApi.entity.phyz.Order;
+import com.vincent.rsf.openApi.entity.phyz.*;
 import com.vincent.rsf.openApi.service.WmsErpService;
 import com.vincent.rsf.openApi.service.phyz.ErpReportService;
 import com.vincent.rsf.openApi.utils.ParamsMapUtils;
@@ -34,8 +33,8 @@
 import org.springframework.stereotype.Service;
 import org.springframework.web.client.RestTemplate;
 
-import javax.annotation.PostConstruct;
-import javax.annotation.Resource;
+import jakarta.annotation.PostConstruct;
+import jakarta.annotation.Resource;
 import javax.net.ssl.SSLContext;
 import javax.net.ssl.TrustManager;
 import javax.net.ssl.X509TrustManager;
@@ -70,8 +69,249 @@
         ERP_REPORT_URL = erpApi.getErpUrl();
     }
 
+    @Override
+    public String syncMaterial(List<Material> materialList){
+        if (materialList.isEmpty()) {
+            throw new CoolException("鍙傛暟涓嶈兘涓虹┖锛侊紒");
+        }
+        /**WMS鍩虹閰嶇疆閾炬帴*/
+        String wmsUrl = wmsApi.getHost() + ":" + wmsApi.getPort() + WmsConstant.SYNC_MATNRS;
+        HttpHeaders headers = new HttpHeaders();
+        headers.add("Content-Type", "application/json");
+        headers.add("api-version", "v2.0");
+        // Material -> BaseMatParms 瀛楁涓�涓�瀵瑰簲鍚庡啀涓嬪彂
+        List<Map<String, Object>> baseMatParamsList = materialToBaseMatParams(materialList);
+        HttpEntity httpEntity2 = new HttpEntity<>(baseMatParamsList, headers);//cs
+        // sync/warehouse
+        ResponseEntity<String> exchange = restTemplate.exchange(wmsUrl, HttpMethod.POST, httpEntity2, String.class);//cs
+        log.info("鍚屾鐗╂枡淇℃伅杩斿洖缁撴灉锛� {}", exchange);
+        if (Objects.isNull(exchange.getBody())) {
+            throw new CoolException("鏌ヨ澶辫触锛侊紒");
+        } else {
+            ObjectMapper objectMapper = new ObjectMapper();
+            objectMapper.coercionConfigDefaults().setCoercion(CoercionInputShape.EmptyString, CoercionAction.AsEmpty);
+            try {
+                CommonResponse result = objectMapper.readValue(exchange.getBody(), CommonResponse.class);
+                if (result.getCode() == 200) {
+//                    JSONObject object = JSONObject.parseObject(JSONObject.toJSONString(result.getData()));
+                    return "200";
+                } else {
+                    return result.getMsg();
+//                    throw new CoolException("鏌ヨ澶辫触锛侊紒");
+                }
+            } catch (JsonProcessingException e) {
+                return e.getMessage();
+//                throw new CoolException(e.getMessage());
+            }
+        }
+    }
 
+    /**
+     * Material 瀛楁鏄犲皠涓� server 绔� BaseMatParms 瀛楁
+     */
+    private List<Map<String, Object>> materialToBaseMatParams(List<Material> materialList) {
+        List<Map<String, Object>> mappedList = new ArrayList<>();
+        for (Material material : materialList) {
+            if (Objects.isNull(material)) {
+                continue;
+            }
+            Map<String, Object> map = new HashMap<>();
+            map.put("maktx", material.getMakTx());
+            map.put("matnr", material.getMatNr());
+            map.put("groupName", material.getGroupName());
+            map.put("model", material.getModel());
+            map.put("weight", material.getWeight() == null ? null : material.getWeight().toString());
+            map.put("color", material.getColor());
+            map.put("size", material.getSize());
+            map.put("spec", material.getSpec());
+            map.put("describle", material.getDescribe());
+            map.put("unit", material.getUnit());
+            mappedList.add(map);
+        }
+        return mappedList;
+    }
 
+    @Override
+    public String syncWareHouse(List<Warehouse> warehouseList){
+        if (warehouseList.isEmpty()) {
+            throw new CoolException("鍙傛暟涓嶈兘涓虹┖锛侊紒");
+        }
+        /**WMS鍩虹閰嶇疆閾炬帴*/
+        String wmsUrl = wmsApi.getHost() + ":" + wmsApi.getPort() + WmsConstant.SYNC_WAREHOUSE;
+        HttpHeaders headers = new HttpHeaders();
+        headers.add("Content-Type", "application/json");
+        headers.add("api-version", "v2.0");
+        // Warehouse -> WarehouseParams 瀛楁涓�涓�瀵瑰簲鍚庡啀涓嬪彂
+        List<Map<String, Object>> warehouseParamsList = warehouseToWarehouseParams(warehouseList);
+        HttpEntity httpEntity2 = new HttpEntity<>(warehouseParamsList, headers);//cs
+        // sync/warehouse
+        ResponseEntity<String> exchange = restTemplate.exchange(wmsUrl, HttpMethod.POST, httpEntity2, String.class);//cs
+        log.info("鍚屾浠撳簱淇℃伅杩斿洖缁撴灉锛� {}", exchange);
+        if (Objects.isNull(exchange.getBody())) {
+            throw new CoolException("鏌ヨ澶辫触锛侊紒");
+        } else {
+            ObjectMapper objectMapper = new ObjectMapper();
+            objectMapper.coercionConfigDefaults().setCoercion(CoercionInputShape.EmptyString, CoercionAction.AsEmpty);
+            try {
+                CommonResponse result = objectMapper.readValue(exchange.getBody(), CommonResponse.class);
+                if (result.getCode() == 200) {
+//                    JSONObject object = JSONObject.parseObject(JSONObject.toJSONString(result.getData()));
+                    return "200";
+                } else {
+                    return result.getMsg();
+//                    throw new CoolException("鏌ヨ澶辫触锛侊紒");
+                }
+            } catch (JsonProcessingException e) {
+                return e.getMessage();
+//                throw new CoolException(e.getMessage());
+            }
+        }
+    }
+    @Override
+    public String syncCustomer(List<Customer> customerList){
+        if (customerList.isEmpty()) {
+            throw new CoolException("鍙傛暟涓嶈兘涓虹┖锛侊紒");
+        }
+        /**WMS鍩虹閰嶇疆閾炬帴*/
+        String wmsUrl = wmsApi.getHost() + ":" + wmsApi.getPort() + WmsConstant.SYNC_COMPANIES;
+        HttpHeaders headers = new HttpHeaders();
+        headers.add("Content-Type", "application/json");
+        headers.add("api-version", "v2.0");
+        // Customer -> CompaniesParam 瀛楁涓�涓�瀵瑰簲鍚庡啀涓嬪彂
+        List<Map<String, Object>> companiesParamsList = customerToCompaniesParams(customerList);
+        HttpEntity httpEntity2 = new HttpEntity<>(companiesParamsList, headers);//cs
+        ResponseEntity<String> exchange = restTemplate.exchange(wmsUrl, HttpMethod.POST, httpEntity2, String.class);//cs
+        log.info("鍚屾瀹㈡埛淇℃伅杩斿洖缁撴灉锛� {}", exchange);
+        if (Objects.isNull(exchange.getBody())) {
+            throw new CoolException("鏌ヨ澶辫触锛侊紒");
+        } else {
+            ObjectMapper objectMapper = new ObjectMapper();
+            objectMapper.coercionConfigDefaults().setCoercion(CoercionInputShape.EmptyString, CoercionAction.AsEmpty);
+            try {
+                CommonResponse result = objectMapper.readValue(exchange.getBody(), CommonResponse.class);
+                if (result.getCode() == 200) {
+                    return "200";
+                } else {
+                    return result.getMsg();
+                }
+            } catch (JsonProcessingException e) {
+                return e.getMessage();
+            }
+        }
+    }
+
+    @Override
+    public String syncSupplier(List<Supplier> supplierList){
+        if (supplierList.isEmpty()) {
+            throw new CoolException("鍙傛暟涓嶈兘涓虹┖锛侊紒");
+        }
+        /**WMS鍩虹閰嶇疆閾炬帴*/
+        String wmsUrl = wmsApi.getHost() + ":" + wmsApi.getPort() + WmsConstant.SYNC_COMPANIES;
+        HttpHeaders headers = new HttpHeaders();
+        headers.add("Content-Type", "application/json");
+        headers.add("api-version", "v2.0");
+        // Supplier -> supplierParams 瀛楁涓�涓�瀵瑰簲鍚庡啀涓嬪彂
+        List<Map<String, Object>> supplierParamsList = customerToSupplierParams(supplierList);
+        HttpEntity httpEntity2 = new HttpEntity<>(supplierParamsList, headers);//cs
+        ResponseEntity<String> exchange = restTemplate.exchange(wmsUrl, HttpMethod.POST, httpEntity2, String.class);//cs
+        log.info("鍚屾瀹㈡埛淇℃伅杩斿洖缁撴灉锛� {}", exchange);
+        if (Objects.isNull(exchange.getBody())) {
+            throw new CoolException("鏌ヨ澶辫触锛侊紒");
+        } else {
+            ObjectMapper objectMapper = new ObjectMapper();
+            objectMapper.coercionConfigDefaults().setCoercion(CoercionInputShape.EmptyString, CoercionAction.AsEmpty);
+            try {
+                CommonResponse result = objectMapper.readValue(exchange.getBody(), CommonResponse.class);
+                if (result.getCode() == 200) {
+                    return "200";
+                } else {
+                    return result.getMsg();
+                }
+            } catch (JsonProcessingException e) {
+                return e.getMessage();
+            }
+        }
+    }
+
+    /**
+     * Warehouse 瀛楁鏄犲皠涓� server 绔� WarehouseParams 瀛楁
+     */
+    private List<Map<String, Object>> warehouseToWarehouseParams(List<Warehouse> warehouseList) {
+        List<Map<String, Object>> mappedList = new ArrayList<>();
+        for (Warehouse warehouse : warehouseList) {
+            if (Objects.isNull(warehouse)) {
+                continue;
+            }
+            Map<String, Object> map = new HashMap<>();
+            map.put("name", warehouse.getWareHouseName());
+            map.put("code", warehouse.getUseOrgId());
+            map.put("factory",  warehouse.getUseOrgName());
+            map.put("address", warehouse.getAddress());
+            map.put("type", null);
+            map.put("longitude", null);
+            map.put("latitude", null);
+            mappedList.add(map);
+        }
+        return mappedList;
+    }
+
+    /**
+     * Customer 瀛楁鏄犲皠涓� server 绔� CompaniesParam 瀛楁
+     */
+    private List<Map<String, Object>> customerToCompaniesParams(List<Customer> customerList) {
+        List<Map<String, Object>> mappedList = new ArrayList<>();
+        for (Customer customer : customerList) {
+            if (Objects.isNull(customer)) {
+                continue;
+            }
+            Map<String, Object> map = new HashMap<>();
+            map.put("name", customer.getCustomerName());
+            map.put("nameEn", null);
+            map.put("breifCode", customer.getCustomerNickName());
+            // server 绔被鍨嬭浆鎹娇鐢ㄤ腑鏂囨弿杩�
+            map.put("type", customer.getType());
+            map.put("contact", customer.getContact());
+            map.put("tel", customer.getTelephone());
+            map.put("email", customer.getEmail());
+            map.put("pcode", null);
+            map.put("city", customer.getCustomerGroup());
+            map.put("province", null);
+            map.put("address", customer.getAddress());
+            map.put("code", customer.getCustomerId());
+            mappedList.add(map);
+        }
+        return mappedList;
+    }
+
+    /**
+     * Customer 瀛楁鏄犲皠涓� server 绔� CompaniesParam 瀛楁
+     */
+    private List<Map<String, Object>> customerToSupplierParams(List<Supplier> supplierList) {
+        List<Map<String, Object>> mappedList = new ArrayList<>();
+        for (Supplier supplier : supplierList) {
+            if (Objects.isNull(supplier)) {
+                continue;
+            }
+            Map<String, Object> map = new HashMap<>();
+            map.put("name", supplier.getSupplierName());
+            map.put("nameEn", null);
+            map.put("breifCode", supplier.getSupplierName());
+            // server 绔被鍨嬭浆鎹娇鐢ㄤ腑鏂囨弿杩�
+            map.put("type", supplier.getType());
+            map.put("contact", supplier.getContact());
+            map.put("tel", supplier.getTelephone());
+            map.put("email", supplier.getEmail());
+            map.put("pcode", null);
+            map.put("city", supplier.getSupplierGroup());
+            map.put("province", null);
+            map.put("address", supplier.getAddress());
+            map.put("code", supplier.getSupplierId());
+            mappedList.add(map);
+        }
+        return mappedList;
+    }
+
+    @Override
     public String addOrderToServer(Order order) {
         if (Objects.isNull(order.getOrderNo()) || order.getOrderNo().isEmpty()) {
             throw new CoolException("璁㈠崟鍙蜂笉鑳戒负绌猴紒锛�");

--
Gitblit v1.9.1