Explorar o código

根据装运打印单覆盖部分装运单信息

lingpeng.li hai 1 mes
pai
achega
445f794cc2

+ 58 - 2
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/storageBill/controller/StorageBillController.java

@@ -8,6 +8,9 @@ import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
@@ -72,6 +75,7 @@ import org.jeecg.modules.billet.storageBill.vo.*;
 import org.jeecg.modules.billet.storageCarLog.entity.StorageCarLog;
 import org.jeecg.modules.billet.storageCarLog.service.IStorageCarLogService;
 import org.jeecg.modules.carUnit.service.ICarUnitService;
+import org.jeecg.modules.carUnit.service.ISysDictService;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.redis.core.RedisTemplate;
@@ -281,15 +285,67 @@ public class StorageBillController extends JeecgController<StorageBill, IStorage
 			bill.setAssemblyNumber(mergedAssemblyNumbers);
 		}
 
+		//  查询 StorageBillPrint 中对应的最新记录
+		Map<String, StorageBillPrint> latestPrints = new HashMap<>();
+		if (!records.isEmpty()) {
+			LambdaQueryWrapper<StorageBillPrint> printWrapper = new LambdaQueryWrapper<>();
+			printWrapper.in(StorageBillPrint::getStorageBillId, billIds);
+			printWrapper.orderByDesc(StorageBillPrint::getCreateTime);
+
+			List<StorageBillPrint> allPrints = storageBillPrintService.list(printWrapper);
+
+			latestPrints = allPrints.stream()
+					.collect(Collectors.toMap(
+							StorageBillPrint::getStorageBillId,
+							p -> p,
+							(existing, replacement) -> existing // 保留 createTime 最大的那条
+					));
+		}
+
+		// 构建未匹配的 StorageBill 集合
+		List<StorageBill> needFillHeatNoBills = new ArrayList<>();
+
+		for (StorageBill bill : records) {
+			StorageBillPrint print = latestPrints.get(bill.getId());
+			if (print != null) {
+				bill.setOutTime(print.getArrivalTime());
+				bill.setDestination(print.getDestination());
+				bill.setAmountTotal(print.getAmountTotal());
+				bill.setSize(print.getSize());
+				bill.setBrandNum(print.getBrandNum());
+				try {
+					String heatNoJson = print.getHeatNo();
+					if (StringUtils.isNotBlank(heatNoJson)) {
+						ObjectMapper objectMapper = new ObjectMapper();
+						Map<String, Integer> heatNoMap = objectMapper.readValue(heatNoJson, new TypeReference<Map<String, Integer>>() {});
+
+						bill.setHeatNoCountMap(heatNoMap);
+					} else {
+						bill.setHeatNoCountMap(new HashMap<>()); // 空值处理
+					}
+				} catch (JsonProcessingException e) {
+					log.error("解析 heatNo JSON 失败,原始值: {}", print.getHeatNo(), e);
+					bill.setHeatNo(""); // 异常时设为空
+				}
+
+			} else {
+				needFillHeatNoBills.add(bill); // 未匹配的放入待补充集合
+			}
+		}
+
 
 		// 8. 填充车次编号与交班记录信息
 		storageBillService.fillCarNumbersAndShiftInfo(records);
 
-		storageBillService.fillHeatNoCountMapForBills(page.getRecords());
+		// 9. 仅对未匹配记录调用 fillHeatNoCountMapForBills
+		if (!needFillHeatNoBills.isEmpty()) {
+			storageBillService.fillHeatNoCountMapForBills(needFillHeatNoBills);
+		}
 
-		// 9. 返回分页结果
+		// 10. 设置分页返回内容
 		pagedBills.setRecords(records);
 		return Result.OK(pagedBills);
+
 	}
 
 

+ 11 - 8
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/storageBill/entity/StorageBillPrint.java

@@ -10,7 +10,6 @@ import lombok.experimental.Accessors;
 import org.jeecg.common.aspect.annotation.Dict;
 import org.jeecgframework.poi.excel.annotation.Excel;
 import org.springframework.format.annotation.DateTimeFormat;
-import org.w3c.dom.Text;
 
 import java.io.Serializable;
 import java.math.BigDecimal;
@@ -52,7 +51,7 @@ public class StorageBillPrint implements Serializable {
     @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
     @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     @ApiModelProperty(value = "创建日期")
-    private java.util.Date createTime;
+    private Date createTime;
     /**
      * 更新人
      */
@@ -66,7 +65,7 @@ public class StorageBillPrint implements Serializable {
     @ApiModelProperty(value = "更新日期")
     private Date updateTime;
     /**
-     *  确认日期
+     * 确认日期
      */
     @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
     @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
@@ -78,7 +77,9 @@ public class StorageBillPrint implements Serializable {
      */
     @ApiModelProperty(value = "所属部门")
     private String sysOrgCode;
-    /**铸机*/
+    /**
+     * 铸机
+     */
     @Excel(name = "铸机", width = 15)
     @ApiModelProperty(value = "铸机")
     @Dict(dicCode = "lg_zj")
@@ -90,12 +91,12 @@ public class StorageBillPrint implements Serializable {
     @ApiModelProperty(value = "目的地")
     private String destination;
     /**
-     * 到站时间
+     * 发车时间
      */
-    @Excel(name = "到站时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
+    @Excel(name = "发车时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
     @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
     @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
-    @ApiModelProperty(value = "到站时间")
+    @ApiModelProperty(value = "发车时间")
     private Date arrivalTime;
     /**
      * 车牌号
@@ -157,7 +158,9 @@ public class StorageBillPrint implements Serializable {
     @Excel(name = "班次信息", width = 15)
     @ApiModelProperty(value = "班次信息")
     private String classes;
-    /**类型*/
+    /**
+     * 类型
+     */
     @Excel(name = "类型", width = 15)
     @ApiModelProperty(value = "类型")
     @TableField(updateStrategy = FieldStrategy.IGNORED)