From 9d15441ad6bcbd90f61624702f6acd285646fd9b Mon Sep 17 00:00:00 2001 From: xiaofajia <1665375861@qq.com> Date: Thu, 21 Nov 2024 11:11:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=B7=BB=E5=8A=A0=E9=85=8D?= =?UTF-8?q?=E4=BB=B6=E5=88=B0=E9=85=8D=E4=BB=B6=E7=94=B3=E8=AF=B7=E5=8D=95?= =?UTF-8?q?=E4=B8=AD=E5=87=BA=E7=8E=B0=E9=87=8D=E5=A4=8D=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/DlTwItemServiceImpl.java | 69 +++++++++++++++---- 1 file changed, 56 insertions(+), 13 deletions(-) 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 ca30ae54..2fcf23b8 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 @@ -14,6 +14,7 @@ import cn.iocoder.yudao.module.tickets.vo.AddTwiVO; import cn.iocoder.yudao.module.tickets.vo.AppWaresGroupVO; import cn.iocoder.yudao.module.tickets.vo.DlTwItemReqVO; import cn.iocoder.yudao.module.tickets.vo.DlTwItemRespVO; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.apache.commons.lang3.StringUtils; import org.springframework.context.annotation.Lazy; @@ -104,19 +105,61 @@ public class DlTwItemServiceImpl extends ServiceImpl if (CollectionUtil.isEmpty(addTwiVO.getItems())){ throw exception0(500, "请选择配件"); } - 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.setWaresAlreadyCount(0); - twItem.setWaresStatus(""); - twItem.setRemark(item.getRemark()); - return twItem; - }).collect(Collectors.toList()); - // 新增 - baseMapper.insert(twItems); + // 查出该配件申请单已有的所有配件,这里只取没有审核过(通过、驳回的不要,同一个配件如果已经审核过了又添加,还是算新的) + 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.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()); + twItem.setWaresName(item.getName()); + twItem.setWaresCount(item.getCount()); + twItem.setWaresAlreadyCount(0); + twItem.setWaresStatus(""); + twItem.setRemark(item.getRemark()); + return twItem; + }).collect(Collectors.toList()); + // 新增 + baseMapper.insert(twItems); + } } /**