From 6331768f662e7a11854170c9c0fb86c5b3cb6afd Mon Sep 17 00:00:00 2001
From: zjj <3272660260@qq.com>
Date: 星期一, 28 四月 2025 17:01:26 +0800
Subject: [PATCH] #wms端生成任务优化
---
rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/WaveServiceImpl.java | 141 +++++++++++++++++++++++++++++++++++++++-------
1 files changed, 119 insertions(+), 22 deletions(-)
diff --git a/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/WaveServiceImpl.java b/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/WaveServiceImpl.java
index d42bfd6..96355b3 100644
--- a/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/WaveServiceImpl.java
+++ b/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/WaveServiceImpl.java
@@ -1,64 +1,161 @@
package com.vincent.rsf.server.manager.service.impl;
+import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
-import com.vincent.rsf.framework.common.Cools;
import com.vincent.rsf.framework.common.R;
import com.vincent.rsf.framework.exception.CoolException;
import com.vincent.rsf.server.manager.entity.AsnOrder;
-import com.vincent.rsf.server.manager.entity.AsnOrderItem;
+import com.vincent.rsf.server.manager.entity.LocItem;
+import com.vincent.rsf.server.manager.entity.WaveItem;
+import com.vincent.rsf.server.manager.enums.AsnExceStatus;
import com.vincent.rsf.server.manager.enums.WaveExceStatus;
import com.vincent.rsf.server.manager.mapper.WaveMapper;
import com.vincent.rsf.server.manager.entity.Wave;
-import com.vincent.rsf.server.manager.service.AsnOrderItemService;
-import com.vincent.rsf.server.manager.service.AsnOrderService;
-import com.vincent.rsf.server.manager.service.WaveService;
+import com.vincent.rsf.server.manager.service.*;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.vincent.rsf.server.manager.utils.OptimalAlgorithmUtil;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;
+import java.util.stream.Collectors;
+import java.util.stream.IntStream;
@Service("waveService")
public class WaveServiceImpl extends ServiceImpl<WaveMapper, Wave> implements WaveService {
@Autowired
private AsnOrderItemService asnOrderItemService;
-
@Autowired
private AsnOrderService asnOrderService;
+ @Autowired
+ private WaveItemService waveItemService;
+ @Autowired
+ private TaskService taskService;
+ @Autowired
+ private TaskItemService taskItemService;
+ @Autowired
+ private LocItemService locItemService;
/**
- * @author Ryan
- * @description 娉㈡浠诲姟涓嬪彂
* @param
* @return
+ * @author Ryan
+ * @description 娉㈡浠诲姟涓嬪彂
* @time 2025/4/25 16:24
*/
@Override
@Transactional(rollbackFor = Exception.class)
public R publicTask(Map<String, Object> map) {
- List<Long> ids = (List<Long>) map.get("ids");
- if (Objects.isNull(ids) || ids.isEmpty()) {
+ List<WaveItem> itemParams = (List<WaveItem>) map.get("wave");
+ if (Objects.isNull(itemParams) || itemParams.isEmpty()) {
throw new CoolException("鍙傛暟涓嶈兘涓虹┖锛侊紒");
}
+ List<Long> ids = itemParams.stream().map(WaveItem::getWaveId).collect(Collectors.toList());
List<Wave> waves = this.list(new LambdaQueryWrapper<Wave>().in(Wave::getId, ids));
if (Objects.isNull(waves) || waves.isEmpty()) {
throw new CoolException("娉㈡鏁版嵁涓嶅瓨鍦紒锛�");
}
-
- List<AsnOrder> orders = asnOrderService.list(new LambdaQueryWrapper<AsnOrder>().eq(AsnOrder::getId, ids));
-
-
- asnOrderItemService.list(new LambdaQueryWrapper<AsnOrderItem>().eq(AsnOrderItem::getAsnId, ids));
-
- if (!this.update(new LambdaUpdateWrapper<Wave>().set(Wave::getExceStatus, WaveExceStatus.WAVE_EXCE_STATUS_TASK).in(Wave::getId,ids))) {
- throw new CoolException("娉㈡鐘舵�佷慨鏀瑰け璐ワ紒锛�");
+ List<Long> list = waves.stream().map(Wave::getId).collect(Collectors.toList());
+ List<WaveItem> waveItems = waveItemService.list(new LambdaQueryWrapper<WaveItem>().in(WaveItem::getWaveId, list));
+ if (waveItems.isEmpty()) {
+ throw new CoolException("娉㈡鏄庣粏涓嶅瓨鍦紒锛�");
}
-
+ List<Long> orderIds = waveItems.stream().map(WaveItem::getOrderId).collect(Collectors.toList());
+ /**鏌ヨ姣忔潯鏄庣粏鍖归厤鐨勫簱浣�*/
+ try {
+// List<WaveItem> items = getLocs(waveItems);
+ } catch (Exception e) {
+ throw new CoolException("搴撲綅鑾峰彇澶辫触锛侊紒锛�");
+ }
+ //TODO 1. 鏍规嵁娉㈡鏄庣粏鐢熸垚鍑哄簱浠诲姟
+ // 2. 鏍规嵁鐗╂枡SKU瀵绘壘绗﹀悎鐗╂枡搴撲綅 {1. 鏍规嵁鐗╂枡缂栫爜锛屾壒娆★紝鍔ㄦ�佸瓧娈� 鏌ヨ绗﹀悎鐨勫簱浣嶏紝鍐嶆牴鎹簱浣嶄腑鐗╂枡鐨勬暟閲忛�夋嫨鏈�閫傚悎鐨勫簱浣� 2. 鍒ゆ柇褰撳墠璁㈠崟鏄叏鎷栧嚭搴撹繕鏄嫞鏂欏叆搴搣
+ // 3. 淇敼涓诲崟銆佹尝娆℃墽琛屾暟閲�
+ // 4. 鍒ゆ柇鍏ㄤ粨鍑哄簱鎴栨嫞鏂欏嚭搴�
+// List<AsnOrder> orders = asnOrderService.list(new LambdaQueryWrapper<AsnOrder>().in(AsnOrder::getId, orderIds));
+// /**淇敼鍘熷嚭搴撳崟鐘舵��*/
+// if (!asnOrderService.update(new LambdaQueryWrapper<AsnOrder>()
+// .eq(AsnOrder::getExceStatus, AsnExceStatus.OUT_STOCK_STATUS_TASK_WORKING.val)
+// .in(AsnOrder::getId, orders))) {
+// throw new CoolException("鍑哄簱鍗曟嵁鐘舵�佷慨鏀瑰け璐ワ紒锛�");
+// }
+// if (!this.update(new LambdaUpdateWrapper<Wave>().set(Wave::getExceStatus, WaveExceStatus.WAVE_EXCE_STATUS_TASK).in(Wave::getId, ids))) {
+// throw new CoolException("娉㈡鐘舵�佷慨鏀瑰け璐ワ紒锛�");
+// }
return R.ok();
}
+
+ /**
+ * @param
+ * @return
+ * @author Ryan
+ * @description 棰勮娉㈡涓嬪彂浠诲姟
+ * @time 2025/4/27 11:09
+ */
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public List<WaveItem> mergeWavePreview(Long waveId) {
+ Wave wave = this.getById(waveId);
+ if (Objects.isNull(wave)) {
+ throw new CoolException("娉㈡涓嶈兘瀛樺湪锛侊紒");
+ }
+ List<WaveItem> waveItems = waveItemService.list(new LambdaQueryWrapper<WaveItem>().eq(WaveItem::getWaveId, waveId));
+ if (waveItems.isEmpty()) {
+ throw new CoolException("娉㈡鏄庣粏涓嶅瓨鍦紒锛�");
+ }
+ List<WaveItem> itemPreview = null;
+ try {
+ itemPreview = getLocs(waveItems);
+ } catch (Exception e) {
+ throw new CoolException("搴撲綅鑾峰彇澶辫触锛侊紒锛侊紒");
+ }
+ return itemPreview;
+ }
+
+ /**
+ * @param
+ * @param waveItems
+ * @return
+ * @author Ryan
+ * @description 鏍规嵁鐗╂枡缂栫爜锛屾壒娆★紝鍔ㄦ�佸瓧娈� 鏌ヨ绗﹀悎鐨勫簱浣嶏紝鍐嶆牴鎹簱浣嶄腑鐗╂枡鐨勬暟閲忛�夋嫨鏈�閫傚悎鐨勫簱浣�
+ * @time 2025/4/27 09:26
+ */
+ private synchronized List<WaveItem> getLocs(List<WaveItem> waveItems) throws Exception {
+ //TODO 鏍规嵁鐗╂枡缂栫爜锛屾壒娆★紝鍔ㄦ�佸瓧娈� 鏌ヨ绗﹀悎鐨勫簱浣嶏紝鍐嶆牴鎹簱浣嶄腑鐗╂枡鐨勬暟閲忛�夋嫨鏈�閫傚悎鐨勫簱浣�
+ waveItems.forEach(waveItem -> {
+ List<LocItem> locItems = locItemService.list(new QueryWrapper<LocItem>()
+ .select("id", "loc_id", "loc_code", "order_id", "SUM(anfme) anfme", "SUM(work_qty) work_qty", "splr_batch", "fields_index", "matnr_code")
+ .lambda()
+ .eq(LocItem::getMatnrCode, waveItem.getMatnrCode())
+ .eq(LocItem::getSplrBatch, waveItem.getSplrBatch())
+ .eq(StringUtils.isNotBlank(waveItem.getFieldsIndex()), LocItem::getFieldsIndex, waveItem.getFieldsIndex())
+ .groupBy(LocItem::getMatnrCode, LocItem::getSplrBatch, LocItem::getFieldsIndex, LocItem::getId));
+ List<Double> doubles1 = locItems.stream().map(LocItem::getAnfme).collect(Collectors.toList());
+ double[] doubles = doubles1.stream().mapToDouble(Double::doubleValue).toArray();
+
+ /**浣跨敤鍥炴函绠楁硶璁$畻锛岃幏鍙栫鍚堝嚭搴撻噺鐨勬渶绠�缁勫悎*/
+ List<Integer> result = OptimalAlgorithmUtil.findCombination(doubles, waveItem.getAnfme());
+ String locs = "[]";
+ if (Objects.isNull(result)) {
+ waveItem.setStockLocs(locs).setStockQty(0.0);
+ } else {
+ /**杩囨护闆嗗悎涓渶绠�鐭殑缁勫悎*/
+ List<LocItem> locsInfo = result.stream()
+ .filter(i -> i >= 0 && i < locItems.size())
+ .map(locItems::get).collect(Collectors.toList());
+ locs = JSONArray.toJSONString(locsInfo);
+ double sumQty = locItems.stream().mapToDouble(LocItem::getAnfme).sum();
+ double surQty = locItems.stream().mapToDouble(LocItem::getWorkQty).sum();
+ double qty = locItems.stream().mapToDouble(LocItem::getQty).sum();
+ double v = sumQty - surQty - qty;
+ waveItem.setStockLocs(locs).setStockQty(v);
+ }
+ });
+ return waveItems;
+ }
}
--
Gitblit v1.9.1