Procházet zdrojové kódy

【华信科小米EDI对接】【小米SRM推送送货指令至外部供应商公用X5同步接口】

wub před 1 týdnem
rodič
revize
5dcf252805

+ 5 - 0
src/main/java/com/uas/eis/controller/ERPController.java

@@ -49,4 +49,9 @@ public class ERPController {
     public Map<String, Object> closePurchase(String data){
         return erpService.closePurchase(data);
     }
+
+    @RequestMapping("/erp/deliInstruction")
+    public Map<String, Object> deliInstruction(String data){
+        return erpService.deliInstruction(data);
+    }
 }

+ 26 - 0
src/main/java/com/uas/eis/sdk/dto/DeliInstruction.java

@@ -0,0 +1,26 @@
+package com.uas.eis.sdk.dto;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class DeliInstruction {
+
+    @JsonProperty("SYSTEMID")
+    private String SYSTEMID;
+    @JsonProperty("GUID")
+    private String GUID;
+    @JsonProperty("DELI_INSTRU_NO")
+    private String DELI_INSTRU_NO;
+    @JsonProperty("SUPPLIER_CODE")
+    private String SUPPLIER_CODE;
+    @JsonProperty("SUPPLIER_NAME")
+    private String SUPPLIER_NAME;
+    @JsonProperty("OPERATION_TYPE")
+    private String OPERATION_TYPE;
+    @JsonProperty("ET_ITEM")
+    private List<DeliInstructionItem> ET_ITEM;
+
+}

+ 81 - 0
src/main/java/com/uas/eis/sdk/dto/DeliInstructionItem.java

@@ -0,0 +1,81 @@
+package com.uas.eis.sdk.dto;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Data;
+
+@Data
+public class DeliInstructionItem {
+
+    @JsonProperty("DELI_INSTRU_NUM")
+    private String DELI_INSTRU_NUM;
+    @JsonProperty("DELI_INSTRU_ITEM")
+    private String DELI_INSTRU_ITEM;
+    @JsonProperty("INSTRUTION_TYPE")
+    private String INSTRUTION_TYPE;
+    @JsonProperty("INSTRUTION_TYPE_DESC")
+    private String INSTRUTION_TYPE_DESC;
+    @JsonProperty("PURCHASE_ORG")
+    private String PURCHASE_ORG;
+    @JsonProperty("PURCHASE_ORG_DESC")
+    private String PURCHASE_ORG_DESC;
+    @JsonProperty("RECESTOCK_ORG")
+    private String RECESTOCK_ORG;
+    @JsonProperty("RECESTOCK_ORG_DESC")
+    private String RECESTOCK_ORG_DESC;
+    @JsonProperty("SHIP_FROM_CODE")
+    private String SHIP_FROM_CODE;
+    @JsonProperty("SHIP_FROM_NAME")
+    private String SHIP_FROM_NAME;
+    @JsonProperty("SHIP_TO_CODE")
+    private String SHIP_TO_CODE;
+    @JsonProperty("SHIP_TO_NAME")
+    private String SHIP_TO_NAME;
+    @JsonProperty("DESTINATION_CODE")
+    private String DESTINATION_CODE;
+    @JsonProperty("DESTINATION_NAME")
+    private String DESTINATION_NAME;
+    @JsonProperty("MATERIAL_NUM")
+    private String MATERIAL_NUM;
+    @JsonProperty("MAKTX")
+    private String MAKTX;
+    @JsonProperty("SUPP_MAT_NUM")
+    private String SUPP_MAT_NUM;
+    @JsonProperty("CVPN")
+    private String CVPN;
+    @JsonProperty("PN")
+    private String PN;
+    @JsonProperty("PURCHASE_MODE")
+    private String PURCHASE_MODE;
+    @JsonProperty("COMMAND_QUANTITY")
+    private String COMMAND_QUANTITY;
+    @JsonProperty("QTY_UNIT")
+    private String QTY_UNIT;
+    @JsonProperty("APP_MODELS")
+    private String APP_MODELS;
+    @JsonProperty("REQ_DELI_DATE")
+    private String REQ_DELI_DATE;
+    @JsonProperty("EST_DELI_DATE")
+    private String EST_DELI_DATE;
+    @JsonProperty("COMMAND_CREATED_DATE")
+    private String COMMAND_CREATED_DATE;
+    @JsonProperty("COMMAND_CREATED_TIME")
+    private String COMMAND_CREATED_TIME;
+    @JsonProperty("COMMAND_VALID_STATUS")
+    private String COMMAND_VALID_STATUS;
+    @JsonProperty("COMMAND_VALID_DATE")
+    private String COMMAND_VALID_DATE;
+    @JsonProperty("COMMAND_VALID_TIME")
+    private String COMMAND_VALID_TIME;
+    @JsonProperty("URGENT_FLAG")
+    private String URGENT_FLAG;
+    @JsonProperty("URGENT_FLAG_DATE")
+    private String URGENT_FLAG_DATE;
+    @JsonProperty("URGENT_FLAG_TIME")
+    private String URGENT_FLAG_TIME;
+    @JsonProperty("FPO_NUM")
+    private String FPO_NUM;
+    @JsonProperty("FPO_ITEM_NUM")
+    private String FPO_ITEM_NUM;
+    @JsonProperty("DESTINATION_COUNTRY")
+    private String DESTINATION_COUNTRY;
+}

+ 1 - 0
src/main/java/com/uas/eis/service/ERPService.java

@@ -13,4 +13,5 @@ public interface ERPService {
     Map<String, Object> savePurchase(String data);
     void confirmPurchase(String id);
     Map<String, Object> closePurchase(String data);
+    Map<String, Object> deliInstruction(String data);
 }

+ 107 - 0
src/main/java/com/uas/eis/service/Impl/ERPServiceImpl.java

@@ -21,6 +21,8 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
+import java.net.URLDecoder;
+import java.nio.charset.StandardCharsets;
 import java.text.SimpleDateFormat;
 import java.util.*;
 
@@ -300,6 +302,111 @@ public class ERPServiceImpl implements ERPService {
         return result;
     }
 
+    @Override
+    public Map<String, Object> deliInstruction(String data) {
+        Map<String, Object> result = new HashMap<>();
+        Map<String, Object> header_result = new HashMap<>();
+        String resultSuccessMsg = "";
+        String resultErrorMsg = "";
+        String sign = null;
+        String body = null;
+        try {
+            ObjectMapper objectMapper = new ObjectMapper();
+            String decode = URLDecoder.decode(data, StandardCharsets.UTF_8.toString());
+            String jsonString = X5StringUtils.decodeBase64(decode);
+            Map<String, Object> map = objectMapper.readValue(jsonString, Map.class);
+            if(map.size()>0 && map.get("header")!=null ){
+                Map<String, Object> header_map = (Map<String, Object>) map.get("header");
+                sign = header_map.get("sign") == null ? "" : header_map.get("sign").toString();
+            }
+            boolean checkSign = X5StringUtils.checkSign(sign, "test", jsonString, "218A05A252469F5A62B0B3204F669E1D");
+            if(checkSign || true){
+                try {
+                    if(map.get("body")!=null){
+                        body = map.get("body") == null ? "" : map.get("body").toString();
+                        DeliInstruction deliInstruction = objectMapper.readValue(body, DeliInstruction.class);
+                        String deli_instru_no = deliInstruction.getDELI_INSTRU_NO();
+                        String guid = deliInstruction.getGUID();
+                        resultSuccessMsg="送货指令:"+deli_instru_no+"处理成功";
+                        resultErrorMsg="送货指令:"+deli_instru_no+"处理失败,";
+
+                        String operation_type = deliInstruction.getOPERATION_TYPE();
+                        if("I".equals(operation_type) || "U".equals(operation_type)){
+                            int count = baseDao.getCount("select * from deliInstructionXM where GUID='" + guid + "'");
+                            if (count == 0){
+                                //主表
+                                Map<String, Object> deliInstruction_map = ObjectToMapConverter.objectToMap(deliInstruction);
+                                deliInstruction_map.remove("ET_ITEM");
+                                deliInstruction_map.put("DI_ID", 0);
+                                baseDao.execute(SqlUtil.getInsertSql(deliInstruction_map,"deliInstructionXM","DI_ID"));
+                                Object DI_ID = baseDao.getFieldDataByCondition("deliInstructionXM", "DI_ID", "GUID='" + guid+"'");
+                                //从表
+                                List<DeliInstructionItem> et_item = deliInstruction.getET_ITEM();
+                                for (DeliInstructionItem deliInstructionItem:et_item) {
+                                    //List<String> ItemSqls = new ArrayList<>();
+                                    Map<String, Object> deliInstructionItem_map = ObjectToMapConverter.objectToMap(deliInstructionItem);
+                                    deliInstructionItem_map.remove("ET_ITEM_AMOUNT");
+                                    deliInstructionItem_map.put("DID_ID",0);
+                                    deliInstructionItem_map.put("DID_DIID",DI_ID);
+                                    String insertItemSql = SqlUtil.getInsertSql(deliInstructionItem_map, "deliInstructionDetailXM", "DID_ID");
+                                    baseDao.execute(insertItemSql);
+                                }
+                            }else{
+                                //更新
+                                header_result.put("code", "400");
+                                header_result.put("desc", resultErrorMsg+"具体报错原因:重复推送,GUID已存在!");
+                                result.put("header", header_result);
+                                return result;
+                            }
+                        }else{
+                            int count = baseDao.getCount("select * from deliInstructionXM where GUID='" + guid + "'");
+                            if (count == 0){
+                                //更新
+                                header_result.put("code", "400");
+                                header_result.put("desc", resultErrorMsg+"具体报错原因:采购单号不存在,不能执行更新操作!");
+                                result.put("header", header_result);
+                                return result;
+                            }else{
+                                //更新
+                                header_result.put("code", "200");
+                                header_result.put("desc", resultSuccessMsg+"执行更新操作中!");
+                                result.put("header", header_result);
+                                return result;
+                            }
+                        }
+
+                        header_result.put("code", "200");
+                        header_result.put("desc", resultSuccessMsg);
+                        result.put("header", header_result);
+                    }else{
+                        header_result.put("code", "400");
+                        header_result.put("desc", resultErrorMsg+"具体报错原因:body数据不存在!");
+                        result.put("header", header_result);
+                        return result;
+                    }
+                }catch (Exception e){
+                    logger.info("同步收料单异常信息:"+body);
+                    header_result.put("code", "400");
+                    header_result.put("desc", resultErrorMsg+"具体报错原因:解析body失败!");
+                    result.put("header", header_result);
+                    return result;
+                }
+            }else{
+                header_result.put("code", "400");
+                header_result.put("desc", resultErrorMsg+"具体报错原因:身份验证失败!");
+                result.put("header", header_result);
+                return result;
+            }
+        }catch (Exception e){
+            logger.info("同步收料单异常信息:"+e.getMessage());
+            header_result.put("code", "400");
+            header_result.put("desc", resultErrorMsg+"具体报错原因:JSON解析失败!!");
+            result.put("header", header_result);
+            return result;
+        }
+        return result;
+    }
+
     public static String unescapeJsonWithJackson(String jsonString) {
         try {
             ObjectMapper mapper = new ObjectMapper();