From e66095ce55dcc9450b953f77dd753c698c53fd55 Mon Sep 17 00:00:00 2001
From: zwl <1051256694@qq.com>
Date: 星期一, 27 十月 2025 08:12:27 +0800
Subject: [PATCH] 更新erp对接 1.销售订单按子单自动上报 2.其他订单按主单上报 3.客户可以选择物料进行出库
---
src/main/java/com/zy/asrs/task/handler/OrderSyncHandler.java | 403 ++++++++++++++++++++++++++++++++++++++++++--------------
1 files changed, 299 insertions(+), 104 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 0080271..fdf3095 100644
--- a/src/main/java/com/zy/asrs/task/handler/OrderSyncHandler.java
+++ b/src/main/java/com/zy/asrs/task/handler/OrderSyncHandler.java
@@ -1,29 +1,26 @@
package com.zy.asrs.task.handler;
-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;
-import com.zy.asrs.entity.OrderDetl;
-import com.zy.asrs.service.ApiLogService;
-import com.zy.asrs.service.DocTypeService;
-import com.zy.asrs.service.OrderDetlService;
-import com.zy.asrs.service.OrderService;
+import com.zy.asrs.entity.*;
+import com.zy.asrs.service.*;
+import com.zy.asrs.service.impl.OrderDetl1ServiceImpl;
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.model.MesPakoutParam;
-import com.zy.common.utils.HttpHandler;
+import com.zy.third.entity.ExdInstockTarget;
+import com.zy.third.entity.ExdOutstockTarget;
+import com.zy.third.entity.ExdvYanbu;
+import com.zy.third.mapper.ExdMaterialMapper;
+import com.zy.third.service.ExdInstockTargetService;
+import com.zy.third.service.ExdOutstockTargetService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
+import java.math.BigDecimal;
+import java.util.Date;
import java.util.List;
/**
@@ -33,8 +30,7 @@
@Service
public class OrderSyncHandler extends AbstractHandler<String> {
- @Autowired
- private JdbcTemplate jdbcTemplate;
+
@Autowired
private OrderService orderService;
@Autowired
@@ -44,6 +40,20 @@
@Autowired
private DocTypeService docTypeService;
+ @Autowired
+ private ExdInstockTargetService exdInstockTargetService;
+
+ @Autowired
+ private ExdOutstockTargetService exdOutstockTargetService;
+ @Autowired
+ private MatService matService;
+ @Autowired
+ private OrderDetl1ServiceImpl orderDetl1Service;
+ @Autowired
+ private ExdMaterialMapper exdMaterialMapper;
+ @Autowired
+ private Order1Service order1Service;
+
@Transactional
public ReturnT<String> start(Order order) {
DocType docType = docTypeService.selectById(order.getDocType());
@@ -51,105 +61,290 @@
return SUCCESS;
}
List<OrderDetl> orderDetls = orderDetlService.selectByOrderId(order.getId());
+ if (orderDetls.isEmpty()) {
+ return SUCCESS;
+ }
// 鍏ュ簱瀹屾垚涓婃姤
if (docType.getPakin() == 1) {
- MesPakinParam pakinParam = new MesPakinParam();
- pakinParam.setPakinTime(DateUtils.convert(order.getUpdateTime()));
- pakinParam.setLgortFrom("5008");
- pakinParam.setLgortTo("5006");
+ ExdInstockTarget exdInstockTarge = null;
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()));
+ exdInstockTarge = new ExdInstockTarget();
+ exdInstockTarge.setFinterid(orderDetl.getDeadWarn());
+ exdInstockTarge.setFbillno(orderDetl.getOrderNo());
+ exdInstockTarge.setFtrantype(order.getDocType().intValue());
+ exdInstockTarge.setFdate(DateUtils.convert(order.getOrderTime()));
+ exdInstockTarge.setFrob(orderDetl.getInspect());
+ exdInstockTarge.setFuserid(Integer.getInteger(orderDetl.getColor()));
+ exdInstockTarge.setWritetime(new Date());
+ exdInstockTarge.setWritor("WMS");
+ exdInstockTarge.setStatus(0);
+ exdInstockTargetService.insert(exdInstockTarge);
}
- 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); }
+ if (!orderService.updateSettle(order.getId(), 6L, null)) {
+ throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇紝璇疯仈绯荤鐞嗗憳");
}
- }
- // 鍑哄簱瀹屾垚涓婃姤
- if (docType.getPakout() == 1) {
- MesPakoutParam pakoutParam = new MesPakoutParam();
- pakoutParam.setPakoutTime(DateUtils.convert(order.getUpdateTime())); // todo:luxiaotao
- pakoutParam.setLgortFrom("5008"); // todo:luxiaotao
- pakoutParam.setLgortTo("5006"); // todo:luxiaotao
+ } else if (docType.getPakout() == 1) {
+ // 鍑哄簱瀹屾垚涓婃姤
+ ExdOutstockTarget exdOutstockTarget = null;
for (OrderDetl orderDetl : orderDetls) {
- String serial = Cools.isEmpty(orderDetl.getBatch()) ? "" : orderDetl.getBatch();
- pakoutParam.getList().add(new MesPakoutParam.Detl(orderDetl.getMatnr() + (Cools.isEmpty(serial) ? "" : "-" + serial), orderDetl.getAnfme()));
- }
- String response = "";
- boolean success = false;
- try {
- response = new HttpHandler.Builder()
- .setUri(MesConstant.URL)
- .setPath(MesConstant.PAKOUT_URL) // todo:luxiaotao
- .setJson(JSON.toJSONString(pakoutParam))
- .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("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇紝璇疯仈绯荤鐞嗗憳");
- }
+ exdOutstockTarget = new ExdOutstockTarget();
+ exdOutstockTarget.setFinterid(orderDetl.getDeadWarn());
+ exdOutstockTarget.setFbillno(orderDetl.getOrderNo());
+ if (order.getDocType() == 42) {
+ exdOutstockTarget.setFtrantype(41);
} else {
- log.error("璇锋眰鎺ュ彛澶辫触锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", MesConstant.URL+MesConstant.PAKOUT_URL, JSON.toJSONString(pakoutParam), response);
- throw new CoolException("涓婃姤mes绯荤粺澶辫触");
+ exdOutstockTarget.setFtrantype(order.getDocType().intValue());
}
- } catch (Exception e) {
- log.error("fail", e);
-// TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
- return FAIL.setMsg(e.getMessage());
- } finally {
- try {
- // 淇濆瓨鎺ュ彛鏃ュ織
- apiLogService.save(
- "鎴愬搧搴撳嚭搴撲笂鎶�",
- MesConstant.URL + MesConstant.PAKOUT_URL,
- null,
- "127.0.0.1",
- JSON.toJSONString(pakoutParam),
- response,
- success
- );
- } catch (Exception e) { log.error("", e); }
+ exdOutstockTarget.setFdate(DateUtils.convert(order.getOrderTime()));
+ exdOutstockTarget.setFrob(orderDetl.getInspect());
+ exdOutstockTarget.setFuserid(Integer.getInteger(orderDetl.getColor()));
+ exdOutstockTarget.setWritetime(new Date());
+ exdOutstockTarget.setWritor("WMS");
+ exdOutstockTarget.setStatus(0);
+ exdOutstockTargetService.insert(exdOutstockTarget);
+
+ }
+ if (!orderService.updateSettle(order.getId(), 6L, null)) {
+ throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇紝璇疯仈绯荤鐞嗗憳");
}
}
return SUCCESS;
}
+ @Transactional
+ public ReturnT<String> start1(Order1 order) {
+ DocType docType = docTypeService.selectById(order.getDocType());
+ if (null == docType) {
+ return FAIL;
+ }
+ List<OrderDetl1> orderDetls = orderDetl1Service.selectByOrderId(order.getId());
+ if (orderDetls.isEmpty()) {
+ return FAIL;
+ }
+
+
+ for (OrderDetl1 orderDetl : orderDetls) {
+
+ ExdvYanbu bacode = exdMaterialMapper.getBacode(orderDetl.getThreeCode());
+ //鑾峰彇涓昏〃鏄庣粏
+ OrderDetl orderDetl1 = orderDetlService.selectItem(orderDetl.getOrderNo(), orderDetl.getMatnr(), null);
+ //涓婃姤鏁伴噺
+ BigDecimal anfme = new BigDecimal(orderDetl1.getAnfme());
+ BigDecimal Units = new BigDecimal((Cools.isEmpty(orderDetl1.getUnits()) ? 0.0 : orderDetl1.getUnits()));
+ BigDecimal result = anfme.subtract(Units);
+ double count = result.doubleValue();
+
+// //鍓╀綑鏁伴噺
+// BigDecimal Anfme = new BigDecimal(orderDetl.getAnfme());
+// BigDecimal subtract = Anfme.subtract(Qty);
+
+
+ // 鍑哄簱瀹屾垚涓婃姤
+ ExdOutstockTarget exdOutstockTarget = null;
+ exdOutstockTarget = new ExdOutstockTarget();
+ //璁㈠崟鍐呯爜
+ exdOutstockTarget.setFinterid(orderDetl.getDeadWarn());
+ //鍗曞彿 = erp璁㈠崟鍙�+鐗╂枡缂栧彿+涓婃姤娆℃暟
+ exdOutstockTarget.setFbillno(order.getOrderNo());
+
+ //閮ㄩ棬ID
+ exdOutstockTarget.setFdeptid(7502);
+ //渚涘簲鍟�/瀹㈡埛ID
+ exdOutstockTarget.setFsupplyid(0);
+ //鍒跺崟鐢ㄦ埛ID
+ exdOutstockTarget.setFbillerid(Math.toIntExact(orderDetl.getUpdateBy()));
+ //缁嗚〃ID
+ Integer c = Integer.valueOf(order.getOrderNo().split("-")[1]);
+ exdOutstockTarget.setFentryid(c);
+ //鐗╂枡ID
+ Mat mat = matService.selectByMatnr(orderDetl.getMatnr());
+ exdOutstockTarget.setFitemid(Integer.valueOf(mat.getUuid()));
+ //婧愬崟鏁伴噺
+ exdOutstockTarget.setFqtymust(count);
+ //鍑哄簱鏁伴噺
+ exdOutstockTarget.setFqty(orderDetl.getQty());
+ //鍗曚环
+ exdOutstockTarget.setFprice(0.0);
+ //鎵瑰彿 鏆傚畾
+ exdOutstockTarget.setFbatchno(orderDetl.getBatch());
+ //鍗曚綅ID
+ exdOutstockTarget.setFunitid(0);
+ //婧愬崟鍙�
+ exdOutstockTarget.setFsourcebillno(orderDetl.getOrderNo());
+ //婧愬崟缁嗚〃ID 鏆傚畾
+ exdOutstockTarget.setFsourceentryid(0);
+ //婧愬崟鍐呯爜 鏆傚畾
+ exdOutstockTarget.setFsourceinterid(0);
+ //婧愬崟鍗曟嵁绫诲瀷
+ exdOutstockTarget.setFsourcetrantype(0);
+ //搴撲綅ID
+ exdOutstockTarget.setFdcspid(0);
+ //浠撳簱ID 鏆傚畾
+ exdOutstockTarget.setFdcstockid(0);
+ //閿�鍞鍗曞崟鍙� 鏆傚畾
+ exdOutstockTarget.setForderbillno(orderDetl.getOrderNo());
+ //閿�鍞鍗曠粏琛↖D 鏆傚畾
+ exdOutstockTarget.setForderentryid(0);
+ //閿�鍞鍗曞唴鐮� 鏆傚畾
+ exdOutstockTarget.setForderinterid(0);
+ //璁″垝妯″紡
+ exdOutstockTarget.setFplanmode(0);
+
+ //鍗曟嵁绫诲瀷
+ exdOutstockTarget.setFtrantype(21);
+
+ //鍗曟嵁鏃ユ湡
+ exdOutstockTarget.setFdate(DateUtils.convert(order.getOrderTime()));
+ //绾㈣摑瀛�
+ exdOutstockTarget.setFrob(orderDetl.getBeBatch());
+ //鎿嶄綔鐢ㄦ埛
+ exdOutstockTarget.setFuserid(Integer.getInteger(orderDetl.getColor()));
+
+ exdOutstockTarget.setBarcode(orderDetl.getBatch());
+ exdOutstockTarget.setGross(BigDecimal.valueOf(bacode.getGross()));
+ exdOutstockTarget.setWidth(BigDecimal.valueOf(bacode.getWidth()));
+ exdOutstockTarget.setDefects(BigDecimal.valueOf(bacode.getDefects()));
+ exdOutstockTarget.setBackcode(bacode.getBackcode());
+ exdOutstockTarget.setWritetime(new Date());
+ exdOutstockTarget.setWritor("WMS");
+ exdOutstockTarget.setStatus(0);
+//
+// //浠撳簱
+ exdOutstockTarget.setProdinkind(bacode.getProdinkind());
+
+ //鍐欏叆鏃堕棿
+ exdOutstockTarget.setWritetime(new Date());
+ //鍐欏叆鑰�
+ exdOutstockTarget.setWritor("WMS");
+ //鐘舵��
+ exdOutstockTarget.setStatus(0);
+ if (exdOutstockTargetService.insert(exdOutstockTarget)) {
+
+
+
+ }
+ }
+ for (OrderDetl1 orderDetl : orderDetls) {
+ OrderDetl orderDetl1 = orderDetlService.selectItem(orderDetl.getOrderNo(), orderDetl.getMatnr(), null);
+ orderDetl1.setUnits(orderDetl.getAnfme() + (Cools.isEmpty(orderDetl.getUnits()) ? 0.0 : orderDetl.getUnits()));
+ orderDetl1.setUpdateTime(new Date());
+ orderDetl1Service.updateById(orderDetl);
+ }
+ return SUCCESS;
+ }
}
+
+
+// @Transactional
+// public ReturnT<String> start1(Order order, OrderDetl orderDetl) {
+// DocType docType = docTypeService.selectById(order.getDocType());
+// if (null == docType) {
+// return SUCCESS;
+// }
+// List<OrderDetl> orderDetls = orderDetlService.selectByOrderId(order.getId());
+// if (orderDetls.isEmpty()) {
+// return SUCCESS;
+// }
+//
+//// ExdvYanbu bacode = exdMaterialMapper.getBacode(wrkDetl.getThreeCode());
+//
+// //涓婃姤鏁伴噺
+// BigDecimal Qty = new BigDecimal(orderDetl.getQty());
+// BigDecimal Units = new BigDecimal((Cools.isEmpty(orderDetl.getUnits()) ? 0.0 : orderDetl.getUnits()));
+// BigDecimal result = Qty.subtract(Units);
+// double count = result.doubleValue();
+//
+// //鍓╀綑鏁伴噺
+// BigDecimal Anfme = new BigDecimal(orderDetl.getAnfme());
+// BigDecimal subtract = Anfme.subtract(Qty);
+//
+//
+// // 鍑哄簱瀹屾垚涓婃姤
+// ExdOutstockTarget exdOutstockTarget = null;
+// exdOutstockTarget = new ExdOutstockTarget();
+// //璁㈠崟鍐呯爜
+// exdOutstockTarget.setFinterid(orderDetl.getDeadWarn());
+// //鍗曞彿 = erp璁㈠崟鍙�+鐗╂枡缂栧彿+涓婃姤娆℃暟
+// exdOutstockTarget.setFbillno(orderDetl.getOrderNo() + "--" + orderDetl.getMatnr() + "--" + (Cools.isEmpty(orderDetl.getInspect()) ? 1 : (orderDetl.getInspect() + 1)));
+//
+// //閮ㄩ棬ID
+// exdOutstockTarget.setFdeptid(7502);
+// //渚涘簲鍟�/瀹㈡埛ID
+// exdOutstockTarget.setFsupplyid(0);
+// //鍒跺崟鐢ㄦ埛ID
+// exdOutstockTarget.setFbillerid(Math.toIntExact(orderDetl.getUpdateBy()));
+// //缁嗚〃ID
+// exdOutstockTarget.setFentryid((Cools.isEmpty(orderDetl.getInspect()) ? 1 : (orderDetl.getInspect() + 1)));
+// //鐗╂枡ID
+// Mat mat = matService.selectByMatnr(orderDetl.getMatnr());
+// exdOutstockTarget.setFitemid(Integer.valueOf(mat.getUuid()));
+// //婧愬崟鏁伴噺
+// exdOutstockTarget.setFqtymust(subtract.doubleValue());
+// //鍑哄簱鏁伴噺
+// exdOutstockTarget.setFqty(count);
+// //鍗曚环
+// exdOutstockTarget.setFprice(0.0);
+// //鎵瑰彿 鏆傚畾
+// exdOutstockTarget.setFbatchno(orderDetl.getBatch());
+// //鍗曚綅ID
+// exdOutstockTarget.setFunitid(0);
+// //婧愬崟鍙�
+// exdOutstockTarget.setFsourcebillno(orderDetl.getOrderNo());
+// //婧愬崟缁嗚〃ID 鏆傚畾
+// exdOutstockTarget.setFsourceentryid(0);
+// //婧愬崟鍐呯爜 鏆傚畾
+// exdOutstockTarget.setFsourceinterid(0);
+// //婧愬崟鍗曟嵁绫诲瀷
+// exdOutstockTarget.setFsourcetrantype(0);
+// //搴撲綅ID
+// exdOutstockTarget.setFdcspid(0);
+// //浠撳簱ID 鏆傚畾
+// exdOutstockTarget.setFdcstockid(0);
+// //閿�鍞鍗曞崟鍙� 鏆傚畾
+// exdOutstockTarget.setForderbillno(orderDetl.getOrderNo());
+// //閿�鍞鍗曠粏琛↖D 鏆傚畾
+// exdOutstockTarget.setForderentryid(0);
+// //閿�鍞鍗曞唴鐮� 鏆傚畾
+// exdOutstockTarget.setForderinterid(0);
+// //璁″垝妯″紡
+// exdOutstockTarget.setFplanmode(0);
+//
+// //鍗曟嵁绫诲瀷
+// exdOutstockTarget.setFtrantype(21);
+//
+// //鍗曟嵁鏃ユ湡
+// exdOutstockTarget.setFdate(DateUtils.convert(order.getOrderTime()));
+// //绾㈣摑瀛�
+// exdOutstockTarget.setFrob(orderDetl.getBeBatch());
+// //鎿嶄綔鐢ㄦ埛
+// exdOutstockTarget.setFuserid(Integer.getInteger(orderDetl.getColor()));
+//
+//// exdOutstockTarget.setBarcode(wrkDetl.getBatch());
+//// exdOutstockTarget.setGross(bacode.getGross());
+//// exdOutstockTarget.setWidth(bacode.getWidth());
+//// exdOutstockTarget.setDefects(bacode.getDefects());
+//// exdOutstockTarget.setBackcode(bacode.getBackcode());
+//// exdOutstockTarget.setWritetime(new Date());
+//// exdOutstockTarget.setWritor("WMS");
+//// exdOutstockTarget.setStatus(0);
+////
+//// //浠撳簱
+//// exdOutstockTarget.setProdinkind(bacode.getProdinkind());
+//
+// //鍐欏叆鏃堕棿
+// exdOutstockTarget.setWritetime(new Date());
+// //鍐欏叆鑰�
+// exdOutstockTarget.setWritor("WMS");
+// //鐘舵��
+// exdOutstockTarget.setStatus(0);
+// if (exdOutstockTargetService.insert(exdOutstockTarget)) {
+// orderDetl.setInspect((Cools.isEmpty(orderDetl.getInspect()) ? 1 : (orderDetl.getInspect() + 1)));
+// orderDetl.setUnits(count + (Cools.isEmpty(orderDetl.getUnits()) ? 0.0 : orderDetl.getUnits()));
+// orderDetlService.updateById(orderDetl);
+// }
+//
+// return SUCCESS;
+// }
+
+
+
--
Gitblit v1.9.1