Commit a306fa601a91c83469b3109bde9ea4cb6ac487d8

Authored by 潘钊
2 parents f7603ac9 c88a1206

Merge branch 'minhang' into qingpu

Showing 31 changed files with 2384 additions and 1346 deletions

Too many changes to show.

To preserve performance only 31 of 109 files are displayed.

src/main/java/com/bsth/controller/DeviceGpsController.java 0 → 100644
  1 +package com.bsth.controller;
  2 +
  3 +import java.io.BufferedOutputStream;
  4 +import java.io.BufferedReader;
  5 +import java.io.File;
  6 +import java.io.FileInputStream;
  7 +import java.io.IOException;
  8 +import java.io.InputStreamReader;
  9 +import java.io.OutputStream;
  10 +import java.text.SimpleDateFormat;
  11 +import java.util.ArrayList;
  12 +import java.util.Date;
  13 +import java.util.HashMap;
  14 +import java.util.List;
  15 +import java.util.Map;
  16 +
  17 +import javax.servlet.http.HttpServletRequest;
  18 +import javax.servlet.http.HttpServletResponse;
  19 +
  20 +import org.apache.commons.lang.StringEscapeUtils;
  21 +import org.apache.poi.hssf.usermodel.HSSFCell;
  22 +import org.apache.poi.hssf.usermodel.HSSFRichTextString;
  23 +import org.apache.poi.hssf.usermodel.HSSFRow;
  24 +import org.apache.poi.hssf.usermodel.HSSFSheet;
  25 +import org.apache.poi.hssf.usermodel.HSSFWorkbook;
  26 +import org.springframework.beans.BeanUtils;
  27 +import org.springframework.beans.factory.annotation.Autowired;
  28 +import org.springframework.util.StringUtils;
  29 +import org.springframework.web.bind.annotation.PathVariable;
  30 +import org.springframework.web.bind.annotation.RequestMapping;
  31 +import org.springframework.web.bind.annotation.RequestMethod;
  32 +import org.springframework.web.bind.annotation.RequestParam;
  33 +import org.springframework.web.bind.annotation.RestController;
  34 +import org.springframework.web.multipart.MultipartFile;
  35 +
  36 +import com.bsth.data.gpsdata.GpsEntity;
  37 +import com.bsth.data.gpsdata.GpsRealData;
  38 +import com.fasterxml.jackson.core.JsonParseException;
  39 +import com.fasterxml.jackson.databind.JsonMappingException;
  40 +import com.fasterxml.jackson.databind.ObjectMapper;
  41 +import com.fasterxml.jackson.databind.util.BeanUtil;
  42 +
  43 +@RestController
  44 +@RequestMapping("devicegps")
  45 +public class DeviceGpsController {
  46 +
  47 + @Autowired
  48 + GpsRealData gpsRealData;
  49 +
  50 + @RequestMapping(value = "/real/line/{lineCode}")
  51 + public List<GpsEntity> findByLineCode(@PathVariable("lineCode") String lineCode) {
  52 + return gpsRealData.getByLine(lineCode);
  53 + }
  54 +
  55 + @RequestMapping(value = "/real/all")
  56 + public List<GpsEntity> findByLineCodes() {
  57 + return new ArrayList<>(gpsRealData.all());
  58 + }
  59 +
  60 + @RequestMapping(value = "/open", method = RequestMethod.POST)
  61 + public Map<String, Object> open(@RequestParam(value = "_txt_", required = false) MultipartFile file, HttpServletRequest request) {
  62 + Map<String, Object> res = new HashMap<>();
  63 + File rf = new File(request.getServletContext().getRealPath("/temp"), System.currentTimeMillis() + "");
  64 + File rd = rf.getParentFile();
  65 + if (!rd.exists()) {
  66 + rd.mkdirs();
  67 + }
  68 +
  69 + BufferedReader reader = null;
  70 + try {
  71 + file.transferTo(rf);
  72 + reader = new BufferedReader(new InputStreamReader(new FileInputStream(rf), "GBK"));
  73 + String line = null;
  74 + List<Map<String, Object>> data = new ArrayList<>();
  75 + while ((line = reader.readLine()) != null) {
  76 + if (!StringUtils.isEmpty(line)) {
  77 + String temp[] = line.split(",");
  78 + if (temp.length != 4) {
  79 + res.put("errCode", 1);
  80 + res.put("msg", "txt文档格式错误,请检查");
  81 + return res;
  82 + }
  83 + Map<String, Object> info = new HashMap<>();
  84 + info.put("lineName", temp[0]);
  85 + info.put("lineCode", temp[1]);
  86 + info.put("inCode", temp[2]);
  87 + info.put("deviceId", temp[3]);
  88 + info.put("detail", gpsRealData.get(temp[3]));
  89 +
  90 + data.add(info);
  91 + }
  92 + }
  93 + // 删除临时文件
  94 + rf.delete();
  95 + res.put("errCode", 0);
  96 + res.put("data", data);
  97 + } catch (IllegalStateException e) {
  98 + // TODO Auto-generated catch block
  99 + e.printStackTrace();
  100 + } catch (IOException e) {
  101 + // TODO Auto-generated catch block
  102 + e.printStackTrace();
  103 + } finally {
  104 + try {
  105 + if (reader != null) reader.close();
  106 + } catch (IOException e) {
  107 + // TODO Auto-generated catch block
  108 + e.printStackTrace();
  109 + }
  110 + }
  111 +
  112 + return res;
  113 + }
  114 +
  115 + @SuppressWarnings("unchecked")
  116 + @RequestMapping(value = "/opened", method = RequestMethod.POST)
  117 + public Map<String, Object> opened(@RequestParam(value = "json")String json) {
  118 + json = StringEscapeUtils.unescapeHtml(json);
  119 + Map<String, Object> res = new HashMap<>();
  120 + List<Map<String, Object>> data = null;
  121 + try {
  122 + data = new ObjectMapper().readValue(json, List.class);
  123 + for (Map<String, Object> info : data) {
  124 + info.put("detail", gpsRealData.findByDeviceId((String)info.get("deviceId")));
  125 + }
  126 +
  127 + res.put("errCode", 0);
  128 + res.put("data", data);
  129 + } catch (JsonParseException e) {
  130 + // TODO Auto-generated catch block
  131 + e.printStackTrace();
  132 + } catch (JsonMappingException e) {
  133 + // TODO Auto-generated catch block
  134 + e.printStackTrace();
  135 + } catch (IOException e) {
  136 + // TODO Auto-generated catch block
  137 + e.printStackTrace();
  138 + }
  139 +
  140 + return res;
  141 + }
  142 +
  143 + @SuppressWarnings("unchecked")
  144 + @RequestMapping(value = "/export", method = RequestMethod.POST)
  145 + public void export(@RequestParam(value = "json")String json, HttpServletResponse response) {
  146 + json = StringEscapeUtils.unescapeHtml(json);
  147 + List<Map<String, Object>> data = null;
  148 + OutputStream out = null;
  149 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  150 + try {
  151 + data = new ObjectMapper().readValue(json, List.class);
  152 + for (Map<String, Object> info : data) {
  153 + Map<String, Object> detail = (Map<String, Object>)info.get("detail");
  154 + if (detail != null) {
  155 + info.put("lineId", detail.get("lineId"));
  156 + info.put("valid", (int)detail.get("valid") == 0 ? "有效" : "无效");
  157 + info.put("timestamp", sdf.format(new Date((Long)detail.get("timestamp"))));
  158 + info.put("version", detail.get("version"));
  159 + } else {
  160 + info.put("lineId", "");
  161 + info.put("valid", "");
  162 + info.put("timestamp", "");
  163 + info.put("version", "");
  164 + }
  165 + }
  166 +
  167 + List<Header> head = new ArrayList<>();
  168 + head.add(new Header("线路编码", "lineCode"));
  169 + head.add(new Header("线路名称", "lineName"));
  170 + head.add(new Header("内部编码", "inCode"));
  171 + head.add(new Header("识别码", "deviceId"));
  172 + head.add(new Header("线路ID", "lineId"));
  173 + head.add(new Header("GPS", "valid"));
  174 + head.add(new Header("report", "timestamp"));
  175 + head.add(new Header("版本", "version"));
  176 +
  177 + // 清空response
  178 + response.reset();
  179 + // 设置response的Header
  180 + response.addHeader("Content-Disposition", "attachment;filename=" + System.currentTimeMillis() + ".xls");
  181 + response.setContentType("application/vnd.ms-excel;charset=UTF-8");
  182 + out = new BufferedOutputStream(response.getOutputStream());
  183 + excel(head, data, out);
  184 + out.flush();
  185 + } catch (JsonParseException e) {
  186 + // TODO Auto-generated catch block
  187 + e.printStackTrace();
  188 + } catch (JsonMappingException e) {
  189 + // TODO Auto-generated catch block
  190 + e.printStackTrace();
  191 + } catch (IOException e) {
  192 + // TODO Auto-generated catch block
  193 + e.printStackTrace();
  194 + } finally {
  195 + try {
  196 + if (out != null) out.close();
  197 + } catch (IOException e) {
  198 + e.printStackTrace();
  199 + }
  200 + }
  201 + }
  202 +
  203 + private void excel(List<Header> head, List<Map<String, Object>> data, OutputStream out) throws IOException {
  204 + // 声明一个工作薄
  205 + HSSFWorkbook wb = new HSSFWorkbook();
  206 + // 生成一个表格
  207 + HSSFSheet sheet = wb.createSheet("1");
  208 + // 产生表格标题行
  209 + HSSFRow row = sheet.createRow(0);
  210 + for (int i = 0;i < head.size();i++) {
  211 + HSSFCell cell = row.createCell(i);
  212 + HSSFRichTextString text = new HSSFRichTextString(head.get(i).getDescribe());
  213 + cell.setCellValue(text);
  214 + }
  215 +
  216 + int rownum = 1;
  217 + for (Map<String, Object> map : data) {
  218 + HSSFRow r = sheet.createRow(rownum);
  219 + for (int i = 0;i < head.size();i++) {
  220 + HSSFCell cell = r.createCell(i);
  221 + HSSFRichTextString text = new HSSFRichTextString(String.valueOf(map.get(head.get(i).getField())));
  222 + cell.setCellValue(text);
  223 + }
  224 + rownum++;
  225 + }
  226 +
  227 + wb.write(out);
  228 + wb.close();
  229 + }
  230 +
  231 + final class Header {
  232 + private String describe;
  233 + private String field;
  234 +
  235 + Header(){
  236 +
  237 + }
  238 +
  239 + Header(String describe, String field) {
  240 + this.describe = describe;
  241 + this.field = field;
  242 + }
  243 +
  244 + public String getDescribe() {
  245 + return describe;
  246 + }
  247 +
  248 + public void setDescribe(String describe) {
  249 + this.describe = describe;
  250 + }
  251 +
  252 + public String getField() {
  253 + return field;
  254 + }
  255 +
  256 + public void setField(String field) {
  257 + this.field = field;
  258 + }
  259 + }
  260 +}
src/main/java/com/bsth/controller/directive/DirectiveController.java
@@ -71,6 +71,30 @@ public class DirectiveController { @@ -71,6 +71,30 @@ public class DirectiveController {
71 SysUser user = SecurityUtils.getCurrentUser(); 71 SysUser user = SecurityUtils.getCurrentUser();
72 return directiveService.lineChange(nbbm, lineId, user.getUserName()); 72 return directiveService.lineChange(nbbm, lineId, user.getUserName());
73 } 73 }
  74 +
  75 + /**
  76 + *
  77 + * @Title: lineChangeByDevice
  78 + * @Description: TODO(切换线路)
  79 + * @param @param deviceId 设备编码
  80 + * @param @param lineId 新线路编码
  81 + * @throws
  82 + */
  83 + @RequestMapping(value = "/lineChangeByDevice", method = RequestMethod.POST)
  84 + public int lineChangeByDevice(@RequestParam String deviceId, @RequestParam String lineId){
  85 + SysUser user = SecurityUtils.getCurrentUser();
  86 + return directiveService.lineChangeByDeviceId(deviceId, lineId, user.getUserName());
  87 + }
  88 +
  89 + /**
  90 + * 刷新线路文件
  91 + * @param deviceId 设备号
  92 + * @return
  93 + */
  94 + @RequestMapping(value = "/refreshLineFile", method = RequestMethod.POST)
  95 + public int refreshLineFile(@RequestParam String deviceId){
  96 + return directiveService.refreshLineFile(deviceId);
  97 + }
74 98
75 /** 99 /**
76 * 100 *
src/main/java/com/bsth/controller/gps/GpsController.java
@@ -4,10 +4,7 @@ import java.util.List; @@ -4,10 +4,7 @@ import java.util.List;
4 import java.util.Map; 4 import java.util.Map;
5 5
6 import org.springframework.beans.factory.annotation.Autowired; 6 import org.springframework.beans.factory.annotation.Autowired;
7 -import org.springframework.web.bind.annotation.PathVariable;  
8 -import org.springframework.web.bind.annotation.RequestMapping;  
9 -import org.springframework.web.bind.annotation.RequestParam;  
10 -import org.springframework.web.bind.annotation.RestController; 7 +import org.springframework.web.bind.annotation.*;
11 8
12 import com.bsth.data.BasicData; 9 import com.bsth.data.BasicData;
13 import com.bsth.data.gpsdata.GpsEntity; 10 import com.bsth.data.gpsdata.GpsEntity;
@@ -46,6 +43,16 @@ public class GpsController { @@ -46,6 +43,16 @@ public class GpsController {
46 return gpsRealData.get(Splitter.on(",").splitToList(lineCodes)); 43 return gpsRealData.get(Splitter.on(",").splitToList(lineCodes));
47 } 44 }
48 45
  46 + @RequestMapping(value = "/allDevices")
  47 + public Iterable<String> allDevices(){
  48 + return gpsRealData.allDevices();
  49 + }
  50 +
  51 + @RequestMapping(value = "/removeRealGps", method = RequestMethod.POST)
  52 + public Map<String, Object> removeRealGps(@RequestParam String device){
  53 + return gpsService.removeRealGps(device);
  54 + }
  55 +
49 /** 56 /**
50 * 57 *
51 * @Title: history @Description: TODO(这个方法给测试页面用) @throws 58 * @Title: history @Description: TODO(这个方法给测试页面用) @throws
src/main/java/com/bsth/controller/oil/CwjyController.java 0 → 100644
  1 +package com.bsth.controller.oil;
  2 +
  3 +
  4 +import java.util.Date;
  5 +import java.util.Map;
  6 +
  7 +import org.springframework.beans.factory.annotation.Autowired;
  8 +import org.springframework.web.bind.annotation.PathVariable;
  9 +import org.springframework.web.bind.annotation.RequestMapping;
  10 +import org.springframework.web.bind.annotation.RequestMethod;
  11 +import org.springframework.web.bind.annotation.RequestParam;
  12 +import org.springframework.web.bind.annotation.RestController;
  13 +
  14 +import com.bsth.controller.BaseController;
  15 +import com.bsth.entity.oil.Cwjy;
  16 +import com.bsth.entity.oil.Ylxxb;
  17 +import com.bsth.entity.sys.SysUser;
  18 +import com.bsth.security.util.SecurityUtils;
  19 +import com.bsth.service.oil.CwjyService;
  20 +import com.bsth.util.PageObject;
  21 +
  22 +@RestController
  23 +@RequestMapping("cwjy")
  24 +public class CwjyController extends BaseController<Cwjy, Integer>{
  25 + @Autowired
  26 + private CwjyService service;
  27 + @RequestMapping(method = RequestMethod.POST)
  28 + public Map<String, Object> save(Cwjy t){
  29 + SysUser sysUser = SecurityUtils.getCurrentUser();
  30 + t.setCreateDate(new Date());
  31 + t.setXgr(sysUser.getUserName());
  32 + return service.save(t);
  33 + }
  34 +
  35 + @RequestMapping(value = "/pagequery",method = RequestMethod.GET)
  36 + public PageObject<Ylxxb> pagequery(@RequestParam Map<String, Object> map){
  37 + PageObject<Ylxxb> pagequery=null;
  38 + map.put("curPage", map.get("page").toString());
  39 + map.put("pageData","10");
  40 + pagequery=service.Pagequery(map);
  41 + return pagequery;
  42 + }
  43 +
  44 + @RequestMapping(value="/bynbbm",method = RequestMethod.GET)
  45 + public Ylxxb bynbbm(@RequestParam Map<String, Object> map){
  46 +
  47 + return service.bynbbm(map);
  48 + }
  49 +
  50 + /**
  51 + *
  52 + * @Title: save
  53 + * @Description: TODO(持久化对象)
  54 + * @param @param t
  55 + * @param @return 设定文件
  56 + * @return Map<String,Object> {status: 1(成功),-1(失败)}
  57 + * @throws
  58 + */
  59 + @RequestMapping(value="/savejzl",method = RequestMethod.POST)
  60 + public Map<String, Object> savejzl(Ylxxb t){
  61 + Map<String, Object> map=service.savejzl(t);
  62 + return map;
  63 + }
  64 +
  65 +
  66 +}
src/main/java/com/bsth/controller/realcontrol/LineConfigController.java
@@ -21,13 +21,13 @@ public class LineConfigController extends BaseController&lt;LineConfig, Integer&gt;{ @@ -21,13 +21,13 @@ public class LineConfigController extends BaseController&lt;LineConfig, Integer&gt;{
21 LineConfigService lineConfigService; 21 LineConfigService lineConfigService;
22 22
23 @RequestMapping("/check") 23 @RequestMapping("/check")
24 - public Map<String, Object> check(@RequestParam Integer[] codeArray){ 24 + public Map<String, Object> check(@RequestParam String[] codeArray){
25 return lineConfigService.check(codeArray); 25 return lineConfigService.check(codeArray);
26 } 26 }
27 27
28 @RequestMapping("/init/{lineCode}") 28 @RequestMapping("/init/{lineCode}")
29 - public Integer init(@PathVariable("lineCode") Integer lineCode) throws Exception{  
30 - return lineConfigService.inti(lineCode); 29 + public Integer init(@PathVariable("lineCode") String lineCode) throws Exception{
  30 + return lineConfigService.init(lineCode);
31 } 31 }
32 32
33 @RequestMapping(value = "/editTime", method = RequestMethod.POST) 33 @RequestMapping(value = "/editTime", method = RequestMethod.POST)
src/main/java/com/bsth/controller/realcontrol/RealChartsController.java 0 → 100644
  1 +package com.bsth.controller.realcontrol;
  2 +
  3 +import com.bsth.service.realcontrol.RealChartsService;
  4 +import com.bsth.service.realcontrol.dto.CarOutRate;
  5 +import com.bsth.service.realcontrol.dto.DeviceOnlineRate;
  6 +import com.bsth.service.realcontrol.dto.StratEndPunctualityRate;
  7 +import org.springframework.beans.factory.annotation.Autowired;
  8 +import org.springframework.web.bind.annotation.RequestMapping;
  9 +import org.springframework.web.bind.annotation.RequestParam;
  10 +import org.springframework.web.bind.annotation.RestController;
  11 +
  12 +import java.util.List;
  13 +
  14 +/**
  15 + * 线路调度统计图
  16 + * Created by panzhao on 2016/11/9.
  17 + */
  18 +@RestController
  19 +@RequestMapping("realCharts")
  20 +public class RealChartsController {
  21 +
  22 + @Autowired
  23 + RealChartsService realChartsService;
  24 +
  25 + @RequestMapping("deviceOnlineRate")
  26 + public List<DeviceOnlineRate> deviceOnlineRate(@RequestParam String idx, @RequestParam String month){
  27 + return realChartsService.deviceOnlineRate(month, idx);
  28 + }
  29 +
  30 + @RequestMapping("carOutRate")
  31 + public List<CarOutRate> carOutRate(@RequestParam String idx, @RequestParam String month){
  32 + return realChartsService.carOutRate(month, idx);
  33 + }
  34 +
  35 + @RequestMapping("stratEndPunctualityRate")
  36 + public List<StratEndPunctualityRate> stratEndPunctualityRate(@RequestParam String idx, @RequestParam String month){
  37 + return realChartsService.stratEndPunctualityRate(month, idx);
  38 + }
  39 +}
src/main/java/com/bsth/controller/report/ReportController.java 0 → 100644
  1 +package com.bsth.controller.report;
  2 +
  3 +import java.util.List;
  4 +import java.util.Map;
  5 +
  6 +import org.springframework.beans.factory.annotation.Autowired;
  7 +import org.springframework.web.bind.annotation.RequestMapping;
  8 +import org.springframework.web.bind.annotation.RequestMethod;
  9 +import org.springframework.web.bind.annotation.RequestParam;
  10 +import org.springframework.web.bind.annotation.RestController;
  11 +
  12 +import com.bsth.entity.excep.ArrivalInfo;
  13 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
  14 +import com.bsth.service.report.ReportService;
  15 +
  16 +@RestController
  17 +@RequestMapping("report")
  18 +public class ReportController {
  19 +
  20 + @Autowired
  21 + ReportService service;
  22 +
  23 + @RequestMapping(value="/queryListBczx" ,method = RequestMethod.POST)
  24 + public List<ScheduleRealInfo> queryListBczx(@RequestParam String clzbh,@RequestParam String line,@RequestParam String date){
  25 + return service.queryListBczx(line,date,clzbh);
  26 + }
  27 +
  28 + @RequestMapping(value="/queryListZdxx" ,method = RequestMethod.POST)
  29 + public List<ArrivalInfo> queryListZdxx(@RequestParam String clzbh,@RequestParam String line,
  30 + @RequestParam String date,@RequestParam String fcsj,@RequestParam String ddsj){
  31 + return service.queryListZdxx(line,date,clzbh,fcsj,ddsj);
  32 + }
  33 + @RequestMapping(value="/queryListClzd" ,method = RequestMethod.POST)
  34 + public List<ArrivalInfo> queryListClzd(@RequestParam String zd,@RequestParam String line,
  35 + @RequestParam String zdlx,@RequestParam String fcsj,@RequestParam String ddsj){
  36 + return service.queryListClzd(line,zd,zdlx,fcsj,ddsj);
  37 + }
  38 +
  39 + @RequestMapping(value = "/sreachZd", method = RequestMethod.GET)
  40 + public List<Map<String, String>> sreachPersonnel(@RequestParam String line,@RequestParam int zdlx,@RequestParam String zd) {
  41 + return service.sreachZd(line,zdlx, zd);
  42 + }
  43 +
  44 +
  45 +
  46 + @RequestMapping(value = "/historyMessageCount", method = RequestMethod.GET)
  47 + public List<Object[]> historyMessageCount(@RequestParam String line, @RequestParam String date,
  48 + @RequestParam String code) {
  49 + return service.historyMessageCount(line, date, code);
  50 + }
  51 +
  52 +}
src/main/java/com/bsth/controller/sys/util/RSAUtils.java
@@ -10,10 +10,14 @@ import java.security.interfaces.RSAPublicKey; @@ -10,10 +10,14 @@ import java.security.interfaces.RSAPublicKey;
10 import javax.crypto.Cipher; 10 import javax.crypto.Cipher;
11 11
12 import org.apache.commons.net.util.Base64; 12 import org.apache.commons.net.util.Base64;
  13 +import org.slf4j.Logger;
  14 +import org.slf4j.LoggerFactory;
13 15
14 public class RSAUtils { 16 public class RSAUtils {
15 private static final KeyPair keyPair = initKey(); 17 private static final KeyPair keyPair = initKey();
16 - 18 +
  19 + static Logger logger = LoggerFactory.getLogger(RSAUtils.class);
  20 +
17 private static KeyPair initKey(){ 21 private static KeyPair initKey(){
18 try { 22 try {
19 Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider()); 23 Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
@@ -41,6 +45,7 @@ public class RSAUtils { @@ -41,6 +45,7 @@ public class RSAUtils {
41 * @return 45 * @return
42 */ 46 */
43 public static String decryptBase64(String string) { 47 public static String decryptBase64(String string) {
  48 + logger.info("decryptBase64 -[" + string + "]");
44 return new String(decrypt(Base64.decodeBase64(string))); 49 return new String(decrypt(Base64.decodeBase64(string)));
45 } 50 }
46 51
src/main/java/com/bsth/data/LineConfigData.java
@@ -77,7 +77,7 @@ public class LineConfigData implements CommandLineRunner { @@ -77,7 +77,7 @@ public class LineConfigData implements CommandLineRunner {
77 * @Title: init 77 * @Title: init
78 * @Description: TODO(初始化配置信息) 78 * @Description: TODO(初始化配置信息)
79 */ 79 */
80 - public void init(Integer lineCode) throws Exception{ 80 + public void init(String lineCode) throws Exception{
81 LineConfig conf = new LineConfig(); 81 LineConfig conf = new LineConfig();
82 //线路 82 //线路
83 Line line = lineService.findByLineCode(lineCode); 83 Line line = lineService.findByLineCode(lineCode);
src/main/java/com/bsth/data/arrival/ArrivalData_GPS.java
@@ -50,8 +50,8 @@ public class ArrivalData_GPS implements CommandLineRunner{ @@ -50,8 +50,8 @@ public class ArrivalData_GPS implements CommandLineRunner{
50 50
51 @Override 51 @Override
52 public void run(String... arg0) throws Exception { 52 public void run(String... arg0) throws Exception {
53 - logger.info("ArrivalData_GPS,30,10");  
54 - //Application.mainServices.scheduleWithFixedDelay(dataLoaderThread, 40, 10, TimeUnit.SECONDS); 53 + logger.info("ArrivalData_GPS,100,10 @11-10");
  54 + //Application.mainServices.scheduleWithFixedDelay(dataLoaderThread, 100, 10, TimeUnit.SECONDS);
55 } 55 }
56 56
57 @Component 57 @Component
src/main/java/com/bsth/data/directive/DayOfDirectives.java
@@ -91,9 +91,11 @@ public class DayOfDirectives { @@ -91,9 +91,11 @@ public class DayOfDirectives {
91 break; 91 break;
92 case 1: 92 case 1:
93 d60.setReply46((short) 0);// 发送成功 93 d60.setReply46((short) 0);// 发送成功
  94 + d60.setReply46Time(System.currentTimeMillis());
94 break; 95 break;
95 case 2: 96 case 2:
96 d60.setReply47((short) 0);// 驾驶员阅读 97 d60.setReply47((short) 0);// 驾驶员阅读
  98 + d60.setReply47Time(System.currentTimeMillis());
97 break; 99 break;
98 } 100 }
99 // 入库 101 // 入库
src/main/java/com/bsth/data/directive/DirectiveCreator.java
@@ -122,30 +122,33 @@ public class DirectiveCreator { @@ -122,30 +122,33 @@ public class DirectiveCreator {
122 122
123 /** 123 /**
124 * 124 *
125 - * @Title: createDirective64 125 + * @Title: createD64
126 * @Description: TODO(创建线路切换指令 64) 126 * @Description: TODO(创建线路切换指令 64)
127 * @param @param nbbm 车辆内部编码 127 * @param @param nbbm 车辆内部编码
128 * @param @param lineId 线路编码 128 * @param @param lineId 线路编码
129 * @param @param t 时间戳 129 * @param @param t 时间戳
130 * @throws 130 * @throws
131 - */ 131 +
132 public D64 createD64(String nbbm, String lineCode, long t){ 132 public D64 createD64(String nbbm, String lineCode, long t){
133 String deviceId = BasicData.deviceId2NbbmMap.inverse().get(nbbm); 133 String deviceId = BasicData.deviceId2NbbmMap.inverse().get(nbbm);
  134 + return create64(deviceId, lineCode, t);
  135 + }*/
134 136
  137 + public D64 create64(String deviceId, String lineCode, long t){
135 D64 change = new D64(); 138 D64 change = new D64();
136 D64Data data = new D64Data(); 139 D64Data data = new D64Data();
137 data.setCityCode(cityCode); 140 data.setCityCode(cityCode);
138 data.setDeviceId(deviceId); 141 data.setDeviceId(deviceId);
139 - 142 +
140 //线路编码补满6位数 143 //线路编码补满6位数
141 String lineCodeStr = padLeft(lineCode, 6, '0'); 144 String lineCodeStr = padLeft(lineCode, 6, '0');
142 data.setLineId(lineCodeStr); 145 data.setLineId(lineCodeStr);
143 - 146 +
144 change.setDeviceId(deviceId); 147 change.setDeviceId(deviceId);
145 change.setOperCode((short) 0X64); 148 change.setOperCode((short) 0X64);
146 change.setTimestamp(t); 149 change.setTimestamp(t);
147 change.setData(data); 150 change.setData(data);
148 - 151 +
149 return change; 152 return change;
150 } 153 }
151 154
src/main/java/com/bsth/data/forecast/ForecastRealServer.java
@@ -61,7 +61,7 @@ public class ForecastRealServer implements CommandLineRunner { @@ -61,7 +61,7 @@ public class ForecastRealServer implements CommandLineRunner {
61 @Override 61 @Override
62 public void run(String... arg0) throws Exception { 62 public void run(String... arg0) throws Exception {
63 //2小时更新一次站点间耗时数据 63 //2小时更新一次站点间耗时数据
64 - //Application.mainServices.scheduleWithFixedDelay(dataLoader, 12, 120 * 60, TimeUnit.SECONDS); 64 + Application.mainServices.scheduleWithFixedDelay(dataLoader, 12, 120 * 60, TimeUnit.SECONDS);
65 } 65 }
66 66
67 /** 67 /**
src/main/java/com/bsth/data/gpsdata/GpsEntity.java
@@ -66,6 +66,10 @@ public class GpsEntity { @@ -66,6 +66,10 @@ public class GpsEntity {
66 66
67 /** 是否异常数据 */ 67 /** 是否异常数据 */
68 private boolean abnormal; 68 private boolean abnormal;
  69 +
  70 + private int valid;
  71 +
  72 + private int version;
69 73
70 public Integer getCompanyCode() { 74 public Integer getCompanyCode() {
71 return companyCode; 75 return companyCode;
@@ -218,4 +222,20 @@ public class GpsEntity { @@ -218,4 +222,20 @@ public class GpsEntity {
218 public void setAbnormal(boolean abnormal) { 222 public void setAbnormal(boolean abnormal) {
219 this.abnormal = abnormal; 223 this.abnormal = abnormal;
220 } 224 }
  225 +
  226 + public int getValid() {
  227 + return valid;
  228 + }
  229 +
  230 + public void setValid(int valid) {
  231 + this.valid = valid;
  232 + }
  233 +
  234 + public int getVersion() {
  235 + return version;
  236 + }
  237 +
  238 + public void setVersion(int version) {
  239 + this.version = version;
  240 + }
221 } 241 }
src/main/java/com/bsth/data/gpsdata/GpsRealData.java
@@ -2,12 +2,7 @@ package com.bsth.data.gpsdata; @@ -2,12 +2,7 @@ package com.bsth.data.gpsdata;
2 2
3 import java.io.BufferedReader; 3 import java.io.BufferedReader;
4 import java.io.InputStreamReader; 4 import java.io.InputStreamReader;
5 -import java.util.ArrayList;  
6 -import java.util.Collection;  
7 -import java.util.HashMap;  
8 -import java.util.List;  
9 -import java.util.Map;  
10 -import java.util.NavigableSet; 5 +import java.util.*;
11 import java.util.concurrent.TimeUnit; 6 import java.util.concurrent.TimeUnit;
12 7
13 import org.apache.commons.lang3.StringUtils; 8 import org.apache.commons.lang3.StringUtils;
@@ -137,6 +132,10 @@ public class GpsRealData implements CommandLineRunner{ @@ -137,6 +132,10 @@ public class GpsRealData implements CommandLineRunner{
137 list.addAll(getByLine(code)); 132 list.addAll(getByLine(code));
138 return list; 133 return list;
139 } 134 }
  135 +
  136 + public Set<String> allDevices(){
  137 + return gpsMap.keySet();
  138 + }
140 139
141 public GpsEntity findByDeviceId(String deviceId) { 140 public GpsEntity findByDeviceId(String deviceId) {
142 return gpsMap.get(deviceId); 141 return gpsMap.get(deviceId);
@@ -145,7 +144,10 @@ public class GpsRealData implements CommandLineRunner{ @@ -145,7 +144,10 @@ public class GpsRealData implements CommandLineRunner{
145 public Collection<GpsEntity> all(){ 144 public Collection<GpsEntity> all(){
146 return gpsMap.values(); 145 return gpsMap.values();
147 } 146 }
148 - 147 +
  148 + public void remove(String device){
  149 + gpsMap.remove(device);
  150 + }
149 @Component 151 @Component
150 public static class GpsDataLoader extends Thread{ 152 public static class GpsDataLoader extends Thread{
151 153
src/main/java/com/bsth/data/pilot80/PilotReport.java
@@ -85,13 +85,13 @@ public class PilotReport { @@ -85,13 +85,13 @@ public class PilotReport {
85 85
86 //下发调度指令 86 //下发调度指令
87 directiveService.send60Dispatch(outSch, dayOfSchedule.doneSum(nbbm), "请出@系统"); 87 directiveService.send60Dispatch(outSch, dayOfSchedule.doneSum(nbbm), "请出@系统");
88 - d80.setRemarks("计划出场时间:" + outSch.getDfsj()); 88 +/* d80.setRemarks("计划出场时间:" + outSch.getDfsj());
89 //当前GPS位置 89 //当前GPS位置
90 GpsEntity gps = gpsRealData.get(d80.getDeviceId()); 90 GpsEntity gps = gpsRealData.get(d80.getDeviceId());
91 if(null != gps) 91 if(null != gps)
92 - d80.addRemarks("<br> 位置:" + coordHtmlStr(gps)); 92 + d80.addRemarks("<br> 位置:" + coordHtmlStr(gps));*/
93 93
94 - sendUtils.refreshSch(outSch); 94 + //sendUtils.refreshSch(outSch);
95 }else 95 }else
96 d80.setRemarks("没有出场计划"); 96 d80.setRemarks("没有出场计划");
97 97
src/main/java/com/bsth/data/schedule/DayOfSchedule.java
1 -package com.bsth.data.schedule;  
2 -  
3 -import java.text.SimpleDateFormat;  
4 -import java.util.ArrayList;  
5 -import java.util.Collection;  
6 -import java.util.Collections;  
7 -import java.util.HashMap;  
8 -import java.util.HashSet;  
9 -import java.util.Iterator;  
10 -import java.util.LinkedList;  
11 -import java.util.List;  
12 -import java.util.Map;  
13 -import java.util.Set;  
14 -import java.util.concurrent.TimeUnit;  
15 -  
16 -import org.joda.time.format.DateTimeFormat;  
17 -import org.joda.time.format.DateTimeFormatter;  
18 -import org.slf4j.Logger;  
19 -import org.slf4j.LoggerFactory;  
20 -import org.springframework.beans.factory.annotation.Autowired;  
21 -import org.springframework.boot.CommandLineRunner;  
22 -import org.springframework.stereotype.Component;  
23 -  
24 -import com.alibaba.fastjson.JSON;  
25 -import com.alibaba.fastjson.JSONArray;  
26 -import com.bsth.Application;  
27 -import com.bsth.data.LineConfigData;  
28 -import com.bsth.data.directive.FirstScheduleCheckThread;  
29 -import com.bsth.data.gpsdata.GpsRealData;  
30 -import com.bsth.data.schedule.thread.ScheduleLateThread;  
31 -import com.bsth.data.schedule.thread.SchedulePstThread;  
32 -import com.bsth.data.schedule.thread.ScheduleRefreshThread;  
33 -import com.bsth.entity.realcontrol.LineConfig;  
34 -import com.bsth.entity.realcontrol.ScheduleRealInfo;  
35 -import com.bsth.entity.schedule.SchedulePlanInfo;  
36 -import com.bsth.repository.realcontrol.ScheduleRealInfoRepository;  
37 -import com.bsth.service.schedule.SchedulePlanInfoService;  
38 -import com.bsth.util.BatchSaveUtils;  
39 -import com.bsth.util.DateUtils;  
40 -import com.bsth.websocket.handler.SendUtils;  
41 -import com.google.common.collect.ArrayListMultimap;  
42 -import com.google.common.collect.TreeMultimap;  
43 -  
44 -/**  
45 - *  
46 - * @ClassName: DayOfSchedule  
47 - * @Description: TODO(当日实际排班)  
48 - * @author PanZhao  
49 - * @date 2016年8月15日 上午10:16:12  
50 - *  
51 - */  
52 -@Component  
53 -public class DayOfSchedule implements CommandLineRunner {  
54 -  
55 - Logger logger = LoggerFactory.getLogger(this.getClass());  
56 -  
57 - // 按车辆分组的班次数据  
58 - private static ArrayListMultimap<String, ScheduleRealInfo> nbbmScheduleMap;  
59 -  
60 - // 班次主键映射  
61 - private static Map<Long, ScheduleRealInfo> id2SchedulMap;  
62 -  
63 - // 车辆和排班起终点站对照(包括进出的停车场,区间起终点)  
64 - private static TreeMultimap<String, String> nbbm2SEStationMap;  
65 -  
66 - //车辆 ——> 当前执行班次  
67 - private static Map<String, ScheduleRealInfo> carExecutePlanMap;  
68 -  
69 - // 持久化缓冲区  
70 - public static LinkedList<ScheduleRealInfo> pstBuffer;  
71 -  
72 - // 排序器  
73 - private static ScheduleComparator.FCSJ schFCSJComparator;  
74 -  
75 - @Autowired  
76 - LineConfigData lineConfigData;  
77 -  
78 - @Autowired  
79 - ScheduleRealInfoRepository schRepository;  
80 -  
81 - @Autowired  
82 - SchedulePlanInfoService schPlanService;  
83 -  
84 - @Autowired  
85 - SchAttrCalculator schAttrCalculator;  
86 -  
87 - @Autowired  
88 - SendUtils sendUtils;  
89 -  
90 - @Autowired  
91 - GpsRealData gpsRealData;  
92 -  
93 - /** 线路当前使用的排班的日期 */  
94 - public static Map<String, String> currSchDateMap;  
95 -  
96 - static {  
97 - nbbmScheduleMap = ArrayListMultimap.create();  
98 - id2SchedulMap = new HashMap<>();  
99 - pstBuffer = new LinkedList<>();  
100 - schFCSJComparator = new ScheduleComparator.FCSJ();  
101 - currSchDateMap = new HashMap<>();  
102 - nbbm2SEStationMap = TreeMultimap.create();  
103 - carExecutePlanMap = new HashMap<>();  
104 - }  
105 -  
106 - @Autowired  
107 - ScheduleRefreshThread scheduleRefreshThread;  
108 -  
109 - @Autowired  
110 - SchedulePstThread schedulePstThread;  
111 -  
112 - @Autowired  
113 - FirstScheduleCheckThread firstScheduleCheckThread;  
114 -  
115 - @Autowired  
116 - ScheduleLateThread scheduleLateThread;  
117 -  
118 - private static DateTimeFormatter fmtyyyyMMdd = DateTimeFormat.forPattern("yyyy-MM-dd")  
119 - ,fmtHHmm = DateTimeFormat.forPattern("HH:mm");  
120 -  
121 - @Override  
122 - public void run(String... arg0) throws Exception {  
123 - //翻班线程  
124 - Application.mainServices.scheduleWithFixedDelay(scheduleRefreshThread, 15, 240, TimeUnit.SECONDS);  
125 - //入库  
126 - Application.mainServices.scheduleWithFixedDelay(schedulePstThread, 60, 60, TimeUnit.SECONDS);  
127 - //首班出场指令补发器  
128 - Application.mainServices.scheduleWithFixedDelay(firstScheduleCheckThread, 30, 240, TimeUnit.SECONDS);  
129 - //班次误点扫描  
130 - //Application.mainServices.scheduleWithFixedDelay(scheduleLateThread, 60, 60, TimeUnit.SECONDS);  
131 - }  
132 -  
133 - public Map<String, String> getCurrSchDate() {  
134 - return currSchDateMap;  
135 - }  
136 -  
137 - /**  
138 - *  
139 - * @Title: calcSchDateB  
140 - * @Description: TODO(计算线路当前应该使用的排班日期)  
141 - */  
142 - public String calcSchDate(String lineCode) {  
143 - LineConfig conf = lineConfigData.get(lineCode);  
144 - long ct = System.currentTimeMillis();  
145 -  
146 - String schDate = fmtyyyyMMdd.print(ct);  
147 - // 小于当天起始运营时间,则取前一天的排班  
148 - if (ct < conf.getCurrStartTime())  
149 - schDate = DateUtils.subtractDay(schDate, 1);  
150 -  
151 - return schDate;  
152 - }  
153 -  
154 - /**  
155 - * @Title: reloadSch  
156 - * @Title: reloadSch  
157 - * @Description: TODO(重新载入排班)  
158 - * @param @param  
159 - * lineCode 线路编码  
160 - * @param @param  
161 - * schDate 班次日期 yyyy-MM-dd  
162 - * @param @param  
163 - * forcePlan 强制从计划调度重新抓取  
164 - */  
165 - public int reloadSch(String lineCode, String schDate, boolean forcePlan) {  
166 - try {  
167 - List<ScheduleRealInfo> list;  
168 -  
169 - if (forcePlan)  
170 - removeRealSch(lineCode, schDate);  
171 - else  
172 - clearRAMData(lineCode);  
173 -  
174 - if (existRealSch(lineCode, schDate))  
175 - list = loadRealSch(lineCode, schDate);// 从实际排班表加载  
176 - else {  
177 - list = loadPlanSch(lineCode, schDate);// 从计划排班表加载  
178 - // 写入数据库  
179 - batchSave(list);  
180 - }  
181 -  
182 - //更新线路和班次日期对照  
183 - currSchDateMap.put(lineCode, schDate);  
184 - //添加到缓存  
185 - putAll(list);  
186 -  
187 - Set<String> cars = searchAllCars(list);  
188 - //计算“起点站应到”时间  
189 - for(String nbbm : cars)  
190 - schAttrCalculator.calcQdzTimePlan(nbbmScheduleMap.get(nbbm));  
191 -  
192 - //是否是出站即出场  
193 - LineConfig conf = lineConfigData.get(lineCode);  
194 - if(conf.getOutConfig() == 2){  
195 - for(String nbbm : cars)  
196 - schAttrCalculator.connectOutSchedule(nbbmScheduleMap.get(nbbm));  
197 - }  
198 -  
199 - // 页面 翻班通知  
200 - sendUtils.shiftSchedule(lineCode);  
201 - } catch (Exception e) {  
202 - logger.error("", e);  
203 - return -1;  
204 - }  
205 -  
206 - return 0;  
207 - }  
208 -  
209 - /**  
210 - *  
211 - * @Title: searchAllCars  
212 - * @Description: TODO(搜索班次集合中的车辆)  
213 - */  
214 - private Set<String> searchAllCars(List<ScheduleRealInfo> list) {  
215 - Set<String> cars = new HashSet<>();  
216 - for(ScheduleRealInfo sch : list)  
217 - cars.add(sch.getClZbh());  
218 -  
219 - return cars;  
220 - }  
221 -  
222 - private void putAll(List<ScheduleRealInfo> list) {  
223 - for (ScheduleRealInfo sch : list)  
224 - put(sch);  
225 - }  
226 -  
227 - /**  
228 - * @Title: removeRealSch  
229 - * @Description: TODO(清除实际排班,包括数据库和内存数据)  
230 - * @param @param  
231 - * lineCode 线路编码  
232 - * @param @param  
233 - * schDate 班次日期 yyyy-MM-dd  
234 - */  
235 - public void removeRealSch(String lineCode, String schDate) throws Exception {  
236 - try {  
237 - // 清理数据库数据  
238 - schRepository.deleteByLineCodeAndDate(lineCode + "", schDate);  
239 -  
240 - // 清理内存数据  
241 - clearRAMData(lineCode + "");  
242 - } catch (Exception e) {  
243 - logger.error("removeRealSch error, " + lineCode + " -" + schDate, e);  
244 - throw e;  
245 - }  
246 - }  
247 -  
248 - /**  
249 - *  
250 - * @Title: clearRAMData  
251 - * @Description: TODO(清理内存数据)  
252 - */  
253 - public void clearRAMData(String lineCode) {  
254 - int count = 0;  
255 - List<ScheduleRealInfo> remList = new ArrayList<>();  
256 - Collection<ScheduleRealInfo> schs = nbbmScheduleMap.values();  
257 - for (ScheduleRealInfo sch : schs) {  
258 - if (sch.getXlBm().equals(lineCode))  
259 - remList.add(sch);  
260 - }  
261 -  
262 - for(ScheduleRealInfo sch : remList){  
263 - if(null != sch){  
264 - nbbmScheduleMap.remove(sch.getClZbh(), sch);  
265 - id2SchedulMap.remove(sch.getId());  
266 - count ++;  
267 - }  
268 - }  
269 -  
270 - logger.info(lineCode + "排班清理 " + count);  
271 - }  
272 -  
273 - /**  
274 - * @Title: existRealSch  
275 - * @Description: TODO(实际排班是否已存在)  
276 - */  
277 - public boolean existRealSch(String lineCode, String schDate) {  
278 - int count = schRepository.countByLineCodeAndDate(lineCode, schDate);  
279 - return count > 0;  
280 - }  
281 -  
282 - /**  
283 - * @Title: loadRealSch  
284 - * @Description: TODO(从实际排班表加载数据)  
285 - */  
286 - public List<ScheduleRealInfo> loadRealSch(String lineCode, String schDate) {  
287 - return schRepository.findByLineCodeAndDate(lineCode, schDate);  
288 - }  
289 -  
290 - /**  
291 - * @Title: loadPlanSch  
292 - * @Description: TODO(从计划排班表加载数据)  
293 - */  
294 - public List<ScheduleRealInfo> loadPlanSch(String lineCode, String schDate) {  
295 - logger.info("从计划排班表恢复排班,lineCode: " + lineCode + ", schDate: " + schDate);  
296 - List<ScheduleRealInfo> realList = new ArrayList<>();  
297 -  
298 - try {  
299 - Map<String, Object> data = new HashMap<>();  
300 -  
301 - data.put("scheduleDate_eq", fmtyyyyMMdd.parseDateTime(schDate).toDate());  
302 - data.put("xlBm_eq", lineCode);  
303 -  
304 - // 查询计划排班  
305 - List<SchedulePlanInfo> planItr = cleanSchPlanItr(schPlanService.list(data).iterator());  
306 -  
307 - // 转换为实际排班  
308 - realList = JSONArray.parseArray(JSON.toJSONString(planItr), ScheduleRealInfo.class);  
309 -  
310 - for (ScheduleRealInfo sch : realList) {  
311 - sch.setScheduleDateStr(fmtyyyyMMdd.print(sch.getScheduleDate().getTime()));  
312 - sch.setRealExecDate(sch.getScheduleDateStr());  
313 - // 计划终点时间  
314 - if (sch.getBcsj() != null) {  
315 - sch.setZdsj(fmtHHmm.print(fmtHHmm.parseMillis(sch.getFcsj()) + (sch.getBcsj() * 60 * 1000)));  
316 - sch.setLate(false);  
317 - }  
318 - //计划里程为0,设置NULL  
319 - if(sch.getJhlc() != null && sch.getJhlc() == 0)  
320 - sch.setJhlc(null);  
321 - }  
322 - } catch (Exception e) {  
323 - logger.error("", e);  
324 - }  
325 - return realList;  
326 - }  
327 -  
328 - /**  
329 - * @Title: batchSave  
330 - * @Description: TODO(批量入库)  
331 - */  
332 - private void batchSave(List<ScheduleRealInfo> list) {  
333 - // 查询数据库最大ID  
334 - Long id = schRepository.getMaxId();  
335 - if (null == id)  
336 - id = 0L;  
337 - id++;  
338 -  
339 - SimpleDateFormat sdfyyyyMMdd = new SimpleDateFormat("yyyy-MM-dd");  
340 - for (ScheduleRealInfo item : list) {  
341 - item.setSpId(item.getId());// 保留原始的计划ID  
342 - item.setId(id++);// 设置ID  
343 - item.setScheduleDateStr(sdfyyyyMMdd.format(item.getScheduleDate()));  
344 - }  
345 -  
346 - // 入库  
347 - new BatchSaveUtils<ScheduleRealInfo>().saveList(list, ScheduleRealInfo.class);  
348 - }  
349 -  
350 - private List<SchedulePlanInfo> cleanSchPlanItr(Iterator<SchedulePlanInfo> itrab) {  
351 - List<SchedulePlanInfo> list = new ArrayList<>();  
352 -  
353 - SchedulePlanInfo sp;  
354 - while (itrab.hasNext()) {  
355 - sp = itrab.next();  
356 - sp.setSchedulePlan(null);  
357 - list.add(sp);  
358 - }  
359 - return list;  
360 - }  
361 -  
362 - /**  
363 - *  
364 - * @Title: findByLineCode  
365 - * @Description: TODO(lineCode 获取班次)  
366 - */  
367 - public List<ScheduleRealInfo> findByLineCode(String lineCode) {  
368 - List<ScheduleRealInfo> rs = new ArrayList<>();  
369 -  
370 - Collection<ScheduleRealInfo> schs = nbbmScheduleMap.values();  
371 - for (ScheduleRealInfo sch : schs) {  
372 - if (sch.getXlBm().equals(lineCode))  
373 - rs.add(sch);  
374 - }  
375 - return rs;  
376 - }  
377 -  
378 - /**  
379 - *  
380 - * @Title: findCarByLineCode  
381 - * @Description: TODO(线路下运营的车辆)  
382 - */  
383 - public Set<String> findCarByLineCode(String lineCode){  
384 - Set<String> rs = new HashSet<>();  
385 -  
386 - Collection<ScheduleRealInfo> schs = nbbmScheduleMap.values();  
387 - for (ScheduleRealInfo sch : schs) {  
388 - if (sch.getXlBm().equals(lineCode))  
389 - rs.add(sch.getClZbh());  
390 - }  
391 -  
392 - return rs;  
393 - }  
394 -  
395 - public List<ScheduleRealInfo> findByNbbm(String nbbm) {  
396 - return nbbmScheduleMap.get(nbbm);  
397 - }  
398 -  
399 - /**  
400 - *  
401 - * @Title: findByLineAndUpDown  
402 - * @Description: TODO(lineCode 和走向获取班次)  
403 - */  
404 - public List<ScheduleRealInfo> findByLineAndUpDown(String lineCode, Integer upDown) {  
405 - List<ScheduleRealInfo> list = findByLineCode(lineCode), rs = new ArrayList<>();  
406 -  
407 - for (ScheduleRealInfo sch : list) {  
408 - if (sch.getXlDir().equals(upDown + ""))  
409 - rs.add(sch);  
410 - }  
411 - return rs;  
412 - }  
413 -  
414 - public ScheduleRealInfo get(long id) {  
415 - return id2SchedulMap.get(id);  
416 - }  
417 -  
418 - public Set<String> getSEStationList(String nbbm) {  
419 - return nbbm2SEStationMap.get(nbbm);  
420 - }  
421 -  
422 - /**  
423 - *  
424 - * @Title: next  
425 - * @Description: TODO(下一个班次)  
426 - */  
427 - public ScheduleRealInfo next(ScheduleRealInfo sch) {  
428 -  
429 - List<ScheduleRealInfo> list = nbbmScheduleMap.get(sch.getClZbh());  
430 -  
431 - boolean flag = false;  
432 - ScheduleRealInfo next = null;  
433 - for(ScheduleRealInfo temp : list){  
434 - if(temp.getId() == sch.getId()){  
435 - flag = true;  
436 - continue;  
437 - }  
438 - //忽略烂班  
439 - if(temp.isDestroy())  
440 - continue;  
441 -  
442 - if(flag){  
443 - next = temp;  
444 - break;  
445 - }  
446 - }  
447 - return next;  
448 - }  
449 -  
450 - public void put(ScheduleRealInfo sch) {  
451 -  
452 - schAttrCalculator  
453 - .calcRealDate(sch)  
454 - .calcAllTimeByFcsj(sch);  
455 -  
456 - String nbbm = sch.getClZbh();  
457 - nbbmScheduleMap.put(nbbm, sch);  
458 - nbbm2SEStationMap.put(nbbm, sch.getQdzCode());  
459 - nbbm2SEStationMap.put(nbbm, sch.getZdzCode());  
460 -  
461 - //主键索引  
462 - id2SchedulMap.put(sch.getId(), sch);  
463 - }  
464 -  
465 - public void delete(ScheduleRealInfo sch) {  
466 - //ScheduleRealInfo sch = id2SchedulMap.get(id);  
467 - if(!sch.isSflj())  
468 - return;  
469 -  
470 - nbbmScheduleMap.remove(sch.getClZbh(), sch);  
471 - id2SchedulMap.remove(sch.getId());  
472 - //return sch;  
473 - }  
474 -  
475 -// public void calcQdzTimePlan(String nbbm){  
476 -// schAttrCalculator.calcQdzTimePlan(nbbmScheduleMap.get(nbbm));  
477 -// }  
478 -  
479 - public List<ScheduleRealInfo> updateQdzTimePlan(String nbbm){  
480 - return schAttrCalculator.updateQdzTimePlan(nbbmScheduleMap.get(nbbm));  
481 - }  
482 -  
483 - /**  
484 - *  
485 - * @Title: nextAll  
486 - * @Description: TODO(之后的所有班次)  
487 - */  
488 -/* public List<ScheduleRealInfo> nextAll(ScheduleRealInfo sch) {  
489 - List<ScheduleRealInfo> list = nbbmScheduleMap.get(sch.getClZbh());  
490 - // 排序  
491 - Collections.sort(list, schFCSJComparator);  
492 -  
493 - List<ScheduleRealInfo> rs = new ArrayList<>();  
494 - ScheduleRealInfo temp;  
495 - for (int i = 0; i < list.size() - 1; i++) {  
496 - temp = list.get(i);  
497 - if(temp.getFcsjT() > sch.getFcsjT())  
498 - rs.add(temp);  
499 -  
500 - }  
501 - return rs;  
502 - }*/  
503 -  
504 - /**  
505 - *  
506 - * @Title: doneSum  
507 - * @Description: TODO(已完成班次总数)  
508 - */  
509 - public int doneSum(String clZbh) {  
510 - List<ScheduleRealInfo> list = nbbmScheduleMap.get(clZbh);  
511 - int rs = 0;  
512 -  
513 - for(ScheduleRealInfo sch : list){  
514 - if(sch.getStatus() == 2 && !sch.isDestroy())  
515 - rs ++;  
516 - }  
517 - return rs;  
518 - }  
519 -  
520 - /**  
521 - *  
522 - * @Title: prveNotExecNum  
523 - * @Description: TODO(班次之前未执行班次数量)  
524 - */  
525 - public int prveNotExecNum(ScheduleRealInfo sch){  
526 - int n = 0;  
527 - List<ScheduleRealInfo> list = nbbmScheduleMap.get(sch.getClZbh());  
528 - for(ScheduleRealInfo s : list){  
529 - if(s.getFcsjActual() == null && !s.isDestroy())  
530 - n ++;  
531 -  
532 - if(s.getId().equals(sch.getId()))  
533 - break;  
534 - }  
535 - return n;  
536 - }  
537 -  
538 - /**  
539 - *  
540 - * @Title: validEndTime  
541 - * @Description: TODO(是否是有效的到达时间)  
542 - */  
543 - public boolean validEndTime(ScheduleRealInfo sch, Long ts) {  
544 - if(sch.getFcsjActualTime() != null && sch.getFcsjActualTime() > ts)  
545 - return false;  
546 -  
547 - return validTime(sch, ts);  
548 - }  
549 -  
550 - /**  
551 - *  
552 - * @Title: validStartTime  
553 - * @Description: TODO(是否是合适的发车时间)  
554 - */  
555 - public boolean validStartTime(ScheduleRealInfo sch, Long ts) {  
556 - if(sch.getZdsjActualTime() != null && sch.getZdsjActualTime() < ts)  
557 - return false;  
558 -  
559 - return validTime(sch, ts);  
560 - }  
561 -  
562 - public boolean validTime(ScheduleRealInfo sch, Long ts){  
563 - List<ScheduleRealInfo> list = nbbmScheduleMap.get(sch.getClZbh());  
564 - int ci = list.indexOf(sch);  
565 - ScheduleRealInfo prve, next;  
566 - if(ci > 0){  
567 - //之前班次实际时间不能大于该时间  
568 - for(int i = ci - 1; i >= 0; i --){  
569 - prve = list.get(i);  
570 - if(prve.getZdsjActualTime() != null && prve.getZdsjActualTime() > ts )  
571 - return false;  
572 -  
573 - if(prve.getFcsjActualTime() != null && prve.getFcsjActualTime() > ts)  
574 - return false;  
575 - }  
576 - }  
577 -  
578 - if(ci < list.size() - 1){  
579 - //之后班次实际时间不能小于该时间  
580 - for(int i = ci + 1; i < list.size(); i ++){  
581 - next = list.get(i);  
582 - if(next.getFcsjActualTime() != null && next.getFcsjActualTime() < ts)  
583 - return false;  
584 -  
585 - if(next.getZdsjActualTime() != null && next.getZdsjActualTime() < ts)  
586 - return false;  
587 - }  
588 - }  
589 - return true;  
590 - }  
591 -  
592 - public void save(ScheduleRealInfo sch){  
593 - //schRepository.save(sch);  
594 - pstBuffer.add(sch);  
595 - }  
596 -  
597 -  
598 - /**  
599 - *  
600 - * @Title: nextByBcType  
601 - * @Description: TODO(获取下一个指定班次类型的班次)  
602 - */  
603 - public ScheduleRealInfo nextByBcType(String nbbm, String bcType){  
604 - List<ScheduleRealInfo> list = findByBcType(nbbm, bcType);  
605 -  
606 - Collections.sort(list, schFCSJComparator);  
607 - ScheduleRealInfo sch = null;  
608 - for(ScheduleRealInfo temp : list){  
609 - if(temp.getFcsjActual() == null)  
610 - sch = temp;  
611 - }  
612 -  
613 - return sch;  
614 - }  
615 -  
616 - public List<ScheduleRealInfo> findByBcType(String nbbm, String bcType){  
617 - List<ScheduleRealInfo> all = nbbmScheduleMap.get(nbbm)  
618 - ,outList = new ArrayList<>();  
619 -  
620 - for(ScheduleRealInfo sch : all){  
621 - if(sch.getBcType().equals(bcType))  
622 - outList.add(sch);  
623 - }  
624 - return outList;  
625 - }  
626 -  
627 - public Set<String> allCar(){  
628 - return nbbmScheduleMap.keySet();  
629 - }  
630 -  
631 - public Collection<ScheduleRealInfo> findAll(){  
632 - return nbbmScheduleMap.values();  
633 - }  
634 -  
635 - public void addExecPlan(ScheduleRealInfo sch){  
636 - carExecutePlanMap.put(sch.getClZbh(), sch);  
637 - }  
638 -  
639 - public void removeExecPlan(String clzbh){  
640 - carExecutePlanMap.remove(clzbh);  
641 - }  
642 -  
643 - public Map<String, ScheduleRealInfo> execPlamMap(){  
644 - return carExecutePlanMap;  
645 - }  
646 -  
647 - /**  
648 - * @Title: changeCar  
649 - * @Description: TODO(班次换车) 返回有更新的班次  
650 - * @param @param sch  
651 - * @param @param newClZbh 新的车辆自编号  
652 - */  
653 - public List<ScheduleRealInfo> changeCar(ScheduleRealInfo sch , String newClZbh){  
654 - List<ScheduleRealInfo> ups = new ArrayList<>();  
655 - String oldClzbh = sch.getClZbh();  
656 - if(oldClzbh.equals(newClZbh))  
657 - return ups;  
658 -  
659 -  
660 - //变更相关映射信息  
661 - nbbmScheduleMap.remove(sch.getClZbh(), sch);  
662 -  
663 - sch.setClZbh(newClZbh);  
664 - nbbmScheduleMap.put(newClZbh, sch);  
665 - nbbm2SEStationMap.put(newClZbh, sch.getQdzCode());  
666 - nbbm2SEStationMap.put(newClZbh, sch.getZdzCode());  
667 -  
668 - //重新计算班次应到时间  
669 - ups.addAll(updateQdzTimePlan(oldClzbh));  
670 - ups.addAll(updateQdzTimePlan(newClZbh));  
671 - return ups;  
672 - }  
673 -  
674 - /**  
675 - *  
676 - * @Title: linkToSchPlan  
677 - * @Description: TODO(车辆关联到班次)  
678 - */  
679 -/* public void linkToSchPlan(String nbbm) {  
680 - //当前GPS状态  
681 - GpsEntity gps = gpsRealData.get(BasicData.deviceId2NbbmMap.inverse().get(nbbm));  
682 - if(null == gps)  
683 - return;  
684 -  
685 - //班次集合  
686 - List<ScheduleRealInfo> schArr = nbbmScheduleMap.get(nbbm);  
687 -  
688 - for(ScheduleRealInfo sch : schArr){  
689 - if(sch.getStatus() == 2)  
690 - continue;  
691 - if(sch.isDestroy())  
692 - continue;  
693 - if(!sch.getXlBm().equals(gps.getLineId())  
694 - || Integer.parseInt(sch.getXlDir()) != gps.getUpDown().intValue())  
695 - continue;  
696 -  
697 - addExecPlan(sch);  
698 - break;  
699 - }  
700 - }*/  
701 -} 1 +package com.bsth.data.schedule;
  2 +
  3 +import java.text.ParseException;
  4 +import java.text.SimpleDateFormat;
  5 +import java.util.ArrayList;
  6 +import java.util.Collection;
  7 +import java.util.Collections;
  8 +import java.util.HashMap;
  9 +import java.util.HashSet;
  10 +import java.util.Iterator;
  11 +import java.util.LinkedList;
  12 +import java.util.List;
  13 +import java.util.Map;
  14 +import java.util.Set;
  15 +import java.util.concurrent.TimeUnit;
  16 +
  17 +import com.bsth.data.schedule.thread.SubmitToTrafficManage;
  18 +import org.apache.commons.lang3.StringUtils;
  19 +import org.joda.time.DateTime;
  20 +import org.joda.time.format.DateTimeFormat;
  21 +import org.joda.time.format.DateTimeFormatter;
  22 +import org.slf4j.Logger;
  23 +import org.slf4j.LoggerFactory;
  24 +import org.springframework.beans.factory.annotation.Autowired;
  25 +import org.springframework.boot.CommandLineRunner;
  26 +import org.springframework.stereotype.Component;
  27 +
  28 +import com.alibaba.fastjson.JSON;
  29 +import com.alibaba.fastjson.JSONArray;
  30 +import com.bsth.Application;
  31 +import com.bsth.data.LineConfigData;
  32 +import com.bsth.data.directive.FirstScheduleCheckThread;
  33 +import com.bsth.data.gpsdata.GpsRealData;
  34 +import com.bsth.data.schedule.thread.ScheduleLateThread;
  35 +import com.bsth.data.schedule.thread.SchedulePstThread;
  36 +import com.bsth.data.schedule.thread.ScheduleRefreshThread;
  37 +import com.bsth.entity.realcontrol.LineConfig;
  38 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
  39 +import com.bsth.entity.schedule.SchedulePlanInfo;
  40 +import com.bsth.repository.realcontrol.ScheduleRealInfoRepository;
  41 +import com.bsth.service.schedule.SchedulePlanInfoService;
  42 +import com.bsth.util.BatchSaveUtils;
  43 +import com.bsth.util.DateUtils;
  44 +import com.bsth.websocket.handler.SendUtils;
  45 +import com.google.common.collect.ArrayListMultimap;
  46 +import com.google.common.collect.TreeMultimap;
  47 +
  48 +/**
  49 + *
  50 + * @ClassName: DayOfSchedule
  51 + * @Description: TODO(当日实际排班)
  52 + * @author PanZhao
  53 + * @date 2016年8月15日 上午10:16:12
  54 + *
  55 + */
  56 +@Component
  57 +public class DayOfSchedule implements CommandLineRunner {
  58 +
  59 + Logger logger = LoggerFactory.getLogger(this.getClass());
  60 +
  61 + // 按车辆分组的班次数据
  62 + private static ArrayListMultimap<String, ScheduleRealInfo> nbbmScheduleMap;
  63 +
  64 + // 班次主键映射
  65 + private static Map<Long, ScheduleRealInfo> id2SchedulMap;
  66 +
  67 + // 车辆和排班起终点站对照(包括进出的停车场,区间起终点)
  68 + private static TreeMultimap<String, String> nbbm2SEStationMap;
  69 +
  70 + //车辆 ——> 当前执行班次
  71 + private static Map<String, ScheduleRealInfo> carExecutePlanMap;
  72 +
  73 + // 持久化缓冲区
  74 + public static LinkedList<ScheduleRealInfo> pstBuffer;
  75 +
  76 + // 排序器
  77 + private static ScheduleComparator.FCSJ schFCSJComparator;
  78 +
  79 + @Autowired
  80 + LineConfigData lineConfigData;
  81 +
  82 + @Autowired
  83 + ScheduleRealInfoRepository schRepository;
  84 +
  85 + @Autowired
  86 + SchedulePlanInfoService schPlanService;
  87 +
  88 + @Autowired
  89 + SchAttrCalculator schAttrCalculator;
  90 +
  91 + @Autowired
  92 + SendUtils sendUtils;
  93 +
  94 + @Autowired
  95 + GpsRealData gpsRealData;
  96 +
  97 + /** 线路当前使用的排班的日期 */
  98 + public static Map<String, String> currSchDateMap;
  99 +
  100 + static {
  101 + nbbmScheduleMap = ArrayListMultimap.create();
  102 + id2SchedulMap = new HashMap<>();
  103 + pstBuffer = new LinkedList<>();
  104 + schFCSJComparator = new ScheduleComparator.FCSJ();
  105 + currSchDateMap = new HashMap<>();
  106 + nbbm2SEStationMap = TreeMultimap.create();
  107 + carExecutePlanMap = new HashMap<>();
  108 + }
  109 +
  110 + @Autowired
  111 + ScheduleRefreshThread scheduleRefreshThread;
  112 +
  113 + @Autowired
  114 + SchedulePstThread schedulePstThread;
  115 +
  116 + @Autowired
  117 + FirstScheduleCheckThread firstScheduleCheckThread;
  118 +
  119 + @Autowired
  120 + ScheduleLateThread scheduleLateThread;
  121 +
  122 + @Autowired
  123 + SubmitToTrafficManage submitToTrafficManage;
  124 +
  125 + private static DateTimeFormatter fmtyyyyMMdd = DateTimeFormat.forPattern("yyyy-MM-dd")
  126 + ,fmtHHmm = DateTimeFormat.forPattern("HH:mm");
  127 +
  128 + @Override
  129 + public void run(String... arg0) throws Exception {
  130 + //翻班线程
  131 + Application.mainServices.scheduleWithFixedDelay(scheduleRefreshThread, 15, 240, TimeUnit.SECONDS);
  132 + //入库
  133 + //Application.mainServices.scheduleWithFixedDelay(schedulePstThread, 60, 60, TimeUnit.SECONDS);
  134 + //首班出场指令补发器
  135 + //Application.mainServices.scheduleWithFixedDelay(firstScheduleCheckThread, 30, 240, TimeUnit.SECONDS);
  136 + //班次误点扫描
  137 + //Application.mainServices.scheduleWithFixedDelay(scheduleLateThread, 60, 60, TimeUnit.SECONDS);
  138 +
  139 + //每天凌晨1点40提交数据到运管处
  140 + long diff = (DateUtils.getTimestamp() + 1000*60*100) - System.currentTimeMillis();
  141 + if(diff < 0)
  142 + diff+=(1000*60*60*24);
  143 +
  144 + logger.info(diff/1000/60 + "分钟之后提交到运管处");
  145 + //Application.mainServices.scheduleWithFixedDelay(submitToTrafficManage, diff / 1000, 60 * 60 * 24, TimeUnit.SECONDS);
  146 + }
  147 +
  148 + public Map<String, String> getCurrSchDate() {
  149 + return currSchDateMap;
  150 + }
  151 +
  152 + /**
  153 + *
  154 + * @Title: calcSchDateB
  155 + * @Description: TODO(计算线路当前应该使用的排班日期)
  156 + */
  157 + public String calcSchDate(String lineCode) {
  158 + LineConfig conf = lineConfigData.get(lineCode);
  159 + long ct = System.currentTimeMillis();
  160 +
  161 + String schDate = fmtyyyyMMdd.print(ct);
  162 + // 小于当天起始运营时间,则取前一天的排班
  163 + if (ct < conf.getCurrStartTime())
  164 + schDate = DateUtils.subtractDay(schDate, 1);
  165 +
  166 + return schDate;
  167 + }
  168 +
  169 + /**
  170 + * @Title: reloadSch
  171 + * @Title: reloadSch
  172 + * @Description: TODO(重新载入排班)
  173 + * @param @param
  174 + * lineCode 线路编码
  175 + * @param @param
  176 + * schDate 班次日期 yyyy-MM-dd
  177 + * @param @param
  178 + * forcePlan 强制从计划调度重新抓取
  179 + */
  180 + public int reloadSch(String lineCode, String schDate, boolean forcePlan) {
  181 + try {
  182 + List<ScheduleRealInfo> list;
  183 +
  184 + if (forcePlan)
  185 + removeRealSch(lineCode, schDate);
  186 + else
  187 + clearRAMData(lineCode);
  188 +
  189 + if (existRealSch(lineCode, schDate))
  190 + list = loadRealSch(lineCode, schDate);// 从实际排班表加载
  191 + else {
  192 + list = loadPlanSch(lineCode, schDate);// 从计划排班表加载
  193 + // 写入数据库
  194 + batchSave(list);
  195 + }
  196 +
  197 + //更新线路和班次日期对照
  198 + currSchDateMap.put(lineCode, schDate);
  199 + //添加到缓存
  200 + putAll(list);
  201 +
  202 + Set<String> cars = searchAllCars(list);
  203 + //计算“起点站应到”时间
  204 + for(String nbbm : cars)
  205 + schAttrCalculator.calcQdzTimePlan(nbbmScheduleMap.get(nbbm));
  206 +
  207 + //是否是出站即出场
  208 + LineConfig conf = lineConfigData.get(lineCode);
  209 + if(conf.getOutConfig() == 2){
  210 + for(String nbbm : cars)
  211 + schAttrCalculator.connectOutSchedule(nbbmScheduleMap.get(nbbm));
  212 + }
  213 +
  214 + // 页面 翻班通知
  215 + sendUtils.shiftSchedule(lineCode);
  216 + } catch (Exception e) {
  217 + logger.error("", e);
  218 + return -1;
  219 + }
  220 +
  221 + return 0;
  222 + }
  223 +
  224 + /**
  225 + *
  226 + * @Title: searchAllCars
  227 + * @Description: TODO(搜索班次集合中的车辆)
  228 + */
  229 + private Set<String> searchAllCars(List<ScheduleRealInfo> list) {
  230 + Set<String> cars = new HashSet<>();
  231 + for(ScheduleRealInfo sch : list)
  232 + cars.add(sch.getClZbh());
  233 +
  234 + return cars;
  235 + }
  236 +
  237 + private void putAll(List<ScheduleRealInfo> list) {
  238 + for (ScheduleRealInfo sch : list)
  239 + put(sch);
  240 + }
  241 +
  242 + /**
  243 + * @Title: removeRealSch
  244 + * @Description: TODO(清除实际排班,包括数据库和内存数据)
  245 + * @param @param
  246 + * lineCode 线路编码
  247 + * @param @param
  248 + * schDate 班次日期 yyyy-MM-dd
  249 + */
  250 + public void removeRealSch(String lineCode, String schDate) throws Exception {
  251 + try {
  252 + // 清理数据库数据
  253 + schRepository.deleteByLineCodeAndDate(lineCode + "", schDate);
  254 +
  255 + // 清理内存数据
  256 + clearRAMData(lineCode + "");
  257 + } catch (Exception e) {
  258 + logger.error("removeRealSch error, " + lineCode + " -" + schDate, e);
  259 + throw e;
  260 + }
  261 + }
  262 +
  263 + /**
  264 + *
  265 + * @Title: clearRAMData
  266 + * @Description: TODO(清理内存数据)
  267 + */
  268 + public void clearRAMData(String lineCode) {
  269 + int count = 0;
  270 + List<ScheduleRealInfo> remList = new ArrayList<>();
  271 + Collection<ScheduleRealInfo> schs = nbbmScheduleMap.values();
  272 + for (ScheduleRealInfo sch : schs) {
  273 + if (sch.getXlBm().equals(lineCode))
  274 + remList.add(sch);
  275 + }
  276 +
  277 + for(ScheduleRealInfo sch : remList){
  278 + if(null != sch){
  279 + nbbmScheduleMap.remove(sch.getClZbh(), sch);
  280 + id2SchedulMap.remove(sch.getId());
  281 + count ++;
  282 + }
  283 + }
  284 +
  285 + logger.info(lineCode + "排班清理 " + count);
  286 + }
  287 +
  288 + /**
  289 + * @Title: existRealSch
  290 + * @Description: TODO(实际排班是否已存在)
  291 + */
  292 + public boolean existRealSch(String lineCode, String schDate) {
  293 + int count = schRepository.countByLineCodeAndDate(lineCode, schDate);
  294 + return count > 0;
  295 + }
  296 +
  297 + /**
  298 + * @Title: loadRealSch
  299 + * @Description: TODO(从实际排班表加载数据)
  300 + */
  301 + public List<ScheduleRealInfo> loadRealSch(String lineCode, String schDate) {
  302 + return schRepository.findByLineCodeAndDate(lineCode, schDate);
  303 + }
  304 +
  305 + /**
  306 + * @Title: loadPlanSch
  307 + * @Description: TODO(从计划排班表加载数据)
  308 + */
  309 + public List<ScheduleRealInfo> loadPlanSch(String lineCode, String schDate) {
  310 + logger.info("从计划排班表恢复排班,lineCode: " + lineCode + ", schDate: " + schDate);
  311 + List<ScheduleRealInfo> realList = new ArrayList<>();
  312 +
  313 + try {
  314 + Map<String, Object> data = new HashMap<>();
  315 +
  316 + data.put("scheduleDate_eq", fmtyyyyMMdd.parseDateTime(schDate).toDate());
  317 + data.put("xlBm_eq", lineCode);
  318 +
  319 + // 查询计划排班
  320 + List<SchedulePlanInfo> planItr = cleanSchPlanItr(schPlanService.list(data).iterator());
  321 +
  322 + // 转换为实际排班
  323 + realList = JSONArray.parseArray(JSON.toJSONString(planItr), ScheduleRealInfo.class);
  324 +
  325 + SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
  326 + String fcsj;
  327 + for (ScheduleRealInfo sch : realList) {
  328 + sch.setScheduleDateStr(fmtyyyyMMdd.print(sch.getScheduleDate().getTime()));
  329 + sch.setRealExecDate(sch.getScheduleDateStr());
  330 +
  331 + if(StringUtils.isEmpty(sch.getFcsj()))
  332 + sch.setFcsj("00:00");
  333 +
  334 + fcsj=sch.getFcsj().trim();
  335 + //处理一下发车时间格式没有:号的问题
  336 + if(fcsj.indexOf(":") == -1 && fcsj.length() >= 4){
  337 + sch.setFcsj(fcsj.substring(0, 2) + ":" + fcsj.substring(2, 4));
  338 + }
  339 +
  340 + try {
  341 + sdf.parse(sch.getFcsj());
  342 + } catch (ParseException e) {
  343 + //发车时间仍然校验不过的,直接写成00:00
  344 + sch.setFcsj("00:00");
  345 + }
  346 +
  347 + // 计划终点时间
  348 + if (sch.getBcsj() != null) {
  349 + sch.setZdsj(fmtHHmm.print(fmtHHmm.parseMillis(sch.getFcsj()) + (sch.getBcsj() * 60 * 1000)));
  350 + sch.setLate(false);
  351 + }
  352 + //计划里程为0,设置NULL
  353 + if(sch.getJhlc() != null && sch.getJhlc() == 0)
  354 + sch.setJhlc(null);
  355 + }
  356 + } catch (Exception e) {
  357 + logger.error("", e);
  358 + }
  359 + return realList;
  360 + }
  361 +
  362 + /**
  363 + * @Title: batchSave
  364 + * @Description: TODO(批量入库)
  365 + */
  366 + private void batchSave(List<ScheduleRealInfo> list) {
  367 + // 查询数据库最大ID
  368 + Long id = schRepository.getMaxId();
  369 + if (null == id)
  370 + id = 0L;
  371 + id++;
  372 +
  373 + SimpleDateFormat sdfyyyyMMdd = new SimpleDateFormat("yyyy-MM-dd");
  374 + for (ScheduleRealInfo item : list) {
  375 + item.setSpId(item.getId());// 保留原始的计划ID
  376 + item.setId(id++);// 设置ID
  377 + item.setScheduleDateStr(sdfyyyyMMdd.format(item.getScheduleDate()));
  378 + }
  379 +
  380 + // 入库
  381 + new BatchSaveUtils<ScheduleRealInfo>().saveList(list, ScheduleRealInfo.class);
  382 + }
  383 +
  384 + private List<SchedulePlanInfo> cleanSchPlanItr(Iterator<SchedulePlanInfo> itrab) {
  385 + List<SchedulePlanInfo> list = new ArrayList<>();
  386 +
  387 + SchedulePlanInfo sp;
  388 + while (itrab.hasNext()) {
  389 + sp = itrab.next();
  390 + sp.setSchedulePlan(null);
  391 + list.add(sp);
  392 + }
  393 + return list;
  394 + }
  395 +
  396 + /**
  397 + *
  398 + * @Title: findByLineCode
  399 + * @Description: TODO(lineCode 获取班次)
  400 + */
  401 + public List<ScheduleRealInfo> findByLineCode(String lineCode) {
  402 + List<ScheduleRealInfo> rs = new ArrayList<>();
  403 +
  404 + Collection<ScheduleRealInfo> schs = nbbmScheduleMap.values();
  405 + for (ScheduleRealInfo sch : schs) {
  406 + if (sch.getXlBm().equals(lineCode))
  407 + rs.add(sch);
  408 + }
  409 + return rs;
  410 + }
  411 +
  412 + /**
  413 + *
  414 + * @Title: findCarByLineCode
  415 + * @Description: TODO(线路下运营的车辆)
  416 + */
  417 + public Set<String> findCarByLineCode(String lineCode){
  418 + Set<String> rs = new HashSet<>();
  419 +
  420 + Collection<ScheduleRealInfo> schs = nbbmScheduleMap.values();
  421 + for (ScheduleRealInfo sch : schs) {
  422 + if (sch.getXlBm().equals(lineCode))
  423 + rs.add(sch.getClZbh());
  424 + }
  425 +
  426 + return rs;
  427 + }
  428 +
  429 + public List<ScheduleRealInfo> findByNbbm(String nbbm) {
  430 + return nbbmScheduleMap.get(nbbm);
  431 + }
  432 +
  433 + /**
  434 + *
  435 + * @Title: findByLineAndUpDown
  436 + * @Description: TODO(lineCode 和走向获取班次)
  437 + */
  438 + public List<ScheduleRealInfo> findByLineAndUpDown(String lineCode, Integer upDown) {
  439 + List<ScheduleRealInfo> list = findByLineCode(lineCode), rs = new ArrayList<>();
  440 +
  441 + for (ScheduleRealInfo sch : list) {
  442 + if (sch.getXlDir().equals(upDown + ""))
  443 + rs.add(sch);
  444 + }
  445 + return rs;
  446 + }
  447 +
  448 + public ScheduleRealInfo get(long id) {
  449 + return id2SchedulMap.get(id);
  450 + }
  451 +
  452 + public Set<String> getSEStationList(String nbbm) {
  453 + return nbbm2SEStationMap.get(nbbm);
  454 + }
  455 +
  456 + /**
  457 + *
  458 + * @Title: next
  459 + * @Description: TODO(下一个班次)
  460 + */
  461 + public ScheduleRealInfo next(ScheduleRealInfo sch) {
  462 +
  463 + List<ScheduleRealInfo> list = nbbmScheduleMap.get(sch.getClZbh());
  464 +
  465 + boolean flag = false;
  466 + ScheduleRealInfo next = null;
  467 + for(ScheduleRealInfo temp : list){
  468 + if(temp.getId() == sch.getId()){
  469 + flag = true;
  470 + continue;
  471 + }
  472 + //忽略烂班
  473 + if(temp.isDestroy())
  474 + continue;
  475 +
  476 + if(flag){
  477 + next = temp;
  478 + break;
  479 + }
  480 + }
  481 + return next;
  482 + }
  483 +
  484 + public void put(ScheduleRealInfo sch) {
  485 +
  486 + schAttrCalculator
  487 + .calcRealDate(sch)
  488 + .calcAllTimeByFcsj(sch);
  489 +
  490 + String nbbm = sch.getClZbh();
  491 + nbbmScheduleMap.put(nbbm, sch);
  492 + nbbm2SEStationMap.put(nbbm, sch.getQdzCode());
  493 + nbbm2SEStationMap.put(nbbm, sch.getZdzCode());
  494 +
  495 + //主键索引
  496 + id2SchedulMap.put(sch.getId(), sch);
  497 + }
  498 +
  499 + public void delete(ScheduleRealInfo sch) {
  500 + //ScheduleRealInfo sch = id2SchedulMap.get(id);
  501 + if(!sch.isSflj())
  502 + return;
  503 +
  504 + nbbmScheduleMap.remove(sch.getClZbh(), sch);
  505 + id2SchedulMap.remove(sch.getId());
  506 + //return sch;
  507 + }
  508 +
  509 +// public void calcQdzTimePlan(String nbbm){
  510 +// schAttrCalculator.calcQdzTimePlan(nbbmScheduleMap.get(nbbm));
  511 +// }
  512 +
  513 + public List<ScheduleRealInfo> updateQdzTimePlan(String nbbm){
  514 + return schAttrCalculator.updateQdzTimePlan(nbbmScheduleMap.get(nbbm));
  515 + }
  516 +
  517 + /**
  518 + *
  519 + * @Title: nextAll
  520 + * @Description: TODO(之后的所有班次)
  521 + */
  522 +/* public List<ScheduleRealInfo> nextAll(ScheduleRealInfo sch) {
  523 + List<ScheduleRealInfo> list = nbbmScheduleMap.get(sch.getClZbh());
  524 + // 排序
  525 + Collections.sort(list, schFCSJComparator);
  526 +
  527 + List<ScheduleRealInfo> rs = new ArrayList<>();
  528 + ScheduleRealInfo temp;
  529 + for (int i = 0; i < list.size() - 1; i++) {
  530 + temp = list.get(i);
  531 + if(temp.getFcsjT() > sch.getFcsjT())
  532 + rs.add(temp);
  533 +
  534 + }
  535 + return rs;
  536 + }*/
  537 +
  538 + /**
  539 + *
  540 + * @Title: doneSum
  541 + * @Description: TODO(已完成班次总数)
  542 + */
  543 + public int doneSum(String clZbh) {
  544 + List<ScheduleRealInfo> list = nbbmScheduleMap.get(clZbh);
  545 + int rs = 0;
  546 +
  547 + for(ScheduleRealInfo sch : list){
  548 + if(sch.getStatus() == 2 && !sch.isDestroy())
  549 + rs ++;
  550 + }
  551 + return rs;
  552 + }
  553 +
  554 + /**
  555 + *
  556 + * @Title: prveNotExecNum
  557 + * @Description: TODO(班次之前未执行班次数量)
  558 + */
  559 + public int prveNotExecNum(ScheduleRealInfo sch){
  560 + int n = 0;
  561 + List<ScheduleRealInfo> list = nbbmScheduleMap.get(sch.getClZbh());
  562 + for(ScheduleRealInfo s : list){
  563 + if(s.getFcsjActual() == null && !s.isDestroy())
  564 + n ++;
  565 +
  566 + if(s.getId().equals(sch.getId()))
  567 + break;
  568 + }
  569 + return n;
  570 + }
  571 +
  572 + /**
  573 + *
  574 + * @Title: validEndTime
  575 + * @Description: TODO(是否是有效的到达时间)
  576 + */
  577 + public boolean validEndTime(ScheduleRealInfo sch, Long ts) {
  578 + if(sch.getFcsjActualTime() != null && sch.getFcsjActualTime() > ts)
  579 + return false;
  580 +
  581 + return validTime(sch, ts);
  582 + }
  583 +
  584 + /**
  585 + *
  586 + * @Title: validStartTime
  587 + * @Description: TODO(是否是合适的发车时间)
  588 + */
  589 + public boolean validStartTime(ScheduleRealInfo sch, Long ts) {
  590 + if(sch.getZdsjActualTime() != null && sch.getZdsjActualTime() < ts)
  591 + return false;
  592 +
  593 + return validTime(sch, ts);
  594 + }
  595 +
  596 + public boolean validTime(ScheduleRealInfo sch, Long ts){
  597 + List<ScheduleRealInfo> list = nbbmScheduleMap.get(sch.getClZbh());
  598 + int ci = list.indexOf(sch);
  599 + ScheduleRealInfo prve, next;
  600 + if(ci > 0){
  601 + //之前班次实际时间不能大于该时间
  602 + for(int i = ci - 1; i >= 0; i --){
  603 + prve = list.get(i);
  604 + if(prve.getZdsjActualTime() != null && prve.getZdsjActualTime() > ts )
  605 + return false;
  606 +
  607 + if(prve.getFcsjActualTime() != null && prve.getFcsjActualTime() > ts)
  608 + return false;
  609 + }
  610 + }
  611 +
  612 + if(ci < list.size() - 1){
  613 + //之后班次实际时间不能小于该时间
  614 + for(int i = ci + 1; i < list.size(); i ++){
  615 + next = list.get(i);
  616 + if(next.getFcsjActualTime() != null && next.getFcsjActualTime() < ts)
  617 + return false;
  618 +
  619 + if(next.getZdsjActualTime() != null && next.getZdsjActualTime() < ts)
  620 + return false;
  621 + }
  622 + }
  623 + return true;
  624 + }
  625 +
  626 + public void save(ScheduleRealInfo sch){
  627 + //schRepository.save(sch);
  628 + pstBuffer.add(sch);
  629 + }
  630 +
  631 +
  632 + /**
  633 + *
  634 + * @Title: nextByBcType
  635 + * @Description: TODO(获取下一个指定班次类型的班次)
  636 + */
  637 + public ScheduleRealInfo nextByBcType(String nbbm, String bcType){
  638 + List<ScheduleRealInfo> list = findByBcType(nbbm, bcType);
  639 +
  640 + Collections.sort(list, schFCSJComparator);
  641 + ScheduleRealInfo sch = null;
  642 + for(ScheduleRealInfo temp : list){
  643 + if(temp.getFcsjActual() == null)
  644 + sch = temp;
  645 + }
  646 +
  647 + return sch;
  648 + }
  649 +
  650 + public List<ScheduleRealInfo> findByBcType(String nbbm, String bcType){
  651 + List<ScheduleRealInfo> all = nbbmScheduleMap.get(nbbm)
  652 + ,outList = new ArrayList<>();
  653 +
  654 + for(ScheduleRealInfo sch : all){
  655 + if(sch.getBcType().equals(bcType))
  656 + outList.add(sch);
  657 + }
  658 + return outList;
  659 + }
  660 +
  661 + public Set<String> allCar(){
  662 + return nbbmScheduleMap.keySet();
  663 + }
  664 +
  665 + public Collection<ScheduleRealInfo> findAll(){
  666 + return nbbmScheduleMap.values();
  667 + }
  668 +
  669 + public void addExecPlan(ScheduleRealInfo sch){
  670 + carExecutePlanMap.put(sch.getClZbh(), sch);
  671 + }
  672 +
  673 + public void removeExecPlan(String clzbh){
  674 + carExecutePlanMap.remove(clzbh);
  675 + }
  676 +
  677 + public Map<String, ScheduleRealInfo> execPlamMap(){
  678 + return carExecutePlanMap;
  679 + }
  680 +
  681 + /**
  682 + * @Title: changeCar
  683 + * @Description: TODO(班次换车) 返回有更新的班次
  684 + * @param @param sch
  685 + * @param @param newClZbh 新的车辆自编号
  686 + */
  687 + public List<ScheduleRealInfo> changeCar(ScheduleRealInfo sch , String newClZbh){
  688 + List<ScheduleRealInfo> ups = new ArrayList<>();
  689 + String oldClzbh = sch.getClZbh();
  690 + if(oldClzbh.equals(newClZbh))
  691 + return ups;
  692 +
  693 +
  694 + //变更相关映射信息
  695 + nbbmScheduleMap.remove(sch.getClZbh(), sch);
  696 +
  697 + sch.setClZbh(newClZbh);
  698 + nbbmScheduleMap.put(newClZbh, sch);
  699 + nbbm2SEStationMap.put(newClZbh, sch.getQdzCode());
  700 + nbbm2SEStationMap.put(newClZbh, sch.getZdzCode());
  701 +
  702 + //重新计算班次应到时间
  703 + ups.addAll(updateQdzTimePlan(oldClzbh));
  704 + ups.addAll(updateQdzTimePlan(newClZbh));
  705 + return ups;
  706 + }
  707 +
  708 + /**
  709 + *
  710 + * @Title: linkToSchPlan
  711 + * @Description: TODO(车辆关联到班次)
  712 + */
  713 +/* public void linkToSchPlan(String nbbm) {
  714 + //当前GPS状态
  715 + GpsEntity gps = gpsRealData.get(BasicData.deviceId2NbbmMap.inverse().get(nbbm));
  716 + if(null == gps)
  717 + return;
  718 +
  719 + //班次集合
  720 + List<ScheduleRealInfo> schArr = nbbmScheduleMap.get(nbbm);
  721 +
  722 + for(ScheduleRealInfo sch : schArr){
  723 + if(sch.getStatus() == 2)
  724 + continue;
  725 + if(sch.isDestroy())
  726 + continue;
  727 + if(!sch.getXlBm().equals(gps.getLineId())
  728 + || Integer.parseInt(sch.getXlDir()) != gps.getUpDown().intValue())
  729 + continue;
  730 +
  731 + addExecPlan(sch);
  732 + break;
  733 + }
  734 + }*/
  735 +}
702 \ No newline at end of file 736 \ No newline at end of file
src/main/java/com/bsth/data/schedule/thread/SubmitToTrafficManage.java 0 → 100644
  1 +package com.bsth.data.schedule.thread;
  2 +
  3 +import com.bsth.service.TrafficManageService;
  4 +import org.slf4j.Logger;
  5 +import org.slf4j.LoggerFactory;
  6 +import org.springframework.beans.factory.annotation.Autowired;
  7 +import org.springframework.stereotype.Component;
  8 +
  9 +/**
  10 + * 运营数据提交到运管处
  11 + * Created by panzhao on 2016/11/9.
  12 + */
  13 +@Component
  14 +public class SubmitToTrafficManage extends Thread{
  15 +
  16 + Logger logger = LoggerFactory.getLogger(this.getClass());
  17 +
  18 + @Autowired
  19 + TrafficManageService trafficManageService;
  20 +
  21 + @Override
  22 + public void run() {
  23 + logger.info("开始提交数据到运管处...");
  24 + try {
  25 + //路单
  26 + trafficManageService.setLD();
  27 + } catch (Exception e) {
  28 + logger.error("提交路单到运管处失败", e);
  29 + }
  30 + try {
  31 + //车辆里程、油耗
  32 + trafficManageService.setLCYH();
  33 + } catch (Exception e) {
  34 + logger.error("提交车辆里程、油耗到运管处失败", e);
  35 + }
  36 + try {
  37 + //线路调度日报
  38 + trafficManageService.setDDRB();
  39 + } catch (Exception e) {
  40 + logger.error("提交线路调度日报到运管处失败", e);
  41 + }
  42 + try {
  43 + //线路计划班次表
  44 + trafficManageService.setJHBC();
  45 + } catch (Exception e) {
  46 + logger.error("提交线路计划班次表到运管处失败", e);
  47 + }
  48 + logger.info("提交数据到运管处结束!");
  49 + }
  50 +}
src/main/java/com/bsth/entity/Line.java
@@ -116,6 +116,12 @@ public class Line implements Serializable { @@ -116,6 +116,12 @@ public class Line implements Serializable {
116 /** 普通车辆数量 老版本系统字段, 新版本系统业务需求暂时没用到该字段 ,这里暂时留着 int length(11) */ 116 /** 普通车辆数量 老版本系统字段, 新版本系统业务需求暂时没用到该字段 ,这里暂时留着 int length(11) */
117 private Integer ordCarNumber; 117 private Integer ordCarNumber;
118 118
  119 + /** 权证车辆数量 报表需要的字段值 */
  120 + private Integer warrantCar;
  121 +
  122 + /** 权证配车启用日期 报表需要的字段值 */
  123 + private Integer warrantDate;
  124 +
119 /** 停车场编码 老版本系统字段, 新版本系统业务需求暂时没用到该字段 ,这里暂时留着 int length(11) */ 125 /** 停车场编码 老版本系统字段, 新版本系统业务需求暂时没用到该字段 ,这里暂时留着 int length(11) */
120 private String carParkCode; 126 private String carParkCode;
121 127
@@ -139,6 +145,22 @@ public class Line implements Serializable { @@ -139,6 +145,22 @@ public class Line implements Serializable {
139 @Column(name = "update_date", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP") 145 @Column(name = "update_date", columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")
140 private Date updateDate; 146 private Date updateDate;
141 147
  148 + public Integer getWarrantCar() {
  149 + return warrantCar;
  150 + }
  151 +
  152 + public void setWarrantCar(Integer warrantCar) {
  153 + this.warrantCar = warrantCar;
  154 + }
  155 +
  156 + public Integer getWarrantDate() {
  157 + return warrantDate;
  158 + }
  159 +
  160 + public void setWarrantDate(Integer warrantDate) {
  161 + this.warrantDate = warrantDate;
  162 + }
  163 +
142 public Integer getLinePlayType() { 164 public Integer getLinePlayType() {
143 return linePlayType; 165 return linePlayType;
144 } 166 }
src/main/java/com/bsth/entity/directive/D60.java
@@ -17,251 +17,276 @@ import com.fasterxml.jackson.annotation.JsonIgnore; @@ -17,251 +17,276 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
17 17
18 18
19 /** 19 /**
20 - *  
21 - * @ClassName: D60  
22 - * @Description: TODO(调度指令)  
23 * @author PanZhao 20 * @author PanZhao
24 - * @date 2016年6月7日 上午10:21:59  
25 - * 21 + * @ClassName: D60
  22 + * @Description: TODO(调度指令)
  23 + * @date 2016年6月7日 上午10:21:59
26 */ 24 */
27 @Entity 25 @Entity
28 @Table(name = "bsth_v_directive_60") 26 @Table(name = "bsth_v_directive_60")
29 @NamedEntityGraphs({ 27 @NamedEntityGraphs({
30 - @NamedEntityGraph(name = "directive60_sch", attributeNodes = {  
31 - @NamedAttributeNode("sch")  
32 - }) 28 + @NamedEntityGraph(name = "directive60_sch", attributeNodes = {
  29 + @NamedAttributeNode("sch")
  30 + })
33 }) 31 })
34 -public class D60 extends Directive{ 32 +public class D60 extends Directive {
35 33
36 - @Id 34 + @Id
37 @GeneratedValue 35 @GeneratedValue
38 - private Integer id;  
39 -  
40 - /**  
41 - * 数据  
42 - */  
43 - private D60Data data;  
44 -  
45 - /**  
46 - * 唯一标识  
47 - */  
48 - @Transient  
49 - private Integer msgId;  
50 -  
51 - /**  
52 - * 46上行  
53 - */  
54 - private Short reply46 = -1;  
55 -  
56 - /**  
57 - * 47上行  
58 - */  
59 - private Short reply47 = -1;  
60 -  
61 - /**  
62 - * 是否是调度指令  
63 - * 目前调度指令和消息短语都是短语下发,所以从协议上无法区分  
64 - */  
65 - private boolean isDispatch;  
66 -  
67 - /**  
68 - * 相关联的班次  
69 - */  
70 - @JsonIgnore  
71 - @ManyToOne(fetch = FetchType.LAZY)  
72 - private ScheduleRealInfo sch;  
73 -  
74 - @Embeddable  
75 - public static class D60Data {  
76 - // 公司代码  
77 - private short companyCode;  
78 -  
79 - // 设备号  
80 - @Transient  
81 - private String deviceId;  
82 -  
83 - // 时间戳  
84 - @Transient  
85 - private Long timestamp;  
86 -  
87 - // 保留 默认0  
88 - private short instructType = 0;  
89 -  
90 - /*  
91 - * 调度指令 调度指令。  
92 - * 0X00表示信息短语  
93 - * 0X01表示取消上次指令+调度指令(闹钟有效)  
94 - * 0x02表示为调度指令(闹钟有效)  
95 - * 0x03表示运营状态指令(闹钟无效)  
96 - * 0x04表示其他指令  
97 - */  
98 - private Short dispatchInstruct;  
99 -  
100 - // 唯一标识  
101 - private int msgId;  
102 -  
103 - // 闹钟  
104 - private Long alarmTime;  
105 -  
106 - // 多个运营状态字节  
107 - private Long serviceState;  
108 -  
109 - // 消息文本  
110 - private String txtContent;  
111 -  
112 - public short getCompanyCode() {  
113 - return companyCode;  
114 - }  
115 -  
116 - public void setCompanyCode(short companyCode) {  
117 - this.companyCode = companyCode;  
118 - }  
119 -  
120 - public String getDeviceId() {  
121 - return deviceId;  
122 - }  
123 -  
124 - public void setDeviceId(String deviceId) {  
125 - this.deviceId = deviceId;  
126 - }  
127 -  
128 - public Long getTimestamp() {  
129 - return timestamp;  
130 - }  
131 -  
132 - public void setTimestamp(Long timestamp) {  
133 - this.timestamp = timestamp;  
134 - }  
135 -  
136 - public short getInstructType() {  
137 - return instructType;  
138 - }  
139 -  
140 - public void setInstructType(short instructType) {  
141 - this.instructType = instructType;  
142 - }  
143 -  
144 - public Short getDispatchInstruct() {  
145 - return dispatchInstruct;  
146 - }  
147 -  
148 - public void setDispatchInstruct(Short dispatchInstruct) {  
149 - this.dispatchInstruct = dispatchInstruct;  
150 - }  
151 -  
152 - public int getMsgId() {  
153 - return msgId;  
154 - }  
155 -  
156 - public void setMsgId(int msgId) {  
157 - this.msgId = msgId;  
158 - }  
159 -  
160 - public Long getAlarmTime() {  
161 - return alarmTime;  
162 - }  
163 -  
164 - public void setAlarmTime(Long alarmTime) {  
165 - this.alarmTime = alarmTime;  
166 - }  
167 -  
168 - public Long getServiceState() {  
169 - return serviceState;  
170 - }  
171 -  
172 - public void setServiceState(Long serviceState) {  
173 - this.serviceState = serviceState;  
174 - }  
175 -  
176 - public String getTxtContent() {  
177 - return txtContent;  
178 - }  
179 -  
180 - public void setTxtContent(String txtContent) {  
181 - this.txtContent = txtContent;  
182 - }  
183 - }  
184 -  
185 - public Integer getId() {  
186 - return id;  
187 - }  
188 -  
189 - public void setId(Integer id) {  
190 - this.id = id;  
191 - }  
192 -  
193 - public short getOperCode() {  
194 - return operCode;  
195 - }  
196 -  
197 - public void setOperCode(short operCode) {  
198 - this.operCode = operCode;  
199 - }  
200 -  
201 - public D60Data getData() {  
202 - return data;  
203 - }  
204 -  
205 - public void setData(D60Data data) {  
206 - this.data = data;  
207 - }  
208 -  
209 - public Integer getMsgId() {  
210 - if(this.msgId != null)  
211 - return this.msgId;  
212 - else  
213 - return this.getData().getMsgId();  
214 - }  
215 -  
216 - public void setMsgId(Integer msgId) {  
217 - this.msgId = msgId;  
218 - }  
219 -  
220 - @Override  
221 - public void setTimestamp(Long timestamp) {  
222 - if(this.data != null)  
223 - this.data.setTimestamp(timestamp);  
224 -  
225 - this.timestamp = timestamp;  
226 - }  
227 -  
228 - @Override  
229 - public void setDeviceId(String deviceId) {  
230 - if(this.data != null)  
231 - this.data.setDeviceId(deviceId);  
232 -  
233 - this.deviceId = deviceId;  
234 - }  
235 -  
236 - public Short getReply46() {  
237 - return reply46;  
238 - }  
239 -  
240 - public void setReply46(Short reply46) {  
241 - this.reply46 = reply46;  
242 - }  
243 -  
244 - public Short getReply47() {  
245 - return reply47;  
246 - }  
247 -  
248 - public void setReply47(Short reply47) {  
249 - this.reply47 = reply47;  
250 - }  
251 -  
252 - public boolean isDispatch() {  
253 - return isDispatch;  
254 - }  
255 -  
256 - public void setDispatch(boolean isDispatch) {  
257 - this.isDispatch = isDispatch;  
258 - }  
259 -  
260 - public ScheduleRealInfo getSch() {  
261 - return sch;  
262 - }  
263 -  
264 - public void setSch(ScheduleRealInfo sch) {  
265 - this.sch = sch;  
266 - } 36 + private Integer id;
  37 +
  38 + /**
  39 + * 数据
  40 + */
  41 + private D60Data data;
  42 +
  43 + /**
  44 + * 唯一标识
  45 + */
  46 + @Transient
  47 + private Integer msgId;
  48 +
  49 + /**
  50 + * 46上行
  51 + */
  52 + private Short reply46 = -1;
  53 + /**
  54 + * 46收到时间
  55 + */
  56 + private Long reply46Time;
  57 +
  58 + /**
  59 + * 47上行
  60 + */
  61 + private Short reply47 = -1;
  62 +
  63 + /**
  64 + * 47收到时间
  65 + */
  66 + private Long reply47Time;
  67 +
  68 + /**
  69 + * 是否是调度指令
  70 + * 目前调度指令和消息短语都是短语下发,所以从协议上无法区分
  71 + */
  72 + private boolean isDispatch;
  73 +
  74 + /**
  75 + * 相关联的班次
  76 + */
  77 + @JsonIgnore
  78 + @ManyToOne(fetch = FetchType.LAZY)
  79 + private ScheduleRealInfo sch;
  80 +
  81 + public Long getReply46Time() {
  82 + return reply46Time;
  83 + }
  84 +
  85 + public void setReply46Time(Long reply46Time) {
  86 + this.reply46Time = reply46Time;
  87 + }
  88 +
  89 + public Long getReply47Time() {
  90 + return reply47Time;
  91 + }
  92 +
  93 + public void setReply47Time(Long reply47Time) {
  94 + this.reply47Time = reply47Time;
  95 + }
  96 +
  97 + @Embeddable
  98 + public static class D60Data {
  99 + // 公司代码
  100 + private short companyCode;
  101 +
  102 + // 设备号
  103 + @Transient
  104 + private String deviceId;
  105 +
  106 + // 时间戳
  107 + @Transient
  108 + private Long timestamp;
  109 +
  110 + // 保留 默认0
  111 + private short instructType = 0;
  112 +
  113 + /*
  114 + * 调度指令 调度指令。
  115 + * 0X00表示信息短语
  116 + * 0X01表示取消上次指令+调度指令(闹钟有效)
  117 + * 0x02表示为调度指令(闹钟有效)
  118 + * 0x03表示运营状态指令(闹钟无效)
  119 + * 0x04表示其他指令
  120 + */
  121 + private Short dispatchInstruct;
  122 +
  123 + // 唯一标识
  124 + private int msgId;
  125 +
  126 + // 闹钟
  127 + private Long alarmTime;
  128 +
  129 + // 多个运营状态字节
  130 + private Long serviceState;
  131 +
  132 + // 消息文本
  133 + private String txtContent;
  134 +
  135 + public short getCompanyCode() {
  136 + return companyCode;
  137 + }
  138 +
  139 + public void setCompanyCode(short companyCode) {
  140 + this.companyCode = companyCode;
  141 + }
  142 +
  143 + public String getDeviceId() {
  144 + return deviceId;
  145 + }
  146 +
  147 + public void setDeviceId(String deviceId) {
  148 + this.deviceId = deviceId;
  149 + }
  150 +
  151 + public Long getTimestamp() {
  152 + return timestamp;
  153 + }
  154 +
  155 + public void setTimestamp(Long timestamp) {
  156 + this.timestamp = timestamp;
  157 + }
  158 +
  159 + public short getInstructType() {
  160 + return instructType;
  161 + }
  162 +
  163 + public void setInstructType(short instructType) {
  164 + this.instructType = instructType;
  165 + }
  166 +
  167 + public Short getDispatchInstruct() {
  168 + return dispatchInstruct;
  169 + }
  170 +
  171 + public void setDispatchInstruct(Short dispatchInstruct) {
  172 + this.dispatchInstruct = dispatchInstruct;
  173 + }
  174 +
  175 + public int getMsgId() {
  176 + return msgId;
  177 + }
  178 +
  179 + public void setMsgId(int msgId) {
  180 + this.msgId = msgId;
  181 + }
  182 +
  183 + public Long getAlarmTime() {
  184 + return alarmTime;
  185 + }
  186 +
  187 + public void setAlarmTime(Long alarmTime) {
  188 + this.alarmTime = alarmTime;
  189 + }
  190 +
  191 + public Long getServiceState() {
  192 + return serviceState;
  193 + }
  194 +
  195 + public void setServiceState(Long serviceState) {
  196 + this.serviceState = serviceState;
  197 + }
  198 +
  199 + public String getTxtContent() {
  200 + return txtContent;
  201 + }
  202 +
  203 + public void setTxtContent(String txtContent) {
  204 + this.txtContent = txtContent;
  205 + }
  206 + }
  207 +
  208 + public Integer getId() {
  209 + return id;
  210 + }
  211 +
  212 + public void setId(Integer id) {
  213 + this.id = id;
  214 + }
  215 +
  216 + public short getOperCode() {
  217 + return operCode;
  218 + }
  219 +
  220 + public void setOperCode(short operCode) {
  221 + this.operCode = operCode;
  222 + }
  223 +
  224 + public D60Data getData() {
  225 + return data;
  226 + }
  227 +
  228 + public void setData(D60Data data) {
  229 + this.data = data;
  230 + }
  231 +
  232 + public Integer getMsgId() {
  233 + if (this.msgId != null)
  234 + return this.msgId;
  235 + else
  236 + return this.getData().getMsgId();
  237 + }
  238 +
  239 + public void setMsgId(Integer msgId) {
  240 + this.msgId = msgId;
  241 + }
  242 +
  243 + @Override
  244 + public void setTimestamp(Long timestamp) {
  245 + if (this.data != null)
  246 + this.data.setTimestamp(timestamp);
  247 +
  248 + this.timestamp = timestamp;
  249 + }
  250 +
  251 + @Override
  252 + public void setDeviceId(String deviceId) {
  253 + if (this.data != null)
  254 + this.data.setDeviceId(deviceId);
  255 +
  256 + this.deviceId = deviceId;
  257 + }
  258 +
  259 + public Short getReply46() {
  260 + return reply46;
  261 + }
  262 +
  263 + public void setReply46(Short reply46) {
  264 + this.reply46 = reply46;
  265 + }
  266 +
  267 + public Short getReply47() {
  268 + return reply47;
  269 + }
  270 +
  271 + public void setReply47(Short reply47) {
  272 + this.reply47 = reply47;
  273 + }
  274 +
  275 + public boolean isDispatch() {
  276 + return isDispatch;
  277 + }
  278 +
  279 + public void setDispatch(boolean isDispatch) {
  280 + this.isDispatch = isDispatch;
  281 + }
  282 +
  283 + public ScheduleRealInfo getSch() {
  284 + return sch;
  285 + }
  286 +
  287 + public void setSch(ScheduleRealInfo sch) {
  288 + this.sch = sch;
  289 + }
  290 +
  291 +
267 } 292 }
src/main/java/com/bsth/entity/excep/ArrivalInfo.java 0 → 100644
  1 +package com.bsth.entity.excep;
  2 +
  3 +import java.text.SimpleDateFormat;
  4 +import java.util.Date;
  5 +
  6 +import com.bsth.data.BasicData;
  7 +
  8 +/**
  9 + *
  10 + * @ClassName: ArrivalEntity
  11 + * @Description: TODO(进出站实体)
  12 + * @author PanZhao
  13 + * @date 2016年8月19日 上午9:32:20
  14 + *
  15 + */
  16 +public class ArrivalInfo {
  17 +
  18 + /** 设备号*/
  19 + private String deviceId;
  20 +
  21 + private String nbbm;
  22 +
  23 + /** 站点名称 */
  24 + private String stopName;
  25 +
  26 + /** 时间戳*/
  27 + private Long ts;
  28 +
  29 + /** 线路编码*/
  30 + private String lineCode;
  31 +
  32 + /** 上下行*/
  33 + private Integer upDown;
  34 +
  35 + /**站点编码*/
  36 + private String stopNo;
  37 +
  38 + /** 0: 进 1:出*/
  39 + private Integer inOut;
  40 +
  41 + private Long createDate;
  42 +
  43 + /** 是否有效 */
  44 + private boolean enable;
  45 +
  46 + /**分区字段,当年的第几周*/
  47 + private Integer weeksYear;
  48 +
  49 + private boolean tcc;
  50 +
  51 + //是否被纠正
  52 + private boolean correct;
  53 +
  54 + private String correctText;
  55 +
  56 +
  57 + private String czsj;
  58 +
  59 + private String jzsj;
  60 + /** -1 则信号有效,但程序标记为不使用 */
  61 + private int flag = 0;
  62 +
  63 + public ArrivalInfo(){}
  64 +
  65 + public ArrivalInfo(String deviceId, long ts, String lineCode, int upDown, String stopNo, int inOut, long createDate,
  66 + int weeksYear, String stopName) {
  67 +
  68 + this.deviceId = deviceId;
  69 + this.ts = ts;
  70 + this.lineCode = lineCode;
  71 + this.upDown = upDown;
  72 + this.stopNo = stopNo;
  73 + this.stopName = stopName;
  74 + this.inOut = inOut;
  75 + this.createDate = createDate;
  76 + }
  77 +
  78 +/* @Override
  79 + public boolean equals(Object obj) {
  80 + ArrivalEntity a2 = (ArrivalEntity)obj;
  81 +
  82 + return this.toString().equals(a2.toString())
  83 + && Math.abs(this.ts - a2.ts) < EQ_RANGE;
  84 + }
  85 +
  86 + @Override
  87 + public int hashCode() {
  88 + return this.toString().hashCode();
  89 + }*/
  90 +
  91 +
  92 + @Override
  93 + public String toString() {
  94 + try {
  95 + SimpleDateFormat sdfHHmm = new SimpleDateFormat("HH:mm");
  96 + return "["+BasicData.deviceId2NbbmMap.get(this.deviceId)+", "+sdfHHmm.format(new Date(this.ts))
  97 + +","+(this.getUpDown()==0?"上行":"下行")+","+(this.inOut==0?"进":"出")+","+this.stopNo+" ("+this.stopName+")]";
  98 + } catch (Exception e) {
  99 + return "";
  100 + }
  101 + }
  102 +
  103 + public String getLineCode() {
  104 + return lineCode;
  105 + }
  106 +
  107 + public void setLineCode(String lineCode) {
  108 + this.lineCode = lineCode;
  109 + }
  110 +
  111 + public Integer getUpDown() {
  112 + return upDown;
  113 + }
  114 +
  115 + public void setUpDown(Integer upDown) {
  116 + this.upDown = upDown;
  117 + }
  118 +
  119 + public String getStopNo() {
  120 + return stopNo;
  121 + }
  122 +
  123 + public void setStopNo(String stopNo) {
  124 + this.stopNo = stopNo;
  125 + }
  126 +
  127 + public Integer getInOut() {
  128 + return inOut;
  129 + }
  130 +
  131 + public void setInOut(Integer inOut) {
  132 + this.inOut = inOut;
  133 + }
  134 +
  135 + public Long getCreateDate() {
  136 + return createDate;
  137 + }
  138 +
  139 + public void setCreateDate(Long createDate) {
  140 + this.createDate = createDate;
  141 + }
  142 +
  143 + public Integer getWeeksYear() {
  144 + return weeksYear;
  145 + }
  146 +
  147 + public void setWeeksYear(Integer weeksYear) {
  148 + this.weeksYear = weeksYear;
  149 + }
  150 +
  151 + public String getDeviceId() {
  152 + return deviceId;
  153 + }
  154 +
  155 + public void setDeviceId(String deviceId) {
  156 + this.deviceId = deviceId;
  157 + }
  158 +
  159 + public Long getTs() {
  160 + return ts;
  161 + }
  162 +
  163 + public void setTs(Long ts) {
  164 + this.ts = ts;
  165 + }
  166 +
  167 + public String getStopName() {
  168 + return stopName;
  169 + }
  170 +
  171 + public void setStopName(String stopName) {
  172 + this.stopName = stopName;
  173 + }
  174 +
  175 + public String getId(){
  176 + return this.deviceId + "_" + this.ts;
  177 + }
  178 +
  179 + public String getNbbm() {
  180 + return nbbm;
  181 + }
  182 +
  183 + public void setNbbm(String nbbm) {
  184 + this.nbbm = nbbm;
  185 + }
  186 +
  187 + public boolean isEnable() {
  188 + return enable;
  189 + }
  190 +
  191 + public void setEnable(boolean enable) {
  192 + this.enable = enable;
  193 + }
  194 +
  195 + public boolean isTcc() {
  196 + return tcc;
  197 + }
  198 +
  199 + public void setTcc(boolean tcc) {
  200 + this.tcc = tcc;
  201 + }
  202 +
  203 + public boolean isOutTcc() {
  204 + return isTcc() && inOut == 1;
  205 + }
  206 +
  207 + public boolean isCorrect() {
  208 + return correct;
  209 + }
  210 +
  211 + public void setCorrect(boolean correct) {
  212 + this.correct = correct;
  213 + }
  214 +
  215 + public String getCorrectText() {
  216 + return correctText;
  217 + }
  218 +
  219 + public void setCorrectText(String correctText) {
  220 + this.correctText = correctText;
  221 + }
  222 +
  223 + public Integer getFlag() {
  224 + return flag;
  225 + }
  226 +
  227 + public void setFlag(Integer flag) {
  228 + this.flag = flag;
  229 + }
  230 +
  231 + public String getCzsj() {
  232 + return czsj;
  233 + }
  234 +
  235 + public void setCzsj(String czsj) {
  236 + this.czsj = czsj;
  237 + }
  238 +
  239 + public String getJzsj() {
  240 + return jzsj;
  241 + }
  242 +
  243 + public void setJzsj(String jzsj) {
  244 + this.jzsj = jzsj;
  245 + }
  246 +
  247 +
  248 +
  249 +}
src/main/java/com/bsth/entity/oil/Cwjy.java 0 → 100644
  1 +package com.bsth.entity.oil;
  2 +
  3 +import java.util.Date;
  4 +
  5 +import javax.persistence.Entity;
  6 +import javax.persistence.GeneratedValue;
  7 +import javax.persistence.Id;
  8 +import javax.persistence.Table;
  9 +
  10 +@Entity
  11 +@Table(name = "bsth_c_cwjy")
  12 +public class Cwjy {
  13 + @Id
  14 + @GeneratedValue
  15 + private Integer id;
  16 +
  17 + private String gsdm;
  18 +
  19 + private String fgsdm;
  20 +
  21 + private String nbbm;
  22 +
  23 + private String xgr;
  24 +
  25 + private Date createDate;
  26 +
  27 + public Integer getId() {
  28 + return id;
  29 + }
  30 +
  31 + public void setId(Integer id) {
  32 + this.id = id;
  33 + }
  34 +
  35 + public String getGsdm() {
  36 + return gsdm;
  37 + }
  38 +
  39 + public void setGsdm(String gsdm) {
  40 + this.gsdm = gsdm;
  41 + }
  42 +
  43 + public String getFgsdm() {
  44 + return fgsdm;
  45 + }
  46 +
  47 + public void setFgsdm(String fgsdm) {
  48 + this.fgsdm = fgsdm;
  49 + }
  50 +
  51 + public String getNbbm() {
  52 + return nbbm;
  53 + }
  54 +
  55 + public void setNbbm(String nbbm) {
  56 + this.nbbm = nbbm;
  57 + }
  58 +
  59 + public String getXgr() {
  60 + return xgr;
  61 + }
  62 +
  63 + public void setXgr(String xgr) {
  64 + this.xgr = xgr;
  65 + }
  66 +
  67 + public Date getCreateDate() {
  68 + return createDate;
  69 + }
  70 +
  71 + public void setCreateDate(Date createDate) {
  72 + this.createDate = createDate;
  73 + }
  74 +
  75 +
  76 +}
src/main/java/com/bsth/oplog/db/DBHelper.java
@@ -43,6 +43,6 @@ public class DBHelper implements CommandLineRunner{ @@ -43,6 +43,6 @@ public class DBHelper implements CommandLineRunner{
43 43
44 @Override 44 @Override
45 public void run(String... arg0) throws Exception { 45 public void run(String... arg0) throws Exception {
46 - Application.mainServices.scheduleWithFixedDelay(fixedTimeThread, fixedMinute, fixedMinute, TimeUnit.MINUTES); 46 + //Application.mainServices.scheduleWithFixedDelay(fixedTimeThread, fixedMinute, fixedMinute, TimeUnit.MINUTES);
47 } 47 }
48 } 48 }
src/main/java/com/bsth/repository/oil/CwjyRepository.java 0 → 100644
  1 +package com.bsth.repository.oil;
  2 +
  3 +
  4 +import java.util.List;
  5 +import java.util.Map;
  6 +
  7 +import org.springframework.data.jpa.repository.Modifying;
  8 +import org.springframework.data.jpa.repository.Query;
  9 +import org.springframework.stereotype.Repository;
  10 +import org.springframework.transaction.annotation.Transactional;
  11 +
  12 +import com.bsth.entity.oil.Cwjy;
  13 +import com.bsth.entity.oil.Ylxxb;
  14 +import com.bsth.repository.BaseRepository;
  15 +
  16 +@Repository
  17 +public interface CwjyRepository extends BaseRepository<Cwjy, Integer>{
  18 + /**
  19 + * 当天手动添加的加油信息
  20 + * @param rq
  21 + * @return
  22 + */
  23 + @Transactional
  24 + @Modifying
  25 + @Query(value="SELECT a.gsdm as gsdm,a.nbbm as nbbm,b.jsy as jsy,b.jzl as jzl ,b.stationid as stationid,"
  26 + + "b.nylx as nylx,b.yj as yj,b.bz as bz,c.jsy as ldgh FROM bsth_c_cwjy a "+
  27 + " left join ( select * from bsth_c_ylxxb b where to_days(b.yyrq)=to_days(?1) and jylx=1) b " +
  28 + " on a.nbbm=b.nbbm left join (select nbbm,group_concat(jsy) as jsy from bsth_c_ylb where to_days(rq)= to_days(?1 ) group by nbbm "+
  29 + " ) c on a.nbbm=c.nbbm where a.nbbm like %?2% ",nativeQuery=true)
  30 + List<Object[]> obtainCwjycl(String rq,String nbbm);
  31 +
  32 +}
src/main/java/com/bsth/repository/realcontrol/ScheduleRealInfoRepository.java
@@ -29,12 +29,24 @@ public interface ScheduleRealInfoRepository extends BaseRepository&lt;ScheduleRealI @@ -29,12 +29,24 @@ public interface ScheduleRealInfoRepository extends BaseRepository&lt;ScheduleRealI
29 @Query(value="select s from ScheduleRealInfo s where s.jName = ?1 and s.clZbh = ?2 and s.lpName = ?3 order by bcs") 29 @Query(value="select s from ScheduleRealInfo s where s.jName = ?1 and s.clZbh = ?2 and s.lpName = ?3 order by bcs")
30 List<ScheduleRealInfo> exportWaybill(String jName,String clZbh,String lpName); 30 List<ScheduleRealInfo> exportWaybill(String jName,String clZbh,String lpName);
31 31
32 - @Query(value="select new map(clZbh as clZbh,jGh as jGh,jName as jName,sum(jhlc) as zgl,sum(addMileage) as ksgl,count(jName) as bcs) from ScheduleRealInfo s where s.xlBm = ?1 and DATE_FORMAT(s.scheduleDate,'%Y-%m-%d') = ?2 group by clZbh,jGh") 32 + @Query(value="select new map(clZbh as clZbh,jGh as jGh,jName as jName,sum(jhlc) as zgl,"
  33 + + "sum(addMileage) as ksgl,count(jName) as bcs) from ScheduleRealInfo s where"
  34 + + " s.xlBm = ?1 and DATE_FORMAT(s.scheduleDate,'%Y-%m-%d') = ?2 group by clZbh,jGh,jName")
33 List<Map<String, Object>> dailyInfo(String line,String date); 35 List<Map<String, Object>> dailyInfo(String line,String date);
34 36
35 - @Query(value="SELECT r.xl_name,r.lp_name,r.cl_zbh,d.sender,d.timestamp,d.txt_content FROM bsth_c_s_sp_info_real r RIGHT JOIN bsth_v_directive_60 d ON r.id = d.sch WHERE d.is_dispatch = 1 AND r.xl_bm = ?1 AND r.schedule_date = ?2 and r.cl_zbh = ?3 order by d.timestamp",nativeQuery=true) 37 + @Query(value="SELECT r.xl_name,r.lp_name,r.cl_zbh,d.sender,d.timestamp,"
  38 + + " d.txt_content FROM bsth_c_s_sp_info_real r RIGHT JOIN bsth_v_directive_60 "
  39 + + "d ON r.id = d.sch WHERE d.is_dispatch = 1 AND r.xl_bm like %?1% AND "
  40 + + "r.schedule_date like %?2% and r.cl_zbh like %?3% order by d.timestamp",nativeQuery=true)
36 List<Object[]> historyMessage(String line,String date,String code); 41 List<Object[]> historyMessage(String line,String date,String code);
37 42
  43 + @Query(value="SELECT r.xl_name,r.lp_name,r.cl_zbh,count(*) as cs "
  44 + + " FROM bsth_c_s_sp_info_real r RIGHT JOIN bsth_v_directive_60 d "
  45 + + " ON r.id = d.sch WHERE d.is_dispatch = 1 AND r.xl_bm like %?1% AND "
  46 + + " r.schedule_date like %?2% and r.cl_zbh like %?3% group by "
  47 + + " lp_name,xl_name,cl_zbh order by d.timestamp",nativeQuery=true)
  48 + List<Object[]> historyMessageCount(String line,String date,String code);
  49 +
38 @Query(value = "select max(id) from ScheduleRealInfo") 50 @Query(value = "select max(id) from ScheduleRealInfo")
39 Long getMaxId(); 51 Long getMaxId();
40 52
@@ -45,6 +57,10 @@ public interface ScheduleRealInfoRepository extends BaseRepository&lt;ScheduleRealI @@ -45,6 +57,10 @@ public interface ScheduleRealInfoRepository extends BaseRepository&lt;ScheduleRealI
45 @Query(value = "select s from ScheduleRealInfo s where s.scheduleDateStr = ?1") 57 @Query(value = "select s from ScheduleRealInfo s where s.scheduleDateStr = ?1")
46 List<ScheduleRealInfo> findByDate(String dateStr); 58 List<ScheduleRealInfo> findByDate(String dateStr);
47 59
  60 + @EntityGraph(value = "scheduleRealInfo_cTasks", type = EntityGraph.EntityGraphType.FETCH)
  61 + @Query(value="select s from ScheduleRealInfo s where s.xlBm = ?1 and DATE_FORMAT(s.scheduleDate,'%Y-%m-%d') = ?2 and cl_zbh=?3 order by bcs")
  62 + List<ScheduleRealInfo> findByDate2(String line,String date,String clzbh);
  63 +
48 @Query(value="select count(jName) from ScheduleRealInfo s where s.jName = ?1 and s.clZbh = ?2 and s.lpName = ?3 and s.status = -1") 64 @Query(value="select count(jName) from ScheduleRealInfo s where s.jName = ?1 and s.clZbh = ?2 and s.lpName = ?3 and s.status = -1")
49 int findCjbc(String jName,String clZbh,String lpName); 65 int findCjbc(String jName,String clZbh,String lpName);
50 66
@@ -54,8 +70,10 @@ public interface ScheduleRealInfoRepository extends BaseRepository&lt;ScheduleRealI @@ -54,8 +70,10 @@ public interface ScheduleRealInfoRepository extends BaseRepository&lt;ScheduleRealI
54 @Query(value="SELECT c.company,r.request_code,FROM_UNIXTIME(r.timestamp/1000,'%Y-%m-%d %T') FROM bsth_v_report_80 r LEFT JOIN bsth_c_cars c ON c.equipment_code = r.device_id where FROM_UNIXTIME(r.timestamp/1000,'%Y-%m-%d') = ?2 and r.line_id = ?1 and c.inside_code = ?3",nativeQuery=true) 70 @Query(value="SELECT c.company,r.request_code,FROM_UNIXTIME(r.timestamp/1000,'%Y-%m-%d %T') FROM bsth_v_report_80 r LEFT JOIN bsth_c_cars c ON c.equipment_code = r.device_id where FROM_UNIXTIME(r.timestamp/1000,'%Y-%m-%d') = ?2 and r.line_id = ?1 and c.inside_code = ?3",nativeQuery=true)
55 List<Object[]> account(String line,String date,String code); 71 List<Object[]> account(String line,String date,String code);
56 72
57 - @Query(value="select s from ScheduleRealInfo s where s.xlBm = ?1 and s.scheduleDate >= str_to_date(?2,'%Y-%m-%d') and s.scheduleDate <= str_to_date(?3,'%Y-%m-%d') and s.lpName = ?4 order by s.fcsj")  
58 - List<ScheduleRealInfo> correctForm(String line,String startDate,String endDate,String lpName); 73 + @Query(value="select s from ScheduleRealInfo s where s.xlBm = ?1 and s.scheduleDate >= str_to_date(?2,'%Y-%m-%d') "
  74 + + " and s.scheduleDate <= str_to_date(?3,'%Y-%m-%d') and s.lpName like %?4% "
  75 + + " and clZbh like %?5% order by s.fcsj")
  76 + List<ScheduleRealInfo> correctForm(String line,String startDate,String endDate,String lpName,String code);
59 77
60 @Query(value="select s from ScheduleRealInfo s where s.jName = ?1 and s.clZbh = ?2 and s.lpName = ?3 and s.scheduleDate = str_to_date(?4,'%Y-%m-%d') order by bcs") 78 @Query(value="select s from ScheduleRealInfo s where s.jName = ?1 and s.clZbh = ?2 and s.lpName = ?3 and s.scheduleDate = str_to_date(?4,'%Y-%m-%d') order by bcs")
61 List<ScheduleRealInfo> queryListWaybill(String jName,String clZbh,String lpName,String date); 79 List<ScheduleRealInfo> queryListWaybill(String jName,String clZbh,String lpName,String date);
@@ -63,6 +81,9 @@ public interface ScheduleRealInfoRepository extends BaseRepository&lt;ScheduleRealI @@ -63,6 +81,9 @@ public interface ScheduleRealInfoRepository extends BaseRepository&lt;ScheduleRealI
63 @Query(value="select s from ScheduleRealInfo s where s.jName = ?1 and s.clZbh = ?2 and s.lpName = ?3 and s.scheduleDate = str_to_date(?4,'%Y-%m-%d') and bcType='normal' order by bcs") 81 @Query(value="select s from ScheduleRealInfo s where s.jName = ?1 and s.clZbh = ?2 and s.lpName = ?3 and s.scheduleDate = str_to_date(?4,'%Y-%m-%d') and bcType='normal' order by bcs")
64 List<ScheduleRealInfo> queryListWaybill2(String jName,String clZbh,String lpName,String date); 82 List<ScheduleRealInfo> queryListWaybill2(String jName,String clZbh,String lpName,String date);
65 83
  84 + @Query(value="select s from ScheduleRealInfo s where s.jGh = ?1 and s.clZbh = ?2 and s.lpName = ?3 and s.scheduleDate = str_to_date(?4,'%Y-%m-%d') and bcType='normal' order by bcs")
  85 + List<ScheduleRealInfo> queryListWaybill3(String jName,String clZbh,String lpName,String date);
  86 +
66 @Query(value="select s from ScheduleRealInfo s where s.xlBm = ?1 and DATE_FORMAT(s.scheduleDate,'%Y-%m-%d') = ?2") 87 @Query(value="select s from ScheduleRealInfo s where s.xlBm = ?1 and DATE_FORMAT(s.scheduleDate,'%Y-%m-%d') = ?2")
67 List<ScheduleRealInfo> scheduleDaily(String line,String date); 88 List<ScheduleRealInfo> scheduleDaily(String line,String date);
68 89
@@ -78,7 +99,8 @@ public interface ScheduleRealInfoRepository extends BaseRepository&lt;ScheduleRealI @@ -78,7 +99,8 @@ public interface ScheduleRealInfoRepository extends BaseRepository&lt;ScheduleRealI
78 @Query(value = "delete ScheduleRealInfo s where s.xlBm=?1 and s.scheduleDateStr=?2") 99 @Query(value = "delete ScheduleRealInfo s where s.xlBm=?1 and s.scheduleDateStr=?2")
79 void deleteByLineCodeAndDate(String xlBm, String schDate); 100 void deleteByLineCodeAndDate(String xlBm, String schDate);
80 101
81 - @Query(value="select s from ScheduleRealInfo s where (s.xlBm = ?1 or s.xlBm is not null) and DATE_FORMAT(s.scheduleDate,'%Y-%m-%d') = ?2") 102 + //去掉了 xlBm is not null
  103 + @Query(value="select s from ScheduleRealInfo s where s.xlBm = ?1 and DATE_FORMAT(s.scheduleDate,'%Y-%m-%d') = ?2")
82 List<ScheduleRealInfo> scheduleByDateAndLine(String line,String date); 104 List<ScheduleRealInfo> scheduleByDateAndLine(String line,String date);
83 105
84 @Query(value="select new map(s.scheduleDate as scheduleDate,s.xlBm as xlBm,s.clZbh as clZbh,s.jGh as jGh) from ScheduleRealInfo s where (s.xlBm = ?1 or s.xlBm is not null) and DATE_FORMAT(s.scheduleDate,'%Y-%m-%d') = ?2 GROUP BY xlBm,clZbh,jGh ORDER BY xlBm,clZbh,realExecDate,fcsjActual") 106 @Query(value="select new map(s.scheduleDate as scheduleDate,s.xlBm as xlBm,s.clZbh as clZbh,s.jGh as jGh) from ScheduleRealInfo s where (s.xlBm = ?1 or s.xlBm is not null) and DATE_FORMAT(s.scheduleDate,'%Y-%m-%d') = ?2 GROUP BY xlBm,clZbh,jGh ORDER BY xlBm,clZbh,realExecDate,fcsjActual")
src/main/java/com/bsth/service/LineService.java
@@ -26,5 +26,5 @@ public interface LineService extends BaseService&lt;Line, Integer&gt; { @@ -26,5 +26,5 @@ public interface LineService extends BaseService&lt;Line, Integer&gt; {
26 */ 26 */
27 long selectMaxIdToLineCode(); 27 long selectMaxIdToLineCode();
28 28
29 - Line findByLineCode(Integer lineCode); 29 + Line findByLineCode(String lineCode);
30 } 30 }
src/main/java/com/bsth/service/directive/DirectiveService.java
@@ -55,8 +55,10 @@ public interface DirectiveService extends BaseService&lt;D60, Integer&gt;{ @@ -55,8 +55,10 @@ public interface DirectiveService extends BaseService&lt;D60, Integer&gt;{
55 * @throws 55 * @throws
56 */ 56 */
57 int lineChange(String nbbm, String lineId, String sender); 57 int lineChange(String nbbm, String lineId, String sender);
58 -  
59 - /** 58 +
  59 + int lineChangeByDeviceId(String deviceId, String lineCode, String sender);
  60 +
  61 + /**
60 * 62 *
61 * @Title: upDownChange 63 * @Title: upDownChange
62 * @Description: TODO(切换上下行) 64 * @Description: TODO(切换上下行)
@@ -89,4 +91,6 @@ public interface DirectiveService extends BaseService&lt;D60, Integer&gt;{ @@ -89,4 +91,6 @@ public interface DirectiveService extends BaseService&lt;D60, Integer&gt;{
89 int sendC0A3(DC0_A3 c0a4); 91 int sendC0A3(DC0_A3 c0a4);
90 92
91 int sendC0A5(String json); 93 int sendC0A5(String json);
  94 +
  95 + int refreshLineFile(String deviceId);
92 } 96 }
src/main/java/com/bsth/service/directive/DirectiveServiceImpl.java
@@ -222,18 +222,23 @@ public class DirectiveServiceImpl extends BaseServiceImpl&lt;D60, Integer&gt; implemen @@ -222,18 +222,23 @@ public class DirectiveServiceImpl extends BaseServiceImpl&lt;D60, Integer&gt; implemen
222 */ 222 */
223 @Override 223 @Override
224 public int lineChange(String nbbm, String lineCode, String sender) { 224 public int lineChange(String nbbm, String lineCode, String sender) {
  225 + return lineChangeByDeviceId(BasicData.deviceId2NbbmMap.inverse().get(nbbm), lineCode, sender);
  226 + }
  227 +
  228 +
  229 + @Override
  230 + public int lineChangeByDeviceId(String deviceId, String lineCode, String sender){
225 DirectiveCreator crt = new DirectiveCreator(); 231 DirectiveCreator crt = new DirectiveCreator();
226 -  
227 Long t = System.currentTimeMillis(); 232 Long t = System.currentTimeMillis();
228 //生成64数据包 233 //生成64数据包
229 - D64 d64 = crt.createD64(nbbm, lineCode, t);  
230 - 234 + D64 d64 = crt.create64(deviceId, lineCode, t);
  235 +
231 if(null != sender) 236 if(null != sender)
232 d64.setSender(sender); 237 d64.setSender(sender);
233 else 238 else
234 d64.setSender("系统"); 239 d64.setSender("系统");
235 240
236 - String deviceId = d64.getDeviceId(); 241 + //String deviceId = d64.getDeviceId();
237 int code = GatewayHttpUtils.postJson(JSON.toJSONString(d64)); 242 int code = GatewayHttpUtils.postJson(JSON.toJSONString(d64));
238 // 入库 243 // 入库
239 d64.setHttpCode(code); 244 d64.setHttpCode(code);
@@ -332,6 +337,7 @@ public class DirectiveServiceImpl extends BaseServiceImpl&lt;D60, Integer&gt; implemen @@ -332,6 +337,7 @@ public class DirectiveServiceImpl extends BaseServiceImpl&lt;D60, Integer&gt; implemen
332 Map<String, Object> sockMap = new HashMap<>(); 337 Map<String, Object> sockMap = new HashMap<>();
333 sockMap.put("fn", "d80Confirm"); 338 sockMap.put("fn", "d80Confirm");
334 sockMap.put("id", d80.getId()); 339 sockMap.put("id", d80.getId());
  340 + sockMap.put("lineId", d80.getData().getLineId());
335 socketHandler.sendMessageToLine(d80.getData().getLineId().toString(), JSON.toJSONString(sockMap)); 341 socketHandler.sendMessageToLine(d80.getData().getLineId().toString(), JSON.toJSONString(sockMap));
336 } 342 }
337 343
@@ -463,7 +469,7 @@ public class DirectiveServiceImpl extends BaseServiceImpl&lt;D60, Integer&gt; implemen @@ -463,7 +469,7 @@ public class DirectiveServiceImpl extends BaseServiceImpl&lt;D60, Integer&gt; implemen
463 469
464 Map<String, Object> rsMap = new HashMap<>(); 470 Map<String, Object> rsMap = new HashMap<>();
465 rsMap.put("list", rs); 471 rsMap.put("list", rs);
466 - rsMap.put("totalPages", count % size == 0 ? count / size : count / size + 1); 472 + rsMap.put("totalPages", count % size == 0 ? count / size -1 : count / size);
467 rsMap.put("page", page); 473 rsMap.put("page", page);
468 474
469 return rsMap; 475 return rsMap;
@@ -501,4 +507,13 @@ public class DirectiveServiceImpl extends BaseServiceImpl&lt;D60, Integer&gt; implemen @@ -501,4 +507,13 @@ public class DirectiveServiceImpl extends BaseServiceImpl&lt;D60, Integer&gt; implemen
501 public int sendC0A5(String json) { 507 public int sendC0A5(String json) {
502 return GatewayHttpUtils.postJson(json); 508 return GatewayHttpUtils.postJson(json);
503 } 509 }
  510 +
  511 + @Override
  512 + public int refreshLineFile(String deviceId) {
  513 + GpsEntity gps = gpsRealDataBuffer.get(deviceId);
  514 + if(gps == null)
  515 + return -1;
  516 +
  517 + return GatewayHttpUtils.postJson(new DirectiveCreator().createDeviceRefreshData(deviceId, gps.getLineId()));
  518 + }
504 } 519 }
src/main/java/com/bsth/service/gps/GpsService.java
@@ -12,4 +12,6 @@ public interface GpsService { @@ -12,4 +12,6 @@ public interface GpsService {
12 Map<String, Object> findBuffAeraByCode(String code, String type); 12 Map<String, Object> findBuffAeraByCode(String code, String type);
13 13
14 Map<String, Object> search(Map<String, Object> map, int page, int size, String order, String direction); 14 Map<String, Object> search(Map<String, Object> map, int page, int size, String order, String direction);
  15 +
  16 + Map<String,Object> removeRealGps(String device);
15 } 17 }
src/main/java/com/bsth/service/gps/GpsServiceImpl.java
@@ -14,6 +14,7 @@ import java.util.HashMap; @@ -14,6 +14,7 @@ import java.util.HashMap;
14 import java.util.List; 14 import java.util.List;
15 import java.util.Map; 15 import java.util.Map;
16 16
  17 +import org.apache.commons.lang3.StringUtils;
17 import org.slf4j.Logger; 18 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory; 19 import org.slf4j.LoggerFactory;
19 import org.springframework.beans.factory.annotation.Autowired; 20 import org.springframework.beans.factory.annotation.Autowired;
@@ -32,372 +33,398 @@ import com.bsth.util.TransGPS.Location; @@ -32,372 +33,398 @@ import com.bsth.util.TransGPS.Location;
32 import com.bsth.util.db.DBUtils_MS; 33 import com.bsth.util.db.DBUtils_MS;
33 34
34 @Service 35 @Service
35 -public class GpsServiceImpl implements GpsService{  
36 - /** 历史gps查询最大范围 24小时 */  
37 - final static Long GPS_RANGE = 60 * 60 * 24L;  
38 -  
39 - /** jdbc */  
40 - Connection conn = null;  
41 - PreparedStatement ps = null;  
42 - ResultSet rs = null;  
43 -  
44 - Logger logger = LoggerFactory.getLogger(this.getClass());  
45 -  
46 - @Autowired  
47 - GpsRealData gpsRealData;  
48 -  
49 - // 历史gps查询  
50 - @Override  
51 - public List<Map<String, Object>> history(String device, Long startTime, Long endTime, int directions) {  
52 - Calendar sCal = Calendar.getInstance();  
53 - sCal.setTime(new Date(startTime));  
54 -  
55 - Calendar eCal = Calendar.getInstance();  
56 - eCal.setTime(new Date(endTime));  
57 -  
58 - int dayOfYear = sCal.get(Calendar.DAY_OF_YEAR);  
59 - /* 36 +public class GpsServiceImpl implements GpsService {
  37 + /**
  38 + * 历史gps查询最大范围 24小时
  39 + */
  40 + final static Long GPS_RANGE = 60 * 60 * 24L;
  41 +
  42 + /**
  43 + * jdbc
  44 + */
  45 + Connection conn = null;
  46 + PreparedStatement ps = null;
  47 + ResultSet rs = null;
  48 +
  49 + Logger logger = LoggerFactory.getLogger(this.getClass());
  50 +
  51 + @Autowired
  52 + GpsRealData gpsRealData;
  53 +
  54 + // 历史gps查询
  55 + @Override
  56 + public List<Map<String, Object>> history(String device, Long startTime, Long endTime, int directions) {
  57 + Calendar sCal = Calendar.getInstance();
  58 + sCal.setTime(new Date(startTime));
  59 +
  60 + Calendar eCal = Calendar.getInstance();
  61 + eCal.setTime(new Date(endTime));
  62 +
  63 + int dayOfYear = sCal.get(Calendar.DAY_OF_YEAR);
  64 + /*
60 * if(dayOfYear != eCal.get(Calendar.DAY_OF_YEAR)){ 65 * if(dayOfYear != eCal.get(Calendar.DAY_OF_YEAR)){
61 * System.out.println("暂时不支持跨天查询..."); return null; } 66 * System.out.println("暂时不支持跨天查询..."); return null; }
62 */ 67 */
63 68
64 - String sql = "select DEVICE_ID,LON,LAT,TS,INOUT_STOP,SERVICE_STATE ,STOP_NO from bsth_c_gps_info where days_year=? and device_id=? and ts > ? and ts < ?";  
65 - Connection conn = null;  
66 - PreparedStatement ps = null;  
67 - ResultSet rs = null;  
68 - List<Map<String, Object>> list = new ArrayList<>();  
69 - Map<String, Object> map = null;  
70 - try {  
71 - conn = DBUtils_MS.getConnection();  
72 - ps = conn.prepareStatement(sql);  
73 - ps.setInt(1, dayOfYear);  
74 - ps.setString(2, device);  
75 - ps.setLong(3, startTime);  
76 - ps.setLong(4, endTime);  
77 -  
78 - rs = ps.executeQuery();  
79 - Float lon, lat;  
80 - Location location;  
81 - int upDown;  
82 - while (rs.next()) {  
83 - upDown = getUpOrDown(rs.getLong("SERVICE_STATE"));  
84 - if (upDown != directions)  
85 - continue;  
86 -  
87 - // to 百度坐标  
88 - lon = rs.getFloat("LON");  
89 - lat = rs.getFloat("LAT");  
90 - location = TransGPS.LocationMake(lon, lat);  
91 - location = TransGPS.bd_encrypt(TransGPS.transformFromWGSToGCJ(location));  
92 -  
93 - map = new HashMap<>();  
94 - map.put("device", rs.getString("DEVICE_ID"));  
95 - map.put("lon", location.getLng());  
96 - map.put("lat", location.getLat());  
97 - map.put("ts", rs.getLong("TS"));  
98 - map.put("stopNo", rs.getString("STOP_NO"));  
99 - map.put("inout_stop", rs.getInt("INOUT_STOP"));  
100 - // 上下行  
101 - map.put("upDown", upDown);  
102 - list.add(map);  
103 - }  
104 - } catch (Exception e) {  
105 - e.printStackTrace();  
106 - } finally {  
107 - DBUtils_MS.close(rs, ps, conn);  
108 - }  
109 - return list;  
110 - }  
111 -  
112 - /**  
113 - * 王通 2016/6/29 9:23:24 获取车辆线路上下行  
114 - *  
115 - * @return -1无效 0上行 1下行  
116 - */  
117 - public static byte getUpOrDown(long serviceState) {  
118 - if ((serviceState & 0x00020000) == 0x00020000 || (serviceState & 0x80000000) == 0x80000000  
119 - || (serviceState & 0x01000000) == 0x01000000 || (serviceState & 0x08000000) == 0x08000000)  
120 - return -1;  
121 - return (byte) (((serviceState & 0x10000000) == 0x10000000) ? 1 : 0);  
122 - }  
123 -  
124 - @Override  
125 - public List<Map<String, Object>> history(String[] nbbmArray, Long st, Long et) {  
126 - List<Map<String, Object>> list = new ArrayList<>();  
127 - // 超过最大查询范围,直接忽略  
128 - if (et - st > GPS_RANGE)  
129 - return list;  
130 -  
131 - // 车辆编码转换成设备号  
132 - String[] devices = new String[nbbmArray.length];  
133 - for (int i = 0; i < nbbmArray.length; i++) {  
134 - devices[i] = BasicData.deviceId2NbbmMap.inverse().get(nbbmArray[i]);  
135 - }  
136 - // day_of_year  
137 - Calendar sCal = Calendar.getInstance();  
138 - sCal.setTime(new Date(st * 1000));  
139 - int sDayOfYear = sCal.get(Calendar.DAY_OF_YEAR)/* 200 */;  
140 -  
141 - Calendar eCal = Calendar.getInstance();  
142 - eCal.setTime(new Date(et * 1000));  
143 - int eDayOfYear = eCal.get(Calendar.DAY_OF_YEAR)/* 200 */;  
144 -  
145 - Calendar weekCal = Calendar.getInstance();  
146 -  
147 - // 如果是同一天  
148 - if (sDayOfYear == eDayOfYear) {  
149 - weekCal.setTimeInMillis(st * 1000);  
150 - list = findByTs(weekCal.get(Calendar.WEEK_OF_YEAR), sDayOfYear, st, et, devices);  
151 - } else {  
152 - // 跨天  
153 - Long tempSt = 0L, tempEt = 0L;  
154 - for (int i = sDayOfYear; i <= eDayOfYear; i++) {  
155 -  
156 - if (i == sDayOfYear) {  
157 - tempSt = st;  
158 - tempEt = DateUtils.getTimesnight(sCal);  
159 - } else if (i == eDayOfYear) {  
160 - tempSt = DateUtils.getTimesmorning(sCal);  
161 - tempEt = et;  
162 - } else {  
163 - tempSt = DateUtils.getTimesmorning(sCal);  
164 - tempEt = DateUtils.getTimesnight(sCal);  
165 - }  
166 -  
167 - weekCal.setTimeInMillis(tempSt * 1000);  
168 - list.addAll(findByTs(weekCal.get(Calendar.WEEK_OF_YEAR), i, tempSt, tempEt, devices));  
169 - // 加一天  
170 - sCal.add(Calendar.DATE, 1);  
171 - }  
172 - }  
173 -  
174 - // 按时间排序  
175 - Collections.sort(list, new Comparator<Map<String, Object>>() {  
176 -  
177 - @Override  
178 - public int compare(Map<String, Object> o1, Map<String, Object> o2) {  
179 - return (int) (Long.parseLong(o1.get("ts").toString()) - Long.parseLong(o2.get("ts").toString()));  
180 - }  
181 - });  
182 - ;  
183 - return list;  
184 - }  
185 -  
186 - public List<Map<String, Object>> findByTs(int weekOfYear, int dayOfYear, Long st, Long et, String[] devices) {  
187 - List<Map<String, Object>> list = new ArrayList<>();  
188 - Map<String, Object> map = null;  
189 -  
190 - // setArray 不好用,直接拼 in 语句  
191 - String inv = "";  
192 - for (String device : devices)  
193 - inv += ("'" + device + "',");  
194 - inv = inv.substring(0, inv.length() - 1);  
195 -  
196 - // 查询到离站数据  
197 - Map<String, ArrivalEntity> arrivalMap = findArrivalByTs(weekOfYear/* 30 */, st, et, inv);  
198 -  
199 - String sql = "select DEVICE_ID,LON,LAT,TS,INOUT_STOP,SERVICE_STATE ,STOP_NO from bsth_c_gps_info where days_year=? and device_id in ("  
200 - + inv + ") and ts > ? and ts < ?";  
201 - try {  
202 - conn = DBUtils_MS.getConnection();  
203 - ps = conn.prepareStatement(sql);  
204 - ps.setInt(1, dayOfYear); 69 + String sql = "select DEVICE_ID,LON,LAT,TS,INOUT_STOP,SERVICE_STATE ,STOP_NO from bsth_c_gps_info where days_year=? and device_id=? and ts > ? and ts < ?";
  70 + Connection conn = null;
  71 + PreparedStatement ps = null;
  72 + ResultSet rs = null;
  73 + List<Map<String, Object>> list = new ArrayList<>();
  74 + Map<String, Object> map = null;
  75 + try {
  76 + conn = DBUtils_MS.getConnection();
  77 + ps = conn.prepareStatement(sql);
  78 + ps.setInt(1, dayOfYear);
  79 + ps.setString(2, device);
  80 + ps.setLong(3, startTime);
  81 + ps.setLong(4, endTime);
  82 +
  83 + rs = ps.executeQuery();
  84 + Float lon, lat;
  85 + Location location;
  86 + int upDown;
  87 + while (rs.next()) {
  88 + upDown = getUpOrDown(rs.getLong("SERVICE_STATE"));
  89 + if (upDown != directions)
  90 + continue;
  91 +
  92 + // to 百度坐标
  93 + lon = rs.getFloat("LON");
  94 + lat = rs.getFloat("LAT");
  95 + location = TransGPS.LocationMake(lon, lat);
  96 + location = TransGPS.bd_encrypt(TransGPS.transformFromWGSToGCJ(location));
  97 +
  98 + map = new HashMap<>();
  99 + map.put("device", rs.getString("DEVICE_ID"));
  100 + map.put("lon", location.getLng());
  101 + map.put("lat", location.getLat());
  102 + map.put("ts", rs.getLong("TS"));
  103 + map.put("stopNo", rs.getString("STOP_NO"));
  104 + map.put("inout_stop", rs.getInt("INOUT_STOP"));
  105 + // 上下行
  106 + map.put("upDown", upDown);
  107 + list.add(map);
  108 + }
  109 + } catch (Exception e) {
  110 + e.printStackTrace();
  111 + } finally {
  112 + DBUtils_MS.close(rs, ps, conn);
  113 + }
  114 + return list;
  115 + }
  116 +
  117 + /**
  118 + * 王通 2016/6/29 9:23:24 获取车辆线路上下行
  119 + *
  120 + * @return -1无效 0上行 1下行
  121 + */
  122 + public static byte getUpOrDown(long serviceState) {
  123 + if ((serviceState & 0x00020000) == 0x00020000 || (serviceState & 0x80000000) == 0x80000000
  124 + || (serviceState & 0x01000000) == 0x01000000 || (serviceState & 0x08000000) == 0x08000000)
  125 + return -1;
  126 + return (byte) (((serviceState & 0x10000000) == 0x10000000) ? 1 : 0);
  127 + }
  128 +
  129 + @Override
  130 + public List<Map<String, Object>> history(String[] nbbmArray, Long st, Long et) {
  131 + List<Map<String, Object>> list = new ArrayList<>();
  132 + // 超过最大查询范围,直接忽略
  133 + if (et - st > GPS_RANGE)
  134 + return list;
  135 +
  136 + // 车辆编码转换成设备号
  137 + String[] devices = new String[nbbmArray.length];
  138 + for (int i = 0; i < nbbmArray.length; i++) {
  139 + devices[i] = BasicData.deviceId2NbbmMap.inverse().get(nbbmArray[i]);
  140 + }
  141 + // day_of_year
  142 + Calendar sCal = Calendar.getInstance();
  143 + sCal.setTime(new Date(st * 1000));
  144 + int sDayOfYear = sCal.get(Calendar.DAY_OF_YEAR)/* 200 */;
  145 +
  146 + Calendar eCal = Calendar.getInstance();
  147 + eCal.setTime(new Date(et * 1000));
  148 + int eDayOfYear = eCal.get(Calendar.DAY_OF_YEAR)/* 200 */;
  149 +
  150 + Calendar weekCal = Calendar.getInstance();
  151 +
  152 + // 如果是同一天
  153 + if (sDayOfYear == eDayOfYear) {
  154 + weekCal.setTimeInMillis(st * 1000);
  155 + list = findByTs(weekCal.get(Calendar.WEEK_OF_YEAR), sDayOfYear, st, et, devices);
  156 + } else {
  157 + // 跨天
  158 + Long tempSt = 0L, tempEt = 0L;
  159 + for (int i = sDayOfYear; i <= eDayOfYear; i++) {
  160 +
  161 + if (i == sDayOfYear) {
  162 + tempSt = st;
  163 + tempEt = DateUtils.getTimesnight(sCal);
  164 + } else if (i == eDayOfYear) {
  165 + tempSt = DateUtils.getTimesmorning(sCal);
  166 + tempEt = et;
  167 + } else {
  168 + tempSt = DateUtils.getTimesmorning(sCal);
  169 + tempEt = DateUtils.getTimesnight(sCal);
  170 + }
  171 +
  172 + weekCal.setTimeInMillis(tempSt * 1000);
  173 + list.addAll(findByTs(weekCal.get(Calendar.WEEK_OF_YEAR), i, tempSt, tempEt, devices));
  174 + // 加一天
  175 + sCal.add(Calendar.DATE, 1);
  176 + }
  177 + }
  178 +
  179 + // 按时间排序
  180 + Collections.sort(list, new Comparator<Map<String, Object>>() {
  181 +
  182 + @Override
  183 + public int compare(Map<String, Object> o1, Map<String, Object> o2) {
  184 + return (int) (Long.parseLong(o1.get("ts").toString()) - Long.parseLong(o2.get("ts").toString()));
  185 + }
  186 + });
  187 + ;
  188 + return list;
  189 + }
  190 +
  191 + public List<Map<String, Object>> findByTs(int weekOfYear, int dayOfYear, Long st, Long et, String[] devices) {
  192 + List<Map<String, Object>> list = new ArrayList<>();
  193 + Map<String, Object> map = null;
  194 +
  195 + // 直接拼 in 语句
  196 + String inv = "";
  197 + for (String device : devices)
  198 + inv += ("'" + device + "',");
  199 + inv = inv.substring(0, inv.length() - 1);
  200 +
  201 + // 查询到离站数据
  202 + Map<String, ArrivalEntity> arrivalMap = findArrivalByTs(weekOfYear/* 30 */, st, et, inv);
  203 +
  204 + String sql = "select DEVICE_ID,LON,LAT,TS,INOUT_STOP,SERVICE_STATE ,STOP_NO from bsth_c_gps_info where days_year=? and device_id in ("
  205 + + inv + ") and ts > ? and ts < ?";
  206 + try {
  207 + conn = DBUtils_MS.getConnection();
  208 + ps = conn.prepareStatement(sql);
  209 + ps.setInt(1, dayOfYear);
205 /* ps.setArray(2, conn.createArrayOf("VARCHAR", devices)); */ 210 /* ps.setArray(2, conn.createArrayOf("VARCHAR", devices)); */
206 - ps.setLong(2, st * 1000);  
207 - ps.setLong(3, et * 1000);  
208 -  
209 - rs = ps.executeQuery();  
210 - Float lon, lat;  
211 - Location bdLoc, gdLoc;  
212 - int upDown, inOutStop;  
213 - ArrivalEntity arrival;  
214 - while (rs.next()) {  
215 - upDown = getUpOrDown(rs.getLong("SERVICE_STATE"));  
216 - map = new HashMap<>();  
217 -  
218 - lon = rs.getFloat("LON");  
219 - lat = rs.getFloat("LAT");  
220 - // 高德坐标  
221 - gdLoc = TransGPS.transformFromWGSToGCJ(TransGPS.LocationMake(lon, lat));  
222 - map.put("gcj_lon", gdLoc.getLng());  
223 - map.put("gcj_lat", gdLoc.getLat());  
224 - // 百度坐标  
225 - bdLoc = TransGPS.bd_encrypt(gdLoc);  
226 - map.put("bd_lon", bdLoc.getLng());  
227 - map.put("bd_lat", bdLoc.getLat());  
228 -  
229 - map.put("deviceId", rs.getString("DEVICE_ID"));  
230 - map.put("ts", rs.getLong("TS"));  
231 - map.put("timestamp", rs.getLong("TS"));  
232 - map.put("stopNo", rs.getString("STOP_NO"));  
233 -  
234 - inOutStop = rs.getInt("INOUT_STOP");  
235 - map.put("inout_stop", inOutStop);  
236 -  
237 - arrival = arrivalMap.get(rs.getString("DEVICE_ID") + "_" + rs.getLong("TS"));  
238 - if (arrival != null) {  
239 - map.put("inout_stop_info",arrival);  
240 - map.put("inout_stop", arrival.getInOut());  
241 - }  
242 - map.put("nbbm", BasicData.deviceId2NbbmMap.get(rs.getString("DEVICE_ID")));  
243 - map.put("state", 0);  
244 - // 上下行  
245 - map.put("upDown", upDown);  
246 - list.add(map);  
247 - }  
248 - } catch (Exception e) {  
249 - logger.error("", e);  
250 - } finally {  
251 - DBUtils_MS.close(rs, ps, conn);  
252 - }  
253 - return list;  
254 - }  
255 -  
256 - public Map<String, ArrivalEntity> findArrivalByTs(int weekOfYear, Long st, Long et, String devicesInSql) {  
257 - Map<String, ArrivalEntity> map = new HashMap<>();  
258 -  
259 - String sql = "SELECT DEVICE_ID,LINE_ID,STOP_NO,TS,UP_DOWN,IN_OUT,WEEKS_YEAR,CREATE_DATE FROM bsth_c_arrival_info where weeks_year=? and device_id in ("  
260 - + devicesInSql + ") and ts > ? and ts < ?";  
261 - try {  
262 - conn = DBUtils_MS.getConnection();  
263 - ps = conn.prepareStatement(sql);  
264 - ps.setInt(1, weekOfYear);  
265 - ps.setLong(2, st * 1000);  
266 - ps.setLong(3, et * 1000);  
267 -  
268 - rs = ps.executeQuery();  
269 - ArrivalEntity arr;  
270 - int inOut;  
271 - while (rs.next()) {  
272 - arr = new ArrivalEntity(rs.getString("DEVICE_ID"), rs.getLong("TS"), rs.getString("LINE_ID"),  
273 - rs.getInt("UP_DOWN"), rs.getString("STOP_NO"), rs.getInt("IN_OUT"), rs.getLong("CREATE_DATE"),  
274 - rs.getInt("WEEKS_YEAR"), BasicData.stationCode2NameMap.get(rs.getString("STOP_NO")));  
275 -  
276 - // 设备号_时间戳_进出状态 为key  
277 - // 反转进出状态  
278 - inOut = arr.getInOut() == 0 ? 1 : 0;  
279 - map.put(arr.getDeviceId() + "_" + arr.getTs(), arr);  
280 - }  
281 - } catch (Exception e) {  
282 - logger.error("", e);  
283 - } finally {  
284 - DBUtils_MS.close(rs, ps, conn);  
285 - }  
286 - return map;  
287 - }  
288 -  
289 -  
290 - @Autowired  
291 - StationRepository stationRepository;  
292 -  
293 - @Autowired  
294 - CarParkRepository carParkRepository;  
295 -  
296 - @Override  
297 - public Map<String, Object> findBuffAeraByCode(String code, String type) {  
298 - Object[][] obj = null;  
299 - if(type.equals("station"))  
300 - obj = stationRepository.bufferAera(code);  
301 - else if(type.equals("park"))  
302 - obj = carParkRepository.bufferAera(code);  
303 -  
304 - Map<String, Object> rs = new HashMap<>();  
305 -  
306 - Object[] subObj = obj[0];  
307 - if(subObj != null && subObj.length == 6){  
308 - rs.put("polygon", subObj[0]);  
309 - rs.put("type", subObj[1]);  
310 - rs.put("cPoint", subObj[2]);  
311 - rs.put("radius", subObj[3]);  
312 - rs.put("code", subObj[4]);  
313 - rs.put("text", subObj[5]);  
314 - }  
315 -  
316 - return rs;  
317 - }  
318 -  
319 - @Override  
320 - public Map<String, Object> search(Map<String, Object> map, int page, int size, String order, String direction) {  
321 - Map<String, Object> rsMap = new HashMap<>();  
322 - try{  
323 - //全量  
324 - Collection<GpsEntity> list = gpsRealData.all();  
325 - //过滤后的  
326 - List<GpsEntity> rs = new ArrayList<>();  
327 - Field[] fields = GpsEntity.class.getDeclaredFields();  
328 - //排序字段  
329 - Field orderField = null;  
330 - //参与过滤的字段  
331 - List<Field> fs = new ArrayList<>();  
332 - for(Field f : fields){  
333 - f.setAccessible(true);  
334 - if(map.containsKey(f.getName()))  
335 - fs.add(f);  
336 -  
337 - if(f.getName().equals(order))  
338 - orderField = f;  
339 - }  
340 - //过滤数据  
341 - for(GpsEntity gps : list){  
342 - if(fieldEquals(fs, gps, map))  
343 - rs.add(gps);  
344 - }  
345 -  
346 - //排序  
347 - if(null != orderField)  
348 - sortGpsList(orderField, rs);  
349 -  
350 - //分页  
351 - int count = rs.size()  
352 - ,s = page * size, e = s + size;  
353 - if (e > count)  
354 - e = count;  
355 -  
356 - rsMap.put("list", rs.subList(s, e));  
357 - rsMap.put("totalPages", count % size == 0 ? count / size : count / size + 1);  
358 - rsMap.put("page", page);  
359 - rsMap.put("status", ResponseCode.SUCCESS);  
360 - }catch(Exception e){  
361 - logger.error("", e);  
362 - rsMap.put("status", ResponseCode.ERROR);  
363 - }  
364 - return rsMap;  
365 - }  
366 -  
367 - private void sortGpsList(final Field f, List<GpsEntity> rs) {  
368 - Collections.sort(rs, new Comparator<GpsEntity>() {  
369 -  
370 - @Override  
371 - public int compare(GpsEntity o1, GpsEntity o2) {  
372 - try {  
373 - if(f.get(o1) == f.get(o2))  
374 - return 0;  
375 -  
376 - if(null == f.get(o1))  
377 - return 1;  
378 -  
379 - if(null == f.get(o2))  
380 - return -1;  
381 -  
382 - return f.get(o1).toString().compareTo(f.get(o2).toString());  
383 - } catch (Exception e) {  
384 - logger.error("", e);  
385 - return -1;  
386 - }  
387 - }  
388 - });  
389 - }  
390 -  
391 - public boolean fieldEquals(List<Field> fs, Object obj, Map<String, Object> map){  
392 - try{  
393 - for(Field f : fs){  
394 - if(f.get(obj).toString().indexOf(map.get(f.getName()).toString()) == -1)  
395 - return false;  
396 - }  
397 - }catch(Exception e){  
398 - logger.error("", e);  
399 - return false;  
400 - }  
401 - return true;  
402 - } 211 + ps.setLong(2, st * 1000);
  212 + ps.setLong(3, et * 1000);
  213 +
  214 + rs = ps.executeQuery();
  215 + Float lon, lat;
  216 + Location bdLoc, gdLoc;
  217 + int upDown, inOutStop;
  218 + ArrivalEntity arrival;
  219 + while (rs.next()) {
  220 + upDown = getUpOrDown(rs.getLong("SERVICE_STATE"));
  221 + map = new HashMap<>();
  222 +
  223 + lon = rs.getFloat("LON");
  224 + lat = rs.getFloat("LAT");
  225 + // 高德坐标
  226 + gdLoc = TransGPS.transformFromWGSToGCJ(TransGPS.LocationMake(lon, lat));
  227 + map.put("gcj_lon", gdLoc.getLng());
  228 + map.put("gcj_lat", gdLoc.getLat());
  229 + // 百度坐标
  230 + bdLoc = TransGPS.bd_encrypt(gdLoc);
  231 + map.put("bd_lon", bdLoc.getLng());
  232 + map.put("bd_lat", bdLoc.getLat());
  233 +
  234 + map.put("deviceId", rs.getString("DEVICE_ID"));
  235 + map.put("ts", rs.getLong("TS"));
  236 + map.put("timestamp", rs.getLong("TS"));
  237 + map.put("stopNo", rs.getString("STOP_NO"));
  238 +
  239 + inOutStop = rs.getInt("INOUT_STOP");
  240 + map.put("inout_stop", inOutStop);
  241 +
  242 + arrival = arrivalMap.get(rs.getString("DEVICE_ID") + "_" + rs.getLong("TS"));
  243 + if (arrival != null) {
  244 + map.put("inout_stop_info", arrival);
  245 + map.put("inout_stop", arrival.getInOut());
  246 + }
  247 + map.put("nbbm", BasicData.deviceId2NbbmMap.get(rs.getString("DEVICE_ID")));
  248 + map.put("state", 0);
  249 + // 上下行
  250 + map.put("upDown", upDown);
  251 + list.add(map);
  252 + }
  253 + } catch (Exception e) {
  254 + logger.error("", e);
  255 + } finally {
  256 + DBUtils_MS.close(rs, ps, conn);
  257 + }
  258 + return list;
  259 + }
  260 +
  261 + public Map<String, ArrivalEntity> findArrivalByTs(int weekOfYear, Long st, Long et, String devicesInSql) {
  262 + Map<String, ArrivalEntity> map = new HashMap<>();
  263 +
  264 + String sql = "SELECT DEVICE_ID,LINE_ID,STOP_NO,TS,UP_DOWN,IN_OUT,WEEKS_YEAR,CREATE_DATE FROM bsth_c_arrival_info where weeks_year=? and device_id in ("
  265 + + devicesInSql + ") and ts > ? and ts < ?";
  266 + try {
  267 + conn = DBUtils_MS.getConnection();
  268 + ps = conn.prepareStatement(sql);
  269 + ps.setInt(1, weekOfYear);
  270 + ps.setLong(2, st * 1000);
  271 + ps.setLong(3, et * 1000);
  272 +
  273 + rs = ps.executeQuery();
  274 + ArrivalEntity arr;
  275 + int inOut;
  276 + while (rs.next()) {
  277 + arr = new ArrivalEntity(rs.getString("DEVICE_ID"), rs.getLong("TS"), rs.getString("LINE_ID"),
  278 + rs.getInt("UP_DOWN"), rs.getString("STOP_NO"), rs.getInt("IN_OUT"), rs.getLong("CREATE_DATE"),
  279 + rs.getInt("WEEKS_YEAR"), BasicData.stationCode2NameMap.get(rs.getString("STOP_NO")));
  280 +
  281 + // 设备号_时间戳_进出状态 为key
  282 + // 反转进出状态
  283 + inOut = arr.getInOut() == 0 ? 1 : 0;
  284 + map.put(arr.getDeviceId() + "_" + arr.getTs(), arr);
  285 + }
  286 + } catch (Exception e) {
  287 + logger.error("", e);
  288 + } finally {
  289 + DBUtils_MS.close(rs, ps, conn);
  290 + }
  291 + return map;
  292 + }
  293 +
  294 +
  295 + @Autowired
  296 + StationRepository stationRepository;
  297 +
  298 + @Autowired
  299 + CarParkRepository carParkRepository;
  300 +
  301 + @Override
  302 + public Map<String, Object> findBuffAeraByCode(String code, String type) {
  303 + Object[][] obj = null;
  304 + if (type.equals("station"))
  305 + obj = stationRepository.bufferAera(code);
  306 + else if (type.equals("park"))
  307 + obj = carParkRepository.bufferAera(code);
  308 +
  309 + Map<String, Object> rs = new HashMap<>();
  310 +
  311 + Object[] subObj = obj[0];
  312 + if (subObj != null && subObj.length == 6) {
  313 + rs.put("polygon", subObj[0]);
  314 + rs.put("type", subObj[1]);
  315 + rs.put("cPoint", subObj[2]);
  316 + rs.put("radius", subObj[3]);
  317 + rs.put("code", subObj[4]);
  318 + rs.put("text", subObj[5]);
  319 + }
  320 +
  321 + return rs;
  322 + }
  323 +
  324 + @Override
  325 + public Map<String, Object> search(Map<String, Object> map, int page, int size, String order, String direction) {
  326 + Map<String, Object> rsMap = new HashMap<>();
  327 + try {
  328 + //全量
  329 + List<GpsEntity> list = new ArrayList<>(gpsRealData.all());
  330 + //过滤后的
  331 + List<GpsEntity> rs = new ArrayList<>();
  332 + Field[] fields = GpsEntity.class.getDeclaredFields();
  333 + //排序字段
  334 + Field orderField = null;
  335 + //参与过滤的字段
  336 + List<Field> fs = new ArrayList<>();
  337 + for (Field f : fields) {
  338 + f.setAccessible(true);
  339 + if (map.containsKey(f.getName()))
  340 + fs.add(f);
  341 +
  342 + if (f.getName().equals(order))
  343 + orderField = f;
  344 + }
  345 + //过滤数据
  346 + for (GpsEntity gps : list) {
  347 + if (fieldEquals(fs, gps, map))
  348 + rs.add(gps);
  349 + }
  350 +
  351 + //排序
  352 +/* if (null != orderField)
  353 + sortGpsList(orderField, rs);*/
  354 + //时间戳排序
  355 + Collections.sort(rs, new Comparator<GpsEntity>() {
  356 + @Override
  357 + public int compare(GpsEntity o1, GpsEntity o2) {
  358 + return o2.getTimestamp().intValue() - o1.getTimestamp().intValue();
  359 + }
  360 + });
  361 +
  362 + //分页
  363 + int count = rs.size(), s = page * size, e = s + size;
  364 + if (e > count)
  365 + e = count;
  366 +
  367 + rsMap.put("list", rs.subList(s, e));
  368 + rsMap.put("totalPages", count % size == 0 ? count / size - 1 : count / size);
  369 + rsMap.put("page", page);
  370 + rsMap.put("status", ResponseCode.SUCCESS);
  371 + } catch (Exception e) {
  372 + logger.error("", e);
  373 + rsMap.put("status", ResponseCode.ERROR);
  374 + }
  375 + return rsMap;
  376 + }
  377 +
  378 + @Override
  379 + public Map<String, Object> removeRealGps(String device) {
  380 + Map<String, Object> rs = new HashMap<>();
  381 + try {
  382 +
  383 + gpsRealData.remove(device);
  384 + rs.put("status", ResponseCode.SUCCESS);
  385 + }catch (Exception e){
  386 + rs.put("status", ResponseCode.ERROR);
  387 + }
  388 + return rs;
  389 + }
  390 +
  391 + private void sortGpsList(final Field f, List<GpsEntity> rs) {
  392 + Collections.sort(rs, new Comparator<GpsEntity>() {
  393 +
  394 + @Override
  395 + public int compare(GpsEntity o1, GpsEntity o2) {
  396 + try {
  397 + if (f.get(o1) == f.get(o2))
  398 + return 0;
  399 +
  400 + if (null == f.get(o1))
  401 + return 1;
  402 +
  403 + if (null == f.get(o2))
  404 + return -1;
  405 +
  406 + return f.get(o1).toString().compareTo(f.get(o2).toString());
  407 + } catch (Exception e) {
  408 + logger.error("", e);
  409 + return -1;
  410 + }
  411 + }
  412 + });
  413 + }
  414 +
  415 + public boolean fieldEquals(List<Field> fs, Object obj, Map<String, Object> map) {
  416 + try {
  417 + for (Field f : fs) {
  418 + if (StringUtils.isEmpty(map.get(f.getName()).toString()))
  419 + continue;
  420 +
  421 + if (f.get(obj) == null || f.get(obj).toString().indexOf(map.get(f.getName()).toString()) == -1)
  422 + return false;
  423 + }
  424 + } catch (Exception e) {
  425 + logger.error("", e);
  426 + return false;
  427 + }
  428 + return true;
  429 + }
403 } 430 }
src/main/java/com/bsth/service/impl/LineServiceImpl.java
@@ -40,8 +40,8 @@ public class LineServiceImpl extends BaseServiceImpl&lt;Line, Integer&gt; implements L @@ -40,8 +40,8 @@ public class LineServiceImpl extends BaseServiceImpl&lt;Line, Integer&gt; implements L
40 } 40 }
41 41
42 @Override 42 @Override
43 - public Line findByLineCode(Integer lineCode) {  
44 - return repository.findByLineCode(lineCode + ""); 43 + public Line findByLineCode(String lineCode) {
  44 + return repository.findByLineCode(lineCode);
45 } 45 }
46 46
47 } 47 }