From 9b1437c9bcec2130ee67e43575fcde517f71f9ce Mon Sep 17 00:00:00 2001
From: lty <876263681@qq.com>
Date: 星期四, 26 三月 2026 10:23:46 +0800
Subject: [PATCH] #
---
src/main/java/com/zy/asrs/task/OrderSyncScheduler.java | 133 +++++++++++++++++++++++++++++++++++---------
1 files changed, 106 insertions(+), 27 deletions(-)
diff --git a/src/main/java/com/zy/asrs/task/OrderSyncScheduler.java b/src/main/java/com/zy/asrs/task/OrderSyncScheduler.java
index 05d7cba..0b1ca17 100644
--- a/src/main/java/com/zy/asrs/task/OrderSyncScheduler.java
+++ b/src/main/java/com/zy/asrs/task/OrderSyncScheduler.java
@@ -1,14 +1,29 @@
package com.zy.asrs.task;
-import com.baomidou.mybatisplus.mapper.EntityWrapper;
+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.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
@@ -19,35 +34,99 @@
@Autowired
private OrderService orderService;
+ @Autowired
+ private OrderDetlService orderDetlService;
+ @Autowired
+ private DocTypeService docTypeService;
+ @Autowired
+ private ApiLogService apiLogService;
- @Scheduled(cron = "0/3 * * * * ? ")
- private void queryAndSave(){
-// for (WrkMast wrkMast : wrkMasts) {
-// ReturnT<String> result = workLogHandler.start(wrkMast);
-// if (!result.isSuccess()) {
-// log.error("宸ヤ綔妗workNo={}]鍘嗗彶妗e鐞嗗け璐�", wrkMast.getWrkNo());
-// }
-// }
+ @Scheduled(cron = "0 0 1 * * ? ")
+ public void clearApiLog(){
+ try {
+ apiLogService.clearWeekBefore();
+ } catch (Exception e) {
+ log.error("绗笁鏂规帴鍙f棩蹇楄嚜鍔ㄦ竻闄ゅけ璐ワ紙鑼冨洿锛氫竴鍛ㄤ箣鍓�", e);
+ }
}
- @Scheduled(cron = "0/3 * * * * ? ")
- private void completeAndReport(){
- // 鎵�鏈夎鍗�
- List<Order> orders = orderService.selectList(new EntityWrapper<Order>().eq("settle", 4L));
- for (Order order : orders) {
-// OpenOrderCompeteResult result = new OpenOrderCompeteResult();
-// results.add(result);
-// result.setOrderNo(order.getOrderNo());
-// result.setOrderTime(order.getOrderTime());
-// result.setOrderType(order.getDocType$());
-// List<OrderDetl> orderDetls = orderDetlService.selectByOrderId(order.getId());
-// for (OrderDetl orderDetl : orderDetls) {
-// result.getOrderDetails().add(new DetlDto(orderDetl.getOrderNo(), orderDetl.getMatnr(), orderDetl.getBatch(), orderDetl.getQty()));
-// }
-// // 淇敼璁㈠崟鐘舵�� 4.瀹屾垚 ===>> 6.宸蹭笂鎶�
-// if (!orderService.updateSettle(order.getId(), 6L, null)) {
-// throw new CoolException("鏈嶅姟鍣ㄥ唴閮ㄩ敊璇紝璇疯仈绯荤鐞嗗憳");
-// }
+// @Scheduled(cron = "0/5 * * * * ? ")
+ @Async("orderThreadPool")
+ 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 = reportToMesOrderReport(order);
+ if (!result.isSuccess()) {
+ log.error("鍗曟嵁[orderNo={}]涓婃姤澶辫触锛歿}", order.getOrderNo(), result.getMsg());
+ }
+ }
+ }
+ }
+
+ 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:8889";
+ String path = "/lfdwms/open/asrs/MES/orderReport";
+ String url = "http://" + uri + path;
+
+ Map<String, Object> payload = new HashMap<>();
+ payload.put("orderNo", order.getOrderNo());
+ payload.put("warehouseId", null);
+ 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