Commit 1ef94bff6beb7b8f1a0982162de606d57233c81b

Authored by 王通
2 parents f0ffda3f a7dc8893

1.站点和站点路由数据结构变更

Showing 29 changed files with 2259 additions and 1638 deletions
src/main/java/com/bsth/CXFConfig.java
... ... @@ -13,6 +13,7 @@ import com.bsth.server_rs.base_info.station.StationRestService;
13 13 import com.bsth.server_rs.departure.DepartureRestService;
14 14 import com.bsth.server_rs.destroy.DestroyDetailRestService;
15 15 import com.bsth.server_rs.directive.DirectiveRestService;
  16 +import com.bsth.server_rs.dks.BxRestService;
16 17 import com.bsth.server_rs.electric.ElectricService;
17 18 import com.bsth.server_rs.exception.AesExceptionMapper;
18 19 import com.bsth.server_rs.gps.GpsRestService;
... ... @@ -132,6 +133,8 @@ public class CXFConfig {
132 133 private ManHoursRestService manHoursRestService;
133 134 @Autowired
134 135 private IoCarparkRestService ioCarparkRestService;
  136 + @Autowired
  137 + private BxRestService bxRestService;
135 138  
136 139 @Bean
137 140 public Server rsServer() {
... ... @@ -159,7 +162,8 @@ public class CXFConfig {
159 162 departureRestService,
160 163 whiteIpRestService,
161 164 manHoursRestService,
162   - ioCarparkRestService));
  165 + ioCarparkRestService,
  166 + bxRestService));
163 167 endpoint.setProviders(Arrays.asList(new JacksonJsonProvider(), new AesExceptionMapper()));
164 168 //endpoint.setFeatures(Arrays.asList(new Swagger2Feature()));
165 169 endpoint.getInInterceptors().add(new AuthorizeInterceptor_IN());
... ...
src/main/java/com/bsth/StartCommand.java
... ... @@ -7,6 +7,7 @@ import com.bsth.server_rs.man_hours.ManHoursRefreshScheduler;
7 7 import com.bsth.server_rs.schedule.real.thread.ExecSchDataRefreshThread;
8 8 import com.bsth.server_rs.schedule.real.thread.SchInOutDataRefreshThread;
9 9 import com.bsth.server_rs.thread.RfidCardInfoPersistenceThread;
  10 +import com.bsth.service.SystemParamService;
10 11 import org.springframework.beans.factory.annotation.Autowired;
11 12 import org.springframework.boot.CommandLineRunner;
12 13 import org.springframework.stereotype.Component;
... ... @@ -37,6 +38,9 @@ public class StartCommand implements CommandLineRunner{
37 38 @Autowired
38 39 ManHoursRefreshScheduler manHoursRefreshScheduler;
39 40  
  41 + @Autowired
  42 + SystemParamService systemParamService;
  43 +
40 44 @Override
41 45 public void run(String... arg0){
42 46  
... ... @@ -53,6 +57,7 @@ public class StartCommand implements CommandLineRunner{
53 57 //定时刷新基础信息
54 58 Application.mainServices.scheduleWithFixedDelay(basicDataRefreshThread, 30, 30, TimeUnit.MINUTES);
55 59 manHoursRefreshScheduler.refresh();
  60 + systemParamService.refresh();
56 61 } catch (Exception e) {
57 62 e.printStackTrace();
58 63 }
... ...
src/main/java/com/bsth/common/SystemParamKeys.java 0 → 100644
  1 +package com.bsth.common;
  2 +
  3 +/**
  4 + * @author Hill
  5 + */
  6 +public class SystemParamKeys {
  7 +
  8 + public static final String SPECIAL_ROLES = "special.roles";
  9 +
  10 + public static final String LIMIT_PASSWORDS = "limit.passwords";
  11 +
  12 + public static final String LIMIT_URIS = "limit.uris";
  13 +
  14 + public static final String LIMIT_LINES = "limit.lines";
  15 +
  16 + public static final String LIMIT_DEVICES = "limit.devices";
  17 +}
... ...
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/entity/Resource.java 0 → 100644
  1 +package com.bsth.entity;
  2 +
  3 +import javax.persistence.*;
  4 +
  5 +/**
  6 + * @Author Hill
  7 + */
  8 +@Entity
  9 +@Table(name = "interface_resources")
  10 +public class Resource {
  11 +
  12 + @Id
  13 + @GeneratedValue
  14 + private Integer id;
  15 +
  16 + private String name;
  17 +
  18 + private String url;
  19 +
  20 + private String remark;
  21 +
  22 + public Integer getId() {
  23 + return id;
  24 + }
  25 +
  26 + public void setId(Integer id) {
  27 + this.id = id;
  28 + }
  29 +
  30 + public String getName() {
  31 + return name;
  32 + }
  33 +
  34 + public void setName(String name) {
  35 + this.name = name;
  36 + }
  37 +
  38 + public String getUrl() {
  39 + return url;
  40 + }
  41 +
  42 + public void setUrl(String url) {
  43 + this.url = url;
  44 + }
  45 +
  46 + public String getRemark() {
  47 + return remark;
  48 + }
  49 +
  50 + public void setRemark(String remark) {
  51 + this.remark = remark;
  52 + }
  53 +}
... ...
src/main/java/com/bsth/entity/SystemParam.java 0 → 100644
  1 +package com.bsth.entity;
  2 +
  3 +import javax.persistence.*;
  4 +
  5 +/**
  6 + * @author Hill
  7 + */
  8 +@Entity
  9 +@Table(name = "bsth_c_sys_param")
  10 +public class SystemParam {
  11 +
  12 + @Id
  13 + @GeneratedValue(strategy = GenerationType.IDENTITY)
  14 + private Integer id;
  15 +
  16 + /**
  17 + * 键名(唯一)
  18 + */
  19 + private String key;
  20 +
  21 + /**
  22 + * 值
  23 + */
  24 + private String value;
  25 +
  26 + /**
  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 getKey() {
  40 + return key;
  41 + }
  42 +
  43 + public void setKey(String key) {
  44 + this.key = key;
  45 + }
  46 +
  47 + public String getValue() {
  48 + return value;
  49 + }
  50 +
  51 + public void setValue(String value) {
  52 + this.value = value;
  53 + }
  54 +
  55 + public String getRemark() {
  56 + return remark;
  57 + }
  58 +
  59 + public void setRemark(String remark) {
  60 + this.remark = remark;
  61 + }
  62 +}
... ...
src/main/java/com/bsth/redis/PlanScheduleRedisService.java
1   -package com.bsth.redis;
2   -
3   -import com.bsth.Application;
4   -import com.bsth.entity.SchedulePlanInfo;
5   -import com.bsth.redis.util.DateUtils;
6   -import com.bsth.redis.util.RedisUtils;
7   -import com.bsth.repository.SchedulePlanInfoRepository;
8   -import com.bsth.server_rs.base_info.line.Line;
9   -import com.bsth.server_rs.base_info.line.buffer.LineBufferData;
10   -import com.bsth.util.ConfigUtil;
11   -import com.bsth.util.ConvertUtil;
12   -import com.google.common.collect.ArrayListMultimap;
13   -import org.joda.time.DateTime;
14   -import org.slf4j.Logger;
15   -import org.slf4j.LoggerFactory;
16   -import org.springframework.beans.factory.annotation.Autowired;
17   -import org.springframework.boot.CommandLineRunner;
18   -import org.springframework.core.annotation.Order;
19   -import org.springframework.data.redis.core.ListOperations;
20   -import org.springframework.data.redis.core.RedisTemplate;
21   -import org.springframework.data.redis.serializer.StringRedisSerializer;
22   -import org.springframework.stereotype.Component;
23   -import org.springframework.stereotype.Service;
24   -
25   -import java.util.ArrayList;
26   -import java.util.Date;
27   -import java.util.Iterator;
28   -import java.util.List;
29   -import java.util.concurrent.TimeUnit;
30   -
31   -/**
32   - * 计调的 计划排班redis缓存
33   - * Created by panzhao on 2017/3/27.
34   - */
35   -@Service
36   -@Order(6)
37   -public class PlanScheduleRedisService implements CommandLineRunner {
38   -
39   - @Autowired
40   - private RedisTemplate redisTemplate;
41   -
42   - @Autowired
43   - SchedulePlanInfoRepository planInfoRepository;
44   -
45   - @Autowired
46   - RedisUtils redisUtils;
47   -
48   - static Logger logger = LoggerFactory.getLogger(PlanScheduleRedisService.class);
49   -
50   - private final static String REDIS_KEY_PREFIX = "plan:";
51   -
52   - /**
53   - * 将一批计划写入redis
54   - *
55   - * @param list
56   - */
57   - public void wirte(List<SchedulePlanInfo> list) {
58   - ArrayListMultimap<String, SchedulePlanInfo> multimap;
59   - try {
60   - if (list.size() == 0)
61   - return;
62   - //按日期和线路分组数据
63   - Class clazz = SchedulePlanInfo.class;
64   - multimap = new ConvertUtil().groupMultiList(list, ":", clazz.getDeclaredField("xlBm"), clazz.getDeclaredField("scheduleDate"));
65   -
66   - //写入redis
67   - Iterator<String> iterator = multimap.keySet().iterator();
68   - String key;
69   - while (iterator.hasNext()) {
70   - key = iterator.next();
71   - replace(key, multimap.get(key));
72   - }
73   - } catch (Exception e) {
74   - logger.error("", e);
75   - }
76   - }
77   -
78   - /**
79   - * 将 list 与redis里的数据合并
80   - *
81   - * @param key
82   - * @param list
83   - */
84   - public void mergeData(String key, List<SchedulePlanInfo> list) {
85   - key = REDIS_KEY_PREFIX + key.replaceAll("-", "");
86   -
87   - ListOperations<String, SchedulePlanInfo> ops = redisTemplate.opsForList();
88   - List<SchedulePlanInfo> cacheList = ops.range(key, 0, -1);
89   -
90   - for (SchedulePlanInfo plan : cacheList) {
91   - if (!list.contains(plan))
92   - list.add(plan);
93   - }
94   -
95   - //更新
96   - redisTemplate.execute(redisUtils.getUpdateCallback(key, list));
97   - }
98   -
99   - /**
100   - * 覆盖数据
101   - *
102   - * @param key
103   - * @param list
104   - */
105   - public void replace(String key, List<SchedulePlanInfo> list) {
106   - key = REDIS_KEY_PREFIX + key.replaceAll("-", "");
107   - redisTemplate.execute(redisUtils.getUpdateCallback(key, list));
108   - }
109   -
110   - /**
111   - * 根据日期和线路编码从redis获取计划
112   - *
113   - * @param dateStr
114   - * @param lineCode
115   - * @return
116   - */
117   - public List<SchedulePlanInfo> read(String dateStr, String lineCode) {
118   - return redisTemplate.opsForList().range(REDIS_KEY_PREFIX + lineCode + ":" + dateStr, 0, -1);
119   - }
120   -
121   -
122   - @Autowired
123   - PlanClearThread planClearThread;
124   -
125   - @Override
126   - public void run(String... strings) throws Exception {
127   - Application.mainServices.schedule(new Runnable() {
128   - @Override
129   - public void run() {
130   - int cacheDays = Integer.parseInt(ConfigUtil.get("cache.days"));
131   - //设置key 序列化器
132   - redisTemplate.setKeySerializer(new StringRedisSerializer());
133   -
134   - DateTime dt = new DateTime();
135   - dt = dt.minusDays(cacheDays);
136   - dt = dt.withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0).minusDays(cacheDays);
137   - List<SchedulePlanInfo> list = planInfoRepository.findByDateRange(dt.toDate(), new Date());
138   - //写入redis
139   - wirte(list);
140   - }
141   - }, 60 * 5, TimeUnit.SECONDS);
142   -
143   -
144   - //定时 00:05 分清理计划,并加载当天的计划
145   - long diff = (DateUtils.getTimestamp() + 1000 * 60 * 5) - System.currentTimeMillis();
146   - if (diff < 0)
147   - diff += (1000 * 60 * 60 * 24);
148   - Application.mainServices.scheduleAtFixedRate(planClearThread, diff / 1000, 60 * 60 * 24, TimeUnit.SECONDS);
149   - }
150   -
151   - public List<SchedulePlanInfo> findByMultiLine(List<String> lineArray, String rq) {
152   - rq = rq.replaceAll("-", "");
153   - List<SchedulePlanInfo> rs = new ArrayList<>();
154   - for (String lineCode : lineArray) {
155   - rs.addAll(read(rq, lineCode));
156   - }
157   - return rs;
158   - }
159   -
160   - @Component
161   - public static class PlanClearThread extends Thread {
162   -
163   - @Autowired
164   - PlanScheduleRedisService planRedisService;
165   - @Autowired
166   - SchedulePlanInfoRepository planInfoRepository;
167   -
168   - @Override
169   - public void run() {
170   - try {
171   - logger.info("redis -清理计划排班");
172   -
173   - int cacheDays = Integer.parseInt(ConfigUtil.get("cache.days"));
174   - DateTime dt = new DateTime();
175   - dt = dt.minusDays(cacheDays);
176   - String rq = dt.toString("yyyy-MM-dd");
177   -
178   - List<Line> lines = LineBufferData.findAll();
179   - for (Line line : lines) {
180   - planRedisService.delete(line.getLineCode(), rq);
181   - }
182   -
183   - //加载当天的计划
184   - Date d = new Date();
185   - Date s = new Date(d.getTime() - 1000 * 60 * 60 * 24);
186   - List<SchedulePlanInfo> list = planInfoRepository.findByDateRange(s, d);
187   - //写入redis
188   - planRedisService.wirte(list);
189   - } catch (Exception e) {
190   - logger.error("", e);
191   - }
192   - }
193   - }
194   -
195   - private void delete(String lineCode, String rq) {
196   - String key = REDIS_KEY_PREFIX + (lineCode + ":" + rq).replaceAll("-", "");
197   - redisTemplate.delete(key);
198   - }
199   -}
  1 +package com.bsth.redis;
  2 +
  3 +import com.bsth.Application;
  4 +import com.bsth.entity.SchedulePlanInfo;
  5 +import com.bsth.redis.util.DateUtils;
  6 +import com.bsth.redis.util.RedisUtils;
  7 +import com.bsth.repository.SchedulePlanInfoRepository;
  8 +import com.bsth.server_rs.base_info.line.Line;
  9 +import com.bsth.server_rs.base_info.line.buffer.LineBufferData;
  10 +import com.bsth.util.ConfigUtil;
  11 +import com.bsth.util.ConvertUtil;
  12 +import com.google.common.collect.ArrayListMultimap;
  13 +import org.joda.time.DateTime;
  14 +import org.slf4j.Logger;
  15 +import org.slf4j.LoggerFactory;
  16 +import org.springframework.beans.factory.annotation.Autowired;
  17 +import org.springframework.boot.CommandLineRunner;
  18 +import org.springframework.core.annotation.Order;
  19 +import org.springframework.data.redis.core.ListOperations;
  20 +import org.springframework.data.redis.core.RedisTemplate;
  21 +import org.springframework.data.redis.serializer.StringRedisSerializer;
  22 +import org.springframework.stereotype.Component;
  23 +import org.springframework.stereotype.Service;
  24 +
  25 +import java.util.ArrayList;
  26 +import java.util.Date;
  27 +import java.util.Iterator;
  28 +import java.util.List;
  29 +import java.util.concurrent.TimeUnit;
  30 +
  31 +/**
  32 + * 计调的 计划排班redis缓存
  33 + * Created by panzhao on 2017/3/27.
  34 + */
  35 +@Service
  36 +@Order(6)
  37 +public class PlanScheduleRedisService implements CommandLineRunner {
  38 +
  39 + @Autowired
  40 + private RedisTemplate redisTemplate;
  41 +
  42 + @Autowired
  43 + SchedulePlanInfoRepository planInfoRepository;
  44 +
  45 + @Autowired
  46 + RedisUtils redisUtils;
  47 +
  48 + static Logger logger = LoggerFactory.getLogger(PlanScheduleRedisService.class);
  49 +
  50 + private final static String REDIS_KEY_PREFIX = "plan:";
  51 +
  52 + /**
  53 + * 将一批计划写入redis
  54 + *
  55 + * @param list
  56 + */
  57 + public void wirte(List<SchedulePlanInfo> list) {
  58 + ArrayListMultimap<String, SchedulePlanInfo> multimap;
  59 + try {
  60 + if (list.size() == 0)
  61 + return;
  62 + //按日期和线路分组数据
  63 + Class clazz = SchedulePlanInfo.class;
  64 + multimap = new ConvertUtil().groupMultiList(list, ":", clazz.getDeclaredField("xlBm"), clazz.getDeclaredField("scheduleDate"));
  65 +
  66 + //写入redis
  67 + Iterator<String> iterator = multimap.keySet().iterator();
  68 + String key;
  69 + while (iterator.hasNext()) {
  70 + key = iterator.next();
  71 + replace(key, multimap.get(key));
  72 + }
  73 + } catch (Exception e) {
  74 + logger.error("", e);
  75 + }
  76 + }
  77 +
  78 + /**
  79 + * 将 list 与redis里的数据合并
  80 + *
  81 + * @param key
  82 + * @param list
  83 + */
  84 + public void mergeData(String key, List<SchedulePlanInfo> list) {
  85 + key = REDIS_KEY_PREFIX + key.replaceAll("-", "");
  86 +
  87 + ListOperations<String, SchedulePlanInfo> ops = redisTemplate.opsForList();
  88 + List<SchedulePlanInfo> cacheList = ops.range(key, 0, -1);
  89 +
  90 + for (SchedulePlanInfo plan : cacheList) {
  91 + if (!list.contains(plan))
  92 + list.add(plan);
  93 + }
  94 +
  95 + //更新
  96 + redisTemplate.execute(redisUtils.getUpdateCallback(key, list));
  97 + }
  98 +
  99 + /**
  100 + * 覆盖数据
  101 + *
  102 + * @param key
  103 + * @param list
  104 + */
  105 + public void replace(String key, List<SchedulePlanInfo> list) {
  106 + key = REDIS_KEY_PREFIX + key.replaceAll("-", "");
  107 + redisTemplate.execute(redisUtils.getUpdateCallback(key, list));
  108 + }
  109 +
  110 + /**
  111 + * 根据日期和线路编码从redis获取计划
  112 + *
  113 + * @param dateStr
  114 + * @param lineCode
  115 + * @return
  116 + */
  117 + public List<SchedulePlanInfo> read(String dateStr, String lineCode) {
  118 + return redisTemplate.opsForList().range(REDIS_KEY_PREFIX + lineCode + ":" + dateStr, 0, -1);
  119 + }
  120 +
  121 +
  122 + @Autowired
  123 + PlanClearThread planClearThread;
  124 +
  125 + @Override
  126 + public void run(String... strings) throws Exception {
  127 + Application.mainServices.schedule(new Runnable() {
  128 + @Override
  129 + public void run() {
  130 + int cacheDays = Integer.parseInt(ConfigUtil.get("cache.days"));
  131 + //设置key 序列化器
  132 + redisTemplate.setKeySerializer(new StringRedisSerializer());
  133 +
  134 + DateTime dt = new DateTime();
  135 + dt = dt.withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0);
  136 + List<SchedulePlanInfo> list = planInfoRepository.findByDateRange(dt.minusDays(cacheDays).toDate(), dt.plusDays(1).toDate());
  137 + //写入redis
  138 + wirte(list);
  139 + }
  140 + }, 20, TimeUnit.SECONDS);
  141 +
  142 +
  143 + //定时 00:05 分清理计划,并加载当天的计划
  144 + long diff = (DateUtils.getTimestamp() + 1000 * 60 * 5) - System.currentTimeMillis();
  145 + if (diff < 0)
  146 + diff += (1000 * 60 * 60 * 24);
  147 + Application.mainServices.scheduleAtFixedRate(planClearThread, diff / 1000, 60 * 60 * 24, TimeUnit.SECONDS);
  148 + }
  149 +
  150 + public List<SchedulePlanInfo> findByMultiLine(List<String> lineArray, String rq) {
  151 + rq = rq.replaceAll("-", "");
  152 + List<SchedulePlanInfo> rs = new ArrayList<>();
  153 + for (String lineCode : lineArray) {
  154 + rs.addAll(read(rq, lineCode));
  155 + }
  156 + return rs;
  157 + }
  158 +
  159 + @Component
  160 + public static class PlanClearThread extends Thread {
  161 +
  162 + @Autowired
  163 + PlanScheduleRedisService planRedisService;
  164 + @Autowired
  165 + SchedulePlanInfoRepository planInfoRepository;
  166 +
  167 + @Override
  168 + public void run() {
  169 + try {
  170 + logger.info("redis -清理计划排班");
  171 +
  172 + int cacheDays = Integer.parseInt(ConfigUtil.get("cache.days"));
  173 + DateTime dt = new DateTime();
  174 + dt = dt.minusDays(cacheDays);
  175 + String rq = dt.toString("yyyy-MM-dd");
  176 +
  177 + List<Line> lines = LineBufferData.findAll();
  178 + for (Line line : lines) {
  179 + planRedisService.delete(line.getLineCode(), rq);
  180 + }
  181 +
  182 + //加载明天的计划
  183 + DateTime d = new DateTime();
  184 + d.withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0);
  185 + List<SchedulePlanInfo> list = planInfoRepository.findByDateRange(d.toDate(), d.plusDays(1).toDate());
  186 + //写入redis
  187 + planRedisService.wirte(list);
  188 + } catch (Exception e) {
  189 + logger.error("", e);
  190 + }
  191 + }
  192 + }
  193 +
  194 + private void delete(String lineCode, String rq) {
  195 + String key = REDIS_KEY_PREFIX + (lineCode + ":" + rq).replaceAll("-", "");
  196 + redisTemplate.delete(key);
  197 + }
  198 +}
... ...
src/main/java/com/bsth/repository/SystemParamRepository.java 0 → 100644
  1 +package com.bsth.repository;
  2 +
  3 +import com.bsth.entity.SystemParam;
  4 +import org.springframework.data.repository.PagingAndSortingRepository;
  5 +
  6 +/**
  7 + * @author Hill
  8 + */
  9 +public interface SystemParamRepository extends PagingAndSortingRepository<SystemParam, Integer> {
  10 +}
... ...
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.SystemParamService;
  7 +import com.bsth.service.UserService;
  8 +import org.apache.commons.lang3.StringEscapeUtils;
  9 +import org.apache.cxf.interceptor.Fault;
  10 +import org.apache.cxf.message.Message;
  11 +import org.apache.cxf.phase.AbstractPhaseInterceptor;
  12 +import org.apache.cxf.phase.Phase;
  13 +import org.eclipse.jetty.util.MultiMap;
  14 +import org.eclipse.jetty.util.UrlEncoded;
  15 +import org.slf4j.Logger;
  16 +import org.slf4j.LoggerFactory;
  17 +import org.springframework.beans.BeansException;
  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.security.MessageDigest;
  25 +import java.util.Arrays;
  26 +import java.util.HashMap;
  27 +import java.util.Map;
  28 +import java.util.Set;
  29 +
  30 +/**
  31 + * rest 接口授权校验(IN 输入拦截)
  32 + * Created by panzhao on 2017/3/28.
  33 + */
  34 +@Component
  35 +public class AuthorizeInterceptor_IN extends AbstractPhaseInterceptor<Message> implements ApplicationContextAware {
  36 +
  37 + private static final String SIGN = "sign";
  38 + private static final String TIMESTAMP = "timestamp";
  39 + private static final String NONCE = "nonce";
  40 + private static final String PASSWORD = "password";
  41 + private static final int MAX_TIME_DIFF = 1000 * 60 * 10;
  42 + private static Map<String, String> pwd2nonceMap;
  43 +
  44 + static UserService userService;
  45 +
  46 + static SystemParamService systemParamService;
  47 +
  48 + static Logger logger = LoggerFactory.getLogger(AuthorizeInterceptor_IN.class);
  49 +
  50 + private static PathMatcher matcher = new AntPathMatcher();
  51 +
  52 + public AuthorizeInterceptor_IN() {
  53 + super(Phase.RECEIVE);
  54 + }
  55 +
  56 + static {
  57 + pwd2nonceMap = new HashMap<>();
  58 + }
  59 +
  60 + @Override
  61 + public void handleMessage(Message message) throws Fault {
  62 +
  63 + long t = System.currentTimeMillis();
  64 + if (message.get(Message.QUERY_STRING) == null) {
  65 + throw new AesException(AesException.MISS_SIGN);
  66 + }
  67 +
  68 + //放行wadl
  69 + if(message.get(Message.QUERY_STRING).equals("_wadl")
  70 + && message.get(Message.PATH_INFO).equals("/webservice/rest")){
  71 + return ;
  72 + }
  73 +
  74 + //获取参数,不包括 url 路径参数 只包括?号之后的
  75 + String queryString = StringEscapeUtils.unescapeHtml4(message.get(Message.QUERY_STRING).toString());
  76 + MultiMap<String> params = new MultiMap<>();
  77 + UrlEncoded.decodeTo(queryString, params, "utf-8");
  78 + Map<String, String> map = multi2One(params);
  79 +
  80 + if (!map.containsKey(SIGN)) {
  81 + throw new AesException(AesException.MISS_SIGN);
  82 + }
  83 + if (!map.containsKey(TIMESTAMP)) {
  84 + throw new AesException(AesException.MISS_TIMESTAMP);
  85 + }
  86 +
  87 + try{
  88 + long timestamp = Long.parseLong(map.get(TIMESTAMP));
  89 + if(Math.abs(t - timestamp) > MAX_TIME_DIFF){
  90 + throw new AesException(AesException.INVALID_TIMESTAMP);
  91 + }
  92 + }catch(Exception e){
  93 + throw new AesException(AesException.INVALID_TIMESTAMP);
  94 + }
  95 +
  96 + if (!map.containsKey(NONCE)) {
  97 + throw new AesException(AesException.MISS_NONCE);
  98 + }
  99 + if (!map.containsKey(PASSWORD)) {
  100 + throw new AesException(AesException.MISS_PWD);
  101 + }
  102 +
  103 + String prevNonce = pwd2nonceMap.get(map.get(PASSWORD));
  104 + if(prevNonce != null && prevNonce.equals(map.get(NONCE)))
  105 + throw new AesException(AesException.NO_RANDOM_NONCE);
  106 +
  107 + if (userService.get(map.get(PASSWORD)) == null) {
  108 + throw new AesException(AesException.INVALID_PWD);
  109 + }
  110 +
  111 + String sign = map.get(SIGN);
  112 + map.remove(SIGN);
  113 + String sh1 = "";
  114 + try {
  115 + sh1 = getSHA1(map);
  116 + } catch (Exception e) {
  117 + throw new AesException(AesException.SIGN_CHECK_ERROR);
  118 + }
  119 +
  120 + if (!sign.equals(sh1)) {
  121 + throw new AesException(AesException.SIGN_CHECK_FAIL);
  122 + }
  123 +
  124 + validate(map, message);
  125 + }
  126 +
  127 + private static void validate(Map<String, String> map, Message message) {
  128 + PasswordUser user = userService.get(map.get(PASSWORD));
  129 + if (user.getResources().size() > 0) {
  130 + boolean isMatch = false;
  131 + String uri = (String) message.get(Message.REQUEST_URI);
  132 + for (Resource resource : user.getResources()) {
  133 + if (matcher.match(resource.getUrl(), uri)) {
  134 + isMatch = true;
  135 + break;
  136 + }
  137 + }
  138 + if (!isMatch) {
  139 + throw new AesException(AesException.INVALID_URI);
  140 + }
  141 + }
  142 + }
  143 +
  144 + public static Map<String, String> multi2One(MultiMap<String> params) {
  145 + Map<String, String> map = new HashMap<>();
  146 + Set<String> ks = params.keySet();
  147 + for (String k : ks) {
  148 + map.put(k, params.getString(k));
  149 + }
  150 + return map;
  151 + }
  152 +
  153 +
  154 + public static String getSHA1(Map<String, String> map) throws Exception {
  155 +
  156 + try {
  157 + String[] array = new String[map.size()];
  158 + map.values().toArray(array);
  159 + StringBuffer sb = new StringBuffer();
  160 +
  161 + // 字符串排序
  162 + Arrays.sort(array);
  163 + for (int i = 0; i < array.length; i++) {
  164 + sb.append(array[i]);
  165 + }
  166 + String str = sb.toString();
  167 + // SHA1签名生成
  168 + MessageDigest md = MessageDigest.getInstance("SHA-1");
  169 + md.update(str.getBytes());
  170 + byte[] digest = md.digest();
  171 +
  172 + StringBuffer hexstr = new StringBuffer();
  173 + String shaHex = "";
  174 + for (int i = 0; i < digest.length; i++) {
  175 + shaHex = Integer.toHexString(digest[i] & 0xFF);
  176 + if (shaHex.length() < 2) {
  177 + hexstr.append(0);
  178 + }
  179 + hexstr.append(shaHex);
  180 + }
  181 + return hexstr.toString();
  182 + } catch (Exception e) {
  183 + logger.error("", e);
  184 + throw e;
  185 + }
  186 + }
  187 +
  188 + @Override
  189 + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
  190 + userService = applicationContext.getBean(UserService.class);
  191 + systemParamService = applicationContext.getBean(SystemParamService.class);
  192 + }
  193 +}
... ...
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/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,c2.qyrq 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   -}
  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/base_info/line/Line.java
... ... @@ -125,6 +125,16 @@ public class Line implements Serializable {
125 125 */
126 126 private Date revokeDate;
127 127  
  128 + /**
  129 + * 停车场编码
  130 + */
  131 + private String carPark;
  132 +
  133 + /**
  134 + * 坐标点
  135 + */
  136 + private String coordinates;
  137 +
128 138 public String getName() {
129 139 return name;
130 140 }
... ... @@ -381,4 +391,20 @@ public class Line implements Serializable {
381 391 public void setRevokeDate(Date revokeDate) {
382 392 this.revokeDate = revokeDate;
383 393 }
  394 +
  395 + public String getCarPark() {
  396 + return carPark;
  397 + }
  398 +
  399 + public void setCarPark(String carPark) {
  400 + this.carPark = carPark;
  401 + }
  402 +
  403 + public String getCoordinates() {
  404 + return coordinates;
  405 + }
  406 +
  407 + public void setCoordinates(String coordinates) {
  408 + this.coordinates = coordinates;
  409 + }
384 410 }
... ...
src/main/java/com/bsth/server_rs/base_info/line/buffer/LineRefreshThread.java
... ... @@ -28,7 +28,7 @@ public class LineRefreshThread extends Thread{
28 28 public void run() {
29 29  
30 30 try {
31   - List<Line> list = jdbcTemplate.query("SELECT t1. NAME,t1.line_code,t1.start_station_name,t1.end_station_name,t1.start_station_first_time,t1.start_station_end_time,t1.end_station_first_time,t1.end_station_end_time,t1.company,t1.branche_company,t1.nature,t1.`level`,t1.destroy,t1.supper_line,t1.eq_linecode,t1.create_date,t2.total_mileage,t2.early_interval_lg,t2.late_interval_lg,t2.interval_lg,t2.speed_limit,t2.lag_station,t2.skip,t2.speeding,t2.crossed_line,t2.overflights,t1.shanghai_linecode, t1.line_play_type, t1.region, t1.in_use, t3.business_name company_name,t1.revoke_date FROM bsth_c_line t1 LEFT JOIN bsth_c_line_information t2 ON t1.id = t2.line LEFT JOIN bsth_c_business t3 on t1.company = t3.business_code",
  31 + List<Line> list = jdbcTemplate.query("SELECT t1. NAME,t1.line_code,t1.start_station_name,t1.end_station_name,t1.start_station_first_time,t1.start_station_end_time,t1.end_station_first_time,t1.end_station_end_time,t1.company,t1.branche_company,t1.nature,t1.`level`,t1.destroy,t1.supper_line,t1.eq_linecode,t1.create_date,t2.total_mileage,t2.early_interval_lg,t2.late_interval_lg,t2.interval_lg,t2.speed_limit,t2.lag_station,t2.skip,t2.speeding,t2.crossed_line,t2.overflights,t1.shanghai_linecode, t1.line_play_type, t1.region, t1.in_use, t3.business_name company_name,t1.revoke_date,t2.car_park FROM bsth_c_line t1 LEFT JOIN bsth_c_line_information t2 ON t1.id = t2.line LEFT JOIN bsth_c_business t3 on t1.company = t3.business_code",
32 32 BeanPropertyRowMapper.newInstance(Line.class));
33 33  
34 34 Map<String, Line> map = new HashMap<>(), revokeMap = new HashMap<>();
... ...
src/main/java/com/bsth/server_rs/base_info/person/Personnel.java
... ... @@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
4 4  
5 5 import javax.xml.bind.annotation.XmlRootElement;
6 6 import java.io.Serializable;
  7 +import java.util.Date;
7 8  
8 9 /**
9 10 * @ClassName : Personnel(人员实体类)
... ... @@ -53,6 +54,7 @@ public class Personnel implements Serializable {
53 54 /**
54 55 * 身份证
55 56 */
  57 + @JsonIgnore
56 58 private String card;
57 59  
58 60 public String getCard() {
... ... @@ -104,6 +106,8 @@ public class Personnel implements Serializable {
104 106 */
105 107 private String jdCodeori;
106 108  
  109 + private Date updateDate;
  110 +
107 111 public String getCompanyCode() {
108 112 return companyCode;
109 113 }
... ... @@ -231,4 +235,12 @@ public class Personnel implements Serializable {
231 235 public void setJdCodeori(String jdCodeori) {
232 236 this.jdCodeori = jdCodeori;
233 237 }
  238 +
  239 + public Date getUpdateDate() {
  240 + return updateDate;
  241 + }
  242 +
  243 + public void setUpdateDate(Date updateDate) {
  244 + this.updateDate = updateDate;
  245 + }
234 246 }
... ...
src/main/java/com/bsth/server_rs/base_info/person/buffer/PersonRefreshThread.java
... ... @@ -28,13 +28,12 @@ public class PersonRefreshThread extends Thread{
28 28 public void run() {
29 29  
30 30 try {
31   - List<Personnel> list = jdbcTemplate.query("select DISTINCT t1.*,t2.name as line_name,t2.line_code from (SELECT company_code,branche_company_code,job_code,personnel_name,papers_code,ic_card_code,personnel_type,posts,card,telphone,ic_rfid,id_rfid,tag_rfid,jd_codeori,e.xl FROM bsth_c_personnel p left JOIN bsth_c_s_ecinfo e on p.id=e.jsy) t1 LEFT JOIN bsth_c_line t2 on t1.xl=t2.id "
  31 + List<Personnel> list = jdbcTemplate.query("select DISTINCT t1.*,t2.name as line_name,t2.line_code from (SELECT company_code,branche_company_code,job_code,personnel_name,papers_code,ic_card_code,personnel_type,posts,card,telphone,ic_rfid,id_rfid,tag_rfid,jd_codeori,p.update_date,e.xl FROM bsth_c_personnel p left JOIN bsth_c_s_ecinfo e on p.id=e.jsy) t1 LEFT JOIN bsth_c_line t2 on t1.xl=t2.id "
32 32 ,BeanPropertyRowMapper.newInstance(Personnel.class));
33 33  
34 34 Map<String, Personnel> map = new HashMap<>();
35 35 //过滤数据,多条线路配人的保留一条
36 36 for(Personnel p : list){
37   - p.setCard("");
38 37 map.put(p.getJobCode(), p);
39 38 }
40 39  
... ...
src/main/java/com/bsth/server_rs/base_info/section/buffer/LD_SectionBufferData.java
1   -package com.bsth.server_rs.base_info.section.buffer;
2   -
3   -import com.bsth.Application;
4   -import com.bsth.server_rs.base_info.line.Line;
5   -import com.bsth.server_rs.base_info.line.buffer.LineBufferData;
6   -import com.bsth.server_rs.base_info.section.entity.LD_Section;
7   -import com.bsth.server_rs.base_info.section.entity.LD_SectionRoute;
8   -import com.bsth.server_rs.base_info.section.entity.RoadSpeed;
9   -import com.google.common.collect.ArrayListMultimap;
10   -import org.slf4j.Logger;
11   -import org.slf4j.LoggerFactory;
12   -import org.springframework.beans.factory.annotation.Autowired;
13   -import org.springframework.boot.CommandLineRunner;
14   -import org.springframework.core.annotation.Order;
15   -import org.springframework.jdbc.core.JdbcTemplate;
16   -import org.springframework.stereotype.Component;
17   -
18   -import java.util.*;
19   -import java.util.concurrent.ConcurrentHashMap;
20   -import java.util.concurrent.TimeUnit;
21   -
22   -/**
23   - * 站点数据缓存(自更新)
24   - * Created by panzhao on 2017/3/27.
25   - */
26   -@Component
27   -@Order(6)
28   -public class LD_SectionBufferData implements CommandLineRunner {
29   -
30   -
31   - private static List<LD_Section> data;
32   - private static Map<String, LD_Section> codeMap;
33   -
34   - /**
35   - * 线路名称和路段集合映射
36   - */
37   - private static Map<String, List<LD_SectionRoute>> name2sections = new ConcurrentHashMap<>();
38   -
39   - //路段限速缓存信息
40   - private static List<RoadSpeed> roadSpeedList;
41   -
42   - @Autowired
43   - JdbcTemplate jdbcTemplate;
44   -
45   - @Autowired
46   - LD_SectionRefreshThread ld_sectionRefreshThread;
47   -
48   - Logger logger = LoggerFactory.getLogger(this.getClass());
49   -
50   - /**
51   - 路由缓存
52   - 线路编码_上下行 ——> 路由集合
53   - */
54   - private static ArrayListMultimap<String, LD_SectionRoute> routeListMap;
55   -
56   -
57   - public static List<LD_Section> findAll(){
58   - return data;
59   - }
60   -
61   - public static Map<String, Collection<LD_SectionRoute>> findAllRoute(){
62   - return routeListMap.asMap();
63   - }
64   -
65   - public static LD_Section findOne(String code){
66   - return codeMap.get(code);
67   - }
68   -
69   - public static void replaceAll(List<LD_Section> newData){
70   - data = newData;
71   - Map<String, LD_Section> codeMapCopy = new HashMap<>();
72   - for(LD_Section section : data){
73   - codeMapCopy.put(section.getSectionCode(), section);
74   - }
75   -
76   - codeMap = codeMapCopy;
77   - }
78   -
79   - public static void putRoadSpeeds(List<RoadSpeed> list){
80   - roadSpeedList = list;
81   - }
82   -
83   - public static void replaceRoutes(List<LD_SectionRoute> list){
84   - Collections.sort(list, new Comparator<LD_SectionRoute>() {
85   - @Override
86   - public int compare(LD_SectionRoute o1, LD_SectionRoute o2) {
87   - return o1.getSectionrouteCode().compareTo(o2.getSectionrouteCode());
88   - }
89   - });
90   -
91   - ArrayListMultimap<String, LD_SectionRoute> routeListMapCopy = ArrayListMultimap.create();
92   - for(LD_SectionRoute sr : list){
93   - routeListMapCopy.put(sr.getLineCode()+"_" + sr.getDirections(), sr);
94   - }
95   -
96   - routeListMap = routeListMapCopy;
97   - }
98   -
99   - @Override
100   - public void run(String... strings) throws Exception {
101   - Application.mainServices.scheduleWithFixedDelay(ld_sectionRefreshThread, 10, 60 * 60, TimeUnit.SECONDS);
102   - }
103   -
104   - public Map<String, Collection<LD_SectionRoute>> findRouteByCompany(String company) {
105   - List<Line> lines = LineBufferData.findByCompany(company);
106   -
107   - ArrayListMultimap<String, LD_SectionRoute> listMap = ArrayListMultimap.create();
108   -
109   -
110   - Set<String> ks = routeListMap.keySet();
111   -
112   - for(String k : ks){
113   - if(include(lines, k)){
114   - listMap.putAll(k, routeListMap.get(k));
115   - }
116   - }
117   - return listMap.asMap();
118   - }
119   -
120   - private static boolean include(List<Line> lines, String k){
121   -
122   - for(Line line : lines){
123   - if(k.startsWith(line.getLineCode() + "_"))
124   - return true;
125   - }
126   - return false;
127   - }
128   -
129   - public List<RoadSpeed> roadSpeedList(String company) {
130   - return roadSpeedList;
131   - }
132   -
133   - public Map<String, Collection<LD_SectionRoute>> findByLineCode(String lineCode) {
134   -
135   - ArrayListMultimap<String, LD_SectionRoute> listMap = ArrayListMultimap.create();
136   -
137   - String k1 = lineCode + "_0";
138   - String k2 = lineCode + "_1";
139   -
140   - listMap.putAll(k1, routeListMap.get(k1));
141   - listMap.putAll(k2, routeListMap.get(k2));
142   - return listMap.asMap();
143   - }
144   -
145   - public static void putLastedRoute(Map<String, List<LD_SectionRoute>> map) {
146   - name2sections = map;
147   - }
148   -
149   - public List<LD_SectionRoute> findByLineName(String lineName) {
150   - return name2sections.get(lineName);
151   - }
152   -}
  1 +package com.bsth.server_rs.base_info.section.buffer;
  2 +
  3 +import com.bsth.Application;
  4 +import com.bsth.server_rs.base_info.line.Line;
  5 +import com.bsth.server_rs.base_info.line.buffer.LineBufferData;
  6 +import com.bsth.server_rs.base_info.section.entity.LD_Section;
  7 +import com.bsth.server_rs.base_info.section.entity.LD_SectionRoute;
  8 +import com.bsth.server_rs.base_info.section.entity.RoadSpeed;
  9 +import com.google.common.collect.ArrayListMultimap;
  10 +import org.slf4j.Logger;
  11 +import org.slf4j.LoggerFactory;
  12 +import org.springframework.beans.factory.annotation.Autowired;
  13 +import org.springframework.boot.CommandLineRunner;
  14 +import org.springframework.core.annotation.Order;
  15 +import org.springframework.jdbc.core.JdbcTemplate;
  16 +import org.springframework.stereotype.Component;
  17 +
  18 +import java.util.*;
  19 +import java.util.concurrent.ConcurrentHashMap;
  20 +import java.util.concurrent.TimeUnit;
  21 +
  22 +/**
  23 + * 站点数据缓存(自更新)
  24 + * Created by panzhao on 2017/3/27.
  25 + */
  26 +@Component
  27 +@Order(6)
  28 +public class LD_SectionBufferData implements CommandLineRunner {
  29 +
  30 +
  31 + private static List<LD_Section> data;
  32 + private static Map<String, LD_Section> codeMap;
  33 +
  34 + /**
  35 + * 线路名称和路段集合映射
  36 + */
  37 + private static Map<String, List<LD_SectionRoute>> name2sections = new ConcurrentHashMap<>();
  38 +
  39 + //路段限速缓存信息
  40 + private static List<RoadSpeed> roadSpeedList = new ArrayList<>();
  41 +
  42 + @Autowired
  43 + JdbcTemplate jdbcTemplate;
  44 +
  45 + @Autowired
  46 + LD_SectionRefreshThread ld_sectionRefreshThread;
  47 +
  48 + Logger logger = LoggerFactory.getLogger(this.getClass());
  49 +
  50 + /**
  51 + 路由缓存
  52 + 线路编码_上下行 ——> 路由集合
  53 + */
  54 + private static ArrayListMultimap<String, LD_SectionRoute> routeListMap;
  55 +
  56 +
  57 + public static List<LD_Section> findAll(){
  58 + return data;
  59 + }
  60 +
  61 + public static Map<String, Collection<LD_SectionRoute>> findAllRoute(){
  62 + return routeListMap.asMap();
  63 + }
  64 +
  65 + public static LD_Section findOne(String code){
  66 + return codeMap.get(code);
  67 + }
  68 +
  69 + public static void replaceAll(List<LD_Section> newData){
  70 + data = newData;
  71 + Map<String, LD_Section> codeMapCopy = new HashMap<>();
  72 + for(LD_Section section : data){
  73 + codeMapCopy.put(section.getSectionCode(), section);
  74 + }
  75 +
  76 + codeMap = codeMapCopy;
  77 + }
  78 +
  79 + public static void putRoadSpeeds(List<RoadSpeed> list){
  80 + roadSpeedList = list;
  81 + }
  82 +
  83 + public static void replaceRoutes(List<LD_SectionRoute> list){
  84 + Collections.sort(list, new Comparator<LD_SectionRoute>() {
  85 + @Override
  86 + public int compare(LD_SectionRoute o1, LD_SectionRoute o2) {
  87 + return o1.getSectionrouteCode().compareTo(o2.getSectionrouteCode());
  88 + }
  89 + });
  90 +
  91 + ArrayListMultimap<String, LD_SectionRoute> routeListMapCopy = ArrayListMultimap.create();
  92 + for(LD_SectionRoute sr : list){
  93 + routeListMapCopy.put(sr.getLineCode()+"_" + sr.getDirections(), sr);
  94 + }
  95 +
  96 + routeListMap = routeListMapCopy;
  97 + }
  98 +
  99 + @Override
  100 + public void run(String... strings) throws Exception {
  101 + Application.mainServices.scheduleWithFixedDelay(ld_sectionRefreshThread, 10, 60 * 60, TimeUnit.SECONDS);
  102 + }
  103 +
  104 + public Map<String, Collection<LD_SectionRoute>> findRouteByCompany(String company) {
  105 + List<Line> lines = LineBufferData.findByCompany(company);
  106 +
  107 + ArrayListMultimap<String, LD_SectionRoute> listMap = ArrayListMultimap.create();
  108 +
  109 +
  110 + Set<String> ks = routeListMap.keySet();
  111 +
  112 + for(String k : ks){
  113 + if(include(lines, k)){
  114 + listMap.putAll(k, routeListMap.get(k));
  115 + }
  116 + }
  117 + return listMap.asMap();
  118 + }
  119 +
  120 + private static boolean include(List<Line> lines, String k){
  121 +
  122 + for(Line line : lines){
  123 + if(k.startsWith(line.getLineCode() + "_"))
  124 + return true;
  125 + }
  126 + return false;
  127 + }
  128 +
  129 + public List<RoadSpeed> roadSpeedList(String company) {
  130 + return roadSpeedList;
  131 + }
  132 +
  133 + public Map<String, Collection<LD_SectionRoute>> findByLineCode(String lineCode) {
  134 +
  135 + ArrayListMultimap<String, LD_SectionRoute> listMap = ArrayListMultimap.create();
  136 +
  137 + String k1 = lineCode + "_0";
  138 + String k2 = lineCode + "_1";
  139 +
  140 + listMap.putAll(k1, routeListMap.get(k1));
  141 + listMap.putAll(k2, routeListMap.get(k2));
  142 + return listMap.asMap();
  143 + }
  144 +
  145 + public static void putLastedRoute(Map<String, List<LD_SectionRoute>> map) {
  146 + name2sections = map;
  147 + }
  148 +
  149 + public List<LD_SectionRoute> findByLineName(String lineName) {
  150 + return name2sections.get(lineName);
  151 + }
  152 +}
... ...
src/main/java/com/bsth/server_rs/base_info/section/buffer/LD_SectionRefreshThread.java
... ... @@ -63,9 +63,9 @@ public class LD_SectionRefreshThread extends Thread{
63 63 IoCarparkBufferData.replaceRoutes(routeList1);
64 64  
65 65 //查询路段限速信息
66   - List<RoadSpeed> roadSpeedList = jdbcTemplate.query("select id,name,ST_AsText(g_road_vector) as g_road_vector,speed,speed_start_date,speed_end_date,line,is_start,create_date,update_date from bsth_c_road_speed where is_start=0", BeanPropertyRowMapper.newInstance(RoadSpeed.class));
67   - if(roadSpeedList.size() > 0)
68   - LD_SectionBufferData.putRoadSpeeds(roadSpeedList);
  66 +// List<RoadSpeed> roadSpeedList = jdbcTemplate.query("select id,name,ST_AsText(g_road_vector) as g_road_vector,speed,speed_start_date,speed_end_date,line,is_start,create_date,update_date from bsth_c_road_speed where is_start=0", BeanPropertyRowMapper.newInstance(RoadSpeed.class));
  67 +// if(roadSpeedList.size() > 0)
  68 +// LD_SectionBufferData.putRoadSpeeds(roadSpeedList);
69 69  
70 70 //查询最新版本路段信息
71 71 List<LD_SectionRoute> sectionRoutes = jdbcTemplate.query("select b.line_name,a.line_code,a.section_code,a.directions,a.sectionroute_code,a.versions from (select l.name line_name,l.line_code line_code,max(versions) versions from bsth_c_line l left join bsth_c_line_versions v on l.line_code = v.line_code where l.destroy = 0 group by l.name,l.line_code) b left join bsth_c_ls_sectionroute a on a.line_code = b.line_code and a.versions = b.versions where a.destroy = 0 order by a.line_code,a.directions,a.sectionroute_code", BeanPropertyRowMapper.newInstance(LD_SectionRoute.class));
... ...
src/main/java/com/bsth/server_rs/dks/BxRestService.java 0 → 100644
  1 +package com.bsth.server_rs.dks;
  2 +
  3 +import com.bsth.common.SystemParamKeys;
  4 +import com.bsth.server_rs.base_info.car.Car;
  5 +import com.bsth.server_rs.base_info.car.buffer.CarBufferData;
  6 +import com.bsth.server_rs.base_info.carpark.Carpark;
  7 +import com.bsth.server_rs.base_info.carpark.buffer.CarparkBufferData;
  8 +import com.bsth.server_rs.base_info.line.Line;
  9 +import com.bsth.server_rs.base_info.line.buffer.LineBufferData;
  10 +import com.bsth.server_rs.base_info.section.buffer.LD_SectionBufferData;
  11 +import com.bsth.server_rs.base_info.section.entity.LD_Section;
  12 +import com.bsth.server_rs.base_info.section.entity.LD_SectionRoute;
  13 +import com.bsth.server_rs.base_info.station.buffer.StationBufferData;
  14 +import com.bsth.server_rs.base_info.station.entity.StationRotue;
  15 +import com.bsth.server_rs.gps.buffer.BasicDataBuffer;
  16 +import com.bsth.server_rs.gps.buffer.GpsRealDataBuffer;
  17 +import com.bsth.server_rs.gps.entity.GpsEntity;
  18 +import com.bsth.server_rs.gps.entity.LineInfo;
  19 +import com.bsth.service.SystemParamService;
  20 +import org.slf4j.Logger;
  21 +import org.slf4j.LoggerFactory;
  22 +import org.springframework.beans.factory.annotation.Autowired;
  23 +import org.springframework.stereotype.Component;
  24 +
  25 +import javax.ws.rs.GET;
  26 +import javax.ws.rs.Path;
  27 +import javax.ws.rs.Produces;
  28 +import javax.ws.rs.core.MediaType;
  29 +import java.util.*;
  30 +import java.util.concurrent.ConcurrentHashMap;
  31 +
  32 +/**
  33 + * @author Hill
  34 + * @date 2021-09
  35 + */
  36 +@Component
  37 +@Path("/external")
  38 +@Produces({MediaType.APPLICATION_JSON})
  39 +public class BxRestService {
  40 +
  41 + private final static Logger log = LoggerFactory.getLogger(BxRestService.class);
  42 +
  43 + @Autowired
  44 + private SystemParamService systemParamService;
  45 +
  46 + @Autowired
  47 + private LD_SectionBufferData ldSectionBufferData;
  48 +
  49 + @GET
  50 + @Path("/line")
  51 + public List<Map<String, Object>> findAllLine() {
  52 + List<Map<String, Object>> result = new ArrayList<>();
  53 + String limitLines = systemParamService.getValue(SystemParamKeys.LIMIT_LINES);
  54 + if (limitLines == null) {
  55 + return result;
  56 + }
  57 + for (Line line : LineBufferData.findAll()) {
  58 + String lineCode = line.getLineCode();
  59 + if (limitLines.indexOf(String.format("%s,", lineCode)) > -1) {
  60 + Map<String, Object> lineMap = new HashMap<>();
  61 + Collection<LD_SectionRoute> sectionRoutes = ldSectionBufferData.findByLineCode(lineCode).get(String.format("%s_0", lineCode));
  62 + StringBuilder sb = new StringBuilder();
  63 + for (LD_SectionRoute sectionRoute : sectionRoutes) {
  64 + sb.append(sectionRoute.getSection().getGsectionVector().replace("LINESTRING(", "").replace(")", "")).append(",");
  65 + }
  66 + sb.deleteCharAt(sb.length() - 1);
  67 + lineMap.put("company", BasicDataBuffer.getBusinessByCode(line.getCompany()));
  68 + lineMap.put("branch", BasicDataBuffer.getBusinessByCode(String.format("%s_%s", line.getCompany(), line.getBrancheCompany())));
  69 + lineMap.put("lineName", line.getName());
  70 + lineMap.put("lineCode", line.getShanghaiLinecode());
  71 + lineMap.put("startStation", line.getStartStationName());
  72 + lineMap.put("endStation", line.getEndStationName());
  73 + lineMap.put("lineLength", line.getTotalMileage());
  74 + lineMap.put("upSEtime", String.format("%s-%s", line.getStartStationFirstTime(), line.getStartStationEndTime()));
  75 + lineMap.put("upLinelonlat", sb.toString());
  76 + lineMap.put("downSEtime", String.format("%s-%s", line.getEndStationFirstTime(), line.getEndStationEndTime()));
  77 + lineMap.put("downLinelonlat", null);
  78 +
  79 + result.add(lineMap);
  80 + }
  81 + }
  82 +
  83 + return result;
  84 + }
  85 +
  86 + @GET
  87 + @Path("/station")
  88 + public List<Map<String, Object>> findAllStation() {
  89 + List<Map<String, Object>> result = new ArrayList<>();
  90 + String limitLines = systemParamService.getValue(SystemParamKeys.LIMIT_LINES);
  91 + if (limitLines == null) {
  92 + return result;
  93 + }
  94 + for (String lineCode : limitLines.split(",")) {
  95 + if (!"".equals(lineCode)) {
  96 + Map<String, Object> lineMap = new HashMap<>();
  97 + Line line = LineBufferData.findOne(lineCode);
  98 + lineMap.put("lineName", line.getName());
  99 + lineMap.put("lineCode", line.getShanghaiLinecode());
  100 +
  101 + int count = 1;
  102 + List<Map<String, Object>> upStations = new ArrayList<>(), downStations = new ArrayList<>();
  103 + for (StationRotue route : StationBufferData.findRouteByLineCode(lineCode).get(String.format("%s_0", lineCode))) {
  104 + Map<String, Object> stopMap = new HashMap<>();
  105 + stopMap.put("levelNo", count);
  106 + stopMap.put("levelName", route.getStationName());
  107 + stopMap.put("levelLonlat", String.format("%f %f", route.getStation().getLon(), route.getStation().getLat()));
  108 + stopMap.put("stationCode", null);
  109 + upStations.add(stopMap);
  110 + count++;
  111 + }
  112 + count = 1;
  113 + for (StationRotue route : StationBufferData.findRouteByLineCode(lineCode).get(String.format("%s_1", lineCode))) {
  114 + Map<String, Object> stopMap = new HashMap<>();
  115 + stopMap.put("levelNo", count);
  116 + stopMap.put("levelName", route.getStationName());
  117 + stopMap.put("levelLonlat", String.format("%f %f", route.getStation().getLon(), route.getStation().getLat()));
  118 + stopMap.put("stationCode", null);
  119 + downStations.add(stopMap);
  120 + count++;
  121 + }
  122 +
  123 + lineMap.put("upStations", upStations);
  124 + lineMap.put("downStations", downStations);
  125 + result.add(lineMap);
  126 + }
  127 + }
  128 +
  129 + return result;
  130 + }
  131 +
  132 + @GET
  133 + @Path("/vehicle")
  134 + public List<Map<String, Object>> findAllVehicle() {
  135 + StringBuilder sb = new StringBuilder();
  136 + Map<String, String> device2line = GpsRealDataBuffer.getDevice2Line();
  137 + String limitLines = systemParamService.getValue(SystemParamKeys.LIMIT_LINES);
  138 + for (Map.Entry<String, String> entry : device2line.entrySet()) {
  139 + String deviceId = entry.getKey(), lineCode = entry.getValue();
  140 + if (limitLines.indexOf(String.format("%s,", lineCode)) > -1) {
  141 + sb.append(deviceId).append(",");
  142 + }
  143 + }
  144 + String limitDevices = sb.toString();
  145 + List<Map<String, Object>> result = new ArrayList<>();
  146 + if (limitDevices.equals("")) {
  147 + return result;
  148 + }
  149 + for (Car car : CarBufferData.findAll()) {
  150 + if (limitDevices.indexOf(String.format("%s,", car.getEquipmentCode())) > -1) {
  151 + Map<String, Object> carMap = new HashMap<>();
  152 + Line line = LineBufferData.findOne(device2line.get(car.getEquipmentCode()));
  153 + if (line == null) {
  154 + continue;
  155 + }
  156 + carMap.put("lineName", line.getName());
  157 + carMap.put("lineCode", line.getShanghaiLinecode());
  158 + carMap.put("vehicleId", car.getCarPlate());
  159 + carMap.put("vehicleNo", car.getNbbm());
  160 + carMap.put("vehicleType", car.getVehicleType());
  161 + carMap.put("energyType", car.getSfdc() ? 3 : 0);
  162 +
  163 + result.add(carMap);
  164 + }
  165 + }
  166 +
  167 + return result;
  168 + }
  169 +
  170 + @GET
  171 + @Path("/parking")
  172 + public List<Map<String, Object>> findAllParking() {
  173 + List<Map<String, Object>> result = new ArrayList<>();
  174 + String limitLines = systemParamService.getValue(SystemParamKeys.LIMIT_LINES);
  175 + if (limitLines == null) {
  176 + return result;
  177 + }
  178 + StringBuilder sb = new StringBuilder();
  179 + for (Line line : LineBufferData.findAll()) {
  180 + String lineCode = line.getLineCode();
  181 + if (limitLines.indexOf(String.format("%s,", lineCode)) > -1) {
  182 + sb.append(line.getCarPark()).append(",");
  183 + }
  184 + }
  185 + String limitParkings = sb.toString();
  186 +
  187 + if (limitParkings.equals("")) {
  188 + return result;
  189 + }
  190 + for (Carpark carpark : CarparkBufferData.findAll()) {
  191 + if (limitParkings.indexOf(String.format("%s,", carpark.getParkCode())) > -1) {
  192 + Map<String, Object> parkMap = new HashMap<>();
  193 + parkMap.put("company", BasicDataBuffer.getBusinessByCode(carpark.getCompany()));
  194 + parkMap.put("parkName", carpark.getParkName());
  195 + parkMap.put("parkAddress", null);
  196 + parkMap.put("parkLonlat", carpark.getgParkPoint());
  197 + result.add(parkMap);
  198 + }
  199 + }
  200 +
  201 + return result;
  202 + }
  203 +
  204 + @GET
  205 + @Path("/gps/all")
  206 + public List<Map<String, Object>> findAllGps() {
  207 + List<Map<String, Object>> result = new ArrayList<>();
  208 + String limitLines = systemParamService.getValue(SystemParamKeys.LIMIT_LINES);
  209 + if (limitLines == null) {
  210 + return result;
  211 + }
  212 + for (GpsEntity gps : GpsRealDataBuffer.all()) {
  213 + String lineCode = gps.getLineId(), deviceId = gps.getDeviceId();
  214 + if (limitLines.indexOf(String.format("%s,", lineCode)) > -1) {
  215 + Line line = LineBufferData.findOne(lineCode);
  216 + Car car = CarBufferData.findOne(deviceId);
  217 + Map<String, Object> gpsMap = new HashMap<>();
  218 + gpsMap.put("lineName", line.getName());
  219 + gpsMap.put("lineCode", line.getShanghaiLinecode());
  220 + gpsMap.put("vehicleId", car.getCarPlate());
  221 + gpsMap.put("gpsTime", gps.getTimestamp());
  222 + gpsMap.put("gpsLonlat", String.format("%f %f", gps.getLon(), gps.getLat()));
  223 + gpsMap.put("angle", gps.getDirection());
  224 +
  225 + result.add(gpsMap);
  226 + }
  227 + }
  228 +
  229 + return result;
  230 + }
  231 +}
... ...
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 +}
... ...
src/main/java/com/bsth/server_rs/gps/buffer/GpsRefreshThread.java
1   -package com.bsth.server_rs.gps.buffer;
2   -
3   -import com.alibaba.fastjson.JSON;
4   -import com.alibaba.fastjson.JSONObject;
5   -import com.bsth.server_rs.gps.entity.GpsEntity;
6   -import com.bsth.util.ConfigUtil;
7   -import org.apache.http.HttpEntity;
8   -import org.apache.http.client.config.RequestConfig;
9   -import org.apache.http.client.methods.CloseableHttpResponse;
10   -import org.apache.http.client.methods.HttpGet;
11   -import org.apache.http.impl.client.CloseableHttpClient;
12   -import org.apache.http.impl.client.HttpClients;
13   -import org.slf4j.Logger;
14   -import org.slf4j.LoggerFactory;
15   -import org.springframework.stereotype.Component;
16   -
17   -import java.io.BufferedReader;
18   -import java.io.InputStreamReader;
19   -import java.util.List;
20   -
21   -/**
22   - * Created by panzhao on 2017/3/30.
23   - */
24   -@Component
25   -public class GpsRefreshThread extends Thread{
26   -
27   - static String url;
28   -
29   - static {
30   - url = ConfigUtil.get("http.gps.real.url");
31   - }
32   -
33   - Logger logger = LoggerFactory.getLogger(this.getClass());
34   -
35   - @Override
36   - public void run() {
37   - try {
38   - CloseableHttpClient httpClient = null;
39   - List<GpsEntity> rs = null;
40   - httpClient = HttpClients.createDefault();
41   - //超时时间
42   - RequestConfig requestConfig = RequestConfig.custom()
43   - .setConnectTimeout(2000).setConnectionRequestTimeout(1000)
44   - .setSocketTimeout(3000).build();
45   -
46   - HttpGet get = new HttpGet(url);
47   - get.setConfig(requestConfig);
48   -
49   - CloseableHttpResponse response = httpClient.execute(get);
50   -
51   - HttpEntity entity = response.getEntity();
52   - BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent()));
53   - StringBuffer stringBuffer = new StringBuffer();
54   - String str = "";
55   - while ((str = br.readLine()) != null)
56   - stringBuffer.append(str);
57   -
58   - JSONObject jsonObj = JSON.parseObject(stringBuffer.toString());
59   -
60   - if (jsonObj != null)
61   - rs = JSON.parseArray(jsonObj.getString("data"), GpsEntity.class);
62   -
63   - for(GpsEntity gps : rs){
64   - GpsRealDataBuffer.put(gps);
65   - }
66   - }catch (Exception e){
67   - logger.error("", e);
68   - }
69   - }
70   -}
  1 +package com.bsth.server_rs.gps.buffer;
  2 +
  3 +import com.alibaba.fastjson.JSON;
  4 +import com.alibaba.fastjson.JSONObject;
  5 +import com.bsth.server_rs.gps.entity.GpsEntity;
  6 +import com.bsth.util.ConfigUtil;
  7 +import org.apache.http.HttpEntity;
  8 +import org.apache.http.client.config.RequestConfig;
  9 +import org.apache.http.client.methods.CloseableHttpResponse;
  10 +import org.apache.http.client.methods.HttpGet;
  11 +import org.apache.http.impl.client.CloseableHttpClient;
  12 +import org.apache.http.impl.client.HttpClients;
  13 +import org.slf4j.Logger;
  14 +import org.slf4j.LoggerFactory;
  15 +import org.springframework.stereotype.Component;
  16 +
  17 +import java.io.BufferedReader;
  18 +import java.io.InputStreamReader;
  19 +import java.util.List;
  20 +
  21 +/**
  22 + * Created by panzhao on 2017/3/30.
  23 + */
  24 +@Component
  25 +public class GpsRefreshThread extends Thread{
  26 +
  27 + static String url;
  28 +
  29 + static {
  30 + url = ConfigUtil.get("http.gps.real.url");
  31 + }
  32 +
  33 + Logger logger = LoggerFactory.getLogger(this.getClass());
  34 +
  35 + @Override
  36 + public void run() {
  37 + try {
  38 + CloseableHttpClient httpClient = null;
  39 + List<GpsEntity> rs = null;
  40 + httpClient = HttpClients.createDefault();
  41 + //超时时间
  42 + RequestConfig requestConfig = RequestConfig.custom()
  43 + .setConnectTimeout(2000).setConnectionRequestTimeout(1000)
  44 + .setSocketTimeout(3000).build();
  45 +
  46 + HttpGet get = new HttpGet(url);
  47 + get.setConfig(requestConfig);
  48 +
  49 + CloseableHttpResponse response = httpClient.execute(get);
  50 +
  51 + HttpEntity entity = response.getEntity();
  52 + BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent()));
  53 + StringBuffer stringBuffer = new StringBuffer();
  54 + String str = "";
  55 + while ((str = br.readLine()) != null)
  56 + stringBuffer.append(str);
  57 +
  58 + JSONObject jsonObj = JSON.parseObject(stringBuffer.toString());
  59 +
  60 + if (jsonObj != null)
  61 + rs = JSON.parseArray(jsonObj.getString("data"), GpsEntity.class);
  62 +
  63 + for(GpsEntity gps : rs){
  64 + GpsRealDataBuffer.put(gps);
  65 + GpsRealDataBuffer.putLineCode(gps.getDeviceId(), gps.getLineId());
  66 + }
  67 + }catch (Exception e){
  68 + logger.error("", e);
  69 + }
  70 + }
  71 +}
... ...
src/main/java/com/bsth/server_rs/man_hours/ManHoursRestService.java
1 1 package com.bsth.server_rs.man_hours;
2 2  
3   -import com.bsth.entity.WhiteIp;
4   -import org.springframework.beans.factory.annotation.Autowired;
5   -import org.springframework.jdbc.core.BeanPropertyRowMapper;
6   -import org.springframework.jdbc.core.JdbcTemplate;
7 3 import org.springframework.stereotype.Component;
8   -import org.springframework.web.bind.annotation.PathVariable;
9 4  
10 5 import javax.ws.rs.GET;
11 6 import javax.ws.rs.Path;
... ... @@ -13,7 +8,6 @@ import javax.ws.rs.PathParam;
13 8 import javax.ws.rs.Produces;
14 9 import javax.ws.rs.core.MediaType;
15 10 import java.util.HashMap;
16   -import java.util.List;
17 11 import java.util.Map;
18 12  
19 13 /**
... ...
src/main/java/com/bsth/server_rs/schedule/dto/ScheduleRealInfoDTO_JK.java
1   -package com.bsth.server_rs.schedule.dto;
2   -
3   -import com.bsth.entity.ChildTaskPlan;
4   -import com.bsth.entity.ScheduleRealInfo;
5   -
6   -import javax.xml.bind.annotation.XmlRootElement;
7   -import java.io.Serializable;
8   -import java.util.*;
9   -
10   -/**
11   - * 输出给监控平台的实际排班
12   - * Created by panzhao on 2017/8/30.
13   - */
14   -@XmlRootElement
15   -public class ScheduleRealInfoDTO_JK implements Serializable {
16   -
17   - public static List<ScheduleRealInfoDTO_JK> getMultiInstance(List<ScheduleRealInfo> list) {
18   -
19   - List<ScheduleRealInfoDTO_JK> rs = new ArrayList<>();
20   -
21   - if(list == null || list.size()==0)
22   - return rs;
23   - Collections.sort(list, new Comparator<ScheduleRealInfo>() {
24   - @Override
25   - public int compare(ScheduleRealInfo o1, ScheduleRealInfo o2) {
26   - return o1.getFcsj().compareTo(o2.getFcsj());
27   - }
28   - });
29   -
30   - for (ScheduleRealInfo sch : list) {
31   - rs.add(new ScheduleRealInfoDTO_JK(sch));
32   - }
33   - return rs;
34   - }
35   -
36   - ScheduleRealInfoDTO_JK() {
37   - }
38   -
39   - ScheduleRealInfoDTO_JK(ScheduleRealInfo sch) {
40   - this.id = sch.getId();
41   - this.scheduleDate = sch.getScheduleDateStr();
42   - this.lineName = sch.getXlName();
43   - this.lineCode = sch.getXlBm();
44   - this.lpName = sch.getLpName();
45   - this.nbbm = sch.getClZbh();
46   - this.jsy = sch.getjGh() + "/" + sch.getjName();
47   - this.spy = sch.getsGh() + "/" + sch.getsName();
48   - this.upDown = Integer.parseInt(sch.getXlDir());
49   - this.qdzCode = sch.getQdzCode();
50   - this.qdzName = sch.getQdzName();
51   - this.zdzCode = sch.getZdzCode();
52   - this.zdzName = sch.getZdzName();
53   - this.fcsjT = sch.getFcsjT();
54   - this.dfsjT = sch.getDfsjT();
55   - this.zdsjT = sch.getZdsjT();
56   - this.fcsjActualTime = sch.getFcsjActualTime();
57   - this.zdsjActualTime = sch.getZdsjActualTime();
58   - this.jhlc = sch.getJhlc();
59   - this.jhlcOrig = sch.getJhlcOrig();
60   - this.bcsj = sch.getBcsj();
61   - this.bcType = sch.getBcType();
62   - this.status = sch.getStatus();
63   - this.adjustExps = sch.getAdjustExps();
64   - this.sflj = sch.isSflj();
65   - this.remarks = sch.getRemarks();
66   - this.cTasks = sch.getcTasks();
67   - }
68   -
69   - private Long id;
70   -
71   - private String scheduleDate;
72   -
73   - /**
74   - * 线路名称
75   - */
76   - private String lineName;
77   - /**
78   - * 线路编码
79   - */
80   - private String lineCode;
81   -
82   - /**
83   - * 路牌名称
84   - */
85   - private String lpName;
86   -
87   - /**
88   - * 车辆自编号
89   - */
90   - private String nbbm;
91   -
92   - /**
93   - * 驾驶员工号/名称
94   - */
95   - private String jsy;
96   - /**
97   - * 售票员工号/名称
98   - */
99   - private String spy;
100   -
101   - /**
102   - * 线路方向
103   - */
104   - private Integer upDown;
105   - /**
106   - * 起点站code
107   - */
108   - private String qdzCode;
109   - /**
110   - * 起点站名字
111   - */
112   - private String qdzName;
113   -
114   - /**
115   - * 终点站code
116   - */
117   - private String zdzCode;
118   - /**
119   - * 终点站名字
120   - */
121   - private String zdzName;
122   -
123   - /**
124   - * 计划发车时间戳
125   - */
126   - private Long fcsjT;
127   - /**
128   - * 待发时间戳
129   - */
130   - private Long dfsjT;
131   - /**
132   - * 计划终点时间戳
133   - */
134   - private Long zdsjT;
135   -
136   - /**
137   - * 实际发车时间戳
138   - */
139   - private Long fcsjActualTime;
140   - /**
141   - * 实际终点时间戳
142   - */
143   - private Long zdsjActualTime;
144   -
145   - /**
146   - * 实际计划里程
147   - */
148   - private Double jhlc;
149   -
150   - /**
151   - * 计划里程
152   - */
153   - private Double jhlcOrig;
154   -
155   - /**
156   - * 班次历时
157   - */
158   - private Integer bcsj;
159   -
160   - /**
161   - * 班次类型 TODO:正常班次、出场、进场、加油、区间班次、放空班次、放大站班次、两点间空驶
162   - */
163   - private String bcType;
164   -
165   -
166   - /**
167   - * 班次状态 0 未执行 1 正在执行 2 已执行 -1 已烂班
168   - */
169   - private int status;
170   -
171   - private String adjustExps;
172   -
173   - /**
174   - * 是否是临加班次
175   - */
176   - private boolean sflj;
177   -
178   - /**
179   - * 备注
180   - */
181   - private String remarks;
182   -
183   - /**
184   - * 子任务
185   - */
186   - private Set<ChildTaskPlan> cTasks;
187   -
188   - public Long getId() {
189   - return id;
190   - }
191   -
192   - public void setId(Long id) {
193   - this.id = id;
194   - }
195   -
196   - public String getScheduleDate() {
197   - return scheduleDate;
198   - }
199   -
200   - public void setScheduleDate(String scheduleDate) {
201   - this.scheduleDate = scheduleDate;
202   - }
203   -
204   - public String getLineName() {
205   - return lineName;
206   - }
207   -
208   - public void setLineName(String lineName) {
209   - this.lineName = lineName;
210   - }
211   -
212   - public String getLineCode() {
213   - return lineCode;
214   - }
215   -
216   - public void setLineCode(String lineCode) {
217   - this.lineCode = lineCode;
218   - }
219   -
220   - public String getLpName() {
221   - return lpName;
222   - }
223   -
224   - public void setLpName(String lpName) {
225   - this.lpName = lpName;
226   - }
227   -
228   - public String getNbbm() {
229   - return nbbm;
230   - }
231   -
232   - public void setNbbm(String nbbm) {
233   - this.nbbm = nbbm;
234   - }
235   -
236   - public String getJsy() {
237   - return jsy;
238   - }
239   -
240   - public void setJsy(String jsy) {
241   - this.jsy = jsy;
242   - }
243   -
244   - public String getSpy() {
245   - return spy;
246   - }
247   -
248   - public void setSpy(String spy) {
249   - this.spy = spy;
250   - }
251   -
252   - public String getQdzCode() {
253   - return qdzCode;
254   - }
255   -
256   - public void setQdzCode(String qdzCode) {
257   - this.qdzCode = qdzCode;
258   - }
259   -
260   - public String getQdzName() {
261   - return qdzName;
262   - }
263   -
264   - public void setQdzName(String qdzName) {
265   - this.qdzName = qdzName;
266   - }
267   -
268   - public String getZdzCode() {
269   - return zdzCode;
270   - }
271   -
272   - public void setZdzCode(String zdzCode) {
273   - this.zdzCode = zdzCode;
274   - }
275   -
276   - public String getZdzName() {
277   - return zdzName;
278   - }
279   -
280   - public void setZdzName(String zdzName) {
281   - this.zdzName = zdzName;
282   - }
283   -
284   - public Long getFcsjT() {
285   - return fcsjT;
286   - }
287   -
288   - public void setFcsjT(Long fcsjT) {
289   - this.fcsjT = fcsjT;
290   - }
291   -
292   - public Long getDfsjT() {
293   - return dfsjT;
294   - }
295   -
296   - public void setDfsjT(Long dfsjT) {
297   - this.dfsjT = dfsjT;
298   - }
299   -
300   - public Long getZdsjT() {
301   - return zdsjT;
302   - }
303   -
304   - public void setZdsjT(Long zdsjT) {
305   - this.zdsjT = zdsjT;
306   - }
307   -
308   - public Long getFcsjActualTime() {
309   - return fcsjActualTime;
310   - }
311   -
312   - public void setFcsjActualTime(Long fcsjActualTime) {
313   - this.fcsjActualTime = fcsjActualTime;
314   - }
315   -
316   - public Long getZdsjActualTime() {
317   - return zdsjActualTime;
318   - }
319   -
320   - public void setZdsjActualTime(Long zdsjActualTime) {
321   - this.zdsjActualTime = zdsjActualTime;
322   - }
323   -
324   - public Double getJhlc() {
325   - return jhlc;
326   - }
327   -
328   - public void setJhlc(Double jhlc) {
329   - this.jhlc = jhlc;
330   - }
331   -
332   - public Double getJhlcOrig() {
333   - return jhlcOrig;
334   - }
335   -
336   - public void setJhlcOrig(Double jhlcOrig) {
337   - this.jhlcOrig = jhlcOrig;
338   - }
339   -
340   - public Integer getBcsj() {
341   - return bcsj;
342   - }
343   -
344   - public void setBcsj(Integer bcsj) {
345   - this.bcsj = bcsj;
346   - }
347   -
348   - public String getBcType() {
349   - return bcType;
350   - }
351   -
352   - public void setBcType(String bcType) {
353   - this.bcType = bcType;
354   - }
355   -
356   - public int getStatus() {
357   - return status;
358   - }
359   -
360   - public void setStatus(int status) {
361   - this.status = status;
362   - }
363   -
364   - public String getAdjustExps() {
365   - return adjustExps;
366   - }
367   -
368   - public void setAdjustExps(String adjustExps) {
369   - this.adjustExps = adjustExps;
370   - }
371   -
372   - public boolean isSflj() {
373   - return sflj;
374   - }
375   -
376   - public void setSflj(boolean sflj) {
377   - this.sflj = sflj;
378   - }
379   -
380   - public String getRemarks() {
381   - return remarks;
382   - }
383   -
384   - public void setRemarks(String remarks) {
385   - this.remarks = remarks;
386   - }
387   -
388   - public Set<ChildTaskPlan> getcTasks() {
389   - return cTasks;
390   - }
391   -
392   - public void setcTasks(Set<ChildTaskPlan> cTasks) {
393   - this.cTasks = cTasks;
394   - }
395   -
396   - public Integer getUpDown() {
397   - return upDown;
398   - }
399   -
400   - public void setUpDown(Integer upDown) {
401   - this.upDown = upDown;
402   - }
403   -}
  1 +package com.bsth.server_rs.schedule.dto;
  2 +
  3 +import com.bsth.entity.ChildTaskPlan;
  4 +import com.bsth.entity.ScheduleRealInfo;
  5 +
  6 +import javax.xml.bind.annotation.XmlRootElement;
  7 +import java.io.Serializable;
  8 +import java.util.*;
  9 +
  10 +/**
  11 + * 输出给监控平台的实际排班
  12 + * Created by panzhao on 2017/8/30.
  13 + */
  14 +@XmlRootElement
  15 +public class ScheduleRealInfoDTO_JK implements Serializable {
  16 +
  17 + public static List<ScheduleRealInfoDTO_JK> getMultiInstance(List<ScheduleRealInfo> list) {
  18 +
  19 + List<ScheduleRealInfoDTO_JK> rs = new ArrayList<>();
  20 +
  21 + if(list == null || list.size()==0)
  22 + return rs;
  23 + Collections.sort(list, new Comparator<ScheduleRealInfo>() {
  24 + @Override
  25 + public int compare(ScheduleRealInfo o1, ScheduleRealInfo o2) {
  26 + return o1.getFcsj().compareTo(o2.getFcsj());
  27 + }
  28 + });
  29 +
  30 + for (ScheduleRealInfo sch : list) {
  31 + rs.add(new ScheduleRealInfoDTO_JK(sch));
  32 + }
  33 + return rs;
  34 + }
  35 +
  36 + ScheduleRealInfoDTO_JK() {
  37 + }
  38 +
  39 + ScheduleRealInfoDTO_JK(ScheduleRealInfo sch) {
  40 + this.id = sch.getId();
  41 + this.scheduleDate = sch.getScheduleDateStr();
  42 + this.lineName = sch.getXlName();
  43 + this.lineCode = sch.getXlBm();
  44 + this.lpName = sch.getLpName();
  45 + this.nbbm = sch.getClZbh();
  46 + this.jsy = sch.getjGh() + "/" + sch.getjName();
  47 + this.spy = sch.getsGh() + "/" + sch.getsName();
  48 + this.upDown = Integer.parseInt(sch.getXlDir());
  49 + this.qdzCode = sch.getQdzCode();
  50 + this.qdzName = sch.getQdzName();
  51 + this.zdzCode = sch.getZdzCode();
  52 + this.zdzName = sch.getZdzName();
  53 + this.fcsjT = sch.getFcsjT();
  54 + this.dfsjT = sch.getDfsjT();
  55 + this.zdsjT = sch.getZdsjT();
  56 + this.fcsjActualTime = sch.getFcsjActualTime();
  57 + this.zdsjActualTime = sch.getZdsjActualTime();
  58 + this.jhlc = sch.getJhlc();
  59 + this.jhlcOrig = sch.getJhlcOrig();
  60 + this.bcsj = sch.getBcsj();
  61 + this.bcType = sch.getBcType();
  62 + this.status = sch.getStatus();
  63 + this.adjustExps = sch.getAdjustExps();
  64 + this.sflj = sch.isSflj();
  65 + this.remarks = sch.getRemarks();
  66 + this.cTasks = sch.getcTasks();
  67 + this.updateDate = sch.getUpdateDate().getTime();
  68 + }
  69 +
  70 + private Long id;
  71 +
  72 + private String scheduleDate;
  73 +
  74 + /**
  75 + * 线路名称
  76 + */
  77 + private String lineName;
  78 + /**
  79 + * 线路编码
  80 + */
  81 + private String lineCode;
  82 +
  83 + /**
  84 + * 路牌名称
  85 + */
  86 + private String lpName;
  87 +
  88 + /**
  89 + * 车辆自编号
  90 + */
  91 + private String nbbm;
  92 +
  93 + /**
  94 + * 驾驶员工号/名称
  95 + */
  96 + private String jsy;
  97 + /**
  98 + * 售票员工号/名称
  99 + */
  100 + private String spy;
  101 +
  102 + /**
  103 + * 线路方向
  104 + */
  105 + private Integer upDown;
  106 + /**
  107 + * 起点站code
  108 + */
  109 + private String qdzCode;
  110 + /**
  111 + * 起点站名字
  112 + */
  113 + private String qdzName;
  114 +
  115 + /**
  116 + * 终点站code
  117 + */
  118 + private String zdzCode;
  119 + /**
  120 + * 终点站名字
  121 + */
  122 + private String zdzName;
  123 +
  124 + /**
  125 + * 计划发车时间戳
  126 + */
  127 + private Long fcsjT;
  128 + /**
  129 + * 待发时间戳
  130 + */
  131 + private Long dfsjT;
  132 + /**
  133 + * 计划终点时间戳
  134 + */
  135 + private Long zdsjT;
  136 +
  137 + /**
  138 + * 实际发车时间戳
  139 + */
  140 + private Long fcsjActualTime;
  141 + /**
  142 + * 实际终点时间戳
  143 + */
  144 + private Long zdsjActualTime;
  145 +
  146 + /**
  147 + * 实际计划里程
  148 + */
  149 + private Double jhlc;
  150 +
  151 + /**
  152 + * 计划里程
  153 + */
  154 + private Double jhlcOrig;
  155 +
  156 + /**
  157 + * 班次历时
  158 + */
  159 + private Integer bcsj;
  160 +
  161 + /**
  162 + * 班次类型 TODO:正常班次、出场、进场、加油、区间班次、放空班次、放大站班次、两点间空驶
  163 + */
  164 + private String bcType;
  165 +
  166 +
  167 + /**
  168 + * 班次状态 0 未执行 1 正在执行 2 已执行 -1 已烂班
  169 + */
  170 + private int status;
  171 +
  172 + private String adjustExps;
  173 +
  174 + /**
  175 + * 是否是临加班次
  176 + */
  177 + private boolean sflj;
  178 +
  179 + /**
  180 + * 备注
  181 + */
  182 + private String remarks;
  183 +
  184 + private Double oilConsum;
  185 + private Double elecConsum;
  186 + private Double h2Consum;
  187 + private Long updateDate;
  188 +
  189 + /**
  190 + * 子任务
  191 + */
  192 + private Set<ChildTaskPlan> cTasks;
  193 +
  194 + public Long getId() {
  195 + return id;
  196 + }
  197 +
  198 + public void setId(Long id) {
  199 + this.id = id;
  200 + }
  201 +
  202 + public String getScheduleDate() {
  203 + return scheduleDate;
  204 + }
  205 +
  206 + public void setScheduleDate(String scheduleDate) {
  207 + this.scheduleDate = scheduleDate;
  208 + }
  209 +
  210 + public String getLineName() {
  211 + return lineName;
  212 + }
  213 +
  214 + public void setLineName(String lineName) {
  215 + this.lineName = lineName;
  216 + }
  217 +
  218 + public String getLineCode() {
  219 + return lineCode;
  220 + }
  221 +
  222 + public void setLineCode(String lineCode) {
  223 + this.lineCode = lineCode;
  224 + }
  225 +
  226 + public String getLpName() {
  227 + return lpName;
  228 + }
  229 +
  230 + public void setLpName(String lpName) {
  231 + this.lpName = lpName;
  232 + }
  233 +
  234 + public String getNbbm() {
  235 + return nbbm;
  236 + }
  237 +
  238 + public void setNbbm(String nbbm) {
  239 + this.nbbm = nbbm;
  240 + }
  241 +
  242 + public String getJsy() {
  243 + return jsy;
  244 + }
  245 +
  246 + public void setJsy(String jsy) {
  247 + this.jsy = jsy;
  248 + }
  249 +
  250 + public String getSpy() {
  251 + return spy;
  252 + }
  253 +
  254 + public void setSpy(String spy) {
  255 + this.spy = spy;
  256 + }
  257 +
  258 + public String getQdzCode() {
  259 + return qdzCode;
  260 + }
  261 +
  262 + public void setQdzCode(String qdzCode) {
  263 + this.qdzCode = qdzCode;
  264 + }
  265 +
  266 + public String getQdzName() {
  267 + return qdzName;
  268 + }
  269 +
  270 + public void setQdzName(String qdzName) {
  271 + this.qdzName = qdzName;
  272 + }
  273 +
  274 + public String getZdzCode() {
  275 + return zdzCode;
  276 + }
  277 +
  278 + public void setZdzCode(String zdzCode) {
  279 + this.zdzCode = zdzCode;
  280 + }
  281 +
  282 + public String getZdzName() {
  283 + return zdzName;
  284 + }
  285 +
  286 + public void setZdzName(String zdzName) {
  287 + this.zdzName = zdzName;
  288 + }
  289 +
  290 + public Long getFcsjT() {
  291 + return fcsjT;
  292 + }
  293 +
  294 + public void setFcsjT(Long fcsjT) {
  295 + this.fcsjT = fcsjT;
  296 + }
  297 +
  298 + public Long getDfsjT() {
  299 + return dfsjT;
  300 + }
  301 +
  302 + public void setDfsjT(Long dfsjT) {
  303 + this.dfsjT = dfsjT;
  304 + }
  305 +
  306 + public Long getZdsjT() {
  307 + return zdsjT;
  308 + }
  309 +
  310 + public void setZdsjT(Long zdsjT) {
  311 + this.zdsjT = zdsjT;
  312 + }
  313 +
  314 + public Long getFcsjActualTime() {
  315 + return fcsjActualTime;
  316 + }
  317 +
  318 + public void setFcsjActualTime(Long fcsjActualTime) {
  319 + this.fcsjActualTime = fcsjActualTime;
  320 + }
  321 +
  322 + public Long getZdsjActualTime() {
  323 + return zdsjActualTime;
  324 + }
  325 +
  326 + public void setZdsjActualTime(Long zdsjActualTime) {
  327 + this.zdsjActualTime = zdsjActualTime;
  328 + }
  329 +
  330 + public Double getJhlc() {
  331 + return jhlc;
  332 + }
  333 +
  334 + public void setJhlc(Double jhlc) {
  335 + this.jhlc = jhlc;
  336 + }
  337 +
  338 + public Double getJhlcOrig() {
  339 + return jhlcOrig;
  340 + }
  341 +
  342 + public void setJhlcOrig(Double jhlcOrig) {
  343 + this.jhlcOrig = jhlcOrig;
  344 + }
  345 +
  346 + public Integer getBcsj() {
  347 + return bcsj;
  348 + }
  349 +
  350 + public void setBcsj(Integer bcsj) {
  351 + this.bcsj = bcsj;
  352 + }
  353 +
  354 + public String getBcType() {
  355 + return bcType;
  356 + }
  357 +
  358 + public void setBcType(String bcType) {
  359 + this.bcType = bcType;
  360 + }
  361 +
  362 + public int getStatus() {
  363 + return status;
  364 + }
  365 +
  366 + public void setStatus(int status) {
  367 + this.status = status;
  368 + }
  369 +
  370 + public String getAdjustExps() {
  371 + return adjustExps;
  372 + }
  373 +
  374 + public void setAdjustExps(String adjustExps) {
  375 + this.adjustExps = adjustExps;
  376 + }
  377 +
  378 + public boolean isSflj() {
  379 + return sflj;
  380 + }
  381 +
  382 + public void setSflj(boolean sflj) {
  383 + this.sflj = sflj;
  384 + }
  385 +
  386 + public String getRemarks() {
  387 + return remarks;
  388 + }
  389 +
  390 + public void setRemarks(String remarks) {
  391 + this.remarks = remarks;
  392 + }
  393 +
  394 + public Set<ChildTaskPlan> getcTasks() {
  395 + return cTasks;
  396 + }
  397 +
  398 + public void setcTasks(Set<ChildTaskPlan> cTasks) {
  399 + this.cTasks = cTasks;
  400 + }
  401 +
  402 + public Integer getUpDown() {
  403 + return upDown;
  404 + }
  405 +
  406 + public void setUpDown(Integer upDown) {
  407 + this.upDown = upDown;
  408 + }
  409 +
  410 + public Double getOilConsum() {
  411 + return oilConsum;
  412 + }
  413 +
  414 + public void setOilConsum(Double oilConsum) {
  415 + this.oilConsum = oilConsum;
  416 + }
  417 +
  418 + public Double getElecConsum() {
  419 + return elecConsum;
  420 + }
  421 +
  422 + public void setElecConsum(Double elecConsum) {
  423 + this.elecConsum = elecConsum;
  424 + }
  425 +
  426 + public Double getH2Consum() {
  427 + return h2Consum;
  428 + }
  429 +
  430 + public void setH2Consum(Double h2Consum) {
  431 + this.h2Consum = h2Consum;
  432 + }
  433 +
  434 + public Long getUpdateDate() {
  435 + return updateDate;
  436 + }
  437 +
  438 + public void setUpdateDate(Long updateDate) {
  439 + this.updateDate = updateDate;
  440 + }
  441 +}
... ...
src/main/java/com/bsth/server_rs/schedule/real/SchRealDataBuffer.java
1   -package com.bsth.server_rs.schedule.real;
2   -
3   -import com.alibaba.fastjson.JSONObject;
4   -import com.bsth.entity.ScheduleRealInfo;
5   -import com.google.common.collect.ArrayListMultimap;
6   -import org.apache.commons.lang3.StringUtils;
7   -import org.springframework.stereotype.Component;
8   -
9   -import java.util.Collection;
10   -import java.util.List;
11   -import java.util.Map;
12   -
13   -/**
14   - * 实际排班缓存
15   - * Created by panzhao on 2017/9/27.
16   - */
17   -@Component
18   -public class SchRealDataBuffer {
19   -
20   - /**
21   - * 进出场班次数据,定时从调度系统获取。 对各场站输出
22   - */
23   - private static ArrayListMultimap<String, ScheduleRealInfo> inOutMap;
24   -
25   - /**
26   - * 车辆 和 当前正在执行班次对照
27   - */
28   - private static Map<String, JSONObject> execMap;
29   -
30   - public void putInOutData(List<ScheduleRealInfo> list) {
31   - ArrayListMultimap<String, ScheduleRealInfo> inOutMapCopy = ArrayListMultimap.create();
32   -
33   - String type;
34   - for (ScheduleRealInfo sch : list) {
35   - type = sch.getBcType();
36   - if (StringUtils.isEmpty(type))
37   - continue;
38   -
39   - if (type.equals("in"))
40   - inOutMapCopy.put(sch.getZdzCode(), sch);
41   - else if (type.equals("out"))
42   - inOutMapCopy.put(sch.getQdzCode(), sch);
43   - }
44   -
45   - inOutMap = inOutMapCopy;
46   - }
47   -
48   -
49   - public void setExecMap(Map<String, JSONObject> map) {
50   - if (map.size() > 0)
51   - execMap = map;
52   - }
53   -
54   - public List<ScheduleRealInfo> findByParkCode(String parkCode) {
55   - return inOutMap.get(parkCode);
56   - }
57   -
58   - /* public List<JSONObject> findExec(List<String> cars){
59   - List<JSONObject> rs = new ArrayList<>(cars.size());
60   -
61   - for(String nbbm : cars){
62   - rs.add(execMap.get(nbbm));
63   - }
64   - return rs;
65   - }*/
66   -
67   - public JSONObject getExecPlan(String nbbm) {
68   - return execMap.get(nbbm);
69   - }
70   -
71   - public Collection<JSONObject> execs() {
72   - return execMap.values();
73   - }
74   -}
  1 +package com.bsth.server_rs.schedule.real;
  2 +
  3 +import com.alibaba.fastjson.JSONObject;
  4 +import com.bsth.entity.ScheduleRealInfo;
  5 +import com.google.common.collect.ArrayListMultimap;
  6 +import org.apache.commons.lang3.StringUtils;
  7 +import org.springframework.stereotype.Component;
  8 +
  9 +import java.util.Collection;
  10 +import java.util.List;
  11 +import java.util.Map;
  12 +
  13 +/**
  14 + * 实际排班缓存
  15 + * Created by panzhao on 2017/9/27.
  16 + */
  17 +@Component
  18 +public class SchRealDataBuffer {
  19 +
  20 + /**
  21 + * 进出场班次数据,定时从调度系统获取。 对各场站输出
  22 + */
  23 + private static ArrayListMultimap<String, ScheduleRealInfo> inOutMap;
  24 +
  25 + /**
  26 + * 车辆 和 当前正在执行班次对照
  27 + */
  28 + private static Map<String, JSONObject> execMap;
  29 +
  30 + public void putInOutData(List<ScheduleRealInfo> list) {
  31 + ArrayListMultimap<String, ScheduleRealInfo> inOutMapCopy = ArrayListMultimap.create();
  32 +
  33 + String type;
  34 + for (ScheduleRealInfo sch : list) {
  35 + type = sch.getBcType();
  36 + if (StringUtils.isEmpty(type))
  37 + continue;
  38 +
  39 + if (type.equals("in"))
  40 + inOutMapCopy.put(sch.getZdzCode(), sch);
  41 + else if (type.equals("out"))
  42 + inOutMapCopy.put(sch.getQdzCode(), sch);
  43 + }
  44 +
  45 + inOutMap = inOutMapCopy;
  46 + }
  47 +
  48 + public Collection<ScheduleRealInfo> getInOutData() {
  49 + return inOutMap.values();
  50 + }
  51 +
  52 + public void setExecMap(Map<String, JSONObject> map) {
  53 + if (map.size() > 0)
  54 + execMap = map;
  55 + }
  56 +
  57 + public List<ScheduleRealInfo> findByParkCode(String parkCode) {
  58 + return inOutMap.get(parkCode);
  59 + }
  60 +
  61 + /* public List<JSONObject> findExec(List<String> cars){
  62 + List<JSONObject> rs = new ArrayList<>(cars.size());
  63 +
  64 + for(String nbbm : cars){
  65 + rs.add(execMap.get(nbbm));
  66 + }
  67 + return rs;
  68 + }*/
  69 +
  70 + public JSONObject getExecPlan(String nbbm) {
  71 + return execMap.get(nbbm);
  72 + }
  73 +
  74 + public Collection<JSONObject> execs() {
  75 + return execMap.values();
  76 + }
  77 +}
... ...
src/main/java/com/bsth/server_rs/schedule/real/ScheduleRealService.java
... ... @@ -14,6 +14,8 @@ import com.bsth.server_rs.base_info.car.Car;
14 14 import com.bsth.server_rs.base_info.car.buffer.CarBufferData;
15 15 import com.bsth.server_rs.base_info.line.Line;
16 16 import com.bsth.server_rs.base_info.line.buffer.LineBufferData;
  17 +import com.bsth.server_rs.gps.buffer.GpsRealDataBuffer;
  18 +import com.bsth.server_rs.gps.entity.GpsEntity;
17 19 import com.bsth.server_rs.schedule.dto.ScheduleCcInfoConfig;
18 20 import com.bsth.server_rs.schedule.dto.ScheduleInOut;
19 21 import com.bsth.server_rs.schedule.dto.ScheduleRealInfoDTO_JK;
... ... @@ -326,11 +328,36 @@ public class ScheduleRealService implements InitializingBean {
326 328 @GET
327 329 @Path("/insideCodes/{rq}")
328 330 public List<String> insideCodes(@PathParam("rq") String rq) {
329   - List<String> codes = jdbcTemplate.queryForList("select DISTINCT cl_zbh from bsth_c_s_sp_info_real t where t.schedule_date_str = ? and status = 2", new Object[]{ rq }, String.class);
  331 + List<String> codes = jdbcTemplate.queryForList("select DISTINCT cl_zbh from bsth_c_s_sp_info_real t where t.schedule_date_str = ? and status = 2", new Object[]{rq}, String.class);
330 332  
331 333 return codes;
332 334 }
333 335  
  336 + /**
  337 + * 获取不在岗的班次信息
  338 + */
  339 + @GET
  340 + @Path("/notOnDuty")
  341 + public List<ScheduleRealInfo> notOnDuty() {
  342 + List<ScheduleRealInfo> result = new ArrayList<>();
  343 + Collection<ScheduleRealInfo> collection = schRealDataBuffer.getInOutData();
  344 + long now = System.currentTimeMillis();
  345 + for (ScheduleRealInfo sch : collection) {
  346 + if ("in".equals(sch.getBcType())) {
  347 + continue;
  348 + }
  349 + GpsEntity gpsEntity = GpsRealDataBuffer.get(CarBufferData.findOne(sch.getClZbh()).getEquipmentCode());
  350 + long schIntervalMillis = sch.getDfsjT() - now, gpsIntervalMillis = sch.getDfsjT() - (gpsEntity == null ? 0 : gpsEntity.getTimestamp());
  351 + boolean isSchMatch = schIntervalMillis > 0 && schIntervalMillis < 1200000, isGpsMatch = gpsIntervalMillis > 1200000;
  352 + // 当前时间往后20分钟内的出场班次 且相应车辆在待发时间20分钟内无GPS数据
  353 + if (isSchMatch && isGpsMatch) {
  354 + result.add(sch);
  355 + }
  356 + }
  357 +
  358 + return result;
  359 + }
  360 +
334 361 @Override
335 362 public void afterPropertiesSet() throws Exception {
336 363 Application.mainServices.scheduleWithFixedDelay(new Runnable() {
... ...
src/main/java/com/bsth/service/SystemParamService.java 0 → 100644
  1 +package com.bsth.service;
  2 +
  3 +public interface SystemParamService {
  4 +
  5 + void refresh();
  6 +
  7 + String getValue(String key);
  8 +}
... ...
src/main/java/com/bsth/service/impl/SystemParamServiceImpl.java 0 → 100644
  1 +package com.bsth.service.impl;
  2 +
  3 +import com.bsth.entity.SystemParam;
  4 +import com.bsth.repository.SystemParamRepository;
  5 +import com.bsth.service.SystemParamService;
  6 +import org.springframework.beans.factory.annotation.Autowired;
  7 +import org.springframework.scheduling.annotation.EnableScheduling;
  8 +import org.springframework.scheduling.annotation.Scheduled;
  9 +import org.springframework.stereotype.Service;
  10 +
  11 +import java.util.HashMap;
  12 +import java.util.Map;
  13 +
  14 +@Service
  15 +@EnableScheduling
  16 +public class SystemParamServiceImpl implements SystemParamService {
  17 +
  18 + @Autowired
  19 + private SystemParamRepository systemParamRepository;
  20 +
  21 + private Map<String, String> pairs = new HashMap<>();
  22 +
  23 + @Scheduled(cron = "0 0/30 * * * ?")
  24 + public void refresh() {
  25 + for (SystemParam sp : systemParamRepository.findAll()) {
  26 + pairs.put(sp.getKey(), sp.getValue());
  27 + }
  28 + }
  29 +
  30 + public String getValue(String key) {
  31 + return pairs.get(key);
  32 + }
  33 +}
... ...