From 608e6b5a45d2e53879b10aca3475dd8df92e5e5f Mon Sep 17 00:00:00 2001
From: skyouc <creaycat@gmail.com>
Date: 星期一, 22 十二月 2025 20:18:02 +0800
Subject: [PATCH] bug修复
---
src/main/java/com/zy/asrs/task/handler/OrderSyncHandler.java | 416 ++++++++++++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 368 insertions(+), 48 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 9008f74..35cd074 100644
--- a/src/main/java/com/zy/asrs/task/handler/OrderSyncHandler.java
+++ b/src/main/java/com/zy/asrs/task/handler/OrderSyncHandler.java
@@ -2,26 +2,36 @@
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.Order;
-import com.zy.asrs.entity.OrderDetl;
-import com.zy.asrs.service.ApiLogService;
-import com.zy.asrs.service.OrderDetlService;
-import com.zy.asrs.service.OrderService;
+import com.zy.api.entity.ReportOrderParam;
+import com.zy.api.entity.ReportOrderParams;
+import com.zy.api.entity.dto.XSR;
+import com.zy.api.service.KopenApiService;
+import com.zy.asrs.entity.*;
+import com.zy.asrs.enums.OrderTypeEnum;
+import com.zy.asrs.service.*;
import com.zy.asrs.task.AbstractHandler;
import com.zy.asrs.task.core.ReturnT;
+import com.zy.asrs.utils.OrderInAndOutUtil;
+import com.zy.asrs.utils.Utils;
import com.zy.common.constant.MesConstant;
+import com.zy.common.model.DetlDto;
import com.zy.common.model.MesPakinParam;
+import com.zy.common.model.MesPakoutParam;
import com.zy.common.utils.HttpHandler;
import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.BeanUtils;
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 org.springframework.transaction.interceptor.TransactionAspectSupport;
+import java.util.ArrayList;
+import java.util.Date;
import java.util.List;
+import java.util.Objects;
/**
* Created by vincent on 2020/7/7
@@ -38,55 +48,365 @@
private OrderDetlService orderDetlService;
@Autowired
private ApiLogService apiLogService;
+ @Autowired
+ private DocTypeService docTypeService;
+ @Autowired
+ private OrderPakinService orderPakinService;
+ @Autowired
+ private OrderDetlPakinService orderDetlPakinService;
+ @Autowired
+ private KopenApiService kopenApiService;
+ @Autowired
+ private MatService matService;
@Transactional
- public ReturnT<String> start(Order order) {
+ public ReturnT<String> startOrderIssuedOnceMore(Order order) {
+ DocType docType = docTypeService.selectById(order.getDocType());
+ if (null == docType) {
+ return SUCCESS;
+ }
+
+ Order order1 = OrderInAndOutUtil.selectByNo(order.getPakinPakoutStatus$(), order.getOrderNo());
+ if (!Cools.isEmpty(order1)) {
+ return FAIL.setMsg("璇风瓑寰�...璁㈠崟鎵ц妗f姝e湪杞巻鍙叉。妗堬紒锛侊紒");
+ }
+ List<OrderDetl> orderDetls = OrderInAndOutUtil.selectByOrderId(order.getPakinPakoutStatus$(), order.getId());
+ if (!Cools.isEmpty(orderDetls) || !orderDetls.isEmpty()) {
+ return FAIL.setMsg("璇风瓑寰�...璁㈠崟鎵ц鏄庣粏妗f姝e湪杞巻鍙叉。妗堬紒锛侊紒");
+ }
+
+ // 鍗曟嵁鏄庣粏妗�
+ List<OrderDetl> orderDetlList = orderDetlService.selectByOrderId(order.getId());
+ for (OrderDetl orderDetl : orderDetlList) {
+ if (orderDetl.getQty().equals(0D)) {
+ continue;
+ }
+ orderDetl.setWorkQty(orderDetl.getQty());
+ orderDetl.setAnfme(orderDetl.getAnfme() - orderDetl.getQty());
+ orderDetl.setQty(0D);
+ orderDetlService.updateById(orderDetl);
+ }
+
+ // 淇敼璁㈠崟鐘舵�� 99.鍐嶆浣滀笟 ===>> 1.寰呬綔涓�
+ if (!orderService.updateSettle(order.getId(), 1L, null)) {
+ throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇紝璇疯仈绯荤鐞嗗憳");
+ }
+ return SUCCESS;
+ }
+
+ @Transactional(rollbackFor = Exception.class)
+ public ReturnT<String> startOrderIssued(Order order) {
+ DocType docType = docTypeService.selectById(order.getDocType());
+ if (null == docType) {
+ return SUCCESS;
+ }
List<OrderDetl> orderDetls = orderDetlService.selectByOrderId(order.getId());
- MesPakinParam pakinParam = new MesPakinParam();
- pakinParam.setPakinTime(DateUtils.convert(order.getUpdateTime()));
- pakinParam.setLgortFrom("5008");
- pakinParam.setLgortTo("5006");
- for (OrderDetl orderDetl : orderDetls) {
- pakinParam.getList().add(new MesPakinParam.Detl(orderDetl.getMatnr() + "-" + orderDetl.getBatch(), 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("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇紝璇疯仈绯荤鐞嗗憳");
- }
+ OrderInAndOutUtil.insertOrder(order.getPakinPakoutStatus$(), order);
+ // 鍗曟嵁鏄庣粏妗�
+ List<DetlDto> list = new ArrayList<>();
+ List<OrderDetl> orderDetlList = new ArrayList<>();
+
+ for (OrderDetl detail : orderDetls) {
+ DetlDto dto = new DetlDto(detail.getMatnr(), detail.getBatch(), detail.getBrand(), detail.getStandby1(),
+ detail.getStandby2(), detail.getStandby3(),
+ detail.getBoxType1(), detail.getBoxType2(), detail.getBoxType3(), detail.getAnfme(),
+ detail.getThreeCode());
+ if (DetlDto.has(list, dto)) {
+ DetlDto detlDto = DetlDto.find(list, dto.getMatnr(), dto.getBatch(), dto.getBrand(), dto.getStandby1(),
+ dto.getStandby2(), dto.getStandby3(), dto.getBoxType1(), dto.getBoxType2(), dto.getBoxType3());
+ assert detlDto != null;
+ detlDto.setAnfme(detlDto.getAnfme() + detail.getAnfme());
+
+ OrderDetl orderDetl = OrderDetl.find(orderDetlList, dto.getMatnr(), dto.getBatch(), dto.getBrand(),
+ dto.getStandby1(), dto.getStandby2(), dto.getStandby3(), dto.getBoxType1(), dto.getBoxType2(),
+ dto.getBoxType3());
+ assert orderDetl != null;
+ orderDetl.setAnfme(orderDetl.getAnfme() + detail.getAnfme());
} else {
- log.error("璇锋眰鎺ュ彛澶辫触锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", MesConstant.URL+MesConstant.PAKIN_URL, JSON.toJSONString(pakinParam), response);
- throw new CoolException("涓婃姤mes绯荤粺澶辫触");
+ list.add(dto);
+ orderDetlList.add(detail);
}
- } catch (Exception e) {
- log.error("fail", e);
- TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
- return FAIL.setMsg(e.getMessage());
- } finally {
+ }
+ for (OrderDetl orderDetl : orderDetlList) {
+ orderDetl.setWorkQty(0D);
+ OrderInAndOutUtil.insertOrderDetl(order.getPakinPakoutStatus$(), order, orderDetl);
+ // 灏忔澗锛氬鏋滀笅鍙戝璐ф淳宸ュ崟锛屽垯鐢熸垚澶囪揣鍑哄簱+澶囪揣鍏ュ簱
+ if (order.getDocType().equals(OrderTypeEnum.TRANSFER.type.longValue())) {
+ try {
+ ifTransfetInsertStockIn(order, orderDetl);
+ } catch (Exception e) {
+ throw new CoolException(e.getMessage());
+ }
+ }
+ }
+ // 淇敼璁㈠崟鐘舵�� 1.鏈綔涓� ===>> 2.浣滀笟涓�
+ if (!orderService.updateSettle(order.getId(), 2L, null)) {
+ throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇紝璇疯仈绯荤鐞嗗憳");
+ }
+ return SUCCESS;
+ }
+
+ @Transactional(rollbackFor = Exception.class)
+ public void ifTransfetInsertStockIn(Order order, OrderDetl orderDetl) {
+ OrderPakin orderPakin = new OrderPakin();
+ BeanUtils.copyProperties(order, orderPakin);
+ orderPakin.setDocType(OrderTypeEnum.STOCK_IN.type.longValue());
+
+ if (!orderPakinService.insert(orderPakin)) {
+ throw new CoolException("鎻掑叆澶囪揣鍏ュ簱鍗曞け璐�");
+ }
+ OrderDetlPakin orderDetlPakin = new OrderDetlPakin();
+ BeanUtils.copyProperties(orderDetl, orderDetlPakin);
+ orderDetlPakin.setOrderId(orderPakin.getId());
+
+ if (!orderDetlPakinService.insert(orderDetlPakin)) {
+ throw new CoolException("鎻掑叆澶囪揣鍏ュ簱鍗曞け璐�");
+ }
+
+ }
+
+ @Transactional
+ public ReturnT<String> startOrderInAndOutUtil(Order order) {
+ // 灏忔澗锛氳疆璁埌澶囪揣娲惧伐鍗曟槸鏌ヨ澶囪揣鍏ュ簱鍗曟槸鍚﹀畬鎴�
+ if (order.getDocType().equals(OrderTypeEnum.STOCK_IN.type.longValue())) {
+ return SUCCESS;
+ }
+ if (order.getDocType().equals(OrderTypeEnum.TRANSFER.type.longValue())) {
+ OrderPakin orderPakin = orderPakinService.selectByNo(order.getOrderNo());
+ if (null != orderPakin) {
+ if (!orderPakin.getSettle().equals(4L)) {
+ return SUCCESS;
+ }
+ }
+ }
+ DocType docType = docTypeService.selectById(order.getDocType());
+ if (null == docType) {
+ return SUCCESS;
+ }
+ Order orderSou = orderService.selectByNo(order.getOrderNo());
+ if (!orderSou.getSettle().equals(2L)) {
+ return FAIL.setMsg("璁㈠崟鐘舵�佷笉姝g‘锛岃鑱旂郴绠$悊鍛�");
+ }
+ List<OrderDetl> orderDetlList = orderDetlService.selectByOrderId(orderSou.getId());
+
+ List<OrderDetl> orderDetls = OrderInAndOutUtil.selectByOrderId(order.getPakinPakoutStatus$(), order.getId());
+
+ for (OrderDetl orderDetlSou : orderDetlList) {
+ for (OrderDetl orderDetl : orderDetls) {
+ if (orderDetl.getQty().equals(0D)) {
+ continue;
+ }
+ if (orderDetlSou.beSimilar(orderDetl)) {
+ double v = orderDetlSou.getAnfme() - orderDetlSou.getQty();
+ if (v < orderDetl.getQty() || orderDetl.getQty().equals(v)) {
+ orderDetlSou.setQty(orderDetlSou.getAnfme());
+ orderDetl.setQty(orderDetl.getQty() - v);
+ break;
+ } else {
+ orderDetlSou.setQty(orderDetlSou.getQty() + orderDetl.getQty());
+ orderDetl.setQty(0D);
+ }
+ }
+ }
+ }
+ for (OrderDetl orderDetlSou : orderDetlList) {
+ orderDetlService.updateById(orderDetlSou);
+ }
+ // 淇敼璁㈠崟鐘舵�� 2.浣滀笟涓� ===>> 4.寰呬笂鎶�
+ if (!orderService.updateSettle(orderSou.getId(), 4L, null)) {
+ throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇紝璇疯仈绯荤鐞嗗憳");
+ }
+ // 淇敼璁㈠崟鐘舵�� 4.瀹屾垚 ===>> 6.缁撴潫
+ OrderInAndOutUtil.updateOrder(order.getPakinPakoutStatus$(), order.getId(), 6L, null);
+ return SUCCESS;
+ }
+
+ /**
+ * 鍗曟嵁涓婃姤
+ *
+ * @param order
+ * @return com.zy.asrs.task.core.ReturnT<java.lang.String>
+ * @author Ryan
+ * @date 2025/12/15 16:14
+ */
+ @Transactional
+ public ReturnT<String> startOrderReport(Order order) {
+ DocType docType = docTypeService.selectById(order.getDocType());
+ if (null == docType) {
+ return SUCCESS;
+ }
+ long settle = 6L;
+ List<OrderDetl> orderDetls = orderDetlService.selectByOrderId(order.getId());
+ if (Integer.valueOf(docType.getDocId() + "").equals(OrderTypeEnum.PICKING.type)) {
+ // 涓婃灦娲惧伐鍗曞畬鎴�
+ ReportOrderParam orderParam = new ReportOrderParam();
+ orderParam.setCompany_id(order.getCstmrName())
+ .setWms_id(order.getId() + "")
+ .setOrder_no(order.getOrderNo())
+ .setType(order.getDocType() + "")
+ .setInv_no(order.getNumber())
+ .setPm_tktid(order.getItemName())
+ .setUpdate_time(Utils.dateToStr(new Date(), "yyyy-MM-dd HH:mm:ss"))
+ .setTarget_location("");
+
+ List<ReportOrderParams> reportOrderParams = new ArrayList<>();
+ orderDetls.forEach(detl -> {
+ Mat material = matService.selectByMatnr(detl.getMatnr());
+ if (Objects.isNull(material)) {
+ throw new CoolException("鐗╂枡涓嶅瓨鍦�");
+ }
+ ReportOrderParams itemParam = new ReportOrderParams();
+ // BS Code
+ itemParam.setTotal_serial(detl.getThreeCode())
+ // 涓婃姤鏃讹紝榛樿浜у搧绫诲瀷鏄痭ull
+ .setPro_type(material.getProType())
+ // 涓婃姤鏃讹紝榛樿浜у搧缂栫爜
+ .setPro_komcode(detl.getMatnr())
+ // 涓婃姤鏃讹紝榛樿浜у搧id鏄緵搴斿晢缂栫爜
+ .setPro_id(detl.getSuppCode())
+ // 涓婃姤鏃讹紝榛樿鏉ユ簮浣嶇疆鏄痭ull
+ .setLocation_no(null)
+ // 涓婃姤鏃讹紝榛樿鐩爣浣嶇疆鏄痭ull
+ .setLocation_type(null)
+ // 涓婃姤鏃讹紝榛樿涓婃姤鏃堕棿鏄洿鏂版椂闂�
+ .setSj_date(order.getUpdateBy().toString())
+ // 涓婃姤鏃讹紝榛樿涓婃姤浜烘槸鏇存柊浜�
+ .setSj_emp(order.getUpdateBy$())
+ // 涓婃姤鏃讹紝榛樿涓婃姤鏁伴噺鏄鍗曟暟閲�
+ .setPick_qty(detl.getQty().intValue())
+ // 涓婃姤鏃讹紝榛樿鎹熷潖鏁伴噺鏄�0
+ .setDamage_qty(0)
+ // 涓婃姤鏃讹紝榛樿宸紓鏁伴噺鏄�0
+ .setDiff_qty(0);
+
+ reportOrderParams.add(itemParam);
+ });
+
+ orderParam.setDetails(reportOrderParams);
+
+ XSR response = null;
+ boolean success = false;
try {
- // 淇濆瓨鎺ュ彛鏃ュ織
- apiLogService.save(
- "鎴愬搧搴撳叆搴撲笂鎶�",
- MesConstant.URL + MesConstant.PAKIN_URL,
- null,
- "127.0.0.1",
- JSON.toJSONString(pakinParam),
- response,
- success
- );
- } catch (Exception e) { log.error("", e); }
+ response = kopenApiService.getInDispatchResult(orderParam);
+
+ // if (true) {
+ // success = true;
+ // // 淇敼璁㈠崟鐘舵�� 4.瀹屾垚 ===>> 6.宸蹭笂鎶�
+ // if (!orderService.updateSettle(order.getId(), settle, 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(orderParam),
+ JSON.toJSONString(response),
+ success);
+ } catch (Exception e) {
+ log.error("", e);
+ }
+ }
+ } else if (Integer.valueOf(docType.getDocId() + "").equals(OrderTypeEnum.TRANSFER.type)) {
+ // 澶囪揣娲惧伐鍗曪紙鍑哄簱锛�
+ ReportOrderParam orderParam = new ReportOrderParam();
+ orderParam.setCompany_id(order.getCstmrName())
+ .setWms_id(order.getId() + "")
+ .setOrder_no(order.getOrderNo())
+ .setType(order.getDocType() + "")
+ .setInv_no(order.getNumber())
+ .setPm_tktid(order.getItemName())
+ .setUpdate_time(Utils.dateToStr(new Date(), "yyyy-MM-dd HH:mm:ss"))
+ .setTarget_location("");
+
+ List<ReportOrderParams> reportOrderParams = new ArrayList<>();
+ orderDetls.forEach(detl -> {
+ Mat material = matService.selectByMatnr(detl.getMatnr());
+ if (Objects.isNull(material)) {
+ throw new CoolException("鐗╂枡涓嶅瓨鍦�");
+ }
+ ReportOrderParams itemParam = new ReportOrderParams();
+ // BS Code
+ itemParam.setTotal_serial(detl.getThreeCode())
+ // 涓婃姤鏃讹紝榛樿浜у搧绫诲瀷鏄痭ull
+ .setPro_type(material.getProType())
+ // 涓婃姤鏃讹紝榛樿浜у搧缂栫爜
+ .setPro_komcode(detl.getMatnr())
+ // 涓婃姤鏃讹紝榛樿浜у搧id鏄緵搴斿晢缂栫爜
+ .setPro_id(detl.getSuppCode())
+ // 涓婃姤鏃讹紝榛樿鏉ユ簮浣嶇疆鏄痭ull
+ .setLocation_no(null)
+ // 涓婃姤鏃讹紝榛樿鐩爣浣嶇疆鏄痭ull
+ .setLocation_type(null)
+ // 涓婃姤鏃讹紝榛樿涓婃姤鏃堕棿鏄洿鏂版椂闂�
+ .setSj_date(order.getUpdateBy().toString())
+ // 涓婃姤鏃讹紝榛樿涓婃姤浜烘槸鏇存柊浜�
+ .setSj_emp(order.getUpdateBy$())
+ // 涓婃姤鏃讹紝榛樿涓婃姤鏁伴噺鏄鍗曟暟閲�
+ .setPick_qty(detl.getQty().intValue())
+ // 涓婃姤鏃讹紝榛樿鎹熷潖鏁伴噺鏄�0
+ .setDamage_qty(0)
+ // 涓婃姤鏃讹紝榛樿宸紓鏁伴噺鏄�0
+ .setDiff_qty(0);
+
+ reportOrderParams.add(itemParam);
+ });
+
+ orderParam.setDetails(reportOrderParams);
+
+ XSR response = null;
+ boolean success = false;
+ try {
+ // response = new HttpHandler.Builder()
+ // .setUri(MesConstant.URL)
+ // .setPath(MesConstant.PAKOUT_URL)
+ // .setJson(JSON.toJSONString(pakoutParam))
+ // .build()
+ // .doPost();
+ // JSONObject jsonObject = JSON.parseObject(response);
+ // if (jsonObject.getInteger("code").equals(200)) {
+ if (true) {
+ success = true;
+ // 淇敼璁㈠崟鐘舵�� 4.瀹屾垚 ===>> 6.宸蹭笂鎶�
+ if (!orderService.updateSettle(order.getId(), settle, null)) {
+ throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇紝璇疯仈绯荤鐞嗗憳");
+ }
+ } else {
+ log.error("璇锋眰鎺ュ彛澶辫触锛侊紒锛乽rl锛歿}锛況equest锛歿}锛況esponse锛歿}", MesConstant.URL + MesConstant.PAKOUT_URL,
+ JSON.toJSONString(orderParam), JSON.toJSONString(response));
+ throw new CoolException("涓婃姤mes绯荤粺澶辫触");
+ }
+ } catch (Exception e) {
+ log.error("fail", e);
+ return FAIL.setMsg(e.getMessage());
+ } finally {
+ try {
+ // 淇濆瓨鎺ュ彛鏃ュ織
+ apiLogService.save(
+ "澶囪揣娲惧伐鍗曞畬鎴愪笂鎶�",
+ MesConstant.URL + MesConstant.PAKOUT_URL,
+ null,
+ "127.0.0.1",
+ JSON.toJSONString(orderParam),
+ JSON.toJSONString(response),
+ success);
+ } catch (Exception e) {
+ log.error("", e);
+ }
+ }
}
return SUCCESS;
}
--
Gitblit v1.9.1