diff --git a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/service/impl/DlRepairTicketsServiceImpl.java b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/service/impl/DlRepairTicketsServiceImpl.java index 50c32faa..e7720842 100644 --- a/dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/service/impl/DlRepairTicketsServiceImpl.java +++ b/dl-module-repair/src/main/java/cn/iocoder/yudao/module/tickets/service/impl/DlRepairTicketsServiceImpl.java @@ -217,7 +217,6 @@ public class DlRepairTicketsServiceImpl extends ServiceImpl list = customerService.list(new LambdaQueryWrapper().eq(CustomerMain::getPhoneNumber, customerAndCarVO.getUserInfo().getPhoneNumber())); - if (CollectionUtil.isNotEmpty(list)){ + if (CollectionUtil.isNotEmpty(list)) { throw exception0(500, "电话号码重复"); } customerService.save(customerAndCarVO.getUserInfo()); // 如果新增了数据,id没有回填 - if (ObjectUtil.isEmpty(customerAndCarVO.getUserInfo().getId())){ + if (ObjectUtil.isEmpty(customerAndCarVO.getUserInfo().getId())) { CustomerMain byPhoneNumber = customerService.getOne(new LambdaQueryWrapper().eq(CustomerMain::getPhoneNumber, customerAndCarVO.getUserInfo().getPhoneNumber())); customerAndCarVO.getUserInfo().setId(byPhoneNumber.getId()); } @@ -469,12 +468,12 @@ public class DlRepairTicketsServiceImpl extends ServiceImpl list = carMainService.list(new LambdaQueryWrapper().eq(CarMain::getLicenseNumber, customerAndCarVO.getCarInfo().getLicenseNumber())); - if (CollectionUtil.isNotEmpty(list)){ + if (CollectionUtil.isNotEmpty(list)) { throw exception0(500, "车牌重复"); } carMainService.createCarMain(customerAndCarVO.getCarInfo()); // 如果新增了数据,id没有回填 - if (ObjectUtil.isEmpty(customerAndCarVO.getCarInfo().getId())){ + if (ObjectUtil.isEmpty(customerAndCarVO.getCarInfo().getId())) { CarMain byLicenseNumber = carMainService.getOne(new LambdaQueryWrapper().eq(CarMain::getLicenseNumber, customerAndCarVO.getCarInfo().getLicenseNumber())); customerAndCarVO.getCarInfo().setId(byLicenseNumber.getId()); } @@ -514,7 +513,7 @@ public class DlRepairTicketsServiceImpl extends ServiceImpl userIds = new ArrayList<>(); - for (RepairWorker worker:list){ + for (RepairWorker worker : list) { userIds.add(worker.getUserId()); - if("".equals(userIdsStr)){ + if ("".equals(userIdsStr)) { userIdsStr = String.valueOf(worker.getUserId()); - }else{ - userIdsStr = ","+worker.getUserId(); + } else { + userIdsStr = "," + worker.getUserId(); } } repairTicketsReqVO.setUserIds(userIds); @@ -1176,56 +1175,54 @@ public class DlRepairTicketsServiceImpl extends ServiceImpl ids = list.stream().map(DlTicketWares::getId).collect(Collectors.toList()); - List twItems = new ArrayList<>(); - if (CollectionUtil.isNotEmpty(ids)){ - twItems = twItemService.list(new LambdaQueryWrapper().and(item -> { + if (CollectionUtil.isNotEmpty(list)) { + // 查配件申请表的所有已领取数量小于申请数量的子表信息 + List ids = list.stream().map(DlTicketWares::getId).collect(Collectors.toList()); + List twItems = twItemService.list(new LambdaQueryWrapper().and(item -> { item.in(DlTwItem::getTwId, ids) .apply("wares_already_count < wares_count"); })); - } - if (CollectionUtil.isNotEmpty(twItems)) { - // 更新工单子表(主要是把已领料的字段同步给工单配件的数量字段) - // 查询工单子表(三个查询条件,属于那个工单,属于配件类型,属于需要改变的(即申请表的已领取数量小于申请数量的)) - Set waresId = twItems.stream().map(DlTwItem::getWaresId).collect(Collectors.toSet()); - List items = titemService.list(new LambdaQueryWrapper().and(item -> { - item.eq(DlRepairTitem::getTicketId, id) - .eq(DlRepairTitem::getItemType, "02") - .in(DlRepairTitem::getPartId, waresId); - })); - // 同一个配件可能申请过多次,属于是一个工单配件可能是对应多个申请表配件 - List finalTwItems = twItems; - List AllItems = items.stream().map(item -> { - DlRepairTitem titem = new DlRepairTitem(); - titem.setId(item.getId()); - List wares = finalTwItems.stream().filter(i -> i.getWaresId().equals(item.getPartId())).collect(Collectors.toList()); - int sum = wares.stream().mapToInt(DlTwItem::getWaresAlreadyCount).sum(); - titem.setItemCount(sum); - BigDecimal discount = item.getItemDiscount() == null ? BigDecimal.ONE : item.getItemDiscount(); - titem.setItemMoney(item.getItemPrice().multiply(BigDecimal.valueOf(sum)).multiply(discount)); - return titem; - }).collect(Collectors.toList()); + if (CollectionUtil.isNotEmpty(twItems)) { + // 更新工单子表(主要是把已领料的字段同步给工单配件的数量字段) + // 查询工单子表(三个查询条件,属于那个工单,属于配件类型,属于需要改变的(即申请表的已领取数量小于申请数量的)) + Set waresId = twItems.stream().map(DlTwItem::getWaresId).collect(Collectors.toSet()); + List items = titemService.list(new LambdaQueryWrapper().and(item -> { + item.eq(DlRepairTitem::getTicketId, id) + .eq(DlRepairTitem::getItemType, "02") + .in(DlRepairTitem::getPartId, waresId); + })); + // 同一个配件可能申请过多次,属于是一个工单配件可能是对应多个申请表配件 + List AllItems = items.stream().map(item -> { + DlRepairTitem titem = new DlRepairTitem(); + titem.setId(item.getId()); + List wares = twItems.stream().filter(i -> i.getWaresId().equals(item.getPartId())).collect(Collectors.toList()); + int sum = wares.stream().mapToInt(DlTwItem::getWaresAlreadyCount).sum(); + titem.setItemCount(sum); + BigDecimal discount = item.getItemDiscount() == null ? BigDecimal.ONE : item.getItemDiscount(); + titem.setItemMoney(item.getItemPrice().multiply(BigDecimal.valueOf(sum)).multiply(discount)); + return titem; + }).collect(Collectors.toList()); - // 可能出现配件申请单审核通过了没有任何领取或全部退了的情况,所以如果itemCount等于0,直接把这个数据删掉 - // 过滤出需要删除的数据 - List delItems = AllItems.stream().filter(item -> item.getItemCount() == 0).collect(Collectors.toList()); - if (CollectionUtil.isNotEmpty(delItems)) { - // 删除需要删的 - titemService.removeBatchByIds(delItems); - Set delIds = delItems.stream().map(DlRepairTitem::getId).collect(Collectors.toSet()); - // 得到需要改的 - List updateItems = AllItems.stream().filter(item -> delIds.contains(item.getId())).collect(Collectors.toList()); - if (CollectionUtil.isNotEmpty(updateItems)) { - titemService.updateBatchById(updateItems); + // 可能出现配件申请单审核通过了没有任何领取或全部退了的情况,所以如果itemCount等于0,直接把这个数据删掉 + // 过滤出需要删除的数据 + List delItems = AllItems.stream().filter(item -> item.getItemCount() == 0).collect(Collectors.toList()); + if (CollectionUtil.isNotEmpty(delItems)) { + // 删除需要删的 + titemService.removeBatchByIds(delItems); + Set delIds = delItems.stream().map(DlRepairTitem::getId).collect(Collectors.toSet()); + // 得到需要改的 + List updateItems = AllItems.stream().filter(item -> delIds.contains(item.getId())).collect(Collectors.toList()); + if (CollectionUtil.isNotEmpty(updateItems)) { + titemService.updateBatchById(updateItems); + } + } else { + // 没有需要删的就是全部都需要改 + titemService.updateBatchById(AllItems); } - } else { - // 没有需要删的就是全部都需要改 - titemService.updateBatchById(AllItems); - } - // 重新计算维修工单 - return computeTicket(id); + // 重新计算维修工单 + return computeTicket(id); + } } return true; } @@ -1335,7 +1332,7 @@ public class DlRepairTicketsServiceImpl extends ServiceImpl list = titemService.list(new LambdaQueryWrapper().eq(DlRepairTitem::getTicketId, ticketId)); // 计算子表 - if (CollectionUtil.isEmpty(list)){ + if (CollectionUtil.isEmpty(list)) { throw exception0(500, "没有项目、配件或其他"); } List updateItems = list.stream().map(item -> { @@ -1516,19 +1513,19 @@ public class DlRepairTicketsServiceImpl extends ServiceImpl().eq(RepairOrderInfo::getGoodsId, id)); // 删除工单