Commit 0c7e798a67eeca8d8bc9e8bed798f7700e0aeccd

Authored by 房远帅
1 parent 78a285d4

订货单-申请发货:申请发货自动生成发货计划,半小时内的同一分厂数据自动加入该计划

@@ -1104,6 +1104,7 @@ CREATE TABLE `pending_delivery_order` ( @@ -1104,6 +1104,7 @@ CREATE TABLE `pending_delivery_order` (
1104 1104
1105 alter table shipments_order_info add column delivery_time datetime default null comment '签收时间'; 1105 alter table shipments_order_info add column delivery_time datetime default null comment '签收时间';
1106 alter table shipments_plan add column auto_generate bool default true comment '是否系统自动生成'; 1106 alter table shipments_plan add column auto_generate bool default true comment '是否系统自动生成';
  1107 +alter table shipments_plan add column source varchar(32) default null comment '来源(APPLY_SHIPMENT-申请发货,null-其它)';
1107 1108
1108 create table if not exists base_data_customer_short( 1109 create table if not exists base_data_customer_short(
1109 id varchar(32) primary key comment 'ID', 1110 id varchar(32) primary key comment 'ID',
@@ -58,6 +58,11 @@ public class ShipmentsPlan extends BaseEntity implements BaseDto { @@ -58,6 +58,11 @@ public class ShipmentsPlan extends BaseEntity implements BaseDto {
58 private Boolean autoGenerate; 58 private Boolean autoGenerate;
59 59
60 /** 60 /**
  61 + * 来源(APPLY_SHIPMENT-申请发货,null-其它)
  62 + */
  63 + private String source;
  64 +
  65 + /**
61 * 经营办审核人(发货计划提交人) 66 * 经营办审核人(发货计划提交人)
62 */ 67 */
63 private String businessOfficeAuditor; 68 private String businessOfficeAuditor;
@@ -207,7 +207,7 @@ public class ShipmentsPlanDetail extends BaseEntity implements BaseDto { @@ -207,7 +207,7 @@ public class ShipmentsPlanDetail extends BaseEntity implements BaseDto {
207 private LocalTime shipmentsTime; 207 private LocalTime shipmentsTime;
208 208
209 /** 209 /**
210 - * 是否预发 210 + * 是否预发(明日预发 false,后日预发 true)
211 */ 211 */
212 private Boolean preShipments; 212 private Boolean preShipments;
213 213
@@ -371,6 +371,7 @@ public class ShipmentsPlanDetailServiceImpl extends BaseMpServiceImpl<ShipmentsP @@ -371,6 +371,7 @@ public class ShipmentsPlanDetailServiceImpl extends BaseMpServiceImpl<ShipmentsP
371 plan.setWorkshopId(workshop.getId()); 371 plan.setWorkshopId(workshop.getId());
372 plan.setTomoPreShipDate(tomorrow); 372 plan.setTomoPreShipDate(tomorrow);
373 plan.setAfTomoPreShipDate(afTomorrow); 373 plan.setAfTomoPreShipDate(afTomorrow);
  374 + plan.setAutoGenerate(Boolean.TRUE);
374 375
375 shipmentsPlanService.getBaseMapper().insert(plan); 376 shipmentsPlanService.getBaseMapper().insert(plan);
376 // 生成发货计划明细 377 // 生成发货计划明细
@@ -417,6 +418,97 @@ public class ShipmentsPlanDetailServiceImpl extends BaseMpServiceImpl<ShipmentsP @@ -417,6 +418,97 @@ public class ShipmentsPlanDetailServiceImpl extends BaseMpServiceImpl<ShipmentsP
417 } 418 }
418 } 419 }
419 420
  421 + @Override
  422 + public void autoCreateShipmentPlanFromApply(String purchaseOrderId, String workshopId) {
  423 + // 1. 获取订货单数据
  424 + PurchaseOrderInfo orderInfo = purchaseOrderInfoService.findById(purchaseOrderId);
  425 + if (orderInfo == null) {
  426 + return;
  427 + }
  428 +
  429 + // 2. 过滤不需要发货的数据(参考autoCreateShipmentPlan逻辑)
  430 + String type = orderInfo.getType();
  431 + String examineStatus = orderInfo.getExamineStatus();
  432 + String status = orderInfo.getStatus();
  433 + String revokeStatus = orderInfo.getRevokeStatus();
  434 + String specChangeStatus = orderInfo.getSpecChangeStatus();
  435 + if (!"PRODUCTION".equals(type) || !"PASS".equals(examineStatus)
  436 + || "SHIPPED".equals(status) || "DELIVERED".equals(status) || "CANCEL".equals(status)
  437 + || "UNDOING".equals(revokeStatus) || "IN_PROGRESS".equals(specChangeStatus)) {
  438 + return;
  439 + }
  440 +
  441 + // 3. 获取订货单规格
  442 + List<PurchaseOrderLine> orderLines = purchaseOrderLineService.listByOrderIds(Collections.singletonList(purchaseOrderId), false);
  443 + if (CollectionUtils.isEmpty(orderLines)) {
  444 + return;
  445 + }
  446 +
  447 + // 4. 过滤已在发货计划中的数据(明日预发的数据)
  448 + List<String> specIds = orderLines.stream().map(PurchaseOrderLine::getId).collect(Collectors.toList());
  449 + LambdaQueryWrapper<ShipmentsPlanDetail> queryWrapper = Wrappers.lambdaQuery(ShipmentsPlanDetail.class);
  450 + queryWrapper.in(ShipmentsPlanDetail::getOrderSpecId, specIds)
  451 + .eq(ShipmentsPlanDetail::getDelFlag, Boolean.FALSE)
  452 + .eq(ShipmentsPlanDetail::getPreShipments, Boolean.FALSE);
  453 + List<ShipmentsPlanDetail> existingDetails = getBaseMapper().selectList(queryWrapper);
  454 + if (CollectionUtils.isNotEmpty(existingDetails)) {
  455 + // 过滤掉已在发货计划中的规格
  456 + List<String> existingSpecIds = existingDetails.stream()
  457 + .map(ShipmentsPlanDetail::getOrderSpecId).distinct().collect(Collectors.toList());
  458 + orderLines.removeIf(next -> existingSpecIds.contains(next.getId()));
  459 + }
  460 + if (CollectionUtils.isEmpty(orderLines)) {
  461 + return;
  462 + }
  463 +
  464 + // 5. 查找30分钟内同分厂的申请发货计划
  465 + LocalDateTime thirtyMinutesAgo = LocalDateTime.now().minusMinutes(30);
  466 + LambdaQueryWrapper<ShipmentsPlan> planQueryWrapper = Wrappers.lambdaQuery(ShipmentsPlan.class);
  467 + planQueryWrapper.eq(ShipmentsPlan::getWorkshopId, workshopId)
  468 + .eq(ShipmentsPlan::getSource, "APPLY_SHIPMENT")
  469 + .eq(ShipmentsPlan::getStatus, "DRAFT")
  470 + .ge(ShipmentsPlan::getCreateTime, thirtyMinutesAgo);
  471 + List<ShipmentsPlan> existingPlans = shipmentsPlanService.getBaseMapper().selectList(planQueryWrapper);
  472 +
  473 + ShipmentsPlan plan;
  474 + LocalDate tomorrow = LocalDate.now().plusDays(1);
  475 + if (CollectionUtils.isNotEmpty(existingPlans)) {
  476 + // 已存在30分钟内的计划,复用
  477 + plan = existingPlans.get(0);
  478 + } else {
  479 + // 新建发货计划
  480 + plan = new ShipmentsPlan();
  481 + plan.setId(IdUtil.getId());
  482 + plan.setStatus("DRAFT");
  483 + plan.setWorkshopId(workshopId);
  484 + plan.setTomoPreShipDate(tomorrow);
  485 + plan.setAfTomoPreShipDate(LocalDate.now().plusDays(2));
  486 + plan.setAutoGenerate(Boolean.TRUE);
  487 + plan.setSource("APPLY_SHIPMENT");
  488 + shipmentsPlanService.getBaseMapper().insert(plan);
  489 + }
  490 +
  491 + // 6. 生成发货计划明细,加入明日预发
  492 + List<ShipmentsPlanDetail> planDetails = new ArrayList<>();
  493 + for (PurchaseOrderLine line : orderLines) {
  494 + ShipmentsPlanDetail detail = new ShipmentsPlanDetail();
  495 + detail.setId(IdUtil.getId());
  496 + detail.setPlanId(plan.getId());
  497 + detail.setOrderId(purchaseOrderId);
  498 + detail.setOrderSpecId(line.getId());
  499 + detail.setShipmentsDate(tomorrow);
  500 + detail.setPreShipments(Boolean.FALSE);
  501 + detail.setDelFlag(Boolean.FALSE);
  502 + detail.setCreateById("1");
  503 + detail.setUpdateById("1");
  504 +
  505 + planDetails.add(detail);
  506 + }
  507 + if (CollectionUtils.isNotEmpty(planDetails)) {
  508 + getBaseMapper().batchAdd(planDetails);
  509 + }
  510 + }
  511 +
420 /** 512 /**
421 * 批量删除 513 * 批量删除
422 * 514 *
@@ -27,6 +27,7 @@ import com.lframework.xingyun.sc.entity.DraftRequestCarTicket; @@ -27,6 +27,7 @@ import com.lframework.xingyun.sc.entity.DraftRequestCarTicket;
27 import com.lframework.xingyun.sc.entity.PurchaseOrderInfo; 27 import com.lframework.xingyun.sc.entity.PurchaseOrderInfo;
28 import com.lframework.xingyun.sc.mappers.DraftRequestCarTicketMapper; 28 import com.lframework.xingyun.sc.mappers.DraftRequestCarTicketMapper;
29 import com.lframework.xingyun.sc.service.order.PurchaseOrderInfoService; 29 import com.lframework.xingyun.sc.service.order.PurchaseOrderInfoService;
  30 +import com.lframework.xingyun.sc.service.shipments.ShipmentsPlanDetailService;
30 import com.lframework.xingyun.sc.service.shipments.car.DraftRequestCarTicketService; 31 import com.lframework.xingyun.sc.service.shipments.car.DraftRequestCarTicketService;
31 import com.lframework.xingyun.sc.vo.shipments.car.*; 32 import com.lframework.xingyun.sc.vo.shipments.car.*;
32 import org.apache.commons.collections.CollectionUtils; 33 import org.apache.commons.collections.CollectionUtils;
@@ -51,6 +52,8 @@ public class DraftRequestCarTicketServiceImpl extends BaseMpServiceImpl<DraftReq @@ -51,6 +52,8 @@ public class DraftRequestCarTicketServiceImpl extends BaseMpServiceImpl<DraftReq
51 private PurchaseOrderInfoService purchaseOrderInfoService; 52 private PurchaseOrderInfoService purchaseOrderInfoService;
52 @Resource 53 @Resource
53 private SysUserService sysUserService; 54 private SysUserService sysUserService;
  55 + @Resource
  56 + private ShipmentsPlanDetailService shipmentsPlanDetailService;
54 57
55 @Override 58 @Override
56 public PageResult<DraftRequestCarTicket> query(Integer pageIndex, Integer pageSize, QueryDraftRequestCarTicketVo vo) { 59 public PageResult<DraftRequestCarTicket> query(Integer pageIndex, Integer pageSize, QueryDraftRequestCarTicketVo vo) {
@@ -185,6 +188,8 @@ public class DraftRequestCarTicketServiceImpl extends BaseMpServiceImpl<DraftReq @@ -185,6 +188,8 @@ public class DraftRequestCarTicketServiceImpl extends BaseMpServiceImpl<DraftReq
185 OpLogUtil.setVariable("id", data.getId()); 188 OpLogUtil.setVariable("id", data.getId());
186 OpLogUtil.setExtra(vo); 189 OpLogUtil.setExtra(vo);
187 if (!"SHIPMENTSPLAN".equals(vo.getSource())) { 190 if (!"SHIPMENTSPLAN".equals(vo.getSource())) {
  191 + // 申请发货自动生成发货计划,30分钟内同分厂数据加入同一个计划的明日预发
  192 + shipmentsPlanDetailService.autoCreateShipmentPlanFromApply(vo.getPurchaseOrderId(), vo.getWorkshopId());
188 //开启审核 193 //开启审核
189 data.setUpdateById(SecurityUtil.getCurrentUser().getId()); 194 data.setUpdateById(SecurityUtil.getCurrentUser().getId());
190 flowInstanceWrapperService.startInstance(BPM_FLAG, data.getId(), BPM_FLAG, data); 195 flowInstanceWrapperService.startInstance(BPM_FLAG, data.getId(), BPM_FLAG, data);
@@ -162,4 +162,13 @@ public interface ShipmentsPlanDetailService extends BaseMpService<ShipmentsPlanD @@ -162,4 +162,13 @@ public interface ShipmentsPlanDetailService extends BaseMpService<ShipmentsPlanD
162 * @return List<String> 162 * @return List<String>
163 */ 163 */
164 List<String> getOrderIdByShipmentOrderId(String shipmentOrderId); 164 List<String> getOrderIdByShipmentOrderId(String shipmentOrderId);
  165 +
  166 + /**
  167 + * 申请发货自动生成发货计划
  168 + * 30分钟内同分厂的数据加入同一个发货计划的明日预发
  169 + *
  170 + * @param purchaseOrderId 订货单ID
  171 + * @param workshopId 分厂ID
  172 + */
  173 + void autoCreateShipmentPlanFromApply(String purchaseOrderId, String workshopId);
165 } 174 }
@@ -10,6 +10,7 @@ @@ -10,6 +10,7 @@
10 <result column="tomo_pre_ship_date" property="tomoPreShipDate"/> 10 <result column="tomo_pre_ship_date" property="tomoPreShipDate"/>
11 <result column="af_tomo_pre_ship_date" property="afTomoPreShipDate"/> 11 <result column="af_tomo_pre_ship_date" property="afTomoPreShipDate"/>
12 <result column="auto_generate" property="autoGenerate"/> 12 <result column="auto_generate" property="autoGenerate"/>
  13 + <result column="source" property="source"/>
13 <result column="business_office_auditor" property="businessOfficeAuditor"/> 14 <result column="business_office_auditor" property="businessOfficeAuditor"/>
14 <result column="create_by_id" property="createById"/> 15 <result column="create_by_id" property="createById"/>
15 <result column="update_by_id" property="updateById"/> 16 <result column="update_by_id" property="updateById"/>
@@ -26,6 +27,7 @@ @@ -26,6 +27,7 @@
26 tb.tomo_pre_ship_date, 27 tb.tomo_pre_ship_date,
27 tb.af_tomo_pre_ship_date, 28 tb.af_tomo_pre_ship_date,
28 tb.auto_generate, 29 tb.auto_generate,
  30 + tb.source,
29 tb.business_office_auditor, 31 tb.business_office_auditor,
30 tb.create_by_id, 32 tb.create_by_id,
31 tb.update_by_id, 33 tb.update_by_id,