省厅系统接口对接
This commit is contained in:
parent
cf929bb4c0
commit
3b782b7368
|
|
@ -1,4 +1,4 @@
|
|||
package com.common.utils.encryption;
|
||||
package com.rzyc.provinceUtil;
|
||||
|
||||
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
|
|
@ -6,6 +6,7 @@ import cn.hutool.core.util.IdUtil;
|
|||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.crypto.asymmetric.KeyType;
|
||||
import cn.hutool.crypto.asymmetric.RSA;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
|
||||
|
|
@ -22,7 +23,7 @@ import java.util.Base64;
|
|||
* 省清单数据对接请求响应加解密工具
|
||||
* Created by why on 2024/5/11.
|
||||
*/
|
||||
public class ENDEUtils {
|
||||
public class EnedUtils {
|
||||
|
||||
private static final String AES_CIPHER_ALGORITHM = "AES/ECB/PKCS5Padding";
|
||||
|
||||
|
|
@ -122,8 +123,51 @@ public class ENDEUtils {
|
|||
return JSONObject.parseObject(decryptData);
|
||||
}
|
||||
|
||||
/**
|
||||
* 省厅接口网络请求
|
||||
* @version v1.0
|
||||
* @author dong
|
||||
* @date 2025/3/18 14:38
|
||||
*/
|
||||
public static String doPost(String url,String paramsSts,String accessToken){
|
||||
|
||||
//加密请求参数
|
||||
JSONObject req = RSAEncryptRequest(paramsSts);
|
||||
|
||||
|
||||
|
||||
HttpRequest request = HttpUtil.createPost(url)
|
||||
.header("Content-Type", "application/json") // 确保服务器能解析 JSON
|
||||
.header("access_token", accessToken)
|
||||
.header("accessToken", accessToken)
|
||||
.header("Authorization", accessToken)
|
||||
.setFollowRedirects(false)
|
||||
.body(req.toJSONString());
|
||||
|
||||
// 3. 打印请求信息(调试用)
|
||||
System.out.println("Request Body: " + req.toJSONString());
|
||||
System.out.println("Request Headers: " + request.headers());
|
||||
|
||||
// 4. 发送请求
|
||||
HttpResponse response = request.execute();
|
||||
|
||||
// 5. 打印响应信息(调试用)
|
||||
System.out.println("Response Status: " + response.getStatus());
|
||||
System.out.println("Response Body: " + response.body());
|
||||
|
||||
|
||||
//返回结果转json
|
||||
JSONObject res = JSONObject.parseObject(response.body());
|
||||
//返回结果解密
|
||||
JSONObject responseStr = RSADecryptResponse(res.getString("k"), res.getString("v"));
|
||||
//返回界面结果
|
||||
return responseStr.toJSONString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
//加密请求测试JSON格式字符参数
|
||||
String bodyStr = "{\"sysUniqueCode\":\"127829545796636679\"}";
|
||||
//加密请求参数
|
||||
116
inventory-dao/src/main/java/com/rzyc/provinceUtil/JsonUtils.java
Normal file
116
inventory-dao/src/main/java/com/rzyc/provinceUtil/JsonUtils.java
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
package com.rzyc.provinceUtil;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
/**
|
||||
* @author dong
|
||||
* @date 2025-03-18 15:25
|
||||
* @Version V1.0
|
||||
*/
|
||||
public class JsonUtils {
|
||||
|
||||
|
||||
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
/**
|
||||
* 将 JSON 字符串转换为包含泛型的对象
|
||||
* @param json JSON 字符串
|
||||
* @param mainClass 主类型(如 Result.class)
|
||||
* @param subClass 泛型参数类型(如 User.class)
|
||||
* @return 转换后的对象
|
||||
*/
|
||||
public static <T, R> T fromJson(String json, Class<T> mainClass, Class<R> subClass) {
|
||||
try {
|
||||
// 动态构建泛型类型(例如 Result<User>)
|
||||
Type type = createParametricType(mainClass, subClass);
|
||||
return objectMapper.readValue(json, new TypeReference<T>() {
|
||||
@Override
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("JSON 转换失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 构建 ParameterizedType(例如 Result<User>)
|
||||
*/
|
||||
private static ParameterizedType createParametricType(final Class<?> rawType,
|
||||
final Type... typeArguments){
|
||||
return new ParameterizedType() {
|
||||
@Override
|
||||
public Type[] getActualTypeArguments() {
|
||||
return typeArguments;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getRawType() {
|
||||
return rawType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getOwnerType() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用示例:解析 Result<List<User>>
|
||||
* @version v1.0
|
||||
* @author dong
|
||||
* @date 2025/3/18 15:44
|
||||
*/
|
||||
/* Type userListType = new TypeToken<List<User>>() {}.getType();
|
||||
Result<List<User>> result = JsonUtils.fromJsonComplex(
|
||||
json,
|
||||
Result.class,
|
||||
userListType
|
||||
);*/
|
||||
|
||||
/**
|
||||
* json转list
|
||||
* @version v1.0
|
||||
* @author dong
|
||||
* @date 2025/3/18 15:43
|
||||
*/
|
||||
public static <T> T fromJsonComplex(String json, Class<?> rawType, Type... genericTypes) {
|
||||
try {
|
||||
ParameterizedType type = new ParameterizedType() {
|
||||
@Override
|
||||
public Type[] getActualTypeArguments() {
|
||||
return genericTypes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getRawType() {
|
||||
return rawType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getOwnerType() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
return objectMapper.readValue(json, new TypeReference<T>() {
|
||||
@Override
|
||||
public Type getType() {
|
||||
return type;
|
||||
}
|
||||
});
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("JSON 转换失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
package com.rzyc.provinceUtil;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.rzyc.provinceUtil.bean.TokenData;
|
||||
import lombok.Data;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
/**
|
||||
* @author dong
|
||||
* @date 2025-03-18 14:30
|
||||
* @Version V1.0
|
||||
*/
|
||||
@Data
|
||||
public class ProvData<T> {
|
||||
|
||||
//访问状态
|
||||
private String code;
|
||||
|
||||
//返回信息
|
||||
private String msg;
|
||||
|
||||
//返回数据
|
||||
private T data;
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
package com.rzyc.provinceUtil.bean;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 部门信息
|
||||
* @author dong
|
||||
* @date 2025-03-18 16:16
|
||||
* @Version V1.0
|
||||
*/
|
||||
@Data
|
||||
public class DeptInfo {
|
||||
|
||||
//部门id
|
||||
private String deptId;
|
||||
|
||||
//部门名
|
||||
private String deptName;
|
||||
|
||||
//父级id
|
||||
private String parentId;
|
||||
|
||||
//子级部门
|
||||
private List<DeptInfo> children;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
package com.rzyc.provinceUtil.bean;
|
||||
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 省厅token信息
|
||||
* @author dong
|
||||
* @date 2025-03-18 14:46
|
||||
* @Version V1.0
|
||||
*/
|
||||
@Data
|
||||
public class TokenData {
|
||||
|
||||
|
||||
//token
|
||||
private String access_token;
|
||||
|
||||
//时效(分钟)
|
||||
private String expires_in;
|
||||
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.rzyc.config;
|
||||
package com.rzyc.redis;
|
||||
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.rzyc.config;
|
||||
package com.rzyc.redis;
|
||||
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
|
@ -15,8 +15,10 @@ import com.rzyc.mapper.oth.*;
|
|||
import com.rzyc.mapper.personal.SysResourceMapper;
|
||||
import com.rzyc.mapper.sys.*;
|
||||
import com.rzyc.mapper.user.*;
|
||||
import com.rzyc.redis.RedisUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
/**
|
||||
|
|
@ -587,4 +589,8 @@ public class BaseService {
|
|||
@Autowired
|
||||
protected ExScoreRecordMapper exScoreRecordMapper;
|
||||
|
||||
//redis
|
||||
@Resource
|
||||
protected RedisUtil redisUtil;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,116 @@
|
|||
package com.rzyc.service;
|
||||
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.common.utils.StringUtils;
|
||||
import com.common.utils.TypeConversion;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.zxing.Result;
|
||||
import com.rzyc.provinceUtil.EnedUtils;
|
||||
import com.rzyc.provinceUtil.JsonUtils;
|
||||
import com.rzyc.provinceUtil.ProvData;
|
||||
import com.rzyc.provinceUtil.bean.DeptInfo;
|
||||
import com.rzyc.provinceUtil.bean.TokenData;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
/**
|
||||
* 省厅接口对接
|
||||
* @author dong
|
||||
* @date 2025-03-18 9:40
|
||||
* @Version V1.0
|
||||
*/
|
||||
@Service
|
||||
@Service("ProvinceService")
|
||||
public class ProvinceService extends BaseService{
|
||||
|
||||
//接口基础地址 正式服
|
||||
private static String BASE_URL = "https://qdz.scasst.net/prod-api";
|
||||
|
||||
//平台唯一标识码
|
||||
private static String SYS_UNIQUE_CODE = "127829545796636679 ";
|
||||
|
||||
|
||||
//获取token接口地址
|
||||
private static String GET_TOKEN_URL = "/auth/sync/getToken";
|
||||
|
||||
|
||||
private static String REDIS_TOKEN_KEY = "province_token_key";
|
||||
|
||||
|
||||
/**
|
||||
* 通过接口后期token
|
||||
* @version v1.0
|
||||
* @author dong
|
||||
* @date 2025/3/18 16:01
|
||||
*/
|
||||
public String getTokenApi(){
|
||||
Map<String,String> params = new HashMap<>();
|
||||
params.put("sysUniqueCode",SYS_UNIQUE_CODE);
|
||||
//加密请求参数
|
||||
String responseStr = EnedUtils.doPost(BASE_URL+GET_TOKEN_URL,JSONObject.toJSONString(params),"");
|
||||
ProvData<TokenData> data = JsonUtils.fromJson(responseStr,ProvData.class,TokenData.class);
|
||||
System.out.println("req --> "+data.getData().getAccess_token());
|
||||
System.out.println("req --> "+data.getData().getExpires_in());
|
||||
String expiresIn = data.getData().getExpires_in();
|
||||
String token = data.getData().getAccess_token();
|
||||
redisUtil.set(REDIS_TOKEN_KEY, token, TypeConversion.StringToInteger(expiresIn)-1);
|
||||
return token;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取token
|
||||
* @version v1.0
|
||||
* @author dong
|
||||
* @date 2025/3/18 14:13
|
||||
*/
|
||||
public String getToken(){
|
||||
Object accessToken = redisUtil.get(REDIS_TOKEN_KEY);
|
||||
if(null == accessToken){
|
||||
accessToken = getTokenApi();
|
||||
}
|
||||
return accessToken.toString();
|
||||
}
|
||||
|
||||
//获取部门信息
|
||||
private static String GET_DEPT = "/gov/sync/base/dept";
|
||||
|
||||
|
||||
/**
|
||||
* 获取部门信息
|
||||
* @version v1.0
|
||||
* @author dong
|
||||
* @date 2025/3/18 16:18
|
||||
*/
|
||||
public void getDeptApi(){
|
||||
String token = getToken();
|
||||
Map<String,String> params = new HashMap<>();
|
||||
params.put("sysUniqueCode",SYS_UNIQUE_CODE);
|
||||
params.put("access_token",token);
|
||||
//加密请求参数
|
||||
String responseStr = EnedUtils.doPost(BASE_URL+GET_DEPT,JSONObject.toJSONString(params),token);
|
||||
|
||||
Type userListType = new TypeToken<List<DeptInfo>>() {}.getType();
|
||||
ProvData<List<DeptInfo>> data = JsonUtils.fromJsonComplex(responseStr,ProvData.class, userListType);
|
||||
|
||||
System.out.println("data --> "+JSONArray.toJSONString(data));
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据测试
|
||||
* @version v1.0
|
||||
* @author dong
|
||||
* @date 2025/3/18 16:19
|
||||
*/
|
||||
public void dataTest(){
|
||||
getDeptApi();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,52 +0,0 @@
|
|||
package com.rzyc.config;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAutoDetect;
|
||||
import com.fasterxml.jackson.annotation.PropertyAccessor;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.databind.module.SimpleModule;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.connection.RedisConnectionFactory;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
|
||||
/**
|
||||
* Redis 连接及序列化
|
||||
* @author Xuwanxin
|
||||
* @date 2022/10/13
|
||||
* */
|
||||
|
||||
@Configuration
|
||||
public class RedisConfig {
|
||||
|
||||
|
||||
/**
|
||||
* 在使用localTime对象时,GenericJackson2JsonRedisSerializer反序列化会报转换错误,遇到之后还需要再单独处理
|
||||
* */
|
||||
@Bean
|
||||
public RedisTemplate<String,Object> strRedisTemplate(RedisConnectionFactory redisConnectionFactory){
|
||||
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
|
||||
// key 序列化方式
|
||||
redisTemplate.setKeySerializer(new StringRedisSerializer());
|
||||
// value 序列化
|
||||
redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());
|
||||
// hash 类型 key序列化
|
||||
redisTemplate.setHashKeySerializer(new StringRedisSerializer());
|
||||
// hash 类型 value序列化方式
|
||||
redisTemplate.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());
|
||||
// 注入连接工厂
|
||||
redisTemplate.setConnectionFactory(redisConnectionFactory);
|
||||
// 让设置生效
|
||||
redisTemplate.afterPropertiesSet();
|
||||
return redisTemplate;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -1,618 +0,0 @@
|
|||
package com.rzyc.config;
|
||||
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Redis操作api工具
|
||||
* @author Xuwanxin
|
||||
* @date 2022/10/17
|
||||
* */
|
||||
|
||||
@Component
|
||||
public class RedisUtil {
|
||||
|
||||
|
||||
RedisTemplate<String,Object> redisTemplate;
|
||||
|
||||
@Autowired
|
||||
public RedisUtil(RedisTemplate<String, Object> redisTemplate) {
|
||||
this.redisTemplate = redisTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
* get 多参数分隔 :
|
||||
* @param key 键
|
||||
*/
|
||||
public String appendSymbol(String ... key) {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
try {
|
||||
for (String k:key) {
|
||||
stringBuilder.append(k);
|
||||
stringBuilder.append(":");
|
||||
}
|
||||
return stringBuilder.deleteCharAt(stringBuilder.lastIndexOf(":")).toString();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return "error";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 指定缓存失效时间
|
||||
* @param key 键
|
||||
* @param time 时间(秒)
|
||||
*/
|
||||
public boolean expire(String key, long time) {
|
||||
try {
|
||||
if (time > 0) {
|
||||
redisTemplate.expire(key, time, TimeUnit.SECONDS);
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据key 获取过期时间
|
||||
* @param key 键 不能为null
|
||||
* @return 时间(秒) 返回0代表为永久有效
|
||||
*/
|
||||
public long getExpire(String key) {
|
||||
return redisTemplate.getExpire(key, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 判断key是否存在
|
||||
* @param key 键
|
||||
* @return true 存在 false不存在
|
||||
*/
|
||||
public boolean hasKey(String key) {
|
||||
try {
|
||||
return redisTemplate.hasKey(key);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除缓存
|
||||
* @param key 可以传一个值 或多个
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public void del(String... key) {
|
||||
if (key != null && key.length > 0) {
|
||||
if (key.length == 1) {
|
||||
redisTemplate.delete(key[0]);
|
||||
} else {
|
||||
redisTemplate.delete(String.valueOf(CollectionUtils.arrayToList(key)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ============================String=============================
|
||||
|
||||
/**
|
||||
* 普通缓存获取
|
||||
* @param key 键
|
||||
* @return 值
|
||||
*/
|
||||
public Object get(String key) {
|
||||
return key == null ? null : redisTemplate.opsForValue().get(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 普通缓存放入
|
||||
* @param key 键
|
||||
* @param value 值
|
||||
* @return true成功 false失败
|
||||
*/
|
||||
|
||||
public boolean set(String key, Object value) {
|
||||
try {
|
||||
redisTemplate.opsForValue().set(key, value);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 普通缓存放入并设置时间
|
||||
* @param key 键
|
||||
* @param value 值
|
||||
* @param time 时间(秒) time要大于0 如果time小于等于0 将设置默认8小时
|
||||
* @return true成功 false 失败
|
||||
*/
|
||||
|
||||
public boolean set(String key, Object value, long time) {
|
||||
//默认8小时ttl时间
|
||||
time = time > 0 ? time : 28800;
|
||||
try {
|
||||
if (time > 0) {
|
||||
redisTemplate.opsForValue().set(key, value, time, TimeUnit.SECONDS);
|
||||
} else {
|
||||
set(key, value);
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 递增
|
||||
* @param key 键
|
||||
* @param delta 要增加几(大于0)
|
||||
*/
|
||||
public long incr(String key, long delta) {
|
||||
if (delta < 0) {
|
||||
throw new RuntimeException("递增因子必须大于0");
|
||||
}
|
||||
return redisTemplate.opsForValue().increment(key, delta);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 递减
|
||||
* @param key 键
|
||||
* @param delta 要减少几(小于0)
|
||||
*/
|
||||
public long decr(String key, long delta) {
|
||||
if (delta < 0) {
|
||||
throw new RuntimeException("递减因子必须大于0");
|
||||
}
|
||||
return redisTemplate.opsForValue().increment(key, -delta);
|
||||
}
|
||||
|
||||
|
||||
// ================================Map=================================
|
||||
|
||||
/**
|
||||
* HashGet
|
||||
* @param key 键 不能为null
|
||||
* @param item 项 不能为null
|
||||
*/
|
||||
public Object hget(String key, String item) {
|
||||
return redisTemplate.opsForHash().get(key, item);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取hashKey对应的所有键值
|
||||
* @param key 键
|
||||
* @return 对应的多个键值
|
||||
*/
|
||||
public Map<Object, Object> hmget(String key) {
|
||||
return redisTemplate.opsForHash().entries(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* HashSet
|
||||
* @param key 键
|
||||
* @param map 对应多个键值
|
||||
*/
|
||||
public boolean hmset(String key, Map<String, Object> map) {
|
||||
try {
|
||||
redisTemplate.opsForHash().putAll(key, map);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* HashSet 并设置时间
|
||||
* @param key 键
|
||||
* @param map 对应多个键值
|
||||
* @param time 时间(秒)
|
||||
* @return true成功 false失败
|
||||
*/
|
||||
public boolean hmset(String key, Map<String, Object> map, long time) {
|
||||
//默认8小时ttl时间
|
||||
time = time > 0 ? time : 28800;
|
||||
try {
|
||||
redisTemplate.opsForHash().putAll(key, map);
|
||||
if (time > 0) {
|
||||
expire(key, time);
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 向一张hash表中放入数据,如果不存在将创建
|
||||
*
|
||||
* @param key 键
|
||||
* @param item 项
|
||||
* @param value 值
|
||||
* @return true 成功 false失败
|
||||
*/
|
||||
public boolean hset(String key, String item, Object value) {
|
||||
try {
|
||||
redisTemplate.opsForHash().put(key, item, value);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 向一张hash表中放入数据,如果不存在将创建
|
||||
*
|
||||
* @param key 键
|
||||
* @param item 项
|
||||
* @param value 值
|
||||
* @param time 时间(秒) 注意:如果已存在的hash表有时间,这里将会替换原有的时间
|
||||
* @return true 成功 false失败
|
||||
*/
|
||||
public boolean hset(String key, String item, Object value, long time) {
|
||||
//默认8小时ttl时间
|
||||
time = time > 0 ? time : 28800;
|
||||
try {
|
||||
redisTemplate.opsForHash().put(key, item, value);
|
||||
if (time > 0) {
|
||||
expire(key, time);
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 删除hash表中的值
|
||||
*
|
||||
* @param key 键 不能为null
|
||||
* @param item 项 可以使多个 不能为null
|
||||
*/
|
||||
public void hdel(String key, Object... item) {
|
||||
redisTemplate.opsForHash().delete(key, item);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 判断hash表中是否有该项的值
|
||||
*
|
||||
* @param key 键 不能为null
|
||||
* @param item 项 不能为null
|
||||
* @return true 存在 false不存在
|
||||
*/
|
||||
public boolean hHasKey(String key, String item) {
|
||||
return redisTemplate.opsForHash().hasKey(key, item);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* hash递增 如果不存在,就会创建一个 并把新增后的值返回
|
||||
*
|
||||
* @param key 键
|
||||
* @param item 项
|
||||
* @param by 要增加几(大于0)
|
||||
*/
|
||||
public double hincr(String key, String item, double by) {
|
||||
return redisTemplate.opsForHash().increment(key, item, by);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* hash递减
|
||||
*
|
||||
* @param key 键
|
||||
* @param item 项
|
||||
* @param by 要减少记(小于0)
|
||||
*/
|
||||
public double hdecr(String key, String item, double by) {
|
||||
return redisTemplate.opsForHash().increment(key, item, -by);
|
||||
}
|
||||
|
||||
|
||||
// ============================set=============================
|
||||
|
||||
/**
|
||||
* 根据key获取Set中的所有值
|
||||
* @param key 键
|
||||
*/
|
||||
public Set<Object> sGet(String key) {
|
||||
try {
|
||||
return redisTemplate.opsForSet().members(key);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据value从一个set中查询,是否存在
|
||||
*
|
||||
* @param key 键
|
||||
* @param value 值
|
||||
* @return true 存在 false不存在
|
||||
*/
|
||||
public boolean sHasKey(String key, Object value) {
|
||||
try {
|
||||
return redisTemplate.opsForSet().isMember(key, value);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将数据放入set缓存
|
||||
*
|
||||
* @param key 键
|
||||
* @param values 值 可以是多个
|
||||
* @return 成功个数
|
||||
*/
|
||||
public long sSet(String key, Object... values) {
|
||||
try {
|
||||
return redisTemplate.opsForSet().add(key, values);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将set数据放入缓存
|
||||
*
|
||||
* @param key 键
|
||||
* @param time 时间(秒)
|
||||
* @param values 值 可以是多个
|
||||
* @return 成功个数
|
||||
*/
|
||||
public long sSetAndTime(String key, long time, Object... values) {
|
||||
//默认8小时ttl时间
|
||||
time = time > 0 ? time : 28800;
|
||||
try {
|
||||
Long count = redisTemplate.opsForSet().add(key, values);
|
||||
if (time > 0) {
|
||||
expire(key, time);
|
||||
}
|
||||
return count;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取set缓存的长度
|
||||
*
|
||||
* @param key 键
|
||||
*/
|
||||
public long sGetSetSize(String key) {
|
||||
try {
|
||||
return redisTemplate.opsForSet().size(key);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 移除值为value的
|
||||
*
|
||||
* @param key 键
|
||||
* @param values 值 可以是多个
|
||||
* @return 移除的个数
|
||||
*/
|
||||
|
||||
public long setRemove(String key, Object... values) {
|
||||
try {
|
||||
Long count = redisTemplate.opsForSet().remove(key, values);
|
||||
return count;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// ===============================list=================================
|
||||
|
||||
/**
|
||||
* 获取list缓存的内容
|
||||
*
|
||||
* @param key 键
|
||||
* @param start 开始
|
||||
* @param end 结束 0 到 -1代表所有值
|
||||
*/
|
||||
public List<Object> lGet(String key, long start, long end) {
|
||||
try {
|
||||
return redisTemplate.opsForList().range(key, start, end);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取list缓存的长度
|
||||
*
|
||||
* @param key 键
|
||||
*/
|
||||
public long lGetListSize(String key) {
|
||||
try {
|
||||
return redisTemplate.opsForList().size(key);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 通过索引 获取list中的值
|
||||
*
|
||||
* @param key 键
|
||||
* @param index 索引 index>=0时, 0 表头,1 第二个元素,依次类推;index<0时,-1,表尾,-2倒数第二个元素,依次类推
|
||||
*/
|
||||
public Object lGetIndex(String key, long index) {
|
||||
try {
|
||||
return redisTemplate.opsForList().index(key, index);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将list放入缓存
|
||||
*
|
||||
* @param key 键
|
||||
* @param value 值
|
||||
*/
|
||||
public boolean lSet(String key, Object value) {
|
||||
try {
|
||||
redisTemplate.opsForList().rightPush(key, value);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将list放入缓存
|
||||
* @param key 键
|
||||
* @param value 值
|
||||
* @param time 时间(秒)
|
||||
*/
|
||||
public boolean lSet(String key, Object value, long time) {
|
||||
//默认8小时ttl时间
|
||||
time = time > 0 ? time : 28800;
|
||||
try {
|
||||
redisTemplate.opsForList().rightPush(key, value);
|
||||
if (time > 0) {
|
||||
expire(key, time);
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将list放入缓存
|
||||
*
|
||||
* @param key 键
|
||||
* @param value 值
|
||||
* @return
|
||||
*/
|
||||
public boolean lSet(String key, List<Object> value) {
|
||||
try {
|
||||
redisTemplate.opsForList().rightPushAll(key, value);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 将list放入缓存
|
||||
*
|
||||
* @param key 键
|
||||
* @param value 值
|
||||
* @param time 时间(秒)
|
||||
* @return
|
||||
*/
|
||||
public boolean lSet(String key, List<Object> value, long time) {
|
||||
//默认8小时ttl时间
|
||||
time = time > 0 ? time : 28800;
|
||||
try {
|
||||
redisTemplate.opsForList().rightPushAll(key, value);
|
||||
if (time > 0) {
|
||||
expire(key, time);
|
||||
}
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据索引修改list中的某条数据
|
||||
*
|
||||
* @param key 键
|
||||
* @param index 索引
|
||||
* @param value 值
|
||||
* @return
|
||||
*/
|
||||
|
||||
public boolean lUpdateIndex(String key, long index, Object value) {
|
||||
try {
|
||||
redisTemplate.opsForList().set(key, index, value);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 移除N个值为value
|
||||
*
|
||||
* @param key 键
|
||||
* @param count 移除多少个
|
||||
* @param value 值
|
||||
* @return 移除的个数
|
||||
*/
|
||||
|
||||
public long lRemove(String key, long count, Object value) {
|
||||
try {
|
||||
Long remove = redisTemplate.opsForList().remove(key, count, value);
|
||||
return remove;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -3,7 +3,6 @@ package com.rzyc.controller;
|
|||
|
||||
import com.common.utils.model.SingleResult;
|
||||
import com.rzyc.config.MethodAnnotation;
|
||||
import com.rzyc.config.RedisUtil;
|
||||
import com.rzyc.model.ent.EntEmEquipment;
|
||||
import com.rzyc.model.ent.EntEmExpert;
|
||||
import com.rzyc.model.ent.EntEmRehearsal;
|
||||
|
|
@ -12,6 +11,7 @@ import com.rzyc.model.dto.EntEmEquipmentDto;
|
|||
import com.rzyc.model.dto.EntEmExpertDto;
|
||||
import com.rzyc.model.dto.EntEmRehearsalDto;
|
||||
import com.rzyc.model.dto.EntEmReservePlanDto;
|
||||
import com.rzyc.redis.RedisUtil;
|
||||
import com.rzyc.service.PcBusinessService;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
|
|
|
|||
|
|
@ -10,10 +10,10 @@ import com.common.utils.model.SingleResult;
|
|||
import com.rzyc.bean.user.dto.AppLoginDto;
|
||||
import com.rzyc.bean.user.dto.LoginDto;
|
||||
import com.rzyc.config.MethodAnnotation;
|
||||
import com.rzyc.config.RedisUtil;
|
||||
import com.rzyc.model.*;
|
||||
import com.rzyc.model.dto.*;
|
||||
import com.rzyc.model.ent.*;
|
||||
import com.rzyc.redis.RedisUtil;
|
||||
import com.rzyc.service.PcBusinessService;
|
||||
import com.rzyc.service.UserLoginService;
|
||||
import com.rzyc.bean.user.dto.WeChartLoginDto;
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ import com.common.utils.model.SingleResult;
|
|||
import com.rzyc.pager.PageOperation;
|
||||
import com.github.pagehelper.Page;
|
||||
import com.rzyc.advice.CustomException;
|
||||
import com.rzyc.config.RedisUtil;
|
||||
import com.rzyc.controller.BaseController;
|
||||
import com.rzyc.enums.*;
|
||||
import com.rzyc.model.*;
|
||||
|
|
@ -21,6 +20,7 @@ import com.rzyc.model.dto.*;
|
|||
import com.rzyc.model.ent.*;
|
||||
import com.rzyc.model.dto.SparePartDto;
|
||||
|
||||
import com.rzyc.redis.RedisUtil;
|
||||
import com.rzyc.utils.easyexcel.EntEnterpriseListener;
|
||||
import com.rzyc.utils.easyexcel.InListListener;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
|
|
|
|||
|
|
@ -1,13 +1,12 @@
|
|||
package com.rzyc.advice.log;
|
||||
|
||||
import cn.hutool.extra.spring.SpringUtil;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.common.utils.RandomNumber;
|
||||
import com.common.utils.StringUtils;
|
||||
import com.common.utils.jwt.JwtUtil;
|
||||
import com.common.utils.model.Result;
|
||||
import com.rzyc.advice.exception.AccessException;
|
||||
import com.rzyc.config.RedisUtil;
|
||||
import com.rzyc.redis.RedisUtil;
|
||||
import com.rzyc.mapper.log.SysLogsMapper;
|
||||
import com.rzyc.mapper.user.SysUserMapper;
|
||||
import com.rzyc.model.user.SysUser;
|
||||
|
|
|
|||
|
|
@ -40,10 +40,12 @@ import com.rzyc.model.sys.SysOrg;
|
|||
import com.rzyc.model.sys.SysRole;
|
||||
import com.rzyc.model.user.*;
|
||||
import com.common.utils.copy.ObjectConversion;
|
||||
import com.rzyc.service.ProvinceService;
|
||||
import org.apache.poi.ss.usermodel.*;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.InputStream;
|
||||
import java.text.SimpleDateFormat;
|
||||
|
|
@ -614,6 +616,10 @@ public class BaseController {
|
|||
@Autowired
|
||||
protected ExScoreRecordMapper exScoreRecordMapper;
|
||||
|
||||
//省厅数据对接
|
||||
@Resource
|
||||
protected ProvinceService provinceService;
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package com.rzyc.controller;
|
|||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.common.utils.AMAP.Amap;
|
||||
import com.common.utils.RandomNumber;
|
||||
import com.common.utils.RedisClient;
|
||||
import com.common.utils.StringUtils;
|
||||
import com.common.utils.TypeConversion;
|
||||
import com.common.utils.encryption.PasswdFactory;
|
||||
|
|
@ -741,4 +742,21 @@ public class DataController extends com.rzyc.controller.BaseController {
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 数据测试
|
||||
* @version v1.0
|
||||
* @author dong
|
||||
* @date 2025/3/18 12:30
|
||||
*/
|
||||
@ApiOperation(value = "数据测试", notes = "数据测试")
|
||||
@RequestMapping(value = "/dataTest", method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public SingleResult<String>dataTest()throws Exception{
|
||||
SingleResult<String> result = new SingleResult<>();
|
||||
|
||||
provinceService.dataTest();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
package com.rzyc.filter;
|
||||
|
||||
import com.rzyc.config.RedisUtil;
|
||||
import com.rzyc.redis.RedisUtil;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.web.context.support.WebApplicationContextUtils;
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import com.common.utils.model.SingleResult;
|
|||
import com.rzyc.pager.PageOperation;
|
||||
import com.github.pagehelper.Page;
|
||||
import com.rzyc.bean.RiskSource.RiskSourceStatistic;
|
||||
import com.rzyc.config.RedisUtil;
|
||||
import com.rzyc.redis.RedisUtil;
|
||||
import com.rzyc.controller.BaseController;
|
||||
import com.rzyc.model.*;
|
||||
import com.rzyc.model.EasyExcel.EasyExcelPostList;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user