Forráskód Böngészése

【深爱-物流-创建订单】

DINGYL 9 hónapja
szülő
commit
84c961251c

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

@@ -52,6 +52,6 @@ public class ERPController {
     @RequestMapping(value="/erp/cancelOrder")
     @ResponseBody
     public Map<String, Object> cancelOrder(String master,Integer id){
-        return erpService.creatOrder(master,id);
+        return erpService.cancelOrder(master,id);
     }
 }

+ 1 - 0
src/main/java/com/uas/eis/entity/LogisticsPrice.java

@@ -45,4 +45,5 @@ public class LogisticsPrice {
     private String lp_DockingCode;
     private String lp_ReceiveCompany;
     private String lp_dockingstatus;
+    private String lp_goodsType;
 }

+ 156 - 5
src/main/java/com/uas/eis/service/Impl/ERPServiceImpl.java

@@ -1,9 +1,21 @@
 package com.uas.eis.service.Impl;
 
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
 import com.deppon.dop.module.sdk.shared.util.FastJsonUtil;
 import com.deppon.dop.module.sdk.shared.util.SecurityUtil;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.kyexpress.openapi.bo.request.batchorder.OrderCustomerInfo;
+import com.kyexpress.openapi.bo.request.batchorder.OrderInfo;
+import com.kyexpress.openapi.bo.request.batchorder.OrderInfoItem;
+import com.kyexpress.openapi.bo.response.batchorder.InvalidResult;
+import com.kyexpress.openapi.bo.response.batchorder.OrderResult;
+import com.kyexpress.openapi.bo.response.batchorder.SuccessOrderResult;
+import com.kyexpress.openapi.bo.response.batchorder.UnconfirmResult;
 import com.kyexpress.openapi.sdk.KyeDefaultOpenApi;
+import com.kyexpress.openapi.sdk.exception.KyeOpenApiException;
+import com.kyexpress.openapi.sdk.utils.JsonUtils;
 import com.sf.csim.express.service.CallExpressServiceTools;
 import com.sf.csim.express.service.HttpClientUtil;
 import com.sf.csim.express.service.IServiceCodeStandard;
@@ -27,6 +39,7 @@ import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.jdbc.core.BeanPropertyRowMapper;
 import org.springframework.stereotype.Service;
 
+import java.io.IOException;
 import java.util.*;
 
 /**
@@ -567,6 +580,7 @@ public class ERPServiceImpl implements ERPService {
                             retMap.put("success",true);
                             retMap.put("logisticscode",waybillNoList.toString());
                             retMap.put("dockingcode",orderCode);
+                            return retMap;
                         } else {
                             retMap.put("message","创建失败:["+sfApiRespData.getErrorCode()+"]"+sfApiRespData.getErrorMsg());
                             retMap.put("success",false);
@@ -580,7 +594,6 @@ public class ERPServiceImpl implements ERPService {
                         return retMap;
                     }
                 }else {
-//                        System.out.println("code:"+sfApiResp.getApiResultCode()+"===apiResponseID:"+sfApiResp.getApiResponseID()+"===apiErrorMsg:"+sfApiResp.getApiErrorMsg());
                     retMap.put("message","创建失败:["+sfApiResp.getApiResultCode()+"]"+sfApiResp.getApiErrorMsg());
                     retMap.put("success",false);
                     logger.info("creatSFOrder-F:id {} err {}",logisticsPrice.getLp_Id(),retMap.get("message"));
@@ -676,6 +689,7 @@ public class ERPServiceImpl implements ERPService {
                             if(sfOrderResp.getResStatus()==2){
                                 retMap.put("success",true);
                                 retMap.put("logisticscode",waybillNo.length()>0?waybillNo.toString():"");
+                                return retMap;
                             }else {
                                 if(sfOrderResp.getResStatus()==1){
                                     retMap.put("message","取消失败:客户订单号与顺丰运单不匹配");
@@ -725,9 +739,143 @@ public class ERPServiceImpl implements ERPService {
         logger.info("cancelDOPOrder-Begin");
         return modelMap;
     }
-    private Map<String, Object> creatOrder_KY(LogisticsPrice logisticsPrice){
+    private Map<String, Object> creatOrder_KY(LogisticsPrice logisticsPrice) throws IOException {
         Map<String, Object> modelMap = new HashMap<String, Object>();
-        logger.info("creatKYOrder-Begin");
+        logger.info("pushKyeOrder begin:id {} ",logisticsPrice.getLp_Id());
+        Object[] obs = baseDao.getFieldsDataByCondition("SZSI_P.DOCK_LOGISTICS_CONFIG A "
+                , new String[]{"CALL_URL","CLIENT_CODE","CHECK_WORD","ENABLE_"}, "LOGISTICS_='KYTEST' and type_='CREATEORDER' AND A.ENABLE_ = 1");
+        String appkey="83955";//obs[1].toString();
+        String appSecret = obs[2].toString();//"46129BED8B381806B1FE15562523E2E0";
+        //组装请求参数,设置具体业务值
+        OrderInfo orderInfo = new OrderInfo();
+        orderInfo.setCustomerCode(obs[1].toString());//固定值
+        orderInfo.setPlatformFlag("6820933B508C2977269F78B2DCD329CB");//固定值 正式BY2ENZQAAQKLKHT8NYN7Y0DPKCXW1XS1
+        //设置寄件方
+        OrderCustomerInfo preWaybillDelivery = new OrderCustomerInfo();
+        preWaybillDelivery.setCompanyName("深爱半导体");  //固定值
+        preWaybillDelivery.setPerson(logisticsPrice.getLp_Recorder());
+        String sendMobile = baseDao.getFieldValue("employee","max(em_mobile)","em_name='"+ logisticsPrice.getLp_Recorder()+"'",String.class);
+        preWaybillDelivery.setMobile(sendMobile); //改成固定 电话 人员资料的 em_mobile
+        preWaybillDelivery.setAddress("深圳市龙岗区宝龙工业区宝龙七路3号"); //固定值
+        preWaybillDelivery.setContactName("甘维东");  //取货人
+        preWaybillDelivery.setContactPhone(logisticsPrice.getLp_Recorder());  //取货人电话固定值
+        OrderInfoItem orderInfoItem = new OrderInfoItem();
+        orderInfoItem.setPreWaybillDelivery(preWaybillDelivery);
+        //设置收件方
+        OrderCustomerInfo preWaybillPickup = new OrderCustomerInfo();
+        preWaybillPickup.setCompanyName(logisticsPrice.getLp_ReceiveCompany());     //收件公司
+        preWaybillPickup.setPerson(logisticsPrice.getLp_Recipient());  //  联系人 必填
+        //preWaybillPickup.setPhone();//(座机)
+        preWaybillPickup.setMobile(logisticsPrice.getLp_Tel());  //	 手机  必填"
+        preWaybillPickup.setAddress(logisticsPrice.getLp_Add()); //必填  地址字段 --目前看好像有些地址没到省市,后续需要规范
+        orderInfoItem.setPreWaybillPickup(preWaybillPickup);
+        String businessType="";
+        /*10-当天达,20-次日达,30-隔日达,40-陆运件,50-同城次日,70-同城即日,160-省内次日,170-省内即日,210-空运,220-专运
+         * */
+        if("特快".equals(logisticsPrice.getLp_Type())){
+            businessType="20";
+        }else if("普快".equals(logisticsPrice.getLp_Type())){
+            businessType="30";
+        }else if("物流".equals(logisticsPrice.getLp_Type())){
+            businessType="40";
+            if("深圳市".equals(logisticsPrice.getLp_Route())){
+                businessType="50";
+            }else if("广东省".equals(logisticsPrice.getLp_Province())){
+                businessType="160";
+            }
+        }
+        orderInfoItem.setServiceMode(businessType);
+        orderInfoItem.setPayMode("10");  //10-寄方付 ,20-收方付 ,30-第三方付 (传代码)  必填
+        orderInfoItem.setPaymentCustomer(obs[1].toString());
+        /*if(rs.getString("pi_paymode").equals("10")) {
+            orderInfoItem.setPaymentCustomer(kyeConfig.getCustomerCode());
+        }else if( rs.getString("pi_paymode").equals("30")){
+            orderInfoItem.setPaymentCustomer(rs.getString("PI_PAYMENTCUSTOMER"));   //正式值:75532690963  校验当付款方式=10-寄方付 或者 30-第三方付 时,付款账号必填
+        }*/
+
+        orderInfoItem.setGoodsType(logisticsPrice.getLp_goodsType());//托寄物 必填
+        String inoutNo = logisticsPrice.getLp_Code();
+        String orderCode = logisticsPrice.getLp_DockingCode();
+        if(orderCode!=null && orderCode.length()>0){
+            orderCode=inoutNo+"-"+(Integer.valueOf(orderCode.split("-")[1])+1);
+        }else {
+            orderCode=inoutNo+"-1";
+        }
+        orderInfoItem.setOrderId(orderCode);  //客户订单号
+        //10:回单原件(含回单照片),20:无需回单,30:回单照片,40:电子回单(传代码)
+        orderInfoItem.setReceiptFlag("10");
+        /*if(rs.getInt("PI_IFRECEIPTFLAG") == 0) {
+            orderInfoItem.setReceiptFlag("20");  //必填 出货单增加字段是否回单原件,是就是:10,否是:20	10:回单原件(含回单照片),20:无需回单,30:回单照片,40:电子回单(传代码)
+        }else{
+            orderInfoItem.setReceiptFlag("10");
+        }*/
+        //保价值
+        //orderInfoItem.setInsuranceValue(rs.getGeneralBigDecimal("pi_insuranceValue"));
+
+        //回单张数
+        orderInfoItem.setReceiptCount(1); //默认值为1
+        //orderInfoItem.setWaybillRemark();// 运单备注
+        orderInfoItem.setDismantling("20"); //固定值 20-否	10-是,表示根据预约揽件的时间上门揽收,20-否,表示线下自主联系揽收(传代码,是否预约取货为“10”时,货好时间字段必填,同时根据货好时间安排司机上门揽收)
+        //回单联
+        List<String> pic = new ArrayList<>();
+        pic.add("10");
+        //pictureSubscription
+        //图片订阅服务        //array[string]        //否        //10        //10-回单 20-签收联
+        orderInfoItem.setPictureSubscription(pic);
+        List<OrderInfoItem> infoItems = new ArrayList<>();
+        infoItems.add(orderInfoItem);
+        orderInfo.setRepeatCheck("10");
+        orderInfo.setOrderInfos(infoItems);
+        boolean suc = true;
+        boolean isSandbox = true;
+        String method="open.api.openCommon.batchOrder";
+        String bizBody =JSONArray.toJSONString(orderInfo);
+        String response = null;
+        try {
+            response = KyeDefaultOpenApi.builder
+                            (appkey, appSecret) //应用Key,密钥
+                    .env("uat") //对应环境,包含(uat:测试环境,prod:生产环境),获取对应环境的请求路径
+                    .api(method) //所调用Api Code
+                    .sandbox(isSandbox)//是否沙盒环境(env=prod且isSandbox=true时对应的就是跨越测试环境)
+                    .body(bizBody) //请求体参数,可接受字符串,List,Map三种类型的参数
+                    .connectTimeout(3000) //连接超时时间
+                    .readTimeout(15000) //读取超时时间
+                    .request()
+                    .response();
+        } catch (KyeOpenApiException e) {
+            throw new RuntimeException(e);
+        }
+        Map<Object, Object> res  = BaseUtil.parseFormStoreToMap(response);
+        if(Boolean.valueOf(res.get("success").toString())){
+            OrderResult orderResult = JsonUtils.serializable(JSON.toJSONString(res.get("data")),new TypeReference<OrderResult>(){});
+            if(orderResult.getTotal().getSuccessTotal()>0) {
+                SuccessOrderResult result = orderResult.getSuccess().get(0);
+                modelMap.put("success",true);
+                modelMap.put("logisticscode",result.getWaybillNumber());
+                modelMap.put("dockingcode",orderCode);
+                logger.info("creatKYOrder-S:id {} logisticscode {}",logisticsPrice.getLp_Id(),modelMap.get("logisticscode"));
+                return modelMap;
+            }else if(orderResult.getTotal().getUnconfirmTotal()>0){
+                UnconfirmResult result = orderResult.getUnconfirm().get(0);
+                logger.info("creatKYOrder-F:id {} ConfirmUrl {}",logisticsPrice.getLp_Id(),orderResult.getConfirmUrl());
+                /*commonService.logKyeSRecord(rs.getString("pi_inoutno"),id,result.getWaybillNumber(),result.getMessage()+",确认链接:"+orderResult.getConfirmUrl());
+                map.put("confirmUrl",orderResult.getConfirmUrl());
+                suc = true;*/
+            }else{
+                InvalidResult result = orderResult.getFailure().get(0);
+                modelMap.put("message","创建失败:"+ result.getMessage());
+                modelMap.put("success",false);
+                logger.info("creatKYOrder-F:id {} err {}",logisticsPrice.getLp_Id(),modelMap.get("message"));
+                return modelMap;
+            }
+        }else{
+            if(StringUtil.hasText(res.get("msg"))) {
+                modelMap.put("message","创建失败:"+ res.get("msg").toString());
+                modelMap.put("success",false);
+                logger.info("creatKYOrder-F:id {} err {}",logisticsPrice.getLp_Id(),modelMap.get("message"));
+                return modelMap;
+            }
+        }
         return modelMap;
     }
     private Map<String, Object> cancelOrder_KY(LogisticsPrice logisticsPrice){
@@ -745,8 +893,11 @@ public class ERPServiceImpl implements ERPService {
                 creatOrder_SF(logisticsPrice);
             }else if("德邦".equals(logisticsPrice.getLp_FinalCompany())){
                 creatOrder_DoP(logisticsPrice);
-            }else if("跨越".equals(logisticsPrice.getLp_FinalCompany())){
-                creatOrder_KY(logisticsPrice);
+                try {
+                    creatOrder_KY(logisticsPrice);
+                } catch (IOException e) {
+                    throw new RuntimeException(e);
+                }
             }
         }else{
             modelMap.put("message", "单据不存在!");