From cf7a09fdfb98e41039e08af1ff5e9dacfbecfc03 Mon Sep 17 00:00:00 2001
From: ‘liusuyi’ <1951119284@qq.com>
Date: 星期三, 23 八月 2023 17:13:31 +0800
Subject: [PATCH] 新增配置工具类 迁移配置信息实体类到common包
---
ruoyi-common/src/main/java/com/ruoyi/common/utils/ConfigUtils.java | 55 ++++++++++++++++++
ard-work/src/main/java/com/ruoyi/storage/minio/utils/MinioConfig.java | 52 ++---------------
ard-work/src/main/java/com/ruoyi/test/ReadAccessDatabase.java | 11 +++
ard-work/src/main/java/com/ruoyi/storage/minio/utils/MinioUtils.java | 3
ruoyi-common/src/main/java/com/ruoyi/common/core/redis/RedisCache.java | 22 +++++--
ard-work/src/main/java/com/ruoyi/sy/controller/ArdSyCarController.java | 2
ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysConfigController.java | 2
ruoyi-system/src/main/java/com/ruoyi/system/service/ISysConfigService.java | 2
ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysConfigMapper.java | 2
ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysConfig.java | 2
ard-work/src/main/java/com/ruoyi/device/camera/service/impl/ArdCamerasServiceImpl.java | 7 --
ard-work/src/main/java/com/ruoyi/sy/service/impl/ArdSyCarServiceImpl.java | 5 -
ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java | 3
13 files changed, 97 insertions(+), 71 deletions(-)
diff --git a/ard-work/src/main/java/com/ruoyi/device/camera/service/impl/ArdCamerasServiceImpl.java b/ard-work/src/main/java/com/ruoyi/device/camera/service/impl/ArdCamerasServiceImpl.java
index af4c67b..245b74e 100644
--- a/ard-work/src/main/java/com/ruoyi/device/camera/service/impl/ArdCamerasServiceImpl.java
+++ b/ard-work/src/main/java/com/ruoyi/device/camera/service/impl/ArdCamerasServiceImpl.java
@@ -1,7 +1,5 @@
package com.ruoyi.device.camera.service.impl;
-import java.awt.geom.Point2D;
-import java.time.LocalTime;
import java.util.*;
import java.util.stream.Collectors;
@@ -14,11 +12,7 @@
import com.ruoyi.device.camera.domain.CameraCmd;
import com.ruoyi.device.channel.domain.ArdChannel;
import com.ruoyi.device.channel.mapper.ArdChannelMapper;
-import com.ruoyi.device.channel.service.IArdChannelService;
-import com.ruoyi.device.hiksdk.common.GlobalVariable;
-import com.ruoyi.device.hiksdk.service.IHikClientService;
import com.ruoyi.scheduling.domian.SchedulingParam;
-import com.ruoyi.system.domain.SysConfig;
import com.ruoyi.utils.tools.ArdTool;
import com.ruoyi.device.camera.domain.ArdCameras;
import com.ruoyi.device.camera.mapper.ArdCamerasMapper;
@@ -27,7 +21,6 @@
import com.ruoyi.system.mapper.SysDeptMapper;
import com.ruoyi.utils.tools.GisTool;
import com.ruoyi.utils.tools.Point;
-import com.sun.org.apache.bcel.internal.generic.NEW;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
diff --git a/ard-work/src/main/java/com/ruoyi/storage/minio/utils/MinioConfig.java b/ard-work/src/main/java/com/ruoyi/storage/minio/utils/MinioConfig.java
index 2a3989f..28b2235 100644
--- a/ard-work/src/main/java/com/ruoyi/storage/minio/utils/MinioConfig.java
+++ b/ard-work/src/main/java/com/ruoyi/storage/minio/utils/MinioConfig.java
@@ -1,5 +1,6 @@
package com.ruoyi.storage.minio.utils;
+import io.minio.MinioClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
@@ -16,60 +17,19 @@
@Component
public class MinioConfig {
@Value("${minio.endpoint}")
- private String endpoint;
+ private String endpoint;
@Value("${minio.accessKey}")
- private String accessKey;
+ private String accessKey;
@Value("${minio.secretKey}")
- private String secretKey;
-
-// private volatile static MinioClient minioClient;
+ private String secretKey;
@Bean
- public io.minio.MinioClient getMinioClient() {
- return io.minio.MinioClient.builder()
+ public MinioClient getMinioClient() {
+ return MinioClient.builder()
.endpoint(endpoint)
.credentials(accessKey, secretKey)
.build();
}
-
-// /**
-// * 鑾峰彇minio瀹㈡埛绔疄渚�
-// *
-// * @return {@link MinioClient}
-// */
-// public static MinioClient getMinioClient() {
-// if (minioClient == null) {
-// synchronized (MinioClientSingleton.class) {
-// if (minioClient == null) {
-// minioClient = MinioClient.builder()
-// .endpoint(endpoint)
-// .credentials(accessKey, secretKey)
-// .build();
-// }
-// }
-// }
-// return minioClient;
-// }
- // static {
-// domainUrl = getYmlNew("minio.endpoint");
-// accessKey = getYmlNew("minio.accessKey");
-// secretKey = getYmlNew("minio.secretKey");
-// log.debug("minio淇℃伅锛�" + domainUrl + "(" + accessKey + "/" + secretKey + ")");
-// }
- /*yml閰嶇疆淇℃伅鑾峰彇*/
-// public static String getYmlNew(String key) {
-// Resource resource = new ClassPathResource("application-prod.yml");
-// Properties properties = null;
-// try {
-// YamlPropertiesFactoryBean yamlFactory = new YamlPropertiesFactoryBean();
-// yamlFactory.setResources(resource);
-// properties = yamlFactory.getObject();
-// } catch (Exception e) {
-// e.printStackTrace();
-// return null;
-// }
-// return properties.get(key).toString();
-// }
}
diff --git a/ard-work/src/main/java/com/ruoyi/storage/minio/utils/MinioUtils.java b/ard-work/src/main/java/com/ruoyi/storage/minio/utils/MinioUtils.java
index ff3e870..7cbcec6 100644
--- a/ard-work/src/main/java/com/ruoyi/storage/minio/utils/MinioUtils.java
+++ b/ard-work/src/main/java/com/ruoyi/storage/minio/utils/MinioUtils.java
@@ -355,6 +355,7 @@
/**
* 鑾峰彇鍗曚釜妗朵腑鐨勬墍鏈夋枃浠跺璞″悕绉�
+ *
* @param [bucket,prefix]
* @return {@link List}<{@link String}>
*/
@@ -571,7 +572,7 @@
/**
* @鎻忚堪 鑾峰彇妗朵腑鎵�鏈夊璞�
- * @鍙傛暟 [bucketName,prefix]
+ * @鍙傛暟 [bucketName, prefix]
* @杩斿洖鍊� java.lang.Iterable<io.minio.Result < io.minio.messages.Item>>
* @鍒涘缓浜� 鍒樿嫃涔�
* @鍒涘缓鏃堕棿 2023/2/6 10:32
diff --git a/ard-work/src/main/java/com/ruoyi/sy/controller/ArdSyCarController.java b/ard-work/src/main/java/com/ruoyi/sy/controller/ArdSyCarController.java
index 3ecae28..ad6a795 100644
--- a/ard-work/src/main/java/com/ruoyi/sy/controller/ArdSyCarController.java
+++ b/ard-work/src/main/java/com/ruoyi/sy/controller/ArdSyCarController.java
@@ -13,7 +13,7 @@
import com.ruoyi.sy.gps31.PushClientImplAlarm;
import com.ruoyi.sy.gps31.PushClientImplPosition;
import com.ruoyi.sy.service.IArdSyUserService;
-import com.ruoyi.system.domain.SysConfig;
+import com.ruoyi.common.core.domain.entity.SysConfig;
import com.ruoyi.system.service.ISysConfigService;
import com.ruoyi.system.service.ISysDeptService;
import com.ruoyi.system.service.ISysUserService;
diff --git a/ard-work/src/main/java/com/ruoyi/sy/service/impl/ArdSyCarServiceImpl.java b/ard-work/src/main/java/com/ruoyi/sy/service/impl/ArdSyCarServiceImpl.java
index 83789ea..788a2b2 100644
--- a/ard-work/src/main/java/com/ruoyi/sy/service/impl/ArdSyCarServiceImpl.java
+++ b/ard-work/src/main/java/com/ruoyi/sy/service/impl/ArdSyCarServiceImpl.java
@@ -23,19 +23,16 @@
import com.ruoyi.sy.mapper.ArdSyCarDayMapper;
import com.ruoyi.utils.tools.GisTool;
import com.ruoyi.utils.websocket.util.WebSocketUtils;
-import com.ruoyi.storage.minio.utils.MinioConfig;
import com.ruoyi.storage.minio.utils.MinioUtils;
import com.ruoyi.sy.domain.ArdSyUser;
import com.ruoyi.sy.gps31.PositionContainer;
import com.ruoyi.sy.mapper.ArdSyUserMapper;
-import com.ruoyi.system.domain.SysConfig;
+import com.ruoyi.common.core.domain.entity.SysConfig;
import com.ruoyi.system.mapper.SysConfigMapper;
import com.ruoyi.system.mapper.SysUserMapper;
import com.ruoyi.utils.forest.SYClient;
import com.ruoyi.utils.result.Results;
import io.minio.GetPresignedObjectUrlArgs;
-import io.minio.ListObjectsArgs;
-import io.minio.PutObjectArgs;
import io.minio.Result;
import io.minio.http.Method;
import io.minio.messages.Item;
diff --git a/ard-work/src/main/java/com/ruoyi/test/ReadAccessDatabase.java b/ard-work/src/main/java/com/ruoyi/test/ReadAccessDatabase.java
index 7c1e365..2d48af9 100644
--- a/ard-work/src/main/java/com/ruoyi/test/ReadAccessDatabase.java
+++ b/ard-work/src/main/java/com/ruoyi/test/ReadAccessDatabase.java
@@ -8,9 +8,20 @@
* @Version: 1.0
**/
+import com.ruoyi.common.utils.ConfigUtils;
+import com.ruoyi.common.utils.DictUtils;
import lombok.extern.slf4j.Slf4j;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.PostConstruct;
import java.sql.*;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
@Slf4j
+@Component
public class ReadAccessDatabase {
public static void main(String[] args) {
diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysConfigController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysConfigController.java
index 588480f..78f0cac 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysConfigController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/system/SysConfigController.java
@@ -23,7 +23,7 @@
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
-import com.ruoyi.system.domain.SysConfig;
+import com.ruoyi.common.core.domain.entity.SysConfig;
import com.ruoyi.system.service.ISysConfigService;
/**
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysConfig.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysConfig.java
similarity index 98%
rename from ruoyi-system/src/main/java/com/ruoyi/system/domain/SysConfig.java
rename to ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysConfig.java
index c54678c..79e16ab 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/domain/SysConfig.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/domain/entity/SysConfig.java
@@ -1,4 +1,4 @@
-package com.ruoyi.system.domain;
+package com.ruoyi.common.core.domain.entity;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.Size;
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/redis/RedisCache.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/redis/RedisCache.java
index 1098fd8..e035b3c 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/core/redis/RedisCache.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/redis/RedisCache.java
@@ -1,10 +1,6 @@
package com.ruoyi.common.core.redis;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
import java.util.concurrent.TimeUnit;
import org.springframework.beans.factory.annotation.Autowired;
@@ -249,8 +245,22 @@
* 鏍规嵁鍓嶇紑鑾峰彇鎵�鏈夌殑key* 渚嬪锛歱ro_
*/
public List<Object> getListKey(String prefix) {
- Set<Object> keys = redisTemplate.keys(prefix+"*");
+ Set<Object> keys = redisTemplate.keys(prefix + "*");
List<Object> values = redisTemplate.opsForValue().multiGet(keys);
return values;
}
+
+ /**
+ * 鏍规嵁鍓嶇紑鑾峰彇鎵�鏈夌殑key* 渚嬪锛歱ro_
+ */
+ public HashMap<String, Object> getMapKey(String prefix) {
+ HashMap<String, Object> map = new HashMap<>();
+ Set<String> keys = redisTemplate.keys(prefix + "*");
+ for (String key : keys) {
+ Object value = redisTemplate.opsForValue().get(key);
+ String nKey = key.replace(prefix, "");
+ map.put(nKey, value);
+ }
+ return map;
+ }
}
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/ConfigUtils.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/ConfigUtils.java
new file mode 100644
index 0000000..1df7a75
--- /dev/null
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/ConfigUtils.java
@@ -0,0 +1,55 @@
+package com.ruoyi.common.utils;
+
+import com.ruoyi.common.constant.CacheConstants;
+import com.ruoyi.common.core.redis.RedisCache;
+import com.ruoyi.common.utils.spring.SpringUtils;
+
+import java.util.Map;
+
+
+/**
+ * @Description: 閰嶇疆宸ュ叿绫�
+ * @ClassName: ConfigUtils
+ * @Author: 鍒樿嫃涔�
+ * @Date: 2023骞�08鏈�23鏃�16:12:09
+ * @Version: 1.0
+ **/
+public class ConfigUtils {
+ /**
+ * 鏍规嵁閰嶇疆key鑾峰彇閰嶇疆value鍊�
+ *
+ * @param key 閰嶇疆key
+ * @return configValue 閰嶇疆value鍊�
+ */
+ public static String getConfigValue(String key) {
+ String configValue = SpringUtils.getBean(RedisCache.class).getCacheObject(getCacheKey(key));
+ if (StringUtils.isNotNull(configValue)) {
+ return configValue;
+ }
+ return null;
+ }
+
+ /**
+ * 鑾峰彇鎵�鏈夐厤缃俊鎭�
+ *
+ * @return configMap 閰嶇疆淇℃伅map
+ */
+ public static Map<String, Object> getConfigMap() {
+ Map<String, Object> configMap = SpringUtils.getBean(RedisCache.class).getMapKey(CacheConstants.SYS_CONFIG_KEY);
+ if (StringUtils.isNotNull(configMap)) {
+ return configMap;
+ }
+ return null;
+ }
+
+ /**
+ * 璁剧疆cache key
+ *
+ * @param configKey 鍙傛暟閿�
+ * @return 缂撳瓨閿甼ey
+ */
+ public static String getCacheKey(String configKey) {
+ return CacheConstants.SYS_CONFIG_KEY + configKey;
+ }
+
+}
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysConfigMapper.java b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysConfigMapper.java
index 6bf1ca5..6918853 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysConfigMapper.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/mapper/SysConfigMapper.java
@@ -1,7 +1,7 @@
package com.ruoyi.system.mapper;
import java.util.List;
-import com.ruoyi.system.domain.SysConfig;
+import com.ruoyi.common.core.domain.entity.SysConfig;
/**
* 鍙傛暟閰嶇疆 鏁版嵁灞�
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysConfigService.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysConfigService.java
index 50cdf83..6aebca6 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysConfigService.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/ISysConfigService.java
@@ -1,7 +1,7 @@
package com.ruoyi.system.service;
import java.util.List;
-import com.ruoyi.system.domain.SysConfig;
+import com.ruoyi.common.core.domain.entity.SysConfig;
/**
* 鍙傛暟閰嶇疆 鏈嶅姟灞�
diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java
index dd79ede..3a42b75 100644
--- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java
+++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/SysConfigServiceImpl.java
@@ -5,7 +5,6 @@
import javax.annotation.PostConstruct;
import javax.annotation.Resource;
-import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.common.annotation.DataSource;
import com.ruoyi.common.constant.CacheConstants;
@@ -15,7 +14,7 @@
import com.ruoyi.common.enums.DataSourceType;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
-import com.ruoyi.system.domain.SysConfig;
+import com.ruoyi.common.core.domain.entity.SysConfig;
import com.ruoyi.system.mapper.SysConfigMapper;
import com.ruoyi.system.service.ISysConfigService;
--
Gitblit v1.9.3