Просмотр исходного кода

钢坯实绩入库添加定尺模式判断

qiangxuan 2 дней назад
Родитель
Сommit
38fe9ddcd6

+ 9 - 0
zgzt-sys-java/jeecg-module-conn/src/main/java/org/jeecg/modules/billetActual/entity/StrandLength.java

@@ -0,0 +1,9 @@
+package org.jeecg.modules.billetActual.entity;
+
+import lombok.Data;
+
+@Data
+public class StrandLength {
+    private Integer length;
+    private Integer strandNo;
+}

+ 29 - 0
zgzt-sys-java/jeecg-module-conn/src/main/java/org/jeecg/modules/billetActual/service/impl/BilletBasicInfoExceptionServiceImpl.java

@@ -1,5 +1,6 @@
 package org.jeecg.modules.billetActual.service.impl;
 
+import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.IdWorker;
 import lombok.extern.slf4j.Slf4j;
@@ -17,6 +18,9 @@ import org.springframework.stereotype.Service;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 
 import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 /**
  * @Description: 钢坯实绩异常表
@@ -40,6 +44,31 @@ public class BilletBasicInfoExceptionServiceImpl extends ServiceImpl<BilletBasic
     @Override
     public void addBilletBasicInfoException(BilletBasicInfoException billetBasicInfoException) {
         try {
+
+            // 获取缓存中的定尺信息
+            String redisCuttoLengthKey = String.format("cut:to:length:%s", billetBasicInfoException.getCcmNo());
+            String cuttolengthType = !oConvertUtils.getString(redisTemplate.opsForValue().get(redisCuttoLengthKey)).isEmpty() ? oConvertUtils.getString(redisTemplate.opsForValue().get(redisCuttoLengthKey)) : "";
+            if ("1".equals(cuttolengthType)){
+                String redisLengthKey = String.format("ccmno:length:stream:%s", billetBasicInfoException.getCcmNo());
+                String redisLengthJson = !oConvertUtils.getString(redisTemplate.opsForValue().get(redisLengthKey)).isEmpty() ? oConvertUtils.getString(redisTemplate.opsForValue().get(redisLengthKey)) : "";
+                // 解析 JSON 并构建映射
+                Map<Integer, Integer> strandLengthMap = new HashMap<>();
+                if (!redisLengthJson.isEmpty()) {
+                    try {
+                        List<StrandLength> strandLengths = JSON.parseArray(redisLengthJson, StrandLength.class);
+                        // 转换为Map:键为strandNo,值为length(流号无0,无需额外处理)
+                        for (StrandLength item : strandLengths) {
+                            strandLengthMap.put(item.getStrandNo(), item.getLength());
+                        }
+                    } catch (Exception e) {
+                        log.error("解析流号长度缓存失败,JSON: {}, 错误: {}", redisLengthJson, e);
+                    }
+                }
+                Integer strandNo = billetBasicInfoException.getStrandNo();
+                Integer length = strandLengthMap.get(strandNo);
+                billetBasicInfoException.setLength(length);
+            }
+
             log.info("{}{}", "start接收到mqtt钢坯基础<异常>消息,开始保存异常数据:", DateUtils.date2Str(new Date(), DateUtils.datetimeFormat.get()));
             String classShiftGroup = String.format("class:shift:group:%s", billetBasicInfoException.getCcmNo()); // 班组
             String classShift = String.format("class:shift:%s", billetBasicInfoException.getCcmNo()); // 班别

+ 30 - 5
zgzt-sys-java/jeecg-module-conn/src/main/java/org/jeecg/modules/billetActual/service/impl/BilletBasicInfoServiceImpl.java

@@ -1,14 +1,12 @@
 package org.jeecg.modules.billetActual.service.impl;
 
+import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.util.DateUtils;
 import org.jeecg.common.util.oConvertUtils;
-import org.jeecg.modules.billetActual.entity.BilletBasicInfo;
-import org.jeecg.modules.billetActual.entity.BilletHotsend;
-import org.jeecg.modules.billetActual.entity.BilletHotsendChangeShift;
-import org.jeecg.modules.billetActual.entity.BilletRulerConfig;
+import org.jeecg.modules.billetActual.entity.*;
 import org.jeecg.modules.billetActual.mapper.BilletBasicInfoMapper;
 import org.jeecg.modules.billetActual.mapper.BilletHotsendChangeShiftMapper;
 import org.jeecg.modules.billetActual.mapper.BilletHotsendMapper;
@@ -23,6 +21,9 @@ import org.springframework.transaction.annotation.Transactional;
 
 import java.text.SimpleDateFormat;
 import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 /**
  * @Description: 钢坯基础信息
@@ -48,11 +49,35 @@ public class BilletBasicInfoServiceImpl extends ServiceImpl<BilletBasicInfoMappe
 
     @Autowired
     BilletHotsendChangeShiftMapper billetHotsendChangeShiftMapper;
-
     @Override
     @Transactional(rollbackFor = Exception.class)
     public void addC(BilletBasicInfo billetBasicInfo) {
         try {
+            // 获取缓存中的定尺信息
+            String redisCuttoLengthKey = String.format("cut:to:length:%s", billetBasicInfo.getCcmNo());
+            String cuttolengthType = !oConvertUtils.getString(redisTemplate.opsForValue().get(redisCuttoLengthKey)).isEmpty() ? oConvertUtils.getString(redisTemplate.opsForValue().get(redisCuttoLengthKey)) : "";
+            if ("1".equals(cuttolengthType)){
+                log.info("{}{}", "手动模式定尺取缓存:", billetBasicInfo.getCcmNo());
+                String redisLengthKey = String.format("ccmno:length:stream:%s", billetBasicInfo.getCcmNo());
+                String redisLengthJson = !oConvertUtils.getString(redisTemplate.opsForValue().get(redisLengthKey)).isEmpty() ? oConvertUtils.getString(redisTemplate.opsForValue().get(redisLengthKey)) : "";
+                // 解析 JSON 并构建映射
+                Map<Integer, Integer> strandLengthMap = new HashMap<>();
+                if (!redisLengthJson.isEmpty()) {
+                    try {
+                        List<StrandLength> strandLengths = JSON.parseArray(redisLengthJson, StrandLength.class);
+                        // 转换为Map:键为strandNo,值为length(流号无0,无需额外处理)
+                        for (StrandLength item : strandLengths) {
+                            strandLengthMap.put(item.getStrandNo(), item.getLength());
+                        }
+                    } catch (Exception e) {
+                        log.error("解析流号长度缓存失败,JSON: {}, 错误: {}", redisLengthJson, e);
+                    }
+                }
+                Integer strandNo = billetBasicInfo.getStrandNo();
+                Integer length = strandLengthMap.get(strandNo);
+                billetBasicInfo.setLength(length);
+            }
+            
             log.info("{}{}", "start钢坯基础信息接收到mqtt消息,开始处理逻辑:", DateUtils.date2Str(new Date(), DateUtils.datetimeFormat.get()));
             String classShiftGroup = String.format("class:shift:group:%s", billetBasicInfo.getCcmNo()); // 班组
             String classShift = String.format("class:shift:%s", billetBasicInfo.getCcmNo()); // 班别

+ 8 - 1
zgzt-sys-java/jeecg-module-conn/src/main/java/org/jeecg/modules/billetActual/service/impl/BilletHotsendBaseServiceImpl.java

@@ -600,12 +600,19 @@ public class BilletHotsendBaseServiceImpl extends ServiceImpl<BilletHotsendBaseM
 			throw new JeecgBootException("流号定尺集合不能为空!");
 		}
 
+		String redisCuttoLengthKey = String.format("cut:to:length:%s", ccmNo);
+		String cuttolengthType = !oConvertUtils.getString(redisTemplate.opsForValue().get(redisCuttoLengthKey))
+				.isEmpty() ? oConvertUtils.getString(redisTemplate.opsForValue().get(redisCuttoLengthKey)) : "";
+		if ("1".equals(cuttolengthType)){
+			// 定尺类型为手动模式,忽略,不更新定尺缓存
+			return;
+		}
+
 		// 构造 Redis key
 		String redisKey = String.format("ccmno:length:stream:%s", ccmNo);
 
 		// 序列化成 JSON 字符串(保留原始格式存储)
 		String jsonValue = strandNoSizeArray.toJSONString();
-
 		// 存入 Redis
 		redisTemplate.opsForValue().set(redisKey, jsonValue);