From a76bde8ba1f9a35a0490b5ced3fd6a8ba084a712 Mon Sep 17 00:00:00 2001
From: chen.lin <1442464845@qq.com>
Date: 星期三, 11 二月 2026 13:09:06 +0800
Subject: [PATCH] 修改库口
---
rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/OutStockServiceImpl.java | 82 ++++++++++++++++++++++++-----------------
1 files changed, 48 insertions(+), 34 deletions(-)
diff --git a/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/OutStockServiceImpl.java b/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/OutStockServiceImpl.java
index 9da1c20..3b301d7 100644
--- a/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/OutStockServiceImpl.java
+++ b/rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/OutStockServiceImpl.java
@@ -29,6 +29,7 @@
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
+import java.math.RoundingMode;
import java.util.*;
import java.util.stream.Collectors;
@@ -47,6 +48,8 @@
public Logger logger = LoggerFactory.getLogger(this.getClass());
+ /** 鍑哄簱鍓╀綑閲忓宸細灏忎簬绛変簬姝ゅ�艰涓哄凡鍒嗛厤瀹岋紝閬垮厤娴偣璇樊浜х敓澶氫綑鈥滃簱瀛樹笉瓒斥�濊 */
+ private static final BigDecimal ISSUED_TOLERANCE = new BigDecimal("0.000001");
@Autowired
private AsnOrderItemService asnOrderItemService;
@@ -517,7 +520,12 @@
if (StringUtils.isNotBlank(locItem.getFieldsIndex())) {
orderItemWrapper.eq(WkOrderItem::getFieldsIndex, locItem.getFieldsIndex());
}
- WkOrderItem orderItem = outStockItemService.getOne(orderItemWrapper);
+ // 鍚屼竴鍑哄簱鍗曚笅鍚屼竴鐗╂枡鍙兘鏈夊鏉℃槑缁嗭紙濡傚琛屽悎骞讹級锛岀敤 list 鍙栦粛鏈夊墿浣欐暟閲忕殑绗竴鏉★紝閬垮厤 getOne 杩斿洖澶氭潯鎶� TooManyResultsException
+ List<WkOrderItem> orderItemCandidates = outStockItemService.list(orderItemWrapper);
+ WkOrderItem orderItem = orderItemCandidates.stream()
+ .filter(o -> o.getAnfme() != null && o.getWorkQty() != null && o.getAnfme().compareTo(o.getWorkQty()) > 0)
+ .findFirst()
+ .orElse(null);
// 濡傛灉鎵句笉鍒板崟鎹槑缁嗭紝涓擫ocItem鏉ヨ嚜搴撳瓨璋冩暣锛屽垯鑷姩鍒涘缓WkOrderItem
if (Objects.isNull(orderItem)) {
@@ -681,9 +689,8 @@
Set<ExistDto> existDtos = new HashSet<>();
for (WkOrderItem wkOrderItem : wkOrderItems) {
BigDecimal issued = new BigDecimal(wkOrderItem.getAnfme().toString())
- .subtract(new BigDecimal(wkOrderItem.getWorkQty().toString())
- );
- if (issued.doubleValue() <= 0) {
+ .subtract(new BigDecimal(wkOrderItem.getWorkQty().toString()));
+ if (issued.compareTo(ISSUED_TOLERANCE) <= 0) {
continue;
}
List<LocItem> locItems = new ArrayList<>();
@@ -697,47 +704,54 @@
for (LocItem locItem : locItems) {
Loc loc = locService.getById(locItem.getLocId());
List<LocItem> itemList = locItemService.list(new LambdaQueryWrapper<LocItem>().eq(LocItem::getLocCode, locItem.getLocCode()));
- if (issued.doubleValue() > 0) {
- ExistDto existDto = new ExistDto().setBatch(locItem.getBatch()).setMatnr(locItem.getMatnrCode()).setLocNo(locItem.getLocCode());
- if (existDtos.add(existDto)) {
- locItem.setOutQty(issued.doubleValue() >= locItem.getAnfme() ? locItem.getAnfme() : issued.doubleValue());
- locItem.setBarcode(loc.getBarcode());
- OrderOutItemDto orderOutItemDto = new OrderOutItemDto();
- orderOutItemDto.setLocItem(locItem);
+ if (issued.compareTo(ISSUED_TOLERANCE) <= 0) {
+ break;
+ }
+ // 璇ュ簱浣嶅彲鍒嗛厤鏁伴噺锛氬彇鏈寰呭垎閰嶄笌搴撲綅搴撳瓨鐨勮緝灏忓��
+ double allocatable = Math.min(issued.doubleValue(), locItem.getAnfme() != null ? locItem.getAnfme() : 0);
+ ExistDto existDto = new ExistDto().setBatch(locItem.getBatch()).setMatnr(locItem.getMatnrCode()).setLocNo(locItem.getLocCode());
+ if (existDtos.add(existDto)) {
+ // 棣栨浣跨敤璇ュ簱浣嶏細鍔犲叆鍒楄〃骞舵墸鍑� issued
+ locItem.setOutQty(allocatable);
+ locItem.setBarcode(loc.getBarcode());
+ OrderOutItemDto orderOutItemDto = new OrderOutItemDto();
+ orderOutItemDto.setLocItem(locItem);
- List<DeviceSite> deviceSites = deviceSiteService.list(new LambdaQueryWrapper<DeviceSite>()
- .eq(DeviceSite::getChannel, loc.getChannel())
- .eq(DeviceSite::getType, issued.doubleValue() >= locItem.getAnfme() && itemList.size() == 1 ? TaskType.TASK_TYPE_OUT.type : TaskType.TASK_TYPE_PICK_AGAIN_OUT.type)
- );
+ List<DeviceSite> deviceSites = deviceSiteService.list(new LambdaQueryWrapper<DeviceSite>()
+ .eq(DeviceSite::getChannel, loc.getChannel())
+ .eq(DeviceSite::getType, issued.doubleValue() >= locItem.getAnfme() && itemList.size() == 1 ? TaskType.TASK_TYPE_OUT.type : TaskType.TASK_TYPE_PICK_AGAIN_OUT.type)
+ );
- if (!deviceSites.isEmpty()) {
- List<OrderOutItemDto.staListDto> maps = new ArrayList<>();
- for (DeviceSite sta : deviceSites) {
- OrderOutItemDto.staListDto staListDto = new OrderOutItemDto.staListDto();
- staListDto.setStaNo(sta.getSite());
- staListDto.setStaName(sta.getSite());
- maps.add(staListDto);
- }
- orderOutItemDto.setStaNos(maps);
- //榛樿鑾峰彇绗竴绔欑偣
- DeviceSite deviceSite = deviceSites.stream().findFirst().get();
- orderOutItemDto.setSiteNo(deviceSite.getSite());
+ if (!deviceSites.isEmpty()) {
+ List<OrderOutItemDto.staListDto> maps = new ArrayList<>();
+ for (DeviceSite sta : deviceSites) {
+ OrderOutItemDto.staListDto staListDto = new OrderOutItemDto.staListDto();
+ staListDto.setStaNo(sta.getSite());
+ staListDto.setStaName(sta.getSite());
+ maps.add(staListDto);
}
-
- list.add(orderOutItemDto);
-
- issued = issued.subtract(new BigDecimal(locItem.getAnfme().toString()));
+ orderOutItemDto.setStaNos(maps);
+ //榛樿鑾峰彇绗竴绔欑偣
+ DeviceSite deviceSite = deviceSites.stream().findFirst().get();
+ orderOutItemDto.setSiteNo(deviceSite.getSite());
}
+
+ list.add(orderOutItemDto);
+ issued = issued.subtract(new BigDecimal(locItem.getAnfme().toString()));
+ } else {
+ // 璇ュ簱浣嶅凡琚墠搴忚鍗曡鍗犵敤锛氬彧鎵e噺 issued锛屼笉閲嶅鍔犲叆鍒楄〃锛岄伩鍏嶄骇鐢熲�滃簱瀛樹笉瓒斥�濊剰鏁版嵁
+ issued = issued.subtract(new BigDecimal(String.valueOf(allocatable)));
}
}
- if (issued.doubleValue() > 0) {
+ if (issued.compareTo(ISSUED_TOLERANCE) > 0) {
+ double remaining = issued.setScale(6, RoundingMode.HALF_UP).doubleValue();
LocItem locItem = new LocItem()
.setId(new Random().nextLong())
.setMatnrCode(wkOrderItem.getMatnrCode())
.setMaktx(wkOrderItem.getMaktx())
.setAnfme(0.00)
- .setWorkQty(issued.doubleValue())
- .setOutQty(issued.doubleValue())
+ .setWorkQty(remaining)
+ .setOutQty(remaining)
.setUnit(wkOrderItem.getStockUnit())
.setBatch(wkOrderItem.getSplrBatch());
OrderOutItemDto orderOutItemDto = new OrderOutItemDto();
--
Gitblit v1.9.1