From 070534b2c236985276747d2190b13f899c23c8fa Mon Sep 17 00:00:00 2001 From: Vinjor Date: Wed, 4 Dec 2024 14:52:12 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=9A=E7=9F=A5=E9=A2=86=E6=96=99=E9=80=80?= =?UTF-8?q?=E6=96=99=E9=80=BB=E8=BE=91=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/DlRepairSoServiceImpl.java | 110 ++++++++++++++++- .../service/impl/DlTwItemServiceImpl.java | 111 +++++++++++------- .../yudao/module/tickets/vo/AddTwiVO.java | 4 + .../mapper/tickets/DlTwItemMapper.xml | 6 + 4 files changed, 182 insertions(+), 49 deletions(-) diff --git a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/stockOperate/service/impl/DlRepairSoServiceImpl.java b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/stockOperate/service/impl/DlRepairSoServiceImpl.java index 94e42894..eb1de94e 100644 --- a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/stockOperate/service/impl/DlRepairSoServiceImpl.java +++ b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/stockOperate/service/impl/DlRepairSoServiceImpl.java @@ -3,10 +3,7 @@ package cn.iocoder.yudao.module.stockOperate.service.impl; import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.ObjectUtil; -import cn.iocoder.yudao.common.RecordTypeEnum; -import cn.iocoder.yudao.common.RepairErrorCodeConstants; -import cn.iocoder.yudao.common.RepairRoleEnum; -import cn.iocoder.yudao.common.SoStatusEnum; +import cn.iocoder.yudao.common.*; import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; import cn.iocoder.yudao.module.base.service.RepairRecordsService; import cn.iocoder.yudao.module.base.service.RepairWorkerService; @@ -21,13 +18,13 @@ import cn.iocoder.yudao.module.stockOperate.service.DlRepairSoService; import cn.iocoder.yudao.module.stockOperate.service.DlRepairSoiService; import cn.iocoder.yudao.module.stockOperate.vo.DlRepairSoReqVO; import cn.iocoder.yudao.module.stockOperate.vo.DlRepairSoRespVO; -import cn.iocoder.yudao.module.stockOperate.vo.DlRepairSoiReqVO; import cn.iocoder.yudao.module.stockOperate.vo.DlRepairSoiRespVO; import cn.iocoder.yudao.module.supplier.service.BaseSupplierService; import cn.iocoder.yudao.module.system.api.dept.DeptApi; import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO; import cn.iocoder.yudao.module.system.api.user.AdminUserApi; import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; +import cn.iocoder.yudao.module.tickets.entity.DlRepairTitem; import cn.iocoder.yudao.module.tickets.entity.DlTicketWares; import cn.iocoder.yudao.module.tickets.entity.DlTwItem; import cn.iocoder.yudao.module.tickets.service.DlRepairTicketsService; @@ -333,7 +330,9 @@ public class DlRepairSoServiceImpl extends ServiceImpl sois = repairSoiService.list(new LambdaQueryWrapper().eq(DlRepairSoi::getSoId, id)); + //本次领料的配件id Set waresIds = sois.stream().map(DlRepairSoi::getGoodsId).collect(Collectors.toSet()); + //配件库的数据集合 List repairWares = repairWaresService.listByIds(waresIds); List list = sois.stream().map(item -> { DlRepairSoiRespVO bean = BeanUtil.toBean(item, DlRepairSoiRespVO.class); @@ -341,6 +340,10 @@ public class DlRepairSoServiceImpl extends ServiceImpl sois,List repairWares){ + //配件申请单 + DlTicketWares dlTicketWares = ticketWaresService.getById(applyId); + //工单现有的配件 + List titems = titemService.list(new LambdaQueryWrapper().and(i -> { + i.eq(DlRepairTitem::getTicketId,dlTicketWares.getTicketId()) + .eq(DlRepairTitem::getItemType, "02"); + })); + //更新或插入的数据集合 + List saveOrUpdateList = new ArrayList<>(); + //删除的数据id集合 + List delIdList = new ArrayList<>(); + //工单现有配件转MAP + Map itemMap = titems.stream().collect(Collectors.toMap(DlRepairTitem::getPartId,Function.identity())); + //配件库的数据集合转MAP + Map repairWaresMap = repairWares.stream().collect(Collectors.toMap(RepairWares::getId,Function.identity())); + //遍历本次领料/退料的所有配件 + for (DlRepairSoi repairSoi:sois){ + if(itemMap.containsKey(repairSoi.getGoodsId())){ + //工单中有这个配件 + if(ifGet){ + //领料 + //工单现有配件中就有这个领取的配件,需要更新这个配件的数量、价格 + DlRepairTitem item = itemMap.get(repairSoi.getGoodsId()); + item.setItemCount(item.getItemCount() + repairSoi.getGoodsCount()); + item.setItemMoney(item.getItemPrice().multiply(BigDecimal.valueOf(item.getItemCount())).multiply(item.getItemDiscount())); + item.setItemStatus(TicketsItemStatusEnum.RECEIVED.getCode()); + saveOrUpdateList.add(item); + }else{ + //退料 + //工单现有配件中就有这个领取的配件,需要更新这个配件的数量、价格 + DlRepairTitem item = itemMap.get(repairSoi.getGoodsId()); + if(item.getItemCount()>repairSoi.getGoodsCount()){ + //现有数量大于要退的数量,扣掉 + item.setItemCount(item.getItemCount() - repairSoi.getGoodsCount()); + item.setItemMoney(item.getItemPrice().multiply(BigDecimal.valueOf(item.getItemCount())).multiply(item.getItemDiscount())); + item.setItemStatus(TicketsItemStatusEnum.RECEIVED.getCode()); + saveOrUpdateList.add(item); + }else{ + //现有数量小于或等于要退的数量,直接将这个配件删掉 + delIdList.add(item.getId()); + } + } + }else{ + //工单中没有这个配件 + if (ifGet) { + //领料,需要把这个配件添加到工单子表中 + //配件库的对象 + RepairWares waresItem = repairWaresMap.get(repairSoi.getGoodsId()); + //工单子表对象 + DlRepairTitem titem = new DlRepairTitem(); + titem.setTicketId(dlTicketWares.getTicketId()); + titem.setItemType("02"); + titem.setItemName(waresItem.getName()); + titem.setItemCount(repairSoi.getGoodsCount()); + titem.setItemUnit(waresItem.getUnit()); + //优先取领配件的价格,再取配件库的价格, + BigDecimal itemPrice = null != repairSoi.getGoodsPrice() ? repairSoi.getGoodsPrice() : (null != waresItem.getPrice() ? waresItem.getPrice() : BigDecimal.ZERO); + titem.setItemPrice(itemPrice); + titem.setItemDiscount(BigDecimal.ONE); + titem.setItemMoney(titem.getItemPrice().multiply(BigDecimal.valueOf(titem.getItemCount())).multiply(titem.getItemDiscount())); + titem.setRepairIds(String.valueOf(dlTicketWares.getRepairId())); + titem.setRepairNames(dlTicketWares.getRepairName()); + titem.setSaleId(dlTicketWares.getAdviserId()); + titem.setSaleName(dlTicketWares.getAdviserName()); + titem.setPartId(repairSoi.getGoodsId()); + titem.setItemStatus(TicketsItemStatusEnum.RECEIVED.getCode()); + saveOrUpdateList.add(titem); + }else{ + //退料,不可能出现,没领料就退料的情况,不用处理 + } + } + } + if(!saveOrUpdateList.isEmpty()){ + titemService.saveOrUpdateBatch(saveOrUpdateList); + } + if(!delIdList.isEmpty()){ + titemService.removeBatchByIds(delIdList); + } + //重新计算工单的价格和订单的价格 + ticketsService.computeTicket(dlTicketWares.getTicketId()); + } + /** * 采购入库 * diff --git a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/service/impl/DlTwItemServiceImpl.java b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/service/impl/DlTwItemServiceImpl.java index db87ca04..88970f62 100644 --- a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/service/impl/DlTwItemServiceImpl.java +++ b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/service/impl/DlTwItemServiceImpl.java @@ -108,21 +108,73 @@ public class DlTwItemServiceImpl extends ServiceImpl if (CollectionUtil.isEmpty(addTwiVO.getItems())){ throw exception0(500, "请选择配件"); } - // 查出该配件申请单已有的所有配件,这里只取没有审核过(通过、驳回的不要,同一个配件如果已经审核过了又添加,还是算新的) - List oldData = baseMapper.selectList(new LambdaQueryWrapper().and(i -> { - i.in(DlTwItem::getTwId, addTwiVO.getId()) - .eq(DlTwItem::getWaresStatus, ""); - })); - if (CollectionUtil.isNotEmpty(oldData)){ - // 取配件ID - List ids = oldData.stream().map(DlTwItem::getWaresId).collect(Collectors.toList()); - // 过滤添加的 - List add = addTwiVO.getItems().stream().filter(item -> !ids.contains(item.getId())).collect(Collectors.toList()); - // 过滤存在的 - List update = addTwiVO.getItems().stream().filter(item -> ids.contains(item.getId())).collect(Collectors.toList()); - // 添加 - if (CollectionUtil.isNotEmpty(add)){ - List twItems = add.stream().map(item -> { + if(addTwiVO.getIfHouseAdd()){ + //仓管添加 + List twItems = addTwiVO.getItems().stream().map(item -> { + DlTwItem twItem = new DlTwItem(); + twItem.setTwId(addTwiVO.getId()); + twItem.setWaresId(item.getId()); + twItem.setWaresName(item.getName()); + twItem.setWaresCount(item.getCount()); + twItem.setAddUserId(loginUser.getId()); + twItem.setAddUserName(loginUser.getInfo().get("nickname")); + twItem.setIfHouseAdd(true); + twItem.setWaresAlreadyCount(0); + twItem.setWaresStatus("1"); + twItem.setHandleId(loginUser.getId()); + twItem.setHandleName(loginUser.getInfo().get("nickname")); + twItem.setRemark(item.getRemark()); + return twItem; + }).collect(Collectors.toList()); + // 新增 + baseMapper.insert(twItems); + }else{ + //服务顾问添加 + // 查出该配件申请单已有的所有配件,这里只取没有审核过(通过、驳回的不要,同一个配件如果已经审核过了又添加,还是算新的) + List oldData = baseMapper.selectList(new LambdaQueryWrapper().and(i -> { + i.in(DlTwItem::getTwId, addTwiVO.getId()) + .eq(DlTwItem::getWaresStatus, ""); + })); + if (CollectionUtil.isNotEmpty(oldData)){ + // 取配件ID + List ids = oldData.stream().map(DlTwItem::getWaresId).collect(Collectors.toList()); + // 过滤添加的 + List add = addTwiVO.getItems().stream().filter(item -> !ids.contains(item.getId())).collect(Collectors.toList()); + // 过滤存在的 + List update = addTwiVO.getItems().stream().filter(item -> ids.contains(item.getId())).collect(Collectors.toList()); + // 添加 + if (CollectionUtil.isNotEmpty(add)){ + List twItems = add.stream().map(item -> { + DlTwItem twItem = new DlTwItem(); + twItem.setTwId(addTwiVO.getId()); + twItem.setWaresId(item.getId()); + twItem.setWaresName(item.getName()); + twItem.setWaresCount(item.getCount()); + twItem.setAddUserId(loginUser.getId()); + twItem.setAddUserName(loginUser.getInfo().get("nickname")); + twItem.setIfHouseAdd(false); + twItem.setWaresAlreadyCount(0); + twItem.setWaresStatus(""); + twItem.setRemark(item.getRemark()); + return twItem; + }).collect(Collectors.toList()); + // 新增 + baseMapper.insert(twItems); + } + // 更新 + if (CollectionUtil.isNotEmpty(update)){ + List twItems = update.stream().map(item -> { + DlTwItem twItem = oldData.stream().filter(i -> i.getWaresId().equals(item.getId())).findFirst().orElse(null); + // 只更新数量,其他不变 + if (twItem != null) { + twItem.setWaresCount(twItem.getWaresCount() + item.getCount()); + } + return twItem; + }).collect(Collectors.toList()); + baseMapper.updateById(twItems); + } + }else { + List twItems = addTwiVO.getItems().stream().map(item -> { DlTwItem twItem = new DlTwItem(); twItem.setTwId(addTwiVO.getId()); twItem.setWaresId(item.getId()); @@ -139,35 +191,6 @@ public class DlTwItemServiceImpl extends ServiceImpl // 新增 baseMapper.insert(twItems); } - // 更新 - if (CollectionUtil.isNotEmpty(update)){ - List twItems = update.stream().map(item -> { - DlTwItem twItem = oldData.stream().filter(i -> i.getWaresId().equals(item.getId())).findFirst().orElse(null); - // 只更新数量,其他不变 - if (twItem != null) { - twItem.setWaresCount(twItem.getWaresCount() + item.getCount()); - } - return twItem; - }).collect(Collectors.toList()); - baseMapper.updateById(twItems); - } - }else { - List twItems = addTwiVO.getItems().stream().map(item -> { - DlTwItem twItem = new DlTwItem(); - twItem.setTwId(addTwiVO.getId()); - twItem.setWaresId(item.getId()); - twItem.setWaresName(item.getName()); - twItem.setWaresCount(item.getCount()); - twItem.setAddUserId(loginUser.getId()); - twItem.setAddUserName(loginUser.getInfo().get("nickname")); - twItem.setIfHouseAdd(false); - twItem.setWaresAlreadyCount(0); - twItem.setWaresStatus(""); - twItem.setRemark(item.getRemark()); - return twItem; - }).collect(Collectors.toList()); - // 新增 - baseMapper.insert(twItems); } } diff --git a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/vo/AddTwiVO.java b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/vo/AddTwiVO.java index ec012d54..09a09cdd 100644 --- a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/vo/AddTwiVO.java +++ b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/vo/AddTwiVO.java @@ -14,6 +14,10 @@ import java.util.List; public class AddTwiVO { private String id; + /** + * 是否仓管添加 + */ + private Boolean ifHouseAdd; private List items; diff --git a/dl-module-repair/src/main/resources/mapper/tickets/DlTwItemMapper.xml b/dl-module-repair/src/main/resources/mapper/tickets/DlTwItemMapper.xml index 1bd01b6f..41e94516 100644 --- a/dl-module-repair/src/main/resources/mapper/tickets/DlTwItemMapper.xml +++ b/dl-module-repair/src/main/resources/mapper/tickets/DlTwItemMapper.xml @@ -26,6 +26,9 @@ wares_count, wares_already_count, wares_status, + add_user_id, + add_user_name, + if_house_add, handle_id, handle_name, remark @@ -56,6 +59,9 @@ dti.wares_count, dti.wares_already_count, dti.wares_status, + dti.add_user_id, + dti.add_user_name, + dti.if_house_add, dti.handle_id, dti.handle_name, dti.update_time,