diff --git a/utils/src/main/java/com/common/utils/encryption/ENDEUtils.java b/inventory-dao/src/main/java/com/rzyc/provinceUtil/EnedUtils.java similarity index 79% rename from utils/src/main/java/com/common/utils/encryption/ENDEUtils.java rename to inventory-dao/src/main/java/com/rzyc/provinceUtil/EnedUtils.java index bb6eebc..37bbe97 100644 --- a/utils/src/main/java/com/common/utils/encryption/ENDEUtils.java +++ b/inventory-dao/src/main/java/com/rzyc/provinceUtil/EnedUtils.java @@ -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\"}"; //加密请求参数 diff --git a/inventory-dao/src/main/java/com/rzyc/provinceUtil/JsonUtils.java b/inventory-dao/src/main/java/com/rzyc/provinceUtil/JsonUtils.java new file mode 100644 index 0000000..afa6c78 --- /dev/null +++ b/inventory-dao/src/main/java/com/rzyc/provinceUtil/JsonUtils.java @@ -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 fromJson(String json, Class mainClass, Class subClass) { + try { + // 动态构建泛型类型(例如 Result) + Type type = createParametricType(mainClass, subClass); + return objectMapper.readValue(json, new TypeReference() { + @Override + public Type getType() { + return type; + } + }); + } catch (Exception e) { + throw new RuntimeException("JSON 转换失败", e); + } + } + + + + + /** + * 构建 ParameterizedType(例如 Result) + */ + 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> + * @version v1.0 + * @author dong + * @date 2025/3/18 15:44 + */ +/* Type userListType = new TypeToken>() {}.getType(); + Result> result = JsonUtils.fromJsonComplex( + json, + Result.class, + userListType + );*/ + + /** + * json转list + * @version v1.0 + * @author dong + * @date 2025/3/18 15:43 + */ + public static 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() { + @Override + public Type getType() { + return type; + } + }); + } catch (Exception e) { + throw new RuntimeException("JSON 转换失败", e); + } + } + + +} diff --git a/inventory-dao/src/main/java/com/rzyc/provinceUtil/ProvData.java b/inventory-dao/src/main/java/com/rzyc/provinceUtil/ProvData.java new file mode 100644 index 0000000..9673f06 --- /dev/null +++ b/inventory-dao/src/main/java/com/rzyc/provinceUtil/ProvData.java @@ -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 { + + //访问状态 + private String code; + + //返回信息 + private String msg; + + //返回数据 + private T data; + + +} diff --git a/inventory-dao/src/main/java/com/rzyc/provinceUtil/bean/DeptInfo.java b/inventory-dao/src/main/java/com/rzyc/provinceUtil/bean/DeptInfo.java new file mode 100644 index 0000000..b657bfa --- /dev/null +++ b/inventory-dao/src/main/java/com/rzyc/provinceUtil/bean/DeptInfo.java @@ -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 children; + +} diff --git a/inventory-dao/src/main/java/com/rzyc/provinceUtil/bean/TokenData.java b/inventory-dao/src/main/java/com/rzyc/provinceUtil/bean/TokenData.java new file mode 100644 index 0000000..a9fcafd --- /dev/null +++ b/inventory-dao/src/main/java/com/rzyc/provinceUtil/bean/TokenData.java @@ -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; + +} diff --git a/inventory-gov/src/main/java/com/rzyc/config/RedisConfig.java b/inventory-dao/src/main/java/com/rzyc/redis/RedisConfig.java similarity index 98% rename from inventory-gov/src/main/java/com/rzyc/config/RedisConfig.java rename to inventory-dao/src/main/java/com/rzyc/redis/RedisConfig.java index 754ea74..de8249c 100644 --- a/inventory-gov/src/main/java/com/rzyc/config/RedisConfig.java +++ b/inventory-dao/src/main/java/com/rzyc/redis/RedisConfig.java @@ -1,4 +1,4 @@ -package com.rzyc.config; +package com.rzyc.redis; import org.springframework.context.annotation.Bean; diff --git a/inventory-gov/src/main/java/com/rzyc/config/RedisUtil.java b/inventory-dao/src/main/java/com/rzyc/redis/RedisUtil.java similarity index 99% rename from inventory-gov/src/main/java/com/rzyc/config/RedisUtil.java rename to inventory-dao/src/main/java/com/rzyc/redis/RedisUtil.java index 5ee26c9..a8b8b0f 100644 --- a/inventory-gov/src/main/java/com/rzyc/config/RedisUtil.java +++ b/inventory-dao/src/main/java/com/rzyc/redis/RedisUtil.java @@ -1,4 +1,4 @@ -package com.rzyc.config; +package com.rzyc.redis; import org.springframework.beans.factory.annotation.Autowired; diff --git a/inventory-dao/src/main/java/com/rzyc/service/BaseService.java b/inventory-dao/src/main/java/com/rzyc/service/BaseService.java index 706e0dc..e257f70 100644 --- a/inventory-dao/src/main/java/com/rzyc/service/BaseService.java +++ b/inventory-dao/src/main/java/com/rzyc/service/BaseService.java @@ -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; + } diff --git a/inventory-dao/src/main/java/com/rzyc/service/ProvinceService.java b/inventory-dao/src/main/java/com/rzyc/service/ProvinceService.java index b293420..ae9e78a 100644 --- a/inventory-dao/src/main/java/com/rzyc/service/ProvinceService.java +++ b/inventory-dao/src/main/java/com/rzyc/service/ProvinceService.java @@ -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 params = new HashMap<>(); + params.put("sysUniqueCode",SYS_UNIQUE_CODE); + //加密请求参数 + String responseStr = EnedUtils.doPost(BASE_URL+GET_TOKEN_URL,JSONObject.toJSONString(params),""); + ProvData 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 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>() {}.getType(); + ProvData> 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(); + } } diff --git a/inventory-ent/src/main/java/com/rzyc/config/RedisConfig.java b/inventory-ent/src/main/java/com/rzyc/config/RedisConfig.java deleted file mode 100644 index 4dfc9ed..0000000 --- a/inventory-ent/src/main/java/com/rzyc/config/RedisConfig.java +++ /dev/null @@ -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 strRedisTemplate(RedisConnectionFactory redisConnectionFactory){ - RedisTemplate 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; - } - - - - -} diff --git a/inventory-ent/src/main/java/com/rzyc/config/RedisUtil.java b/inventory-ent/src/main/java/com/rzyc/config/RedisUtil.java deleted file mode 100644 index 1858b1a..0000000 --- a/inventory-ent/src/main/java/com/rzyc/config/RedisUtil.java +++ /dev/null @@ -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 redisTemplate; - - @Autowired - public RedisUtil(RedisTemplate 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 hmget(String key) { - return redisTemplate.opsForHash().entries(key); - } - - /** - * HashSet - * @param key 键 - * @param map 对应多个键值 - */ - public boolean hmset(String key, Map 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 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 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 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 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 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; - } - - } - - -} diff --git a/inventory-ent/src/main/java/com/rzyc/controller/EmergencyEquipmentController.java b/inventory-ent/src/main/java/com/rzyc/controller/EmergencyEquipmentController.java index e9fc187..3ab0a19 100644 --- a/inventory-ent/src/main/java/com/rzyc/controller/EmergencyEquipmentController.java +++ b/inventory-ent/src/main/java/com/rzyc/controller/EmergencyEquipmentController.java @@ -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; diff --git a/inventory-ent/src/main/java/com/rzyc/controller/PersonalController.java b/inventory-ent/src/main/java/com/rzyc/controller/PersonalController.java index 239352f..0d16c3b 100644 --- a/inventory-ent/src/main/java/com/rzyc/controller/PersonalController.java +++ b/inventory-ent/src/main/java/com/rzyc/controller/PersonalController.java @@ -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; diff --git a/inventory-ent/src/main/java/com/rzyc/service/PcBusinessService.java b/inventory-ent/src/main/java/com/rzyc/service/PcBusinessService.java index d5bf52b..012f04a 100644 --- a/inventory-ent/src/main/java/com/rzyc/service/PcBusinessService.java +++ b/inventory-ent/src/main/java/com/rzyc/service/PcBusinessService.java @@ -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; diff --git a/inventory-gov/src/main/java/com/rzyc/advice/log/LogAspect.java b/inventory-gov/src/main/java/com/rzyc/advice/log/LogAspect.java index a55e94b..ec10715 100644 --- a/inventory-gov/src/main/java/com/rzyc/advice/log/LogAspect.java +++ b/inventory-gov/src/main/java/com/rzyc/advice/log/LogAspect.java @@ -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; diff --git a/inventory-gov/src/main/java/com/rzyc/controller/BaseController.java b/inventory-gov/src/main/java/com/rzyc/controller/BaseController.java index 4a84ef1..2552088 100644 --- a/inventory-gov/src/main/java/com/rzyc/controller/BaseController.java +++ b/inventory-gov/src/main/java/com/rzyc/controller/BaseController.java @@ -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; + diff --git a/inventory-gov/src/main/java/com/rzyc/controller/DataController.java b/inventory-gov/src/main/java/com/rzyc/controller/DataController.java index 7db6bee..850e691 100644 --- a/inventory-gov/src/main/java/com/rzyc/controller/DataController.java +++ b/inventory-gov/src/main/java/com/rzyc/controller/DataController.java @@ -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 SingleResultdataTest()throws Exception{ + SingleResult result = new SingleResult<>(); + + provinceService.dataTest(); + + return result; + } + } diff --git a/inventory-gov/src/main/java/com/rzyc/filter/IpFilter.java b/inventory-gov/src/main/java/com/rzyc/filter/IpFilter.java index aac2d69..9457dd2 100644 --- a/inventory-gov/src/main/java/com/rzyc/filter/IpFilter.java +++ b/inventory-gov/src/main/java/com/rzyc/filter/IpFilter.java @@ -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; diff --git a/inventory-gov/src/main/java/com/rzyc/service/PcBusinessService.java b/inventory-gov/src/main/java/com/rzyc/service/PcBusinessService.java index c3511b0..edd0237 100644 --- a/inventory-gov/src/main/java/com/rzyc/service/PcBusinessService.java +++ b/inventory-gov/src/main/java/com/rzyc/service/PcBusinessService.java @@ -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; diff --git a/pom.xml b/pom.xml index eacd770..6cdda4e 100644 --- a/pom.xml +++ b/pom.xml @@ -552,6 +552,15 @@ + + +