From aea629d098bdab0918d90e0c51af9d7b099bca12 Mon Sep 17 00:00:00 2001
From: Junjie <fallin.jie@qq.com>
Date: 星期五, 31 五月 2024 20:45:51 +0800
Subject: [PATCH] #新旧物料更新接口
---
src/main/java/com/zy/asrs/task/handler/OrderSyncHandler.java | 135 ++++++++++++++++++++++++++------------------
1 files changed, 79 insertions(+), 56 deletions(-)
diff --git a/src/main/java/com/zy/asrs/task/handler/OrderSyncHandler.java b/src/main/java/com/zy/asrs/task/handler/OrderSyncHandler.java
index a94b4bd..9da4362 100644
--- a/src/main/java/com/zy/asrs/task/handler/OrderSyncHandler.java
+++ b/src/main/java/com/zy/asrs/task/handler/OrderSyncHandler.java
@@ -3,7 +3,6 @@
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.core.common.Cools;
-import com.core.common.DateUtils;
import com.core.exception.CoolException;
import com.zy.asrs.entity.DocType;
import com.zy.asrs.entity.Order;
@@ -14,16 +13,16 @@
import com.zy.asrs.service.OrderService;
import com.zy.asrs.task.AbstractHandler;
import com.zy.asrs.task.core.ReturnT;
-import com.zy.common.constant.MesConstant;
-import com.zy.common.model.MesPakinParam;
import com.zy.common.utils.HttpHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
-import java.util.List;
+import java.text.SimpleDateFormat;
+import java.util.*;
/**
* Created by vincent on 2020/7/7
@@ -43,67 +42,91 @@
@Autowired
private DocTypeService docTypeService;
+ @Value("${u8.url}")
+ private String url;
+
+ @Value("${u8.orderReportPath}")
+ private String orderReportPath;
+
@Transactional
public ReturnT<String> start(Order order) {
+
DocType docType = docTypeService.selectById(order.getDocType());
- if (null == docType) {
+ if("鎵嬪姩鍑哄簱鍗�".equals(docType.getDocName())
+ || "鎵嬪姩鍏ュ簱鍗�".equals(docType.getDocName())
+ || "鑷姩琛ヨ揣鍗�".equals(docType.getDocName())
+ || "浜哄伐琛ヨ揣鍗�".equals(docType.getDocName())){
+ order.setSettle(8L);
+ orderService.updateById(order);
return SUCCESS;
}
+
+
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+ Map<String, Object> param = new HashMap<>();
+ param.put("id",order.getOrderNo());
+ param.put("dDate",sdf.format(new Date()));
+ param.put("cHandler","WMS绯荤粺");
+
+ List<Map<String,Object>> orderDetlsParam = new ArrayList<>();
+ param.put("orderDetails",orderDetlsParam);
+
List<OrderDetl> orderDetls = orderDetlService.selectByOrderId(order.getId());
- // 鍏ュ簱瀹屾垚涓婃姤
- if (docType.getPakin() == 1) {
- MesPakinParam pakinParam = new MesPakinParam();
- pakinParam.setPakinTime(DateUtils.convert(order.getUpdateTime()));
- pakinParam.setLgortFrom("5008");
- pakinParam.setLgortTo("5006");
- for (OrderDetl orderDetl : orderDetls) {
- String serial = Cools.isEmpty(orderDetl.getBatch()) ? "" : orderDetl.getBatch();
- pakinParam.getList().add(new MesPakinParam.Detl(orderDetl.getMatnr() + (Cools.isEmpty(serial) ? "" : "-" + serial), orderDetl.getAnfme()));
- }
- String response = "";
- boolean success = false;
- try {
- response = new HttpHandler.Builder()
- .setUri(MesConstant.URL)
- .setPath(MesConstant.PAKIN_URL)
- .setJson(JSON.toJSONString(pakinParam))
- .build()
- .doPost();
- JSONObject jsonObject = JSON.parseObject(response);
- if (jsonObject.getInteger("code").equals(200)) {
- success = true;
- // 淇敼璁㈠崟鐘舵�� 4.瀹屾垚 ===>> 6.宸蹭笂鎶�
- if (!orderService.updateSettle(order.getId(), 6L, null)) {
- throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇紝璇疯仈绯荤鐞嗗憳");
- }
- } else {
- log.error("璇锋眰鎺ュ彛澶辫触锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", MesConstant.URL+MesConstant.PAKIN_URL, JSON.toJSONString(pakinParam), response);
- throw new CoolException("涓婃姤mes绯荤粺澶辫触");
- }
- } catch (Exception e) {
- log.error("fail", e);
-// TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
- return FAIL.setMsg(e.getMessage());
- } finally {
- try {
- // 淇濆瓨鎺ュ彛鏃ュ織
- apiLogService.save(
- "鎴愬搧搴撳叆搴撲笂鎶�",
- MesConstant.URL + MesConstant.PAKIN_URL,
- null,
- "127.0.0.1",
- JSON.toJSONString(pakinParam),
- response,
- success
- );
- } catch (Exception e) { log.error("", e); }
- }
+
+ for (OrderDetl orderDetl : orderDetls){
+ Map<String, Object> odMap = new HashMap<>();
+ odMap.put("autoid",orderDetl.getItemNum());
+ odMap.put("iQuantity",orderDetl.getQty());
+ orderDetlsParam.add(odMap);
}
- // 鍑哄簱瀹屾垚涓婃姤
- if (docType.getPakout() == 1) {
- // todo
+
+ int code = doHttpRequest(param, "鍗曟嵁瀹℃牳", url, orderReportPath, null, "127.0.0.1");
+ if(code == 0){
+ order.setSettle(6L);
+ orderService.updateById(order);
}
+
return SUCCESS;
}
+ private int doHttpRequest(Object requestParam, String namespace, String url, String path, String appkey, String ip){
+ String response = "";
+ boolean success = false;
+
+ try {
+ response = new HttpHandler.Builder()
+ .setUri(url)
+ .setPath(path)
+ .setJson(JSONObject.toJSONString(requestParam))
+ .build()
+ .doPost();
+ JSONObject jsonObject = JSON.parseObject(response);
+
+ if(Cools.isEmpty(jsonObject.get("errCode"))){
+ throw new CoolException(jsonObject.get("Message").toString());
+ }
+
+ int code = (int) jsonObject.get("errCode");
+ if(code != 0){
+ throw new CoolException(jsonObject.get("errMsg").toString());
+ }
+ success = true;
+ return code;
+ }catch (Exception e){
+ log.error(e.getMessage());
+ throw new CoolException("璋冪敤鎺ュ彛鍝嶅簲閿欒");
+ }finally {
+ apiLogService.save(
+ namespace,
+ url + path,
+ appkey,
+ ip,
+ JSON.toJSONString(JSONObject.toJSONString(requestParam)),
+ response,
+ success
+ );
+ }
+
+ }
+
}
--
Gitblit v1.9.1