Commit adab80acce70eebb8d63f72c4eef2d9fe4d028cb

Authored by 杨鸣坤
1 parent 7cad1a01

楚江ERP:补货单生成发货计划单

1 1 package com.lframework.xingyun.sc.impl.purchase;
2 2
  3 +import com.baomidou.mybatisplus.core.conditions.Wrapper;
3 4 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
4 5 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
5 6 import com.github.pagehelper.PageInfo;
... ... @@ -20,12 +21,15 @@ import com.lframework.xingyun.sc.service.purchase.ReplenishmentOrderLineService;
20 21 import com.lframework.xingyun.sc.vo.purchase.CreateReplenishmentOrderLineVo;
21 22 import com.lframework.xingyun.sc.vo.purchase.QueryReplenishmentOrderLineVo;
22 23 import com.lframework.xingyun.sc.vo.purchase.UpdateReplenishmentOrderLineVo;
  24 +import org.apache.commons.collections4.CollectionUtils;
23 25 import org.springframework.cache.annotation.CacheEvict;
24 26 import org.springframework.cache.annotation.Cacheable;
25 27 import org.springframework.stereotype.Service;
26 28 import org.springframework.transaction.annotation.Transactional;
27 29
28 30 import java.io.Serializable;
  31 +import java.time.LocalDate;
  32 +import java.util.ArrayList;
29 33 import java.util.List;
30 34
31 35 @Service
... ... @@ -131,6 +135,17 @@ public class ReplenishmentOrderLineServiceImpl extends BaseMpServiceImpl<Repleni
131 135 OpLogUtil.setExtra(vo);
132 136 }
133 137
  138 + @Override
  139 + public List<ReplenishmentOrderLine> listByShipmentDate(List<LocalDate> shipmentDateList) {
  140 + if (CollectionUtils.isEmpty(shipmentDateList)) {
  141 + return new ArrayList<>(0);
  142 + }
  143 +
  144 + Wrapper<ReplenishmentOrderLine> wrappers = Wrappers.lambdaQuery(ReplenishmentOrderLine.class)
  145 + .in(ReplenishmentOrderLine::getConfirmedDeliveryDate, shipmentDateList);
  146 + return getBaseMapper().selectList(wrappers);
  147 + }
  148 +
134 149 @CacheEvict(value = ReplenishmentOrderLine.CACHE_NAME, key = "@cacheVariables.tenantId() + #key")
135 150 @Override
136 151 public void cleanCacheByKey(Serializable key) {
... ...
... ... @@ -9,10 +9,7 @@ import com.lframework.starter.web.core.utils.*;
9 9 import com.lframework.xingyun.basedata.entity.Workshop;
10 10 import com.lframework.xingyun.basedata.service.workshop.WorkshopService;
11 11 import com.lframework.xingyun.basedata.vo.workshop.QueryWorkshopVo;
12   -import com.lframework.xingyun.sc.entity.PurchaseOrderInfo;
13   -import com.lframework.xingyun.sc.entity.PurchaseOrderLine;
14   -import com.lframework.xingyun.sc.entity.ShipmentsPlan;
15   -import com.lframework.xingyun.sc.entity.ShipmentsPlanDetail;
  12 +import com.lframework.xingyun.sc.entity.*;
16 13 import com.lframework.starter.web.core.impl.BaseMpServiceImpl;
17 14 import com.lframework.starter.web.core.components.resp.PageResult;
18 15 import com.lframework.starter.common.exceptions.impl.DefaultClientException;
... ... @@ -23,6 +20,8 @@ import com.lframework.starter.web.inner.components.oplog.OtherOpLogType;
23 20 import com.lframework.xingyun.sc.mappers.ShipmentsPlanDetailMapper;
24 21 import com.lframework.xingyun.sc.service.order.PurchaseOrderInfoService;
25 22 import com.lframework.xingyun.sc.service.order.PurchaseOrderLineService;
  23 +import com.lframework.xingyun.sc.service.purchase.ReplenishmentOrderLineService;
  24 +import com.lframework.xingyun.sc.service.purchase.ReplenishmentOrderService;
26 25 import com.lframework.xingyun.sc.service.shipments.ShipmentsPlanDetailService;
27 26 import com.lframework.xingyun.sc.service.shipments.ShipmentsPlanService;
28 27 import com.lframework.xingyun.sc.utils.CommonUtil;
... ... @@ -54,6 +53,10 @@ public class ShipmentsPlanDetailServiceImpl extends BaseMpServiceImpl<ShipmentsP
54 53 private WorkshopService workshopService;
55 54 @Resource
56 55 private PurchaseOrderInfoService purchaseOrderInfoService;
  56 + @Resource
  57 + private ReplenishmentOrderLineService replenishmentOrderLineService;
  58 + @Resource
  59 + private ReplenishmentOrderService replenishmentOrderService;
57 60
58 61
59 62 @Override
... ... @@ -147,7 +150,7 @@ public class ShipmentsPlanDetailServiceImpl extends BaseMpServiceImpl<ShipmentsP
147 150 * @param pageIndex 分页页码
148 151 * @param pageSize 分页大小
149 152 * @param vo 查询条件
150   - * @return PageResult<ShipmentsPlanDetail>
  153 + * @return PageResult<ShipmentsPlanDetail>
151 154 */
152 155 @Override
153 156 public PageResult<ShipmentsPlanDetail> queryCanShipmentsData(Integer pageIndex, Integer pageSize, QueryShipmentsPlanDetailVo vo) {
... ... @@ -170,7 +173,7 @@ public class ShipmentsPlanDetailServiceImpl extends BaseMpServiceImpl<ShipmentsP
170 173 /**
171 174 * 计划明细拆分
172 175 *
173   - * @param vo 条件
  176 + * @param vo 条件
174 177 */
175 178 @Override
176 179 public void planDetailSplit(ShipmentsPlanDetailSplitVo vo) {
... ... @@ -233,6 +236,18 @@ public class ShipmentsPlanDetailServiceImpl extends BaseMpServiceImpl<ShipmentsP
233 236 orderInfoMap = orderInfoList.stream().collect(Collectors.toMap(PurchaseOrderInfo::getId, Function.identity()));
234 237 }
235 238 }
  239 +
  240 + // 获取补货单数据
  241 + List<ReplenishmentOrderLine> replenishmentOrderLineList = replenishmentOrderLineService.listByShipmentDate(dateList);
  242 + Map<String, ReplenishmentOrder> replenishmentOrderMap = new HashMap<>();
  243 + if (CollectionUtils.isNotEmpty(replenishmentOrderLineList)) {
  244 + List<String> replenishmentOrderIdList = replenishmentOrderLineList.stream().map(ReplenishmentOrderLine::getReplenishmentOrderId).collect(Collectors.toList());
  245 + List<ReplenishmentOrder> replenishmentOrderList = replenishmentOrderService.listByIds(replenishmentOrderIdList);
  246 + if (CollectionUtils.isNotEmpty(replenishmentOrderList)) {
  247 + replenishmentOrderMap = replenishmentOrderList.stream().collect(Collectors.toMap(ReplenishmentOrder::getId, Function.identity()));
  248 + }
  249 + }
  250 +
236 251 for (Workshop workshop : workshopList) {
237 252 // 生成发货计划
238 253 ShipmentsPlan plan = new ShipmentsPlan();
... ... @@ -244,8 +259,8 @@ public class ShipmentsPlanDetailServiceImpl extends BaseMpServiceImpl<ShipmentsP
244 259
245 260 shipmentsPlanService.getBaseMapper().insert(plan);
246 261 // 生成发货计划明细
  262 + List<ShipmentsPlanDetail> planDetails = new ArrayList<>();
247 263 if (CollectionUtils.isNotEmpty(orderLineList)) {
248   - List<ShipmentsPlanDetail> planDetails = new ArrayList<>();
249 264 for (PurchaseOrderLine line : orderLineList) {
250 265 ShipmentsPlanDetail detail = new ShipmentsPlanDetail();
251 266 detail.setId(IdUtil.getId());
... ... @@ -269,17 +284,45 @@ public class ShipmentsPlanDetailServiceImpl extends BaseMpServiceImpl<ShipmentsP
269 284
270 285 planDetails.add(detail);
271 286 }
272   - if (CollectionUtils.isNotEmpty(planDetails)) {
273   - getBaseMapper().batchAdd(planDetails);
  287 + }
  288 + // 补货单生成发货单明细
  289 + if (CollectionUtils.isNotEmpty(replenishmentOrderLineList)) {
  290 + for (ReplenishmentOrderLine replenishmentOrderLine : replenishmentOrderLineList) {
  291 + ReplenishmentOrder replenishmentOrder = replenishmentOrderMap.get(replenishmentOrderLine.getReplenishmentOrderId());
  292 + if (replenishmentOrder == null) {
  293 + continue;
  294 + }
  295 +
  296 + if (!workshop.getId().equals(replenishmentOrder.getWorkshopId())) {
  297 + continue;
  298 + }
  299 +
  300 + ShipmentsPlanDetail detail = new ShipmentsPlanDetail();
  301 + detail.setId(IdUtil.getId());
  302 + detail.setPlanId(plan.getId());
  303 + detail.setOrderId(replenishmentOrder.getId());
  304 + detail.setOrderSpecId(replenishmentOrderLine.getId());
  305 + detail.setShipmentsDate(replenishmentOrderLine.getConfirmedDeliveryDate());
  306 + detail.setPreShipments(afTomorrow.equals(replenishmentOrderLine.getConfirmedDeliveryDate()));
  307 + detail.setDelFlag(Boolean.FALSE);
  308 +
  309 + detail.setCreateById("1");
  310 + detail.setUpdateById("1");
  311 +
  312 + planDetails.add(detail);
274 313 }
275 314 }
  315 +
  316 + if (CollectionUtils.isNotEmpty(planDetails)) {
  317 + getBaseMapper().batchAdd(planDetails);
  318 + }
276 319 }
277 320 }
278 321
279 322 /**
280 323 * 批量删除
281 324 *
282   - * @param ids 主键ID集合
  325 + * @param ids 主键ID集合
283 326 */
284 327 @Override
285 328 public void batchDelete(List<String> ids) {
... ... @@ -331,10 +374,10 @@ public class ShipmentsPlanDetailServiceImpl extends BaseMpServiceImpl<ShipmentsP
331 374 /**
332 375 * 封装发货计划明细数据
333 376 *
334   - * @param quantity 数量
335   - * @param detail 原数据
336   - * @param userId 人员ID
337   - * @return ShipmentsPlanDetail
  377 + * @param quantity 数量
  378 + * @param detail 原数据
  379 + * @param userId 人员ID
  380 + * @return ShipmentsPlanDetail
338 381 */
339 382 private static ShipmentsPlanDetail getShipmentsPlanDetail(BigDecimal quantity, ShipmentsPlanDetail detail, String userId) {
340 383 ShipmentsPlanDetail data = new ShipmentsPlanDetail();
... ...
... ... @@ -7,6 +7,7 @@ import com.lframework.xingyun.sc.vo.purchase.CreateReplenishmentOrderLineVo;
7 7 import com.lframework.xingyun.sc.vo.purchase.QueryReplenishmentOrderLineVo;
8 8 import com.lframework.xingyun.sc.vo.purchase.UpdateReplenishmentOrderLineVo;
9 9
  10 +import java.time.LocalDate;
10 11 import java.util.List;
11 12
12 13 /**
... ... @@ -52,4 +53,5 @@ public interface ReplenishmentOrderLineService extends BaseMpService<Replenishme
52 53 */
53 54 void update(UpdateReplenishmentOrderLineVo vo);
54 55
  56 + List<ReplenishmentOrderLine> listByShipmentDate(List<LocalDate> shipmentDateList);
55 57 }
... ...