|
@@ -0,0 +1,261 @@
|
|
|
|
|
+package utility;
|
|
|
|
|
+
|
|
|
|
|
+import beans.uploaderpdata.UploadDataToERP_HY;
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
+import common.BaseClass;
|
|
|
|
|
+import common.Controller;
|
|
|
|
|
+import common.YosException;
|
|
|
|
|
+import common.data.Row;
|
|
|
|
|
+import common.data.Rows;
|
|
|
|
|
+import common.data.SQLFactory;
|
|
|
|
|
+import org.apache.cxf.common.i18n.Exception;
|
|
|
|
|
+import utility.tools.WebRequest;
|
|
|
|
|
+
|
|
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
|
|
|
+import java.security.MessageDigest;
|
|
|
|
|
+import java.security.NoSuchAlgorithmException;
|
|
|
|
|
+import java.util.Base64;
|
|
|
|
|
+import java.util.HashMap;
|
|
|
|
|
+
|
|
|
|
|
+public class WzwlDocking extends BaseClass {
|
|
|
|
|
+ String url = "http://w800.zjwqrj.com:9092/zh-CN/Flow/WApi/";
|
|
|
|
|
+ String companyCode = "202409241033166130229eade94bece";
|
|
|
|
|
+ String appKey = "jA0TvC5VOHnmk8P4RdEX1wAgktMQvtlC";
|
|
|
|
|
+ String secretKey = "mIAZwKEaUOpp";
|
|
|
|
|
+
|
|
|
|
|
+ /**创建万中物流订单
|
|
|
|
|
+ * @param logisticRow
|
|
|
|
|
+ * @param logisticItems
|
|
|
|
|
+ * @param controller
|
|
|
|
|
+ * @param sa_logisticsid
|
|
|
|
|
+ * @return
|
|
|
|
|
+ * @throws YosException
|
|
|
|
|
+ * @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 data = new JSONObject();
|
|
|
|
|
+ JSONObject consigner = new JSONObject();
|
|
|
|
|
+ JSONObject consignee = new JSONObject();
|
|
|
|
|
+ JSONArray cargo = new JSONArray();
|
|
|
|
|
+ int settleType=1;
|
|
|
|
|
+ int deliverType=2;
|
|
|
|
|
+ switch (logisticRow.getString("paytype")){
|
|
|
|
|
+ case "发货人付款(现付)":{
|
|
|
|
|
+ settleType=1;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ case "按月支付(月结)":{
|
|
|
|
|
+ settleType=2;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ case "收货人付款(到付)":{
|
|
|
|
|
+ settleType=3;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ case "回付":{
|
|
|
|
|
+ settleType=4;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ case "混合支付":{
|
|
|
|
|
+ settleType=5;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ default:
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ switch (logisticRow.getString("delivertype")){
|
|
|
|
|
+ case "送货上门":{
|
|
|
|
|
+ deliverType=1;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ case "自提":{
|
|
|
|
|
+ deliverType=2;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ case "送货安装":{
|
|
|
|
|
+ deliverType=4;
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ 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", 0); //待定
|
|
|
|
|
+ data.put("totalWeight", 0);//待定
|
|
|
|
|
+ data.put("totalVolume", 0);//待定
|
|
|
|
|
+ data.put("settleType", settleType);
|
|
|
|
|
+ data.put("isPickup", "false");
|
|
|
|
|
+ data.put("deliverType", 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("\"", "'");
|
|
|
|
|
+ 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, "创建万众物流订单", request.toString(), resultobject);
|
|
|
|
|
+
|
|
|
|
|
+ if (resultobject != null) {
|
|
|
|
|
+ if (resultobject.getString("success").equals("true")) {
|
|
|
|
|
+ return "true";
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return resultobject.getString("errorMessage");
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ return "false";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ *订单状态查询
|
|
|
|
|
+ * @param orderNo
|
|
|
|
|
+ * @return
|
|
|
|
|
+ * @throws YosException
|
|
|
|
|
+ * @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);
|
|
|
|
|
+
|
|
|
|
|
+ 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);
|
|
|
|
|
+
|
|
|
|
|
+ return resultobject;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ *查询总费用
|
|
|
|
|
+ * @param orderNo
|
|
|
|
|
+ * @return
|
|
|
|
|
+ * @throws YosException
|
|
|
|
|
+ * @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);
|
|
|
|
|
+
|
|
|
|
|
+ return resultobject;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ //生成digest (data 中的内容,使用data+secretKey 进行 MD5,再进行 Base64 转换后生成的摘要内容)
|
|
|
|
|
+ public static String digest_MD5_Base64(String data, String secretKey) throws NoSuchAlgorithmException, UnsupportedEncodingException {
|
|
|
|
|
+ String str = data+secretKey;
|
|
|
|
|
+ System.out.println(str);
|
|
|
|
|
+ // 创建MD5摘要
|
|
|
|
|
+ MessageDigest md = MessageDigest.getInstance("MD5");
|
|
|
|
|
+ byte[] digest = md.digest(str.getBytes("UTF-8"));
|
|
|
|
|
+
|
|
|
|
|
+ // 将摘要转换为Base64字符串
|
|
|
|
|
+ String base64Digest = Base64.getEncoder().encodeToString(digest);
|
|
|
|
|
+ System.out.println(base64Digest);
|
|
|
|
|
+ return base64Digest;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 上传日志更新
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param controller
|
|
|
|
|
+ * @param ownertable
|
|
|
|
|
+ * @param ownerid
|
|
|
|
|
+ * @param type
|
|
|
|
|
+ * @param request
|
|
|
|
|
+ * @param response
|
|
|
|
|
+ * @return
|
|
|
|
|
+ */
|
|
|
|
|
+ public static boolean saveLog(Controller controller, String ownertable, long ownerid, String type, String
|
|
|
|
|
+ request,
|
|
|
|
|
+ JSONObject response) {
|
|
|
|
|
+ boolean issuccess = false;
|
|
|
|
|
+ try {
|
|
|
|
|
+ Rows rows = controller.dbConnect.runSqlQuery(
|
|
|
|
|
+ "select * from sys_erpupdatelog where ownertable='" + ownertable + "' and ownerid=" + ownerid);
|
|
|
|
|
+ SQLFactory sqlFactory;
|
|
|
|
|
+ if (!rows.isEmpty()) {
|
|
|
|
|
+ sqlFactory = new SQLFactory(new UploadDataToERP_HY(), "erp上传日志更新");
|
|
|
|
|
+ sqlFactory.addParameter("sys_erpupdatelogid", rows.get(0).getLong("sys_erpupdatelogid"));
|
|
|
|
|
+ } else {
|
|
|
|
|
+ sqlFactory = new SQLFactory(new UploadDataToERP_HY(), "erp上传日志新增");
|
|
|
|
|
+ sqlFactory.addParameter("sys_erpupdatelogid", controller.createTableID("sys_erpupdatelog"));
|
|
|
|
|
+ }
|
|
|
|
|
+ sqlFactory.addParameter("siteid", controller.siteid);
|
|
|
|
|
+ sqlFactory.addParameter("userid", controller.userid);
|
|
|
|
|
+ sqlFactory.addParameter("username", controller.username);
|
|
|
|
|
+ sqlFactory.addParameter("ownerid", ownerid);
|
|
|
|
|
+ sqlFactory.addParameter("ownertable", ownertable);
|
|
|
|
|
+ sqlFactory.addParameter("type", type);
|
|
|
|
|
+ sqlFactory.addParameter("request", request);
|
|
|
|
|
+ sqlFactory.addParameter("response", response.toJSONString());
|
|
|
|
|
+
|
|
|
|
|
+ if ("true".equals(response.getString("success"))) {
|
|
|
|
|
+ sqlFactory.addParameter("erpbillno", response.getString("orderNo"));
|
|
|
|
|
+ sqlFactory.addParameter("errmsg", "");
|
|
|
|
|
+ issuccess = true;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ sqlFactory.addParameter("erpbillno", "");
|
|
|
|
|
+ sqlFactory.addParameter("errmsg", response.getString("errorMessage"));
|
|
|
|
|
+ issuccess = false;
|
|
|
|
|
+ }
|
|
|
|
|
+ sqlFactory.addParameter("status", response.getString("success"));
|
|
|
|
|
+ logger.info("sql:" + sqlFactory.getSQL());
|
|
|
|
|
+ controller.dbConnect.runSqlUpdate(sqlFactory);
|
|
|
|
|
+ } catch (YosException e) {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ }
|
|
|
|
|
+ return issuccess;
|
|
|
|
|
+ }
|
|
|
|
|
+}
|