Browse Source

万中物流添加站点判断

hu 10 months ago
parent
commit
0211e151e8

+ 12 - 11
src/custom/restcontroller/webmanage/sale/logistics/LSALogistics.java

@@ -268,11 +268,12 @@ public class LSALogistics extends Controller {
         row.putIfAbsent("receivedate", "");
         //对接万中物流
 //        if(siteid.equalsIgnoreCase("lsa")){
-            WzwlDocking wzwlDocking =new WzwlDocking();
+            WzwlDocking wzwlDocking =new WzwlDocking(siteid);
             if(!row.getString("logisticsstatus").equals("签收") && !row.get("status").equals("新建")){
 
                 JSONObject jsonObject = wzwlDocking.queryWzwlOrderAmountExtendList(row.getString("billno"));
-                if(jsonObject.getString("success").equals("true")){
+                System.out.println(jsonObject.getStringValue("success"));
+                if(jsonObject.getStringValue("success").equals("true")){
                     JSONArray data = jsonObject.getJSONArray("data");
                     dbConnect.runSqlUpdate("update sa_logistics set logisticsamount="+(((JSONObject)data.get(0)).getBigDecimalValue("transportFee").compareTo(BigDecimal.ZERO)>0?((JSONObject)data.get(0)).getBigDecimalValue("transportFee"):row.getDouble("logisticsamount"))+",volume='"+(((JSONObject)data.get(0)).getBigDecimalValue("volume").compareTo(BigDecimal.ZERO)>0?((JSONObject)data.get(0)).getBigDecimalValue("volume"):row.getDouble("volume"))+"',weight='"+(((JSONObject)data.get(0)).getBigDecimalValue("weight").compareTo(BigDecimal.ZERO)>0?((JSONObject)data.get(0)).getBigDecimalValue("weight"):row.getDouble("weight"))+"' where sa_logisticsid="+sa_logisticsid);
                     row.put("logisticsamount",(((JSONObject)data.get(0)).getBigDecimalValue("transportFee").compareTo(BigDecimal.ZERO)>0?((JSONObject)data.get(0)).getBigDecimalValue("transportFee"):row.getDouble("logisticsamount")));
@@ -281,7 +282,7 @@ public class LSALogistics extends Controller {
                 }
 
                 JSONObject wzwlOrder = wzwlDocking.queryWzwlOrder(row.getString("billno"));
-                if(wzwlOrder.getString("success").equals("true")){
+                if(wzwlOrder.getStringValue("success").equals("true")){
                     JSONArray data = wzwlOrder.getJSONArray("data");
                     dbConnect.runSqlUpdate("update sa_logistics set logisticsstatus='"+((JSONObject)data.get(0)).getStringValue("status")+"',logisticno='"+((JSONObject)data.get(0)).getStringValue("waybillNo")+"' where sa_logisticsid="+sa_logisticsid);
                     row.put("logisticsstatus",((JSONObject)data.get(0)).getStringValue("status"));
@@ -459,10 +460,10 @@ public class LSALogistics extends Controller {
 
         SQLFactory sqlFactory = new SQLFactory(this, "物流单审核");
         if (status.equals("审核")) {
-            WzwlDocking wzwlDocking =new WzwlDocking();
+            WzwlDocking wzwlDocking =new WzwlDocking(siteid);
             JSONObject wzwlOrder = wzwlDocking.queryWzwlOrder(billno);
-            System.out.println(wzwlOrder.getString("success"));
-            if(wzwlOrder.getString("success").equals("true")){
+            System.out.println(wzwlOrder.getStringValue("success"));
+            if(wzwlOrder.getStringValue("success").equals("true")){
                 JSONArray data = wzwlOrder.getJSONArray("data");
                 System.out.println(((JSONObject)data.get(0)).getStringValue("status"));
                 if(((JSONObject)data.get(0)).getStringValue("status").equals("已签收")){
@@ -525,7 +526,7 @@ public class LSALogistics extends Controller {
     @API(title = "发送至物流", apiversion = R.ID2024101114031103.v1.class)
     public String SendToLogistics() throws YosException, NoSuchAlgorithmException, UnsupportedEncodingException {
 
-        WzwlDocking wzwlDocking =new WzwlDocking();
+        WzwlDocking wzwlDocking =new WzwlDocking(siteid);
         Long sa_logisticsid = content.getLong("sa_logisticsid");
         Rows rows = LSALogisticsHelper.getLogisticsRows(this);
         if (rows.isEmpty()) {
@@ -535,7 +536,7 @@ public class LSALogistics extends Controller {
             return getErrReturnObject().setErrMsg("该物流单为非审核状态,无法发送至物流").toString();
         }
         JSONObject wzwlOrder = wzwlDocking.queryWzwlOrder(rows.get(0).getString("billno"));
-        if(wzwlOrder.getString("success").equals("true")){
+        if(wzwlOrder.getStringValue("success").equals("true")){
             JSONArray data = wzwlOrder.getJSONArray("data");
             if(((JSONObject)data.get(0)).getStringValue("status").equals("已签收")){
                 return getErrReturnObject().setErrMsg("物流单已签收,无法再次发送!").toString();
@@ -564,7 +565,7 @@ public class LSALogistics extends Controller {
 
     @API(title = "物流状态查询", apiversion = R.ID2024101114155503.v1.class)
     public String queryWzwlOrder() throws YosException, NoSuchAlgorithmException {
-        WzwlDocking wzwlDocking =new WzwlDocking();
+        WzwlDocking wzwlDocking =new WzwlDocking(siteid);
         String billno = content.getString("billno");
         JSONObject jsonObject = wzwlDocking.queryWzwlOrder(billno);
         return getSucReturnObject().setData(jsonObject).toString();
@@ -573,7 +574,7 @@ public class LSALogistics extends Controller {
     @API(title = "物流费用查询", apiversion = R.ID2024101114265803.v1.class)
     public String queryWzwlOrderAmount() throws YosException, NoSuchAlgorithmException, UnsupportedEncodingException {
 
-        WzwlDocking wzwlDocking =new WzwlDocking();
+        WzwlDocking wzwlDocking =new WzwlDocking(siteid);
         String billno = content.getString("billno");
         JSONObject jsonObject = wzwlDocking.queryWzwlOrderAmount(billno);
         return getSucReturnObject().setData(jsonObject).toString();
@@ -582,7 +583,7 @@ public class LSALogistics extends Controller {
     @API(title = "物流费用查询", apiversion = R.ID20241019150603.v1.class)
     public String queryWzwlOrderAmountExtendList() throws YosException, NoSuchAlgorithmException, UnsupportedEncodingException {
 
-        WzwlDocking wzwlDocking =new WzwlDocking();
+        WzwlDocking wzwlDocking =new WzwlDocking(siteid);
         String billno = content.getString("billno");
         JSONObject jsonObject = wzwlDocking.queryWzwlOrderAmountExtendList(billno);
         return getSucReturnObject().setData(jsonObject).toString();

+ 118 - 103
src/custom/utility/WzwlDocking.java

@@ -24,7 +24,13 @@ public class WzwlDocking extends BaseClass {
     String companyCode = "202409241033166130229eade94bece";
     String appKey = "jA0TvC5VOHnmk8P4RdEX1wAgktMQvtlC";
     String secretKey = "mIAZwKEaUOpp";
+    boolean isDocking = false;
 
+    public WzwlDocking(String siteid) throws YosException {
+        if(siteid.equalsIgnoreCase("lsa")){
+            isDocking=true;
+        }
+    }
     /**创建万中物流订单
      * @param logisticRow
      * @param logisticItems
@@ -35,14 +41,15 @@ public class WzwlDocking extends BaseClass {
      * @throws NoSuchAlgorithmException
      */
     public String createWzwlOrder(Row logisticRow, Rows logisticItems, Controller controller, long sa_logisticsid, JSONObject sender) throws YosException, NoSuchAlgorithmException, UnsupportedEncodingException {
-        JSONObject request = new JSONObject();
-        JSONObject request1 = new JSONObject();
-        JSONObject data = new JSONObject();
-        JSONObject consigner = new JSONObject();
-        JSONObject consignee = new JSONObject();
-        JSONArray cargo = new JSONArray();
-        String settleType=logisticRow.getString("paytype");
-        String deliverType=logisticRow.getString("delivertype");
+        if(isDocking){
+            JSONObject request = new JSONObject();
+            JSONObject request1 = new JSONObject();
+            JSONObject data = new JSONObject();
+            JSONObject consigner = new JSONObject();
+            JSONObject consignee = new JSONObject();
+            JSONArray cargo = new JSONArray();
+            String settleType=logisticRow.getString("paytype");
+            String deliverType=logisticRow.getString("delivertype");
 //        switch (logisticRow.getString("paytype")){
 //            case "发货人付款(现付)":{
 //                settleType=1;
@@ -83,71 +90,73 @@ public class WzwlDocking extends BaseClass {
 //            default:
 //                break;
 //        }
-        data.put("companyCode", companyCode);
-        data.put("logisticCompanyID", "WZ");
-        data.put("custOrderNo", logisticRow.getString("billno"));
-        long timestamp = System.currentTimeMillis() / 1000;
-        data.put("submitTime",timestamp);
-        data.put("totalNum", StringUtils.isBlank(logisticRow.getString("packageqty"))?0:logisticRow.getInteger("packageqty")); //待定
-        data.put("totalWeight", StringUtils.isBlank(logisticRow.getString("weight"))?0:logisticRow.getBigDecimal("weight"));//待定
-        data.put("totalVolume", StringUtils.isBlank(logisticRow.getString("volume"))?0:logisticRow.getBigDecimal("volume"));//待定
-        data.put("settleType", StringUtils.isBlank(logisticRow.getString("paytype"))?3:logisticRow.getInteger("paytype"));
-        data.put("isPickup", "false");
-        data.put("deliverType", StringUtils.isBlank(logisticRow.getString("delivertype"))?2:logisticRow.getInteger("delivertype"));
-        data.put("remark", logisticRow.getString("remarks"));
-        //发货人
-        consigner.put("company", sender.getString("company"));
-        consigner.put("name", sender.getString("name"));
-        consigner.put("mobile", sender.getString("phonenumber"));
-        consigner.put("phone", sender.getString("phonenumber"));
-        consigner.put("province", sender.getString("province"));
-        consigner.put("city", sender.getString("city"));
-        consigner.put("district", sender.getString("county"));
-        consigner.put("address", sender.getString("address"));
-        //收货人
-        consignee.put("company", "");
-        consignee.put("name", logisticRow.getString("name"));
-        consignee.put("mobile", logisticRow.getString("phonenumber"));
-        consignee.put("phone",  logisticRow.getString("phonenumber"));
-        consignee.put("province",  logisticRow.getString("province"));
-        consignee.put("city",  logisticRow.getString("city"));
-        consignee.put("district", logisticRow.getString("county"));
-        consignee.put("address",  logisticRow.getString("address"));
-        data.put("consigner", consigner);
-        data.put("consignee", consignee);
-        for (Row row : logisticItems) {
-            JSONObject logisticItem = new JSONObject();
-            logisticItem.put("name", row.getString("itemname"));
-            logisticItem.put("num", row.getInteger("qty"));
-            cargo.add(logisticItem);
-        }
-        data.put("cargo", cargo);
-        String datastr=data.toString().replace("\"", "'");
-        String datastr1=data.toString().replace("\"", "''");
-        request1.put("data", datastr1);
-        request1.put("appKey", appKey);
-        request1.put("digest", digest_MD5_Base64(datastr, secretKey));
-        request.put("data", datastr);
-        request.put("appKey", appKey);
-        request.put("digest", digest_MD5_Base64(datastr, secretKey));
-        HashMap<String, String> map = new HashMap<>();
-        map.put("content-Type", "application/json");
-        System.out.println(request.toString());
-        String result = new WebRequest().doPost(request.toString(), url + "OrderCreate", map);
-        JSONObject resultobject = JSONObject.parseObject(result);
+            data.put("companyCode", companyCode);
+            data.put("logisticCompanyID", "WZ");
+            data.put("custOrderNo", logisticRow.getString("billno"));
+            long timestamp = System.currentTimeMillis() / 1000;
+            data.put("submitTime",timestamp);
+            data.put("totalNum", StringUtils.isBlank(logisticRow.getString("packageqty"))?0:logisticRow.getInteger("packageqty")); //待定
+            data.put("totalWeight", StringUtils.isBlank(logisticRow.getString("weight"))?0:logisticRow.getBigDecimal("weight"));//待定
+            data.put("totalVolume", StringUtils.isBlank(logisticRow.getString("volume"))?0:logisticRow.getBigDecimal("volume"));//待定
+            data.put("settleType", StringUtils.isBlank(logisticRow.getString("paytype"))?3:logisticRow.getInteger("paytype"));
+            data.put("isPickup", "false");
+            data.put("deliverType", StringUtils.isBlank(logisticRow.getString("delivertype"))?2:logisticRow.getInteger("delivertype"));
+            data.put("remark", logisticRow.getString("remarks"));
+            //发货人
+            consigner.put("company", sender.getString("company"));
+            consigner.put("name", sender.getString("name"));
+            consigner.put("mobile", sender.getString("phonenumber"));
+            consigner.put("phone", sender.getString("phonenumber"));
+            consigner.put("province", sender.getString("province"));
+            consigner.put("city", sender.getString("city"));
+            consigner.put("district", sender.getString("county"));
+            consigner.put("address", sender.getString("address"));
+            //收货人
+            consignee.put("company", "");
+            consignee.put("name", logisticRow.getString("name"));
+            consignee.put("mobile", logisticRow.getString("phonenumber"));
+            consignee.put("phone",  logisticRow.getString("phonenumber"));
+            consignee.put("province",  logisticRow.getString("province"));
+            consignee.put("city",  logisticRow.getString("city"));
+            consignee.put("district", logisticRow.getString("county"));
+            consignee.put("address",  logisticRow.getString("address"));
+            data.put("consigner", consigner);
+            data.put("consignee", consignee);
+            for (Row row : logisticItems) {
+                JSONObject logisticItem = new JSONObject();
+                logisticItem.put("name", row.getString("itemname"));
+                logisticItem.put("num", row.getInteger("qty"));
+                cargo.add(logisticItem);
+            }
+            data.put("cargo", cargo);
+            String datastr=data.toString().replace("\"", "'");
+            String datastr1=data.toString().replace("\"", "''");
+            request1.put("data", datastr1);
+            request1.put("appKey", appKey);
+            request1.put("digest", digest_MD5_Base64(datastr, secretKey));
+            request.put("data", datastr);
+            request.put("appKey", appKey);
+            request.put("digest", digest_MD5_Base64(datastr, secretKey));
+            HashMap<String, String> map = new HashMap<>();
+            map.put("content-Type", "application/json");
+            System.out.println(request.toString());
+            String result = new WebRequest().doPost(request.toString(), url + "OrderCreate", map);
+            JSONObject resultobject = JSONObject.parseObject(result);
 
-        saveLog(controller, "sa_logistics", sa_logisticsid, "创建万众物流订单", request1.toString(), resultobject);
+            saveLog(controller, "sa_logistics", sa_logisticsid, "创建万众物流订单", request1.toString(), resultobject);
 
-        if (resultobject != null) {
-            if (resultobject.getString("success").equals("true")) {
-                return "true";
+            if (resultobject != null) {
+                if (resultobject.getString("success").equals("true")) {
+                    return "true";
+                } else {
+                    return resultobject.getString("errorMessage");
+                }
             } else {
-                return resultobject.getString("errorMessage");
+                return "false";
             }
-        } else {
-            return "false";
+        }else{
+            return "true";
         }
-
     }
 
     /**
@@ -158,17 +167,19 @@ public class WzwlDocking extends BaseClass {
      * @throws NoSuchAlgorithmException
      */
     public JSONObject queryWzwlOrder(String orderNo) throws YosException, NoSuchAlgorithmException {
-        JSONObject request = new JSONObject();
-        JSONObject data = new JSONObject();
-
-        data.put("companyCode", companyCode);
-        data.put("orderNo", orderNo);
+        JSONObject resultobject=new JSONObject();
+        if(isDocking) {
+            JSONObject request = new JSONObject();
+            JSONObject data = new JSONObject();
 
-        HashMap<String, String> map = new HashMap<>();
-        map.put("content-Type", "application/json");
-        String result = new WebRequest().doPost(data.toString(), url + "OrderQuery", map);
-        JSONObject resultobject = JSONObject.parseObject(result);
+            data.put("companyCode", companyCode);
+            data.put("orderNo", orderNo);
 
+            HashMap<String, String> map = new HashMap<>();
+            map.put("content-Type", "application/json");
+            String result = new WebRequest().doPost(data.toString(), url + "OrderQuery", map);
+            resultobject = JSONObject.parseObject(result);
+        }
         return  resultobject;
     }
 
@@ -180,39 +191,43 @@ public class WzwlDocking extends BaseClass {
      * @throws NoSuchAlgorithmException
      */
     public JSONObject queryWzwlOrderAmount(String orderNo) throws YosException, NoSuchAlgorithmException, UnsupportedEncodingException {
-        JSONObject request = new JSONObject();
-        JSONObject data = new JSONObject();
-
-        data.put("companyCode", companyCode);
-        data.put("orderNo", orderNo);
-        String datastr =data.toString().replace("\"", "'");
-        request.put("data", data.toString().replace("\"", "'"));
-        request.put("appKey", appKey);
-        request.put("digest", digest_MD5_Base64(datastr, secretKey));
-        HashMap<String, String> map = new HashMap<>();
-        map.put("content-Type", "application/json");
-        String result = new WebRequest().doPost(request.toString(), url + "OrderAmountList", map);
-        JSONObject resultobject = JSONObject.parseObject(result);
+        JSONObject resultobject=new JSONObject();
+        if(isDocking) {
+            JSONObject request = new JSONObject();
+            JSONObject data = new JSONObject();
 
+            data.put("companyCode", companyCode);
+            data.put("orderNo", orderNo);
+            String datastr =data.toString().replace("\"", "'");
+            request.put("data", data.toString().replace("\"", "'"));
+            request.put("appKey", appKey);
+            request.put("digest", digest_MD5_Base64(datastr, secretKey));
+            HashMap<String, String> map = new HashMap<>();
+            map.put("content-Type", "application/json");
+            String result = new WebRequest().doPost(request.toString(), url + "OrderAmountList", map);
+            resultobject = JSONObject.parseObject(result);
+        }
         return  resultobject;
     }
 
 
     public JSONObject queryWzwlOrderAmountExtendList(String orderNo) throws YosException, NoSuchAlgorithmException, UnsupportedEncodingException {
-        JSONObject request = new JSONObject();
-        JSONObject data = new JSONObject();
-
-        data.put("companyCode", companyCode);
-        data.put("orderNo", orderNo);
-        String datastr =data.toString().replace("\"", "'");
-        request.put("data", data.toString().replace("\"", "'"));
-        request.put("appKey", appKey);
-        request.put("digest", digest_MD5_Base64(datastr, secretKey));
-        HashMap<String, String> map = new HashMap<>();
-        map.put("content-Type", "application/json");
-        String result = new WebRequest().doPost(request.toString(), url + "OrderAmountExtendList", map);
-        JSONObject resultobject = JSONObject.parseObject(result);
+        JSONObject resultobject=new JSONObject();
+        if(isDocking) {
+            JSONObject request = new JSONObject();
+            JSONObject data = new JSONObject();
 
+            data.put("companyCode", companyCode);
+            data.put("orderNo", orderNo);
+            String datastr =data.toString().replace("\"", "'");
+            request.put("data", data.toString().replace("\"", "'"));
+            request.put("appKey", appKey);
+            request.put("digest", digest_MD5_Base64(datastr, secretKey));
+            HashMap<String, String> map = new HashMap<>();
+            map.put("content-Type", "application/json");
+            String result = new WebRequest().doPost(request.toString(), url + "OrderAmountExtendList", map);
+            resultobject = JSONObject.parseObject(result);
+        }
         return  resultobject;
     }