|
@@ -0,0 +1,207 @@
|
|
|
+package com.sd.wln.util;
|
|
|
+
|
|
|
+import cn.hutool.core.io.IoUtil;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
+import com.ruoyi.common.exception.ServiceException;
|
|
|
+import com.ruoyi.common.utils.MapUtil;
|
|
|
+import com.sd.wln.constants.WlnConstant;
|
|
|
+import com.sd.wln.entity.GoodsSpecParam;
|
|
|
+import com.sd.wln.entity.SkuClassifyParam;
|
|
|
+import com.sd.wln.entity.StockParam;
|
|
|
+import com.sd.wln.entity.TradesParam;
|
|
|
+import org.apache.http.HttpEntity;
|
|
|
+import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
+import org.apache.http.client.methods.HttpPost;
|
|
|
+import org.apache.http.entity.StringEntity;
|
|
|
+import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
+import org.apache.http.impl.client.HttpClients;
|
|
|
+import org.apache.http.util.EntityUtils;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+public class WlnUtil {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 万里牛路径前缀
|
|
|
+ */
|
|
|
+ private static final String PREFIX = "https://open-api.hupun.com/api/";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取sku分类
|
|
|
+ */
|
|
|
+ public static List<JSONObject> getSkuClassifyList() throws Exception {
|
|
|
+ SkuClassifyParam param = new SkuClassifyParam();
|
|
|
+ param.setCom_uid(WlnConstant.COM_UID);
|
|
|
+ String linkString = MapUtil.createLinkString(MapUtil.beanToMap(param));
|
|
|
+ param.generateSign(linkString);
|
|
|
+
|
|
|
+ String result = send(PREFIX + "erp/goods/catagory/query", param);
|
|
|
+ JSONObject json = JSONObject.parseObject(result);
|
|
|
+ Integer code = json.getInteger("code");
|
|
|
+ if (code != 0) {
|
|
|
+ throw new ServiceException(result);
|
|
|
+ }
|
|
|
+ return json.getJSONArray("data").toJavaList(JSONObject.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取sku列表
|
|
|
+ */
|
|
|
+ public static List<JSONObject> getSkuList(Integer page, Integer limit) throws Exception {
|
|
|
+ GoodsSpecParam param = new GoodsSpecParam();
|
|
|
+ param.setPage(page);
|
|
|
+ param.setLimit(limit);
|
|
|
+ param.setModify_time(965381503L);
|
|
|
+ param.generateSign(MapUtil.createLinkString(MapUtil.beanToMap(param)));
|
|
|
+ String result = send(PREFIX + "erp/goods/spec/open/query/goodswithspeclist", MapUtil.beanToMap(param));
|
|
|
+ JSONObject json = JSONObject.parseObject(result);
|
|
|
+ Integer code = json.getInteger("code");
|
|
|
+ if (code != 0) {
|
|
|
+ throw new ServiceException(result);
|
|
|
+ }
|
|
|
+ return json.getJSONArray("data").toJavaList(JSONObject.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取订单
|
|
|
+ */
|
|
|
+ public static List<JSONObject> getOrderList(Integer page, Integer limit, Long startTime, Long endTime, String warehouseCode) throws Exception {
|
|
|
+ TradesParam param = new TradesParam();
|
|
|
+ param.setPage(page);
|
|
|
+ param.setLimit(limit);
|
|
|
+ param.setModify_time(startTime);
|
|
|
+ param.setEnd_time(endTime);
|
|
|
+ param.setStorage_code(warehouseCode);
|
|
|
+ param.setIs_split(true);
|
|
|
+ param.setManualImport(false);
|
|
|
+ param.generateSign(MapUtil.createLinkString(MapUtil.beanToMap(param)));
|
|
|
+
|
|
|
+ String result = send(PREFIX + "erp/opentrade/list/trades", MapUtil.beanToMap(param));
|
|
|
+ JSONObject json = JSONObject.parseObject(result);
|
|
|
+ Integer code = json.getInteger("code");
|
|
|
+ if (code != 0) {
|
|
|
+ throw new ServiceException(result);
|
|
|
+ }
|
|
|
+ return json.getJSONArray("data").toJavaList(JSONObject.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取订单
|
|
|
+ */
|
|
|
+ public static JSONObject getOrderByWlnCode(String wlnCode) throws Exception {
|
|
|
+ TradesParam param = new TradesParam();
|
|
|
+ param.setBill_code(wlnCode);
|
|
|
+ param.setPage(1);
|
|
|
+ param.setLimit(10);
|
|
|
+ param.setIs_split(true);
|
|
|
+ param.setManualImport(false);
|
|
|
+ param.generateSign(MapUtil.createLinkString(MapUtil.beanToMap(param)));
|
|
|
+ String result = send(PREFIX + "erp/opentrade/list/trades", MapUtil.beanToMap(param));
|
|
|
+ JSONObject json = JSONObject.parseObject(result);
|
|
|
+ Integer code = json.getInteger("code");
|
|
|
+ if (code != 0) {
|
|
|
+ throw new ServiceException(result);
|
|
|
+ }
|
|
|
+ List<JSONObject> list = json.getJSONArray("data").toJavaList(JSONObject.class);
|
|
|
+
|
|
|
+ if (list.isEmpty()) {
|
|
|
+ throw new ServiceException("未能通过万里牛订单编号找到订单");
|
|
|
+ }
|
|
|
+ if (list.size() > 1) {
|
|
|
+ throw new ServiceException("通过万里牛订单编号找到多条订单");
|
|
|
+ }
|
|
|
+ return list.get(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取出库单
|
|
|
+ */
|
|
|
+ public static List<JSONObject> getOutboundOrder(Integer page, Integer limit, Long startTime, Long endTime) throws IOException {
|
|
|
+ StockParam param = new StockParam();
|
|
|
+ param.setPage(page);
|
|
|
+ param.setLimit(limit);
|
|
|
+ param.setModify_time(startTime);
|
|
|
+ param.setModify_end_time(endTime);
|
|
|
+ param.setIs_split(true);
|
|
|
+ param.generateSign(MapUtil.createLinkString(MapUtil.beanToMap(param)));
|
|
|
+
|
|
|
+ String result = send(PREFIX + "erp/sale/stock/out/query", MapUtil.beanToMap(param));
|
|
|
+ JSONObject json = JSONObject.parseObject(result);
|
|
|
+ Integer code = json.getInteger("code");
|
|
|
+ if (code != 0) {
|
|
|
+ throw new ServiceException(result);
|
|
|
+ }
|
|
|
+ return json.getJSONArray("data").toJavaList(JSONObject.class);
|
|
|
+ }
|
|
|
+
|
|
|
+// public static void main(String[] args) throws Exception {
|
|
|
+// List<JSONObject> skuList = getSkuList(1, 200);
|
|
|
+// System.out.println();
|
|
|
+//
|
|
|
+// List<JSONObject> skuClassifyList = getSkuClassifyList();
|
|
|
+// System.out.println();
|
|
|
+//
|
|
|
+// long endTime = System.currentTimeMillis();
|
|
|
+// long startTime = endTime - 1000 * 60 * 60 * 24;
|
|
|
+// List<JSONObject> orderList = getOrderList(1, 50, startTime, endTime, "B012");
|
|
|
+// System.out.println();
|
|
|
+
|
|
|
+// String a = "[\"XD231026000939\",\"XD231026000908\",\"XD231026001177\",\"XD231026001036\",\"XD231026001184\",\"XD231026001229\",\"XD231026001432\",\"XD231026001431\",\"XD231026001310\",\"XD231026001572\",\"XD231026001441\",\"XD231026001205\",\"XD231026001215\",\"XD231026001602\",\"XD231026001419\",\"XD231026001632\",\"XD231026001662\",\"XD231026001459\",\"XD231026001414\",\"XD231026001235\",\"XD231026001268\",\"XD231026001298\",\"XD231026001481\",\"XD231026001265\",\"XD231026001376\",\"XD231026001683\",\"XD231026001559\",\"XD231026001589\",\"XD231026001325\",\"XD231026001511\",\"XD231026001497\",\"XD231026001507\",\"XD231026001506\",\"XD231026001365\",\"XD231026001742\",\"XD231026001574\",\"XD231026001551\",\"XD231026001620\",\"XD231026001614\",\"XD231026001762\",\"XD231026001455\",\"XD231026001680\",\"XD231026001684\",\"XD231026001641\",\"XD231026001704\",\"XD231026001724\",\"XD231026001667\",\"XD231026001606\",\"XD231026001852\",\"XD231026001872\",\"XD231026001710\",\"XD231026001677\",\"XD231026001681\",\"XD231026001892\",\"XD231026001749\",\"XD231026001701\",\"XD231026001721\",\"XD231026001750\",\"XD231026001666\",\"XD231026002062\"]";
|
|
|
+// List<String> strings = JSON.parseArray(a, String.class);
|
|
|
+// String collect = String.join(",", strings);
|
|
|
+// List<JSONObject> orderList = getOrderListByWlnCodeList(collect);
|
|
|
+// System.out.println(orderList.toString());
|
|
|
+
|
|
|
+// long endTime = System.currentTimeMillis();
|
|
|
+// long startTime = endTime - 1000 * 60 * 60 * 24 * 7;
|
|
|
+// List<JSONObject> outboundOrder = getOutboundOrder(0, 200, 1690367461000L, 1690367461000L);
|
|
|
+// System.out.println();
|
|
|
+// }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * post请求
|
|
|
+ */
|
|
|
+ private static String send(String url, Object param) throws IOException {
|
|
|
+ String params = JSONUtil.toJsonStr(param);
|
|
|
+ StringEntity entity = new StringEntity(params, "UTF-8");
|
|
|
+
|
|
|
+ HttpPost httpPost = new HttpPost(url);
|
|
|
+ httpPost.setHeader("Accept", "application/json");
|
|
|
+ httpPost.setHeader("Content-Type", "application/json");
|
|
|
+ httpPost.setHeader("User-Agent", "PostmanRuntime/7.29.2");
|
|
|
+ httpPost.setHeader("Accept", "*/*");
|
|
|
+ httpPost.setEntity(entity);
|
|
|
+ CloseableHttpClient httpclient = HttpClients.createDefault();
|
|
|
+ CloseableHttpResponse response = null;
|
|
|
+ try {
|
|
|
+ response = httpclient.execute(httpPost);
|
|
|
+ HttpEntity responseEntity = response.getEntity();
|
|
|
+ return EntityUtils.toString(responseEntity);
|
|
|
+ } finally {
|
|
|
+ IoUtil.close(response);
|
|
|
+ IoUtil.close(httpclient);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取订单
|
|
|
+ */
|
|
|
+ public static List<JSONObject> getOrderListByWlnCodeList(String wlnCodeListStr) throws Exception {
|
|
|
+ TradesParam param = new TradesParam();
|
|
|
+ param.setBill_code(wlnCodeListStr);
|
|
|
+ param.setPage(1);
|
|
|
+ param.setLimit(200);
|
|
|
+ param.generateSign(MapUtil.createLinkString(MapUtil.beanToMap(param)));
|
|
|
+ String result = send(PREFIX + "erp/opentrade/list/trades", MapUtil.beanToMap(param));
|
|
|
+ JSONObject json = JSONObject.parseObject(result);
|
|
|
+ Integer code = json.getInteger("code");
|
|
|
+ if (code != 0) {
|
|
|
+ throw new ServiceException(result);
|
|
|
+ }
|
|
|
+ return json.getJSONArray("data").toJavaList(JSONObject.class);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|