导入修改,PDA批次字段回显

This commit is contained in:
秦鸿展
2026-05-28 21:21:48 +08:00
parent 39503f9f3c
commit b7c17be566
3 changed files with 60 additions and 51 deletions
@@ -515,33 +515,10 @@ public class MaterialBaseInfoApplicationService {
materialBaseInfoDO.setMaterialCommon(null);
materialBaseInfoDO.setMaterialWarehouseControl(null);
materialBaseInfoDO.setMaterialBarCodeList(buildImportBarCodeList(row));
// 商品规则由 buildImportMaterialGoodsRule + insert() 统一写入,勿再单独 insert,避免 MATERIAL_GOODS_RULE 重复
insert(materialBaseInfoDO);
Long materialBaseInfoId = materialBaseInfoDO.getMaterialBaseInfoId();
//商品规则批次
if (StringUtils.isNotBlank(row.getBatchRuleNameImport())) {
MaterialGoodsRuleDO materialGoodsRuleDO = new MaterialGoodsRuleDO();
Object batchListByName = systemServiceFeign.getBatchListByName(row.getBatchRuleNameImport(), row.getOrganizationId());
Map<String, Object> batchListByNameMap = JSON.parseObject(JSONObject.toJSONString(batchListByName), new TypeReference<Map<String, Object>>() {});
Object codeObj = batchListByNameMap.get("code");
Object totalObj = batchListByNameMap.get("total");
List<Map<String, Object>> rowsBatch = extractTableDataRows(batchListByNameMap);
for (Map<String, Object> p : rowsBatch) {
if (p == null) {
continue;
}
String rowBatchName = normalizeBatchKeyword(p.get("batchName") == null ? "" : String.valueOf(p.get("batchName")));
if (StringUtils.equals(row.getBatchRuleNameImport(), rowBatchName)) {
Object idObj = p.get("batchId");
Long.valueOf(String.valueOf(idObj));
materialGoodsRuleDO.setBatchId(Long.valueOf(String.valueOf(idObj)));
materialGoodsRuleDO.setMaterialBaseInfoId(materialBaseInfoId);
materialGoodsRuleDomainService.insert(materialGoodsRuleDO);
}
}
}
//公共信息
MaterialCommonDO materialCommonDO = materialBaseInfoDO.getMaterialCommon();
if (materialCommonDO != null) {
@@ -213,33 +213,7 @@ public class StockReceiptOrderApplicationService {
.filter(Objects::nonNull)
.collect(Collectors.toSet());
// 2. 批量查询批次属性(使用Map缓存,避免重复查询相同的materialBaseInfoId
Map<Long, List<BatchDetailFeignPO>> batchDetailMap = new HashMap<>();
for (Long materialBaseInfoId : materialBaseInfoIdSet) {
try {
MaterialGoodsRulePO localGoodsRule = materialGoodsRuleService.getInfoByMaterialBaseInfoIds(materialBaseInfoId);
if (localGoodsRule == null || localGoodsRule.getBatchId() == null) {
continue;
}
AjaxResult ajaxResult = systemServiceFeign.getBatchDetailListByMaterialBaseInfoId(materialBaseInfoId);
if (ajaxResult != null && "200".equals(String.valueOf(ajaxResult.get("code")))) {
List<BatchDetailFeignPO> batchDetailFeignPOList = JSON.parseArray(
JSONObject.toJSONString(ajaxResult.get("data")), BatchDetailFeignPO.class);
// 与物料商品规则中的 batchId 对齐,避免多批次模板的 isDisplay=1 行全部合并成几十条
batchDetailFeignPOList = ReceiptBatchDetailFilter.filterByMaterialGoodsRule(
materialBaseInfoId, batchDetailFeignPOList, materialGoodsRuleService);
if (!CollectionUtils.isEmpty(batchDetailFeignPOList)) {
// 过滤isDisplay=1的属性
List<BatchDetailFeignPO> filteredList = batchDetailFeignPOList.stream()
.filter(batchDetail -> batchDetail.getIsDisplay() != null && batchDetail.getIsDisplay() == 1)
.collect(Collectors.toList());
batchDetailMap.put(materialBaseInfoId, filteredList);
}
}
} catch (Exception e) {
log.warn("获取物料批次属性失败,物料基础信息ID:{},错误:{}", materialBaseInfoId, e.getMessage());
}
}
Map<Long, List<BatchDetailFeignPO>> batchDetailMap = buildBatchDetailMapForReceiptInfo(materialBaseInfoIdSet);
// 3. 为每个物料明细设置更多属性(从缓存中获取),递归处理所有层级
setMaterialMoreDetailListRecursively(receiptMaterialDetailPOList, batchDetailMap);
@@ -1044,6 +1018,10 @@ public class StockReceiptOrderApplicationService {
labelToFieldNameMap.put("总体积", "totalVolume");
labelToFieldNameMap.put("总面积", "totalArea");
labelToFieldNameMap.put("总价", "totalPrice");
labelToFieldNameMap.put("生产日期", "productionDate");
labelToFieldNameMap.put("过期日期", "expiryDate");
labelToFieldNameMap.put("存货日期", "inventoryDate");
labelToFieldNameMap.put("饮用日期", "drinkDate");
// 精确匹配
String fieldName = labelToFieldNameMap.get(batchLabel.trim());
@@ -1216,6 +1194,9 @@ public class StockReceiptOrderApplicationService {
}
Set<Long> materialBaseInfoIdSet = new HashSet<>();
collectMaterialBaseInfoIdsRecursively(materialDetailList, materialBaseInfoIdSet);
// 与 PC getInfo 一致:将明细行 expiryDate/productionDate 等回填到 materialMoreDetailList,避免批次「过期日期」为 null
Map<Long, List<BatchDetailFeignPO>> batchDetailMap = buildBatchDetailMapForReceiptInfo(materialBaseInfoIdSet);
setMaterialMoreDetailListRecursively(materialDetailList, batchDetailMap);
Map<Long, MaterialBaseInfoPO> materialBaseInfoMap = new HashMap<>();
for (Long materialBaseInfoId : materialBaseInfoIdSet) {
try {
@@ -1483,6 +1464,40 @@ public class StockReceiptOrderApplicationService {
return detailStatus != null && (detailStatus == 3 || detailStatus == 4 || detailStatus == 5);
}
/**
* 批量加载物料批次属性(isDisplay=1),供 PC/PDA 详情回填 materialMoreDetailList 使用
*/
private Map<Long, List<BatchDetailFeignPO>> buildBatchDetailMapForReceiptInfo(Set<Long> materialBaseInfoIdSet) {
Map<Long, List<BatchDetailFeignPO>> batchDetailMap = new HashMap<>();
if (CollectionUtils.isEmpty(materialBaseInfoIdSet)) {
return batchDetailMap;
}
for (Long materialBaseInfoId : materialBaseInfoIdSet) {
try {
MaterialGoodsRulePO localGoodsRule = materialGoodsRuleService.getInfoByMaterialBaseInfoIds(materialBaseInfoId);
if (localGoodsRule == null || localGoodsRule.getBatchId() == null) {
continue;
}
AjaxResult ajaxResult = systemServiceFeign.getBatchDetailListByMaterialBaseInfoId(materialBaseInfoId);
if (ajaxResult != null && "200".equals(String.valueOf(ajaxResult.get("code")))) {
List<BatchDetailFeignPO> batchDetailFeignPOList = JSON.parseArray(
JSONObject.toJSONString(ajaxResult.get("data")), BatchDetailFeignPO.class);
batchDetailFeignPOList = ReceiptBatchDetailFilter.filterByMaterialGoodsRule(
materialBaseInfoId, batchDetailFeignPOList, materialGoodsRuleService);
if (!CollectionUtils.isEmpty(batchDetailFeignPOList)) {
List<BatchDetailFeignPO> filteredList = batchDetailFeignPOList.stream()
.filter(batchDetail -> batchDetail.getIsDisplay() != null && batchDetail.getIsDisplay() == 1)
.collect(Collectors.toList());
batchDetailMap.put(materialBaseInfoId, filteredList);
}
}
} catch (Exception e) {
log.warn("获取物料批次属性失败,物料基础信息ID:{},错误:{}", materialBaseInfoId, e.getMessage());
}
}
return batchDetailMap;
}
/**
* 递归收集明细树中所有物料基础信息ID
*/
@@ -893,6 +893,18 @@ public class ReceiptMaterialDetailImpl extends ServiceImpl<ReceiptMaterialDetail
case "面积":
val = receiptMaterialDetailPO.getTotalArea() != null ? receiptMaterialDetailPO.getTotalArea().toString() : (inMaterialDetail.getTotalArea() != null ? inMaterialDetail.getTotalArea().toString() : null);
break;
case "过期日期":
val = formatDateForBatchAttribute(receiptMaterialDetailPO.getExpiryDate(), inMaterialDetail.getExpiryDate());
break;
case "生产日期":
val = formatDateForBatchAttribute(receiptMaterialDetailPO.getProductionDate(), inMaterialDetail.getProductionDate());
break;
case "存货日期":
val = formatDateForBatchAttribute(receiptMaterialDetailPO.getInventoryDate(), inMaterialDetail.getInventoryDate());
break;
case "饮用日期":
val = formatDateForBatchAttribute(receiptMaterialDetailPO.getDrinkDate(), inMaterialDetail.getDrinkDate());
break;
default:
break;
}
@@ -903,6 +915,11 @@ public class ReceiptMaterialDetailImpl extends ServiceImpl<ReceiptMaterialDetail
}
}
private static String formatDateForBatchAttribute(Date receiptVal, Date inVal) {
Date d = receiptVal != null ? receiptVal : inVal;
return d != null ? DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD, d) : null;
}
/**
* @description 无单收货 新增收货单 包含序列号和更多属性