From c81fc5e2a4f4153be2bb8602ed14a0743e6ecd29 Mon Sep 17 00:00:00 2001
From: chen.lin <1442464845@qq.com>
Date: 星期四, 05 三月 2026 11:14:50 +0800
Subject: [PATCH] RCS对接优化
---
rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/WaitPakinServiceImpl.java | 325 +++++++++++++++++++++++++++++++++++++----------------
1 files changed, 224 insertions(+), 101 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 137fa7a..5ff3493 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
@@ -11,10 +11,13 @@
import com.vincent.rsf.server.manager.mapper.MatnrMapper;
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;
@@ -44,6 +47,8 @@
private TaskItemService taskItemService;
@Autowired
private MatnrMapper matnrMapper;
+ @Autowired
+ private ConfigService configService;
/**
@@ -66,9 +71,9 @@
WaitPakin pakin = waitPakinService.getOne(new LambdaQueryWrapper<WaitPakin>()
.eq(WaitPakin::getBarcode, waitPakin.getBarcode()));
- // 濡傛灉瀹瑰櫒鍙峰凡缁忕粍鎵樿繃锛屾彁绀哄凡缁勬墭锛岃鏇存崲瀹瑰櫒鏉$爜
- if (!Objects.isNull(pakin)) {
- throw new CoolException("宸茬粍鎵橈紝璇锋洿鎹㈠鍣ㄦ潯鐮�");
+ // 鍗婄鏃跺厑璁稿悓涓�鏂欑鐮佺户缁粍鎵樿拷鍔狅紱闈炲崐绠辨椂鏂欑鐮佸凡缁勬墭鍒欎笉鍙啀鐢�
+ if (!Objects.isNull(pakin) && !Boolean.TRUE.equals(waitPakin.getIsHalf())) {
+ throw new CoolException("宸茬粍鎵橈紝璇锋洿鎹㈡枡绠辩爜");
}
List<Task> tasks = taskService.list(new LambdaQueryWrapper<Task>().eq(Task::getBarcode, waitPakin.getBarcode()));
@@ -76,22 +81,25 @@
throw new CoolException("褰撳墠鏂欑宸叉湁浠诲姟妗e湪鎵ц锛屼笉鑳藉啀娆$粍鎵橈紒锛�");
}
- // 妫�鏌ュ鍣ㄥ彿鏄惁鍦ㄥ簱瀛樹腑瀛樺湪锛堥�氳繃搴撲綅琛ㄦ煡璇級
+ // 妫�鏌ユ枡绠辩爜鏄惁鍦ㄥ簱瀛樹腑瀛樺湪锛堥�氳繃搴撲綅琛ㄦ煡璇級
List<Loc> locs = locService.list(new LambdaQueryWrapper<Loc>().eq(Loc::getBarcode, waitPakin.getBarcode()));
if (!locs.isEmpty()) {
- throw new CoolException("鍦ㄥ簱锛岃鏇存崲瀹瑰櫒鏉$爜");
+ throw new CoolException("鍦ㄥ簱锛岃鏇存崲鏂欑鐮�");
}
- double sum = waitPakin.getItems().stream().mapToDouble(PakinItem::getReceiptQty).sum();
+ 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)
@@ -101,14 +109,133 @@
throw new CoolException("涓诲崟淇濆瓨澶辫触锛侊紒");
}
} else {
- BeanUtils.copyProperties(pakin, waitPakin1);
+ // 鍗婄杩藉姞锛氭部鐢ㄥ凡鏈夌粍鎵樺崟锛屽彧杩藉姞鏄庣粏
+ waitPakin1 = pakin;
}
List<WaitPakinItem> items = new ArrayList<>();
+ if (directWaitPakin) {
+ // DirectWaitPakin 鍚敤锛氱粍鎵樺彲鏉ヨ嚜鏀惰揣鍖猴紙鏈� id锛夋垨鏃犺鍗曠粍鎵橈紙id 涓� null锛屼粎鐗╂枡+鏁伴噺锛�
+ for (PakinItem pakinItem1 : waitPakin.getItems()) {
+ if (pakinItem1.getId() == null) {
+ // 鏃犺鍗曠粍鎵橈細鏃犳敹璐у尯鏉ユ簮锛屾寜 matnrId + receiptQty 寤虹粍鎵樻槑缁�
+ if (pakinItem1.getMatnrId() == null) {
+ throw new CoolException("鏃犺鍗曠粍鎵樻椂鐗╂枡ID涓嶈兘涓虹┖锛侊紒");
+ }
+ Matnr matnr = matnrMapper.selectById(pakinItem1.getMatnrId());
+ if (matnr == null) {
+ throw new CoolException("鐗╂枡淇℃伅涓嶅瓨鍦紝鐗╂枡ID锛�" + pakinItem1.getMatnrId());
+ }
+ if (pakinItem1.getReceiptQty() == null || pakinItem1.getReceiptQty().compareTo(0.0) <= 0) {
+ throw new CoolException("缁勬墭鏁伴噺涓嶈兘灏忎簬绛変簬闆讹紒锛�");
+ }
+ WaitPakinItem pakinItem = new WaitPakinItem();
+ pakinItem.setPakinId(waitPakin1.getId())
+ .setSource(null)
+ .setAsnId(null)
+ .setAsnCode(null)
+ .setAsnItemId(null)
+ .setIsptResult(null)
+ .setPlatItemId(null)
+ .setPlatOrderCode(null)
+ .setPlatWorkCode(null)
+ .setProjectCode(null)
+ .setBatch(null)
+ .setUnit(matnr.getStockUnit() != null ? matnr.getStockUnit() : "涓�")
+ .setFieldsIndex(matnr.getFieldsIndex())
+ .setMatnrId(matnr.getId())
+ .setMaktx(matnr.getName())
+ .setUpdateBy(userId)
+ .setCreateBy(userId)
+ .setMatnrCode(matnr.getCode())
+ .setAnfme(QuantityUtils.roundToScale(pakinItem1.getReceiptQty()))
+ .setTrackCode(pakinItem1.getTrackCode());
+ items.add(pakinItem);
+ continue;
+ }
+ 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) {
+ if (pakinItem.getSource() == null) {
+ continue; // 鏃犺鍗曠粍鎵樻棤鏀惰揣鍖烘潵婧愶紝涓嶆洿鏂版敹璐у尯
+ }
+ 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涓嶈兘涓虹┖锛侊紒");
@@ -144,47 +271,51 @@
if (pakinItem1.getReceiptQty() == null || pakinItem1.getReceiptQty().compareTo(0.0) <= 0) {
throw new CoolException("缁勬墭鏁伴噺涓嶈兘灏忎簬绛変簬闆讹紒锛�");
}
- pakinItem.setAnfme(pakinItem1.getReceiptQty())
+ pakinItem.setAnfme(QuantityUtils.roundToScale(pakinItem1.getReceiptQty()))
.setTrackCode(pakinItem1.getTrackCode());
} else {
- // 鏈堿SN鍗曞彿锛屼粠鏀惰揣鍖鸿幏鍙栫墿鏂欎俊鎭�
- WarehouseAreasItem warehouseAreasItems = warehouseAreasItemService.getById(pakinItem1.getId());
- if (null == warehouseAreasItems) {
- throw new CoolException("鐗╂枡鏈�佽嚦鏀惰揣鍖猴紒锛�");
+ // 鏀惰揣鍖哄凡鍋滅敤锛氭湁ASN鍗曞彿鏃朵粠璁㈠崟鏄庣粏鑾峰彇鐗╂枡淇℃伅
+ WkOrderItem orderItem = asnOrderItemService.getById(pakinItem1.getId());
+ if (null == orderItem) {
+ throw new CoolException("璁㈠崟鏄庣粏涓嶅瓨鍦紒锛�");
}
-
- pakinItem.setAnfme(warehouseAreasItems.getAnfme())
+ WkOrder order = asnOrderService.getById(orderItem.getOrderId());
+ if (null == order) {
+ throw new CoolException("璁㈠崟涓嶅瓨鍦紒锛�");
+ }
+ pakinItem.setAnfme(QuantityUtils.roundToScale(orderItem.getAnfme()))
.setPakinId(waitPakin1.getId())
- .setSource(warehouseAreasItems.getId())
- .setAsnId(warehouseAreasItems.getAsnId())
- .setAsnCode(warehouseAreasItems.getAsnCode())
- .setAsnItemId(warehouseAreasItems.getAsnItemId())
- .setIsptResult(warehouseAreasItems.getIsptResult())
- .setPlatItemId(warehouseAreasItems.getPlatItemId())
- .setPlatOrderCode(warehouseAreasItems.getPlatOrderCode())
- .setPlatWorkCode(warehouseAreasItems.getPlatWorkCode())
- .setProjectCode(warehouseAreasItems.getProjectCode())
- .setBatch(warehouseAreasItems.getSplrBatch())
- .setUnit(warehouseAreasItems.getStockUnit())
- .setFieldsIndex(warehouseAreasItems.getFieldsIndex())
- .setMatnrId(warehouseAreasItems.getMatnrId())
- .setMaktx(warehouseAreasItems.getMaktx())
+ .setSource(null) // 鏀惰揣鍖哄凡鍋滅敤锛屼笉鍏宠仈鏀惰揣鍖�
+ .setAsnId(order.getId())
+ .setAsnCode(order.getCode())
+ .setAsnItemId(orderItem.getId())
+ .setIsptResult(orderItem.getIsptResult())
+ .setPlatItemId(orderItem.getPlatItemId())
+ .setPlatOrderCode(orderItem.getPlatOrderCode())
+ .setPlatWorkCode(orderItem.getPlatWorkCode())
+ .setProjectCode(orderItem.getProjectCode())
+ .setBatch(orderItem.getSplrBatch())
+ .setUnit(orderItem.getStockUnit())
+ .setFieldsIndex(orderItem.getFieldsIndex())
+ .setMatnrId(orderItem.getMatnrId())
+ .setMaktx(orderItem.getMaktx())
.setUpdateBy(userId)
.setCreateBy(userId)
- .setMatnrCode(warehouseAreasItems.getMatnrCode());
-
- WkOrder order = asnOrderService.getById(warehouseAreasItems.getAsnId());
- if (!Objects.isNull(order)) {
- pakinItem.setType(null == order.getType() ? null : order.getType())
- .setWkType(null == order.getWkType() ? null : Short.parseShort(order.getWkType()));
- }
+ .setMatnrCode(orderItem.getMatnrCode());
+ pakinItem.setType(null == order.getType() ? null : order.getType())
+ .setWkType(StringUtils.isNotBlank(order.getWkType()) ? Short.parseShort(order.getWkType()) : null);
for (PakinItem waitPakinItem : waitPakin.getItems()) {
- if (waitPakinItem.getId().equals(warehouseAreasItems.getId())) {
- if (waitPakinItem.getReceiptQty() > warehouseAreasItems.getAnfme() || waitPakinItem.getReceiptQty().compareTo(0.0) <= 0) {
- throw new CoolException("缁勬墭鏁伴噺涓嶈兘澶т簬鏀惰揣鏁伴噺涓斾笉鑳藉皬浜庨浂锛侊紒");
+ if (waitPakinItem.getId().equals(orderItem.getId())) {
+ if (waitPakinItem.getReceiptQty() == null || waitPakinItem.getReceiptQty().compareTo(0.0) <= 0) {
+ throw new CoolException("缁勬墭鏁伴噺涓嶈兘灏忎簬绛変簬闆讹紒锛�");
}
- pakinItem.setAnfme(waitPakinItem.getReceiptQty())
+ 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());
}
}
@@ -200,31 +331,22 @@
List<WaitPakinItem> pakinItems = waitPakinItemService.list(new LambdaQueryWrapper<WaitPakinItem>().eq(WaitPakinItem::getPakinId, waitPakin1.getId()));
Double waitSum = 0.0;
if (!pakinItems.isEmpty()) {
- waitSum = pakinItems.stream().mapToDouble(WaitPakinItem::getAnfme).sum();
+ waitSum = QuantityUtils.roundToScale(pakinItems.stream().mapToDouble(WaitPakinItem::getAnfme).sum());
}
// Double total = Math.round((sum + waitSum) * 100) / 100.0;
- for (WaitPakinItem pakinItem : items) {
- // 濡傛灉source涓虹┖锛堟病鏈堿SN鍗曞彿锛屼笉鍦ㄦ敹璐у尯锛夛紝璺宠繃鏀惰揣鍖烘洿鏂�
- if (Objects.isNull(pakinItem.getSource())) {
- continue;
- }
-
- WarehouseAreasItem one = warehouseAreasItemService.getOne(new LambdaQueryWrapper<WarehouseAreasItem>()
- .eq(WarehouseAreasItem::getId, pakinItem.getSource()));
- if (Objects.isNull(one)) {
- throw new CoolException("鏀惰揣鍖烘暟鎹敊璇紒锛�");
- }
- Double workQty = Math.round((one.getWorkQty() + pakinItem.getAnfme()) * 1000000) / 1000000.0;
- Double qty = Math.round((workQty + one.getQty()) * 1000000) / 1000000.0;
- one.setWorkQty(workQty);
- if (qty.compareTo(one.getAnfme()) > 0) {
- throw new CoolException("缁勬墭鏁伴噺涓嶈兘澶т簬鏀惰揣鏁伴噺锛侊紒");
- }
- if (!warehouseAreasItemService.saveOrUpdate(one)) {
- throw new CoolException("鏀惰揣鍖烘墽琛屾暟閲忎慨鏀瑰け璐ワ紒锛�");
- }
- }
+ // 鏀惰揣鍖哄凡鍋滅敤锛屼笉鍐嶆洿鏂版敹璐у尯
+ // for (WaitPakinItem pakinItem : items) {
+ // if (Objects.isNull(pakinItem.getSource())) continue;
+ // WarehouseAreasItem one = warehouseAreasItemService.getOne(new LambdaQueryWrapper<WarehouseAreasItem>()
+ // .eq(WarehouseAreasItem::getId, pakinItem.getSource()));
+ // if (Objects.isNull(one)) throw new CoolException("鏀惰揣鍖烘暟鎹敊璇紒锛�");
+ // Double workQty = Math.round((one.getWorkQty() + pakinItem.getAnfme()) * 1000000) / 1000000.0;
+ // Double qty = Math.round((workQty + one.getQty()) * 1000000) / 1000000.0;
+ // one.setWorkQty(workQty);
+ // if (qty.compareTo(one.getAnfme()) > 0) throw new CoolException("缁勬墭鏁伴噺涓嶈兘澶т簬鏀惰揣鏁伴噺锛侊紒");
+ // if (!warehouseAreasItemService.saveOrUpdate(one)) throw new CoolException("鏀惰揣鍖烘墽琛屾暟閲忎慨鏀瑰け璐ワ紒锛�");
+ // }
waitPakin1.setAnfme(waitSum);
if (!this.updateById(waitPakin1)) {
@@ -265,21 +387,22 @@
// if (!waitPakinItemService.removeByIds(ids)) {
// throw new CoolException("缁勬墭鏄庣粏瑙g粦澶辫触锛侊紒");
// }
- List<Long> list2 = pakinItems.stream().map(WaitPakinItem::getSource).collect(Collectors.toList());
- List<WarehouseAreasItem> warehouseAreasItems = warehouseAreasItemService.listByIds(list2);
+ // 鏀惰揣鍖哄凡鍋滅敤锛氫粎淇濈暀闈炵┖ source 鐢ㄤ簬鍏煎鏃ф暟鎹紝涓嶅啀鏇存柊鏀惰揣鍖�
+ List<Long> list2 = pakinItems.stream().map(WaitPakinItem::getSource).filter(Objects::nonNull).collect(Collectors.toList());
+ List<WarehouseAreasItem> warehouseAreasItems = list2.isEmpty() ? Collections.emptyList() : warehouseAreasItemService.listByIds(list2);
for (int i1 = 0; i1 < pakinItems.size(); i1++) {
for (PakinItem item : paramItems) {
if (item.getId().equals(pakinItems.get(i1).getId())) {
- if (pakinItems.get(i1).getAnfme().compareTo(item.getReceiptQty()) > 0) {
- if (item.getReceiptQty().compareTo(0.00) == 0) {
+ if (QuantityUtils.compare(pakinItems.get(i1).getAnfme(), item.getReceiptQty()) > 0) {
+ if (QuantityUtils.compare(item.getReceiptQty(), 0.00) == 0) {
throw new CoolException("瑙g粦鏁伴噺涓嶈兘涓洪浂锛侊紒");
}
- Double reslt = Math.round((pakinItems.get(i1).getAnfme() - pakinItems.get(i1).getWorkQty() - pakinItems.get(i1).getQty()) * 1000000) / 1000000.0;
- if (item.getReceiptQty().compareTo(reslt) > 0) {
+ Double reslt = QuantityUtils.subtract(QuantityUtils.subtract(pakinItems.get(i1).getAnfme(), pakinItems.get(i1).getWorkQty()), pakinItems.get(i1).getQty());
+ if (QuantityUtils.compare(item.getReceiptQty(), reslt) > 0) {
throw new CoolException("瑙g粦鏁伴噺涓嶈兘澶т簬鍓╀綑鍙墽琛屾暟锛侊紒");
}
- Double anfme = Math.round((pakinItems.get(i1).getAnfme() - item.getReceiptQty()) * 1000000) / 1000000.0;
+ Double anfme = QuantityUtils.subtract(pakinItems.get(i1).getAnfme(), item.getReceiptQty());
pakinItems.get(i1).setAnfme(anfme);
if (!waitPakinItemService.updateById(pakinItems.get(i1))) {
throw new CoolException("缁勬墭鏄庣粏鏁伴噺淇敼澶辫触锛侊紒");
@@ -289,12 +412,16 @@
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;
}
}
}
@@ -302,15 +429,14 @@
}
}
- double anfmes = paramItems.stream().mapToDouble(PakinItem::getReceiptQty).sum();
+ Double anfmes = QuantityUtils.roundToScale(paramItems.stream().mapToDouble(PakinItem::getReceiptQty).sum());
// double anfmes = warehouseAreasItems.stream().mapToDouble(WarehouseAreasItem::getAnfme).sum();
- if (waitPakins.getAnfme().compareTo(anfmes) <= 0) {
+ if (QuantityUtils.compare(waitPakins.getAnfme(), anfmes) <= 0) {
if (!waitPakinService.removeById(waitPakins.getId())) {
throw new CoolException("缁勬墭鍒犻櫎澶辫触锛侊紒");
}
} else {
- Double anfme = Math.round((waitPakins.getAnfme() - anfmes) * 1000000) / 1000000.0;
- waitPakins.setAnfme(anfme);
+ waitPakins.setAnfme(QuantityUtils.subtract(waitPakins.getAnfme(), anfmes));
if (!waitPakinService.updateById(waitPakins)) {
throw new CoolException("缁勬墭鏁版嵁淇敼澶辫触锛侊紒");
}
@@ -338,26 +464,23 @@
return R.error("缁勬嫋妗f湁鏄庣粏浠诲姟");
}
- Set<Long> sourceIds = pakinItems.stream().map(WaitPakinItem::getSource).collect(Collectors.toSet());
+ Set<Long> sourceIds = pakinItems.stream().map(WaitPakinItem::getSource).filter(Objects::nonNull).collect(Collectors.toSet());
- List<WarehouseAreasItem> areasItems = warehouseAreasItemService.list(new LambdaQueryWrapper<WarehouseAreasItem>()
- .in(WarehouseAreasItem::getId, sourceIds));
+ List<WarehouseAreasItem> areasItems = sourceIds.isEmpty() ? Collections.emptyList() : warehouseAreasItemService.list(new LambdaQueryWrapper<WarehouseAreasItem>().in(WarehouseAreasItem::getId, sourceIds));
- if (areasItems.isEmpty()) {
- return R.error("鏀惰揣鍖烘暟鎹笉瀛樺湪锛侊紒");
- }
-
- Map<Long, List<WaitPakinItem>> listMap = pakinItems.stream().collect(Collectors.groupingBy(WaitPakinItem::getSource));
- for (WarehouseAreasItem item : areasItems) {
- List<WaitPakinItem> pakin = listMap.get(item.getId());
- if (Objects.isNull(pakin)) {
- continue;
- }
- double sum = pakin.stream().mapToDouble(WaitPakinItem::getAnfme).sum();
- Double workQty = Math.round((item.getWorkQty() - sum) * 1000000) / 1000000.0;
- item.setWorkQty(workQty);
- if (!warehouseAreasItemService.updateById(item)) {
- throw new CoolException("鏀惰揣鍖烘暟鎹洖婊氬け璐ワ紒锛�");
+ // 鏀惰揣鍖哄凡鍋滅敤锛屼粎鍏煎鏃ф暟鎹椂鍥炴粴鏀惰揣鍖烘暟閲�
+ if (!areasItems.isEmpty()) {
+ Map<Long, List<WaitPakinItem>> listMap = pakinItems.stream().collect(Collectors.groupingBy(WaitPakinItem::getSource));
+ for (WarehouseAreasItem item : areasItems) {
+ List<WaitPakinItem> pakin = listMap.get(item.getId());
+ if (Objects.isNull(pakin)) {
+ continue;
+ }
+ Double sum = QuantityUtils.roundToScale(pakin.stream().mapToDouble(WaitPakinItem::getAnfme).sum());
+ item.setWorkQty(QuantityUtils.subtract(item.getWorkQty(), sum));
+ if (!warehouseAreasItemService.updateById(item)) {
+ throw new CoolException("鏀惰揣鍖烘暟鎹洖婊氬け璐ワ紒锛�");
+ }
}
}
--
Gitblit v1.9.1