Commit d2379a4c1ee60df43e6c486d7c450666c577db87

Authored by 王通
1 parent c5990340

1.

src/main/java/com/bsth/CXFConfig.java
1   -package com.bsth;
2   -
3   -import com.bsth.server_rs.AuthorizeInterceptor_IN;
4   -import com.bsth.server_rs.base_info.car.CarRestService;
5   -import com.bsth.server_rs.base_info.line.LineRestService;
6   -import com.bsth.server_rs.base_info.person.PersonRestService;
7   -import com.bsth.server_rs.base_info.section.LD_RoadSpeedRestService;
8   -import com.bsth.server_rs.base_info.section.LD_SectionRestService;
9   -import com.bsth.server_rs.base_info.station.StationRestService;
10   -import com.bsth.server_rs.bigdata.BigdateService;
11   -import com.bsth.server_rs.directive.DirectiveRestService;
12   -import com.bsth.server_rs.electric.ElectricService;
13   -import com.bsth.server_rs.exception.AesExceptionMapper;
14   -import com.bsth.server_rs.gps.GpsRestService;
15   -import com.bsth.server_rs.logs.RealLogRestService;
16   -import com.bsth.server_rs.schedule.plan.SchedulePlanService;
17   -import com.bsth.server_rs.schedule.real.ScheduleRealService;
18   -import com.bsth.server_rs.schedule.real.StaffViewRealService;
19   -import com.bsth.server_ws.attendance.AttendanceServiceSoap;
20   -import com.bsth.server_ws.electric_oil.OilServiceSoap;
21   -import com.bsth.server_ws.park_station.CompanyServiceSoap;
22   -import com.bsth.server_ws.waybill.LD_ServiceSoap;
23   -import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
24   -import org.apache.cxf.Bus;
25   -import org.apache.cxf.bus.spring.SpringBus;
26   -import org.apache.cxf.endpoint.Server;
27   -import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
28   -import org.apache.cxf.jaxws.EndpointImpl;
29   -import org.apache.cxf.transport.servlet.CXFServlet;
30   -import org.springframework.beans.factory.annotation.Autowired;
31   -import org.springframework.boot.web.servlet.ServletRegistrationBean;
32   -import org.springframework.context.annotation.Bean;
33   -import org.springframework.context.annotation.Configuration;
34   -import org.springframework.core.Ordered;
35   -
36   -import javax.xml.ws.Endpoint;
37   -import java.util.Arrays;
38   -
39   -/**
40   - * Created by panzhao on 2017/3/9.
41   - */
42   -@Configuration
43   -public class CXFConfig {
44   -
45   - @Bean(name = Bus.DEFAULT_BUS_ID)
46   - public SpringBus springBus() {
47   - return new SpringBus();
48   - }
49   -
50   - @Autowired
51   - CompanyServiceSoap companyServiceSoap;
52   - @Autowired
53   - LD_ServiceSoap ld_serviceSoap;
54   - @Autowired
55   - AttendanceServiceSoap attendanceServiceSoap;
56   - @Autowired
57   - OilServiceSoap oilServiceSoap;
58   -
59   - @Bean
60   - public Endpoint companyEndpoint() {
61   - EndpointImpl endpoint = new EndpointImpl(springBus(), companyServiceSoap);
62   - endpoint.publish("/CompanyService");
63   - //endpoint.getInInterceptors().add(new AuthInterceptor());
64   - return endpoint;
65   - }
66   -
67   - @Bean
68   - public Endpoint ldServiceEndpoint() {
69   - EndpointImpl endpoint = new EndpointImpl(springBus(), ld_serviceSoap);
70   - endpoint.publish("/LD_Service");
71   - //endpoint.getInInterceptors().add(new AuthInterceptor());
72   - return endpoint;
73   - }
74   -
75   - @Bean
76   - public Endpoint attendanceServiceEndpoint() {
77   - EndpointImpl endpoint = new EndpointImpl(springBus(), attendanceServiceSoap);
78   - endpoint.publish("/attendanceService");
79   - //endpoint.getInInterceptors().add(new AuthInterceptor());
80   - return endpoint;
81   - }
82   -
83   - @Bean
84   - public Endpoint electricServiceEndpoint() {
85   - EndpointImpl endpoint = new EndpointImpl(springBus(), oilServiceSoap);
86   - endpoint.publish("/oilServiceSoap");
87   - //endpoint.getInInterceptors().add(new AuthInterceptor());
88   - return endpoint;
89   - }
90   -
91   - @Autowired
92   - ScheduleRealService scheduleRealService;
93   - @Autowired
94   - StationRestService stationRestService;
95   - @Autowired
96   - LD_SectionRestService ldSectionRestService;
97   - @Autowired
98   - SchedulePlanService schedulePlanService;
99   - @Autowired
100   - RealLogRestService realLogRestService;
101   - @Autowired
102   - GpsRestService gpsRestService;
103   - @Autowired
104   - DirectiveRestService directiveRestService;
105   - @Autowired
106   - LD_RoadSpeedRestService ld_roadSpeedRestService;
107   - @Autowired
108   - ElectricService electricService;
109   - @Autowired
110   - BigdateService bigdateService;
111   - @Autowired
112   - StaffViewRealService staffViewRealService;
113   -
114   - @Bean
115   - public Server rsServer() {
116   - JAXRSServerFactoryBean endpoint = new JAXRSServerFactoryBean();
117   - endpoint.setBus(springBus());
118   - endpoint.setAddress("/rest");
119   - endpoint.setServiceBeans(Arrays.<Object>asList(
120   - new LineRestService(),
121   - new CarRestService(),
122   - new PersonRestService(),
123   - gpsRestService,
124   - scheduleRealService,
125   - stationRestService,
126   - ldSectionRestService,
127   - schedulePlanService,
128   - realLogRestService,
129   - directiveRestService,
130   - ld_roadSpeedRestService,
131   - electricService,
132   - staffViewRealService,
133   - bigdateService));
134   - endpoint.setProviders(Arrays.asList(new JacksonJsonProvider(), new AesExceptionMapper()));
135   - //endpoint.setFeatures(Arrays.asList(new Swagger2Feature()));
136   - endpoint.getInInterceptors().add(new AuthorizeInterceptor_IN());
137   - return endpoint.create();
138   - }
139   -
140   - @Bean
141   - public ServletRegistrationBean servletRegistrationBean() {
142   - ServletRegistrationBean bean = new ServletRegistrationBean(new CXFServlet(), "/webservice/*");
143   - bean.setLoadOnStartup(0);
144   - bean.setOrder(Ordered.HIGHEST_PRECEDENCE);
145   - return bean;
146   - }
147   -}
  1 +package com.bsth;
  2 +
  3 +import com.bsth.server_rs.AuthorizeInterceptor_IN;
  4 +import com.bsth.server_rs.base_info.car.CarRestService;
  5 +import com.bsth.server_rs.base_info.line.LineRestService;
  6 +import com.bsth.server_rs.base_info.person.PersonRestService;
  7 +import com.bsth.server_rs.base_info.section.LD_RoadSpeedRestService;
  8 +import com.bsth.server_rs.base_info.section.LD_SectionRestService;
  9 +import com.bsth.server_rs.base_info.station.StationRestService;
  10 +import com.bsth.server_rs.bigdata.BigdateService;
  11 +import com.bsth.server_rs.directive.DirectiveRestService;
  12 +import com.bsth.server_rs.electric.ElectricService;
  13 +import com.bsth.server_rs.exception.AesExceptionMapper;
  14 +import com.bsth.server_rs.gps.GpsRestService;
  15 +import com.bsth.server_rs.logs.RealLogRestService;
  16 +import com.bsth.server_rs.mileage.MileageService;
  17 +import com.bsth.server_rs.schedule.plan.SchedulePlanService;
  18 +import com.bsth.server_rs.schedule.real.ScheduleRealService;
  19 +import com.bsth.server_rs.schedule.real.StaffViewRealService;
  20 +import com.bsth.server_ws.attendance.AttendanceServiceSoap;
  21 +import com.bsth.server_ws.electric_oil.OilServiceSoap;
  22 +import com.bsth.server_ws.park_station.CompanyServiceSoap;
  23 +import com.bsth.server_ws.waybill.LD_ServiceSoap;
  24 +import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
  25 +import org.apache.cxf.Bus;
  26 +import org.apache.cxf.bus.spring.SpringBus;
  27 +import org.apache.cxf.endpoint.Server;
  28 +import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
  29 +import org.apache.cxf.jaxws.EndpointImpl;
  30 +import org.apache.cxf.transport.servlet.CXFServlet;
  31 +import org.springframework.beans.factory.annotation.Autowired;
  32 +import org.springframework.boot.web.servlet.ServletRegistrationBean;
  33 +import org.springframework.context.annotation.Bean;
  34 +import org.springframework.context.annotation.Configuration;
  35 +import org.springframework.core.Ordered;
  36 +
  37 +import javax.xml.ws.Endpoint;
  38 +import java.util.Arrays;
  39 +
  40 +/**
  41 + * Created by panzhao on 2017/3/9.
  42 + */
  43 +@Configuration
  44 +public class CXFConfig {
  45 +
  46 + @Bean(name = Bus.DEFAULT_BUS_ID)
  47 + public SpringBus springBus() {
  48 + return new SpringBus();
  49 + }
  50 +
  51 + @Autowired
  52 + CompanyServiceSoap companyServiceSoap;
  53 + @Autowired
  54 + LD_ServiceSoap ld_serviceSoap;
  55 + @Autowired
  56 + AttendanceServiceSoap attendanceServiceSoap;
  57 + @Autowired
  58 + OilServiceSoap oilServiceSoap;
  59 +
  60 + @Bean
  61 + public Endpoint companyEndpoint() {
  62 + EndpointImpl endpoint = new EndpointImpl(springBus(), companyServiceSoap);
  63 + endpoint.publish("/CompanyService");
  64 + //endpoint.getInInterceptors().add(new AuthInterceptor());
  65 + return endpoint;
  66 + }
  67 +
  68 + @Bean
  69 + public Endpoint ldServiceEndpoint() {
  70 + EndpointImpl endpoint = new EndpointImpl(springBus(), ld_serviceSoap);
  71 + endpoint.publish("/LD_Service");
  72 + //endpoint.getInInterceptors().add(new AuthInterceptor());
  73 + return endpoint;
  74 + }
  75 +
  76 + @Bean
  77 + public Endpoint attendanceServiceEndpoint() {
  78 + EndpointImpl endpoint = new EndpointImpl(springBus(), attendanceServiceSoap);
  79 + endpoint.publish("/attendanceService");
  80 + //endpoint.getInInterceptors().add(new AuthInterceptor());
  81 + return endpoint;
  82 + }
  83 +
  84 + @Bean
  85 + public Endpoint electricServiceEndpoint() {
  86 + EndpointImpl endpoint = new EndpointImpl(springBus(), oilServiceSoap);
  87 + endpoint.publish("/oilServiceSoap");
  88 + //endpoint.getInInterceptors().add(new AuthInterceptor());
  89 + return endpoint;
  90 + }
  91 +
  92 + @Autowired
  93 + ScheduleRealService scheduleRealService;
  94 + @Autowired
  95 + StationRestService stationRestService;
  96 + @Autowired
  97 + LD_SectionRestService ldSectionRestService;
  98 + @Autowired
  99 + SchedulePlanService schedulePlanService;
  100 + @Autowired
  101 + RealLogRestService realLogRestService;
  102 + @Autowired
  103 + GpsRestService gpsRestService;
  104 + @Autowired
  105 + DirectiveRestService directiveRestService;
  106 + @Autowired
  107 + LD_RoadSpeedRestService ld_roadSpeedRestService;
  108 + @Autowired
  109 + ElectricService electricService;
  110 + @Autowired
  111 + BigdateService bigdateService;
  112 + @Autowired
  113 + StaffViewRealService staffViewRealService;
  114 +
  115 + @Autowired
  116 + MileageService mileageService;
  117 +
  118 + @Bean
  119 + public Server rsServer() {
  120 + JAXRSServerFactoryBean endpoint = new JAXRSServerFactoryBean();
  121 + endpoint.setBus(springBus());
  122 + endpoint.setAddress("/rest");
  123 + endpoint.setServiceBeans(Arrays.<Object>asList(
  124 + new LineRestService(),
  125 + new CarRestService(),
  126 + new PersonRestService(),
  127 + gpsRestService,
  128 + scheduleRealService,
  129 + stationRestService,
  130 + ldSectionRestService,
  131 + schedulePlanService,
  132 + realLogRestService,
  133 + directiveRestService,
  134 + ld_roadSpeedRestService,
  135 + electricService,
  136 + staffViewRealService,
  137 + bigdateService,
  138 + mileageService));
  139 + endpoint.setProviders(Arrays.asList(new JacksonJsonProvider(), new AesExceptionMapper()));
  140 + //endpoint.setFeatures(Arrays.asList(new Swagger2Feature()));
  141 + endpoint.getInInterceptors().add(new AuthorizeInterceptor_IN());
  142 + return endpoint.create();
  143 + }
  144 +
  145 + @Bean
  146 + public ServletRegistrationBean servletRegistrationBean() {
  147 + ServletRegistrationBean bean = new ServletRegistrationBean(new CXFServlet(), "/webservice/*");
  148 + bean.setLoadOnStartup(0);
  149 + bean.setOrder(Ordered.HIGHEST_PRECEDENCE);
  150 + return bean;
  151 + }
  152 +}
... ...
src/main/java/com/bsth/StartCommand.java
... ... @@ -2,6 +2,7 @@ package com.bsth;
2 2  
3 3  
4 4 import com.bsth.server_rs.gps.buffer.GpsRefreshThread;
  5 +import com.bsth.server_rs.mileage.MileageCache;
5 6 import com.bsth.server_rs.schedule.real.thread.ExecSchDataRefreshThread;
6 7 import com.bsth.server_rs.schedule.real.thread.SchInOutDataRefreshThread;
7 8 import com.bsth.server_rs.thread.RfidCardInfoPersistenceThread;
... ... @@ -31,6 +32,9 @@ public class StartCommand implements CommandLineRunner{
31 32 @Autowired
32 33 GpsRefreshThread gpsRefreshThread;
33 34  
  35 + @Autowired
  36 + private MileageCache mileageCache;
  37 +
34 38 @Override
35 39 public void run(String... arg0){
36 40  
... ... @@ -45,7 +49,7 @@ public class StartCommand implements CommandLineRunner{
45 49 //定时刷新实时gps缓存
46 50 Application.mainServices.scheduleWithFixedDelay(gpsRefreshThread, 10, 7, TimeUnit.SECONDS);
47 51  
48   -
  52 + mileageCache.load();
49 53 } catch (Exception e) {
50 54 e.printStackTrace();
51 55 }
... ...
src/main/java/com/bsth/entity/DailyMileage.java 0 → 100644
  1 +package com.bsth.entity;
  2 +
  3 +/**
  4 + * @author Hill
  5 + */
  6 +public class DailyMileage {
  7 +
  8 + private String scheduleDate;
  9 +
  10 + /**
  11 + *
  12 + */
  13 + private String lineCode;
  14 +
  15 + private String lineName;
  16 +
  17 + private String vehicle;
  18 +
  19 + private String plate;
  20 +
  21 + private String driver;
  22 +
  23 + private int planCount;
  24 +
  25 + private int realCount;
  26 +
  27 + private double planMileage;
  28 +
  29 + private double realMileage;
  30 +
  31 + private double loseMileage;
  32 +
  33 + private double inParkingMileage;
  34 +
  35 + private double outParkingMileage;
  36 +
  37 + private double outServiceMileage;
  38 +
  39 + public String getScheduleDate() {
  40 + return scheduleDate;
  41 + }
  42 +
  43 + public void setScheduleDate(String scheduleDate) {
  44 + this.scheduleDate = scheduleDate;
  45 + }
  46 +
  47 + public String getLineCode() {
  48 + return lineCode;
  49 + }
  50 +
  51 + public void setLineCode(String lineCode) {
  52 + this.lineCode = lineCode;
  53 + }
  54 +
  55 + public String getLineName() {
  56 + return lineName;
  57 + }
  58 +
  59 + public void setLineName(String lineName) {
  60 + this.lineName = lineName;
  61 + }
  62 +
  63 + public String getVehicle() {
  64 + return vehicle;
  65 + }
  66 +
  67 + public void setVehicle(String vehicle) {
  68 + this.vehicle = vehicle;
  69 + }
  70 +
  71 + public String getPlate() {
  72 + return plate;
  73 + }
  74 +
  75 + public void setPlate(String plate) {
  76 + this.plate = plate;
  77 + }
  78 +
  79 + public String getDriver() {
  80 + return driver;
  81 + }
  82 +
  83 + public void setDriver(String driver) {
  84 + this.driver = driver;
  85 + }
  86 +
  87 + public int getPlanCount() {
  88 + return planCount;
  89 + }
  90 +
  91 + public void setPlanCount(int planCount) {
  92 + this.planCount = planCount;
  93 + }
  94 +
  95 + public int getRealCount() {
  96 + return realCount;
  97 + }
  98 +
  99 + public void setRealCount(int realCount) {
  100 + this.realCount = realCount;
  101 + }
  102 +
  103 + public double getPlanMileage() {
  104 + return planMileage;
  105 + }
  106 +
  107 + public void setPlanMileage(double planMileage) {
  108 + this.planMileage = planMileage;
  109 + }
  110 +
  111 + public double getRealMileage() {
  112 + return realMileage;
  113 + }
  114 +
  115 + public void setRealMileage(double realMileage) {
  116 + this.realMileage = realMileage;
  117 + }
  118 +
  119 + public double getLoseMileage() {
  120 + return loseMileage;
  121 + }
  122 +
  123 + public void setLoseMileage(double loseMileage) {
  124 + this.loseMileage = loseMileage;
  125 + }
  126 +
  127 + public double getInParkingMileage() {
  128 + return inParkingMileage;
  129 + }
  130 +
  131 + public void setInParkingMileage(double inParkingMileage) {
  132 + this.inParkingMileage = inParkingMileage;
  133 + }
  134 +
  135 + public double getOutParkingMileage() {
  136 + return outParkingMileage;
  137 + }
  138 +
  139 + public void setOutParkingMileage(double outParkingMileage) {
  140 + this.outParkingMileage = outParkingMileage;
  141 + }
  142 +
  143 + public double getOutServiceMileage() {
  144 + return outServiceMileage;
  145 + }
  146 +
  147 + public void setOutServiceMileage(double outServiceMileage) {
  148 + this.outServiceMileage = outServiceMileage;
  149 + }
  150 +}
... ...
src/main/java/com/bsth/server_rs/mileage/MileageCache.java 0 → 100644
  1 +package com.bsth.server_rs.mileage;
  2 +
  3 +import com.bsth.entity.DailyMileage;
  4 +import org.joda.time.DateTime;
  5 +import org.springframework.beans.factory.annotation.Autowired;
  6 +import org.springframework.beans.factory.annotation.Value;
  7 +import org.springframework.jdbc.core.BeanPropertyRowMapper;
  8 +import org.springframework.jdbc.core.JdbcTemplate;
  9 +import org.springframework.scheduling.annotation.EnableScheduling;
  10 +import org.springframework.scheduling.annotation.Scheduled;
  11 +import org.springframework.stereotype.Component;
  12 +
  13 +import java.util.ArrayList;
  14 +import java.util.List;
  15 +import java.util.Map;
  16 +import java.util.concurrent.ConcurrentHashMap;
  17 +
  18 +/**
  19 + * @author Hill
  20 + */
  21 +@EnableScheduling
  22 +@Component
  23 +public class MileageCache {
  24 +
  25 + private int days = 5;
  26 +
  27 + private static Map<String, List<DailyMileage>> DATE_MILEAGES = new ConcurrentHashMap<>();
  28 +
  29 + @Autowired
  30 + private JdbcTemplate jdbcTemplate;
  31 +
  32 + @Scheduled(cron = "0 0 10 * * ?")
  33 + public void load() {
  34 + Map<String, List<DailyMileage>> date2mileages = new ConcurrentHashMap<>();
  35 + DateTime dateTime = new DateTime();
  36 + for (int i = 0;i < days;i++) {
  37 + dateTime = dateTime.minusDays(1);
  38 + String date = dateTime.toString("yyyy-MM-dd");
  39 + List<DailyMileage> dailyMileages = jdbcTemplate.query("SELECT * FROM statistics.bsth_c_mileage_statistic WHERE schedule_date = ?", new Object[]{ date }, BeanPropertyRowMapper.newInstance(DailyMileage.class));
  40 + date2mileages.put(date, dailyMileages);
  41 + }
  42 + if (date2mileages.size() > 0) {
  43 + DATE_MILEAGES.clear();
  44 + DATE_MILEAGES = date2mileages;
  45 + }
  46 + }
  47 +
  48 + public static List<DailyMileage> findByDate(String date) {
  49 + List<DailyMileage> result = DATE_MILEAGES.get(date);
  50 + if (result != null) {
  51 + return result;
  52 + }
  53 +
  54 + return new ArrayList<>();
  55 + }
  56 +}
... ...
src/main/java/com/bsth/server_rs/mileage/MileageService.java 0 → 100644
  1 +package com.bsth.server_rs.mileage;
  2 +
  3 +import com.bsth.entity.DailyMileage;
  4 +import org.springframework.stereotype.Service;
  5 +
  6 +import javax.ws.rs.GET;
  7 +import javax.ws.rs.Path;
  8 +import javax.ws.rs.PathParam;
  9 +import java.util.List;
  10 +
  11 +/**
  12 + * @author Hill
  13 + */
  14 +@Service
  15 +public class MileageService {
  16 +
  17 + @GET
  18 + @Path("/mileage/{rq}")
  19 + public List<DailyMileage> findByCompany(@PathParam("rq") String rq) {
  20 + return MileageCache.findByDate(rq);
  21 + }
  22 +}
... ...
src/main/resources/application-prod.properties
... ... @@ -8,9 +8,9 @@ spring.jpa.hibernate.naming_strategy= org.hibernate.cfg.ImprovedNamingStrategy
8 8 spring.jpa.database= MYSQL
9 9 spring.jpa.show-sql= false
10 10 spring.datasource.driver-class-name= com.mysql.jdbc.Driver
11   -spring.datasource.url= jdbc:mysql://192.168.40.82/control?useUnicode=true&characterEncoding=utf-8&useSSL=false
  11 +spring.datasource.url= jdbc:mysql://192.168.50.213/control?useUnicode=true&characterEncoding=utf-8&useSSL=false
12 12 spring.datasource.username= root
13   -spring.datasource.password= 123456
  13 +spring.datasource.password= root2jsp
14 14 #DATASOURCE
15 15 spring.datasource.max-active=100
16 16 spring.datasource.max-idle=8
... ... @@ -29,7 +29,7 @@ spring.redis.host=192.168.50.120
29 29 spring.redis.password=bsth_control_001
30 30 spring.redis.port=28008
31 31  
32   -http.control.service_data_url= http://192.168.40.82:9088/companyService
  32 +http.control.service_data_url= http://192.168.40.88:9088/companyService
33 33 http.control.secret.key= dVPHJkWUt5FhMT7jrM2dLV7QvlHAmZFd42rs1P0usBx8A7HZki
34 34  
35 35 http.gps.real.url= http://192.168.40.82:8080/transport_server/rtgps/
36 36 \ No newline at end of file
... ...