1
This commit is contained in:
parent
291360d2e6
commit
00b51b8b86
@ -1582,50 +1582,8 @@ public class DlRepairTicketsServiceImpl extends ServiceImpl<DlRepairTicketsMappe
|
|||||||
@Override
|
@Override
|
||||||
@DSTransactional
|
@DSTransactional
|
||||||
public boolean computeTicket(String ticketId) {
|
public boolean computeTicket(String ticketId) {
|
||||||
// 查子表
|
Long time1 = System.currentTimeMillis();
|
||||||
List<DlRepairTitem> list = titemService.list(new LambdaQueryWrapper<DlRepairTitem>().eq(DlRepairTitem::getTicketId, ticketId));
|
/*1.查主表 */
|
||||||
// 计算子表
|
|
||||||
if (CollectionUtil.isEmpty(list)) {
|
|
||||||
throw exception0(500, "没有项目、配件或其他");
|
|
||||||
}
|
|
||||||
List<DlRepairTitem> updateItems = list.stream().map(item -> {
|
|
||||||
DlRepairTitem titem = new DlRepairTitem();
|
|
||||||
titem.setId(item.getId());
|
|
||||||
// 取出折扣
|
|
||||||
BigDecimal discount = item.getItemDiscount() == null ? new BigDecimal("1") : item.getItemDiscount();
|
|
||||||
BigDecimal itemPrice = item.getItemPrice() == null ? BigDecimal.ZERO : item.getItemPrice();
|
|
||||||
titem.setItemMoney(itemPrice.multiply(BigDecimal.valueOf(item.getItemCount())).multiply(discount));
|
|
||||||
return titem;
|
|
||||||
}).collect(Collectors.toList());
|
|
||||||
// 更新
|
|
||||||
titemService.updateBatchById(updateItems);
|
|
||||||
|
|
||||||
// 计算主表
|
|
||||||
// 查新的子表信息
|
|
||||||
List<DlRepairTitem> newList = titemService.list(new LambdaQueryWrapper<DlRepairTitem>().eq(DlRepairTitem::getTicketId, ticketId));
|
|
||||||
DlRepairTickets tickets = new DlRepairTickets();
|
|
||||||
// 计算子项总数
|
|
||||||
int count = newList.stream().mapToInt(DlRepairTitem::getItemCount).sum();
|
|
||||||
tickets.setId(ticketId);
|
|
||||||
tickets.setCount(count);
|
|
||||||
// 分类计算各自的总价和最终工单总价
|
|
||||||
Map<String, List<DlRepairTitem>> map = newList.stream().collect(Collectors.groupingBy(DlRepairTitem::getItemType));
|
|
||||||
// 01项目,02,配件,03,其他
|
|
||||||
tickets.setTotalPrice(BigDecimal.ZERO);
|
|
||||||
map.forEach((k, v) -> {
|
|
||||||
BigDecimal reduce = v.stream().map(DlRepairTitem::getItemMoney).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
||||||
tickets.setTotalPrice(tickets.getTotalPrice().add(reduce));
|
|
||||||
if (k.equals("01")) {
|
|
||||||
tickets.setProjectPrice(reduce);
|
|
||||||
} else if (k.equals("02")) {
|
|
||||||
tickets.setPartPrice(reduce);
|
|
||||||
} else if (k.equals("03")) {
|
|
||||||
tickets.setOtherPrice(reduce);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// 工单总价还需要变,把其他新加的费用也需要算上
|
|
||||||
// 查主表
|
|
||||||
DlRepairTickets oldTicket = baseMapper.selectById(ticketId);
|
DlRepairTickets oldTicket = baseMapper.selectById(ticketId);
|
||||||
// 管理费
|
// 管理费
|
||||||
BigDecimal managerMoney = ObjectUtil.isNotEmpty(oldTicket.getManagerMoney()) ? oldTicket.getManagerMoney() : new BigDecimal("0");
|
BigDecimal managerMoney = ObjectUtil.isNotEmpty(oldTicket.getManagerMoney()) ? oldTicket.getManagerMoney() : new BigDecimal("0");
|
||||||
@ -1635,19 +1593,69 @@ public class DlRepairTicketsServiceImpl extends ServiceImpl<DlRepairTicketsMappe
|
|||||||
BigDecimal threePackMoney = ObjectUtil.isNotEmpty(oldTicket.getThreePackMoney()) ? oldTicket.getThreePackMoney() : new BigDecimal("0");
|
BigDecimal threePackMoney = ObjectUtil.isNotEmpty(oldTicket.getThreePackMoney()) ? oldTicket.getThreePackMoney() : new BigDecimal("0");
|
||||||
// 定损费
|
// 定损费
|
||||||
BigDecimal confirmFaultMoney = ObjectUtil.isNotEmpty(oldTicket.getConfirmFaultMoney()) ? oldTicket.getConfirmFaultMoney() : new BigDecimal("0");
|
BigDecimal confirmFaultMoney = ObjectUtil.isNotEmpty(oldTicket.getConfirmFaultMoney()) ? oldTicket.getConfirmFaultMoney() : new BigDecimal("0");
|
||||||
|
/*2.查子表 */
|
||||||
tickets.setTotalPrice(tickets.getTotalPrice().add(managerMoney).add(rescueMoney).add(threePackMoney).add(confirmFaultMoney));
|
List<DlRepairTitem> list = titemService.list(new LambdaQueryWrapper<DlRepairTitem>().eq(DlRepairTitem::getTicketId, ticketId));
|
||||||
|
if (CollectionUtil.isEmpty(list)) {
|
||||||
|
throw exception0(500, "没有项目、配件或其他");
|
||||||
|
}
|
||||||
|
/*3.遍历数据--遍历这一次,处理所有需要处理的*/
|
||||||
|
//商品总数
|
||||||
|
Integer goodsCount=0;
|
||||||
|
//工单总价
|
||||||
|
BigDecimal totalAmount = BigDecimal.ZERO.add(managerMoney).add(rescueMoney).add(threePackMoney).add(confirmFaultMoney);
|
||||||
|
//项目总价
|
||||||
|
BigDecimal proAmount = BigDecimal.ZERO;
|
||||||
|
//配件总价
|
||||||
|
BigDecimal waresAmount = BigDecimal.ZERO;
|
||||||
|
//其他总价
|
||||||
|
BigDecimal otherAmount = BigDecimal.ZERO;
|
||||||
|
for(DlRepairTitem item:list){
|
||||||
|
//空字段设置默认值
|
||||||
|
if(null==item.getItemDiscount()){
|
||||||
|
item.setItemDiscount(new BigDecimal(1));
|
||||||
|
}
|
||||||
|
if(null==item.getItemPrice()){
|
||||||
|
item.setItemPrice(BigDecimal.ZERO);
|
||||||
|
}
|
||||||
|
if(null==item.getItemCount()){
|
||||||
|
item.setItemCount(1);
|
||||||
|
}
|
||||||
|
//总价
|
||||||
|
item.setItemMoney(item.getItemPrice().multiply(BigDecimal.valueOf(item.getItemCount())).multiply(item.getItemDiscount()));
|
||||||
|
//商品数量
|
||||||
|
goodsCount+=item.getItemCount();
|
||||||
|
//工单总价
|
||||||
|
totalAmount = totalAmount.add(item.getItemMoney());
|
||||||
|
if("01".equals(item.getItemType())){
|
||||||
|
//项目
|
||||||
|
proAmount = proAmount.add(item.getItemMoney());
|
||||||
|
}else if("02".equals(item.getItemType())){
|
||||||
|
//配件
|
||||||
|
waresAmount = waresAmount.add(item.getItemMoney());
|
||||||
|
}else if("03".equals(item.getItemType())){
|
||||||
|
//其他
|
||||||
|
otherAmount = otherAmount.add(item.getItemMoney());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*4.设置指定字段值*/
|
||||||
|
oldTicket.setCount(goodsCount);
|
||||||
|
oldTicket.setTotalPrice(totalAmount);
|
||||||
|
oldTicket.setProjectPrice(proAmount);
|
||||||
|
oldTicket.setPartPrice(waresAmount);
|
||||||
|
oldTicket.setOtherPrice(otherAmount);
|
||||||
|
/*5.更新数据*/
|
||||||
|
//暂不更新,只要计算不出问题就行
|
||||||
|
// titemService.updateBatchById(list);
|
||||||
|
baseMapper.updateById(oldTicket);
|
||||||
// 因为订单是在工单创建的时候就新增了,后面加的配件之类的金额没有同步到订单,这里同步一下
|
// 因为订单是在工单创建的时候就新增了,后面加的配件之类的金额没有同步到订单,这里同步一下
|
||||||
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();
|
|
||||||
newOrderInfo.setId(orderInfo.getId());
|
|
||||||
// 更新商品原价和实付金额
|
// 更新商品原价和实付金额
|
||||||
newOrderInfo.setGoodsPrice(tickets.getTotalPrice());
|
orderInfo.setGoodsPrice(totalAmount);
|
||||||
newOrderInfo.setPayMoney(tickets.getTotalPrice());
|
orderInfo.setPayMoney(totalAmount);
|
||||||
repairOrderInfoService.updateById(newOrderInfo);
|
repairOrderInfoService.updateById(orderInfo);
|
||||||
|
Long time2 = System.currentTimeMillis();
|
||||||
return baseMapper.updateById(tickets) > 0;
|
System.out.println("时间差:"+(time2-time1));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -347,13 +347,11 @@ public class DlTicketWaresServiceImpl extends ServiceImpl<DlTicketWaresMapper, D
|
|||||||
}).collect(Collectors.toList());
|
}).collect(Collectors.toList());
|
||||||
repairTitemService.saveBatch(newTitems);
|
repairTitemService.saveBatch(newTitems);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 更新维修工单主表
|
// 更新维修工单主表
|
||||||
boolean flag = repairTicketsService.computeTicket(ticketWares.getTicketId());
|
boolean flag = repairTicketsService.computeTicket(ticketWares.getTicketId());
|
||||||
if (!flag) {
|
if (!flag) {
|
||||||
throw exception0(500, "重新计算工单错误");
|
throw exception0(500, "重新计算工单错误");
|
||||||
}
|
}
|
||||||
|
|
||||||
// 发送通过的消息给仓库
|
// 发送通过的消息给仓库
|
||||||
RoleReqDTO roleInfo = roleApi.getRoleInfo(RepairRoleEnum.WAREHOUSE.getCode());
|
RoleReqDTO roleInfo = roleApi.getRoleInfo(RepairRoleEnum.WAREHOUSE.getCode());
|
||||||
List<Long> ids = permissionApi.getUserIdByRoleId(roleInfo.getId());
|
List<Long> ids = permissionApi.getUserIdByRoleId(roleInfo.getId());
|
||||||
|
Loading…
Reference in New Issue
Block a user