修改了重新计算工单的接口

This commit is contained in:
xiaofajia 2024-11-21 12:27:21 +08:00
parent 9d15441ad6
commit a63c015e53

View File

@ -1582,70 +1582,68 @@ public class DlRepairTicketsServiceImpl extends ServiceImpl<DlRepairTicketsMappe
@Override @Override
@DSTransactional @DSTransactional
public boolean computeTicket(String ticketId) { public boolean computeTicket(String ticketId) {
// 查子表 // 取主表
List<DlRepairTitem> list = titemService.list(new LambdaQueryWrapper<DlRepairTitem>().eq(DlRepairTitem::getTicketId, ticketId)); DlRepairTickets tickets = baseMapper.selectById(ticketId);
// 计算子表 // 取子表
if (CollectionUtil.isEmpty(list)) { List<DlRepairTitem> titems = titemService.list(new LambdaQueryWrapper<DlRepairTitem>().eq(DlRepairTitem::getTicketId, ticketId));
if (CollectionUtil.isEmpty(titems)) {
throw exception0(500, "没有项目、配件或其他"); throw exception0(500, "没有项目、配件或其他");
} }
List<DlRepairTitem> updateItems = list.stream().map(item -> { // 计算子表
DlRepairTitem titem = new DlRepairTitem(); Map<String, BigDecimal> titemsMap = titems.stream().collect(Collectors.toMap(
titem.setId(item.getId()); DlRepairTitem::getId,
// 取出折扣 item -> {
BigDecimal discount = item.getItemDiscount() == null ? new BigDecimal("1") : item.getItemDiscount(); BigDecimal discount = item.getItemDiscount() == null ? BigDecimal.ONE : item.getItemDiscount();
BigDecimal itemPrice = item.getItemPrice() == null ? BigDecimal.ZERO : item.getItemPrice(); BigDecimal itemPrice = item.getItemPrice() == null ? BigDecimal.ZERO : item.getItemPrice();
titem.setItemMoney(itemPrice.multiply(BigDecimal.valueOf(item.getItemCount())).multiply(discount)); return itemPrice.multiply(BigDecimal.valueOf(item.getItemCount())).multiply(discount);
return titem; }
}).collect(Collectors.toList()); ));
// 更新 titems.forEach(item -> {
titemService.updateBatchById(updateItems); item.setItemMoney(titemsMap.get(item.getId()));
});
titemService.updateBatchById(titems);
// 计算主表 // 计算主表
// 查新的子表信息 // 总数量
List<DlRepairTitem> newList = titemService.list(new LambdaQueryWrapper<DlRepairTitem>().eq(DlRepairTitem::getTicketId, ticketId)); tickets.setCount(titems.stream().mapToInt(DlRepairTitem::getItemCount).sum());
DlRepairTickets tickets = new DlRepairTickets(); // 各类总价
// 计算子项总数 Map<String, BigDecimal> typePrice = titems.stream()
int count = newList.stream().mapToInt(DlRepairTitem::getItemCount).sum(); .collect(Collectors.groupingBy(DlRepairTitem::getItemType,
tickets.setId(ticketId); Collectors.mapping(DlRepairTitem::getItemMoney,
tickets.setCount(count); Collectors.reducing(BigDecimal.ZERO, BigDecimal::add))));
// 分类计算各自的总价和最终工单总价 BigDecimal itemTotalPrice = new BigDecimal("0");
Map<String, List<DlRepairTitem>> map = newList.stream().collect(Collectors.groupingBy(DlRepairTitem::getItemType)); for (Map.Entry<String, BigDecimal> entry : typePrice.entrySet()) {
// 01项目02配件03其他 itemTotalPrice = itemTotalPrice.add(entry.getValue());
tickets.setTotalPrice(BigDecimal.ZERO); switch (entry.getKey()){
map.forEach((k, v) -> { case "01":
BigDecimal reduce = v.stream().map(DlRepairTitem::getItemMoney).reduce(BigDecimal.ZERO, BigDecimal::add); tickets.setProjectPrice(entry.getValue());
tickets.setTotalPrice(tickets.getTotalPrice().add(reduce)); break;
if (k.equals("01")) { case "02":
tickets.setProjectPrice(reduce); tickets.setPartPrice(entry.getValue());
} else if (k.equals("02")) { break;
tickets.setPartPrice(reduce); case "03":
} else if (k.equals("03")) { tickets.setOtherPrice(entry.getValue());
tickets.setOtherPrice(reduce); break;
} }
}); }
// 其他费用
// 工单总价还需要变把其他新加的费用也需要算上
// 查主表
DlRepairTickets oldTicket = baseMapper.selectById(ticketId);
// 管理费 // 管理费
BigDecimal managerMoney = ObjectUtil.isNotEmpty(oldTicket.getManagerMoney()) ? oldTicket.getManagerMoney() : new BigDecimal("0"); BigDecimal managerMoney = ObjectUtil.isNotEmpty(tickets.getManagerMoney()) ? tickets.getManagerMoney() : new BigDecimal("0");
// 救援费 // 救援费
BigDecimal rescueMoney = ObjectUtil.isNotEmpty(oldTicket.getRescueMoney()) ? oldTicket.getRescueMoney() : new BigDecimal("0"); BigDecimal rescueMoney = ObjectUtil.isNotEmpty(tickets.getRescueMoney()) ? tickets.getRescueMoney() : new BigDecimal("0");
// 三包费 // 三包费
BigDecimal threePackMoney = ObjectUtil.isNotEmpty(oldTicket.getThreePackMoney()) ? oldTicket.getThreePackMoney() : new BigDecimal("0"); BigDecimal threePackMoney = ObjectUtil.isNotEmpty(tickets.getThreePackMoney()) ? tickets.getThreePackMoney() : new BigDecimal("0");
// 定损费 // 定损费
BigDecimal confirmFaultMoney = ObjectUtil.isNotEmpty(oldTicket.getConfirmFaultMoney()) ? oldTicket.getConfirmFaultMoney() : new BigDecimal("0"); BigDecimal confirmFaultMoney = ObjectUtil.isNotEmpty(tickets.getConfirmFaultMoney()) ? tickets.getConfirmFaultMoney() : new BigDecimal("0");
tickets.setTotalPrice(tickets.getTotalPrice().add(managerMoney).add(rescueMoney).add(threePackMoney).add(confirmFaultMoney)); tickets.setTotalPrice(itemTotalPrice.add(managerMoney).add(rescueMoney).add(threePackMoney).add(confirmFaultMoney));
baseMapper.updateById(tickets);
// 因为订单是在工单创建的时候就新增了后面加的配件之类的金额没有同步到订单这里同步一下 // 更新订单
RepairOrderInfo orderInfo = repairOrderInfoService.getOne(new LambdaQueryWrapper<RepairOrderInfo>().eq(RepairOrderInfo::getGoodsId, ticketId)); RepairOrderInfo orderInfo = repairOrderInfoService.getOne(new LambdaQueryWrapper<RepairOrderInfo>().eq(RepairOrderInfo::getGoodsId, ticketId));
RepairOrderInfo newOrderInfo = new RepairOrderInfo(); orderInfo.setGoodsPrice(tickets.getTotalPrice());
newOrderInfo.setId(orderInfo.getId()); orderInfo.setPayMoney(tickets.getTotalPrice());
// 更新商品原价和实付金额 repairOrderInfoService.updateById(orderInfo);
newOrderInfo.setGoodsPrice(tickets.getTotalPrice());
newOrderInfo.setPayMoney(tickets.getTotalPrice());
repairOrderInfoService.updateById(newOrderInfo);
return baseMapper.updateById(tickets) > 0; return baseMapper.updateById(tickets) > 0;
} }
@ -1829,9 +1827,9 @@ public class DlRepairTicketsServiceImpl extends ServiceImpl<DlRepairTicketsMappe
/** /**
* 根据工单ID查客户和车辆信息 * 根据工单ID查客户和车辆信息
* *
* @param id id
* @author 小李 * @author 小李
* @date 19:07 2024/11/18 * @date 19:07 2024/11/18
* @param id id
**/ **/
@Override @Override
public CustomerAndCarVO getCusAndCarById(String id) { public CustomerAndCarVO getCusAndCarById(String id) {