Commit a4bf89a2ba588a4c91294623e863faebb72f6c42

Authored by 王通
1 parent c6475169

1.encrypt

1 -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
2 - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  
3 -  
4 - <modelVersion>4.0.0</modelVersion>  
5 - <groupId>com.bsth</groupId>  
6 - <artifactId>control_service_data_interface</artifactId>  
7 - <version>0.0.1-SNAPSHOT</version>  
8 - <packaging>jar</packaging>  
9 -  
10 - <parent>  
11 - <groupId>org.springframework.boot</groupId>  
12 - <artifactId>spring-boot-starter-parent</artifactId>  
13 - <version>1.5.2.RELEASE</version>  
14 - </parent>  
15 -  
16 - <dependencies>  
17 - <dependency>  
18 - <groupId>org.apache.cxf</groupId>  
19 - <artifactId>cxf-rt-frontend-jaxws</artifactId>  
20 - <version>3.1.10</version>  
21 - </dependency>  
22 -  
23 - <dependency>  
24 - <groupId>org.apache.cxf</groupId>  
25 - <artifactId>cxf-rt-transports-http</artifactId>  
26 - <version>3.1.10</version>  
27 - </dependency>  
28 -  
29 - <dependency>  
30 - <groupId>org.apache.cxf</groupId>  
31 - <artifactId>cxf-rt-rs-service-description</artifactId>  
32 - <version>3.1.10</version>  
33 - </dependency>  
34 -  
35 - <dependency>  
36 - <groupId>org.springframework.boot</groupId>  
37 - <artifactId>spring-boot-starter-web</artifactId>  
38 - </dependency>  
39 -  
40 - <dependency>  
41 - <groupId>org.springframework.boot</groupId>  
42 - <artifactId>spring-boot-starter-tomcat</artifactId>  
43 - <scope>provided</scope>  
44 - </dependency>  
45 -  
46 - <dependency>  
47 - <groupId>org.springframework.boot</groupId>  
48 - <artifactId>spring-boot-starter-data-jpa</artifactId>  
49 - </dependency>  
50 - <dependency>  
51 - <groupId>org.springframework.boot</groupId>  
52 - <artifactId>spring-boot-starter-aop</artifactId>  
53 - </dependency>  
54 -  
55 - <dependency>  
56 - <groupId>org.springframework.boot</groupId>  
57 - <artifactId>spring-boot-starter-data-redis</artifactId>  
58 - </dependency>  
59 -  
60 - <dependency>  
61 - <groupId>org.springframework</groupId>  
62 - <artifactId>spring-context-support</artifactId>  
63 - </dependency>  
64 - <dependency>  
65 - <groupId>mysql</groupId>  
66 - <artifactId>mysql-connector-java</artifactId>  
67 - </dependency>  
68 -  
69 - <dependency>  
70 - <groupId>joda-time</groupId>  
71 - <artifactId>joda-time</artifactId>  
72 - </dependency>  
73 - <dependency>  
74 - <groupId>com.alibaba</groupId>  
75 - <artifactId>fastjson</artifactId>  
76 - <version>1.2.4</version>  
77 - </dependency>  
78 -  
79 - <dependency>  
80 - <groupId>org.apache.httpcomponents</groupId>  
81 - <artifactId>httpclient</artifactId>  
82 - </dependency>  
83 -  
84 - <dependency>  
85 - <groupId>commons-dbcp</groupId>  
86 - <artifactId>commons-dbcp</artifactId>  
87 - </dependency>  
88 - <dependency>  
89 - <groupId>commons-lang</groupId>  
90 - <artifactId>commons-lang</artifactId>  
91 - <version>2.6</version>  
92 - </dependency>  
93 - <dependency>  
94 - <groupId>org.apache.commons</groupId>  
95 - <artifactId>commons-lang3</artifactId>  
96 - <version>3.4</version>  
97 - </dependency>  
98 - <dependency>  
99 - <groupId>commons-fileupload</groupId>  
100 - <artifactId>commons-fileupload</artifactId>  
101 - <version>1.2.2</version>  
102 - </dependency>  
103 - <dependency>  
104 - <groupId>commons-io</groupId>  
105 - <artifactId>commons-io</artifactId>  
106 - <version>2.4</version>  
107 - </dependency>  
108 - <dependency>  
109 - <groupId>org.codehaus.janino</groupId>  
110 - <artifactId>janino</artifactId>  
111 - </dependency>  
112 -  
113 - <dependency>  
114 - <groupId>org.apache.poi</groupId>  
115 - <artifactId>poi</artifactId>  
116 - <version>3.13</version>  
117 - </dependency>  
118 -  
119 - <dependency>  
120 - <groupId>com.google.guava</groupId>  
121 - <artifactId>guava</artifactId>  
122 - <version>19.0</version>  
123 - </dependency>  
124 -  
125 - <dependency>  
126 - <groupId>c3p0</groupId>  
127 - <artifactId>c3p0</artifactId>  
128 - <version>0.9.1.2</version>  
129 - </dependency>  
130 -  
131 - <dependency>  
132 - <groupId>axis</groupId>  
133 - <artifactId>axis</artifactId>  
134 - <version>1.4</version>  
135 - </dependency>  
136 -  
137 - <dependency>  
138 - <groupId>com.fasterxml.jackson.jaxrs</groupId>  
139 - <artifactId>jackson-jaxrs-json-provider</artifactId>  
140 - <version>2.8.7</version>  
141 - </dependency>  
142 -  
143 - <dependency>  
144 - <groupId>org.eclipse.jetty</groupId>  
145 - <artifactId>jetty-util</artifactId>  
146 - <version>8.1.15.v20140411</version>  
147 - </dependency>  
148 -  
149 - <dependency>  
150 - <groupId>org.apache.geronimo.specs</groupId>  
151 - <artifactId>geronimo-jaxws_2.2_spec</artifactId>  
152 - <version>1.0</version>  
153 - </dependency>  
154 -  
155 - <dependency>  
156 - <groupId>org.springframework.kafka</groupId>  
157 - <artifactId>spring-kafka</artifactId>  
158 - </dependency>  
159 - </dependencies>  
160 -  
161 - <build>  
162 - <plugins>  
163 - <plugin>  
164 - <artifactId>maven-compiler-plugin</artifactId>  
165 - <version>2.3.2</version><!--$NO-MVN-MAN-VER$ -->  
166 - <configuration>  
167 - <source>1.7</source>  
168 - <target>1.7</target>  
169 - </configuration>  
170 - </plugin>  
171 - <plugin>  
172 - <artifactId>maven-war-plugin</artifactId>  
173 - <version>2.2</version><!--$NO-MVN-MAN-VER$ -->  
174 - <configuration>  
175 - <failOnMissingWebXml>false</failOnMissingWebXml>  
176 - </configuration>  
177 - </plugin>  
178 - <plugin>  
179 - <groupId>org.springframework.boot</groupId>  
180 - <artifactId>spring-boot-maven-plugin</artifactId>  
181 - </plugin>  
182 - </plugins>  
183 - <resources>  
184 - <resource>  
185 - <directory>src/main/resources</directory>  
186 - <filtering>false</filtering>  
187 - </resource>  
188 - </resources>  
189 - </build>  
190 - <repositories>  
191 - <repository>  
192 - <id>spring-snapshots</id>  
193 - <url>http://repo.spring.io/snapshot</url>  
194 - <snapshots>  
195 - <enabled>true</enabled>  
196 - </snapshots>  
197 - </repository>  
198 - <repository>  
199 - <id>spring-milestones</id>  
200 - <url>http://repo.spring.io/milestone</url>  
201 - </repository>  
202 - </repositories>  
203 - <pluginRepositories>  
204 - <pluginRepository>  
205 - <id>spring-snapshots</id>  
206 - <url>http://repo.spring.io/snapshot</url>  
207 - </pluginRepository>  
208 - <pluginRepository>  
209 - <id>spring-milestones</id>  
210 - <url>http://repo.spring.io/milestone</url>  
211 - </pluginRepository>  
212 - </pluginRepositories>  
213 -  
214 - <properties>  
215 - <start-class>com.bsth.Application</start-class>  
216 - </properties>  
217 -</project> 1 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  2 + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  3 +
  4 + <modelVersion>4.0.0</modelVersion>
  5 + <groupId>com.bsth</groupId>
  6 + <artifactId>control_service_data_interface</artifactId>
  7 + <version>0.0.1-SNAPSHOT</version>
  8 + <packaging>jar</packaging>
  9 +
  10 + <parent>
  11 + <groupId>org.springframework.boot</groupId>
  12 + <artifactId>spring-boot-starter-parent</artifactId>
  13 + <version>1.5.2.RELEASE</version>
  14 + </parent>
  15 +
  16 + <dependencies>
  17 + <dependency>
  18 + <groupId>org.apache.cxf</groupId>
  19 + <artifactId>cxf-rt-frontend-jaxws</artifactId>
  20 + <version>3.1.10</version>
  21 + </dependency>
  22 +
  23 + <dependency>
  24 + <groupId>org.apache.cxf</groupId>
  25 + <artifactId>cxf-rt-transports-http</artifactId>
  26 + <version>3.1.10</version>
  27 + </dependency>
  28 +
  29 + <dependency>
  30 + <groupId>org.apache.cxf</groupId>
  31 + <artifactId>cxf-rt-rs-service-description</artifactId>
  32 + <version>3.1.10</version>
  33 + </dependency>
  34 +
  35 + <dependency>
  36 + <groupId>org.springframework.boot</groupId>
  37 + <artifactId>spring-boot-starter-web</artifactId>
  38 + </dependency>
  39 +
  40 + <dependency>
  41 + <groupId>org.springframework.boot</groupId>
  42 + <artifactId>spring-boot-starter-tomcat</artifactId>
  43 + <scope>provided</scope>
  44 + </dependency>
  45 +
  46 + <dependency>
  47 + <groupId>org.springframework.boot</groupId>
  48 + <artifactId>spring-boot-starter-data-jpa</artifactId>
  49 + </dependency>
  50 + <dependency>
  51 + <groupId>org.springframework.boot</groupId>
  52 + <artifactId>spring-boot-starter-aop</artifactId>
  53 + </dependency>
  54 +
  55 + <dependency>
  56 + <groupId>org.springframework.boot</groupId>
  57 + <artifactId>spring-boot-starter-data-redis</artifactId>
  58 + </dependency>
  59 +
  60 + <dependency>
  61 + <groupId>org.springframework</groupId>
  62 + <artifactId>spring-context-support</artifactId>
  63 + </dependency>
  64 + <dependency>
  65 + <groupId>mysql</groupId>
  66 + <artifactId>mysql-connector-java</artifactId>
  67 + </dependency>
  68 +
  69 + <dependency>
  70 + <groupId>joda-time</groupId>
  71 + <artifactId>joda-time</artifactId>
  72 + </dependency>
  73 + <dependency>
  74 + <groupId>com.alibaba</groupId>
  75 + <artifactId>fastjson</artifactId>
  76 + <version>1.2.4</version>
  77 + </dependency>
  78 +
  79 + <dependency>
  80 + <groupId>org.apache.httpcomponents</groupId>
  81 + <artifactId>httpclient</artifactId>
  82 + </dependency>
  83 +
  84 + <dependency>
  85 + <groupId>commons-dbcp</groupId>
  86 + <artifactId>commons-dbcp</artifactId>
  87 + </dependency>
  88 + <dependency>
  89 + <groupId>commons-lang</groupId>
  90 + <artifactId>commons-lang</artifactId>
  91 + <version>2.6</version>
  92 + </dependency>
  93 + <dependency>
  94 + <groupId>org.apache.commons</groupId>
  95 + <artifactId>commons-lang3</artifactId>
  96 + <version>3.4</version>
  97 + </dependency>
  98 + <dependency>
  99 + <groupId>commons-fileupload</groupId>
  100 + <artifactId>commons-fileupload</artifactId>
  101 + <version>1.2.2</version>
  102 + </dependency>
  103 + <dependency>
  104 + <groupId>commons-io</groupId>
  105 + <artifactId>commons-io</artifactId>
  106 + <version>2.4</version>
  107 + </dependency>
  108 + <dependency>
  109 + <groupId>org.codehaus.janino</groupId>
  110 + <artifactId>janino</artifactId>
  111 + </dependency>
  112 +
  113 + <dependency>
  114 + <groupId>org.apache.poi</groupId>
  115 + <artifactId>poi</artifactId>
  116 + <version>3.13</version>
  117 + </dependency>
  118 +
  119 + <dependency>
  120 + <groupId>com.google.guava</groupId>
  121 + <artifactId>guava</artifactId>
  122 + <version>19.0</version>
  123 + </dependency>
  124 +
  125 + <dependency>
  126 + <groupId>c3p0</groupId>
  127 + <artifactId>c3p0</artifactId>
  128 + <version>0.9.1.2</version>
  129 + </dependency>
  130 +
  131 + <dependency>
  132 + <groupId>axis</groupId>
  133 + <artifactId>axis</artifactId>
  134 + <version>1.4</version>
  135 + </dependency>
  136 +
  137 + <dependency>
  138 + <groupId>com.fasterxml.jackson.jaxrs</groupId>
  139 + <artifactId>jackson-jaxrs-json-provider</artifactId>
  140 + <version>2.8.7</version>
  141 + </dependency>
  142 +
  143 + <dependency>
  144 + <groupId>org.eclipse.jetty</groupId>
  145 + <artifactId>jetty-util</artifactId>
  146 + <version>8.1.15.v20140411</version>
  147 + </dependency>
  148 +
  149 + <dependency>
  150 + <groupId>org.apache.geronimo.specs</groupId>
  151 + <artifactId>geronimo-jaxws_2.2_spec</artifactId>
  152 + <version>1.0</version>
  153 + </dependency>
  154 + </dependencies>
  155 +
  156 + <build>
  157 + <plugins>
  158 + <plugin>
  159 + <artifactId>maven-compiler-plugin</artifactId>
  160 + <version>2.3.2</version><!--$NO-MVN-MAN-VER$ -->
  161 + <configuration>
  162 + <source>1.7</source>
  163 + <target>1.7</target>
  164 + </configuration>
  165 + </plugin>
  166 + <plugin>
  167 + <artifactId>maven-war-plugin</artifactId>
  168 + <version>2.2</version><!--$NO-MVN-MAN-VER$ -->
  169 + <configuration>
  170 + <failOnMissingWebXml>false</failOnMissingWebXml>
  171 + </configuration>
  172 + </plugin>
  173 + <plugin>
  174 + <groupId>org.springframework.boot</groupId>
  175 + <artifactId>spring-boot-maven-plugin</artifactId>
  176 + </plugin>
  177 + <plugin>
  178 + <groupId>net.roseboy</groupId>
  179 + <artifactId>classfinal-maven-plugin</artifactId>
  180 + <version>1.2.1</version>
  181 + <configuration>
  182 + <password>bsth@369147258</password>
  183 + <packages>com.bsth</packages>
  184 + <cfgfiles>*.properties</cfgfiles>
  185 + <excludes>org.spring</excludes>
  186 + <libjars></libjars>
  187 + </configuration>
  188 + <executions>
  189 + <execution>
  190 + <phase>package</phase>
  191 + <goals>
  192 + <goal>classFinal</goal>
  193 + </goals>
  194 + </execution>
  195 + </executions>
  196 + </plugin>
  197 + </plugins>
  198 + <resources>
  199 + <resource>
  200 + <directory>src/main/resources</directory>
  201 + <filtering>false</filtering>
  202 + </resource>
  203 + </resources>
  204 + </build>
  205 + <repositories>
  206 + <repository>
  207 + <id>spring-snapshots</id>
  208 + <url>http://repo.spring.io/snapshot</url>
  209 + <snapshots>
  210 + <enabled>true</enabled>
  211 + </snapshots>
  212 + </repository>
  213 + <repository>
  214 + <id>spring-milestones</id>
  215 + <url>http://repo.spring.io/milestone</url>
  216 + </repository>
  217 + </repositories>
  218 + <pluginRepositories>
  219 + <pluginRepository>
  220 + <id>spring-snapshots</id>
  221 + <url>http://repo.spring.io/snapshot</url>
  222 + </pluginRepository>
  223 + <pluginRepository>
  224 + <id>spring-milestones</id>
  225 + <url>http://repo.spring.io/milestone</url>
  226 + </pluginRepository>
  227 + </pluginRepositories>
  228 +
  229 + <properties>
  230 + <start-class>com.bsth.Application</start-class>
  231 + </properties>
  232 +</project>
src/main/java/com/bsth/Application.java
1 -package com.bsth;  
2 -  
3 -import org.springframework.boot.SpringApplication;  
4 -import org.springframework.boot.autoconfigure.SpringBootApplication;  
5 -import org.springframework.boot.builder.SpringApplicationBuilder;  
6 -import org.springframework.boot.web.support.SpringBootServletInitializer;  
7 -  
8 -import java.util.concurrent.Executors;  
9 -import java.util.concurrent.ScheduledExecutorService;  
10 -  
11 -@SpringBootApplication  
12 -public class Application extends SpringBootServletInitializer {  
13 -  
14 - public static ScheduledExecutorService mainServices = Executors.newScheduledThreadPool(10);  
15 -  
16 - @Override  
17 - protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {  
18 - return application.sources(Application.class);  
19 - }  
20 -  
21 - public static void main(String[] args) throws Exception {  
22 - SpringApplication.run(Application.class, args);  
23 - }  
24 - 1 +package com.bsth;
  2 +
  3 +import com.bsth.util.AppProperties;
  4 +import org.springframework.beans.factory.annotation.Autowired;
  5 +import org.springframework.boot.SpringApplication;
  6 +import org.springframework.boot.autoconfigure.SpringBootApplication;
  7 +import org.springframework.boot.builder.SpringApplicationBuilder;
  8 +import org.springframework.boot.web.support.SpringBootServletInitializer;
  9 +
  10 +import java.util.concurrent.Executors;
  11 +import java.util.concurrent.ScheduledExecutorService;
  12 +
  13 +@SpringBootApplication
  14 +public class Application extends SpringBootServletInitializer {
  15 +
  16 + @Autowired
  17 + private AppProperties appProperties;
  18 +
  19 + public static ScheduledExecutorService mainServices = Executors.newScheduledThreadPool(10);
  20 +
  21 + @Override
  22 + protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
  23 + return application.sources(Application.class);
  24 + }
  25 +
  26 + public static void main(String[] args) throws Exception {
  27 + SpringApplication.run(Application.class, args);
  28 + }
  29 +
25 } 30 }
26 \ No newline at end of file 31 \ No newline at end of file
src/main/java/com/bsth/CXFConfig.java
@@ -14,7 +14,6 @@ import com.bsth.server_rs.bigdata.BigscreenService; @@ -14,7 +14,6 @@ import com.bsth.server_rs.bigdata.BigscreenService;
14 import com.bsth.server_rs.departure.DepartureRestService; 14 import com.bsth.server_rs.departure.DepartureRestService;
15 import com.bsth.server_rs.destroy.DestroyDetailRestService; 15 import com.bsth.server_rs.destroy.DestroyDetailRestService;
16 import com.bsth.server_rs.directive.DirectiveRestService; 16 import com.bsth.server_rs.directive.DirectiveRestService;
17 -import com.bsth.server_rs.dks.DksRestService;  
18 import com.bsth.server_rs.electric.ElectricService; 17 import com.bsth.server_rs.electric.ElectricService;
19 import com.bsth.server_rs.exception.AesExceptionMapper; 18 import com.bsth.server_rs.exception.AesExceptionMapper;
20 import com.bsth.server_rs.gps.GpsRestService; 19 import com.bsth.server_rs.gps.GpsRestService;
@@ -132,8 +131,6 @@ public class CXFConfig { @@ -132,8 +131,6 @@ public class CXFConfig {
132 @Autowired 131 @Autowired
133 private DepartureRestService departureRestService; 132 private DepartureRestService departureRestService;
134 @Autowired 133 @Autowired
135 - private DksRestService dksRestService;  
136 - @Autowired  
137 private XxfbRestService xxfbRestService; 134 private XxfbRestService xxfbRestService;
138 135
139 @Bean 136 @Bean
@@ -162,7 +159,6 @@ public class CXFConfig { @@ -162,7 +159,6 @@ public class CXFConfig {
162 destroyDetailRestService, 159 destroyDetailRestService,
163 carparkRestService, 160 carparkRestService,
164 departureRestService, 161 departureRestService,
165 - dksRestService,  
166 xxfbRestService)); 162 xxfbRestService));
167 endpoint.setProviders(Arrays.asList(new JacksonJsonProvider(), new AesExceptionMapper())); 163 endpoint.setProviders(Arrays.asList(new JacksonJsonProvider(), new AesExceptionMapper()));
168 //endpoint.setFeatures(Arrays.asList(new Swagger2Feature())); 164 //endpoint.setFeatures(Arrays.asList(new Swagger2Feature()));
src/main/java/com/bsth/redis/ElecRedisService.java
1 -package com.bsth.redis;  
2 -  
3 -import com.bsth.Application;  
4 -import com.bsth.entity.ElecInfo;  
5 -import com.bsth.redis.util.RedisUtils;  
6 -import com.bsth.repository.ElecInfoRepository;  
7 -import com.bsth.util.ConfigUtil;  
8 -import com.bsth.util.ConvertUtil;  
9 -import com.google.common.collect.ArrayListMultimap;  
10 -import org.joda.time.DateTime;  
11 -import org.slf4j.Logger;  
12 -import org.slf4j.LoggerFactory;  
13 -import org.springframework.beans.factory.annotation.Autowired;  
14 -import org.springframework.boot.CommandLineRunner;  
15 -import org.springframework.core.annotation.Order;  
16 -import org.springframework.data.redis.core.RedisTemplate;  
17 -import org.springframework.data.redis.serializer.StringRedisSerializer;  
18 -import org.springframework.stereotype.Component;  
19 -import org.springframework.stereotype.Service;  
20 -  
21 -import java.util.*;  
22 -import java.util.concurrent.TimeUnit;  
23 -  
24 -/**  
25 - * 油量数据Redis缓存  
26 - * Created by panzhao on 2017/3/19.  
27 - */  
28 -@Service  
29 -@Order(3)  
30 -public class ElecRedisService implements CommandLineRunner {  
31 -  
32 - @Autowired  
33 - private RedisTemplate redisTemplate;  
34 -  
35 - @Autowired  
36 - ElecInfoRepository elecInfoRepository;  
37 -  
38 - @Autowired  
39 - RedisUtils redisUtils;  
40 -  
41 - static Logger logger = LoggerFactory.getLogger(ElecRedisService.class);  
42 -  
43 - private final static String REDIS_KEY_PREFIX = "elec:";  
44 -  
45 - /**  
46 - * 将油量数据写入redis  
47 - *  
48 - * @param list  
49 - */  
50 - public void wirte(List<ElecInfo> list) {  
51 - ArrayListMultimap<String, ElecInfo> multimap;  
52 - try {  
53 - if (list.size() == 0)  
54 - return;  
55 - //按日期和线路分组数据  
56 - Class clazz = ElecInfo.class;  
57 - multimap = new ConvertUtil().groupMultiList(list, ":", clazz.getDeclaredField("nbbm"), clazz.getDeclaredField("rq"));  
58 -  
59 - //写入redis  
60 - Iterator<String> iterator = multimap.keySet().iterator();  
61 - String key;  
62 - while (iterator.hasNext()) {  
63 - key = iterator.next();  
64 - mergeData(key, multimap.get(key));  
65 - }  
66 - } catch (Exception e) {  
67 - logger.error("", e);  
68 - }  
69 - }  
70 -  
71 - /**  
72 - * 根据车辆和日期获取油耗数据,以 车辆_驾驶员 为key  
73 - *  
74 - * @param nbbmArray  
75 - * @param rq  
76 - * @return  
77 - */  
78 - public ArrayListMultimap findByNbbmGroup(Iterable<String> nbbmArray, String rq) {  
79 - ArrayListMultimap rs = ArrayListMultimap.create();  
80 -  
81 - rq = rq.replaceAll("-", "");  
82 - try {  
83 - List<ElecInfo> list = new ArrayList<>();  
84 - for (String nbbm : nbbmArray) {  
85 - nbbm = nbbm.split("_")[1];  
86 - list.addAll(read(nbbm, rq));  
87 - }  
88 - Class clazz = ElecInfo.class;  
89 - rs = new ConvertUtil().groupMultiList(list, "_", clazz.getDeclaredField("nbbm"), clazz.getDeclaredField("jsy"));  
90 - } catch (Exception e) {  
91 - logger.error("", e);  
92 - }  
93 - return rs;  
94 - }  
95 -  
96 - /**  
97 - * 根据车辆和日期获取油耗数据,以 车辆 为key  
98 - *  
99 - * @param nbbmArray  
100 - * @param rq  
101 - * @return  
102 - */  
103 - public ArrayListMultimap findByNbbmGroup1(Iterable<String> nbbmArray, String rq) {  
104 - ArrayListMultimap rs = ArrayListMultimap.create();  
105 -  
106 - rq = rq.replaceAll("-", "");  
107 - try {  
108 - List<ElecInfo> list = new ArrayList<>();  
109 - for (String nbbm : nbbmArray) {  
110 - list.addAll(read(nbbm, rq));  
111 - }  
112 - Class clazz = ElecInfo.class;  
113 - rs = new ConvertUtil().groupMultiList(list, "_", clazz.getDeclaredField("nbbm"));  
114 - } catch (Exception e) {  
115 - logger.error("", e);  
116 - }  
117 - return rs;  
118 - }  
119 -  
120 - public List<ElecInfo> read(String nbbm, String rq) {  
121 - return redisTemplate.opsForList().range(REDIS_KEY_PREFIX + nbbm + ":" + rq, 0, -1);  
122 - }  
123 -  
124 - /**  
125 - * 将 list 与redis里的数据合并  
126 - *  
127 - * @param key  
128 - * @param list  
129 - */  
130 - public void mergeData(String key, List<ElecInfo> list) {  
131 - key = REDIS_KEY_PREFIX + key;  
132 -  
133 - //更新 直接覆盖更新  
134 - redisTemplate.execute(redisUtils.getUpdateCallback(key, list));  
135 - }  
136 -  
137 - @Autowired  
138 - ElecRefreshThread elecRefreshThread;  
139 -  
140 - @Override  
141 - public void run(String... strings) throws Exception {  
142 - Application.mainServices.schedule(new Runnable() {  
143 - @Override  
144 - public void run() {  
145 - //启动加载油耗缓存  
146 - synchData(null);  
147 - }  
148 - }, 30, TimeUnit.SECONDS);  
149 -  
150 -  
151 - //定时刷新油耗信息  
152 - Application.mainServices.scheduleWithFixedDelay(elecRefreshThread, 60 * 40, 60 * 40, TimeUnit.SECONDS);  
153 - }  
154 -  
155 - /**  
156 - * 和数据库同步数据  
157 - */  
158 - public void synchData(Integer days) {  
159 - int cacheDays = Integer.parseInt(ConfigUtil.get("cache.days"));  
160 - if (null != days && days < cacheDays)  
161 - cacheDays = days;  
162 - //设置key 序列化器  
163 - redisTemplate.setKeySerializer(new StringRedisSerializer());  
164 -  
165 - DateTime dt = new DateTime();  
166 - dt = dt.withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0).minusDays(cacheDays);  
167 - List<ElecInfo> list = elecInfoRepository.findByDateLT(dt.toDate());  
168 - //写入redis  
169 - wirte(list);  
170 - logger.info("刷新电耗数据, days: " + cacheDays + " -size: " + list.size() + " -LT: " + dt.toString("yyyy-MM-dd"));  
171 - }  
172 -  
173 - @Component  
174 - public static class ElecRefreshThread extends Thread {  
175 -  
176 - @Autowired  
177 - ElecRedisService elecRedisService;  
178 -  
179 - @Override  
180 - public void run() {  
181 - try {  
182 - elecRedisService.synchData(5);  
183 - } catch (Exception e) {  
184 - logger.error("", e);  
185 - }  
186 - }  
187 - }  
188 -} 1 +package com.bsth.redis;
  2 +
  3 +import com.bsth.Application;
  4 +import com.bsth.entity.ElecInfo;
  5 +import com.bsth.redis.util.RedisUtils;
  6 +import com.bsth.repository.ElecInfoRepository;
  7 +import com.bsth.util.AppProperties;
  8 +import com.bsth.util.ConvertUtil;
  9 +import com.google.common.collect.ArrayListMultimap;
  10 +import org.joda.time.DateTime;
  11 +import org.slf4j.Logger;
  12 +import org.slf4j.LoggerFactory;
  13 +import org.springframework.beans.factory.annotation.Autowired;
  14 +import org.springframework.boot.CommandLineRunner;
  15 +import org.springframework.core.annotation.Order;
  16 +import org.springframework.data.redis.core.RedisTemplate;
  17 +import org.springframework.data.redis.serializer.StringRedisSerializer;
  18 +import org.springframework.stereotype.Component;
  19 +import org.springframework.stereotype.Service;
  20 +
  21 +import java.util.*;
  22 +import java.util.concurrent.TimeUnit;
  23 +
  24 +/**
  25 + * 油量数据Redis缓存
  26 + * Created by panzhao on 2017/3/19.
  27 + */
  28 +@Service
  29 +@Order(3)
  30 +public class ElecRedisService implements CommandLineRunner {
  31 +
  32 + @Autowired
  33 + private RedisTemplate redisTemplate;
  34 +
  35 + @Autowired
  36 + ElecInfoRepository elecInfoRepository;
  37 +
  38 + @Autowired
  39 + RedisUtils redisUtils;
  40 +
  41 + static Logger logger = LoggerFactory.getLogger(ElecRedisService.class);
  42 +
  43 + private final static String REDIS_KEY_PREFIX = "elec:";
  44 +
  45 + /**
  46 + * 将油量数据写入redis
  47 + *
  48 + * @param list
  49 + */
  50 + public void wirte(List<ElecInfo> list) {
  51 + ArrayListMultimap<String, ElecInfo> multimap;
  52 + try {
  53 + if (list.size() == 0)
  54 + return;
  55 + //按日期和线路分组数据
  56 + Class clazz = ElecInfo.class;
  57 + multimap = new ConvertUtil().groupMultiList(list, ":", clazz.getDeclaredField("nbbm"), clazz.getDeclaredField("rq"));
  58 +
  59 + //写入redis
  60 + Iterator<String> iterator = multimap.keySet().iterator();
  61 + String key;
  62 + while (iterator.hasNext()) {
  63 + key = iterator.next();
  64 + mergeData(key, multimap.get(key));
  65 + }
  66 + } catch (Exception e) {
  67 + logger.error("", e);
  68 + }
  69 + }
  70 +
  71 + /**
  72 + * 根据车辆和日期获取油耗数据,以 车辆_驾驶员 为key
  73 + *
  74 + * @param nbbmArray
  75 + * @param rq
  76 + * @return
  77 + */
  78 + public ArrayListMultimap findByNbbmGroup(Iterable<String> nbbmArray, String rq) {
  79 + ArrayListMultimap rs = ArrayListMultimap.create();
  80 +
  81 + rq = rq.replaceAll("-", "");
  82 + try {
  83 + List<ElecInfo> list = new ArrayList<>();
  84 + for (String nbbm : nbbmArray) {
  85 + nbbm = nbbm.split("_")[1];
  86 + list.addAll(read(nbbm, rq));
  87 + }
  88 + Class clazz = ElecInfo.class;
  89 + rs = new ConvertUtil().groupMultiList(list, "_", clazz.getDeclaredField("nbbm"), clazz.getDeclaredField("jsy"));
  90 + } catch (Exception e) {
  91 + logger.error("", e);
  92 + }
  93 + return rs;
  94 + }
  95 +
  96 + /**
  97 + * 根据车辆和日期获取油耗数据,以 车辆 为key
  98 + *
  99 + * @param nbbmArray
  100 + * @param rq
  101 + * @return
  102 + */
  103 + public ArrayListMultimap findByNbbmGroup1(Iterable<String> nbbmArray, String rq) {
  104 + ArrayListMultimap rs = ArrayListMultimap.create();
  105 +
  106 + rq = rq.replaceAll("-", "");
  107 + try {
  108 + List<ElecInfo> list = new ArrayList<>();
  109 + for (String nbbm : nbbmArray) {
  110 + list.addAll(read(nbbm, rq));
  111 + }
  112 + Class clazz = ElecInfo.class;
  113 + rs = new ConvertUtil().groupMultiList(list, "_", clazz.getDeclaredField("nbbm"));
  114 + } catch (Exception e) {
  115 + logger.error("", e);
  116 + }
  117 + return rs;
  118 + }
  119 +
  120 + public List<ElecInfo> read(String nbbm, String rq) {
  121 + return redisTemplate.opsForList().range(REDIS_KEY_PREFIX + nbbm + ":" + rq, 0, -1);
  122 + }
  123 +
  124 + /**
  125 + * 将 list 与redis里的数据合并
  126 + *
  127 + * @param key
  128 + * @param list
  129 + */
  130 + public void mergeData(String key, List<ElecInfo> list) {
  131 + key = REDIS_KEY_PREFIX + key;
  132 +
  133 + //更新 直接覆盖更新
  134 + redisTemplate.execute(redisUtils.getUpdateCallback(key, list));
  135 + }
  136 +
  137 + @Autowired
  138 + ElecRefreshThread elecRefreshThread;
  139 +
  140 + @Override
  141 + public void run(String... strings) throws Exception {
  142 + Application.mainServices.schedule(new Runnable() {
  143 + @Override
  144 + public void run() {
  145 + //启动加载油耗缓存
  146 + synchData(null);
  147 + }
  148 + }, 30, TimeUnit.SECONDS);
  149 +
  150 +
  151 + //定时刷新油耗信息
  152 + Application.mainServices.scheduleWithFixedDelay(elecRefreshThread, 60 * 40, 60 * 40, TimeUnit.SECONDS);
  153 + }
  154 +
  155 + /**
  156 + * 和数据库同步数据
  157 + */
  158 + public void synchData(Integer days) {
  159 + int cacheDays = AppProperties.getCacheDays();
  160 + if (null != days && days < cacheDays)
  161 + cacheDays = days;
  162 + //设置key 序列化器
  163 + redisTemplate.setKeySerializer(new StringRedisSerializer());
  164 +
  165 + DateTime dt = new DateTime();
  166 + dt = dt.withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0).minusDays(cacheDays);
  167 + List<ElecInfo> list = elecInfoRepository.findByDateLT(dt.toDate());
  168 + //写入redis
  169 + wirte(list);
  170 + logger.info("刷新电耗数据, days: " + cacheDays + " -size: " + list.size() + " -LT: " + dt.toString("yyyy-MM-dd"));
  171 + }
  172 +
  173 + @Component
  174 + public static class ElecRefreshThread extends Thread {
  175 +
  176 + @Autowired
  177 + ElecRedisService elecRedisService;
  178 +
  179 + @Override
  180 + public void run() {
  181 + try {
  182 + elecRedisService.synchData(5);
  183 + } catch (Exception e) {
  184 + logger.error("", e);
  185 + }
  186 + }
  187 + }
  188 +}
src/main/java/com/bsth/redis/OilRedisService.java
1 -package com.bsth.redis;  
2 -  
3 -import com.bsth.Application;  
4 -import com.bsth.entity.OilInfo;  
5 -import com.bsth.redis.util.RedisUtils;  
6 -import com.bsth.repository.OilInfoRepository;  
7 -import com.bsth.util.ConfigUtil;  
8 -import com.bsth.util.ConvertUtil;  
9 -import com.google.common.collect.ArrayListMultimap;  
10 -import org.joda.time.DateTime;  
11 -import org.slf4j.Logger;  
12 -import org.slf4j.LoggerFactory;  
13 -import org.springframework.beans.factory.annotation.Autowired;  
14 -import org.springframework.boot.CommandLineRunner;  
15 -import org.springframework.core.annotation.Order;  
16 -import org.springframework.data.redis.core.RedisTemplate;  
17 -import org.springframework.data.redis.serializer.StringRedisSerializer;  
18 -import org.springframework.stereotype.Component;  
19 -import org.springframework.stereotype.Service;  
20 -  
21 -import java.util.*;  
22 -import java.util.concurrent.TimeUnit;  
23 -  
24 -/**  
25 - * 油量数据Redis缓存  
26 - * Created by panzhao on 2017/3/19.  
27 - */  
28 -@Service  
29 -@Order(3)  
30 -public class OilRedisService implements CommandLineRunner {  
31 -  
32 - @Autowired  
33 - private RedisTemplate redisTemplate;  
34 -  
35 - @Autowired  
36 - OilInfoRepository oilInfoRepository;  
37 -  
38 - @Autowired  
39 - RedisUtils redisUtils;  
40 -  
41 - static Logger logger = LoggerFactory.getLogger(OilRedisService.class);  
42 -  
43 - private final static String REDIS_KEY_PREFIX = "oil:";  
44 -  
45 - /**  
46 - * 将油量数据写入redis  
47 - *  
48 - * @param list  
49 - */  
50 - public void wirte(List<OilInfo> list) {  
51 - ArrayListMultimap<String, OilInfo> multimap;  
52 - try {  
53 - if (list.size() == 0)  
54 - return;  
55 - //按日期和线路分组数据  
56 - Class clazz = OilInfo.class;  
57 - multimap = new ConvertUtil().groupMultiList(list, ":", clazz.getDeclaredField("nbbm"), clazz.getDeclaredField("rq"));  
58 -  
59 - //写入redis  
60 - Iterator<String> iterator = multimap.keySet().iterator();  
61 - String key;  
62 - while (iterator.hasNext()) {  
63 - key = iterator.next();  
64 - mergeData(key, multimap.get(key));  
65 - }  
66 - } catch (Exception e) {  
67 - logger.error("", e);  
68 - }  
69 - }  
70 -  
71 - /**  
72 - * 根据车辆和日期获取油耗数据,以 车辆_驾驶员 为key  
73 - *  
74 - * @param nbbmArray  
75 - * @param rq  
76 - * @return  
77 - */  
78 - public ArrayListMultimap<String, OilInfo> findByNbbmGroup(Iterable<String> nbbmArray, String rq) {  
79 - ArrayListMultimap<String, OilInfo> rs = ArrayListMultimap.create();  
80 -  
81 - rq = rq.replaceAll("-", "");  
82 - try {  
83 - List<OilInfo> list = new ArrayList<>();  
84 - Set<String> nbbms = new HashSet<>();  
85 - for (String nbbm : nbbmArray) {  
86 - nbbm = nbbm.split("_")[1];  
87 - if (!nbbms.contains(nbbm)) {  
88 - nbbms.add(nbbm);  
89 - list.addAll(read(nbbm, rq));  
90 - }  
91 - }  
92 - Class clazz = OilInfo.class;  
93 - rs = new ConvertUtil().groupMultiList(list, "_", clazz.getDeclaredField("nbbm"), clazz.getDeclaredField("jsy"));  
94 - } catch (Exception e) {  
95 - logger.error("", e);  
96 - }  
97 - return rs;  
98 - }  
99 -  
100 - /**  
101 - * 根据车辆和日期获取油耗数据,以 车辆_驾驶员 为key  
102 - *  
103 - * @param nbbmArray  
104 - * @param rq  
105 - * @return  
106 - */  
107 - public Map<String, OilInfo> findByNbbmGroupRaw(Iterable<String> nbbmArray, String rq) {  
108 - Map<String, OilInfo> rs = new HashMap<>();  
109 -  
110 - rq = rq.replaceAll("-", "");  
111 - try {  
112 - List<OilInfo> list = new ArrayList<>();  
113 - for (String nbbm : nbbmArray) {  
114 - nbbm = nbbm.split("_")[1];  
115 - list.addAll(read(nbbm, rq));  
116 - }  
117 - Class clazz = OilInfo.class;  
118 - rs = new ConvertUtil().groupList(list, "_", clazz.getDeclaredField("nbbm"), clazz.getDeclaredField("jsy"));  
119 - } catch (Exception e) {  
120 - logger.error("", e);  
121 - }  
122 - return rs;  
123 - }  
124 -  
125 - /**  
126 - * 根据车辆和日期获取油耗数据,以 车辆 为key  
127 - *  
128 - * @param nbbmArray  
129 - * @param rq  
130 - * @return  
131 - */  
132 - public ArrayListMultimap<String, OilInfo> findByNbbmGroup1(Iterable<String> nbbmArray, String rq) {  
133 - ArrayListMultimap<String, OilInfo> rs = ArrayListMultimap.create();  
134 -  
135 - rq = rq.replaceAll("-", "");  
136 - try {  
137 - List<OilInfo> list = new ArrayList<>();  
138 - Set<String> nbbms = new HashSet<>();  
139 - for (String nbbm : nbbmArray) {  
140 - if (!nbbms.contains(nbbm)) {  
141 - nbbms.add(nbbm);  
142 - list.addAll(read(nbbm, rq));  
143 - }  
144 - }  
145 - Class clazz = OilInfo.class;  
146 - rs = new ConvertUtil().groupMultiList(list, "_", clazz.getDeclaredField("nbbm"));  
147 - } catch (Exception e) {  
148 - logger.error("", e);  
149 - }  
150 - return rs;  
151 - }  
152 -  
153 - public List<OilInfo> read(String nbbm, String rq) {  
154 - return redisTemplate.opsForList().range(REDIS_KEY_PREFIX + nbbm + ":" + rq, 0, -1);  
155 - }  
156 -  
157 - /**  
158 - * 将 list 与redis里的数据合并  
159 - *  
160 - * @param key  
161 - * @param list  
162 - */  
163 - public void mergeData(String key, List<OilInfo> list) {  
164 - key = REDIS_KEY_PREFIX + key;  
165 -  
166 - //更新 直接覆盖更新  
167 - redisTemplate.execute(redisUtils.getUpdateCallback(key, list));  
168 - }  
169 -  
170 - @Autowired  
171 - OilRefreshThread oilRefreshThread;  
172 -  
173 - @Override  
174 - public void run(String... strings) throws Exception {  
175 - Application.mainServices.schedule(new Runnable() {  
176 - @Override  
177 - public void run() {  
178 - //启动加载油耗缓存  
179 - synchData(null);  
180 - }  
181 - }, 30, TimeUnit.SECONDS);  
182 -  
183 -  
184 - //定时刷新油耗信息  
185 - Application.mainServices.scheduleWithFixedDelay(oilRefreshThread, 60 * 40, 60 * 40, TimeUnit.SECONDS);  
186 - }  
187 -  
188 - /**  
189 - * 和数据库同步数据  
190 - */  
191 - public void synchData(Integer days) {  
192 - int cacheDays = Integer.parseInt(ConfigUtil.get("cache.days"));  
193 - if (null != days && days < cacheDays)  
194 - cacheDays = days;  
195 - //设置key 序列化器  
196 - redisTemplate.setKeySerializer(new StringRedisSerializer());  
197 -  
198 - DateTime dt = new DateTime();  
199 - dt = dt.withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0).minusDays(cacheDays);  
200 - List<OilInfo> list = oilInfoRepository.findByDateLT(dt.toDate());  
201 - //写入redis  
202 - wirte(list);  
203 - logger.info("刷新油耗数据, days: " + cacheDays + " -size: " + list.size() + " -LT: " + dt.toString("yyyy-MM-dd"));  
204 - }  
205 -  
206 - @Component  
207 - public static class OilRefreshThread extends Thread {  
208 -  
209 - @Autowired  
210 - OilRedisService oilRedisService;  
211 -  
212 - @Override  
213 - public void run() {  
214 - try {  
215 - oilRedisService.synchData(5);  
216 - } catch (Exception e) {  
217 - logger.error("", e);  
218 - }  
219 - }  
220 - }  
221 -} 1 +package com.bsth.redis;
  2 +
  3 +import com.bsth.Application;
  4 +import com.bsth.entity.OilInfo;
  5 +import com.bsth.redis.util.RedisUtils;
  6 +import com.bsth.repository.OilInfoRepository;
  7 +import com.bsth.util.AppProperties;
  8 +import com.bsth.util.ConvertUtil;
  9 +import com.google.common.collect.ArrayListMultimap;
  10 +import org.joda.time.DateTime;
  11 +import org.slf4j.Logger;
  12 +import org.slf4j.LoggerFactory;
  13 +import org.springframework.beans.factory.annotation.Autowired;
  14 +import org.springframework.boot.CommandLineRunner;
  15 +import org.springframework.core.annotation.Order;
  16 +import org.springframework.data.redis.core.RedisTemplate;
  17 +import org.springframework.data.redis.serializer.StringRedisSerializer;
  18 +import org.springframework.stereotype.Component;
  19 +import org.springframework.stereotype.Service;
  20 +
  21 +import java.util.*;
  22 +import java.util.concurrent.TimeUnit;
  23 +
  24 +/**
  25 + * 油量数据Redis缓存
  26 + * Created by panzhao on 2017/3/19.
  27 + */
  28 +@Service
  29 +@Order(3)
  30 +public class OilRedisService implements CommandLineRunner {
  31 +
  32 + @Autowired
  33 + private RedisTemplate redisTemplate;
  34 +
  35 + @Autowired
  36 + OilInfoRepository oilInfoRepository;
  37 +
  38 + @Autowired
  39 + RedisUtils redisUtils;
  40 +
  41 + static Logger logger = LoggerFactory.getLogger(OilRedisService.class);
  42 +
  43 + private final static String REDIS_KEY_PREFIX = "oil:";
  44 +
  45 + /**
  46 + * 将油量数据写入redis
  47 + *
  48 + * @param list
  49 + */
  50 + public void wirte(List<OilInfo> list) {
  51 + ArrayListMultimap<String, OilInfo> multimap;
  52 + try {
  53 + if (list.size() == 0)
  54 + return;
  55 + //按日期和线路分组数据
  56 + Class clazz = OilInfo.class;
  57 + multimap = new ConvertUtil().groupMultiList(list, ":", clazz.getDeclaredField("nbbm"), clazz.getDeclaredField("rq"));
  58 +
  59 + //写入redis
  60 + Iterator<String> iterator = multimap.keySet().iterator();
  61 + String key;
  62 + while (iterator.hasNext()) {
  63 + key = iterator.next();
  64 + mergeData(key, multimap.get(key));
  65 + }
  66 + } catch (Exception e) {
  67 + logger.error("", e);
  68 + }
  69 + }
  70 +
  71 + /**
  72 + * 根据车辆和日期获取油耗数据,以 车辆_驾驶员 为key
  73 + *
  74 + * @param nbbmArray
  75 + * @param rq
  76 + * @return
  77 + */
  78 + public ArrayListMultimap<String, OilInfo> findByNbbmGroup(Iterable<String> nbbmArray, String rq) {
  79 + ArrayListMultimap<String, OilInfo> rs = ArrayListMultimap.create();
  80 +
  81 + rq = rq.replaceAll("-", "");
  82 + try {
  83 + List<OilInfo> list = new ArrayList<>();
  84 + Set<String> nbbms = new HashSet<>();
  85 + for (String nbbm : nbbmArray) {
  86 + nbbm = nbbm.split("_")[1];
  87 + if (!nbbms.contains(nbbm)) {
  88 + nbbms.add(nbbm);
  89 + list.addAll(read(nbbm, rq));
  90 + }
  91 + }
  92 + Class clazz = OilInfo.class;
  93 + rs = new ConvertUtil().groupMultiList(list, "_", clazz.getDeclaredField("nbbm"), clazz.getDeclaredField("jsy"));
  94 + } catch (Exception e) {
  95 + logger.error("", e);
  96 + }
  97 + return rs;
  98 + }
  99 +
  100 + /**
  101 + * 根据车辆和日期获取油耗数据,以 车辆_驾驶员 为key
  102 + *
  103 + * @param nbbmArray
  104 + * @param rq
  105 + * @return
  106 + */
  107 + public Map<String, OilInfo> findByNbbmGroupRaw(Iterable<String> nbbmArray, String rq) {
  108 + Map<String, OilInfo> rs = new HashMap<>();
  109 +
  110 + rq = rq.replaceAll("-", "");
  111 + try {
  112 + List<OilInfo> list = new ArrayList<>();
  113 + for (String nbbm : nbbmArray) {
  114 + nbbm = nbbm.split("_")[1];
  115 + list.addAll(read(nbbm, rq));
  116 + }
  117 + Class clazz = OilInfo.class;
  118 + rs = new ConvertUtil().groupList(list, "_", clazz.getDeclaredField("nbbm"), clazz.getDeclaredField("jsy"));
  119 + } catch (Exception e) {
  120 + logger.error("", e);
  121 + }
  122 + return rs;
  123 + }
  124 +
  125 + /**
  126 + * 根据车辆和日期获取油耗数据,以 车辆 为key
  127 + *
  128 + * @param nbbmArray
  129 + * @param rq
  130 + * @return
  131 + */
  132 + public ArrayListMultimap<String, OilInfo> findByNbbmGroup1(Iterable<String> nbbmArray, String rq) {
  133 + ArrayListMultimap<String, OilInfo> rs = ArrayListMultimap.create();
  134 +
  135 + rq = rq.replaceAll("-", "");
  136 + try {
  137 + List<OilInfo> list = new ArrayList<>();
  138 + Set<String> nbbms = new HashSet<>();
  139 + for (String nbbm : nbbmArray) {
  140 + if (!nbbms.contains(nbbm)) {
  141 + nbbms.add(nbbm);
  142 + list.addAll(read(nbbm, rq));
  143 + }
  144 + }
  145 + Class clazz = OilInfo.class;
  146 + rs = new ConvertUtil().groupMultiList(list, "_", clazz.getDeclaredField("nbbm"));
  147 + } catch (Exception e) {
  148 + logger.error("", e);
  149 + }
  150 + return rs;
  151 + }
  152 +
  153 + public List<OilInfo> read(String nbbm, String rq) {
  154 + return redisTemplate.opsForList().range(REDIS_KEY_PREFIX + nbbm + ":" + rq, 0, -1);
  155 + }
  156 +
  157 + /**
  158 + * 将 list 与redis里的数据合并
  159 + *
  160 + * @param key
  161 + * @param list
  162 + */
  163 + public void mergeData(String key, List<OilInfo> list) {
  164 + key = REDIS_KEY_PREFIX + key;
  165 +
  166 + //更新 直接覆盖更新
  167 + redisTemplate.execute(redisUtils.getUpdateCallback(key, list));
  168 + }
  169 +
  170 + @Autowired
  171 + OilRefreshThread oilRefreshThread;
  172 +
  173 + @Override
  174 + public void run(String... strings) throws Exception {
  175 + Application.mainServices.schedule(new Runnable() {
  176 + @Override
  177 + public void run() {
  178 + //启动加载油耗缓存
  179 + synchData(null);
  180 + }
  181 + }, 30, TimeUnit.SECONDS);
  182 +
  183 +
  184 + //定时刷新油耗信息
  185 + Application.mainServices.scheduleWithFixedDelay(oilRefreshThread, 60 * 40, 60 * 40, TimeUnit.SECONDS);
  186 + }
  187 +
  188 + /**
  189 + * 和数据库同步数据
  190 + */
  191 + public void synchData(Integer days) {
  192 + int cacheDays = AppProperties.getCacheDays();
  193 + if (null != days && days < cacheDays)
  194 + cacheDays = days;
  195 + //设置key 序列化器
  196 + redisTemplate.setKeySerializer(new StringRedisSerializer());
  197 +
  198 + DateTime dt = new DateTime();
  199 + dt = dt.withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0).minusDays(cacheDays);
  200 + List<OilInfo> list = oilInfoRepository.findByDateLT(dt.toDate());
  201 + //写入redis
  202 + wirte(list);
  203 + logger.info("刷新油耗数据, days: " + cacheDays + " -size: " + list.size() + " -LT: " + dt.toString("yyyy-MM-dd"));
  204 + }
  205 +
  206 + @Component
  207 + public static class OilRefreshThread extends Thread {
  208 +
  209 + @Autowired
  210 + OilRedisService oilRedisService;
  211 +
  212 + @Override
  213 + public void run() {
  214 + try {
  215 + oilRedisService.synchData(5);
  216 + } catch (Exception e) {
  217 + logger.error("", e);
  218 + }
  219 + }
  220 + }
  221 +}
src/main/java/com/bsth/redis/PlanScheduleRedisService.java
1 -package com.bsth.redis;  
2 -  
3 -import com.bsth.Application;  
4 -import com.bsth.entity.SchedulePlanInfo;  
5 -import com.bsth.redis.util.DateUtils;  
6 -import com.bsth.redis.util.RedisUtils;  
7 -import com.bsth.repository.SchedulePlanInfoRepository;  
8 -import com.bsth.server_rs.base_info.line.Line;  
9 -import com.bsth.server_rs.base_info.line.buffer.LineBufferData;  
10 -import com.bsth.util.ConfigUtil;  
11 -import com.bsth.util.ConvertUtil;  
12 -import com.google.common.collect.ArrayListMultimap;  
13 -import org.joda.time.DateTime;  
14 -import org.slf4j.Logger;  
15 -import org.slf4j.LoggerFactory;  
16 -import org.springframework.beans.factory.annotation.Autowired;  
17 -import org.springframework.boot.CommandLineRunner;  
18 -import org.springframework.core.annotation.Order;  
19 -import org.springframework.data.redis.core.ListOperations;  
20 -import org.springframework.data.redis.core.RedisTemplate;  
21 -import org.springframework.data.redis.serializer.StringRedisSerializer;  
22 -import org.springframework.stereotype.Component;  
23 -import org.springframework.stereotype.Service;  
24 -  
25 -import java.util.ArrayList;  
26 -import java.util.Date;  
27 -import java.util.Iterator;  
28 -import java.util.List;  
29 -import java.util.concurrent.TimeUnit;  
30 -  
31 -/**  
32 - * 计调的 计划排班redis缓存  
33 - * Created by panzhao on 2017/3/27.  
34 - */  
35 -@Service  
36 -@Order(6)  
37 -public class PlanScheduleRedisService implements CommandLineRunner {  
38 -  
39 - @Autowired  
40 - private RedisTemplate redisTemplate;  
41 -  
42 - @Autowired  
43 - SchedulePlanInfoRepository planInfoRepository;  
44 -  
45 - @Autowired  
46 - RedisUtils redisUtils;  
47 -  
48 - static Logger logger = LoggerFactory.getLogger(PlanScheduleRedisService.class);  
49 -  
50 - private final static String REDIS_KEY_PREFIX = "plan:";  
51 -  
52 - /**  
53 - * 将一批计划写入redis  
54 - *  
55 - * @param list  
56 - */  
57 - public void wirte(List<SchedulePlanInfo> list) {  
58 - ArrayListMultimap<String, SchedulePlanInfo> multimap;  
59 - try {  
60 - if (list.size() == 0)  
61 - return;  
62 - //按日期和线路分组数据  
63 - Class clazz = SchedulePlanInfo.class;  
64 - multimap = new ConvertUtil().groupMultiList(list, ":", clazz.getDeclaredField("xlBm"), clazz.getDeclaredField("scheduleDate"));  
65 -  
66 - //写入redis  
67 - Iterator<String> iterator = multimap.keySet().iterator();  
68 - String key;  
69 - while (iterator.hasNext()) {  
70 - key = iterator.next();  
71 - replace(key, multimap.get(key));  
72 - }  
73 - } catch (Exception e) {  
74 - logger.error("", e);  
75 - }  
76 - }  
77 -  
78 - /**  
79 - * 将 list 与redis里的数据合并  
80 - *  
81 - * @param key  
82 - * @param list  
83 - */  
84 - public void mergeData(String key, List<SchedulePlanInfo> list) {  
85 - key = REDIS_KEY_PREFIX + key.replaceAll("-", "");  
86 -  
87 - ListOperations<String, SchedulePlanInfo> ops = redisTemplate.opsForList();  
88 - List<SchedulePlanInfo> cacheList = ops.range(key, 0, -1);  
89 -  
90 - for (SchedulePlanInfo plan : cacheList) {  
91 - if (!list.contains(plan))  
92 - list.add(plan);  
93 - }  
94 -  
95 - //更新  
96 - redisTemplate.execute(redisUtils.getUpdateCallback(key, list));  
97 - }  
98 -  
99 - /**  
100 - * 覆盖数据  
101 - *  
102 - * @param key  
103 - * @param list  
104 - */  
105 - public void replace(String key, List<SchedulePlanInfo> list) {  
106 - key = REDIS_KEY_PREFIX + key.replaceAll("-", "");  
107 - redisTemplate.execute(redisUtils.getUpdateCallback(key, list));  
108 - }  
109 -  
110 - /**  
111 - * 根据日期和线路编码从redis获取计划  
112 - *  
113 - * @param dateStr  
114 - * @param lineCode  
115 - * @return  
116 - */  
117 - public List<SchedulePlanInfo> read(String dateStr, String lineCode) {  
118 - return redisTemplate.opsForList().range(REDIS_KEY_PREFIX + lineCode + ":" + dateStr, 0, -1);  
119 - }  
120 -  
121 -  
122 - @Autowired  
123 - PlanClearThread planClearThread;  
124 -  
125 - @Override  
126 - public void run(String... strings) throws Exception {  
127 - Application.mainServices.schedule(new Runnable() {  
128 - @Override  
129 - public void run() {  
130 - int cacheDays = Integer.parseInt(ConfigUtil.get("cache.days"));  
131 - //设置key 序列化器  
132 - redisTemplate.setKeySerializer(new StringRedisSerializer());  
133 -  
134 - DateTime dt = new DateTime();  
135 - dt = dt.minusDays(cacheDays);  
136 - dt = dt.withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0).minusDays(cacheDays);  
137 - List<SchedulePlanInfo> list = planInfoRepository.findByDateRange(dt.toDate(), new Date());  
138 - //写入redis  
139 - wirte(list);  
140 - }  
141 - }, 60 * 5, TimeUnit.SECONDS);  
142 -  
143 -  
144 - //定时 00:05 分清理计划,并加载当天的计划  
145 - long diff = (DateUtils.getTimestamp() + 1000 * 60 * 5) - System.currentTimeMillis();  
146 - if (diff < 0)  
147 - diff += (1000 * 60 * 60 * 24);  
148 - Application.mainServices.scheduleAtFixedRate(planClearThread, diff / 1000, 60 * 60 * 24, TimeUnit.SECONDS);  
149 - }  
150 -  
151 - public List<SchedulePlanInfo> findByMultiLine(List<String> lineArray, String rq) {  
152 - rq = rq.replaceAll("-", "");  
153 - List<SchedulePlanInfo> rs = new ArrayList<>();  
154 - for (String lineCode : lineArray) {  
155 - rs.addAll(read(rq, lineCode));  
156 - }  
157 - return rs;  
158 - }  
159 -  
160 - @Component  
161 - public static class PlanClearThread extends Thread {  
162 -  
163 - @Autowired  
164 - PlanScheduleRedisService planRedisService;  
165 - @Autowired  
166 - SchedulePlanInfoRepository planInfoRepository;  
167 -  
168 - @Override  
169 - public void run() {  
170 - try {  
171 - logger.info("redis -清理计划排班");  
172 -  
173 - int cacheDays = Integer.parseInt(ConfigUtil.get("cache.days"));  
174 - DateTime dt = new DateTime();  
175 - dt = dt.minusDays(cacheDays);  
176 - String rq = dt.toString("yyyy-MM-dd");  
177 -  
178 - List<Line> lines = LineBufferData.findAll();  
179 - for (Line line : lines) {  
180 - planRedisService.delete(line.getLineCode(), rq);  
181 - }  
182 -  
183 - //加载当天的计划  
184 - Date d = new Date();  
185 - Date s = new Date(d.getTime() - 1000 * 60 * 60 * 24);  
186 - List<SchedulePlanInfo> list = planInfoRepository.findByDateRange(s, d);  
187 - //写入redis  
188 - planRedisService.wirte(list);  
189 - } catch (Exception e) {  
190 - logger.error("", e);  
191 - }  
192 - }  
193 - }  
194 -  
195 - private void delete(String lineCode, String rq) {  
196 - String key = REDIS_KEY_PREFIX + (lineCode + ":" + rq).replaceAll("-", "");  
197 - redisTemplate.delete(key);  
198 - }  
199 -} 1 +package com.bsth.redis;
  2 +
  3 +import com.bsth.Application;
  4 +import com.bsth.entity.SchedulePlanInfo;
  5 +import com.bsth.redis.util.DateUtils;
  6 +import com.bsth.redis.util.RedisUtils;
  7 +import com.bsth.repository.SchedulePlanInfoRepository;
  8 +import com.bsth.server_rs.base_info.line.Line;
  9 +import com.bsth.server_rs.base_info.line.buffer.LineBufferData;
  10 +import com.bsth.util.AppProperties;
  11 +import com.bsth.util.ConvertUtil;
  12 +import com.google.common.collect.ArrayListMultimap;
  13 +import org.joda.time.DateTime;
  14 +import org.slf4j.Logger;
  15 +import org.slf4j.LoggerFactory;
  16 +import org.springframework.beans.factory.annotation.Autowired;
  17 +import org.springframework.boot.CommandLineRunner;
  18 +import org.springframework.core.annotation.Order;
  19 +import org.springframework.data.redis.core.ListOperations;
  20 +import org.springframework.data.redis.core.RedisTemplate;
  21 +import org.springframework.data.redis.serializer.StringRedisSerializer;
  22 +import org.springframework.stereotype.Component;
  23 +import org.springframework.stereotype.Service;
  24 +
  25 +import java.util.ArrayList;
  26 +import java.util.Date;
  27 +import java.util.Iterator;
  28 +import java.util.List;
  29 +import java.util.concurrent.TimeUnit;
  30 +
  31 +/**
  32 + * 计调的 计划排班redis缓存
  33 + * Created by panzhao on 2017/3/27.
  34 + */
  35 +@Service
  36 +@Order(6)
  37 +public class PlanScheduleRedisService implements CommandLineRunner {
  38 +
  39 + @Autowired
  40 + private RedisTemplate redisTemplate;
  41 +
  42 + @Autowired
  43 + SchedulePlanInfoRepository planInfoRepository;
  44 +
  45 + @Autowired
  46 + RedisUtils redisUtils;
  47 +
  48 + static Logger logger = LoggerFactory.getLogger(PlanScheduleRedisService.class);
  49 +
  50 + private final static String REDIS_KEY_PREFIX = "plan:";
  51 +
  52 + /**
  53 + * 将一批计划写入redis
  54 + *
  55 + * @param list
  56 + */
  57 + public void wirte(List<SchedulePlanInfo> list) {
  58 + ArrayListMultimap<String, SchedulePlanInfo> multimap;
  59 + try {
  60 + if (list.size() == 0)
  61 + return;
  62 + //按日期和线路分组数据
  63 + Class clazz = SchedulePlanInfo.class;
  64 + multimap = new ConvertUtil().groupMultiList(list, ":", clazz.getDeclaredField("xlBm"), clazz.getDeclaredField("scheduleDate"));
  65 +
  66 + //写入redis
  67 + Iterator<String> iterator = multimap.keySet().iterator();
  68 + String key;
  69 + while (iterator.hasNext()) {
  70 + key = iterator.next();
  71 + replace(key, multimap.get(key));
  72 + }
  73 + } catch (Exception e) {
  74 + logger.error("", e);
  75 + }
  76 + }
  77 +
  78 + /**
  79 + * 将 list 与redis里的数据合并
  80 + *
  81 + * @param key
  82 + * @param list
  83 + */
  84 + public void mergeData(String key, List<SchedulePlanInfo> list) {
  85 + key = REDIS_KEY_PREFIX + key.replaceAll("-", "");
  86 +
  87 + ListOperations<String, SchedulePlanInfo> ops = redisTemplate.opsForList();
  88 + List<SchedulePlanInfo> cacheList = ops.range(key, 0, -1);
  89 +
  90 + for (SchedulePlanInfo plan : cacheList) {
  91 + if (!list.contains(plan))
  92 + list.add(plan);
  93 + }
  94 +
  95 + //更新
  96 + redisTemplate.execute(redisUtils.getUpdateCallback(key, list));
  97 + }
  98 +
  99 + /**
  100 + * 覆盖数据
  101 + *
  102 + * @param key
  103 + * @param list
  104 + */
  105 + public void replace(String key, List<SchedulePlanInfo> list) {
  106 + key = REDIS_KEY_PREFIX + key.replaceAll("-", "");
  107 + redisTemplate.execute(redisUtils.getUpdateCallback(key, list));
  108 + }
  109 +
  110 + /**
  111 + * 根据日期和线路编码从redis获取计划
  112 + *
  113 + * @param dateStr
  114 + * @param lineCode
  115 + * @return
  116 + */
  117 + public List<SchedulePlanInfo> read(String dateStr, String lineCode) {
  118 + return redisTemplate.opsForList().range(REDIS_KEY_PREFIX + lineCode + ":" + dateStr, 0, -1);
  119 + }
  120 +
  121 +
  122 + @Autowired
  123 + PlanClearThread planClearThread;
  124 +
  125 + @Override
  126 + public void run(String... strings) throws Exception {
  127 + Application.mainServices.schedule(new Runnable() {
  128 + @Override
  129 + public void run() {
  130 + int cacheDays = AppProperties.getCacheDays();
  131 + //设置key 序列化器
  132 + redisTemplate.setKeySerializer(new StringRedisSerializer());
  133 +
  134 + DateTime dt = new DateTime();
  135 + dt = dt.minusDays(cacheDays);
  136 + dt = dt.withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0).minusDays(cacheDays);
  137 + List<SchedulePlanInfo> list = planInfoRepository.findByDateRange(dt.toDate(), new Date());
  138 + //写入redis
  139 + wirte(list);
  140 + }
  141 + }, 60 * 5, TimeUnit.SECONDS);
  142 +
  143 +
  144 + //定时 00:05 分清理计划,并加载当天的计划
  145 + long diff = (DateUtils.getTimestamp() + 1000 * 60 * 5) - System.currentTimeMillis();
  146 + if (diff < 0)
  147 + diff += (1000 * 60 * 60 * 24);
  148 + Application.mainServices.scheduleAtFixedRate(planClearThread, diff / 1000, 60 * 60 * 24, TimeUnit.SECONDS);
  149 + }
  150 +
  151 + public List<SchedulePlanInfo> findByMultiLine(List<String> lineArray, String rq) {
  152 + rq = rq.replaceAll("-", "");
  153 + List<SchedulePlanInfo> rs = new ArrayList<>();
  154 + for (String lineCode : lineArray) {
  155 + rs.addAll(read(rq, lineCode));
  156 + }
  157 + return rs;
  158 + }
  159 +
  160 + @Component
  161 + public static class PlanClearThread extends Thread {
  162 +
  163 + @Autowired
  164 + PlanScheduleRedisService planRedisService;
  165 + @Autowired
  166 + SchedulePlanInfoRepository planInfoRepository;
  167 +
  168 + @Override
  169 + public void run() {
  170 + try {
  171 + logger.info("redis -清理计划排班");
  172 +
  173 + int cacheDays = AppProperties.getCacheDays();
  174 + DateTime dt = new DateTime();
  175 + dt = dt.minusDays(cacheDays);
  176 + String rq = dt.toString("yyyy-MM-dd");
  177 +
  178 + List<Line> lines = LineBufferData.findAll();
  179 + for (Line line : lines) {
  180 + planRedisService.delete(line.getLineCode(), rq);
  181 + }
  182 +
  183 + //加载当天的计划
  184 + Date d = new Date();
  185 + Date s = new Date(d.getTime() - 1000 * 60 * 60 * 24);
  186 + List<SchedulePlanInfo> list = planInfoRepository.findByDateRange(s, d);
  187 + //写入redis
  188 + planRedisService.wirte(list);
  189 + } catch (Exception e) {
  190 + logger.error("", e);
  191 + }
  192 + }
  193 + }
  194 +
  195 + private void delete(String lineCode, String rq) {
  196 + String key = REDIS_KEY_PREFIX + (lineCode + ":" + rq).replaceAll("-", "");
  197 + redisTemplate.delete(key);
  198 + }
  199 +}
src/main/java/com/bsth/redis/ScheduleRedisService.java
1 -package com.bsth.redis;  
2 -  
3 -import com.bsth.Application;  
4 -import com.bsth.common.BasicData;  
5 -import com.bsth.entity.ScheduleRealInfo;  
6 -import com.bsth.redis.util.RedisUtils;  
7 -import com.bsth.repository.ScheduleRealInfoRepository;  
8 -import com.bsth.server_rs.base_info.line.Line;  
9 -import com.bsth.server_rs.base_info.line.buffer.LineBufferData;  
10 -import com.bsth.util.ConfigUtil;  
11 -import com.bsth.util.ConvertUtil;  
12 -import com.google.common.collect.ArrayListMultimap;  
13 -import org.apache.commons.lang3.StringUtils;  
14 -import org.joda.time.DateTime;  
15 -import org.joda.time.format.DateTimeFormat;  
16 -import org.joda.time.format.DateTimeFormatter;  
17 -import org.slf4j.Logger;  
18 -import org.slf4j.LoggerFactory;  
19 -import org.springframework.beans.factory.annotation.Autowired;  
20 -import org.springframework.boot.CommandLineRunner;  
21 -import org.springframework.core.annotation.Order;  
22 -import org.springframework.data.redis.core.ListOperations;  
23 -import org.springframework.data.redis.core.RedisTemplate;  
24 -import org.springframework.data.redis.serializer.StringRedisSerializer;  
25 -import org.springframework.stereotype.Component;  
26 -import org.springframework.stereotype.Service;  
27 -  
28 -import java.util.ArrayList;  
29 -import java.util.Iterator;  
30 -import java.util.List;  
31 -import java.util.concurrent.TimeUnit;  
32 -  
33 -/**  
34 - * 班次 redis 缓存管理  
35 - * Created by panzhao on 2017/3/13.  
36 - */  
37 -@Service  
38 -@Order(2)  
39 -public class ScheduleRedisService implements CommandLineRunner {  
40 -  
41 - @Autowired  
42 - ScheduleRealInfoRepository scheduleRealInfoRepository;  
43 -  
44 - private final static String REDIS_KEY_PREFIX = "schedule:";  
45 -  
46 - @Autowired  
47 - private RedisTemplate redisTemplate;  
48 -  
49 - @Autowired  
50 - RedisUtils redisUtils;  
51 -  
52 - static Logger logger = LoggerFactory.getLogger(ScheduleRedisService.class);  
53 -  
54 - private final static long DAY_TIME = 1000 * 60 * 60 * 24L;  
55 -  
56 - /**  
57 - * 将一批班次写入redis  
58 - *  
59 - * @param list  
60 - */  
61 - public void wirte(List<ScheduleRealInfo> list) {  
62 - ArrayListMultimap<String, ScheduleRealInfo> multimap;  
63 - try {  
64 - if (list.size() == 0)  
65 - return;  
66 - //按日期和线路分组数据  
67 - Class clazz = ScheduleRealInfo.class;  
68 - multimap = new ConvertUtil().groupMultiList(list, ":", clazz.getDeclaredField("xlBm"), clazz.getDeclaredField("scheduleDateStr"));  
69 -  
70 - //写入redis  
71 - Iterator<String> iterator = multimap.keySet().iterator();  
72 - String key;  
73 - while (iterator.hasNext()) {  
74 - key = iterator.next();  
75 - replace(key, multimap.get(key));  
76 - }  
77 - } catch (Exception e) {  
78 - logger.error("", e);  
79 - }  
80 - }  
81 -  
82 - /**  
83 - * 将 list 与redis里的数据合并  
84 - *  
85 - * @param key  
86 - * @param list  
87 - */  
88 - public void mergeData(String key, List<ScheduleRealInfo> list) {  
89 - key = REDIS_KEY_PREFIX + key.replaceAll("-", "");  
90 -  
91 - ListOperations<String, ScheduleRealInfo> ops = redisTemplate.opsForList();  
92 - List<ScheduleRealInfo> cacheList = ops.range(key, 0, -1);  
93 -  
94 - for (ScheduleRealInfo sch : cacheList) {  
95 - if (!list.contains(sch))  
96 - list.add(sch);  
97 - }  
98 -  
99 - //更新  
100 - redisTemplate.execute(redisUtils.getUpdateCallback(key, list));  
101 - }  
102 -  
103 - /**  
104 - * 覆盖数据  
105 - *  
106 - * @param key  
107 - * @param list  
108 - */  
109 - public void replace(String key, List<ScheduleRealInfo> list) {  
110 - key = REDIS_KEY_PREFIX + key.replaceAll("-", "");  
111 - redisTemplate.execute(redisUtils.getUpdateCallback(key, list));  
112 - }  
113 -  
114 - /**  
115 - * 删除数据  
116 - *  
117 - * @param key  
118 - */  
119 - public void delete(String lineCode, String rq) {  
120 - String key = REDIS_KEY_PREFIX + (lineCode + ":" + rq).replaceAll("-", "");  
121 - redisTemplate.delete(key);  
122 - }  
123 -  
124 - /**  
125 - * 根据日期和线路编码从redis获取班次  
126 - *  
127 - * @param dateStr  
128 - * @param lineCode  
129 - * @return  
130 - */  
131 - public List<ScheduleRealInfo> read(String dateStr, String lineCode) {  
132 - return redisTemplate.opsForList().range(REDIS_KEY_PREFIX + lineCode + ":" + dateStr, 0, -1);  
133 - }  
134 -  
135 - /**  
136 - * 返回指定日期,公司的实际排班,并按线路_车辆分组  
137 - *  
138 - * @param rq  
139 - * @param companyId  
140 - * @return  
141 - */  
142 - public ArrayListMultimap<String, ScheduleRealInfo> findByDateAndGroupByNbbm(String rq, String companyId) {  
143 - List<String> lineArray = LineBufferData.findCodesByCompany(companyId);  
144 - ArrayListMultimap<String, ScheduleRealInfo> rs = ArrayListMultimap.create();  
145 -  
146 - rq = rq.replaceAll("-", "");  
147 - List<ScheduleRealInfo> list;  
148 - for (String lineCode : lineArray) {  
149 -  
150 - list = read(rq, lineCode);  
151 -  
152 - for (ScheduleRealInfo sch : list) {  
153 - rs.put(sch.getXlBm() + "_" + sch.getClZbh(), sch);  
154 - }  
155 - }  
156 - return rs;  
157 - }  
158 -  
159 - /**  
160 - * 返回指定日期,公司的实际排班,并按线路分组  
161 - *  
162 - * @param rq  
163 - * @param companyId  
164 - * @return  
165 - */  
166 - public ArrayListMultimap<String, ScheduleRealInfo> findByDateAndGroupByLine(String rq, String companyId) {  
167 -  
168 - List<String> lineArray = LineBufferData.findCodesByCompany(companyId);  
169 - ArrayListMultimap<String, ScheduleRealInfo> rs = ArrayListMultimap.create();  
170 -  
171 - rq = rq.replaceAll("-", "");  
172 - List<ScheduleRealInfo> list;  
173 - for (String lineCode : lineArray) {  
174 -  
175 - list = read(rq, lineCode);  
176 -  
177 - for (ScheduleRealInfo sch : list) {  
178 - rs.put(sch.getXlBm(), sch);  
179 - }  
180 - }  
181 - return rs;  
182 - }  
183 -  
184 - /**  
185 - * 返回指定日期,所有实际排班,并按自编号分组  
186 - *  
187 - * @param rq  
188 - * @return  
189 - */  
190 - public ArrayListMultimap<String, ScheduleRealInfo> findByDate(String rq) {  
191 -  
192 - List<Line> lines = LineBufferData.findAll();  
193 - ArrayListMultimap<String, ScheduleRealInfo> rs = ArrayListMultimap.create();  
194 -  
195 - rq = rq.replaceAll("-", "");  
196 - List<ScheduleRealInfo> list;  
197 - for (Line line : lines) {  
198 -  
199 - list = read(rq, line.getLineCode());  
200 -  
201 - for (ScheduleRealInfo sch : list) {  
202 - rs.put(sch.getClZbh(), sch);  
203 - }  
204 - }  
205 - return rs;  
206 - }  
207 -  
208 - @Autowired  
209 - ScheduleRefreshThread scheduleRefreshThread;  
210 - @Autowired  
211 - ScheduleClearThread scheduleClearThread;  
212 -  
213 - @Override  
214 - public void run(String... strings) throws Exception {  
215 - //用子线程去加载,,不要阻塞  
216 - Application.mainServices.schedule(new Runnable() {  
217 - @Override  
218 - public void run() {  
219 - try {  
220 - logger.info("redis 实际排班 start...");  
221 - int cacheDays = Integer.parseInt(ConfigUtil.get("cache.days"));  
222 - //设置key 序列化器  
223 - redisTemplate.setKeySerializer(new StringRedisSerializer());  
224 -  
225 - DateTime dt = new DateTime();  
226 - dt = dt.minusDays(cacheDays);  
227 - List<ScheduleRealInfo> list = scheduleRealInfoRepository.findByDateLT(dt.toString("yyyy-MM-dd"));  
228 - calcTime(list);  
229 - //写入redis  
230 - wirte(list);  
231 - logger.info("redis 实际排班 over...");  
232 - } catch (Exception e) {  
233 - logger.info("redis 实际排班 异常", e);  
234 - }  
235 - }  
236 - }, 5, TimeUnit.SECONDS);  
237 -  
238 - //定时刷新一次当日实际排班  
239 - int minute = 5;  
240 - Application.mainServices.scheduleWithFixedDelay(scheduleRefreshThread, minute, minute, TimeUnit.MINUTES);  
241 - //24小时清理一次实际排班数据  
242 - Application.mainServices.scheduleWithFixedDelay(scheduleClearThread, 24, 24, TimeUnit.HOURS);  
243 - }  
244 -  
245 - public List<ScheduleRealInfo> findByMultiLine(List<String> lineArray, String rq) {  
246 - rq = rq.replaceAll("-", "");  
247 - List<ScheduleRealInfo> rs = new ArrayList<>();  
248 - for (String lineCode : lineArray) {  
249 - rs.addAll(read(rq, lineCode));  
250 - }  
251 - return rs;  
252 - }  
253 -  
254 - @Component  
255 - public static class ScheduleRefreshThread extends Thread {  
256 -  
257 - @Autowired  
258 - ScheduleRealInfoRepository realInfoRepository;  
259 -  
260 - @Autowired  
261 - ScheduleRedisService scheduleRedisService;  
262 -  
263 - @Override  
264 - public void run() {  
265 - try {  
266 - DateTime dt = new DateTime();  
267 - DateTime yesterday = dt.minusDays(2);  
268 -  
269 - String rq = yesterday.toString("yyyy-MM-dd");  
270 - logger.info("refresh lt yesterday ..." + rq + " -start");  
271 - List<ScheduleRealInfo> list = realInfoRepository.findByDateLT(rq);  
272 -  
273 - //计算时间戳  
274 - scheduleRedisService.calcTime(list);  
275 - scheduleRedisService.wirte(list);  
276 -  
277 - logger.info("refresh lt yesterday ..." + rq + " -end### size: " + list.size());  
278 - } catch (Exception e) {  
279 - logger.error("", e);  
280 - }  
281 - }  
282 - }  
283 -  
284 - @Component  
285 - public static class ScheduleClearThread extends Thread {  
286 -  
287 - @Autowired  
288 - ScheduleRedisService scheduleRedisService;  
289 -  
290 - @Override  
291 - public void run() {  
292 - try {  
293 - int cacheDays = Integer.parseInt(ConfigUtil.get("cache.days"));  
294 - DateTime dt = new DateTime();  
295 - dt = dt.minusDays(cacheDays);  
296 - String rq = dt.toString("yyyy-MM-dd");  
297 -  
298 - List<Line> lines = LineBufferData.findAll();  
299 - for (Line line : lines) {  
300 - scheduleRedisService.delete(line.getLineCode(), rq);  
301 - }  
302 - } catch (Exception e) {  
303 - logger.error("", e);  
304 - }  
305 - }  
306 - }  
307 -  
308 - /**  
309 - * ############ 时间戳计算 ##########  
310 - */  
311 - private static DateTimeFormatter fmtyyyyMMddHHmm = DateTimeFormat.forPattern("yyyy-MM-ddHH:mm"),  
312 - fmtHHmm = DateTimeFormat.forPattern("HH:mm");  
313 -  
314 - public void calcTime(List<ScheduleRealInfo> list) {  
315 - if (list.size() == 0)  
316 - return;  
317 -  
318 - //计算真实执行日期 和 时间戳  
319 - for (ScheduleRealInfo sch : list) {  
320 - calcRealDate(BasicData.lineStartTimeMap.get(sch.getXlBm()), sch);  
321 - }  
322 - }  
323 -  
324 - /**  
325 - * @Title: calcRealDate  
326 - * @Description: TODO(计算班次的真实执行日期)  
327 - */  
328 - public void calcRealDate(String startTime, ScheduleRealInfo sch) {  
329 - try {  
330 - if (null == startTime)  
331 - return;  
332 -  
333 - if (null == sch.getBcsj())  
334 - sch.setBcsj(0);  
335 -  
336 - String rq = sch.getScheduleDateStr();  
337 - //计发时间  
338 - sch.setFcsjT(parseTime(rq, sch.getFcsj(), startTime));  
339 - //待发时间  
340 - sch.setDfsjT(parseTime(rq, sch.getDfsj(), startTime));  
341 - //计划终点时间  
342 - if (StringUtils.isEmpty(sch.getZdsj())) {  
343 - sch.setZdsjT(sch.getFcsjT() + (sch.getBcsj() * 60 * 1000));  
344 - sch.setZdsj(fmtHHmm.print(sch.getZdsjT()));  
345 - } else  
346 - sch.setZdsjT(sch.getFcsjT() + (sch.getBcsj() * 60 * 1000));  
347 - //实发时间  
348 - if (StringUtils.isNotEmpty(sch.getFcsjActual()))  
349 - sch.setFcsjActualAll(parseTime(rq, sch.getFcsjActual(), startTime));  
350 -  
351 - //实达时间  
352 - if (StringUtils.isNotEmpty(sch.getZdsjActual()))  
353 - sch.setZdsjActualAll(parseTime(rq, sch.getZdsjActual(), startTime));  
354 - } catch (Exception e) {  
355 - logger.error("", e);  
356 - }  
357 - }  
358 -  
359 - private long parseTime(String rq, String sj, String startTime) {  
360 - long t = fmtyyyyMMddHHmm.parseMillis(rq + sj);  
361 - if (sj.compareTo(startTime) < 0) {  
362 - t += DAY_TIME;  
363 - }  
364 - return t;  
365 - }  
366 -} 1 +package com.bsth.redis;
  2 +
  3 +import com.bsth.Application;
  4 +import com.bsth.common.BasicData;
  5 +import com.bsth.entity.ScheduleRealInfo;
  6 +import com.bsth.redis.util.RedisUtils;
  7 +import com.bsth.repository.ScheduleRealInfoRepository;
  8 +import com.bsth.server_rs.base_info.line.Line;
  9 +import com.bsth.server_rs.base_info.line.buffer.LineBufferData;
  10 +import com.bsth.util.AppProperties;
  11 +import com.bsth.util.ConvertUtil;
  12 +import com.google.common.collect.ArrayListMultimap;
  13 +import org.apache.commons.lang3.StringUtils;
  14 +import org.joda.time.DateTime;
  15 +import org.joda.time.format.DateTimeFormat;
  16 +import org.joda.time.format.DateTimeFormatter;
  17 +import org.slf4j.Logger;
  18 +import org.slf4j.LoggerFactory;
  19 +import org.springframework.beans.factory.annotation.Autowired;
  20 +import org.springframework.boot.CommandLineRunner;
  21 +import org.springframework.core.annotation.Order;
  22 +import org.springframework.data.redis.core.ListOperations;
  23 +import org.springframework.data.redis.core.RedisTemplate;
  24 +import org.springframework.data.redis.serializer.StringRedisSerializer;
  25 +import org.springframework.stereotype.Component;
  26 +import org.springframework.stereotype.Service;
  27 +
  28 +import java.util.ArrayList;
  29 +import java.util.Iterator;
  30 +import java.util.List;
  31 +import java.util.concurrent.TimeUnit;
  32 +
  33 +/**
  34 + * 班次 redis 缓存管理
  35 + * Created by panzhao on 2017/3/13.
  36 + */
  37 +@Service
  38 +@Order(2)
  39 +public class ScheduleRedisService implements CommandLineRunner {
  40 +
  41 + @Autowired
  42 + ScheduleRealInfoRepository scheduleRealInfoRepository;
  43 +
  44 + private final static String REDIS_KEY_PREFIX = "schedule:";
  45 +
  46 + @Autowired
  47 + private RedisTemplate redisTemplate;
  48 +
  49 + @Autowired
  50 + RedisUtils redisUtils;
  51 +
  52 + static Logger logger = LoggerFactory.getLogger(ScheduleRedisService.class);
  53 +
  54 + private final static long DAY_TIME = 1000 * 60 * 60 * 24L;
  55 +
  56 + /**
  57 + * 将一批班次写入redis
  58 + *
  59 + * @param list
  60 + */
  61 + public void wirte(List<ScheduleRealInfo> list) {
  62 + ArrayListMultimap<String, ScheduleRealInfo> multimap;
  63 + try {
  64 + if (list.size() == 0)
  65 + return;
  66 + //按日期和线路分组数据
  67 + Class clazz = ScheduleRealInfo.class;
  68 + multimap = new ConvertUtil().groupMultiList(list, ":", clazz.getDeclaredField("xlBm"), clazz.getDeclaredField("scheduleDateStr"));
  69 +
  70 + //写入redis
  71 + Iterator<String> iterator = multimap.keySet().iterator();
  72 + String key;
  73 + while (iterator.hasNext()) {
  74 + key = iterator.next();
  75 + replace(key, multimap.get(key));
  76 + }
  77 + } catch (Exception e) {
  78 + logger.error("", e);
  79 + }
  80 + }
  81 +
  82 + /**
  83 + * 将 list 与redis里的数据合并
  84 + *
  85 + * @param key
  86 + * @param list
  87 + */
  88 + public void mergeData(String key, List<ScheduleRealInfo> list) {
  89 + key = REDIS_KEY_PREFIX + key.replaceAll("-", "");
  90 +
  91 + ListOperations<String, ScheduleRealInfo> ops = redisTemplate.opsForList();
  92 + List<ScheduleRealInfo> cacheList = ops.range(key, 0, -1);
  93 +
  94 + for (ScheduleRealInfo sch : cacheList) {
  95 + if (!list.contains(sch))
  96 + list.add(sch);
  97 + }
  98 +
  99 + //更新
  100 + redisTemplate.execute(redisUtils.getUpdateCallback(key, list));
  101 + }
  102 +
  103 + /**
  104 + * 覆盖数据
  105 + *
  106 + * @param key
  107 + * @param list
  108 + */
  109 + public void replace(String key, List<ScheduleRealInfo> list) {
  110 + key = REDIS_KEY_PREFIX + key.replaceAll("-", "");
  111 + redisTemplate.execute(redisUtils.getUpdateCallback(key, list));
  112 + }
  113 +
  114 + /**
  115 + * 删除数据
  116 + *
  117 + * @param
  118 + */
  119 + public void delete(String lineCode, String rq) {
  120 + String key = REDIS_KEY_PREFIX + (lineCode + ":" + rq).replaceAll("-", "");
  121 + redisTemplate.delete(key);
  122 + }
  123 +
  124 + /**
  125 + * 根据日期和线路编码从redis获取班次
  126 + *
  127 + * @param dateStr
  128 + * @param lineCode
  129 + * @return
  130 + */
  131 + public List<ScheduleRealInfo> read(String dateStr, String lineCode) {
  132 + return redisTemplate.opsForList().range(REDIS_KEY_PREFIX + lineCode + ":" + dateStr, 0, -1);
  133 + }
  134 +
  135 + /**
  136 + * 返回指定日期,公司的实际排班,并按线路_车辆分组
  137 + *
  138 + * @param rq
  139 + * @param companyId
  140 + * @return
  141 + */
  142 + public ArrayListMultimap<String, ScheduleRealInfo> findByDateAndGroupByNbbm(String rq, String companyId) {
  143 + List<String> lineArray = LineBufferData.findCodesByCompany(companyId);
  144 + ArrayListMultimap<String, ScheduleRealInfo> rs = ArrayListMultimap.create();
  145 +
  146 + rq = rq.replaceAll("-", "");
  147 + List<ScheduleRealInfo> list;
  148 + for (String lineCode : lineArray) {
  149 +
  150 + list = read(rq, lineCode);
  151 +
  152 + for (ScheduleRealInfo sch : list) {
  153 + rs.put(sch.getXlBm() + "_" + sch.getClZbh(), sch);
  154 + }
  155 + }
  156 + return rs;
  157 + }
  158 +
  159 + /**
  160 + * 返回指定日期,公司的实际排班,并按线路分组
  161 + *
  162 + * @param rq
  163 + * @param companyId
  164 + * @return
  165 + */
  166 + public ArrayListMultimap<String, ScheduleRealInfo> findByDateAndGroupByLine(String rq, String companyId) {
  167 +
  168 + List<String> lineArray = LineBufferData.findCodesByCompany(companyId);
  169 + ArrayListMultimap<String, ScheduleRealInfo> rs = ArrayListMultimap.create();
  170 +
  171 + rq = rq.replaceAll("-", "");
  172 + List<ScheduleRealInfo> list;
  173 + for (String lineCode : lineArray) {
  174 +
  175 + list = read(rq, lineCode);
  176 +
  177 + for (ScheduleRealInfo sch : list) {
  178 + rs.put(sch.getXlBm(), sch);
  179 + }
  180 + }
  181 + return rs;
  182 + }
  183 +
  184 + /**
  185 + * 返回指定日期,所有实际排班,并按自编号分组
  186 + *
  187 + * @param rq
  188 + * @return
  189 + */
  190 + public ArrayListMultimap<String, ScheduleRealInfo> findByDate(String rq) {
  191 +
  192 + List<Line> lines = LineBufferData.findAll();
  193 + ArrayListMultimap<String, ScheduleRealInfo> rs = ArrayListMultimap.create();
  194 +
  195 + rq = rq.replaceAll("-", "");
  196 + List<ScheduleRealInfo> list;
  197 + for (Line line : lines) {
  198 +
  199 + list = read(rq, line.getLineCode());
  200 +
  201 + for (ScheduleRealInfo sch : list) {
  202 + rs.put(sch.getClZbh(), sch);
  203 + }
  204 + }
  205 + return rs;
  206 + }
  207 +
  208 + @Autowired
  209 + ScheduleRefreshThread scheduleRefreshThread;
  210 + @Autowired
  211 + ScheduleClearThread scheduleClearThread;
  212 +
  213 + @Override
  214 + public void run(String... strings) throws Exception {
  215 + //用子线程去加载,,不要阻塞
  216 + Application.mainServices.schedule(new Runnable() {
  217 + @Override
  218 + public void run() {
  219 + try {
  220 + logger.info("redis 实际排班 start...");
  221 + int cacheDays = AppProperties.getCacheDays();
  222 + //设置key 序列化器
  223 + redisTemplate.setKeySerializer(new StringRedisSerializer());
  224 +
  225 + DateTime dt = new DateTime();
  226 + dt = dt.minusDays(cacheDays);
  227 + List<ScheduleRealInfo> list = scheduleRealInfoRepository.findByDateLT(dt.toString("yyyy-MM-dd"));
  228 + calcTime(list);
  229 + //写入redis
  230 + wirte(list);
  231 + logger.info("redis 实际排班 over...");
  232 + } catch (Exception e) {
  233 + logger.info("redis 实际排班 异常", e);
  234 + }
  235 + }
  236 + }, 5, TimeUnit.SECONDS);
  237 +
  238 + //定时刷新一次当日实际排班
  239 + int minute = 5;
  240 + Application.mainServices.scheduleWithFixedDelay(scheduleRefreshThread, minute, minute, TimeUnit.MINUTES);
  241 + //24小时清理一次实际排班数据
  242 + Application.mainServices.scheduleWithFixedDelay(scheduleClearThread, 24, 24, TimeUnit.HOURS);
  243 + }
  244 +
  245 + public List<ScheduleRealInfo> findByMultiLine(List<String> lineArray, String rq) {
  246 + rq = rq.replaceAll("-", "");
  247 + List<ScheduleRealInfo> rs = new ArrayList<>();
  248 + for (String lineCode : lineArray) {
  249 + rs.addAll(read(rq, lineCode));
  250 + }
  251 + return rs;
  252 + }
  253 +
  254 + @Component
  255 + public static class ScheduleRefreshThread extends Thread {
  256 +
  257 + @Autowired
  258 + ScheduleRealInfoRepository realInfoRepository;
  259 +
  260 + @Autowired
  261 + ScheduleRedisService scheduleRedisService;
  262 +
  263 + @Override
  264 + public void run() {
  265 + try {
  266 + DateTime dt = new DateTime();
  267 + DateTime yesterday = dt.minusDays(2);
  268 +
  269 + String rq = yesterday.toString("yyyy-MM-dd");
  270 + logger.info("refresh lt yesterday ..." + rq + " -start");
  271 + List<ScheduleRealInfo> list = realInfoRepository.findByDateLT(rq);
  272 +
  273 + //计算时间戳
  274 + scheduleRedisService.calcTime(list);
  275 + scheduleRedisService.wirte(list);
  276 +
  277 + logger.info("refresh lt yesterday ..." + rq + " -end### size: " + list.size());
  278 + } catch (Exception e) {
  279 + logger.error("", e);
  280 + }
  281 + }
  282 + }
  283 +
  284 + @Component
  285 + public static class ScheduleClearThread extends Thread {
  286 +
  287 + @Autowired
  288 + ScheduleRedisService scheduleRedisService;
  289 +
  290 + @Override
  291 + public void run() {
  292 + try {
  293 + int cacheDays = AppProperties.getCacheDays();
  294 + DateTime dt = new DateTime();
  295 + dt = dt.minusDays(cacheDays);
  296 + String rq = dt.toString("yyyy-MM-dd");
  297 +
  298 + List<Line> lines = LineBufferData.findAll();
  299 + for (Line line : lines) {
  300 + scheduleRedisService.delete(line.getLineCode(), rq);
  301 + }
  302 + } catch (Exception e) {
  303 + logger.error("", e);
  304 + }
  305 + }
  306 + }
  307 +
  308 + /**
  309 + * ############ 时间戳计算 ##########
  310 + */
  311 + private static DateTimeFormatter fmtyyyyMMddHHmm = DateTimeFormat.forPattern("yyyy-MM-ddHH:mm"),
  312 + fmtHHmm = DateTimeFormat.forPattern("HH:mm");
  313 +
  314 + public void calcTime(List<ScheduleRealInfo> list) {
  315 + if (list.size() == 0)
  316 + return;
  317 +
  318 + //计算真实执行日期 和 时间戳
  319 + for (ScheduleRealInfo sch : list) {
  320 + calcRealDate(BasicData.lineStartTimeMap.get(sch.getXlBm()), sch);
  321 + }
  322 + }
  323 +
  324 + /**
  325 + * @Title: calcRealDate
  326 + * @Description: TODO(计算班次的真实执行日期)
  327 + */
  328 + public void calcRealDate(String startTime, ScheduleRealInfo sch) {
  329 + try {
  330 + if (null == startTime)
  331 + return;
  332 +
  333 + if (null == sch.getBcsj())
  334 + sch.setBcsj(0);
  335 +
  336 + String rq = sch.getScheduleDateStr();
  337 + //计发时间
  338 + sch.setFcsjT(parseTime(rq, sch.getFcsj(), startTime));
  339 + //待发时间
  340 + sch.setDfsjT(parseTime(rq, sch.getDfsj(), startTime));
  341 + //计划终点时间
  342 + if (StringUtils.isEmpty(sch.getZdsj())) {
  343 + sch.setZdsjT(sch.getFcsjT() + (sch.getBcsj() * 60 * 1000));
  344 + sch.setZdsj(fmtHHmm.print(sch.getZdsjT()));
  345 + } else
  346 + sch.setZdsjT(sch.getFcsjT() + (sch.getBcsj() * 60 * 1000));
  347 + //实发时间
  348 + if (StringUtils.isNotEmpty(sch.getFcsjActual()))
  349 + sch.setFcsjActualAll(parseTime(rq, sch.getFcsjActual(), startTime));
  350 +
  351 + //实达时间
  352 + if (StringUtils.isNotEmpty(sch.getZdsjActual()))
  353 + sch.setZdsjActualAll(parseTime(rq, sch.getZdsjActual(), startTime));
  354 + } catch (Exception e) {
  355 + logger.error("", e);
  356 + }
  357 + }
  358 +
  359 + private long parseTime(String rq, String sj, String startTime) {
  360 + long t = fmtyyyyMMddHHmm.parseMillis(rq + sj);
  361 + if (sj.compareTo(startTime) < 0) {
  362 + t += DAY_TIME;
  363 + }
  364 + return t;
  365 + }
  366 +}
src/main/java/com/bsth/server_rs/directive/DirectiveRestService.java
1 -package com.bsth.server_rs.directive;  
2 -  
3 -import com.alibaba.fastjson.JSON;  
4 -import com.bsth.server_rs.schedule.real.SchRealDataBuffer;  
5 -import com.bsth.util.ConfigUtil;  
6 -import com.bsth.util.HttpClientUtils;  
7 -import org.slf4j.Logger;  
8 -import org.slf4j.LoggerFactory;  
9 -import org.springframework.beans.factory.annotation.Autowired;  
10 -import org.springframework.stereotype.Component;  
11 -import org.springframework.web.bind.annotation.RequestBody;  
12 -  
13 -import javax.ws.rs.*;  
14 -import javax.ws.rs.core.MediaType;  
15 -import java.util.List;  
16 -import java.util.Map;  
17 -  
18 -/**  
19 - * Created by panzhao on 2017/11/10.  
20 - */  
21 -@Component  
22 -@Path("/directive")  
23 -@Produces({MediaType.APPLICATION_JSON})  
24 -public class DirectiveRestService {  
25 -  
26 - static String url;  
27 - static String secretKey;  
28 -  
29 - @Autowired  
30 - SchRealDataBuffer schRealDataBuffer;  
31 - Logger logger = LoggerFactory.getLogger(this.getClass());  
32 -  
33 - static {  
34 - secretKey = ConfigUtil.get("http.control.secret.key");  
35 - url = ConfigUtil.get("http.control.service_data_url") + "/send60Phrase?secretKey=" + secretKey;  
36 - }  
37 -  
38 - @POST  
39 - @Path("/send")  
40 - public int send(@RequestBody Map<String, Object> map){  
41 - try{  
42 - map.put("sender", "接口@系统");  
43 - StringBuilder sb = HttpClientUtils.post(url , JSON.toJSONString(map));  
44 - return Integer.parseInt(sb.toString());  
45 - }catch (Exception e){  
46 - logger.error("", e);  
47 - return -500;  
48 - }  
49 - }  
50 -  
51 - @GET  
52 - @Path("/reply/{msgIds}")  
53 - public List<Map> reply(@PathParam("msgIds") String msgIds){  
54 - try{  
55 - StringBuilder sb = HttpClientUtils.get(url + "&msgIds=" + msgIds);  
56 - return JSON.parseArray(sb.toString(), Map.class);  
57 - }catch (Exception e){  
58 - logger.error("", e);  
59 - return null;  
60 - }  
61 - }  
62 -} 1 +package com.bsth.server_rs.directive;
  2 +
  3 +import com.alibaba.fastjson.JSON;
  4 +import com.bsth.server_rs.schedule.real.SchRealDataBuffer;
  5 +import com.bsth.util.AppProperties;
  6 +import com.bsth.util.HttpClientUtils;
  7 +import org.slf4j.Logger;
  8 +import org.slf4j.LoggerFactory;
  9 +import org.springframework.beans.factory.annotation.Autowired;
  10 +import org.springframework.stereotype.Component;
  11 +import org.springframework.web.bind.annotation.RequestBody;
  12 +
  13 +import javax.ws.rs.*;
  14 +import javax.ws.rs.core.MediaType;
  15 +import java.util.List;
  16 +import java.util.Map;
  17 +
  18 +/**
  19 + * Created by panzhao on 2017/11/10.
  20 + */
  21 +@Component
  22 +@Path("/directive")
  23 +@Produces({MediaType.APPLICATION_JSON})
  24 +public class DirectiveRestService {
  25 +
  26 + static String url = AppProperties.getScheduleDataUrl();
  27 + static String secretKey = AppProperties.getScheduleSecret();
  28 +
  29 + @Autowired
  30 + SchRealDataBuffer schRealDataBuffer;
  31 + Logger logger = LoggerFactory.getLogger(this.getClass());
  32 +
  33 + @POST
  34 + @Path("/send")
  35 + public int send(@RequestBody Map<String, Object> map){
  36 + try{
  37 + map.put("sender", "接口@系统");
  38 + StringBuilder sb = HttpClientUtils.post(url , JSON.toJSONString(map));
  39 + return Integer.parseInt(sb.toString());
  40 + }catch (Exception e){
  41 + logger.error("", e);
  42 + return -500;
  43 + }
  44 + }
  45 +
  46 + @GET
  47 + @Path("/reply/{msgIds}")
  48 + public List<Map> reply(@PathParam("msgIds") String msgIds){
  49 + try{
  50 + StringBuilder sb = HttpClientUtils.get(url + "&msgIds=" + msgIds);
  51 + return JSON.parseArray(sb.toString(), Map.class);
  52 + }catch (Exception e){
  53 + logger.error("", e);
  54 + return null;
  55 + }
  56 + }
  57 +}
src/main/java/com/bsth/server_rs/gps/buffer/GpsRefreshThread.java
1 -package com.bsth.server_rs.gps.buffer;  
2 -  
3 -import com.alibaba.fastjson.JSON;  
4 -import com.alibaba.fastjson.JSONObject;  
5 -import com.bsth.server_rs.gps.entity.GpsEntity;  
6 -import com.bsth.util.ConfigUtil;  
7 -import org.apache.http.HttpEntity;  
8 -import org.apache.http.client.config.RequestConfig;  
9 -import org.apache.http.client.methods.CloseableHttpResponse;  
10 -import org.apache.http.client.methods.HttpGet;  
11 -import org.apache.http.impl.client.CloseableHttpClient;  
12 -import org.apache.http.impl.client.HttpClients;  
13 -import org.slf4j.Logger;  
14 -import org.slf4j.LoggerFactory;  
15 -import org.springframework.stereotype.Component;  
16 -  
17 -import java.io.BufferedReader;  
18 -import java.io.InputStreamReader;  
19 -import java.util.List;  
20 -  
21 -/**  
22 - * Created by panzhao on 2017/3/30.  
23 - */  
24 -@Component  
25 -public class GpsRefreshThread extends Thread{  
26 -  
27 - static String url;  
28 -  
29 - static {  
30 - url = ConfigUtil.get("http.gps.real.url");  
31 - }  
32 -  
33 - Logger logger = LoggerFactory.getLogger(this.getClass());  
34 -  
35 - @Override  
36 - public void run() {  
37 - try {  
38 - CloseableHttpClient httpClient = null;  
39 - List<GpsEntity> rs = null;  
40 - httpClient = HttpClients.createDefault();  
41 - //超时时间  
42 - RequestConfig requestConfig = RequestConfig.custom()  
43 - .setConnectTimeout(2000).setConnectionRequestTimeout(1000)  
44 - .setSocketTimeout(3000).build();  
45 -  
46 - HttpGet get = new HttpGet(url);  
47 - get.setConfig(requestConfig);  
48 -  
49 - CloseableHttpResponse response = httpClient.execute(get);  
50 -  
51 - HttpEntity entity = response.getEntity();  
52 - BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent()));  
53 - StringBuffer stringBuffer = new StringBuffer();  
54 - String str = "";  
55 - while ((str = br.readLine()) != null)  
56 - stringBuffer.append(str);  
57 -  
58 - JSONObject jsonObj = JSON.parseObject(stringBuffer.toString());  
59 -  
60 - if (jsonObj != null)  
61 - rs = JSON.parseArray(jsonObj.getString("data"), GpsEntity.class);  
62 -  
63 - for(GpsEntity gps : rs){  
64 - GpsRealDataBuffer.put(gps);  
65 - }  
66 - }catch (Exception e){  
67 - logger.error("", e);  
68 - }  
69 - }  
70 -} 1 +package com.bsth.server_rs.gps.buffer;
  2 +
  3 +import com.alibaba.fastjson.JSON;
  4 +import com.alibaba.fastjson.JSONObject;
  5 +import com.bsth.server_rs.gps.entity.GpsEntity;
  6 +import com.bsth.util.AppProperties;
  7 +import org.apache.http.HttpEntity;
  8 +import org.apache.http.client.config.RequestConfig;
  9 +import org.apache.http.client.methods.CloseableHttpResponse;
  10 +import org.apache.http.client.methods.HttpGet;
  11 +import org.apache.http.impl.client.CloseableHttpClient;
  12 +import org.apache.http.impl.client.HttpClients;
  13 +import org.slf4j.Logger;
  14 +import org.slf4j.LoggerFactory;
  15 +import org.springframework.stereotype.Component;
  16 +
  17 +import java.io.BufferedReader;
  18 +import java.io.InputStreamReader;
  19 +import java.util.List;
  20 +
  21 +/**
  22 + * Created by panzhao on 2017/3/30.
  23 + */
  24 +@Component
  25 +public class GpsRefreshThread extends Thread{
  26 +
  27 + static String url = AppProperties.getGpsDataUrl();
  28 +
  29 + Logger logger = LoggerFactory.getLogger(this.getClass());
  30 +
  31 + @Override
  32 + public void run() {
  33 + try {
  34 + CloseableHttpClient httpClient = null;
  35 + List<GpsEntity> rs = null;
  36 + httpClient = HttpClients.createDefault();
  37 + //超时时间
  38 + RequestConfig requestConfig = RequestConfig.custom()
  39 + .setConnectTimeout(2000).setConnectionRequestTimeout(1000)
  40 + .setSocketTimeout(3000).build();
  41 +
  42 + HttpGet get = new HttpGet(url);
  43 + get.setConfig(requestConfig);
  44 +
  45 + CloseableHttpResponse response = httpClient.execute(get);
  46 +
  47 + HttpEntity entity = response.getEntity();
  48 + BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent()));
  49 + StringBuffer stringBuffer = new StringBuffer();
  50 + String str = "";
  51 + while ((str = br.readLine()) != null)
  52 + stringBuffer.append(str);
  53 +
  54 + JSONObject jsonObj = JSON.parseObject(stringBuffer.toString());
  55 +
  56 + if (jsonObj != null)
  57 + rs = JSON.parseArray(jsonObj.getString("data"), GpsEntity.class);
  58 +
  59 + for(GpsEntity gps : rs){
  60 + GpsRealDataBuffer.put(gps);
  61 + }
  62 + }catch (Exception e){
  63 + logger.error("", e);
  64 + }
  65 + }
  66 +}
src/main/java/com/bsth/server_rs/schedule/real/ScheduleRealService.java
@@ -3,49 +3,33 @@ package com.bsth.server_rs.schedule.real; @@ -3,49 +3,33 @@ package com.bsth.server_rs.schedule.real;
3 import com.alibaba.fastjson.JSON; 3 import com.alibaba.fastjson.JSON;
4 import com.alibaba.fastjson.JSONArray; 4 import com.alibaba.fastjson.JSONArray;
5 import com.alibaba.fastjson.JSONObject; 5 import com.alibaba.fastjson.JSONObject;
6 -import com.bsth.Application;  
7 import com.bsth.common.BasicData; 6 import com.bsth.common.BasicData;
8 import com.bsth.common.ResponseCode; 7 import com.bsth.common.ResponseCode;
9 import com.bsth.entity.ScheduleRealInfo; 8 import com.bsth.entity.ScheduleRealInfo;
10 -import com.bsth.entity.ScheduleRealInfoVo;  
11 import com.bsth.redis.ScheduleRedisService; 9 import com.bsth.redis.ScheduleRedisService;
12 import com.bsth.repository.ScheduleRealInfoRepository; 10 import com.bsth.repository.ScheduleRealInfoRepository;
13 -import com.bsth.server_rs.base_info.car.Car;  
14 -import com.bsth.server_rs.base_info.car.buffer.CarBufferData;  
15 import com.bsth.server_rs.base_info.line.Line; 11 import com.bsth.server_rs.base_info.line.Line;
16 import com.bsth.server_rs.base_info.line.buffer.LineBufferData; 12 import com.bsth.server_rs.base_info.line.buffer.LineBufferData;
17 -import com.bsth.server_rs.gps.buffer.GpsRealDataBuffer;  
18 -import com.bsth.server_rs.gps.entity.GpsEntity;  
19 import com.bsth.server_rs.schedule.dto.ScheduleCcInfoConfig; 13 import com.bsth.server_rs.schedule.dto.ScheduleCcInfoConfig;
20 import com.bsth.server_rs.schedule.dto.ScheduleInOut; 14 import com.bsth.server_rs.schedule.dto.ScheduleInOut;
21 import com.bsth.server_rs.schedule.dto.ScheduleRealInfoDTO_JK; 15 import com.bsth.server_rs.schedule.dto.ScheduleRealInfoDTO_JK;
22 -import com.bsth.util.ConfigUtil; 16 +import com.bsth.util.AppProperties;
23 import com.bsth.util.HttpClientUtils; 17 import com.bsth.util.HttpClientUtils;
24 -import com.fasterxml.jackson.core.JsonProcessingException;  
25 -import com.fasterxml.jackson.databind.ObjectMapper;  
26 import com.google.common.base.Splitter; 18 import com.google.common.base.Splitter;
27 import org.apache.commons.lang3.StringUtils; 19 import org.apache.commons.lang3.StringUtils;
28 -import org.apache.kafka.clients.producer.ProducerRecord;  
29 import org.joda.time.DateTime; 20 import org.joda.time.DateTime;
30 import org.joda.time.format.DateTimeFormat; 21 import org.joda.time.format.DateTimeFormat;
31 import org.joda.time.format.DateTimeFormatter; 22 import org.joda.time.format.DateTimeFormatter;
32 import org.slf4j.Logger; 23 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory; 24 import org.slf4j.LoggerFactory;
34 -import org.springframework.beans.BeanUtils;  
35 -import org.springframework.beans.factory.InitializingBean;  
36 import org.springframework.beans.factory.annotation.Autowired; 25 import org.springframework.beans.factory.annotation.Autowired;
37 -import org.springframework.kafka.core.KafkaTemplate;  
38 -import org.springframework.kafka.support.SendResult;  
39 -import org.springframework.messaging.Message; 26 +import org.springframework.jdbc.core.JdbcTemplate;
40 import org.springframework.stereotype.Component; 27 import org.springframework.stereotype.Component;
41 -import org.springframework.util.concurrent.ListenableFuture;  
42 -import org.springframework.util.concurrent.ListenableFutureCallback;  
43 28
44 import javax.ws.rs.*; 29 import javax.ws.rs.*;
45 import javax.ws.rs.core.MediaType; 30 import javax.ws.rs.core.MediaType;
46 import java.net.URLEncoder; 31 import java.net.URLEncoder;
47 import java.util.*; 32 import java.util.*;
48 -import java.util.concurrent.*;  
49 33
50 /** 34 /**
51 * Created by panzhao on 2017/8/24. 35 * Created by panzhao on 2017/8/24.
@@ -53,7 +37,7 @@ import java.util.concurrent.*; @@ -53,7 +37,7 @@ import java.util.concurrent.*;
53 @Component 37 @Component
54 @Path("/schedule_real") 38 @Path("/schedule_real")
55 @Produces({MediaType.APPLICATION_JSON}) 39 @Produces({MediaType.APPLICATION_JSON})
56 -public class ScheduleRealService implements InitializingBean { 40 +public class ScheduleRealService {
57 41
58 @Autowired 42 @Autowired
59 ScheduleRedisService redisService; 43 ScheduleRedisService redisService;
@@ -65,22 +49,15 @@ public class ScheduleRealService implements InitializingBean { @@ -65,22 +49,15 @@ public class ScheduleRealService implements InitializingBean {
65 private ScheduleRealInfoRepository scheduleRealInfoRepository; 49 private ScheduleRealInfoRepository scheduleRealInfoRepository;
66 50
67 @Autowired 51 @Autowired
68 - private KafkaTemplate kafkaTemplate; 52 + private JdbcTemplate jdbcTemplate;
69 53
70 Logger logger = LoggerFactory.getLogger(this.getClass()); 54 Logger logger = LoggerFactory.getLogger(this.getClass());
71 55
72 - static String url;  
73 - static String secretKey; 56 + static String url = AppProperties.getScheduleDataUrl();
  57 + static String secretKey = AppProperties.getScheduleSecret();
74 58
75 private volatile long timestamp; 59 private volatile long timestamp;
76 60
77 - private final static int KAFKA_BATCH_SIZE = 100;  
78 -  
79 - static {  
80 - secretKey = ConfigUtil.get("http.control.secret.key");  
81 - url = ConfigUtil.get("http.control.service_data_url");// + "/execSchList?secretKey=" + secretKey;  
82 - }  
83 -  
84 @POST 61 @POST
85 @Path("tcc_tzrc") 62 @Path("tcc_tzrc")
86 public Map<String, Object> tccTzrc(String jsonStr) { 63 public Map<String, Object> tccTzrc(String jsonStr) {
@@ -306,91 +283,16 @@ public class ScheduleRealService implements InitializingBean { @@ -306,91 +283,16 @@ public class ScheduleRealService implements InitializingBean {
306 } 283 }
307 284
308 /** 285 /**
309 - * 获取不在岗的班次信息 286 + * 读取指定日期执行过班次的车辆编码
  287 + *
  288 + * @param rq
  289 + * @return
310 */ 290 */
311 @GET 291 @GET
312 - @Path("/notOnDuty")  
313 - public List<ScheduleRealInfo> notOnDuty() {  
314 - List<ScheduleRealInfo> result = new ArrayList<>();  
315 - Collection<ScheduleRealInfo> collection = schRealDataBuffer.getInOutData();  
316 - long now = System.currentTimeMillis();  
317 - for (ScheduleRealInfo sch : collection) {  
318 - if ("in".equals(sch.getBcType())) {  
319 - continue;  
320 - }  
321 - GpsEntity gpsEntity = GpsRealDataBuffer.get(CarBufferData.findOne(sch.getClZbh()).getEquipmentCode());  
322 - long schIntervalMillis = sch.getDfsjT() - now, gpsIntervalMillis = sch.getDfsjT() - (gpsEntity == null ? 0 : gpsEntity.getTimestamp());  
323 - boolean isSchMatch = schIntervalMillis > 0 && schIntervalMillis < 1200000, isGpsMatch = gpsIntervalMillis > 1200000;  
324 - // 当前时间往后20分钟内的出场班次 且相应车辆在待发时间20分钟内无GPS数据  
325 - if (isSchMatch && isGpsMatch) {  
326 - result.add(sch);  
327 - }  
328 - } 292 + @Path("/insideCodes/{rq}")
  293 + public List<String> insideCodes(@PathParam("rq") String rq) {
  294 + List<String> codes = jdbcTemplate.queryForList("select DISTINCT cl_zbh from bsth_c_s_sp_info_real t where t.schedule_date_str = ? and status = 2", new Object[]{ rq }, String.class);
329 295
330 - return result;  
331 - }  
332 -  
333 - @Override  
334 - public void afterPropertiesSet() throws Exception {  
335 - /*Application.mainServices.scheduleWithFixedDelay(new Runnable() {  
336 - @Override  
337 - public void run() {  
338 - try {  
339 - DateTime dateTime = DateTime.now(), preDate = dateTime.minusDays(1);  
340 - List<String> dates = new ArrayList<>();  
341 - dates.add(dateTime.toString("yyyy-MM-dd"));  
342 - dates.add(preDate.toString("yyyy-MM-dd"));  
343 - if (timestamp == 0) {  
344 - timestamp = dateTime.minusHours(1).getMillis();  
345 - }  
346 - List<ScheduleRealInfo> scheduleRealInfos = scheduleRealInfoRepository.findByDates(dates, new Date(timestamp));  
347 - timestamp = dateTime.getMillis();  
348 -  
349 - Queue<ScheduleRealInfoVo> queue = new ConcurrentLinkedDeque<>();  
350 - for (ScheduleRealInfo sch : scheduleRealInfos) {  
351 - ScheduleRealInfoVo scheduleRealInfoVo = new ScheduleRealInfoVo();  
352 - BeanUtils.copyProperties(sch, scheduleRealInfoVo);  
353 - Car car = CarBufferData.findOne(scheduleRealInfoVo.getClZbh());  
354 - scheduleRealInfoVo.setCarPlate(car == null ? "" : car.getCarPlate());  
355 - queue.add(scheduleRealInfoVo);  
356 - }  
357 -  
358 - int size = scheduleRealInfos.size();  
359 - for (int i = 0, len = size % KAFKA_BATCH_SIZE == 0 ? size / KAFKA_BATCH_SIZE : size / KAFKA_BATCH_SIZE + 1;i < len;i++) {  
360 - List<ScheduleRealInfoVo> scheduleRealInfoVos = new ArrayList<>();  
361 - for (int j = 0; j < KAFKA_BATCH_SIZE;j++) {  
362 - ScheduleRealInfoVo scheduleRealInfoVo = queue.poll();  
363 - if (scheduleRealInfoVo == null) {  
364 - break;  
365 - }  
366 - scheduleRealInfoVos.add(scheduleRealInfoVo);  
367 - }  
368 -  
369 - Map<String, Object> data = new HashMap<>();  
370 - data.put("datatype", "waybill");  
371 - data.put("datas", scheduleRealInfoVos);  
372 -  
373 - ObjectMapper mapper = new ObjectMapper();  
374 - String json = mapper.writeValueAsString(data);  
375 - logger.info(json);  
376 - ListenableFuture<SendResult<String, String>> future = kafkaTemplate.send("PDGJ_JQDD", json);  
377 - future.addCallback(new ListenableFutureCallback<SendResult<String, String>>() {  
378 -  
379 - @Override  
380 - public void onSuccess(SendResult<String, String> result) {  
381 -  
382 - }  
383 -  
384 - @Override  
385 - public void onFailure(Throwable ex) {  
386 - logger.error("kafka发送电子路单异常", ex);  
387 - }  
388 - });  
389 - }  
390 - } catch (Exception e) {  
391 - logger.error("kafka发电子路单调度异常", e);  
392 - }  
393 - }  
394 - }, 30, 240, TimeUnit.SECONDS);*/ 296 + return codes;
395 } 297 }
396 } 298 }
src/main/java/com/bsth/server_rs/schedule/real/thread/ExecSchDataRefreshThread.java
1 -package com.bsth.server_rs.schedule.real.thread;  
2 -  
3 -import com.alibaba.fastjson.JSON;  
4 -import com.alibaba.fastjson.JSONObject;  
5 -import com.bsth.server_rs.schedule.real.SchRealDataBuffer;  
6 -import com.bsth.util.ConfigUtil;  
7 -import com.bsth.util.HttpClientUtils;  
8 -import org.slf4j.Logger;  
9 -import org.slf4j.LoggerFactory;  
10 -import org.springframework.beans.factory.annotation.Autowired;  
11 -import org.springframework.stereotype.Component;  
12 -  
13 -import java.util.HashMap;  
14 -import java.util.List;  
15 -import java.util.Map;  
16 -  
17 -/**  
18 - * 车辆当前执行班次数据刷新线程  
19 - * Created by panzhao on 2017/11/9.  
20 - */  
21 -@Component  
22 -public class ExecSchDataRefreshThread extends Thread{  
23 -  
24 - static String url;  
25 - static String secretKey;  
26 -  
27 - @Autowired  
28 - SchRealDataBuffer schRealDataBuffer;  
29 - Logger logger = LoggerFactory.getLogger(this.getClass());  
30 -  
31 - static {  
32 - secretKey = ConfigUtil.get("http.control.secret.key");  
33 - url = ConfigUtil.get("http.control.service_data_url") + "/execSchList?secretKey=" + secretKey;  
34 - }  
35 -  
36 - @Override  
37 - public void run() {  
38 - try {  
39 - StringBuilder sb = HttpClientUtils.get(url);  
40 - List<JSONObject> list = JSON.parseArray(sb.toString(), JSONObject.class);  
41 -  
42 - Map<String, JSONObject> map = new HashMap<>();  
43 - for(JSONObject obj : list){  
44 - map.put(obj.getString("clZbh"), obj);  
45 - }  
46 -  
47 - if(map.size() > 0)  
48 - schRealDataBuffer.setExecMap(map);  
49 - } catch (Exception e) {  
50 - logger.error("", e);  
51 - }  
52 - }  
53 -} 1 +package com.bsth.server_rs.schedule.real.thread;
  2 +
  3 +import com.alibaba.fastjson.JSON;
  4 +import com.alibaba.fastjson.JSONObject;
  5 +import com.bsth.server_rs.schedule.real.SchRealDataBuffer;
  6 +import com.bsth.util.AppProperties;
  7 +import com.bsth.util.HttpClientUtils;
  8 +import org.slf4j.Logger;
  9 +import org.slf4j.LoggerFactory;
  10 +import org.springframework.beans.factory.annotation.Autowired;
  11 +import org.springframework.stereotype.Component;
  12 +
  13 +import java.util.HashMap;
  14 +import java.util.List;
  15 +import java.util.Map;
  16 +
  17 +/**
  18 + * 车辆当前执行班次数据刷新线程
  19 + * Created by panzhao on 2017/11/9.
  20 + */
  21 +@Component
  22 +public class ExecSchDataRefreshThread extends Thread{
  23 +
  24 + static String url = AppProperties.getScheduleDataUrl();
  25 + static String secretKey = AppProperties.getScheduleSecret();
  26 +
  27 + @Autowired
  28 + SchRealDataBuffer schRealDataBuffer;
  29 + Logger logger = LoggerFactory.getLogger(this.getClass());
  30 +
  31 + @Override
  32 + public void run() {
  33 + try {
  34 + StringBuilder sb = HttpClientUtils.get(url);
  35 + List<JSONObject> list = JSON.parseArray(sb.toString(), JSONObject.class);
  36 +
  37 + Map<String, JSONObject> map = new HashMap<>();
  38 + for(JSONObject obj : list){
  39 + map.put(obj.getString("clZbh"), obj);
  40 + }
  41 +
  42 + if(map.size() > 0)
  43 + schRealDataBuffer.setExecMap(map);
  44 + } catch (Exception e) {
  45 + logger.error("", e);
  46 + }
  47 + }
  48 +}
src/main/java/com/bsth/server_rs/schedule/real/thread/SchInOutDataRefreshThread.java
1 -package com.bsth.server_rs.schedule.real.thread;  
2 -  
3 -import com.alibaba.fastjson.JSON;  
4 -import com.bsth.entity.ScheduleRealInfo;  
5 -import com.bsth.server_rs.schedule.real.SchRealDataBuffer;  
6 -import com.bsth.util.ConfigUtil;  
7 -import com.bsth.util.HttpClientUtils;  
8 -import org.slf4j.Logger;  
9 -import org.slf4j.LoggerFactory;  
10 -import org.springframework.beans.factory.annotation.Autowired;  
11 -import org.springframework.stereotype.Component;  
12 -  
13 -import java.util.List;  
14 -  
15 -/**  
16 - * 从调度系统获取进出场数据线程  
17 - * Created by panzhao on 2017/9/27.  
18 - */  
19 -@Component  
20 -public class SchInOutDataRefreshThread extends Thread {  
21 -  
22 - static String url;  
23 - static String secretKey;  
24 -  
25 - @Autowired  
26 - SchRealDataBuffer schRealDataBuffer;  
27 - Logger logger = LoggerFactory.getLogger(this.getClass());  
28 -  
29 - static {  
30 - secretKey = ConfigUtil.get("http.control.secret.key");  
31 - url = ConfigUtil.get("http.control.service_data_url") + "/findCurrInAndOut?secretKey=" + secretKey;  
32 - }  
33 -  
34 - @Override  
35 - public void run() {  
36 - try {  
37 - StringBuilder sb = HttpClientUtils.get(url);  
38 - List<ScheduleRealInfo> list = JSON.parseArray(sb.toString(), ScheduleRealInfo.class);  
39 -  
40 - if(null != list && list.size() > 0){  
41 - schRealDataBuffer.putInOutData(list);  
42 - logger.info("从调度系统刷新进出场班次: " + list.size());  
43 - }  
44 - } catch (Exception e) {  
45 - logger.error("", e);  
46 - }  
47 - }  
48 -} 1 +package com.bsth.server_rs.schedule.real.thread;
  2 +
  3 +import com.alibaba.fastjson.JSON;
  4 +import com.bsth.entity.ScheduleRealInfo;
  5 +import com.bsth.server_rs.schedule.real.SchRealDataBuffer;
  6 +import com.bsth.util.AppProperties;
  7 +import com.bsth.util.HttpClientUtils;
  8 +import org.slf4j.Logger;
  9 +import org.slf4j.LoggerFactory;
  10 +import org.springframework.beans.factory.annotation.Autowired;
  11 +import org.springframework.stereotype.Component;
  12 +
  13 +import java.util.List;
  14 +
  15 +/**
  16 + * 从调度系统获取进出场数据线程
  17 + * Created by panzhao on 2017/9/27.
  18 + */
  19 +@Component
  20 +public class SchInOutDataRefreshThread extends Thread {
  21 +
  22 + static String url = AppProperties.getScheduleDataUrl();
  23 + static String secretKey = AppProperties.getScheduleSecret();
  24 +
  25 + @Autowired
  26 + SchRealDataBuffer schRealDataBuffer;
  27 + Logger logger = LoggerFactory.getLogger(this.getClass());
  28 +
  29 + @Override
  30 + public void run() {
  31 + try {
  32 + StringBuilder sb = HttpClientUtils.get(url);
  33 + List<ScheduleRealInfo> list = JSON.parseArray(sb.toString(), ScheduleRealInfo.class);
  34 +
  35 + if(null != list && list.size() > 0){
  36 + schRealDataBuffer.putInOutData(list);
  37 + logger.info("从调度系统刷新进出场班次: " + list.size());
  38 + }
  39 + } catch (Exception e) {
  40 + logger.error("", e);
  41 + }
  42 + }
  43 +}
src/main/java/com/bsth/server_ws/util/ControlHttpUtils.java
1 -package com.bsth.server_ws.util;  
2 -  
3 -import com.alibaba.fastjson.JSONArray;  
4 -import com.bsth.entity.ScheduleRealInfo;  
5 -import com.bsth.util.ConfigUtil;  
6 -import org.apache.http.client.config.RequestConfig;  
7 -import org.apache.http.client.methods.CloseableHttpResponse;  
8 -import org.apache.http.client.methods.HttpGet;  
9 -import org.apache.http.impl.client.CloseableHttpClient;  
10 -import org.apache.http.impl.client.HttpClients;  
11 -import org.apache.http.util.EntityUtils;  
12 -import org.slf4j.Logger;  
13 -import org.slf4j.LoggerFactory;  
14 -  
15 -import java.io.IOException;  
16 -import java.util.List;  
17 -  
18 -/**  
19 - * Created by panzhao on 2017/3/15.  
20 - */  
21 -public class ControlHttpUtils {  
22 -  
23 - static Logger logger = LoggerFactory.getLogger(ControlHttpUtils.class);  
24 -  
25 - static String url;  
26 -  
27 - static String secretKey;  
28 -  
29 - static {  
30 - url = ConfigUtil.get("http.control.service_data_url");  
31 - secretKey = ConfigUtil.get("http.control.secret.key");  
32 - }  
33 -  
34 - /**  
35 - * 从调度系统获取班次信息  
36 - *  
37 - * @return  
38 - */  
39 - public static List<ScheduleRealInfo> getCurrentDayPlan(String companyId, String workId) throws IOException {  
40 -  
41 - CloseableHttpClient httpClient = null;  
42 - List<ScheduleRealInfo> rs = null;  
43 - httpClient = HttpClients.createDefault();  
44 - //超时时间  
45 - RequestConfig requestConfig = RequestConfig.custom()  
46 - .setConnectTimeout(2000).setConnectionRequestTimeout(1000)  
47 - .setSocketTimeout(3000).build();  
48 -  
49 - HttpGet get = new HttpGet(url + "/getCurrentDayPlan?companyId=" + companyId + "&workId=" + workId + "&secretKey=" + secretKey);  
50 - get.setConfig(requestConfig);  
51 -  
52 - CloseableHttpResponse response = httpClient.execute(get);  
53 -  
54 - rs = JSONArray.parseArray(EntityUtils.toString(response.getEntity()), ScheduleRealInfo.class);  
55 - return rs;  
56 - }  
57 -  
58 - /**  
59 - * 从调度系统获取进出场班次信息  
60 - * @param comanyId  
61 - * @param jcOrCc  
62 - * @return  
63 - */  
64 - public static List<ScheduleRealInfo> returnJCCInfo(String companyId, String jcOrCc) throws IOException{  
65 -  
66 - String method = jcOrCc.equals("out")?"/returnCCInfo":"/returnJCInfo";  
67 -  
68 - CloseableHttpClient httpClient = null;  
69 - List<ScheduleRealInfo> rs = null;  
70 - httpClient = HttpClients.createDefault();  
71 - //超时时间  
72 - RequestConfig requestConfig = RequestConfig.custom()  
73 - .setConnectTimeout(2000).setConnectionRequestTimeout(1000)  
74 - .setSocketTimeout(3000).build();  
75 -  
76 - HttpGet get = new HttpGet(url + method+"?companyId=" + companyId + "&secretKey=" + secretKey);  
77 - get.setConfig(requestConfig);  
78 -  
79 - CloseableHttpResponse response = httpClient.execute(get);  
80 -  
81 - rs = JSONArray.parseArray(EntityUtils.toString(response.getEntity()), ScheduleRealInfo.class);  
82 - return rs;  
83 - }  
84 -} 1 +package com.bsth.server_ws.util;
  2 +
  3 +import com.alibaba.fastjson.JSONArray;
  4 +import com.bsth.entity.ScheduleRealInfo;
  5 +import com.bsth.util.AppProperties;
  6 +import org.apache.http.client.config.RequestConfig;
  7 +import org.apache.http.client.methods.CloseableHttpResponse;
  8 +import org.apache.http.client.methods.HttpGet;
  9 +import org.apache.http.impl.client.CloseableHttpClient;
  10 +import org.apache.http.impl.client.HttpClients;
  11 +import org.apache.http.util.EntityUtils;
  12 +import org.slf4j.Logger;
  13 +import org.slf4j.LoggerFactory;
  14 +
  15 +import java.io.IOException;
  16 +import java.util.List;
  17 +
  18 +/**
  19 + * Created by panzhao on 2017/3/15.
  20 + */
  21 +public class ControlHttpUtils {
  22 +
  23 + static Logger logger = LoggerFactory.getLogger(ControlHttpUtils.class);
  24 +
  25 + static String url = AppProperties.getScheduleDataUrl();
  26 +
  27 + static String secretKey = AppProperties.getScheduleSecret();
  28 +
  29 + /**
  30 + * 从调度系统获取班次信息
  31 + *
  32 + * @return
  33 + */
  34 + public static List<ScheduleRealInfo> getCurrentDayPlan(String companyId, String workId) throws IOException {
  35 +
  36 + CloseableHttpClient httpClient = null;
  37 + List<ScheduleRealInfo> rs = null;
  38 + httpClient = HttpClients.createDefault();
  39 + //超时时间
  40 + RequestConfig requestConfig = RequestConfig.custom()
  41 + .setConnectTimeout(2000).setConnectionRequestTimeout(1000)
  42 + .setSocketTimeout(3000).build();
  43 +
  44 + HttpGet get = new HttpGet(url + "/getCurrentDayPlan?companyId=" + companyId + "&workId=" + workId + "&secretKey=" + secretKey);
  45 + get.setConfig(requestConfig);
  46 +
  47 + CloseableHttpResponse response = httpClient.execute(get);
  48 +
  49 + rs = JSONArray.parseArray(EntityUtils.toString(response.getEntity()), ScheduleRealInfo.class);
  50 + return rs;
  51 + }
  52 +
  53 + /**
  54 + * 从调度系统获取进出场班次信息
  55 + * @param comanyId
  56 + * @param jcOrCc
  57 + * @return
  58 + */
  59 + public static List<ScheduleRealInfo> returnJCCInfo(String companyId, String jcOrCc) throws IOException{
  60 +
  61 + String method = jcOrCc.equals("out")?"/returnCCInfo":"/returnJCInfo";
  62 +
  63 + CloseableHttpClient httpClient = null;
  64 + List<ScheduleRealInfo> rs = null;
  65 + httpClient = HttpClients.createDefault();
  66 + //超时时间
  67 + RequestConfig requestConfig = RequestConfig.custom()
  68 + .setConnectTimeout(2000).setConnectionRequestTimeout(1000)
  69 + .setSocketTimeout(3000).build();
  70 +
  71 + HttpGet get = new HttpGet(url + method+"?companyId=" + companyId + "&secretKey=" + secretKey);
  72 + get.setConfig(requestConfig);
  73 +
  74 + CloseableHttpResponse response = httpClient.execute(get);
  75 +
  76 + rs = JSONArray.parseArray(EntityUtils.toString(response.getEntity()), ScheduleRealInfo.class);
  77 + return rs;
  78 + }
  79 +}
src/main/java/com/bsth/util/ConfigUtil.java deleted 100644 → 0
1 -package com.bsth.util;  
2 -  
3 -public class ConfigUtil {  
4 -  
5 - static Tools tools;  
6 -  
7 - static{  
8 - tools = new Tools("application.properties");  
9 - String active = tools.getValue("spring.profiles.active");  
10 - tools = new Tools("application-"+active+".properties");  
11 - }  
12 -  
13 - public static String get(String key){  
14 - return tools.getValue(key);  
15 - }  
16 -}  
src/main/java/com/bsth/util/DBUtils_MS.java
1 -package com.bsth.util;  
2 -  
3 -import com.mchange.v2.c3p0.DataSources;  
4 -import org.apache.log4j.Logger;  
5 -  
6 -import javax.sql.DataSource;  
7 -import java.io.FileNotFoundException;  
8 -import java.io.IOException;  
9 -import java.sql.Connection;  
10 -import java.sql.ResultSet;  
11 -import java.sql.SQLException;  
12 -import java.sql.Statement;  
13 -import java.util.HashMap;  
14 -import java.util.Map;  
15 -import java.util.Properties;  
16 -  
17 -/**  
18 - * 网关ms库连接池  
19 - * @author PanZhao  
20 - *  
21 - */  
22 -//@Component  
23 -public class DBUtils_MS {  
24 -  
25 - private static String url = null;  
26 -  
27 - private static String username = null;  
28 -  
29 - private static String pwd = null;  
30 -  
31 - private static DataSource ds_pooled;  
32 -  
33 - static Logger logger = Logger.getLogger(DBUtils_MS.class);  
34 -  
35 - static {  
36 - Properties env = new Properties();  
37 -  
38 - try {  
39 - env.load(DBUtils_MS.class.getClassLoader().getResourceAsStream("ms-jdbc.properties"));  
40 - // 1. 加载驱动类  
41 - Class.forName(env.getProperty("ms.mysql.driver"));  
42 -  
43 - url = env.getProperty("ms.mysql.url");  
44 - username = env.getProperty("ms.mysql.username");  
45 - pwd = env.getProperty("ms.mysql.password");  
46 -  
47 - // 设置连接数据库的配置信息  
48 - DataSource ds_unpooled = DataSources.unpooledDataSource(url,  
49 - username, pwd);  
50 -  
51 - Map<String, Object> pool_conf = new HashMap<String, Object>();  
52 - // 设置最大连接数  
53 - pool_conf.put("maxPoolSize", 10);  
54 -  
55 - pool_conf.put("testConnectionOnCheckout", false);  
56 - //异步检测连接的有效性  
57 - pool_conf.put("testConnectionOnCheckin", true);  
58 - //30秒检测一次  
59 - pool_conf.put("idleConnectionTestPeriod", 30);  
60 - ds_pooled = DataSources.pooledDataSource(ds_unpooled, pool_conf);  
61 - } catch (FileNotFoundException e) {  
62 - logger.error(e.toString());  
63 - e.printStackTrace();  
64 - } catch (IOException e) {  
65 - logger.error(e.toString());  
66 - e.printStackTrace();  
67 - } catch (ClassNotFoundException e) {  
68 - logger.error(e.toString());  
69 - e.printStackTrace();  
70 - } catch (SQLException e) {  
71 - logger.error(e.toString());  
72 - e.printStackTrace();  
73 - }  
74 - }  
75 -  
76 - /**  
77 - * 获取连接对象  
78 - */  
79 - public static Connection getConnection() throws SQLException {  
80 - return ds_pooled.getConnection();  
81 - }  
82 -  
83 - /**  
84 - * 释放连接池资源  
85 - */  
86 - public static void clearup() {  
87 - if (ds_pooled != null) {  
88 - try {  
89 - DataSources.destroy(ds_pooled);  
90 - } catch (SQLException e) {  
91 - logger.error(e.toString());  
92 - e.printStackTrace();  
93 - }  
94 - }  
95 - }  
96 -  
97 - /**  
98 - * 资源关闭  
99 - *  
100 - * @param rs  
101 - * @param stmt  
102 - * @param conn  
103 - */  
104 - public static void close(ResultSet rs, Statement stmt, Connection conn) {  
105 - if (rs != null) {  
106 - try {  
107 - rs.close();  
108 - } catch (SQLException e) {  
109 - logger.error(e.toString());  
110 - e.printStackTrace();  
111 - }  
112 - }  
113 -  
114 - if (stmt != null) {  
115 - try {  
116 - stmt.close();  
117 - } catch (SQLException e) {  
118 - logger.error(e.toString());  
119 - e.printStackTrace();  
120 - }  
121 - }  
122 -  
123 - if (conn != null) {  
124 - try {  
125 - conn.close();  
126 - } catch (SQLException e) {  
127 - logger.error(e.toString());  
128 - e.printStackTrace();  
129 - }  
130 - }  
131 - }  
132 -  
133 - public static DataSource getDataSource(){  
134 - return ds_pooled;  
135 - }  
136 -} 1 +package com.bsth.util;
  2 +
  3 +import com.mchange.v2.c3p0.DataSources;
  4 +import org.apache.log4j.Logger;
  5 +import org.springframework.beans.factory.InitializingBean;
  6 +import org.springframework.beans.factory.annotation.Value;
  7 +import org.springframework.stereotype.Component;
  8 +
  9 +import javax.sql.DataSource;
  10 +import java.io.FileNotFoundException;
  11 +import java.io.IOException;
  12 +import java.sql.Connection;
  13 +import java.sql.ResultSet;
  14 +import java.sql.SQLException;
  15 +import java.sql.Statement;
  16 +import java.util.HashMap;
  17 +import java.util.Map;
  18 +import java.util.Properties;
  19 +
  20 +/**
  21 + * 网关ms库连接池
  22 + * @author PanZhao
  23 + *
  24 + */
  25 +@Component
  26 +public class DBUtils_MS implements InitializingBean {
  27 +
  28 + @Value("${ms.mysql.driver}")
  29 + private String driver;
  30 +
  31 + @Value("${ms.mysql.url}")
  32 + private String url = null;
  33 +
  34 + @Value("${ms.mysql.username}")
  35 + private String username = null;
  36 +
  37 + @Value("${ms.mysql.password}")
  38 + private String pwd = null;
  39 +
  40 + private static DataSource ds_pooled;
  41 +
  42 + static Logger logger = Logger.getLogger(DBUtils_MS.class);
  43 +
  44 + /**
  45 + * 获取连接对象
  46 + */
  47 + public static Connection getConnection() throws SQLException {
  48 + return ds_pooled.getConnection();
  49 + }
  50 +
  51 + /**
  52 + * 释放连接池资源
  53 + */
  54 + public static void clearup() {
  55 + if (ds_pooled != null) {
  56 + try {
  57 + DataSources.destroy(ds_pooled);
  58 + } catch (SQLException e) {
  59 + logger.error(e.toString());
  60 + e.printStackTrace();
  61 + }
  62 + }
  63 + }
  64 +
  65 + /**
  66 + * 资源关闭
  67 + *
  68 + * @param rs
  69 + * @param stmt
  70 + * @param conn
  71 + */
  72 + public static void close(ResultSet rs, Statement stmt, Connection conn) {
  73 + if (rs != null) {
  74 + try {
  75 + rs.close();
  76 + } catch (SQLException e) {
  77 + logger.error(e.toString());
  78 + e.printStackTrace();
  79 + }
  80 + }
  81 +
  82 + if (stmt != null) {
  83 + try {
  84 + stmt.close();
  85 + } catch (SQLException e) {
  86 + logger.error(e.toString());
  87 + e.printStackTrace();
  88 + }
  89 + }
  90 +
  91 + if (conn != null) {
  92 + try {
  93 + conn.close();
  94 + } catch (SQLException e) {
  95 + logger.error(e.toString());
  96 + e.printStackTrace();
  97 + }
  98 + }
  99 + }
  100 +
  101 + public static DataSource getDataSource(){
  102 + return ds_pooled;
  103 + }
  104 +
  105 + @Override
  106 + public void afterPropertiesSet() throws Exception {
  107 + try {
  108 + Class.forName(driver);
  109 + // 设置连接数据库的配置信息
  110 + DataSource ds_un_pooled = DataSources.unpooledDataSource(url, username, pwd);
  111 + Map<String, Object> pool_conf = new HashMap<>();
  112 + // 设置最大连接数
  113 + pool_conf.put("maxPoolSize", 10);
  114 +
  115 + pool_conf.put("testConnectionOnCheckout", false);
  116 + //异步检测连接的有效性
  117 + pool_conf.put("testConnectionOnCheckin", true);
  118 + //30秒检测一次
  119 + pool_conf.put("idleConnectionTestPeriod", 30);
  120 + ds_pooled = DataSources.pooledDataSource(ds_un_pooled, pool_conf);
  121 + } catch (ClassNotFoundException e) {
  122 + logger.error(e.toString());
  123 + } catch (SQLException e) {
  124 + logger.error(e.toString());
  125 + }
  126 + }
  127 +}
src/main/java/com/bsth/util/DBUtils_Xxfb.java deleted 100644 → 0
1 -package com.bsth.util;  
2 -  
3 -import com.mchange.v2.c3p0.DataSources;  
4 -import org.apache.log4j.Logger;  
5 -import org.springframework.jdbc.core.JdbcTemplate;  
6 -  
7 -import javax.sql.DataSource;  
8 -import java.io.FileNotFoundException;  
9 -import java.io.IOException;  
10 -import java.sql.Connection;  
11 -import java.sql.ResultSet;  
12 -import java.sql.SQLException;  
13 -import java.sql.Statement;  
14 -import java.util.HashMap;  
15 -import java.util.Map;  
16 -import java.util.Properties;  
17 -  
18 -/**  
19 - * 网关ms库连接池  
20 - * @author PanZhao  
21 - *  
22 - */  
23 -//@Component  
24 -public class DBUtils_Xxfb {  
25 -  
26 - private static String url = null;  
27 -  
28 - private static String username = null;  
29 -  
30 - private static String pwd = null;  
31 -  
32 - private static DataSource ds_pooled;  
33 -  
34 - static Logger logger = Logger.getLogger(DBUtils_Xxfb.class);  
35 -  
36 - private static JdbcTemplate jdbcTemplate;  
37 -  
38 - static {  
39 - Properties env = new Properties();  
40 -  
41 - try {  
42 - env.load(DBUtils_Xxfb.class.getClassLoader().getResourceAsStream("xxfb-jdbc.properties"));  
43 - // 1. 加载驱动类  
44 - Class.forName(env.getProperty("xxfb.mysql.driver"));  
45 -  
46 - url = env.getProperty("xxfb.mysql.url");  
47 - username = env.getProperty("xxfb.mysql.username");  
48 - pwd = env.getProperty("xxfb.mysql.password");  
49 -  
50 - // 设置连接数据库的配置信息  
51 - DataSource ds_unpooled = DataSources.unpooledDataSource(url,  
52 - username, pwd);  
53 -  
54 - Map<String, Object> pool_conf = new HashMap<String, Object>();  
55 - // 设置最大连接数  
56 - pool_conf.put("maxPoolSize", 10);  
57 -  
58 - pool_conf.put("testConnectionOnCheckout", false);  
59 - //异步检测连接的有效性  
60 - pool_conf.put("testConnectionOnCheckin", true);  
61 - //30秒检测一次  
62 - pool_conf.put("idleConnectionTestPeriod", 30);  
63 - ds_pooled = DataSources.pooledDataSource(ds_unpooled, pool_conf);  
64 - jdbcTemplate = new JdbcTemplate(ds_unpooled);  
65 - } catch (FileNotFoundException e) {  
66 - logger.error(e.toString());  
67 - e.printStackTrace();  
68 - } catch (IOException e) {  
69 - logger.error(e.toString());  
70 - e.printStackTrace();  
71 - } catch (ClassNotFoundException e) {  
72 - logger.error(e.toString());  
73 - e.printStackTrace();  
74 - } catch (SQLException e) {  
75 - logger.error(e.toString());  
76 - e.printStackTrace();  
77 - }  
78 - }  
79 -  
80 - /**  
81 - * 获取连接对象  
82 - */  
83 - public static Connection getConnection() throws SQLException {  
84 - return ds_pooled.getConnection();  
85 - }  
86 -  
87 - /**  
88 - * 释放连接池资源  
89 - */  
90 - public static void clearup() {  
91 - if (ds_pooled != null) {  
92 - try {  
93 - DataSources.destroy(ds_pooled);  
94 - } catch (SQLException e) {  
95 - logger.error(e.toString());  
96 - e.printStackTrace();  
97 - }  
98 - }  
99 - }  
100 -  
101 - /**  
102 - * 资源关闭  
103 - *  
104 - * @param rs  
105 - * @param stmt  
106 - * @param conn  
107 - */  
108 - public static void close(ResultSet rs, Statement stmt, Connection conn) {  
109 - if (rs != null) {  
110 - try {  
111 - rs.close();  
112 - } catch (SQLException e) {  
113 - logger.error(e.toString());  
114 - e.printStackTrace();  
115 - }  
116 - }  
117 -  
118 - if (stmt != null) {  
119 - try {  
120 - stmt.close();  
121 - } catch (SQLException e) {  
122 - logger.error(e.toString());  
123 - e.printStackTrace();  
124 - }  
125 - }  
126 -  
127 - if (conn != null) {  
128 - try {  
129 - conn.close();  
130 - } catch (SQLException e) {  
131 - logger.error(e.toString());  
132 - e.printStackTrace();  
133 - }  
134 - }  
135 - }  
136 -  
137 - public static DataSource getDataSource(){  
138 - return ds_pooled;  
139 - }  
140 -  
141 - public static JdbcTemplate getJdbcTemplate() {  
142 - return jdbcTemplate;  
143 - }  
144 -}  
src/main/resources/application-prod.properties
1 -server.port=9089  
2 -management.port= 9001  
3 -management.address= 127.0.0.1  
4 -  
5 -spring.jpa.hibernate.ddl-auto= none  
6 -spring.jpa.hibernate.naming_strategy= org.hibernate.cfg.ImprovedNamingStrategy  
7 -#DATABASE  
8 -spring.jpa.database= MYSQL  
9 -spring.jpa.show-sql= false  
10 -spring.datasource.driver-class-name= com.mysql.jdbc.Driver  
11 -spring.datasource.url= jdbc:mysql://10.10.150.103:3306/control?useUnicode=true&characterEncoding=utf-8&useSSL=false  
12 -spring.datasource.username= root  
13 -spring.datasource.password= Aa123456  
14 -#DATASOURCE  
15 -spring.datasource.max-active=100  
16 -spring.datasource.max-idle=8  
17 -spring.datasource.min-idle=8  
18 -spring.datasource.initial-size=3  
19 -  
20 -spring.datasource.test-on-borrow=true  
21 -spring.datasource.test-on-connect=true  
22 -spring.datasource.test-on-return=true  
23 -spring.datasource.test-while-idle=true  
24 -spring.datasource.validation-query=select 1  
25 -  
26 -#REDIS  
27 -spring.redis.database=0  
28 -spring.redis.host=10.10.150.103  
29 -spring.redis.password=bsth_control_001  
30 -spring.redis.port=28008  
31 -  
32 -http.control.service_data_url= http://10.10.150.103:9088/companyService  
33 -http.control.secret.key= dVPHJkWUt5FhMT7jrM2dLV7QvlHAmZFd42rs1P0usBx8A7HZki  
34 -  
35 -http.gps.real.url= http://10.10.150.103:8080/transport_server/rtgps/  
36 \ No newline at end of file 1 \ No newline at end of file
  2 +server.port=9089
  3 +management.port= 9001
  4 +management.address= 127.0.0.1
  5 +
  6 +spring.jpa.hibernate.ddl-auto= none
  7 +spring.jpa.hibernate.naming_strategy= org.hibernate.cfg.ImprovedNamingStrategy
  8 +#DATABASE
  9 +spring.jpa.database= MYSQL
  10 +spring.jpa.show-sql= false
  11 +spring.datasource.driver-class-name= com.mysql.jdbc.Driver
  12 +spring.datasource.url= jdbc:mysql://58.34.47.74/control?useUnicode=true&characterEncoding=utf-8&useSSL=false
  13 +spring.datasource.username= root
  14 +spring.datasource.password= A123456ab
  15 +#DATASOURCE
  16 +spring.datasource.max-active=100
  17 +spring.datasource.max-idle=8
  18 +spring.datasource.min-idle=8
  19 +spring.datasource.initial-size=3
  20 +
  21 +spring.datasource.test-on-borrow=true
  22 +spring.datasource.test-on-connect=true
  23 +spring.datasource.test-on-return=true
  24 +spring.datasource.test-while-idle=true
  25 +spring.datasource.validation-query=select 1
  26 +
  27 +#REDIS
  28 +spring.redis.database=0
  29 +spring.redis.host=127.0.0.1
  30 +spring.redis.password=LHjDZkwL2y41IvQk
  31 +spring.redis.port=16379
  32 +
  33 +http.control.service_data_url= http://127.0.0.1:9088/companyService
  34 +http.control.secret.key= dVPHJkWUt5FhMT7jrM2dLV7QvlHAmZFd42rs1P0usBx8A7HZki
  35 +
  36 +http.gps.real.url= http://127.0.0.1:8080/transport_server/rtgps/
  37 +
  38 +ms.mysql.driver= com.mysql.jdbc.Driver
  39 +ms.mysql.url= jdbc:mysql://58.34.47.74/ms?useUnicode=true&characterEncoding=utf-8
  40 +ms.mysql.username= root
  41 +ms.mysql.password= A123456ab
  42 +
  43 +xxfb.mysql.driver= com.mysql.jdbc.Driver
  44 +xxfb.mysql.url= jdbc:mysql://58.34.47.74/info_publish?useUnicode=true&characterEncoding=utf-8
  45 +xxfb.mysql.username= root
  46 +xxfb.mysql.password= A123456ab
37 \ No newline at end of file 47 \ No newline at end of file
src/main/resources/logback.xml
@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 <configuration> 3 <configuration>
4 4
5 <!-- <property resource="application.properties" /> --> 5 <!-- <property resource="application.properties" /> -->
6 - <property name="LOG_BASE" value="/home/control/control_interface_logs" /> 6 + <property name="LOG_BASE" value="control_interface_logs" />
7 <!-- 控制台输出 --> 7 <!-- 控制台输出 -->
8 <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> 8 <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
9 9
src/main/resources/ms-jdbc.properties deleted 100644 → 0
1 -#ms.mysql.driver= com.mysql.jdbc.Driver  
2 -#ms.mysql.url= jdbc:mysql://127.0.0.1:3306/ms?useUnicode=true&characterEncoding=utf-8  
3 -#ms.mysql.username= root  
4 -#ms.mysql.password= panzhao  
5 -  
6 -ms.mysql.driver= com.mysql.jdbc.Driver  
7 -ms.mysql.url= jdbc:mysql://10.10.150.103/ms?useUnicode=true&characterEncoding=utf-8  
8 -ms.mysql.username= root  
9 -ms.mysql.password= Aa123456  
10 \ No newline at end of file 0 \ No newline at end of file