Commit e48f4f6bcc153c82c5f3e323c47198094d09ef91

Authored by 王通
1 parent d45f6d0c

1.加入历史路单修改逻辑

src/main/java/com/bsth/entity/Business.java 0 → 100644
  1 +package com.bsth.entity;
  2 +
  3 +/**
  4 + * @author Hill
  5 + */
  6 +public class Business {
  7 +
  8 + private String businessCode;
  9 +
  10 + private String businessName;
  11 +
  12 + public String getBusinessCode() {
  13 + return businessCode;
  14 + }
  15 +
  16 + public void setBusinessCode(String businessCode) {
  17 + this.businessCode = businessCode;
  18 + }
  19 +
  20 + public String getBusinessName() {
  21 + return businessName;
  22 + }
  23 +
  24 + public void setBusinessName(String businessName) {
  25 + this.businessName = businessName;
  26 + }
  27 +}
src/main/java/com/bsth/server_rs/gps/buffer/BasicDataBuffer.java
@@ -4,6 +4,7 @@ import java.util.HashMap; @@ -4,6 +4,7 @@ import java.util.HashMap;
4 import java.util.Map; 4 import java.util.Map;
5 import java.util.Set; 5 import java.util.Set;
6 6
  7 +import com.bsth.entity.Business;
7 import org.springframework.stereotype.Component; 8 import org.springframework.stereotype.Component;
8 9
9 import com.bsth.server_rs.gps.entity.LineInfo; 10 import com.bsth.server_rs.gps.entity.LineInfo;
@@ -14,20 +15,27 @@ import com.bsth.server_rs.gps.entity.LineInfo; @@ -14,20 +15,27 @@ import com.bsth.server_rs.gps.entity.LineInfo;
14 @Component 15 @Component
15 public class BasicDataBuffer { 16 public class BasicDataBuffer {
16 17
17 - private static Map<Integer, LineInfo> LINEID_INFO = new HashMap<Integer, LineInfo>(); 18 + private static Map<Integer, LineInfo> LINEID_INFO = new HashMap<>();
  19 +
  20 + private static Map<String, LineInfo> LINENAME_INFO = new HashMap<>();
18 21
19 - private static Map<String, String> DEVICE_PLATE = new HashMap<String, String>(); 22 + private static Map<String, String> DEVICE_PLATE = new HashMap<>();
20 23
21 - private static Map<String, String> DEVICE_INCODE = new HashMap<String, String>(); 24 + private static Map<String, String> DEVICE_INCODE = new HashMap<>();
22 25
23 - private static Map<String, String> INCODE_PLATE = new HashMap<String, String>(); 26 + private static Map<String, String> INCODE_PLATE = new HashMap<>();
24 27
25 private static Map<String, String> INCODE_INCODE = new HashMap<>(); 28 private static Map<String, String> INCODE_INCODE = new HashMap<>();
26 29
27 private static Map<String, String> INCODE_VIN = new HashMap<>(); 30 private static Map<String, String> INCODE_VIN = new HashMap<>();
  31 +
  32 + private static Map<String, String> CODE_NAME = new HashMap<>();
  33 +
  34 + private static Map<String, String> BCODE_BNAME = new HashMap<>();
28 35
29 public static void putLine(Integer lineId, LineInfo info) { 36 public static void putLine(Integer lineId, LineInfo info) {
30 LINEID_INFO.put(lineId, info); 37 LINEID_INFO.put(lineId, info);
  38 + LINENAME_INFO.put(info.getLineName(), info);
31 } 39 }
32 40
33 public static void putCar(String deviceId, String plateNo, String insideCode, String vin) { 41 public static void putCar(String deviceId, String plateNo, String insideCode, String vin) {
@@ -40,6 +48,14 @@ public class BasicDataBuffer { @@ -40,6 +48,14 @@ public class BasicDataBuffer {
40 INCODE_INCODE.put(insideCode.replaceAll("-", ""), insideCode); 48 INCODE_INCODE.put(insideCode.replaceAll("-", ""), insideCode);
41 } 49 }
42 } 50 }
  51 +
  52 + public static void putCompany(Business business) {
  53 + CODE_NAME.put(business.getBusinessCode(), business.getBusinessName());
  54 + }
  55 +
  56 + public static void putBrancheCompany(Business business) {
  57 + BCODE_BNAME.put(business.getBusinessCode(), business.getBusinessName());
  58 + }
43 59
44 public static String getPlateByDevice(String deviceId) { 60 public static String getPlateByDevice(String deviceId) {
45 return DEVICE_PLATE.get(deviceId); 61 return DEVICE_PLATE.get(deviceId);
@@ -68,4 +84,16 @@ public class BasicDataBuffer { @@ -68,4 +84,16 @@ public class BasicDataBuffer {
68 public static LineInfo getLineById(Integer lineId) { 84 public static LineInfo getLineById(Integer lineId) {
69 return LINEID_INFO.get(lineId); 85 return LINEID_INFO.get(lineId);
70 } 86 }
  87 +
  88 + public static LineInfo getLineByName(String lineName) {
  89 + return LINENAME_INFO.get(lineName);
  90 + }
  91 +
  92 + public static String getCompanyNameByCode(String code) {
  93 + return CODE_NAME.get(code);
  94 + }
  95 +
  96 + public static String getBranchCompanyNameByCode(String code) {
  97 + return BCODE_BNAME.get(code);
  98 + }
71 } 99 }
src/main/java/com/bsth/server_rs/gps/buffer/BasicDataRefreshThread.java
@@ -6,10 +6,12 @@ import java.util.ArrayList; @@ -6,10 +6,12 @@ import java.util.ArrayList;
6 import java.util.List; 6 import java.util.List;
7 import java.util.Map; 7 import java.util.Map;
8 8
  9 +import com.bsth.entity.Business;
9 import org.slf4j.Logger; 10 import org.slf4j.Logger;
10 import org.slf4j.LoggerFactory; 11 import org.slf4j.LoggerFactory;
11 import org.springframework.beans.factory.InitializingBean; 12 import org.springframework.beans.factory.InitializingBean;
12 import org.springframework.beans.factory.annotation.Autowired; 13 import org.springframework.beans.factory.annotation.Autowired;
  14 +import org.springframework.jdbc.core.BeanPropertyRowMapper;
13 import org.springframework.jdbc.core.JdbcTemplate; 15 import org.springframework.jdbc.core.JdbcTemplate;
14 import org.springframework.jdbc.core.RowMapper; 16 import org.springframework.jdbc.core.RowMapper;
15 import org.springframework.stereotype.Component; 17 import org.springframework.stereotype.Component;
@@ -36,13 +38,17 @@ public class BasicDataRefreshThread extends Thread implements InitializingBean { @@ -36,13 +38,17 @@ public class BasicDataRefreshThread extends Thread implements InitializingBean {
36 38
37 private void loadBasicData() { 39 private void loadBasicData() {
38 try { 40 try {
39 - String qline = "select a.id,in_use,line_code,name,start_station_name,start_station_first_time,start_station_end_time,end_station_name,end_station_first_time,end_station_end_time,company,branche_company,length,telephone,speed_limit,shanghai_linecode,line_play_type,up_travel_time,down_travel_time from bsth_c_line a left join bsth_c_line_information b on a.id = b.line where a.destroy = 0 and a.nature = 'hlwgj'"; 41 + 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";
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"; 42 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, inside_code, vin from bsth_c_cars"; 43 String qcar = "select equipment_code device_id, car_plate plate_no, inside_code, vin from bsth_c_cars";
  44 + String qcompany = "select business_code, business_name from bsth_c_business where up_code = 88";
  45 + String qbcompany = "select business_code, business_name from bsth_c_business where up_code = 77";
42 46
43 List<LineInfo> lines = jdbcTemplate.query(qline, new RowMapperLineInfo()); 47 List<LineInfo> lines = jdbcTemplate.query(qline, new RowMapperLineInfo());
44 List<StopInfo> stops = jdbcTemplate.query(qstop, new RowMapperStopInfo()); 48 List<StopInfo> stops = jdbcTemplate.query(qstop, new RowMapperStopInfo());
45 List<Map<String, Object>> cars = jdbcTemplate.queryForList(qcar); 49 List<Map<String, Object>> cars = jdbcTemplate.queryForList(qcar);
  50 + List<Business> company = jdbcTemplate.query(qcompany, BeanPropertyRowMapper.newInstance(Business.class));
  51 + List<Business> bcompany = jdbcTemplate.query(qbcompany, BeanPropertyRowMapper.newInstance(Business.class));
46 52
47 // 缓存线路基本信息 53 // 缓存线路基本信息
48 for (LineInfo line : lines) { 54 for (LineInfo line : lines) {
@@ -66,6 +72,14 @@ public class BasicDataRefreshThread extends Thread implements InitializingBean { @@ -66,6 +72,14 @@ public class BasicDataRefreshThread extends Thread implements InitializingBean {
66 for (Map<String, Object> car : cars) { 72 for (Map<String, Object> car : cars) {
67 BasicDataBuffer.putCar((String) car.get("device_id"), (String) car.get("plate_no"), (String) car.get("inside_code"), (String) car.get("vin")); 73 BasicDataBuffer.putCar((String) car.get("device_id"), (String) car.get("plate_no"), (String) car.get("inside_code"), (String) car.get("vin"));
68 } 74 }
  75 +
  76 + for (Business business : company) {
  77 + BasicDataBuffer.putCompany(business);
  78 + }
  79 +
  80 + for (Business business : bcompany) {
  81 + BasicDataBuffer.putBrancheCompany(business);
  82 + }
69 83
70 logger.info("基础数据加载成功"); 84 logger.info("基础数据加载成功");
71 }catch (Exception e){ 85 }catch (Exception e){
src/main/java/com/bsth/server_rs/schedule/WaybillService.java
1 package com.bsth.server_rs.schedule; 1 package com.bsth.server_rs.schedule;
2 2
3 import com.bsth.entity.Waybill; 3 import com.bsth.entity.Waybill;
  4 +import com.bsth.server_rs.gps.buffer.BasicDataBuffer;
  5 +import com.bsth.server_rs.gps.buffer.BasicDataRefreshThread;
  6 +import com.bsth.server_rs.gps.entity.LineInfo;
  7 +import com.bsth.server_rs.gps.entity.StopInfo;
4 import com.fasterxml.jackson.core.JsonProcessingException; 8 import com.fasterxml.jackson.core.JsonProcessingException;
5 import com.fasterxml.jackson.databind.ObjectMapper; 9 import com.fasterxml.jackson.databind.ObjectMapper;
  10 +import org.joda.time.DateTime;
6 import org.slf4j.Logger; 11 import org.slf4j.Logger;
7 import org.slf4j.LoggerFactory; 12 import org.slf4j.LoggerFactory;
  13 +import org.springframework.beans.factory.InitializingBean;
8 import org.springframework.beans.factory.annotation.Autowired; 14 import org.springframework.beans.factory.annotation.Autowired;
9 import org.springframework.jdbc.core.BatchPreparedStatementSetter; 15 import org.springframework.jdbc.core.BatchPreparedStatementSetter;
10 import org.springframework.jdbc.core.JdbcTemplate; 16 import org.springframework.jdbc.core.JdbcTemplate;
  17 +import org.springframework.scheduling.annotation.EnableScheduling;
  18 +import org.springframework.scheduling.annotation.Scheduled;
11 import org.springframework.stereotype.Component; 19 import org.springframework.stereotype.Component;
12 20
13 import javax.ws.rs.POST; 21 import javax.ws.rs.POST;
14 import javax.ws.rs.Path; 22 import javax.ws.rs.Path;
15 import javax.ws.rs.Produces; 23 import javax.ws.rs.Produces;
16 import javax.ws.rs.core.MediaType; 24 import javax.ws.rs.core.MediaType;
  25 +import java.io.BufferedReader;
  26 +import java.io.FileReader;
  27 +import java.nio.charset.StandardCharsets;
  28 +import java.sql.Date;
17 import java.sql.PreparedStatement; 29 import java.sql.PreparedStatement;
18 import java.sql.SQLException; 30 import java.sql.SQLException;
19 -import java.util.HashMap;  
20 -import java.util.List;  
21 -import java.util.Map; 31 +import java.util.*;
22 32
23 @Component 33 @Component
24 @Path("/waybill") 34 @Path("/waybill")
25 @Produces({MediaType.APPLICATION_JSON}) 35 @Produces({MediaType.APPLICATION_JSON})
26 -public class WaybillService { 36 +@EnableScheduling
  37 +public class WaybillService implements InitializingBean {
27 38
28 private final static Logger log = LoggerFactory.getLogger(WaybillService.class); 39 private final static Logger log = LoggerFactory.getLogger(WaybillService.class);
29 40
@@ -32,53 +43,122 @@ public class WaybillService { @@ -32,53 +43,122 @@ public class WaybillService {
32 @Autowired 43 @Autowired
33 private JdbcTemplate jdbcTemplate; 44 private JdbcTemplate jdbcTemplate;
34 45
  46 + @Autowired
  47 + private BasicDataRefreshThread basicDataRefreshThread;
  48 +
  49 + private Set<String> adjustExps = new HashSet<>();
  50 +
  51 + @Scheduled(cron = "0 0 0/2 * * *")
  52 + public void task() {
  53 + DateTime current = new DateTime();
  54 + for (int i = 0;i < 2;i++) {
  55 + current = current.minusDays(1);
  56 + String rq = current.toString("yyyy-MM-dd");
  57 + jdbcTemplate.update("delete from bsth_c_s_sp_info_real where schedule_date_str = ? and xl_name like '临港中运量%'", new Object[] { rq });
  58 + jdbcTemplate.update("insert into bsth_c_s_sp_info_real SELECT * FROM zyl.bsth_c_s_sp_info_real_1 where schedule_date_str = ?", new Object[] { rq });
  59 + }
  60 + }
  61 +
35 @POST 62 @POST
36 public Map<String, Object> save(final List<Waybill> waybills) throws JsonProcessingException { 63 public Map<String, Object> save(final List<Waybill> waybills) throws JsonProcessingException {
37 Map<String, Object> result = new HashMap<>(); 64 Map<String, Object> result = new HashMap<>();
38 log.error(mapper.writeValueAsString(waybills)); 65 log.error(mapper.writeValueAsString(waybills));
39 - jdbcTemplate.batchUpdate("insert into zyl.bsth_c_s_sp_real_info (schedule_date_str,real_exec_date,xl_name,lp_name,cl_zbh,j_gh,j_name,s_gh,s_name," +  
40 - "xl_dir,qdz_name,qdz_code,zdz_name,zdz_code,fcsj,zdsj,fcno,bcs,jhlc,bcsj,bc_type,fcsj_actual,zdsj_actual,status,dfsj,gs_bm,fgs_bm,remarks) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", new BatchPreparedStatementSetter() {  
41 - @Override  
42 - public void setValues(PreparedStatement ps, int i) throws SQLException {  
43 - Waybill sri = waybills.get(i);  
44 - ps.setString(1, sri.getScheduleDateStr());  
45 - ps.setString(2, sri.getRealExecDate());  
46 - ps.setString(3, sri.getXlName());  
47 - ps.setString(4, sri.getLpName());  
48 - ps.setString(5, sri.getClZbh());  
49 - ps.setString(6, sri.getjGh());  
50 - ps.setString(7, sri.getjName());  
51 - ps.setString(8, sri.getsGh());  
52 - ps.setString(9, sri.getsName());  
53 - ps.setString(10, sri.getXlDir());  
54 - ps.setString(11, sri.getQdzName());  
55 - ps.setString(12, sri.getQdzCode());  
56 - ps.setString(13, sri.getZdzName());  
57 - ps.setString(14, sri.getZdzCode());  
58 - ps.setString(15, sri.getFcsj());  
59 - ps.setString(16, sri.getZdsj());  
60 - ps.setInt(17, sri.getFcno());  
61 - ps.setInt(18, sri.getBcs());  
62 - ps.setDouble(19, sri.getJhlc());  
63 - ps.setInt(20, sri.getBcsj());  
64 - ps.setString(21, sri.getBcType());  
65 - ps.setString(22, sri.getFcsjActual());  
66 - ps.setString(23, sri.getZdsjActual());  
67 - ps.setInt(24, sri.getStatus());  
68 - ps.setString(25, sri.getDfsj());  
69 - ps.setString(26, sri.getGsBm());  
70 - ps.setString(27, sri.getFgsBm());  
71 - ps.setString(28, sri.getRemarks());  
72 - } 66 + if (waybills.size() > 0) {
  67 + Waybill waybill = waybills.get(0);
  68 + String scheduleDateStr = new DateTime(Long.parseLong(waybill.getScheduleDateStr())).toString("yyyy-MM-dd");
  69 + jdbcTemplate.update("delete from zyl.bsth_c_s_sp_info_real_1 where schedule_date_str = ? and xl_name = ?", new Object[] { scheduleDateStr, waybill.getXlName() });
  70 + jdbcTemplate.batchUpdate("insert into zyl.bsth_c_s_sp_info_real_1 (schedule_date_str,real_exec_date,xl_name,lp_name,cl_zbh,j_gh,j_name,s_gh,s_name," +
  71 + "xl_dir,qdz_name,qdz_code,zdz_name,zdz_code,fcsj,zdsj,fcno,bcs,jhlc,bcsj,bc_type,fcsj_actual,zdsj_actual,status,dfsj,gs_bm,fgs_bm,remarks,schedule_date,xl_bm,jhlc_orig,adjust_exps,gs_name,fgs_name) values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", new BatchPreparedStatementSetter() {
  72 + @Override
  73 + public void setValues(PreparedStatement ps, int i) throws SQLException {
  74 + Waybill sri = waybills.get(i);
  75 + LineInfo lineInfo = BasicDataBuffer.getLineByName(sri.getXlName());
  76 + DateTime scheduleDate = new DateTime(Long.parseLong(sri.getScheduleDateStr())), realScheduleDate = new DateTime(Long.parseLong(sri.getRealExecDate()));
  77 + int direction = Integer.parseInt(sri.getXlDir()) - 1;
  78 + String clzbh = sri.getClZbh().replace("LG", "LG-"), remark = sri.getRemarks();
  79 + String jgh = sri.getjGh() != null ? sri.getjGh().replace("05-", "") : "", sgh = sri.getsGh() != null ? sri.getsGh().replace("05-", "") : "";
  80 + String adjustExp = sri.getStatus() == -1 ? getAdjustExp(remark) : null;
  81 + sri.setScheduleDateStr(scheduleDate.toString("yyyy-MM-dd"));
  82 + sri.setRealExecDate(realScheduleDate.toString("yyyy-MM-dd"));
  83 + ps.setString(1, sri.getScheduleDateStr());
  84 + ps.setString(2, sri.getRealExecDate());
  85 + ps.setString(3, sri.getXlName());
  86 + ps.setString(4, sri.getLpName());
  87 + ps.setString(5, clzbh);
  88 + ps.setString(6, jgh);
  89 + ps.setString(7, sri.getjName());
  90 + ps.setString(8, sgh);
  91 + ps.setString(9, sri.getsName());
  92 + ps.setString(10, String.valueOf(direction));
  93 + ps.setString(11, sri.getQdzName());
  94 + ps.setString(12, getStationCode(lineInfo, direction, sri.getQdzName()));
  95 + ps.setString(13, sri.getZdzName());
  96 + ps.setString(14, getStationCode(lineInfo, direction, sri.getZdzName()));
  97 + ps.setString(15, sri.getFcsj());
  98 + ps.setString(16, sri.getZdsj());
  99 + ps.setInt(17, sri.getFcno());
  100 + ps.setInt(18, i + 1);
  101 + ps.setDouble(19, sri.getJhlc());
  102 + ps.setInt(20, sri.getBcsj());
  103 + ps.setString(21, sri.getBcType());
  104 + ps.setString(22, sri.getFcsjActual());
  105 + ps.setString(23, sri.getZdsjActual());
  106 + ps.setInt(24, sri.getStatus());
  107 + ps.setString(25, sri.getDfsj());
  108 + ps.setString(26, lineInfo.getCompany());
  109 + ps.setString(27, lineInfo.getBrancheCompany());
  110 + ps.setString(28, sri.getRemarks());
  111 + ps.setDate(29, new Date(scheduleDate.getMillis()));
  112 + ps.setString(30, String.valueOf(lineInfo.getId()));
  113 + ps.setDouble(31, sri.getJhlc());
  114 + ps.setString(32, adjustExp);
  115 + ps.setString(33, BasicDataBuffer.getCompanyNameByCode(lineInfo.getCompany()));
  116 + ps.setString(34, BasicDataBuffer.getBranchCompanyNameByCode(lineInfo.getBrancheCompany()));
  117 + }
73 118
74 - @Override  
75 - public int getBatchSize() {  
76 - return waybills.size();  
77 - }  
78 - }); 119 + @Override
  120 + public int getBatchSize() {
  121 + return waybills.size();
  122 + }
  123 + });
  124 + }
79 result.put("code", 0); 125 result.put("code", 0);
80 result.put("msg", "ok"); 126 result.put("msg", "ok");
81 127
82 return result; 128 return result;
83 } 129 }
  130 +
  131 + private String getStationCode(LineInfo lineInfo, int direction, String stationName) {
  132 + List<StopInfo> stopInfos = direction == 0 ? lineInfo.getStopsUp() : lineInfo.getStopsDown();
  133 + for (StopInfo stopInfo : stopInfos) {
  134 + if (stationName.equals(stopInfo.getStationName().replace("(", "").replace("(", "").replace("起点站", "").replace("终点站","").replace(")","").replace(")", ""))) {
  135 + return stopInfo.getStationCod();
  136 + }
  137 + }
  138 +
  139 + return null;
  140 + }
  141 +
  142 + private String getAdjustExp(String remark) {
  143 + int idx = -1;
  144 + String exp = null;
  145 + for (String adjustExp : adjustExps) {
  146 + int currentIdx = remark.indexOf(adjustExp);
  147 + if (currentIdx > idx) {
  148 + idx = currentIdx;
  149 + exp = adjustExp;
  150 + }
  151 + }
  152 +
  153 + return exp == null ? "其他" : exp;
  154 + }
  155 +
  156 + @Override
  157 + public void afterPropertiesSet() throws Exception {
  158 + adjustExps.addAll(Arrays.asList("配车", "保养", "故障", "肇事", "路阻", "纠纷", "缺人", "客稀", "缺车", "气候", "援外", "吊慢", "抽减", "路救抛锚", "其他"));
  159 + /*BufferedReader reader = new BufferedReader(new FileReader("E:/waybill.txt"));
  160 + String line = reader.readLine();
  161 + List<Waybill> waybills = mapper.readValue(line, mapper.getTypeFactory().constructParametricType(List.class, Waybill.class));
  162 + save(waybills);*/
  163 + }
84 } 164 }