1.解决谐波高级算法远程调用bug

2.新增redis,切库方法
This commit is contained in:
wr
2023-11-02 14:07:36 +08:00
parent c0c35152df
commit 7ccce51049
4 changed files with 86 additions and 1 deletions

View File

@@ -9,7 +9,9 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
@FeignClient(value = ServerInfo.ADVANCE_BOOT,path = "/waveAnalysis",fallbackFactory = EventWaveAnalysisFeignClientFallbackFactory.class,contextId = "waveAnalysis") @FeignClient(value = ServerInfo.ADVANCE_BOOT,path = "/waveAnalysis",
fallbackFactory = EventWaveAnalysisFeignClientFallbackFactory.class,
contextId = "waveAnalysis" )
public interface EventWaveAnalysisFeignClient { public interface EventWaveAnalysisFeignClient {

View File

@@ -1,6 +1,9 @@
package com.njcn.advance.pojo.dto.waveAnalysis; package com.njcn.advance.pojo.dto.waveAnalysis;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.sun.jna.Structure; import com.sun.jna.Structure;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
@@ -44,6 +47,7 @@ import java.util.List;
* angle_diff_cn C相相位负跳变 * angle_diff_cn C相相位负跳变
* bph_max_value 不平衡度(单位% * bph_max_value 不平衡度(单位%
*/ */
@JsonIgnoreProperties(ignoreUnknown = true)
public class BackData extends Structure { public class BackData extends Structure {
public int qvvr_cata_cause[] = new int[256]; public int qvvr_cata_cause[] = new int[256];
public int qvvr_phasetype[] = new int[256]; public int qvvr_phasetype[] = new int[256];
@@ -75,10 +79,14 @@ public class BackData extends Structure {
public float angle_diff_cn[] = new float[256]; public float angle_diff_cn[] = new float[256];
public float bph_max_value[] = new float[256]; public float bph_max_value[] = new float[256];
@Data
@NoArgsConstructor
public static class ByReference extends BackData implements Structure.ByReference { public static class ByReference extends BackData implements Structure.ByReference {
} }
@Data
@NoArgsConstructor
public static class ByValue extends BackData implements Structure.ByValue { public static class ByValue extends BackData implements Structure.ByValue {
} }

View File

@@ -1,6 +1,7 @@
package com.njcn.advance.pojo.dto.waveAnalysis; package com.njcn.advance.pojo.dto.waveAnalysis;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor;
/** /**
* @author njcn * @author njcn
@@ -10,6 +11,7 @@ import lombok.Data;
* @处理返回的结果 * @处理返回的结果
*/ */
@Data @Data
@NoArgsConstructor
public class EntityAdvancedData { public class EntityAdvancedData {
public float smp_a[]; public float smp_a[];
public float smp_b[]; public float smp_b[];

View File

@@ -1,6 +1,7 @@
package com.njcn.redis.utils; package com.njcn.redis.utils;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
@@ -68,6 +69,31 @@ public class RedisUtil {
return (String) redisTemplate.opsForValue().get(key); return (String) redisTemplate.opsForValue().get(key);
} }
/**
* 根据key和库索引获取内容字(切库之后,之后查询都是切库数据)
*
* @param dbIndex 指定库索引
* @param key key值
*/
public String getStringByKey(Integer dbIndex,String key) {
return getStringByKey(dbIndex,key,true);
}
/**
* 根据key和库索引获取内容字(切库之后,之后查询都是切库数据)
*
* @param dbIndex 指定库索引
* @param key key值
* @param fly 是否切回原库
*/
public String getStringByKey(Integer dbIndex,String key,Boolean fly) {
Integer index = setDbIndex(dbIndex);
String s = (String) redisTemplate.opsForValue().get(key);
if(fly){
setDbIndex(index);
}
return s;
}
/** /**
* 获取key对应对象数据 * 获取key对应对象数据
*/ */
@@ -101,6 +127,37 @@ public class RedisUtil {
redisTemplate.boundValueOps(key).set(value, expireTime, TimeUnit.SECONDS); redisTemplate.boundValueOps(key).set(value, expireTime, TimeUnit.SECONDS);
} }
} }
/**
* 保存数据,指定生命周期(秒)
*
* @param dbIndex 指定库索引
* @param key 键
* @param value 值
* @param expireTime 生命时间
* @param expireTime 生命时间
*/
public void saveByKeyWithExpire(Integer dbIndex,String key, Object value, Integer expireTime) {
saveByKeyWithExpire(dbIndex,key,value,expireTime,true);
}
/**
* 保存数据,指定生命周期(秒)
*
* @param dbIndex 指定库索引
* @param key 键
* @param value 值
* @param fly 是否切回原库
*/
public void saveByKeyWithExpire(Integer dbIndex,String key, Object value, Integer expireTime,Boolean fly) {
Integer index = setDbIndex(dbIndex);
if (expireTime <= 0) {
saveByKey(key, value);
} else {
redisTemplate.boundValueOps(key).set(value, expireTime, TimeUnit.SECONDS);
}
if(fly){
setDbIndex(index);
}
}
/** /**
* 顺序的递增和递减 * 顺序的递增和递减
@@ -242,4 +299,20 @@ public class RedisUtil {
} }
return info; return info;
} }
private Integer setDbIndex(Integer dbIndex) {
if (dbIndex == null || dbIndex > 15 || dbIndex < 0) {
dbIndex = 0;
}
LettuceConnectionFactory jedisConnectionFactory = (LettuceConnectionFactory) redisTemplate
.getConnectionFactory();
int database = jedisConnectionFactory.getDatabase();
jedisConnectionFactory.setDatabase(dbIndex);
redisTemplate.setConnectionFactory(jedisConnectionFactory);
//需要刷新才能生效
jedisConnectionFactory.afterPropertiesSet();
// 重置连接
jedisConnectionFactory.resetConnection();
return database;
}
} }