瀏覽代碼

完善高线工作台的统计以及储运中心打印票据返回棒一的数据

lingpeng.li 22 小時之前
父節點
當前提交
d1199f244f

+ 41 - 0
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/billetOriginalProductRecord/controller/BilletOriginalProductRecordController.java

@@ -2319,6 +2319,11 @@ public class BilletOriginalProductRecordController extends JeecgController<Bille
 					log.error("解析rollClubOneDetails、rollHeightDetails失败: {}", rollClubOneDetails, e);
 				}
 			}
+
+			// 步进冷床处理逻辑
+			if ("6".equals(record.getCcmNo()) && StringUtils.isNotBlank(record.getStackLength())) {
+				handleSteppingColdBedData(statisticsMap, record.getStackLength());
+			}
 		}
 
 		// 计算总数量和总重量
@@ -2341,6 +2346,42 @@ public class BilletOriginalProductRecordController extends JeecgController<Bille
 		return billetDetailsInfoList;
 	}
 
+	private void handleSteppingColdBedData(Map<String, BilletStatisticsDetail> statisticsMap, String stackLengthJson) {
+		try {
+			JSONArray jsonArray = JSON.parseArray(stackLengthJson);
+			for (int i = 0; i < jsonArray.size(); i++) {
+				JSONObject item = jsonArray.getJSONObject(i);
+				Integer stackingLength = item.getInteger("stackingLength");
+				Integer stackingCount = item.getInteger("stackingCount");
+				BigDecimal stackingWeight = item.getBigDecimal("stackingWeight");
+				String bhtcId = item.getString("stackingBhtcId");
+				if (stackingCount != null && stackingCount > 0 && "9".equals(bhtcId)) {
+					String sizeKey = String.valueOf(stackingLength);
+					double sizeValue = stackingLength != null ? stackingLength.doubleValue() : 0d;
+					updateStatistics(statisticsMap, sizeKey, stackingCount, sizeValue, stackingWeight.doubleValue());
+				}
+			}
+		} catch (Exception e) {
+			log.error("步进冷床JSON解析失败,数据:{}", stackLengthJson, e);
+		}
+	}
+
+
+	private void updateStatistics(Map<String, BilletStatisticsDetail> map, String size, int count, double sizeValue, double weightOverride) {
+		BilletStatisticsDetail detail = map.getOrDefault(size, new BilletStatisticsDetail());
+		detail.setSize(size);
+		detail.setAmountTotal(detail.getAmountTotal() + count);
+		if (weightOverride > 0) {
+			detail.setBlankOutput(detail.getBlankOutput() + weightOverride);
+		} else {
+			// 原逻辑
+			detail.setBlankOutput(detail.getBlankOutput() + sizeValue * count / 1000);
+		}
+		map.put(size, detail);
+	}
+
+
+
 	/**
 	 * 装运单统计明细查询
 	 * @param ccmNo

+ 117 - 0
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/storageBill/controller/StorageBillPrintController.java

@@ -8,6 +8,8 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
 import lombok.extern.slf4j.Slf4j;
@@ -25,6 +27,8 @@ import org.jeecg.modules.actualControl.billetActual.billetActual.entity.BilletRu
 import org.jeecg.modules.actualControl.billetActual.billetActual.mapper.BilletRulerConfigMapper;
 import org.jeecg.modules.billet.billetHotsendChangeShift.entity.BilletHotsendChangeShift;
 import org.jeecg.modules.billet.billetHotsendChangeShift.service.IBilletHotsendChangeShiftService;
+import org.jeecg.modules.billet.billetOriginalProductRecord.entity.BilletOriginalProductRecord;
+import org.jeecg.modules.billet.billetOriginalProductRecord.service.IBilletOriginalProductRecordService;
 import org.jeecg.modules.billet.rollClubThree.entity.RollClubThreeDetails;
 import org.jeecg.modules.billet.rollClubThree.service.IRollClubThreeDetailsService;
 import org.jeecg.modules.billet.rollClubTwo.entity.RollClubTwoDetails;
@@ -40,6 +44,7 @@ import org.jeecg.modules.billet.storageBill.entity.StorageBillPrint;
 import org.jeecg.modules.billet.storageBill.entity.StorageBilletControl;
 import org.jeecg.modules.billet.storageBill.service.IStorageBillPrintService;
 import org.jeecg.modules.billet.storageBill.service.IStorageBillService;
+import org.jeecg.modules.billet.storageBill.vo.RollClubOneExportVO;
 import org.jeecg.modules.billet.storageBill.vo.StorageCenterExportRow;
 import org.jeecg.modules.carUnit.entity.SysDict;
 import org.jeecg.modules.carUnit.entity.SysDictItem;
@@ -96,6 +101,9 @@ public class StorageBillPrintController extends JeecgController<StorageBillPrint
     @Autowired
     private IBilletHotsendChangeShiftService billetHotsendChangeShiftService;
 
+    @Autowired
+    private IBilletOriginalProductRecordService billetOriginalProductRecordService;
+
     @Autowired
     BilletRulerConfigMapper billetRulerConfigMapper;
     @Autowired
@@ -309,6 +317,14 @@ public class StorageBillPrintController extends JeecgController<StorageBillPrint
      */
     @RequestMapping(value = "/exportXls")
     public void exportXls(HttpServletResponse response, StorageBillPrint storageBillPrint) {
+
+        // 获取米重数据
+        String meterWeightKey = String.format("ccmno:meter:weight:%s", storageBillPrint.getCcmNo());
+        String mWeightStr = oConvertUtils.getString(redisTemplate.opsForValue().get(meterWeightKey));
+        BigDecimal meterWeightFactor = StringUtils.isNotEmpty(mWeightStr)
+                ? new BigDecimal(mWeightStr)
+                : new BigDecimal("0.2265"); // 如果没有米重数据,使用 0.2265 作为系数
+
         try {
             QueryWrapper<StorageBillPrint> queryWrapper = new QueryWrapper<>();
 
@@ -492,6 +508,107 @@ public class StorageBillPrintController extends JeecgController<StorageBillPrint
                 exportRows.add(exportRow);
             });
 
+            QueryWrapper<BilletOriginalProductRecord> recordQueryWrapper = new QueryWrapper<>();
+
+            // 手动设置必要条件,避免 QueryGenerator 自动生成不必要的条件
+            if (oConvertUtils.isNotEmpty(storageBillPrint.getCcmNo())) {
+                recordQueryWrapper.eq("ccm_no", storageBillPrint.getCcmNo());
+            }
+
+            // 修改时间范围查询条件为 >= startTime 且 <= endTime
+            recordQueryWrapper.ge("create_time", startTime)  // 大于等于开始时间
+                    .le("create_time", endTime);   // 小于等于结束时间
+
+            // Step.2 获取导出数据
+            // 打印完整的查询条件
+            List<BilletOriginalProductRecord> list = billetOriginalProductRecordService.list(recordQueryWrapper);
+
+            ObjectMapper objectMapper = new ObjectMapper();
+
+            List<RollClubOneExportVO> oneList = new ArrayList<>();
+            for (BilletOriginalProductRecord record : list) {
+
+                Map<String, Integer> lengthCountMap = new HashMap<>();
+
+                // 3. 解析 JSON 明细
+                String detailJson = record.getRollClubOneDetails();
+                if (StringUtils.isNotBlank(detailJson)) {
+                    try {
+                        JsonNode rootNode = objectMapper.readTree(detailJson);
+
+                        String heatNo = record.getHeatNo();
+                        String ccmNo = record.getCcmNo();
+                        Date createTime = record.getCreateTime();
+
+                        // 品号从 grade 映射
+                        String brandNum = Optional.ofNullable(record.getGrade())
+                                .map(bn -> sysDictService.queryDictTextByKey("billet_spec", bn))
+                                .orElseGet(() -> sysDictService.queryDictTextByKey("billet_spec", "5"));
+
+                        // 各定尺计数
+                        JsonNode lengthGroupNode = rootNode.get("lengthGroupCount");
+                        if (lengthGroupNode != null && lengthGroupNode.isObject()) {
+                            lengthGroupNode.fields().forEachRemaining(e ->
+                                    lengthCountMap.merge(e.getKey(), e.getValue().asInt(), Integer::sum)
+                            );
+                        }
+
+                        // 【新增】跳过没有定尺数据的记录
+                        if (lengthCountMap.isEmpty()) {
+                            log.info("heatNo={} 的 lengthGroupCount 为空,跳过处理", heatNo);
+                            continue;
+                        }
+
+                        // 4. 根据每种定尺构建 sizeDetail & rollSendDetail
+                        for (Map.Entry<String, Integer> entry : lengthCountMap.entrySet()) {
+                            String length = entry.getKey();
+                            int count = entry.getValue();
+
+                            RollClubOneExportVO rollClubOneExportVO = new RollClubOneExportVO();
+
+                            rollClubOneExportVO.setHeatNo(heatNo);
+                            rollClubOneExportVO.setSize(length);
+                            rollClubOneExportVO.setCount(count);
+                            rollClubOneExportVO.setCcmNo(ccmNo);
+                            rollClubOneExportVO.setBrandNum(brandNum);
+                            rollClubOneExportVO.setCreateTime(createTime);
+
+                            oneList.add(rollClubOneExportVO);
+                        }
+
+                    } catch (Exception e) {
+                        log.info("JSON 解析失败,数据:{}", detailJson, e);
+                    }
+                }
+            }
+
+            oneList.forEach(x -> {
+                StorageCenterExportRow exportRow = new StorageCenterExportRow();
+                exportRow.setAmount(x.getCount());
+                exportRow.setCcmNo(Integer.valueOf(x.getCcmNo()));
+                exportRow.setEndPoint("棒一");
+                exportRow.setFactoryDate(DateUtils.date2Str(x.getCreateTime(), DateUtils.datetimeFormat.get()));
+                exportRow.setHeatNo(x.getHeatNo());
+                exportRow.setLicensePlate("辊道");
+                BigDecimal result = safeToBigDecimal(x.getSize()).divide(BigDecimal.valueOf(1000));
+                if (result != null) {
+                    exportRow.setSize("170*170*" + result.toPlainString());
+                }
+                BigDecimal singleWeight = new BigDecimal(x.getSize())
+                        .divide(new BigDecimal("1000"), 3, RoundingMode.HALF_UP)
+                        .multiply(meterWeightFactor)
+                        .setScale(3, RoundingMode.HALF_UP);
+
+                BigDecimal weight = singleWeight.multiply(BigDecimal.valueOf(x.getCount()));
+                exportRow.setWeightPerPiece(singleWeight);
+                exportRow.setTotalWeight(weight);
+                exportRow.setBrand(x.getBrandNum());
+
+                exportRows.add(exportRow);
+            });
+
+            exportRows.sort(Comparator.comparing(StorageCenterExportRow::getFactoryDate));
+
             // 设置响应
             response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
             response.setCharacterEncoding("utf-8");

+ 27 - 0
zgztBus/jeecg-module-sbm/src/main/java/org/jeecg/modules/billet/storageBill/vo/RollClubOneExportVO.java

@@ -0,0 +1,27 @@
+package org.jeecg.modules.billet.storageBill.vo;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.util.Date;
+
+@Data
+public class RollClubOneExportVO {
+
+    private String ccmNo;
+
+    private String size;
+
+    private String heatNo;
+
+    private Integer count;
+
+    private String brandNum;
+
+    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value = "创建时间")
+    private Date createTime;
+}