diff --git a/ruoyi-admin/src/main/java/com/ruoyi/aftersales/service/impl/AftersalesOutOrderServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/aftersales/service/impl/AftersalesOutOrderServiceImpl.java index 9566b4c1..05495858 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/aftersales/service/impl/AftersalesOutOrderServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/aftersales/service/impl/AftersalesOutOrderServiceImpl.java @@ -14,9 +14,11 @@ import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.ShiroUtils; import com.ruoyi.common.utils.StringUtils; import com.ruoyi.system.domain.SysSalesOrder; +import com.ruoyi.system.domain.SysSalesOrderChild; import com.ruoyi.system.domain.SysSalesShippingInform; import com.ruoyi.system.domain.SysSalesShippingInformDetail; import com.ruoyi.system.domain.Vo.ConfirmReceivingDetailVo; +import com.ruoyi.system.mapper.SysSalesOrderChildMapper; import com.ruoyi.system.mapper.SysSalesOrderMapper; import com.ruoyi.system.mapper.SysSalesShippingInformDetailMapper; import com.ruoyi.system.mapper.SysSalesShippingInformMapper; @@ -33,7 +35,6 @@ import com.ruoyi.common.core.text.Convert; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.CollectionUtils; -import static com.ruoyi.common.config.datasource.DynamicDataSourceContextHolder.log; /** * 售后维护设备出库Service业务层处理 @@ -66,6 +67,9 @@ public class AftersalesOutOrderServiceImpl implements IAftersalesOutOrderService @Autowired private SysSalesOrderMapper sysSalesOrderMapper; + @Autowired + private SysSalesOrderChildMapper salesOrderChildMapper; + /** * 查询售后维护设备出库 * @@ -649,12 +653,12 @@ public class AftersalesOutOrderServiceImpl implements IAftersalesOutOrderService if (!CollectionUtils.isEmpty(withoutShippingDeviceIdList)){ // 处理没有出货设备ID的数据 - allWithoutCheckFlag = processWithoutShippingDeviceId(withoutShippingDeviceIdList, allWithoutCheckFlag); + allWithoutCheckFlag = processWithoutShippingDeviceId(withoutShippingDeviceIdList, allWithoutCheckFlag,sysSalesShippingInform); } if (!CollectionUtils.isEmpty(withShippingDeviceIdList)){ // 处理有出货设备ID的数据 - allWithCheckFlag = processWithShippingDeviceId(withShippingDeviceIdList, allWithCheckFlag); + allWithCheckFlag = processWithShippingDeviceId(withShippingDeviceIdList, allWithCheckFlag,sysSalesShippingInform); } @@ -674,7 +678,40 @@ public class AftersalesOutOrderServiceImpl implements IAftersalesOutOrderService salesOrderCodes = Arrays.asList(splitSalesOrderCode); } - // List sysSalesOrders = sysSalesOrderMapper.selectSysSalesOrderListByCodeList(salesOrderCodes); + List sysSalesOrders = sysSalesOrderMapper.selectSysSalesOrderListByCodeList(salesOrderCodes); + List sysSalesOrderChildren = salesOrderChildMapper.selectBatchOrderChildListBySalesOrderCode(salesOrderCodes); + + //创建映射,用于快速查找每个销售订单号对应的子表数据 + Map> orderCodeToChildrenMap = sysSalesOrderChildren.stream().collect(Collectors.groupingBy(SysSalesOrderChild::getQuoteId)); + + + //遍历每个销售订单主表的数据 + for (SysSalesOrder sysSalesOrder : sysSalesOrders) { + String orderCode = sysSalesOrder.getSalesOrderCode(); + List childrenList = orderCodeToChildrenMap.get(orderCode); + + if (!CollectionUtils.isEmpty(childrenList)){ + + //检查子表数据的所有订单数量和已验收数量是否相等 + boolean allNumbersEqual = childrenList.stream() + .allMatch(child -> Objects.equals(child.getMaterialNum(), child.getHasCheckNum())); + if (allNumbersEqual){ + sysSalesOrder.setDeliveryStatus("8"); + }else { + sysSalesOrder.setDeliveryStatus("7"); + } + }else { + sysSalesOrder.setDeliveryStatus("7"); + } + + sysSalesOrder.setUpdateTime(new Date()); + sysSalesOrder.setUpdateBy(loginName); + int updateSysSalesOrderResult = sysSalesOrderMapper.updateSysSalesOrderBySalesOrderCode(sysSalesOrder); + if (updateSysSalesOrderResult <= 0){ + throw new BusinessException("更新销售订单数据失败"); + } + } + //设置为全部验收 if (allWithoutCheckFlag == 1 && allWithCheckFlag == 1){ @@ -718,9 +755,10 @@ public class AftersalesOutOrderServiceImpl implements IAftersalesOutOrderService } - private Integer processWithoutShippingDeviceId(List withoutShippingDeviceIdList,Integer allWithoutCheckFlag) { + private Integer processWithoutShippingDeviceId(List withoutShippingDeviceIdList,Integer allWithoutCheckFlag,SysSalesShippingInform sysSalesShippingInform) { + String loginName = ShiroUtils.getLoginName(); for (SysSalesShippingInformDetail sysSalesShippingInformDetail : withoutShippingDeviceIdList) { Long shippingInformDetailId = sysSalesShippingInformDetail.getShippingInformDetailId(); @@ -736,10 +774,50 @@ public class AftersalesOutOrderServiceImpl implements IAftersalesOutOrderService throw new BusinessException("已验收数和本次验收数之和不能大于已收货数"); } sysSalesShippingInformDetail.setThisCheckNum(null); - + sysSalesShippingInformDetail.setUpdateTime(new Date()); + sysSalesShippingInformDetail.setUpdateBy(loginName); if (Objects.equals(tempShippingInformDetail.getThisShippingNum(), sysSalesShippingInformDetail.getHasCheckNum())){ allWithoutCheckFlag = 1; } + // 当前时间 + Date now = new Date(); + + // 从数据库中查询销售出库单信息 + sysSalesShippingInform = shippingInformMapper.selectSysSalesShippingInformByCode(sysSalesShippingInform.getOutOrderCode()); + String salesOrderCode = sysSalesShippingInform.getSalesOrderCode(); + String materialNo = sysSalesShippingInformDetail.getMaterialNo(); + List salesOrderCodes = new ArrayList<>(); + + if (StringUtils.isNotEmpty(salesOrderCode)) { + salesOrderCodes = Arrays.asList(salesOrderCode.split(",")); + } + + // 存储每个销售订单详情及其计划交付时间 + List orderChildren = new ArrayList<>(); + + for (String orderCode : salesOrderCodes) { + SysSalesOrderChild sysSalesOrderChild = new SysSalesOrderChild(); + sysSalesOrderChild.setMaterialCode(materialNo); + sysSalesOrderChild.setQuoteId(orderCode); + SysSalesOrderChild tempSalesOrderChild = salesOrderChildMapper.selectSalesOrderChildByCodeAndNo(sysSalesOrderChild); + if (tempSalesOrderChild != null) { + orderChildren.add(tempSalesOrderChild); + } + } + //按照计划交付时间与当前时间的差值排序 + orderChildren.sort(Comparator.comparing(o->Math.abs(o.getDeliveryTime().getTime() - now.getTime()))); + + //更新 HasCheckNum 数据 + for (SysSalesOrderChild orderChild : orderChildren) { + orderChild.setUpdateTime(new Date()); + orderChild.setUpdateBy(loginName); + orderChild.setHasCheckNum(sysSalesShippingInformDetail.getHasCheckNum()); + int updateSalesOrderChildResult = salesOrderChildMapper.updateSysSalesOrderChildByCodeAndQuoteId(orderChild); + if (updateSalesOrderChildResult <= 0) { + throw new BusinessException("更新销售订单子表数据失败"); + } + } + int updateShippingInformDetailResult = shippingInformDetailMapper.updateSysSalesShippingInformDetail(sysSalesShippingInformDetail); if (updateShippingInformDetailResult <= 0) { @@ -749,7 +827,7 @@ public class AftersalesOutOrderServiceImpl implements IAftersalesOutOrderService return allWithoutCheckFlag; } - private Integer processWithShippingDeviceId(List withShippingDeviceIdList,Integer allWithCheckFlag) { + private Integer processWithShippingDeviceId(List withShippingDeviceIdList,Integer allWithCheckFlag,SysSalesShippingInform sysSalesShippingInform) { String loginName = ShiroUtils.getLoginName(); // List filterShippingDeviceIdList = withShippingDeviceIdList.stream() @@ -795,6 +873,65 @@ public class AftersalesOutOrderServiceImpl implements IAftersalesOutOrderService allWithCheckFlag = 1; } +// //当前时间 +// Date now = new Date(); +// SysSalesShippingInform sysSalesShippingInform = shippingInformMapper.selectSysSalesShippingInformByCode(sysSalesShippingInformDetail.getOutOrderCode()); +// String salesOrderCode = sysSalesShippingInform.getSalesOrderCode(); +// String materialNo = sysSalesShippingInformDetail.getMaterialNo(); +// List salesOrderCodes = new ArrayList<>(); +// +// if (StringUtils.isNotEmpty(salesOrderCode)){ +// String[] splitSalesOrderCode = salesOrderCode.split(","); +// salesOrderCodes = Arrays.asList(splitSalesOrderCode); +// } +// for (String orderCode : salesOrderCodes) { +// SysSalesOrderChild sysSalesOrderChild = new SysSalesOrderChild(); +// sysSalesOrderChild.setMaterialCode(materialNo); +// sysSalesOrderChild.setQuoteId(orderCode); +// SysSalesOrderChild tempSalesOrderChild = salesOrderChildMapper.selectSalesOrderChildByCodeAndNo(sysSalesOrderChild); +// long time = tempSalesOrderChild.getDeliveryTime().getTime(); +// } + + + // 当前时间 + Date now = new Date(); + + // 从数据库中查询销售出库单信息 + sysSalesShippingInform = shippingInformMapper.selectSysSalesShippingInformByCode(sysSalesShippingInform.getOutOrderCode()); + String salesOrderCode = sysSalesShippingInform.getSalesOrderCode(); + String materialNo = sysSalesShippingInformDetail.getMaterialNo(); + List salesOrderCodes = new ArrayList<>(); + + if (StringUtils.isNotEmpty(salesOrderCode)) { + salesOrderCodes = Arrays.asList(salesOrderCode.split(",")); + } + + // 存储每个销售订单详情及其计划交付时间 + List orderChildren = new ArrayList<>(); + + for (String orderCode : salesOrderCodes) { + SysSalesOrderChild sysSalesOrderChild = new SysSalesOrderChild(); + sysSalesOrderChild.setMaterialCode(materialNo); + sysSalesOrderChild.setQuoteId(orderCode); + SysSalesOrderChild tempSalesOrderChild = salesOrderChildMapper.selectSalesOrderChildByCodeAndNo(sysSalesOrderChild); + if (tempSalesOrderChild != null) { + orderChildren.add(tempSalesOrderChild); + } + } + //按照计划交付时间与当前时间的差值排序 + orderChildren.sort(Comparator.comparing(o->Math.abs(o.getDeliveryTime().getTime() - now.getTime()))); + + //更新 HasCheckNum 数据 + for (SysSalesOrderChild orderChild : orderChildren) { + orderChild.setUpdateTime(new Date()); + orderChild.setUpdateBy(loginName); + orderChild.setHasCheckNum(sysSalesShippingInformDetail.getHasCheckNum()); + int updateSalesOrderChildResult = salesOrderChildMapper.updateSysSalesOrderChildByCodeAndQuoteId(orderChild); + if (updateSalesOrderChildResult <= 0) { + throw new BusinessException("更新销售订单子表数据失败"); + } + } + int updateShippingInformDetailResult = shippingInformDetailMapper.updateSysSalesShippingInformDetail(tempShippingInformDetail); if (updateShippingInformDetailResult <= 0) { throw new BusinessException("更新销售出货通知单详情数据失败");