Commit 1d26b63cd59969df0f9a0217f82a2fbdc12201d9
1 parent
ee678e33
1.大邑迁移
Showing
12 changed files
with
130 additions
and
129 deletions
src/main/java/com/bsth/Application.java
| 1 | package com.bsth; | 1 | package com.bsth; |
| 2 | 2 | ||
| 3 | -import com.bsth.util.AppProperties; | ||
| 4 | -import org.springframework.beans.factory.annotation.Autowired; | ||
| 5 | -import org.springframework.beans.factory.annotation.Value; | ||
| 6 | -import org.springframework.boot.CommandLineRunner; | ||
| 7 | import org.springframework.boot.SpringApplication; | 3 | import org.springframework.boot.SpringApplication; |
| 8 | import org.springframework.boot.autoconfigure.SpringBootApplication; | 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; |
| 9 | import org.springframework.boot.builder.SpringApplicationBuilder; | 5 | import org.springframework.boot.builder.SpringApplicationBuilder; |
| 10 | import org.springframework.boot.web.support.SpringBootServletInitializer; | 6 | import org.springframework.boot.web.support.SpringBootServletInitializer; |
| 11 | -import org.springframework.core.env.ConfigurableEnvironment; | ||
| 12 | 7 | ||
| 13 | -import java.io.IOException; | ||
| 14 | -import java.io.InputStream; | ||
| 15 | import java.lang.management.ManagementFactory; | 8 | import java.lang.management.ManagementFactory; |
| 16 | import java.lang.management.RuntimeMXBean; | 9 | import java.lang.management.RuntimeMXBean; |
| 17 | import java.util.List; | 10 | import java.util.List; |
| 18 | -import java.util.Properties; | ||
| 19 | import java.util.concurrent.Executors; | 11 | import java.util.concurrent.Executors; |
| 20 | import java.util.concurrent.ScheduledExecutorService; | 12 | import java.util.concurrent.ScheduledExecutorService; |
| 21 | 13 | ||
| @@ -41,29 +33,7 @@ public class Application extends SpringBootServletInitializer { | @@ -41,29 +33,7 @@ public class Application extends SpringBootServletInitializer { | ||
| 41 | } | 33 | } |
| 42 | 34 | ||
| 43 | if (normal) { | 35 | if (normal) { |
| 44 | - loadProperties(); | ||
| 45 | SpringApplication.run(Application.class, args); | 36 | SpringApplication.run(Application.class, args); |
| 46 | } | 37 | } |
| 47 | } | 38 | } |
| 48 | - | ||
| 49 | - private static void loadProperties() { | ||
| 50 | - Properties prop = new Properties(); | ||
| 51 | - try (InputStream input = Application.class.getClassLoader().getResourceAsStream("application.properties")) { | ||
| 52 | - prop.load(input); | ||
| 53 | - String activeProfile = prop.getProperty("spring.profiles.active", ""); | ||
| 54 | - String cacheDays = prop.getProperty("cache.days", "15"); | ||
| 55 | - InputStream input1 = Application.class.getClassLoader().getResourceAsStream(String.format("application-%s.properties", activeProfile)); | ||
| 56 | - prop.load(input1); | ||
| 57 | - String controlUrl = prop.getProperty("http.control.service_data_url", ""); | ||
| 58 | - String secretKey = prop.getProperty("http.control.secret.key", ""); | ||
| 59 | - String gpsUrl = prop.getProperty("http.gps.real.url", ""); | ||
| 60 | - | ||
| 61 | - AppProperties.setCacheDays(Integer.parseInt(cacheDays)); | ||
| 62 | - AppProperties.setControlUrl(controlUrl); | ||
| 63 | - AppProperties.setSecretKey(secretKey); | ||
| 64 | - AppProperties.setGpsUrl(gpsUrl); | ||
| 65 | - } catch (IOException e) { | ||
| 66 | - throw new RuntimeException(e); | ||
| 67 | - } | ||
| 68 | - } | ||
| 69 | } | 39 | } |
| 70 | \ No newline at end of file | 40 | \ No newline at end of file |
src/main/java/com/bsth/redis/ElecRedisService.java
| @@ -38,6 +38,9 @@ public class ElecRedisService implements CommandLineRunner { | @@ -38,6 +38,9 @@ public class ElecRedisService implements CommandLineRunner { | ||
| 38 | @Autowired | 38 | @Autowired |
| 39 | RedisUtils redisUtils; | 39 | RedisUtils redisUtils; |
| 40 | 40 | ||
| 41 | + @Autowired | ||
| 42 | + private AppProperties appProperties; | ||
| 43 | + | ||
| 41 | static Logger logger = LoggerFactory.getLogger(ElecRedisService.class); | 44 | static Logger logger = LoggerFactory.getLogger(ElecRedisService.class); |
| 42 | 45 | ||
| 43 | private final static String REDIS_KEY_PREFIX = "elec:"; | 46 | private final static String REDIS_KEY_PREFIX = "elec:"; |
| @@ -156,7 +159,7 @@ public class ElecRedisService implements CommandLineRunner { | @@ -156,7 +159,7 @@ public class ElecRedisService implements CommandLineRunner { | ||
| 156 | * 和数据库同步数据 | 159 | * 和数据库同步数据 |
| 157 | */ | 160 | */ |
| 158 | public void synchData(Integer days) { | 161 | public void synchData(Integer days) { |
| 159 | - int cacheDays = AppProperties.getCacheDays(); | 162 | + int cacheDays = appProperties.getCacheDays(); |
| 160 | if (null != days && days < cacheDays) | 163 | if (null != days && days < cacheDays) |
| 161 | cacheDays = days; | 164 | cacheDays = days; |
| 162 | //设置key 序列化器 | 165 | //设置key 序列化器 |
src/main/java/com/bsth/redis/OilRedisService.java
| @@ -38,6 +38,9 @@ public class OilRedisService implements CommandLineRunner { | @@ -38,6 +38,9 @@ public class OilRedisService implements CommandLineRunner { | ||
| 38 | @Autowired | 38 | @Autowired |
| 39 | RedisUtils redisUtils; | 39 | RedisUtils redisUtils; |
| 40 | 40 | ||
| 41 | + @Autowired | ||
| 42 | + private AppProperties appProperties; | ||
| 43 | + | ||
| 41 | static Logger logger = LoggerFactory.getLogger(OilRedisService.class); | 44 | static Logger logger = LoggerFactory.getLogger(OilRedisService.class); |
| 42 | 45 | ||
| 43 | private final static String REDIS_KEY_PREFIX = "oil:"; | 46 | private final static String REDIS_KEY_PREFIX = "oil:"; |
| @@ -189,7 +192,7 @@ public class OilRedisService implements CommandLineRunner { | @@ -189,7 +192,7 @@ public class OilRedisService implements CommandLineRunner { | ||
| 189 | * 和数据库同步数据 | 192 | * 和数据库同步数据 |
| 190 | */ | 193 | */ |
| 191 | public void synchData(Integer days) { | 194 | public void synchData(Integer days) { |
| 192 | - int cacheDays = AppProperties.getCacheDays(); | 195 | + int cacheDays = appProperties.getCacheDays(); |
| 193 | if (null != days && days < cacheDays) | 196 | if (null != days && days < cacheDays) |
| 194 | cacheDays = days; | 197 | cacheDays = days; |
| 195 | //设置key 序列化器 | 198 | //设置key 序列化器 |
src/main/java/com/bsth/redis/PlanScheduleRedisService.java
| @@ -44,6 +44,9 @@ public class PlanScheduleRedisService implements CommandLineRunner { | @@ -44,6 +44,9 @@ public class PlanScheduleRedisService implements CommandLineRunner { | ||
| 44 | @Autowired | 44 | @Autowired |
| 45 | RedisUtils redisUtils; | 45 | RedisUtils redisUtils; |
| 46 | 46 | ||
| 47 | + @Autowired | ||
| 48 | + private AppProperties appProperties; | ||
| 49 | + | ||
| 47 | static Logger logger = LoggerFactory.getLogger(PlanScheduleRedisService.class); | 50 | static Logger logger = LoggerFactory.getLogger(PlanScheduleRedisService.class); |
| 48 | 51 | ||
| 49 | private final static String REDIS_KEY_PREFIX = "plan:"; | 52 | private final static String REDIS_KEY_PREFIX = "plan:"; |
| @@ -126,7 +129,7 @@ public class PlanScheduleRedisService implements CommandLineRunner { | @@ -126,7 +129,7 @@ public class PlanScheduleRedisService implements CommandLineRunner { | ||
| 126 | Application.mainServices.schedule(new Runnable() { | 129 | Application.mainServices.schedule(new Runnable() { |
| 127 | @Override | 130 | @Override |
| 128 | public void run() { | 131 | public void run() { |
| 129 | - int cacheDays = AppProperties.getCacheDays(); | 132 | + int cacheDays = appProperties.getCacheDays(); |
| 130 | //设置key 序列化器 | 133 | //设置key 序列化器 |
| 131 | redisTemplate.setKeySerializer(new StringRedisSerializer()); | 134 | redisTemplate.setKeySerializer(new StringRedisSerializer()); |
| 132 | 135 | ||
| @@ -163,12 +166,15 @@ public class PlanScheduleRedisService implements CommandLineRunner { | @@ -163,12 +166,15 @@ public class PlanScheduleRedisService implements CommandLineRunner { | ||
| 163 | @Autowired | 166 | @Autowired |
| 164 | SchedulePlanInfoRepository planInfoRepository; | 167 | SchedulePlanInfoRepository planInfoRepository; |
| 165 | 168 | ||
| 169 | + @Autowired | ||
| 170 | + private AppProperties appProperties; | ||
| 171 | + | ||
| 166 | @Override | 172 | @Override |
| 167 | public void run() { | 173 | public void run() { |
| 168 | try { | 174 | try { |
| 169 | logger.info("redis -清理计划排班"); | 175 | logger.info("redis -清理计划排班"); |
| 170 | 176 | ||
| 171 | - int cacheDays = AppProperties.getCacheDays(); | 177 | + int cacheDays = appProperties.getCacheDays(); |
| 172 | DateTime dt = new DateTime(); | 178 | DateTime dt = new DateTime(); |
| 173 | dt = dt.minusDays(cacheDays); | 179 | dt = dt.minusDays(cacheDays); |
| 174 | String rq = dt.toString("yyyy-MM-dd"); | 180 | String rq = dt.toString("yyyy-MM-dd"); |
src/main/java/com/bsth/redis/ScheduleRedisService.java
| @@ -210,6 +210,9 @@ public class ScheduleRedisService implements CommandLineRunner { | @@ -210,6 +210,9 @@ public class ScheduleRedisService implements CommandLineRunner { | ||
| 210 | @Autowired | 210 | @Autowired |
| 211 | ScheduleClearThread scheduleClearThread; | 211 | ScheduleClearThread scheduleClearThread; |
| 212 | 212 | ||
| 213 | + @Autowired | ||
| 214 | + private AppProperties appProperties; | ||
| 215 | + | ||
| 213 | @Override | 216 | @Override |
| 214 | public void run(String... strings) throws Exception { | 217 | public void run(String... strings) throws Exception { |
| 215 | //用子线程去加载,,不要阻塞 | 218 | //用子线程去加载,,不要阻塞 |
| @@ -218,7 +221,7 @@ public class ScheduleRedisService implements CommandLineRunner { | @@ -218,7 +221,7 @@ public class ScheduleRedisService implements CommandLineRunner { | ||
| 218 | public void run() { | 221 | public void run() { |
| 219 | try { | 222 | try { |
| 220 | logger.info("redis 实际排班 start..."); | 223 | logger.info("redis 实际排班 start..."); |
| 221 | - int cacheDays = AppProperties.getCacheDays(); | 224 | + int cacheDays = appProperties.getCacheDays(); |
| 222 | //设置key 序列化器 | 225 | //设置key 序列化器 |
| 223 | redisTemplate.setKeySerializer(new StringRedisSerializer()); | 226 | redisTemplate.setKeySerializer(new StringRedisSerializer()); |
| 224 | 227 | ||
| @@ -287,10 +290,13 @@ public class ScheduleRedisService implements CommandLineRunner { | @@ -287,10 +290,13 @@ public class ScheduleRedisService implements CommandLineRunner { | ||
| 287 | @Autowired | 290 | @Autowired |
| 288 | ScheduleRedisService scheduleRedisService; | 291 | ScheduleRedisService scheduleRedisService; |
| 289 | 292 | ||
| 293 | + @Autowired | ||
| 294 | + private AppProperties appProperties; | ||
| 295 | + | ||
| 290 | @Override | 296 | @Override |
| 291 | public void run() { | 297 | public void run() { |
| 292 | try { | 298 | try { |
| 293 | - int cacheDays = AppProperties.getCacheDays(); | 299 | + int cacheDays = appProperties.getCacheDays(); |
| 294 | DateTime dt = new DateTime(); | 300 | DateTime dt = new DateTime(); |
| 295 | dt = dt.minusDays(cacheDays); | 301 | dt = dt.minusDays(cacheDays); |
| 296 | String rq = dt.toString("yyyy-MM-dd"); | 302 | String rq = dt.toString("yyyy-MM-dd"); |
src/main/java/com/bsth/server_rs/directive/DirectiveRestService.java
| @@ -6,6 +6,7 @@ import com.bsth.util.AppProperties; | @@ -6,6 +6,7 @@ import com.bsth.util.AppProperties; | ||
| 6 | import com.bsth.util.HttpClientUtils; | 6 | import com.bsth.util.HttpClientUtils; |
| 7 | import org.slf4j.Logger; | 7 | import org.slf4j.Logger; |
| 8 | import org.slf4j.LoggerFactory; | 8 | import org.slf4j.LoggerFactory; |
| 9 | +import org.springframework.beans.factory.InitializingBean; | ||
| 9 | import org.springframework.beans.factory.annotation.Autowired; | 10 | import org.springframework.beans.factory.annotation.Autowired; |
| 10 | import org.springframework.stereotype.Component; | 11 | import org.springframework.stereotype.Component; |
| 11 | import org.springframework.web.bind.annotation.RequestBody; | 12 | import org.springframework.web.bind.annotation.RequestBody; |
| @@ -21,13 +22,17 @@ import java.util.Map; | @@ -21,13 +22,17 @@ import java.util.Map; | ||
| 21 | @Component | 22 | @Component |
| 22 | @Path("/directive") | 23 | @Path("/directive") |
| 23 | @Produces({MediaType.APPLICATION_JSON}) | 24 | @Produces({MediaType.APPLICATION_JSON}) |
| 24 | -public class DirectiveRestService { | 25 | +public class DirectiveRestService implements InitializingBean { |
| 25 | 26 | ||
| 26 | - static String secretKey = AppProperties.getSecretKey(); | ||
| 27 | - static String url = AppProperties.getControlUrl() + "/send60Phrase?secretKey=" + secretKey; | 27 | + private String secretKey; |
| 28 | + private String url; | ||
| 28 | 29 | ||
| 29 | @Autowired | 30 | @Autowired |
| 30 | SchRealDataBuffer schRealDataBuffer; | 31 | SchRealDataBuffer schRealDataBuffer; |
| 32 | + | ||
| 33 | + @Autowired | ||
| 34 | + private AppProperties appProperties; | ||
| 35 | + | ||
| 31 | Logger logger = LoggerFactory.getLogger(this.getClass()); | 36 | Logger logger = LoggerFactory.getLogger(this.getClass()); |
| 32 | 37 | ||
| 33 | @POST | 38 | @POST |
| @@ -54,4 +59,10 @@ public class DirectiveRestService { | @@ -54,4 +59,10 @@ public class DirectiveRestService { | ||
| 54 | return null; | 59 | return null; |
| 55 | } | 60 | } |
| 56 | } | 61 | } |
| 62 | + | ||
| 63 | + @Override | ||
| 64 | + public void afterPropertiesSet() throws Exception { | ||
| 65 | + secretKey = appProperties.getSecretKey(); | ||
| 66 | + url = appProperties.getControlUrl() + "/send60Phrase?secretKey=" + secretKey; | ||
| 67 | + } | ||
| 57 | } | 68 | } |
src/main/java/com/bsth/server_rs/gps/buffer/GpsRefreshThread.java
| @@ -12,6 +12,8 @@ import org.apache.http.impl.client.CloseableHttpClient; | @@ -12,6 +12,8 @@ import org.apache.http.impl.client.CloseableHttpClient; | ||
| 12 | import org.apache.http.impl.client.HttpClients; | 12 | import org.apache.http.impl.client.HttpClients; |
| 13 | import org.slf4j.Logger; | 13 | import org.slf4j.Logger; |
| 14 | import org.slf4j.LoggerFactory; | 14 | import org.slf4j.LoggerFactory; |
| 15 | +import org.springframework.beans.factory.InitializingBean; | ||
| 16 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 15 | import org.springframework.stereotype.Component; | 17 | import org.springframework.stereotype.Component; |
| 16 | 18 | ||
| 17 | import java.io.BufferedReader; | 19 | import java.io.BufferedReader; |
| @@ -22,9 +24,12 @@ import java.util.List; | @@ -22,9 +24,12 @@ import java.util.List; | ||
| 22 | * Created by panzhao on 2017/3/30. | 24 | * Created by panzhao on 2017/3/30. |
| 23 | */ | 25 | */ |
| 24 | @Component | 26 | @Component |
| 25 | -public class GpsRefreshThread extends Thread{ | 27 | +public class GpsRefreshThread extends Thread implements InitializingBean { |
| 26 | 28 | ||
| 27 | - static String url = AppProperties.getGpsUrl(); | 29 | + private String url; |
| 30 | + | ||
| 31 | + @Autowired | ||
| 32 | + private AppProperties appProperties; | ||
| 28 | 33 | ||
| 29 | Logger logger = LoggerFactory.getLogger(this.getClass()); | 34 | Logger logger = LoggerFactory.getLogger(this.getClass()); |
| 30 | 35 | ||
| @@ -63,4 +68,9 @@ public class GpsRefreshThread extends Thread{ | @@ -63,4 +68,9 @@ public class GpsRefreshThread extends Thread{ | ||
| 63 | logger.error("", e); | 68 | logger.error("", e); |
| 64 | } | 69 | } |
| 65 | } | 70 | } |
| 71 | + | ||
| 72 | + @Override | ||
| 73 | + public void afterPropertiesSet() throws Exception { | ||
| 74 | + url = appProperties.getGpsUrl(); | ||
| 75 | + } | ||
| 66 | } | 76 | } |
src/main/java/com/bsth/server_rs/schedule/real/ScheduleRealService.java
| @@ -56,11 +56,14 @@ public class ScheduleRealService implements InitializingBean { | @@ -56,11 +56,14 @@ public class ScheduleRealService implements InitializingBean { | ||
| 56 | @Autowired | 56 | @Autowired |
| 57 | private KafkaTemplate kafkaTemplate; | 57 | private KafkaTemplate kafkaTemplate; |
| 58 | 58 | ||
| 59 | + @Autowired | ||
| 60 | + private AppProperties appProperties; | ||
| 61 | + | ||
| 59 | Logger logger = LoggerFactory.getLogger(this.getClass()); | 62 | Logger logger = LoggerFactory.getLogger(this.getClass()); |
| 60 | 63 | ||
| 61 | - static String url = AppProperties.getControlUrl(); | 64 | + private String url; |
| 62 | 65 | ||
| 63 | - static String secretKey = AppProperties.getSecretKey(); | 66 | + private String secretKey; |
| 64 | 67 | ||
| 65 | private volatile long timestamp; | 68 | private volatile long timestamp; |
| 66 | 69 | ||
| @@ -317,65 +320,7 @@ public class ScheduleRealService implements InitializingBean { | @@ -317,65 +320,7 @@ public class ScheduleRealService implements InitializingBean { | ||
| 317 | 320 | ||
| 318 | @Override | 321 | @Override |
| 319 | public void afterPropertiesSet() throws Exception { | 322 | public void afterPropertiesSet() throws Exception { |
| 320 | - /*Application.mainServices.scheduleWithFixedDelay(new Runnable() { | ||
| 321 | - @Override | ||
| 322 | - public void run() { | ||
| 323 | - try { | ||
| 324 | - DateTime dateTime = DateTime.now(), preDate = dateTime.minusDays(1); | ||
| 325 | - List<String> dates = new ArrayList<>(); | ||
| 326 | - dates.add(dateTime.toString("yyyy-MM-dd")); | ||
| 327 | - dates.add(preDate.toString("yyyy-MM-dd")); | ||
| 328 | - if (timestamp == 0) { | ||
| 329 | - timestamp = dateTime.minusHours(1).getMillis(); | ||
| 330 | - } | ||
| 331 | - List<ScheduleRealInfo> scheduleRealInfos = scheduleRealInfoRepository.findByDates(dates, new Date(timestamp)); | ||
| 332 | - timestamp = dateTime.getMillis(); | ||
| 333 | - | ||
| 334 | - Queue<ScheduleRealInfoVo> queue = new ConcurrentLinkedDeque<>(); | ||
| 335 | - for (ScheduleRealInfo sch : scheduleRealInfos) { | ||
| 336 | - ScheduleRealInfoVo scheduleRealInfoVo = new ScheduleRealInfoVo(); | ||
| 337 | - BeanUtils.copyProperties(sch, scheduleRealInfoVo); | ||
| 338 | - Car car = CarBufferData.findOne(scheduleRealInfoVo.getClZbh()); | ||
| 339 | - scheduleRealInfoVo.setCarPlate(car == null ? "" : car.getCarPlate()); | ||
| 340 | - queue.add(scheduleRealInfoVo); | ||
| 341 | - } | ||
| 342 | - | ||
| 343 | - int size = scheduleRealInfos.size(); | ||
| 344 | - for (int i = 0, len = size % KAFKA_BATCH_SIZE == 0 ? size / KAFKA_BATCH_SIZE : size / KAFKA_BATCH_SIZE + 1;i < len;i++) { | ||
| 345 | - List<ScheduleRealInfoVo> scheduleRealInfoVos = new ArrayList<>(); | ||
| 346 | - for (int j = 0; j < KAFKA_BATCH_SIZE;j++) { | ||
| 347 | - ScheduleRealInfoVo scheduleRealInfoVo = queue.poll(); | ||
| 348 | - if (scheduleRealInfoVo == null) { | ||
| 349 | - break; | ||
| 350 | - } | ||
| 351 | - scheduleRealInfoVos.add(scheduleRealInfoVo); | ||
| 352 | - } | ||
| 353 | - | ||
| 354 | - Map<String, Object> data = new HashMap<>(); | ||
| 355 | - data.put("datatype", "waybill"); | ||
| 356 | - data.put("datas", scheduleRealInfoVos); | ||
| 357 | - | ||
| 358 | - ObjectMapper mapper = new ObjectMapper(); | ||
| 359 | - String json = mapper.writeValueAsString(data); | ||
| 360 | - logger.info(json); | ||
| 361 | - ListenableFuture<SendResult<String, String>> future = kafkaTemplate.send("PDGJ_JQDD", json); | ||
| 362 | - future.addCallback(new ListenableFutureCallback<SendResult<String, String>>() { | ||
| 363 | - | ||
| 364 | - @Override | ||
| 365 | - public void onSuccess(SendResult<String, String> result) { | ||
| 366 | - | ||
| 367 | - } | ||
| 368 | - | ||
| 369 | - @Override | ||
| 370 | - public void onFailure(Throwable ex) { | ||
| 371 | - logger.error("kafka发送电子路单异常", ex); | ||
| 372 | - } | ||
| 373 | - }); | ||
| 374 | - } | ||
| 375 | - } catch (Exception e) { | ||
| 376 | - logger.error("kafka发电子路单调度异常", e); | ||
| 377 | - } | ||
| 378 | - } | ||
| 379 | - }, 30, 240, TimeUnit.SECONDS);*/ | 323 | + url = appProperties.getControlUrl(); |
| 324 | + secretKey = appProperties.getSecretKey(); | ||
| 380 | } | 325 | } |
| 381 | } | 326 | } |
src/main/java/com/bsth/server_rs/schedule/real/thread/ExecSchDataRefreshThread.java
| @@ -7,6 +7,7 @@ import com.bsth.util.AppProperties; | @@ -7,6 +7,7 @@ import com.bsth.util.AppProperties; | ||
| 7 | import com.bsth.util.HttpClientUtils; | 7 | import com.bsth.util.HttpClientUtils; |
| 8 | import org.slf4j.Logger; | 8 | import org.slf4j.Logger; |
| 9 | import org.slf4j.LoggerFactory; | 9 | import org.slf4j.LoggerFactory; |
| 10 | +import org.springframework.beans.factory.InitializingBean; | ||
| 10 | import org.springframework.beans.factory.annotation.Autowired; | 11 | import org.springframework.beans.factory.annotation.Autowired; |
| 11 | import org.springframework.stereotype.Component; | 12 | import org.springframework.stereotype.Component; |
| 12 | 13 | ||
| @@ -19,13 +20,18 @@ import java.util.Map; | @@ -19,13 +20,18 @@ import java.util.Map; | ||
| 19 | * Created by panzhao on 2017/11/9. | 20 | * Created by panzhao on 2017/11/9. |
| 20 | */ | 21 | */ |
| 21 | @Component | 22 | @Component |
| 22 | -public class ExecSchDataRefreshThread extends Thread{ | 23 | +public class ExecSchDataRefreshThread extends Thread implements InitializingBean { |
| 23 | 24 | ||
| 24 | - static String secretKey = AppProperties.getSecretKey(); | ||
| 25 | - static String url = AppProperties.getControlUrl() + "/execSchList?secretKey=" + secretKey; | 25 | + private String secretKey; |
| 26 | + | ||
| 27 | + private String url; | ||
| 26 | 28 | ||
| 27 | @Autowired | 29 | @Autowired |
| 28 | SchRealDataBuffer schRealDataBuffer; | 30 | SchRealDataBuffer schRealDataBuffer; |
| 31 | + | ||
| 32 | + @Autowired | ||
| 33 | + private AppProperties appProperties; | ||
| 34 | + | ||
| 29 | Logger logger = LoggerFactory.getLogger(this.getClass()); | 35 | Logger logger = LoggerFactory.getLogger(this.getClass()); |
| 30 | 36 | ||
| 31 | @Override | 37 | @Override |
| @@ -45,4 +51,10 @@ public class ExecSchDataRefreshThread extends Thread{ | @@ -45,4 +51,10 @@ public class ExecSchDataRefreshThread extends Thread{ | ||
| 45 | logger.error("", e); | 51 | logger.error("", e); |
| 46 | } | 52 | } |
| 47 | } | 53 | } |
| 54 | + | ||
| 55 | + @Override | ||
| 56 | + public void afterPropertiesSet() throws Exception { | ||
| 57 | + secretKey = appProperties.getSecretKey(); | ||
| 58 | + url = appProperties.getControlUrl() + "/execSchList?secretKey=" + secretKey; | ||
| 59 | + } | ||
| 48 | } | 60 | } |
src/main/java/com/bsth/server_rs/schedule/real/thread/SchInOutDataRefreshThread.java
| @@ -7,6 +7,7 @@ import com.bsth.util.AppProperties; | @@ -7,6 +7,7 @@ import com.bsth.util.AppProperties; | ||
| 7 | import com.bsth.util.HttpClientUtils; | 7 | import com.bsth.util.HttpClientUtils; |
| 8 | import org.slf4j.Logger; | 8 | import org.slf4j.Logger; |
| 9 | import org.slf4j.LoggerFactory; | 9 | import org.slf4j.LoggerFactory; |
| 10 | +import org.springframework.beans.factory.InitializingBean; | ||
| 10 | import org.springframework.beans.factory.annotation.Autowired; | 11 | import org.springframework.beans.factory.annotation.Autowired; |
| 11 | import org.springframework.stereotype.Component; | 12 | import org.springframework.stereotype.Component; |
| 12 | 13 | ||
| @@ -17,13 +18,17 @@ import java.util.List; | @@ -17,13 +18,17 @@ import java.util.List; | ||
| 17 | * Created by panzhao on 2017/9/27. | 18 | * Created by panzhao on 2017/9/27. |
| 18 | */ | 19 | */ |
| 19 | @Component | 20 | @Component |
| 20 | -public class SchInOutDataRefreshThread extends Thread { | 21 | +public class SchInOutDataRefreshThread extends Thread implements InitializingBean { |
| 21 | 22 | ||
| 22 | - static String secretKey = AppProperties.getSecretKey(); | ||
| 23 | - static String url = AppProperties.getControlUrl() + "/findCurrInAndOut?secretKey=" + secretKey; | 23 | + private String secretKey; |
| 24 | + private String url; | ||
| 24 | 25 | ||
| 25 | @Autowired | 26 | @Autowired |
| 26 | SchRealDataBuffer schRealDataBuffer; | 27 | SchRealDataBuffer schRealDataBuffer; |
| 28 | + | ||
| 29 | + @Autowired | ||
| 30 | + private AppProperties appProperties; | ||
| 31 | + | ||
| 27 | Logger logger = LoggerFactory.getLogger(this.getClass()); | 32 | Logger logger = LoggerFactory.getLogger(this.getClass()); |
| 28 | 33 | ||
| 29 | @Override | 34 | @Override |
| @@ -40,4 +45,10 @@ public class SchInOutDataRefreshThread extends Thread { | @@ -40,4 +45,10 @@ public class SchInOutDataRefreshThread extends Thread { | ||
| 40 | logger.error("", e); | 45 | logger.error("", e); |
| 41 | } | 46 | } |
| 42 | } | 47 | } |
| 48 | + | ||
| 49 | + @Override | ||
| 50 | + public void afterPropertiesSet() throws Exception { | ||
| 51 | + secretKey = appProperties.getSecretKey(); | ||
| 52 | + url = appProperties.getControlUrl() + "/findCurrInAndOut?secretKey=" + secretKey; | ||
| 53 | + } | ||
| 43 | } | 54 | } |
src/main/java/com/bsth/server_ws/util/ControlHttpUtils.java
| @@ -11,20 +11,28 @@ import org.apache.http.impl.client.HttpClients; | @@ -11,20 +11,28 @@ import org.apache.http.impl.client.HttpClients; | ||
| 11 | import org.apache.http.util.EntityUtils; | 11 | import org.apache.http.util.EntityUtils; |
| 12 | import org.slf4j.Logger; | 12 | import org.slf4j.Logger; |
| 13 | import org.slf4j.LoggerFactory; | 13 | import org.slf4j.LoggerFactory; |
| 14 | +import org.springframework.beans.factory.InitializingBean; | ||
| 15 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 16 | +import org.springframework.stereotype.Component; | ||
| 14 | 17 | ||
| 15 | import java.io.IOException; | 18 | import java.io.IOException; |
| 19 | +import java.util.ArrayList; | ||
| 16 | import java.util.List; | 20 | import java.util.List; |
| 17 | 21 | ||
| 18 | /** | 22 | /** |
| 19 | * Created by panzhao on 2017/3/15. | 23 | * Created by panzhao on 2017/3/15. |
| 20 | */ | 24 | */ |
| 21 | -public class ControlHttpUtils { | 25 | +@Component |
| 26 | +public class ControlHttpUtils implements InitializingBean { | ||
| 22 | 27 | ||
| 23 | - static Logger logger = LoggerFactory.getLogger(ControlHttpUtils.class); | 28 | + private static Logger logger = LoggerFactory.getLogger(ControlHttpUtils.class); |
| 24 | 29 | ||
| 25 | - static String url = AppProperties.getControlUrl(); | 30 | + private static String url; |
| 26 | 31 | ||
| 27 | - static String secretKey = AppProperties.getSecretKey(); | 32 | + private static String secretKey; |
| 33 | + | ||
| 34 | + @Autowired | ||
| 35 | + private AppProperties appProperties; | ||
| 28 | 36 | ||
| 29 | /** | 37 | /** |
| 30 | * 从调度系统获取班次信息 | 38 | * 从调度系统获取班次信息 |
| @@ -32,6 +40,9 @@ public class ControlHttpUtils { | @@ -32,6 +40,9 @@ public class ControlHttpUtils { | ||
| 32 | * @return | 40 | * @return |
| 33 | */ | 41 | */ |
| 34 | public static List<ScheduleRealInfo> getCurrentDayPlan(String companyId, String workId) throws IOException { | 42 | public static List<ScheduleRealInfo> getCurrentDayPlan(String companyId, String workId) throws IOException { |
| 43 | + if (secretKey == null || url == null) { | ||
| 44 | + return new ArrayList<>(); | ||
| 45 | + } | ||
| 35 | 46 | ||
| 36 | CloseableHttpClient httpClient = null; | 47 | CloseableHttpClient httpClient = null; |
| 37 | List<ScheduleRealInfo> rs = null; | 48 | List<ScheduleRealInfo> rs = null; |
| @@ -57,6 +68,9 @@ public class ControlHttpUtils { | @@ -57,6 +68,9 @@ public class ControlHttpUtils { | ||
| 57 | * @return | 68 | * @return |
| 58 | */ | 69 | */ |
| 59 | public static List<ScheduleRealInfo> returnJCCInfo(String companyId, String jcOrCc) throws IOException{ | 70 | public static List<ScheduleRealInfo> returnJCCInfo(String companyId, String jcOrCc) throws IOException{ |
| 71 | + if (secretKey == null || url == null) { | ||
| 72 | + return new ArrayList<>(); | ||
| 73 | + } | ||
| 60 | 74 | ||
| 61 | String method = jcOrCc.equals("out")?"/returnCCInfo":"/returnJCInfo"; | 75 | String method = jcOrCc.equals("out")?"/returnCCInfo":"/returnJCInfo"; |
| 62 | 76 | ||
| @@ -76,4 +90,10 @@ public class ControlHttpUtils { | @@ -76,4 +90,10 @@ public class ControlHttpUtils { | ||
| 76 | rs = JSONArray.parseArray(EntityUtils.toString(response.getEntity()), ScheduleRealInfo.class); | 90 | rs = JSONArray.parseArray(EntityUtils.toString(response.getEntity()), ScheduleRealInfo.class); |
| 77 | return rs; | 91 | return rs; |
| 78 | } | 92 | } |
| 93 | + | ||
| 94 | + @Override | ||
| 95 | + public void afterPropertiesSet() throws Exception { | ||
| 96 | + url = appProperties.getControlUrl(); | ||
| 97 | + secretKey = appProperties.getSecretKey(); | ||
| 98 | + } | ||
| 79 | } | 99 | } |
src/main/java/com/bsth/util/AppProperties.java
| @@ -9,43 +9,47 @@ import org.springframework.stereotype.Component; | @@ -9,43 +9,47 @@ import org.springframework.stereotype.Component; | ||
| 9 | @Component | 9 | @Component |
| 10 | public class AppProperties { | 10 | public class AppProperties { |
| 11 | 11 | ||
| 12 | - private static int cacheDays; | 12 | + private int cacheDays; |
| 13 | 13 | ||
| 14 | - private static String controlUrl; | 14 | + private String controlUrl; |
| 15 | 15 | ||
| 16 | - private static String secretKey; | 16 | + private String secretKey; |
| 17 | 17 | ||
| 18 | - private static String gpsUrl; | 18 | + private String gpsUrl; |
| 19 | 19 | ||
| 20 | - public static int getCacheDays() { | 20 | + public int getCacheDays() { |
| 21 | return cacheDays; | 21 | return cacheDays; |
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | - public static void setCacheDays(int cacheDays) { | ||
| 25 | - AppProperties.cacheDays = cacheDays; | 24 | + @Value("${cache.days}") |
| 25 | + public void setCacheDays(int cacheDays) { | ||
| 26 | + this.cacheDays = cacheDays; | ||
| 26 | } | 27 | } |
| 27 | 28 | ||
| 28 | - public static String getControlUrl() { | 29 | + public String getControlUrl() { |
| 29 | return controlUrl; | 30 | return controlUrl; |
| 30 | } | 31 | } |
| 31 | 32 | ||
| 32 | - public static void setControlUrl(String controlUrl) { | ||
| 33 | - AppProperties.controlUrl = controlUrl; | 33 | + @Value("${http.control.service_data_url}") |
| 34 | + public void setControlUrl(String controlUrl) { | ||
| 35 | + this.controlUrl = controlUrl; | ||
| 34 | } | 36 | } |
| 35 | 37 | ||
| 36 | - public static String getSecretKey() { | 38 | + public String getSecretKey() { |
| 37 | return secretKey; | 39 | return secretKey; |
| 38 | } | 40 | } |
| 39 | 41 | ||
| 40 | - public static void setSecretKey(String secretKey) { | ||
| 41 | - AppProperties.secretKey = secretKey; | 42 | + @Value("${http.control.secret.key}") |
| 43 | + public void setSecretKey(String secretKey) { | ||
| 44 | + this.secretKey = secretKey; | ||
| 42 | } | 45 | } |
| 43 | 46 | ||
| 44 | - public static String getGpsUrl() { | 47 | + public String getGpsUrl() { |
| 45 | return gpsUrl; | 48 | return gpsUrl; |
| 46 | } | 49 | } |
| 47 | 50 | ||
| 48 | - public static void setGpsUrl(String gpsUrl) { | ||
| 49 | - AppProperties.gpsUrl = gpsUrl; | 51 | + @Value("${http.gps.real.url}") |
| 52 | + public void setGpsUrl(String gpsUrl) { | ||
| 53 | + this.gpsUrl = gpsUrl; | ||
| 50 | } | 54 | } |
| 51 | } | 55 | } |