Commit e45666a8f2ebc327463ab85eb01bc10569398d75

Authored by guzijian
1 parent c9e95116

feat: 修改配置文件

Bsth-admin/src/main/java/com/ruoyi/common/SchedulerProperty.java 0 → 100644
  1 +package com.ruoyi.common;
  2 +
  3 +import lombok.Data;
  4 +
  5 +@Data
  6 +public class SchedulerProperty {
  7 + private String getSchedulingInfoUrl;
  8 + private String nonce;
  9 + private String password;
  10 +}
Bsth-admin/src/main/java/com/ruoyi/common/cache/SchedulingCache.java
1 package com.ruoyi.common.cache; 1 package com.ruoyi.common.cache;
2 2
  3 +import com.ruoyi.common.SchedulerProperty;
3 import com.ruoyi.pojo.response.ResponseSchedulingDto; 4 import com.ruoyi.pojo.response.ResponseSchedulingDto;
4 import com.ruoyi.utils.ConstDateUtil; 5 import com.ruoyi.utils.ConstDateUtil;
5 import org.slf4j.Logger; 6 import org.slf4j.Logger;
@@ -24,49 +25,42 @@ import static com.ruoyi.common.redispre.GlobalRedisPreName.DRIVER_SCHEDULING_PRE @@ -24,49 +25,42 @@ import static com.ruoyi.common.redispre.GlobalRedisPreName.DRIVER_SCHEDULING_PRE
24 @Component 25 @Component
25 public class SchedulingCache { 26 public class SchedulingCache {
26 27
27 - Logger log = LoggerFactory.getLogger(SchedulingCache.class); 28 + private static final Logger log = LoggerFactory.getLogger(SchedulingCache.class);
28 29
29 30
30 - // @Value("${api.url.getSchedulingInfoNew}")  
31 - private static final String getSchedulingInfoUrl = "http://192.168.50.120:9089/webservice/rest/schedule_real/sch_jk_db/%s/%s?timestamp=%d&nonce=%s&password=%s&sign=%s";  
32 - // @Value("${api.config.nonce}")  
33 - private static final String NONCE = "adfsad";  
34 - // @Value("${api.config.password}")  
35 - private static final String PASSWORD = "c4dd3d8cb9a82f6d6a625818618b28ca7bebb464";  
36 -  
37 /** 31 /**
38 * 实时更新排班 32 * 实时更新排班
39 */ 33 */
40 - private static ConcurrentHashMap<String, Map<String, List<ResponseSchedulingDto>>> cacheScheduling = new ConcurrentHashMap<>(); 34 + private static final ConcurrentHashMap<String, Map<String, List<ResponseSchedulingDto>>> CONCURRENT_HASH_MAP = new ConcurrentHashMap<>();
41 35
42 36
43 - public SchedulingCache() { 37 + public SchedulingCache(SchedulerProperty property) {
44 log.info("项目启动加载中获取实时班次并存入缓存-----"); 38 log.info("项目启动加载中获取实时班次并存入缓存-----");
45 - schedulingInit(); 39 + schedulingInit(property);
46 } 40 }
47 41
48 42
49 /** 43 /**
50 * 初始化排班数据 并存入缓存 44 * 初始化排班数据 并存入缓存
51 */ 45 */
52 - private void schedulingInit() { 46 + private void schedulingInit(SchedulerProperty property) {
53 String formatNowDate = ConstDateUtil.formatDate(new Date()); 47 String formatNowDate = ConstDateUtil.formatDate(new Date());
54 - String url = getUrl(formatNowDate); 48 + String url = getUrl(formatNowDate, property);
55 log.info("初始化排班数据:{}", formatNowDate); 49 log.info("初始化排班数据:{}", formatNowDate);
56 saveSchedulingToCache(url, formatNowDate); 50 saveSchedulingToCache(url, formatNowDate);
57 String formatYesterdayDate = ConstDateUtil.formatDate(ConstDateUtil.getTheSpecifiedNumberOfDaysOfTime(-1)); 51 String formatYesterdayDate = ConstDateUtil.formatDate(ConstDateUtil.getTheSpecifiedNumberOfDaysOfTime(-1));
58 log.info("初始化排班数据:{}", formatYesterdayDate); 52 log.info("初始化排班数据:{}", formatYesterdayDate);
59 - url = getUrl(formatYesterdayDate); 53 + url = getUrl(formatYesterdayDate, property);
60 saveSchedulingToCache(url, formatYesterdayDate); 54 saveSchedulingToCache(url, formatYesterdayDate);
61 } 55 }
62 56
63 - private String getUrl(String formatNowDate) { 57 + private String getUrl(String formatNowDate, SchedulerProperty property) {
64 String url = null; 58 String url = null;
65 long timestamp = System.currentTimeMillis(); 59 long timestamp = System.currentTimeMillis();
66 // String formatDate = ConstDateUtil.formatDate(ConstDateUtil.getTheSpecifiedNumberOfDaysOfTime(-1)); 60 // String formatDate = ConstDateUtil.formatDate(ConstDateUtil.getTheSpecifiedNumberOfDaysOfTime(-1));
67 // 获取排班请求 61 // 获取排班请求
68 try { 62 try {
69 - url = String.format(getSchedulingInfoUrl, "99", formatNowDate, timestamp, NONCE, PASSWORD, getSHA1(getStringStringMap(String.valueOf(timestamp)))); 63 + url = String.format(property.getGetSchedulingInfoUrl(), "99", formatNowDate, timestamp, property.getNonce(), property.getPassword(), getSHA1(getStringStringMap(String.valueOf(timestamp), property)));
70 } catch (Exception e) { 64 } catch (Exception e) {
71 throw new RuntimeException(e); 65 throw new RuntimeException(e);
72 } 66 }
@@ -164,32 +158,32 @@ public class SchedulingCache { @@ -164,32 +158,32 @@ public class SchedulingCache {
164 } 158 }
165 } 159 }
166 160
167 - private Map<String, String> getStringStringMap(String timestamp) { 161 + private Map<String, String> getStringStringMap(String timestamp, SchedulerProperty property) {
168 Map<String, String> configMap = new HashMap<>(5); 162 Map<String, String> configMap = new HashMap<>(5);
169 configMap.put("timestamp", String.valueOf(timestamp)); 163 configMap.put("timestamp", String.valueOf(timestamp));
170 - configMap.put("nonce", NONCE);  
171 - configMap.put("password", PASSWORD); 164 + configMap.put("nonce", property.getNonce());
  165 + configMap.put("password", property.getPassword());
172 return configMap; 166 return configMap;
173 } 167 }
174 168
175 public void setCacheScheduling(String key, Map<String, List<ResponseSchedulingDto>> mapValue) { 169 public void setCacheScheduling(String key, Map<String, List<ResponseSchedulingDto>> mapValue) {
176 - cacheScheduling.put(key, mapValue); 170 + CONCURRENT_HASH_MAP.put(key, mapValue);
177 } 171 }
178 172
179 public void removeCacheSchedulingByKey(String key) { 173 public void removeCacheSchedulingByKey(String key) {
180 - cacheScheduling.remove(key); 174 + CONCURRENT_HASH_MAP.remove(key);
181 } 175 }
182 176
183 public List<String> getKeys() { 177 public List<String> getKeys() {
184 - return new ArrayList<>(cacheScheduling.keySet()); 178 + return new ArrayList<>(CONCURRENT_HASH_MAP.keySet());
185 } 179 }
186 180
187 public Integer size() { 181 public Integer size() {
188 - return cacheScheduling.size(); 182 + return CONCURRENT_HASH_MAP.size();
189 } 183 }
190 184
191 public List<ResponseSchedulingDto> getCacheSchedulingMapValueByHKey(String key, String HKey) { 185 public List<ResponseSchedulingDto> getCacheSchedulingMapValueByHKey(String key, String HKey) {
192 - Map<String, List<ResponseSchedulingDto>> map = cacheScheduling.get(key); 186 + Map<String, List<ResponseSchedulingDto>> map = CONCURRENT_HASH_MAP.get(key);
193 if (Objects.isNull(map)) { 187 if (Objects.isNull(map)) {
194 return null; 188 return null;
195 } 189 }
@@ -199,7 +193,7 @@ public class SchedulingCache { @@ -199,7 +193,7 @@ public class SchedulingCache {
199 } 193 }
200 194
201 public List<String> getHKeysByKey(String key) { 195 public List<String> getHKeysByKey(String key) {
202 - return new ArrayList<>(cacheScheduling.get(key).keySet()); 196 + return new ArrayList<>(CONCURRENT_HASH_MAP.get(key).keySet());
203 } 197 }
204 198
205 } 199 }
Bsth-admin/src/main/java/com/ruoyi/common/cache/TempCache.java
@@ -11,7 +11,7 @@ public class TempCache { @@ -11,7 +11,7 @@ public class TempCache {
11 map = new ConcurrentHashMap<>(); 11 map = new ConcurrentHashMap<>();
12 // map.put("620001", true); 12 // map.put("620001", true);
13 // map.put("620002", true); 13 // map.put("620002", true);
14 - map.put("700001", true); 14 +// map.put("700001", true);
15 map.put("722717", true); 15 map.put("722717", true);
16 } 16 }
17 17
@@ -42,7 +42,7 @@ public class TempCache { @@ -42,7 +42,7 @@ public class TempCache {
42 public static void resetMapStatus() { 42 public static void resetMapStatus() {
43 map.put("620001", true); 43 map.put("620001", true);
44 map.put("620002", true); 44 map.put("620002", true);
45 - map.put("700001", true); 45 +// map.put("700001", true);
46 map.put("722717", true); 46 map.put("722717", true);
47 } 47 }
48 } 48 }
Bsth-admin/src/main/java/com/ruoyi/config/SchedulerConfig.java 0 → 100644
  1 +package com.ruoyi.config;
  2 +
  3 +import com.ruoyi.common.SchedulerProperty;
  4 +import org.springframework.beans.factory.annotation.Value;
  5 +import org.springframework.context.annotation.Bean;
  6 +import org.springframework.context.annotation.Configuration;
  7 +
  8 +@Configuration
  9 +public class SchedulerConfig {
  10 + @Value("${api.url.getSchedulingInfoNew}")
  11 + private String getSchedulingInfoUrl;
  12 + @Value("${api.config.nonce}")
  13 + private String nonce;
  14 + @Value("${api.config.password}")
  15 + private String password;
  16 +
  17 + @Bean
  18 + public SchedulerProperty getSchedulerProperty(){
  19 + SchedulerProperty property = new SchedulerProperty();
  20 + property.setPassword(password);
  21 + property.setNonce(nonce);
  22 + property.setGetSchedulingInfoUrl(getSchedulingInfoUrl);
  23 + return property;
  24 + }
  25 +}