Commit cc3111fca6f46cea3415fc7dc1c52110855df4f4

Authored by yeqianyong
1 parent 19c2f9a2

楚江ERP-自动生成发货计划

... ... @@ -2,6 +2,7 @@ package com.lframework.xingyun.sc.controller.shipments;
2 2
3 3 import com.lframework.starter.web.core.controller.DefaultBaseController;
4 4 import com.lframework.xingyun.sc.bo.shipments.plan.ShipmentsPlanBo;
  5 +import com.lframework.xingyun.sc.service.shipments.ShipmentsPlanDetailService;
5 6 import com.lframework.xingyun.sc.vo.shipments.plan.QueryShipmentsPlanVo;
6 7 import com.lframework.xingyun.sc.service.shipments.ShipmentsPlanService;
7 8 import com.lframework.xingyun.sc.vo.shipments.plan.UpdateShipmentsPlanVo;
... ... @@ -19,6 +20,7 @@ import io.swagger.annotations.ApiOperation;
19 20 import com.lframework.starter.common.utils.CollectionUtil;
20 21 import io.swagger.annotations.Api;
21 22 import com.lframework.starter.web.core.annotations.security.HasPermission;
  23 +import org.springframework.scheduling.annotation.Scheduled;
22 24 import org.springframework.validation.annotation.Validated;
23 25 import org.springframework.web.bind.annotation.*;
24 26
... ... @@ -39,6 +41,8 @@ public class ShipmentsPlanController extends DefaultBaseController {
39 41
40 42 @Resource
41 43 private ShipmentsPlanService shipmentsPlanService;
  44 + @Resource
  45 + private ShipmentsPlanDetailService shipmentsPlanDetailService;
42 46
43 47
44 48 /**
... ... @@ -84,4 +88,13 @@ public class ShipmentsPlanController extends DefaultBaseController {
84 88 shipmentsPlanService.update(vo);
85 89 return InvokeResultBuilder.success();
86 90 }
  91 +
  92 + /**
  93 + * 自动生成发货计划
  94 + */
  95 + @Scheduled(cron = "0 10 1 * * ?")
  96 + @GetMapping("/autoCreateShipmentPlan")
  97 + public void autoCreateShipmentPlan() {
  98 + shipmentsPlanDetailService.autoCreateShipmentPlan();
  99 + }
87 100 }
... ...
... ... @@ -30,8 +30,8 @@ import org.springframework.transaction.annotation.Transactional;
30 30 import org.springframework.stereotype.Service;
31 31
32 32 import java.math.BigDecimal;
33   -import java.util.Collections;
34   -import java.util.List;
  33 +import java.time.LocalDate;
  34 +import java.util.*;
35 35
36 36 @Service
37 37 public class PurchaseOrderLineServiceImpl extends BaseMpServiceImpl<PurchaseOrderLineMapper, PurchaseOrderLine> implements PurchaseOrderLineService {
... ... @@ -282,6 +282,18 @@ public class PurchaseOrderLineServiceImpl extends BaseMpServiceImpl<PurchaseOrde
282 282 }
283 283
284 284 @Override
  285 + public List<PurchaseOrderLine> listByShipmentDate(List<LocalDate> shipmentDateList) {
  286 + if (CollectionUtils.isEmpty(shipmentDateList)) {
  287 + return Collections.emptyList();
  288 + }
  289 + // 根据日期批量查询
  290 + LambdaQueryWrapper<PurchaseOrderLine> queryWrapper = Wrappers.lambdaQuery(PurchaseOrderLine.class);
  291 + queryWrapper.in(PurchaseOrderLine::getDeliveryDate, shipmentDateList);
  292 +
  293 + return getBaseMapper().selectList(queryWrapper);
  294 + }
  295 +
  296 + @Override
285 297 public void cleanCacheByKey(Serializable key) {
286 298
287 299 }
... ...
... ... @@ -5,6 +5,10 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
5 5 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
6 6 import com.github.pagehelper.PageInfo;
7 7 import com.lframework.starter.web.core.components.security.SecurityUtil;
  8 +import com.lframework.xingyun.basedata.entity.Workshop;
  9 +import com.lframework.xingyun.basedata.service.workshop.WorkshopService;
  10 +import com.lframework.xingyun.basedata.vo.workshop.QueryWorkshopVo;
  11 +import com.lframework.xingyun.sc.entity.PurchaseOrderInfo;
8 12 import com.lframework.xingyun.sc.entity.PurchaseOrderLine;
9 13 import com.lframework.xingyun.sc.entity.ShipmentsPlan;
10 14 import com.lframework.xingyun.sc.entity.ShipmentsPlanDetail;
... ... @@ -20,6 +24,7 @@ import com.lframework.starter.web.core.utils.PageHelperUtil;
20 24 import com.lframework.starter.common.utils.Assert;
21 25 import com.lframework.starter.web.inner.components.oplog.OtherOpLogType;
22 26 import com.lframework.xingyun.sc.mappers.ShipmentsPlanDetailMapper;
  27 +import com.lframework.xingyun.sc.service.order.PurchaseOrderInfoService;
23 28 import com.lframework.xingyun.sc.service.order.PurchaseOrderLineService;
24 29 import com.lframework.xingyun.sc.service.shipments.ShipmentsPlanDetailService;
25 30 import com.lframework.xingyun.sc.service.shipments.ShipmentsPlanService;
... ... @@ -36,8 +41,10 @@ import javax.annotation.Resource;
36 41 import java.math.BigDecimal;
37 42 import java.time.LocalDate;
38 43 import java.util.ArrayList;
  44 +import java.util.HashMap;
39 45 import java.util.List;
40 46 import java.util.Map;
  47 +import java.util.function.Function;
41 48 import java.util.stream.Collectors;
42 49
43 50 @Service
... ... @@ -48,6 +55,10 @@ public class ShipmentsPlanDetailServiceImpl extends BaseMpServiceImpl<ShipmentsP
48 55 private PurchaseOrderLineService purchaseOrderLineService;
49 56 @Resource
50 57 private ShipmentsPlanService shipmentsPlanService;
  58 + @Resource
  59 + private WorkshopService workshopService;
  60 + @Resource
  61 + private PurchaseOrderInfoService purchaseOrderInfoService;
51 62
52 63
53 64 @Override
... ... @@ -207,6 +218,69 @@ public class ShipmentsPlanDetailServiceImpl extends BaseMpServiceImpl<ShipmentsP
207 218 purchaseOrderLineService.batchAdd(orderLineList);
208 219 }
209 220
  221 + @Override
  222 + public void autoCreateShipmentPlan() {
  223 + // 获取所有厂房
  224 + List<Workshop> workshopList = workshopService.query(new QueryWorkshopVo());
  225 + LocalDate tomorrow = LocalDate.now().plusDays(1);
  226 + LocalDate afTomorrow = LocalDate.now().plusDays(2);
  227 + // 获取所有明日、后日需要发货的订货单规格数据
  228 + List<LocalDate> dateList = new ArrayList<>();
  229 + dateList.add(tomorrow);
  230 + dateList.add(afTomorrow);
  231 + List<PurchaseOrderLine> orderLineList = purchaseOrderLineService.listByShipmentDate(dateList);
  232 + // 获取订货单数据
  233 + Map<String, PurchaseOrderInfo> orderInfoMap = new HashMap<>();
  234 + if (CollectionUtils.isNotEmpty(orderLineList)) {
  235 + List<String> orderIds = orderLineList.stream().map(PurchaseOrderLine::getPurchaseOrderId).collect(Collectors.toList());
  236 + List<PurchaseOrderInfo> orderInfoList = purchaseOrderInfoService.listByIds(orderIds);
  237 + if (CollectionUtils.isNotEmpty(orderInfoList)) {
  238 + orderInfoMap = orderInfoList.stream().collect(Collectors.toMap(PurchaseOrderInfo::getId, Function.identity()));
  239 + }
  240 + }
  241 + for (Workshop workshop : workshopList) {
  242 + // 生成发货计划
  243 + ShipmentsPlan plan = new ShipmentsPlan();
  244 + plan.setId(IdUtil.getId());
  245 + plan.setStatus("DRAFT");
  246 + plan.setWorkshopId(workshop.getId());
  247 + plan.setTomoPreShipDate(tomorrow);
  248 + plan.setAfTomoPreShipDate(afTomorrow);
  249 +
  250 + shipmentsPlanService.getBaseMapper().insert(plan);
  251 + // 生成发货计划明细
  252 + if (CollectionUtils.isNotEmpty(orderLineList)) {
  253 + List<ShipmentsPlanDetail> planDetails = new ArrayList<>();
  254 + for (PurchaseOrderLine line : orderLineList) {
  255 + ShipmentsPlanDetail detail = new ShipmentsPlanDetail();
  256 + detail.setId(IdUtil.getId());
  257 + detail.setPlanId(plan.getId());
  258 + String orderId = line.getPurchaseOrderId();
  259 + detail.setOrderId(orderId);
  260 + PurchaseOrderInfo orderInfo = orderInfoMap.get(orderId);
  261 + if (orderInfo == null) {
  262 + continue;
  263 + }
  264 + String workshopId = orderInfo.getWorkshopId();
  265 + if (!workshop.getId().equals(workshopId)) {
  266 + continue;
  267 + }
  268 + detail.setOrderSpecId(line.getId());
  269 + detail.setShipmentsDate(line.getDeliveryDate());
  270 + detail.setPreShipments(afTomorrow.equals(line.getDeliveryDate()));
  271 + detail.setDelFlag(Boolean.FALSE);
  272 + detail.setCreateById("1");
  273 + detail.setUpdateById("1");
  274 +
  275 + planDetails.add(detail);
  276 + }
  277 + if (CollectionUtils.isNotEmpty(planDetails)) {
  278 + getBaseMapper().batchAdd(planDetails);
  279 + }
  280 + }
  281 + }
  282 + }
  283 +
210 284
211 285 /**
212 286 * 封装发货计划明细数据
... ... @@ -224,6 +298,8 @@ public class ShipmentsPlanDetailServiceImpl extends BaseMpServiceImpl<ShipmentsP
224 298 data.setOrderSpecId(IdUtil.getId());
225 299 data.setParentId(detail.getId());
226 300 data.setShipmentsDate(detail.getShipmentsDate());
  301 + data.setShipmentsTime(detail.getShipmentsTime());
  302 + data.setCanShipments(detail.getCanShipments());
227 303 data.setQuantity(quantity);
228 304 data.setPreShipments(Boolean.FALSE);
229 305 data.setCreateById(userId);
... ...
... ... @@ -8,6 +8,7 @@ import com.lframework.xingyun.sc.vo.order.QueryPurchaseOrderLineVo;
8 8 import com.lframework.xingyun.sc.vo.order.UpdatePurchaseOrderLineVo;
9 9
10 10 import java.math.BigDecimal;
  11 +import java.time.LocalDate;
11 12 import java.util.List;
12 13
13 14 /**
... ... @@ -106,4 +107,12 @@ public interface PurchaseOrderLineService extends BaseMpService<PurchaseOrderLin
106 107 * @param id 主键ID
107 108 */
108 109 void logicDelById(String id);
  110 +
  111 + /**
  112 + * 根据发货日期批量查询
  113 + *
  114 + * @param shipmentDateList 发货日期
  115 + * @return List<PurchaseOrderLine>
  116 + */
  117 + List<PurchaseOrderLine> listByShipmentDate(List<LocalDate> shipmentDateList);
109 118 }
... ...
... ... @@ -68,4 +68,9 @@ public interface ShipmentsPlanDetailService extends BaseMpService<ShipmentsPlanD
68 68 * @param vo 条件
69 69 */
70 70 void planDetailSplit(ShipmentsPlanDetailSplitVo vo);
  71 +
  72 + /**
  73 + * 自动生成发货计划
  74 + */
  75 + void autoCreateShipmentPlan();
71 76 }
... ...