Commit a269d4e9ef8a33c799cd19e6ec54fa85b3891484
1 parent
012a3d0d
发货:只处理今日应该发货但状态仍是未发货的数据,避免已签收/已发货的数据被重复处理
Showing
3 changed files
with
74 additions
and
19 deletions
| ... | ... | @@ -248,30 +248,36 @@ public class ShipmentsOrderInfoController extends DefaultBaseController { |
| 248 | 248 | @GetMapping("/dataHandler") |
| 249 | 249 | @Scheduled(cron = "0 8 0 * * ?") |
| 250 | 250 | public InvokeResult<Void> dataHandler() { |
| 251 | - List<ShipmentsOrderInfo> shipmentsOrderInfoList = shipmentsOrderInfoService.queryByShipmentDate(LocalDate.now()); | |
| 251 | + // 只处理今日应该发货但状态仍是未发货的数据,避免已签收/已发货的数据被重复处理 | |
| 252 | + List<ShipmentsOrderInfo> shipmentsOrderInfoList = shipmentsOrderInfoService.queryUnShipmentsByShipmentDate(LocalDate.now()); | |
| 252 | 253 | if (CollectionUtils.isNotEmpty(shipmentsOrderInfoList)) { |
| 253 | 254 | for (ShipmentsOrderInfo orderInfo : shipmentsOrderInfoList) { |
| 254 | - ShipmentsOrderInfo shipmentsOrderInfo = shipmentsOrderInfoService.findById(orderInfo.getId()); | |
| 255 | - List<ShipmentsPlanDetail> detailList = shipmentsPlanDetailService.listByShipmentOrderId(shipmentsOrderInfo.getId()); | |
| 256 | - if (CollectionUtils.isEmpty(detailList)) { | |
| 257 | - continue; | |
| 258 | - } | |
| 259 | - List<String> orderIds = new ArrayList<>(); | |
| 260 | - List<String> orderSpecIds = new ArrayList<>(); | |
| 261 | - List<String> detailIds = new ArrayList<>(); | |
| 262 | - for (ShipmentsPlanDetail shipmentsPlanDetail : detailList) { | |
| 263 | - if (!orderIds.contains(shipmentsPlanDetail.getOrderId())) { | |
| 264 | - orderIds.add(shipmentsPlanDetail.getOrderId()); | |
| 265 | - } | |
| 266 | - if (!orderSpecIds.contains(shipmentsPlanDetail.getOrderSpecId())) { | |
| 267 | - orderSpecIds.add(shipmentsPlanDetail.getOrderSpecId()); | |
| 255 | + try { | |
| 256 | + ShipmentsOrderInfo shipmentsOrderInfo = shipmentsOrderInfoService.findById(orderInfo.getId()); | |
| 257 | + List<ShipmentsPlanDetail> detailList = shipmentsPlanDetailService.listByShipmentOrderId(shipmentsOrderInfo.getId()); | |
| 258 | + if (CollectionUtils.isEmpty(detailList)) { | |
| 259 | + continue; | |
| 268 | 260 | } |
| 269 | - if (!detailIds.contains(shipmentsPlanDetail.getId())) { | |
| 270 | - detailIds.add(shipmentsPlanDetail.getId()); | |
| 261 | + List<String> orderIds = new ArrayList<>(); | |
| 262 | + List<String> orderSpecIds = new ArrayList<>(); | |
| 263 | + List<String> detailIds = new ArrayList<>(); | |
| 264 | + for (ShipmentsPlanDetail shipmentsPlanDetail : detailList) { | |
| 265 | + if (!orderIds.contains(shipmentsPlanDetail.getOrderId())) { | |
| 266 | + orderIds.add(shipmentsPlanDetail.getOrderId()); | |
| 267 | + } | |
| 268 | + if (!orderSpecIds.contains(shipmentsPlanDetail.getOrderSpecId())) { | |
| 269 | + orderSpecIds.add(shipmentsPlanDetail.getOrderSpecId()); | |
| 270 | + } | |
| 271 | + if (!detailIds.contains(shipmentsPlanDetail.getId())) { | |
| 272 | + detailIds.add(shipmentsPlanDetail.getId()); | |
| 273 | + } | |
| 271 | 274 | } |
| 275 | + List<PurchaseOrderInfo> orderInfoList = purchaseOrderInfoService.listByIds(orderIds); | |
| 276 | + shipmentsOrderInfoService.handleData(shipmentsOrderInfo, orderInfoList, orderSpecIds, detailIds); | |
| 277 | + } catch (Exception e) { | |
| 278 | + // 单张发货单处理失败不影响其他发货单 | |
| 279 | + log.error("定时任务处理发货单 [{}] 失败:{}", orderInfo.getId(), e.getMessage(), e); | |
| 272 | 280 | } |
| 273 | - List<PurchaseOrderInfo> orderInfoList = purchaseOrderInfoService.listByIds(orderIds); | |
| 274 | - shipmentsOrderInfoService.handleData(shipmentsOrderInfo, orderInfoList, orderSpecIds, detailIds); | |
| 275 | 281 | } |
| 276 | 282 | } |
| 277 | 283 | return InvokeResultBuilder.success(); | ... | ... |
xingyun-sc/src/main/java/com/lframework/xingyun/sc/impl/shipments/ShipmentsOrderInfoServiceImpl.java
| ... | ... | @@ -705,6 +705,47 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr |
| 705 | 705 | } |
| 706 | 706 | |
| 707 | 707 | @Override |
| 708 | + public List<ShipmentsOrderInfo> queryUnShipmentsByShipmentDate(LocalDate shipmentDate) { | |
| 709 | + // 只查未发货状态 | |
| 710 | + LambdaQueryWrapper<ShipmentsOrderInfo> queryWrapper = Wrappers.lambdaQuery(ShipmentsOrderInfo.class); | |
| 711 | + queryWrapper.eq(ShipmentsOrderInfo::getStatus, "UN_SHIPMENTS"); | |
| 712 | + if (shipmentDate != null) { | |
| 713 | + LocalDate finalShipmentDate = shipmentDate; | |
| 714 | + queryWrapper.and(wrapper -> wrapper | |
| 715 | + .eq(ShipmentsOrderInfo::getShipmentsDate, finalShipmentDate) | |
| 716 | + .or() | |
| 717 | + .eq(ShipmentsOrderInfo::getNewShipmentDate, finalShipmentDate)); | |
| 718 | + } else { | |
| 719 | + shipmentDate = LocalDate.now(); | |
| 720 | + queryWrapper.and(wrapper -> wrapper | |
| 721 | + .lt(ShipmentsOrderInfo::getShipmentsDate, LocalDate.now()) | |
| 722 | + .or() | |
| 723 | + .lt(ShipmentsOrderInfo::getNewShipmentDate, LocalDate.now())); | |
| 724 | + } | |
| 725 | + List<ShipmentsOrderInfo> shipmentsOrderInfos = getBaseMapper().selectList(queryWrapper); | |
| 726 | + if (CollectionUtils.isEmpty(shipmentsOrderInfos)) { | |
| 727 | + return Collections.emptyList(); | |
| 728 | + } | |
| 729 | + // 过滤掉不符合条件的数据 | |
| 730 | + Iterator<ShipmentsOrderInfo> iterator = shipmentsOrderInfos.iterator(); | |
| 731 | + while (iterator.hasNext()) { | |
| 732 | + ShipmentsOrderInfo next = iterator.next(); | |
| 733 | + Boolean onTimeShipment = next.getOnTimeShipment(); | |
| 734 | + if (BooleanUtils.isFalse(onTimeShipment)) { | |
| 735 | + LocalDate newShipmentDate = next.getNewShipmentDate(); | |
| 736 | + if (newShipmentDate == null || newShipmentDate.isAfter(shipmentDate)) { | |
| 737 | + iterator.remove(); | |
| 738 | + } | |
| 739 | + } else { | |
| 740 | + if (next.getShipmentsDate().isAfter(shipmentDate)) { | |
| 741 | + iterator.remove(); | |
| 742 | + } | |
| 743 | + } | |
| 744 | + } | |
| 745 | + return shipmentsOrderInfos; | |
| 746 | + } | |
| 747 | + | |
| 748 | + @Override | |
| 708 | 749 | public String generateSerialNumber(String pre, String key, String format, LocalDateTime startTime, LocalDateTime endTime) { |
| 709 | 750 | // 获取当前时间,并做格式化处理 |
| 710 | 751 | String datePart = LocalDate.now().format(DateTimeFormatter.ofPattern(format)); | ... | ... |
| ... | ... | @@ -130,6 +130,14 @@ public interface ShipmentsOrderInfoService extends BaseMpService<ShipmentsOrderI |
| 130 | 130 | List<ShipmentsOrderInfo> queryByShipmentDate(LocalDate shipmentDate); |
| 131 | 131 | |
| 132 | 132 | /** |
| 133 | + * 根据发货日期获取未发货的数据 | |
| 134 | + * | |
| 135 | + * @param shipmentDate 发货日期 | |
| 136 | + * @return List<ShipmentsOrderInfo> | |
| 137 | + */ | |
| 138 | + List<ShipmentsOrderInfo> queryUnShipmentsByShipmentDate(LocalDate shipmentDate); | |
| 139 | + | |
| 140 | + /** | |
| 133 | 141 | * 生成流水号 |
| 134 | 142 | * |
| 135 | 143 | * @param pre 流水号前缀 | ... | ... |