From a372a11167f095bd70d1070d70ec36af56489898 Mon Sep 17 00:00:00 2001
From: skyouc
Date: 星期五, 18 四月 2025 17:56:58 +0800
Subject: [PATCH] 人工上架任务修改
---
rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/WaitPakinServiceImpl.java | 186 ++++++++++++++++++++++++++++++----------------
1 files changed, 121 insertions(+), 65 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 70ce7d0..41f21f6 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
@@ -1,7 +1,7 @@
package com.vincent.rsf.server.manager.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.vincent.rsf.framework.exception.CoolException;
import com.vincent.rsf.server.manager.controller.params.PakinItem;
import com.vincent.rsf.server.manager.controller.params.WaitPakinParam;
@@ -13,15 +13,12 @@
import com.vincent.rsf.server.system.constant.SerialRuleCode;
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.security.core.parameters.P;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
+import java.util.*;
import java.util.stream.Collectors;
@Service("waitPakinService")
@@ -37,100 +34,159 @@
@Autowired
private WaitPakinItemService waitPakinItemService;
@Autowired
+ private WarehouseAreasItemService warehouseAreasItemService;
+ @Autowired
private LocService locService;
/**
+ * @param
+ * @param userId
+ * @return
* @author Ryan
* @description 缁勬嫋
- * @param
- * @return
* @time 2025/3/29 14:42
*/
@Override
@Transactional(rollbackFor = Exception.class)
- public WaitPakin mergeItems(WaitPakinParam waitPakin) {
- if (waitPakin.getItems().isEmpty()) {
+ public WaitPakin mergeItems(WaitPakinParam waitPakin, Long userId) {
+ if (Objects.isNull(waitPakin.getItems()) || waitPakin.getItems().isEmpty()) {
throw new CoolException("鍙傛暟閿欒锛氱墿鏂欒窡韪爜涓虹┖锛�");
}
if (StringUtils.isBlank(waitPakin.getBarcode())) {
throw new CoolException("鍙傛暟閿欒锛氭墭鐩樼爜涓虹┖锛侊紒");
}
-
- List<WaitPakin> list = waitPakinService.list(new LambdaQueryWrapper<WaitPakin>().eq(WaitPakin::getBarcode, waitPakin.getBarcode()));
- if (!list.isEmpty()) {
- List<String> stringList = list.stream().map(WaitPakin::getCode).collect(Collectors.toList());
- String join = StringUtils.join(stringList, ",");
- throw new CoolException("鎷栫洏鐮侊細" + waitPakin.getBarcode() + "宸茶缁勬嫋鍗曪細" + join + "浣跨敤锛侊紒");
+ List<Short> asList = Arrays.asList(Short.valueOf(PakinIOStatus.PAKIN_IO_STATUS_DONE.val), Short.valueOf(PakinIOStatus.PAKIN_IO_STATUS_DONE.val));
+ WaitPakin list = waitPakinService.getOne(new LambdaQueryWrapper<WaitPakin>()
+ .notIn(WaitPakin::getIoStatus, asList)
+ .eq(WaitPakin::getBarcode, waitPakin.getBarcode()));
+ if (!Objects.isNull(list)) {
+ throw new CoolException("鎷栫洏鐮侊細" + waitPakin.getBarcode() + "宸茶缁勬嫋鍗曪細" + list.getCode() + "浣跨敤锛侊紒");
}
-
List<Loc> locs = locService.list(new LambdaQueryWrapper<Loc>().eq(Loc::getBarcode, waitPakin.getBarcode()));
if (!locs.isEmpty()) {
List<String> locCodes = locs.stream().map(Loc::getCode).collect(Collectors.toList());
String join = StringUtils.join(locCodes, ",");
throw new CoolException("鎷栫洏鐮侊細" + waitPakin.getBarcode() + "宸茶搴撲綅锛�" + join + "浣跨敤锛侊紒");
}
-
double sum = waitPakin.getItems().stream().mapToDouble(PakinItem::getReceiptQty).sum();
- WaitPakin pakin = new WaitPakin();
-
- String ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_WAIT_PAKIN_CODE, null);
- if (StringUtils.isBlank(ruleCode)) {
- throw new CoolException("缂栫爜瑙勫垯閿欒锛� 缂栫爜瑙勫垯銆孲YS_WAIT_PAKIN_CODE銆嶈鍒欐槸涓嶅瓨鍦�");
+ WaitPakin waitPakin1 = new WaitPakin();
+ WaitPakin pakin = waitPakinService.getOne(new LambdaQueryWrapper<WaitPakin>()
+ .in(WaitPakin::getIoStatus, asList)
+ .eq(WaitPakin::getBarcode, waitPakin.getBarcode()));
+ if (Objects.isNull(pakin)) {
+ 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(Short.parseShort(PakinIOStatus.PAKIN_IO_STATUS_DONE.val))
+ .setAnfme(sum)
+ .setUpdateBy(userId)
+ .setCreateBy(userId)
+ .setBarcode(waitPakin.getBarcode());
+ if (!this.save(waitPakin1)) {
+ throw new CoolException("涓诲崟淇濆瓨澶辫触锛侊紒");
+ }
+ } else {
+ BeanUtils.copyProperties(pakin, waitPakin1);
+ waitPakin1.setAnfme(sum);
+ if (!this.saveOrUpdate(waitPakin1)) {
+ throw new CoolException("涓诲崟淇敼澶辫触锛侊紒");
+ }
}
- pakin.setCode(ruleCode)
- //鐘舵�佷慨鏀逛负鍏ュ簱涓�
- .setIoStatus(Short.parseShort(PakinIOStatus.QLY_ISPT_STAS_DONE.val))
- .setAnfme(sum)
- .setBarcode(waitPakin.getBarcode());
- if (!this.save(pakin)) {
- throw new CoolException("涓诲崟淇濆瓨澶辫触锛侊紒");
- }
-
/**鐗╂枡璺熻釜鐮�*/
List<String> tracks = waitPakin.getItems().stream().map(PakinItem::getTrackCode).collect(Collectors.toList());
-
- List<AsnOrderItem> asnOrderItems = asnOrderItemService.list(new LambdaQueryWrapper<AsnOrderItem>()
- .in(AsnOrderItem::getTrackCode, tracks));
- if (Objects.isNull(asnOrderItems) || asnOrderItems.isEmpty()) {
- throw new CoolException("鍗曟嵁涓嶅瓨鍦紒锛�");
+ List<WaitPakinItem> pakinItems = waitPakinItemService.list(new LambdaQueryWrapper<WaitPakinItem>()
+ .eq(WaitPakinItem::getPakinId, waitPakin1.getId())
+ .in(WaitPakinItem::getTrackCode, tracks));
+ if (!pakinItems.isEmpty()) {
+ if (!waitPakinItemService.remove(new LambdaQueryWrapper<WaitPakinItem>()
+ .eq(WaitPakinItem::getPakinId, waitPakin1.getId())
+ .in(WaitPakinItem::getTrackCode, tracks))) {
+ throw new CoolException("鍘熷崟鎹竻闄ゅけ璐ワ紒锛�");
+ }
}
-
List<WaitPakinItem> items = new ArrayList<>();
- for (AsnOrderItem item : asnOrderItems) {
- WaitPakinItem pakinItem = new WaitPakinItem();
- pakinItem.setAnfme(item.getAnfme())
- .setPakinId(pakin.getId())
- .setAsnId(item.getAsnId())
- .setAsnCode(item.getAsnCode())
- .setAsnItemId(item.getId())
- .setMatnrCode(item.getMatnrCode())
- .setBatch(item.getSplrBatch())
- .setUnit(item.getStockUnit())
- .setFieldsIndex(item.getFieldsIndex())
- .setUnit(item.getStockUnit())
- .setMatnrId(item.getMatnrId())
- .setMaktx(item.getMaktx())
- .setMatnrCode(item.getMatnrCode());
- for (PakinItem waitPakinItem : waitPakin.getItems()) {
- if (waitPakinItem.getTrackCode().equals(item.getTrackCode())) {
- Double v = item.getWorkQty() + waitPakinItem.getReceiptQty();
- pakinItem.setWorkQty(v)
- .setAnfme(waitPakinItem.getReceiptQty())
- .setTrackCode(waitPakinItem.getTrackCode());
- /**鏇存柊鍗曟嵁鎵ц涓簱瀛�*/
- if (v.compareTo(item.getAnfme()) > 0) {throw new CoolException("鎵ц涓暟閲忓ぇ浜庢敹璐ф暟閲忥紒锛�");}
- if (!asnOrderItemService.update(new LambdaUpdateWrapper<AsnOrderItem>()
- .eq(AsnOrderItem::getTrackCode, waitPakinItem.getTrackCode()).set(AsnOrderItem::getWorkQty, v))) {
- throw new CoolException("鎵ц涓簱瀛樻洿鏂板け璐ワ紒锛�");
+ if (!Objects.isNull(waitPakin.getType()) && waitPakin.getType().equals("defective")) {
+ List<AsnOrderItem> orderItems = asnOrderItemService.list(new LambdaQueryWrapper<AsnOrderItem>().in(AsnOrderItem::getTrackCode, tracks));
+ if (Objects.isNull(orderItems) || orderItems.isEmpty()) {
+ throw new CoolException("鍗曟嵁涓嶅瓨鍦紒锛�");
+ }
+ for (AsnOrderItem item : orderItems) {
+ WaitPakinItem pakinItem = new WaitPakinItem();
+ pakinItem.setAnfme(item.getAnfme())
+ .setPakinId(waitPakin1.getId())
+ .setAsnId(item.getAsnId())
+ .setAsnCode(item.getAsnCode())
+ .setAsnItemId(item.getId())
+ .setBatch(item.getSplrBatch())
+ .setUnit(item.getStockUnit())
+ .setFieldsIndex(item.getFieldsIndex())
+ .setMatnrId(item.getMatnrId())
+ .setMaktx(item.getMaktx())
+ .setUpdateBy(userId)
+ .setCreateBy(userId)
+ .setMatnrCode(item.getMatnrCode());
+ for (PakinItem waitPakinItem : waitPakin.getItems()) {
+ if (waitPakinItem.getTrackCode().equals(item.getTrackCode())) {
+ if (waitPakinItem.getReceiptQty() > item.getAnfme() || waitPakinItem.getReceiptQty().compareTo(0.0) >= 0) {
+ throw new CoolException("缁勬嫋鏁伴噺涓嶈兘澶т簬鏀惰揣鏁伴噺锛侊紒");
+ }
+ pakinItem.setAnfme(waitPakinItem.getReceiptQty()).setTrackCode(waitPakinItem.getTrackCode());
}
}
+ items.add(pakinItem);
}
- items.add(pakinItem);
+ } else {
+ LambdaQueryWrapper<WarehouseAreasItem> queryWrapper = new QueryWrapper<WarehouseAreasItem>()
+ .select("SUM(anfme) as anfme, track_code, asn_code, id, splr_batch, ispt_result, plat_item_id, batch, qty, work_qty, matnr_code, matnr_id, maktx")
+ .lambda()
+ .in(WarehouseAreasItem::getTrackCode, tracks)
+ .groupBy(WarehouseAreasItem::getSplrBatch,
+ WarehouseAreasItem::getTrackCode);
+ List<WarehouseAreasItem> warehouseAreasItems = warehouseAreasItemService.list(queryWrapper);
+ if (Objects.isNull(warehouseAreasItems) || warehouseAreasItems.isEmpty()) {
+ throw new CoolException("鐗╂枡鏈�佽嚦鏀惰揣鍖猴紒锛�");
+ }
+ for (WarehouseAreasItem item : warehouseAreasItems) {
+ WaitPakinItem pakinItem = new WaitPakinItem();
+ pakinItem.setAnfme(item.getAnfme())
+ .setPakinId(waitPakin1.getId())
+ .setAsnId(item.getAsnId())
+ .setAsnCode(item.getAsnCode())
+ .setAsnItemId(item.getId())
+ .setBatch(item.getSplrBatch())
+ .setUnit(item.getStockUnit())
+ .setFieldsIndex(item.getFieldsIndex())
+ .setMatnrId(item.getMatnrId())
+ .setMaktx(item.getMaktx())
+ .setUpdateBy(userId)
+ .setCreateBy(userId)
+ .setMatnrCode(item.getMatnrCode());
+ for (PakinItem waitPakinItem : waitPakin.getItems()) {
+ if (waitPakinItem.getTrackCode().equals(item.getTrackCode())) {
+ if (waitPakinItem.getReceiptQty() > item.getAnfme() || waitPakinItem.getReceiptQty().compareTo(0.0) <= 0) {
+ throw new CoolException("缁勬嫋鏁伴噺涓嶈兘澶т簬鏀惰揣鏁伴噺涓斾笉鑳藉皬浜庨浂锛侊紒");
+ }
+ pakinItem.setAnfme(waitPakinItem.getReceiptQty()).setTrackCode(waitPakinItem.getTrackCode());
+ }
+ }
+ items.add(pakinItem);
+ }
}
+ double sum1 = items.stream().mapToDouble(WaitPakinItem::getAnfme).sum();
if (!waitPakinItemService.saveBatch(items)) {
throw new CoolException("缁勬嫋鏄庣粏淇濆瓨澶辫触锛侊紒");
}
+ waitPakin1.setAnfme(sum1);
+ if (!this.updateById(waitPakin1)) {
+ throw new CoolException("缁勬嫋鏁伴噺淇敼澶辫触锛侊紒");
+ }
+
+ //TODO 缁勬嫋瀹屾垚鍚庯紝鎵e噺鏀惰揣鍖哄簱瀛�
+
return pakin;
}
--
Gitblit v1.9.1