diff --git a/jsowell-admin/src/test/java/SpringBootTestController.java b/jsowell-admin/src/test/java/SpringBootTestController.java index eea75b1d7..d6ab436f8 100644 --- a/jsowell-admin/src/test/java/SpringBootTestController.java +++ b/jsowell-admin/src/test/java/SpringBootTestController.java @@ -100,7 +100,6 @@ import org.springframework.util.StopWatch; import java.io.UnsupportedEncodingException; import java.math.BigDecimal; -import java.math.RoundingMode; import java.nio.charset.StandardCharsets; import java.text.ParseException; import java.text.SimpleDateFormat; @@ -274,6 +273,19 @@ public class SpringBootTestController { @Qualifier("zhongDianLianPlatformServiceImpl") private ThirdPartyPlatformService platformLogic; + @Test + public void saveSOCTest() { + String transactionCode = "123"; + YKCUtils.saveSOC(transactionCode, "4"); + YKCUtils.saveSOC(transactionCode, "3"); + YKCUtils.saveSOC(transactionCode, "5"); + YKCUtils.saveSOC(transactionCode, "10"); + YKCUtils.saveSOC(transactionCode, "20"); + YKCUtils.saveSOC(transactionCode, "19.9"); + YKCUtils.saveSOC(transactionCode, "29.9"); + System.out.println(redisCache.getCacheMap(CacheConstants.GET_THE_SOC + transactionCode)); + } + @Test public void queryStationStatus() { QueryStationInfoDTO dto = new QueryStationInfoDTO(); diff --git a/jsowell-common/src/main/java/com/jsowell/common/constant/CacheConstants.java b/jsowell-common/src/main/java/com/jsowell/common/constant/CacheConstants.java index ec0c1f1da..10d374ee3 100644 --- a/jsowell-common/src/main/java/com/jsowell/common/constant/CacheConstants.java +++ b/jsowell-common/src/main/java/com/jsowell/common/constant/CacheConstants.java @@ -47,6 +47,9 @@ public class CacheConstants { // 缓存时间 30天 public static final int cache_expire_time_30d = cache_expire_time_1d * 30; + // 获取SOC + public static final String GET_THE_SOC = "GET_THE_SOC:"; + // 第三方平台密钥配置 public static final String THIRD_PARTY_SECRET_INFO_BY_ID = "third_party_secret_info_by_id:"; public static final String THIRD_PARTY_SECRET_INFO_BY_TYPE = "third_party_secret_info_by_type:"; diff --git a/jsowell-common/src/main/java/com/jsowell/common/util/YKCUtils.java b/jsowell-common/src/main/java/com/jsowell/common/util/YKCUtils.java index 7a8f575f0..277fcebb2 100644 --- a/jsowell-common/src/main/java/com/jsowell/common/util/YKCUtils.java +++ b/jsowell-common/src/main/java/com/jsowell/common/util/YKCUtils.java @@ -7,6 +7,7 @@ import com.jsowell.common.constant.Constants; import com.jsowell.common.core.domain.ykc.YKCBaseMessage; import com.jsowell.common.core.domain.ykc.YKCDataProtocol; import com.jsowell.common.core.domain.ykc.YKCFrameTypeCode; +import com.jsowell.common.core.redis.RedisCache; import com.jsowell.common.core.redis.StaticRedisCache; import com.jsowell.common.enums.ykc.PileChannelEntity; import com.jsowell.common.enums.ykc.ReturnCodeEnum; @@ -16,6 +17,7 @@ import lombok.extern.slf4j.Slf4j; import java.math.BigDecimal; import java.util.Map; +import java.util.concurrent.TimeUnit; @Slf4j public class YKCUtils { @@ -135,14 +137,6 @@ public class YKCUtils { return Bytes.concat(headBytes, BytesUtil.intToBytes(dataFields.length, 1), dataFields, BytesUtil.intToBytes(crc16)); } - public static void main(String[] args) { - String type = "0x3B"; - System.out.println(type); - byte[] bytes = BytesUtil.hexString2Bytes(type.replace("0x", "")); - System.out.println(YKCUtils.frameType2Str(bytes)); - - } - /** * 保存桩最后链接到平台的时间 * @param pileSn 桩编号 @@ -337,4 +331,39 @@ public class YKCUtils { return map.get("connectorCode"); } + /** + * 保存soc + * @param transactionCode + * @param soc + */ + public static void saveSOC(String transactionCode, String soc) { + String hashKey = CacheConstants.GET_THE_SOC + transactionCode; + RedisCache staticRedisCache = StaticRedisCache.staticRedisCache; + try { + // 检查值是否符合要求 + if (!soc.matches("^-?\\d+(\\.\\d{1})?$")) { + throw new IllegalArgumentException("输入的值必须是一个最多有一位小数的数字: " + soc); + } + double doubleValue = Double.parseDouble(soc); + // 获取当前的最小值和最大值 + String currentMin = (String) staticRedisCache.hget(hashKey, "min"); + String currentMax = (String) staticRedisCache.hget(hashKey, "max"); + + double min = currentMin != null ? Double.parseDouble(currentMin) : Double.MAX_VALUE; + double max = currentMax != null ? Double.parseDouble(currentMax) : Double.MIN_VALUE; + + // 更新最小值或最大值 + if (doubleValue < min) { + staticRedisCache.hset(hashKey, "min", soc, 7, TimeUnit.DAYS); + } + if (doubleValue > max) { + staticRedisCache.hset(hashKey, "max", soc, 7, TimeUnit.DAYS); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + + + }