From 322e78c971769c8417810ac0dc4cdad065d40d3f Mon Sep 17 00:00:00 2001
From: dubin <bindu_bean@163.com>
Date: 星期三, 06 五月 2026 16:21:30 +0800
Subject: [PATCH] 入出库结果上报
---
src/main/java/com/zy/asrs/task/OrderSyncScheduler.java | 88 ++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 84 insertions(+), 4 deletions(-)
diff --git a/src/main/java/com/zy/asrs/task/OrderSyncScheduler.java b/src/main/java/com/zy/asrs/task/OrderSyncScheduler.java
index 1619b74..21fd303 100644
--- a/src/main/java/com/zy/asrs/task/OrderSyncScheduler.java
+++ b/src/main/java/com/zy/asrs/task/OrderSyncScheduler.java
@@ -1,19 +1,30 @@
package com.zy.asrs.task;
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONObject;
import com.core.common.Cools;
+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.task.core.ReturnT;
import com.zy.asrs.task.handler.OrderSyncHandler;
import com.zy.common.entity.Parameter;
+import com.zy.common.utils.HttpHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
+import java.io.IOException;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
/**
* Created by vincent on 2020/7/7
@@ -28,9 +39,13 @@
private OrderService orderService;
@Autowired
private ApiLogService apiLogService;
+ @Autowired
+ private OrderDetlService orderDetlService;
+ @Autowired
+ private DocTypeService docTypeService;
@Scheduled(cron = "0 0 1 * * ? ")
- public void clearApiLog(){
+ public void clearApiLog() {
try {
apiLogService.clearWeekBefore();
} catch (Exception e) {
@@ -38,14 +53,14 @@
}
}
- @Scheduled(cron = "0/5 * * * * ? ")
+// @Scheduled(cron = "0/5 * * * * ? ")
@Async("orderThreadPool")
- public void completeAndReport(){
+ public void completeAndReport() {
String erpReport = Parameter.get().getErpReport();
if (!Cools.isEmpty(erpReport) && erpReport.equals("true")) {
List<Order> orders = orderService.selectComplete();
for (Order order : orders) {
- ReturnT<String> result = orderSyncHandler.start(order);
+ ReturnT<String> result = reportToMesOrderReport(order);
if (!result.isSuccess()) {
log.error("鍗曟嵁[orderNo={}]涓婃姤erp澶辫触", order.getOrderNo());
}
@@ -53,4 +68,69 @@
}
}
+ private ReturnT<String> reportToMesOrderReport(Order order) {
+ if (order == null) {
+ return new ReturnT<>(ReturnT.SUCCESS_CODE, "SUCCESS");
+ }
+
+ DocType docType = docTypeService.selectById(order.getDocType());
+ if (docType == null) {
+ return new ReturnT<>(ReturnT.SUCCESS_CODE, "SUCCESS");
+ }
+
+ String wkType = docType.getDocName();
+ List<OrderDetl> orderDetls = orderDetlService.selectByOrderId(order.getId());
+
+ String uri = "localhost:9090";
+ String path = "/erp/open/asrs/MES/orderReport";
+ String url = "http://" + uri + path;
+
+ Map<String, Object> payload = new HashMap<>();
+ payload.put("orderNo", order.getOrderNo());
+// payload.put("warehouseId", "WH01");
+ payload.put("wkType", wkType);
+ payload.put("orderDetls", orderDetls);
+ String requestJson = JSON.toJSONString(payload);
+
+ String response = "";
+ boolean success = false;
+ try {
+ response = new HttpHandler.Builder()
+ .setUri(uri)
+ .setPath(path)
+ .setJson(requestJson)
+ .build()
+ .doPost();
+ JSONObject json = JSON.parseObject(response);
+ Integer code = json == null ? null : json.getInteger("code");
+ success = code != null && code == 200;
+ if (!success) {
+ String msg = json == null ? null : json.getString("msg");
+ throw new CoolException(!Cools.isEmpty(msg) ? msg : "鎺ュ彛杩斿洖澶辫触锛�" + response);
+ }
+ if (!orderService.updateSettle(order.getId(), 6L, null)) {
+ throw new CoolException("鏇存柊鍗曟嵁鐘舵�佸け璐�");
+ }
+ return new ReturnT<>(ReturnT.SUCCESS_CODE, "SUCCESS");
+ } catch (IOException e) {
+ return new ReturnT<>(ReturnT.FAIL_CODE, e.getMessage());
+ } catch (Exception e) {
+ return new ReturnT<>(ReturnT.FAIL_CODE, e.getMessage());
+ } finally {
+ try {
+ apiLogService.save(
+ "MES璁㈠崟涓婃姤",
+ url,
+ null,
+ "127.0.0.1",
+ requestJson,
+ response,
+ success
+ );
+ } catch (Exception e) {
+ log.error("", e);
+ }
+ }
+ }
+
}
--
Gitblit v1.9.1