修改领料、退料逻辑

This commit is contained in:
xiaofajia 2024-10-25 22:04:18 +08:00
parent eb5f52e67d
commit a4257f3bd3
2 changed files with 261 additions and 132 deletions

View File

@ -92,6 +92,10 @@ public class DlRepairSoServiceImpl extends ServiceImpl<DlRepairSoMapper, DlRepai
@Resource
private AdminUserApi userApi;
@Resource
@Lazy
private RepairWaresService repairWaresService;
/**
* 采购单/领料单 新增
*
@ -183,6 +187,54 @@ public class DlRepairSoServiceImpl extends ServiceImpl<DlRepairSoMapper, DlRepai
boolean flag = so.getUserId().equals(loginUserId);
if (flag) {
repairWorkerService.sentMessage(Long.valueOf(so.getCreator()), (so.getSoType().equals("02") ? "领料单:" : "退料单:") + so.getSoNo() + "已被" + so.getUserName() + "作废");
// 需要更新库存和申请表数据
// 查单据子表
List<DlRepairSoi> sois = repairSoiService.list(new LambdaQueryWrapper<DlRepairSoi>().in(DlRepairSoi::getSoId, so.getId()));
// 查要操作申请表子表
List<DlTwItem> oldTwItems = twItemService.list(new LambdaQueryWrapper<DlTwItem>().and(item -> {
item.eq(DlTwItem::getTwId, so.getTwId())
.in(DlTwItem::getWaresId, sois.stream().map(DlRepairSoi::getGoodsId).collect(Collectors.toList()));
}));
// 查要操作的配件
List<RepairWares> oldWares = repairWaresService.list(new LambdaQueryWrapper<RepairWares>().in(RepairWares::getId, sois.stream().map(DlRepairSoi::getGoodsId).collect(Collectors.toList())));
// 新的申请表子表数据和配件数据
List<DlTwItem> newTwItems = new ArrayList<>();
List<RepairWares> newWares = new ArrayList<>();
// 需要区分是领料还是退料
// 得到新申请表子表数据
oldTwItems.forEach(item -> {
DlTwItem dlTwItem = new DlTwItem();
dlTwItem.setId(item.getId());
sois.stream().filter(i -> i.getGoodsId().equals(item.getWaresId())).findFirst().ifPresent(repairSoiByTwItem -> {
if (so.getSoType().equals("02")){
dlTwItem.setWaresAlreadyCount(item.getWaresAlreadyCount() - repairSoiByTwItem.getGoodsCount());
dlTwItem.setWaresCouldCount(item.getWaresCouldCount() + repairSoiByTwItem.getGoodsCount());
dlTwItem.setWaresStatus("02");
}else {
dlTwItem.setWaresAlreadyCount(item.getWaresAlreadyCount() + repairSoiByTwItem.getGoodsCount());
dlTwItem.setWaresCouldCount(item.getWaresCouldCount() - repairSoiByTwItem.getGoodsCount());
}
});
newTwItems.add(dlTwItem);
});
// 得到新配件数据
oldWares.forEach(item -> {
RepairWares wares = new RepairWares();
wares.setId(item.getId());
sois.stream().filter(i -> i.getGoodsId().equals(wares.getId())).findFirst().ifPresent(repairSoiByWares -> {
if (so.getSoType().equals("02")){
wares.setStock(item.getStock().add(BigDecimal.valueOf(repairSoiByWares.getGoodsCount())));
}else {
wares.setStock(item.getStock().subtract(BigDecimal.valueOf(repairSoiByWares.getGoodsCount())));
}
});
newWares.add(wares);
});
// 更新申请表子表
twItemService.updateBatchById(newTwItems);
// 更新配件
repairWaresService.updateBatchById(newWares);
}
}
@ -235,53 +287,54 @@ public class DlRepairSoServiceImpl extends ServiceImpl<DlRepairSoMapper, DlRepai
.list(new LambdaQueryWrapper<DlRepairSoi>()
.eq(DlRepairSoi::getSoId, id)
);
// 查库存
List<RepairWares> wares = waresService
.list(new LambdaQueryWrapper<RepairWares>()
.in(RepairWares::getId, sois.stream()
.map(DlRepairSoi::getGoodsId)
.collect(Collectors.toList())
));
// 更新库存
List<RepairWares> newWares = wares.stream().map(item -> {
RepairWares ware = new RepairWares();
ware.setId(item.getId());
sois.stream().filter(i -> i.getGoodsId().equals(item.getId())).findFirst().ifPresent(i -> {
ware.setStock(item.getStock().subtract(BigDecimal.valueOf(i.getGoodsCount())));
});
return ware;
}).collect(Collectors.toList());
waresService.updateBatchById(newWares);
// 查库存---生成领料单的时候更新了
// List<RepairWares> wares = waresService
// .list(new LambdaQueryWrapper<RepairWares>()
// .in(RepairWares::getId, sois.stream()
// .map(DlRepairSoi::getGoodsId)
// .collect(Collectors.toList())
// ));
// // 更新库存
// List<RepairWares> newWares = wares.stream().map(item -> {
// RepairWares ware = new RepairWares();
// ware.setId(item.getId());
// sois.stream().filter(i -> i.getGoodsId().equals(item.getId())).findFirst().ifPresent(i -> {
// ware.setStock(item.getStock().subtract(BigDecimal.valueOf(i.getGoodsCount())));
// });
// return ware;
// }).collect(Collectors.toList());
// waresService.updateBatchById(newWares);
// 更新主表状态 为已领料
DlRepairSo dlRepairSo = new DlRepairSo();
dlRepairSo.setId(id);
dlRepairSo.setSoStatus(SoStatusEnum.PICKED.getCode());
baseMapper.updateById(dlRepairSo);
// 更新申请表的数据
DlRepairSo so = baseMapper.selectOne(new LambdaQueryWrapper<DlRepairSo>().eq(DlRepairSo::getId, id));
// 查申请表的子表对应的配件信息
List<DlTwItem> twItems = twItemService.list(new LambdaQueryWrapper<DlTwItem>().and(item -> {
item.eq(DlTwItem::getTwId, so.getTwId())
.in(DlTwItem::getWaresId, sois.stream().map(DlRepairSoi::getGoodsId).collect(Collectors.toList()));
}));
// 更新子表
List<DlTwItem> newTwItems = twItems.stream().map(item -> {
DlTwItem dlTwItem = new DlTwItem();
dlTwItem.setId(item.getId());
dlTwItem.setWaresAlreadyCount(ObjectUtil.isNotEmpty(item.getWaresAlreadyCount()) ? item.getWaresAlreadyCount() + item.getWaresCouldCount() : item.getWaresCouldCount());
dlTwItem.setWaresStatus(dlTwItem.getWaresAlreadyCount().equals(item.getWaresCount()) ? "01" : item.getWaresStatus());
return dlTwItem;
}).collect(Collectors.toList());
twItemService.updateBatchById(newTwItems);
// 更新申请表的数据----生成领料单的时候更新了
// // 查申请表的子表对应的配件信息
// List<DlTwItem> twItems = twItemService.list(new LambdaQueryWrapper<DlTwItem>().and(item -> {
// item.eq(DlTwItem::getTwId, so.getTwId())
// .in(DlTwItem::getWaresId, sois.stream().map(DlRepairSoi::getGoodsId).collect(Collectors.toList()));
// }));
// // 更新子表
// List<DlTwItem> newTwItems = twItems.stream().map(item -> {
// DlTwItem dlTwItem = new DlTwItem();
// dlTwItem.setId(item.getId());
// dlTwItem.setWaresAlreadyCount(ObjectUtil.isNotEmpty(item.getWaresAlreadyCount()) ? item.getWaresAlreadyCount() + item.getWaresCouldCount() : item.getWaresCouldCount());
// dlTwItem.setWaresStatus(dlTwItem.getWaresAlreadyCount().equals(item.getWaresCount()) ? "01" : item.getWaresStatus());
// return dlTwItem;
// }).collect(Collectors.toList());
// twItemService.updateBatchById(newTwItems);
// 查最新的子表信息
DlRepairSo so = baseMapper.selectOne(new LambdaQueryWrapper<DlRepairSo>().eq(DlRepairSo::getId, id));
List<DlTwItem> list = twItemService.list(new LambdaQueryWrapper<DlTwItem>().eq(DlTwItem::getTwId, so.getTwId()));
// 判断是部分完成还是全部完成
DlTicketWares dlTicketWares = new DlTicketWares();
dlTicketWares.setId(so.getTwId());
List<DlTwItem> flag = list.stream().filter(item -> !item.getWaresStatus().equals("01")).collect(Collectors.toList());
dlTicketWares.setStatus(CollectionUtil.isEmpty(flag) ? "03" : "04");
// 更新主表的状态
ticketWaresService.updateById(dlTicketWares);
// 查主表记录
@ -305,92 +358,94 @@ public class DlRepairSoServiceImpl extends ServiceImpl<DlRepairSoMapper, DlRepai
.set(DlRepairSo::getSoStatus, SoStatusEnum.RETURNED.getCode())
.eq(DlRepairSo::getId, id)
);
// 更新配件申请表
DlRepairSo so = baseMapper.selectOne(new LambdaQueryWrapper<DlRepairSo>().eq(DlRepairSo::getId, id));
// 查配件退料表子表
List<DlRepairSoi> sois = repairSoiService.list(new LambdaQueryWrapper<DlRepairSoi>().eq(DlRepairSoi::getSoId, so.getId()));
// 查申请表子表
List<DlTwItem> twItems = twItemService.list(new LambdaQueryWrapper<DlTwItem>().eq(DlTwItem::getTwId, so.getTwId()));
// 得到需要更新的数据
List<DlTwItem> newTwItems = twItems.stream().map(item -> {
DlTwItem dlTwItem = new DlTwItem();
dlTwItem.setId(item.getId());
sois.stream().filter(i -> i.getGoodsId().equals(item.getWaresId())).findFirst().ifPresent(i -> {
dlTwItem.setWaresBackCount(
ObjectUtil.isNotEmpty(item.getWaresBackCount())
? item.getWaresCount() + item.getWaresBackCount()
: i.getGoodsCount());
// 如果退料数就是领料申请数那就是全退了
if (i.getGoodsCount().equals(dlTwItem.getWaresCount())) {
dlTwItem.setWaresStatus("03");
}
});
return dlTwItem;
}).collect(Collectors.toList());
twItemService.updateBatchById(newTwItems);
// 更新库存
// 查库存
List<RepairWares> wares = waresService.list(new LambdaQueryWrapper<RepairWares>().in(RepairWares::getId, sois.stream().map(DlRepairSoi::getGoodsId).collect(Collectors.toList())));
// 构建新数据
List<RepairWares> newWares = wares.stream().map(item -> {
RepairWares ware = new RepairWares();
ware.setId(item.getId());
sois.stream().filter(i -> i.getGoodsId().equals(item.getId())).findFirst().ifPresent(i -> {
ware.setStock(item.getStock().add(BigDecimal.valueOf(i.getGoodsCount())));
});
return ware;
}).collect(Collectors.toList());
waresService.updateBatchById(newWares);
// 更新配件申请表----生成退料单的时候更新了
// DlRepairSo so = baseMapper.selectOne(new LambdaQueryWrapper<DlRepairSo>().eq(DlRepairSo::getId, id));
// // 查配件退料表子表
// List<DlRepairSoi> sois = repairSoiService.list(new LambdaQueryWrapper<DlRepairSoi>().eq(DlRepairSoi::getSoId, so.getId()));
// // 查申请表子表
// List<DlTwItem> twItems = twItemService.list(new LambdaQueryWrapper<DlTwItem>().eq(DlTwItem::getTwId, so.getTwId()));
// // 得到需要更新的数据
// List<DlTwItem> newTwItems = twItems.stream().map(item -> {
// DlTwItem dlTwItem = new DlTwItem();
// dlTwItem.setId(item.getId());
// sois.stream().filter(i -> i.getGoodsId().equals(item.getWaresId())).findFirst().ifPresent(i -> {
// dlTwItem.setWaresBackCount(
// ObjectUtil.isNotEmpty(item.getWaresBackCount())
// ? item.getWaresCount() + item.getWaresBackCount()
// : i.getGoodsCount());
// // 如果退料数就是领料申请数那就是全退了
// if (i.getGoodsCount().equals(dlTwItem.getWaresCount())) {
// dlTwItem.setWaresStatus("03");
// }
// });
// return dlTwItem;
// }).collect(Collectors.toList());
// twItemService.updateBatchById(newTwItems);
// // 更新库存
// // 查库存
// List<RepairWares> wares = waresService.list(new LambdaQueryWrapper<RepairWares>().in(RepairWares::getId, sois.stream().map(DlRepairSoi::getGoodsId).collect(Collectors.toList())));
// // 构建新数据
// List<RepairWares> newWares = wares.stream().map(item -> {
// RepairWares ware = new RepairWares();
// ware.setId(item.getId());
// sois.stream().filter(i -> i.getGoodsId().equals(item.getId())).findFirst().ifPresent(i -> {
// ware.setStock(item.getStock().add(BigDecimal.valueOf(i.getGoodsCount())));
// });
// return ware;
// }).collect(Collectors.toList());
// waresService.updateBatchById(newWares);
// 更新维修工单
// 查申请表主表
DlTicketWares ticketWares = ticketWaresService.getOne(new LambdaQueryWrapper<DlTicketWares>().eq(DlTicketWares::getId, so.getTwId()));
// 查维修工单子表为配件的数据
List<DlRepairTitem> titems = titemService.list(new LambdaQueryWrapper<DlRepairTitem>().and(item -> {
item.eq(DlRepairTitem::getTicketId, ticketWares.getTicketId())
.eq(DlRepairTitem::getItemType, "02")
.in(DlRepairTitem::getPartId, sois.stream().map(DlRepairSoi::getGoodsId).collect(Collectors.toList()));
}));
// 构建新数据更新维修工单子表
List<DlRepairTitem> newTitems = titems.stream().map(item -> {
DlRepairTitem titem = new DlRepairTitem();
titem.setId(item.getId());
sois.stream().filter(i -> i.getGoodsId().equals(item.getPartId())).findFirst().ifPresent(i -> {
titem.setItemCount(item.getItemCount() - i.getGoodsCount());
BigDecimal itemDiscount = ObjectUtil.isNotEmpty(item.getItemDiscount()) ? item.getItemDiscount() : BigDecimal.ONE;
titem.setItemMoney(new BigDecimal(titem.getItemCount()).multiply(item.getItemPrice()).multiply(itemDiscount));
});
return titem;
}).collect(Collectors.toList());
// 分开全部退料了的和没有全部退料的数据
List<DlRepairTitem> delTitems = newTitems.stream().filter(item -> item.getItemCount() == 0).collect(Collectors.toList());
if (CollectionUtil.isEmpty(delTitems)) {
titemService.updateBatchById(newTitems);
} else {
titemService.removeBatchByIds(delTitems);
List<DlRepairTitem> updateTitems = newTitems.stream().filter(item -> !delTitems.contains(item)).collect(Collectors.toList());
if (CollectionUtil.isEmpty(updateTitems)) {
titemService.updateBatchById(updateTitems);
}
}
// 更新维修工单
DlRepairTickets tickets = ticketsService.getOne(new LambdaQueryWrapper<DlRepairTickets>().eq(DlRepairTickets::getId, ticketWares.getTicketId()));
// 查最新的子表信息
List<DlRepairTitem> list = titemService.list(new LambdaQueryWrapper<DlRepairTitem>().in(DlRepairTitem::getTicketId, tickets.getId()));
// 计算工单总子项工单配件总价工单总价
DlRepairTickets newTickets = new DlRepairTickets();
newTickets.setId(tickets.getId());
newTickets.setCount(list.stream().mapToInt(DlRepairTitem::getItemCount).sum());
newTickets.setPartPrice(list.stream()
.filter(item -> item.getItemType().equals("02"))
.map(DlRepairTitem::getItemMoney)
.reduce(BigDecimal.ZERO, BigDecimal::add));
BigDecimal projectPrice = tickets.getProjectPrice() == null ? BigDecimal.ZERO : tickets.getProjectPrice();
BigDecimal otherPrice = tickets.getOtherPrice() != null ? tickets.getOtherPrice() : BigDecimal.ZERO;
BigDecimal partPrice = newTickets.getPartPrice() == null ? BigDecimal.ZERO : newTickets.getPartPrice();
newTickets.setTotalPrice(projectPrice.add(partPrice).add(otherPrice));
ticketsService.updateById(newTickets);
// 更新维修工单----最后完成工单的时候来更新
// // 查配件退料表子表
// List<DlRepairSoi> sois = repairSoiService.list(new LambdaQueryWrapper<DlRepairSoi>().eq(DlRepairSoi::getSoId, so.getId()));
// // 查申请表主表
// DlTicketWares ticketWares = ticketWaresService.getOne(new LambdaQueryWrapper<DlTicketWares>().eq(DlTicketWares::getId, so.getTwId()));
// // 查维修工单子表为配件的数据
// List<DlRepairTitem> titems = titemService.list(new LambdaQueryWrapper<DlRepairTitem>().and(item -> {
// item.eq(DlRepairTitem::getTicketId, ticketWares.getTicketId())
// .eq(DlRepairTitem::getItemType, "02")
// .in(DlRepairTitem::getPartId, sois.stream().map(DlRepairSoi::getGoodsId).collect(Collectors.toList()));
// }));
// // 构建新数据更新维修工单子表
// List<DlRepairTitem> newTitems = titems.stream().map(item -> {
// DlRepairTitem titem = new DlRepairTitem();
// titem.setId(item.getId());
// sois.stream().filter(i -> i.getGoodsId().equals(item.getPartId())).findFirst().ifPresent(i -> {
// titem.setItemCount(item.getItemCount() - i.getGoodsCount());
// BigDecimal itemDiscount = ObjectUtil.isNotEmpty(item.getItemDiscount()) ? item.getItemDiscount() : BigDecimal.ONE;
// titem.setItemMoney(new BigDecimal(titem.getItemCount()).multiply(item.getItemPrice()).multiply(itemDiscount));
// });
// return titem;
// }).collect(Collectors.toList());
// // 分开全部退料了的和没有全部退料的数据
// List<DlRepairTitem> delTitems = newTitems.stream().filter(item -> item.getItemCount() == 0).collect(Collectors.toList());
// if (CollectionUtil.isEmpty(delTitems)) {
// titemService.updateBatchById(newTitems);
// } else {
// titemService.removeBatchByIds(delTitems);
// List<DlRepairTitem> updateTitems = newTitems.stream().filter(item -> !delTitems.contains(item)).collect(Collectors.toList());
// if (CollectionUtil.isEmpty(updateTitems)) {
// titemService.updateBatchById(updateTitems);
// }
//
// }
// // 更新维修工单
// DlRepairTickets tickets = ticketsService.getOne(new LambdaQueryWrapper<DlRepairTickets>().eq(DlRepairTickets::getId, ticketWares.getTicketId()));
// // 查最新的子表信息
// List<DlRepairTitem> list = titemService.list(new LambdaQueryWrapper<DlRepairTitem>().in(DlRepairTitem::getTicketId, tickets.getId()));
// // 计算工单总子项工单配件总价工单总价
// DlRepairTickets newTickets = new DlRepairTickets();
// newTickets.setId(tickets.getId());
// newTickets.setCount(list.stream().mapToInt(DlRepairTitem::getItemCount).sum());
// newTickets.setPartPrice(list.stream()
// .filter(item -> item.getItemType().equals("02"))
// .map(DlRepairTitem::getItemMoney)
// .reduce(BigDecimal.ZERO, BigDecimal::add));
// BigDecimal projectPrice = tickets.getProjectPrice() == null ? BigDecimal.ZERO : tickets.getProjectPrice();
// BigDecimal otherPrice = tickets.getOtherPrice() != null ? tickets.getOtherPrice() : BigDecimal.ZERO;
// BigDecimal partPrice = newTickets.getPartPrice() == null ? BigDecimal.ZERO : newTickets.getPartPrice();
// newTickets.setTotalPrice(projectPrice.add(partPrice).add(otherPrice));
// ticketsService.updateById(newTickets);
// 查主表
DlRepairSo newSo = baseMapper.selectById(id);
@ -455,7 +510,7 @@ public class DlRepairSoServiceImpl extends ServiceImpl<DlRepairSoMapper, DlRepai
inWares.setInCount(filterSoi.getInCount());
inWares.setId(null);
//采购品中入库数量字段累加
item.setInCount(item.getInCount() == null?0:item.getInCount()+filterSoi.getInCount());
item.setInCount(item.getInCount() == null ? 0 : item.getInCount() + filterSoi.getInCount());
inWaresList.add(inWares);
});
//更新采购品
@ -467,12 +522,11 @@ public class DlRepairSoServiceImpl extends ServiceImpl<DlRepairSoMapper, DlRepai
Map<String, DlRepairSoi> wareMap = filterWare.stream().collect(Collectors.toMap(DlRepairSoi::getWareId, soi -> soi));
waresList.forEach(item -> {
DlRepairSoi filterSoi = wareMap.get(item.getId());
item.setStock((item.getStock()==null?new BigDecimal(0):item.getStock()).add(new BigDecimal(filterSoi.getInCount())));
item.setStock((item.getStock() == null ? new BigDecimal(0) : item.getStock()).add(new BigDecimal(filterSoi.getInCount())));
});
waresService.updateBatchById(waresList);
}
}

View File

@ -340,7 +340,7 @@ public class DlTicketWaresServiceImpl extends ServiceImpl<DlTicketWaresMapper, D
}
}
// 如果是驳回通知维修工
if (status.equals("05")){
if (status.equals("05")) {
// 发送没有通过的消息给员工
DlTicketWares ticketWares = baseMapper.selectById(respVO.getId());
repairWorkerService.sentMessage(ticketWares.getRepairId(), "您的配件申请单被驳回了");
@ -450,12 +450,15 @@ public class DlTicketWaresServiceImpl extends ServiceImpl<DlTicketWaresMapper, D
});
repairSoiService.saveBatch(respVO.getRepairSois());
// 更新配件申请子表
/*
同理通知领料的数量可能与实际需要的数量不一致需要重新计算状态
*/
// 先查老数据领料才需要更新
if (type.equals("02")) {
List<DlTwItem> oldData = twItemService.list(new LambdaQueryWrapper<DlTwItem>().in(DlTwItem::getId, respVO.getItems().stream().map(DlTwItem::getId).collect(Collectors.toList())));
// 分领料和退料
// 先取出要操作的子表数据
List<DlTwItem> oldData = twItemService.list(new LambdaQueryWrapper<DlTwItem>().and(item -> {
item.eq(DlTwItem::getTwId, respVO.getRepairSo().getTwId())
.in(DlTwItem::getWaresId, respVO.getRepairSois().stream().map(DlRepairSoi::getGoodsId).collect(Collectors.toList()));
}));
// 要操作的库存数据
List<RepairWares> wares = repairWaresService.list(new LambdaQueryWrapper<RepairWares>().in(RepairWares::getId, respVO.getRepairSois().stream().map(DlRepairSoi::getGoodsId).collect(Collectors.toList())));
if (type.equals("02")) { // 领料
// 构造新数据
List<DlTwItem> newData = oldData.stream().map(item -> {
DlTwItem dlTwItem = new DlTwItem();
@ -464,13 +467,85 @@ public class DlTicketWaresServiceImpl extends ServiceImpl<DlTicketWaresMapper, D
.filter(i -> i.getGoodsId().equals(item.getWaresId()))
.findFirst()
.ifPresent(repairSoi -> {
dlTwItem.setWaresCouldCount(repairSoi.getGoodsCount());
dlTwItem.setWaresStatus(repairSoi.getGoodsCount().equals(item.getWaresCount()) ? "04" : item.getWaresStatus());
// 先取该申请配件的已领料数量如过是第一次就是0
Integer waresAlreadyCount = item.getWaresAlreadyCount() == null ? 0 : item.getWaresAlreadyCount();
// 取本来的已领取数量+本次要领取的数量
dlTwItem.setWaresAlreadyCount(repairSoi.getGoodsCount() + waresAlreadyCount);
// 可领取数量就是申请数量-已领料数量
// item是操作的申请配件的数量dlTwItem取最新的已领取数量
dlTwItem.setWaresCouldCount(item.getWaresCount() - dlTwItem.getWaresAlreadyCount());
// dlTwItem.setWaresStatus(repairSoi.getGoodsCount().equals(item.getWaresCount()) ? "04" : item.getWaresStatus());
// 如果已领取数量等于申请数量那这个配件就是领料完了为01已领料反之不变
dlTwItem.setWaresStatus(item.getWaresCount().equals(dlTwItem.getWaresAlreadyCount()) ? "01" : item.getWaresStatus());
});
return dlTwItem;
}).collect(Collectors.toList());
twItemService.updateBatchById(newData);
// 同时操作库存扣减
// 构造新数据
List<RepairWares> newWares = wares.stream().map(item -> {
RepairWares ware = new RepairWares();
ware.setId(item.getId());
respVO.getRepairSois().stream().filter(i -> i.getGoodsId().equals(item.getId())).findFirst().ifPresent(repairSoi -> ware.setStock(item.getStock().subtract(BigDecimal.valueOf(repairSoi.getGoodsCount()))));
return ware;
}).collect(Collectors.toList());
// 更新库存
repairWaresService.updateBatchById(newWares);
} else { // 退料
// 构造新数据
List<DlTwItem> newData = oldData.stream().map(item -> {
DlTwItem dlTwItem = new DlTwItem();
dlTwItem.setId(item.getId());
respVO.getRepairSois().stream()
.filter(i -> i.getGoodsId().equals(item.getWaresId()))
.findFirst()
.ifPresent(repairSoi -> {
// 取本来的已领取数量-本次要退料的数量
dlTwItem.setWaresAlreadyCount(item.getWaresAlreadyCount() - repairSoi.getGoodsCount());
// 可领取数量就是上次的可领取+退料数量
// item是操作的可领取数量repairSoi是取本次退料的数量
dlTwItem.setWaresCouldCount(item.getWaresCouldCount() + repairSoi.getGoodsCount());
// dlTwItem.setWaresStatus(repairSoi.getGoodsCount().equals(item.getWaresCount()) ? "04" : item.getWaresStatus());
// 如果可领料数量等于申请数量那这个配件就是退料完了为03已退料反之不变
dlTwItem.setWaresStatus(item.getWaresCount().equals(dlTwItem.getWaresCouldCount()) ? "03" : "02");
});
return dlTwItem;
}).collect(Collectors.toList());
twItemService.updateBatchById(newData);
// 同时操作库存新增
// 构造新数据
List<RepairWares> newWares = wares.stream().map(item -> {
RepairWares ware = new RepairWares();
ware.setId(item.getId());
respVO.getRepairSois().stream().filter(i -> i.getGoodsId().equals(item.getId())).findFirst().ifPresent(repairSoi -> ware.setStock(item.getStock().add(BigDecimal.valueOf(repairSoi.getGoodsCount()))));
return ware;
}).collect(Collectors.toList());
// 更新库存
repairWaresService.updateBatchById(newWares);
}
// /*
// 同理通知领料的数量可能与实际需要的数量不一致需要重新计算状态
// */
// // 先查老数据领料才需要更新
// if (type.equals("02")) {
// List<DlTwItem> oldData = twItemService.list(new LambdaQueryWrapper<DlTwItem>().in(DlTwItem::getId, respVO.getItems().stream().map(DlTwItem::getId).collect(Collectors.toList())));
// // 构造新数据
// List<DlTwItem> newData = oldData.stream().map(item -> {
// DlTwItem dlTwItem = new DlTwItem();
// dlTwItem.setId(item.getId());
// respVO.getRepairSois().stream()
// .filter(i -> i.getGoodsId().equals(item.getWaresId()))
// .findFirst()
// .ifPresent(repairSoi -> {
// dlTwItem.setWaresCouldCount(repairSoi.getGoodsCount());
// dlTwItem.setWaresStatus(repairSoi.getGoodsCount().equals(item.getWaresCount()) ? "04" : item.getWaresStatus());
// });
// return dlTwItem;
// }).collect(Collectors.toList());
// twItemService.updateBatchById(newData);
// }
// 通知维修工
// 查维修工的userId
@ -482,7 +557,7 @@ public class DlTicketWaresServiceImpl extends ServiceImpl<DlTicketWaresMapper, D
*
* @param respVO 请求对象
* @author 小李
* @date 22:07 2024/10/16
* @date 22:07 2024/10/16 应该是弃用了但不确定先不删
**/
@Override
@DSTransactional
@ -509,7 +584,7 @@ public class DlTicketWaresServiceImpl extends ServiceImpl<DlTicketWaresMapper, D
*
* @param respVO 请求对象
* @author 小李
* @date 22:03 2024/10/17
* @date 22:03 2024/10/17 应该是弃用了但不确定先不删
**/
@Override
public void passBackTicketWares(DlTicketWaresRespVO respVO) {