From 5f13213af588444a59d0b3725f3d028cbdaffca4 Mon Sep 17 00:00:00 2001 From: skyouc Date: 星期三, 07 五月 2025 15:46:22 +0800 Subject: [PATCH] 完成任务优化 删除组托优化 --- rsf-server/src/main/java/com/vincent/rsf/server/manager/service/impl/WaitPakinServiceImpl.java | 128 +++++++++++++++++++++++++++++------------- 1 files changed, 87 insertions(+), 41 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 0254d22..28d32d7 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 @@ -4,6 +4,7 @@ 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.controller.params.PakinItem; import com.vincent.rsf.server.manager.controller.params.WaitPakinParam; @@ -39,6 +40,10 @@ private WarehouseAreasItemService warehouseAreasItemService; @Autowired private LocService locService; + @Autowired + private TaskService taskService; + @Autowired + private TaskItemService taskItemService; /** @@ -59,11 +64,11 @@ throw new CoolException("鍙傛暟閿欒锛氭墭鐩樼爜涓虹┖锛侊紒"); } 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>() + WaitPakin pakin = 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() + "浣跨敤锛侊紒"); + if (!Objects.isNull(pakin)) { + throw new CoolException("鎵樼洏鐮侊細" + waitPakin.getBarcode() + "宸茶缁勬墭鍗曪細" + pakin.getCode() + "浣跨敤锛侊紒"); } List<Loc> locs = locService.list(new LambdaQueryWrapper<Loc>().eq(Loc::getBarcode, waitPakin.getBarcode())); if (!locs.isEmpty()) { @@ -74,43 +79,31 @@ double sum = waitPakin.getItems().stream().mapToDouble(PakinItem::getReceiptQty).sum(); 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("涓诲崟淇敼澶辫触锛侊紒"); - } + String ruleCode = SerialRuleUtils.generateRuleCode(SerialRuleCode.SYS_WAIT_PAKIN_CODE, null); + if (StringUtils.isBlank(ruleCode)) { + throw new CoolException("缂栫爜瑙勫垯閿欒锛� 缂栫爜瑙勫垯銆孲YS_WAIT_PAKIN_CODE銆嶈鍒欐槸涓嶅瓨鍦�"); } - /**鐗╂枡璺熻釜鐮�*/ - - List<WaitPakinItem> pakinItems = waitPakinItemService.list(new LambdaQueryWrapper<WaitPakinItem>() - .eq(WaitPakinItem::getPakinId, waitPakin1.getId())) - ; - if (!pakinItems.isEmpty()) { - if (!waitPakinItemService.remove(new LambdaQueryWrapper<WaitPakinItem>() - .eq(WaitPakinItem::getPakinId, waitPakin1.getId()) - )) { - throw new CoolException("鍘熷崟鎹竻闄ゅけ璐ワ紒锛�"); - } + 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("涓诲崟淇濆瓨澶辫触锛侊紒"); } +// /**鐗╂枡璺熻釜鐮�*/ +// List<WaitPakinItem> pakinItems = waitPakinItemService.list(new LambdaQueryWrapper<WaitPakinItem>() +// .eq(WaitPakinItem::getPakinId, waitPakin1.getId())) +// ; +// if (!pakinItems.isEmpty()) { +// if (!waitPakinItemService.remove(new LambdaQueryWrapper<WaitPakinItem>() +// .eq(WaitPakinItem::getPakinId, waitPakin1.getId()) +// )) { +// throw new CoolException("鍘熷崟鎹竻闄ゅけ璐ワ紒锛�"); +// } +// } List<WaitPakinItem> items = new ArrayList<>(); for (PakinItem pakinItem1 : waitPakin.getItems()) { //涓嶈壇鏍囩缁勬墭 @@ -157,6 +150,7 @@ WaitPakinItem pakinItem = new WaitPakinItem(); pakinItem.setAnfme(warehouseAreasItems.getAnfme()) .setPakinId(waitPakin1.getId()) + .setSource(warehouseAreasItems.getId()) .setAsnId(warehouseAreasItems.getAsnId()) .setAsnCode(warehouseAreasItems.getAsnCode()) .setAsnItemId(warehouseAreasItems.getId()) @@ -199,7 +193,8 @@ if (Objects.isNull(one)) { throw new CoolException("鏀惰揣鍖烘暟鎹敊璇紒锛�"); } - one.setWorkQty(one.getWorkQty() + pakinItem.getAnfme() + one.getQty()) ; + one.setAnfme(one.getAnfme() - pakinItem.getAnfme()) + .setWorkQty(one.getWorkQty() + pakinItem.getAnfme() + one.getQty()) ; if (one.getWorkQty() > one.getAnfme()) { throw new CoolException("缁勬墭鏁伴噺涓嶈兘澶т簬鏀惰揣鏁伴噺锛侊紒"); } @@ -207,8 +202,6 @@ throw new CoolException("鏀惰揣鍖烘墽琛屾暟閲忎慨鏀瑰け璐ワ紒锛�"); } } - - waitPakin1.setAnfme(sum1); if (!this.updateById(waitPakin1)) { @@ -255,4 +248,57 @@ } return new WaitPakin(); } + + /** + * @author Ryan + * @date 2025/5/7 + * @description: 鍒犻櫎缁勬嫋淇℃伅 + * @version 1.0 + */ + @Override + @Transactional(rollbackFor = Exception.class) + public R removePakin(List<Long> pakinIds) { + List<WaitPakinItem> pakinItems = waitPakinItemService.list(new LambdaQueryWrapper<WaitPakinItem>() + .in(WaitPakinItem::getPakinId, pakinIds)); + if (!pakinItems.isEmpty()) { + List<Long> list = pakinItems.stream().map(WaitPakinItem::getId).collect(Collectors.toList()); + List<TaskItem> taskItems = taskItemService.list(new LambdaQueryWrapper<TaskItem>().in(TaskItem::getSource, list)); + if (!taskItems.isEmpty()) { + return R.error("缁勬嫋妗f湁鏄庣粏浠诲姟"); + } + } + + Set<Long> sourceIds = pakinItems.stream().map(WaitPakinItem::getSource).collect(Collectors.toSet()); + + List<WarehouseAreasItem> areasItems = warehouseAreasItemService.listByIds(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(); + item.setWorkQty(item.getWorkQty() - sum) + .setAnfme(item.getAnfme() + sum); + if (!warehouseAreasItemService.updateById(item)) { + throw new CoolException("鏀惰揣鍖烘暟鎹洖婊氬け璐ワ紒锛�"); + } + } + + if (!waitPakinService.removeByIds(pakinIds)) { + return R.error("Delete Fail"); + } + + Set<Long> pakinItemIds = pakinItems.stream().map(WaitPakinItem::getId).collect(Collectors.toSet()); + + if (!waitPakinItemService.removeByIds(pakinItemIds)) { + throw new CoolException("鏄庣粏鍒犻櫎澶辫触锛侊紒"); + } + return R.ok("Delete Success").add(pakinIds); + + + } } -- Gitblit v1.9.1