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

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.AppWaresGroupVO;
import cn.iocoder.yudao.module.tickets.vo.DlTwItemReqVO; import cn.iocoder.yudao.module.tickets.vo.DlTwItemReqVO;
import cn.iocoder.yudao.module.tickets.vo.DlTwItemRespVO; 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 com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
@ -104,19 +105,61 @@ public class DlTwItemServiceImpl extends ServiceImpl<DlTwItemMapper, DlTwItem>
if (CollectionUtil.isEmpty(addTwiVO.getItems())){ if (CollectionUtil.isEmpty(addTwiVO.getItems())){
throw exception0(500, "请选择配件"); throw exception0(500, "请选择配件");
} }
List<DlTwItem> twItems = addTwiVO.getItems().stream().map(item -> { // 查出该配件申请单已有的所有配件这里只取没有审核过通过驳回的不要同一个配件如果已经审核过了又添加还是算新的
DlTwItem twItem = new DlTwItem(); List<DlTwItem> oldData = baseMapper.selectList(new LambdaQueryWrapper<DlTwItem>().and(i -> {
twItem.setTwId(addTwiVO.getId()); i.in(DlTwItem::getTwId, addTwiVO.getId())
twItem.setWaresId(item.getId()); .eq(DlTwItem::getWaresStatus, "");
twItem.setWaresName(item.getName()); }));
twItem.setWaresCount(item.getCount()); if (CollectionUtil.isNotEmpty(oldData)){
twItem.setWaresAlreadyCount(0); // 取配件ID
twItem.setWaresStatus(""); List<String> ids = oldData.stream().map(DlTwItem::getWaresId).collect(Collectors.toList());
twItem.setRemark(item.getRemark()); // 过滤添加的
return twItem; List<AddTwiVO.AddTwiVoItem> add = addTwiVO.getItems().stream().filter(item -> !ids.contains(item.getId())).collect(Collectors.toList());
}).collect(Collectors.toList()); // 过滤存在的
// 新增 List<AddTwiVO.AddTwiVoItem> update = addTwiVO.getItems().stream().filter(item -> ids.contains(item.getId())).collect(Collectors.toList());
baseMapper.insert(twItems); // 添加
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());
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);
}
} }
/** /**