|
@@ -443,7 +443,8 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr |
|
@@ -443,7 +443,8 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr |
|
443
|
}
|
443
|
}
|
|
444
|
}
|
444
|
}
|
|
445
|
List<PurchaseOrderInfo> orderInfoList = purchaseOrderInfoService.listByIds(orderIds);
|
445
|
List<PurchaseOrderInfo> orderInfoList = purchaseOrderInfoService.listByIds(orderIds);
|
|
446
|
- this.handleData(data, orderInfoList, orderSpecIds, detailIds);
|
446
|
+ //todo 暂时只在填写实发数的时候处理相关数据(生成发货明细报表数据、生成台账等)
|
|
|
|
447
|
+// this.handleData(data, orderInfoList, orderSpecIds, detailIds);
|
|
447
|
}
|
448
|
}
|
|
448
|
}
|
449
|
}
|
|
449
|
|
450
|
|
|
@@ -642,12 +643,13 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr |
|
@@ -642,12 +643,13 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr |
|
642
|
}
|
643
|
}
|
|
643
|
}
|
644
|
}
|
|
644
|
// 判断当前日期是否大于等于发货日期
|
645
|
// 判断当前日期是否大于等于发货日期
|
|
645
|
- LocalDate now = LocalDate.now();
|
|
|
|
646
|
- LocalDate shipmentsDate = orderInfo.getShipmentsDate();
|
|
|
|
647
|
- if (BooleanUtils.isTrue(vo.getOnTimeShipment()) && !now.isBefore(shipmentsDate)) {
|
|
|
|
648
|
- orderInfo = findById(shipmentsOrderId);
|
646
|
+// LocalDate now = LocalDate.now();
|
|
|
|
647
|
+// LocalDate shipmentsDate = orderInfo.getShipmentsDate();
|
|
|
|
648
|
+// if (BooleanUtils.isTrue(vo.getOnTimeShipment()) && !now.isBefore(shipmentsDate)) {
|
|
|
|
649
|
+// orderInfo = findById(shipmentsOrderId);
|
|
|
|
650
|
+ //todo 填写实发数的时候就直接生成相关数据,目前暂时不考虑不是当日发货的情况
|
|
649
|
handleData(orderInfo, orderInfoList, orderSpecIds, detailIds);
|
651
|
handleData(orderInfo, orderInfoList, orderSpecIds, detailIds);
|
|
650
|
- }
|
652
|
+// }
|
|
651
|
}
|
653
|
}
|
|
652
|
|
654
|
|
|
653
|
@Override
|
655
|
@Override
|
|
@@ -882,7 +884,8 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr |
|
@@ -882,7 +884,8 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr |
|
882
|
// 生成发货明细报表数据
|
884
|
// 生成发货明细报表数据
|
|
883
|
shipmentDetailStatisticsService.generateStatisticsData(detailIds);
|
885
|
shipmentDetailStatisticsService.generateStatisticsData(detailIds);
|
|
884
|
// 生成要车计划、要车单数据
|
886
|
// 生成要车计划、要车单数据
|
|
885
|
- carRequestPlanService.generate(orderInfoList, shipmentsOrderInfo);
|
887
|
+ //todo 提前到生成发货单的时候生成要车计划、要车单数据
|
|
|
|
888
|
+// carRequestPlanService.generate(orderInfoList, shipmentsOrderInfo);
|
|
886
|
// 消息通知
|
889
|
// 消息通知
|
|
887
|
String type = shipmentsOrderInfo.getShipmentType();
|
890
|
String type = shipmentsOrderInfo.getShipmentType();
|
|
888
|
List<String> userIds = new ArrayList<>();
|
891
|
List<String> userIds = new ArrayList<>();
|
|
@@ -927,12 +930,22 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr |
|
@@ -927,12 +930,22 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr |
|
927
|
if (CollectionUtils.isNotEmpty(orderInfoList)) {
|
930
|
if (CollectionUtils.isNotEmpty(orderInfoList)) {
|
|
928
|
orderInfoMap = orderInfoList.stream().collect(Collectors.toMap(PurchaseOrderInfo::getId, Function.identity()));
|
931
|
orderInfoMap = orderInfoList.stream().collect(Collectors.toMap(PurchaseOrderInfo::getId, Function.identity()));
|
|
929
|
}
|
932
|
}
|
|
|
|
933
|
+ //先检查是否都有审核通过的草稿要车单
|
|
|
|
934
|
+ boolean allApproved = areAllDraftTicketsApproved(orderIds);
|
|
|
|
935
|
+
|
|
930
|
Map<String, BigDecimal> quantityMap = new HashMap<>();
|
936
|
Map<String, BigDecimal> quantityMap = new HashMap<>();
|
|
931
|
Map<String, String> shipmentsOrderIdMap = new HashMap<>();
|
937
|
Map<String, String> shipmentsOrderIdMap = new HashMap<>();
|
|
932
|
Map<String, List<String>> deptIdMap = new HashMap<>();
|
938
|
Map<String, List<String>> deptIdMap = new HashMap<>();
|
|
933
|
Map<String, List<String>> regionMap = new HashMap<>();
|
939
|
Map<String, List<String>> regionMap = new HashMap<>();
|
|
934
|
List<ShipmentsOrderInfo> shipmentsOrderInfoList = new ArrayList<>();
|
940
|
List<ShipmentsOrderInfo> shipmentsOrderInfoList = new ArrayList<>();
|
|
935
|
for (List<ShipmentsPlanDetail> details : batchList) {
|
941
|
for (List<ShipmentsPlanDetail> details : batchList) {
|
|
|
|
942
|
+ // 获取当前批次订货单数据
|
|
|
|
943
|
+ List<String> batchOrderIds = details.stream()
|
|
|
|
944
|
+ .map(ShipmentsPlanDetail::getOrderId)
|
|
|
|
945
|
+ .filter(Objects::nonNull)
|
|
|
|
946
|
+ .distinct()
|
|
|
|
947
|
+ .collect(Collectors.toList());
|
|
|
|
948
|
+ List<PurchaseOrderInfo> batchOrderInfoList = purchaseOrderInfoService.queryByIds(batchOrderIds);
|
|
936
|
List<String> detailIds = new ArrayList<>();
|
949
|
List<String> detailIds = new ArrayList<>();
|
|
937
|
String id = IdUtil.getId();
|
950
|
String id = IdUtil.getId();
|
|
938
|
String customerId = details.get(0).getCustomerId();
|
951
|
String customerId = details.get(0).getCustomerId();
|
|
@@ -1034,7 +1047,11 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr |
|
@@ -1034,7 +1047,11 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr |
|
1034
|
|
1047
|
|
|
1035
|
shipmentsOrderInfoList.add(shipmentsOrderInfo);
|
1048
|
shipmentsOrderInfoList.add(shipmentsOrderInfo);
|
|
1036
|
// 更新明细数据
|
1049
|
// 更新明细数据
|
|
1037
|
- shipmentsPlanDetailService.setShipmentsOrderId(detailIds, id);
|
1050
|
+ if (allApproved) {
|
|
|
|
1051
|
+ shipmentsPlanDetailService.setShipmentsOrderId(detailIds, id);
|
|
|
|
1052
|
+ //生成要车单和要车计划
|
|
|
|
1053
|
+ carRequestPlanService.generate(batchOrderInfoList, shipmentsOrderInfo);
|
|
|
|
1054
|
+ }
|
|
1038
|
}
|
1055
|
}
|
|
1039
|
// 获取所有部门数据
|
1056
|
// 获取所有部门数据
|
|
1040
|
for (ShipmentsOrderInfo orderInfo : shipmentsOrderInfoList) {
|
1057
|
for (ShipmentsOrderInfo orderInfo : shipmentsOrderInfoList) {
|
|
@@ -1050,11 +1067,10 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr |
|
@@ -1050,11 +1067,10 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr |
|
1050
|
orderInfo.setRegion(regionStr);
|
1067
|
orderInfo.setRegion(regionStr);
|
|
1051
|
}
|
1068
|
}
|
|
1052
|
}
|
1069
|
}
|
|
1053
|
- // 批量新增发货单
|
|
|
|
1054
|
- batchAdd(shipmentsOrderInfoList);
|
1070
|
+ // 先检查是否都有审核通过的草稿,再批量新增发货单,否则只生成草稿要车单
|
|
|
|
1071
|
+ generateRequestCarData(orderInfoList, orderIds, plan, quantityMap);
|
|
1055
|
// todo 后续如果数据量过大,则此处需要优化
|
1072
|
// todo 后续如果数据量过大,则此处需要优化
|
|
1056
|
- // 生成要车相关数据
|
|
|
|
1057
|
- generateRequestCarData(orderInfoList, orderIds, plan, quantityMap, shipmentsOrderIdMap);
|
1073
|
+ batchAdd(shipmentsOrderInfoList);
|
|
1058
|
// 生成发货单编号
|
1074
|
// 生成发货单编号
|
|
1059
|
// 获取当月最后一天的23:59:59
|
1075
|
// 获取当月最后一天的23:59:59
|
|
1060
|
LocalDateTime monthEnd = LocalDateTime.now()
|
1076
|
LocalDateTime monthEnd = LocalDateTime.now()
|
|
@@ -1070,6 +1086,32 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr |
|
@@ -1070,6 +1086,32 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr |
|
1070
|
getBaseMapper().setShipmentOrderCode(shipmentsOrderInfoList);
|
1086
|
getBaseMapper().setShipmentOrderCode(shipmentsOrderInfoList);
|
|
1071
|
}
|
1087
|
}
|
|
1072
|
|
1088
|
|
|
|
|
1089
|
+ /**
|
|
|
|
1090
|
+ * 检查指定的订单是否都存在审核通过的草稿要车单
|
|
|
|
1091
|
+ * @param orderIds 订单ID列表
|
|
|
|
1092
|
+ * @return true-全部审核通过;false-存在缺失或未通过的草稿
|
|
|
|
1093
|
+ */
|
|
|
|
1094
|
+ private boolean areAllDraftTicketsApproved(List<String> orderIds) {
|
|
|
|
1095
|
+ if (CollectionUtils.isEmpty(orderIds)) {
|
|
|
|
1096
|
+ return true;
|
|
|
|
1097
|
+ }
|
|
|
|
1098
|
+
|
|
|
|
1099
|
+ List<DraftRequestCarTicket> draftTickets = draftRequestCarTicketService.listByOrderId(orderIds);
|
|
|
|
1100
|
+ Map<String, DraftRequestCarTicket> draftTicketMap = new HashMap<>();
|
|
|
|
1101
|
+ if (CollectionUtils.isNotEmpty(draftTickets)) {
|
|
|
|
1102
|
+ draftTicketMap = draftTickets.stream()
|
|
|
|
1103
|
+ .collect(Collectors.toMap(DraftRequestCarTicket::getPurchaseOrderId, Function.identity(), (v1, v2) -> v2));
|
|
|
|
1104
|
+ }
|
|
|
|
1105
|
+
|
|
|
|
1106
|
+ for (String orderId : orderIds) {
|
|
|
|
1107
|
+ DraftRequestCarTicket draftTicket = draftTicketMap.get(orderId);
|
|
|
|
1108
|
+ // 只要有一个不存在,或者状态不是 PASS,直接返回 false
|
|
|
|
1109
|
+ if (draftTicket == null || !"PASS".equals(draftTicket.getStatus())) {
|
|
|
|
1110
|
+ return false;
|
|
|
|
1111
|
+ }
|
|
|
|
1112
|
+ }
|
|
|
|
1113
|
+ return true;
|
|
|
|
1114
|
+ }
|
|
1073
|
|
1115
|
|
|
1074
|
/**
|
1116
|
/**
|
|
1075
|
* 生成要车相关数据
|
1117
|
* 生成要车相关数据
|
|
@@ -1079,44 +1121,53 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr |
|
@@ -1079,44 +1121,53 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr |
|
1079
|
* @param plan 发货计划
|
1121
|
* @param plan 发货计划
|
|
1080
|
*/
|
1122
|
*/
|
|
1081
|
private void generateRequestCarData(List<PurchaseOrderInfo> orderInfoList, List<String> orderIds, ShipmentsPlan plan
|
1123
|
private void generateRequestCarData(List<PurchaseOrderInfo> orderInfoList, List<String> orderIds, ShipmentsPlan plan
|
|
1082
|
- , Map<String, BigDecimal> quantityMap, Map<String, String> shipmentsOrderIdMap) {
|
|
|
|
1083
|
- // 根据订货单获取草稿要车单
|
1124
|
+ , Map<String, BigDecimal> quantityMap) {
|
|
|
|
1125
|
+ // 1. 批量获取已有的草稿要车单
|
|
1084
|
Map<String, DraftRequestCarTicket> draftTicketMap = new HashMap<>();
|
1126
|
Map<String, DraftRequestCarTicket> draftTicketMap = new HashMap<>();
|
|
1085
|
List<DraftRequestCarTicket> draftTickets = draftRequestCarTicketService.listByOrderId(orderIds);
|
1127
|
List<DraftRequestCarTicket> draftTickets = draftRequestCarTicketService.listByOrderId(orderIds);
|
|
1086
|
if (CollectionUtils.isNotEmpty(draftTickets)) {
|
1128
|
if (CollectionUtils.isNotEmpty(draftTickets)) {
|
|
1087
|
- draftTicketMap = draftTickets.stream().collect(Collectors.toMap(DraftRequestCarTicket::getPurchaseOrderId, Function.identity()
|
|
|
|
1088
|
- , (v1, v2) -> v2));
|
1129
|
+ draftTicketMap = draftTickets.stream()
|
|
|
|
1130
|
+ .collect(Collectors.toMap(DraftRequestCarTicket::getPurchaseOrderId, Function.identity(), (v1, v2) -> v2));
|
|
1089
|
}
|
1131
|
}
|
|
|
|
1132
|
+
|
|
|
|
1133
|
+ // 标记本次循环中是否有新生成的草稿要车单
|
|
|
|
1134
|
+ boolean hasNewDraftCreated = false;
|
|
|
|
1135
|
+
|
|
1090
|
for (PurchaseOrderInfo orderInfo : orderInfoList) {
|
1136
|
for (PurchaseOrderInfo orderInfo : orderInfoList) {
|
|
1091
|
String orderId = orderInfo.getId();
|
1137
|
String orderId = orderInfo.getId();
|
|
1092
|
DraftRequestCarTicket draftTicket = draftTicketMap.get(orderId);
|
1138
|
DraftRequestCarTicket draftTicket = draftTicketMap.get(orderId);
|
|
1093
|
BigDecimal quantity = quantityMap.get(orderId);
|
1139
|
BigDecimal quantity = quantityMap.get(orderId);
|
|
1094
|
- String shipmentsOrderId = shipmentsOrderIdMap.get(orderId);
|
|
|
|
1095
|
if (draftTicket == null) {
|
1140
|
if (draftTicket == null) {
|
|
|
|
1141
|
+ // 【第一阶段:生成草稿】
|
|
1096
|
// 生成草稿要车单
|
1142
|
// 生成草稿要车单
|
|
1097
|
CreateDraftRequestCarTicketVo createVo = packDraftRequestCarTicket(orderInfo, plan.getTomoPreShipDate(), quantity);
|
1143
|
CreateDraftRequestCarTicketVo createVo = packDraftRequestCarTicket(orderInfo, plan.getTomoPreShipDate(), quantity);
|
|
1098
|
- String draftId = draftRequestCarTicketService.create(createVo);
|
|
|
|
1099
|
- // 草稿要车单ID和发货单ID映射
|
|
|
|
1100
|
- redisHandler.set("GET_SHIPMENTS_ORDER_ID_" + draftId, shipmentsOrderId);
|
|
|
|
1101
|
- //发送消息提醒业务员(发货单中合同创建人)补充草稿要车单相关数据
|
1144
|
+ draftRequestCarTicketService.create(createVo);
|
|
|
|
1145
|
+ // 发送消息提醒业务员补充数据
|
|
1102
|
SysSiteMessageDto messageDto = new SysSiteMessageDto();
|
1146
|
SysSiteMessageDto messageDto = new SysSiteMessageDto();
|
|
1103
|
List<String> userIdList = new ArrayList<>();
|
1147
|
List<String> userIdList = new ArrayList<>();
|
|
1104
|
userIdList.add(orderInfo.getContractCreateById());
|
1148
|
userIdList.add(orderInfo.getContractCreateById());
|
|
1105
|
messageDto.setUserIdList(userIdList);
|
1149
|
messageDto.setUserIdList(userIdList);
|
|
1106
|
messageDto.setTitle("草稿要车单补充通知");
|
1150
|
messageDto.setTitle("草稿要车单补充通知");
|
|
1107
|
- messageDto.setContent("您有新的草稿要车单需要补充,请尽快完成!");
|
1151
|
+ messageDto.setContent("您有新的草稿要车单需要补充,请尽快完成!订单编号:" + orderInfo.getOrderNo());
|
|
1108
|
messageDto.setBizKey(IdUtil.getId());
|
1152
|
messageDto.setBizKey(IdUtil.getId());
|
|
1109
|
- //如果是空表示由系统自动发起
|
|
|
|
1110
|
- messageDto.setCreateUserId(null);
|
1153
|
+ messageDto.setCreateUserId(null); // 系统自动发起
|
|
1111
|
mqProducerService.createSysSiteMessage(messageDto);
|
1154
|
mqProducerService.createSysSiteMessage(messageDto);
|
|
1112
|
- // 更新发货单状态为草稿
|
|
|
|
1113
|
- updateStatus(shipmentsOrderId, "DRAFT");
|
|
|
|
1114
|
- continue;
|
|
|
|
1115
|
- }
|
|
|
|
1116
|
- if (!"PASS".equals(draftTicket.getStatus())) {
|
|
|
|
1117
|
- throw new DefaultClientException("请先补充草稿要车单数据!");
|
1155
|
+
|
|
|
|
1156
|
+ // 标记已生成新草稿
|
|
|
|
1157
|
+ hasNewDraftCreated = true;
|
|
|
|
1158
|
+
|
|
|
|
1159
|
+ } else if (!"PASS".equals(draftTicket.getStatus())) {
|
|
|
|
1160
|
+ // 如果草稿已存在但未通过审核,也标记为需要补充
|
|
|
|
1161
|
+ hasNewDraftCreated = true;
|
|
1118
|
}
|
1162
|
}
|
|
1119
|
}
|
1163
|
}
|
|
|
|
1164
|
+
|
|
|
|
1165
|
+ // 【第二阶段:统一校验并返回提示】
|
|
|
|
1166
|
+ // 循环结束后,只要生成了新的草稿或有未通过的草稿,就统一抛出异常
|
|
|
|
1167
|
+ // 这样既保证了所有草稿都被创建,又实现了已创建数据不回退的效果
|
|
|
|
1168
|
+ if (hasNewDraftCreated) {
|
|
|
|
1169
|
+ throw new DefaultClientException("请先补充草稿要车单数据!");
|
|
|
|
1170
|
+ }
|
|
1120
|
}
|
1171
|
}
|
|
1121
|
|
1172
|
|
|
1122
|
|
1173
|
|