Commit 247ee6cdb2c61ea225b29c8bb79b7fdebc149fd9
Merge branch 'lingang' of http://192.168.168.245:8888/panzhaov5/control_service_…
…data_Interface into lingang
Showing
14 changed files
with
1383 additions
and
942 deletions
Too many changes to show.
To preserve performance only 14 of 25 files are displayed.
src/main/java/com/bsth/entity/HInfo.java
0 → 100644
| 1 | +package com.bsth.entity; | ||
| 2 | + | ||
| 3 | + | ||
| 4 | +import org.springframework.format.annotation.DateTimeFormat; | ||
| 5 | + | ||
| 6 | +import javax.persistence.Entity; | ||
| 7 | +import javax.persistence.Id; | ||
| 8 | +import javax.persistence.Table; | ||
| 9 | +import java.io.Serializable; | ||
| 10 | +import java.util.Date; | ||
| 11 | + | ||
| 12 | +/** | ||
| 13 | + * 电量信息表 | ||
| 14 | + */ | ||
| 15 | +@Entity | ||
| 16 | +@Table(name = "bsth_c_qlb") | ||
| 17 | +public class HInfo implements Serializable { | ||
| 18 | + @Id | ||
| 19 | + private Integer id; | ||
| 20 | + /** | ||
| 21 | + * 日期 | ||
| 22 | + */ | ||
| 23 | + @DateTimeFormat(pattern = "yyyy-MM-dd") | ||
| 24 | + private Date rq; | ||
| 25 | + /** | ||
| 26 | + * 内部编码 | ||
| 27 | + */ | ||
| 28 | + private String nbbm; | ||
| 29 | + /** | ||
| 30 | + * 驾驶员 | ||
| 31 | + */ | ||
| 32 | + private String jsy; | ||
| 33 | + /** | ||
| 34 | + * 充氢量 | ||
| 35 | + */ | ||
| 36 | + private Double jql; | ||
| 37 | + /** | ||
| 38 | + * 耗氢 | ||
| 39 | + */ | ||
| 40 | + private Double hn; | ||
| 41 | + | ||
| 42 | + @Override | ||
| 43 | + public int hashCode() { | ||
| 44 | + return this.toString().hashCode(); | ||
| 45 | + } | ||
| 46 | + | ||
| 47 | + @Override | ||
| 48 | + public boolean equals(Object obj) { | ||
| 49 | + return this.toString().equals(((HInfo)obj).toString()); | ||
| 50 | + } | ||
| 51 | + | ||
| 52 | + @Override | ||
| 53 | + public String toString() { | ||
| 54 | + return "hydrogen_" + this.id; | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + public Integer getId() { | ||
| 58 | + return id; | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + public void setId(Integer id) { | ||
| 62 | + this.id = id; | ||
| 63 | + } | ||
| 64 | + | ||
| 65 | + public Date getRq() { | ||
| 66 | + return rq; | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + public void setRq(Date rq) { | ||
| 70 | + this.rq = rq; | ||
| 71 | + } | ||
| 72 | + | ||
| 73 | + public String getNbbm() { | ||
| 74 | + return nbbm; | ||
| 75 | + } | ||
| 76 | + | ||
| 77 | + public void setNbbm(String nbbm) { | ||
| 78 | + this.nbbm = nbbm; | ||
| 79 | + } | ||
| 80 | + | ||
| 81 | + public String getJsy() { | ||
| 82 | + return jsy; | ||
| 83 | + } | ||
| 84 | + | ||
| 85 | + public void setJsy(String jsy) { | ||
| 86 | + this.jsy = jsy; | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + public Double getJql() { | ||
| 90 | + return jql; | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + public void setJql(Double jql) { | ||
| 94 | + this.jql = jql; | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + public Double getHn() { | ||
| 98 | + return hn; | ||
| 99 | + } | ||
| 100 | + | ||
| 101 | + public void setHn(Double hn) { | ||
| 102 | + this.hn = hn; | ||
| 103 | + } | ||
| 104 | + | ||
| 105 | +} |
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/redis/HRedisService.java
0 → 100644
| 1 | +package com.bsth.redis; | ||
| 2 | + | ||
| 3 | +import com.bsth.Application; | ||
| 4 | +import com.bsth.entity.HInfo; | ||
| 5 | +import com.bsth.redis.util.RedisUtils; | ||
| 6 | +import com.bsth.repository.HInfoRepository; | ||
| 7 | +import com.bsth.util.ConfigUtil; | ||
| 8 | +import com.bsth.util.ConvertUtil; | ||
| 9 | +import com.google.common.collect.ArrayListMultimap; | ||
| 10 | +import org.joda.time.DateTime; | ||
| 11 | +import org.slf4j.Logger; | ||
| 12 | +import org.slf4j.LoggerFactory; | ||
| 13 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 14 | +import org.springframework.boot.CommandLineRunner; | ||
| 15 | +import org.springframework.core.annotation.Order; | ||
| 16 | +import org.springframework.data.redis.core.RedisTemplate; | ||
| 17 | +import org.springframework.data.redis.serializer.StringRedisSerializer; | ||
| 18 | +import org.springframework.stereotype.Component; | ||
| 19 | +import org.springframework.stereotype.Service; | ||
| 20 | + | ||
| 21 | +import java.util.*; | ||
| 22 | +import java.util.concurrent.TimeUnit; | ||
| 23 | + | ||
| 24 | +/** | ||
| 25 | + * 油量数据Redis缓存 | ||
| 26 | + * Created by panzhao on 2017/3/19. | ||
| 27 | + */ | ||
| 28 | +@Service | ||
| 29 | +@Order(3) | ||
| 30 | +public class HRedisService implements CommandLineRunner { | ||
| 31 | + | ||
| 32 | + @Autowired | ||
| 33 | + private RedisTemplate redisTemplate; | ||
| 34 | + | ||
| 35 | + @Autowired | ||
| 36 | + HInfoRepository hInfoRepository; | ||
| 37 | + | ||
| 38 | + @Autowired | ||
| 39 | + RedisUtils redisUtils; | ||
| 40 | + | ||
| 41 | + static Logger logger = LoggerFactory.getLogger(HRedisService.class); | ||
| 42 | + | ||
| 43 | + private final static String REDIS_KEY_PREFIX = "hydrogen:"; | ||
| 44 | + | ||
| 45 | + /** | ||
| 46 | + * 将油量数据写入redis | ||
| 47 | + * | ||
| 48 | + * @param list | ||
| 49 | + */ | ||
| 50 | + public void wirte(List<HInfo> list) { | ||
| 51 | + ArrayListMultimap<String, HInfo> multimap; | ||
| 52 | + try { | ||
| 53 | + if (list.size() == 0) | ||
| 54 | + return; | ||
| 55 | + //按日期和线路分组数据 | ||
| 56 | + Class clazz = HInfo.class; | ||
| 57 | + multimap = new ConvertUtil().groupMultiList(list, ":", clazz.getDeclaredField("nbbm"), clazz.getDeclaredField("rq")); | ||
| 58 | + | ||
| 59 | + //写入redis | ||
| 60 | + Iterator<String> iterator = multimap.keySet().iterator(); | ||
| 61 | + String key; | ||
| 62 | + while (iterator.hasNext()) { | ||
| 63 | + key = iterator.next(); | ||
| 64 | + mergeData(key, multimap.get(key)); | ||
| 65 | + } | ||
| 66 | + } catch (Exception e) { | ||
| 67 | + logger.error("", e); | ||
| 68 | + } | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + /** | ||
| 72 | + * 根据车辆和日期获取油耗数据,以 车辆_驾驶员 为key | ||
| 73 | + * | ||
| 74 | + * @param nbbmArray | ||
| 75 | + * @param rq | ||
| 76 | + * @return | ||
| 77 | + */ | ||
| 78 | + public ArrayListMultimap findByNbbmGroup(Iterable<String> nbbmArray, String rq) { | ||
| 79 | + ArrayListMultimap rs = ArrayListMultimap.create(); | ||
| 80 | + | ||
| 81 | + rq = rq.replaceAll("-", ""); | ||
| 82 | + try { | ||
| 83 | + List<HInfo> list = new ArrayList<>(); | ||
| 84 | + Set<String> nbbms = new HashSet<>(); | ||
| 85 | + for (String nbbm : nbbmArray) { | ||
| 86 | + nbbm = nbbm.split("_")[1]; | ||
| 87 | + if (!nbbms.contains(nbbm)) { | ||
| 88 | + nbbms.add(nbbm); | ||
| 89 | + list.addAll(read(nbbm, rq)); | ||
| 90 | + } | ||
| 91 | + } | ||
| 92 | + Class clazz = HInfo.class; | ||
| 93 | + rs = new ConvertUtil().groupMultiList(list, "_", clazz.getDeclaredField("nbbm"), clazz.getDeclaredField("jsy")); | ||
| 94 | + } catch (Exception e) { | ||
| 95 | + logger.error("", e); | ||
| 96 | + } | ||
| 97 | + return rs; | ||
| 98 | + } | ||
| 99 | + | ||
| 100 | + /** | ||
| 101 | + * 根据车辆和日期获取油耗数据,以 车辆 为key | ||
| 102 | + * | ||
| 103 | + * @param nbbmArray | ||
| 104 | + * @param rq | ||
| 105 | + * @return | ||
| 106 | + */ | ||
| 107 | + public ArrayListMultimap findByNbbmGroup1(Iterable<String> nbbmArray, String rq) { | ||
| 108 | + ArrayListMultimap rs = ArrayListMultimap.create(); | ||
| 109 | + | ||
| 110 | + rq = rq.replaceAll("-", ""); | ||
| 111 | + try { | ||
| 112 | + List<HInfo> list = new ArrayList<>(); | ||
| 113 | + Set<String> nbbms = new HashSet<>(); | ||
| 114 | + for (String nbbm : nbbmArray) { | ||
| 115 | + if (!nbbms.contains(nbbm)) { | ||
| 116 | + nbbms.add(nbbm); | ||
| 117 | + list.addAll(read(nbbm, rq)); | ||
| 118 | + } | ||
| 119 | + } | ||
| 120 | + Class clazz = HInfo.class; | ||
| 121 | + rs = new ConvertUtil().groupMultiList(list, "_", clazz.getDeclaredField("nbbm")); | ||
| 122 | + } catch (Exception e) { | ||
| 123 | + logger.error("", e); | ||
| 124 | + } | ||
| 125 | + return rs; | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | + public List<HInfo> read(String nbbm, String rq) { | ||
| 129 | + return redisTemplate.opsForList().range(REDIS_KEY_PREFIX + nbbm + ":" + rq, 0, -1); | ||
| 130 | + } | ||
| 131 | + | ||
| 132 | + /** | ||
| 133 | + * 将 list 与redis里的数据合并 | ||
| 134 | + * | ||
| 135 | + * @param key | ||
| 136 | + * @param list | ||
| 137 | + */ | ||
| 138 | + public void mergeData(String key, List<HInfo> list) { | ||
| 139 | + key = REDIS_KEY_PREFIX + key; | ||
| 140 | + | ||
| 141 | + //更新 直接覆盖更新 | ||
| 142 | + redisTemplate.execute(redisUtils.getUpdateCallback(key, list)); | ||
| 143 | + } | ||
| 144 | + | ||
| 145 | + @Autowired | ||
| 146 | + HRefreshThread hRefreshThread; | ||
| 147 | + | ||
| 148 | + @Override | ||
| 149 | + public void run(String... strings) throws Exception { | ||
| 150 | + Application.mainServices.schedule(new Runnable() { | ||
| 151 | + @Override | ||
| 152 | + public void run() { | ||
| 153 | + //启动加载油耗缓存 | ||
| 154 | + synchData(null); | ||
| 155 | + } | ||
| 156 | + }, 30, TimeUnit.SECONDS); | ||
| 157 | + | ||
| 158 | + | ||
| 159 | + //定时刷新油耗信息 | ||
| 160 | + Application.mainServices.scheduleWithFixedDelay(hRefreshThread, 60 * 40, 60 * 40, TimeUnit.SECONDS); | ||
| 161 | + } | ||
| 162 | + | ||
| 163 | + /** | ||
| 164 | + * 和数据库同步数据 | ||
| 165 | + */ | ||
| 166 | + public void synchData(Integer days) { | ||
| 167 | + int cacheDays = Integer.parseInt(ConfigUtil.get("cache.days")); | ||
| 168 | + if (null != days && days < cacheDays) | ||
| 169 | + cacheDays = days; | ||
| 170 | + //设置key 序列化器 | ||
| 171 | + redisTemplate.setKeySerializer(new StringRedisSerializer()); | ||
| 172 | + | ||
| 173 | + DateTime dt = new DateTime(); | ||
| 174 | + dt = dt.withHourOfDay(0).withMinuteOfHour(0).withSecondOfMinute(0).minusDays(cacheDays); | ||
| 175 | + List<HInfo> list = hInfoRepository.findByDateLT(dt.toDate()); | ||
| 176 | + //写入redis | ||
| 177 | + wirte(list); | ||
| 178 | + logger.info("刷新氢耗数据, days: " + cacheDays + " -size: " + list.size() + " -LT: " + dt.toString("yyyy-MM-dd")); | ||
| 179 | + } | ||
| 180 | + | ||
| 181 | + @Component | ||
| 182 | + public static class HRefreshThread extends Thread { | ||
| 183 | + | ||
| 184 | + @Autowired | ||
| 185 | + HRedisService hRedisService; | ||
| 186 | + | ||
| 187 | + @Override | ||
| 188 | + public void run() { | ||
| 189 | + try { | ||
| 190 | + hRedisService.synchData(5); | ||
| 191 | + } catch (Exception e) { | ||
| 192 | + logger.error("", e); | ||
| 193 | + } | ||
| 194 | + } | ||
| 195 | + } | ||
| 196 | +} |
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/HInfoRepository.java
0 → 100644
| 1 | +package com.bsth.repository; | ||
| 2 | + | ||
| 3 | +import com.bsth.entity.HInfo; | ||
| 4 | + | ||
| 5 | +import org.springframework.data.jpa.repository.Query; | ||
| 6 | +import org.springframework.data.repository.PagingAndSortingRepository; | ||
| 7 | +import org.springframework.stereotype.Repository; | ||
| 8 | + | ||
| 9 | +import java.util.Date; | ||
| 10 | +import java.util.List; | ||
| 11 | + | ||
| 12 | +@Repository | ||
| 13 | +public interface HInfoRepository extends PagingAndSortingRepository<HInfo, Long> { | ||
| 14 | + | ||
| 15 | + | ||
| 16 | + @Query("select h from HInfo h where h.rq>?1") | ||
| 17 | + List<HInfo> findByDateLT(Date rq); | ||
| 18 | +} |
src/main/java/com/bsth/server_rs/AuthorizeInterceptor_IN.java
| 1 | package com.bsth.server_rs; | 1 | package com.bsth.server_rs; |
| 2 | 2 | ||
| 3 | import com.bsth.common.SystemParamKeys; | 3 | import com.bsth.common.SystemParamKeys; |
| 4 | +import com.bsth.entity.PasswordUser; | ||
| 5 | +import com.bsth.entity.Resource; | ||
| 4 | import com.bsth.server_rs.exception.AesException; | 6 | import com.bsth.server_rs.exception.AesException; |
| 5 | import com.bsth.service.SystemParamService; | 7 | import com.bsth.service.SystemParamService; |
| 6 | import com.bsth.service.UserService; | 8 | import com.bsth.service.UserService; |
| @@ -18,6 +20,8 @@ import org.springframework.beans.factory.InitializingBean; | @@ -18,6 +20,8 @@ import org.springframework.beans.factory.InitializingBean; | ||
| 18 | import org.springframework.context.ApplicationContext; | 20 | import org.springframework.context.ApplicationContext; |
| 19 | import org.springframework.context.ApplicationContextAware; | 21 | import org.springframework.context.ApplicationContextAware; |
| 20 | import org.springframework.stereotype.Component; | 22 | import org.springframework.stereotype.Component; |
| 23 | +import org.springframework.util.AntPathMatcher; | ||
| 24 | +import org.springframework.util.PathMatcher; | ||
| 21 | 25 | ||
| 22 | import java.security.MessageDigest; | 26 | import java.security.MessageDigest; |
| 23 | import java.util.Arrays; | 27 | import java.util.Arrays; |
| @@ -45,6 +49,8 @@ public class AuthorizeInterceptor_IN extends AbstractPhaseInterceptor<Message> i | @@ -45,6 +49,8 @@ public class AuthorizeInterceptor_IN extends AbstractPhaseInterceptor<Message> i | ||
| 45 | 49 | ||
| 46 | static Logger logger = LoggerFactory.getLogger(AuthorizeInterceptor_IN.class); | 50 | static Logger logger = LoggerFactory.getLogger(AuthorizeInterceptor_IN.class); |
| 47 | 51 | ||
| 52 | + private static PathMatcher matcher = new AntPathMatcher(); | ||
| 53 | + | ||
| 48 | public AuthorizeInterceptor_IN() { | 54 | public AuthorizeInterceptor_IN() { |
| 49 | super(Phase.RECEIVE); | 55 | super(Phase.RECEIVE); |
| 50 | } | 56 | } |
| @@ -121,10 +127,17 @@ public class AuthorizeInterceptor_IN extends AbstractPhaseInterceptor<Message> i | @@ -121,10 +127,17 @@ public class AuthorizeInterceptor_IN extends AbstractPhaseInterceptor<Message> i | ||
| 121 | } | 127 | } |
| 122 | 128 | ||
| 123 | private static void validate(Map<String, String> map, Message message) { | 129 | private static void validate(Map<String, String> map, Message message) { |
| 124 | - String limitPasswords = systemParamService.getValue(SystemParamKeys.LIMIT_PASSWORDS); | ||
| 125 | - String limitUris = systemParamService.getValue(SystemParamKeys.LIMIT_URIS); | ||
| 126 | - if (limitPasswords != null && limitPasswords.indexOf(String.format("%s,", map.get(PASSWORD))) > -1) { | ||
| 127 | - if (limitUris != null && limitUris.indexOf(String.format("%s,", message.get(Message.REQUEST_URI))) == -1) { | 130 | + PasswordUser user = userService.get(map.get(PASSWORD)); |
| 131 | + if (user.getResources().size() > 0) { | ||
| 132 | + boolean isMatch = false; | ||
| 133 | + String uri = (String) message.get(Message.REQUEST_URI); | ||
| 134 | + for (Resource resource : user.getResources()) { | ||
| 135 | + if (matcher.match(resource.getUrl(), uri)) { | ||
| 136 | + isMatch = true; | ||
| 137 | + break; | ||
| 138 | + } | ||
| 139 | + } | ||
| 140 | + if (!isMatch) { | ||
| 128 | throw new AesException(AesException.INVALID_URI); | 141 | throw new AesException(AesException.INVALID_URI); |
| 129 | } | 142 | } |
| 130 | } | 143 | } |
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
| 1 | -package com.bsth.server_rs.base_info.section.buffer; | ||
| 2 | - | ||
| 3 | -import com.bsth.server_rs.base_info.section.entity.LD_Section; | ||
| 4 | -import com.bsth.server_rs.base_info.section.entity.LD_SectionRoute; | ||
| 5 | -import com.bsth.server_rs.base_info.section.entity.RoadSpeed; | ||
| 6 | -import org.slf4j.Logger; | ||
| 7 | -import org.slf4j.LoggerFactory; | ||
| 8 | -import org.springframework.beans.factory.annotation.Autowired; | ||
| 9 | -import org.springframework.jdbc.core.BeanPropertyRowMapper; | ||
| 10 | -import org.springframework.jdbc.core.JdbcTemplate; | ||
| 11 | -import org.springframework.stereotype.Component; | ||
| 12 | - | ||
| 13 | -import java.util.ArrayList; | ||
| 14 | -import java.util.HashMap; | ||
| 15 | -import java.util.List; | ||
| 16 | -import java.util.Map; | ||
| 17 | - | ||
| 18 | -/** | ||
| 19 | - * Created by panzhao on 2017/3/27. | ||
| 20 | - */ | ||
| 21 | -@Component | ||
| 22 | -public class LD_SectionRefreshThread extends Thread{ | ||
| 23 | - | ||
| 24 | - @Autowired | ||
| 25 | - JdbcTemplate jdbcTemplate; | ||
| 26 | - | ||
| 27 | - Logger logger = LoggerFactory.getLogger(this.getClass()); | ||
| 28 | - | ||
| 29 | - @Override | ||
| 30 | - public void run() { | ||
| 31 | - | ||
| 32 | - try { | ||
| 33 | - | ||
| 34 | - //路段信息 | ||
| 35 | - List<LD_Section> sectionList = jdbcTemplate.query("select section_code,section_name,section_type,ST_AsText(gsection_vector) as gsection_vector,ST_AsText(bsection_vector) as bsection_vector,croses_road,versions from bsth_c_section ", | ||
| 36 | - BeanPropertyRowMapper.newInstance(LD_Section.class)); | ||
| 37 | - | ||
| 38 | - if(sectionList == null || sectionList.size() == 0) | ||
| 39 | - return; | ||
| 40 | - | ||
| 41 | - LD_SectionBufferData.replaceAll(sectionList); | ||
| 42 | - | ||
| 43 | - //路段路由信息 | ||
| 44 | - List<LD_SectionRoute> routeList = jdbcTemplate.query("select line_code,section_code,directions,sectionroute_code,versions from bsth_c_sectionroute where destroy=0", | ||
| 45 | - BeanPropertyRowMapper.newInstance(LD_SectionRoute.class)); | ||
| 46 | - | ||
| 47 | - for(LD_SectionRoute sr : routeList){ | ||
| 48 | - sr.setSection(LD_SectionBufferData.findOne(sr.getSectionCode())); | ||
| 49 | - } | ||
| 50 | - | ||
| 51 | - LD_SectionBufferData.replaceRoutes(routeList); | ||
| 52 | - | ||
| 53 | - //查询路段限速信息 | ||
| 54 | - 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)); | ||
| 55 | - if(roadSpeedList.size() > 0) | ||
| 56 | - LD_SectionBufferData.putRoadSpeeds(roadSpeedList); | ||
| 57 | - | ||
| 58 | - //查询最新版本路段信息 | ||
| 59 | - 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)); | ||
| 60 | - Map<String, List<LD_SectionRoute>> name2sections = new HashMap<>(); | ||
| 61 | - List<LD_SectionRoute> routes = null; | ||
| 62 | - String lastedLineName = ""; | ||
| 63 | - for (LD_SectionRoute sr : sectionRoutes) { | ||
| 64 | - if ("".equals(lastedLineName) || !lastedLineName.equals(sr.getLineName())) { | ||
| 65 | - name2sections.put(lastedLineName, routes); | ||
| 66 | - lastedLineName = sr.getLineName(); | ||
| 67 | - routes = new ArrayList<>(); | ||
| 68 | - } | ||
| 69 | - sr.setSection(LD_SectionBufferData.findOne(sr.getSectionCode())); | ||
| 70 | - routes.add(sr); | ||
| 71 | - } | ||
| 72 | - LD_SectionBufferData.putLastedRoute(name2sections); | ||
| 73 | - }catch (Exception e){ | ||
| 74 | - logger.error("", e); | ||
| 75 | - } | ||
| 76 | - } | ||
| 77 | -} | 1 | +package com.bsth.server_rs.base_info.section.buffer; |
| 2 | + | ||
| 3 | +import com.bsth.server_rs.base_info.section.entity.LD_Section; | ||
| 4 | +import com.bsth.server_rs.base_info.section.entity.LD_SectionRoute; | ||
| 5 | +import com.bsth.server_rs.base_info.section.entity.RoadSpeed; | ||
| 6 | +import org.slf4j.Logger; | ||
| 7 | +import org.slf4j.LoggerFactory; | ||
| 8 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 9 | +import org.springframework.jdbc.core.BeanPropertyRowMapper; | ||
| 10 | +import org.springframework.jdbc.core.JdbcTemplate; | ||
| 11 | +import org.springframework.stereotype.Component; | ||
| 12 | + | ||
| 13 | +import java.util.ArrayList; | ||
| 14 | +import java.util.HashMap; | ||
| 15 | +import java.util.List; | ||
| 16 | +import java.util.Map; | ||
| 17 | + | ||
| 18 | +/** | ||
| 19 | + * Created by panzhao on 2017/3/27. | ||
| 20 | + */ | ||
| 21 | +@Component | ||
| 22 | +public class LD_SectionRefreshThread extends Thread{ | ||
| 23 | + | ||
| 24 | + @Autowired | ||
| 25 | + JdbcTemplate jdbcTemplate; | ||
| 26 | + | ||
| 27 | + Logger logger = LoggerFactory.getLogger(this.getClass()); | ||
| 28 | + | ||
| 29 | + @Override | ||
| 30 | + public void run() { | ||
| 31 | + | ||
| 32 | + try { | ||
| 33 | + | ||
| 34 | + //路段信息 | ||
| 35 | + List<LD_Section> sectionList = jdbcTemplate.query("select section_code,section_name,section_type,ST_AsText(gsection_vector) as gsection_vector,ST_AsText(bsection_vector) as bsection_vector,croses_road,versions from bsth_c_section ", | ||
| 36 | + BeanPropertyRowMapper.newInstance(LD_Section.class)); | ||
| 37 | + | ||
| 38 | + if(sectionList == null || sectionList.size() == 0) | ||
| 39 | + return; | ||
| 40 | + | ||
| 41 | + LD_SectionBufferData.replaceAll(sectionList); | ||
| 42 | + | ||
| 43 | + //路段路由信息 | ||
| 44 | + List<LD_SectionRoute> routeList = jdbcTemplate.query("select line_code,section_code,directions,sectionroute_code,versions from bsth_c_sectionroute where destroy=0", | ||
| 45 | + BeanPropertyRowMapper.newInstance(LD_SectionRoute.class)); | ||
| 46 | + | ||
| 47 | + for(LD_SectionRoute sr : routeList){ | ||
| 48 | + sr.setSection(LD_SectionBufferData.findOne(sr.getSectionCode())); | ||
| 49 | + } | ||
| 50 | + | ||
| 51 | + LD_SectionBufferData.replaceRoutes(routeList); | ||
| 52 | + | ||
| 53 | + //查询路段限速信息 | ||
| 54 | + //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)); | ||
| 55 | + //if(roadSpeedList.size() > 0) | ||
| 56 | + // LD_SectionBufferData.putRoadSpeeds(roadSpeedList); | ||
| 57 | + | ||
| 58 | + //查询最新版本路段信息 | ||
| 59 | + 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)); | ||
| 60 | + Map<String, List<LD_SectionRoute>> name2sections = new HashMap<>(); | ||
| 61 | + List<LD_SectionRoute> routes = null; | ||
| 62 | + String lastedLineName = ""; | ||
| 63 | + for (LD_SectionRoute sr : sectionRoutes) { | ||
| 64 | + if ("".equals(lastedLineName) || !lastedLineName.equals(sr.getLineName())) { | ||
| 65 | + name2sections.put(lastedLineName, routes); | ||
| 66 | + lastedLineName = sr.getLineName(); | ||
| 67 | + routes = new ArrayList<>(); | ||
| 68 | + } | ||
| 69 | + sr.setSection(LD_SectionBufferData.findOne(sr.getSectionCode())); | ||
| 70 | + routes.add(sr); | ||
| 71 | + } | ||
| 72 | + LD_SectionBufferData.putLastedRoute(name2sections); | ||
| 73 | + }catch (Exception e){ | ||
| 74 | + logger.error("", e); | ||
| 75 | + } | ||
| 76 | + } | ||
| 77 | +} |
src/main/java/com/bsth/server_rs/base_info/station/buffer/StationRefreshThread.java
| 1 | -package com.bsth.server_rs.base_info.station.buffer; | ||
| 2 | - | ||
| 3 | -import com.bsth.server_rs.base_info.station.entity.Station; | ||
| 4 | -import com.bsth.server_rs.base_info.station.entity.StationRotue; | ||
| 5 | -import org.slf4j.Logger; | ||
| 6 | -import org.slf4j.LoggerFactory; | ||
| 7 | -import org.springframework.beans.factory.annotation.Autowired; | ||
| 8 | -import org.springframework.jdbc.core.BeanPropertyRowMapper; | ||
| 9 | -import org.springframework.jdbc.core.JdbcTemplate; | ||
| 10 | -import org.springframework.stereotype.Component; | ||
| 11 | - | ||
| 12 | -import java.util.List; | ||
| 13 | - | ||
| 14 | -/** | ||
| 15 | - * Created by panzhao on 2017/3/27. | ||
| 16 | - */ | ||
| 17 | -@Component | ||
| 18 | -public class StationRefreshThread extends Thread{ | ||
| 19 | - | ||
| 20 | - @Autowired | ||
| 21 | - JdbcTemplate jdbcTemplate; | ||
| 22 | - | ||
| 23 | - Logger logger = LoggerFactory.getLogger(this.getClass()); | ||
| 24 | - | ||
| 25 | - @Override | ||
| 26 | - public void run() { | ||
| 27 | - | ||
| 28 | - try { | ||
| 29 | - //站点信息 | ||
| 30 | - List<Station> stationList = jdbcTemplate.query("SELECT station_cod AS station_code,station_name,g_lonx AS lon,g_laty AS lat,shapes_type,radius,ST_AsText(g_polygon_grid) AS polygon_grid,versions FROM bsth_c_station where destroy=0 ", | ||
| 31 | - BeanPropertyRowMapper.newInstance(Station.class)); | ||
| 32 | - | ||
| 33 | - if(stationList == null || stationList.size() == 0) | ||
| 34 | - return; | ||
| 35 | - StationBufferData.replaceAll(stationList); | ||
| 36 | - | ||
| 37 | - //站点路由信息 | ||
| 38 | - List<StationRotue> routeList = jdbcTemplate.query("select id, line, station_route_code, line_code,station_code,station_mark,distances, to_time,directions,station_name from bsth_c_stationroute where destroy=0", | ||
| 39 | - BeanPropertyRowMapper.newInstance(StationRotue.class)); | ||
| 40 | - | ||
| 41 | - for(StationRotue sr : routeList){ | ||
| 42 | - sr.setStation(StationBufferData.findOne(sr.getStationCode())); | ||
| 43 | - } | ||
| 44 | - StationBufferData.replaceRoutes(routeList); | ||
| 45 | - }catch (Exception e){ | ||
| 46 | - logger.error("", e); | ||
| 47 | - } | ||
| 48 | - } | ||
| 49 | -} | 1 | +package com.bsth.server_rs.base_info.station.buffer; |
| 2 | + | ||
| 3 | +import com.bsth.server_rs.base_info.station.entity.Station; | ||
| 4 | +import com.bsth.server_rs.base_info.station.entity.StationRotue; | ||
| 5 | +import org.slf4j.Logger; | ||
| 6 | +import org.slf4j.LoggerFactory; | ||
| 7 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 8 | +import org.springframework.jdbc.core.BeanPropertyRowMapper; | ||
| 9 | +import org.springframework.jdbc.core.JdbcTemplate; | ||
| 10 | +import org.springframework.stereotype.Component; | ||
| 11 | + | ||
| 12 | +import java.util.List; | ||
| 13 | + | ||
| 14 | +/** | ||
| 15 | + * Created by panzhao on 2017/3/27. | ||
| 16 | + */ | ||
| 17 | +@Component | ||
| 18 | +public class StationRefreshThread extends Thread{ | ||
| 19 | + | ||
| 20 | + @Autowired | ||
| 21 | + JdbcTemplate jdbcTemplate; | ||
| 22 | + | ||
| 23 | + Logger logger = LoggerFactory.getLogger(this.getClass()); | ||
| 24 | + | ||
| 25 | + @Override | ||
| 26 | + public void run() { | ||
| 27 | + | ||
| 28 | + try { | ||
| 29 | + //站点信息 | ||
| 30 | + List<Station> stationList = jdbcTemplate.query("SELECT station_code,station_name,ST_X(center_point_wgs) AS lon,ST_Y(center_point_wgs) AS lat,versions FROM bsth_c_station where destroy=0", | ||
| 31 | + BeanPropertyRowMapper.newInstance(Station.class)); | ||
| 32 | + | ||
| 33 | + if(stationList == null || stationList.size() == 0) | ||
| 34 | + return; | ||
| 35 | + StationBufferData.replaceAll(stationList); | ||
| 36 | + | ||
| 37 | + //站点路由信息 | ||
| 38 | + List<StationRotue> routeList = jdbcTemplate.query("select id, line, station_route_code, line_code,station_code,station_mark,distances, to_time,directions,station_name,shaped_type as shapes_type,radius,ST_AsText(buffer_polygon_wgs) AS polygon_grid from bsth_c_stationroute where destroy=0", | ||
| 39 | + BeanPropertyRowMapper.newInstance(StationRotue.class)); | ||
| 40 | + | ||
| 41 | + for(StationRotue sr : routeList){ | ||
| 42 | + sr.setStation(StationBufferData.findOne(sr.getStationCode())); | ||
| 43 | + } | ||
| 44 | + StationBufferData.replaceRoutes(routeList); | ||
| 45 | + }catch (Exception e){ | ||
| 46 | + logger.error("", e); | ||
| 47 | + } | ||
| 48 | + } | ||
| 49 | +} |
src/main/java/com/bsth/server_rs/base_info/station/entity/Station.java
| 1 | -package com.bsth.server_rs.base_info.station.entity; | ||
| 2 | - | ||
| 3 | -/** | ||
| 4 | - * 站点信息 | ||
| 5 | - * Created by panzhao on 2017/8/31. | ||
| 6 | - */ | ||
| 7 | -public class Station { | ||
| 8 | - | ||
| 9 | - /** 站点编码 */ | ||
| 10 | - private String stationCode; | ||
| 11 | - | ||
| 12 | - /** 站点名称 */ | ||
| 13 | - private String stationName; | ||
| 14 | - | ||
| 15 | - /** WGS 经度 */ | ||
| 16 | - private Float lon; | ||
| 17 | - | ||
| 18 | - /** WGS 纬度 */ | ||
| 19 | - private Float lat; | ||
| 20 | - | ||
| 21 | - /** | ||
| 22 | - * 电子围栏类型 | ||
| 23 | - * | ||
| 24 | - * ------ r:圆形 | ||
| 25 | - * | ||
| 26 | - * ------ d:多边形 | ||
| 27 | - */ | ||
| 28 | - private String shapesType; | ||
| 29 | - | ||
| 30 | - /** 圆形半径 */ | ||
| 31 | - private Integer radius; | ||
| 32 | - | ||
| 33 | - /** 多边形 WGS 坐标 */ | ||
| 34 | - private String polygonGrid; | ||
| 35 | - | ||
| 36 | - /** 版本号 */ | ||
| 37 | - private Integer versions; | ||
| 38 | - | ||
| 39 | - | ||
| 40 | - public String getStationName() { | ||
| 41 | - return stationName; | ||
| 42 | - } | ||
| 43 | - | ||
| 44 | - public void setStationName(String stationName) { | ||
| 45 | - this.stationName = stationName; | ||
| 46 | - } | ||
| 47 | - | ||
| 48 | - public String getShapesType() { | ||
| 49 | - return shapesType; | ||
| 50 | - } | ||
| 51 | - | ||
| 52 | - public void setShapesType(String shapesType) { | ||
| 53 | - this.shapesType = shapesType; | ||
| 54 | - } | ||
| 55 | - | ||
| 56 | - public Integer getRadius() { | ||
| 57 | - return radius; | ||
| 58 | - } | ||
| 59 | - | ||
| 60 | - public void setRadius(Integer radius) { | ||
| 61 | - this.radius = radius; | ||
| 62 | - } | ||
| 63 | - | ||
| 64 | - | ||
| 65 | - public Integer getVersions() { | ||
| 66 | - return versions; | ||
| 67 | - } | ||
| 68 | - | ||
| 69 | - public void setVersions(Integer versions) { | ||
| 70 | - this.versions = versions; | ||
| 71 | - } | ||
| 72 | - | ||
| 73 | - public String getStationCode() { | ||
| 74 | - return stationCode; | ||
| 75 | - } | ||
| 76 | - | ||
| 77 | - public void setStationCode(String stationCode) { | ||
| 78 | - this.stationCode = stationCode; | ||
| 79 | - } | ||
| 80 | - | ||
| 81 | - public Float getLon() { | ||
| 82 | - return lon; | ||
| 83 | - } | ||
| 84 | - | ||
| 85 | - public void setLon(Float lon) { | ||
| 86 | - this.lon = lon; | ||
| 87 | - } | ||
| 88 | - | ||
| 89 | - public Float getLat() { | ||
| 90 | - return lat; | ||
| 91 | - } | ||
| 92 | - | ||
| 93 | - public void setLat(Float lat) { | ||
| 94 | - this.lat = lat; | ||
| 95 | - } | ||
| 96 | - | ||
| 97 | - public String getPolygonGrid() { | ||
| 98 | - return polygonGrid; | ||
| 99 | - } | ||
| 100 | - | ||
| 101 | - public void setPolygonGrid(String polygonGrid) { | ||
| 102 | - this.polygonGrid = polygonGrid; | ||
| 103 | - } | ||
| 104 | -} | 1 | +package com.bsth.server_rs.base_info.station.entity; |
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * 站点信息 | ||
| 5 | + * Created by panzhao on 2017/8/31. | ||
| 6 | + */ | ||
| 7 | +public class Station { | ||
| 8 | + | ||
| 9 | + /** 站点编码 */ | ||
| 10 | + private String stationCode; | ||
| 11 | + | ||
| 12 | + /** 站点名称 */ | ||
| 13 | + private String stationName; | ||
| 14 | + | ||
| 15 | + /** WGS 经度 */ | ||
| 16 | + private Float lon; | ||
| 17 | + | ||
| 18 | + /** WGS 纬度 */ | ||
| 19 | + private Float lat; | ||
| 20 | + | ||
| 21 | + /** 版本号 */ | ||
| 22 | + private Integer versions; | ||
| 23 | + | ||
| 24 | + | ||
| 25 | + public String getStationName() { | ||
| 26 | + return stationName; | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + public void setStationName(String stationName) { | ||
| 30 | + this.stationName = stationName; | ||
| 31 | + } | ||
| 32 | + | ||
| 33 | + public Integer getVersions() { | ||
| 34 | + return versions; | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + public void setVersions(Integer versions) { | ||
| 38 | + this.versions = versions; | ||
| 39 | + } | ||
| 40 | + | ||
| 41 | + public String getStationCode() { | ||
| 42 | + return stationCode; | ||
| 43 | + } | ||
| 44 | + | ||
| 45 | + public void setStationCode(String stationCode) { | ||
| 46 | + this.stationCode = stationCode; | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + public Float getLon() { | ||
| 50 | + return lon; | ||
| 51 | + } | ||
| 52 | + | ||
| 53 | + public void setLon(Float lon) { | ||
| 54 | + this.lon = lon; | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + public Float getLat() { | ||
| 58 | + return lat; | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + public void setLat(Float lat) { | ||
| 62 | + this.lat = lat; | ||
| 63 | + } | ||
| 64 | +} |
src/main/java/com/bsth/server_rs/base_info/station/entity/StationRotue.java
| 1 | -package com.bsth.server_rs.base_info.station.entity; | ||
| 2 | - | ||
| 3 | -/** | ||
| 4 | - * Created by panzhao on 2017/8/31. | ||
| 5 | - */ | ||
| 6 | -public class StationRotue { | ||
| 7 | - | ||
| 8 | - /** 线路编码 */ | ||
| 9 | - private String lineCode; | ||
| 10 | - | ||
| 11 | - /** 站点路由序号 */ | ||
| 12 | - private Integer stationRouteCode; | ||
| 13 | - | ||
| 14 | - private String stationCode; | ||
| 15 | - | ||
| 16 | - private String stationName; | ||
| 17 | - | ||
| 18 | - private Station station; | ||
| 19 | - | ||
| 20 | - /** | ||
| 21 | - * 站点类型 | ||
| 22 | - * ------ B:起点站 | ||
| 23 | - * ------ Z:中途站 | ||
| 24 | - * ------ E:终点站 | ||
| 25 | - * ------ T:停车场 | ||
| 26 | - */ | ||
| 27 | - private String stationMark; | ||
| 28 | - | ||
| 29 | - /** 站点路由到站距离 */ | ||
| 30 | - private Double distances; | ||
| 31 | - | ||
| 32 | - /** 站点路由到站时间 */ | ||
| 33 | - private Double toTime; | ||
| 34 | - | ||
| 35 | - /** 首班时间 */ | ||
| 36 | - private String firstTime; | ||
| 37 | - | ||
| 38 | - /** 末班时间 */ | ||
| 39 | - private String endTime; | ||
| 40 | - | ||
| 41 | - /** 站点路由方向 */ | ||
| 42 | - private Integer directions; | ||
| 43 | - | ||
| 44 | - /** 版本号 */ | ||
| 45 | - private Integer versions; | ||
| 46 | - | ||
| 47 | - public String getLineCode() { | ||
| 48 | - return lineCode; | ||
| 49 | - } | ||
| 50 | - | ||
| 51 | - public void setLineCode(String lineCode) { | ||
| 52 | - this.lineCode = lineCode; | ||
| 53 | - } | ||
| 54 | - | ||
| 55 | - public Integer getStationRouteCode() { | ||
| 56 | - return stationRouteCode; | ||
| 57 | - } | ||
| 58 | - | ||
| 59 | - public void setStationRouteCode(Integer stationRouteCode) { | ||
| 60 | - this.stationRouteCode = stationRouteCode; | ||
| 61 | - } | ||
| 62 | - | ||
| 63 | - public Station getStation() { | ||
| 64 | - return station; | ||
| 65 | - } | ||
| 66 | - | ||
| 67 | - public void setStation(Station station) { | ||
| 68 | - this.station = station; | ||
| 69 | - } | ||
| 70 | - | ||
| 71 | - public String getStationMark() { | ||
| 72 | - return stationMark; | ||
| 73 | - } | ||
| 74 | - | ||
| 75 | - public void setStationMark(String stationMark) { | ||
| 76 | - this.stationMark = stationMark; | ||
| 77 | - } | ||
| 78 | - | ||
| 79 | - public Double getDistances() { | ||
| 80 | - return distances; | ||
| 81 | - } | ||
| 82 | - | ||
| 83 | - public void setDistances(Double distances) { | ||
| 84 | - this.distances = distances; | ||
| 85 | - } | ||
| 86 | - | ||
| 87 | - public Double getToTime() { | ||
| 88 | - return toTime; | ||
| 89 | - } | ||
| 90 | - | ||
| 91 | - public void setToTime(Double toTime) { | ||
| 92 | - this.toTime = toTime; | ||
| 93 | - } | ||
| 94 | - | ||
| 95 | - public String getFirstTime() { | ||
| 96 | - return firstTime; | ||
| 97 | - } | ||
| 98 | - | ||
| 99 | - public void setFirstTime(String firstTime) { | ||
| 100 | - this.firstTime = firstTime; | ||
| 101 | - } | ||
| 102 | - | ||
| 103 | - public String getEndTime() { | ||
| 104 | - return endTime; | ||
| 105 | - } | ||
| 106 | - | ||
| 107 | - public void setEndTime(String endTime) { | ||
| 108 | - this.endTime = endTime; | ||
| 109 | - } | ||
| 110 | - | ||
| 111 | - public Integer getDirections() { | ||
| 112 | - return directions; | ||
| 113 | - } | ||
| 114 | - | ||
| 115 | - public void setDirections(Integer directions) { | ||
| 116 | - this.directions = directions; | ||
| 117 | - } | ||
| 118 | - | ||
| 119 | - public Integer getVersions() { | ||
| 120 | - return versions; | ||
| 121 | - } | ||
| 122 | - | ||
| 123 | - public void setVersions(Integer versions) { | ||
| 124 | - this.versions = versions; | ||
| 125 | - } | ||
| 126 | - | ||
| 127 | - public String getStationCode() { | ||
| 128 | - return stationCode; | ||
| 129 | - } | ||
| 130 | - | ||
| 131 | - public void setStationCode(String stationCode) { | ||
| 132 | - this.stationCode = stationCode; | ||
| 133 | - } | ||
| 134 | - | ||
| 135 | - public String getStationName() { | ||
| 136 | - return stationName; | ||
| 137 | - } | ||
| 138 | - | ||
| 139 | - public void setStationName(String stationName) { | ||
| 140 | - this.stationName = stationName; | ||
| 141 | - } | ||
| 142 | -} | 1 | +package com.bsth.server_rs.base_info.station.entity; |
| 2 | + | ||
| 3 | +/** | ||
| 4 | + * Created by panzhao on 2017/8/31. | ||
| 5 | + */ | ||
| 6 | +public class StationRotue { | ||
| 7 | + | ||
| 8 | + /** 线路编码 */ | ||
| 9 | + private String lineCode; | ||
| 10 | + | ||
| 11 | + /** 站点路由序号 */ | ||
| 12 | + private Integer stationRouteCode; | ||
| 13 | + | ||
| 14 | + private String stationCode; | ||
| 15 | + | ||
| 16 | + private String stationName; | ||
| 17 | + | ||
| 18 | + private Station station; | ||
| 19 | + | ||
| 20 | + /** | ||
| 21 | + * 站点类型 | ||
| 22 | + * ------ B:起点站 | ||
| 23 | + * ------ Z:中途站 | ||
| 24 | + * ------ E:终点站 | ||
| 25 | + * ------ T:停车场 | ||
| 26 | + */ | ||
| 27 | + private String stationMark; | ||
| 28 | + | ||
| 29 | + /** 站点路由到站距离 */ | ||
| 30 | + private Double distances; | ||
| 31 | + | ||
| 32 | + /** 站点路由到站时间 */ | ||
| 33 | + private Double toTime; | ||
| 34 | + | ||
| 35 | + /** 首班时间 */ | ||
| 36 | + private String firstTime; | ||
| 37 | + | ||
| 38 | + /** 末班时间 */ | ||
| 39 | + private String endTime; | ||
| 40 | + | ||
| 41 | + /** 站点路由方向 */ | ||
| 42 | + private Integer directions; | ||
| 43 | + | ||
| 44 | + /** 版本号 */ | ||
| 45 | + private Integer versions; | ||
| 46 | + | ||
| 47 | + /** | ||
| 48 | + * 电子围栏类型 | ||
| 49 | + * | ||
| 50 | + * ------ r:圆形 | ||
| 51 | + * | ||
| 52 | + * ------ d:多边形 | ||
| 53 | + */ | ||
| 54 | + private String shapesType; | ||
| 55 | + | ||
| 56 | + /** 圆形半径 */ | ||
| 57 | + private Integer radius; | ||
| 58 | + | ||
| 59 | + /** 多边形 WGS 坐标 */ | ||
| 60 | + private String polygonGrid; | ||
| 61 | + | ||
| 62 | + public String getLineCode() { | ||
| 63 | + return lineCode; | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + public void setLineCode(String lineCode) { | ||
| 67 | + this.lineCode = lineCode; | ||
| 68 | + } | ||
| 69 | + | ||
| 70 | + public Integer getStationRouteCode() { | ||
| 71 | + return stationRouteCode; | ||
| 72 | + } | ||
| 73 | + | ||
| 74 | + public void setStationRouteCode(Integer stationRouteCode) { | ||
| 75 | + this.stationRouteCode = stationRouteCode; | ||
| 76 | + } | ||
| 77 | + | ||
| 78 | + public Station getStation() { | ||
| 79 | + return station; | ||
| 80 | + } | ||
| 81 | + | ||
| 82 | + public void setStation(Station station) { | ||
| 83 | + this.station = station; | ||
| 84 | + } | ||
| 85 | + | ||
| 86 | + public String getStationMark() { | ||
| 87 | + return stationMark; | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + public void setStationMark(String stationMark) { | ||
| 91 | + this.stationMark = stationMark; | ||
| 92 | + } | ||
| 93 | + | ||
| 94 | + public Double getDistances() { | ||
| 95 | + return distances; | ||
| 96 | + } | ||
| 97 | + | ||
| 98 | + public void setDistances(Double distances) { | ||
| 99 | + this.distances = distances; | ||
| 100 | + } | ||
| 101 | + | ||
| 102 | + public Double getToTime() { | ||
| 103 | + return toTime; | ||
| 104 | + } | ||
| 105 | + | ||
| 106 | + public void setToTime(Double toTime) { | ||
| 107 | + this.toTime = toTime; | ||
| 108 | + } | ||
| 109 | + | ||
| 110 | + public String getFirstTime() { | ||
| 111 | + return firstTime; | ||
| 112 | + } | ||
| 113 | + | ||
| 114 | + public void setFirstTime(String firstTime) { | ||
| 115 | + this.firstTime = firstTime; | ||
| 116 | + } | ||
| 117 | + | ||
| 118 | + public String getEndTime() { | ||
| 119 | + return endTime; | ||
| 120 | + } | ||
| 121 | + | ||
| 122 | + public void setEndTime(String endTime) { | ||
| 123 | + this.endTime = endTime; | ||
| 124 | + } | ||
| 125 | + | ||
| 126 | + public Integer getDirections() { | ||
| 127 | + return directions; | ||
| 128 | + } | ||
| 129 | + | ||
| 130 | + public void setDirections(Integer directions) { | ||
| 131 | + this.directions = directions; | ||
| 132 | + } | ||
| 133 | + | ||
| 134 | + public Integer getVersions() { | ||
| 135 | + return versions; | ||
| 136 | + } | ||
| 137 | + | ||
| 138 | + public void setVersions(Integer versions) { | ||
| 139 | + this.versions = versions; | ||
| 140 | + } | ||
| 141 | + | ||
| 142 | + public String getStationCode() { | ||
| 143 | + return stationCode; | ||
| 144 | + } | ||
| 145 | + | ||
| 146 | + public void setStationCode(String stationCode) { | ||
| 147 | + this.stationCode = stationCode; | ||
| 148 | + } | ||
| 149 | + | ||
| 150 | + public String getStationName() { | ||
| 151 | + return stationName; | ||
| 152 | + } | ||
| 153 | + | ||
| 154 | + public void setStationName(String stationName) { | ||
| 155 | + this.stationName = stationName; | ||
| 156 | + } | ||
| 157 | + | ||
| 158 | + public String getShapesType() { | ||
| 159 | + return shapesType; | ||
| 160 | + } | ||
| 161 | + | ||
| 162 | + public void setShapesType(String shapesType) { | ||
| 163 | + this.shapesType = shapesType; | ||
| 164 | + } | ||
| 165 | + | ||
| 166 | + public Integer getRadius() { | ||
| 167 | + return radius; | ||
| 168 | + } | ||
| 169 | + | ||
| 170 | + public void setRadius(Integer radius) { | ||
| 171 | + this.radius = radius; | ||
| 172 | + } | ||
| 173 | + | ||
| 174 | + public String getPolygonGrid() { | ||
| 175 | + return polygonGrid; | ||
| 176 | + } | ||
| 177 | + | ||
| 178 | + public void setPolygonGrid(String polygonGrid) { | ||
| 179 | + this.polygonGrid = polygonGrid; | ||
| 180 | + } | ||
| 181 | +} |
src/main/java/com/bsth/server_rs/electric/ElectricService.java
| 1 | package com.bsth.server_rs.electric; | 1 | package com.bsth.server_rs.electric; |
| 2 | 2 | ||
| 3 | +import com.alibaba.fastjson.JSONObject; | ||
| 3 | import com.bsth.server_ws.electric_oil.entity.Electric; | 4 | import com.bsth.server_ws.electric_oil.entity.Electric; |
| 4 | import org.slf4j.Logger; | 5 | import org.slf4j.Logger; |
| 5 | import org.slf4j.LoggerFactory; | 6 | import org.slf4j.LoggerFactory; |
| @@ -8,12 +9,19 @@ import org.springframework.jdbc.core.BeanPropertyRowMapper; | @@ -8,12 +9,19 @@ import org.springframework.jdbc.core.BeanPropertyRowMapper; | ||
| 8 | import org.springframework.jdbc.core.JdbcTemplate; | 9 | import org.springframework.jdbc.core.JdbcTemplate; |
| 9 | import org.springframework.stereotype.Component; | 10 | import org.springframework.stereotype.Component; |
| 10 | 11 | ||
| 12 | +import javax.servlet.http.HttpServletRequest; | ||
| 13 | +import javax.servlet.http.HttpServletResponse; | ||
| 11 | import javax.ws.rs.GET; | 14 | import javax.ws.rs.GET; |
| 15 | +import javax.ws.rs.POST; | ||
| 12 | import javax.ws.rs.Path; | 16 | import javax.ws.rs.Path; |
| 13 | import javax.ws.rs.PathParam; | 17 | import javax.ws.rs.PathParam; |
| 14 | import javax.ws.rs.Produces; | 18 | import javax.ws.rs.Produces; |
| 15 | import javax.ws.rs.core.MediaType; | 19 | import javax.ws.rs.core.MediaType; |
| 20 | + | ||
| 21 | +import java.io.BufferedReader; | ||
| 22 | +import java.io.InputStreamReader; | ||
| 16 | import java.util.List; | 23 | import java.util.List; |
| 24 | +import java.util.Map; | ||
| 17 | 25 | ||
| 18 | /** | 26 | /** |
| 19 | * Created by panzhao on 2018/3/27. | 27 | * Created by panzhao on 2018/3/27. |
| @@ -36,11 +44,36 @@ public class ElectricService { | @@ -36,11 +44,36 @@ public class ElectricService { | ||
| 36 | //从数据库查询 | 44 | //从数据库查询 |
| 37 | //list = jdbcTemplate.query("select fgs_bm,fgs_name,gs_bm,gs_name,jdl,jdz,remarks,rq,creater_date,nbbm,jsy from bsth_c_jdl where gs_bm="+company+" and rq='"+rq+"'" | 45 | //list = jdbcTemplate.query("select fgs_bm,fgs_name,gs_bm,gs_name,jdl,jdz,remarks,rq,creater_date,nbbm,jsy from bsth_c_jdl where gs_bm="+company+" and rq='"+rq+"'" |
| 38 | // , BeanPropertyRowMapper.newInstance(Electric.class)); | 46 | // , BeanPropertyRowMapper.newInstance(Electric.class)); |
| 39 | - list = jdbcTemplate.query("select fgsdm as fgs_bm,c.business_name as fgs_name,ssgsdm as gs_bm,b.business_name as gs_name,cdl as jdl,'' as jdz,'' as remarks,rq,createtime as create_date,nbbm,'' as jsy from (select fgsdm,ssgsdm,sum(cdl * 1000) / 1000 as cdl,rq,max(createtime) as createtime,nbbm from bsth_c_dlb where rq = '" + rq + "' GROUP BY fgsdm,ssgsdm,rq,nbbm) a left join bsth_c_business b on a.ssgsdm = b.business_code LEFT JOIN bsth_c_business c on concat(a.ssgsdm, '_', a.fgsdm) = concat(c.up_code, '_', c.business_code) where ssgsdm="+company | ||
| 40 | - , BeanPropertyRowMapper.newInstance(Electric.class)); | 47 | + list = jdbcTemplate.query("select fgsdm as fgs_bm,c.business_name as fgs_name,ssgsdm as gs_bm,b.business_name as gs_name,cdl as jdl,'' as jdz,'' as remarks,rq,createtime as create_date,nbbm,'' as jsy from (select fgsdm,ssgsdm,sum(cdl * 1000) / 1000 as cdl,rq,max(createtime) as createtime,nbbm from bsth_c_dlb where rq = ? GROUP BY fgsdm,ssgsdm,rq,nbbm) a left join bsth_c_business b on a.ssgsdm = b.business_code LEFT JOIN bsth_c_business c on concat(a.ssgsdm, '_', a.fgsdm) = concat(c.up_code, '_', c.business_code) where ssgsdm = ?" |
| 48 | + , new Object[]{ rq, company }, BeanPropertyRowMapper.newInstance(Electric.class)); | ||
| 41 | }catch (Exception e){ | 49 | }catch (Exception e){ |
| 42 | logger.error("", e); | 50 | logger.error("", e); |
| 43 | } | 51 | } |
| 44 | return list; | 52 | return list; |
| 45 | } | 53 | } |
| 54 | + | ||
| 55 | + @POST | ||
| 56 | + @Path("/charge") | ||
| 57 | + public void charge(HttpServletRequest request, HttpServletResponse response){ | ||
| 58 | + try { | ||
| 59 | + request.setCharacterEncoding("UTF-8"); | ||
| 60 | + response.setContentType("application/json; charset=UTF-8"); | ||
| 61 | + // 读取请求体 | ||
| 62 | + StringBuilder sb = new StringBuilder(); | ||
| 63 | + String line; | ||
| 64 | + BufferedReader reader = new BufferedReader(new InputStreamReader(request.getInputStream())); | ||
| 65 | + while ((line = reader.readLine()) != null) { | ||
| 66 | + sb.append(line); | ||
| 67 | + } | ||
| 68 | + reader.close(); | ||
| 69 | + // 处理消息主体 | ||
| 70 | + String messageBody = sb.toString(); | ||
| 71 | + JSONObject body = JSONObject.parseObject(messageBody); | ||
| 72 | +// JSONObject data = body.getJSONObject("Data"); | ||
| 73 | + | ||
| 74 | + }catch (Exception e){ | ||
| 75 | + logger.error("", e); | ||
| 76 | + } | ||
| 77 | + } | ||
| 78 | + | ||
| 46 | } | 79 | } |
src/main/java/com/bsth/server_ws/park_station/CompanyServiceSoap.java
| 1 | -package com.bsth.server_ws.park_station; | ||
| 2 | - | ||
| 3 | -import com.bsth.entity.OilInfo; | ||
| 4 | -import com.bsth.entity.SchedulePlanInfo; | ||
| 5 | -import com.bsth.entity.ScheduleRealInfo; | ||
| 6 | -import com.bsth.server_ws.util.Constants; | ||
| 7 | -import com.bsth.server_ws.util.ControlHttpUtils; | ||
| 8 | -import com.bsth.server_ws.util.WSDataConver; | ||
| 9 | -import org.slf4j.Logger; | ||
| 10 | -import org.slf4j.LoggerFactory; | ||
| 11 | -import org.springframework.beans.factory.annotation.Autowired; | ||
| 12 | -import org.springframework.jdbc.core.BeanPropertyRowMapper; | ||
| 13 | -import org.springframework.jdbc.core.JdbcTemplate; | ||
| 14 | -import org.springframework.stereotype.Component; | ||
| 15 | - | ||
| 16 | -import javax.jws.WebMethod; | ||
| 17 | -import javax.jws.WebService; | ||
| 18 | -import javax.xml.ws.Holder; | ||
| 19 | -import java.util.List; | ||
| 20 | - | ||
| 21 | -/** | ||
| 22 | - * 场站数据接口 | ||
| 23 | - * BS调度系统webservice接口实现,完美兼容老系统接口格式 | ||
| 24 | - * Created by panzhao on 2017/3/10. | ||
| 25 | - */ | ||
| 26 | -@Component | ||
| 27 | -@WebService( | ||
| 28 | - name = "CompanyServiceSoap", | ||
| 29 | - portName = "CompanyServiceSoap", | ||
| 30 | - serviceName = "CompanyService", | ||
| 31 | - targetNamespace = "http://control.bsth.com/", | ||
| 32 | - endpointInterface = "com.bsth.server_ws.park_station.CompanyService") | ||
| 33 | -public class CompanyServiceSoap implements CompanyService { | ||
| 34 | - | ||
| 35 | - | ||
| 36 | - Logger logger = LoggerFactory.getLogger(this.getClass()); | ||
| 37 | - | ||
| 38 | - @Autowired | ||
| 39 | - JdbcTemplate jdbcTemplate; | ||
| 40 | - | ||
| 41 | - @Override | ||
| 42 | - @WebMethod | ||
| 43 | - public boolean returnCCInfo(String password, String companyId, String rq, javax.xml.ws.Holder<String[]> result, javax.xml.ws.Holder<String> fError) { | ||
| 44 | - if(!password.equals(Constants.OLD_SYS_PASSWORD)){ | ||
| 45 | - fError.value = "密码有误!"; | ||
| 46 | - return false; | ||
| 47 | - } | ||
| 48 | - | ||
| 49 | - List<ScheduleRealInfo> list = null; | ||
| 50 | - try{ | ||
| 51 | - //从调度系统获取数据 | ||
| 52 | - list = ControlHttpUtils.returnJCCInfo(companyId, "out"); | ||
| 53 | - }catch (Exception e){ | ||
| 54 | - //访问调度系统异常,尝试从数据库获取 | ||
| 55 | - | ||
| 56 | - } | ||
| 57 | - result.value = WSDataConver.to_returnJCCInfo(list); | ||
| 58 | - | ||
| 59 | - //不再代理老接口数据 | ||
| 60 | - /*if(!WebServiceProxy.isAllNew(companyId)){ | ||
| 61 | - String[] oldArray = OldWSClient.returnCCInfo(companyId, rq); | ||
| 62 | - //合并新老系统的数据 | ||
| 63 | - result.value = WebServiceProxy.mergerJccData(result.value, oldArray, companyId); | ||
| 64 | - }*/ | ||
| 65 | - return true; | ||
| 66 | - } | ||
| 67 | - | ||
| 68 | - @Override | ||
| 69 | - @WebMethod | ||
| 70 | - public boolean returnJCInfo(String password, String companyId, String rq, Holder<String[]> result, Holder<String> fError) { | ||
| 71 | - if(!password.equals(Constants.OLD_SYS_PASSWORD)){ | ||
| 72 | - fError.value = "密码有误!"; | ||
| 73 | - return false; | ||
| 74 | - } | ||
| 75 | - | ||
| 76 | - List<ScheduleRealInfo> list = null; | ||
| 77 | - try{ | ||
| 78 | - //从调度系统获取数据 | ||
| 79 | - list = ControlHttpUtils.returnJCCInfo(companyId, "in"); | ||
| 80 | - }catch (Exception e){ | ||
| 81 | - //访问调度系统异常,尝试从数据库获取 | ||
| 82 | - | ||
| 83 | - } | ||
| 84 | - result.value = WSDataConver.to_returnJCCInfo(list); | ||
| 85 | - | ||
| 86 | - //不再代理老接口数据 | ||
| 87 | - /*if(!WebServiceProxy.isAllNew(companyId)){ | ||
| 88 | - String[] oldArray = OldWSClient.returnJCInfo(companyId, rq); | ||
| 89 | - //合并新老系统的数据 | ||
| 90 | - result.value = WebServiceProxy.mergerJccData(result.value, oldArray, companyId); | ||
| 91 | - }*/ | ||
| 92 | - | ||
| 93 | - return true; | ||
| 94 | - } | ||
| 95 | - | ||
| 96 | - @Override | ||
| 97 | - @WebMethod | ||
| 98 | - public boolean getCurrentDayPlan(String ip, String userName, String password, String workId, String company, Holder<String[]> result, Holder<String> fError) { | ||
| 99 | - try{ | ||
| 100 | - logger.info("getCurrentDayPlan workId: " + workId); | ||
| 101 | - List<ScheduleRealInfo> list = null; | ||
| 102 | - try{ | ||
| 103 | - //从调度系统获取数据 | ||
| 104 | - list = ControlHttpUtils.getCurrentDayPlan(company, workId); | ||
| 105 | - logger.info("从调度系统获取到数据 size: " + list.size()); | ||
| 106 | - }catch (Exception e){ | ||
| 107 | - //访问调度系统异常,尝试从数据库获取 | ||
| 108 | - logger.error("", e); | ||
| 109 | - } | ||
| 110 | - result.value = WSDataConver.to_getCurrentDayPlan(list); | ||
| 111 | - }catch(Exception e){ | ||
| 112 | - fError.value = e.getMessage(); | ||
| 113 | - logger.error("", e); | ||
| 114 | - } | ||
| 115 | - return false; | ||
| 116 | - } | ||
| 117 | - | ||
| 118 | - @Override | ||
| 119 | - public boolean getLSLC_PB(String ip, String userName, String password, String month, String workId, String company, Holder<String[]> result, Holder<String> fError) { | ||
| 120 | - try{ | ||
| 121 | - //实际排班 | ||
| 122 | - List<ScheduleRealInfo> schList = | ||
| 123 | - jdbcTemplate.query("select * from bsth_c_s_sp_info_real where gs_bm='"+company+"' and j_gh='"+workId+"' and schedule_date_str like '"+month+"-%'", | ||
| 124 | - BeanPropertyRowMapper.newInstance(ScheduleRealInfo.class)); | ||
| 125 | - | ||
| 126 | - //计划排班 | ||
| 127 | - List<SchedulePlanInfo> planList = | ||
| 128 | - jdbcTemplate.query("select * from bsth_c_s_sp_info where gs_bm='"+company+"' and j_gh='"+workId+"' and schedule_date>sysdate() and schedule_date like '"+month+"-%' order by bcs", | ||
| 129 | - BeanPropertyRowMapper.newInstance(SchedulePlanInfo.class)); | ||
| 130 | - | ||
| 131 | - //油耗 | ||
| 132 | - List<OilInfo> oilList = | ||
| 133 | - jdbcTemplate.query("select * from bsth_c_ylb where jsy='"+workId+"' and rq like '"+month+"-%'", | ||
| 134 | - BeanPropertyRowMapper.newInstance(OilInfo.class)); | ||
| 135 | - | ||
| 136 | - result.value = WSDataConver.to_getLSLC_PB(month, schList, oilList, planList); | ||
| 137 | - }catch(Exception e){ | ||
| 138 | - fError.value = e.getMessage(); | ||
| 139 | - logger.error("", e); | ||
| 140 | - } | ||
| 141 | - return false; | ||
| 142 | - } | ||
| 143 | -} | 1 | +package com.bsth.server_ws.park_station; |
| 2 | + | ||
| 3 | +import com.bsth.entity.OilInfo; | ||
| 4 | +import com.bsth.entity.SchedulePlanInfo; | ||
| 5 | +import com.bsth.entity.ScheduleRealInfo; | ||
| 6 | +import com.bsth.server_ws.util.Constants; | ||
| 7 | +import com.bsth.server_ws.util.ControlHttpUtils; | ||
| 8 | +import com.bsth.server_ws.util.WSDataConver; | ||
| 9 | +import org.slf4j.Logger; | ||
| 10 | +import org.slf4j.LoggerFactory; | ||
| 11 | +import org.springframework.beans.factory.annotation.Autowired; | ||
| 12 | +import org.springframework.jdbc.core.BeanPropertyRowMapper; | ||
| 13 | +import org.springframework.jdbc.core.JdbcTemplate; | ||
| 14 | +import org.springframework.stereotype.Component; | ||
| 15 | + | ||
| 16 | +import javax.jws.WebMethod; | ||
| 17 | +import javax.jws.WebService; | ||
| 18 | +import javax.xml.ws.Holder; | ||
| 19 | +import java.util.List; | ||
| 20 | + | ||
| 21 | +/** | ||
| 22 | + * 场站数据接口 | ||
| 23 | + * BS调度系统webservice接口实现,完美兼容老系统接口格式 | ||
| 24 | + * Created by panzhao on 2017/3/10. | ||
| 25 | + */ | ||
| 26 | +@Component | ||
| 27 | +@WebService( | ||
| 28 | + name = "CompanyServiceSoap", | ||
| 29 | + portName = "CompanyServiceSoap", | ||
| 30 | + serviceName = "CompanyService", | ||
| 31 | + targetNamespace = "http://control.bsth.com/", | ||
| 32 | + endpointInterface = "com.bsth.server_ws.park_station.CompanyService") | ||
| 33 | +public class CompanyServiceSoap implements CompanyService { | ||
| 34 | + | ||
| 35 | + | ||
| 36 | + Logger logger = LoggerFactory.getLogger(this.getClass()); | ||
| 37 | + | ||
| 38 | + @Autowired | ||
| 39 | + JdbcTemplate jdbcTemplate; | ||
| 40 | + | ||
| 41 | + @Override | ||
| 42 | + @WebMethod | ||
| 43 | + public boolean returnCCInfo(String password, String companyId, String rq, javax.xml.ws.Holder<String[]> result, javax.xml.ws.Holder<String> fError) { | ||
| 44 | + if(!password.equals(Constants.OLD_SYS_PASSWORD)){ | ||
| 45 | + fError.value = "无效密码"; | ||
| 46 | + return false; | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + List<ScheduleRealInfo> list = null; | ||
| 50 | + try{ | ||
| 51 | + //从调度系统获取数据 | ||
| 52 | + list = ControlHttpUtils.returnJCCInfo(companyId, "out"); | ||
| 53 | + }catch (Exception e){ | ||
| 54 | + //访问调度系统异常,尝试从数据库获取 | ||
| 55 | + | ||
| 56 | + } | ||
| 57 | + result.value = WSDataConver.to_returnJCCInfo(list); | ||
| 58 | + | ||
| 59 | + //不再代理老接口数据 | ||
| 60 | + /*if(!WebServiceProxy.isAllNew(companyId)){ | ||
| 61 | + String[] oldArray = OldWSClient.returnCCInfo(companyId, rq); | ||
| 62 | + //合并新老系统的数据 | ||
| 63 | + result.value = WebServiceProxy.mergerJccData(result.value, oldArray, companyId); | ||
| 64 | + }*/ | ||
| 65 | + return true; | ||
| 66 | + } | ||
| 67 | + | ||
| 68 | + @Override | ||
| 69 | + @WebMethod | ||
| 70 | + public boolean returnJCInfo(String password, String companyId, String rq, Holder<String[]> result, Holder<String> fError) { | ||
| 71 | + if(!password.equals(Constants.OLD_SYS_PASSWORD)){ | ||
| 72 | + fError.value = "无效密码"; | ||
| 73 | + return false; | ||
| 74 | + } | ||
| 75 | + | ||
| 76 | + List<ScheduleRealInfo> list = null; | ||
| 77 | + try{ | ||
| 78 | + //从调度系统获取数据 | ||
| 79 | + list = ControlHttpUtils.returnJCCInfo(companyId, "in"); | ||
| 80 | + }catch (Exception e){ | ||
| 81 | + //访问调度系统异常,尝试从数据库获取 | ||
| 82 | + | ||
| 83 | + } | ||
| 84 | + result.value = WSDataConver.to_returnJCCInfo(list); | ||
| 85 | + | ||
| 86 | + //不再代理老接口数据 | ||
| 87 | + /*if(!WebServiceProxy.isAllNew(companyId)){ | ||
| 88 | + String[] oldArray = OldWSClient.returnJCInfo(companyId, rq); | ||
| 89 | + //合并新老系统的数据 | ||
| 90 | + result.value = WebServiceProxy.mergerJccData(result.value, oldArray, companyId); | ||
| 91 | + }*/ | ||
| 92 | + | ||
| 93 | + return true; | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + @Override | ||
| 97 | + @WebMethod | ||
| 98 | + public boolean getCurrentDayPlan(String ip, String userName, String password, String workId, String company, Holder<String[]> result, Holder<String> fError) { | ||
| 99 | + if(!password.equals(Constants.OLD_SYS_PASSWORD)){ | ||
| 100 | + fError.value = "无效密码"; | ||
| 101 | + return false; | ||
| 102 | + } | ||
| 103 | + | ||
| 104 | + try{ | ||
| 105 | + logger.info("getCurrentDayPlan workId: " + workId); | ||
| 106 | + List<ScheduleRealInfo> list = null; | ||
| 107 | + try{ | ||
| 108 | + //从调度系统获取数据 | ||
| 109 | + list = ControlHttpUtils.getCurrentDayPlan(company, workId); | ||
| 110 | + logger.info("从调度系统获取到数据 size: " + list.size()); | ||
| 111 | + }catch (Exception e){ | ||
| 112 | + //访问调度系统异常,尝试从数据库获取 | ||
| 113 | + logger.error("", e); | ||
| 114 | + } | ||
| 115 | + result.value = WSDataConver.to_getCurrentDayPlan(list); | ||
| 116 | + }catch(Exception e){ | ||
| 117 | + fError.value = e.getMessage(); | ||
| 118 | + logger.error("", e); | ||
| 119 | + } | ||
| 120 | + return false; | ||
| 121 | + } | ||
| 122 | + | ||
| 123 | + @Override | ||
| 124 | + public boolean getLSLC_PB(String ip, String userName, String password, String month, String workId, String company, Holder<String[]> result, Holder<String> fError) { | ||
| 125 | + if(!password.equals(Constants.OLD_SYS_PASSWORD)){ | ||
| 126 | + fError.value = "无效密码"; | ||
| 127 | + return false; | ||
| 128 | + } | ||
| 129 | + | ||
| 130 | + try{ | ||
| 131 | + //实际排班 | ||
| 132 | + List<ScheduleRealInfo> schList = | ||
| 133 | + jdbcTemplate.query("select * from bsth_c_s_sp_info_real where gs_bm= ? and j_gh= ? and schedule_date_str like concat(? '-%')", new Object[]{ company, workId, month }, | ||
| 134 | + BeanPropertyRowMapper.newInstance(ScheduleRealInfo.class)); | ||
| 135 | + | ||
| 136 | + //计划排班 | ||
| 137 | + List<SchedulePlanInfo> planList = | ||
| 138 | + jdbcTemplate.query("select * from bsth_c_s_sp_info where gs_bm= ? and j_gh= ? and schedule_date>sysdate() and schedule_date like concat(? '-%') order by bcs", new Object[]{ company, workId, month }, | ||
| 139 | + BeanPropertyRowMapper.newInstance(SchedulePlanInfo.class)); | ||
| 140 | + | ||
| 141 | + //油耗 | ||
| 142 | + List<OilInfo> oilList = | ||
| 143 | + jdbcTemplate.query("select * from bsth_c_ylb where jsy= ? and rq like concat(? '-%')", new Object[]{ workId, month }, | ||
| 144 | + BeanPropertyRowMapper.newInstance(OilInfo.class)); | ||
| 145 | + | ||
| 146 | + result.value = WSDataConver.to_getLSLC_PB(month, schList, oilList, planList); | ||
| 147 | + }catch(Exception e){ | ||
| 148 | + fError.value = e.getMessage(); | ||
| 149 | + logger.error("", e); | ||
| 150 | + } | ||
| 151 | + return false; | ||
| 152 | + } | ||
| 153 | +} |