|
@@ -13,8 +13,7 @@ import com.lframework.xingyun.basedata.entity.Customer; |
|
@@ -13,8 +13,7 @@ import com.lframework.xingyun.basedata.entity.Customer; |
|
13
|
import com.lframework.xingyun.basedata.entity.Workshop;
|
13
|
import com.lframework.xingyun.basedata.entity.Workshop;
|
|
14
|
import com.lframework.xingyun.basedata.service.customer.CustomerService;
|
14
|
import com.lframework.xingyun.basedata.service.customer.CustomerService;
|
|
15
|
import com.lframework.xingyun.basedata.service.workshop.WorkshopService;
|
15
|
import com.lframework.xingyun.basedata.service.workshop.WorkshopService;
|
|
16
|
-import com.lframework.xingyun.sc.entity.PurchaseOrderInfo;
|
|
|
|
17
|
-import com.lframework.xingyun.sc.entity.ShipmentsOrderInfo;
|
16
|
+import com.lframework.xingyun.sc.entity.*;
|
|
18
|
import com.lframework.starter.web.core.impl.BaseMpServiceImpl;
|
17
|
import com.lframework.starter.web.core.impl.BaseMpServiceImpl;
|
|
19
|
import com.lframework.starter.web.core.components.resp.PageResult;
|
18
|
import com.lframework.starter.web.core.components.resp.PageResult;
|
|
20
|
import com.lframework.starter.common.exceptions.impl.DefaultClientException;
|
19
|
import com.lframework.starter.common.exceptions.impl.DefaultClientException;
|
|
@@ -22,12 +21,16 @@ import com.lframework.starter.common.utils.ObjectUtil; |
|
@@ -22,12 +21,16 @@ import com.lframework.starter.common.utils.ObjectUtil; |
|
22
|
import com.lframework.starter.web.core.annotations.oplog.OpLog;
|
21
|
import com.lframework.starter.web.core.annotations.oplog.OpLog;
|
|
23
|
import com.lframework.starter.common.utils.Assert;
|
22
|
import com.lframework.starter.common.utils.Assert;
|
|
24
|
import com.lframework.starter.web.inner.components.oplog.OtherOpLogType;
|
23
|
import com.lframework.starter.web.inner.components.oplog.OtherOpLogType;
|
|
25
|
-import com.lframework.xingyun.sc.entity.ShipmentsPlan;
|
|
|
|
26
|
-import com.lframework.xingyun.sc.entity.ShipmentsPlanDetail;
|
|
|
|
27
|
import com.lframework.xingyun.sc.service.order.PurchaseOrderInfoService;
|
24
|
import com.lframework.xingyun.sc.service.order.PurchaseOrderInfoService;
|
|
28
|
import com.lframework.xingyun.sc.service.shipments.ShipmentsPlanDetailService;
|
25
|
import com.lframework.xingyun.sc.service.shipments.ShipmentsPlanDetailService;
|
|
29
|
import com.lframework.xingyun.sc.service.shipments.ShipmentsPlanService;
|
26
|
import com.lframework.xingyun.sc.service.shipments.ShipmentsPlanService;
|
|
|
|
27
|
+import com.lframework.xingyun.sc.service.shipments.car.CarRequestPlanService;
|
|
|
|
28
|
+import com.lframework.xingyun.sc.service.shipments.car.DraftRequestCarTicketService;
|
|
|
|
29
|
+import com.lframework.xingyun.sc.service.shipments.car.RequestCarTicketService;
|
|
30
|
import com.lframework.xingyun.sc.utils.CommonUtil;
|
30
|
import com.lframework.xingyun.sc.utils.CommonUtil;
|
|
|
|
31
|
+import com.lframework.xingyun.sc.vo.shipments.car.CreateCarRequestPlanVo;
|
|
|
|
32
|
+import com.lframework.xingyun.sc.vo.shipments.car.CreateDraftRequestCarTicketVo;
|
|
|
|
33
|
+import com.lframework.xingyun.sc.vo.shipments.car.CreateRequestCarTicketVo;
|
|
31
|
import com.lframework.xingyun.sc.vo.shipments.order.GenerateShipmentsOrderVo;
|
34
|
import com.lframework.xingyun.sc.vo.shipments.order.GenerateShipmentsOrderVo;
|
|
32
|
import lombok.extern.slf4j.Slf4j;
|
35
|
import lombok.extern.slf4j.Slf4j;
|
|
33
|
import org.apache.commons.collections4.CollectionUtils;
|
36
|
import org.apache.commons.collections4.CollectionUtils;
|
|
@@ -41,6 +44,8 @@ import com.lframework.xingyun.sc.vo.shipments.order.UpdateShipmentsOrderInfoVo; |
|
@@ -41,6 +44,8 @@ import com.lframework.xingyun.sc.vo.shipments.order.UpdateShipmentsOrderInfoVo; |
|
41
|
import org.springframework.stereotype.Service;
|
44
|
import org.springframework.stereotype.Service;
|
|
42
|
|
45
|
|
|
43
|
import javax.annotation.Resource;
|
46
|
import javax.annotation.Resource;
|
|
|
|
47
|
+import java.math.BigDecimal;
|
|
|
|
48
|
+import java.time.LocalDate;
|
|
44
|
import java.util.*;
|
49
|
import java.util.*;
|
|
45
|
import java.util.function.Function;
|
50
|
import java.util.function.Function;
|
|
46
|
import java.util.stream.Collectors;
|
51
|
import java.util.stream.Collectors;
|
|
@@ -61,6 +66,12 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr |
|
@@ -61,6 +66,12 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr |
|
61
|
private DicCityService dicCityService;
|
66
|
private DicCityService dicCityService;
|
|
62
|
@Resource
|
67
|
@Resource
|
|
63
|
private PurchaseOrderInfoService purchaseOrderInfoService;
|
68
|
private PurchaseOrderInfoService purchaseOrderInfoService;
|
|
|
|
69
|
+ @Resource
|
|
|
|
70
|
+ private DraftRequestCarTicketService draftRequestCarTicketService;
|
|
|
|
71
|
+ @Resource
|
|
|
|
72
|
+ private CarRequestPlanService carRequestPlanService;
|
|
|
|
73
|
+ @Resource
|
|
|
|
74
|
+ private RequestCarTicketService requestCarTicketService;
|
|
64
|
|
75
|
|
|
65
|
|
76
|
|
|
66
|
@Override
|
77
|
@Override
|
|
@@ -213,6 +224,7 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr |
|
@@ -213,6 +224,7 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr |
|
213
|
}
|
224
|
}
|
|
214
|
|
225
|
|
|
215
|
@Override
|
226
|
@Override
|
|
|
|
227
|
+ @Transactional(rollbackFor = Exception.class)
|
|
216
|
public void generate(GenerateShipmentsOrderVo vo) {
|
228
|
public void generate(GenerateShipmentsOrderVo vo) {
|
|
217
|
String planId = vo.getPlanId();
|
229
|
String planId = vo.getPlanId();
|
|
218
|
String type = vo.getType();
|
230
|
String type = vo.getType();
|
|
@@ -278,7 +290,7 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr |
|
@@ -278,7 +290,7 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr |
|
278
|
.collect(Collectors.toList());
|
290
|
.collect(Collectors.toList());
|
|
279
|
List<PurchaseOrderInfo> orderInfoList = purchaseOrderInfoService.queryByIds(orderIds);
|
291
|
List<PurchaseOrderInfo> orderInfoList = purchaseOrderInfoService.queryByIds(orderIds);
|
|
280
|
Map<String, PurchaseOrderInfo> orderInfoMap = new HashMap<>();
|
292
|
Map<String, PurchaseOrderInfo> orderInfoMap = new HashMap<>();
|
|
281
|
- if (CollectionUtils.isEmpty(orderInfoList)) {
|
293
|
+ if (CollectionUtils.isNotEmpty(orderInfoList)) {
|
|
282
|
orderInfoMap = orderInfoList.stream().collect(Collectors.toMap(PurchaseOrderInfo::getId, Function.identity()));
|
294
|
orderInfoMap = orderInfoList.stream().collect(Collectors.toMap(PurchaseOrderInfo::getId, Function.identity()));
|
|
283
|
}
|
295
|
}
|
|
284
|
Map<String, List<String>> deptIdMap = new HashMap<>();
|
296
|
Map<String, List<String>> deptIdMap = new HashMap<>();
|
|
@@ -306,20 +318,20 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr |
|
@@ -306,20 +318,20 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr |
|
306
|
}
|
318
|
}
|
|
307
|
// 办事处
|
319
|
// 办事处
|
|
308
|
List<String> list = deptIdMap.computeIfAbsent(id, k -> new ArrayList<>());
|
320
|
List<String> list = deptIdMap.computeIfAbsent(id, k -> new ArrayList<>());
|
|
309
|
- if (list.contains(orderInfo.getDeptId())) {
|
321
|
+ if (!list.contains(orderInfo.getDeptId())) {
|
|
310
|
list.add(orderInfo.getDeptId());
|
322
|
list.add(orderInfo.getDeptId());
|
|
311
|
}
|
323
|
}
|
|
312
|
// 交货方式
|
324
|
// 交货方式
|
|
313
|
String deliveryMethod = orderInfo.getDeliveryMethod();
|
325
|
String deliveryMethod = orderInfo.getDeliveryMethod();
|
|
314
|
if (StringUtils.isNotBlank(deliveryMethod) && !deliveryTypeSet.contains(deliveryMethod)) {
|
326
|
if (StringUtils.isNotBlank(deliveryMethod) && !deliveryTypeSet.contains(deliveryMethod)) {
|
|
315
|
deliveryTypeSet.add(deliveryMethod);
|
327
|
deliveryTypeSet.add(deliveryMethod);
|
|
316
|
- deliveryTypeBuilder.append(deliveryMethod).append(",");
|
328
|
+ deliveryTypeBuilder.append(deliveryMethod).append(" | ");
|
|
317
|
}
|
329
|
}
|
|
318
|
// 付款方式
|
330
|
// 付款方式
|
|
319
|
String paymentType = orderInfo.getSettlementTerms();
|
331
|
String paymentType = orderInfo.getSettlementTerms();
|
|
320
|
if (StringUtils.isNotBlank(paymentType) && !paymentTypeSet.contains(paymentType)) {
|
332
|
if (StringUtils.isNotBlank(paymentType) && !paymentTypeSet.contains(paymentType)) {
|
|
321
|
paymentTypeSet.add(paymentType);
|
333
|
paymentTypeSet.add(paymentType);
|
|
322
|
- paymentTypeBuilder.append(paymentType).append(",");
|
334
|
+ paymentTypeBuilder.append(paymentType).append(" | ");
|
|
323
|
}
|
335
|
}
|
|
324
|
// 目的地
|
336
|
// 目的地
|
|
325
|
String destination = orderInfo.getDestination();
|
337
|
String destination = orderInfo.getDestination();
|
|
@@ -329,16 +341,20 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr |
|
@@ -329,16 +341,20 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr |
|
329
|
for (DicCityDto cityDto : fullPath) {
|
341
|
for (DicCityDto cityDto : fullPath) {
|
|
330
|
destinationBuilder.append(cityDto.getName()).append(",");
|
342
|
destinationBuilder.append(cityDto.getName()).append(",");
|
|
331
|
}
|
343
|
}
|
|
|
|
344
|
+ if (destinationBuilder.length() > 0) {
|
|
|
|
345
|
+ destinationBuilder.setLength(destinationBuilder.length() - 1);
|
|
|
|
346
|
+ destinationBuilder.append(" | ");
|
|
|
|
347
|
+ }
|
|
332
|
}
|
348
|
}
|
|
333
|
}
|
349
|
}
|
|
334
|
- if (deliveryTypeBuilder.length() > 0) {
|
|
|
|
335
|
- deliveryTypeBuilder.setLength(deliveryTypeBuilder.length() - 1);
|
350
|
+ if (deliveryTypeBuilder.length() > 3) {
|
|
|
|
351
|
+ deliveryTypeBuilder.setLength(deliveryTypeBuilder.length() - 3);
|
|
336
|
}
|
352
|
}
|
|
337
|
- if (destinationBuilder.length() > 0) {
|
|
|
|
338
|
- destinationBuilder.setLength(destinationBuilder.length() - 1);
|
353
|
+ if (destinationBuilder.length() > 3) {
|
|
|
|
354
|
+ destinationBuilder.setLength(destinationBuilder.length() - 3);
|
|
339
|
}
|
355
|
}
|
|
340
|
- if (paymentTypeBuilder.length() > 0) {
|
|
|
|
341
|
- paymentTypeBuilder.setLength(paymentTypeBuilder.length() - 1);
|
356
|
+ if (paymentTypeBuilder.length() > 3) {
|
|
|
|
357
|
+ paymentTypeBuilder.setLength(paymentTypeBuilder.length() - 3);
|
|
342
|
}
|
358
|
}
|
|
343
|
// 封装发货单数据
|
359
|
// 封装发货单数据
|
|
344
|
ShipmentsOrderInfo shipmentsOrderInfo = new ShipmentsOrderInfo();
|
360
|
ShipmentsOrderInfo shipmentsOrderInfo = new ShipmentsOrderInfo();
|
|
@@ -369,5 +385,92 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr |
|
@@ -369,5 +385,92 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr |
|
369
|
}
|
385
|
}
|
|
370
|
// 批量新增发货单
|
386
|
// 批量新增发货单
|
|
371
|
batchAdd(shipmentsOrderInfoList);
|
387
|
batchAdd(shipmentsOrderInfoList);
|
|
|
|
388
|
+ // todo 后续如果数据量过大,则此处需要优化
|
|
|
|
389
|
+ // 生成要车相关数据
|
|
|
|
390
|
+ generateRequestCarData(orderInfoList, orderIds, plan);
|
|
|
|
391
|
+ }
|
|
|
|
392
|
+
|
|
|
|
393
|
+
|
|
|
|
394
|
+ /**
|
|
|
|
395
|
+ * 生成要车相关数据
|
|
|
|
396
|
+ *
|
|
|
|
397
|
+ * @param orderInfoList 订货单数据集合
|
|
|
|
398
|
+ * @param orderIds 订货单ID集合
|
|
|
|
399
|
+ * @param plan 发货计划
|
|
|
|
400
|
+ */
|
|
|
|
401
|
+ private void generateRequestCarData(List<PurchaseOrderInfo> orderInfoList, List<String> orderIds, ShipmentsPlan plan) {
|
|
|
|
402
|
+ // 根据订货单获取草稿要车单
|
|
|
|
403
|
+ Map<String, DraftRequestCarTicket> draftTicketMap = new HashMap<>();
|
|
|
|
404
|
+ List<DraftRequestCarTicket> draftTickets = draftRequestCarTicketService.listByOrderId(orderIds);
|
|
|
|
405
|
+ if (CollectionUtils.isNotEmpty(draftTickets)) {
|
|
|
|
406
|
+ draftTicketMap = draftTickets.stream().collect(Collectors.toMap(DraftRequestCarTicket::getOrderingUnit, Function.identity()
|
|
|
|
407
|
+ , (v1, v2) -> v2));
|
|
|
|
408
|
+ }
|
|
|
|
409
|
+ for (PurchaseOrderInfo orderInfo : orderInfoList) {
|
|
|
|
410
|
+ String status = orderInfo.getStatus();
|
|
|
|
411
|
+ if ("ISSUED".equals(status)) {
|
|
|
|
412
|
+ // 生成草稿要车单
|
|
|
|
413
|
+ CreateDraftRequestCarTicketVo createVo = packDraftRequestCarTicket(orderInfo, plan.getTomoPreShipDate());
|
|
|
|
414
|
+ draftRequestCarTicketService.create(createVo);
|
|
|
|
415
|
+ } else {
|
|
|
|
416
|
+ // 生成要车计划
|
|
|
|
417
|
+ CreateCarRequestPlanVo planCreateVo = new CreateCarRequestPlanVo();
|
|
|
|
418
|
+ planCreateVo.setRequestCarDate(LocalDate.now());
|
|
|
|
419
|
+ planCreateVo.setWorkshopId(orderInfo.getWorkshopId());
|
|
|
|
420
|
+ String requestCarPlanId = carRequestPlanService.create(planCreateVo);
|
|
|
|
421
|
+ // 生成要车单
|
|
|
|
422
|
+ DraftRequestCarTicket draftTicket = draftTicketMap.get(orderInfo.getId());
|
|
|
|
423
|
+ CreateRequestCarTicketVo ticketCreateVo = packRequestCarTicket(orderInfo, requestCarPlanId, draftTicket == null
|
|
|
|
424
|
+ ? null : draftTicket.getId(), plan.getTomoPreShipDate());
|
|
|
|
425
|
+ requestCarTicketService.create(ticketCreateVo);
|
|
|
|
426
|
+ }
|
|
|
|
427
|
+ }
|
|
|
|
428
|
+ }
|
|
|
|
429
|
+
|
|
|
|
430
|
+
|
|
|
|
431
|
+ /**
|
|
|
|
432
|
+ * 封装草稿要车单数据
|
|
|
|
433
|
+ *
|
|
|
|
434
|
+ * @param orderInfo 订货单数据
|
|
|
|
435
|
+ * @param shipmentsDate 发货日期
|
|
|
|
436
|
+ * @return CreateDraftRequestCarTicketVo
|
|
|
|
437
|
+ */
|
|
|
|
438
|
+ private CreateDraftRequestCarTicketVo packDraftRequestCarTicket(PurchaseOrderInfo orderInfo, LocalDate shipmentsDate) {
|
|
|
|
439
|
+ CreateDraftRequestCarTicketVo draftTicketVo = new CreateDraftRequestCarTicketVo();
|
|
|
|
440
|
+ draftTicketVo.setPurchaseOrderId(orderInfo.getId());
|
|
|
|
441
|
+ draftTicketVo.setDeptId(orderInfo.getDeptId());
|
|
|
|
442
|
+ draftTicketVo.setDeliveryDate(shipmentsDate);
|
|
|
|
443
|
+ draftTicketVo.setWorkshopId(orderInfo.getWorkshopId());
|
|
|
|
444
|
+ draftTicketVo.setOrderNo(orderInfo.getOrderNo());
|
|
|
|
445
|
+ draftTicketVo.setOrderingUnit(orderInfo.getOrderingUnit());
|
|
|
|
446
|
+ if (orderInfo.getTotalQuantity() != null) {
|
|
|
|
447
|
+ BigDecimal result = orderInfo.getTotalQuantity().divide(new BigDecimal(1000), 4, BigDecimal.ROUND_HALF_UP);
|
|
|
|
448
|
+ draftTicketVo.setQuantity(result);
|
|
|
|
449
|
+ }
|
|
|
|
450
|
+ return draftTicketVo;
|
|
|
|
451
|
+ }
|
|
|
|
452
|
+
|
|
|
|
453
|
+ /**
|
|
|
|
454
|
+ * 封装要车单数据
|
|
|
|
455
|
+ *
|
|
|
|
456
|
+ * @param orderInfo 订货单数据
|
|
|
|
457
|
+ * @return CreateRequestCarTicketVo
|
|
|
|
458
|
+ */
|
|
|
|
459
|
+ private CreateRequestCarTicketVo packRequestCarTicket(PurchaseOrderInfo orderInfo, String planId, String draftId, LocalDate shipmentsDate) {
|
|
|
|
460
|
+ CreateRequestCarTicketVo ticketVo = new CreateRequestCarTicketVo();
|
|
|
|
461
|
+ ticketVo.setDraftId(draftId);
|
|
|
|
462
|
+ ticketVo.setPlanId(draftId);
|
|
|
|
463
|
+ ticketVo.setPurchaseOrderId(orderInfo.getId());
|
|
|
|
464
|
+ ticketVo.setRequestCarDate(LocalDate.now());
|
|
|
|
465
|
+ ticketVo.setDeptId(orderInfo.getDeptId());
|
|
|
|
466
|
+ ticketVo.setDeliveryDate(shipmentsDate);
|
|
|
|
467
|
+ ticketVo.setWorkshopId(orderInfo.getWorkshopId());
|
|
|
|
468
|
+ ticketVo.setOrderNo(orderInfo.getOrderNo());
|
|
|
|
469
|
+ ticketVo.setOrderingUnit(orderInfo.getOrderingUnit());
|
|
|
|
470
|
+ if (orderInfo.getTotalQuantity() != null) {
|
|
|
|
471
|
+ BigDecimal result = orderInfo.getTotalQuantity().divide(new BigDecimal(1000), 4, BigDecimal.ROUND_HALF_UP);
|
|
|
|
472
|
+ ticketVo.setQuantity(result);
|
|
|
|
473
|
+ }
|
|
|
|
474
|
+ return ticketVo;
|
|
372
|
}
|
475
|
}
|
|
373
|
} |
476
|
} |