Commit ce88def0275d3be97df47b53c4872a3860b9e0d9

Authored by 王通
1 parent 4acffd9a

1.电科接口数据重生成变化

2.提供IP白名单服务
src/main/java/com/bsth/CXFConfig.java
1 -package com.bsth;  
2 -  
3 -  
4 -import com.bsth.server_rs.AuthorizeInterceptor_IN;  
5 -import com.bsth.server_rs.base_info.car.CarRestService;  
6 -import com.bsth.server_rs.base_info.carpark.CarparkRestService;  
7 -import com.bsth.server_rs.base_info.line.LineRestService;  
8 -import com.bsth.server_rs.base_info.person.PersonRestService;  
9 -import com.bsth.server_rs.base_info.section.LD_RoadSpeedRestService;  
10 -import com.bsth.server_rs.base_info.section.LD_SectionRestService;  
11 -import com.bsth.server_rs.base_info.station.StationRestService;  
12 -import com.bsth.server_rs.bigdata.BigdataService;  
13 -import com.bsth.server_rs.bigdata.BigscreenService;  
14 -import com.bsth.server_rs.departure.DepartureRestService;  
15 -import com.bsth.server_rs.destroy.DestroyDetailRestService;  
16 -import com.bsth.server_rs.directive.DirectiveRestService;  
17 -import com.bsth.server_rs.dks.DksRestService;  
18 -import com.bsth.server_rs.electric.ElectricService;  
19 -import com.bsth.server_rs.exception.AesExceptionMapper;  
20 -import com.bsth.server_rs.gps.GpsRestService;  
21 -import com.bsth.server_rs.logs.RealLogRestService;  
22 -import com.bsth.server_rs.rate.RateService;  
23 -import com.bsth.server_rs.schedule.plan.SchedulePlanService;  
24 -import com.bsth.server_rs.schedule.real.ScheduleRealService;  
25 -import com.bsth.server_rs.schedule.real.StaffViewRealService;  
26 -import com.bsth.server_rs.waybill.WaybillRestService;  
27 -import com.bsth.server_ws.attendance.AttendanceServiceSoap;  
28 -import com.bsth.server_ws.electric_oil.OilServiceSoap;  
29 -import com.bsth.server_ws.park_station.CompanyServiceSoap;  
30 -import com.bsth.server_ws.waybill.LD_ServiceSoap;  
31 -import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;  
32 -import org.apache.cxf.Bus;  
33 -import org.apache.cxf.bus.spring.SpringBus;  
34 -import org.apache.cxf.endpoint.Server;  
35 -import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;  
36 -import org.apache.cxf.jaxws.EndpointImpl;  
37 -import org.apache.cxf.transport.servlet.CXFServlet;  
38 -import org.springframework.beans.factory.annotation.Autowired;  
39 -import org.springframework.boot.web.servlet.ServletRegistrationBean;  
40 -import org.springframework.context.annotation.Bean;  
41 -import org.springframework.context.annotation.Configuration;  
42 -import org.springframework.core.Ordered;  
43 -  
44 -import javax.xml.ws.Endpoint;  
45 -import java.util.Arrays;  
46 -  
47 -/**  
48 - * Created by panzhao on 2017/3/9.  
49 - */  
50 -@Configuration  
51 -public class CXFConfig {  
52 -  
53 - @Bean(name = Bus.DEFAULT_BUS_ID)  
54 - public SpringBus springBus() {  
55 - return new SpringBus();  
56 - }  
57 -  
58 - @Autowired  
59 - CompanyServiceSoap companyServiceSoap;  
60 - @Autowired  
61 - LD_ServiceSoap ld_serviceSoap;  
62 - @Autowired  
63 - AttendanceServiceSoap attendanceServiceSoap;  
64 - @Autowired  
65 - OilServiceSoap oilServiceSoap;  
66 -  
67 - @Bean  
68 - public Endpoint companyEndpoint() {  
69 - EndpointImpl endpoint = new EndpointImpl(springBus(), companyServiceSoap);  
70 - endpoint.publish("/CompanyService");  
71 - //endpoint.getInInterceptors().add(new AuthInterceptor());  
72 - return endpoint;  
73 - }  
74 -  
75 - @Bean  
76 - public Endpoint ldServiceEndpoint() {  
77 - EndpointImpl endpoint = new EndpointImpl(springBus(), ld_serviceSoap);  
78 - endpoint.publish("/LD_Service");  
79 - //endpoint.getInInterceptors().add(new AuthInterceptor());  
80 - return endpoint;  
81 - }  
82 -  
83 - @Bean  
84 - public Endpoint attendanceServiceEndpoint() {  
85 - EndpointImpl endpoint = new EndpointImpl(springBus(), attendanceServiceSoap);  
86 - endpoint.publish("/attendanceService");  
87 - //endpoint.getInInterceptors().add(new AuthInterceptor());  
88 - return endpoint;  
89 - }  
90 -  
91 - @Bean  
92 - public Endpoint electricServiceEndpoint() {  
93 - EndpointImpl endpoint = new EndpointImpl(springBus(), oilServiceSoap);  
94 - endpoint.publish("/oilServiceSoap");  
95 - //endpoint.getInInterceptors().add(new AuthInterceptor());  
96 - return endpoint;  
97 - }  
98 -  
99 - @Autowired  
100 - ScheduleRealService scheduleRealService;  
101 - @Autowired  
102 - StationRestService stationRestService;  
103 - @Autowired  
104 - LD_SectionRestService ldSectionRestService;  
105 - @Autowired  
106 - SchedulePlanService schedulePlanService;  
107 - @Autowired  
108 - RealLogRestService realLogRestService;  
109 - @Autowired  
110 - GpsRestService gpsRestService;  
111 - @Autowired  
112 - WaybillRestService waybillRestService;  
113 - @Autowired  
114 - DirectiveRestService directiveRestService;  
115 - @Autowired  
116 - LD_RoadSpeedRestService ld_roadSpeedRestService;  
117 - @Autowired  
118 - ElectricService electricService;  
119 - @Autowired  
120 - BigdataService bigdataService;  
121 - @Autowired  
122 - BigscreenService bigscreenService;  
123 - @Autowired  
124 - StaffViewRealService staffViewRealService;  
125 - @Autowired  
126 - RateService rateService;  
127 - @Autowired  
128 - private DestroyDetailRestService destroyDetailRestService;  
129 - @Autowired  
130 - private CarparkRestService carparkRestService;  
131 - @Autowired  
132 - private DepartureRestService departureRestService;  
133 - @Autowired  
134 - private DksRestService dksRestService;  
135 -  
136 - @Bean  
137 - public Server rsServer() {  
138 - JAXRSServerFactoryBean endpoint = new JAXRSServerFactoryBean();  
139 - endpoint.setBus(springBus());  
140 - endpoint.setAddress("/rest");  
141 - endpoint.setServiceBeans(Arrays.<Object>asList(  
142 - new LineRestService(),  
143 - new CarRestService(),  
144 - new PersonRestService(),  
145 - gpsRestService,  
146 - waybillRestService,  
147 - scheduleRealService,  
148 - stationRestService,  
149 - ldSectionRestService,  
150 - schedulePlanService,  
151 - realLogRestService,  
152 - directiveRestService,  
153 - ld_roadSpeedRestService,  
154 - electricService,  
155 - staffViewRealService,  
156 - bigdataService,  
157 - bigscreenService,  
158 - rateService,  
159 - destroyDetailRestService,  
160 - carparkRestService,  
161 - departureRestService,  
162 - dksRestService));  
163 - endpoint.setProviders(Arrays.asList(new JacksonJsonProvider(), new AesExceptionMapper()));  
164 - //endpoint.setFeatures(Arrays.asList(new Swagger2Feature()));  
165 - endpoint.getInInterceptors().add(new AuthorizeInterceptor_IN());  
166 - return endpoint.create();  
167 - }  
168 -  
169 - @Bean  
170 - public ServletRegistrationBean servletRegistrationBean() {  
171 - ServletRegistrationBean bean = new ServletRegistrationBean(new CXFServlet(), "/webservice/*");  
172 - bean.setLoadOnStartup(0);  
173 - bean.setOrder(Ordered.HIGHEST_PRECEDENCE);  
174 - return bean;  
175 - }  
176 -} 1 +package com.bsth;
  2 +
  3 +
  4 +import com.bsth.server_rs.AuthorizeInterceptor_IN;
  5 +import com.bsth.server_rs.base_info.car.CarRestService;
  6 +import com.bsth.server_rs.base_info.carpark.CarparkRestService;
  7 +import com.bsth.server_rs.base_info.line.LineRestService;
  8 +import com.bsth.server_rs.base_info.person.PersonRestService;
  9 +import com.bsth.server_rs.base_info.section.LD_RoadSpeedRestService;
  10 +import com.bsth.server_rs.base_info.section.LD_SectionRestService;
  11 +import com.bsth.server_rs.base_info.station.StationRestService;
  12 +import com.bsth.server_rs.bigdata.BigdataService;
  13 +import com.bsth.server_rs.bigdata.BigscreenService;
  14 +import com.bsth.server_rs.departure.DepartureRestService;
  15 +import com.bsth.server_rs.destroy.DestroyDetailRestService;
  16 +import com.bsth.server_rs.directive.DirectiveRestService;
  17 +import com.bsth.server_rs.dks.DksRestService;
  18 +import com.bsth.server_rs.electric.ElectricService;
  19 +import com.bsth.server_rs.exception.AesExceptionMapper;
  20 +import com.bsth.server_rs.gps.GpsRestService;
  21 +import com.bsth.server_rs.logs.RealLogRestService;
  22 +import com.bsth.server_rs.rate.RateService;
  23 +import com.bsth.server_rs.schedule.plan.SchedulePlanService;
  24 +import com.bsth.server_rs.schedule.real.ScheduleRealService;
  25 +import com.bsth.server_rs.schedule.real.StaffViewRealService;
  26 +import com.bsth.server_rs.waybill.WaybillRestService;
  27 +import com.bsth.server_rs.white_ip.WhiteIpRestService;
  28 +import com.bsth.server_ws.attendance.AttendanceServiceSoap;
  29 +import com.bsth.server_ws.electric_oil.OilServiceSoap;
  30 +import com.bsth.server_ws.park_station.CompanyServiceSoap;
  31 +import com.bsth.server_ws.waybill.LD_ServiceSoap;
  32 +import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
  33 +import org.apache.cxf.Bus;
  34 +import org.apache.cxf.bus.spring.SpringBus;
  35 +import org.apache.cxf.endpoint.Server;
  36 +import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
  37 +import org.apache.cxf.jaxws.EndpointImpl;
  38 +import org.apache.cxf.transport.servlet.CXFServlet;
  39 +import org.springframework.beans.factory.annotation.Autowired;
  40 +import org.springframework.boot.web.servlet.ServletRegistrationBean;
  41 +import org.springframework.context.annotation.Bean;
  42 +import org.springframework.context.annotation.Configuration;
  43 +import org.springframework.core.Ordered;
  44 +
  45 +import javax.xml.ws.Endpoint;
  46 +import java.util.Arrays;
  47 +
  48 +/**
  49 + * Created by panzhao on 2017/3/9.
  50 + */
  51 +@Configuration
  52 +public class CXFConfig {
  53 +
  54 + @Bean(name = Bus.DEFAULT_BUS_ID)
  55 + public SpringBus springBus() {
  56 + return new SpringBus();
  57 + }
  58 +
  59 + @Autowired
  60 + CompanyServiceSoap companyServiceSoap;
  61 + @Autowired
  62 + LD_ServiceSoap ld_serviceSoap;
  63 + @Autowired
  64 + AttendanceServiceSoap attendanceServiceSoap;
  65 + @Autowired
  66 + OilServiceSoap oilServiceSoap;
  67 +
  68 + @Bean
  69 + public Endpoint companyEndpoint() {
  70 + EndpointImpl endpoint = new EndpointImpl(springBus(), companyServiceSoap);
  71 + endpoint.publish("/CompanyService");
  72 + //endpoint.getInInterceptors().add(new AuthInterceptor());
  73 + return endpoint;
  74 + }
  75 +
  76 + @Bean
  77 + public Endpoint ldServiceEndpoint() {
  78 + EndpointImpl endpoint = new EndpointImpl(springBus(), ld_serviceSoap);
  79 + endpoint.publish("/LD_Service");
  80 + //endpoint.getInInterceptors().add(new AuthInterceptor());
  81 + return endpoint;
  82 + }
  83 +
  84 + @Bean
  85 + public Endpoint attendanceServiceEndpoint() {
  86 + EndpointImpl endpoint = new EndpointImpl(springBus(), attendanceServiceSoap);
  87 + endpoint.publish("/attendanceService");
  88 + //endpoint.getInInterceptors().add(new AuthInterceptor());
  89 + return endpoint;
  90 + }
  91 +
  92 + @Bean
  93 + public Endpoint electricServiceEndpoint() {
  94 + EndpointImpl endpoint = new EndpointImpl(springBus(), oilServiceSoap);
  95 + endpoint.publish("/oilServiceSoap");
  96 + //endpoint.getInInterceptors().add(new AuthInterceptor());
  97 + return endpoint;
  98 + }
  99 +
  100 + @Autowired
  101 + ScheduleRealService scheduleRealService;
  102 + @Autowired
  103 + StationRestService stationRestService;
  104 + @Autowired
  105 + LD_SectionRestService ldSectionRestService;
  106 + @Autowired
  107 + SchedulePlanService schedulePlanService;
  108 + @Autowired
  109 + RealLogRestService realLogRestService;
  110 + @Autowired
  111 + GpsRestService gpsRestService;
  112 + @Autowired
  113 + WaybillRestService waybillRestService;
  114 + @Autowired
  115 + DirectiveRestService directiveRestService;
  116 + @Autowired
  117 + LD_RoadSpeedRestService ld_roadSpeedRestService;
  118 + @Autowired
  119 + ElectricService electricService;
  120 + @Autowired
  121 + BigdataService bigdataService;
  122 + @Autowired
  123 + BigscreenService bigscreenService;
  124 + @Autowired
  125 + StaffViewRealService staffViewRealService;
  126 + @Autowired
  127 + RateService rateService;
  128 + @Autowired
  129 + private DestroyDetailRestService destroyDetailRestService;
  130 + @Autowired
  131 + private CarparkRestService carparkRestService;
  132 + @Autowired
  133 + private DepartureRestService departureRestService;
  134 + @Autowired
  135 + private DksRestService dksRestService;
  136 + @Autowired
  137 + private WhiteIpRestService whiteIpRestService;
  138 +
  139 + @Bean
  140 + public Server rsServer() {
  141 + JAXRSServerFactoryBean endpoint = new JAXRSServerFactoryBean();
  142 + endpoint.setBus(springBus());
  143 + endpoint.setAddress("/rest");
  144 + endpoint.setServiceBeans(Arrays.<Object>asList(
  145 + new LineRestService(),
  146 + new CarRestService(),
  147 + new PersonRestService(),
  148 + gpsRestService,
  149 + waybillRestService,
  150 + scheduleRealService,
  151 + stationRestService,
  152 + ldSectionRestService,
  153 + schedulePlanService,
  154 + realLogRestService,
  155 + directiveRestService,
  156 + ld_roadSpeedRestService,
  157 + electricService,
  158 + staffViewRealService,
  159 + bigdataService,
  160 + bigscreenService,
  161 + rateService,
  162 + destroyDetailRestService,
  163 + carparkRestService,
  164 + departureRestService,
  165 + dksRestService,
  166 + whiteIpRestService));
  167 + endpoint.setProviders(Arrays.asList(new JacksonJsonProvider(), new AesExceptionMapper()));
  168 + //endpoint.setFeatures(Arrays.asList(new Swagger2Feature()));
  169 + endpoint.getInInterceptors().add(new AuthorizeInterceptor_IN());
  170 + return endpoint.create();
  171 + }
  172 +
  173 + @Bean
  174 + public ServletRegistrationBean servletRegistrationBean() {
  175 + ServletRegistrationBean bean = new ServletRegistrationBean(new CXFServlet(), "/webservice/*");
  176 + bean.setLoadOnStartup(0);
  177 + bean.setOrder(Ordered.HIGHEST_PRECEDENCE);
  178 + return bean;
  179 + }
  180 +}
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.ConfigUtil;
  8 +import com.bsth.util.ConvertUtil;
  9 +import com.google.common.collect.ArrayListMultimap;
  10 +import org.joda.time.DateTime;
  11 +import org.joda.time.format.DateTimeFormat;
  12 +import org.slf4j.Logger;
  13 +import org.slf4j.LoggerFactory;
  14 +import org.springframework.beans.factory.annotation.Autowired;
  15 +import org.springframework.boot.CommandLineRunner;
  16 +import org.springframework.core.annotation.Order;
  17 +import org.springframework.data.redis.core.RedisTemplate;
  18 +import org.springframework.data.redis.serializer.StringRedisSerializer;
  19 +import org.springframework.stereotype.Component;
  20 +import org.springframework.stereotype.Service;
  21 +
  22 +import java.util.*;
  23 +import java.util.concurrent.TimeUnit;
  24 +
  25 +/**
  26 + * 油量数据Redis缓存
  27 + * Created by panzhao on 2017/3/19.
  28 + */
  29 +@Service
  30 +@Order(3)
  31 +public class ElecRedisService implements CommandLineRunner {
  32 +
  33 + @Autowired
  34 + private RedisTemplate redisTemplate;
  35 +
  36 + @Autowired
  37 + ElecInfoRepository elecInfoRepository;
  38 +
  39 + @Autowired
  40 + RedisUtils redisUtils;
  41 +
  42 + static Logger logger = LoggerFactory.getLogger(ElecRedisService.class);
  43 +
  44 + private final static String REDIS_KEY_PREFIX = "elec:";
  45 +
  46 + /**
  47 + * 将油量数据写入redis
  48 + *
  49 + * @param list
  50 + */
  51 + public void wirte(List<ElecInfo> list) {
  52 + ArrayListMultimap<String, ElecInfo> multimap;
  53 + try {
  54 + if (list.size() == 0)
  55 + return;
  56 + //按日期和线路分组数据
  57 + Class clazz = ElecInfo.class;
  58 + multimap = new ConvertUtil().groupMultiList(list, ":", clazz.getDeclaredField("nbbm"), clazz.getDeclaredField("rq"));
  59 +
  60 + //写入redis
  61 + Iterator<String> iterator = multimap.keySet().iterator();
  62 + String key;
  63 + while (iterator.hasNext()) {
  64 + key = iterator.next();
  65 + mergeData(key, multimap.get(key));
  66 + }
  67 + } catch (Exception e) {
  68 + logger.error("", e);
  69 + }
  70 + }
  71 +
  72 + /**
  73 + * 根据车辆和日期获取油耗数据,以 车辆_驾驶员 为key
  74 + *
  75 + * @param nbbmArray
  76 + * @param rq
  77 + * @return
  78 + */
  79 + public ArrayListMultimap findByNbbmGroup(Iterable<String> nbbmArray, String rq) {
  80 + ArrayListMultimap rs = ArrayListMultimap.create();
  81 +
  82 + rq = rq.replaceAll("-", "");
  83 + try {
  84 + List<ElecInfo> list = new ArrayList<>();
  85 + for (String nbbm : nbbmArray) {
  86 + nbbm = nbbm.split("_")[1];
  87 + list.addAll(read(nbbm, rq));
  88 + }
  89 + Class clazz = ElecInfo.class;
  90 + rs = new ConvertUtil().groupMultiList(list, "_", clazz.getDeclaredField("nbbm"), clazz.getDeclaredField("jsy"));
  91 + } catch (Exception e) {
  92 + logger.error("", e);
  93 + }
  94 + return rs;
  95 + }
  96 +
  97 + /**
  98 + * 根据车辆和日期获取油耗数据,以 车辆 为key
  99 + *
  100 + * @param nbbmArray
  101 + * @param rq
  102 + * @return
  103 + */
  104 + public ArrayListMultimap findByNbbmGroup1(Iterable<String> nbbmArray, String rq) {
  105 + ArrayListMultimap rs = ArrayListMultimap.create();
  106 +
  107 + DateTime dateTime = DateTimeFormat.forPattern("yyyy-MM-dd").parseDateTime(rq);
  108 + try {
  109 + List<ElecInfo> list = elecInfoRepository.findByDate(dateTime.toDate());
  110 + Class clazz = ElecInfo.class;
  111 + rs = new ConvertUtil().groupMultiList(list, "_", clazz.getDeclaredField("nbbm"));
  112 + } catch (Exception e) {
  113 + logger.error("", e);
  114 + }
  115 + return rs;
  116 + }
  117 +
  118 + public List<ElecInfo> read(String nbbm, String rq) {
  119 + return redisTemplate.opsForList().range(REDIS_KEY_PREFIX + nbbm + ":" + rq, 0, -1);
  120 + }
  121 +
  122 + /**
  123 + * 将 list 与redis里的数据合并
  124 + *
  125 + * @param key
  126 + * @param list
  127 + */
  128 + public void mergeData(String key, List<ElecInfo> list) {
  129 + key = REDIS_KEY_PREFIX + key;
  130 +
  131 + //更新 直接覆盖更新
  132 + redisTemplate.execute(redisUtils.getUpdateCallback(key, list));
  133 + }
  134 +
  135 + @Autowired
  136 + ElecRefreshThread elecRefreshThread;
  137 +
  138 + @Override
  139 + public void run(String... strings) throws Exception {
  140 + Application.mainServices.schedule(new Runnable() {
  141 + @Override
  142 + public void run() {
  143 + //启动加载油耗缓存
  144 + synchData(null);
  145 + }
  146 + }, 30, TimeUnit.SECONDS);
  147 +
  148 +
  149 + //定时刷新油耗信息
  150 + Application.mainServices.scheduleWithFixedDelay(elecRefreshThread, 60 * 40, 60 * 40, TimeUnit.SECONDS);
  151 + }
  152 +
  153 + /**
  154 + * 和数据库同步数据
  155 + */
  156 + public void synchData(Integer days) {
  157 + int cacheDays = Integer.parseInt(ConfigUtil.get("cache.days"));
  158 + if (null != days && days < cacheDays)
  159 + cacheDays = days;
  160 + //设置key 序列化器
  161 + redisTemplate.setKeySerializer(new StringRedisSerializer());
  162 +
  163 + DateTime dt = new DateTime();
  164 + dt = dt.withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0).minusDays(cacheDays);
  165 + List<ElecInfo> list = elecInfoRepository.findByDateLT(dt.toDate());
  166 + //写入redis
  167 + wirte(list);
  168 + logger.info("刷新电耗数据, days: " + cacheDays + " -size: " + list.size() + " -LT: " + dt.toString("yyyy-MM-dd"));
  169 + }
  170 +
  171 + @Component
  172 + public static class ElecRefreshThread extends Thread {
  173 +
  174 + @Autowired
  175 + ElecRedisService elecRedisService;
  176 +
  177 + @Override
  178 + public void run() {
  179 + try {
  180 + elecRedisService.synchData(5);
  181 + } catch (Exception e) {
  182 + logger.error("", e);
  183 + }
  184 + }
  185 + }
  186 +}
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.ConfigUtil;
  8 +import com.bsth.util.ConvertUtil;
  9 +import com.google.common.collect.ArrayListMultimap;
  10 +import org.joda.time.DateTime;
  11 +import org.joda.time.format.DateTimeFormat;
  12 +import org.slf4j.Logger;
  13 +import org.slf4j.LoggerFactory;
  14 +import org.springframework.beans.factory.annotation.Autowired;
  15 +import org.springframework.boot.CommandLineRunner;
  16 +import org.springframework.core.annotation.Order;
  17 +import org.springframework.data.redis.core.RedisTemplate;
  18 +import org.springframework.data.redis.serializer.StringRedisSerializer;
  19 +import org.springframework.stereotype.Component;
  20 +import org.springframework.stereotype.Service;
  21 +
  22 +import java.util.*;
  23 +import java.util.concurrent.TimeUnit;
  24 +
  25 +/**
  26 + * 油量数据Redis缓存
  27 + * Created by panzhao on 2017/3/19.
  28 + */
  29 +@Service
  30 +@Order(3)
  31 +public class OilRedisService implements CommandLineRunner {
  32 +
  33 + @Autowired
  34 + private RedisTemplate redisTemplate;
  35 +
  36 + @Autowired
  37 + OilInfoRepository oilInfoRepository;
  38 +
  39 + @Autowired
  40 + RedisUtils redisUtils;
  41 +
  42 + static Logger logger = LoggerFactory.getLogger(OilRedisService.class);
  43 +
  44 + private final static String REDIS_KEY_PREFIX = "oil:";
  45 +
  46 + /**
  47 + * 将油量数据写入redis
  48 + *
  49 + * @param list
  50 + */
  51 + public void wirte(List<OilInfo> list) {
  52 + ArrayListMultimap<String, OilInfo> multimap;
  53 + try {
  54 + if (list.size() == 0)
  55 + return;
  56 + //按日期和线路分组数据
  57 + Class clazz = OilInfo.class;
  58 + multimap = new ConvertUtil().groupMultiList(list, ":", clazz.getDeclaredField("nbbm"), clazz.getDeclaredField("rq"));
  59 +
  60 + //写入redis
  61 + Iterator<String> iterator = multimap.keySet().iterator();
  62 + String key;
  63 + while (iterator.hasNext()) {
  64 + key = iterator.next();
  65 + mergeData(key, multimap.get(key));
  66 + }
  67 + } catch (Exception e) {
  68 + logger.error("", e);
  69 + }
  70 + }
  71 +
  72 + /**
  73 + * 根据车辆和日期获取油耗数据,以 车辆_驾驶员 为key
  74 + *
  75 + * @param nbbmArray
  76 + * @param rq
  77 + * @return
  78 + */
  79 + public ArrayListMultimap<String, OilInfo> findByNbbmGroup(Iterable<String> nbbmArray, String rq) {
  80 + ArrayListMultimap<String, OilInfo> rs = ArrayListMultimap.create();
  81 +
  82 + rq = rq.replaceAll("-", "");
  83 + try {
  84 + List<OilInfo> list = new ArrayList<>();
  85 + Set<String> nbbms = new HashSet<>();
  86 + for (String nbbm : nbbmArray) {
  87 + nbbm = nbbm.split("_")[1];
  88 + if (!nbbms.contains(nbbm)) {
  89 + nbbms.add(nbbm);
  90 + list.addAll(read(nbbm, rq));
  91 + }
  92 + }
  93 + Class clazz = OilInfo.class;
  94 + rs = new ConvertUtil().groupMultiList(list, "_", clazz.getDeclaredField("nbbm"), clazz.getDeclaredField("jsy"));
  95 + } catch (Exception e) {
  96 + logger.error("", e);
  97 + }
  98 + return rs;
  99 + }
  100 +
  101 + /**
  102 + * 根据车辆和日期获取油耗数据,以 车辆_驾驶员 为key
  103 + *
  104 + * @param nbbmArray
  105 + * @param rq
  106 + * @return
  107 + */
  108 + public Map<String, OilInfo> findByNbbmGroupRaw(Iterable<String> nbbmArray, String rq) {
  109 + Map<String, OilInfo> rs = new HashMap<>();
  110 +
  111 + rq = rq.replaceAll("-", "");
  112 + try {
  113 + List<OilInfo> list = new ArrayList<>();
  114 + for (String nbbm : nbbmArray) {
  115 + nbbm = nbbm.split("_")[1];
  116 + list.addAll(read(nbbm, rq));
  117 + }
  118 + Class clazz = OilInfo.class;
  119 + rs = new ConvertUtil().groupList(list, "_", clazz.getDeclaredField("nbbm"), clazz.getDeclaredField("jsy"));
  120 + } catch (Exception e) {
  121 + logger.error("", e);
  122 + }
  123 + return rs;
  124 + }
  125 +
  126 + /**
  127 + * 根据车辆和日期获取油耗数据,以 车辆 为key
  128 + *
  129 + * @param nbbmArray
  130 + * @param rq
  131 + * @return
  132 + */
  133 + public ArrayListMultimap<String, OilInfo> findByNbbmGroup1(Iterable<String> nbbmArray, String rq) {
  134 + ArrayListMultimap<String, OilInfo> rs = ArrayListMultimap.create();
  135 +
  136 + DateTime dateTime = DateTimeFormat.forPattern("yyyy-MM-dd").parseDateTime(rq);
  137 + try {
  138 + List<OilInfo> list = oilInfoRepository.findByDate(dateTime.toDate());
  139 + Class clazz = OilInfo.class;
  140 + rs = new ConvertUtil().groupMultiList(list, "_", clazz.getDeclaredField("nbbm"));
  141 + } catch (Exception e) {
  142 + logger.error("", e);
  143 + }
  144 + return rs;
  145 + }
  146 +
  147 + public List<OilInfo> read(String nbbm, String rq) {
  148 + return redisTemplate.opsForList().range(REDIS_KEY_PREFIX + nbbm + ":" + rq, 0, -1);
  149 + }
  150 +
  151 + /**
  152 + * 将 list 与redis里的数据合并
  153 + *
  154 + * @param key
  155 + * @param list
  156 + */
  157 + public void mergeData(String key, List<OilInfo> list) {
  158 + key = REDIS_KEY_PREFIX + key;
  159 +
  160 + //更新 直接覆盖更新
  161 + redisTemplate.execute(redisUtils.getUpdateCallback(key, list));
  162 + }
  163 +
  164 + @Autowired
  165 + OilRefreshThread oilRefreshThread;
  166 +
  167 + @Override
  168 + public void run(String... strings) throws Exception {
  169 + Application.mainServices.schedule(new Runnable() {
  170 + @Override
  171 + public void run() {
  172 + //启动加载油耗缓存
  173 + synchData(null);
  174 + }
  175 + }, 30, TimeUnit.SECONDS);
  176 +
  177 +
  178 + //定时刷新油耗信息
  179 + Application.mainServices.scheduleWithFixedDelay(oilRefreshThread, 60 * 40, 60 * 40, TimeUnit.SECONDS);
  180 + }
  181 +
  182 + /**
  183 + * 和数据库同步数据
  184 + */
  185 + public void synchData(Integer days) {
  186 + int cacheDays = Integer.parseInt(ConfigUtil.get("cache.days"));
  187 + if (null != days && days < cacheDays)
  188 + cacheDays = days;
  189 + //设置key 序列化器
  190 + redisTemplate.setKeySerializer(new StringRedisSerializer());
  191 +
  192 + DateTime dt = new DateTime();
  193 + dt = dt.withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0).minusDays(cacheDays);
  194 + List<OilInfo> list = oilInfoRepository.findByDateLT(dt.toDate());
  195 + //写入redis
  196 + wirte(list);
  197 + logger.info("刷新油耗数据, days: " + cacheDays + " -size: " + list.size() + " -LT: " + dt.toString("yyyy-MM-dd"));
  198 + }
  199 +
  200 + @Component
  201 + public static class OilRefreshThread extends Thread {
  202 +
  203 + @Autowired
  204 + OilRedisService oilRedisService;
  205 +
  206 + @Override
  207 + public void run() {
  208 + try {
  209 + oilRedisService.synchData(5);
  210 + } catch (Exception e) {
  211 + logger.error("", e);
  212 + }
  213 + }
  214 + }
  215 +}
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.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 + List<ScheduleRealInfo> list = scheduleRealInfoRepository.findAll(rq);
  196 + for (Line line : lines) {
  197 + for (ScheduleRealInfo sch : list) {
  198 + rs.put(sch.getClZbh(), sch);
  199 + }
  200 + }
  201 + return rs;
  202 + }
  203 +
  204 + @Autowired
  205 + ScheduleRefreshThread scheduleRefreshThread;
  206 + @Autowired
  207 + ScheduleClearThread scheduleClearThread;
  208 +
  209 + @Override
  210 + public void run(String... strings) throws Exception {
  211 + //用子线程去加载,,不要阻塞
  212 + Application.mainServices.schedule(new Runnable() {
  213 + @Override
  214 + public void run() {
  215 + try {
  216 + logger.info("redis 实际排班 start...");
  217 + int cacheDays = Integer.parseInt(ConfigUtil.get("cache.days"));
  218 + //设置key 序列化器
  219 + redisTemplate.setKeySerializer(new StringRedisSerializer());
  220 +
  221 + DateTime dt = new DateTime();
  222 + dt = dt.minusDays(cacheDays);
  223 + List<ScheduleRealInfo> list = scheduleRealInfoRepository.findByDateLT(dt.toString("yyyy-MM-dd"));
  224 + calcTime(list);
  225 + //写入redis
  226 + wirte(list);
  227 + logger.info("redis 实际排班 over...");
  228 + } catch (Exception e) {
  229 + logger.info("redis 实际排班 异常", e);
  230 + }
  231 + }
  232 + }, 5, TimeUnit.SECONDS);
  233 +
  234 + //定时刷新一次当日实际排班
  235 + int minute = 5;
  236 + Application.mainServices.scheduleWithFixedDelay(scheduleRefreshThread, minute, minute, TimeUnit.MINUTES);
  237 + //24小时清理一次实际排班数据
  238 + Application.mainServices.scheduleWithFixedDelay(scheduleClearThread, 24, 24, TimeUnit.HOURS);
  239 + }
  240 +
  241 + public List<ScheduleRealInfo> findByMultiLine(List<String> lineArray, String rq) {
  242 + rq = rq.replaceAll("-", "");
  243 + List<ScheduleRealInfo> rs = new ArrayList<>();
  244 + for (String lineCode : lineArray) {
  245 + rs.addAll(read(rq, lineCode));
  246 + }
  247 + return rs;
  248 + }
  249 +
  250 + @Component
  251 + public static class ScheduleRefreshThread extends Thread {
  252 +
  253 + @Autowired
  254 + ScheduleRealInfoRepository realInfoRepository;
  255 +
  256 + @Autowired
  257 + ScheduleRedisService scheduleRedisService;
  258 +
  259 + @Override
  260 + public void run() {
  261 + try {
  262 + DateTime dt = new DateTime();
  263 + DateTime yesterday = dt.minusDays(2);
  264 +
  265 + String rq = yesterday.toString("yyyy-MM-dd");
  266 + logger.info("refresh lt yesterday ..." + rq + " -start");
  267 + List<ScheduleRealInfo> list = realInfoRepository.findByDateLT(rq);
  268 +
  269 + //计算时间戳
  270 + scheduleRedisService.calcTime(list);
  271 + scheduleRedisService.wirte(list);
  272 +
  273 + logger.info("refresh lt yesterday ..." + rq + " -end### size: " + list.size());
  274 + } catch (Exception e) {
  275 + logger.error("", e);
  276 + }
  277 + }
  278 + }
  279 +
  280 + @Component
  281 + public static class ScheduleClearThread extends Thread {
  282 +
  283 + @Autowired
  284 + ScheduleRedisService scheduleRedisService;
  285 +
  286 + @Override
  287 + public void run() {
  288 + try {
  289 + int cacheDays = Integer.parseInt(ConfigUtil.get("cache.days"));
  290 + DateTime dt = new DateTime();
  291 + dt = dt.minusDays(cacheDays);
  292 + String rq = dt.toString("yyyy-MM-dd");
  293 +
  294 + List<Line> lines = LineBufferData.findAll();
  295 + for (Line line : lines) {
  296 + scheduleRedisService.delete(line.getLineCode(), rq);
  297 + }
  298 + } catch (Exception e) {
  299 + logger.error("", e);
  300 + }
  301 + }
  302 + }
  303 +
  304 + /**
  305 + * ############ 时间戳计算 ##########
  306 + */
  307 + private static DateTimeFormatter fmtyyyyMMddHHmm = DateTimeFormat.forPattern("yyyy-MM-ddHH:mm"),
  308 + fmtHHmm = DateTimeFormat.forPattern("HH:mm");
  309 +
  310 + public void calcTime(List<ScheduleRealInfo> list) {
  311 + if (list.size() == 0)
  312 + return;
  313 +
  314 + //计算真实执行日期 和 时间戳
  315 + for (ScheduleRealInfo sch : list) {
  316 + calcRealDate(BasicData.lineStartTimeMap.get(sch.getXlBm()), sch);
  317 + }
  318 + }
  319 +
  320 + /**
  321 + * @Title: calcRealDate
  322 + * @Description: TODO(计算班次的真实执行日期)
  323 + */
  324 + public void calcRealDate(String startTime, ScheduleRealInfo sch) {
  325 + try {
  326 + if (null == startTime)
  327 + return;
  328 +
  329 + if (null == sch.getBcsj())
  330 + sch.setBcsj(0);
  331 +
  332 + String rq = sch.getScheduleDateStr();
  333 + //计发时间
  334 + sch.setFcsjT(parseTime(rq, sch.getFcsj(), startTime));
  335 + //待发时间
  336 + sch.setDfsjT(parseTime(rq, sch.getDfsj(), startTime));
  337 + //计划终点时间
  338 + if (StringUtils.isEmpty(sch.getZdsj())) {
  339 + sch.setZdsjT(sch.getFcsjT() + (sch.getBcsj() * 60 * 1000));
  340 + sch.setZdsj(fmtHHmm.print(sch.getZdsjT()));
  341 + } else
  342 + sch.setZdsjT(sch.getFcsjT() + (sch.getBcsj() * 60 * 1000));
  343 + //实发时间
  344 + if (StringUtils.isNotEmpty(sch.getFcsjActual()))
  345 + sch.setFcsjActualAll(parseTime(rq, sch.getFcsjActual(), startTime));
  346 +
  347 + //实达时间
  348 + if (StringUtils.isNotEmpty(sch.getZdsjActual()))
  349 + sch.setZdsjActualAll(parseTime(rq, sch.getZdsjActual(), startTime));
  350 + } catch (Exception e) {
  351 + logger.error("", e);
  352 + }
  353 + }
  354 +
  355 + private long parseTime(String rq, String sj, String startTime) {
  356 + long t = fmtyyyyMMddHHmm.parseMillis(rq + sj);
  357 + if (sj.compareTo(startTime) < 0) {
  358 + t += DAY_TIME;
  359 + }
  360 + return t;
  361 + }
  362 +}
src/main/java/com/bsth/repository/ElecInfoRepository.java
1 -package com.bsth.repository;  
2 -  
3 -import com.bsth.entity.ElecInfo;  
4 -import org.springframework.data.jpa.repository.Query;  
5 -import org.springframework.data.repository.PagingAndSortingRepository;  
6 -import org.springframework.stereotype.Repository;  
7 -  
8 -import java.util.Date;  
9 -import java.util.List;  
10 -  
11 -/**  
12 - * Created by panzhao on 2017/3/19.  
13 - */  
14 -@Repository  
15 -public interface ElecInfoRepository extends PagingAndSortingRepository<ElecInfo, Long> {  
16 -  
17 -  
18 - @Query("select elec from ElecInfo elec where elec.rq>?1")  
19 - List<ElecInfo> findByDateLT(Date rq);  
20 -} 1 +package com.bsth.repository;
  2 +
  3 +import com.bsth.entity.ElecInfo;
  4 +import org.springframework.data.jpa.repository.Query;
  5 +import org.springframework.data.repository.PagingAndSortingRepository;
  6 +import org.springframework.stereotype.Repository;
  7 +
  8 +import java.util.Date;
  9 +import java.util.List;
  10 +
  11 +/**
  12 + * Created by panzhao on 2017/3/19.
  13 + */
  14 +@Repository
  15 +public interface ElecInfoRepository extends PagingAndSortingRepository<ElecInfo, Long> {
  16 +
  17 +
  18 + @Query("select elec from ElecInfo elec where elec.rq>?1")
  19 + List<ElecInfo> findByDateLT(Date rq);
  20 +
  21 + @Query("select elec from ElecInfo elec where elec.rq=?1")
  22 + List<ElecInfo> findByDate(Date rq);
  23 +}
src/main/java/com/bsth/repository/OilInfoRepository.java
1 -package com.bsth.repository;  
2 -  
3 -import com.bsth.entity.OilInfo;  
4 -import org.springframework.data.jpa.repository.Query;  
5 -import org.springframework.data.repository.PagingAndSortingRepository;  
6 -import org.springframework.stereotype.Repository;  
7 -  
8 -import java.util.Date;  
9 -import java.util.List;  
10 -  
11 -/**  
12 - * Created by panzhao on 2017/3/19.  
13 - */  
14 -@Repository  
15 -public interface OilInfoRepository extends PagingAndSortingRepository<OilInfo, Long> {  
16 -  
17 -  
18 - @Query("select oil from OilInfo oil where oil.rq>?1")  
19 - List<OilInfo> findByDateLT(Date rq);  
20 -} 1 +package com.bsth.repository;
  2 +
  3 +import com.bsth.entity.OilInfo;
  4 +import org.springframework.data.jpa.repository.Query;
  5 +import org.springframework.data.repository.PagingAndSortingRepository;
  6 +import org.springframework.stereotype.Repository;
  7 +
  8 +import java.util.Date;
  9 +import java.util.List;
  10 +
  11 +/**
  12 + * Created by panzhao on 2017/3/19.
  13 + */
  14 +@Repository
  15 +public interface OilInfoRepository extends PagingAndSortingRepository<OilInfo, Long> {
  16 +
  17 +
  18 + @Query("select oil from OilInfo oil where oil.rq>?1")
  19 + List<OilInfo> findByDateLT(Date rq);
  20 +
  21 + @Query("select oil from OilInfo oil where oil.rq=?1")
  22 + List<OilInfo> findByDate(Date rq);
  23 +}
src/main/java/com/bsth/server_rs/destroy/DestroyDetailRestService.java
@@ -57,6 +57,7 @@ public class DestroyDetailRestService { @@ -57,6 +57,7 @@ public class DestroyDetailRestService {
57 COMPANY_CODE2NAME.put("26_1", "南汇一分"); 57 COMPANY_CODE2NAME.put("26_1", "南汇一分");
58 COMPANY_CODE2NAME.put("26_6", "南汇六分"); 58 COMPANY_CODE2NAME.put("26_6", "南汇六分");
59 COMPANY_CODE2NAME.put("26_3", "南汇三分"); 59 COMPANY_CODE2NAME.put("26_3", "南汇三分");
  60 + COMPANY_CODE2NAME.put("26_7", "南汇五分");
60 COMPANY_CODE2NAME.put("26_4", "南汇维修公司"); 61 COMPANY_CODE2NAME.put("26_4", "南汇维修公司");
61 COMPANY_CODE2NAME.put("55_2", "上南三分公司"); 62 COMPANY_CODE2NAME.put("55_2", "上南三分公司");
62 COMPANY_CODE2NAME.put("55_3", "上南六分公司"); 63 COMPANY_CODE2NAME.put("55_3", "上南六分公司");
src/main/java/com/bsth/server_rs/dks/DksRestService.java
@@ -428,6 +428,7 @@ public class DksRestService { @@ -428,6 +428,7 @@ public class DksRestService {
428 if (scheduleRealInfos.size() == 0) { 428 if (scheduleRealInfos.size() == 0) {
429 continue; 429 continue;
430 } 430 }
  431 + ScheduleRealInfo scheduleRealInfo = scheduleRealInfos.get(0);
431 BusMileage busMileage = new BusMileage(); 432 BusMileage busMileage = new BusMileage();
432 busMileage.setScheduleDate(rq); 433 busMileage.setScheduleDate(rq);
433 busMileage.setNbbm(nbbm); 434 busMileage.setNbbm(nbbm);
@@ -452,6 +453,8 @@ public class DksRestService { @@ -452,6 +453,8 @@ public class DksRestService {
452 } 453 }
453 busMileage.setYh(yh); 454 busMileage.setYh(yh);
454 busMileage.setDh(dh); 455 busMileage.setDh(dh);
  456 + busMileage.setCompany(scheduleRealInfo.getGsName());
  457 + busMileage.setCompanyCode(scheduleRealInfo.getGsBm());
455 458
456 busMileages.add(busMileage); 459 busMileages.add(busMileage);
457 } 460 }
src/main/java/com/bsth/server_ws/util/WSDataConver.java
@@ -70,6 +70,8 @@ public class WSDataConver { @@ -70,6 +70,8 @@ public class WSDataConver {
70 gsMap.put("26_2", "南汇二分"); 70 gsMap.put("26_2", "南汇二分");
71 gsMap.put("26_1", "南汇一分"); 71 gsMap.put("26_1", "南汇一分");
72 gsMap.put("26_4", "南汇维修公司"); 72 gsMap.put("26_4", "南汇维修公司");
  73 + gsMap.put("26_6", "南汇六分");
  74 + gsMap.put("26_7", "南汇五分");
73 } 75 }
74 76
75 /** 77 /**