Commit 2dd32eb39d85f9f6f5298f7bf1bc8db1bf5c7870

Authored by 王通
1 parent 875de6d0

1.

src/main/java/com/bsth/server_rs/base_info/car/CarRestService.java
... ... @@ -11,9 +11,14 @@ import com.fasterxml.jackson.databind.ObjectMapper;
11 11 import org.apache.commons.lang3.StringEscapeUtils;
12 12 import org.slf4j.Logger;
13 13 import org.slf4j.LoggerFactory;
  14 +import org.springframework.beans.factory.annotation.Autowired;
  15 +import org.springframework.jdbc.core.BatchPreparedStatementSetter;
  16 +import org.springframework.jdbc.core.JdbcTemplate;
14 17  
15 18 import javax.ws.rs.*;
16 19 import javax.ws.rs.core.MediaType;
  20 +import java.sql.PreparedStatement;
  21 +import java.sql.SQLException;
17 22 import java.util.HashMap;
18 23 import java.util.List;
19 24 import java.util.Map;
... ... @@ -29,6 +34,9 @@ public class CarRestService {
29 34  
30 35 private ObjectMapper mapper = new ObjectMapper();
31 36  
  37 + @Autowired
  38 + private JdbcTemplate jdbcTemplate;
  39 +
32 40 @GET
33 41 @Path("/all")
34 42 public List<Car> findAll(){
... ... @@ -57,9 +65,24 @@ public class CarRestService {
57 65  
58 66 @POST
59 67 @Path("")
60   - public Map<String, Object> save(List<Car> cars) throws JsonProcessingException {
  68 + public Map<String, Object> save(final List<Car> cars) throws JsonProcessingException {
61 69 Map<String, Object> result = new HashMap<>();
62   - log.info(mapper.writeValueAsString(cars));
  70 + log.error(mapper.writeValueAsString(cars));
  71 + jdbcTemplate.batchUpdate("insert into zyl.bsth_c_cars (car_plate,company_code,branche_company_code,energy_type) values(?,?,?,?)", new BatchPreparedStatementSetter() {
  72 + @Override
  73 + public void setValues(PreparedStatement ps, int i) throws SQLException {
  74 + Car car = cars.get(i);
  75 + ps.setString(1, car.getCarPlate());
  76 + ps.setString(2, car.getCompanyCode());
  77 + ps.setString(3, car.getBrancheCompanyCode());
  78 + ps.setInt(4, car.getEnergyType());
  79 + }
  80 +
  81 + @Override
  82 + public int getBatchSize() {
  83 + return cars.size();
  84 + }
  85 + });
63 86  
64 87 return result;
65 88 }
... ...
src/main/java/com/bsth/server_rs/base_info/line/LineRestService.java
1 1 package com.bsth.server_rs.base_info.line;
2 2  
  3 +import com.bsth.entity.ScheduleExec;
3 4 import com.bsth.server_rs.base_info.line.buffer.LineBufferData;
4 5 import com.bsth.server_rs.schedule.ScheduleRealService;
5 6 import com.fasterxml.jackson.core.JsonProcessingException;
6 7 import com.fasterxml.jackson.databind.ObjectMapper;
7 8 import org.slf4j.Logger;
8 9 import org.slf4j.LoggerFactory;
  10 +import org.springframework.beans.factory.annotation.Autowired;
  11 +import org.springframework.jdbc.core.BatchPreparedStatementSetter;
  12 +import org.springframework.jdbc.core.JdbcTemplate;
9 13  
10 14 import javax.ws.rs.*;
11 15 import javax.ws.rs.core.MediaType;
  16 +import java.sql.PreparedStatement;
  17 +import java.sql.SQLException;
12 18 import java.util.*;
13 19  
14 20 /**
... ... @@ -23,6 +29,9 @@ public class LineRestService {
23 29  
24 30 private ObjectMapper mapper = new ObjectMapper();
25 31  
  32 + @Autowired
  33 + private JdbcTemplate jdbcTemplate;
  34 +
26 35 @GET
27 36 @Path("/all")
28 37 public List<Line> findAll(){
... ... @@ -58,9 +67,34 @@ public class LineRestService {
58 67  
59 68 @POST
60 69 @Path("")
61   - public Map<String, Object> save(List<Line> lines) throws JsonProcessingException {
  70 + public Map<String, Object> save(final List<Line> lines) throws JsonProcessingException {
62 71 Map<String, Object> result = new HashMap<>();
63   - log.info(mapper.writeValueAsString(lines));
  72 + log.error(mapper.writeValueAsString(lines));
  73 + jdbcTemplate.batchUpdate("insert into zyl.bsth_c_line (name,start_station_name,end_station_name,start_station_first_time,start_station_end_time,end_station_first_time,end_station_end_time,company,branche_company,line_play_type,up_mileage,down_mileage,up_travel_time,down_travel_time) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)", new BatchPreparedStatementSetter() {
  74 + @Override
  75 + public void setValues(PreparedStatement ps, int i) throws SQLException {
  76 + Line line = lines.get(i);
  77 + ps.setString(1, line.getName());
  78 + ps.setString(2, line.getStartStationName());
  79 + ps.setString(3, line.getEndStationName());
  80 + ps.setString(4, line.getStartStationFirstTime());
  81 + ps.setString(5, line.getStartStationEndTime());
  82 + ps.setString(6, line.getEndStationFirstTime());
  83 + ps.setString(7, line.getEndStationEndTime());
  84 + ps.setString(8, line.getCompany());
  85 + ps.setString(9, line.getBrancheCompany());
  86 + ps.setInt(10, line.getLinePlayType());
  87 + ps.setDouble(11, line.getUpMileage());
  88 + ps.setDouble(12, line.getDownMileage());
  89 + ps.setDouble(13, line.getUpTravelTime());
  90 + ps.setDouble(14, line.getDownTravelTime());
  91 + }
  92 +
  93 + @Override
  94 + public int getBatchSize() {
  95 + return lines.size();
  96 + }
  97 + });
64 98  
65 99 return result;
66 100 }
... ...
src/main/java/com/bsth/server_rs/base_info/person/PersonRestService.java
... ... @@ -11,9 +11,14 @@ import com.fasterxml.jackson.databind.ObjectMapper;
11 11 import org.apache.commons.lang3.StringEscapeUtils;
12 12 import org.slf4j.Logger;
13 13 import org.slf4j.LoggerFactory;
  14 +import org.springframework.beans.factory.annotation.Autowired;
  15 +import org.springframework.jdbc.core.BatchPreparedStatementSetter;
  16 +import org.springframework.jdbc.core.JdbcTemplate;
14 17  
15 18 import javax.ws.rs.*;
16 19 import javax.ws.rs.core.MediaType;
  20 +import java.sql.PreparedStatement;
  21 +import java.sql.SQLException;
17 22 import java.util.HashMap;
18 23 import java.util.List;
19 24 import java.util.Map;
... ... @@ -29,6 +34,9 @@ public class PersonRestService {
29 34  
30 35 private ObjectMapper mapper = new ObjectMapper();
31 36  
  37 + @Autowired
  38 + private JdbcTemplate jdbcTemplate;
  39 +
32 40 @GET
33 41 @Path("/all")
34 42 public List<Personnel> findAll(){
... ... @@ -57,9 +65,26 @@ public class PersonRestService {
57 65  
58 66 @POST
59 67 @Path("")
60   - public Map<String, Object> save(List<Personnel> personnels) throws JsonProcessingException {
  68 + public Map<String, Object> save(final List<Personnel> personnels) throws JsonProcessingException {
61 69 Map<String, Object> result = new HashMap<>();
62   - log.info(mapper.writeValueAsString(personnels));
  70 + log.error(mapper.writeValueAsString(personnels));
  71 + jdbcTemplate.batchUpdate("insert into zyl.bsth_c_personnel (job_code,company_code,branche_company_code,personnel_name,personnel_type,posts) values(?,?,?,?,?,?)", new BatchPreparedStatementSetter() {
  72 + @Override
  73 + public void setValues(PreparedStatement ps, int i) throws SQLException {
  74 + Personnel personnel = personnels.get(i);
  75 + ps.setString(1, personnel.getJobCode());
  76 + ps.setString(2, personnel.getCompanyCode());
  77 + ps.setString(3, personnel.getBrancheCompanyCode());
  78 + ps.setString(4, personnel.getPersonnelName());
  79 + ps.setString(5, personnel.getPersonnelType());
  80 + ps.setString(6, personnel.getPosts());
  81 + }
  82 +
  83 + @Override
  84 + public int getBatchSize() {
  85 + return personnels.size();
  86 + }
  87 + });
63 88  
64 89 return result;
65 90 }
... ...
src/main/java/com/bsth/server_rs/base_info/station/StationRestService.java
... ... @@ -8,10 +8,15 @@ import com.fasterxml.jackson.core.JsonProcessingException;
8 8 import com.fasterxml.jackson.databind.ObjectMapper;
9 9 import org.slf4j.Logger;
10 10 import org.slf4j.LoggerFactory;
  11 +import org.springframework.beans.factory.annotation.Autowired;
  12 +import org.springframework.jdbc.core.BatchPreparedStatementSetter;
  13 +import org.springframework.jdbc.core.JdbcTemplate;
11 14 import org.springframework.stereotype.Component;
12 15  
13 16 import javax.ws.rs.*;
14 17 import javax.ws.rs.core.MediaType;
  18 +import java.sql.PreparedStatement;
  19 +import java.sql.SQLException;
15 20 import java.util.Collection;
16 21 import java.util.HashMap;
17 22 import java.util.List;
... ... @@ -29,6 +34,9 @@ public class StationRestService {
29 34  
30 35 private ObjectMapper mapper = new ObjectMapper();
31 36  
  37 + @Autowired
  38 + private JdbcTemplate jdbcTemplate;
  39 +
32 40 @GET
33 41 @Path("/all")
34 42 public Map<String, Collection<StationRotue>> findAll(){
... ... @@ -49,9 +57,33 @@ public class StationRestService {
49 57  
50 58 @POST
51 59 @Path("")
52   - public Map<String, Object> save(List<StationRotue> stationRotues) throws JsonProcessingException {
  60 + public Map<String, Object> save(final List<StationRotue> stationRotues) throws JsonProcessingException {
53 61 Map<String, Object> result = new HashMap<>();
54   - log.info(mapper.writeValueAsString(stationRotues));
  62 + log.error(mapper.writeValueAsString(stationRotues));
  63 + jdbcTemplate.batchUpdate("insert into zyl.bsth_c_stationroute (line_code,station_name,station_route_code,station_mark,distances,to_time,first_time,end_time,directions,lon,lat) values(?,?,?,?,?,?,?,?,?,?,?)", new BatchPreparedStatementSetter() {
  64 + @Override
  65 + public void setValues(PreparedStatement ps, int i) throws SQLException {
  66 + StationRotue stationRotue = stationRotues.get(i);
  67 + ps.setString(1, stationRotue.getLineName());
  68 + ps.setString(2, stationRotue.getStationName());
  69 + ps.setInt(3, stationRotue.getStationRouteCode());
  70 + ps.setString(4, stationRotue.getStationMark());
  71 + ps.setDouble(5, stationRotue.getDistances());
  72 + ps.setDouble(6, stationRotue.getToTime());
  73 + ps.setString(7, stationRotue.getFirstTime());
  74 + ps.setString(8, stationRotue.getEndTime());
  75 + ps.setInt(9, stationRotue.getDirections());
  76 + ps.setFloat(10, stationRotue.getLon());
  77 + ps.setFloat(11, stationRotue.getLat());
  78 + }
  79 +
  80 + @Override
  81 + public int getBatchSize() {
  82 + return stationRotues.size();
  83 + }
  84 + });
  85 + result.put("code", 0);
  86 + result.put("msg", "ok");
55 87  
56 88 return result;
57 89 }
... ...
src/main/java/com/bsth/server_rs/base_info/station/entity/StationRotue.java
... ... @@ -5,6 +5,8 @@ package com.bsth.server_rs.base_info.station.entity;
5 5 */
6 6 public class StationRotue {
7 7  
  8 + private String lineName;
  9 +
8 10 /** 线路编码 */
9 11 private String lineCode;
10 12  
... ... @@ -48,6 +50,14 @@ public class StationRotue {
48 50  
49 51 private Float lat;
50 52  
  53 + public String getLineName() {
  54 + return lineName;
  55 + }
  56 +
  57 + public void setLineName(String lineName) {
  58 + this.lineName = lineName;
  59 + }
  60 +
51 61 public String getLineCode() {
52 62 return lineCode;
53 63 }
... ...
src/main/java/com/bsth/server_rs/directive/DirectiveRestService.java
... ... @@ -4,9 +4,11 @@ import com.alibaba.fastjson.JSON;
4 4 import com.bsth.entity.D60;
5 5 import com.bsth.entity.ZylInfo;
6 6 import com.bsth.repository.DirectiveRepository;
  7 +import com.bsth.server_rs.gps.buffer.BasicDataBuffer;
7 8 import com.bsth.util.ConfigUtil;
8 9 import com.bsth.util.HttpClientUtils;
9 10 import com.bsth.Application;
  11 +import com.fasterxml.jackson.core.JsonProcessingException;
10 12 import com.fasterxml.jackson.databind.ObjectMapper;
11 13 import org.slf4j.Logger;
12 14 import org.slf4j.LoggerFactory;
... ... @@ -18,6 +20,7 @@ import org.springframework.web.bind.annotation.RequestBody;
18 20 import javax.ws.rs.*;
19 21 import javax.ws.rs.core.MediaType;
20 22 import java.io.*;
  23 +import java.util.HashMap;
21 24 import java.util.List;
22 25 import java.util.Map;
23 26 import java.util.concurrent.ConcurrentHashMap;
... ... @@ -41,7 +44,7 @@ public class DirectiveRestService implements InitializingBean {
41 44  
42 45 private ObjectMapper mapper = new ObjectMapper();
43 46  
44   - Logger logger = LoggerFactory.getLogger(this.getClass());
  47 + Logger log = LoggerFactory.getLogger(this.getClass());
45 48  
46 49 static {
47 50 secretKey = ConfigUtil.get("http.control.secret.key");
... ... @@ -49,20 +52,41 @@ public class DirectiveRestService implements InitializingBean {
49 52 }
50 53  
51 54 @POST
52   - @Path("/send")
53   - public int send(@RequestBody Map<String, Object> map){
  55 + @Path("/")
  56 + public Map<String, Object> send(@RequestBody Map<String, Object> map){
  57 + try {
  58 + log.error(mapper.writeValueAsString(map));
  59 + } catch (JsonProcessingException e) {
  60 + e.printStackTrace();
  61 + }
  62 + Map<String, Object> result = new HashMap<>();
  63 + result.put("code", 0);
  64 + result.put("msg", "");
54 65 try{
55 66 String plate = String.valueOf(map.get("plate"));
56 67 int trainNum = (int) map.get("trainNum"), lineId = (int) map.get("lineId");
  68 + if (plate == null || trainNum == 0 || lineId == 0) {
  69 + result.put("code", 500);
  70 + result.put("msg", "参数不完整");
  71 +
  72 + return result;
  73 + }
  74 + if (plate.contains("-")) {
  75 + plate = BasicDataBuffer.getIncodeByIncode(plate);
  76 + }
  77 + plate = BasicDataBuffer.getPlateByIncode(plate);
  78 + map.put("plate", plate);
57 79 ZylInfo zylInfo = new ZylInfo(lineId, trainNum);
58 80 plate2zyl.put(plate, zylInfo);
59 81 map.put("sender", "中运量接口@系统");
60 82 StringBuilder sb = HttpClientUtils.post(url, JSON.toJSONString(map));
61   - return Integer.parseInt(sb.toString());
62 83 }catch (Exception e){
63   - logger.error("", e);
64   - return -500;
  84 + log.error("", e);
  85 + result.put("code", 500);
  86 + result.put("msg", "服务端异常");
65 87 }
  88 +
  89 + return result;
66 90 }
67 91  
68 92 @GET
... ... @@ -72,7 +96,7 @@ public class DirectiveRestService implements InitializingBean {
72 96 StringBuilder sb = HttpClientUtils.get(url + "&msgIds=" + msgIds);
73 97 return JSON.parseArray(sb.toString(), Map.class);
74 98 }catch (Exception e){
75   - logger.error("", e);
  99 + log.error("", e);
76 100 return null;
77 101 }
78 102 }
... ... @@ -83,7 +107,7 @@ public class DirectiveRestService implements InitializingBean {
83 107 try{
84 108 return directiveRepository.findByRqAndDevice(rq, device);
85 109 }catch (Exception e){
86   - logger.error("", e);
  110 + log.error("", e);
87 111 return null;
88 112 }
89 113 }
... ... @@ -122,7 +146,7 @@ public class DirectiveRestService implements InitializingBean {
122 146 try {
123 147 saveZylInfo(file);
124 148 } catch (IOException e) {
125   - logger.error("保存临时文件异常", e);
  149 + log.error("保存临时文件异常", e);
126 150 }
127 151 }
128 152 }, 60, 60, TimeUnit.SECONDS);
... ...
src/main/java/com/bsth/server_rs/gps/GpsRestService.java
... ... @@ -38,6 +38,9 @@ public class GpsRestService {
38 38 @Value("${zyl.lines}")
39 39 private String zylLines;
40 40  
  41 + @Value("${zyl.devices}")
  42 + private String zylDevices;
  43 +
41 44 @Autowired
42 45 HistoryGpsDao historyGpsDao;
43 46  
... ... @@ -59,7 +62,7 @@ public class GpsRestService {
59 62 Collection<GpsEntity> result = new ArrayList<>();
60 63 Collection<GpsEntity> gpsEntities = GpsRealDataBuffer.all();
61 64 for (GpsEntity gpsEntity : gpsEntities) {
62   - if (zylLines.indexOf(String.format("%s,", gpsEntity.getLineId())) > -1) {
  65 + if (zylLines.indexOf(String.format("%s,", gpsEntity.getLineId())) > -1 || zylDevices.indexOf(gpsEntity.getDeviceId()) > -1) {
63 66 result.add(gpsEntity);
64 67 }
65 68 }
... ...
src/main/java/com/bsth/server_rs/gps/buffer/BasicDataBuffer.java
1   -package com.bsth.server_rs.gps.buffer;
2   -
3   -import java.util.HashMap;
4   -import java.util.Map;
5   -import java.util.Set;
6   -
7   -import org.springframework.stereotype.Component;
8   -
9   -import com.bsth.server_rs.gps.entity.LineInfo;
10   -
11   -/**
12   - * Created by panzhao on 2017/3/30.
13   - */
14   -@Component
15   -public class BasicDataBuffer {
16   -
17   - private static Map<Integer, LineInfo> LINEID_INFO = new HashMap<Integer, LineInfo>();
18   -
19   - private static Map<String, String> DEVICE_PLATE = new HashMap<String, String>();
20   -
21   - public static void putLine(Integer lineId, LineInfo info) {
22   - LINEID_INFO.put(lineId, info);
23   - }
24   -
25   - public static void putCar(String deviceId, String plateNo) {
26   - DEVICE_PLATE.put(deviceId, plateNo);
27   - }
28   -
29   - public static String getPlateByDevice(String deviceId) {
30   - return DEVICE_PLATE.get(deviceId);
31   - }
32   -
33   - public static Set<Integer> getAllLine() {
34   - return LINEID_INFO.keySet();
35   - }
36   -
37   - public static LineInfo getLineById(Integer lineId) {
38   - return LINEID_INFO.get(lineId);
39   - }
40   -}
  1 +package com.bsth.server_rs.gps.buffer;
  2 +
  3 +import java.util.HashMap;
  4 +import java.util.Map;
  5 +import java.util.Set;
  6 +
  7 +import org.springframework.stereotype.Component;
  8 +
  9 +import com.bsth.server_rs.gps.entity.LineInfo;
  10 +
  11 +/**
  12 + * Created by panzhao on 2017/3/30.
  13 + */
  14 +@Component
  15 +public class BasicDataBuffer {
  16 +
  17 + private static Map<Integer, LineInfo> LINEID_INFO = new HashMap<Integer, LineInfo>();
  18 +
  19 + private static Map<String, String> DEVICE_PLATE = new HashMap<String, String>();
  20 +
  21 + private static Map<String, String> DEVICE_INCODE = new HashMap<String, String>();
  22 +
  23 + private static Map<String, String> INCODE_PLATE = new HashMap<String, String>();
  24 +
  25 + private static Map<String, String> INCODE_INCODE = new HashMap<>();
  26 +
  27 + public static void putLine(Integer lineId, LineInfo info) {
  28 + LINEID_INFO.put(lineId, info);
  29 + }
  30 +
  31 + public static void putCar(String deviceId, String plateNo, String insideCode) {
  32 + DEVICE_PLATE.put(deviceId, plateNo);
  33 + DEVICE_INCODE.put(deviceId, insideCode);
  34 + INCODE_PLATE.put(insideCode, plateNo);
  35 + if (insideCode != null) {
  36 + INCODE_INCODE.put(insideCode.replaceAll("-", ""), insideCode);
  37 + }
  38 + }
  39 +
  40 + public static String getPlateByDevice(String deviceId) {
  41 + return DEVICE_PLATE.get(deviceId);
  42 + }
  43 +
  44 + public static String getIncodeByDevice(String deviceId) {
  45 + return DEVICE_INCODE.get(deviceId);
  46 + }
  47 +
  48 + public static String getIncodeByIncode(String insideCode) {
  49 + return INCODE_INCODE.get(insideCode);
  50 + }
  51 +
  52 + public static String getPlateByIncode(String insideCode) {
  53 + return INCODE_PLATE.get(insideCode);
  54 + }
  55 +
  56 + public static Set<Integer> getAllLine() {
  57 + return LINEID_INFO.keySet();
  58 + }
  59 +
  60 + public static LineInfo getLineById(Integer lineId) {
  61 + return LINEID_INFO.get(lineId);
  62 + }
  63 +}
... ...
src/main/java/com/bsth/server_rs/gps/buffer/BasicDataRefreshThread.java
... ... @@ -38,7 +38,7 @@ public class BasicDataRefreshThread extends Thread implements InitializingBean {
38 38 try {
39 39 String qline = "select a.id,in_use,line_code,name,start_station_name,start_station_first_time,start_station_end_time,end_station_name,end_station_first_time,end_station_end_time,company,branche_company,length,telephone,speed_limit,shanghai_linecode,line_play_type,up_travel_time,down_travel_time from bsth_c_line a left join bsth_c_line_information b on a.id = b.line where a.destroy = 0 and a.nature = 'hlwgj'";
40 40 String qstop = "select b.id,b.station_cod,b.station_name,b.road_coding,b.g_lonx,b.g_laty,b.shapes_type,b.radius,AsText(b.g_polygon_grid) as g_polygon_grid,a.line,a.line_code,a.directions,a.distances from bsth_c_stationroute a join bsth_c_station b on a.station = b.id where a.destroy = 0 order by a.line,a.directions,a.station_route_code";
41   - String qcar = "select equipment_code device_id, car_plate plate_no from bsth_c_cars";
  41 + String qcar = "select equipment_code device_id, car_plate plate_no, inside_code from bsth_c_cars";
42 42  
43 43 List<LineInfo> lines = jdbcTemplate.query(qline, new RowMapperLineInfo());
44 44 List<StopInfo> stops = jdbcTemplate.query(qstop, new RowMapperStopInfo());
... ... @@ -64,10 +64,7 @@ public class BasicDataRefreshThread extends Thread implements InitializingBean {
64 64 }
65 65  
66 66 for (Map<String, Object> car : cars) {
67   - String plateNo = (String)car.get("plate_no");
68   - if (plateNo != null) {
69   - BasicDataBuffer.putCar((String)car.get("device_id"), plateNo.replace("沪","").replace("-", ""));
70   - }
  67 + BasicDataBuffer.putCar((String)car.get("device_id"), (String)car.get("plate_no"), (String)car.get("inside_code"));
71 68 }
72 69  
73 70 logger.info("基础数据加载成功");
... ...
src/main/java/com/bsth/server_rs/gps/buffer/GpsRefreshThread.java
... ... @@ -66,8 +66,12 @@ public class GpsRefreshThread extends Thread{
66 66 if (jsonObj != null)
67 67 rs = JSON.parseArray(jsonObj.getString("data"), GpsEntity.class);
68 68  
69   - for(GpsEntity gps : rs){
70   - gps.setPlate(BasicDataBuffer.getPlateByDevice(gps.getDeviceId()));
  69 + for (GpsEntity gps : rs) {
  70 + String incode = BasicDataBuffer.getIncodeByDevice(gps.getDeviceId());
  71 + if (incode != null) {
  72 + gps.setPlate(incode);
  73 + //gps.setPlate(incode.replace("-", ""));
  74 + }
71 75 if (gps.getPlate() == null) {
72 76 continue;
73 77 }
... ...
src/main/java/com/bsth/server_rs/schedule/SchedulePlanService.java
1 1 package com.bsth.server_rs.schedule;
2 2  
3 3 import com.bsth.entity.ScheduleRealInfo;
  4 +import com.bsth.server_rs.gps.buffer.BasicDataBuffer;
4 5 import com.bsth.server_rs.gps.buffer.GpsRealDataBuffer;
5 6 import com.bsth.server_rs.gps.entity.GpsEntity;
6 7 import com.fasterxml.jackson.core.JsonProcessingException;
7 8 import com.fasterxml.jackson.databind.ObjectMapper;
8 9 import org.slf4j.Logger;
9 10 import org.slf4j.LoggerFactory;
  11 +import org.springframework.beans.factory.annotation.Autowired;
  12 +import org.springframework.jdbc.core.BatchPreparedStatementSetter;
  13 +import org.springframework.jdbc.core.JdbcTemplate;
10 14 import org.springframework.stereotype.Component;
11 15  
12 16 import javax.ws.rs.*;
13 17 import javax.ws.rs.core.MediaType;
  18 +import java.sql.PreparedStatement;
  19 +import java.sql.SQLException;
  20 +import java.util.ArrayList;
14 21 import java.util.HashMap;
15 22 import java.util.List;
16 23 import java.util.Map;
... ... @@ -24,10 +31,41 @@ public class SchedulePlanService {
24 31  
25 32 private ObjectMapper mapper = new ObjectMapper();
26 33  
  34 + @Autowired
  35 + private JdbcTemplate jdbcTemplate;
  36 +
27 37 @POST
28   - public Map<String, Object> save(List<ScheduleRealInfo> reals) throws JsonProcessingException {
  38 + public Map<String, Object> save(ScheduleRealInfo real) throws JsonProcessingException {
29 39 Map<String, Object> result = new HashMap<>();
30   - log.info(mapper.writeValueAsString(reals));
  40 + final List<ScheduleRealInfo> reals = new ArrayList<>();
  41 + reals.add(real);
  42 + log.error(mapper.writeValueAsString(reals));
  43 + jdbcTemplate.batchUpdate("insert into zyl.bsth_c_s_sp_real_info (schedule_date_str,xl_name,lp_name,cl_zbh,jsy,spy," +
  44 + "direction,qdz_name,zdz_name,fcsj,fcno,jhlc,bcsj,bc_type) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?)", new BatchPreparedStatementSetter() {
  45 + @Override
  46 + public void setValues(PreparedStatement ps, int i) throws SQLException {
  47 + ScheduleRealInfo sri = reals.get(i);
  48 + ps.setString(1, sri.getScheduleDateStr());
  49 + ps.setString(2, sri.getXlName());
  50 + ps.setString(3, sri.getLpName());
  51 + ps.setString(4, BasicDataBuffer.getIncodeByIncode(sri.getClZbh()));
  52 + ps.setString(5, sri.getJsy());
  53 + ps.setString(6, sri.getSpy());
  54 + ps.setString(7, sri.getXlDir());
  55 + ps.setString(8, sri.getQdzName());
  56 + ps.setString(9, sri.getZdzName());
  57 + ps.setString(10, sri.getFcsj());
  58 + ps.setInt(11, sri.getFcno());
  59 + ps.setDouble(12, sri.getJhlc());
  60 + ps.setInt(13, sri.getBcsj());
  61 + ps.setString(14, sri.getBcType());
  62 + }
  63 +
  64 + @Override
  65 + public int getBatchSize() {
  66 + return reals.size();
  67 + }
  68 + });
31 69 result.put("code", 0);
32 70 result.put("msg", "ok");
33 71  
... ...
src/main/java/com/bsth/server_rs/schedule/ScheduleRealService.java
... ... @@ -2,16 +2,24 @@ package com.bsth.server_rs.schedule;
2 2  
3 3 import com.bsth.entity.ScheduleExec;
4 4 import com.bsth.entity.ScheduleRealInfo;
  5 +import com.bsth.server_rs.gps.buffer.BasicDataBuffer;
5 6 import com.fasterxml.jackson.core.JsonProcessingException;
6 7 import com.fasterxml.jackson.databind.ObjectMapper;
  8 +import org.joda.time.DateTime;
7 9 import org.slf4j.Logger;
8 10 import org.slf4j.LoggerFactory;
  11 +import org.springframework.beans.factory.annotation.Autowired;
  12 +import org.springframework.jdbc.core.BatchPreparedStatementSetter;
  13 +import org.springframework.jdbc.core.JdbcTemplate;
9 14 import org.springframework.stereotype.Component;
10 15  
11 16 import javax.ws.rs.POST;
12 17 import javax.ws.rs.Path;
13 18 import javax.ws.rs.Produces;
14 19 import javax.ws.rs.core.MediaType;
  20 +import java.sql.PreparedStatement;
  21 +import java.sql.SQLException;
  22 +import java.util.ArrayList;
15 23 import java.util.HashMap;
16 24 import java.util.List;
17 25 import java.util.Map;
... ... @@ -25,11 +33,32 @@ public class ScheduleRealService {
25 33  
26 34 private ObjectMapper mapper = new ObjectMapper();
27 35  
  36 + @Autowired
  37 + private JdbcTemplate jdbcTemplate;
  38 +
28 39 @POST
29 40 @Path("/leave")
30   - public Map<String, Object> leave(List<ScheduleExec> execs) throws JsonProcessingException {
  41 + public Map<String, Object> leave(ScheduleExec exec) throws JsonProcessingException {
31 42 Map<String, Object> result = new HashMap<>();
32   - log.info(mapper.writeValueAsString(execs));
  43 + final List<ScheduleExec> execs = new ArrayList<>();
  44 + execs.add(exec);
  45 + log.error(mapper.writeValueAsString(execs));
  46 + jdbcTemplate.batchUpdate("update zyl.bsth_c_s_sp_real_info set fcsj_actual = ? where xl_name = ? and cl_zbh = ? and lp_name = ? and fcsj = ?", new BatchPreparedStatementSetter() {
  47 + @Override
  48 + public void setValues(PreparedStatement ps, int i) throws SQLException {
  49 + ScheduleExec scheduleExec = execs.get(i);
  50 + ps.setString(1, new DateTime(scheduleExec.getTime()).toString("HH:mm"));
  51 + ps.setString(2, scheduleExec.getLineName());
  52 + ps.setString(3, BasicDataBuffer.getIncodeByIncode(scheduleExec.getPlate()));
  53 + ps.setString(4, scheduleExec.getLpName());
  54 + ps.setString(5, scheduleExec.getFcsj());
  55 + }
  56 +
  57 + @Override
  58 + public int getBatchSize() {
  59 + return execs.size();
  60 + }
  61 + });
33 62 result.put("code", 0);
34 63 result.put("msg", "ok");
35 64  
... ... @@ -38,9 +67,27 @@ public class ScheduleRealService {
38 67  
39 68 @POST
40 69 @Path("/arrival")
41   - public Map<String, Object> arrival(List<ScheduleExec> execs) throws JsonProcessingException {
  70 + public Map<String, Object> arrival(ScheduleExec exec) throws JsonProcessingException {
42 71 Map<String, Object> result = new HashMap<>();
43   - log.info(mapper.writeValueAsString(execs));
  72 + final List<ScheduleExec> execs = new ArrayList<>();
  73 + execs.add(exec);
  74 + log.error(mapper.writeValueAsString(execs));
  75 + jdbcTemplate.batchUpdate("update zyl.bsth_c_s_sp_real_info set zdsj_actual = ? where xl_name = ? and cl_zbh = ? and lp_name = ? and fcsj = ?", new BatchPreparedStatementSetter() {
  76 + @Override
  77 + public void setValues(PreparedStatement ps, int i) throws SQLException {
  78 + ScheduleExec scheduleExec = execs.get(i);
  79 + ps.setString(1, new DateTime(scheduleExec.getTime()).toString("HH:mm"));
  80 + ps.setString(2, scheduleExec.getLineName());
  81 + ps.setString(3, BasicDataBuffer.getIncodeByIncode(scheduleExec.getPlate()));
  82 + ps.setString(4, scheduleExec.getLpName());
  83 + ps.setString(5, scheduleExec.getFcsj());
  84 + }
  85 +
  86 + @Override
  87 + public int getBatchSize() {
  88 + return execs.size();
  89 + }
  90 + });
44 91 result.put("code", 0);
45 92 result.put("msg", "ok");
46 93  
... ... @@ -49,9 +96,26 @@ public class ScheduleRealService {
49 96  
50 97 @POST
51 98 @Path("/destroy")
52   - public Map<String, Object> destroy(List<ScheduleExec> execs) throws JsonProcessingException {
  99 + public Map<String, Object> destroy(ScheduleExec exec) throws JsonProcessingException {
53 100 Map<String, Object> result = new HashMap<>();
54   - log.info(mapper.writeValueAsString(execs));
  101 + final List<ScheduleExec> execs = new ArrayList<>();
  102 + execs.add(exec);
  103 + log.error(mapper.writeValueAsString(execs));
  104 + jdbcTemplate.batchUpdate("update zyl.bsth_c_s_sp_real_info set status = -1 where xl_name = ? and cl_zbh = ? and lp_name = ? and fcsj = ?", new BatchPreparedStatementSetter() {
  105 + @Override
  106 + public void setValues(PreparedStatement ps, int i) throws SQLException {
  107 + ScheduleExec scheduleExec = execs.get(i);
  108 + ps.setString(1, scheduleExec.getLineName());
  109 + ps.setString(2, BasicDataBuffer.getIncodeByIncode(scheduleExec.getPlate()));
  110 + ps.setString(3, scheduleExec.getLpName());
  111 + ps.setString(4, scheduleExec.getFcsj());
  112 + }
  113 +
  114 + @Override
  115 + public int getBatchSize() {
  116 + return execs.size();
  117 + }
  118 + });
55 119 result.put("code", 0);
56 120 result.put("msg", "ok");
57 121  
... ...
src/main/java/com/bsth/server_rs/schedule/ScheduleTimeService.java
1 1 package com.bsth.server_rs.schedule;
2 2  
  3 +import com.bsth.entity.ScheduleRealInfo;
3 4 import com.bsth.entity.TimeTable;
  5 +import com.bsth.entity.TimeTableDetail;
  6 +import com.bsth.server_rs.gps.buffer.BasicDataBuffer;
4 7 import com.fasterxml.jackson.core.JsonProcessingException;
5 8 import com.fasterxml.jackson.databind.ObjectMapper;
6 9 import org.slf4j.Logger;
7 10 import org.slf4j.LoggerFactory;
  11 +import org.springframework.beans.factory.annotation.Autowired;
  12 +import org.springframework.jdbc.core.BatchPreparedStatementSetter;
  13 +import org.springframework.jdbc.core.JdbcTemplate;
8 14 import org.springframework.stereotype.Component;
9 15  
10 16 import javax.ws.rs.POST;
11 17 import javax.ws.rs.Path;
12 18 import javax.ws.rs.Produces;
13 19 import javax.ws.rs.core.MediaType;
  20 +import java.sql.PreparedStatement;
  21 +import java.sql.SQLException;
14 22 import java.util.HashMap;
15 23 import java.util.List;
16 24 import java.util.Map;
... ... @@ -27,11 +35,38 @@ public class ScheduleTimeService {
27 35  
28 36 private ObjectMapper mapper = new ObjectMapper();
29 37  
  38 + @Autowired
  39 + private JdbcTemplate jdbcTemplate;
  40 +
30 41 @POST
31 42 @Path("")
32 43 public Map<String, Object> save(List<TimeTable> timeTables) throws JsonProcessingException {
33 44 Map<String, Object> result = new HashMap<>();
34   - log.info(mapper.writeValueAsString(timeTables));
  45 + log.error(mapper.writeValueAsString(timeTables));
  46 + for (TimeTable timeTable : timeTables) {
  47 + jdbcTemplate.update("insert into zyl.bsth_c_s_ttinfo (xl,total_mileage,service_mileage,week_days) values(?,?,?,?)", new Object[]{ timeTable.getLineCode(), timeTable.getTotalMileage(), timeTable.getServiceMileage(), timeTable.getWeekDays() });
  48 + final List<TimeTableDetail> timeTableDetails = timeTable.getDetails();
  49 + jdbcTemplate.batchUpdate("insert into zyl.bsth_c_s_ttinfo_detail (bc_type,bcs,bcsj,lp_name,direction,start_station,end_station,leave_time,arrival_time) values (?,?,?,?,?,?,?,?,?)", new BatchPreparedStatementSetter() {
  50 + @Override
  51 + public void setValues(PreparedStatement ps, int i) throws SQLException {
  52 + TimeTableDetail timeTableDetail = timeTableDetails.get(i);
  53 + ps.setString(1, timeTableDetail.getBcType());
  54 + ps.setInt(2, timeTableDetail.getBcs());
  55 + ps.setInt(3, timeTableDetail.getBcsj());
  56 + ps.setString(4, timeTableDetail.getLpName());
  57 + ps.setInt(5, timeTableDetail.getDirection());
  58 + ps.setString(6, timeTableDetail.getStartStation());
  59 + ps.setString(7, timeTableDetail.getEndStation());
  60 + ps.setString(8, timeTableDetail.getLeaveTime());
  61 + ps.setString(9, timeTableDetail.getArrivalTime());
  62 + }
  63 +
  64 + @Override
  65 + public int getBatchSize() {
  66 + return timeTableDetails.size();
  67 + }
  68 + });
  69 + }
35 70 result.put("code", 0);
36 71 result.put("msg", "ok");
37 72  
... ...
src/main/resources/application-prod.properties
... ... @@ -8,7 +8,7 @@ spring.jpa.hibernate.naming_strategy= org.hibernate.cfg.ImprovedNamingStrategy
8 8 spring.jpa.database= MYSQL
9 9 spring.jpa.show-sql= false
10 10 spring.datasource.driver-class-name= com.mysql.jdbc.Driver
11   -spring.datasource.url= jdbc:mysql://10.10.150.103/control?useUnicode=true&characterEncoding=utf-8&useSSL=false
  11 +spring.datasource.url= jdbc:mysql://10.10.150.103/control?rewriteBatchedStatements=true&useUnicode=true&characterEncoding=utf-8&useSSL=false
12 12 spring.datasource.username= root
13 13 spring.datasource.password= Aa123456
14 14 #DATASOURCE
... ... @@ -28,4 +28,5 @@ http.control.secret.key= dVPHJkWUt5FhMT7jrM2dLV7QvlHAmZFd42rs1P0usBx8A7HZki
28 28  
29 29 http.gps.real.url= http://10.10.150.103:8080/transport_server/rtgps/
30 30  
31   -zyl.lines= 230329,
32 31 \ No newline at end of file
  32 +zyl.lines=
  33 +zyl.devices= 77S2C001,77S2C002,77S2C003,77S2C004,77S2C005,77S2C006,77S2C007,77S2C008,77S2C009,77S2C010,77S2C011,77S2C012,77S2C013,77S2C014,77S2C015,77S2C016,77S2C017,77S2C018,77S2C019,77S2C020,
33 34 \ No newline at end of file
... ...
src/main/resources/static/index.html deleted 100644 → 0
1   -<!DOCTYPE html>
2   -<html>
3   -<head>
4   -<title>调度系统营运数据接口</title>
5   -<meta charset="utf-8">
6   -<meta http-equiv="Expires" content="0">
7   -<meta http-equiv="Pragma" content="no-cache">
8   -<meta http-equiv="Cache-control" content="no-cache">
9   -<meta http-equiv="Cache" content="no-cache">
10   -<link rel="stylesheet"
11   - href="http://apps.bdimg.com/libs/bootstrap/3.2.0/css/bootstrap.min.css">
12   -<link rel="stylesheet" href="/simple_switch/simple.switch.three.css">
13   -<style>
14   -.table-wrap {
15   - height: 500px;
16   - overflow: auto;
17   -}
18   -
19   -#line2SysListTable .Switch_FlatRadius .SwitchLine:before {
20   - content: "老系统";
21   -}
22   -
23   -#line2SysListTable .Switch_FlatRadius .SwitchLine:after {
24   - content: "新系统";
25   -}
26   -
27   -#line2SysListTable .Switch_FlatRadius {
28   - width: 118px;
29   -}
30   -
31   -#line2SysListTable .Switch_FlatRadius .SwitchButton {
32   - width: 52px;
33   -}
34   -
35   -#line2SysListTable .Switch_FlatRadius .SwitchButton:before {
36   - left: 18px;
37   -}
38   -
39   -#line2SysListTable .Switch_FlatRadius .SwitchButton:after {
40   - left: 30px;
41   -}
42   -
43   -#line2SysListTable .Switch_FlatRadius.On .SwitchButton {
44   - left: 60px;
45   -}
46   -</style>
47   -</head>
48   -
49   -<body>
50   -
51   - <div class="row" style="margin: 15px;">
52   - <div class="col-md-12 well">
53   - <h4>
54   - Available SOAP services: <a href="/webservice" target="_blank">/webservice</a>
55   - </h4>
56   - <h4>
57   - WSDL: <a href="/webservice/CompanyService?wsdl" target="_blank">/webservice/CompanyService?wsdl</a>
58   - </h4>
59   - </div>
60   -
61   - <div class="col-lg-4 col-md-6 col-sm-12">
62   - <div class="bs-example"
63   - data-example-id="panel-without-body-with-table">
64   - <div class="panel panel-default">
65   - <!-- Default panel contents -->
66   - <div class="panel-heading">线路清单</div>
67   - <div class="panel-body">
68   - <p style="color: #ff2727;">屏蔽新老系统的底层数据差异,对外提供统一的数据输出</p>
69   - <p>1、使用员工号查询数据时,系统将参考 “线路人员配置” 以确定人员所在线路。</p>
70   - <p>2、使用公司编码查询数据时,系统将参考 “线路基础信息” 里的公司编码。</p>
71   - </div>
72   - <div class="table-wrap">
73   - <table class="table" id="line2SysListTable">
74   - <thead>
75   - <tr>
76   - <th>线路编码</th>
77   - <th>线路名称</th>
78   - <th>数据来源</th>
79   - </tr>
80   - </thead>
81   - <tbody>
82   - </tbody>
83   - </table>
84   - </div>
85   - </div>
86   - </div>
87   - </div>
88   -
89   - <div class="col-lg-8 col-md-6 col-sm-12">
90   - <div class="bs-example">
91   - <div class="panel panel-default">
92   - <div class="panel-heading">接口调试工具</div>
93   - <div style="padding: 15px; margin-top: 15px;">
94   - <form class="form-inline">
95   - <div class="form-group">
96   - <label>函数</label> <select class="form-control">
97   - <option value="returnCCInfo">returnCCInfo(获取出场班次信息)</option>
98   - <option value="returnJCInfo">returnJCInfo(获取进场班次信息)</option>
99   - </select>
100   - </div>
101   - &nbsp;
102   - <div class="form-group">
103   - <label>公司编码</label> <select class="form-control">
104   - <option value="55">55(上南)</option>
105   - <option value="22">22(金高)</option>
106   - <option value="05">05(杨高)</option>
107   - <option value="26">26(南汇)</option>
108   - </select>
109   - </div>
110   - &nbsp;
111   - <div class="form-group">
112   - <label>日期</label> <input type="date" class="form-control"
113   - style="width: 150px;" required>
114   - </div>
115   - <button type="submit" class="btn btn-primary">获取数据</button>
116   -
117   - <textarea class="form-control" rows="25"
118   - style="width: 100%; margin-top: 25px;"></textarea>
119   - </form>
120   -
121   - </div>
122   - </div>
123   - </div>
124   - </div>
125   - </div>
126   -
127   - <script id="line2sys-table-list-temp" type="text/html">
128   - {{each list as obj i}}
129   - <tr data-id="{{obj.lineCode}}" data-name="{{obj.lineName}}" {{if obj.new}}class="warning" {{/if}} >
130   - <td>{{obj.lineCode}}</td>
131   - <td>{{obj.lineName}}</td>
132   - <td>
133   - <input type="checkbox" {{if obj.new}}checked{{/if}} />
134   - </td>
135   - </tr>
136   - {{/each}}
137   -</script>
138   -
139   - <script src="http://apps.bdimg.com/libs/jquery/1.8.3/jquery.min.js"></script>
140   - <script
141   - src="http://apps.bdimg.com/libs/bootstrap/3.2.0/js/bootstrap.min.js"></script>
142   - <script src="/assets/js/template.js"></script>
143   - <script src="/simple_switch/simple.switch.min.js"></script>
144   -
145   - <script>
146   -
147   - //线路清单
148   - !function () {
149   - var f = arguments.callee;
150   -/* $.get('/line2System/all', function (list) {
151   - list.sort(function (a, b) {
152   - return b.new - a.new;
153   - });
154   - var htmlStr = template('line2sys-table-list-temp', {list: list});
155   - $('#line2SysListTable tbody').html(htmlStr);
156   -
157   - $('input[type=checkbox]').simpleSwitch({
158   - "theme": "FlatRadius"
159   - });
160   -
161   - $('input[type=checkbox]').on('change', function () {
162   - var $tr = $(this).parents('tr');
163   - var data = {
164   - lineCode: $tr.data('id'),
165   - lineName: $tr.data('name'),
166   - new: this.checked
167   - }
168   -
169   - $.post('/line2System/update', data, function (rs) {
170   - var $tr = $('#line2SysListTable tr[data-id=' + rs.lineCode + ']');
171   - $tr.attr('class', rs.new ? 'warning' : '');
172   - });
173   - });
174   - });*/
175   - }();
176   -
177   -</script>
178   -</body>
179   -</html>
180 0 \ No newline at end of file