ソースを参照

送样卡数据获取从原始记录棒一以及热装明细中获取

lingpeng.li 2 週間 前
コミット
4076f726c1

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

@@ -582,34 +582,34 @@ public class BilletOriginalProductRecordController extends JeecgController<Bille
 			 return Result.error("参数不能为空");
 		 }
 
-		 String shiftGroup = "";
 		 String shift = "";
+		 String shiftGroup = "";
 		 BilletHotsendChangeShift billetHotsendChangeShift;
 
-		 if(oConvertUtils.isEmpty(queryDTO.getChangeShiftId())){
-			 // 从 Redis 获取班次信息
-			 String classShiftGroup = String.format("class:shift:group:%s", queryDTO.getCcmNo()); // 班组
-			 String classShift = String.format("class:shift:%s",queryDTO.getCcmNo()); // 班别
-			 shift = !oConvertUtils.getString(redisTemplate.opsForValue().get(classShift)).isEmpty() ? oConvertUtils.getString(redisTemplate.opsForValue().get(classShift)) : "";
-			 shiftGroup = !oConvertUtils.getString(redisTemplate.opsForValue().get(classShiftGroup)).isEmpty() ? oConvertUtils.getString(redisTemplate.opsForValue().get(classShiftGroup)) : "";
-			 // 根据铸机号、缓存中的当前班次,倒序最新一条,获取交班记录中的创建时间
+		 if (oConvertUtils.isEmpty(queryDTO.getChangeShiftId())) {
+			 String classShiftGroup = String.format("class:shift:group:%s", queryDTO.getCcmNo());
+			 String classShift = String.format("class:shift:%s", queryDTO.getCcmNo());
+			 shift = oConvertUtils.getString(redisTemplate.opsForValue().get(classShift), "");
+			 shiftGroup = oConvertUtils.getString(redisTemplate.opsForValue().get(classShiftGroup), "");
+
 			 LambdaQueryWrapper<BilletHotsendChangeShift> queryWrapper = new LambdaQueryWrapper<>();
 			 queryWrapper.eq(BilletHotsendChangeShift::getCcmNo, queryDTO.getCcmNo())
 					 .eq(BilletHotsendChangeShift::getShift, shift)
 					 .eq(BilletHotsendChangeShift::getShiftGroup, shiftGroup)
 					 .orderByDesc(BilletHotsendChangeShift::getCreateTime)
 					 .last("limit 1");
+
 			 billetHotsendChangeShift = billetHotsendChangeShiftService.getOne(queryWrapper);
-			 if (billetHotsendChangeShift == null){
+			 if (billetHotsendChangeShift == null) {
 				 log.info("查询班次信息失败,交班记录为空!失败时间:{}", new Date());
 				 return Result.OK(Collections.emptyList());
 			 }
-		 }else {
+		 } else {
 			 LambdaQueryWrapper<BilletHotsendChangeShift> queryWrapper = new LambdaQueryWrapper<>();
 			 queryWrapper.eq(BilletHotsendChangeShift::getId, queryDTO.getChangeShiftId())
 					 .eq(BilletHotsendChangeShift::getCcmNo, queryDTO.getCcmNo());
 
-			  billetHotsendChangeShift = billetHotsendChangeShiftService.getOne(queryWrapper);
+			 billetHotsendChangeShift = billetHotsendChangeShiftService.getOne(queryWrapper);
 			 if (billetHotsendChangeShift == null) {
 				 log.info("查询班次信息失败,交班记录为空!失败时间:{}", new Date());
 				 return Result.OK(Collections.emptyList());
@@ -625,54 +625,82 @@ public class BilletOriginalProductRecordController extends JeecgController<Bille
 		 queryWrapperB.eq("ccm_no", queryDTO.getCcmNo())
 				 .eq("shift", billetHotsendChangeShift.getShift())
 				 .eq("shift_group", billetHotsendChangeShift.getShiftGroup())
-				 .ge("create_time", startTime)   // createTime >= 班次开始时间
-				 .le("create_time", endTime)     // createTime <= 班次交接时间(或当前时间)
+				 .ge("create_time", startTime)
+				 .le("create_time", endTime)
 				 .orderByAsc("create_time");
 
 		 List<BilletOriginalProductRecord> records = billetOriginalProductRecordService.list(queryWrapperB);
 
-		 Set<String> allLengths = new TreeSet<>(); // 统一所有定尺值
 		 List<LengthCountVO> resultList = new ArrayList<>();
+		 Set<String> allLengths = new TreeSet<>();
 		 ObjectMapper objectMapper = new ObjectMapper();
 
 		 for (BilletOriginalProductRecord record : records) {
-			 String json = record.getLengthDetails();
-			 if (StringUtils.isBlank(json)) continue;
+			 LengthCountVO vo = new LengthCountVO();
+			 vo.setHeatNo(record.getHeatNo());
 
-			 try {
-				 JsonNode root = objectMapper.readTree(json);
-				 LengthCountVO vo = new LengthCountVO();
-				 vo.setHeatNo(record.getHeatNo());
-				 String brandNum = Optional.ofNullable(record.getGrade())
-						 .map(bn -> sysDictService.queryDictTextByKey("billet_spec", bn))
-						 .orElseGet(() -> sysDictService.queryDictTextByKey("billet_spec", "5"));
-				 vo.setBrandNum(brandNum);
-
-				 for (Iterator<Map.Entry<String, JsonNode>> it = root.fields(); it.hasNext(); ) {
-					 Map.Entry<String, JsonNode> entry = it.next();
-					 String rawLength = entry.getKey();
-					 int count = entry.getValue().path("lengthTotalCount").asInt(0);
-
-					 // 转换为米单位字符串,如 11520 -> "11.52"
-					 String formattedLength;
-					 try {
-						 BigDecimal lengthMM = new BigDecimal(rawLength);
-						 formattedLength = lengthMM.divide(BigDecimal.valueOf(1000), 2, RoundingMode.HALF_UP).toString();
-					 } catch (NumberFormatException e) {
-						 formattedLength = rawLength;
+			 String brandNum = Optional.ofNullable(record.getGrade())
+					 .map(bn -> sysDictService.queryDictTextByKey("billet_spec", bn))
+					 .orElseGet(() -> sysDictService.queryDictTextByKey("billet_spec", "5"));
+			 vo.setBrandNum(brandNum);
+
+			 Map<String, Integer> mergedLengthCount = new HashMap<>();
+
+			 // 解析 rollClubOneDetails 的 lengthGroupCount
+			 String rollClubOneDetailsJson = record.getRollClubOneDetails();
+			 if (StringUtils.isNotBlank(rollClubOneDetailsJson)) {
+				 try {
+					 JsonNode rollDetails = objectMapper.readTree(rollClubOneDetailsJson);
+					 JsonNode lengthGroupCount = rollDetails.path("lengthGroupCount");
+					 if (lengthGroupCount.isObject()) {
+						 for (Iterator<Map.Entry<String, JsonNode>> it = lengthGroupCount.fields(); it.hasNext(); ) {
+							 Map.Entry<String, JsonNode> entry = it.next();
+							 String mm = entry.getKey();
+							 int count = entry.getValue().asInt(0);
+							 mergedLengthCount.merge(mm, count, Integer::sum);
+						 }
 					 }
+				 } catch (Exception e) {
+					 log.warn("解析 rollClubOneDetails 失败: {}, 内容: {}", record.getHeatNo(), rollClubOneDetailsJson, e);
+				 }
+			 }
 
-					 vo.getLengthCountMap().put(formattedLength, count);
-					 allLengths.add(formattedLength);
+			 // 解析 hotChargeLength 数组
+			 String hotChargeLengthJson = record.getHotChargeLength();
+			 if (StringUtils.isNotBlank(hotChargeLengthJson)) {
+				 try {
+					 JsonNode hotArray = objectMapper.readTree(hotChargeLengthJson);
+					 if (hotArray.isArray()) {
+						 for (JsonNode node : hotArray) {
+							 String mm = node.path("hotChargeLength").asText();
+							 int count = node.path("totalCount").asInt(0);
+							 mergedLengthCount.merge(mm, count, Integer::sum);
+						 }
+					 }
+				 } catch (Exception e) {
+					 log.warn("解析 hotChargeLength 失败: {}, 内容: {}", record.getHeatNo(), hotChargeLengthJson, e);
 				 }
+			 }
 
-				 resultList.add(vo);
-			 } catch (Exception e) {
-				 log.warn("解析 lengthDetails 失败: {},内容为: {}", record.getHeatNo(), json, e);
+			 // 转换 mm 为 m(两位小数),组装 vo
+			 for (Map.Entry<String, Integer> entry : mergedLengthCount.entrySet()) {
+				 String mmStr = entry.getKey();
+				 int count = entry.getValue();
+				 String mStr;
+				 try {
+					 BigDecimal mm = new BigDecimal(mmStr);
+					 mStr = mm.divide(BigDecimal.valueOf(1000), 2, RoundingMode.HALF_UP).toString();
+				 } catch (Exception e) {
+					 mStr = mmStr;
+				 }
+				 vo.getLengthCountMap().put(mStr, count);
+				 allLengths.add(mStr);
 			 }
+
+			 resultList.add(vo);
 		 }
 
-		 // 补齐所有定尺列,未出现的定尺补 0
+		 // 补齐所有定尺列(不存在的补0)
 		 for (LengthCountVO vo : resultList) {
 			 for (String length : allLengths) {
 				 vo.getLengthCountMap().putIfAbsent(length, 0);