Commit 95cfa85f02122c2a4b044b0a7bb5a7cec945d413

Authored by 房远帅
1 parent 4b84cc49

发货单:打印添加 物料编码

... ... @@ -9,16 +9,17 @@ import com.lframework.starter.web.inner.service.system.SysUserService;
9 9 import com.lframework.xingyun.sc.bo.shipments.order.GetShipmentsOrderInfoBo;
10 10 import com.lframework.xingyun.sc.bo.shipments.order.QueryShipmentsOrderInfoBo;
11 11 import com.lframework.xingyun.sc.bo.shipments.plan.ShipmentsPlanDetailBo;
12   -import com.lframework.xingyun.sc.entity.PurchaseOrderInfo;
13   -import com.lframework.xingyun.sc.entity.ShipmentsPlanDetail;
  12 +import com.lframework.xingyun.sc.entity.*;
  13 +import com.lframework.xingyun.sc.service.contract.ContractDistributorLineService;
  14 +import com.lframework.xingyun.sc.service.contract.ContractStdProcessingLineService;
14 15 import com.lframework.xingyun.sc.service.order.PurchaseOrderInfoService;
  16 +import com.lframework.xingyun.sc.service.order.PurchaseOrderLineService;
15 17 import com.lframework.xingyun.sc.service.shipments.ShipmentsPlanDetailService;
16 18 import com.lframework.xingyun.sc.utils.ExcelUtil;
17 19 import com.lframework.xingyun.sc.utils.LatexFormulaExcelExporterUtil;
18 20 import com.lframework.xingyun.sc.utils.ResponseUtil;
19 21 import com.lframework.xingyun.sc.vo.shipments.order.*;
20 22 import com.lframework.xingyun.sc.service.shipments.ShipmentsOrderInfoService;
21   -import com.lframework.xingyun.sc.entity.ShipmentsOrderInfo;
22 23 import com.lframework.starter.web.core.utils.PageResultUtil;
23 24 import com.lframework.starter.web.core.components.resp.PageResult;
24 25 import com.lframework.starter.web.core.components.resp.InvokeResult;
... ... @@ -87,6 +88,12 @@ public class ShipmentsOrderInfoController extends DefaultBaseController {
87 88 private SysDeptService sysDeptService;
88 89 @Resource
89 90 private PurchaseOrderInfoService purchaseOrderInfoService;
  91 + @Resource
  92 + private PurchaseOrderLineService purchaseOrderLineService;
  93 + @Resource
  94 + private ContractDistributorLineService contractDistributorLineService;
  95 + @Resource
  96 + private ContractStdProcessingLineService contractStdProcessingLineService;
90 97
91 98
92 99 /**
... ... @@ -394,11 +401,12 @@ public class ShipmentsOrderInfoController extends DefaultBaseController {
394 401 BigDecimal totalActualQuantity = BigDecimal.ZERO;
395 402 BigDecimal totalNum = BigDecimal.ZERO;
396 403 BigDecimal totalPrice = BigDecimal.ZERO;
  404 + Set<String> set = new HashSet<>();
397 405 for (ShipmentsPlanDetail detail : detailList) {
398 406 BigDecimal quantity = detail.getQuantity() == null ? BigDecimal.ZERO : detail.getQuantity();
399 407 BigDecimal actualQuantity = detail.getActualShipmentQuantity() == null ? BigDecimal.ZERO : new BigDecimal(detail.getActualShipmentQuantity());
400 408 BigDecimal num = detail.getNum() == null ? BigDecimal.ZERO : new BigDecimal(detail.getNum());
401   -
  409 + set.add(detail.getOrderSpecId());
402 410 totalQuantity = totalQuantity.add(quantity);
403 411 totalActualQuantity = totalActualQuantity.add(actualQuantity);
404 412 totalNum = totalNum.add(num);
... ... @@ -408,6 +416,68 @@ public class ShipmentsOrderInfoController extends DefaultBaseController {
408 416 totalPrice = totalPrice.add(result);
409 417 }
410 418 }
  419 +
  420 + // 用于存储最终结果的 Map: Key=orderSpecId, Value=materialCode
  421 + Map<String, String> resultMaterialMap = new HashMap<>();
  422 + if (CollectionUtils.isNotEmpty(set)) {
  423 + List<String> orderSpecIds = new ArrayList<>(set);
  424 + List<PurchaseOrderLine> orderLineList = purchaseOrderLineService.listByIds(orderSpecIds);
  425 + if (CollectionUtils.isNotEmpty(orderLineList)) {
  426 + // 3. 提取关联的 contractLineId 列表
  427 + List<String> contractLineIds = orderLineList.stream()
  428 + .map(PurchaseOrderLine::getContractDistributorLineId)
  429 + .filter(Objects::nonNull) // 防止 null 值干扰查询
  430 + .distinct() // 去重,避免重复查询
  431 + .collect(Collectors.toList());
  432 +
  433 + if (CollectionUtils.isNotEmpty(contractLineIds)) {
  434 + // 4. 并行查询两张表 (或者串行,视数据量而定)
  435 + List<ContractDistributorLine> distLines = contractDistributorLineService.listByIds(contractLineIds);
  436 + List<ContractStdProcessingLine> stdLines = contractStdProcessingLineService.listByIds(contractLineIds);
  437 +
  438 + // 5. 将查询结果转为 Map 以便快速匹配 (Key = contractLineId, Value = materialCode)
  439 + Map<String, String> distMaterialMap = distLines.stream()
  440 + .filter(line -> line.getId() != null && line.getMaterialCode() != null)
  441 + .collect(Collectors.toMap(
  442 + ContractDistributorLine::getId,
  443 + ContractDistributorLine::getMaterialCode,
  444 + (v1, v2) -> v1 // 如果有重复 ID,取第一个
  445 + ));
  446 +
  447 + Map<String, String> stdMaterialMap = stdLines.stream()
  448 + .filter(line -> line.getId() != null && line.getMaterialCode() != null)
  449 + .collect(Collectors.toMap(
  450 + ContractStdProcessingLine::getId, // 请确认加工行实体中对应的外键方法名
  451 + ContractStdProcessingLine::getMaterialCode,
  452 + (v1, v2) -> v1
  453 + ));
  454 +
  455 + // 6. 遍历最初的 orderLineList 进行组装
  456 + for (PurchaseOrderLine orderLine : orderLineList) {
  457 + String orderSpecId = orderLine.getId(); // 或者 getOrderSpecId(),根据你的实体定义
  458 + String contractLineId = orderLine.getContractDistributorLineId();
  459 +
  460 + if (contractLineId == null) {
  461 + continue;
  462 + }
  463 +
  464 + String materialCode = null;
  465 + // 【策略】优先取分销行材料码
  466 + if (distMaterialMap.containsKey(contractLineId)) {
  467 + materialCode = distMaterialMap.get(contractLineId);
  468 + }
  469 + // 如果分销行没有,则取加工行材料码
  470 + else if (stdMaterialMap.containsKey(contractLineId)) {
  471 + materialCode = stdMaterialMap.get(contractLineId);
  472 + }
  473 + // 只有找到材料码才放入结果集
  474 + if (materialCode != null) {
  475 + resultMaterialMap.put(orderSpecId, materialCode);
  476 + }
  477 + }
  478 + }
  479 + }
  480 + }
411 481 for (ShipmentsPlanDetail detail : detailList) {
412 482 ExcelUtil.setCellValue(sheet, startRow, 0, detail.getOrderNo());
413 483 ExcelUtil.setCellValue(sheet, startRow, 1, detail.getBrand());
... ... @@ -438,18 +508,20 @@ public class ShipmentsOrderInfoController extends DefaultBaseController {
438 508 if (StringUtils.isNotBlank(latex)) {
439 509 LatexFormulaExcelExporterUtil.insertLatexImageToCell(workbook, sheet, latex, startRow, 2, 1, 7);
440 510 }
441   - ExcelUtil.setCellValue(sheet, startRow, 9, detail.getQuantity());
  511 + String materialCode = resultMaterialMap.get(detail.getOrderSpecId());
  512 + ExcelUtil.setCellValue(sheet, startRow, 9, materialCode);
  513 + ExcelUtil.setCellValue(sheet, startRow, 10, detail.getQuantity());
442 514 if ("TYPE_2".equals(type)) {
443   - ExcelUtil.setCellValue(sheet, startRow, 10, detail.getActualShipmentQuantity());
444   - ExcelUtil.setCellValue(sheet, startRow, 11, detail.getNum());
445   - ExcelUtil.setCellValue(sheet, startRow, 12, detail.getSalesPrice());
446   - ExcelUtil.setCellValue(sheet, startRow, 13, detail.getOrderType());
447   - ExcelUtil.setCellValue(sheet, startRow, 14, detail.getYieldBatchNo());
448   - ExcelUtil.setCellValue(sheet, startRow, 15, " -- ");
449   - } else {
450   - ExcelUtil.setCellValue(sheet, startRow, 13, detail.getPackagingFee());
451   - ExcelUtil.setCellValue(sheet, startRow, 15, detail.getOrderType());
  515 + ExcelUtil.setCellValue(sheet, startRow, 11, detail.getActualShipmentQuantity());
  516 + ExcelUtil.setCellValue(sheet, startRow, 12, detail.getNum());
  517 + ExcelUtil.setCellValue(sheet, startRow, 13, detail.getSalesPrice());
  518 + ExcelUtil.setCellValue(sheet, startRow, 14, detail.getOrderType());
  519 + ExcelUtil.setCellValue(sheet, startRow, 15, detail.getYieldBatchNo());
452 520 ExcelUtil.setCellValue(sheet, startRow, 16, " -- ");
  521 + } else {
  522 + ExcelUtil.setCellValue(sheet, startRow, 14, detail.getPackagingFee());
  523 + ExcelUtil.setCellValue(sheet, startRow, 16, detail.getOrderType());
  524 + ExcelUtil.setCellValue(sheet, startRow, 17, " -- ");
453 525 }
454 526 startRow++;
455 527 }
... ...