Commit 6597099090b4391d16bd5a87d5376bfc32af017d

Authored by 王通
1 parent 1b24416b

1./external相关接口

Too many changes to show.

To preserve performance only 11 of 23 files are displayed.

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.line.LineRestService;  
7 -import com.bsth.server_rs.base_info.person.PersonRestService;  
8 -import com.bsth.server_rs.base_info.section.LD_RoadSpeedRestService;  
9 -import com.bsth.server_rs.base_info.section.LD_SectionRestService;  
10 -import com.bsth.server_rs.base_info.station.StationRestService;  
11 -import com.bsth.server_rs.bigdata.BigdataService;  
12 -import com.bsth.server_rs.directive.DirectiveRestService;  
13 -import com.bsth.server_rs.electric.ElectricService;  
14 -import com.bsth.server_rs.exception.AesExceptionMapper;  
15 -import com.bsth.server_rs.gps.GpsRestService;  
16 -import com.bsth.server_rs.logs.RealLogRestService;  
17 -import com.bsth.server_rs.number.NumberService;  
18 -import com.bsth.server_rs.schedule.plan.SchedulePlanService;  
19 -import com.bsth.server_rs.schedule.real.ScheduleRealService;  
20 -import com.bsth.server_rs.schedule.real.StaffViewRealService;  
21 -import com.bsth.server_rs.waybill.WaybillRestService;  
22 -import com.bsth.server_ws.attendance.AttendanceServiceSoap;  
23 -import com.bsth.server_ws.electric_oil.OilServiceSoap;  
24 -import com.bsth.server_ws.park_station.CompanyServiceSoap;  
25 -import com.bsth.server_ws.waybill.LD_ServiceSoap;  
26 -import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;  
27 -import org.apache.cxf.Bus;  
28 -import org.apache.cxf.bus.spring.SpringBus;  
29 -import org.apache.cxf.endpoint.Server;  
30 -import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;  
31 -import org.apache.cxf.jaxws.EndpointImpl;  
32 -import org.apache.cxf.transport.servlet.CXFServlet;  
33 -import org.springframework.beans.factory.annotation.Autowired;  
34 -import org.springframework.boot.web.servlet.ServletRegistrationBean;  
35 -import org.springframework.context.annotation.Bean;  
36 -import org.springframework.context.annotation.Configuration;  
37 -import org.springframework.core.Ordered;  
38 -  
39 -import javax.xml.ws.Endpoint;  
40 -import java.util.Arrays;  
41 -  
42 -/**  
43 - * Created by panzhao on 2017/3/9.  
44 - */  
45 -@Configuration  
46 -public class CXFConfig {  
47 -  
48 - @Bean(name = Bus.DEFAULT_BUS_ID)  
49 - public SpringBus springBus() {  
50 - return new SpringBus();  
51 - }  
52 -  
53 - @Autowired  
54 - CompanyServiceSoap companyServiceSoap;  
55 - @Autowired  
56 - LD_ServiceSoap ld_serviceSoap;  
57 - @Autowired  
58 - AttendanceServiceSoap attendanceServiceSoap;  
59 - @Autowired  
60 - OilServiceSoap oilServiceSoap;  
61 -  
62 - @Bean  
63 - public Endpoint companyEndpoint() {  
64 - EndpointImpl endpoint = new EndpointImpl(springBus(), companyServiceSoap);  
65 - endpoint.publish("/CompanyService");  
66 - //endpoint.getInInterceptors().add(new AuthInterceptor());  
67 - return endpoint;  
68 - }  
69 -  
70 - @Bean  
71 - public Endpoint ldServiceEndpoint() {  
72 - EndpointImpl endpoint = new EndpointImpl(springBus(), ld_serviceSoap);  
73 - endpoint.publish("/LD_Service");  
74 - //endpoint.getInInterceptors().add(new AuthInterceptor());  
75 - return endpoint;  
76 - }  
77 -  
78 - @Bean  
79 - public Endpoint attendanceServiceEndpoint() {  
80 - EndpointImpl endpoint = new EndpointImpl(springBus(), attendanceServiceSoap);  
81 - endpoint.publish("/attendanceService");  
82 - //endpoint.getInInterceptors().add(new AuthInterceptor());  
83 - return endpoint;  
84 - }  
85 -  
86 - @Bean  
87 - public Endpoint electricServiceEndpoint() {  
88 - EndpointImpl endpoint = new EndpointImpl(springBus(), oilServiceSoap);  
89 - endpoint.publish("/oilServiceSoap");  
90 - //endpoint.getInInterceptors().add(new AuthInterceptor());  
91 - return endpoint;  
92 - }  
93 -  
94 - @Autowired  
95 - ScheduleRealService scheduleRealService;  
96 - @Autowired  
97 - StationRestService stationRestService;  
98 - @Autowired  
99 - LD_SectionRestService ldSectionRestService;  
100 - @Autowired  
101 - SchedulePlanService schedulePlanService;  
102 - @Autowired  
103 - RealLogRestService realLogRestService;  
104 - @Autowired  
105 - GpsRestService gpsRestService;  
106 - @Autowired  
107 - WaybillRestService waybillRestService;  
108 - @Autowired  
109 - DirectiveRestService directiveRestService;  
110 - @Autowired  
111 - LD_RoadSpeedRestService ld_roadSpeedRestService;  
112 - @Autowired  
113 - ElectricService electricService;  
114 - @Autowired  
115 - BigdataService bigdataService;  
116 - @Autowired  
117 - NumberService numberService;  
118 - @Autowired  
119 - StaffViewRealService staffViewRealService;  
120 -  
121 - @Bean  
122 - public Server rsServer() {  
123 - JAXRSServerFactoryBean endpoint = new JAXRSServerFactoryBean();  
124 - endpoint.setBus(springBus());  
125 - endpoint.setAddress("/rest");  
126 - endpoint.setServiceBeans(Arrays.<Object>asList(  
127 - new LineRestService(),  
128 - new CarRestService(),  
129 - new PersonRestService(),  
130 - gpsRestService,  
131 - waybillRestService,  
132 - scheduleRealService,  
133 - stationRestService,  
134 - ldSectionRestService,  
135 - schedulePlanService,  
136 - realLogRestService,  
137 - directiveRestService,  
138 - ld_roadSpeedRestService,  
139 - electricService,  
140 - staffViewRealService,  
141 - bigdataService,  
142 - numberService));  
143 - endpoint.setProviders(Arrays.asList(new JacksonJsonProvider(), new AesExceptionMapper()));  
144 - //endpoint.setFeatures(Arrays.asList(new Swagger2Feature()));  
145 - endpoint.getInInterceptors().add(new AuthorizeInterceptor_IN());  
146 - return endpoint.create();  
147 - }  
148 -  
149 - @Bean  
150 - public ServletRegistrationBean servletRegistrationBean() {  
151 - ServletRegistrationBean bean = new ServletRegistrationBean(new CXFServlet(), "/webservice/*");  
152 - bean.setLoadOnStartup(0);  
153 - bean.setOrder(Ordered.HIGHEST_PRECEDENCE);  
154 - return bean;  
155 - }  
156 -} 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.line.LineRestService;
  7 +import com.bsth.server_rs.base_info.person.PersonRestService;
  8 +import com.bsth.server_rs.base_info.section.LD_RoadSpeedRestService;
  9 +import com.bsth.server_rs.base_info.section.LD_SectionRestService;
  10 +import com.bsth.server_rs.base_info.station.StationRestService;
  11 +import com.bsth.server_rs.bigdata.BigdataService;
  12 +import com.bsth.server_rs.directive.DirectiveRestService;
  13 +import com.bsth.server_rs.electric.ElectricService;
  14 +import com.bsth.server_rs.exception.AesExceptionMapper;
  15 +import com.bsth.server_rs.external.ExternalService;
  16 +import com.bsth.server_rs.gps.GpsRestService;
  17 +import com.bsth.server_rs.logs.RealLogRestService;
  18 +import com.bsth.server_rs.number.NumberService;
  19 +import com.bsth.server_rs.schedule.plan.SchedulePlanService;
  20 +import com.bsth.server_rs.schedule.real.ScheduleRealService;
  21 +import com.bsth.server_rs.schedule.real.StaffViewRealService;
  22 +import com.bsth.server_rs.waybill.WaybillRestService;
  23 +import com.bsth.server_ws.attendance.AttendanceServiceSoap;
  24 +import com.bsth.server_ws.electric_oil.OilServiceSoap;
  25 +import com.bsth.server_ws.park_station.CompanyServiceSoap;
  26 +import com.bsth.server_ws.waybill.LD_ServiceSoap;
  27 +import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
  28 +import org.apache.cxf.Bus;
  29 +import org.apache.cxf.bus.spring.SpringBus;
  30 +import org.apache.cxf.endpoint.Server;
  31 +import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
  32 +import org.apache.cxf.jaxws.EndpointImpl;
  33 +import org.apache.cxf.transport.servlet.CXFServlet;
  34 +import org.springframework.beans.factory.annotation.Autowired;
  35 +import org.springframework.boot.web.servlet.ServletRegistrationBean;
  36 +import org.springframework.context.annotation.Bean;
  37 +import org.springframework.context.annotation.Configuration;
  38 +import org.springframework.core.Ordered;
  39 +
  40 +import javax.xml.ws.Endpoint;
  41 +import java.util.Arrays;
  42 +
  43 +/**
  44 + * Created by panzhao on 2017/3/9.
  45 + */
  46 +@Configuration
  47 +public class CXFConfig {
  48 +
  49 + @Bean(name = Bus.DEFAULT_BUS_ID)
  50 + public SpringBus springBus() {
  51 + return new SpringBus();
  52 + }
  53 +
  54 + @Autowired
  55 + CompanyServiceSoap companyServiceSoap;
  56 + @Autowired
  57 + LD_ServiceSoap ld_serviceSoap;
  58 + @Autowired
  59 + AttendanceServiceSoap attendanceServiceSoap;
  60 + @Autowired
  61 + OilServiceSoap oilServiceSoap;
  62 +
  63 + @Bean
  64 + public Endpoint companyEndpoint() {
  65 + EndpointImpl endpoint = new EndpointImpl(springBus(), companyServiceSoap);
  66 + endpoint.publish("/CompanyService");
  67 + //endpoint.getInInterceptors().add(new AuthInterceptor());
  68 + return endpoint;
  69 + }
  70 +
  71 + @Bean
  72 + public Endpoint ldServiceEndpoint() {
  73 + EndpointImpl endpoint = new EndpointImpl(springBus(), ld_serviceSoap);
  74 + endpoint.publish("/LD_Service");
  75 + //endpoint.getInInterceptors().add(new AuthInterceptor());
  76 + return endpoint;
  77 + }
  78 +
  79 + @Bean
  80 + public Endpoint attendanceServiceEndpoint() {
  81 + EndpointImpl endpoint = new EndpointImpl(springBus(), attendanceServiceSoap);
  82 + endpoint.publish("/attendanceService");
  83 + //endpoint.getInInterceptors().add(new AuthInterceptor());
  84 + return endpoint;
  85 + }
  86 +
  87 + @Bean
  88 + public Endpoint electricServiceEndpoint() {
  89 + EndpointImpl endpoint = new EndpointImpl(springBus(), oilServiceSoap);
  90 + endpoint.publish("/oilServiceSoap");
  91 + //endpoint.getInInterceptors().add(new AuthInterceptor());
  92 + return endpoint;
  93 + }
  94 +
  95 + @Autowired
  96 + AuthorizeInterceptor_IN authorizeInterceptor_IN;
  97 + @Autowired
  98 + ScheduleRealService scheduleRealService;
  99 + @Autowired
  100 + StationRestService stationRestService;
  101 + @Autowired
  102 + LD_SectionRestService ldSectionRestService;
  103 + @Autowired
  104 + SchedulePlanService schedulePlanService;
  105 + @Autowired
  106 + RealLogRestService realLogRestService;
  107 + @Autowired
  108 + GpsRestService gpsRestService;
  109 + @Autowired
  110 + WaybillRestService waybillRestService;
  111 + @Autowired
  112 + DirectiveRestService directiveRestService;
  113 + @Autowired
  114 + LD_RoadSpeedRestService ld_roadSpeedRestService;
  115 + @Autowired
  116 + ElectricService electricService;
  117 + @Autowired
  118 + BigdataService bigdataService;
  119 + @Autowired
  120 + NumberService numberService;
  121 + @Autowired
  122 + StaffViewRealService staffViewRealService;
  123 + @Autowired
  124 + ExternalService externalService;
  125 +
  126 + @Bean
  127 + public Server rsServer() {
  128 + JAXRSServerFactoryBean endpoint = new JAXRSServerFactoryBean();
  129 + endpoint.setBus(springBus());
  130 + endpoint.setAddress("/rest");
  131 + endpoint.setServiceBeans(Arrays.<Object>asList(
  132 + new LineRestService(),
  133 + new CarRestService(),
  134 + new PersonRestService(),
  135 + gpsRestService,
  136 + waybillRestService,
  137 + scheduleRealService,
  138 + stationRestService,
  139 + ldSectionRestService,
  140 + schedulePlanService,
  141 + realLogRestService,
  142 + directiveRestService,
  143 + ld_roadSpeedRestService,
  144 + electricService,
  145 + staffViewRealService,
  146 + bigdataService,
  147 + numberService,
  148 + externalService));
  149 + endpoint.setProviders(Arrays.asList(new JacksonJsonProvider(), new AesExceptionMapper()));
  150 + //endpoint.setFeatures(Arrays.asList(new Swagger2Feature()));
  151 + endpoint.getInInterceptors().add(authorizeInterceptor_IN);
  152 + return endpoint.create();
  153 + }
  154 +
  155 + @Bean
  156 + public ServletRegistrationBean servletRegistrationBean() {
  157 + ServletRegistrationBean bean = new ServletRegistrationBean(new CXFServlet(), "/webservice/*");
  158 + bean.setLoadOnStartup(0);
  159 + bean.setOrder(Ordered.HIGHEST_PRECEDENCE);
  160 + return bean;
  161 + }
  162 +}
src/main/java/com/bsth/entity/PasswordUser.java
1 -package com.bsth.entity;  
2 -  
3 -import javax.persistence.*;  
4 -import java.util.Date;  
5 -  
6 -/**  
7 - * 接口 密码 访问用户  
8 - * Created by panzhao on 2017/3/26.  
9 - */  
10 -@Entity  
11 -@Table(name = "interface_user")  
12 -public class PasswordUser {  
13 -  
14 - @Id  
15 - @GeneratedValue  
16 - private Integer id;  
17 -  
18 - /** 访问密码 */  
19 - private String pwd;  
20 -  
21 - /** 调用方名称 */  
22 - private String callName;  
23 -  
24 - /** 创建日期 */  
25 - @Column(updatable = false, name = "create_date", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP")  
26 - private Date createDate;  
27 -  
28 - /** 备注 */  
29 - private String remark;  
30 -  
31 - public Integer getId() {  
32 - return id;  
33 - }  
34 -  
35 - public void setId(Integer id) {  
36 - this.id = id;  
37 - }  
38 -  
39 - public String getPwd() {  
40 - return pwd;  
41 - }  
42 -  
43 - public void setPwd(String pwd) {  
44 - this.pwd = pwd;  
45 - }  
46 -  
47 - public String getCallName() {  
48 - return callName;  
49 - }  
50 -  
51 - public void setCallName(String callName) {  
52 - this.callName = callName;  
53 - }  
54 -  
55 - public String getRemark() {  
56 - return remark;  
57 - }  
58 -  
59 - public void setRemark(String remark) {  
60 - this.remark = remark;  
61 - }  
62 -  
63 - public Date getCreateDate() {  
64 - return createDate;  
65 - }  
66 -  
67 - public void setCreateDate(Date createDate) {  
68 - this.createDate = createDate;  
69 - }  
70 -} 1 +package com.bsth.entity;
  2 +
  3 +import javax.persistence.*;
  4 +import java.util.Date;
  5 +import java.util.List;
  6 +
  7 +/**
  8 + * 接口 密码 访问用户
  9 + * Created by panzhao on 2017/3/26.
  10 + */
  11 +@Entity
  12 +@Table(name = "interface_user")
  13 +public class PasswordUser {
  14 +
  15 + @Id
  16 + @GeneratedValue
  17 + private Integer id;
  18 +
  19 + /** 访问密码 */
  20 + private String pwd;
  21 +
  22 + /** 调用方名称 */
  23 + private String callName;
  24 +
  25 + /** 创建日期 */
  26 + @Column(updatable = false, name = "create_date", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
  27 + private Date createDate;
  28 +
  29 + /** 备注 */
  30 + private String remark;
  31 +
  32 + @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
  33 + @JoinTable(name = "interface_users_resources",
  34 + joinColumns = @JoinColumn(name = "user_id"),
  35 + inverseJoinColumns = @JoinColumn(name = "resource_id"))
  36 + private List<Resource> resources;
  37 +
  38 + public Integer getId() {
  39 + return id;
  40 + }
  41 +
  42 + public void setId(Integer id) {
  43 + this.id = id;
  44 + }
  45 +
  46 + public String getPwd() {
  47 + return pwd;
  48 + }
  49 +
  50 + public void setPwd(String pwd) {
  51 + this.pwd = pwd;
  52 + }
  53 +
  54 + public String getCallName() {
  55 + return callName;
  56 + }
  57 +
  58 + public void setCallName(String callName) {
  59 + this.callName = callName;
  60 + }
  61 +
  62 + public String getRemark() {
  63 + return remark;
  64 + }
  65 +
  66 + public void setRemark(String remark) {
  67 + this.remark = remark;
  68 + }
  69 +
  70 + public Date getCreateDate() {
  71 + return createDate;
  72 + }
  73 +
  74 + public void setCreateDate(Date createDate) {
  75 + this.createDate = createDate;
  76 + }
  77 +
  78 + public List<Resource> getResources() {
  79 + return resources;
  80 + }
  81 +
  82 + public void setResources(List<Resource> resources) {
  83 + this.resources = resources;
  84 + }
  85 +}
src/main/java/com/bsth/server_rs/AuthorizeInterceptor_IN.java
1 -package com.bsth.server_rs;  
2 -  
3 -import com.bsth.server_rs.exception.AesException;  
4 -import com.bsth.service.UserService;  
5 -import org.apache.commons.lang3.StringEscapeUtils;  
6 -import org.apache.cxf.interceptor.Fault;  
7 -import org.apache.cxf.message.Message;  
8 -import org.apache.cxf.phase.AbstractPhaseInterceptor;  
9 -import org.apache.cxf.phase.Phase;  
10 -import org.eclipse.jetty.util.MultiMap;  
11 -import org.eclipse.jetty.util.UrlEncoded;  
12 -import org.slf4j.Logger;  
13 -import org.slf4j.LoggerFactory;  
14 -import org.springframework.beans.BeansException;  
15 -import org.springframework.context.ApplicationContext;  
16 -import org.springframework.context.ApplicationContextAware;  
17 -import org.springframework.stereotype.Component;  
18 -  
19 -import java.security.MessageDigest;  
20 -import java.util.Arrays;  
21 -import java.util.HashMap;  
22 -import java.util.Map;  
23 -import java.util.Set;  
24 -  
25 -/**  
26 - * rest 接口授权校验(IN 输入拦截)  
27 - * Created by panzhao on 2017/3/28.  
28 - */  
29 -@Component  
30 -public class AuthorizeInterceptor_IN extends AbstractPhaseInterceptor<Message> implements ApplicationContextAware {  
31 -  
32 - private static final String SIGN = "sign";  
33 - private static final String TIMESTAMP = "timestamp";  
34 - private static final String NONCE = "nonce";  
35 - private static final String PASSWORD = "password";  
36 - private static final int MAX_TIME_DIFF = 1000 * 60 * 10;  
37 - private static Map<String, String> pwd2nonceMap;  
38 -  
39 - static UserService userService;  
40 -  
41 - static Logger logger = LoggerFactory.getLogger(AuthorizeInterceptor_IN.class);  
42 -  
43 - public AuthorizeInterceptor_IN() {  
44 - super(Phase.RECEIVE);  
45 - }  
46 -  
47 - static {  
48 - pwd2nonceMap = new HashMap<>();  
49 - }  
50 -  
51 - @Override  
52 - public void handleMessage(Message message) throws Fault {  
53 -  
54 - long t = System.currentTimeMillis();  
55 - if (message.get(Message.QUERY_STRING) == null) {  
56 - throw new AesException(AesException.MISS_SIGN);  
57 - }  
58 -  
59 - //放行wadl  
60 - if(message.get(Message.QUERY_STRING).equals("_wadl")  
61 - && message.get(Message.PATH_INFO).equals("/webservice/rest")){  
62 - return ;  
63 - }  
64 -  
65 - //获取参数,不包括 url 路径参数 只包括?号之后的  
66 - String queryString = StringEscapeUtils.unescapeHtml4(message.get(Message.QUERY_STRING).toString());  
67 - MultiMap<String> params = new MultiMap<>();  
68 - UrlEncoded.decodeTo(queryString, params, "utf-8");  
69 - Map<String, String> map = multi2One(params);  
70 -  
71 - if (!map.containsKey(SIGN)) {  
72 - throw new AesException(AesException.MISS_SIGN);  
73 - }  
74 - if (!map.containsKey(TIMESTAMP)) {  
75 - throw new AesException(AesException.MISS_TIMESTAMP);  
76 - }  
77 -  
78 - try{  
79 - long timestamp = Long.parseLong(map.get(TIMESTAMP));  
80 - if(Math.abs(t - timestamp) > MAX_TIME_DIFF){  
81 - throw new AesException(AesException.INVALID_TIMESTAMP);  
82 - }  
83 - }catch(Exception e){  
84 - throw new AesException(AesException.INVALID_TIMESTAMP);  
85 - }  
86 -  
87 - if (!map.containsKey(NONCE)) {  
88 - throw new AesException(AesException.MISS_NONCE);  
89 - }  
90 - if (!map.containsKey(PASSWORD)) {  
91 - throw new AesException(AesException.MISS_PWD);  
92 - }  
93 -  
94 - String prevNonce = pwd2nonceMap.get(map.get(PASSWORD));  
95 - if(prevNonce != null && prevNonce.equals(map.get(NONCE)))  
96 - throw new AesException(AesException.NO_RANDOM_NONCE);  
97 -  
98 - if (userService.get(map.get(PASSWORD)) == null) {  
99 - throw new AesException(AesException.INVALID_PWD);  
100 - }  
101 -  
102 - String sign = map.get(SIGN);  
103 - map.remove(SIGN);  
104 - String sh1 = "";  
105 - try {  
106 - sh1 = getSHA1(map);  
107 - } catch (Exception e) {  
108 - throw new AesException(AesException.SIGN_CHECK_ERROR);  
109 - }  
110 -  
111 - if (!sign.equals(sh1)) {  
112 - throw new AesException(AesException.SIGN_CHECK_FAIL);  
113 - }  
114 - }  
115 -  
116 - public static Map<String, String> multi2One(MultiMap<String> params) {  
117 - Map<String, String> map = new HashMap<>();  
118 - Set<String> ks = params.keySet();  
119 - for (String k : ks) {  
120 - map.put(k, params.getString(k));  
121 - }  
122 - return map;  
123 - }  
124 -  
125 -  
126 - public static String getSHA1(Map<String, String> map) throws Exception {  
127 -  
128 - try {  
129 - String[] array = new String[map.size()];  
130 - map.values().toArray(array);  
131 - StringBuffer sb = new StringBuffer();  
132 -  
133 - // 字符串排序  
134 - Arrays.sort(array);  
135 - for (int i = 0; i < array.length; i++) {  
136 - sb.append(array[i]);  
137 - }  
138 - String str = sb.toString();  
139 - // SHA1签名生成  
140 - MessageDigest md = MessageDigest.getInstance("SHA-1");  
141 - md.update(str.getBytes());  
142 - byte[] digest = md.digest();  
143 -  
144 - StringBuffer hexstr = new StringBuffer();  
145 - String shaHex = "";  
146 - for (int i = 0; i < digest.length; i++) {  
147 - shaHex = Integer.toHexString(digest[i] & 0xFF);  
148 - if (shaHex.length() < 2) {  
149 - hexstr.append(0);  
150 - }  
151 - hexstr.append(shaHex);  
152 - }  
153 - return hexstr.toString();  
154 - } catch (Exception e) {  
155 - logger.error("", e);  
156 - throw e;  
157 - }  
158 - }  
159 -  
160 - @Override  
161 - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {  
162 - userService = applicationContext.getBean(UserService.class);  
163 - }  
164 -} 1 +package com.bsth.server_rs;
  2 +
  3 +import com.bsth.entity.PasswordUser;
  4 +import com.bsth.entity.Resource;
  5 +import com.bsth.server_rs.exception.AesException;
  6 +import com.bsth.service.UserService;
  7 +import org.apache.commons.lang3.StringEscapeUtils;
  8 +import org.apache.cxf.interceptor.Fault;
  9 +import org.apache.cxf.message.Message;
  10 +import org.apache.cxf.phase.AbstractPhaseInterceptor;
  11 +import org.apache.cxf.phase.Phase;
  12 +import org.eclipse.jetty.util.MultiMap;
  13 +import org.eclipse.jetty.util.UrlEncoded;
  14 +import org.slf4j.Logger;
  15 +import org.slf4j.LoggerFactory;
  16 +import org.springframework.beans.BeansException;
  17 +import org.springframework.beans.factory.annotation.Value;
  18 +import org.springframework.context.ApplicationContext;
  19 +import org.springframework.context.ApplicationContextAware;
  20 +import org.springframework.stereotype.Component;
  21 +import org.springframework.util.AntPathMatcher;
  22 +import org.springframework.util.PathMatcher;
  23 +
  24 +import java.io.BufferedReader;
  25 +import java.io.File;
  26 +import java.io.FileReader;
  27 +import java.io.IOException;
  28 +import java.security.MessageDigest;
  29 +import java.util.*;
  30 +import java.util.concurrent.ConcurrentHashMap;
  31 +
  32 +/**
  33 + * rest 接口授权校验(IN 输入拦截)
  34 + * Created by panzhao on 2017/3/28.
  35 + */
  36 +@Component
  37 +public class AuthorizeInterceptor_IN extends AbstractPhaseInterceptor<Message> implements ApplicationContextAware {
  38 +
  39 + private static final String SIGN = "sign";
  40 + private static final String TIMESTAMP = "timestamp";
  41 + private static final String NONCE = "nonce";
  42 + private static final String PASSWORD = "password";
  43 + private static final int MAX_TIME_DIFF = 1000 * 60 * 10;
  44 + private static Map<String, String> pwd2nonceMap;
  45 +
  46 + static UserService userService;
  47 +
  48 + static Logger logger = LoggerFactory.getLogger(AuthorizeInterceptor_IN.class);
  49 +
  50 + private static PathMatcher matcher = new AntPathMatcher();
  51 +
  52 + @Value("${path.limits}")
  53 + private String pathLimits;
  54 +
  55 + private Map<String, Set<String>> pwd2lines = new ConcurrentHashMap<>();
  56 +
  57 + private Map<String, Set<String>> pwd2device = new ConcurrentHashMap<>();
  58 +
  59 + private ThreadLocal<String> passwords = new ThreadLocal<>();
  60 +
  61 + public AuthorizeInterceptor_IN() {
  62 + super(Phase.RECEIVE);
  63 + }
  64 +
  65 + static {
  66 + pwd2nonceMap = new HashMap<>();
  67 + }
  68 +
  69 + @Override
  70 + public void handleMessage(Message message) throws Fault {
  71 +
  72 + long t = System.currentTimeMillis();
  73 + if (message.get(Message.QUERY_STRING) == null) {
  74 + throw new AesException(AesException.MISS_SIGN);
  75 + }
  76 +
  77 + //放行wadl
  78 + if(message.get(Message.QUERY_STRING).equals("_wadl")
  79 + && message.get(Message.PATH_INFO).equals("/webservice/rest")){
  80 + return ;
  81 + }
  82 +
  83 + //获取参数,不包括 url 路径参数 只包括?号之后的
  84 + String queryString = StringEscapeUtils.unescapeHtml4(message.get(Message.QUERY_STRING).toString());
  85 + MultiMap<String> params = new MultiMap<>();
  86 + UrlEncoded.decodeTo(queryString, params, "utf-8");
  87 + Map<String, String> map = multi2One(params);
  88 +
  89 + if (!map.containsKey(SIGN)) {
  90 + throw new AesException(AesException.MISS_SIGN);
  91 + }
  92 + if (!map.containsKey(TIMESTAMP)) {
  93 + throw new AesException(AesException.MISS_TIMESTAMP);
  94 + }
  95 +
  96 + try{
  97 + long timestamp = Long.parseLong(map.get(TIMESTAMP));
  98 + if(Math.abs(t - timestamp) > MAX_TIME_DIFF){
  99 + throw new AesException(AesException.INVALID_TIMESTAMP);
  100 + }
  101 + }catch(Exception e){
  102 + throw new AesException(AesException.INVALID_TIMESTAMP);
  103 + }
  104 +
  105 + if (!map.containsKey(NONCE)) {
  106 + throw new AesException(AesException.MISS_NONCE);
  107 + }
  108 + if (!map.containsKey(PASSWORD)) {
  109 + throw new AesException(AesException.MISS_PWD);
  110 + }
  111 +
  112 + String prevNonce = pwd2nonceMap.get(map.get(PASSWORD));
  113 + if(prevNonce != null && prevNonce.equals(map.get(NONCE)))
  114 + throw new AesException(AesException.NO_RANDOM_NONCE);
  115 +
  116 + if (userService.get(map.get(PASSWORD)) == null) {
  117 + throw new AesException(AesException.INVALID_PWD);
  118 + }
  119 +
  120 + String sign = map.get(SIGN);
  121 + map.remove(SIGN);
  122 + String sh1 = "";
  123 + try {
  124 + sh1 = getSHA1(map);
  125 + } catch (Exception e) {
  126 + throw new AesException(AesException.SIGN_CHECK_ERROR);
  127 + }
  128 +
  129 + if (!sign.equals(sh1)) {
  130 + throw new AesException(AesException.SIGN_CHECK_FAIL);
  131 + }
  132 +
  133 + validate(map, message);
  134 + }
  135 +
  136 + private void validate(Map<String, String> map, Message message) {
  137 + String password = map.get(PASSWORD);
  138 + PasswordUser user = userService.get(password);
  139 + if (user.getResources().size() > 0) {
  140 + loadLimit(password);
  141 + boolean isMatch = false;
  142 + String uri = (String) message.get(Message.REQUEST_URI);
  143 + for (Resource resource : user.getResources()) {
  144 + if (matcher.match(resource.getUrl(), uri)) {
  145 + isMatch = true;
  146 + break;
  147 + }
  148 + }
  149 + if (!isMatch) {
  150 + throw new AesException(AesException.INVALID_URI);
  151 + }
  152 + }
  153 + }
  154 +
  155 + public void loadLimit(String password) {
  156 + if (!pwd2lines.containsKey(password)) {
  157 + Set<String> set = new HashSet<>();
  158 + try {
  159 + BufferedReader reader = new BufferedReader(new FileReader(pathLimits + String.format("lines-%s.txt", password)));
  160 + String line = null;
  161 + while ((line = reader.readLine()) != null) {
  162 + set.add(line);
  163 + }
  164 + } catch (IOException e) {
  165 + logger.error("加载受限线路信息异常", e);
  166 + } finally {
  167 + pwd2lines.put(password, set);
  168 + }
  169 + }
  170 + if (!pwd2device.containsKey(password)) {
  171 + Set<String> set = new HashSet<>();
  172 + try {
  173 + BufferedReader reader = new BufferedReader(new FileReader(pathLimits + String.format("devices-%s.txt", password)));
  174 + String line = null;
  175 + while ((line = reader.readLine()) != null) {
  176 + set.add(line);
  177 + }
  178 + } catch (IOException e) {
  179 + logger.error("加载受限设备信息异常", e);
  180 + } finally {
  181 + pwd2device.put(password, set);
  182 + }
  183 + }
  184 + }
  185 +
  186 + public Set<String> getLimitLines(String password) {
  187 + return pwd2lines.get(password);
  188 + }
  189 +
  190 + public Set<String> getLimitDevices(String password) {
  191 + return pwd2device.get(password);
  192 + }
  193 +
  194 + public ThreadLocal<String> getPasswords() {
  195 + return passwords;
  196 + }
  197 +
  198 + public static Map<String, String> multi2One(MultiMap<String> params) {
  199 + Map<String, String> map = new HashMap<>();
  200 + Set<String> ks = params.keySet();
  201 + for (String k : ks) {
  202 + map.put(k, params.getString(k));
  203 + }
  204 + return map;
  205 + }
  206 +
  207 +
  208 + public static String getSHA1(Map<String, String> map) throws Exception {
  209 +
  210 + try {
  211 + String[] array = new String[map.size()];
  212 + map.values().toArray(array);
  213 + StringBuffer sb = new StringBuffer();
  214 +
  215 + // 字符串排序
  216 + Arrays.sort(array);
  217 + for (int i = 0; i < array.length; i++) {
  218 + sb.append(array[i]);
  219 + }
  220 + String str = sb.toString();
  221 + // SHA1签名生成
  222 + MessageDigest md = MessageDigest.getInstance("SHA-1");
  223 + md.update(str.getBytes());
  224 + byte[] digest = md.digest();
  225 +
  226 + StringBuffer hexstr = new StringBuffer();
  227 + String shaHex = "";
  228 + for (int i = 0; i < digest.length; i++) {
  229 + shaHex = Integer.toHexString(digest[i] & 0xFF);
  230 + if (shaHex.length() < 2) {
  231 + hexstr.append(0);
  232 + }
  233 + hexstr.append(shaHex);
  234 + }
  235 + return hexstr.toString();
  236 + } catch (Exception e) {
  237 + logger.error("", e);
  238 + throw e;
  239 + }
  240 + }
  241 +
  242 + @Override
  243 + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
  244 + userService = applicationContext.getBean(UserService.class);
  245 + }
  246 +}
src/main/java/com/bsth/server_rs/base_info/car/Car.java
1 -package com.bsth.server_rs.base_info.car;  
2 -  
3 -import javax.xml.bind.annotation.XmlRootElement;  
4 -import java.io.Serializable;  
5 -  
6 -/**  
7 - * 车辆信息  
8 - * Created by panzhao on 2017/3/30.  
9 - */  
10 -@XmlRootElement  
11 -public class Car implements Serializable {  
12 -  
13 - /**  
14 - * 自编号/内部编号  
15 - */  
16 - private String nbbm;  
17 -  
18 - /**  
19 - * 公司代码  
20 - */  
21 - private String companyCode;  
22 - /**  
23 - * 分公司编码  
24 - */  
25 - private String brancheCompanyCode;  
26 -  
27 - /**  
28 - * 车牌号  
29 - */  
30 - private String carPlate;  
31 - /**  
32 - * 设备终端号  
33 - */  
34 - private String equipmentCode;  
35 - /**  
36 - * 车辆类型  
37 - */  
38 - private String carType;  
39 - /**  
40 - * 是否机动车(机动车类型选择)  
41 - */  
42 - private String vehicleStats;  
43 -  
44 - /**  
45 - * 是否电车(TODO:在原系统里没有,这里暂时留着)  
46 - */  
47 - private Boolean sfdc;  
48 - /**  
49 - * 是否报废  
50 - */  
51 - private Boolean scrapState;  
52 -  
53 - /**  
54 - * RFID 车卡ID号(16进制)  
55 - */  
56 - private String idRfid;  
57 -  
58 - /**  
59 - * RFID 标签号  
60 - */  
61 - private String tagRfid;  
62 -  
63 - private String lineCode;  
64 -  
65 - private String lineName;  
66 -  
67 - private String remark;  
68 -  
69 - public String getNbbm() {  
70 - return nbbm;  
71 - }  
72 -  
73 - public void setNbbm(String nbbm) {  
74 - this.nbbm = nbbm;  
75 - }  
76 -  
77 - public String getCompanyCode() {  
78 - return companyCode;  
79 - }  
80 -  
81 - public void setCompanyCode(String companyCode) {  
82 - this.companyCode = companyCode;  
83 - }  
84 -  
85 - public String getBrancheCompanyCode() {  
86 - return brancheCompanyCode;  
87 - }  
88 -  
89 - public void setBrancheCompanyCode(String brancheCompanyCode) {  
90 - this.brancheCompanyCode = brancheCompanyCode;  
91 - }  
92 -  
93 - public String getCarPlate() {  
94 - return carPlate;  
95 - }  
96 -  
97 - public void setCarPlate(String carPlate) {  
98 - this.carPlate = carPlate;  
99 - }  
100 -  
101 - public String getEquipmentCode() {  
102 - return equipmentCode;  
103 - }  
104 -  
105 - public void setEquipmentCode(String equipmentCode) {  
106 - this.equipmentCode = equipmentCode;  
107 - }  
108 -  
109 - public String getCarType() {  
110 - return carType;  
111 - }  
112 -  
113 - public void setCarType(String carType) {  
114 - this.carType = carType;  
115 - }  
116 -  
117 - public String getVehicleStats() {  
118 - return vehicleStats;  
119 - }  
120 -  
121 - public void setVehicleStats(String vehicleStats) {  
122 - this.vehicleStats = vehicleStats;  
123 - }  
124 -  
125 - public Boolean getSfdc() {  
126 - return sfdc;  
127 - }  
128 -  
129 - public void setSfdc(Boolean sfdc) {  
130 - this.sfdc = sfdc;  
131 - }  
132 -  
133 - public Boolean getScrapState() {  
134 - return scrapState;  
135 - }  
136 -  
137 - public void setScrapState(Boolean scrapState) {  
138 - this.scrapState = scrapState;  
139 - }  
140 -  
141 - public String getIdRfid() {  
142 - return idRfid;  
143 - }  
144 -  
145 - public void setIdRfid(String idRfid) {  
146 - this.idRfid = idRfid;  
147 - }  
148 -  
149 - public String getTagRfid() {  
150 - return tagRfid;  
151 - }  
152 -  
153 - public void setTagRfid(String tagRfid) {  
154 - this.tagRfid = tagRfid;  
155 - }  
156 -  
157 - public String getLineCode() {  
158 - return lineCode;  
159 - }  
160 -  
161 - public void setLineCode(String lineCode) {  
162 - this.lineCode = lineCode;  
163 - }  
164 -  
165 - public String getLineName() {  
166 - return lineName;  
167 - }  
168 -  
169 - public void setLineName(String lineName) {  
170 - this.lineName = lineName;  
171 - }  
172 -  
173 - public String getRemark() {  
174 - return remark;  
175 - }  
176 -  
177 - public void setRemark(String remark) {  
178 - this.remark = remark;  
179 - }  
180 -} 1 +package com.bsth.server_rs.base_info.car;
  2 +
  3 +import javax.xml.bind.annotation.XmlRootElement;
  4 +import java.io.Serializable;
  5 +import java.util.Date;
  6 +
  7 +/**
  8 + * 车辆信息
  9 + * Created by panzhao on 2017/3/30.
  10 + */
  11 +@XmlRootElement
  12 +public class Car implements Serializable {
  13 +
  14 + /**
  15 + * 自编号/内部编号
  16 + */
  17 + private String nbbm;
  18 +
  19 + /**
  20 + * 公司代码
  21 + */
  22 + private String companyCode;
  23 + /**
  24 + * 分公司编码
  25 + */
  26 + private String brancheCompanyCode;
  27 +
  28 + /**
  29 + * 车牌号
  30 + */
  31 + private String carPlate;
  32 + /**
  33 + * 设备终端号
  34 + */
  35 + private String equipmentCode;
  36 + /**
  37 + * 车辆类型
  38 + */
  39 + private String carType;
  40 + /**
  41 + * 是否机动车(机动车类型选择)
  42 + */
  43 + private String vehicleStats;
  44 +
  45 + /**
  46 + * 是否电车(TODO:在原系统里没有,这里暂时留着)
  47 + */
  48 + private Boolean sfdc;
  49 + /**
  50 + * 是否报废
  51 + */
  52 + private Boolean scrapState;
  53 +
  54 + /**
  55 + * RFID 车卡ID号(16进制)
  56 + */
  57 + private String idRfid;
  58 +
  59 + /**
  60 + * RFID 标签号
  61 + */
  62 + private String tagRfid;
  63 +
  64 + private String lineCode;
  65 +
  66 + private String lineName;
  67 +
  68 + private String remark;
  69 +
  70 + private Date updateDate;
  71 +
  72 + private String vehicleType;
  73 +
  74 + public String getNbbm() {
  75 + return nbbm;
  76 + }
  77 +
  78 + public void setNbbm(String nbbm) {
  79 + this.nbbm = nbbm;
  80 + }
  81 +
  82 + public String getCompanyCode() {
  83 + return companyCode;
  84 + }
  85 +
  86 + public void setCompanyCode(String companyCode) {
  87 + this.companyCode = companyCode;
  88 + }
  89 +
  90 + public String getBrancheCompanyCode() {
  91 + return brancheCompanyCode;
  92 + }
  93 +
  94 + public void setBrancheCompanyCode(String brancheCompanyCode) {
  95 + this.brancheCompanyCode = brancheCompanyCode;
  96 + }
  97 +
  98 + public String getCarPlate() {
  99 + return carPlate;
  100 + }
  101 +
  102 + public void setCarPlate(String carPlate) {
  103 + this.carPlate = carPlate;
  104 + }
  105 +
  106 + public String getEquipmentCode() {
  107 + return equipmentCode;
  108 + }
  109 +
  110 + public void setEquipmentCode(String equipmentCode) {
  111 + this.equipmentCode = equipmentCode;
  112 + }
  113 +
  114 + public String getCarType() {
  115 + return carType;
  116 + }
  117 +
  118 + public void setCarType(String carType) {
  119 + this.carType = carType;
  120 + }
  121 +
  122 + public String getVehicleStats() {
  123 + return vehicleStats;
  124 + }
  125 +
  126 + public void setVehicleStats(String vehicleStats) {
  127 + this.vehicleStats = vehicleStats;
  128 + }
  129 +
  130 + public Boolean getSfdc() {
  131 + return sfdc;
  132 + }
  133 +
  134 + public void setSfdc(Boolean sfdc) {
  135 + this.sfdc = sfdc;
  136 + }
  137 +
  138 + public Boolean getScrapState() {
  139 + return scrapState;
  140 + }
  141 +
  142 + public void setScrapState(Boolean scrapState) {
  143 + this.scrapState = scrapState;
  144 + }
  145 +
  146 + public String getIdRfid() {
  147 + return idRfid;
  148 + }
  149 +
  150 + public void setIdRfid(String idRfid) {
  151 + this.idRfid = idRfid;
  152 + }
  153 +
  154 + public String getTagRfid() {
  155 + return tagRfid;
  156 + }
  157 +
  158 + public void setTagRfid(String tagRfid) {
  159 + this.tagRfid = tagRfid;
  160 + }
  161 +
  162 + public String getLineCode() {
  163 + return lineCode;
  164 + }
  165 +
  166 + public void setLineCode(String lineCode) {
  167 + this.lineCode = lineCode;
  168 + }
  169 +
  170 + public String getLineName() {
  171 + return lineName;
  172 + }
  173 +
  174 + public void setLineName(String lineName) {
  175 + this.lineName = lineName;
  176 + }
  177 +
  178 + public String getRemark() {
  179 + return remark;
  180 + }
  181 +
  182 + public void setRemark(String remark) {
  183 + this.remark = remark;
  184 + }
  185 +
  186 + public Date getUpdateDate() {
  187 + return updateDate;
  188 + }
  189 +
  190 + public void setUpdateDate(Date updateDate) {
  191 + this.updateDate = updateDate;
  192 + }
  193 +
  194 + public String getVehicleType() {
  195 + return vehicleType;
  196 + }
  197 +
  198 + public void setVehicleType(String vehicleType) {
  199 + this.vehicleType = vehicleType;
  200 + }
  201 +}
src/main/java/com/bsth/server_rs/base_info/car/buffer/CarBufferData.java
1 -package com.bsth.server_rs.base_info.car.buffer;  
2 -  
3 -import com.bsth.Application;  
4 -import com.bsth.server_rs.base_info.car.Car;  
5 -import com.bsth.server_rs.base_info.dto.BusCardDto;  
6 -import com.google.common.collect.ArrayListMultimap;  
7 -import org.springframework.beans.factory.annotation.Autowired;  
8 -import org.springframework.boot.CommandLineRunner;  
9 -import org.springframework.core.annotation.Order;  
10 -import org.springframework.stereotype.Component;  
11 -  
12 -import java.util.*;  
13 -import java.util.concurrent.TimeUnit;  
14 -  
15 -/**  
16 - * 车辆数据缓存  
17 - * Created by panzhao on 2017/3/30.  
18 - */  
19 -@Component  
20 -@Order(6)  
21 -public class CarBufferData implements CommandLineRunner {  
22 -  
23 - private static List<Car> data;  
24 - private static Map<String, Car> idMap;  
25 - private static ArrayListMultimap<String, Car> companyListMap;  
26 -  
27 - /**  
28 - * 待入库的bus car  
29 - */  
30 - public static LinkedList<Car> pstList = new LinkedList<>();  
31 -  
32 - @Autowired  
33 - CarRefreshThread carRefreshThread;  
34 -  
35 - public static List<Car> findAll(){  
36 - return data;  
37 - }  
38 -  
39 - public static Car findOne(String nbbm){  
40 - return idMap.get(nbbm);  
41 - }  
42 -  
43 - public static List<Car> findByCompany(String company){  
44 - return companyListMap.get(company);  
45 - }  
46 -  
47 - public static void replaceAll(List<Car> newData){  
48 - data = newData;  
49 - Map<String, Car> idMapCopy = new HashMap<>();  
50 - ArrayListMultimap<String, Car> listMap = ArrayListMultimap.create();  
51 -  
52 - for(Car car : data){  
53 - idMapCopy.put(car.getNbbm(), car);  
54 - listMap.put(car.getCompanyCode(), car);  
55 - }  
56 - idMap = idMapCopy;  
57 -  
58 - companyListMap = listMap;  
59 - }  
60 -  
61 - @Override  
62 - public void run(String... strings) throws Exception {  
63 - Application.mainServices.scheduleWithFixedDelay(carRefreshThread, 10, 60 * 60, TimeUnit.SECONDS);  
64 - }  
65 -  
66 - public static Map<String, Object> multiSaveCards(List<BusCardDto> list) {  
67 - int success=0,error=0;  
68 - //返回写入成功的卡数据  
69 - List<BusCardDto> rsList = new ArrayList<>();  
70 -  
71 - Car c;  
72 - for(BusCardDto bcd : list){  
73 - c = idMap.get(bcd.getNbbm());  
74 - if(c == null)  
75 - error ++;  
76 - else{  
77 - c.setIdRfid(bcd.getIdCard());  
78 - c.setTagRfid(bcd.getTagCard());  
79 - c.setRemark(bcd.getRemark());  
80 - success ++;  
81 -  
82 - pstList.add(c);  
83 - rsList.add(bcd);  
84 - }  
85 - }  
86 -  
87 - Map<String, Object> rs = new HashMap<>();  
88 - rs.put("success", success);  
89 - rs.put("successList", rsList);  
90 - rs.put("error", error);  
91 - return rs;  
92 - }  
93 -} 1 +package com.bsth.server_rs.base_info.car.buffer;
  2 +
  3 +import com.bsth.Application;
  4 +import com.bsth.server_rs.base_info.car.Car;
  5 +import com.bsth.server_rs.base_info.dto.BusCardDto;
  6 +import com.google.common.collect.ArrayListMultimap;
  7 +import org.springframework.beans.factory.annotation.Autowired;
  8 +import org.springframework.boot.CommandLineRunner;
  9 +import org.springframework.core.annotation.Order;
  10 +import org.springframework.stereotype.Component;
  11 +
  12 +import java.util.*;
  13 +import java.util.concurrent.TimeUnit;
  14 +
  15 +/**
  16 + * 车辆数据缓存
  17 + * Created by panzhao on 2017/3/30.
  18 + */
  19 +@Component
  20 +@Order(6)
  21 +public class CarBufferData implements CommandLineRunner {
  22 +
  23 + private static List<Car> data;
  24 + private static Map<String, Car> idMap;
  25 + private static ArrayListMultimap<String, Car> companyListMap;
  26 + private static Map<String, Car> device2car = new HashMap<>();
  27 +
  28 + /**
  29 + * 待入库的bus car
  30 + */
  31 + public static LinkedList<Car> pstList = new LinkedList<>();
  32 +
  33 + @Autowired
  34 + CarRefreshThread carRefreshThread;
  35 +
  36 + public static List<Car> findAll(){
  37 + return data;
  38 + }
  39 +
  40 + public static Car findOne(String nbbm){
  41 + return idMap.get(nbbm);
  42 + }
  43 +
  44 + public static List<Car> findByCompany(String company){
  45 + return companyListMap.get(company);
  46 + }
  47 +
  48 + public static Car findByDevice(String device){
  49 + return device2car.get(device);
  50 + }
  51 +
  52 + public static void replaceAll(List<Car> newData){
  53 + data = newData;
  54 + Map<String, Car> idMapCopy = new HashMap<>();
  55 + ArrayListMultimap<String, Car> listMap = ArrayListMultimap.create();
  56 + Map<String, Car> device2carCopy = new HashMap<>();
  57 +
  58 + for(Car car : data){
  59 + idMapCopy.put(car.getNbbm(), car);
  60 + listMap.put(car.getCompanyCode(), car);
  61 + device2carCopy.put(car.getEquipmentCode(), car);
  62 + }
  63 + idMap = idMapCopy;
  64 +
  65 + companyListMap = listMap;
  66 + device2car = device2carCopy;
  67 + }
  68 +
  69 + @Override
  70 + public void run(String... strings) throws Exception {
  71 + Application.mainServices.scheduleWithFixedDelay(carRefreshThread, 10, 60 * 60, TimeUnit.SECONDS);
  72 + }
  73 +
  74 + public static Map<String, Object> multiSaveCards(List<BusCardDto> list) {
  75 + int success=0,error=0;
  76 + //返回写入成功的卡数据
  77 + List<BusCardDto> rsList = new ArrayList<>();
  78 +
  79 + Car c;
  80 + for(BusCardDto bcd : list){
  81 + c = idMap.get(bcd.getNbbm());
  82 + if(c == null)
  83 + error ++;
  84 + else{
  85 + c.setIdRfid(bcd.getIdCard());
  86 + c.setTagRfid(bcd.getTagCard());
  87 + c.setRemark(bcd.getRemark());
  88 + success ++;
  89 +
  90 + pstList.add(c);
  91 + rsList.add(bcd);
  92 + }
  93 + }
  94 +
  95 + Map<String, Object> rs = new HashMap<>();
  96 + rs.put("success", success);
  97 + rs.put("successList", rsList);
  98 + rs.put("error", error);
  99 + return rs;
  100 + }
  101 +}
src/main/java/com/bsth/server_rs/base_info/car/buffer/CarRefreshThread.java
1 -package com.bsth.server_rs.base_info.car.buffer;  
2 -  
3 -import com.bsth.server_rs.base_info.car.Car;  
4 -import org.slf4j.Logger;  
5 -import org.slf4j.LoggerFactory;  
6 -import org.springframework.beans.factory.annotation.Autowired;  
7 -import org.springframework.jdbc.core.BeanPropertyRowMapper;  
8 -import org.springframework.jdbc.core.JdbcTemplate;  
9 -import org.springframework.stereotype.Component;  
10 -  
11 -import java.util.ArrayList;  
12 -import java.util.HashMap;  
13 -import java.util.List;  
14 -import java.util.Map;  
15 -  
16 -/**  
17 - * Created by panzhao on 2017/3/30.  
18 - */  
19 -@Component  
20 -public class CarRefreshThread extends Thread{  
21 -  
22 - @Autowired  
23 - JdbcTemplate jdbcTemplate;  
24 -  
25 - Logger logger = LoggerFactory.getLogger(this.getClass());  
26 -  
27 - @Override  
28 - public void run() {  
29 -  
30 - try {  
31 -  
32 - List<Car> list = jdbcTemplate.query("SELECT DISTINCT t1.*,t2.line_code,t2.name as line_name FROM(SELECT c.inside_code as nbbm,c.business_code as company_code,c.branche_company_code,c.car_plate,c.equipment_code,c.car_type,c.vehicle_stats,c.sfdc,c.scrap_state,c.id_rfid,c.tag_rfid,c2.xl FROM bsth_c_cars c LEFT JOIN bsth_c_s_ccinfo c2 ON c.id = c2.cl and c2.is_cancel=0) t1 LEFT JOIN bsth_c_line t2 on t1.xl=t2.id"  
33 - , BeanPropertyRowMapper.newInstance(Car.class));  
34 -  
35 - Map<String, Car> map = new HashMap<>();  
36 - //过滤数据,多条线路配车的保留一条  
37 - for(Car c : list){  
38 - map.put(c.getNbbm(), c);  
39 - }  
40 -  
41 - if(list != null && list.size() > 0)  
42 - CarBufferData.replaceAll(new ArrayList(map.values()));  
43 - }catch (Exception e){  
44 - logger.error("", e);  
45 - }  
46 - }  
47 -} 1 +package com.bsth.server_rs.base_info.car.buffer;
  2 +
  3 +import com.bsth.server_rs.base_info.car.Car;
  4 +import org.slf4j.Logger;
  5 +import org.slf4j.LoggerFactory;
  6 +import org.springframework.beans.factory.annotation.Autowired;
  7 +import org.springframework.jdbc.core.BeanPropertyRowMapper;
  8 +import org.springframework.jdbc.core.JdbcTemplate;
  9 +import org.springframework.stereotype.Component;
  10 +
  11 +import java.util.ArrayList;
  12 +import java.util.HashMap;
  13 +import java.util.List;
  14 +import java.util.Map;
  15 +
  16 +/**
  17 + * Created by panzhao on 2017/3/30.
  18 + */
  19 +@Component
  20 +public class CarRefreshThread extends Thread{
  21 +
  22 + @Autowired
  23 + JdbcTemplate jdbcTemplate;
  24 +
  25 + Logger logger = LoggerFactory.getLogger(this.getClass());
  26 +
  27 + @Override
  28 + public void run() {
  29 +
  30 + try {
  31 +
  32 + List<Car> list = jdbcTemplate.query("SELECT DISTINCT t1.*,t2.line_code,t2.name as line_name FROM(SELECT c.inside_code as nbbm,c.business_code as company_code,c.branche_company_code,c.car_plate,c.equipment_code,c.car_type,c.vehicle_stats,c.sfdc,c.scrap_state,c.id_rfid,c.tag_rfid,c.update_date,c2.xl,c2.qyrq,c.vehicle_type FROM bsth_c_cars c LEFT JOIN bsth_c_s_ccinfo c2 ON c.id = c2.cl and c2.is_cancel=0) t1 LEFT JOIN bsth_c_line t2 on t1.xl=t2.id ORDER BY nbbm,qyrq"
  33 + , BeanPropertyRowMapper.newInstance(Car.class));
  34 +
  35 + Map<String, Car> map = new HashMap<>();
  36 + //过滤数据,多条线路配车的保留一条
  37 + for(Car c : list){
  38 + map.put(c.getNbbm(), c);
  39 + }
  40 +
  41 + if(list != null && list.size() > 0)
  42 + CarBufferData.replaceAll(new ArrayList(map.values()));
  43 + }catch (Exception e){
  44 + logger.error("", e);
  45 + }
  46 + }
  47 +}
src/main/java/com/bsth/server_rs/bigdata/BigdataService.java
1 -package com.bsth.server_rs.bigdata;  
2 -  
3 -import java.sql.ResultSet;  
4 -import java.sql.SQLException;  
5 -import java.text.DecimalFormat;  
6 -import java.text.SimpleDateFormat;  
7 -import java.util.Calendar;  
8 -import java.util.Date;  
9 -import java.util.HashMap;  
10 -import java.util.List;  
11 -import java.util.Map;  
12 -  
13 -import javax.ws.rs.GET;  
14 -import javax.ws.rs.Path;  
15 -import javax.ws.rs.PathParam;  
16 -import javax.ws.rs.Produces;  
17 -import javax.ws.rs.core.MediaType;  
18 -  
19 -import org.slf4j.Logger;  
20 -import org.slf4j.LoggerFactory;  
21 -import org.springframework.beans.factory.annotation.Autowired;  
22 -import org.springframework.jdbc.core.JdbcTemplate;  
23 -import org.springframework.jdbc.core.RowMapper;  
24 -import org.springframework.stereotype.Component;  
25 -  
26 -import com.alibaba.fastjson.JSONObject;  
27 -  
28 -@Component  
29 -@Path("/bigdata")  
30 -@Produces({MediaType.APPLICATION_JSON})  
31 -public class BigdataService {  
32 - Logger logger = LoggerFactory.getLogger(this.getClass());  
33 -  
34 - @Autowired  
35 - JdbcTemplate jdbcTemplate;  
36 -  
37 - DecimalFormat df = new DecimalFormat("0.00");  
38 -  
39 - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");  
40 -  
41 - /*  
42 - * 线路接口开始  
43 - */  
44 -  
45 - private static String getNature(String natureCode){  
46 - String natureName="";  
47 - if("lj".equals(natureCode)){  
48 - natureName="路救";  
49 - }else if("bc".equals(natureCode)){  
50 - natureName="备车";  
51 - }else if("dbc".equals(natureCode)){  
52 - natureName="定班车";  
53 - }else if("yxl".equals(natureCode)){  
54 - natureName="夜宵路";  
55 - }else if("cgxl".equals(natureCode)){  
56 - natureName="常规线路";  
57 - }else if("gjxl".equals(natureCode)){  
58 - natureName="过江线路";  
59 - }else if("csbs".equals(natureCode)){  
60 - natureName="穿梭巴士";  
61 - }else if("tyxl".equals(natureCode)){  
62 - natureName="特约线路";  
63 - }else if("cctxl".equals(natureCode)){  
64 - natureName="村村通线路";  
65 - }else if("qt".equals(natureCode)){  
66 - natureName="其他";  
67 - }else {  
68 - natureName="";  
69 - }  
70 - return natureName;  
71 - }  
72 -  
73 - private static String getGs(String gs){  
74 - String name="";  
75 - if("05".equals(gs)){  
76 - name="杨高公司";  
77 - }else if("22".equals(gs)){  
78 - name="金高公司";  
79 - }else if("26".equals(gs)){  
80 - name="南汇公司";  
81 - }else if("55".equals(gs)){  
82 - name="上南公司";  
83 - }else{  
84 - name="";  
85 - }  
86 - return name;  
87 - }  
88 -  
89 - private static String getState(String carState){  
90 - if(carState.equals("1")){  
91 - return "在册未在用";  
92 - }else if(carState.equals("2")){  
93 - return "在册在用";  
94 - }else if(carState.equals("3")){  
95 - return "报废审核中";  
96 - }else if(carState.equals("4")){  
97 - return "报废待更新";  
98 - }else if(carState.equals("5")){  
99 - return "报废已更新";  
100 - }else{  
101 - return "";  
102 - }  
103 - }  
104 - public Map<String, Long> getEndtime(String date){  
105 - Map<String, Long> map=new HashMap<String,Long>();  
106 - List<String> objList = new ArrayList<String>();  
107 - String sql="select xl,endtime from bsth_c_calc_count "  
108 - + " where date = ? ";  
109 - objList.add(date);  
110 - List<Map<String, Object>> list=jdbcTemplate.query(sql, objList.toArray(),  
111 - new RowMapper<Map<String, Object>>(){  
112 - @Override  
113 - public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {  
114 - Map<String, Object> m=new HashMap<String, Object>();  
115 - m.put("line", rs.getString("xl"));  
116 - m.put("endtime", rs.getString("endtime"));  
117 - return m;  
118 - }  
119 - });  
120 - for (int i = 0; i < list.size(); i++) {  
121 - map.put(list.get(i).get("line").toString(),  
122 - Long.parseLong(list.get(i).get("endtime").toString()));  
123 - }  
124 - return map;  
125 - }  
126 - @GET  
127 - @Path("/line/all")  
128 - public List<Map<String, Object>> findLineAll(){  
129 - String sql="SELECT b.start_opt,a.company,a.line_code,a.name,a.level,"  
130 - + " a.shanghai_linecode, a.nature from "  
131 - + " bsth_c_line a left join bsth_c_line_config b "  
132 - + " on a.id=b.line where "  
133 - + " a.shanghai_linecode is not null and a.shanghai_linecode !='' and a.destroy=0 "  
134 - + " and a.remove=0 ";  
135 - List<Map<String, Object>> list=jdbcTemplate.query(sql,  
136 - new RowMapper<Map<String, Object>>(){  
137 - @Override  
138 - public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {  
139 - Map<String, Object> m=new HashMap<String,Object>();  
140 - m.put("state", rs.getString("start_opt"));  
141 - m.put("company", rs.getString("company"));  
142 - m.put("companyName", getGs(rs.getString("company")));  
143 - m.put("lineCode",rs.getString("line_code"));  
144 - m.put("name", rs.getString("name"));  
145 - m.put("level", rs.getString("level"));  
146 - m.put("shanghaiLinecode", rs.getString("shanghai_linecode"));  
147 - m.put("nature", getNature(rs.getString("nature")));  
148 - return m;  
149 - }  
150 - });  
151 - Date d=new Date();  
152 - SimpleDateFormat hm=new SimpleDateFormat("HH:mm");  
153 - SimpleDateFormat ymd=new SimpleDateFormat("yyyy-MM-dd");  
154 -  
155 - String qqrq=ymd.format(d);  
156 - String qqsj=hm.format(d);  
157 - String qqsjs[]=qqsj.split(":");  
158 - Date nDate=new Date();  
159 - Calendar calendar = Calendar.getInstance();  
160 - calendar.setTime(nDate);  
161 - calendar.add(Calendar.DAY_OF_MONTH, -1);  
162 - Date dBefore = calendar.getTime();  
163 - String qqrqbefore =ymd.format(dBefore);  
164 - int qqsjtime=Integer.parseInt(qqsjs[0])*60+Integer.parseInt(qqsjs[1]);  
165 - Map<String, Long> endMap1=getEndtime(qqrqbefore);  
166 - Map<String, Long> endMap2=getEndtime(qqrq);  
167 -  
168 - for (int i = 0; i < list.size(); i++) {  
169 - Map<String, Object> m=list.get(i);  
170 - int fcsjtime=0;  
171 - if(m.get("state")!=null){  
172 - String start_opt[]=m.get("state").toString().split(":");  
173 - fcsjtime=Integer.parseInt(start_opt[0])*60+Integer.parseInt(start_opt[1]);  
174 - }  
175 - //请求时间小于翻班时间 营运日期当做请求日期的前一天。  
176 - long maxtime=d.getTime();  
177 - String yyzt="";  
178 - if(qqsjtime<fcsjtime){  
179 - if(endMap1.get(m.get("lineCode").toString())!=null){  
180 - if(endMap1.get(m.get("lineCode").toString())>=maxtime){  
181 - yyzt="营运";  
182 - }else{  
183 - yyzt="未营运";  
184 - }  
185 - }else{  
186 - yyzt="未营运";  
187 - }  
188 - }else{  
189 - if(endMap2.get(m.get("lineCode").toString())!=null){  
190 - if(endMap2.get(m.get("lineCode").toString())>=maxtime){  
191 - yyzt="营运";  
192 - }else{  
193 - yyzt="未营运";  
194 - }  
195 - }else{  
196 - yyzt="未营运";  
197 - }  
198 - }  
199 - m.put("state", yyzt);  
200 - }  
201 - return list;  
202 - }  
203 -  
204 -  
205 - @GET  
206 - @Path("/line/company/{companyId}")  
207 - public List<Map<String, Object>> findLineByCompany(@PathParam("companyId") String companyId) {  
208 - List<String> objList = new ArrayList<String>();  
209 - String sql="SELECT b.start_opt,a.company,a.line_code,a.name,a.level,"  
210 - + " a.shanghai_linecode, a.nature from "  
211 - + " bsth_c_line a left join bsth_c_line_config b "  
212 - + " on a.id=b.line where "  
213 - + " a.shanghai_linecode is not null and a.shanghai_linecode !='' and a.destroy=0 "  
214 - + " and a.remove=0 and a.company = ?";  
215 - objList.add(companyId);  
216 - List<Map<String, Object>> list=jdbcTemplate.query(sql, objList.toArray(),  
217 - new RowMapper<Map<String, Object>>(){  
218 - @Override  
219 - public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {  
220 - Map<String, Object> m=new HashMap<String,Object>();  
221 - m.put("state", rs.getString("start_opt"));  
222 - m.put("company", rs.getString("company"));  
223 - m.put("companyName", getGs(rs.getString("company")));  
224 - m.put("lineCode",rs.getString("line_code"));  
225 - m.put("name", rs.getString("name"));  
226 - m.put("level", rs.getString("level"));  
227 - m.put("shanghaiLinecode", rs.getString("shanghai_linecode"));  
228 - m.put("nature", getNature(rs.getString("nature")));  
229 - return m;  
230 - }  
231 - });  
232 - Date d=new Date();  
233 - SimpleDateFormat hm=new SimpleDateFormat("HH:mm");  
234 - SimpleDateFormat ymd=new SimpleDateFormat("yyyy-MM-dd");  
235 -  
236 - String qqrq=ymd.format(d);  
237 - String qqsj=hm.format(d);  
238 - String qqsjs[]=qqsj.split(":");  
239 - Date nDate=new Date();  
240 - Calendar calendar = Calendar.getInstance();  
241 - calendar.setTime(nDate);  
242 - calendar.add(Calendar.DAY_OF_MONTH, -1);  
243 - Date dBefore = calendar.getTime();  
244 - String qqrqbefore =ymd.format(dBefore);  
245 - int qqsjtime=Integer.parseInt(qqsjs[0])*60+Integer.parseInt(qqsjs[1]);  
246 - Map<String, Long> endMap1=getEndtime(qqrqbefore);  
247 - Map<String, Long> endMap2=getEndtime(qqrq);  
248 -  
249 - for (int i = 0; i < list.size(); i++) {  
250 - Map<String, Object> m=list.get(i);  
251 - int fcsjtime=0;  
252 - if(m.get("state")!=null){  
253 - String start_opt[]=m.get("state").toString().split(":");  
254 - fcsjtime=Integer.parseInt(start_opt[0])*60+Integer.parseInt(start_opt[1]);  
255 - }  
256 - //请求时间小于翻班时间 营运日期当做请求日期的前一天。  
257 - long maxtime=d.getTime();  
258 - String yyzt="";  
259 - if(qqsjtime<fcsjtime){  
260 - if(endMap1.get(m.get("lineCode").toString())!=null){  
261 - if(endMap1.get(m.get("lineCode").toString())>=maxtime){  
262 - yyzt="营运";  
263 - }else{  
264 - yyzt="未营运";  
265 - }  
266 - }else{  
267 - yyzt="未营运";  
268 - }  
269 - }else{  
270 - if(endMap2.get(m.get("lineCode").toString())!=null){  
271 - if(endMap2.get(m.get("lineCode").toString())>=maxtime){  
272 - yyzt="营运";  
273 - }else{  
274 - yyzt="未营运";  
275 - }  
276 - }else{  
277 - yyzt="未营运";  
278 - }  
279 - }  
280 - m.put("state", yyzt);  
281 - }  
282 - return list;  
283 - }  
284 -  
285 - @GET  
286 - @Path("/line/{lineCode}")  
287 - public List<Map<String, Object>> findLineByCode(@PathParam("lineCode") String lineCode) {  
288 - List<String> objList = new ArrayList<String>();  
289 - String sql="SELECT b.start_opt,a.company,a.line_code,a.name,a.level,"  
290 - + " a.shanghai_linecode, a.nature from "  
291 - + " bsth_c_line a left join bsth_c_line_config b "  
292 - + " on a.id=b.line where "  
293 - + " a.shanghai_linecode is not null and a.shanghai_linecode !='' and a.destroy=0 "  
294 - + " and a.remove=0 and a.line_code = ?";  
295 - objList.add(lineCode);  
296 - List<Map<String, Object>> list=jdbcTemplate.query(sql, objList.toArray(),  
297 - new RowMapper<Map<String, Object>>(){  
298 - @Override  
299 - public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {  
300 - Map<String, Object> m=new HashMap<String,Object>();  
301 - m.put("state", rs.getString("start_opt"));  
302 - m.put("company", rs.getString("company"));  
303 - m.put("companyName", getGs(rs.getString("company")));  
304 - m.put("lineCode",rs.getString("line_code"));  
305 - m.put("name", rs.getString("name"));  
306 - m.put("level", rs.getString("level"));  
307 - m.put("shanghaiLinecode", rs.getString("shanghai_linecode"));  
308 - m.put("nature", getNature(rs.getString("nature")));  
309 - return m;  
310 - }  
311 - });  
312 - Date d=new Date();  
313 - SimpleDateFormat hm=new SimpleDateFormat("HH:mm");  
314 - SimpleDateFormat ymd=new SimpleDateFormat("yyyy-MM-dd");  
315 -  
316 - String qqrq=ymd.format(d);  
317 - String qqsj=hm.format(d);  
318 - String qqsjs[]=qqsj.split(":");  
319 - Date nDate=new Date();  
320 - Calendar calendar = Calendar.getInstance();  
321 - calendar.setTime(nDate);  
322 - calendar.add(Calendar.DAY_OF_MONTH, -1);  
323 - Date dBefore = calendar.getTime();  
324 - String qqrqbefore =ymd.format(dBefore);  
325 - int qqsjtime=Integer.parseInt(qqsjs[0])*60+Integer.parseInt(qqsjs[1]);  
326 - Map<String, Long> endMap1=getEndtime(qqrqbefore);  
327 - Map<String, Long> endMap2=getEndtime(qqrq);  
328 -  
329 - for (int i = 0; i < list.size(); i++) {  
330 - Map<String, Object> m=list.get(i);  
331 - int fcsjtime=0;  
332 - if(m.get("state")!=null){  
333 - String start_opt[]=m.get("state").toString().split(":");  
334 - fcsjtime=Integer.parseInt(start_opt[0])*60+Integer.parseInt(start_opt[1]);  
335 - }  
336 - //请求时间小于翻班时间 营运日期当做请求日期的前一天。  
337 - long maxtime=d.getTime();  
338 - String yyzt="";  
339 - if(qqsjtime<fcsjtime){  
340 - if(endMap1.get(m.get("lineCode").toString())!=null){  
341 - if(endMap1.get(m.get("lineCode").toString())>=maxtime){  
342 - yyzt="营运";  
343 - }else{  
344 - yyzt="未营运";  
345 - }  
346 - }else{  
347 - yyzt="未营运";  
348 - }  
349 - }else{  
350 - if(endMap2.get(m.get("lineCode").toString())!=null){  
351 - if(endMap2.get(m.get("lineCode").toString())>=maxtime){  
352 - yyzt="营运";  
353 - }else{  
354 - yyzt="未营运";  
355 - }  
356 - }else{  
357 - yyzt="未营运";  
358 - }  
359 - }  
360 - m.put("state", yyzt);  
361 - }  
362 - return list;  
363 - }  
364 -  
365 - @GET  
366 - @Path("/line/level/{level}")  
367 - public List<Map<String, Object>> findLineByLevle(@PathParam("level") String level) {  
368 - List<String> objList = new ArrayList<String>();  
369 - String sql="SELECT b.start_opt,a.company,a.line_code,a.name,a.level,"  
370 - + " a.shanghai_linecode, a.nature from "  
371 - + " bsth_c_line a left join bsth_c_line_config b "  
372 - + " on a.id=b.line where "  
373 - + " a.shanghai_linecode is not null and a.shanghai_linecode !='' and a.destroy=0 "  
374 - + " and a.remove=0 and a.level = ?";  
375 - objList.add(level);  
376 - List<Map<String, Object>> list=jdbcTemplate.query(sql, objList.toArray(),  
377 - new RowMapper<Map<String, Object>>(){  
378 - @Override  
379 - public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {  
380 - Map<String, Object> m=new HashMap<String,Object>();  
381 - m.put("state", rs.getString("start_opt"));  
382 - m.put("company", rs.getString("company"));  
383 - m.put("companyName", getGs(rs.getString("company")));  
384 - m.put("lineCode",rs.getString("line_code"));  
385 - m.put("name", rs.getString("name"));  
386 - m.put("level", rs.getString("level"));  
387 - m.put("shanghaiLinecode", rs.getString("shanghai_linecode"));  
388 - m.put("nature", getNature(rs.getString("nature")));  
389 - return m;  
390 - }  
391 - });  
392 - Date d=new Date();  
393 - SimpleDateFormat hm=new SimpleDateFormat("HH:mm");  
394 - SimpleDateFormat ymd=new SimpleDateFormat("yyyy-MM-dd");  
395 -  
396 - String qqrq=ymd.format(d);  
397 - String qqsj=hm.format(d);  
398 - String qqsjs[]=qqsj.split(":");  
399 - Date nDate=new Date();  
400 - Calendar calendar = Calendar.getInstance();  
401 - calendar.setTime(nDate);  
402 - calendar.add(Calendar.DAY_OF_MONTH, -1);  
403 - Date dBefore = calendar.getTime();  
404 - String qqrqbefore =ymd.format(dBefore);  
405 - int qqsjtime=Integer.parseInt(qqsjs[0])*60+Integer.parseInt(qqsjs[1]);  
406 - Map<String, Long> endMap1=getEndtime(qqrqbefore);  
407 - Map<String, Long> endMap2=getEndtime(qqrq);  
408 -  
409 - for (int i = 0; i < list.size(); i++) {  
410 - Map<String, Object> m=list.get(i);  
411 - int fcsjtime=0;  
412 - if(m.get("state")!=null){  
413 - String start_opt[]=m.get("state").toString().split(":");  
414 - fcsjtime=Integer.parseInt(start_opt[0])*60+Integer.parseInt(start_opt[1]);  
415 - }  
416 - //请求时间小于翻班时间 营运日期当做请求日期的前一天。  
417 - long maxtime=d.getTime();  
418 - String yyzt="";  
419 - if(qqsjtime<fcsjtime){  
420 - if(endMap1.get(m.get("lineCode").toString())!=null){  
421 - if(endMap1.get(m.get("lineCode").toString())>=maxtime){  
422 - yyzt="营运";  
423 - }else{  
424 - yyzt="未营运";  
425 - }  
426 - }else{  
427 - yyzt="未营运";  
428 - }  
429 - }else{  
430 - if(endMap2.get(m.get("lineCode").toString())!=null){  
431 - if(endMap2.get(m.get("lineCode").toString())>=maxtime){  
432 - yyzt="营运";  
433 - }else{  
434 - yyzt="未营运";  
435 - }  
436 - }else{  
437 - yyzt="未营运";  
438 - }  
439 - }  
440 - m.put("state", yyzt);  
441 - }  
442 - return list;  
443 - }  
444 - /*  
445 - * 线路接口结束  
446 - */  
447 -  
448 -  
449 - /*  
450 - * 线路配车接口开始  
451 - */  
452 - @GET  
453 - @Path("/lineCar/{type}/date/{date}")  
454 - public List<Map<String, Object>> findLineCarByDate(@PathParam("type") String type,@PathParam("date") String date) {  
455 - String sql="";  
456 - List<String> objList = new ArrayList<String>();  
457 - if(type.equals("all")){  
458 - sql="select t.date,t.gsdm,t.xl,t.xl_name,t.jhccz as jhcc,t.sjcc"  
459 - + " from bsth_c_calc_count t where t.date = ?";  
460 - objList.add(date);  
461 - }  
462 - if(type.equals("actual")){  
463 - sql="select t.date,t.gsdm,t.xl,t.xl_name,t.jhcc as jhcc,t.sjcc"  
464 - + " from bsth_c_calc_count t where t.date = ?";  
465 - objList.add(date);  
466 - }  
467 - List<Map<String, Object>> list=jdbcTemplate.query(sql, objList.toArray(),  
468 - new RowMapper<Map<String, Object>>(){  
469 - @Override  
470 - public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {  
471 - Map<String, Object> m=new HashMap<String,Object>();  
472 - m.put("date", rs.getString("date"));  
473 - m.put("company", rs.getString("gsdm"));  
474 - m.put("companyName", getGs(rs.getString("gsdm")));  
475 - m.put("lineCode",rs.getString("xl"));  
476 - m.put("lineName", rs.getString("xl_name"));  
477 - m.put("jhcc", rs.getString("jhcc"));  
478 - m.put("sjcc", rs.getString("sjcc"));  
479 - return m;  
480 - }  
481 - });  
482 -  
483 - return list;  
484 - }  
485 -  
486 -  
487 - @GET  
488 - @Path("/lineCar/{type}/date/{date}/line/{line}")  
489 - public List<Map<String, Object>> findLineCarByDateLine(@PathParam("type") String type,@PathParam("date") String date,  
490 - @PathParam("line") String line) {  
491 - String sql="";  
492 - List<String> objList = new ArrayList<String>();  
493 - if(type.equals("all")){  
494 - sql="select t.gsdm,t.xl,t.xl_name,t.jhccz as jhcc,t.sjcc"  
495 - + " from bsth_c_calc_count t where t.date = ?"  
496 - + " and xl = ?";  
497 - objList.add(date);  
498 - objList.add(line);  
499 - }  
500 - if(type.equals("actual")){  
501 - sql="select t.gsdm,t.xl,t.xl_name,t.jhcc as jhcc,t.sjcc"  
502 - + " from bsth_c_calc_count t where t.date = ?"  
503 - + " and xl = ?";  
504 - objList.add(date);  
505 - objList.add(line);  
506 -  
507 - }  
508 - List<Map<String, Object>> list=jdbcTemplate.query(sql, objList.toArray(),  
509 - new RowMapper<Map<String, Object>>(){  
510 - @Override  
511 - public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {  
512 - Map<String, Object> m=new HashMap<String,Object>();  
513 - m.put("company", rs.getString("gsdm"));  
514 - m.put("companyName", getGs(rs.getString("gsdm")));  
515 - m.put("lineCode",rs.getString("xl"));  
516 - m.put("lineName", rs.getString("xl_name"));  
517 - m.put("jhcc", rs.getString("jhcc"));  
518 - m.put("sjcc", rs.getString("sjcc"));  
519 - return m;  
520 - }  
521 - });  
522 -  
523 - return list;  
524 - }  
525 -  
526 - /*  
527 - * 线路配车接口结束  
528 - */  
529 -  
530 - /*  
531 - * 线路配人接口开始  
532 - */  
533 - @GET  
534 - @Path("/linePerson/{type}/date/{date}")  
535 - public List<Map<String, Object>> findLinePersonByDate(@PathParam("type") String type,@PathParam("date") String date) {  
536 - String sql="";  
537 - List<String> objList = new ArrayList<String>();  
538 - if(type.equals("all")){  
539 - sql="select t.date,t.gsdm,t.xl,t.xl_name,t.jhprz as jhpr,t.sjpr"  
540 - + " from bsth_c_calc_count t where t.date = ?";  
541 - objList.add(date);  
542 - }  
543 - if(type.equals("actual")){  
544 - sql="select t.date,t.gsdm,t.xl,t.xl_name,t.jhprss as jhpr,t.sjpr"  
545 - + " from bsth_c_calc_count t where t.date = ?";  
546 - objList.add(date);  
547 - }  
548 - List<Map<String, Object>> list=jdbcTemplate.query(sql, objList.toArray(),  
549 - new RowMapper<Map<String, Object>>(){  
550 - @Override  
551 - public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {  
552 - Map<String, Object> m=new HashMap<String,Object>();  
553 - m.put("date", rs.getString("date"));  
554 - m.put("company", rs.getString("gsdm"));  
555 - m.put("companyName", getGs(rs.getString("gsdm")));  
556 - m.put("lineCode",rs.getString("xl"));  
557 - m.put("lineName", rs.getString("xl_name"));  
558 - String jhpr=rs.getString("jhpr");  
559 - m.put("jhjsy", jhpr.split("/")[0]);  
560 - m.put("jhspy", jhpr.split("/")[1]);  
561 - String sjpr= rs.getString("sjpr");  
562 - m.put("sjjsy", sjpr.split("/")[0]);  
563 - m.put("sjspy", sjpr.split("/")[1]);  
564 - return m;  
565 - }  
566 - });  
567 -  
568 - return list;  
569 - }  
570 -  
571 -  
572 - @GET  
573 - @Path("/linePerson/{type}/date/{date}/line/{line}")  
574 - public List<Map<String, Object>> findLinePersonByDateLine(@PathParam("type") String type,@PathParam("date") String date,  
575 - @PathParam("line") String line) {  
576 - String sql="";  
577 - List<String> objList = new ArrayList<String>();  
578 - if(type.equals("all")){  
579 - sql="select t.date,t.gsdm,t.xl,t.xl_name,t.jhprz as jhpr,t.sjpr"  
580 - + " from bsth_c_calc_count t where t.date = ?"  
581 - + " and xl = ?";  
582 - objList.add(date);  
583 - objList.add(line);  
584 - }  
585 - if(type.equals("actual")){  
586 - sql="select t.date,t.gsdm,t.xl,t.xl_name,t.jhprss as jhpr,t.sjpr"  
587 - + " from bsth_c_calc_count t where t.date = ?"  
588 - + " and xl = ?";  
589 - objList.add(date);  
590 - objList.add(line);  
591 - }  
592 - List<Map<String, Object>> list=jdbcTemplate.query(sql, objList.toArray(),  
593 - new RowMapper<Map<String, Object>>(){  
594 - @Override  
595 - public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {  
596 - Map<String, Object> m=new HashMap<String,Object>();  
597 - m.put("date", rs.getString("date"));  
598 - m.put("company", rs.getString("gsdm"));  
599 - m.put("companyName", getGs(rs.getString("gsdm")));  
600 - m.put("lineCode",rs.getString("xl"));  
601 - m.put("lineName", rs.getString("xl_name"));  
602 - String jhpr=rs.getString("jhpr");  
603 - m.put("jhjsy", jhpr.split("/")[0]);  
604 - m.put("jhspy", jhpr.split("/")[1]);  
605 - String sjpr= rs.getString("sjpr");  
606 - m.put("sjjsy", sjpr.split("/")[0]);  
607 - m.put("sjspy", sjpr.split("/")[1]);  
608 - return m;  
609 - }  
610 - });  
611 -  
612 - return list;  
613 - }  
614 -  
615 -  
616 -  
617 -  
618 - /*  
619 - * 线路配人接口结束  
620 - */  
621 -  
622 -  
623 - /*  
624 - * 线路班次接口开始  
625 - */  
626 - @GET  
627 - @Path("/lineBc/{type}/date/{date}")  
628 - public List<Map<String, Object>> findLineBcByDate(@PathParam("type") String type,  
629 - @PathParam("date") String date) {  
630 - String sql="";  
631 - List<String> objList = new ArrayList<String>();  
632 - if(type.equals("all")){  
633 - sql="select t.gsdm,t.xl,t.xl_name,t.jhbcz as jhbc,t.jhzgfbcz as jhzgfbc,"  
634 - + " t.jhwgfbcz as jhwgfbc,t.sjbc,t.sjzgfbc,t.sjwgfbc from bsth_c_calc_count t"  
635 - + " where t.date = ?";  
636 - objList.add(date);  
637 - }  
638 - if(type.equals("actual")){  
639 - sql="select t.gsdm,t.xl,t.xl_name,t.jhbc as jhbc,t.jhzgfbcss as jhzgfbc,"  
640 - + " t.jhwgfbcss as jhwgfbc,t.sjbc,t.sjzgfbc,t.sjwgfbc from bsth_c_calc_count t"  
641 - + " where t.date = ?";  
642 - objList.add(date);  
643 - }  
644 - List<Map<String, Object>> list=jdbcTemplate.query(sql, objList.toArray(),  
645 - new RowMapper<Map<String, Object>>(){  
646 - @Override  
647 - public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {  
648 - Map<String, Object> m=new HashMap<String,Object>();  
649 - m.put("company", rs.getString("gsdm"));  
650 - m.put("companyName", getGs(rs.getString("gsdm")));  
651 - m.put("lineCode",rs.getString("xl"));  
652 - m.put("lineName", rs.getString("xl_name"));  
653 - m.put("jhbc", rs.getString("jhbc"));  
654 - m.put("jhzgfbc", rs.getString("jhzgfbc"));  
655 - m.put("jhwgfbc", rs.getString("jhwgfbc"));  
656 - m.put("sjbc", rs.getString("sjbc"));  
657 - m.put("sjzgfbc", rs.getString("sjzgfbc"));  
658 - m.put("sjwgfbc", rs.getString("sjwgfbc"));  
659 - return m;  
660 - }  
661 - });  
662 - return list;  
663 - }  
664 -  
665 -  
666 - @GET  
667 - @Path("/lineBc/{type}/date/{date}/line/{line}")  
668 - public List<Map<String, Object>> findLineBcByDateLine(@PathParam("type") String type,  
669 - @PathParam("date") String date,@PathParam("line") String line) {  
670 - String sql="";  
671 - List<String> objList = new ArrayList<String>();  
672 - if(type.equals("all")){  
673 - sql="select t.gsdm,t.xl,t.xl_name,t.jhbcz as jhbc,t.jhzgfbcz as jhzgfbc,"  
674 - + " t.jhwgfbcz as jhwgfbc,t.sjbc,t.sjzgfbc,t.sjwgfbc from bsth_c_calc_count t "  
675 - + " where t.date = ? and xl = ?";  
676 - objList.add(date);  
677 - objList.add(line);  
678 - }  
679 - if(type.equals("actual")){  
680 - sql="select t.gsdm,t.xl,t.xl_name,t.jhbc as jhbc,t.jhzgfbcss as jhzgfbc,"  
681 - + " t.jhwgfbcss as jhwgfbc,t.sjbc,t.sjzgfbc,t.sjwgfbc from bsth_c_calc_count t"  
682 - + " where t.date = ? and xl = ?";  
683 - objList.add(date);  
684 - objList.add(line);  
685 - }  
686 - List<Map<String, Object>> list=jdbcTemplate.query(sql, objList.toArray(),  
687 - new RowMapper<Map<String, Object>>(){  
688 - @Override  
689 - public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {  
690 - Map<String, Object> m=new HashMap<String,Object>();  
691 - m.put("company", rs.getString("gsdm"));  
692 - m.put("companyName", getGs(rs.getString("gsdm")));  
693 - m.put("lineCode",rs.getString("xl"));  
694 - m.put("lineName", rs.getString("xl_name"));  
695 - m.put("jhbc", rs.getString("jhbc"));  
696 - m.put("jhzgfbc", rs.getString("jhzgfbc"));  
697 - m.put("jhwgfbc", rs.getString("jhwgfbc"));  
698 - m.put("sjbc", rs.getString("sjbc"));  
699 - m.put("sjzgfbc", rs.getString("sjzgfbc"));  
700 - m.put("sjwgfbc", rs.getString("sjwgfbc"));  
701 - return m;  
702 - }  
703 - });  
704 - return list;  
705 - }  
706 -  
707 - /*  
708 - * 线路班次接口结束  
709 - */  
710 -  
711 - /*  
712 - * 线路里程接口开始  
713 - */  
714 -  
715 - @GET  
716 - @Path("/lineLc/{type}/date/{date}")  
717 - public List<Map<String, Object>> findLineLcByDate(@PathParam("type") String type,  
718 - @PathParam("date") String date) {  
719 - String sql="";  
720 - List<String> objList = new ArrayList<String>();  
721 - if(type.equals("all")){  
722 - sql="select t.gsdm,t.xl,t.xl_name,t.jhzglz as jhzlc,t.jhyylcz as jhyylc,"  
723 - + " t.jhkslcz as jhkslc,t.sjzgl as sjzlc,t.sjyylc,t.sjkslc from bsth_c_calc_count t"  
724 - + " where t.date = ?";  
725 - objList.add(date);  
726 - }  
727 - if(type.equals("actual")){  
728 - sql="select t.gsdm,t.xl,t.xl_name,t.jhzgl as jhzlc,t.jhyylc as jhyylc,"  
729 - + " t.jhkslc as jhkslc,t.sjzgl as sjzlc,t.sjyylc,t.sjkslc from bsth_c_calc_count t"  
730 - + " where t.date = ?";  
731 - objList.add(date);  
732 - }  
733 - List<Map<String, Object>> list=jdbcTemplate.query(sql, objList.toArray(),  
734 - new RowMapper<Map<String, Object>>(){  
735 - @Override  
736 - public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {  
737 - Map<String, Object> m=new HashMap<String,Object>();  
738 - m.put("company", rs.getString("gsdm"));  
739 - m.put("companyName", getGs(rs.getString("gsdm")));  
740 - m.put("lineCode",rs.getString("xl"));  
741 - m.put("lineName", rs.getString("xl_name"));  
742 - m.put("jhzlc", rs.getString("jhzlc"));  
743 - m.put("jhyylc", rs.getString("jhyylc"));  
744 - m.put("jhkslc", rs.getString("jhkslc"));  
745 - m.put("sjzlc", rs.getString("sjzlc"));  
746 - m.put("sjyylc", rs.getString("sjyylc"));  
747 - m.put("sjkslc", rs.getString("sjkslc"));  
748 - if(Double.parseDouble(rs.getString("jhzlc"))>0){  
749 - double zlczxl=Double.parseDouble(rs.getString("sjzlc"))/Double.parseDouble(rs.getString("jhzlc"));  
750 - m.put("zlczxl",df.format(zlczxl*100)+"%");  
751 - }else{  
752 - m.put("zlczxl","0.00%");  
753 -  
754 - }  
755 - if(Double.parseDouble(rs.getString("jhyylc"))>0){  
756 - double yylczxl=Double.parseDouble(rs.getString("sjyylc"))/Double.parseDouble(rs.getString("jhyylc"));  
757 - m.put("yylczxl",df.format(yylczxl*100)+"%");  
758 - }else{  
759 - m.put("yylczxl","0.00%");  
760 - }  
761 - return m;  
762 - }  
763 - });  
764 - return list;  
765 - }  
766 -  
767 -  
768 - @GET  
769 - @Path("/lineLc/{type}/date/{date}/line/{line}")  
770 - public List<Map<String, Object>> findLineLcByDateLine(@PathParam("type") String type,  
771 - @PathParam("date") String date,@PathParam("line") String line) {  
772 - String sql="";  
773 - List<String> objList = new ArrayList<String>();  
774 - if(type.equals("all")){  
775 - sql="select t.gsdm,t.xl,t.xl_name,t.jhzglz as jhzlc,t.jhyylcz as jhyylc,"  
776 - + " t.jhkslcz as jhkslc,t.sjzgl as sjzlc,t.sjyylc,t.sjkslc from bsth_c_calc_count t"  
777 - + " where t.date = ? and xl = ?";  
778 - objList.add(date);  
779 - objList.add(line);  
780 - }  
781 - if(type.equals("actual")){  
782 - sql="select t.gsdm,t.xl,t.xl_name,t.jhzgl as jhzlc,t.jhyylc as jhyylc,"  
783 - + " t.jhkslc as jhkslc,t.sjzgl as sjzlc,t.sjyylc,t.sjkslc from bsth_c_calc_count t"  
784 - + " where t.date = ? and xl = ?";  
785 - objList.add(date);  
786 - objList.add(line);  
787 - }  
788 - List<Map<String, Object>> list=jdbcTemplate.query(sql, objList.toArray(),  
789 - new RowMapper<Map<String, Object>>(){  
790 - @Override  
791 - public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {  
792 - Map<String, Object> m=new HashMap<String,Object>();  
793 - m.put("company", rs.getString("gsdm"));  
794 - m.put("companyName", getGs(rs.getString("gsdm")));  
795 - m.put("lineCode",rs.getString("xl"));  
796 - m.put("lineName", rs.getString("xl_name"));  
797 - m.put("jhzlc", rs.getString("jhzlc"));  
798 - m.put("jhyylc", rs.getString("jhyylc"));  
799 - m.put("jhkslc", rs.getString("jhkslc"));  
800 - m.put("sjzlc", rs.getString("sjzlc"));  
801 - m.put("sjyylc", rs.getString("sjyylc"));  
802 - m.put("sjkslc", rs.getString("sjkslc"));  
803 - if(Double.parseDouble(rs.getString("jhzlc"))>0){  
804 - double zlczxl=Double.parseDouble(rs.getString("sjzlc"))/Double.parseDouble(rs.getString("jhzlc"));  
805 - m.put("zlczxl",df.format(zlczxl*100)+"%");  
806 - }else{  
807 - m.put("zlczxl","0.00%");  
808 -  
809 - }  
810 - if(Double.parseDouble(rs.getString("jhyylc"))>0){  
811 - double yylczxl=Double.parseDouble(rs.getString("sjyylc"))/Double.parseDouble(rs.getString("jhyylc"));  
812 - m.put("yylczxl",df.format(yylczxl*100)+"%");  
813 - }else{  
814 - m.put("yylczxl","0.00%");  
815 - }  
816 - return m;  
817 - }  
818 - });  
819 - return list;  
820 - }  
821 - /*  
822 - * 线路里程接口结束  
823 - */  
824 -  
825 -  
826 - /*  
827 - * 班次执行率连续三天不满93%推送  
828 - */  
829 - @GET  
830 - @Path("/abnormal/executionRate/date/{date}")  
831 - public List<Map<String, Object>> executionRate(@PathParam("date") String date) {  
832 - List<String> objList = new ArrayList<String>();  
833 - String sql="select gs_name,show_date,xl_bm,xl_name from bsth_c_calc_push t"  
834 - + " where t.date = ? and push_type in ('1','3')";  
835 - objList.add(date);  
836 - List<Map<String, Object>> list=jdbcTemplate.query(sql, objList.toArray(),  
837 - new RowMapper<Map<String, Object>>(){  
838 - @Override  
839 - public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {  
840 - Map<String, Object> m=new HashMap<String,Object>();  
841 - m.put("companyName", rs.getString("gs_name"));  
842 - m.put("lineCode",rs.getString("xl_bm"));  
843 - m.put("lineName", rs.getString("xl_name"));  
844 - m.put("showDate", rs.getString("show_date"));  
845 - return m;  
846 - }  
847 - });  
848 - return list;  
849 - }  
850 - /*  
851 - * 首末班发车连续三天不准点  
852 - */  
853 - @GET  
854 - @Path("/abnormal/firstAndLast/date/{date}")  
855 - public List<Map<String, Object>> firstAndLast(@PathParam("date") String date) {  
856 - List<String> objList = new ArrayList<String>();  
857 - String sql="select gs_name,show_date,xl_bm,xl_name from bsth_c_calc_push t"  
858 - + " where t.date = ? and push_type in ('2','3')";  
859 - objList.add(date);  
860 - List<Map<String, Object>> list=jdbcTemplate.query(sql, objList.toArray(),  
861 - new RowMapper<Map<String, Object>>(){  
862 - @Override  
863 - public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {  
864 - Map<String, Object> m=new HashMap<String,Object>();  
865 - m.put("companyName", rs.getString("gs_name"));  
866 - m.put("lineCode",rs.getString("xl_bm"));  
867 - m.put("lineName", rs.getString("xl_name"));  
868 - m.put("showDate", rs.getString("show_date"));  
869 - return m;  
870 - }  
871 - });  
872 - return list;  
873 - }  
874 -  
875 - /*  
876 - * 车辆数据接口开始  
877 - */  
878 -  
879 - @GET  
880 - @Path("/car/all")  
881 - public List<Map<String, Object>> findCar() {  
882 - String carStr= GetHttpInterface.getHttpInterface("http://180.166.5.82:8076/cars/getAllCarsInterface");  
883 - //车辆库资料资料  
884 - List<Map<String, Object>> clkList=(List<Map<String, Object>>) JSONObject.parse(carStr);  
885 - //调度系统车辆资料  
886 - String carSql="select equipment_code, inside_code,supplier_name from bsth_c_cars";  
887 - List<Map<String, Object>> ddkList=jdbcTemplate.query(carSql,  
888 - new RowMapper<Map<String, Object>>(){  
889 - @Override  
890 - public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {  
891 - Map<String, Object> m=new HashMap<String,Object>();  
892 - m.put("equipment_code", rs.getString("equipment_code"));  
893 - m.put("insideCode", rs.getString("inside_code"));  
894 - m.put("supplier_name",rs.getString("supplier_name"));  
895 - return m;  
896 - }  
897 - });  
898 - for (int i = 0; i < clkList.size(); i++) {  
899 - Map<String, Object> m1=clkList.get(i);  
900 - String carCode=m1.get("car_code").toString();  
901 - m1.put("state_name", getState(m1.get("car_state")==null?"":m1.get("car_state").toString()));  
902 - for (int j = 0; j < ddkList.size(); j++) {  
903 - Map<String, Object> m2=ddkList.get(j);  
904 - String insideCode=m2.get("insideCode").toString();  
905 - if(carCode.equals(insideCode)){  
906 - m1.put("equipment_code", m2.get("equipment_code"));  
907 - m1.put("supplier_name", m2.get("supplier_name"));  
908 - }  
909 -  
910 - }  
911 - }  
912 - return clkList;  
913 - }  
914 -  
915 -  
916 - @GET  
917 - @Path("/car/company/{companyId}")  
918 - public List<Map<String, Object>> findCarByCompany(@PathParam("companyId") String companyId) {  
919 - String carStr= GetHttpInterface.  
920 - getHttpInterface("http://180.166.5.82:8076/cars/getAllCarsInterface?company="+companyId);  
921 - //车辆库资料资料  
922 - List<Map<String, Object>> clkList=(List<Map<String, Object>>) JSONObject.parse(carStr);  
923 - //调度系统车辆资料  
924 - String carSql="select equipment_code, inside_code,supplier_name from bsth_c_cars where business_code='"+companyId+"'";  
925 - List<Map<String, Object>> ddkList=jdbcTemplate.query(carSql,  
926 - new RowMapper<Map<String, Object>>(){  
927 - @Override  
928 - public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {  
929 - Map<String, Object> m=new HashMap<String,Object>();  
930 - m.put("equipment_code", rs.getString("equipment_code"));  
931 - m.put("insideCode", rs.getString("inside_code"));  
932 - m.put("supplier_name",rs.getString("supplier_name"));  
933 - return m;  
934 - }  
935 - });  
936 - for (int i = 0; i < clkList.size(); i++) {  
937 - Map<String, Object> m1=clkList.get(i);  
938 - String carCode=m1.get("car_code").toString();  
939 - m1.put("state_name", getState(m1.get("car_state")==null?"":m1.get("car_state").toString()));  
940 - for (int j = 0; j < ddkList.size(); j++) {  
941 - Map<String, Object> m2=ddkList.get(j);  
942 - String insideCode=m2.get("insideCode").toString();  
943 - if(carCode.equals(insideCode)){  
944 - m1.put("equipment_code", m2.get("equipment_code"));  
945 - m1.put("supplier_name", m2.get("supplier_name"));  
946 - }  
947 -  
948 - }  
949 - }  
950 - return clkList;  
951 - }  
952 -  
953 - @GET  
954 - @Path("/car/code/{carCode}")  
955 - public List<Map<String, Object>> findCarByCode(@PathParam("carCode") String carCode) {  
956 - String carStr= GetHttpInterface.  
957 - getHttpInterface("http://101.95.0.106:8076/cars/getAllCarsInterface?car_code="+carCode);  
958 - //车辆库资料资料  
959 - List<Map<String, Object>> clkList=(List<Map<String, Object>>) JSONObject.parse(carStr);  
960 - //调度系统车辆资料  
961 - String carSql="select equipment_code, inside_code,supplier_name from bsth_c_cars where inside_code='"+carCode+"'";  
962 - List<Map<String, Object>> ddkList=jdbcTemplate.query(carSql,  
963 - new RowMapper<Map<String, Object>>(){  
964 - @Override  
965 - public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {  
966 - Map<String, Object> m=new HashMap<String,Object>();  
967 - m.put("equipment_code", rs.getString("equipment_code"));  
968 - m.put("insideCode", rs.getString("inside_code"));  
969 - m.put("supplier_name",rs.getString("supplier_name"));  
970 - return m;  
971 - }  
972 - });  
973 -  
974 - for (int i = 0; i < clkList.size(); i++) {  
975 - Map<String, Object> m1=clkList.get(i);  
976 - String code=m1.get("car_code").toString().trim();  
977 - m1.put("state_name", getState(m1.get("car_state")==null?"":m1.get("car_state").toString()));  
978 - for (int j = 0; j < ddkList.size(); j++) {  
979 - Map<String, Object> m2=ddkList.get(j);  
980 - String insideCode=m2.get("insideCode").toString().trim();  
981 - if(code.equals(insideCode)){  
982 - m1.put("equipment_code", m2.get("equipment_code"));  
983 - m1.put("supplier_name", m2.get("supplier_name"));  
984 - }  
985 -  
986 - }  
987 - }  
988 - return clkList;  
989 - }  
990 - /*  
991 - * 车辆数据接口结束  
992 - */  
993 -  
994 - /*  
995 - * 事故数据接口开始  
996 - */  
997 - @GET  
998 - @Path("/accident/startTime/{startTime}/endTime/{endTime}")  
999 - public List<Map<String, Object>> findAccident(@PathParam("startTime") String startTime,  
1000 - @PathParam("endTime") String endTime) {  
1001 - String accidentAll= GetHttpInterface.getHttpInterface("http://180.168.57.114:9019/pdsafe/LineSms/getAccidentSubmitAll.do?"  
1002 - + "submitDateBegin="+startTime+"&submitDateEnd="+endTime);  
1003 - List<Map<String, Object>> list=(List<Map<String, Object>>) JSONObject.parse(accidentAll);  
1004 - return list;  
1005 - }  
1006 -  
1007 -  
1008 - /*  
1009 - * 事故数据接口结束  
1010 - */  
1011 -  
1012 - /*  
1013 - *安全驾驶接口开始  
1014 - */  
1015 - @GET  
1016 - @Path("/safedriving/starDate/{starDate}/endDate/{endDate}")  
1017 - public List<Map<String, Object>> findSafedriving(@PathParam("starDate") String starDate,  
1018 - @PathParam("endDate") String endDate) {  
1019 - String accidentAll= GetHttpInterface.getHttpInterface("http://211.95.61.66:9006/safedriving/safedrivingInterface?StarTime="+starDate+"&EndTime="+endDate);  
1020 - List<Map<String, Object>> list=(List<Map<String, Object>>) JSONObject.parse(accidentAll);  
1021 - return list;  
1022 - }  
1023 - @GET  
1024 - @Path("/safedriving/starDate/{starDate}/endDate/{endDate}/line/{line}")  
1025 - public List<Map<String, Object>> findSafedrivingByLine(@PathParam("starDate") String starDate,  
1026 - @PathParam("endDate") String endDate,@PathParam("line") String line) {  
1027 - String accidentAll= GetHttpInterface.getHttpInterface("http://211.95.61.66:9006/safedriving/safedrivingInterface?StarTime="+starDate+"&EndTime="+endDate  
1028 - +"&LineId="+line);  
1029 - List<Map<String, Object>> list=(List<Map<String, Object>>) JSONObject.parse(accidentAll);  
1030 - return list;  
1031 - }  
1032 - /*  
1033 - *安全驾驶接口结束  
1034 - */  
1035 -  
1036 -  
1037 - /**  
1038 - * 闵行线路班次里程  
1039 - *  
1040 - *  
1041 - *  
1042 - */  
1043 -  
1044 - @GET  
1045 - @Path("/findByAll/starDate/{starDate}/endDate/{endDate}/line/{line}")  
1046 - public List<Map<String, Object>> findMinhang(@PathParam("starDate") String starDate,  
1047 - @PathParam("endDate") String endDate,@PathParam("line") String line) {  
1048 - List<String> objList = new ArrayList<String>();  
1049 - String sql="select xl,xl_name,date,jhszfcs,sjszfczds,jhbc,sjbc,jhcc,sjcc,"  
1050 - + " jhyylc,sjyylc,jhkslc,sjkslc,jhssgfbcs,sjgfbcs,jhssdgbcs,"  
1051 - + " sjdgbcs from bsth_c_calc_count "  
1052 - + " where date >= ? and date <= ?";  
1053 - objList.add(starDate);  
1054 - objList.add(endDate);  
1055 -  
1056 - if(!line.equals("all")){  
1057 - sql +=" and xl = ?";  
1058 - objList.add(line);  
1059 - }  
1060 -  
1061 - List<Map<String, Object>> list=jdbcTemplate.query(sql, objList.toArray(),  
1062 - new RowMapper<Map<String, Object>>(){  
1063 - @Override  
1064 - public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {  
1065 - Map<String, Object> m=new HashMap<String,Object>();  
1066 - m.put("lineCode",rs.getString("xl"));  
1067 - m.put("lineName", rs.getString("xl_name"));  
1068 - m.put("date", rs.getString("date"));  
1069 - m.put("jhszfcs", rs.getString("jhszfcs"));  
1070 - m.put("sjszfczds", rs.getString("sjszfczds"));  
1071 - m.put("jhbc", rs.getString("jhbc"));  
1072 - m.put("sjbc", rs.getString("sjbc"));  
1073 - m.put("jhcc", rs.getString("jhcc"));  
1074 - m.put("sjcc", rs.getString("sjcc"));  
1075 - m.put("jhyylc", rs.getString("jhyylc"));  
1076 - m.put("sjyylc", rs.getString("sjyylc"));  
1077 - m.put("jhkslc", rs.getString("jhkslc"));  
1078 - m.put("sjkslc", rs.getString("sjkslc"));  
1079 - m.put("jhgfbcs", rs.getString("jhssgfbcs"));  
1080 - m.put("sjgfbcs", rs.getString("sjgfbcs"));  
1081 - m.put("jhdgbcs", rs.getString("jhssdgbcs"));  
1082 - m.put("sjdgbcs", rs.getString("sjdgbcs"));  
1083 - return m;  
1084 - }  
1085 - });  
1086 - return list;  
1087 - }  
1088 -  
1089 - /**  
1090 - * 赵冲需要的数据接口  
1091 - *  
1092 - */  
1093 - @GET  
1094 - @Path("/findByCompany/{company}/date/{date}")  
1095 - public List<Map<String, Object>> findByCompany(@PathParam("company") String company,  
1096 - @PathParam("date") String date) {  
1097 - List<String> objList = new ArrayList<String>();  
1098 - String sql="select t.company as gs_code,t.date,SUM(t.jhcczgf) as jhccs ,SUM(t.sjcczgf) as ccs,AVG(ccl) as ccl"  
1099 - + " ,SUM(t.sjzgl*1000)/1000 as sum_mileage ,SUM(jcgl*1000)/1000 as airpor_mileage "  
1100 - + " from (select a.line_code,b.date,a.company,b.jhcczgf,b.sjcczgf,"  
1101 - + " round(if(ifnull(b.sjcczgf/b.jhcczgf,0)>1,1,ifnull(b.sjcczgf/b.jhcczgf,0)),3) as ccl,c.sjzgl ,"  
1102 - + " ifnull(d.sjzgl,0) as jcgl from bsth_c_line a LEFT JOIN "  
1103 - + " (SELECT * from bsth_c_calc_sheet where date = ?) b on a.line_code=b.xl"  
1104 - + " left join (select * from bsth_c_calc_count where date = ?) c on a.line_code=c.xl "  
1105 - + " left join (select * from bsth_c_calc_count where date = ? "  
1106 - + " and xl_name like '%机场%') d on a.line_code=d.xl "  
1107 - + " where a.nature in ('yxl','cgxl','gjxl','csbs','cctxl')) t "  
1108 - + " where t.date is not null ";  
1109 - objList.add(date);  
1110 - objList.add(date);  
1111 - objList.add(date);  
1112 - if(!company.equals("all")){  
1113 - sql +=" and t.company = ?";  
1114 - objList.add(company);  
1115 - }  
1116 - sql +=" group by t.company,t.date";  
1117 -  
1118 - List<Map<String, Object>> list=jdbcTemplate.query(sql, objList.toArray(),  
1119 - new RowMapper<Map<String, Object>>(){  
1120 - @Override  
1121 - public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {  
1122 - Map<String, Object> m=new HashMap<String,Object>();  
1123 - m.put("gs_name", getGs(rs.getString("gs_code")));  
1124 - m.put("gs_code",rs.getString("gs_code"));  
1125 - m.put("date", rs.getString("date"));  
1126 - m.put("jhccs", rs.getString("jhccs"));  
1127 - m.put("ccs", rs.getString("ccs"));  
1128 - m.put("ccl", rs.getString("ccl"));  
1129 - m.put("sum_mileage", rs.getString("sum_mileage"));  
1130 - m.put("airpor_mileage", rs.getString("airpor_mileage"));  
1131 - return m;  
1132 - }  
1133 - });  
1134 - return list;  
1135 - }  
1136 - @GET  
1137 - @Path("/findTarget/gs/{gs}/fgs/{fgs}/date/{date}")  
1138 - public List<Map<String, Object>> findTarget(@PathParam("gs") String gs,@PathParam("fgs") String fgs,  
1139 - @PathParam("date") String date) {  
1140 - SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd");  
1141 - String d=sdf.format(new Date());  
1142 - String sql="";  
1143 - List<String> objList = new ArrayList<String>();  
1144 - if(gs.equals("all")){  
1145 - sql ="select x.gsdm,'' as fgsdm,x.smb_zdl,x.zgf_ccl,y.yylc_zxl,y.szfc_zdl,y.bc_zxl from ("  
1146 - + " select b.gsdm,round(avg(if(ifnull(b.sjcczgf/b.jhcczgf,0)>1,1,ifnull(b.sjcczgf/b.jhcczgf,0))),3)* 100 as zgf_ccl,"  
1147 - + " round(avg(ifnull(b.smbfczdl,0)),3) as smb_zdl from "  
1148 - + " bsth_c_calc_sheet b where b.date like ? and b.date < ? "  
1149 - + " and b.xl in(select a.line_code from bsth_c_line a where "  
1150 - + " a.nature in ('yxl','cgxl','gjxl','csbs','cctxl') ) group by b.gsdm ) x "  
1151 - + " left join (select c.gsdm,round(avg(if(CONVERT(c.yylczxl,DECIMAL(9,2))>100,100,c.yylczxl)),3) as yylc_zxl,"  
1152 - + " round(avg(if(CONVERT(c.szfczdl,DECIMAL(9,2))>100,100,c.szfczdl)),3) as szfc_zdl,"  
1153 - + " round(avg(if(CONVERT(c.bczxl,DECIMAL(9,2))>100,100,c.bczxl)),3) as bc_zxl "  
1154 - + " from bsth_c_calc_count c where c.date like ? and c.date < ? and "  
1155 - + " c.xl in(select a.line_code from bsth_c_line a where a.nature in ('yxl','cgxl','gjxl','csbs','cctxl') ) "  
1156 - + " group by c.gsdm ) y on x.gsdm=y.gsdm where 1=1 ";  
1157 - objList.add("%"+date+"%");  
1158 - objList.add(d);  
1159 - objList.add("%"+date+"%");  
1160 - objList.add(d);  
1161 -  
1162 - }else{  
1163 - sql ="select x.gsdm,x.fgsdm,x.smb_zdl,x.zgf_ccl,y.yylc_zxl,y.szfc_zdl,y.bc_zxl from ("  
1164 - + " select b.gsdm,b.fgsdm,round(avg(if(ifnull(b.sjcczgf/b.jhcczgf,0)>1,1,ifnull(b.sjcczgf/b.jhcczgf,0))),3) * 100 as zgf_ccl,"  
1165 - + " round(avg(ifnull(b.smbfczdl,0)),3) as smb_zdl from "  
1166 - + " bsth_c_calc_sheet b where b.date like ? and b.date < ? "  
1167 - + " and b.xl in(select a.line_code from bsth_c_line a where "  
1168 - + " a.nature in ('yxl','cgxl','gjxl','csbs','cctxl') ) group by b.gsdm,b.fgsdm ) x "  
1169 - + " left join (select c.gsdm,c.fgsdm,round(avg(if(CONVERT(c.yylczxl,DECIMAL(9,2))>100,100,c.yylczxl)),3) as yylc_zxl,"  
1170 - + " round(avg(if(CONVERT(c.szfczdl,DECIMAL(9,2))>100,100,c.szfczdl)),3) as szfc_zdl,"  
1171 - + " round(avg(if(CONVERT(c.bczxl,DECIMAL(9,2))>100,100,c.bczxl)),3) as bc_zxl "  
1172 - + " from bsth_c_calc_count c where c.date like ? and c.date < ? and "  
1173 - + " c.xl in(select a.line_code from bsth_c_line a where a.nature in ('yxl','cgxl','gjxl','csbs','cctxl') ) "  
1174 - + " group by c.gsdm,c.fgsdm ) y on x.gsdm=y.gsdm and x.fgsdm=y.fgsdm where 1=1 ";  
1175 - objList.add("%"+date+"%");  
1176 - objList.add(d);  
1177 - objList.add("%"+date+"%");  
1178 - objList.add(d);  
1179 -  
1180 - }  
1181 - if(!gs.equals("all")){  
1182 - sql += " and x.gsdm = ?";  
1183 - objList.add(gs);  
1184 - }  
1185 -  
1186 - if(!fgs.equals("all")){  
1187 - sql += " and x.fgsdm = ?";  
1188 - objList.add(fgs);  
1189 - }  
1190 - List<Map<String, Object>> list=jdbcTemplate.query(sql, objList.toArray(),  
1191 - new RowMapper<Map<String, Object>>(){  
1192 - @Override  
1193 - public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {  
1194 - Map<String, Object> m=new HashMap<String,Object>();  
1195 - m.put("gsdm", getGs(rs.getString("gsdm")));  
1196 - m.put("fgsdm",rs.getString("fgsdm"));  
1197 - m.put("smb_zdl", rs.getString("smb_zdl"));  
1198 - m.put("zgf_ccl", rs.getString("zgf_ccl"));  
1199 - m.put("yylc_zxl", rs.getString("yylc_zxl"));  
1200 - m.put("szfc_zdl", rs.getString("szfc_zdl"));  
1201 - m.put("bc_zxl", rs.getString("bc_zxl"));  
1202 - return m;  
1203 - }  
1204 - });  
1205 - return list;  
1206 - }  
1207 -  
1208 -  
1209 - /**  
1210 - *公司内部使用数据  
1211 - *  
1212 - *班次里程基础数据接口  
1213 - */  
1214 - @GET  
1215 - @Path("/basicData/starDate/{starDate}/endDate/{endDate}/line/{line}")  
1216 - public List<Map<String, Object>> basicData(@PathParam("starDate") String starDate,  
1217 - @PathParam("endDate") String endDate,@PathParam("line") String line) {  
1218 - List<String> objList = new ArrayList<String>();  
1219 - String sql="select gsdm,fgsdm,xl,xl_name,date,jhbc,sjbc,"  
1220 - + " jhyylc,sjyylc,jhkslc,sjkslc,jhgfbcsz,sjgfbcs,jhdgbcsz,"  
1221 - + " sjdgbcs from bsth_c_calc_count "  
1222 - + " where date >= ? and date <= ?";  
1223 - objList.add(starDate);  
1224 - objList.add(endDate);  
1225 - if(!line.equals("all")){  
1226 - sql +=" and xl = ?";  
1227 - objList.add(line);  
1228 - }  
1229 - List<Map<String, Object>> list=jdbcTemplate.query(sql, objList.toArray(),  
1230 - new RowMapper<Map<String, Object>>(){  
1231 - @Override  
1232 - public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {  
1233 - Map<String, Object> m=new HashMap<String,Object>();  
1234 - m.put("gsdm",rs.getString("gsdm"));  
1235 - m.put("fgsdm",rs.getString("fgsdm"));  
1236 - m.put("lineCode",rs.getString("xl"));  
1237 - m.put("lineName", rs.getString("xl_name"));  
1238 - m.put("date", rs.getString("date"));  
1239 - m.put("jhbc", rs.getString("jhbc"));  
1240 - m.put("sjbc", rs.getString("sjbc"));  
1241 - m.put("jhyylc", rs.getString("jhyylc"));  
1242 - m.put("sjyylc", rs.getString("sjyylc"));  
1243 - m.put("jhkslc", rs.getString("jhkslc"));  
1244 - m.put("sjkslc", rs.getString("sjkslc"));  
1245 - m.put("jhgfbcs", rs.getString("jhgfbcsz"));  
1246 - m.put("sjgfbcs", rs.getString("sjgfbcs"));  
1247 - m.put("jhdgbcs", rs.getString("jhdgbcsz"));  
1248 - m.put("sjdgbcs", rs.getString("sjdgbcs"));  
1249 - return m;  
1250 - }  
1251 - });  
1252 - return list;  
1253 - }  
1254 -  
1255 - @GET  
1256 - @Path("/targetData/starDate/{starDate}/endDate/{endDate}/line/{line}")  
1257 - public List<Map<String, Object>> targetData(@PathParam("starDate") String starDate,  
1258 - @PathParam("endDate") String endDate,@PathParam("line") String line) {  
1259 - List<String> objList = new ArrayList<String>();  
1260 - String sql="select gsdm,fgsdm,date,xl,xl_name,szfczdl,smbfczdl,"  
1261 - + " round(if(ifnull(sjcczgf/jhcczgf,0)>1,1,ifnull(sjcczgf/jhcczgf,0)),3) * 100 as zgfccl , "  
1262 - + " round(if(ifnull(sjcc/jhcc,0)>1,1,ifnull(sjcc/jhcc,0)),3) * 100 as ccl from bsth_c_calc_sheet "  
1263 - + " where date >= ? and date <= ?";  
1264 - objList.add(starDate);  
1265 - objList.add(endDate);  
1266 - if(!line.equals("all")){  
1267 - sql +=" and xl = ?";  
1268 - objList.add(line);  
1269 - }  
1270 - List<Map<String, Object>> list=jdbcTemplate.query(sql, objList.toArray(),  
1271 - new RowMapper<Map<String, Object>>(){  
1272 - @Override  
1273 - public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {  
1274 - Map<String, Object> m=new HashMap<String,Object>();  
1275 - m.put("gsdm",rs.getString("gsdm"));  
1276 - m.put("fgsdm",rs.getString("fgsdm"));  
1277 - m.put("lineCode",rs.getString("xl"));  
1278 - m.put("lineName", rs.getString("xl_name"));  
1279 - m.put("date", rs.getString("date"));  
1280 - m.put("szfczdl", rs.getString("szfczdl"));  
1281 - m.put("smbfczdl", rs.getString("smbfczdl"));  
1282 - m.put("zgfccl", rs.getString("zgfccl"));  
1283 - m.put("ccl", rs.getString("ccl"));  
1284 - return m;  
1285 - }  
1286 - });  
1287 - return list;  
1288 - }  
1289 -  
1290 - @GET  
1291 - @Path("/departureTime/starDate/{starDate}/endDate/{endDate}/line/{line}")  
1292 - public List<Map<String, Object>> departureTime(@PathParam("starDate") String starDate,  
1293 - @PathParam("endDate") String endDate,@PathParam("line") String line) {  
1294 - List<String> objList = new ArrayList<String>();  
1295 - String sql="select xl,xl_name,date,jhbc,bczxl,jhbcz,sjbc,jhcc,sjcc,ccl,jhccz,"  
1296 - + " jhyylc,sjyylc,jhyylcz,jhkslc,sjkslc,jhkslcz,"  
1297 - + " jhssgfbcs,sjgfbcs,jhgfbcsz,jhssdgbcs,sjdgbcs,jhdgbcsz,"  
1298 - + " jhsmbcs,sjsmbczds,smbczdl,jhsmbcsz,sjsmbczdsz,smbczdlz,"  
1299 - + " jhszfcs,sjszfczds,szfczdl,"  
1300 - + " create_date from bsth_c_calc_count "  
1301 - + " where date >= ? and date <= ?";  
1302 - objList.add(starDate);  
1303 - objList.add(endDate);  
1304 - if(!line.equals("all")){  
1305 - sql +=" and xl = ?";  
1306 - objList.add(line);  
1307 - }  
1308 -  
1309 - List<Map<String, Object>> list=jdbcTemplate.query(sql, objList.toArray(),  
1310 - new RowMapper<Map<String, Object>>(){  
1311 - @Override  
1312 - public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {  
1313 - Map<String, Object> m=new HashMap<String,Object>();  
1314 - m.put("lineCode",rs.getString("xl"));  
1315 - m.put("lineName", rs.getString("xl_name"));  
1316 - m.put("date", rs.getString("date"));  
1317 -  
1318 - m.put("jhbc", rs.getString("jhbc"));  
1319 - m.put("sjbc", rs.getString("sjbc"));  
1320 - m.put("bczxl", rs.getString("bczxl"));  
1321 - m.put("jhbcz", rs.getString("jhbcz"));  
1322 -  
1323 - m.put("jhcc", rs.getString("jhcc"));  
1324 - m.put("sjcc", rs.getString("sjcc"));  
1325 - m.put("ccl", rs.getString("ccl"));  
1326 - m.put("jhccz", rs.getString("jhccz"));  
1327 -  
1328 - m.put("jhyylc", rs.getString("jhyylc"));  
1329 - m.put("sjyylc", rs.getString("sjyylc"));  
1330 - m.put("jhyylcz", rs.getString("jhyylcz"));  
1331 - m.put("jhkslc", rs.getString("jhkslc"));  
1332 - m.put("sjkslc", rs.getString("sjkslc"));  
1333 - m.put("jhkslcz", rs.getString("jhkslcz"));  
1334 -  
1335 - m.put("jhgfbcs", rs.getString("jhssgfbcs"));  
1336 - m.put("sjgfbcs", rs.getString("sjgfbcs"));  
1337 - m.put("jhgfbcsz", rs.getString("jhgfbcsz"));  
1338 - m.put("jhdgbcs", rs.getString("jhssdgbcs"));  
1339 - m.put("sjdgbcs", rs.getString("sjdgbcs"));  
1340 - m.put("jhdgbcsz", rs.getString("jhdgbcsz"));  
1341 -  
1342 - m.put("jhsmbcs", rs.getString("jhsmbcs"));  
1343 - m.put("sjsmbczds", rs.getString("sjsmbczds"));  
1344 - m.put("smbczdl", rs.getString("smbczdl"));  
1345 - m.put("jhsmbcsz", rs.getString("jhsmbcsz"));  
1346 - m.put("sjsmbczdsz", rs.getString("sjsmbczdsz"));  
1347 - m.put("smbczdlz", rs.getString("smbczdlz"));  
1348 -  
1349 - m.put("jhszfcs", rs.getString("jhszfcs"));  
1350 - m.put("sjszfczds", rs.getString("sjszfczds"));  
1351 - m.put("szfczdl", rs.getString("szfczdl"));  
1352 -  
1353 - Date date = new Date();  
1354 - date.setTime(rs.getTimestamp("create_date").getTime());  
1355 - m.put("createDate", sdf.format(date));  
1356 - return m;  
1357 - }  
1358 - });  
1359 - return list;  
1360 - }  
1361 -  
1362 -} 1 +package com.bsth.server_rs.bigdata;
  2 +
  3 +import java.sql.ResultSet;
  4 +import java.sql.SQLException;
  5 +import java.text.DecimalFormat;
  6 +import java.text.SimpleDateFormat;
  7 +import java.util.*;
  8 +
  9 +import javax.ws.rs.GET;
  10 +import javax.ws.rs.Path;
  11 +import javax.ws.rs.PathParam;
  12 +import javax.ws.rs.Produces;
  13 +import javax.ws.rs.core.MediaType;
  14 +
  15 +import org.slf4j.Logger;
  16 +import org.slf4j.LoggerFactory;
  17 +import org.springframework.beans.factory.annotation.Autowired;
  18 +import org.springframework.jdbc.core.JdbcTemplate;
  19 +import org.springframework.jdbc.core.RowMapper;
  20 +import org.springframework.stereotype.Component;
  21 +
  22 +import com.alibaba.fastjson.JSONObject;
  23 +
  24 +@Component
  25 +@Path("/bigdata")
  26 +@Produces({MediaType.APPLICATION_JSON})
  27 +public class BigdataService {
  28 + Logger logger = LoggerFactory.getLogger(this.getClass());
  29 +
  30 + @Autowired
  31 + JdbcTemplate jdbcTemplate;
  32 +
  33 + DecimalFormat df = new DecimalFormat("0.00");
  34 +
  35 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  36 +
  37 + /*
  38 + * 线路接口开始
  39 + */
  40 +
  41 + private static String getNature(String natureCode){
  42 + String natureName="";
  43 + if("lj".equals(natureCode)){
  44 + natureName="路救";
  45 + }else if("bc".equals(natureCode)){
  46 + natureName="备车";
  47 + }else if("dbc".equals(natureCode)){
  48 + natureName="定班车";
  49 + }else if("yxl".equals(natureCode)){
  50 + natureName="夜宵路";
  51 + }else if("cgxl".equals(natureCode)){
  52 + natureName="常规线路";
  53 + }else if("gjxl".equals(natureCode)){
  54 + natureName="过江线路";
  55 + }else if("csbs".equals(natureCode)){
  56 + natureName="穿梭巴士";
  57 + }else if("tyxl".equals(natureCode)){
  58 + natureName="特约线路";
  59 + }else if("cctxl".equals(natureCode)){
  60 + natureName="村村通线路";
  61 + }else if("qt".equals(natureCode)){
  62 + natureName="其他";
  63 + }else {
  64 + natureName="";
  65 + }
  66 + return natureName;
  67 + }
  68 +
  69 + private static String getGs(String gs){
  70 + String name="";
  71 + if("05".equals(gs)){
  72 + name="杨高公司";
  73 + }else if("22".equals(gs)){
  74 + name="金高公司";
  75 + }else if("26".equals(gs)){
  76 + name="南汇公司";
  77 + }else if("55".equals(gs)){
  78 + name="上南公司";
  79 + }else{
  80 + name="";
  81 + }
  82 + return name;
  83 + }
  84 +
  85 + private static String getState(String carState){
  86 + if(carState.equals("1")){
  87 + return "在册未在用";
  88 + }else if(carState.equals("2")){
  89 + return "在册在用";
  90 + }else if(carState.equals("3")){
  91 + return "报废审核中";
  92 + }else if(carState.equals("4")){
  93 + return "报废待更新";
  94 + }else if(carState.equals("5")){
  95 + return "报废已更新";
  96 + }else{
  97 + return "";
  98 + }
  99 + }
  100 + public Map<String, Long> getEndtime(String date){
  101 + Map<String, Long> map=new HashMap<String,Long>();
  102 + List<String> objList = new ArrayList<String>();
  103 + String sql="select xl,endtime from bsth_c_calc_count "
  104 + + " where date = ? ";
  105 + objList.add(date);
  106 + List<Map<String, Object>> list=jdbcTemplate.query(sql, objList.toArray(),
  107 + new RowMapper<Map<String, Object>>(){
  108 + @Override
  109 + public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
  110 + Map<String, Object> m=new HashMap<String, Object>();
  111 + m.put("line", rs.getString("xl"));
  112 + m.put("endtime", rs.getString("endtime"));
  113 + return m;
  114 + }
  115 + });
  116 + for (int i = 0; i < list.size(); i++) {
  117 + map.put(list.get(i).get("line").toString(),
  118 + Long.parseLong(list.get(i).get("endtime").toString()));
  119 + }
  120 + return map;
  121 + }
  122 + @GET
  123 + @Path("/line/all")
  124 + public List<Map<String, Object>> findLineAll(){
  125 + String sql="SELECT b.start_opt,a.company,a.line_code,a.name,a.level,"
  126 + + " a.shanghai_linecode, a.nature from "
  127 + + " bsth_c_line a left join bsth_c_line_config b "
  128 + + " on a.id=b.line where "
  129 + + " a.shanghai_linecode is not null and a.shanghai_linecode !='' and a.destroy=0 "
  130 + + " and a.remove=0 ";
  131 + List<Map<String, Object>> list=jdbcTemplate.query(sql,
  132 + new RowMapper<Map<String, Object>>(){
  133 + @Override
  134 + public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
  135 + Map<String, Object> m=new HashMap<String,Object>();
  136 + m.put("state", rs.getString("start_opt"));
  137 + m.put("company", rs.getString("company"));
  138 + m.put("companyName", getGs(rs.getString("company")));
  139 + m.put("lineCode",rs.getString("line_code"));
  140 + m.put("name", rs.getString("name"));
  141 + m.put("level", rs.getString("level"));
  142 + m.put("shanghaiLinecode", rs.getString("shanghai_linecode"));
  143 + m.put("nature", getNature(rs.getString("nature")));
  144 + return m;
  145 + }
  146 + });
  147 + Date d=new Date();
  148 + SimpleDateFormat hm=new SimpleDateFormat("HH:mm");
  149 + SimpleDateFormat ymd=new SimpleDateFormat("yyyy-MM-dd");
  150 +
  151 + String qqrq=ymd.format(d);
  152 + String qqsj=hm.format(d);
  153 + String qqsjs[]=qqsj.split(":");
  154 + Date nDate=new Date();
  155 + Calendar calendar = Calendar.getInstance();
  156 + calendar.setTime(nDate);
  157 + calendar.add(Calendar.DAY_OF_MONTH, -1);
  158 + Date dBefore = calendar.getTime();
  159 + String qqrqbefore =ymd.format(dBefore);
  160 + int qqsjtime=Integer.parseInt(qqsjs[0])*60+Integer.parseInt(qqsjs[1]);
  161 + Map<String, Long> endMap1=getEndtime(qqrqbefore);
  162 + Map<String, Long> endMap2=getEndtime(qqrq);
  163 +
  164 + for (int i = 0; i < list.size(); i++) {
  165 + Map<String, Object> m=list.get(i);
  166 + int fcsjtime=0;
  167 + if(m.get("state")!=null){
  168 + String start_opt[]=m.get("state").toString().split(":");
  169 + fcsjtime=Integer.parseInt(start_opt[0])*60+Integer.parseInt(start_opt[1]);
  170 + }
  171 + //请求时间小于翻班时间 营运日期当做请求日期的前一天。
  172 + long maxtime=d.getTime();
  173 + String yyzt="";
  174 + if(qqsjtime<fcsjtime){
  175 + if(endMap1.get(m.get("lineCode").toString())!=null){
  176 + if(endMap1.get(m.get("lineCode").toString())>=maxtime){
  177 + yyzt="营运";
  178 + }else{
  179 + yyzt="未营运";
  180 + }
  181 + }else{
  182 + yyzt="未营运";
  183 + }
  184 + }else{
  185 + if(endMap2.get(m.get("lineCode").toString())!=null){
  186 + if(endMap2.get(m.get("lineCode").toString())>=maxtime){
  187 + yyzt="营运";
  188 + }else{
  189 + yyzt="未营运";
  190 + }
  191 + }else{
  192 + yyzt="未营运";
  193 + }
  194 + }
  195 + m.put("state", yyzt);
  196 + }
  197 + return list;
  198 + }
  199 +
  200 +
  201 + @GET
  202 + @Path("/line/company/{companyId}")
  203 + public List<Map<String, Object>> findLineByCompany(@PathParam("companyId") String companyId) {
  204 + List<String> objList = new ArrayList<String>();
  205 + String sql="SELECT b.start_opt,a.company,a.line_code,a.name,a.level,"
  206 + + " a.shanghai_linecode, a.nature from "
  207 + + " bsth_c_line a left join bsth_c_line_config b "
  208 + + " on a.id=b.line where "
  209 + + " a.shanghai_linecode is not null and a.shanghai_linecode !='' and a.destroy=0 "
  210 + + " and a.remove=0 and a.company = ?";
  211 + objList.add(companyId);
  212 + List<Map<String, Object>> list=jdbcTemplate.query(sql, objList.toArray(),
  213 + new RowMapper<Map<String, Object>>(){
  214 + @Override
  215 + public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
  216 + Map<String, Object> m=new HashMap<String,Object>();
  217 + m.put("state", rs.getString("start_opt"));
  218 + m.put("company", rs.getString("company"));
  219 + m.put("companyName", getGs(rs.getString("company")));
  220 + m.put("lineCode",rs.getString("line_code"));
  221 + m.put("name", rs.getString("name"));
  222 + m.put("level", rs.getString("level"));
  223 + m.put("shanghaiLinecode", rs.getString("shanghai_linecode"));
  224 + m.put("nature", getNature(rs.getString("nature")));
  225 + return m;
  226 + }
  227 + });
  228 + Date d=new Date();
  229 + SimpleDateFormat hm=new SimpleDateFormat("HH:mm");
  230 + SimpleDateFormat ymd=new SimpleDateFormat("yyyy-MM-dd");
  231 +
  232 + String qqrq=ymd.format(d);
  233 + String qqsj=hm.format(d);
  234 + String qqsjs[]=qqsj.split(":");
  235 + Date nDate=new Date();
  236 + Calendar calendar = Calendar.getInstance();
  237 + calendar.setTime(nDate);
  238 + calendar.add(Calendar.DAY_OF_MONTH, -1);
  239 + Date dBefore = calendar.getTime();
  240 + String qqrqbefore =ymd.format(dBefore);
  241 + int qqsjtime=Integer.parseInt(qqsjs[0])*60+Integer.parseInt(qqsjs[1]);
  242 + Map<String, Long> endMap1=getEndtime(qqrqbefore);
  243 + Map<String, Long> endMap2=getEndtime(qqrq);
  244 +
  245 + for (int i = 0; i < list.size(); i++) {
  246 + Map<String, Object> m=list.get(i);
  247 + int fcsjtime=0;
  248 + if(m.get("state")!=null){
  249 + String start_opt[]=m.get("state").toString().split(":");
  250 + fcsjtime=Integer.parseInt(start_opt[0])*60+Integer.parseInt(start_opt[1]);
  251 + }
  252 + //请求时间小于翻班时间 营运日期当做请求日期的前一天。
  253 + long maxtime=d.getTime();
  254 + String yyzt="";
  255 + if(qqsjtime<fcsjtime){
  256 + if(endMap1.get(m.get("lineCode").toString())!=null){
  257 + if(endMap1.get(m.get("lineCode").toString())>=maxtime){
  258 + yyzt="营运";
  259 + }else{
  260 + yyzt="未营运";
  261 + }
  262 + }else{
  263 + yyzt="未营运";
  264 + }
  265 + }else{
  266 + if(endMap2.get(m.get("lineCode").toString())!=null){
  267 + if(endMap2.get(m.get("lineCode").toString())>=maxtime){
  268 + yyzt="营运";
  269 + }else{
  270 + yyzt="未营运";
  271 + }
  272 + }else{
  273 + yyzt="未营运";
  274 + }
  275 + }
  276 + m.put("state", yyzt);
  277 + }
  278 + return list;
  279 + }
  280 +
  281 + @GET
  282 + @Path("/line/{lineCode}")
  283 + public List<Map<String, Object>> findLineByCode(@PathParam("lineCode") String lineCode) {
  284 + List<String> objList = new ArrayList<String>();
  285 + String sql="SELECT b.start_opt,a.company,a.line_code,a.name,a.level,"
  286 + + " a.shanghai_linecode, a.nature from "
  287 + + " bsth_c_line a left join bsth_c_line_config b "
  288 + + " on a.id=b.line where "
  289 + + " a.shanghai_linecode is not null and a.shanghai_linecode !='' and a.destroy=0 "
  290 + + " and a.remove=0 and a.line_code = ?";
  291 + objList.add(lineCode);
  292 + List<Map<String, Object>> list=jdbcTemplate.query(sql, objList.toArray(),
  293 + new RowMapper<Map<String, Object>>(){
  294 + @Override
  295 + public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
  296 + Map<String, Object> m=new HashMap<String,Object>();
  297 + m.put("state", rs.getString("start_opt"));
  298 + m.put("company", rs.getString("company"));
  299 + m.put("companyName", getGs(rs.getString("company")));
  300 + m.put("lineCode",rs.getString("line_code"));
  301 + m.put("name", rs.getString("name"));
  302 + m.put("level", rs.getString("level"));
  303 + m.put("shanghaiLinecode", rs.getString("shanghai_linecode"));
  304 + m.put("nature", getNature(rs.getString("nature")));
  305 + return m;
  306 + }
  307 + });
  308 + Date d=new Date();
  309 + SimpleDateFormat hm=new SimpleDateFormat("HH:mm");
  310 + SimpleDateFormat ymd=new SimpleDateFormat("yyyy-MM-dd");
  311 +
  312 + String qqrq=ymd.format(d);
  313 + String qqsj=hm.format(d);
  314 + String qqsjs[]=qqsj.split(":");
  315 + Date nDate=new Date();
  316 + Calendar calendar = Calendar.getInstance();
  317 + calendar.setTime(nDate);
  318 + calendar.add(Calendar.DAY_OF_MONTH, -1);
  319 + Date dBefore = calendar.getTime();
  320 + String qqrqbefore =ymd.format(dBefore);
  321 + int qqsjtime=Integer.parseInt(qqsjs[0])*60+Integer.parseInt(qqsjs[1]);
  322 + Map<String, Long> endMap1=getEndtime(qqrqbefore);
  323 + Map<String, Long> endMap2=getEndtime(qqrq);
  324 +
  325 + for (int i = 0; i < list.size(); i++) {
  326 + Map<String, Object> m=list.get(i);
  327 + int fcsjtime=0;
  328 + if(m.get("state")!=null){
  329 + String start_opt[]=m.get("state").toString().split(":");
  330 + fcsjtime=Integer.parseInt(start_opt[0])*60+Integer.parseInt(start_opt[1]);
  331 + }
  332 + //请求时间小于翻班时间 营运日期当做请求日期的前一天。
  333 + long maxtime=d.getTime();
  334 + String yyzt="";
  335 + if(qqsjtime<fcsjtime){
  336 + if(endMap1.get(m.get("lineCode").toString())!=null){
  337 + if(endMap1.get(m.get("lineCode").toString())>=maxtime){
  338 + yyzt="营运";
  339 + }else{
  340 + yyzt="未营运";
  341 + }
  342 + }else{
  343 + yyzt="未营运";
  344 + }
  345 + }else{
  346 + if(endMap2.get(m.get("lineCode").toString())!=null){
  347 + if(endMap2.get(m.get("lineCode").toString())>=maxtime){
  348 + yyzt="营运";
  349 + }else{
  350 + yyzt="未营运";
  351 + }
  352 + }else{
  353 + yyzt="未营运";
  354 + }
  355 + }
  356 + m.put("state", yyzt);
  357 + }
  358 + return list;
  359 + }
  360 +
  361 + @GET
  362 + @Path("/line/level/{level}")
  363 + public List<Map<String, Object>> findLineByLevle(@PathParam("level") String level) {
  364 + List<String> objList = new ArrayList<String>();
  365 + String sql="SELECT b.start_opt,a.company,a.line_code,a.name,a.level,"
  366 + + " a.shanghai_linecode, a.nature from "
  367 + + " bsth_c_line a left join bsth_c_line_config b "
  368 + + " on a.id=b.line where "
  369 + + " a.shanghai_linecode is not null and a.shanghai_linecode !='' and a.destroy=0 "
  370 + + " and a.remove=0 and a.level = ?";
  371 + objList.add(level);
  372 + List<Map<String, Object>> list=jdbcTemplate.query(sql, objList.toArray(),
  373 + new RowMapper<Map<String, Object>>(){
  374 + @Override
  375 + public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
  376 + Map<String, Object> m=new HashMap<String,Object>();
  377 + m.put("state", rs.getString("start_opt"));
  378 + m.put("company", rs.getString("company"));
  379 + m.put("companyName", getGs(rs.getString("company")));
  380 + m.put("lineCode",rs.getString("line_code"));
  381 + m.put("name", rs.getString("name"));
  382 + m.put("level", rs.getString("level"));
  383 + m.put("shanghaiLinecode", rs.getString("shanghai_linecode"));
  384 + m.put("nature", getNature(rs.getString("nature")));
  385 + return m;
  386 + }
  387 + });
  388 + Date d=new Date();
  389 + SimpleDateFormat hm=new SimpleDateFormat("HH:mm");
  390 + SimpleDateFormat ymd=new SimpleDateFormat("yyyy-MM-dd");
  391 +
  392 + String qqrq=ymd.format(d);
  393 + String qqsj=hm.format(d);
  394 + String qqsjs[]=qqsj.split(":");
  395 + Date nDate=new Date();
  396 + Calendar calendar = Calendar.getInstance();
  397 + calendar.setTime(nDate);
  398 + calendar.add(Calendar.DAY_OF_MONTH, -1);
  399 + Date dBefore = calendar.getTime();
  400 + String qqrqbefore =ymd.format(dBefore);
  401 + int qqsjtime=Integer.parseInt(qqsjs[0])*60+Integer.parseInt(qqsjs[1]);
  402 + Map<String, Long> endMap1=getEndtime(qqrqbefore);
  403 + Map<String, Long> endMap2=getEndtime(qqrq);
  404 +
  405 + for (int i = 0; i < list.size(); i++) {
  406 + Map<String, Object> m=list.get(i);
  407 + int fcsjtime=0;
  408 + if(m.get("state")!=null){
  409 + String start_opt[]=m.get("state").toString().split(":");
  410 + fcsjtime=Integer.parseInt(start_opt[0])*60+Integer.parseInt(start_opt[1]);
  411 + }
  412 + //请求时间小于翻班时间 营运日期当做请求日期的前一天。
  413 + long maxtime=d.getTime();
  414 + String yyzt="";
  415 + if(qqsjtime<fcsjtime){
  416 + if(endMap1.get(m.get("lineCode").toString())!=null){
  417 + if(endMap1.get(m.get("lineCode").toString())>=maxtime){
  418 + yyzt="营运";
  419 + }else{
  420 + yyzt="未营运";
  421 + }
  422 + }else{
  423 + yyzt="未营运";
  424 + }
  425 + }else{
  426 + if(endMap2.get(m.get("lineCode").toString())!=null){
  427 + if(endMap2.get(m.get("lineCode").toString())>=maxtime){
  428 + yyzt="营运";
  429 + }else{
  430 + yyzt="未营运";
  431 + }
  432 + }else{
  433 + yyzt="未营运";
  434 + }
  435 + }
  436 + m.put("state", yyzt);
  437 + }
  438 + return list;
  439 + }
  440 + /*
  441 + * 线路接口结束
  442 + */
  443 +
  444 +
  445 + /*
  446 + * 线路配车接口开始
  447 + */
  448 + @GET
  449 + @Path("/lineCar/{type}/date/{date}")
  450 + public List<Map<String, Object>> findLineCarByDate(@PathParam("type") String type,@PathParam("date") String date) {
  451 + String sql="";
  452 + List<String> objList = new ArrayList<String>();
  453 + if(type.equals("all")){
  454 + sql="select t.date,t.gsdm,t.xl,t.xl_name,t.jhccz as jhcc,t.sjcc"
  455 + + " from bsth_c_calc_count t where t.date = ?";
  456 + objList.add(date);
  457 + }
  458 + if(type.equals("actual")){
  459 + sql="select t.date,t.gsdm,t.xl,t.xl_name,t.jhcc as jhcc,t.sjcc"
  460 + + " from bsth_c_calc_count t where t.date = ?";
  461 + objList.add(date);
  462 + }
  463 + List<Map<String, Object>> list=jdbcTemplate.query(sql, objList.toArray(),
  464 + new RowMapper<Map<String, Object>>(){
  465 + @Override
  466 + public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
  467 + Map<String, Object> m=new HashMap<String,Object>();
  468 + m.put("date", rs.getString("date"));
  469 + m.put("company", rs.getString("gsdm"));
  470 + m.put("companyName", getGs(rs.getString("gsdm")));
  471 + m.put("lineCode",rs.getString("xl"));
  472 + m.put("lineName", rs.getString("xl_name"));
  473 + m.put("jhcc", rs.getString("jhcc"));
  474 + m.put("sjcc", rs.getString("sjcc"));
  475 + return m;
  476 + }
  477 + });
  478 +
  479 + return list;
  480 + }
  481 +
  482 +
  483 + @GET
  484 + @Path("/lineCar/{type}/date/{date}/line/{line}")
  485 + public List<Map<String, Object>> findLineCarByDateLine(@PathParam("type") String type,@PathParam("date") String date,
  486 + @PathParam("line") String line) {
  487 + String sql="";
  488 + List<String> objList = new ArrayList<String>();
  489 + if(type.equals("all")){
  490 + sql="select t.gsdm,t.xl,t.xl_name,t.jhccz as jhcc,t.sjcc"
  491 + + " from bsth_c_calc_count t where t.date = ?"
  492 + + " and xl = ?";
  493 + objList.add(date);
  494 + objList.add(line);
  495 + }
  496 + if(type.equals("actual")){
  497 + sql="select t.gsdm,t.xl,t.xl_name,t.jhcc as jhcc,t.sjcc"
  498 + + " from bsth_c_calc_count t where t.date = ?"
  499 + + " and xl = ?";
  500 + objList.add(date);
  501 + objList.add(line);
  502 +
  503 + }
  504 + List<Map<String, Object>> list=jdbcTemplate.query(sql, objList.toArray(),
  505 + new RowMapper<Map<String, Object>>(){
  506 + @Override
  507 + public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
  508 + Map<String, Object> m=new HashMap<String,Object>();
  509 + m.put("company", rs.getString("gsdm"));
  510 + m.put("companyName", getGs(rs.getString("gsdm")));
  511 + m.put("lineCode",rs.getString("xl"));
  512 + m.put("lineName", rs.getString("xl_name"));
  513 + m.put("jhcc", rs.getString("jhcc"));
  514 + m.put("sjcc", rs.getString("sjcc"));
  515 + return m;
  516 + }
  517 + });
  518 +
  519 + return list;
  520 + }
  521 +
  522 + /*
  523 + * 线路配车接口结束
  524 + */
  525 +
  526 + /*
  527 + * 线路配人接口开始
  528 + */
  529 + @GET
  530 + @Path("/linePerson/{type}/date/{date}")
  531 + public List<Map<String, Object>> findLinePersonByDate(@PathParam("type") String type,@PathParam("date") String date) {
  532 + String sql="";
  533 + List<String> objList = new ArrayList<String>();
  534 + if(type.equals("all")){
  535 + sql="select t.date,t.gsdm,t.xl,t.xl_name,t.jhprz as jhpr,t.sjpr"
  536 + + " from bsth_c_calc_count t where t.date = ?";
  537 + objList.add(date);
  538 + }
  539 + if(type.equals("actual")){
  540 + sql="select t.date,t.gsdm,t.xl,t.xl_name,t.jhprss as jhpr,t.sjpr"
  541 + + " from bsth_c_calc_count t where t.date = ?";
  542 + objList.add(date);
  543 + }
  544 + List<Map<String, Object>> list=jdbcTemplate.query(sql, objList.toArray(),
  545 + new RowMapper<Map<String, Object>>(){
  546 + @Override
  547 + public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
  548 + Map<String, Object> m=new HashMap<String,Object>();
  549 + m.put("date", rs.getString("date"));
  550 + m.put("company", rs.getString("gsdm"));
  551 + m.put("companyName", getGs(rs.getString("gsdm")));
  552 + m.put("lineCode",rs.getString("xl"));
  553 + m.put("lineName", rs.getString("xl_name"));
  554 + String jhpr=rs.getString("jhpr");
  555 + m.put("jhjsy", jhpr.split("/")[0]);
  556 + m.put("jhspy", jhpr.split("/")[1]);
  557 + String sjpr= rs.getString("sjpr");
  558 + m.put("sjjsy", sjpr.split("/")[0]);
  559 + m.put("sjspy", sjpr.split("/")[1]);
  560 + return m;
  561 + }
  562 + });
  563 +
  564 + return list;
  565 + }
  566 +
  567 +
  568 + @GET
  569 + @Path("/linePerson/{type}/date/{date}/line/{line}")
  570 + public List<Map<String, Object>> findLinePersonByDateLine(@PathParam("type") String type,@PathParam("date") String date,
  571 + @PathParam("line") String line) {
  572 + String sql="";
  573 + List<String> objList = new ArrayList<String>();
  574 + if(type.equals("all")){
  575 + sql="select t.date,t.gsdm,t.xl,t.xl_name,t.jhprz as jhpr,t.sjpr"
  576 + + " from bsth_c_calc_count t where t.date = ?"
  577 + + " and xl = ?";
  578 + objList.add(date);
  579 + objList.add(line);
  580 + }
  581 + if(type.equals("actual")){
  582 + sql="select t.date,t.gsdm,t.xl,t.xl_name,t.jhprss as jhpr,t.sjpr"
  583 + + " from bsth_c_calc_count t where t.date = ?"
  584 + + " and xl = ?";
  585 + objList.add(date);
  586 + objList.add(line);
  587 + }
  588 + List<Map<String, Object>> list=jdbcTemplate.query(sql, objList.toArray(),
  589 + new RowMapper<Map<String, Object>>(){
  590 + @Override
  591 + public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
  592 + Map<String, Object> m=new HashMap<String,Object>();
  593 + m.put("date", rs.getString("date"));
  594 + m.put("company", rs.getString("gsdm"));
  595 + m.put("companyName", getGs(rs.getString("gsdm")));
  596 + m.put("lineCode",rs.getString("xl"));
  597 + m.put("lineName", rs.getString("xl_name"));
  598 + String jhpr=rs.getString("jhpr");
  599 + m.put("jhjsy", jhpr.split("/")[0]);
  600 + m.put("jhspy", jhpr.split("/")[1]);
  601 + String sjpr= rs.getString("sjpr");
  602 + m.put("sjjsy", sjpr.split("/")[0]);
  603 + m.put("sjspy", sjpr.split("/")[1]);
  604 + return m;
  605 + }
  606 + });
  607 +
  608 + return list;
  609 + }
  610 +
  611 +
  612 +
  613 +
  614 + /*
  615 + * 线路配人接口结束
  616 + */
  617 +
  618 +
  619 + /*
  620 + * 线路班次接口开始
  621 + */
  622 + @GET
  623 + @Path("/lineBc/{type}/date/{date}")
  624 + public List<Map<String, Object>> findLineBcByDate(@PathParam("type") String type,
  625 + @PathParam("date") String date) {
  626 + String sql="";
  627 + List<String> objList = new ArrayList<String>();
  628 + if(type.equals("all")){
  629 + sql="select t.gsdm,t.xl,t.xl_name,t.jhbcz as jhbc,t.jhzgfbcz as jhzgfbc,"
  630 + + " t.jhwgfbcz as jhwgfbc,t.sjbc,t.sjzgfbc,t.sjwgfbc from bsth_c_calc_count t"
  631 + + " where t.date = ?";
  632 + objList.add(date);
  633 + }
  634 + if(type.equals("actual")){
  635 + sql="select t.gsdm,t.xl,t.xl_name,t.jhbc as jhbc,t.jhzgfbcss as jhzgfbc,"
  636 + + " t.jhwgfbcss as jhwgfbc,t.sjbc,t.sjzgfbc,t.sjwgfbc from bsth_c_calc_count t"
  637 + + " where t.date = ?";
  638 + objList.add(date);
  639 + }
  640 + List<Map<String, Object>> list=jdbcTemplate.query(sql, objList.toArray(),
  641 + new RowMapper<Map<String, Object>>(){
  642 + @Override
  643 + public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
  644 + Map<String, Object> m=new HashMap<String,Object>();
  645 + m.put("company", rs.getString("gsdm"));
  646 + m.put("companyName", getGs(rs.getString("gsdm")));
  647 + m.put("lineCode",rs.getString("xl"));
  648 + m.put("lineName", rs.getString("xl_name"));
  649 + m.put("jhbc", rs.getString("jhbc"));
  650 + m.put("jhzgfbc", rs.getString("jhzgfbc"));
  651 + m.put("jhwgfbc", rs.getString("jhwgfbc"));
  652 + m.put("sjbc", rs.getString("sjbc"));
  653 + m.put("sjzgfbc", rs.getString("sjzgfbc"));
  654 + m.put("sjwgfbc", rs.getString("sjwgfbc"));
  655 + return m;
  656 + }
  657 + });
  658 + return list;
  659 + }
  660 +
  661 +
  662 + @GET
  663 + @Path("/lineBc/{type}/date/{date}/line/{line}")
  664 + public List<Map<String, Object>> findLineBcByDateLine(@PathParam("type") String type,
  665 + @PathParam("date") String date,@PathParam("line") String line) {
  666 + String sql="";
  667 + List<String> objList = new ArrayList<String>();
  668 + if(type.equals("all")){
  669 + sql="select t.gsdm,t.xl,t.xl_name,t.jhbcz as jhbc,t.jhzgfbcz as jhzgfbc,"
  670 + + " t.jhwgfbcz as jhwgfbc,t.sjbc,t.sjzgfbc,t.sjwgfbc from bsth_c_calc_count t "
  671 + + " where t.date = ? and xl = ?";
  672 + objList.add(date);
  673 + objList.add(line);
  674 + }
  675 + if(type.equals("actual")){
  676 + sql="select t.gsdm,t.xl,t.xl_name,t.jhbc as jhbc,t.jhzgfbcss as jhzgfbc,"
  677 + + " t.jhwgfbcss as jhwgfbc,t.sjbc,t.sjzgfbc,t.sjwgfbc from bsth_c_calc_count t"
  678 + + " where t.date = ? and xl = ?";
  679 + objList.add(date);
  680 + objList.add(line);
  681 + }
  682 + List<Map<String, Object>> list=jdbcTemplate.query(sql, objList.toArray(),
  683 + new RowMapper<Map<String, Object>>(){
  684 + @Override
  685 + public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
  686 + Map<String, Object> m=new HashMap<String,Object>();
  687 + m.put("company", rs.getString("gsdm"));
  688 + m.put("companyName", getGs(rs.getString("gsdm")));
  689 + m.put("lineCode",rs.getString("xl"));
  690 + m.put("lineName", rs.getString("xl_name"));
  691 + m.put("jhbc", rs.getString("jhbc"));
  692 + m.put("jhzgfbc", rs.getString("jhzgfbc"));
  693 + m.put("jhwgfbc", rs.getString("jhwgfbc"));
  694 + m.put("sjbc", rs.getString("sjbc"));
  695 + m.put("sjzgfbc", rs.getString("sjzgfbc"));
  696 + m.put("sjwgfbc", rs.getString("sjwgfbc"));
  697 + return m;
  698 + }
  699 + });
  700 + return list;
  701 + }
  702 +
  703 + /*
  704 + * 线路班次接口结束
  705 + */
  706 +
  707 + /*
  708 + * 线路里程接口开始
  709 + */
  710 +
  711 + @GET
  712 + @Path("/lineLc/{type}/date/{date}")
  713 + public List<Map<String, Object>> findLineLcByDate(@PathParam("type") String type,
  714 + @PathParam("date") String date) {
  715 + String sql="";
  716 + List<String> objList = new ArrayList<String>();
  717 + if(type.equals("all")){
  718 + sql="select t.gsdm,t.xl,t.xl_name,t.jhzglz as jhzlc,t.jhyylcz as jhyylc,"
  719 + + " t.jhkslcz as jhkslc,t.sjzgl as sjzlc,t.sjyylc,t.sjkslc from bsth_c_calc_count t"
  720 + + " where t.date = ?";
  721 + objList.add(date);
  722 + }
  723 + if(type.equals("actual")){
  724 + sql="select t.gsdm,t.xl,t.xl_name,t.jhzgl as jhzlc,t.jhyylc as jhyylc,"
  725 + + " t.jhkslc as jhkslc,t.sjzgl as sjzlc,t.sjyylc,t.sjkslc from bsth_c_calc_count t"
  726 + + " where t.date = ?";
  727 + objList.add(date);
  728 + }
  729 + List<Map<String, Object>> list=jdbcTemplate.query(sql, objList.toArray(),
  730 + new RowMapper<Map<String, Object>>(){
  731 + @Override
  732 + public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
  733 + Map<String, Object> m=new HashMap<String,Object>();
  734 + m.put("company", rs.getString("gsdm"));
  735 + m.put("companyName", getGs(rs.getString("gsdm")));
  736 + m.put("lineCode",rs.getString("xl"));
  737 + m.put("lineName", rs.getString("xl_name"));
  738 + m.put("jhzlc", rs.getString("jhzlc"));
  739 + m.put("jhyylc", rs.getString("jhyylc"));
  740 + m.put("jhkslc", rs.getString("jhkslc"));
  741 + m.put("sjzlc", rs.getString("sjzlc"));
  742 + m.put("sjyylc", rs.getString("sjyylc"));
  743 + m.put("sjkslc", rs.getString("sjkslc"));
  744 + if(Double.parseDouble(rs.getString("jhzlc"))>0){
  745 + double zlczxl=Double.parseDouble(rs.getString("sjzlc"))/Double.parseDouble(rs.getString("jhzlc"));
  746 + m.put("zlczxl",df.format(zlczxl*100)+"%");
  747 + }else{
  748 + m.put("zlczxl","0.00%");
  749 +
  750 + }
  751 + if(Double.parseDouble(rs.getString("jhyylc"))>0){
  752 + double yylczxl=Double.parseDouble(rs.getString("sjyylc"))/Double.parseDouble(rs.getString("jhyylc"));
  753 + m.put("yylczxl",df.format(yylczxl*100)+"%");
  754 + }else{
  755 + m.put("yylczxl","0.00%");
  756 + }
  757 + return m;
  758 + }
  759 + });
  760 + return list;
  761 + }
  762 +
  763 +
  764 + @GET
  765 + @Path("/lineLc/{type}/date/{date}/line/{line}")
  766 + public List<Map<String, Object>> findLineLcByDateLine(@PathParam("type") String type,
  767 + @PathParam("date") String date,@PathParam("line") String line) {
  768 + String sql="";
  769 + List<String> objList = new ArrayList<String>();
  770 + if(type.equals("all")){
  771 + sql="select t.gsdm,t.xl,t.xl_name,t.jhzglz as jhzlc,t.jhyylcz as jhyylc,"
  772 + + " t.jhkslcz as jhkslc,t.sjzgl as sjzlc,t.sjyylc,t.sjkslc from bsth_c_calc_count t"
  773 + + " where t.date = ? and xl = ?";
  774 + objList.add(date);
  775 + objList.add(line);
  776 + }
  777 + if(type.equals("actual")){
  778 + sql="select t.gsdm,t.xl,t.xl_name,t.jhzgl as jhzlc,t.jhyylc as jhyylc,"
  779 + + " t.jhkslc as jhkslc,t.sjzgl as sjzlc,t.sjyylc,t.sjkslc from bsth_c_calc_count t"
  780 + + " where t.date = ? and xl = ?";
  781 + objList.add(date);
  782 + objList.add(line);
  783 + }
  784 + List<Map<String, Object>> list=jdbcTemplate.query(sql, objList.toArray(),
  785 + new RowMapper<Map<String, Object>>(){
  786 + @Override
  787 + public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
  788 + Map<String, Object> m=new HashMap<String,Object>();
  789 + m.put("company", rs.getString("gsdm"));
  790 + m.put("companyName", getGs(rs.getString("gsdm")));
  791 + m.put("lineCode",rs.getString("xl"));
  792 + m.put("lineName", rs.getString("xl_name"));
  793 + m.put("jhzlc", rs.getString("jhzlc"));
  794 + m.put("jhyylc", rs.getString("jhyylc"));
  795 + m.put("jhkslc", rs.getString("jhkslc"));
  796 + m.put("sjzlc", rs.getString("sjzlc"));
  797 + m.put("sjyylc", rs.getString("sjyylc"));
  798 + m.put("sjkslc", rs.getString("sjkslc"));
  799 + if(Double.parseDouble(rs.getString("jhzlc"))>0){
  800 + double zlczxl=Double.parseDouble(rs.getString("sjzlc"))/Double.parseDouble(rs.getString("jhzlc"));
  801 + m.put("zlczxl",df.format(zlczxl*100)+"%");
  802 + }else{
  803 + m.put("zlczxl","0.00%");
  804 +
  805 + }
  806 + if(Double.parseDouble(rs.getString("jhyylc"))>0){
  807 + double yylczxl=Double.parseDouble(rs.getString("sjyylc"))/Double.parseDouble(rs.getString("jhyylc"));
  808 + m.put("yylczxl",df.format(yylczxl*100)+"%");
  809 + }else{
  810 + m.put("yylczxl","0.00%");
  811 + }
  812 + return m;
  813 + }
  814 + });
  815 + return list;
  816 + }
  817 + /*
  818 + * 线路里程接口结束
  819 + */
  820 +
  821 +
  822 + /*
  823 + * 班次执行率连续三天不满93%推送
  824 + */
  825 + @GET
  826 + @Path("/abnormal/executionRate/date/{date}")
  827 + public List<Map<String, Object>> executionRate(@PathParam("date") String date) {
  828 + List<String> objList = new ArrayList<String>();
  829 + String sql="select gs_name,show_date,xl_bm,xl_name from bsth_c_calc_push t"
  830 + + " where t.date = ? and push_type in ('1','3')";
  831 + objList.add(date);
  832 + List<Map<String, Object>> list=jdbcTemplate.query(sql, objList.toArray(),
  833 + new RowMapper<Map<String, Object>>(){
  834 + @Override
  835 + public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
  836 + Map<String, Object> m=new HashMap<String,Object>();
  837 + m.put("companyName", rs.getString("gs_name"));
  838 + m.put("lineCode",rs.getString("xl_bm"));
  839 + m.put("lineName", rs.getString("xl_name"));
  840 + m.put("showDate", rs.getString("show_date"));
  841 + return m;
  842 + }
  843 + });
  844 + return list;
  845 + }
  846 + /*
  847 + * 首末班发车连续三天不准点
  848 + */
  849 + @GET
  850 + @Path("/abnormal/firstAndLast/date/{date}")
  851 + public List<Map<String, Object>> firstAndLast(@PathParam("date") String date) {
  852 + List<String> objList = new ArrayList<String>();
  853 + String sql="select gs_name,show_date,xl_bm,xl_name from bsth_c_calc_push t"
  854 + + " where t.date = ? and push_type in ('2','3')";
  855 + objList.add(date);
  856 + List<Map<String, Object>> list=jdbcTemplate.query(sql, objList.toArray(),
  857 + new RowMapper<Map<String, Object>>(){
  858 + @Override
  859 + public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
  860 + Map<String, Object> m=new HashMap<String,Object>();
  861 + m.put("companyName", rs.getString("gs_name"));
  862 + m.put("lineCode",rs.getString("xl_bm"));
  863 + m.put("lineName", rs.getString("xl_name"));
  864 + m.put("showDate", rs.getString("show_date"));
  865 + return m;
  866 + }
  867 + });
  868 + return list;
  869 + }
  870 +
  871 + /*
  872 + * 车辆数据接口开始
  873 + */
  874 +
  875 + @GET
  876 + @Path("/car/all")
  877 + public List<Map<String, Object>> findCar() {
  878 + String carStr= GetHttpInterface.getHttpInterface("http://180.166.5.82:8076/cars/getAllCarsInterface");
  879 + //车辆库资料资料
  880 + List<Map<String, Object>> clkList=(List<Map<String, Object>>) JSONObject.parse(carStr);
  881 + //调度系统车辆资料
  882 + String carSql="select equipment_code, inside_code,supplier_name from bsth_c_cars";
  883 + List<Map<String, Object>> ddkList=jdbcTemplate.query(carSql,
  884 + new RowMapper<Map<String, Object>>(){
  885 + @Override
  886 + public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
  887 + Map<String, Object> m=new HashMap<String,Object>();
  888 + m.put("equipment_code", rs.getString("equipment_code"));
  889 + m.put("insideCode", rs.getString("inside_code"));
  890 + m.put("supplier_name",rs.getString("supplier_name"));
  891 + return m;
  892 + }
  893 + });
  894 + for (int i = 0; i < clkList.size(); i++) {
  895 + Map<String, Object> m1=clkList.get(i);
  896 + String carCode=m1.get("car_code").toString();
  897 + m1.put("state_name", getState(m1.get("car_state")==null?"":m1.get("car_state").toString()));
  898 + for (int j = 0; j < ddkList.size(); j++) {
  899 + Map<String, Object> m2=ddkList.get(j);
  900 + String insideCode=m2.get("insideCode").toString();
  901 + if(carCode.equals(insideCode)){
  902 + m1.put("equipment_code", m2.get("equipment_code"));
  903 + m1.put("supplier_name", m2.get("supplier_name"));
  904 + }
  905 +
  906 + }
  907 + }
  908 + return clkList;
  909 + }
  910 +
  911 +
  912 + @GET
  913 + @Path("/car/company/{companyId}")
  914 + public List<Map<String, Object>> findCarByCompany(@PathParam("companyId") String companyId) {
  915 + String carStr= GetHttpInterface.
  916 + getHttpInterface("http://180.166.5.82:8076/cars/getAllCarsInterface?company="+companyId);
  917 + //车辆库资料资料
  918 + List<Map<String, Object>> clkList=(List<Map<String, Object>>) JSONObject.parse(carStr);
  919 + //调度系统车辆资料
  920 + String carSql="select equipment_code, inside_code,supplier_name from bsth_c_cars where business_code='"+companyId+"'";
  921 + List<Map<String, Object>> ddkList=jdbcTemplate.query(carSql,
  922 + new RowMapper<Map<String, Object>>(){
  923 + @Override
  924 + public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
  925 + Map<String, Object> m=new HashMap<String,Object>();
  926 + m.put("equipment_code", rs.getString("equipment_code"));
  927 + m.put("insideCode", rs.getString("inside_code"));
  928 + m.put("supplier_name",rs.getString("supplier_name"));
  929 + return m;
  930 + }
  931 + });
  932 + for (int i = 0; i < clkList.size(); i++) {
  933 + Map<String, Object> m1=clkList.get(i);
  934 + String carCode=m1.get("car_code").toString();
  935 + m1.put("state_name", getState(m1.get("car_state")==null?"":m1.get("car_state").toString()));
  936 + for (int j = 0; j < ddkList.size(); j++) {
  937 + Map<String, Object> m2=ddkList.get(j);
  938 + String insideCode=m2.get("insideCode").toString();
  939 + if(carCode.equals(insideCode)){
  940 + m1.put("equipment_code", m2.get("equipment_code"));
  941 + m1.put("supplier_name", m2.get("supplier_name"));
  942 + }
  943 +
  944 + }
  945 + }
  946 + return clkList;
  947 + }
  948 +
  949 + @GET
  950 + @Path("/car/code/{carCode}")
  951 + public List<Map<String, Object>> findCarByCode(@PathParam("carCode") String carCode) {
  952 + String carStr= GetHttpInterface.
  953 + getHttpInterface("http://101.95.0.106:8076/cars/getAllCarsInterface?car_code="+carCode);
  954 + //车辆库资料资料
  955 + List<Map<String, Object>> clkList=(List<Map<String, Object>>) JSONObject.parse(carStr);
  956 + //调度系统车辆资料
  957 + String carSql="select equipment_code, inside_code,supplier_name from bsth_c_cars where inside_code='"+carCode+"'";
  958 + List<Map<String, Object>> ddkList=jdbcTemplate.query(carSql,
  959 + new RowMapper<Map<String, Object>>(){
  960 + @Override
  961 + public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
  962 + Map<String, Object> m=new HashMap<String,Object>();
  963 + m.put("equipment_code", rs.getString("equipment_code"));
  964 + m.put("insideCode", rs.getString("inside_code"));
  965 + m.put("supplier_name",rs.getString("supplier_name"));
  966 + return m;
  967 + }
  968 + });
  969 +
  970 + for (int i = 0; i < clkList.size(); i++) {
  971 + Map<String, Object> m1=clkList.get(i);
  972 + String code=m1.get("car_code").toString().trim();
  973 + m1.put("state_name", getState(m1.get("car_state")==null?"":m1.get("car_state").toString()));
  974 + for (int j = 0; j < ddkList.size(); j++) {
  975 + Map<String, Object> m2=ddkList.get(j);
  976 + String insideCode=m2.get("insideCode").toString().trim();
  977 + if(code.equals(insideCode)){
  978 + m1.put("equipment_code", m2.get("equipment_code"));
  979 + m1.put("supplier_name", m2.get("supplier_name"));
  980 + }
  981 +
  982 + }
  983 + }
  984 + return clkList;
  985 + }
  986 + /*
  987 + * 车辆数据接口结束
  988 + */
  989 +
  990 + /*
  991 + * 事故数据接口开始
  992 + */
  993 + @GET
  994 + @Path("/accident/startTime/{startTime}/endTime/{endTime}")
  995 + public List<Map<String, Object>> findAccident(@PathParam("startTime") String startTime,
  996 + @PathParam("endTime") String endTime) {
  997 + String accidentAll= GetHttpInterface.getHttpInterface("http://180.168.57.114:9019/pdsafe/LineSms/getAccidentSubmitAll.do?"
  998 + + "submitDateBegin="+startTime+"&submitDateEnd="+endTime);
  999 + List<Map<String, Object>> list=(List<Map<String, Object>>) JSONObject.parse(accidentAll);
  1000 + return list;
  1001 + }
  1002 +
  1003 +
  1004 + /*
  1005 + * 事故数据接口结束
  1006 + */
  1007 +
  1008 + /*
  1009 + *安全驾驶接口开始
  1010 + */
  1011 + @GET
  1012 + @Path("/safedriving/starDate/{starDate}/endDate/{endDate}")
  1013 + public List<Map<String, Object>> findSafedriving(@PathParam("starDate") String starDate,
  1014 + @PathParam("endDate") String endDate) {
  1015 + String accidentAll= GetHttpInterface.getHttpInterface("http://211.95.61.66:9006/safedriving/safedrivingInterface?StarTime="+starDate+"&EndTime="+endDate);
  1016 + List<Map<String, Object>> list=(List<Map<String, Object>>) JSONObject.parse(accidentAll);
  1017 + return list;
  1018 + }
  1019 + @GET
  1020 + @Path("/safedriving/starDate/{starDate}/endDate/{endDate}/line/{line}")
  1021 + public List<Map<String, Object>> findSafedrivingByLine(@PathParam("starDate") String starDate,
  1022 + @PathParam("endDate") String endDate,@PathParam("line") String line) {
  1023 + String accidentAll= GetHttpInterface.getHttpInterface("http://211.95.61.66:9006/safedriving/safedrivingInterface?StarTime="+starDate+"&EndTime="+endDate
  1024 + +"&LineId="+line);
  1025 + List<Map<String, Object>> list=(List<Map<String, Object>>) JSONObject.parse(accidentAll);
  1026 + return list;
  1027 + }
  1028 + /*
  1029 + *安全驾驶接口结束
  1030 + */
  1031 +
  1032 +
  1033 + /**
  1034 + * 闵行线路班次里程
  1035 + *
  1036 + *
  1037 + *
  1038 + */
  1039 +
  1040 + @GET
  1041 + @Path("/findByAll/starDate/{starDate}/endDate/{endDate}/line/{line}")
  1042 + public List<Map<String, Object>> findMinhang(@PathParam("starDate") String starDate,
  1043 + @PathParam("endDate") String endDate,@PathParam("line") String line) {
  1044 + List<String> objList = new ArrayList<String>();
  1045 + String sql="select xl,xl_name,date,jhszfcs,sjszfczds,jhbc,sjbc,jhcc,sjcc,"
  1046 + + " jhyylc,sjyylc,jhkslc,sjkslc,jhssgfbcs,sjgfbcs,jhssdgbcs,"
  1047 + + " sjdgbcs from bsth_c_calc_count "
  1048 + + " where date >= ? and date <= ?";
  1049 + objList.add(starDate);
  1050 + objList.add(endDate);
  1051 +
  1052 + if(!line.equals("all")){
  1053 + sql +=" and xl = ?";
  1054 + objList.add(line);
  1055 + }
  1056 +
  1057 + List<Map<String, Object>> list=jdbcTemplate.query(sql, objList.toArray(),
  1058 + new RowMapper<Map<String, Object>>(){
  1059 + @Override
  1060 + public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
  1061 + Map<String, Object> m=new HashMap<String,Object>();
  1062 + m.put("lineCode",rs.getString("xl"));
  1063 + m.put("lineName", rs.getString("xl_name"));
  1064 + m.put("date", rs.getString("date"));
  1065 + m.put("jhszfcs", rs.getString("jhszfcs"));
  1066 + m.put("sjszfczds", rs.getString("sjszfczds"));
  1067 + m.put("jhbc", rs.getString("jhbc"));
  1068 + m.put("sjbc", rs.getString("sjbc"));
  1069 + m.put("jhcc", rs.getString("jhcc"));
  1070 + m.put("sjcc", rs.getString("sjcc"));
  1071 + m.put("jhyylc", rs.getString("jhyylc"));
  1072 + m.put("sjyylc", rs.getString("sjyylc"));
  1073 + m.put("jhkslc", rs.getString("jhkslc"));
  1074 + m.put("sjkslc", rs.getString("sjkslc"));
  1075 + m.put("jhgfbcs", rs.getString("jhssgfbcs"));
  1076 + m.put("sjgfbcs", rs.getString("sjgfbcs"));
  1077 + m.put("jhdgbcs", rs.getString("jhssdgbcs"));
  1078 + m.put("sjdgbcs", rs.getString("sjdgbcs"));
  1079 + return m;
  1080 + }
  1081 + });
  1082 + return list;
  1083 + }
  1084 +
  1085 + /**
  1086 + * 赵冲需要的数据接口
  1087 + *
  1088 + */
  1089 + @GET
  1090 + @Path("/findByCompany/{company}/date/{date}")
  1091 + public List<Map<String, Object>> findByCompany(@PathParam("company") String company,
  1092 + @PathParam("date") String date) {
  1093 + List<String> objList = new ArrayList<String>();
  1094 + String sql="select t.company as gs_code,t.date,SUM(t.jhcczgf) as jhccs ,SUM(t.sjcczgf) as ccs,AVG(ccl) as ccl"
  1095 + + " ,SUM(t.sjzgl*1000)/1000 as sum_mileage ,SUM(jcgl*1000)/1000 as airpor_mileage "
  1096 + + " from (select a.line_code,b.date,a.company,b.jhcczgf,b.sjcczgf,"
  1097 + + " round(if(ifnull(b.sjcczgf/b.jhcczgf,0)>1,1,ifnull(b.sjcczgf/b.jhcczgf,0)),3) as ccl,c.sjzgl ,"
  1098 + + " ifnull(d.sjzgl,0) as jcgl from bsth_c_line a LEFT JOIN "
  1099 + + " (SELECT * from bsth_c_calc_sheet where date = ?) b on a.line_code=b.xl"
  1100 + + " left join (select * from bsth_c_calc_count where date = ?) c on a.line_code=c.xl "
  1101 + + " left join (select * from bsth_c_calc_count where date = ? "
  1102 + + " and xl_name like '%机场%') d on a.line_code=d.xl "
  1103 + + " where a.nature in ('yxl','cgxl','gjxl','csbs','cctxl')) t "
  1104 + + " where t.date is not null ";
  1105 + objList.add(date);
  1106 + objList.add(date);
  1107 + objList.add(date);
  1108 + if(!company.equals("all")){
  1109 + sql +=" and t.company = ?";
  1110 + objList.add(company);
  1111 + }
  1112 + sql +=" group by t.company,t.date";
  1113 +
  1114 + List<Map<String, Object>> list=jdbcTemplate.query(sql, objList.toArray(),
  1115 + new RowMapper<Map<String, Object>>(){
  1116 + @Override
  1117 + public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
  1118 + Map<String, Object> m=new HashMap<String,Object>();
  1119 + m.put("gs_name", getGs(rs.getString("gs_code")));
  1120 + m.put("gs_code",rs.getString("gs_code"));
  1121 + m.put("date", rs.getString("date"));
  1122 + m.put("jhccs", rs.getString("jhccs"));
  1123 + m.put("ccs", rs.getString("ccs"));
  1124 + m.put("ccl", rs.getString("ccl"));
  1125 + m.put("sum_mileage", rs.getString("sum_mileage"));
  1126 + m.put("airpor_mileage", rs.getString("airpor_mileage"));
  1127 + return m;
  1128 + }
  1129 + });
  1130 + return list;
  1131 + }
  1132 + @GET
  1133 + @Path("/findTarget/gs/{gs}/fgs/{fgs}/date/{date}")
  1134 + public List<Map<String, Object>> findTarget(@PathParam("gs") String gs,@PathParam("fgs") String fgs,
  1135 + @PathParam("date") String date) {
  1136 + SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd");
  1137 + String d=sdf.format(new Date());
  1138 + String sql="";
  1139 + List<String> objList = new ArrayList<String>();
  1140 + if(gs.equals("all")){
  1141 + sql ="select x.gsdm,'' as fgsdm,x.smb_zdl,x.zgf_ccl,y.yylc_zxl,y.szfc_zdl,y.bc_zxl from ("
  1142 + + " select b.gsdm,round(avg(if(ifnull(b.sjcczgf/b.jhcczgf,0)>1,1,ifnull(b.sjcczgf/b.jhcczgf,0))),3)* 100 as zgf_ccl,"
  1143 + + " round(avg(ifnull(b.smbfczdl,0)),3) as smb_zdl from "
  1144 + + " bsth_c_calc_sheet b where b.date like ? and b.date < ? "
  1145 + + " and b.xl in(select a.line_code from bsth_c_line a where "
  1146 + + " a.nature in ('yxl','cgxl','gjxl','csbs','cctxl') ) group by b.gsdm ) x "
  1147 + + " left join (select c.gsdm,round(avg(if(CONVERT(c.yylczxl,DECIMAL(9,2))>100,100,c.yylczxl)),3) as yylc_zxl,"
  1148 + + " round(avg(if(CONVERT(c.szfczdl,DECIMAL(9,2))>100,100,c.szfczdl)),3) as szfc_zdl,"
  1149 + + " round(avg(if(CONVERT(c.bczxl,DECIMAL(9,2))>100,100,c.bczxl)),3) as bc_zxl "
  1150 + + " from bsth_c_calc_count c where c.date like ? and c.date < ? and "
  1151 + + " c.xl in(select a.line_code from bsth_c_line a where a.nature in ('yxl','cgxl','gjxl','csbs','cctxl') ) "
  1152 + + " group by c.gsdm ) y on x.gsdm=y.gsdm where 1=1 ";
  1153 + objList.add("%"+date+"%");
  1154 + objList.add(d);
  1155 + objList.add("%"+date+"%");
  1156 + objList.add(d);
  1157 +
  1158 + }else{
  1159 + sql ="select x.gsdm,x.fgsdm,x.smb_zdl,x.zgf_ccl,y.yylc_zxl,y.szfc_zdl,y.bc_zxl from ("
  1160 + + " select b.gsdm,b.fgsdm,round(avg(if(ifnull(b.sjcczgf/b.jhcczgf,0)>1,1,ifnull(b.sjcczgf/b.jhcczgf,0))),3) * 100 as zgf_ccl,"
  1161 + + " round(avg(ifnull(b.smbfczdl,0)),3) as smb_zdl from "
  1162 + + " bsth_c_calc_sheet b where b.date like ? and b.date < ? "
  1163 + + " and b.xl in(select a.line_code from bsth_c_line a where "
  1164 + + " a.nature in ('yxl','cgxl','gjxl','csbs','cctxl') ) group by b.gsdm,b.fgsdm ) x "
  1165 + + " left join (select c.gsdm,c.fgsdm,round(avg(if(CONVERT(c.yylczxl,DECIMAL(9,2))>100,100,c.yylczxl)),3) as yylc_zxl,"
  1166 + + " round(avg(if(CONVERT(c.szfczdl,DECIMAL(9,2))>100,100,c.szfczdl)),3) as szfc_zdl,"
  1167 + + " round(avg(if(CONVERT(c.bczxl,DECIMAL(9,2))>100,100,c.bczxl)),3) as bc_zxl "
  1168 + + " from bsth_c_calc_count c where c.date like ? and c.date < ? and "
  1169 + + " c.xl in(select a.line_code from bsth_c_line a where a.nature in ('yxl','cgxl','gjxl','csbs','cctxl') ) "
  1170 + + " group by c.gsdm,c.fgsdm ) y on x.gsdm=y.gsdm and x.fgsdm=y.fgsdm where 1=1 ";
  1171 + objList.add("%"+date+"%");
  1172 + objList.add(d);
  1173 + objList.add("%"+date+"%");
  1174 + objList.add(d);
  1175 +
  1176 + }
  1177 + if(!gs.equals("all")){
  1178 + sql += " and x.gsdm = ?";
  1179 + objList.add(gs);
  1180 + }
  1181 +
  1182 + if(!fgs.equals("all")){
  1183 + sql += " and x.fgsdm = ?";
  1184 + objList.add(fgs);
  1185 + }
  1186 + List<Map<String, Object>> list=jdbcTemplate.query(sql, objList.toArray(),
  1187 + new RowMapper<Map<String, Object>>(){
  1188 + @Override
  1189 + public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
  1190 + Map<String, Object> m=new HashMap<String,Object>();
  1191 + m.put("gsdm", getGs(rs.getString("gsdm")));
  1192 + m.put("fgsdm",rs.getString("fgsdm"));
  1193 + m.put("smb_zdl", rs.getString("smb_zdl"));
  1194 + m.put("zgf_ccl", rs.getString("zgf_ccl"));
  1195 + m.put("yylc_zxl", rs.getString("yylc_zxl"));
  1196 + m.put("szfc_zdl", rs.getString("szfc_zdl"));
  1197 + m.put("bc_zxl", rs.getString("bc_zxl"));
  1198 + return m;
  1199 + }
  1200 + });
  1201 + return list;
  1202 + }
  1203 +
  1204 +
  1205 + /**
  1206 + *公司内部使用数据
  1207 + *
  1208 + *班次里程基础数据接口
  1209 + */
  1210 + @GET
  1211 + @Path("/basicData/starDate/{starDate}/endDate/{endDate}/line/{line}")
  1212 + public List<Map<String, Object>> basicData(@PathParam("starDate") String starDate,
  1213 + @PathParam("endDate") String endDate,@PathParam("line") String line) {
  1214 + List<String> objList = new ArrayList<String>();
  1215 + String sql="select gsdm,fgsdm,xl,xl_name,date,jhbc,sjbc,"
  1216 + + " jhyylc,sjyylc,jhkslc,sjkslc,jhgfbcsz,sjgfbcs,jhdgbcsz,"
  1217 + + " sjdgbcs from bsth_c_calc_count "
  1218 + + " where date >= ? and date <= ?";
  1219 + objList.add(starDate);
  1220 + objList.add(endDate);
  1221 + if(!line.equals("all")){
  1222 + sql +=" and xl = ?";
  1223 + objList.add(line);
  1224 + }
  1225 + List<Map<String, Object>> list=jdbcTemplate.query(sql, objList.toArray(),
  1226 + new RowMapper<Map<String, Object>>(){
  1227 + @Override
  1228 + public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
  1229 + Map<String, Object> m=new HashMap<String,Object>();
  1230 + m.put("gsdm",rs.getString("gsdm"));
  1231 + m.put("fgsdm",rs.getString("fgsdm"));
  1232 + m.put("lineCode",rs.getString("xl"));
  1233 + m.put("lineName", rs.getString("xl_name"));
  1234 + m.put("date", rs.getString("date"));
  1235 + m.put("jhbc", rs.getString("jhbc"));
  1236 + m.put("sjbc", rs.getString("sjbc"));
  1237 + m.put("jhyylc", rs.getString("jhyylc"));
  1238 + m.put("sjyylc", rs.getString("sjyylc"));
  1239 + m.put("jhkslc", rs.getString("jhkslc"));
  1240 + m.put("sjkslc", rs.getString("sjkslc"));
  1241 + m.put("jhgfbcs", rs.getString("jhgfbcsz"));
  1242 + m.put("sjgfbcs", rs.getString("sjgfbcs"));
  1243 + m.put("jhdgbcs", rs.getString("jhdgbcsz"));
  1244 + m.put("sjdgbcs", rs.getString("sjdgbcs"));
  1245 + return m;
  1246 + }
  1247 + });
  1248 + return list;
  1249 + }
  1250 +
  1251 + @GET
  1252 + @Path("/targetData/starDate/{starDate}/endDate/{endDate}/line/{line}")
  1253 + public List<Map<String, Object>> targetData(@PathParam("starDate") String starDate,
  1254 + @PathParam("endDate") String endDate,@PathParam("line") String line) {
  1255 + List<String> objList = new ArrayList<String>();
  1256 + String sql="select gsdm,fgsdm,date,xl,xl_name,szfczdl,smbfczdl,"
  1257 + + " round(if(ifnull(sjcczgf/jhcczgf,0)>1,1,ifnull(sjcczgf/jhcczgf,0)),3) * 100 as zgfccl , "
  1258 + + " round(if(ifnull(sjcc/jhcc,0)>1,1,ifnull(sjcc/jhcc,0)),3) * 100 as ccl from bsth_c_calc_sheet "
  1259 + + " where date >= ? and date <= ?";
  1260 + objList.add(starDate);
  1261 + objList.add(endDate);
  1262 + if(!line.equals("all")){
  1263 + sql +=" and xl = ?";
  1264 + objList.add(line);
  1265 + }
  1266 + List<Map<String, Object>> list=jdbcTemplate.query(sql, objList.toArray(),
  1267 + new RowMapper<Map<String, Object>>(){
  1268 + @Override
  1269 + public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
  1270 + Map<String, Object> m=new HashMap<String,Object>();
  1271 + m.put("gsdm",rs.getString("gsdm"));
  1272 + m.put("fgsdm",rs.getString("fgsdm"));
  1273 + m.put("lineCode",rs.getString("xl"));
  1274 + m.put("lineName", rs.getString("xl_name"));
  1275 + m.put("date", rs.getString("date"));
  1276 + m.put("szfczdl", rs.getString("szfczdl"));
  1277 + m.put("smbfczdl", rs.getString("smbfczdl"));
  1278 + m.put("zgfccl", rs.getString("zgfccl"));
  1279 + m.put("ccl", rs.getString("ccl"));
  1280 + return m;
  1281 + }
  1282 + });
  1283 + return list;
  1284 + }
  1285 +
  1286 + @GET
  1287 + @Path("/departureTime/starDate/{starDate}/endDate/{endDate}/line/{line}")
  1288 + public List<Map<String, Object>> departureTime(@PathParam("starDate") String starDate,
  1289 + @PathParam("endDate") String endDate,@PathParam("line") String line) {
  1290 + List<String> objList = new ArrayList<String>();
  1291 + String sql="select xl,xl_name,date,jhbc,bczxl,jhbcz,sjbc,jhcc,sjcc,ccl,jhccz,"
  1292 + + " jhyylc,sjyylc,jhyylcz,jhkslc,sjkslc,jhkslcz,"
  1293 + + " jhssgfbcs,sjgfbcs,jhgfbcsz,jhssdgbcs,sjdgbcs,jhdgbcsz,"
  1294 + + " jhsmbcs,sjsmbczds,smbczdl,jhsmbcsz,sjsmbczdsz,smbczdlz,"
  1295 + + " jhszfcs,sjszfczds,szfczdl,"
  1296 + + " create_date from bsth_c_calc_count "
  1297 + + " where date >= ? and date <= ?";
  1298 + objList.add(starDate);
  1299 + objList.add(endDate);
  1300 + if(!line.equals("all")){
  1301 + sql +=" and xl = ?";
  1302 + objList.add(line);
  1303 + }
  1304 +
  1305 + List<Map<String, Object>> list=jdbcTemplate.query(sql, objList.toArray(),
  1306 + new RowMapper<Map<String, Object>>(){
  1307 + @Override
  1308 + public Map<String, Object> mapRow(ResultSet rs, int rowNum) throws SQLException {
  1309 + Map<String, Object> m=new HashMap<String,Object>();
  1310 + m.put("lineCode",rs.getString("xl"));
  1311 + m.put("lineName", rs.getString("xl_name"));
  1312 + m.put("date", rs.getString("date"));
  1313 +
  1314 + m.put("jhbc", rs.getString("jhbc"));
  1315 + m.put("sjbc", rs.getString("sjbc"));
  1316 + m.put("bczxl", rs.getString("bczxl"));
  1317 + m.put("jhbcz", rs.getString("jhbcz"));
  1318 +
  1319 + m.put("jhcc", rs.getString("jhcc"));
  1320 + m.put("sjcc", rs.getString("sjcc"));
  1321 + m.put("ccl", rs.getString("ccl"));
  1322 + m.put("jhccz", rs.getString("jhccz"));
  1323 +
  1324 + m.put("jhyylc", rs.getString("jhyylc"));
  1325 + m.put("sjyylc", rs.getString("sjyylc"));
  1326 + m.put("jhyylcz", rs.getString("jhyylcz"));
  1327 + m.put("jhkslc", rs.getString("jhkslc"));
  1328 + m.put("sjkslc", rs.getString("sjkslc"));
  1329 + m.put("jhkslcz", rs.getString("jhkslcz"));
  1330 +
  1331 + m.put("jhgfbcs", rs.getString("jhssgfbcs"));
  1332 + m.put("sjgfbcs", rs.getString("sjgfbcs"));
  1333 + m.put("jhgfbcsz", rs.getString("jhgfbcsz"));
  1334 + m.put("jhdgbcs", rs.getString("jhssdgbcs"));
  1335 + m.put("sjdgbcs", rs.getString("sjdgbcs"));
  1336 + m.put("jhdgbcsz", rs.getString("jhdgbcsz"));
  1337 +
  1338 + m.put("jhsmbcs", rs.getString("jhsmbcs"));
  1339 + m.put("sjsmbczds", rs.getString("sjsmbczds"));
  1340 + m.put("smbczdl", rs.getString("smbczdl"));
  1341 + m.put("jhsmbcsz", rs.getString("jhsmbcsz"));
  1342 + m.put("sjsmbczdsz", rs.getString("sjsmbczdsz"));
  1343 + m.put("smbczdlz", rs.getString("smbczdlz"));
  1344 +
  1345 + m.put("jhszfcs", rs.getString("jhszfcs"));
  1346 + m.put("sjszfczds", rs.getString("sjszfczds"));
  1347 + m.put("szfczdl", rs.getString("szfczdl"));
  1348 +
  1349 + Date date = new Date();
  1350 + date.setTime(rs.getTimestamp("create_date").getTime());
  1351 + m.put("createDate", sdf.format(date));
  1352 + return m;
  1353 + }
  1354 + });
  1355 + return list;
  1356 + }
  1357 +
  1358 +}
src/main/java/com/bsth/server_rs/exception/AesException.java
1 -package com.bsth.server_rs.exception;  
2 -  
3 -/**  
4 - * Created by panzhao on 2017/3/28.  
5 - */  
6 -public class AesException extends RuntimeException {  
7 -  
8 - public final static int OK = 0;  
9 - public final static int MISS_SIGN = -30001;  
10 - public final static int MISS_TIMESTAMP = -30002;  
11 - public final static int MISS_NONCE = -30003;  
12 - public final static int NO_RANDOM_NONCE = -30005;  
13 - public final static int MISS_PWD = -30004;  
14 - public final static int SIGN_CHECK_ERROR = -40001;  
15 - public final static int SIGN_CHECK_FAIL = -40002;  
16 - public final static int INVALID_PWD = -40003;  
17 - public final static int INVALID_TIMESTAMP = -40004;  
18 -  
19 - private int code;  
20 -  
21 - private static String getMessage(int code) {  
22 - switch (code) {  
23 - case MISS_SIGN:  
24 - return "sign参数丢失";  
25 - case MISS_TIMESTAMP:  
26 - return "timestamp参数丢失";  
27 - case MISS_NONCE:  
28 - return "nonce参数丢失";  
29 - case NO_RANDOM_NONCE:  
30 - return "nonce参数异常";  
31 - case MISS_PWD:  
32 - return "密码参数丢失";  
33 - case INVALID_PWD:  
34 - return "无效的密码";  
35 - case SIGN_CHECK_ERROR:  
36 - return "签名校验时出现异常";  
37 - case SIGN_CHECK_FAIL:  
38 - return "无效的签名";  
39 - case INVALID_TIMESTAMP:  
40 - return "无效的时间戳";  
41 - default:  
42 - return null;  
43 - }  
44 - }  
45 -  
46 - public int getCode() {  
47 - return code;  
48 - }  
49 -  
50 - public AesException(int code) {  
51 - super(getMessage(code));  
52 - this.code = code;  
53 - }  
54 -} 1 +package com.bsth.server_rs.exception;
  2 +
  3 +/**
  4 + * Created by panzhao on 2017/3/28.
  5 + */
  6 +public class AesException extends RuntimeException {
  7 +
  8 + public final static int OK = 0;
  9 + public final static int MISS_SIGN = -30001;
  10 + public final static int MISS_TIMESTAMP = -30002;
  11 + public final static int MISS_NONCE = -30003;
  12 + public final static int NO_RANDOM_NONCE = -30005;
  13 + public final static int MISS_PWD = -30004;
  14 + public final static int SIGN_CHECK_ERROR = -40001;
  15 + public final static int SIGN_CHECK_FAIL = -40002;
  16 + public final static int INVALID_PWD = -40003;
  17 + public final static int INVALID_TIMESTAMP = -40004;
  18 + public final static int INVALID_URI = -40005;
  19 +
  20 + private int code;
  21 +
  22 + private static String getMessage(int code) {
  23 + switch (code) {
  24 + case MISS_SIGN:
  25 + return "sign参数丢失";
  26 + case MISS_TIMESTAMP:
  27 + return "timestamp参数丢失";
  28 + case MISS_NONCE:
  29 + return "nonce参数丢失";
  30 + case NO_RANDOM_NONCE:
  31 + return "nonce参数异常";
  32 + case MISS_PWD:
  33 + return "密码参数丢失";
  34 + case INVALID_PWD:
  35 + return "无效的密码";
  36 + case SIGN_CHECK_ERROR:
  37 + return "签名校验时出现异常";
  38 + case SIGN_CHECK_FAIL:
  39 + return "无效的签名";
  40 + case INVALID_TIMESTAMP:
  41 + return "无效的时间戳";
  42 + case INVALID_URI:
  43 + return "无效的URI";
  44 + default:
  45 + return null;
  46 + }
  47 + }
  48 +
  49 + public int getCode() {
  50 + return code;
  51 + }
  52 +
  53 + public AesException(int code) {
  54 + super(getMessage(code));
  55 + this.code = code;
  56 + }
  57 +}
src/main/java/com/bsth/server_rs/gps/buffer/BasicDataBuffer.java
1 -package com.bsth.server_rs.gps.buffer;  
2 -  
3 -import java.util.HashMap;  
4 -import java.util.Map;  
5 -import java.util.Set;  
6 -  
7 -import org.springframework.stereotype.Component;  
8 -  
9 -import com.bsth.server_rs.gps.entity.LineInfo;  
10 -  
11 -/**  
12 - * Created by panzhao on 2017/3/30.  
13 - */  
14 -@Component  
15 -public class BasicDataBuffer {  
16 -  
17 - private static Map<Integer, LineInfo> LINEID_INFO = new HashMap<Integer, LineInfo>();  
18 -  
19 - private static Map<String, String> DEVICE_PLATE = new HashMap<String, String>();  
20 -  
21 - public static void putLine(Integer lineId, LineInfo info) {  
22 - LINEID_INFO.put(lineId, info);  
23 - }  
24 -  
25 - public static void putCar(String deviceId, String plateNo) {  
26 - DEVICE_PLATE.put(deviceId, plateNo);  
27 - }  
28 -  
29 - public static String getPlateByDevice(String deviceId) {  
30 - return DEVICE_PLATE.get(deviceId);  
31 - }  
32 -  
33 - public static Set<Integer> getAllLine() {  
34 - return LINEID_INFO.keySet();  
35 - }  
36 -  
37 - public static LineInfo getLineById(Integer lineId) {  
38 - return LINEID_INFO.get(lineId);  
39 - }  
40 -} 1 +package com.bsth.server_rs.gps.buffer;
  2 +
  3 +import java.util.HashMap;
  4 +import java.util.Map;
  5 +import java.util.Set;
  6 +
  7 +import org.springframework.stereotype.Component;
  8 +
  9 +import com.bsth.server_rs.gps.entity.LineInfo;
  10 +
  11 +/**
  12 + * Created by panzhao on 2017/3/30.
  13 + */
  14 +@Component
  15 +public class BasicDataBuffer {
  16 +
  17 + private static Map<Integer, LineInfo> LINEID_INFO = new HashMap<Integer, LineInfo>();
  18 +
  19 + private static Map<String, String> DEVICE_PLATE = new HashMap<String, String>();
  20 +
  21 + private static Map<String, String> BCODE_NAME = new HashMap<>();
  22 +
  23 + public static void putLine(Integer lineId, LineInfo info) {
  24 + LINEID_INFO.put(lineId, info);
  25 + }
  26 +
  27 + public static void putCar(String deviceId, String plateNo) {
  28 + DEVICE_PLATE.put(deviceId, plateNo);
  29 + }
  30 +
  31 + public static String getPlateByDevice(String deviceId) {
  32 + return DEVICE_PLATE.get(deviceId);
  33 + }
  34 +
  35 + public static Set<Integer> getAllLine() {
  36 + return LINEID_INFO.keySet();
  37 + }
  38 +
  39 + public static LineInfo getLineById(Integer lineId) {
  40 + return LINEID_INFO.get(lineId);
  41 + }
  42 +
  43 + public static void putBusiness(String code, String name) {
  44 + BCODE_NAME.put(code, name);
  45 + }
  46 +
  47 + public static String getBusinessByCode(String code) {
  48 + return BCODE_NAME.get(code);
  49 + }
  50 +}
src/main/java/com/bsth/server_rs/gps/buffer/BasicDataRefreshThread.java
1 -package com.bsth.server_rs.gps.buffer;  
2 -  
3 -import java.sql.ResultSet;  
4 -import java.sql.SQLException;  
5 -import java.util.ArrayList;  
6 -import java.util.List;  
7 -import java.util.Map;  
8 -  
9 -import org.slf4j.Logger;  
10 -import org.slf4j.LoggerFactory;  
11 -import org.springframework.beans.factory.InitializingBean;  
12 -import org.springframework.beans.factory.annotation.Autowired;  
13 -import org.springframework.jdbc.core.JdbcTemplate;  
14 -import org.springframework.jdbc.core.RowMapper;  
15 -import org.springframework.stereotype.Component;  
16 -  
17 -import com.bsth.server_rs.gps.entity.LineInfo;  
18 -import com.bsth.server_rs.gps.entity.Point;  
19 -import com.bsth.server_rs.gps.entity.StopInfo;  
20 -  
21 -/**  
22 - * Created by panzhao on 2017/3/30.  
23 - */  
24 -@Component  
25 -public class BasicDataRefreshThread extends Thread implements InitializingBean {  
26 -  
27 - Logger logger = LoggerFactory.getLogger(this.getClass());  
28 -  
29 - @Autowired  
30 - private JdbcTemplate jdbcTemplate;  
31 -  
32 - @Override  
33 - public void run() {  
34 - loadBasicData();  
35 - }  
36 -  
37 - private void loadBasicData() {  
38 - try {  
39 - String qline = "select a.id,in_use,line_code,name,start_station_name,start_station_first_time,start_station_end_time,end_station_name,end_station_first_time,end_station_end_time,company,branche_company,length,telephone,speed_limit,shanghai_linecode,line_play_type,up_travel_time,down_travel_time from bsth_c_line a left join bsth_c_line_information b on a.id = b.line where a.destroy = 0 and a.nature = 'hlwgj'";  
40 - String qstop = "select b.id,b.station_cod,b.station_name,b.road_coding,b.g_lonx,b.g_laty,b.shapes_type,b.radius,AsText(b.g_polygon_grid) as g_polygon_grid,a.line,a.line_code,a.directions,a.distances from bsth_c_stationroute a join bsth_c_station b on a.station = b.id where a.destroy = 0 order by a.line,a.directions,a.station_route_code";  
41 - String qcar = "select equipment_code device_id, car_plate plate_no from bsth_c_cars";  
42 -  
43 - List<LineInfo> lines = jdbcTemplate.query(qline, new RowMapperLineInfo());  
44 - List<StopInfo> stops = jdbcTemplate.query(qstop, new RowMapperStopInfo());  
45 - List<Map<String, Object>> cars = jdbcTemplate.queryForList(qcar);  
46 -  
47 - // 缓存线路基本信息  
48 - for (LineInfo line : lines) {  
49 - BasicDataBuffer.putLine(line.getLineId(), line);  
50 - }  
51 -  
52 - // 线路信息中添加上下行站点信息  
53 - int oldId = -1;  
54 - LineInfo line = null;  
55 - for (StopInfo stop : stops) {  
56 - if (stop.getLineCode() != oldId) {  
57 - oldId = stop.getLineCode();  
58 - line = BasicDataBuffer.getLineById(oldId);  
59 - }  
60 - if (line != null) {  
61 - if (stop.getDirections() == 0) line.getStopsUp().add(stop);  
62 - else line.getStopsDown().add(stop);  
63 - }  
64 - }  
65 -  
66 - for (Map<String, Object> car : cars) {  
67 - BasicDataBuffer.putCar((String)car.get("device_id"), (String)car.get("plate_no"));  
68 - }  
69 -  
70 - logger.info("基础数据加载成功");  
71 - }catch (Exception e){  
72 - logger.error("基础数据加载失败", e);  
73 - }  
74 - }  
75 -  
76 - final class RowMapperLineInfo implements RowMapper<LineInfo> {  
77 -  
78 - @Override  
79 - public LineInfo mapRow(ResultSet rs, int rowNum) throws SQLException {  
80 - // TODO Auto-generated method stub  
81 - LineInfo line = new LineInfo();  
82 - line.setId(rs.getInt("id"));  
83 - line.setInUse(rs.getInt("in_use"));  
84 - line.setLineId(rs.getInt("line_code"));  
85 - line.setLineName(rs.getString("name"));  
86 - //line.setStartStation(rs.getInt("start_station"));  
87 - line.setStartStationName(rs.getString("start_station_name"));  
88 - line.setStartStationFirstTime(rs.getString("start_station_first_time"));  
89 - line.setStartStationEndTime(rs.getString("start_station_end_time"));  
90 - //line.setEndStation(rs.getInt("end_station"));  
91 - line.setEndStationName(rs.getString("end_station_name"));  
92 - line.setEndStationFirstTime(rs.getString("end_station_first_time"));  
93 - line.setEndStationEndTime(rs.getString("end_station_end_time"));  
94 - line.setCompany(rs.getString("company"));  
95 - line.setBrancheCompany(rs.getString("branche_company"));  
96 - line.setTelephone(rs.getString("telephone"));  
97 - line.setLinePlayType(rs.getInt("line_play_type"));  
98 - return line;  
99 - }  
100 -  
101 - }  
102 -  
103 - final class RowMapperStopInfo implements RowMapper<StopInfo> {  
104 -  
105 - @Override  
106 - public StopInfo mapRow(ResultSet rs, int rowNum) throws SQLException {  
107 - // TODO Auto-generated method stub  
108 - StopInfo stop = new StopInfo();  
109 - stop.setId(rs.getInt("id"));  
110 - stop.setStationCod(rs.getString("station_cod"));  
111 - stop.setStationName(rs.getString("station_name"));  
112 - //stop.setStationType(rs.getString("station_type"));  
113 - stop.setRoadCoding(rs.getString("road_coding"));  
114 - float lon = rs.getFloat("g_lonx");  
115 - float lat = rs.getFloat("g_laty");  
116 - stop.setPoint(new Point(lon, lat));  
117 - stop.setLineId(rs.getInt("line"));  
118 - stop.setLineCode(rs.getInt("line_code"));  
119 - stop.setDirections(rs.getInt("directions"));  
120 - stop.setShapesType(rs.getString("shapes_type"));  
121 - stop.setRadius(rs.getInt("radius"));  
122 - stop.setPoints(new ArrayList<Point>());  
123 - stop.setDistances(rs.getDouble("distances")*1000);  
124 - return stop;  
125 - }  
126 -  
127 - }  
128 -  
129 - @Override  
130 - public void afterPropertiesSet() throws Exception {  
131 - // TODO Auto-generated method stub  
132 - loadBasicData();  
133 - }  
134 -} 1 +package com.bsth.server_rs.gps.buffer;
  2 +
  3 +import java.sql.ResultSet;
  4 +import java.sql.SQLException;
  5 +import java.util.ArrayList;
  6 +import java.util.List;
  7 +import java.util.Map;
  8 +
  9 +import org.slf4j.Logger;
  10 +import org.slf4j.LoggerFactory;
  11 +import org.springframework.beans.factory.InitializingBean;
  12 +import org.springframework.beans.factory.annotation.Autowired;
  13 +import org.springframework.jdbc.core.JdbcTemplate;
  14 +import org.springframework.jdbc.core.RowMapper;
  15 +import org.springframework.stereotype.Component;
  16 +
  17 +import com.bsth.server_rs.gps.entity.LineInfo;
  18 +import com.bsth.server_rs.gps.entity.Point;
  19 +import com.bsth.server_rs.gps.entity.StopInfo;
  20 +
  21 +/**
  22 + * Created by panzhao on 2017/3/30.
  23 + */
  24 +@Component
  25 +public class BasicDataRefreshThread extends Thread implements InitializingBean {
  26 +
  27 + Logger logger = LoggerFactory.getLogger(this.getClass());
  28 +
  29 + @Autowired
  30 + private JdbcTemplate jdbcTemplate;
  31 +
  32 + @Override
  33 + public void run() {
  34 + loadBasicData();
  35 + }
  36 +
  37 + private void loadBasicData() {
  38 + try {
  39 + String qline = "select a.id,in_use,line_code,name,start_station_name,start_station_first_time,start_station_end_time,end_station_name,end_station_first_time,end_station_end_time,company,branche_company,length,telephone,speed_limit,shanghai_linecode,line_play_type,up_travel_time,down_travel_time from bsth_c_line a left join bsth_c_line_information b on a.id = b.line where a.destroy = 0 and a.nature = 'hlwgj'";
  40 + String qstop = "select b.id,b.station_cod,b.station_name,b.road_coding,b.g_lonx,b.g_laty,b.shapes_type,b.radius,AsText(b.g_polygon_grid) as g_polygon_grid,a.line,a.line_code,a.directions,a.distances from bsth_c_stationroute a join bsth_c_station b on a.station = b.id where a.destroy = 0 order by a.line,a.directions,a.station_route_code";
  41 + String qcar = "select equipment_code device_id, car_plate plate_no from bsth_c_cars";
  42 + String qbusiness = "select business_code, up_code, business_name from bsth_c_business where up_code <> 0";
  43 +
  44 + List<LineInfo> lines = jdbcTemplate.query(qline, new RowMapperLineInfo());
  45 + List<StopInfo> stops = jdbcTemplate.query(qstop, new RowMapperStopInfo());
  46 + List<Map<String, Object>> cars = jdbcTemplate.queryForList(qcar);
  47 + List<Map<String, Object>> businesses = jdbcTemplate.queryForList(qbusiness);
  48 +
  49 + // 缓存线路基本信息
  50 + for (LineInfo line : lines) {
  51 + BasicDataBuffer.putLine(line.getLineId(), line);
  52 + }
  53 +
  54 + // 线路信息中添加上下行站点信息
  55 + int oldId = -1;
  56 + LineInfo line = null;
  57 + for (StopInfo stop : stops) {
  58 + if (stop.getLineCode() != oldId) {
  59 + oldId = stop.getLineCode();
  60 + line = BasicDataBuffer.getLineById(oldId);
  61 + }
  62 + if (line != null) {
  63 + if (stop.getDirections() == 0) line.getStopsUp().add(stop);
  64 + else line.getStopsDown().add(stop);
  65 + }
  66 + }
  67 +
  68 + for (Map<String, Object> car : cars) {
  69 + BasicDataBuffer.putCar((String)car.get("device_id"), (String)car.get("plate_no"));
  70 + }
  71 +
  72 + for (Map<String, Object> business : businesses) {
  73 + String businessCode = (String)business.get("business_code"), upCode = (String)business.get("up_code"), businessName = (String)business.get("business_name");
  74 + if ("88".equals(upCode)) {
  75 + BasicDataBuffer.putBusiness(businessCode, businessName);
  76 + } else {
  77 + BasicDataBuffer.putBusiness(String.format("%s_%s", upCode, businessCode), businessName);
  78 + }
  79 + }
  80 +
  81 + logger.info("基础数据加载成功");
  82 + }catch (Exception e){
  83 + logger.error("基础数据加载失败", e);
  84 + }
  85 + }
  86 +
  87 + final class RowMapperLineInfo implements RowMapper<LineInfo> {
  88 +
  89 + @Override
  90 + public LineInfo mapRow(ResultSet rs, int rowNum) throws SQLException {
  91 + // TODO Auto-generated method stub
  92 + LineInfo line = new LineInfo();
  93 + line.setId(rs.getInt("id"));
  94 + line.setInUse(rs.getInt("in_use"));
  95 + line.setLineId(rs.getInt("line_code"));
  96 + line.setLineName(rs.getString("name"));
  97 + //line.setStartStation(rs.getInt("start_station"));
  98 + line.setStartStationName(rs.getString("start_station_name"));
  99 + line.setStartStationFirstTime(rs.getString("start_station_first_time"));
  100 + line.setStartStationEndTime(rs.getString("start_station_end_time"));
  101 + //line.setEndStation(rs.getInt("end_station"));
  102 + line.setEndStationName(rs.getString("end_station_name"));
  103 + line.setEndStationFirstTime(rs.getString("end_station_first_time"));
  104 + line.setEndStationEndTime(rs.getString("end_station_end_time"));
  105 + line.setCompany(rs.getString("company"));
  106 + line.setBrancheCompany(rs.getString("branche_company"));
  107 + line.setTelephone(rs.getString("telephone"));
  108 + line.setLinePlayType(rs.getInt("line_play_type"));
  109 + return line;
  110 + }
  111 +
  112 + }
  113 +
  114 + final class RowMapperStopInfo implements RowMapper<StopInfo> {
  115 +
  116 + @Override
  117 + public StopInfo mapRow(ResultSet rs, int rowNum) throws SQLException {
  118 + // TODO Auto-generated method stub
  119 + StopInfo stop = new StopInfo();
  120 + stop.setId(rs.getInt("id"));
  121 + stop.setStationCod(rs.getString("station_cod"));
  122 + stop.setStationName(rs.getString("station_name"));
  123 + //stop.setStationType(rs.getString("station_type"));
  124 + stop.setRoadCoding(rs.getString("road_coding"));
  125 + float lon = rs.getFloat("g_lonx");
  126 + float lat = rs.getFloat("g_laty");
  127 + stop.setPoint(new Point(lon, lat));
  128 + stop.setLineId(rs.getInt("line"));
  129 + stop.setLineCode(rs.getInt("line_code"));
  130 + stop.setDirections(rs.getInt("directions"));
  131 + stop.setShapesType(rs.getString("shapes_type"));
  132 + stop.setRadius(rs.getInt("radius"));
  133 + stop.setPoints(new ArrayList<Point>());
  134 + stop.setDistances(rs.getDouble("distances")*1000);
  135 + return stop;
  136 + }
  137 +
  138 + }
  139 +
  140 + @Override
  141 + public void afterPropertiesSet() throws Exception {
  142 + // TODO Auto-generated method stub
  143 + loadBasicData();
  144 + }
  145 +}
src/main/java/com/bsth/server_rs/gps/buffer/GpsRealDataBuffer.java
1 -package com.bsth.server_rs.gps.buffer;  
2 -  
3 -import com.bsth.server_rs.gps.entity.GpsEntity;  
4 -import org.springframework.beans.factory.annotation.Autowired;  
5 -import org.springframework.stereotype.Component;  
6 -  
7 -import java.util.Collection;  
8 -import java.util.HashMap;  
9 -import java.util.Map;  
10 -  
11 -/**  
12 - * Created by panzhao on 2017/3/30.  
13 - */  
14 -@Component  
15 -public class GpsRealDataBuffer {  
16 -  
17 - private static Map<String, GpsEntity> realMap;  
18 -  
19 - @Autowired  
20 - GpsRefreshThread gpsRefreshThread;  
21 -  
22 - static{  
23 - realMap = new HashMap<>();  
24 - }  
25 -  
26 - public static void put(GpsEntity gps){  
27 - realMap.put(gps.getDeviceId(), gps);  
28 - }  
29 -  
30 - public static GpsEntity get(String device){  
31 - return realMap.get(device);  
32 - }  
33 -  
34 - public static Collection<GpsEntity> all(){  
35 - return realMap.values();  
36 - }  
37 -} 1 +package com.bsth.server_rs.gps.buffer;
  2 +
  3 +import com.bsth.server_rs.gps.entity.GpsEntity;
  4 +import org.springframework.beans.factory.annotation.Autowired;
  5 +import org.springframework.stereotype.Component;
  6 +
  7 +import java.util.Collection;
  8 +import java.util.HashMap;
  9 +import java.util.Map;
  10 +
  11 +/**
  12 + * Created by panzhao on 2017/3/30.
  13 + */
  14 +@Component
  15 +public class GpsRealDataBuffer {
  16 +
  17 + private static Map<String, GpsEntity> realMap = new HashMap<>();
  18 +
  19 + private static Map<String, String> device2line = new HashMap<>();
  20 +
  21 + @Autowired
  22 + GpsRefreshThread gpsRefreshThread;
  23 +
  24 + public static void put(GpsEntity gps){
  25 + realMap.put(gps.getDeviceId(), gps);
  26 + }
  27 +
  28 + public static GpsEntity get(String device){
  29 + return realMap.get(device);
  30 + }
  31 +
  32 + public static Collection<GpsEntity> all(){
  33 + return realMap.values();
  34 + }
  35 +
  36 + public static void putLineCode(String device, String lineCode){
  37 + device2line.put(device, lineCode);
  38 + }
  39 +
  40 + public static String getLineCodeByDevice(String device){
  41 + return device2line.get(device);
  42 + }
  43 +
  44 + public static Map<String, String> getDevice2Line(){
  45 + return device2line;
  46 + }
  47 +}