Commit 672b00fa9bb7daef15dd9b655f6f83cdf58a0ea7

Authored by 房远帅
1 parent a55f4c40

发货模块:生成要车计划和要车单问题处理

... ... @@ -960,6 +960,7 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr
960 960 .collect(Collectors.toList());
961 961 List<PurchaseOrderInfo> batchOrderInfoList = purchaseOrderInfoService.queryByIds(batchOrderIds);
962 962 List<String> detailIds = new ArrayList<>();
  963 + List<ShipmentsPlanDetail> shipmentsPlanDetails = new ArrayList<>();
963 964 String id = IdUtil.getId();
964 965 String customerId = details.get(0).getCustomerId();
965 966 StringBuilder deliveryTypeBuilder = new StringBuilder();
... ... @@ -974,6 +975,7 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr
974 975 }
975 976 detail.setShipmentOrderId(id);
976 977 detailIds.add(detail.getId());
  978 + shipmentsPlanDetails.add(detail);
977 979
978 980 PurchaseOrderInfo orderInfo = orderInfoMap.get(detail.getOrderId());
979 981 if (orderInfo == null) {
... ... @@ -1062,6 +1064,7 @@ public class ShipmentsOrderInfoServiceImpl extends BaseMpServiceImpl<ShipmentsOr
1062 1064 // 更新明细数据
1063 1065 if (allApproved) {
1064 1066 shipmentsPlanDetailService.setShipmentsOrderId(detailIds, id);
  1067 + shipmentsOrderInfo.setDetailList(shipmentsPlanDetails);
1065 1068 //生成要车单和要车计划
1066 1069 carRequestPlanService.generate(batchOrderInfoList, shipmentsOrderInfo);
1067 1070 }
... ...
... ... @@ -18,6 +18,7 @@ import com.lframework.starter.web.core.annotations.oplog.OpLog;
18 18 import com.lframework.starter.web.core.utils.PageHelperUtil;
19 19 import com.lframework.starter.common.utils.Assert;
20 20 import com.lframework.starter.web.inner.components.oplog.OtherOpLogType;
  21 +import lombok.extern.slf4j.Slf4j;
21 22 import com.lframework.xingyun.sc.entity.*;
22 23 import com.lframework.xingyun.sc.mappers.CarRequestPlanMapper;
23 24 import com.lframework.xingyun.sc.service.shipments.ShipmentsPlanService;
... ... @@ -40,6 +41,7 @@ import java.util.function.Function;
40 41 import java.util.stream.Collectors;
41 42
42 43 @Service
  44 +@Slf4j
43 45 public class CarRequestPlanServiceImpl extends BaseMpServiceImpl<CarRequestPlanMapper, CarRequestPlan> implements CarRequestPlanService {
44 46 @Resource
45 47 private RequestCarTicketService requestCarTicketService;
... ... @@ -171,8 +173,10 @@ public class CarRequestPlanServiceImpl extends BaseMpServiceImpl<CarRequestPlanM
171 173 @Transactional(rollbackFor = Exception.class)
172 174 public void generate(List<PurchaseOrderInfo> orderInfoList, ShipmentsOrderInfo shipmentsOrderInfo) {
173 175 if (CollectionUtils.isEmpty(orderInfoList) || shipmentsOrderInfo == null) {
  176 + log.warn("[CarRequestPlan.generate] 跳过生成:orderInfoList={}, shipmentsOrderInfo={}", CollectionUtils.isEmpty(orderInfoList), shipmentsOrderInfo);
174 177 return;
175 178 }
  179 + log.info("[CarRequestPlan.generate] 开始生成,发货单ID={},订单数={}", shipmentsOrderInfo.getId(), orderInfoList.size());
176 180 List<String> orderIds = orderInfoList.stream().map(PurchaseOrderInfo::getId).collect(Collectors.toList());
177 181 // 根据订货单获取草稿要车单
178 182 List<DraftRequestCarTicket> draftTickets = draftRequestCarTicketService.listByOrderId(orderIds);
... ... @@ -183,6 +187,10 @@ public class CarRequestPlanServiceImpl extends BaseMpServiceImpl<CarRequestPlanM
183 187 if (StringUtil.isNotBlank(shipmentsOrderInfo.getPlanId())) {
184 188 shipmentsPlan = shipmentsPlanService.findById(shipmentsOrderInfo.getPlanId());
185 189 }
  190 + List<ShipmentsPlanDetail> detailList = shipmentsOrderInfo.getDetailList();
  191 + if (CollectionUtils.isEmpty(detailList)) {
  192 + log.warn("[CarRequestPlan.generate] 发货单 {} 的detailList为空,无法计算吨位/装货时间,跳过生成要车单", shipmentsOrderInfo.getId());
  193 + }
186 194 for (PurchaseOrderInfo orderInfo : orderInfoList) {
187 195 // 生成要车计划
188 196 LocalDate requestCarDate = shipmentsOrderInfo.getShipmentsDate();
... ... @@ -193,9 +201,11 @@ public class CarRequestPlanServiceImpl extends BaseMpServiceImpl<CarRequestPlanM
193 201 planCreateVo.setRequestCarDate(requestCarDate);
194 202 planCreateVo.setWorkshopId(orderInfo.getWorkshopId());
195 203 String requestCarPlanId = create(planCreateVo);
  204 + log.info("[CarRequestPlan.generate] 已生成/复用要车计划ID={},订单ID={}", requestCarPlanId, orderInfo.getId());
196 205 // 生成要车单
197 206 DraftRequestCarTicket draftTicket = draftTicketMap.get(orderInfo.getId());
198 207 if (draftTicket == null) {
  208 + log.warn("[CarRequestPlan.generate] 订单ID={} 缺少草稿要车单,抛异常回滚", orderInfo.getId());
199 209 throw new DefaultClientException("请先补充草稿要车单数据!");
200 210 }
201 211 CreateRequestCarTicketVo ticketVo = new CreateRequestCarTicketVo();
... ... @@ -219,31 +229,31 @@ public class CarRequestPlanServiceImpl extends BaseMpServiceImpl<CarRequestPlanM
219 229 ticketVo.setReturnPlanArrangement(draftTicket.getReturnPlanArrangement());
220 230 ticketVo.setOther(draftTicket.getOther());
221 231 ticketVo.setSpecialLoadingRequirement(draftTicket.getSpecialLoadingRequirement());
222   - List<ShipmentsPlanDetail> detailList = shipmentsOrderInfo.getDetailList();
223   - if (CollectionUtil.isEmpty(detailList)) {
224   - continue;
225   - }
226 232 // 计划吨位
227 233 BigDecimal totalQuantity = BigDecimal.ZERO;
228   - for (ShipmentsPlanDetail detail : detailList) {
229   - BigDecimal quantity = detail.getQuantity();
230   - if (quantity == null || !orderInfo.getId().equals(detail.getOrderId())) {
231   - continue;
  234 + LocalTime minTime = null;
  235 + if (CollectionUtils.isNotEmpty(detailList)) {
  236 + for (ShipmentsPlanDetail detail : detailList) {
  237 + BigDecimal quantity = detail.getQuantity();
  238 + if (orderInfo.getId().equals(detail.getOrderId()) && quantity != null) {
  239 + totalQuantity = totalQuantity.add(quantity);
  240 + }
  241 + if (detail.getShipmentsTime() != null) {
  242 + if (minTime == null || detail.getShipmentsTime().isBefore(minTime)) {
  243 + minTime = detail.getShipmentsTime();
  244 + }
  245 + }
232 246 }
233   - totalQuantity = totalQuantity.add(quantity);
234 247 }
235 248 ticketVo.setQuantity(totalQuantity);
236 249 // 装货时间处理
237   - LocalTime minTime = shipmentsOrderInfo.getDetailList().stream()
238   - .map(ShipmentsPlanDetail::getShipmentsTime)
239   - .min(LocalTime::compareTo)
240   - .orElse(null);
241   - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm");
242 250 if (minTime != null) {
243   - String loadingTime = minTime.format(formatter);
  251 + String loadingTime = minTime.format(DateTimeFormatter.ofPattern("HH:mm"));
244 252 ticketVo.setLoadingTime(loadingTime);
245 253 }
246   - requestCarTicketService.create(ticketVo);
  254 + log.info("=====开始创建要车单====" + ticketVo);
  255 + String ticketId = requestCarTicketService.create(ticketVo);
  256 + log.info("[CarRequestPlan.generate] 已生成要车单ID={},订单ID={},吨位={}", ticketId, orderInfo.getId(), totalQuantity);
247 257 }
248 258 }
249 259
... ...