Commit 422ee31db088ba5272e2e9a0a18205c6dfba322f
1 parent
20f154b3
楚江erp: 1、要车计划、要成单生成逻辑调整;2、增加发货单编号生成逻辑
Showing
7 changed files
with
147 additions
and
119 deletions
| @@ -399,9 +399,7 @@ public class ShipmentsOrderInfoController extends DefaultBaseController { | @@ -399,9 +399,7 @@ public class ShipmentsOrderInfoController extends DefaultBaseController { | ||
| 399 | dataMap.put("totalActualQuantity", totalActualQuantity.doubleValue() > 0 ? totalActualQuantity.setScale(2, RoundingMode.HALF_UP) : null); | 399 | dataMap.put("totalActualQuantity", totalActualQuantity.doubleValue() > 0 ? totalActualQuantity.setScale(2, RoundingMode.HALF_UP) : null); |
| 400 | dataMap.put("totalNum", totalNum.doubleValue() > 0 ? totalNum.setScale(2, RoundingMode.HALF_UP) : null); | 400 | dataMap.put("totalNum", totalNum.doubleValue() > 0 ? totalNum.setScale(2, RoundingMode.HALF_UP) : null); |
| 401 | dataMap.put("totalPrice", totalPrice.doubleValue() > 0 ? totalPrice.setScale(2, RoundingMode.HALF_UP) : null); | 401 | dataMap.put("totalPrice", totalPrice.doubleValue() > 0 ? totalPrice.setScale(2, RoundingMode.HALF_UP) : null); |
| 402 | - // 流水号 | ||
| 403 | - String serialNumber = createSerialNumber(null, "SHIPMENT_ORDER_SERIAL_NUMBER"); | ||
| 404 | - dataMap.put("serialNumber", serialNumber); | 402 | + dataMap.put("serialNumber", orderInfo.getCode()); |
| 405 | // 办事处 | 403 | // 办事处 |
| 406 | String deptId = orderInfo.getDeptId(); | 404 | String deptId = orderInfo.getDeptId(); |
| 407 | if (StringUtils.isNotBlank(deptId)) { | 405 | if (StringUtils.isNotBlank(deptId)) { |
| @@ -437,7 +435,7 @@ public class ShipmentsOrderInfoController extends DefaultBaseController { | @@ -437,7 +435,7 @@ public class ShipmentsOrderInfoController extends DefaultBaseController { | ||
| 437 | // 处理模板中的占位符 | 435 | // 处理模板中的占位符 |
| 438 | ExcelUtil.processTemplate(workbook, dataMap); | 436 | ExcelUtil.processTemplate(workbook, dataMap); |
| 439 | // 生成文件名 | 437 | // 生成文件名 |
| 440 | - String fileName = String.format("发货单_%s.xlsx", serialNumber); | 438 | + String fileName = String.format("发货单_%s.xlsx", orderInfo.getCode()); |
| 441 | File excelFile = new File(tempDir.toFile(), fileName); | 439 | File excelFile = new File(tempDir.toFile(), fileName); |
| 442 | // 保存Excel文件 | 440 | // 保存Excel文件 |
| 443 | try (FileOutputStream fos = new FileOutputStream(excelFile)) { | 441 | try (FileOutputStream fos = new FileOutputStream(excelFile)) { |
| @@ -532,36 +530,4 @@ public class ShipmentsOrderInfoController extends DefaultBaseController { | @@ -532,36 +530,4 @@ public class ShipmentsOrderInfoController extends DefaultBaseController { | ||
| 532 | log.warn("清理临时文件失败", e); | 530 | log.warn("清理临时文件失败", e); |
| 533 | } | 531 | } |
| 534 | } | 532 | } |
| 535 | - | ||
| 536 | - | ||
| 537 | - | ||
| 538 | - /** | ||
| 539 | - * 生成当天流水号 | ||
| 540 | - * | ||
| 541 | - * @return String | ||
| 542 | - */ | ||
| 543 | - public String createSerialNumber(String pre, String key) { | ||
| 544 | - // 1. 获取当前年月日(格式:yyyyMMdd) | ||
| 545 | - String datePart = LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")); | ||
| 546 | - // 2. Redis自增序列 | ||
| 547 | - Long id = redisTemplate.opsForValue().increment(key, 1); | ||
| 548 | - if (id != null && id == 1) { | ||
| 549 | - // 计算到次日零点的秒数 | ||
| 550 | - LocalDateTime now = LocalDateTime.now(); | ||
| 551 | - LocalDateTime midnight = now.toLocalDate().plusDays(1).atStartOfDay(); | ||
| 552 | - long secondsUntilMidnight = Duration.between(now, midnight).getSeconds(); | ||
| 553 | - | ||
| 554 | - redisTemplate.expire(key, secondsUntilMidnight, TimeUnit.SECONDS); | ||
| 555 | - } | ||
| 556 | - // 3. 补零到4位 | ||
| 557 | - String incrPart = String.format("%04d", id); | ||
| 558 | - // 4. 拼接最终结果 | ||
| 559 | - String result = ""; | ||
| 560 | - if (StringUtils.isBlank(pre)) { | ||
| 561 | - result = datePart + incrPart; | ||
| 562 | - } else { | ||
| 563 | - result = pre + datePart + incrPart; | ||
| 564 | - } | ||
| 565 | - return result; | ||
| 566 | - } | ||
| 567 | } | 533 | } |
| @@ -536,17 +536,10 @@ public class BusinessDataHandlerServiceImpl implements BusinessDataHandlerServic | @@ -536,17 +536,10 @@ public class BusinessDataHandlerServiceImpl implements BusinessDataHandlerServic | ||
| 536 | draftRequestCarTicketService.updateExamineUser(businessId, SecurityUtil.getCurrentUser().getId(), null, null); | 536 | draftRequestCarTicketService.updateExamineUser(businessId, SecurityUtil.getCurrentUser().getId(), null, null); |
| 537 | //如果是发货计划生成的草稿要车单-需要生成要车单和要车计划 | 537 | //如果是发货计划生成的草稿要车单-需要生成要车单和要车计划 |
| 538 | DraftRequestCarTicket draftRequestCarTicket = draftRequestCarTicketService.findById(businessId); | 538 | DraftRequestCarTicket draftRequestCarTicket = draftRequestCarTicketService.findById(businessId); |
| 539 | - if (StringUtils.isNotEmpty(draftRequestCarTicket.getSource()) && "SHIPMENTSPLAN".equals(draftRequestCarTicket.getSource())) { | ||
| 540 | - // 生成要车计划 | ||
| 541 | - CreateCarRequestPlanVo planCreateVo = new CreateCarRequestPlanVo(); | ||
| 542 | - planCreateVo.setRequestCarDate(LocalDate.now()); | ||
| 543 | - planCreateVo.setWorkshopId(draftRequestCarTicket.getWorkshopId()); | ||
| 544 | - String requestCarPlanId = carRequestPlanService.create(planCreateVo); | ||
| 545 | - // 生成要车单 | ||
| 546 | - CreateRequestCarTicketVo ticketCreateVo = packRequestCarTicket(draftRequestCarTicket, requestCarPlanId, variable); | ||
| 547 | - requestCarTicketService.create(ticketCreateVo); | 539 | + if (draftRequestCarTicket != null && "SHIPMENTSPLAN".equals(draftRequestCarTicket.getSource())) { |
| 548 | // 处理发货单 | 540 | // 处理发货单 |
| 549 | - List<String> orderIds = shipmentsPlanDetailService.getOrderIdByShipmentOrderId(ticketCreateVo.getShipmentsOrderId()); | 541 | + String shipmentOrderId = (String) redisHandler.get("GET_SHIPMENTS_ORDER_ID_" + draftRequestCarTicket.getId()); |
| 542 | + List<String> orderIds = shipmentsPlanDetailService.getOrderIdByShipmentOrderId(shipmentOrderId); | ||
| 550 | List<DraftRequestCarTicket> draftRequestCarTicketList = draftRequestCarTicketService.listByOrderId(orderIds); | 543 | List<DraftRequestCarTicket> draftRequestCarTicketList = draftRequestCarTicketService.listByOrderId(orderIds); |
| 551 | if (CollectionUtils.isNotEmpty(draftRequestCarTicketList)) { | 544 | if (CollectionUtils.isNotEmpty(draftRequestCarTicketList)) { |
| 552 | boolean flag = true; | 545 | boolean flag = true; |
| @@ -561,7 +554,7 @@ public class BusinessDataHandlerServiceImpl implements BusinessDataHandlerServic | @@ -561,7 +554,7 @@ public class BusinessDataHandlerServiceImpl implements BusinessDataHandlerServic | ||
| 561 | } | 554 | } |
| 562 | if (flag) { | 555 | if (flag) { |
| 563 | // 更新订货单状态(草稿转为正常) | 556 | // 更新订货单状态(草稿转为正常) |
| 564 | - shipmentsOrderInfoService.updateStatus(ticketCreateVo.getShipmentsOrderId(), "UN_SHIPMENTS"); | 557 | + shipmentsOrderInfoService.updateStatus(shipmentOrderId, "UN_SHIPMENTS"); |
| 565 | } | 558 | } |
| 566 | } | 559 | } |
| 567 | } | 560 | } |
xingyun-sc/src/main/java/com/lframework/xingyun/sc/impl/shipments/ShipmentsOrderInfoServiceImpl.java
| @@ -37,11 +37,10 @@ import com.lframework.xingyun.sc.service.shipments.ShipmentsPlanService; | @@ -37,11 +37,10 @@ import com.lframework.xingyun.sc.service.shipments.ShipmentsPlanService; | ||
| 37 | import com.lframework.xingyun.sc.service.shipments.car.CarRequestPlanService; | 37 | import com.lframework.xingyun.sc.service.shipments.car.CarRequestPlanService; |
| 38 | import com.lframework.xingyun.sc.service.shipments.car.DraftRequestCarTicketService; | 38 | import com.lframework.xingyun.sc.service.shipments.car.DraftRequestCarTicketService; |
| 39 | import com.lframework.xingyun.sc.service.shipments.car.RequestCarTicketService; | 39 | import com.lframework.xingyun.sc.service.shipments.car.RequestCarTicketService; |
| 40 | +import com.lframework.xingyun.sc.service.statistics.ShipmentDetailStatisticsService; | ||
| 40 | import com.lframework.xingyun.sc.utils.CommonUtil; | 41 | import com.lframework.xingyun.sc.utils.CommonUtil; |
| 41 | import com.lframework.xingyun.sc.vo.sample.tracking.CreateSampleResultTrackingVo; | 42 | import com.lframework.xingyun.sc.vo.sample.tracking.CreateSampleResultTrackingVo; |
| 42 | -import com.lframework.xingyun.sc.vo.shipments.car.CreateCarRequestPlanVo; | ||
| 43 | import com.lframework.xingyun.sc.vo.shipments.car.CreateDraftRequestCarTicketVo; | 43 | import com.lframework.xingyun.sc.vo.shipments.car.CreateDraftRequestCarTicketVo; |
| 44 | -import com.lframework.xingyun.sc.vo.shipments.car.CreateRequestCarTicketVo; | ||
| 45 | import com.lframework.xingyun.sc.vo.shipments.order.*; | 44 | import com.lframework.xingyun.sc.vo.shipments.order.*; |
| 46 | import com.lframework.xingyun.sc.vo.shipments.plan.QueryShipmentsPlanDetailVo; | 45 | import com.lframework.xingyun.sc.vo.shipments.plan.QueryShipmentsPlanDetailVo; |
| 47 | import lombok.extern.slf4j.Slf4j; | 46 | import lombok.extern.slf4j.Slf4j; |
| @@ -59,7 +58,7 @@ import java.math.BigDecimal; | @@ -59,7 +58,7 @@ import java.math.BigDecimal; | ||
| 59 | import java.time.LocalDate; | 58 | import java.time.LocalDate; |
| 60 | import java.time.LocalDateTime; | 59 | import java.time.LocalDateTime; |
| 61 | import java.time.LocalTime; | 60 | import java.time.LocalTime; |
| 62 | -import java.time.format.DateTimeFormatter; | 61 | +import java.time.temporal.TemporalAdjusters; |
| 63 | import java.util.*; | 62 | import java.util.*; |
| 64 | import java.util.function.Function; | 63 | import java.util.function.Function; |
| 65 | import java.util.stream.Collectors; | 64 | import java.util.stream.Collectors; |
| @@ -102,6 +101,8 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr | @@ -102,6 +101,8 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr | ||
| 102 | private SampleResultTrackingService sampleResultTrackingService; | 101 | private SampleResultTrackingService sampleResultTrackingService; |
| 103 | @Resource | 102 | @Resource |
| 104 | private SampleResultFeedbackService sampleResultFeedbackService; | 103 | private SampleResultFeedbackService sampleResultFeedbackService; |
| 104 | + @Resource | ||
| 105 | + private ShipmentDetailStatisticsService shipmentDetailStatisticsService; | ||
| 105 | 106 | ||
| 106 | 107 | ||
| 107 | @Override | 108 | @Override |
| @@ -462,6 +463,11 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr | @@ -462,6 +463,11 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr | ||
| 462 | if (BooleanUtils.isTrue(vo.getOnTimeShipment()) && !now.isBefore(shipmentsDate)) { | 463 | if (BooleanUtils.isTrue(vo.getOnTimeShipment()) && !now.isBefore(shipmentsDate)) { |
| 463 | // 生成应收款台账明细数据 | 464 | // 生成应收款台账明细数据 |
| 464 | receiptLedgerInfoService.generateLedgerInfo(Collections.singletonList(orderInfo)); | 465 | receiptLedgerInfoService.generateLedgerInfo(Collections.singletonList(orderInfo)); |
| 466 | + // 生成发货明细报表数据 | ||
| 467 | + shipmentDetailStatisticsService.generateStatisticsData(detailIds); | ||
| 468 | + // 生成要车计划、要车单数据 | ||
| 469 | + ShipmentsOrderInfo shipmentsOrderInfo = findById(shipmentsOrderId); | ||
| 470 | + carRequestPlanService.generate(orderInfoList, shipmentsOrderInfo); | ||
| 465 | } | 471 | } |
| 466 | //生成产品试样结果跟踪单 | 472 | //生成产品试样结果跟踪单 |
| 467 | if (CollectionUtils.isNotEmpty(orderIds)) { | 473 | if (CollectionUtils.isNotEmpty(orderIds)) { |
| @@ -782,6 +788,15 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr | @@ -782,6 +788,15 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr | ||
| 782 | // 封装发货单数据 | 788 | // 封装发货单数据 |
| 783 | ShipmentsOrderInfo shipmentsOrderInfo = new ShipmentsOrderInfo(); | 789 | ShipmentsOrderInfo shipmentsOrderInfo = new ShipmentsOrderInfo(); |
| 784 | shipmentsOrderInfo.setId(id); | 790 | shipmentsOrderInfo.setId(id); |
| 791 | + // 发货单编号处理 | ||
| 792 | + // 获取当月最后一天的23:59:59 | ||
| 793 | + LocalDateTime monthEnd = LocalDateTime.now() | ||
| 794 | + .with(TemporalAdjusters.lastDayOfMonth()) | ||
| 795 | + .withHour(23) | ||
| 796 | + .withMinute(59) | ||
| 797 | + .withSecond(59); | ||
| 798 | + String serialNumber = CommonUtil.generateSerialNumber(null, "", "yyMM", LocalDateTime.now(), monthEnd); | ||
| 799 | + shipmentsOrderInfo.setCode(serialNumber); | ||
| 785 | shipmentsOrderInfo.setPlanId(planId); | 800 | shipmentsOrderInfo.setPlanId(planId); |
| 786 | shipmentsOrderInfo.setCustomerId(customerId); | 801 | shipmentsOrderInfo.setCustomerId(customerId); |
| 787 | shipmentsOrderInfo.setWorkshopId(plan.getWorkshopId()); | 802 | shipmentsOrderInfo.setWorkshopId(plan.getWorkshopId()); |
| @@ -859,20 +874,6 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr | @@ -859,20 +874,6 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr | ||
| 859 | mqProducerService.createSysSiteMessage(messageDto); | 874 | mqProducerService.createSysSiteMessage(messageDto); |
| 860 | // 更新发货单状态为草稿 | 875 | // 更新发货单状态为草稿 |
| 861 | updateStatus(shipmentsOrderId, "DRAFT"); | 876 | updateStatus(shipmentsOrderId, "DRAFT"); |
| 862 | - continue; | ||
| 863 | - } | ||
| 864 | - if ("PASS".equals(draftTicket.getStatus())) { | ||
| 865 | - // 生成要车计划 | ||
| 866 | - CreateCarRequestPlanVo planCreateVo = new CreateCarRequestPlanVo(); | ||
| 867 | - planCreateVo.setRequestCarDate(LocalDate.now()); | ||
| 868 | - planCreateVo.setWorkshopId(orderInfo.getWorkshopId()); | ||
| 869 | - String requestCarPlanId = carRequestPlanService.create(planCreateVo); | ||
| 870 | - // 生成要车单 | ||
| 871 | - CreateRequestCarTicketVo ticketCreateVo = packRequestCarTicket(orderInfo, requestCarPlanId, draftTicket, | ||
| 872 | - plan.getTomoPreShipDate(), quantity, shipmentsOrderId); | ||
| 873 | - requestCarTicketService.create(ticketCreateVo); | ||
| 874 | - } else { | ||
| 875 | - throw new DefaultClientException("请先补充草稿要车单数据!"); | ||
| 876 | } | 877 | } |
| 877 | } | 878 | } |
| 878 | } | 879 | } |
| @@ -901,51 +902,6 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr | @@ -901,51 +902,6 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr | ||
| 901 | return draftTicketVo; | 902 | return draftTicketVo; |
| 902 | } | 903 | } |
| 903 | 904 | ||
| 904 | - /** | ||
| 905 | - * 封装要车单数据 | ||
| 906 | - * | ||
| 907 | - * @param orderInfo 订货单数据 | ||
| 908 | - * @return CreateRequestCarTicketVo | ||
| 909 | - */ | ||
| 910 | - private CreateRequestCarTicketVo packRequestCarTicket(PurchaseOrderInfo orderInfo, String planId, DraftRequestCarTicket draftTicket, | ||
| 911 | - LocalDate shipmentsDate, BigDecimal quantity, String shipmentsOrderId) { | ||
| 912 | - QueryShipmentsPlanDetailVo vo = new QueryShipmentsPlanDetailVo(); | ||
| 913 | - vo.setShipmentsOrderId(shipmentsOrderId); | ||
| 914 | - vo.setOrderId(orderInfo.getId()); | ||
| 915 | - List<ShipmentsPlanDetail> details = shipmentsPlanDetailService.query(vo); | ||
| 916 | - LocalTime minTime = details.stream() | ||
| 917 | - .map(ShipmentsPlanDetail::getShipmentsTime) | ||
| 918 | - .min(LocalTime::compareTo) | ||
| 919 | - .orElse(null); | ||
| 920 | - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm"); | ||
| 921 | - String loadingTime = minTime.format(formatter); | ||
| 922 | - | ||
| 923 | - CreateRequestCarTicketVo ticketVo = new CreateRequestCarTicketVo(); | ||
| 924 | - ticketVo.setDraftId(draftTicket.getId()); | ||
| 925 | - ticketVo.setPlanId(planId); | ||
| 926 | - ticketVo.setPurchaseOrderId(orderInfo.getId()); | ||
| 927 | - ticketVo.setRequestCarDate(LocalDate.now()); | ||
| 928 | - ticketVo.setDeptId(orderInfo.getDeptId()); | ||
| 929 | - ticketVo.setDeliveryDate(shipmentsDate); | ||
| 930 | - ticketVo.setWorkshopId(orderInfo.getWorkshopId()); | ||
| 931 | - ticketVo.setOrderNo(orderInfo.getOrderNo()); | ||
| 932 | - ticketVo.setOrderingUnit(orderInfo.getOrderingUnit()); | ||
| 933 | - ticketVo.setQuantity(quantity); | ||
| 934 | - ticketVo.setShipmentsOrderId(shipmentsOrderId); | ||
| 935 | - //外办审核人(草稿要车单审核人) | ||
| 936 | - ticketVo.setExternalAuditor(draftTicket.getExternalAuditor()); | ||
| 937 | - //经营办审核人(发货计划提交人) | ||
| 938 | - ticketVo.setBusinessOfficeAuditor(SecurityUtil.getCurrentUser().getId()); | ||
| 939 | - ticketVo.setDestination(draftTicket.getDestination()); | ||
| 940 | - ticketVo.setConsignee(draftTicket.getConsignee()); | ||
| 941 | - ticketVo.setPhone(draftTicket.getPhone()); | ||
| 942 | - ticketVo.setReturnPlanArrangement(draftTicket.getReturnPlanArrangement()); | ||
| 943 | - ticketVo.setOther(draftTicket.getOther()); | ||
| 944 | - ticketVo.setSpecialLoadingRequirement(draftTicket.getSpecialLoadingRequirement()); | ||
| 945 | - ticketVo.setLoadingTime(loadingTime); | ||
| 946 | - return ticketVo; | ||
| 947 | - } | ||
| 948 | - | ||
| 949 | 905 | ||
| 950 | /** | 906 | /** |
| 951 | * 数据过滤 | 907 | * 数据过滤 |
xingyun-sc/src/main/java/com/lframework/xingyun/sc/impl/shipments/car/CarRequestPlanServiceImpl.java
| @@ -18,27 +18,31 @@ import com.lframework.starter.web.core.annotations.oplog.OpLog; | @@ -18,27 +18,31 @@ import com.lframework.starter.web.core.annotations.oplog.OpLog; | ||
| 18 | import com.lframework.starter.web.core.utils.PageHelperUtil; | 18 | import com.lframework.starter.web.core.utils.PageHelperUtil; |
| 19 | import com.lframework.starter.common.utils.Assert; | 19 | import com.lframework.starter.common.utils.Assert; |
| 20 | import com.lframework.starter.web.inner.components.oplog.OtherOpLogType; | 20 | import com.lframework.starter.web.inner.components.oplog.OtherOpLogType; |
| 21 | -import com.lframework.xingyun.sc.entity.CarRequestPlan; | ||
| 22 | -import com.lframework.xingyun.sc.entity.RequestCarTicket; | 21 | +import com.lframework.xingyun.sc.entity.*; |
| 23 | import com.lframework.xingyun.sc.mappers.CarRequestPlanMapper; | 22 | import com.lframework.xingyun.sc.mappers.CarRequestPlanMapper; |
| 24 | import com.lframework.xingyun.sc.service.shipments.car.CarRequestPlanService; | 23 | import com.lframework.xingyun.sc.service.shipments.car.CarRequestPlanService; |
| 24 | +import com.lframework.xingyun.sc.service.shipments.car.DraftRequestCarTicketService; | ||
| 25 | import com.lframework.xingyun.sc.service.shipments.car.RequestCarTicketService; | 25 | import com.lframework.xingyun.sc.service.shipments.car.RequestCarTicketService; |
| 26 | -import com.lframework.xingyun.sc.vo.shipments.car.CreateCarRequestPlanVo; | ||
| 27 | -import com.lframework.xingyun.sc.vo.shipments.car.QueryCarRequestPlanVo; | ||
| 28 | -import com.lframework.xingyun.sc.vo.shipments.car.QueryRequestCarTicketVo; | ||
| 29 | -import com.lframework.xingyun.sc.vo.shipments.car.UpdateCarRequestPlanVo; | 26 | +import com.lframework.xingyun.sc.vo.shipments.car.*; |
| 27 | +import org.apache.commons.collections4.CollectionUtils; | ||
| 28 | +import org.apache.commons.lang3.BooleanUtils; | ||
| 30 | import org.springframework.transaction.annotation.Transactional; | 29 | import org.springframework.transaction.annotation.Transactional; |
| 31 | import org.springframework.stereotype.Service; | 30 | import org.springframework.stereotype.Service; |
| 32 | import javax.annotation.Resource; | 31 | import javax.annotation.Resource; |
| 33 | import java.time.LocalDate; | 32 | import java.time.LocalDate; |
| 33 | +import java.time.LocalTime; | ||
| 34 | import java.time.format.DateTimeFormatter; | 34 | import java.time.format.DateTimeFormatter; |
| 35 | import java.util.List; | 35 | import java.util.List; |
| 36 | +import java.util.Map; | ||
| 37 | +import java.util.function.Function; | ||
| 36 | import java.util.stream.Collectors; | 38 | import java.util.stream.Collectors; |
| 37 | 39 | ||
| 38 | @Service | 40 | @Service |
| 39 | public class CarRequestPlanServiceImpl extends BaseMpServiceImpl<CarRequestPlanMapper, CarRequestPlan> implements CarRequestPlanService { | 41 | public class CarRequestPlanServiceImpl extends BaseMpServiceImpl<CarRequestPlanMapper, CarRequestPlan> implements CarRequestPlanService { |
| 40 | @Resource | 42 | @Resource |
| 41 | private RequestCarTicketService requestCarTicketService; | 43 | private RequestCarTicketService requestCarTicketService; |
| 44 | + @Resource | ||
| 45 | + private DraftRequestCarTicketService draftRequestCarTicketService; | ||
| 42 | 46 | ||
| 43 | @Override | 47 | @Override |
| 44 | public PageResult<CarRequestPlan> query(Integer pageIndex, Integer pageSize, QueryCarRequestPlanVo vo) { | 48 | public PageResult<CarRequestPlan> query(Integer pageIndex, Integer pageSize, QueryCarRequestPlanVo vo) { |
| @@ -145,6 +149,68 @@ public class CarRequestPlanServiceImpl extends BaseMpServiceImpl<CarRequestPlanM | @@ -145,6 +149,68 @@ public class CarRequestPlanServiceImpl extends BaseMpServiceImpl<CarRequestPlanM | ||
| 145 | } | 149 | } |
| 146 | 150 | ||
| 147 | @Override | 151 | @Override |
| 152 | + @Transactional(rollbackFor = Exception.class) | ||
| 153 | + public void generate(List<PurchaseOrderInfo> orderInfoList, ShipmentsOrderInfo shipmentsOrderInfo) { | ||
| 154 | + if (CollectionUtils.isEmpty(orderInfoList) || shipmentsOrderInfo == null) { | ||
| 155 | + return; | ||
| 156 | + } | ||
| 157 | + List<String> orderIds = orderInfoList.stream().map(PurchaseOrderInfo::getId).collect(Collectors.toList()); | ||
| 158 | + // 根据订货单获取草稿要车单 | ||
| 159 | + List<DraftRequestCarTicket> draftTickets = draftRequestCarTicketService.listByOrderId(orderIds); | ||
| 160 | + Map<String, DraftRequestCarTicket> draftTicketMap = draftTickets.stream().collect(Collectors.toMap(DraftRequestCarTicket::getPurchaseOrderId, Function.identity() | ||
| 161 | + , (v1, v2) -> v2)); | ||
| 162 | + for (PurchaseOrderInfo orderInfo : orderInfoList) { | ||
| 163 | + // 生成要车计划 | ||
| 164 | + CreateCarRequestPlanVo planCreateVo = new CreateCarRequestPlanVo(); | ||
| 165 | + planCreateVo.setRequestCarDate(LocalDate.now()); | ||
| 166 | + planCreateVo.setWorkshopId(orderInfo.getWorkshopId()); | ||
| 167 | + String requestCarPlanId = create(planCreateVo); | ||
| 168 | + // 生成要车单 | ||
| 169 | + DraftRequestCarTicket draftTicket = draftTicketMap.get(orderInfo.getId()); | ||
| 170 | + if (draftTicket == null) { | ||
| 171 | + throw new DefaultClientException("请先补充草稿要车单数据!"); | ||
| 172 | + } | ||
| 173 | + CreateRequestCarTicketVo ticketVo = new CreateRequestCarTicketVo(); | ||
| 174 | + ticketVo.setDraftId(draftTicket.getId()); | ||
| 175 | + ticketVo.setPlanId(requestCarPlanId); | ||
| 176 | + ticketVo.setPurchaseOrderId(orderInfo.getId()); | ||
| 177 | + ticketVo.setRequestCarDate(LocalDate.now()); | ||
| 178 | + ticketVo.setDeptId(orderInfo.getDeptId()); | ||
| 179 | + if (BooleanUtils.isFalse(shipmentsOrderInfo.getOnTimeShipment())) { | ||
| 180 | + ticketVo.setDeliveryDate(shipmentsOrderInfo.getNewShipmentDate()); | ||
| 181 | + } else { | ||
| 182 | + ticketVo.setDeliveryDate(shipmentsOrderInfo.getShipmentsDate()); | ||
| 183 | + } | ||
| 184 | + ticketVo.setWorkshopId(orderInfo.getWorkshopId()); | ||
| 185 | + ticketVo.setOrderNo(orderInfo.getOrderNo()); | ||
| 186 | + ticketVo.setOrderingUnit(orderInfo.getOrderingUnit()); | ||
| 187 | + ticketVo.setQuantity(orderInfo.getTotalQuantity()); | ||
| 188 | + ticketVo.setShipmentsOrderId(shipmentsOrderInfo.getId()); | ||
| 189 | + //外办审核人(草稿要车单审核人) | ||
| 190 | + ticketVo.setExternalAuditor(draftTicket.getExternalAuditor()); | ||
| 191 | + //经营办审核人(发货计划提交人) | ||
| 192 | + ticketVo.setBusinessOfficeAuditor(SecurityUtil.getCurrentUser().getId()); | ||
| 193 | + ticketVo.setDestination(draftTicket.getDestination()); | ||
| 194 | + ticketVo.setConsignee(draftTicket.getConsignee()); | ||
| 195 | + ticketVo.setPhone(draftTicket.getPhone()); | ||
| 196 | + ticketVo.setReturnPlanArrangement(draftTicket.getReturnPlanArrangement()); | ||
| 197 | + ticketVo.setOther(draftTicket.getOther()); | ||
| 198 | + ticketVo.setSpecialLoadingRequirement(draftTicket.getSpecialLoadingRequirement()); | ||
| 199 | + // 装货时间处理 | ||
| 200 | + LocalTime minTime = shipmentsOrderInfo.getDetailList().stream() | ||
| 201 | + .map(ShipmentsPlanDetail::getShipmentsTime) | ||
| 202 | + .min(LocalTime::compareTo) | ||
| 203 | + .orElse(null); | ||
| 204 | + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm"); | ||
| 205 | + if (minTime != null) { | ||
| 206 | + String loadingTime = minTime.format(formatter); | ||
| 207 | + ticketVo.setLoadingTime(loadingTime); | ||
| 208 | + } | ||
| 209 | + requestCarTicketService.create(ticketVo); | ||
| 210 | + } | ||
| 211 | + } | ||
| 212 | + | ||
| 213 | + @Override | ||
| 148 | public void cleanCacheByKey(Serializable key) { | 214 | public void cleanCacheByKey(Serializable key) { |
| 149 | 215 | ||
| 150 | } | 216 | } |
| @@ -3,6 +3,8 @@ package com.lframework.xingyun.sc.service.shipments.car; | @@ -3,6 +3,8 @@ package com.lframework.xingyun.sc.service.shipments.car; | ||
| 3 | import com.lframework.starter.web.core.service.BaseMpService; | 3 | import com.lframework.starter.web.core.service.BaseMpService; |
| 4 | import com.lframework.starter.web.core.components.resp.PageResult; | 4 | import com.lframework.starter.web.core.components.resp.PageResult; |
| 5 | import com.lframework.xingyun.sc.entity.CarRequestPlan; | 5 | import com.lframework.xingyun.sc.entity.CarRequestPlan; |
| 6 | +import com.lframework.xingyun.sc.entity.PurchaseOrderInfo; | ||
| 7 | +import com.lframework.xingyun.sc.entity.ShipmentsOrderInfo; | ||
| 6 | import com.lframework.xingyun.sc.vo.shipments.car.CreateCarRequestPlanVo; | 8 | import com.lframework.xingyun.sc.vo.shipments.car.CreateCarRequestPlanVo; |
| 7 | import com.lframework.xingyun.sc.vo.shipments.car.QueryCarRequestPlanVo; | 9 | import com.lframework.xingyun.sc.vo.shipments.car.QueryCarRequestPlanVo; |
| 8 | import com.lframework.xingyun.sc.vo.shipments.car.UpdateCarRequestPlanVo; | 10 | import com.lframework.xingyun.sc.vo.shipments.car.UpdateCarRequestPlanVo; |
| @@ -52,4 +54,12 @@ public interface CarRequestPlanService extends BaseMpService<CarRequestPlan> { | @@ -52,4 +54,12 @@ public interface CarRequestPlanService extends BaseMpService<CarRequestPlan> { | ||
| 52 | * @return | 54 | * @return |
| 53 | */ | 55 | */ |
| 54 | void deleteById(String id); | 56 | void deleteById(String id); |
| 57 | + | ||
| 58 | + /** | ||
| 59 | + * 生成要车计划、要车单数据 | ||
| 60 | + * | ||
| 61 | + * @param orderInfoList 订货单数据 | ||
| 62 | + * @param shipmentsOrderInfo 发货单信息 | ||
| 63 | + */ | ||
| 64 | + void generate(List<PurchaseOrderInfo> orderInfoList, ShipmentsOrderInfo shipmentsOrderInfo); | ||
| 55 | } | 65 | } |
| 1 | package com.lframework.xingyun.sc.utils; | 1 | package com.lframework.xingyun.sc.utils; |
| 2 | 2 | ||
| 3 | import com.lframework.starter.common.exceptions.impl.DefaultClientException; | 3 | import com.lframework.starter.common.exceptions.impl.DefaultClientException; |
| 4 | +import com.lframework.starter.web.core.utils.ApplicationUtil; | ||
| 4 | import lombok.extern.slf4j.Slf4j; | 5 | import lombok.extern.slf4j.Slf4j; |
| 5 | import org.apache.commons.collections4.CollectionUtils; | 6 | import org.apache.commons.collections4.CollectionUtils; |
| 7 | +import org.apache.commons.lang3.StringUtils; | ||
| 8 | +import org.springframework.data.redis.core.RedisTemplate; | ||
| 6 | 9 | ||
| 7 | import java.io.*; | 10 | import java.io.*; |
| 8 | import java.math.BigDecimal; | 11 | import java.math.BigDecimal; |
| 9 | import java.math.RoundingMode; | 12 | import java.math.RoundingMode; |
| 10 | -import java.time.LocalDate; | ||
| 11 | -import java.time.LocalDateTime; | ||
| 12 | -import java.time.Year; | ||
| 13 | -import java.time.YearMonth; | 13 | +import java.time.*; |
| 14 | import java.time.format.DateTimeFormatter; | 14 | import java.time.format.DateTimeFormatter; |
| 15 | import java.util.ArrayList; | 15 | import java.util.ArrayList; |
| 16 | import java.util.Collections; | 16 | import java.util.Collections; |
| 17 | import java.util.List; | 17 | import java.util.List; |
| 18 | +import java.util.concurrent.TimeUnit; | ||
| 18 | 19 | ||
| 19 | @Slf4j | 20 | @Slf4j |
| 20 | public class CommonUtil { | 21 | public class CommonUtil { |
| @@ -169,4 +170,38 @@ public class CommonUtil { | @@ -169,4 +170,38 @@ public class CommonUtil { | ||
| 169 | } | 170 | } |
| 170 | return String.valueOf(num); | 171 | return String.valueOf(num); |
| 171 | } | 172 | } |
| 173 | + | ||
| 174 | + | ||
| 175 | + /** | ||
| 176 | + * 生成流水号 | ||
| 177 | + * | ||
| 178 | + * @param pre 流水号前缀 | ||
| 179 | + * @param key 缓存key | ||
| 180 | + * @param format 时间格式 | ||
| 181 | + * @param startTime 缓存开始时间 | ||
| 182 | + * @param endTime 缓存到期时间 | ||
| 183 | + * @return String | ||
| 184 | + */ | ||
| 185 | + public static String generateSerialNumber(String pre, String key, String format, LocalDateTime startTime, LocalDateTime endTime) { | ||
| 186 | + // 1. 获取当前时间,并做格式化处理 | ||
| 187 | + String datePart = LocalDate.now().format(DateTimeFormatter.ofPattern(format)); | ||
| 188 | + // 2. Redis自增序列 | ||
| 189 | + RedisTemplate redisTemplate = ApplicationUtil.getBean(RedisTemplate.class); | ||
| 190 | + Long id = redisTemplate.opsForValue().increment(key, 1); | ||
| 191 | + if (id != null && id == 1) { | ||
| 192 | + // 计算时间差(秒) | ||
| 193 | + long secondsUntilMidnight = Duration.between(startTime, endTime).getSeconds(); | ||
| 194 | + redisTemplate.expire(key, secondsUntilMidnight, TimeUnit.SECONDS); | ||
| 195 | + } | ||
| 196 | + // 3. 补零到4位 | ||
| 197 | + String incrPart = String.format("%04d", id); | ||
| 198 | + // 4. 拼接最终结果 | ||
| 199 | + String result = ""; | ||
| 200 | + if (StringUtils.isBlank(pre)) { | ||
| 201 | + result = datePart + incrPart; | ||
| 202 | + } else { | ||
| 203 | + result = pre + datePart + incrPart; | ||
| 204 | + } | ||
| 205 | + return result; | ||
| 206 | + } | ||
| 172 | } | 207 | } |
| @@ -83,6 +83,7 @@ | @@ -83,6 +83,7 @@ | ||
| 83 | <insert id="batchAdd"> | 83 | <insert id="batchAdd"> |
| 84 | INSERT INTO shipments_order_info ( | 84 | INSERT INTO shipments_order_info ( |
| 85 | id, | 85 | id, |
| 86 | + code, | ||
| 86 | plan_id, | 87 | plan_id, |
| 87 | customer_id, | 88 | customer_id, |
| 88 | workshop_id, | 89 | workshop_id, |
| @@ -99,6 +100,7 @@ | @@ -99,6 +100,7 @@ | ||
| 99 | <foreach collection="list" item="item" separator=","> | 100 | <foreach collection="list" item="item" separator=","> |
| 100 | ( | 101 | ( |
| 101 | #{item.id}, | 102 | #{item.id}, |
| 103 | + #{item.code}, | ||
| 102 | #{item.planId}, | 104 | #{item.planId}, |
| 103 | #{item.customerId}, | 105 | #{item.customerId}, |
| 104 | #{item.workshopId}, | 106 | #{item.workshopId}, |