配件申请单审核时,合并维修工单中已存在的配件

This commit is contained in:
xiaofajia 2024-10-25 15:51:03 +08:00
parent b947a96ca8
commit f1e722d302

View File

@ -150,11 +150,11 @@ public class DlTicketWaresServiceImpl extends ServiceImpl<DlTicketWaresMapper, D
String userRoleCode = repairTicketsService.getUserRole(); String userRoleCode = repairTicketsService.getUserRole();
List<DlTicketWares> result = new ArrayList<>(); List<DlTicketWares> result = new ArrayList<>();
//维修业务管理员总检服务顾问均可以进行审批 //维修业务管理员总检服务顾问均可以进行审批
if (userRoleCode.equals(RepairRoleEnum.ADMIN.getCode())|| userRoleCode.equals(RepairRoleEnum.INSPECTION.getCode())||userRoleCode.equals(RepairRoleEnum.ADVISOR.getCode())){ if (userRoleCode.equals(RepairRoleEnum.ADMIN.getCode()) || userRoleCode.equals(RepairRoleEnum.INSPECTION.getCode()) || userRoleCode.equals(RepairRoleEnum.ADVISOR.getCode())) {
LambdaQueryWrapper<DlTicketWares> lambdaQueryWrapper = new LambdaQueryWrapper<>(); LambdaQueryWrapper<DlTicketWares> lambdaQueryWrapper = new LambdaQueryWrapper<>();
lambdaQueryWrapper.eq(DlTicketWares::getTicketId,reqVO.getTicketId()); lambdaQueryWrapper.eq(DlTicketWares::getTicketId, reqVO.getTicketId());
if (null != reqVO.getStatus()){ if (null != reqVO.getStatus()) {
lambdaQueryWrapper.eq(DlTicketWares::getStatus,reqVO.getStatus()); lambdaQueryWrapper.eq(DlTicketWares::getStatus, reqVO.getStatus());
} }
result = list(lambdaQueryWrapper); result = list(lambdaQueryWrapper);
} }
@ -194,7 +194,7 @@ public class DlTicketWaresServiceImpl extends ServiceImpl<DlTicketWaresMapper, D
// 通过角色信息查有这个角色的人 // 通过角色信息查有这个角色的人
List<Long> ids = permissionApi.getUserIdByRoleId(roleInfo.getId()); List<Long> ids = permissionApi.getUserIdByRoleId(roleInfo.getId());
// 发通知 // 发通知
if (CollectionUtil.isNotEmpty(ids)){ if (CollectionUtil.isNotEmpty(ids)) {
ids.forEach(id -> repairWorkerService.sentMessage(id, "您有新的配件申请单需要审核")); ids.forEach(id -> repairWorkerService.sentMessage(id, "您有新的配件申请单需要审核"));
} }
} }
@ -241,18 +241,18 @@ public class DlTicketWaresServiceImpl extends ServiceImpl<DlTicketWaresMapper, D
// 如果是通过并且是领料就还需要把配件信息加入到工单中 // 如果是通过并且是领料就还需要把配件信息加入到工单中
if (ObjectUtil.isNotEmpty(status) && status.equals("02") && type.equals("01")) { if (ObjectUtil.isNotEmpty(status) && status.equals("02") && type.equals("01")) {
// 更新维修工单 // 更新维修工单
if(null== repairItemList || repairItemList.isEmpty()){ if (null == repairItemList || repairItemList.isEmpty()) {
repairItemList = new ArrayList<>(); repairItemList = new ArrayList<>();
//配件没传去库里面查需要的配件 //配件没传去库里面查需要的配件
LambdaQueryWrapper<DlTwItem> queryWrapper= new LambdaQueryWrapper<DlTwItem>() LambdaQueryWrapper<DlTwItem> queryWrapper = new LambdaQueryWrapper<DlTwItem>()
.eq(DlTwItem::getTwId,mainId); .eq(DlTwItem::getTwId, mainId);
List<DlTwItem> applyList = twItemService.list(queryWrapper); List<DlTwItem> applyList = twItemService.list(queryWrapper);
if(!applyList.isEmpty()){ if (!applyList.isEmpty()) {
//查配件库 //查配件库
List<RepairWares> waresList = repairWaresService.listByIds(applyList.stream().map(DlTwItem::getWaresId).collect(Collectors.toList())); List<RepairWares> waresList = repairWaresService.listByIds(applyList.stream().map(DlTwItem::getWaresId).collect(Collectors.toList()));
Map<String,RepairWares> waresMap =waresList.stream().collect(Collectors.toMap(RepairWares::getId, Function.identity())); Map<String, RepairWares> waresMap = waresList.stream().collect(Collectors.toMap(RepairWares::getId, Function.identity()));
//组装工单子表数据 //组装工单子表数据
for (DlTwItem item:applyList){ for (DlTwItem item : applyList) {
DlRepairTitem repairTitem = new DlRepairTitem(); DlRepairTitem repairTitem = new DlRepairTitem();
repairTitem.setTicketId(ticketMainId); repairTitem.setTicketId(ticketMainId);
repairTitem.setItemCount(item.getWaresCount()); repairTitem.setItemCount(item.getWaresCount());
@ -270,25 +270,53 @@ public class DlTicketWaresServiceImpl extends ServiceImpl<DlTicketWaresMapper, D
} }
} }
} }
// 计算配件的总价 // 这里是重新计算维修工单中的配件相关的信息写了一个公共的重新计算工单的方法替换掉
BigDecimal reduce = repairItemList.stream().map(DlRepairTitem::getItemMoney).reduce(BigDecimal.ZERO, BigDecimal::add); // // 计算配件的总价
repairTicketsService.update(new LambdaUpdateWrapper<DlRepairTickets>() // BigDecimal reduce = repairItemList.stream().map(DlRepairTitem::getItemMoney).reduce(BigDecimal.ZERO, BigDecimal::add);
// 工单子项总数量增加上配件的数量 // repairTicketsService.update(new LambdaUpdateWrapper<DlRepairTickets>()
.setSql("count = count + " + repairItemList.size()) // // 工单子项总数量增加上配件的数量
// 工单配件总价 // .setSql("count = count + " + repairItemList.size())
.setSql("part_price = part_price + " + reduce) // // 工单配件总价
// 工单总价 // .setSql("part_price = part_price + " + reduce)
.setSql("total_price = total_price + " + reduce) // // 工单总价
// 参考成本 // .setSql("total_price = total_price + " + reduce)
.setSql("cost = cost + " + reduce) // // 参考成本
// 参考毛利 // .setSql("cost = cost + " + reduce)
.setSql("profit = profit + " + reduce) // // 参考毛利
// 领料状态 // .setSql("profit = profit + " + reduce)
.set(DlRepairTickets::getPartStatus, "02") // // 领料状态
.eq(DlRepairTickets::getId, ticketMainId) // .set(DlRepairTickets::getPartStatus, "02")
); // .eq(DlRepairTickets::getId, ticketMainId)
// 更新维修工单子表 // );
repairItemList.forEach(item -> { // 更新维修工单子表----需要合并相同的配件故修改
// 先查维修工单的子表中的配件相关的信息
List<DlRepairTitem> oldTitem = repairTitemService.list(new LambdaQueryWrapper<DlRepairTitem>().and(i -> i.eq(DlRepairTitem::getTicketId, ticketMainId).eq(DlRepairTitem::getItemType, "02")));
// 过滤出新申请的配件里面有没有已经存在于工单子表的
List<String> waresIds = oldTitem.stream().map(DlRepairTitem::getPartId).collect(Collectors.toList());
List<DlRepairTitem> already = repairItemList.stream().filter(item -> waresIds.contains(item.getPartId())).collect(Collectors.toList());
// 更新已经存在的配件
if (CollectionUtil.isNotEmpty(already)) {
List<DlRepairTitem> updateItems = new ArrayList<>();
already.forEach(item -> {
DlRepairTitem titem = oldTitem.stream().filter(i -> i.getPartId().equals(item.getPartId())).findFirst().orElse(null);
if (titem != null) {
DlRepairTitem newItem = new DlRepairTitem();
newItem.setId(titem.getId());
newItem.setItemCount(titem.getItemCount() + item.getItemCount());
// 如果设置了折扣就用没有就是1
BigDecimal itemDiscount = titem.getItemDiscount() == null ? new BigDecimal(1) : titem.getItemDiscount();
// titem取价格newItem取数量
newItem.setItemMoney(titem.getItemPrice().multiply(BigDecimal.valueOf(newItem.getItemCount())).multiply(itemDiscount));
updateItems.add(newItem);
}
});
if (CollectionUtil.isNotEmpty(updateItems)) {
repairTitemService.updateBatchById(updateItems);
}
}
// 新增维修工单中没有的配件
List<DlRepairTitem> newItems = repairItemList.stream().filter(item -> !waresIds.contains(item.getPartId())).collect(Collectors.toList());
newItems.forEach(item -> {
// 主表id // 主表id
item.setTicketId(ticketMainId); item.setTicketId(ticketMainId);
// 类型为配件 // 类型为配件
@ -296,62 +324,70 @@ public class DlTicketWaresServiceImpl extends ServiceImpl<DlTicketWaresMapper, D
// 状态为未领料 // 状态为未领料
item.setItemStatus(TicketsItemStatusEnum.WAITING_RECEIVE.getCode()); item.setItemStatus(TicketsItemStatusEnum.WAITING_RECEIVE.getCode());
}); });
repairTitemService.saveBatch(repairItemList); repairTitemService.saveBatch(newItems);
// 重新计算工单
boolean flag = repairTicketsService.computeTicket(ticketMainId);
if (!flag) {
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());
if (CollectionUtil.isNotEmpty(ids)){ if (CollectionUtil.isNotEmpty(ids)) {
ids.forEach(id -> repairWorkerService.sentMessage(id, "您有新的配件申请单需要处理")); ids.forEach(id -> repairWorkerService.sentMessage(id, "您有新的配件申请单需要处理"));
} }
} else if (ObjectUtil.isNotEmpty(respVO.getStatus()) && respVO.getStatus().equals("02") && respVO.getType().equals("02")) {
// 如果通过退料也需要更新
// 更新维修工单
// 计算配件的总价
BigDecimal reduce = respVO.getWares().stream().map(DlRepairTitem::getItemMoney).reduce(BigDecimal.ZERO, BigDecimal::add);
repairTicketsService.update(new LambdaUpdateWrapper<DlRepairTickets>()
// 工单子项总数量增加上配件的数量
.setSql("count = count - " + respVO.getWares().size())
// 工单配件总价
.setSql("part_price = part_price - " + reduce)
// 工单总价
.setSql("total_price = total_price - " + reduce)
// 参考成本
.setSql("cost = cost - " + reduce)
// 参考毛利
.setSql("profit = profit - " + reduce)
// 领料状态
.set(DlRepairTickets::getPartStatus, "02")
.eq(DlRepairTickets::getId, respVO.getTicketId())
);
// 维修工单子表对应的数据更新
// 先查数据出来
List<DlRepairTitem> list = repairTitemService.list(new LambdaQueryWrapper<DlRepairTitem>().and(i -> {
i.eq(DlRepairTitem::getTicketId, respVO.getTicketId())
.in(DlRepairTitem::getPartId, respVO.getWares().stream().map(DlRepairTitem::getPartId).collect(Collectors.toList()));
}));
list.forEach(item -> {
respVO.getWares().stream().filter(i -> i.getPartId().equals(item.getPartId())).findFirst().ifPresent(i -> {
// 如果只是退部分就减少数量
if (!i.getItemCount().equals(item.getItemCount())) {
repairTitemService.update(new LambdaUpdateWrapper<DlRepairTitem>()
.setSql("item_count = item_count - " + i.getItemCount())
.setSql("item_money = item_money - " + i.getItemMoney())
.and(x -> {
x.eq(DlRepairTitem::getTicketId, respVO.getTicketId()).eq(DlRepairTitem::getPartId, item.getPartId());
})
);
} else {
// 如果是全部退了就直接删掉数据
repairTitemService.removeById(item.getId());
}
});
});
// 发送没有通过的消息给员工
DlTicketWares ticketWares = baseMapper.selectById(respVO.getId());
repairWorkerService.sentMessage(ticketWares.getRepairId(), "您的配件申请单被驳回了");
} }
// 下面的代码为退料申请单通过的代码但没有退料申请单可以注掉但防止有问题所以先不删除
// } else if (ObjectUtil.isNotEmpty(respVO.getStatus()) && respVO.getStatus().equals("02") && respVO.getType().equals("02")) {
// // 如果通过退料也需要更新
// // 更新维修工单
// // 计算配件的总价
// BigDecimal reduce = respVO.getWares().stream().map(DlRepairTitem::getItemMoney).reduce(BigDecimal.ZERO, BigDecimal::add);
// repairTicketsService.update(new LambdaUpdateWrapper<DlRepairTickets>()
// // 工单子项总数量增加上配件的数量
// .setSql("count = count - " + respVO.getWares().size())
// // 工单配件总价
// .setSql("part_price = part_price - " + reduce)
// // 工单总价
// .setSql("total_price = total_price - " + reduce)
// // 参考成本
// .setSql("cost = cost - " + reduce)
// // 参考毛利
// .setSql("profit = profit - " + reduce)
// // 领料状态
// .set(DlRepairTickets::getPartStatus, "02")
// .eq(DlRepairTickets::getId, respVO.getTicketId())
// );
// // 维修工单子表对应的数据更新
// // 先查数据出来
// List<DlRepairTitem> list = repairTitemService.list(new LambdaQueryWrapper<DlRepairTitem>().and(i -> {
// i.eq(DlRepairTitem::getTicketId, respVO.getTicketId())
// .in(DlRepairTitem::getPartId, respVO.getWares().stream().map(DlRepairTitem::getPartId).collect(Collectors.toList()));
// }));
// list.forEach(item -> {
// respVO.getWares().stream().filter(i -> i.getPartId().equals(item.getPartId())).findFirst().ifPresent(i -> {
// // 如果只是退部分就减少数量
// if (!i.getItemCount().equals(item.getItemCount())) {
// repairTitemService.update(new LambdaUpdateWrapper<DlRepairTitem>()
// .setSql("item_count = item_count - " + i.getItemCount())
// .setSql("item_money = item_money - " + i.getItemMoney())
// .and(x -> {
// x.eq(DlRepairTitem::getTicketId, respVO.getTicketId()).eq(DlRepairTitem::getPartId, item.getPartId());
// })
// );
// } else {
// // 如果是全部退了就直接删掉数据
// repairTitemService.removeById(item.getId());
// }
// });
// });
//
// // 发送没有通过的消息给员工
// DlTicketWares ticketWares = baseMapper.selectById(respVO.getId());
// repairWorkerService.sentMessage(ticketWares.getRepairId(), "您的配件申请单被驳回了");
// }
} }
/** /**
@ -412,7 +448,7 @@ public class DlTicketWaresServiceImpl extends ServiceImpl<DlTicketWaresMapper, D
同理通知领料的数量可能与实际需要的数量不一致需要重新计算状态 同理通知领料的数量可能与实际需要的数量不一致需要重新计算状态
*/ */
// 先查老数据领料才需要更新 // 先查老数据领料才需要更新
if (type.equals("02")){ 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>().in(DlTwItem::getId, respVO.getItems().stream().map(DlTwItem::getId).collect(Collectors.toList())));
// 构造新数据 // 构造新数据
List<DlTwItem> newData = oldData.stream().map(item -> { List<DlTwItem> newData = oldData.stream().map(item -> {
@ -492,7 +528,7 @@ public class DlTicketWaresServiceImpl extends ServiceImpl<DlTicketWaresMapper, D
respVO.setAdviserId(Long.valueOf(tickets.getAdviserId())); respVO.setAdviserId(Long.valueOf(tickets.getAdviserId()));
respVO.setAdviserName(tickets.getAdviserName()); respVO.setAdviserName(tickets.getAdviserName());
this.save(respVO); this.save(respVO);
if(!respVO.getItems().isEmpty()){ if (!respVO.getItems().isEmpty()) {
List<DlTwItem> list = respVO.getItems().stream().map(dlTwItem -> dlTwItem.setTwId(respVO.getId())).collect(Collectors.toList()); List<DlTwItem> list = respVO.getItems().stream().map(dlTwItem -> dlTwItem.setTwId(respVO.getId())).collect(Collectors.toList());
twItemService.saveBatch(list); twItemService.saveBatch(list);
} }
@ -509,8 +545,8 @@ public class DlTicketWaresServiceImpl extends ServiceImpl<DlTicketWaresMapper, D
public Map<String, Integer> getWorkerTodo() { public Map<String, Integer> getWorkerTodo() {
LoginUser loginUser = SecurityFrameworkUtils.getLoginUser(); LoginUser loginUser = SecurityFrameworkUtils.getLoginUser();
LambdaQueryWrapper<DlTicketWares> queryWrapper = new LambdaQueryWrapper<DlTicketWares>() LambdaQueryWrapper<DlTicketWares> queryWrapper = new LambdaQueryWrapper<DlTicketWares>()
.eq(DlTicketWares::getRepairId,loginUser.getId()) .eq(DlTicketWares::getRepairId, loginUser.getId())
.eq(DlTicketWares::getType,"01"); .eq(DlTicketWares::getType, "01");
List<DlTicketWares> list = this.list(queryWrapper); List<DlTicketWares> list = this.list(queryWrapper);
Map<String, Integer> rtnMap = new HashMap<>(); Map<String, Integer> rtnMap = new HashMap<>();
//所有提交的 //所有提交的
@ -520,23 +556,23 @@ public class DlTicketWaresServiceImpl extends ServiceImpl<DlTicketWaresMapper, D
//未通过的 //未通过的
Integer noAllowNum = 0; Integer noAllowNum = 0;
//待确认领料单 //待确认领料单
Integer waitingReceiveNum = dlRepairSoMapper.selectCountNum("02",loginUser.getId(), SoStatusEnum.TO_BE_PICKED.getCode()); Integer waitingReceiveNum = dlRepairSoMapper.selectCountNum("02", loginUser.getId(), SoStatusEnum.TO_BE_PICKED.getCode());
//待确认退料单 //待确认退料单
Integer waitingBackNum = dlRepairSoMapper.selectCountNum("04",loginUser.getId(), SoStatusEnum.TO_BE_RETURNED.getCode()); Integer waitingBackNum = dlRepairSoMapper.selectCountNum("04", loginUser.getId(), SoStatusEnum.TO_BE_RETURNED.getCode());
for (DlTicketWares wares:list){ for (DlTicketWares wares : list) {
if("02".equals(wares.getStatus())){ if ("02".equals(wares.getStatus())) {
//已通过 //已通过
allowNum++; allowNum++;
}else if("05".equals(wares.getStatus())){ } else if ("05".equals(wares.getStatus())) {
//被驳回 //被驳回
noAllowNum++; noAllowNum++;
} }
} }
rtnMap.put("submitNum",submitNum); rtnMap.put("submitNum", submitNum);
rtnMap.put("allowNum",allowNum); rtnMap.put("allowNum", allowNum);
rtnMap.put("noAllowNum",noAllowNum); rtnMap.put("noAllowNum", noAllowNum);
rtnMap.put("waitingReceiveNum",waitingReceiveNum); rtnMap.put("waitingReceiveNum", waitingReceiveNum);
rtnMap.put("waitingBackNum",waitingBackNum); rtnMap.put("waitingBackNum", waitingBackNum);
return rtnMap; return rtnMap;
} }