|
@@ -3,13 +3,17 @@ package com.lframework.xingyun.sc.impl.shipments; |
|
@@ -3,13 +3,17 @@ package com.lframework.xingyun.sc.impl.shipments; |
|
3
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
3
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
4
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
4
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
5
|
import com.github.pagehelper.PageInfo;
|
5
|
import com.github.pagehelper.PageInfo;
|
|
|
|
6
|
+import com.lframework.starter.web.core.components.security.SecurityUtil;
|
|
6
|
import com.lframework.starter.web.core.utils.*;
|
7
|
import com.lframework.starter.web.core.utils.*;
|
|
|
|
8
|
+import com.lframework.starter.web.inner.dto.dic.city.DicCityDto;
|
|
7
|
import com.lframework.starter.web.inner.entity.SysDept;
|
9
|
import com.lframework.starter.web.inner.entity.SysDept;
|
|
|
|
10
|
+import com.lframework.starter.web.inner.service.DicCityService;
|
|
8
|
import com.lframework.starter.web.inner.service.system.SysDeptService;
|
11
|
import com.lframework.starter.web.inner.service.system.SysDeptService;
|
|
9
|
import com.lframework.xingyun.basedata.entity.Customer;
|
12
|
import com.lframework.xingyun.basedata.entity.Customer;
|
|
10
|
import com.lframework.xingyun.basedata.entity.Workshop;
|
13
|
import com.lframework.xingyun.basedata.entity.Workshop;
|
|
11
|
import com.lframework.xingyun.basedata.service.customer.CustomerService;
|
14
|
import com.lframework.xingyun.basedata.service.customer.CustomerService;
|
|
12
|
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;
|
|
13
|
import com.lframework.xingyun.sc.entity.ShipmentsOrderInfo;
|
17
|
import com.lframework.xingyun.sc.entity.ShipmentsOrderInfo;
|
|
14
|
import com.lframework.starter.web.core.impl.BaseMpServiceImpl;
|
18
|
import com.lframework.starter.web.core.impl.BaseMpServiceImpl;
|
|
15
|
import com.lframework.starter.web.core.components.resp.PageResult;
|
19
|
import com.lframework.starter.web.core.components.resp.PageResult;
|
|
@@ -20,9 +24,12 @@ import com.lframework.starter.common.utils.Assert; |
|
@@ -20,9 +24,12 @@ import com.lframework.starter.common.utils.Assert; |
|
20
|
import com.lframework.starter.web.inner.components.oplog.OtherOpLogType;
|
24
|
import com.lframework.starter.web.inner.components.oplog.OtherOpLogType;
|
|
21
|
import com.lframework.xingyun.sc.entity.ShipmentsPlan;
|
25
|
import com.lframework.xingyun.sc.entity.ShipmentsPlan;
|
|
22
|
import com.lframework.xingyun.sc.entity.ShipmentsPlanDetail;
|
26
|
import com.lframework.xingyun.sc.entity.ShipmentsPlanDetail;
|
|
|
|
27
|
+import com.lframework.xingyun.sc.service.order.PurchaseOrderInfoService;
|
|
23
|
import com.lframework.xingyun.sc.service.shipments.ShipmentsPlanDetailService;
|
28
|
import com.lframework.xingyun.sc.service.shipments.ShipmentsPlanDetailService;
|
|
24
|
import com.lframework.xingyun.sc.service.shipments.ShipmentsPlanService;
|
29
|
import com.lframework.xingyun.sc.service.shipments.ShipmentsPlanService;
|
|
|
|
30
|
+import com.lframework.xingyun.sc.utils.CommonUtil;
|
|
25
|
import com.lframework.xingyun.sc.vo.shipments.order.GenerateShipmentsOrderVo;
|
31
|
import com.lframework.xingyun.sc.vo.shipments.order.GenerateShipmentsOrderVo;
|
|
|
|
32
|
+import lombok.extern.slf4j.Slf4j;
|
|
26
|
import org.apache.commons.collections4.CollectionUtils;
|
33
|
import org.apache.commons.collections4.CollectionUtils;
|
|
27
|
import org.apache.commons.lang3.StringUtils;
|
34
|
import org.apache.commons.lang3.StringUtils;
|
|
28
|
import org.springframework.transaction.annotation.Transactional;
|
35
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -39,6 +46,7 @@ import java.util.function.Function; |
|
@@ -39,6 +46,7 @@ import java.util.function.Function; |
|
39
|
import java.util.stream.Collectors;
|
46
|
import java.util.stream.Collectors;
|
|
40
|
|
47
|
|
|
41
|
@Service
|
48
|
@Service
|
|
|
|
49
|
+@Slf4j
|
|
42
|
public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOrderInfoMapper, ShipmentsOrderInfo> implements ShipmentsOrderInfoService {
|
50
|
public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOrderInfoMapper, ShipmentsOrderInfo> implements ShipmentsOrderInfoService {
|
|
43
|
|
51
|
|
|
44
|
|
52
|
|
|
@@ -49,6 +57,10 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr |
|
@@ -49,6 +57,10 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr |
|
49
|
private ShipmentsPlanDetailService shipmentsPlanDetailService;
|
57
|
private ShipmentsPlanDetailService shipmentsPlanDetailService;
|
|
50
|
@Resource
|
58
|
@Resource
|
|
51
|
private ShipmentsPlanService shipmentsPlanService;
|
59
|
private ShipmentsPlanService shipmentsPlanService;
|
|
|
|
60
|
+ @Resource
|
|
|
|
61
|
+ private DicCityService dicCityService;
|
|
|
|
62
|
+ @Resource
|
|
|
|
63
|
+ private PurchaseOrderInfoService purchaseOrderInfoService;
|
|
52
|
|
64
|
|
|
53
|
|
65
|
|
|
54
|
@Override
|
66
|
@Override
|
|
@@ -206,7 +218,22 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr |
|
@@ -206,7 +218,22 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr |
|
206
|
String type = vo.getType();
|
218
|
String type = vo.getType();
|
|
207
|
if ("AUTO".equals(type)) {
|
219
|
if ("AUTO".equals(type)) {
|
|
208
|
// 根据客户批量生成
|
220
|
// 根据客户批量生成
|
|
209
|
-
|
221
|
+ List<ShipmentsPlanDetail> detailList = shipmentsPlanDetailService.listByPlanId(planId);
|
|
|
|
222
|
+ if (CollectionUtils.isEmpty(detailList)) {
|
|
|
|
223
|
+ return;
|
|
|
|
224
|
+ }
|
|
|
|
225
|
+ // 根据客户分组
|
|
|
|
226
|
+ Map<String, List<ShipmentsPlanDetail>> detailMap = new HashMap<>();
|
|
|
|
227
|
+ for (ShipmentsPlanDetail detail : detailList) {
|
|
|
|
228
|
+ List<ShipmentsPlanDetail> list = detailMap.computeIfAbsent(detail.getCustomerId(), k -> new ArrayList<>());
|
|
|
|
229
|
+ list.add(detail);
|
|
|
|
230
|
+ }
|
|
|
|
231
|
+ // todo 如果客户很多,则此处需要优化
|
|
|
|
232
|
+ for (Map.Entry<String, List<ShipmentsPlanDetail>> entry : detailMap.entrySet()) {
|
|
|
|
233
|
+ List<ShipmentsPlanDetail> value = entry.getValue();
|
|
|
|
234
|
+ List<List<ShipmentsPlanDetail>> batchList = CommonUtil.partition(value, 8);
|
|
|
|
235
|
+ handleBatchData(batchList, planId);
|
|
|
|
236
|
+ }
|
|
210
|
} else {
|
237
|
} else {
|
|
211
|
List<String> planDetailIds = vo.getPlanDetailIds();
|
238
|
List<String> planDetailIds = vo.getPlanDetailIds();
|
|
212
|
if (CollectionUtils.isEmpty(planDetailIds)) {
|
239
|
if (CollectionUtils.isEmpty(planDetailIds)) {
|
|
@@ -216,19 +243,93 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr |
|
@@ -216,19 +243,93 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr |
|
216
|
if (CollectionUtils.isEmpty(detailList)) {
|
243
|
if (CollectionUtils.isEmpty(detailList)) {
|
|
217
|
throw new DefaultClientException("发货明细数据不存在!");
|
244
|
throw new DefaultClientException("发货明细数据不存在!");
|
|
218
|
}
|
245
|
}
|
|
|
|
246
|
+ List<List<ShipmentsPlanDetail>> batchList = CommonUtil.partition(detailList, 8);
|
|
|
|
247
|
+ handleBatchData(batchList, planId);
|
|
|
|
248
|
+ }
|
|
|
|
249
|
+ }
|
|
|
|
250
|
+
|
|
|
|
251
|
+
|
|
|
|
252
|
+ @Override
|
|
|
|
253
|
+ public void batchAdd(List<ShipmentsOrderInfo> orderInfos) {
|
|
|
|
254
|
+ if (CollectionUtils.isEmpty(orderInfos)) {
|
|
|
|
255
|
+ return;
|
|
|
|
256
|
+ }
|
|
|
|
257
|
+ getBaseMapper().batchAdd(orderInfos);
|
|
|
|
258
|
+ }
|
|
|
|
259
|
+
|
|
|
|
260
|
+
|
|
|
|
261
|
+ /**
|
|
|
|
262
|
+ * 处理批次数据
|
|
|
|
263
|
+ *
|
|
|
|
264
|
+ * @param batchList 数据批次
|
|
|
|
265
|
+ */
|
|
|
|
266
|
+ private void handleBatchData(List<List<ShipmentsPlanDetail>> batchList, String planId) {
|
|
|
|
267
|
+ if (CollectionUtils.isEmpty(batchList)) {
|
|
|
|
268
|
+ return;
|
|
|
|
269
|
+ }
|
|
|
|
270
|
+ // 获取发货计划数据
|
|
|
|
271
|
+ ShipmentsPlan plan = shipmentsPlanService.findById(planId);
|
|
|
|
272
|
+ // 获取所有城市数据
|
|
|
|
273
|
+ List<DicCityDto> allCity = dicCityService.getAll();
|
|
|
|
274
|
+ // 获取所有订货单数据
|
|
|
|
275
|
+ List<String> orderIds = batchList.stream().flatMap(List::stream).map(ShipmentsPlanDetail::getOrderId)
|
|
|
|
276
|
+ .filter(Objects::nonNull)
|
|
|
|
277
|
+ .distinct()
|
|
|
|
278
|
+ .collect(Collectors.toList());
|
|
|
|
279
|
+ List<PurchaseOrderInfo> orderInfoList = purchaseOrderInfoService.queryByIds(orderIds);
|
|
|
|
280
|
+ Map<String, PurchaseOrderInfo> orderInfoMap = new HashMap<>();
|
|
|
|
281
|
+ if (CollectionUtils.isEmpty(orderInfoList)) {
|
|
|
|
282
|
+ orderInfoMap = orderInfoList.stream().collect(Collectors.toMap(PurchaseOrderInfo::getId, Function.identity()));
|
|
|
|
283
|
+ }
|
|
|
|
284
|
+ Map<String, List<String>> deptIdMap = new HashMap<>();
|
|
|
|
285
|
+ List<String> detailIds = new ArrayList<>();
|
|
|
|
286
|
+ List<ShipmentsOrderInfo> shipmentsOrderInfoList = new ArrayList<>();
|
|
|
|
287
|
+ for (List<ShipmentsPlanDetail> details : batchList) {
|
|
219
|
String id = IdUtil.getId();
|
288
|
String id = IdUtil.getId();
|
|
220
|
- String customerId = detailList.get(0).getCustomerId();
|
289
|
+ String customerId = details.get(0).getCustomerId();
|
|
221
|
StringBuilder deliveryTypeBuilder = new StringBuilder();
|
290
|
StringBuilder deliveryTypeBuilder = new StringBuilder();
|
|
222
|
StringBuilder destinationBuilder = new StringBuilder();
|
291
|
StringBuilder destinationBuilder = new StringBuilder();
|
|
223
|
- // 获取城市数据
|
|
|
|
224
|
-
|
|
|
|
225
|
- for (ShipmentsPlanDetail detail : detailList) {
|
292
|
+ StringBuilder paymentTypeBuilder = new StringBuilder();
|
|
|
|
293
|
+ Set<String> deliveryTypeSet = new HashSet<>();
|
|
|
|
294
|
+ Set<String> destinationSet = new HashSet<>();
|
|
|
|
295
|
+ Set<String> paymentTypeSet = new HashSet<>();
|
|
|
|
296
|
+ for (ShipmentsPlanDetail detail : details) {
|
|
226
|
if (!customerId.equals(detail.getCustomerId())) {
|
297
|
if (!customerId.equals(detail.getCustomerId())) {
|
|
227
|
throw new DefaultClientException("只能选择同一客户下的数据!");
|
298
|
throw new DefaultClientException("只能选择同一客户下的数据!");
|
|
228
|
}
|
299
|
}
|
|
229
|
detail.setShipmentOrderId(id);
|
300
|
detail.setShipmentOrderId(id);
|
|
|
|
301
|
+ detailIds.add(detail.getId());
|
|
230
|
|
302
|
|
|
231
|
- deliveryTypeBuilder.append(detail.getDeliveryMethod()).append(",");
|
303
|
+ PurchaseOrderInfo orderInfo = orderInfoMap.get(detail.getOrderId());
|
|
|
|
304
|
+ if (orderInfo == null) {
|
|
|
|
305
|
+ continue;
|
|
|
|
306
|
+ }
|
|
|
|
307
|
+ // 办事处
|
|
|
|
308
|
+ List<String> list = deptIdMap.computeIfAbsent(id, k -> new ArrayList<>());
|
|
|
|
309
|
+ if (list.contains(orderInfo.getDeptId())) {
|
|
|
|
310
|
+ list.add(orderInfo.getDeptId());
|
|
|
|
311
|
+ }
|
|
|
|
312
|
+ // 交货方式
|
|
|
|
313
|
+ String deliveryMethod = orderInfo.getDeliveryMethod();
|
|
|
|
314
|
+ if (StringUtils.isNotBlank(deliveryMethod) && !deliveryTypeSet.contains(deliveryMethod)) {
|
|
|
|
315
|
+ deliveryTypeSet.add(deliveryMethod);
|
|
|
|
316
|
+ deliveryTypeBuilder.append(deliveryMethod).append(",");
|
|
|
|
317
|
+ }
|
|
|
|
318
|
+ // 付款方式
|
|
|
|
319
|
+ String paymentType = orderInfo.getSettlementTerms();
|
|
|
|
320
|
+ if (StringUtils.isNotBlank(paymentType) && !paymentTypeSet.contains(paymentType)) {
|
|
|
|
321
|
+ paymentTypeSet.add(paymentType);
|
|
|
|
322
|
+ paymentTypeBuilder.append(paymentType).append(",");
|
|
|
|
323
|
+ }
|
|
|
|
324
|
+ // 目的地
|
|
|
|
325
|
+ String destination = orderInfo.getDestination();
|
|
|
|
326
|
+ if (StringUtils.isNotBlank(destination) && !destinationSet.contains(destination)) {
|
|
|
|
327
|
+ destinationSet.add(destination);
|
|
|
|
328
|
+ List<DicCityDto> fullPath = dicCityService.getFullPath(destination, allCity);
|
|
|
|
329
|
+ for (DicCityDto cityDto : fullPath) {
|
|
|
|
330
|
+ destinationBuilder.append(cityDto.getName()).append(",");
|
|
|
|
331
|
+ }
|
|
|
|
332
|
+ }
|
|
232
|
}
|
333
|
}
|
|
233
|
if (deliveryTypeBuilder.length() > 0) {
|
334
|
if (deliveryTypeBuilder.length() > 0) {
|
|
234
|
deliveryTypeBuilder.setLength(deliveryTypeBuilder.length() - 1);
|
335
|
deliveryTypeBuilder.setLength(deliveryTypeBuilder.length() - 1);
|
|
@@ -236,22 +337,37 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr |
|
@@ -236,22 +337,37 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr |
|
236
|
if (destinationBuilder.length() > 0) {
|
337
|
if (destinationBuilder.length() > 0) {
|
|
237
|
destinationBuilder.setLength(destinationBuilder.length() - 1);
|
338
|
destinationBuilder.setLength(destinationBuilder.length() - 1);
|
|
238
|
}
|
339
|
}
|
|
239
|
- // 获取发货计划数据
|
|
|
|
240
|
- ShipmentsPlan plan = shipmentsPlanService.findById(planId);
|
340
|
+ if (paymentTypeBuilder.length() > 0) {
|
|
|
|
341
|
+ paymentTypeBuilder.setLength(paymentTypeBuilder.length() - 1);
|
|
|
|
342
|
+ }
|
|
241
|
// 封装发货单数据
|
343
|
// 封装发货单数据
|
|
242
|
- CreateShipmentsOrderInfoVo createVo = new CreateShipmentsOrderInfoVo();
|
|
|
|
243
|
- createVo.setPlanId(planId);
|
|
|
|
244
|
- createVo.setCustomerId(customerId);
|
|
|
|
245
|
- createVo.setWorkshopId(plan.getWorkshopId());
|
|
|
|
246
|
- createVo.setShipmentsDate(plan.getTomoPreShipDate());
|
|
|
|
247
|
- createVo.setDeliveryType(deliveryTypeBuilder.toString());
|
|
|
|
248
|
- createVo.setDestination(destinationBuilder.toString());
|
344
|
+ ShipmentsOrderInfo shipmentsOrderInfo = new ShipmentsOrderInfo();
|
|
|
|
345
|
+ shipmentsOrderInfo.setId(id);
|
|
|
|
346
|
+ shipmentsOrderInfo.setPlanId(planId);
|
|
|
|
347
|
+ shipmentsOrderInfo.setCustomerId(customerId);
|
|
|
|
348
|
+ shipmentsOrderInfo.setWorkshopId(plan.getWorkshopId());
|
|
|
|
349
|
+ shipmentsOrderInfo.setShipmentsDate(plan.getTomoPreShipDate());
|
|
|
|
350
|
+ shipmentsOrderInfo.setDeliveryType(deliveryTypeBuilder.toString());
|
|
|
|
351
|
+ shipmentsOrderInfo.setDestination(destinationBuilder.toString());
|
|
|
|
352
|
+ shipmentsOrderInfo.setPaymentType(paymentTypeBuilder.toString());
|
|
|
|
353
|
+ shipmentsOrderInfo.setStatus("UN_SHIPMENTS");
|
|
|
|
354
|
+ shipmentsOrderInfo.setCreateById(SecurityUtil.getCurrentUser().getId());
|
|
|
|
355
|
+ shipmentsOrderInfo.setUpdateById(SecurityUtil.getCurrentUser().getId());
|
|
249
|
|
356
|
|
|
250
|
- create(createVo);
|
357
|
+ shipmentsOrderInfoList.add(shipmentsOrderInfo);
|
|
251
|
// 更新明细数据
|
358
|
// 更新明细数据
|
|
252
|
- shipmentsPlanDetailService.setShipmentsOrderId(planDetailIds, id);
|
|
|
|
253
|
- // 获取订货单数据
|
|
|
|
254
|
-
|
359
|
+ shipmentsPlanDetailService.setShipmentsOrderId(detailIds, id);
|
|
|
|
360
|
+ }
|
|
|
|
361
|
+ // 获取所有部门数据
|
|
|
|
362
|
+ for ( ShipmentsOrderInfo orderInfo : shipmentsOrderInfoList) {
|
|
|
|
363
|
+ String id = orderInfo.getId();
|
|
|
|
364
|
+ List<String> deptIds = deptIdMap.get(id);
|
|
|
|
365
|
+ if (CollectionUtils.isNotEmpty(deptIds)) {
|
|
|
|
366
|
+ String deptIdStr = String.join(",", deptIds);
|
|
|
|
367
|
+ orderInfo.setDeptId(deptIdStr);
|
|
|
|
368
|
+ }
|
|
255
|
}
|
369
|
}
|
|
|
|
370
|
+ // 批量新增发货单
|
|
|
|
371
|
+ batchAdd(shipmentsOrderInfoList);
|
|
256
|
}
|
372
|
}
|
|
257
|
} |
373
|
} |