修改添加配件到配件申请单中出现重复问题

This commit is contained in:
xiaofajia 2024-11-21 11:11:28 +08:00
parent 977fb20920
commit 9d15441ad6

View File

@ -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,6 +105,47 @@ public class DlTwItemServiceImpl extends ServiceImpl<DlTwItemMapper, DlTwItem>
if (CollectionUtil.isEmpty(addTwiVO.getItems())){
throw exception0(500, "请选择配件");
}
// 查出该配件申请单已有的所有配件这里只取没有审核过通过驳回的不要同一个配件如果已经审核过了又添加还是算新的
List<DlTwItem> oldData = baseMapper.selectList(new LambdaQueryWrapper<DlTwItem>().and(i -> {
i.in(DlTwItem::getTwId, addTwiVO.getId())
.eq(DlTwItem::getWaresStatus, "");
}));
if (CollectionUtil.isNotEmpty(oldData)){
// 取配件ID
List<String> ids = oldData.stream().map(DlTwItem::getWaresId).collect(Collectors.toList());
// 过滤添加的
List<AddTwiVO.AddTwiVoItem> add = addTwiVO.getItems().stream().filter(item -> !ids.contains(item.getId())).collect(Collectors.toList());
// 过滤存在的
List<AddTwiVO.AddTwiVoItem> update = addTwiVO.getItems().stream().filter(item -> ids.contains(item.getId())).collect(Collectors.toList());
// 添加
if (CollectionUtil.isNotEmpty(add)){
List<DlTwItem> 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<DlTwItem> 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<DlTwItem> twItems = addTwiVO.getItems().stream().map(item -> {
DlTwItem twItem = new DlTwItem();
twItem.setTwId(addTwiVO.getId());
@ -118,6 +160,7 @@ public class DlTwItemServiceImpl extends ServiceImpl<DlTwItemMapper, DlTwItem>
// 新增
baseMapper.insert(twItems);
}
}
/**
* APP查询配件申请单列表-按配件分类进行分组