Commit 13d9784adadb7c640be9ff3fbd58c90a85365133

Authored by 潘钊
1 parent 15bdf37e

update...

src/main/java/com/bsth/CXFConfig.java
... ... @@ -8,6 +8,7 @@ import com.bsth.server_rs.base_info.section.LD_SectionRestService;
8 8 import com.bsth.server_rs.base_info.station.StationRestService;
9 9 import com.bsth.server_rs.exception.AesExceptionMapper;
10 10 import com.bsth.server_rs.gps.GpsRestService;
  11 +import com.bsth.server_rs.logs.RealLogRestService;
11 12 import com.bsth.server_rs.schedule.plan.SchedulePlanService;
12 13 import com.bsth.server_rs.schedule.real.ScheduleRealService;
13 14 import com.bsth.server_ws.attendance.AttendanceServiceSoap;
... ... @@ -81,6 +82,10 @@ public class CXFConfig {
81 82 LD_SectionRestService ldSectionRestService;
82 83 @Autowired
83 84 SchedulePlanService schedulePlanService;
  85 + @Autowired
  86 + RealLogRestService realLogRestService;
  87 + @Autowired
  88 + GpsRestService gpsRestService;
84 89  
85 90 @Bean
86 91 public Server rsServer() {
... ... @@ -91,11 +96,12 @@ public class CXFConfig {
91 96 new LineRestService(),
92 97 new CarRestService(),
93 98 new PersonRestService(),
94   - new GpsRestService(),
  99 + gpsRestService,
95 100 scheduleRealService,
96 101 stationRestService,
97 102 ldSectionRestService,
98   - schedulePlanService));
  103 + schedulePlanService,
  104 + realLogRestService));
99 105 endpoint.setProviders(Arrays.asList(new JacksonJsonProvider(), new AesExceptionMapper()));
100 106 //endpoint.setFeatures(Arrays.asList(new Swagger2Feature()));
101 107 endpoint.getInInterceptors().add(new AuthorizeInterceptor_IN());
... ...
src/main/java/com/bsth/server_rs/base_info/person/buffer/PersonRefreshThread.java
... ... @@ -8,7 +8,10 @@ import org.springframework.jdbc.core.BeanPropertyRowMapper;
8 8 import org.springframework.jdbc.core.JdbcTemplate;
9 9 import org.springframework.stereotype.Component;
10 10  
  11 +import java.util.ArrayList;
  12 +import java.util.HashMap;
11 13 import java.util.List;
  14 +import java.util.Map;
12 15  
13 16 /**
14 17 * Created by panzhao on 2017/3/27.
... ... @@ -27,8 +30,15 @@ public class PersonRefreshThread extends Thread{
27 30 try {
28 31 List<Personnel> list = jdbcTemplate.query("select DISTINCT t1.*,t2.name as line_name,t2.line_code from (SELECT company_code,branche_company_code,job_code,personnel_name,papers_code,ic_card_code,personnel_type,posts,card,telphone,ic_rfid,id_rfid,tag_rfid,e.xl FROM bsth_c_personnel p left JOIN bsth_c_s_ecinfo e on p.id=e.jsy) t1 LEFT JOIN bsth_c_line t2 on t1.xl=t2.id "
29 32 ,BeanPropertyRowMapper.newInstance(Personnel.class));
  33 +
  34 + Map<String, Personnel> map = new HashMap<>();
  35 + //过滤数据,多条线路配车的保留一条
  36 + for(Personnel p : list){
  37 + map.put(p.getJobCode(), p);
  38 + }
  39 +
30 40 if(list != null && list.size() > 0)
31   - PersonBufferData.replaceAll(list);
  41 + PersonBufferData.replaceAll(new ArrayList(map.values()));
32 42 }catch (Exception e){
33 43 logger.error("", e);
34 44 }
... ...
src/main/java/com/bsth/server_rs/gps/GpsRestService.java
1 1 package com.bsth.server_rs.gps;
2 2  
3 3 import com.bsth.server_rs.gps.buffer.GpsRealDataBuffer;
  4 +import com.bsth.server_rs.gps.dao.HistoryGpsDao;
4 5 import com.bsth.server_rs.gps.entity.GpsEntity;
  6 +import com.bsth.server_rs.gps.entity.HistoryGpsEntity;
  7 +import org.springframework.beans.factory.annotation.Autowired;
  8 +import org.springframework.stereotype.Component;
5 9  
6 10 import javax.ws.rs.GET;
7 11 import javax.ws.rs.Path;
... ... @@ -13,19 +17,31 @@ import java.util.Collection;
13 17 /**
14 18 * Created by panzhao on 2017/3/28.
15 19 */
  20 +@Component
16 21 @Path("/gps")
17 22 @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
18 23 public class GpsRestService {
19 24  
  25 + @Autowired
  26 + HistoryGpsDao historyGpsDao;
  27 +
20 28 @GET
21 29 @Path("/{deviceId}")
22   - public GpsEntity findOne(@PathParam("deviceId") String deviceId){
  30 + public GpsEntity findOne(@PathParam("deviceId") String deviceId) {
23 31 return GpsRealDataBuffer.get(deviceId);
24 32 }
25 33  
26 34 @GET
27 35 @Path("/all")
28   - public Collection<GpsEntity> findAll(){
  36 + public Collection<GpsEntity> findAll() {
29 37 return GpsRealDataBuffer.all();
30 38 }
  39 +
  40 + @GET
  41 + @Path("/history/{nbbm}/{st}/{et}")
  42 + public Collection<HistoryGpsEntity> history(@PathParam("nbbm") String nbbm
  43 + , @PathParam("st") String st
  44 + , @PathParam("et") String et) {
  45 + return historyGpsDao.query(nbbm, Long.parseLong(st), Long.parseLong(et));
  46 + }
31 47 }
... ...
src/main/java/com/bsth/server_rs/gps/dao/HistoryGpsDao.java
1 1 package com.bsth.server_rs.gps.dao;
2 2  
  3 +import com.bsth.redis.util.DateUtils;
  4 +import com.bsth.server_rs.base_info.car.Car;
  5 +import com.bsth.server_rs.base_info.car.buffer.CarBufferData;
  6 +import com.bsth.server_rs.gps.entity.HistoryGpsEntity;
  7 +import com.bsth.util.DBUtils_MS;
  8 +import org.springframework.jdbc.core.BeanPropertyRowMapper;
  9 +import org.springframework.jdbc.core.JdbcTemplate;
3 10 import org.springframework.stereotype.Component;
4 11  
  12 +import java.util.*;
  13 +
5 14 /**
6 15 * Created by panzhao on 2017/8/31.
7 16 */
... ... @@ -9,4 +18,103 @@ import org.springframework.stereotype.Component;
9 18 public class HistoryGpsDao {
10 19  
11 20  
  21 + /**
  22 + * 最大查询间隔
  23 + */
  24 + private static final long GPS_RANGE = 1000 * 60 * 60 * 24;
  25 +
  26 + public Collection<HistoryGpsEntity> query(String nbbm, Long st, Long et) {
  27 + //分区字段 day_years
  28 + Calendar sCal = Calendar.getInstance();
  29 + sCal.setTime(new Date(st));
  30 + Calendar eCal = Calendar.getInstance();
  31 + eCal.setTime(new Date(et));
  32 +
  33 + if (null == st)
  34 + return null;
  35 + if (null == et)
  36 + return null;
  37 + if (et < st)
  38 + return null;
  39 +
  40 + if (et - st > GPS_RANGE)
  41 + return null;
  42 +
  43 + Car c = CarBufferData.findOne(nbbm);
  44 + if (null == c)
  45 + return null;
  46 +
  47 + List<HistoryGpsEntity> list = query(c.getEquipmentCode(), sCal, eCal);
  48 + for (HistoryGpsEntity gps : list) {
  49 + gps.setNbbm(nbbm);
  50 + gps.setUpDown(getUpOrDown(gps.getServiceState()));
  51 + gps.setState(getService(gps.getServiceState()));
  52 + }
  53 + return list;
  54 + }
  55 +
  56 + private List<HistoryGpsEntity> query(String deviceId, Calendar sCal, Calendar eCal) {
  57 + int sDayOfYear = sCal.get(Calendar.DAY_OF_YEAR);
  58 + int eDayOfYear = eCal.get(Calendar.DAY_OF_YEAR);
  59 + long st = sCal.getTimeInMillis();
  60 + long et = eCal.getTimeInMillis();
  61 +
  62 + List<HistoryGpsEntity> list = new ArrayList<>();
  63 + // 如果是同一天
  64 + if (sDayOfYear == eDayOfYear) {
  65 + list = query(sDayOfYear, st, et, deviceId);
  66 + } else {
  67 + // 跨天
  68 + Long tempSt = 0L, tempEt = 0L;
  69 + for (int i = sDayOfYear; i <= eDayOfYear; i++) {
  70 +
  71 + if (i == sDayOfYear) {
  72 + tempSt = st;
  73 + tempEt = DateUtils.getTimesnight(sCal);
  74 + } else if (i == eDayOfYear) {
  75 + tempSt = DateUtils.getTimesmorning(sCal);
  76 + tempEt = et;
  77 + } else {
  78 + tempSt = DateUtils.getTimesmorning(sCal);
  79 + tempEt = DateUtils.getTimesnight(sCal);
  80 + }
  81 +
  82 + list.addAll(query(sDayOfYear, tempSt, tempEt, deviceId));
  83 + // 加一天
  84 + sCal.add(Calendar.DATE, 1);
  85 + }
  86 + }
  87 + return list;
  88 + }
  89 +
  90 + private List<HistoryGpsEntity> query(int dayOfYear, Long st, Long et, String deviceId) {
  91 + String sql = "select device_id,line_id,service_state,direction,lon,lat,ts,stop_no,speed_gps as speed,inout_stop from bsth_c_gps_info where days_year=" + dayOfYear + " and device_id='"+deviceId+"' and ts > " + st + " and ts < " + et;
  92 +
  93 + JdbcTemplate jdbcTemplate = new JdbcTemplate(DBUtils_MS.getDataSource());
  94 + List<HistoryGpsEntity> list = jdbcTemplate.query(sql, BeanPropertyRowMapper.newInstance(HistoryGpsEntity.class));
  95 + return list;
  96 + }
  97 +
  98 + /**
  99 + * 王通 2016/6/29 9:23:24 获取车辆线路上下行
  100 + *
  101 + * @return -1无效 0上行 1下行
  102 + */
  103 + private static byte getUpOrDown(long serviceState) {
  104 + if ((serviceState & 0x00020000) == 0x00020000 || (serviceState & 0x80000000) == 0x80000000
  105 + || (serviceState & 0x01000000) == 0x01000000 || (serviceState & 0x08000000) == 0x08000000)
  106 + return -1;
  107 + return (byte) (((serviceState & 0x10000000) == 0x10000000) ? 1 : 0);
  108 + }
  109 +
  110 + /**
  111 + * 获取运营状态
  112 + *
  113 + * @return -1无效 0运营 1未运营
  114 + */
  115 + private static byte getService(long serviceState) {
  116 + if ((serviceState & 0x00020000) == 0x00020000 || (serviceState & 0x80000000) == 0x80000000)
  117 + return -1;
  118 + return (byte) (((serviceState & 0x02000000) == 0x02000000) ? 1 : 0);
  119 + }
12 120 }
... ...
src/main/java/com/bsth/server_rs/gps/entity/HistoryGpsEntity.java
1 1 package com.bsth.server_rs.gps.entity;
2 2  
  3 +import com.fasterxml.jackson.annotation.JsonIgnore;
  4 +
  5 +import java.io.Serializable;
  6 +
3 7 /**
4 8 * 历史GPS
5 9 * Created by panzhao on 2017/8/31.
6 10 */
7   -public class HistoryGpsEntity {
  11 +public class HistoryGpsEntity implements Serializable {
8 12  
9 13 /** 车辆自编号 */
10 14 private String nbbm;
... ... @@ -37,11 +41,15 @@ public class HistoryGpsEntity {
37 41 private float speed;
38 42  
39 43 /** 进出站状态 */
40   - private int inout_stop;
  44 + private int inoutStop;
41 45  
42 46 /** 营运状态 */
43 47 private int state;
44 48  
  49 + @JsonIgnore
  50 + /** 多状态字段 */
  51 + private Long serviceState;
  52 +
45 53 public String getNbbm() {
46 54 return nbbm;
47 55 }
... ... @@ -122,14 +130,6 @@ public class HistoryGpsEntity {
122 130 this.speed = speed;
123 131 }
124 132  
125   - public int getInout_stop() {
126   - return inout_stop;
127   - }
128   -
129   - public void setInout_stop(int inout_stop) {
130   - this.inout_stop = inout_stop;
131   - }
132   -
133 133 public int getState() {
134 134 return state;
135 135 }
... ... @@ -137,4 +137,20 @@ public class HistoryGpsEntity {
137 137 public void setState(int state) {
138 138 this.state = state;
139 139 }
  140 +
  141 + public Long getServiceState() {
  142 + return serviceState;
  143 + }
  144 +
  145 + public void setServiceState(Long serviceState) {
  146 + this.serviceState = serviceState;
  147 + }
  148 +
  149 + public int getInoutStop() {
  150 + return inoutStop;
  151 + }
  152 +
  153 + public void setInoutStop(int inoutStop) {
  154 + this.inoutStop = inoutStop;
  155 + }
140 156 }
... ...
src/main/java/com/bsth/server_rs/logs/RealLogRestService.java 0 → 100644
  1 +package com.bsth.server_rs.logs;
  2 +
  3 +import com.bsth.server_rs.logs.entity.SchEditInfo;
  4 +import org.springframework.beans.factory.annotation.Autowired;
  5 +import org.springframework.jdbc.core.BeanPropertyRowMapper;
  6 +import org.springframework.jdbc.core.JdbcTemplate;
  7 +import org.springframework.stereotype.Component;
  8 +
  9 +import javax.ws.rs.GET;
  10 +import javax.ws.rs.Path;
  11 +import javax.ws.rs.PathParam;
  12 +import javax.ws.rs.Produces;
  13 +import javax.ws.rs.core.MediaType;
  14 +import java.util.List;
  15 +
  16 +/**
  17 + * Created by panzhao on 2017/3/28.
  18 + */
  19 +@Component
  20 +@Path("/real_log")
  21 +@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
  22 +public class RealLogRestService {
  23 +
  24 + @Autowired
  25 + JdbcTemplate jdbcTemplate;
  26 +
  27 + @GET
  28 + @Path("/company/{companyId}/{rq}")
  29 + public List<SchEditInfo> findByCompany(@PathParam("companyId") String companyId, @PathParam("rq") String rq) {
  30 + //不走缓存,暂时直连数据库
  31 + List<SchEditInfo> list = jdbcTemplate.query("select * from logger_sch_modify where gsbm='" + companyId + "' and rq='" + rq + "'", BeanPropertyRowMapper.newInstance(SchEditInfo.class));
  32 + return list;
  33 + }
  34 +}
... ...
src/main/java/com/bsth/server_rs/logs/entity/EditType.java 0 → 100644
  1 +package com.bsth.server_rs.logs.entity;
  2 +
  3 +/**
  4 + * Created by panzhao on 2017/5/18.
  5 + */
  6 +public enum EditType {
  7 +
  8 + DFTZ,SFTZ,FCXXWT,TZRC,LPDD,ZRW,JHLB,CXLB, CXSF, LSBCTZ, CXZX
  9 +}
0 10 \ No newline at end of file
... ...
src/main/java/com/bsth/server_rs/logs/entity/SchEditInfo.java 0 → 100644
  1 +package com.bsth.server_rs.logs.entity;
  2 +
  3 +import javax.persistence.EnumType;
  4 +import javax.persistence.Enumerated;
  5 +
  6 +/**
  7 + * 线调操作日志
  8 + * Created by panzhao on 2017/9/6.
  9 + */
  10 +public class SchEditInfo {
  11 +
  12 + /**
  13 + * 日期 yyyy-MM-dd
  14 + */
  15 + private String rq;
  16 +
  17 + /**
  18 + * 时间戳
  19 + */
  20 + private long ts;
  21 +
  22 + private String lineCode;
  23 +
  24 +
  25 + private String fgsbm;
  26 +
  27 + /**
  28 + * 班次ID
  29 + */
  30 + private long schId;
  31 +
  32 + /**
  33 + * 类型
  34 + */
  35 + @Enumerated(EnumType.STRING)
  36 + private EditType type;
  37 +
  38 + private String type2;
  39 + /**
  40 + * 操作人 @system 系统/用户名
  41 + */
  42 + private String user;
  43 +
  44 + /**
  45 + * 操作明细
  46 + */
  47 + private String jsonArray;
  48 +
  49 + private String remarks;
  50 +
  51 + public String getRq() {
  52 + return rq;
  53 + }
  54 +
  55 + public void setRq(String rq) {
  56 + this.rq = rq;
  57 + }
  58 +
  59 + public long getTs() {
  60 + return ts;
  61 + }
  62 +
  63 + public void setTs(long ts) {
  64 + this.ts = ts;
  65 + }
  66 +
  67 + public String getLineCode() {
  68 + return lineCode;
  69 + }
  70 +
  71 + public void setLineCode(String lineCode) {
  72 + this.lineCode = lineCode;
  73 + }
  74 +
  75 + public String getFgsbm() {
  76 + return fgsbm;
  77 + }
  78 +
  79 + public void setFgsbm(String fgsbm) {
  80 + this.fgsbm = fgsbm;
  81 + }
  82 +
  83 + public long getSchId() {
  84 + return schId;
  85 + }
  86 +
  87 + public void setSchId(long schId) {
  88 + this.schId = schId;
  89 + }
  90 +
  91 + public EditType getType() {
  92 + return type;
  93 + }
  94 +
  95 + public void setType(EditType type) {
  96 + this.type = type;
  97 + }
  98 +
  99 + public String getType2() {
  100 + return type2;
  101 + }
  102 +
  103 + public void setType2(String type2) {
  104 + this.type2 = type2;
  105 + }
  106 +
  107 + public String getUser() {
  108 + return user;
  109 + }
  110 +
  111 + public void setUser(String user) {
  112 + this.user = user;
  113 + }
  114 +
  115 + public String getJsonArray() {
  116 + return jsonArray;
  117 + }
  118 +
  119 + public void setJsonArray(String jsonArray) {
  120 + this.jsonArray = jsonArray;
  121 + }
  122 +
  123 + public String getRemarks() {
  124 + return remarks;
  125 + }
  126 +
  127 + public void setRemarks(String remarks) {
  128 + this.remarks = remarks;
  129 + }
  130 +}
... ...
src/main/java/com/bsth/util/DBUtils_MS.java 0 → 100644
  1 +package com.bsth.util;
  2 +
  3 +import com.mchange.v2.c3p0.DataSources;
  4 +import org.apache.log4j.Logger;
  5 +
  6 +import javax.sql.DataSource;
  7 +import java.io.FileNotFoundException;
  8 +import java.io.IOException;
  9 +import java.sql.Connection;
  10 +import java.sql.ResultSet;
  11 +import java.sql.SQLException;
  12 +import java.sql.Statement;
  13 +import java.util.HashMap;
  14 +import java.util.Map;
  15 +import java.util.Properties;
  16 +
  17 +/**
  18 + * 网关ms库连接池
  19 + * @author PanZhao
  20 + *
  21 + */
  22 +//@Component
  23 +public class DBUtils_MS {
  24 +
  25 + private static String url = null;
  26 +
  27 + private static String username = null;
  28 +
  29 + private static String pwd = null;
  30 +
  31 + private static DataSource ds_pooled;
  32 +
  33 + static Logger logger = Logger.getLogger(DBUtils_MS.class);
  34 +
  35 + static {
  36 + Properties env = new Properties();
  37 +
  38 + try {
  39 + env.load(DBUtils_MS.class.getClassLoader().getResourceAsStream("ms-jdbc.properties"));
  40 + // 1. 加载驱动类
  41 + Class.forName(env.getProperty("ms.mysql.driver"));
  42 +
  43 + url = env.getProperty("ms.mysql.url");
  44 + username = env.getProperty("ms.mysql.username");
  45 + pwd = env.getProperty("ms.mysql.password");
  46 +
  47 + // 设置连接数据库的配置信息
  48 + DataSource ds_unpooled = DataSources.unpooledDataSource(url,
  49 + username, pwd);
  50 +
  51 + Map<String, Object> pool_conf = new HashMap<String, Object>();
  52 + // 设置最大连接数
  53 + pool_conf.put("maxPoolSize", 10);
  54 +
  55 + pool_conf.put("testConnectionOnCheckout", false);
  56 + //异步检测连接的有效性
  57 + pool_conf.put("testConnectionOnCheckin", true);
  58 + //30秒检测一次
  59 + pool_conf.put("idleConnectionTestPeriod", 30);
  60 + ds_pooled = DataSources.pooledDataSource(ds_unpooled, pool_conf);
  61 + } catch (FileNotFoundException e) {
  62 + logger.error(e.toString());
  63 + e.printStackTrace();
  64 + } catch (IOException e) {
  65 + logger.error(e.toString());
  66 + e.printStackTrace();
  67 + } catch (ClassNotFoundException e) {
  68 + logger.error(e.toString());
  69 + e.printStackTrace();
  70 + } catch (SQLException e) {
  71 + logger.error(e.toString());
  72 + e.printStackTrace();
  73 + }
  74 + }
  75 +
  76 + /**
  77 + * 获取连接对象
  78 + */
  79 + public static Connection getConnection() throws SQLException {
  80 + return ds_pooled.getConnection();
  81 + }
  82 +
  83 + /**
  84 + * 释放连接池资源
  85 + */
  86 + public static void clearup() {
  87 + if (ds_pooled != null) {
  88 + try {
  89 + DataSources.destroy(ds_pooled);
  90 + } catch (SQLException e) {
  91 + logger.error(e.toString());
  92 + e.printStackTrace();
  93 + }
  94 + }
  95 + }
  96 +
  97 + /**
  98 + * 资源关闭
  99 + *
  100 + * @param rs
  101 + * @param stmt
  102 + * @param conn
  103 + */
  104 + public static void close(ResultSet rs, Statement stmt, Connection conn) {
  105 + if (rs != null) {
  106 + try {
  107 + rs.close();
  108 + } catch (SQLException e) {
  109 + logger.error(e.toString());
  110 + e.printStackTrace();
  111 + }
  112 + }
  113 +
  114 + if (stmt != null) {
  115 + try {
  116 + stmt.close();
  117 + } catch (SQLException e) {
  118 + logger.error(e.toString());
  119 + e.printStackTrace();
  120 + }
  121 + }
  122 +
  123 + if (conn != null) {
  124 + try {
  125 + conn.close();
  126 + } catch (SQLException e) {
  127 + logger.error(e.toString());
  128 + e.printStackTrace();
  129 + }
  130 + }
  131 + }
  132 +
  133 + public static DataSource getDataSource(){
  134 + return ds_pooled;
  135 + }
  136 +}
... ...
src/main/resources/ms-jdbc.properties 0 → 100644
  1 +#ms.mysql.driver= com.mysql.jdbc.Driver
  2 +#ms.mysql.url= jdbc:mysql://127.0.0.1:3306/ms?useUnicode=true&characterEncoding=utf-8
  3 +#ms.mysql.username= root
  4 +#ms.mysql.password= panzhao
  5 +
  6 +ms.mysql.driver= com.mysql.jdbc.Driver
  7 +ms.mysql.url= jdbc:mysql://10.10.150.21:3306/ms?useUnicode=true&characterEncoding=utf-8
  8 +ms.mysql.username= root
  9 +ms.mysql.password= root2jsp@JSP
0 10 \ No newline at end of file
... ...