mirror of
https://codeup.aliyun.com/67c68d4e484ca2f0a13ac3c1/ydc/jsowell-charger-web.git
synced 2026-04-20 02:55:04 +08:00
Merge branch 'dev-new' into dev-new-rabbitmq
# Conflicts: # jsowell-admin/src/test/java/SpringBootTestController.java
This commit is contained in:
@@ -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:";
|
||||
|
||||
@@ -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,53 @@ public class YKCUtils {
|
||||
return map.get("connectorCode");
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存soc
|
||||
* @param transactionCode
|
||||
* @param soc
|
||||
*/
|
||||
public static void saveSOC(String transactionCode, String soc) {
|
||||
if (StringUtils.isBlank(transactionCode) || Double.parseDouble(soc) <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据的交易码获取当前soc
|
||||
* @param transactionCode
|
||||
*/
|
||||
public static String getCurrentSOC(String transactionCode) {
|
||||
String hashKey = CacheConstants.GET_THE_SOC + transactionCode;
|
||||
RedisCache staticRedisCache = StaticRedisCache.staticRedisCache;
|
||||
Map<String, Object> cacheMap = staticRedisCache.getCacheMap(hashKey);
|
||||
// 获取最小值和最大值, 两个值中最大的为当前soc
|
||||
return (String) cacheMap.get("max");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user