From dbe87fddc43db7e5486489c3a011cc6474c4701c Mon Sep 17 00:00:00 2001
From: 1 <1>
Date: 星期四, 09 十月 2025 16:46:42 +0800
Subject: [PATCH] #和得服务器
---
src/main/java/com/zy/asrs/task/OrderToSortLineScheduler.java | 172 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 171 insertions(+), 1 deletions(-)
diff --git a/src/main/java/com/zy/asrs/task/OrderToSortLineScheduler.java b/src/main/java/com/zy/asrs/task/OrderToSortLineScheduler.java
index f47d516..add09c1 100644
--- a/src/main/java/com/zy/asrs/task/OrderToSortLineScheduler.java
+++ b/src/main/java/com/zy/asrs/task/OrderToSortLineScheduler.java
@@ -1,17 +1,187 @@
package com.zy.asrs.task;
+import com.alibaba.fastjson.JSON;
+import com.zy.asrs.entity.BasArmMastSign;
+import com.zy.asrs.entity.BasArmRules;
+import com.zy.asrs.entity.OrderDetl;
+import com.zy.asrs.entity.param.OrderToLine;
+import com.zy.asrs.service.BasArmMastSignService;
+import com.zy.asrs.service.BasArmRulesService;
+import com.zy.asrs.service.OrderDetlService;
+import com.zy.asrs.service.OrderService;
+import com.zy.asrs.service.impl.OrderDetlServiceImpl;
+import com.zy.asrs.task.core.ReturnT;
+import com.zy.asrs.task.handler.OrderToLineHandler;
import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
+
+import java.util.ArrayList;
+import java.util.List;
@Slf4j
@Component
//璁㈠崟涓嬪彂鑷冲垎鎷g嚎
public class OrderToSortLineScheduler {
+ @Autowired
+ private OrderService orderService;
+ @Autowired
+ private OrderDetlService orderDetlService;
+ @Autowired
+ private BasArmRulesService basArmRulesService;
+ @Autowired
+ private OrderToLineHandler orderToLineHandler;
+ @Autowired
+ private BasArmMastSignService basArmMastSignService;
-// @Scheduled(cron = "0/3 * * * * ? ")
+
+ @Scheduled(cron = "0/3 * * * * ? ")
private void orderToSortLine() {
+ //鑾峰彇鏈笅鍙戝崟鎹�
+ List<String> orderNos = orderService.AllStatusSatisfyOrder(0);
+ if(orderNos == null || orderNos.isEmpty()) {
+// log.info("鏈湁鏂拌鍗�");
+ return;
+ }
+ //閬嶅巻鍗曟嵁
+ for (String orderNo : orderNos) {
+ List<OrderDetl> orderDetls = orderDetlService.selectByOrderNo(orderNo);
+ OrderToLine orderToLine = new OrderToLine();
+ orderToLine.setOrderNo(orderNo); //鍗曟嵁缂栧彿
+ orderToLine.setCreateTime(System.currentTimeMillis()); //鍒涘缓鏃堕棿
+
+ Long bindingTag = System.currentTimeMillis();//娣锋惌鏍囪
+
+ List<OrderToLine.MatList> matLists = new ArrayList<>();
+ List<OrderToLine.MatList> matListsRemainder = new ArrayList<>();
+ List<OrderDetl> orderDetlsRemainder = new ArrayList<>();
+
+ for (OrderDetl orderDetl : orderDetls) {
+ Integer number = basArmRulesService.getNumber(orderDetl.getWeight(),orderDetl.getVolume(),orderDetl.getManLength(),orderDetl.getWidth(),orderDetl.getHeight());
+ if (number == null) {
+ BasArmRules basArmRules = new BasArmRules();
+ basArmRules.setMaterialHeight(orderDetl.getHeight());
+ basArmRules.setMaterialWeight(orderDetl.getWeight());
+ basArmRules.setMaterialLength(orderDetl.getManLength());
+ basArmRules.setMaterialWidth(orderDetl.getWidth());
+ basArmRulesService.insert(basArmRules);
+ return;
+ } else if (number == 0){
+ return;
+ }
+ Double anfme = orderDetl.getAnfme();
+ Double remainder = anfme % number; //鍙栦綑 浣欐暟娣锋惌
+// remainder = 0D;
+ if(!remainder.equals(0D)){
+ // 缁勮鐗╂枡淇℃伅
+ OrderToLine.MatList matMix = new OrderToLine.MatList(
+ orderDetl.getMatnr(), // matnr -> sku
+ orderDetl.getStandby1(), // supp -> po
+ orderDetl.getAnfme(), // 浣欐枡 -> 鍓╀綑浣欐枡缁熶竴鏃堕棿鎴虫爣璁�
+ orderDetl.getStandby2(), //barcode -> upc 鏉$爜
+ 1,
+ null, //origin -> supplier 璐ф簮
+ bindingTag //浣欐枡鏍囪鐩稿悓
+ );
+// matListsRemainder.add(matMix);
+// orderDetlsRemainder.add(orderDetl);
+ matLists.add(matMix);
+ } else {
+ Double ctns = anfme - remainder;
+ // 缁勮鐗╂枡淇℃伅
+ OrderToLine.MatList mat = new OrderToLine.MatList(
+ orderDetl.getMatnr(), // matnr -> sku
+ orderDetl.getStandby1(), // supp -> po
+ orderDetl.getAnfme(), //鏁存枡
+ orderDetl.getStandby2(), //barcode -> upc
+ 1,
+ null, //origin -> supplier 璐ф簮
+ System.currentTimeMillis()
+ );
+ matLists.add(mat);
+ }
+ }
+// // 鏅鸿兘鍒嗙粍浣欐枡
+// if (matListsRemainder.size() > 0) {
+// groupRemainders(orderDetlsRemainder, orderDetlsRemainder.size(), orderDetls.size(), matLists);
+// }
+ orderToLine.setMatList(matLists);
+ try{
+ ReturnT<String> returnT = orderToLineHandler.start(orderToLine);
+ if (!returnT.isSuccess()) {
+ log.error("涓嬪彂鍗曟嵁澶辫触===>"+ JSON.toJSON(orderToLine));
+ }
+ try{
+ for (OrderToLine.MatList matList:orderToLine.getMatList()){
+ BasArmMastSign basArmMastSign = new BasArmMastSign();
+ basArmMastSign.setMatnr(matList.getSku());
+ basArmMastSign.setOrderNo(orderToLine.getOrderNo());
+ basArmMastSign.setSku(matList.getSku());
+ basArmMastSign.setPo(matList.getPo());
+ basArmMastSign.setUpc(matList.getUpc());
+ basArmMastSign.setSupplier(matList.getSupplier());
+ basArmMastSign.setStatus(0);
+ basArmMastSign.setCreateTime(matList.getBindingTags());
+ basArmMastSignService.insert(basArmMastSign);
+ }
+ }catch (Exception e){
+
+ }
+ } catch (Exception e){
+ log.error("涓嬪彂鍗曟嵁寮傚父===>"+e.getMessage());
+ }
+
+ }
+
+ }
+
+
+ private void groupRemainders(List<OrderDetl> sameMaterialList, double totalRemainder,
+ int number, List<OrderToLine.MatList> matLists) {
+ // 绛栫暐1: 濡傛灉浣欐枡鎬婚噺杈冨ぇ锛屽皾璇曞垎鎴愬涓悎鐞嗗ぇ灏忕殑缁�
+ if (totalRemainder > number * 0.6) {
+ // 鍙互鍒嗘垚2缁勬垨鏇村缁�
+ int suggestedGroups = (int) Math.ceil(totalRemainder / (number * 0.8));
+ distributeRemainders(sameMaterialList, totalRemainder, suggestedGroups, matLists);
+ } else {
+ // 灏忎綑鏂欏崟缁勫鐞�
+ Long bindingTag = System.currentTimeMillis();
+ matLists.add(createMatListItem(sameMaterialList.get(0), totalRemainder, bindingTag, true));
+ }
+ }
+
+
+ private void distributeRemainders(List<OrderDetl> sameMaterialList, double totalRemainder,
+ int groupCount, List<OrderToLine.MatList> matLists) {
+ double average = totalRemainder / groupCount;
+
+ for (int i = 0; i < groupCount; i++) {
+ double groupQuantity;
+ if (i == groupCount - 1) {
+ // 鏈�鍚庝竴缁勫彇鍓╀綑鎵�鏈�
+ groupQuantity = totalRemainder - (average * (groupCount - 1));
+ } else {
+ groupQuantity = average;
+ }
+
+ // 涓烘瘡缁勭敓鎴愬敮涓�鏍囪
+ Long groupTag = System.currentTimeMillis() + i;
+ matLists.add(createMatListItem(sameMaterialList.get(0), groupQuantity, groupTag, true));
+ }
+ }
+
+ private OrderToLine.MatList createMatListItem(OrderDetl orderDetl, Double quantity, Long bindingTag, boolean isRemainder) {
+ return new OrderToLine.MatList(
+ orderDetl.getMatnr(),
+ orderDetl.getSupp(),
+ quantity,
+ orderDetl.getBarcode(),
+ 1,
+ isRemainder ? null : orderDetl.getOrigin(),
+ isRemainder ? bindingTag : System.currentTimeMillis()
+ );
}
}
--
Gitblit v1.9.1