From 82065a03737fa1370eb9f4f01ab5332933baf08a Mon Sep 17 00:00:00 2001
From: chen.lin <1442464845@qq.com>
Date: 星期四, 05 三月 2026 09:23:37 +0800
Subject: [PATCH] 云仓WMS+RCS+自动入库临时方法配置
---
rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/WaitPakinServiceImpl.java | 132 +++++++++++++++++++++++++++++++++++++------
1 files changed, 112 insertions(+), 20 deletions(-)
diff --git a/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/WaitPakinServiceImpl.java b/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/WaitPakinServiceImpl.java
index eea2499..b912340 100644
--- a/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/WaitPakinServiceImpl.java
+++ b/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/WaitPakinServiceImpl.java
@@ -12,10 +12,12 @@
import com.vincent.rsf.server.manager.service.*;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.vincent.rsf.server.common.utils.QuantityUtils;
+import com.vincent.rsf.server.system.constant.GlobalConfigCode;
import com.vincent.rsf.server.system.constant.SerialRuleCode;
+import com.vincent.rsf.server.system.entity.Config;
+import com.vincent.rsf.server.system.service.ConfigService;
import com.vincent.rsf.server.system.utils.SerialRuleUtils;
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;
@@ -45,6 +47,8 @@
private TaskItemService taskItemService;
@Autowired
private MatnrMapper matnrMapper;
+ @Autowired
+ private ConfigService configService;
/**
@@ -67,8 +71,8 @@
WaitPakin pakin = waitPakinService.getOne(new LambdaQueryWrapper<WaitPakin>()
.eq(WaitPakin::getBarcode, waitPakin.getBarcode()));
- // 濡傛灉鏂欑鐮佸凡缁忕粍鎵樿繃锛屾彁绀哄凡缁勬墭锛岃鏇存崲鏂欑鐮�
- if (!Objects.isNull(pakin)) {
+ // 鍗婄鏃跺厑璁稿悓涓�鏂欑鐮佺户缁粍鎵樿拷鍔狅紱闈炲崐绠辨椂鏂欑鐮佸凡缁勬墭鍒欎笉鍙啀鐢�
+ if (!Objects.isNull(pakin) && !Boolean.TRUE.equals(waitPakin.getIsHalf())) {
throw new CoolException("宸茬粍鎵橈紝璇锋洿鎹㈡枡绠辩爜");
}
@@ -85,14 +89,17 @@
Double sum = QuantityUtils.roundToScale(waitPakin.getItems().stream().mapToDouble(PakinItem::getReceiptQty).sum());
- WaitPakin waitPakin1 = new WaitPakin();
+ Config directPakinConfig = configService.getOne(new LambdaQueryWrapper<Config>().eq(Config::getFlag, GlobalConfigCode.DIRECT_WAIT_PAKIN));
+ boolean directWaitPakin = directPakinConfig != null && Boolean.parseBoolean(directPakinConfig.getVal());
+
+ WaitPakin waitPakin1;
if (Objects.isNull(pakin)) {
+ waitPakin1 = new WaitPakin();
String ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_WAIT_PAKIN_CODE, null);
if (StringUtils.isBlank(ruleCode)) {
throw new CoolException("缂栫爜瑙勫垯閿欒锛� 缂栫爜瑙勫垯銆孲YS_WAIT_PAKIN_CODE銆嶈鍒欐槸涓嶅瓨鍦�");
}
waitPakin1.setCode(ruleCode)
- //鐘舵�佷慨鏀逛负鍏ュ簱涓�
.setIoStatus(PakinIOStatus.PAKIN_IO_STATUS_DONE.val)
.setAnfme(sum)
.setUpdateBy(userId)
@@ -102,14 +109,94 @@
throw new CoolException("涓诲崟淇濆瓨澶辫触锛侊紒");
}
} else {
- BeanUtils.copyProperties(pakin, waitPakin1);
+ // 鍗婄杩藉姞锛氭部鐢ㄥ凡鏈夌粍鎵樺崟锛屽彧杩藉姞鏄庣粏
+ waitPakin1 = pakin;
}
List<WaitPakinItem> items = new ArrayList<>();
+ if (directWaitPakin) {
+ // DirectWaitPakin 鍚敤锛氱粍鎵樻潵鑷敹璐у尯锛宲aram 涓� id 涓� WarehouseAreasItem.id
+ for (PakinItem pakinItem1 : waitPakin.getItems()) {
+ WarehouseAreasItem areaItem = warehouseAreasItemService.getById(pakinItem1.getId());
+ if (areaItem == null) {
+ throw new CoolException("鐗╂枡鏈�佽嚦鏀惰揣鍖猴紒锛�");
+ }
+ WaitPakinItem pakinItem = new WaitPakinItem();
+ pakinItem.setPakinId(waitPakin1.getId())
+ .setSource(areaItem.getId())
+ .setAsnId(areaItem.getAsnId())
+ .setAsnCode(areaItem.getAsnCode())
+ .setAsnItemId(areaItem.getAsnItemId())
+ .setIsptResult(areaItem.getIsptResult())
+ .setPlatItemId(areaItem.getPlatItemId())
+ .setPlatOrderCode(areaItem.getPlatOrderCode())
+ .setPlatWorkCode(areaItem.getPlatWorkCode())
+ .setProjectCode(areaItem.getProjectCode())
+ .setBatch(areaItem.getSplrBatch())
+ .setUnit(areaItem.getStockUnit())
+ .setFieldsIndex(areaItem.getFieldsIndex())
+ .setMatnrId(areaItem.getMatnrId())
+ .setMaktx(areaItem.getMaktx())
+ .setUpdateBy(userId)
+ .setCreateBy(userId)
+ .setMatnrCode(areaItem.getMatnrCode());
+ WkOrder order = asnOrderService.getById(areaItem.getAsnId());
+ if (order != null) {
+ pakinItem.setType(order.getType()).setWkType(StringUtils.isNotBlank(order.getWkType()) ? Short.parseShort(order.getWkType()) : null);
+ }
+ if (pakinItem1.getReceiptQty() == null || pakinItem1.getReceiptQty().compareTo(0.0) <= 0) {
+ throw new CoolException("缁勬墭鏁伴噺涓嶈兘灏忎簬绛変簬闆讹紒锛�");
+ }
+ if (QuantityUtils.compare(pakinItem1.getReceiptQty(), areaItem.getAnfme()) > 0) {
+ throw new CoolException("缁勬墭鏁伴噺涓嶈兘澶т簬鏀惰揣鏁伴噺锛侊紒");
+ }
+ pakinItem.setAnfme(QuantityUtils.roundToScale(pakinItem1.getReceiptQty())).setTrackCode(pakinItem1.getTrackCode());
+ items.add(pakinItem);
+ }
+ if (!waitPakinItemService.saveBatch(items)) {
+ throw new CoolException("缁勬墭鏄庣粏淇濆瓨澶辫触锛侊紒");
+ }
+ for (WaitPakinItem pakinItem : items) {
+ WarehouseAreasItem one = warehouseAreasItemService.getOne(new LambdaQueryWrapper<WarehouseAreasItem>().eq(WarehouseAreasItem::getId, pakinItem.getSource()));
+ if (one == null) {
+ throw new CoolException("鏀惰揣鍖烘暟鎹敊璇紒锛�");
+ }
+ Double workQty = QuantityUtils.roundToScale(QuantityUtils.add(one.getWorkQty() != null ? one.getWorkQty() : 0.0, pakinItem.getAnfme()));
+ Double qty = QuantityUtils.roundToScale(QuantityUtils.add(workQty, one.getQty() != null ? one.getQty() : 0.0));
+ one.setWorkQty(workQty);
+ if (QuantityUtils.compare(qty, one.getAnfme() != null ? one.getAnfme() : 0.0) > 0) {
+ throw new CoolException("缁勬墭鏁伴噺涓嶈兘澶т簬鏀惰揣鏁伴噺锛侊紒");
+ }
+ if (!warehouseAreasItemService.saveOrUpdate(one)) {
+ throw new CoolException("鏀惰揣鍖烘墽琛屾暟閲忎慨鏀瑰け璐ワ紒锛�");
+ }
+ }
+ // 鍗婄杩藉姞鏃堕渶鎸夎缁勬墭鍗曚笅鍏ㄩ儴鏄庣粏閲嶇畻鎬绘暟閲�
+ List<WaitPakinItem> allItems = waitPakinItemService.list(new LambdaQueryWrapper<WaitPakinItem>().eq(WaitPakinItem::getPakinId, waitPakin1.getId()));
+ waitPakin1.setAnfme(QuantityUtils.roundToScale(allItems.stream().mapToDouble(w -> w.getAnfme() != null ? w.getAnfme() : 0.0).sum()));
+ if (!this.updateById(waitPakin1)) {
+ throw new CoolException("缁勬墭鏁伴噺淇敼澶辫触锛侊紒");
+ }
+ return waitPakin1;
+ }
+
+ // 鏈堿SN鏃讹細鎸夎鍗曟槑缁嗘眹鎬诲凡缁勬墭鏁伴噺锛屾牎楠� 宸茬粍鎵�+鏈缁勭洏 鈮� 璁″垝鏁伴噺
+ Map<Long, Double> alreadyPalletizedByItemId = new java.util.HashMap<>();
+ for (PakinItem p : waitPakin.getItems()) {
+ if (StringUtils.isNotBlank(p.getAsnCode()) && p.getId() != null) {
+ alreadyPalletizedByItemId.putIfAbsent(p.getId(), null);
+ }
+ }
+ if (!alreadyPalletizedByItemId.isEmpty()) {
+ for (Long asnItemId : alreadyPalletizedByItemId.keySet()) {
+ double alreadySum = waitPakinItemService.list(new LambdaQueryWrapper<WaitPakinItem>().eq(WaitPakinItem::getAsnItemId, asnItemId).eq(WaitPakinItem::getDeleted, 0))
+ .stream().mapToDouble(w -> w.getAnfme() != null ? w.getAnfme() : 0.0).sum();
+ alreadyPalletizedByItemId.put(asnItemId, QuantityUtils.roundToScale(alreadySum));
+ }
+ }
+
for (PakinItem pakinItem1 : waitPakin.getItems()) {
WaitPakinItem pakinItem = new WaitPakinItem();
-
- // 濡傛灉ASN鍗曞彿涓虹┖锛屼粠鐗╂枡淇℃伅琛ㄨ幏鍙栫墿鏂欎俊鎭紝涓嶆煡璇㈡敹璐у尯
if (StringUtils.isBlank(pakinItem1.getAsnCode())) {
if (Objects.isNull(pakinItem1.getMatnrId())) {
throw new CoolException("鐗╂枡ID涓嶈兘涓虹┖锛侊紒");
@@ -184,8 +271,10 @@
if (waitPakinItem.getReceiptQty() == null || waitPakinItem.getReceiptQty().compareTo(0.0) <= 0) {
throw new CoolException("缁勬墭鏁伴噺涓嶈兘灏忎簬绛変簬闆讹紒锛�");
}
- if (QuantityUtils.compare(waitPakinItem.getReceiptQty(), orderItem.getAnfme()) > 0) {
- throw new CoolException("缁勬墭鏁伴噺涓嶈兘澶т簬璁″垝鏁伴噺锛侊紒");
+ Double anfme = orderItem.getAnfme() != null ? orderItem.getAnfme() : 0.0;
+ Double already = alreadyPalletizedByItemId.getOrDefault(orderItem.getId(), 0.0);
+ if (QuantityUtils.compare(QuantityUtils.add(already, waitPakinItem.getReceiptQty()), anfme) > 0) {
+ throw new CoolException("缁勬墭鏁伴噺涓嶈兘瓒呰繃鍙粍鐩樻暟閲忥紙璁″垝" + anfme + "锛屽凡缁勬墭" + already + "锛屾湰娆℃渶澶�" + QuantityUtils.subtract(anfme, already) + "锛夛紒锛�");
}
pakinItem.setAnfme(QuantityUtils.roundToScale(waitPakinItem.getReceiptQty()))
.setTrackCode(waitPakinItem.getTrackCode());
@@ -284,16 +373,19 @@
throw new CoolException("缁勬墭鏄庣粏鍒犻櫎澶辫触锛侊紒");
}
}
- // 鏀惰揣鍖哄凡鍋滅敤锛屼笉鍐嶅洖鍐欐敹璐у尯
- // for (int i = 0; i < warehouseAreasItems.size(); i++) {
- // if (warehouseAreasItems.get(i).getId().equals(pakinItems.get(i1).getSource())) {
- // double v = Math.round((warehouseAreasItems.get(i).getWorkQty() - item.getReceiptQty()) * 1000000) / 1000000.0;
- // warehouseAreasItems.get(i).setWorkQty(v);
- // if (!warehouseAreasItemService.updateById(warehouseAreasItems.get(i))) {
- // throw new CoolException("鏀惰揣鍖烘暟閲忎慨鏀瑰け璐ワ紒锛�");
- // }
- // }
- // }
+ // DirectWaitPakin 鍚敤鏃剁粍鎵樻潵鑷敹璐у尯锛岃В缁戦渶鍥炲啓鏀惰揣鍖� workQty
+ if (Objects.nonNull(pakinItems.get(i1).getSource())) {
+ for (WarehouseAreasItem areaItem : warehouseAreasItems) {
+ if (areaItem.getId().equals(pakinItems.get(i1).getSource())) {
+ Double v = QuantityUtils.roundToScale(QuantityUtils.subtract(areaItem.getWorkQty() != null ? areaItem.getWorkQty() : 0.0, item.getReceiptQty()));
+ areaItem.setWorkQty(v);
+ if (!warehouseAreasItemService.updateById(areaItem)) {
+ throw new CoolException("鏀惰揣鍖烘暟閲忎慨鏀瑰け璐ワ紒锛�");
+ }
+ break;
+ }
+ }
+ }
}
}
}
--
Gitblit v1.9.1