Commit 0915b1dfc1248c2d42693477e7b34d6fbd7b2fc4

Authored by 潘钊
2 parents 43e285ed e0064270

Merge branch 'minhang' into pudong

Showing 67 changed files with 3092 additions and 3651 deletions
src/main/java/com/bsth/Application.java
... ... @@ -8,14 +8,16 @@ import org.springframework.boot.builder.SpringApplicationBuilder;
8 8 import org.springframework.boot.context.web.SpringBootServletInitializer;
9 9 import org.springframework.context.annotation.Bean;
10 10 import org.springframework.context.annotation.Primary;
  11 +import org.springframework.transaction.annotation.EnableTransactionManagement;
11 12  
12 13 import java.util.concurrent.Executors;
13 14 import java.util.concurrent.ScheduledExecutorService;
14 15  
  16 +@EnableTransactionManagement
15 17 @SpringBootApplication
16 18 public class Application extends SpringBootServletInitializer {
17 19  
18   - public static ScheduledExecutorService mainServices = Executors.newScheduledThreadPool(13);
  20 + public static ScheduledExecutorService mainServices = Executors.newScheduledThreadPool(14);
19 21  
20 22 @Override
21 23 protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
... ...
src/main/java/com/bsth/controller/forms/ExportController.java
... ... @@ -330,69 +330,22 @@ public class ExportController {
330 330 SimpleDateFormat sdfMonth = new SimpleDateFormat("yyyy-MM-dd"), sdfSimple = new SimpleDateFormat("yyyyMMdd");
331 331 List<Iterator<?>> listI = new ArrayList<Iterator<?>>();
332 332 ReportUtils ee = new ReportUtils();
333   - List<Turnoutrate> turnoutrate = formsService.turnoutrate(map);
334 333 Map<String, Object> map1 = new HashMap<String, Object>();
335   - List<Map<String, Object>> resList = new ArrayList<Map<String, Object>>();
336   - String xlts="";
337   - String zsgs="";
338   - String jh="";
339   - Float j=0f;
340   - Float sj=0f;
341   - Float qz=0f;
342   - Float ccl=0f;
343   - Float bcjh=0f;
344   - String bcsj="";
345   - Float bczxl=0f;
346   - String gs="";
347   - String zhgs="";
348 334  
349   - for (Turnoutrate l : turnoutrate) {
350   - Map<String, Object> m = new HashMap<String, Object>();
351   -
352   - xlts +=l.getGsgs()==""?0:String.valueOf(l.getGsgs());
353   - zsgs +=l.getFgsgs()==""?0:String.valueOf(l.getFgsgs());
354   - jh +=l.getXl()==""?0:String.valueOf(l.getXl());
355   - sj +=l.getCchjh()==""?0f:Float.valueOf(l.getCchjh());
356   - ccl +=l.getCchsj()==""?0f:Float.valueOf(l.getCchsj());
357   - bcjh +=l.getCchqz()==""?0f:Float.valueOf(l.getCchqz());
358   - bcsj +=l.getChl()==""?0:String.valueOf(l.getChl());
359   - bczxl +=l.getBcjh()==""?0f:Float.valueOf(l.getBcjh());
360   - gs +=l.getBcsj()==""?0:String.valueOf(l.getBcsj());
361   - zhgs +=l.getBbzxl()==""?0:String.valueOf(l.getBbzxl());
362   -
363   -
364   - m.put("rq", l.getRq());
365   - m.put("gs", l.getGs());
366   - m.put("zhgs", l.getZhgs());
367   - m.put("xl", l.getXl());
368   - m.put("cchjh", l.getCchjh());
369   - m.put("cchsj", l.getCchsj());
370   - m.put("cchqz", l.getCchqz());
371   - m.put("chl", l.getChl());
372   - m.put("bcjh", l.getBcjh());
373   - m.put("bcsj", l.getBcsj());
374   - m.put("bbzxl", l.getBbzxl());
375   - m.put("sm", l.getSm());
376   - resList.add(m);
377   -
378   -
379   -
380   - m=new HashMap<String,Object>();
381   - m.put("total_xlts", xlts);
382   - m.put("total_zhgs", zsgs);
383   - m.put("total_jh", jh);
384   - m.put("total_sj", sj);
385   - m.put("total_qz", ccl);
386   - m.put("total_ccl", bcjh);
387   - m.put("total_bcjh",bcsj);
388   - m.put("total_bcsj", bczxl);
389   - m.put("total_bczxl", bczxl);
390   - m.put("total_gs", zhgs);
391   -
392   -
393   - map1 = m;
394   - }
395   -
  335 + List<Map<String, Object>> resList = formsService.turnoutrate(map);
  336 + Map<String, Object> m = resList.get(resList.size() - 1);
  337 + map1.put("line", m.get("line"));
  338 + map1.put("jhcc", m.get("jhcc"));
  339 + map1.put("sjcc", m.get("sjcc"));
  340 + map1.put("jhbc", m.get("jhbc"));
  341 + map1.put("sjbc", m.get("sjbc"));
  342 + map1.put("ccl", m.get("ccl"));
  343 + map1.put("zxl", m.get("zxl"));
  344 + map1.put("qz", m.get("qz"));
  345 + map1.put("sm", m.get("sm"));
  346 +
  347 + resList.remove(m);
  348 +
396 349 try {
397 350 listI.add(resList.iterator());
398 351 String path = this.getClass().getResource("/").getPath() + "static/pages/forms/";
... ...
src/main/java/com/bsth/controller/forms/MCY_FormsController.java
... ... @@ -94,7 +94,7 @@ public class MCY_FormsController {
94 94  
95 95 // 营运线路出车率统计表
96 96 @RequestMapping(value = "/turnoutrate", method = RequestMethod.POST)
97   - public List<Turnoutrate> turnoutrate(@RequestParam Map<String, Object> map) {
  97 + public List<Map<String, Object>> turnoutrate(@RequestParam Map<String, Object> map) {
98 98  
99 99 return formsService.turnoutrate(map);
100 100 }
... ...
src/main/java/com/bsth/data/BasicData.java
... ... @@ -40,7 +40,7 @@ public class BasicData implements CommandLineRunner {
40 40 //车辆自编号和公司代码对照 (K: 车辆自编号 ,V:公司代码)
41 41 public static Map<String, String> nbbm2CompanyCodeMap;
42 42  
43   - //车辆自编号和公司代码对照 (K: 车辆自编号 ,V:牌照号)
  43 + //车辆自编号和牌照号对照 (K: 车辆自编号 ,V:牌照号)
44 44 public static Map<String, String> nbbmCompanyPlateMap;
45 45  
46 46 //站点编码和名称对照,包括停车场 (K: lineCode_updown_stationCode ,V:站点名称)
... ...
src/main/java/com/bsth/data/arrival/AnalyseData.java deleted 100644 → 0
1   -package com.bsth.data.arrival;
2   -
3   -import org.slf4j.Logger;
4   -import org.slf4j.LoggerFactory;
5   -import org.springframework.stereotype.Component;
6   -
7   -import java.util.ArrayList;
8   -import java.util.Collections;
9   -import java.util.List;
10   -import java.util.Set;
11   -
12   -/**
13   - *
14   - * @ClassName: AnalyseArrivalData
15   - * @Description: TODO(分析一下进出站场数据)
16   - * @author PanZhao
17   - * @date 2016年8月24日 上午11:09:37
18   - *
19   - */
20   -@Component
21   -public class AnalyseData {
22   -
23   - Logger logger = LoggerFactory.getLogger(AnalyseData.class);
24   -
25   - public void analyse(Set<String> cars){
26   - try{
27   - List<ArrivalEntity> list, clearList;
28   - for(String car : cars){
29   - list = ArrivalData_GPS.findByNbbm(car);
30   - analyse(list);
31   -
32   - //清理掉无效的点
33   - clearList = new ArrayList<>();
34   - for(ArrivalEntity arr : list){
35   - if(!arr.isEnable())
36   - clearList.add(arr);
37   - }
38   - list.removeAll(clearList);
39   - }
40   - }catch(Exception e){
41   - logger.error("", e);
42   - }
43   - }
44   -
45   - private final static int SHIFT_TIME = 1000 * 60 * 5,
46   - SCH_TIME = 1000 * 60 * 10;
47   -
48   - static ArrivalComparator comp = new ArrivalComparator();
49   -
50   - public void analyse(List<ArrivalEntity> list){
51   - if(list.size() <= 1)
52   - return;
53   -
54   - //排序
55   - Collections.sort(list, comp);
56   - ArrivalEntity prve = list.get(0)
57   - ,curr;
58   - for(int i = 1; i < list.size(); i ++){
59   - curr = list.get(i);
60   - //如果第一个点无效
61   - if(!effective(prve)){
62   - prve.setEnable(false);
63   - prve = curr;
64   - continue;
65   - }
66   - //如果第二个点无效
67   - else if(!effective(curr)){
68   - curr.setEnable(false);
69   - continue;
70   - }
71   - else if(curr.getTs() - prve.getTs() < SCH_TIME){
72   - if(prve.getUpDown() == curr.getUpDown()){
73   - //信号漂移,出站无效
74   - if(curr.getStopNo().equals(prve.getStopNo())
75   - && prve.getInOut() == 1 && curr.getInOut() == 0
76   - && curr.getTs() - prve.getTs() < SHIFT_TIME){
77   - prve.setEnable(false);
78   - }
79   -// else if(curr.getInOut()){
80   -// //curr.getTs() - prve.getTs() < 30000
81   -// }
82   - }
83   - else{
84   - //上下行的同名站,新走向的第一个出站信号开始有效
85   - if(prve.getStopName().equals(curr.getStopName())){
86   - if(curr.getInOut() == 0)
87   - curr.setEnable(false);
88   - else
89   - prve = curr;
90   - }
91   - }
92   - }
93   - else
94   - prve = curr;
95   - }
96   - }
97   -
98   - private boolean effective(ArrivalEntity arr){
99   - /*//停车场
100   - if(BasicData.parkCodeList.contains(arr.getStopNo())){
101   - arr.setTcc(true);
102   - return true;
103   - }
104   -
105   - Integer upDown = BasicData.lineStationUpDownMap.get(arr.getLineCode() + "_" + arr.getStopNo());
106   -
107   - return arr.getUpDown() == upDown || BasicData.parkCodeList.contains(arr.getStopNo());*/
108   - return false;
109   - }
110   -}
src/main/java/com/bsth/data/arrival/ArrivalData_GPS.java deleted 100644 → 0
1   -package com.bsth.data.arrival;
2   -
3   -import com.bsth.data.schedule.DayOfSchedule;
4   -import com.google.common.collect.ArrayListMultimap;
5   -import com.google.common.collect.ListMultimap;
6   -import org.slf4j.Logger;
7   -import org.slf4j.LoggerFactory;
8   -import org.springframework.beans.factory.annotation.Autowired;
9   -import org.springframework.boot.CommandLineRunner;
10   -import org.springframework.stereotype.Component;
11   -
12   -import java.util.*;
13   -
14   -/**
15   - *
16   - * @ClassName: ArrivalData_GPS
17   - * @Description: TODO(GPS到离站数据)
18   - * @author PanZhao
19   - * @date 2016年8月18日 下午10:05:27
20   - *
21   - */
22   -@Component
23   -public class ArrivalData_GPS implements CommandLineRunner{
24   -
25   - // 起终点站进出数据 K:车辆编码
26   - private static ListMultimap<String, ArrivalEntity> startAndEndMaps;
27   -
28   - private static Map<String, Integer> carIndexMap;
29   -
30   - static{
31   - startAndEndMaps = ArrayListMultimap.create();
32   -
33   - carIndexMap = new HashMap<>();
34   - }
35   -
36   - @Autowired
37   - DataLoaderThread dataLoaderThread;
38   -
39   - static Logger logger = LoggerFactory.getLogger(ArrivalData_GPS.class);
40   -
41   - @Override
42   - public void run(String... arg0) throws Exception {
43   - logger.info("ArrivalData_GPS,30,06");
44   - //Application.mainServices.scheduleWithFixedDelay(dataLoaderThread, 40, 6, TimeUnit.SECONDS);
45   - }
46   -
47   - @Component
48   - public static class DataLoaderThread extends Thread {
49   -
50   - @Autowired
51   - DataLoader dataLoader;
52   -
53   - @Autowired
54   - DayOfSchedule dayOfSchedule;
55   -
56   - @Autowired
57   - AnalyseData analyseData;
58   -
59   - @Override
60   - public void run() {
61   - /*try{
62   - logger.info("开始加载到离站数据, " + System.currentTimeMillis());
63   - List<ArrivalEntity> arrSets = dataLoader.load();
64   - if(null == arrSets || arrSets.size() == 0)
65   - return;
66   -
67   - //有起终点进出的车辆
68   - Set<String> carSet = new TreeSet<>();
69   - //按车辆起终点站过滤数据
70   - String nbbm;
71   - Set<String> seList;
72   - for(ArrivalEntity arr : arrSets){
73   - nbbm = arr.getNbbm();
74   -
75   - seList = dayOfSchedule.getSEStationList(nbbm);
76   - if(seList.contains(arr.getStopNo())){
77   - startAndEndMaps.put(nbbm, arr);
78   - carSet.add(nbbm);
79   - }
80   - }
81   - //从专业的角度分析一下数据
82   - analyseData.analyse(carSet);
83   -
84   - //开始匹配
85   - Arrival2Schedule.start(carSet);
86   - }catch(Exception e){
87   - logger.error("", e);
88   - }*/
89   - }
90   - }
91   -
92   - /**
93   - *
94   - * @Title: clearRAMData
95   - * @Description: TODO(清理内存数据)
96   - */
97   - public void clearRAMData(String lineCode){
98   -
99   - List<ArrivalEntity> remList = new ArrayList<>();
100   -
101   - //车辆映射的进出站数据,遍历删除对应线路数据。
102   - Collection<ArrivalEntity> seList = startAndEndMaps.values();
103   - for(ArrivalEntity arr : seList){
104   - if(arr.getLineCode().equals(lineCode))
105   - remList.add(arr);
106   - }
107   -
108   - //删除数据
109   - int count = 0;
110   - for(ArrivalEntity arr : remList){
111   - startAndEndMaps.remove(arr.getNbbm(), arr);
112   - count ++;
113   - }
114   -
115   - logger.info(lineCode + " 清除到离站数据 ," + count);
116   - }
117   -
118   - public synchronized static List<ArrivalEntity> findByNbbm(String nbbm){
119   - return startAndEndMaps.get(nbbm);
120   - }
121   -
122   - public static List<ArrivalEntity> getIncrement(String nbbm){
123   - Integer mark = null;
124   - if (!carIndexMap.containsKey(nbbm))
125   - mark = 0;
126   - else
127   - mark = carIndexMap.get(nbbm);
128   -
129   - List<ArrivalEntity> all = startAndEndMaps.get(nbbm);
130   - int size = all.size();
131   - if(size == 0)
132   - return new ArrayList<>(0);
133   -
134   - List<ArrivalEntity> rs = all.subList(mark, size);
135   - carIndexMap.put(nbbm, size);
136   - return rs;
137   - }
138   -}
139 0 \ No newline at end of file
src/main/java/com/bsth/data/car_out_info/CarOutInfo.java 0 → 100644
  1 +package com.bsth.data.car_out_info;
  2 +
  3 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
  4 +
  5 +import java.util.List;
  6 +
  7 +/**
  8 + * Created by panzhao on 2017/5/7.
  9 + */
  10 +public interface CarOutInfo {
  11 +
  12 + void updateAll();
  13 +
  14 + void update(String lineCode);
  15 +
  16 + void update(List<ScheduleRealInfo> list) ;
  17 +}
... ...
src/main/java/com/bsth/data/car_out_info/CarOutInfoHandler.java 0 → 100644
  1 +package com.bsth.data.car_out_info;
  2 +
  3 +import com.bsth.data.BasicData;
  4 +import com.bsth.data.schedule.DayOfSchedule;
  5 +import com.bsth.data.schedule.ScheduleComparator;
  6 +import com.bsth.entity.realcontrol.ScheduleRealInfo;
  7 +import com.google.common.collect.ArrayListMultimap;
  8 +import org.apache.commons.lang3.StringUtils;
  9 +import org.slf4j.Logger;
  10 +import org.slf4j.LoggerFactory;
  11 +import org.springframework.beans.factory.annotation.Autowired;
  12 +import org.springframework.boot.CommandLineRunner;
  13 +import org.springframework.jdbc.core.BatchPreparedStatementSetter;
  14 +import org.springframework.jdbc.core.JdbcTemplate;
  15 +import org.springframework.stereotype.Component;
  16 +import org.springframework.stereotype.Service;
  17 +import org.springframework.transaction.annotation.Transactional;
  18 +
  19 +import java.sql.PreparedStatement;
  20 +import java.sql.SQLException;
  21 +import java.util.*;
  22 +
  23 +/**
  24 + * 发车信息表处理程序
  25 + * Created by panzhao on 2017/5/5.
  26 + */
  27 +@Service
  28 +public class CarOutInfoHandler implements CommandLineRunner, CarOutInfo {
  29 +
  30 + @Autowired
  31 + DayOfSchedule dayOfSchedule;
  32 +
  33 + //班次类型对照表
  34 + Map<String, String> bcTypeMap;
  35 +
  36 + private static ScheduleComparator.FCSJ schFCSJComparator = new ScheduleComparator.FCSJ();
  37 +
  38 + @Autowired
  39 + JdbcTemplate jdbcTemplate;
  40 +
  41 + Logger logger = LoggerFactory.getLogger(this.getClass());
  42 +
  43 + /**
  44 + * 全量更新发车信息表
  45 + */
  46 + @Override
  47 + public void updateAll() {
  48 + Set<String> ks = BasicData.lineCode2NameMap.keySet();
  49 + for (String lineCode : ks) {
  50 + update(lineCode);
  51 + }
  52 + }
  53 +
  54 + @Override
  55 + public void update(String lineCode) {
  56 + try {
  57 + ArrayListMultimap<String, ScheduleRealInfo> lpScheduleMap = dayOfSchedule.getLpScheduleMap();
  58 + List<ScheduleRealInfo> list = new ArrayList<>();
  59 +
  60 + Set<String> ks = lpScheduleMap.keySet();
  61 + String prefix = lineCode + "_";
  62 + for (String k : ks) {
  63 + if (k.indexOf(prefix) != -1) {
  64 + list.addAll(lpScheduleMap.get(k));
  65 + }
  66 + }
  67 +
  68 + update(list);
  69 + } catch (Exception e) {
  70 + logger.error("", e);
  71 + }
  72 + }
  73 +
  74 + @Transactional
  75 + @Override
  76 + public void update(List<ScheduleRealInfo> list) {
  77 + if (list.size() == 0)
  78 + return;
  79 + String lineCode = list.get(0).getXlBm();
  80 + //按上下行分组
  81 + List<ScheduleRealInfo> ups = new ArrayList<>(), downs = new ArrayList<>();
  82 + for (ScheduleRealInfo sch : list) {
  83 + if (sch.getXlDir().equals("0"))
  84 + ups.add(sch);
  85 + else
  86 + downs.add(sch);
  87 + }
  88 +
  89 + ScheduleRealInfo[] upArray = nexts(ups),
  90 + downArray = nexts(downs);
  91 +
  92 + final List<ScheduleRealInfo> pstArray = mergeArray(upArray, downArray);
  93 + //删除
  94 + jdbcTemplate.update("delete from bsth_t_clfcxxb where line_code=?", lineCode);
  95 + //重新写入
  96 + jdbcTemplate.batchUpdate("insert into bsth_t_clfcxxb(rq, line_code, line_name, lp_name, lp_sn, dfsj, nbbm, cph, bc_type, end_station_name, updown, jGh, jName, remarks, sn)" +
  97 + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", new BatchPreparedStatementSetter() {
  98 + @Override
  99 + public void setValues(PreparedStatement ps, int i) throws SQLException {
  100 + ScheduleRealInfo sch = pstArray.get(i);
  101 + ps.setString(1, sch.getScheduleDateStr());
  102 + ps.setString(2, sch.getXlBm());
  103 + ps.setString(3, sch.getXlName());
  104 + ps.setString(4, sch.getLpName());
  105 + ps.setInt(5, sch.getFcno());
  106 + ps.setString(6, sch.getDfsj());
  107 + ps.setString(7, sch.getClZbh());
  108 + ps.setString(8, BasicData.nbbmCompanyPlateMap.get(sch.getClZbh()));
  109 + ps.setString(9, bcTypeMap.containsKey(sch.getBcType()) ? bcTypeMap.get(sch.getBcType()) : sch.getBcType());
  110 + ps.setString(10, sch.getZdzName());
  111 + ps.setInt(11, Integer.parseInt(sch.getXlDir()));
  112 + ps.setString(12, sch.getjGh());
  113 + ps.setString(13, sch.getjName());
  114 + ps.setString(14, sch.getRemarks());
  115 + ps.setInt(15, sch.getFcpSn());
  116 + }
  117 +
  118 + @Override
  119 + public int getBatchSize() {
  120 + return pstArray.size();
  121 + }
  122 + });
  123 + }
  124 +
  125 + private List<ScheduleRealInfo> mergeArray(ScheduleRealInfo[] upArray, ScheduleRealInfo[] downArray) {
  126 + List<ScheduleRealInfo> list = new ArrayList<>();
  127 + for (int i = 0; i < upArray.length; i++) {
  128 + if (upArray[i] != null) {
  129 + upArray[i].setFcpSn(i + 1);
  130 + list.add(upArray[i]);
  131 + }
  132 + }
  133 + for (int i = 0; i < downArray.length; i++) {
  134 + if (downArray[i] != null) {
  135 + downArray[i].setFcpSn(i + 1);
  136 + list.add(downArray[i]);
  137 + }
  138 + }
  139 + return list;
  140 + }
  141 +
  142 + /**
  143 + * 接下来要执行的3个班次
  144 + *
  145 + * @param list
  146 + * @return
  147 + */
  148 + private ScheduleRealInfo[] nexts(List<ScheduleRealInfo> list) {
  149 + ScheduleRealInfo[] array = new ScheduleRealInfo[3];
  150 + Collections.sort(list, schFCSJComparator);
  151 +
  152 + int count = 0, threshold = 1000 * 60 * 30;
  153 + long t = System.currentTimeMillis();
  154 + for (ScheduleRealInfo sch : list) {
  155 + if (count == 3)
  156 + break;
  157 +
  158 + //烂班
  159 + if (sch.isDestroy())
  160 + continue;
  161 +
  162 + //进场、出场、2点间空驶
  163 + if (sch.getBcType().equals("in")
  164 + || sch.getBcType().equals("out")
  165 + || sch.getBcType().equals("ldks"))
  166 + continue;
  167 +
  168 + //有实发实达时间的
  169 + if (StringUtils.isNotEmpty(sch.getFcsjActual())
  170 + || StringUtils.isNotEmpty(sch.getZdsjActual()))
  171 + continue;
  172 +
  173 + if (t - sch.getDfsjT() > threshold)
  174 + continue;
  175 +
  176 + array[count] = sch;
  177 + count++;
  178 + }
  179 + return array;
  180 + }
  181 +
  182 + @Autowired
  183 + UpdateInfoThread updateInfoThread;
  184 +
  185 + @Override
  186 + public void run(String... strings) throws Exception {
  187 + bcTypeMap = new HashMap<>();
  188 + bcTypeMap.put("normal", "正常班次");
  189 + bcTypeMap.put("region", "区间");
  190 + bcTypeMap.put("venting", "直放");
  191 + bcTypeMap.put("major", "放站");
  192 + bcTypeMap.put("ldks", "两点间空驶");
  193 + //Application.mainServices.scheduleWithFixedDelay(updateInfoThread, 60, 40, TimeUnit.SECONDS);
  194 + }
  195 +
  196 + @Component
  197 + private static class UpdateInfoThread extends Thread {
  198 +
  199 + @Autowired
  200 + CarOutInfo carOutInfoHandler;
  201 +
  202 + @Override
  203 + public void run() {
  204 + carOutInfoHandler.updateAll();
  205 + }
  206 + }
  207 +}
... ...
src/main/java/com/bsth/data/arrival/ArrivalComparator.java renamed to src/main/java/com/bsth/data/forecast/ArrivalComparator.java
1   -package com.bsth.data.arrival;
2   -
3   -import java.util.Comparator;
4   -
5   -public class ArrivalComparator implements Comparator<ArrivalEntity>{
6   -
7   - @Override
8   - public int compare(ArrivalEntity a1, ArrivalEntity a2) {
9   - return (int) (a1.getTs() - a2.getTs());
10   - }
11   -}
  1 +package com.bsth.data.forecast;
  2 +
  3 +import com.bsth.data.forecast.entity.ArrivalEntity;
  4 +
  5 +import java.util.Comparator;
  6 +
  7 +public class ArrivalComparator implements Comparator<ArrivalEntity>{
  8 +
  9 + @Override
  10 + public int compare(ArrivalEntity a1, ArrivalEntity a2) {
  11 + return (int) (a1.getTs() - a2.getTs());
  12 + }
  13 +}
... ...
src/main/java/com/bsth/data/arrival/DataLoader.java renamed to src/main/java/com/bsth/data/forecast/ArrivalDataLoader.java
1   -package com.bsth.data.arrival;
2   -
3   -import java.sql.Connection;
4   -import java.sql.PreparedStatement;
5   -import java.sql.ResultSet;
6   -import java.sql.SQLException;
7   -import java.util.ArrayList;
8   -import java.util.Calendar;
9   -import java.util.Collection;
10   -import java.util.List;
11   -
12   -import org.slf4j.Logger;
13   -import org.slf4j.LoggerFactory;
14   -import org.springframework.beans.factory.annotation.Autowired;
15   -import org.springframework.stereotype.Component;
16   -
17   -import com.bsth.data.BasicData;
18   -import com.bsth.data.LineConfigData;
19   -import com.bsth.entity.realcontrol.LineConfig;
20   -import com.bsth.util.db.DBUtils_MS;
21   -
22   -/**
23   - *
24   - * @ClassName: DataLoader
25   - * @Description: TODO(从数据库加载进出站数据)
26   - * @author PanZhao
27   - * @date 2016年8月19日 上午9:59:21
28   - *
29   - */
30   -@Component
31   -public class DataLoader {
32   -
33   - private static Long prveLoadTime;
34   -
35   - private final static long DAY_TIME = 1000 * 60 * 60 * 24;
36   -
37   - private Logger logger = LoggerFactory.getLogger(this.getClass());
38   -
39   - @Autowired
40   - LineConfigData lineConfigData;
41   -
42   - /**
43   - *
44   - * @Title: load
45   - * @Description: TODO(根据上次加载时间,查询之后的增量数据)
46   - */
47   - public List<ArrivalEntity> load(){
48   - List<ArrivalEntity> list = null;
49   -
50   - if(null == prveLoadTime)
51   - list = recovery();
52   - else{
53   - Calendar cal = Calendar.getInstance();
54   - //周数,表分区字段
55   - int weeks_year = cal.get(Calendar.WEEK_OF_YEAR);
56   -
57   - Connection conn = null;
58   - PreparedStatement ps = null;
59   - ResultSet rs = null;
60   -
61   - String sql = "select * from bsth_c_arrival_info where weeks_year=? AND create_timestamp > ? AND create_timestamp <=? AND ABS(create_timestamp - ts) < 3600000 order by create_date";
62   - try{
63   - long t = System.currentTimeMillis();
64   -
65   - conn = DBUtils_MS.getConnection();
66   - ps = conn.prepareStatement(sql);
67   - ps.setInt(1, weeks_year);
68   - ps.setLong(2, prveLoadTime);
69   - ps.setLong(3, t);
70   - rs = ps.executeQuery();
71   -
72   - list = resultSet2Set(rs);
73   -
74   - prveLoadTime = t;
75   - }catch(Exception e){
76   - logger.error("", e);
77   - }finally {
78   - DBUtils_MS.close(rs, ps, conn);
79   - }
80   - }
81   - return list;
82   - }
83   -
84   - /**
85   - *
86   - * @Title: recovery
87   - * @Description: TODO(从数据库恢复数据,按照线路的开始运营时间恢复)
88   - */
89   - public List<ArrivalEntity> recovery(){
90   - Collection<LineConfig> confs = lineConfigData.getAll();
91   - long t = System.currentTimeMillis()
92   - ,st;
93   -
94   - List<ArrivalEntity> all = new ArrayList<>();
95   - for(LineConfig conf : confs){
96   - st = conf.getCurrStartTime();
97   - if(t < st)
98   - st = st - DAY_TIME;
99   - try{
100   - all.addAll(loadByLineAndTime(conf.getLine().getLineCode(), st, t));
101   - }catch(Exception e){
102   - logger.error("", e);
103   - }
104   - }
105   -
106   - prveLoadTime = t;
107   - return all;
108   - }
109   -
110   - /**
111   - *
112   - * @Title: loadByLineAndStartTime
113   - * @Description: TODO(根据线路和时间戳加载数据)
114   - */
115   - public List<ArrivalEntity> loadByLineAndTime(String lineCode, long st, long et){
116   - Calendar cal = Calendar.getInstance();
117   - cal.setTimeInMillis(st);
118   - int weeks_year = cal.get(Calendar.WEEK_OF_YEAR);
119   -
120   - Connection conn = null;
121   - PreparedStatement ps = null;
122   - ResultSet rs = null;
123   -
124   - List<ArrivalEntity> list = new ArrayList<>();
125   - String sql = "select * from bsth_c_arrival_info where weeks_year=? and line_id=? AND create_timestamp > ? AND create_timestamp <=? AND ABS(create_timestamp - ts) < 3600000 order by ts";
126   - try{
127   - conn = DBUtils_MS.getConnection();
128   - ps = conn.prepareStatement(sql);
129   - ps.setInt(1, weeks_year);
130   - ps.setString(2, lineCode);
131   - ps.setLong(3, st);
132   - ps.setLong(4, et);
133   - rs = ps.executeQuery();
134   -
135   - list = resultSet2Set(rs);
136   - }catch(Exception e){
137   - logger.error("", e);
138   - }finally {
139   - DBUtils_MS.close(rs, ps, conn);
140   - }
141   - return list;
142   - }
143   -
144   - /**
145   - *
146   - * @Title: loadByLineAndStartTime
147   - * @Description: TODO(根据线路,走向和时间戳加载数据)
148   - */
149   - public List<ArrivalEntity> loadByLineAndTime(String lineCode, int updown, long st, long et){
150   - Calendar cal = Calendar.getInstance();
151   - cal.setTimeInMillis(st);
152   - int weeks_year = cal.get(Calendar.WEEK_OF_YEAR);
153   -
154   - Connection conn = null;
155   - PreparedStatement ps = null;
156   - ResultSet rs = null;
157   -
158   - List<ArrivalEntity> list = new ArrayList<>();
159   - String sql = "select * from bsth_c_arrival_info where weeks_year=? and line_id=? and up_down=? and in_out=0 AND create_timestamp > ? AND create_timestamp <=? AND ABS(create_timestamp - ts) < 3600000 order by ts";
160   - try{
161   - conn = DBUtils_MS.getConnection();
162   - ps = conn.prepareStatement(sql);
163   - ps.setInt(1, weeks_year);
164   - ps.setString(2, lineCode);
165   - ps.setInt(3, updown);
166   - ps.setLong(4, st);
167   - ps.setLong(5, et);
168   - rs = ps.executeQuery();
169   -
170   - list = resultSet2Set(rs);
171   - }catch(Exception e){
172   - logger.error("", e);
173   - }finally {
174   - DBUtils_MS.close(rs, ps, conn);
175   - }
176   - return list;
177   - }
178   -
179   - public List<ArrivalEntity> resultSet2Set(ResultSet rs) throws SQLException{
180   - List<ArrivalEntity> list = new ArrayList<>();
181   -
182   - ArrivalEntity arr;
183   - while(rs.next()){
184   - arr = new ArrivalEntity();
185   - arr.setDeviceId(rs.getString("device_id"));
186   - arr.setNbbm(BasicData.deviceId2NbbmMap.get(arr.getDeviceId()));
187   - if(null == arr.getNbbm()){
188   - logger.warn("未注册的设备号," + arr.getDeviceId());
189   - continue;
190   - }
191   -
192   - arr.setTs(rs.getLong("ts"));
193   - arr.setLineCode(rs.getString("line_id"));
194   - arr.setUpDown(rs.getInt("up_down"));
195   - arr.setStopNo(rs.getString("stop_no"));
196   - arr.setStopName(BasicData.stationCode2NameMap.get(arr.getStopNo()));
197   - arr.setInOut(rs.getInt("in_out"));
198   - arr.setCreateDate(rs.getLong("create_timestamp"));
199   - arr.setWeeksYear(rs.getInt("weeks_year"));
200   - arr.setEnable(true);
201   -
202   - list.add(arr);
203   - }
204   - return list;
205   - }
206   -
207   - public static void setPrveLoadTime(long t){
208   - prveLoadTime = t;
209   - }
210   -}
  1 +package com.bsth.data.forecast;
  2 +
  3 +import com.bsth.data.BasicData;
  4 +import com.bsth.data.LineConfigData;
  5 +import com.bsth.data.forecast.entity.ArrivalEntity;
  6 +import com.bsth.entity.realcontrol.LineConfig;
  7 +import com.bsth.util.db.DBUtils_MS;
  8 +import org.slf4j.Logger;
  9 +import org.slf4j.LoggerFactory;
  10 +import org.springframework.beans.factory.annotation.Autowired;
  11 +import org.springframework.stereotype.Component;
  12 +
  13 +import java.sql.Connection;
  14 +import java.sql.PreparedStatement;
  15 +import java.sql.ResultSet;
  16 +import java.sql.SQLException;
  17 +import java.util.ArrayList;
  18 +import java.util.Calendar;
  19 +import java.util.Collection;
  20 +import java.util.List;
  21 +
  22 +/**
  23 + *
  24 + * @ClassName: DataLoader
  25 + * @Description: TODO(从数据库加载进出站数据)
  26 + * @author PanZhao
  27 + * @date 2016年8月19日 上午9:59:21
  28 + *
  29 + */
  30 +@Component
  31 +public class ArrivalDataLoader {
  32 +
  33 + private static Long prveLoadTime;
  34 +
  35 + private final static long DAY_TIME = 1000 * 60 * 60 * 24;
  36 +
  37 + private Logger logger = LoggerFactory.getLogger(this.getClass());
  38 +
  39 + @Autowired
  40 + LineConfigData lineConfigData;
  41 +
  42 + /**
  43 + *
  44 + * @Title: load
  45 + * @Description: TODO(根据上次加载时间,查询之后的增量数据)
  46 + */
  47 + public List<ArrivalEntity> load(){
  48 + List<ArrivalEntity> list = null;
  49 +
  50 + if(null == prveLoadTime)
  51 + list = recovery();
  52 + else{
  53 + Calendar cal = Calendar.getInstance();
  54 + //周数,表分区字段
  55 + int weeks_year = cal.get(Calendar.WEEK_OF_YEAR);
  56 +
  57 + Connection conn = null;
  58 + PreparedStatement ps = null;
  59 + ResultSet rs = null;
  60 +
  61 + String sql = "select * from bsth_c_arrival_info where weeks_year=? AND create_timestamp > ? AND create_timestamp <=? AND ABS(create_timestamp - ts) < 3600000 order by create_date";
  62 + try{
  63 + long t = System.currentTimeMillis();
  64 +
  65 + conn = DBUtils_MS.getConnection();
  66 + ps = conn.prepareStatement(sql);
  67 + ps.setInt(1, weeks_year);
  68 + ps.setLong(2, prveLoadTime);
  69 + ps.setLong(3, t);
  70 + rs = ps.executeQuery();
  71 +
  72 + list = resultSet2Set(rs);
  73 +
  74 + prveLoadTime = t;
  75 + }catch(Exception e){
  76 + logger.error("", e);
  77 + }finally {
  78 + DBUtils_MS.close(rs, ps, conn);
  79 + }
  80 + }
  81 + return list;
  82 + }
  83 +
  84 + /**
  85 + *
  86 + * @Title: recovery
  87 + * @Description: TODO(从数据库恢复数据,按照线路的开始运营时间恢复)
  88 + */
  89 + public List<ArrivalEntity> recovery(){
  90 + Collection<LineConfig> confs = lineConfigData.getAll();
  91 + long t = System.currentTimeMillis()
  92 + ,st;
  93 +
  94 + List<ArrivalEntity> all = new ArrayList<>();
  95 + for(LineConfig conf : confs){
  96 + st = conf.getCurrStartTime();
  97 + if(t < st)
  98 + st = st - DAY_TIME;
  99 + try{
  100 + all.addAll(loadByLineAndTime(conf.getLine().getLineCode(), st, t));
  101 + }catch(Exception e){
  102 + logger.error("", e);
  103 + }
  104 + }
  105 +
  106 + prveLoadTime = t;
  107 + return all;
  108 + }
  109 +
  110 + /**
  111 + *
  112 + * @Title: loadByLineAndStartTime
  113 + * @Description: TODO(根据线路和时间戳加载数据)
  114 + */
  115 + public List<ArrivalEntity> loadByLineAndTime(String lineCode, long st, long et){
  116 + Calendar cal = Calendar.getInstance();
  117 + cal.setTimeInMillis(st);
  118 + int weeks_year = cal.get(Calendar.WEEK_OF_YEAR);
  119 +
  120 + Connection conn = null;
  121 + PreparedStatement ps = null;
  122 + ResultSet rs = null;
  123 +
  124 + List<ArrivalEntity> list = new ArrayList<>();
  125 + String sql = "select * from bsth_c_arrival_info where weeks_year=? and line_id=? AND create_timestamp > ? AND create_timestamp <=? AND ABS(create_timestamp - ts) < 3600000 order by ts";
  126 + try{
  127 + conn = DBUtils_MS.getConnection();
  128 + ps = conn.prepareStatement(sql);
  129 + ps.setInt(1, weeks_year);
  130 + ps.setString(2, lineCode);
  131 + ps.setLong(3, st);
  132 + ps.setLong(4, et);
  133 + rs = ps.executeQuery();
  134 +
  135 + list = resultSet2Set(rs);
  136 + }catch(Exception e){
  137 + logger.error("", e);
  138 + }finally {
  139 + DBUtils_MS.close(rs, ps, conn);
  140 + }
  141 + return list;
  142 + }
  143 +
  144 + /**
  145 + *
  146 + * @Title: loadByLineAndStartTime
  147 + * @Description: TODO(根据线路,走向和时间戳加载数据)
  148 + */
  149 + public List<ArrivalEntity> loadByLineAndTime(String lineCode, int updown, long st, long et){
  150 + Calendar cal = Calendar.getInstance();
  151 + cal.setTimeInMillis(st);
  152 + int weeks_year = cal.get(Calendar.WEEK_OF_YEAR);
  153 +
  154 + Connection conn = null;
  155 + PreparedStatement ps = null;
  156 + ResultSet rs = null;
  157 +
  158 + List<ArrivalEntity> list = new ArrayList<>();
  159 + String sql = "select * from bsth_c_arrival_info where weeks_year=? and line_id=? and up_down=? and in_out=0 AND create_timestamp > ? AND create_timestamp <=? AND ABS(create_timestamp - ts) < 3600000 order by ts";
  160 + try{
  161 + conn = DBUtils_MS.getConnection();
  162 + ps = conn.prepareStatement(sql);
  163 + ps.setInt(1, weeks_year);
  164 + ps.setString(2, lineCode);
  165 + ps.setInt(3, updown);
  166 + ps.setLong(4, st);
  167 + ps.setLong(5, et);
  168 + rs = ps.executeQuery();
  169 +
  170 + list = resultSet2Set(rs);
  171 + }catch(Exception e){
  172 + logger.error("", e);
  173 + }finally {
  174 + DBUtils_MS.close(rs, ps, conn);
  175 + }
  176 + return list;
  177 + }
  178 +
  179 + public List<ArrivalEntity> resultSet2Set(ResultSet rs) throws SQLException{
  180 + List<ArrivalEntity> list = new ArrayList<>();
  181 +
  182 + ArrivalEntity arr;
  183 + while(rs.next()){
  184 + arr = new ArrivalEntity();
  185 + arr.setDeviceId(rs.getString("device_id"));
  186 + arr.setNbbm(BasicData.deviceId2NbbmMap.get(arr.getDeviceId()));
  187 + if(null == arr.getNbbm()){
  188 + logger.warn("未注册的设备号," + arr.getDeviceId());
  189 + continue;
  190 + }
  191 +
  192 + arr.setTs(rs.getLong("ts"));
  193 + arr.setLineCode(rs.getString("line_id"));
  194 + arr.setUpDown(rs.getInt("up_down"));
  195 + arr.setStopNo(rs.getString("stop_no"));
  196 + arr.setStopName(BasicData.stationCode2NameMap.get(arr.getStopNo()));
  197 + arr.setInOut(rs.getInt("in_out"));
  198 + arr.setCreateDate(rs.getLong("create_timestamp"));
  199 + arr.setWeeksYear(rs.getInt("weeks_year"));
  200 + arr.setEnable(true);
  201 +
  202 + list.add(arr);
  203 + }
  204 + return list;
  205 + }
  206 +
  207 + public static void setPrveLoadTime(long t){
  208 + prveLoadTime = t;
  209 + }
  210 +}
... ...
src/main/java/com/bsth/data/arrival/ArrivalEntity.java renamed to src/main/java/com/bsth/data/forecast/entity/ArrivalEntity.java
1   -package com.bsth.data.arrival;
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 ArrivalEntity {
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   - /** -1 则信号有效,但程序标记为不使用 */
57   - private int flag = 0;
58   -
59   - public ArrivalEntity(){}
60   -
61   - public ArrivalEntity(String deviceId, long ts, String lineCode, int upDown, String stopNo, int inOut, long createDate,
62   - int weeksYear, String stopName) {
63   -
64   - this.deviceId = deviceId;
65   - this.ts = ts;
66   - this.lineCode = lineCode;
67   - this.upDown = upDown;
68   - this.stopNo = stopNo;
69   - this.stopName = stopName;
70   - this.inOut = inOut;
71   - this.createDate = createDate;
72   - }
73   -
74   -/* @Override
75   - public boolean equals(Object obj) {
76   - ArrivalEntity a2 = (ArrivalEntity)obj;
77   -
78   - return this.toString().equals(a2.toString())
79   - && Math.abs(this.ts - a2.ts) < EQ_RANGE;
80   - }
81   -
82   - @Override
83   - public int hashCode() {
84   - return this.toString().hashCode();
85   - }*/
86   -
87   -
88   - @Override
89   - public String toString() {
90   - try {
91   - SimpleDateFormat sdfHHmm = new SimpleDateFormat("HH:mm");
92   - return "["+BasicData.deviceId2NbbmMap.get(this.deviceId)+", "+sdfHHmm.format(new Date(this.ts))
93   - +","+(this.getUpDown()==0?"上行":"下行")+","+(this.inOut==0?"进":"出")+","+this.stopNo+" ("+this.stopName+")]";
94   - } catch (Exception e) {
95   - return "";
96   - }
97   - }
98   -
99   - public String getLineCode() {
100   - return lineCode;
101   - }
102   -
103   - public void setLineCode(String lineCode) {
104   - this.lineCode = lineCode;
105   - }
106   -
107   - public Integer getUpDown() {
108   - return upDown;
109   - }
110   -
111   - public void setUpDown(Integer upDown) {
112   - this.upDown = upDown;
113   - }
114   -
115   - public String getStopNo() {
116   - return stopNo;
117   - }
118   -
119   - public void setStopNo(String stopNo) {
120   - this.stopNo = stopNo;
121   - }
122   -
123   - public Integer getInOut() {
124   - return inOut;
125   - }
126   -
127   - public void setInOut(Integer inOut) {
128   - this.inOut = inOut;
129   - }
130   -
131   - public Long getCreateDate() {
132   - return createDate;
133   - }
134   -
135   - public void setCreateDate(Long createDate) {
136   - this.createDate = createDate;
137   - }
138   -
139   - public Integer getWeeksYear() {
140   - return weeksYear;
141   - }
142   -
143   - public void setWeeksYear(Integer weeksYear) {
144   - this.weeksYear = weeksYear;
145   - }
146   -
147   - public String getDeviceId() {
148   - return deviceId;
149   - }
150   -
151   - public void setDeviceId(String deviceId) {
152   - this.deviceId = deviceId;
153   - }
154   -
155   - public Long getTs() {
156   - return ts;
157   - }
158   -
159   - public void setTs(Long ts) {
160   - this.ts = ts;
161   - }
162   -
163   - public String getStopName() {
164   - return stopName;
165   - }
166   -
167   - public void setStopName(String stopName) {
168   - this.stopName = stopName;
169   - }
170   -
171   - public String getId(){
172   - return this.deviceId + "_" + this.ts;
173   - }
174   -
175   - public String getNbbm() {
176   - return nbbm;
177   - }
178   -
179   - public void setNbbm(String nbbm) {
180   - this.nbbm = nbbm;
181   - }
182   -
183   - public boolean isEnable() {
184   - return enable;
185   - }
186   -
187   - public void setEnable(boolean enable) {
188   - this.enable = enable;
189   - }
190   -
191   - public boolean isTcc() {
192   - return tcc;
193   - }
194   -
195   - public void setTcc(boolean tcc) {
196   - this.tcc = tcc;
197   - }
198   -
199   - public boolean isOutTcc() {
200   - return isTcc() && inOut == 1;
201   - }
202   -
203   - public boolean isCorrect() {
204   - return correct;
205   - }
206   -
207   - public void setCorrect(boolean correct) {
208   - this.correct = correct;
209   - }
210   -
211   - public String getCorrectText() {
212   - return correctText;
213   - }
214   -
215   - public void setCorrectText(String correctText) {
216   - this.correctText = correctText;
217   - }
218   -
219   - public Integer getFlag() {
220   - return flag;
221   - }
222   -
223   - public void setFlag(Integer flag) {
224   - this.flag = flag;
225   - }
226   -}
  1 +package com.bsth.data.forecast.entity;
  2 +
  3 +import com.bsth.data.BasicData;
  4 +
  5 +import java.text.SimpleDateFormat;
  6 +import java.util.Date;
  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 ArrivalEntity {
  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 + /** -1 则信号有效,但程序标记为不使用 */
  57 + private int flag = 0;
  58 +
  59 + public ArrivalEntity(){}
  60 +
  61 + public ArrivalEntity(String deviceId, long ts, String lineCode, int upDown, String stopNo, int inOut, long createDate,
  62 + int weeksYear, String stopName) {
  63 +
  64 + this.deviceId = deviceId;
  65 + this.ts = ts;
  66 + this.lineCode = lineCode;
  67 + this.upDown = upDown;
  68 + this.stopNo = stopNo;
  69 + this.stopName = stopName;
  70 + this.inOut = inOut;
  71 + this.createDate = createDate;
  72 + }
  73 +
  74 +/* @Override
  75 + public boolean equals(Object obj) {
  76 + ArrivalEntity a2 = (ArrivalEntity)obj;
  77 +
  78 + return this.toString().equals(a2.toString())
  79 + && Math.abs(this.ts - a2.ts) < EQ_RANGE;
  80 + }
  81 +
  82 + @Override
  83 + public int hashCode() {
  84 + return this.toString().hashCode();
  85 + }*/
  86 +
  87 +
  88 + @Override
  89 + public String toString() {
  90 + try {
  91 + SimpleDateFormat sdfHHmm = new SimpleDateFormat("HH:mm");
  92 + return "["+BasicData.deviceId2NbbmMap.get(this.deviceId)+", "+sdfHHmm.format(new Date(this.ts))
  93 + +","+(this.getUpDown()==0?"上行":"下行")+","+(this.inOut==0?"进":"出")+","+this.stopNo+" ("+this.stopName+")]";
  94 + } catch (Exception e) {
  95 + return "";
  96 + }
  97 + }
  98 +
  99 + public String getLineCode() {
  100 + return lineCode;
  101 + }
  102 +
  103 + public void setLineCode(String lineCode) {
  104 + this.lineCode = lineCode;
  105 + }
  106 +
  107 + public Integer getUpDown() {
  108 + return upDown;
  109 + }
  110 +
  111 + public void setUpDown(Integer upDown) {
  112 + this.upDown = upDown;
  113 + }
  114 +
  115 + public String getStopNo() {
  116 + return stopNo;
  117 + }
  118 +
  119 + public void setStopNo(String stopNo) {
  120 + this.stopNo = stopNo;
  121 + }
  122 +
  123 + public Integer getInOut() {
  124 + return inOut;
  125 + }
  126 +
  127 + public void setInOut(Integer inOut) {
  128 + this.inOut = inOut;
  129 + }
  130 +
  131 + public Long getCreateDate() {
  132 + return createDate;
  133 + }
  134 +
  135 + public void setCreateDate(Long createDate) {
  136 + this.createDate = createDate;
  137 + }
  138 +
  139 + public Integer getWeeksYear() {
  140 + return weeksYear;
  141 + }
  142 +
  143 + public void setWeeksYear(Integer weeksYear) {
  144 + this.weeksYear = weeksYear;
  145 + }
  146 +
  147 + public String getDeviceId() {
  148 + return deviceId;
  149 + }
  150 +
  151 + public void setDeviceId(String deviceId) {
  152 + this.deviceId = deviceId;
  153 + }
  154 +
  155 + public Long getTs() {
  156 + return ts;
  157 + }
  158 +
  159 + public void setTs(Long ts) {
  160 + this.ts = ts;
  161 + }
  162 +
  163 + public String getStopName() {
  164 + return stopName;
  165 + }
  166 +
  167 + public void setStopName(String stopName) {
  168 + this.stopName = stopName;
  169 + }
  170 +
  171 + public String getId(){
  172 + return this.deviceId + "_" + this.ts;
  173 + }
  174 +
  175 + public String getNbbm() {
  176 + return nbbm;
  177 + }
  178 +
  179 + public void setNbbm(String nbbm) {
  180 + this.nbbm = nbbm;
  181 + }
  182 +
  183 + public boolean isEnable() {
  184 + return enable;
  185 + }
  186 +
  187 + public void setEnable(boolean enable) {
  188 + this.enable = enable;
  189 + }
  190 +
  191 + public boolean isTcc() {
  192 + return tcc;
  193 + }
  194 +
  195 + public void setTcc(boolean tcc) {
  196 + this.tcc = tcc;
  197 + }
  198 +
  199 + public boolean isOutTcc() {
  200 + return isTcc() && inOut == 1;
  201 + }
  202 +
  203 + public boolean isCorrect() {
  204 + return correct;
  205 + }
  206 +
  207 + public void setCorrect(boolean correct) {
  208 + this.correct = correct;
  209 + }
  210 +
  211 + public String getCorrectText() {
  212 + return correctText;
  213 + }
  214 +
  215 + public void setCorrectText(String correctText) {
  216 + this.correctText = correctText;
  217 + }
  218 +
  219 + public Integer getFlag() {
  220 + return flag;
  221 + }
  222 +
  223 + public void setFlag(Integer flag) {
  224 + this.flag = flag;
  225 + }
  226 +}
... ...
src/main/java/com/bsth/data/gpsdata/GpsRealData.java
1 1 package com.bsth.data.gpsdata;
2 2  
  3 +import com.bsth.Application;
3 4 import com.bsth.data.BasicData;
4 5 import com.bsth.data.forecast.ForecastRealServer;
5 6 import com.bsth.data.gpsdata.client.ClientApp;
... ... @@ -16,6 +17,7 @@ import org.springframework.boot.CommandLineRunner;
16 17 import org.springframework.stereotype.Component;
17 18  
18 19 import java.util.*;
  20 +import java.util.concurrent.TimeUnit;
19 21  
20 22 /**
21 23 * @author PanZhao
... ... @@ -61,7 +63,7 @@ public class GpsRealData implements CommandLineRunner {
61 63 //定时从网关http形式获取GPS数据 --- 已弃用,现socket客户端接入数据
62 64 //Application.mainServices.scheduleWithFixedDelay(gpsDataLoader, 20, 3, TimeUnit.SECONDS);
63 65 //定时扫描掉离线
64   - //Application.mainServices.scheduleWithFixedDelay(offlineMonitorThread, 120, 60, TimeUnit.SECONDS);
  66 + Application.mainServices.scheduleWithFixedDelay(offlineMonitorThread, 120, 60, TimeUnit.SECONDS);
65 67  
66 68 //gps 客户端
67 69 //clientApp.init();
... ...
src/main/java/com/bsth/data/gpsdata/client/ClientApp.java
... ... @@ -15,12 +15,12 @@ import org.apache.mina.filter.codec.ProtocolCodecFilter;
15 15 import org.apache.mina.filter.logging.LogLevel;
16 16 import org.apache.mina.filter.logging.LoggingFilter;
17 17 import org.apache.mina.transport.socket.nio.NioSocketConnector;
  18 +import org.slf4j.Logger;
  19 +import org.slf4j.LoggerFactory;
18 20 import org.springframework.beans.factory.annotation.Autowired;
19 21 import org.springframework.stereotype.Component;
20 22  
21 23 import java.net.InetSocketAddress;
22   -import java.util.concurrent.ExecutorService;
23   -import java.util.concurrent.Executors;
24 24  
25 25 /**
26 26 * Created by panzhao on 2017/5/4.
... ... @@ -30,7 +30,6 @@ public class ClientApp {
30 30  
31 31 private static NioSocketConnector pdDataConnector;
32 32 private static NioSocketConnector pfDataConnector;
33   - private static ExecutorService exec;
34 33  
35 34 @Autowired
36 35 private PdClientHandler pdClient;
... ... @@ -39,6 +38,8 @@ public class ClientApp {
39 38 @Autowired
40 39 GpsBeforeBuffer gpsBeforeBuffer;
41 40  
  41 + static Logger logger = LoggerFactory.getLogger(ClientApp.class);
  42 +
42 43 public static boolean dconnect(String device) {
43 44 boolean flag = false;
44 45 try {
... ... @@ -59,6 +60,8 @@ public class ClientApp {
59 60 WriteFuture write = session.write(bytes);
60 61 write.awaitUninterruptibly();
61 62 flag = true;
  63 +
  64 + logger.info("dconnect...");
62 65 //SessionManager.getInstance().register(device, session);
63 66 } catch (Exception e) {
64 67 e.printStackTrace();
... ... @@ -74,6 +77,8 @@ public class ClientApp {
74 77 IoSession session = con.getSession();
75 78 session.setAttribute("deviceId", device);
76 79 flag = true;
  80 +
  81 + logger.info("fconnect...");
77 82 } catch (Exception e) {
78 83 e.printStackTrace();
79 84 }
... ... @@ -81,7 +86,7 @@ public class ClientApp {
81 86 }
82 87  
83 88 public void init() {
84   - exec = Executors.newFixedThreadPool(4);
  89 + //exec = Executors.newFixedThreadPool(4);
85 90 //sexec.scheduleAtFixedRate(new SessionChecker(), 1, 1, TimeUnit.MINUTES);
86 91 /*******************************浦东********************************/
87 92 pdDataConnector = new NioSocketConnector();
... ... @@ -128,4 +133,4 @@ public class ClientApp {
128 133  
129 134 gpsBeforeBuffer.init();
130 135 }
131 136 -}
  137 +}
132 138 \ No newline at end of file
... ...
src/main/java/com/bsth/data/gpsdata/client/GpsBeforeBuffer.java
... ... @@ -63,7 +63,7 @@ public class GpsBeforeBuffer {
63 63 }
64 64  
65 65 public void init(){
66   - Application.mainServices.scheduleWithFixedDelay(gpsHandleThread, 20, 2, TimeUnit.SECONDS);
  66 + Application.mainServices.scheduleWithFixedDelay(gpsHandleThread, 20 * 1000, 1100, TimeUnit.MILLISECONDS);
67 67 }
68 68  
69 69 @Component
... ... @@ -100,4 +100,4 @@ public class GpsBeforeBuffer {
100 100 return -1;
101 101 return (byte) (((serviceState & 0x02000000) == 0x02000000) ? 1 : 0);
102 102 }
103 103 -}
  104 +}
104 105 \ No newline at end of file
... ...
src/main/java/com/bsth/data/gpsdata/client/common/ExceptionUtil.java
1   -package com.bsth.data.gpsdata.client.common;
2   -
3   -public class ExceptionUtil {
4   -
5   - public static String getTrace(Throwable e) {
6   - StringBuilder sb = new StringBuilder();
7   - sb.append(e.toString());
8   - for (StackTraceElement ste : e.getStackTrace()) {
9   - sb.append(ste).append("\r\n");
10   - }
11   - return sb.toString();
12   - }
13   -}
  1 +package com.bsth.data.gpsdata.client.common;
  2 +
  3 +public class ExceptionUtil {
  4 +
  5 + public static String getTrace(Throwable e) {
  6 + StringBuilder sb = new StringBuilder();
  7 + sb.append(e.toString());
  8 + for (StackTraceElement ste : e.getStackTrace()) {
  9 + sb.append(ste).append("\r\n");
  10 + }
  11 + return sb.toString();
  12 + }
  13 +}
... ...
src/main/java/com/bsth/data/gpsdata/client/common/Protocol2BizUtil.java
1   -package com.bsth.data.gpsdata.client.common;
2   -
3   -//import com.bsth.data.gpsdata.socket_client_001.pd.protocol.BasicInfo;
4   -//import com.bsth.data.gpsdata.socket_client_001.pf.protocol.PfMessage;
5   -//import com.bsth.data.gpsdata.socket_client_001.pf.protocol.Pf_1_0;
6   -
7   -import com.bsth.data.gpsdata.client.pd.protocol.BasicInfo;
8   -import com.bsth.data.gpsdata.client.pf.protocol.PfMessage;
9   -import com.bsth.data.gpsdata.client.pf.protocol.Pf_1_0;
10   -import org.slf4j.Logger;
11   -import org.slf4j.LoggerFactory;
12   -
13   -public class Protocol2BizUtil {
14   -
15   - private final static Logger log = LoggerFactory.getLogger(Protocol2BizUtil.class);
16   -
17   - /**
18   - * 从协议数据中获得基本数据
19   - */
20   - public static BasicInfo getBasicInfoFromMsg(PfMessage msg) {
21   - if (msg == null) return null;
22   - BasicInfo info = null;
23   - if (msg.getCommandType() == 0x01) {
24   - Pf_1_0 pf_1_0 = (Pf_1_0)msg.getMessageBody();
25   - info = new BasicInfo();
26   - info.setLineId(pf_1_0.getXldm());
27   - info.setDeviceId(pf_1_0.getMtd());
28   - info.setDriverEmpNo(Integer.parseInt(pf_1_0.getDriver().trim()));
29   - info.setCarparkNo(pf_1_0.getTccbh());
30   - info.setStopNo(pf_1_0.getZdbh());
31   - double lon = pf_1_0.getLon()/1000000, lat = pf_1_0.getLat()/1000000;
32   - info.setCarLon(((long)lon) * 1000000 + (long)((lon - (long)lon) * 600000));
33   - info.setCarLat(((int)lat) * 1000000 + (int)((lat - (int)lat) * 600000));
34   - info.setTimestamp(pf_1_0.getFssj().getTime());
35   - info.setSpeedGps((short)pf_1_0.getSpeed());
36   - info.setSpeedSensor((short)(pf_1_0.getSpeed()));
37   - info.setDirection((short)(pf_1_0.getFx()));
38   - info.setServiceState(0);
39   - info.setService(pf_1_0.getYyzt() == 0 ? true : false);
40   - info.setUpOrDown(pf_1_0.getSxxzt() == 0 ? true : false);
41   -
42   - info.setLon(Float.parseFloat(String.valueOf(lon)));
43   - info.setLat(Float.parseFloat(String.valueOf(lat)));
44   - }
45   -
46   - return info;
47   - }
48   -}
  1 +package com.bsth.data.gpsdata.client.common;
  2 +
  3 +//import com.bsth.data.gpsdata.socket_client_001.pd.protocol.BasicInfo;
  4 +//import com.bsth.data.gpsdata.socket_client_001.pf.protocol.PfMessage;
  5 +//import com.bsth.data.gpsdata.socket_client_001.pf.protocol.Pf_1_0;
  6 +
  7 +import com.bsth.data.gpsdata.client.pd.protocol.BasicInfo;
  8 +import com.bsth.data.gpsdata.client.pf.protocol.PfMessage;
  9 +import com.bsth.data.gpsdata.client.pf.protocol.Pf_1_0;
  10 +import org.slf4j.Logger;
  11 +import org.slf4j.LoggerFactory;
  12 +
  13 +public class Protocol2BizUtil {
  14 +
  15 + private final static Logger log = LoggerFactory.getLogger(Protocol2BizUtil.class);
  16 +
  17 + /**
  18 + * 从协议数据中获得基本数据
  19 + */
  20 + public static BasicInfo getBasicInfoFromMsg(PfMessage msg) {
  21 + if (msg == null) return null;
  22 + BasicInfo info = null;
  23 + if (msg.getCommandType() == 0x01) {
  24 + Pf_1_0 pf_1_0 = (Pf_1_0)msg.getMessageBody();
  25 + info = new BasicInfo();
  26 + info.setLineId(pf_1_0.getXldm());
  27 + info.setDeviceId(pf_1_0.getMtd());
  28 + info.setDriverEmpNo(Integer.parseInt(pf_1_0.getDriver().trim()));
  29 + info.setCarparkNo(pf_1_0.getTccbh());
  30 + info.setStopNo(pf_1_0.getZdbh());
  31 + double lon = pf_1_0.getLon()/1000000, lat = pf_1_0.getLat()/1000000;
  32 + info.setCarLon(((long)lon) * 1000000 + (long)((lon - (long)lon) * 600000));
  33 + info.setCarLat(((int)lat) * 1000000 + (int)((lat - (int)lat) * 600000));
  34 + info.setTimestamp(pf_1_0.getFssj().getTime());
  35 + info.setSpeedGps((short)pf_1_0.getSpeed());
  36 + info.setSpeedSensor((short)(pf_1_0.getSpeed()));
  37 + info.setDirection((short)(pf_1_0.getFx()));
  38 + info.setServiceState(0);
  39 + info.setService(pf_1_0.getYyzt() == 0 ? true : false);
  40 + info.setUpOrDown(pf_1_0.getSxxzt() == 0 ? true : false);
  41 +
  42 + info.setLon(Float.parseFloat(String.valueOf(lon)));
  43 + info.setLat(Float.parseFloat(String.valueOf(lat)));
  44 + }
  45 +
  46 + return info;
  47 + }
  48 +}
... ...
src/main/java/com/bsth/data/gpsdata/client/common/ThreadLocalDateUtil.java
1   -package com.bsth.data.gpsdata.client.common;
2   -
3   -import java.text.DateFormat;
4   -import java.text.ParseException;
5   -import java.text.SimpleDateFormat;
6   -import java.util.Date;
7   -
8   -public class ThreadLocalDateUtil {
9   - private static final String date_format = "yyyyMMddHHmmss";
10   - private static ThreadLocal<DateFormat> threadLocal = new ThreadLocal<DateFormat>();
11   -
12   - public static DateFormat getDateFormat()
13   - {
14   - DateFormat df = threadLocal.get();
15   - if(df==null){
16   - df = new SimpleDateFormat(date_format);
17   - threadLocal.set(df);
18   - }
19   - return df;
20   - }
21   -
22   - public static String formatDate(Date date) throws ParseException {
23   - return getDateFormat().format(date);
24   - }
25   -
26   - public static Date parse(String strDate) throws ParseException {
27   - return getDateFormat().parse(strDate);
28   - }
29   -}
  1 +package com.bsth.data.gpsdata.client.common;
  2 +
  3 +import java.text.DateFormat;
  4 +import java.text.ParseException;
  5 +import java.text.SimpleDateFormat;
  6 +import java.util.Date;
  7 +
  8 +public class ThreadLocalDateUtil {
  9 + private static final String date_format = "yyyyMMddHHmmss";
  10 + private static ThreadLocal<DateFormat> threadLocal = new ThreadLocal<DateFormat>();
  11 +
  12 + public static DateFormat getDateFormat()
  13 + {
  14 + DateFormat df = threadLocal.get();
  15 + if(df==null){
  16 + df = new SimpleDateFormat(date_format);
  17 + threadLocal.set(df);
  18 + }
  19 + return df;
  20 + }
  21 +
  22 + public static String formatDate(Date date) throws ParseException {
  23 + return getDateFormat().format(date);
  24 + }
  25 +
  26 + public static Date parse(String strDate) throws ParseException {
  27 + return getDateFormat().parse(strDate);
  28 + }
  29 +}
... ...
src/main/java/com/bsth/data/gpsdata/client/msg/IMessage.java
1   -package com.bsth.data.gpsdata.client.msg;
2   -
3   -public interface IMessage extends IMessageIO {
4   -
5   - public IMessageBody getMessageBody();
6   -}
  1 +package com.bsth.data.gpsdata.client.msg;
  2 +
  3 +public interface IMessage extends IMessageIO {
  4 +
  5 + public IMessageBody getMessageBody();
  6 +}
... ...
src/main/java/com/bsth/data/gpsdata/client/msg/IMessageBody.java
1   -package com.bsth.data.gpsdata.client.msg;
2   -
3   -public interface IMessageBody extends IMessageIO {
4   -
5   - public String getDeviceId();
6   -
7   - public long getTimestamp();
8   -}
  1 +package com.bsth.data.gpsdata.client.msg;
  2 +
  3 +public interface IMessageBody extends IMessageIO {
  4 +
  5 + public String getDeviceId();
  6 +
  7 + public long getTimestamp();
  8 +}
... ...
src/main/java/com/bsth/data/gpsdata/client/msg/IMessageIO.java
1   -package com.bsth.data.gpsdata.client.msg;
2   -
3   -public interface IMessageIO {
4   -
5   - public void read(byte[] bytes);
6   -
7   - public byte[] write();
8   -}
  1 +package com.bsth.data.gpsdata.client.msg;
  2 +
  3 +public interface IMessageIO {
  4 +
  5 + public void read(byte[] bytes);
  6 +
  7 + public byte[] write();
  8 +}
... ...
src/main/java/com/bsth/data/gpsdata/client/pd/codec/MessageDecoder.java
1   -package com.bsth.data.gpsdata.client.pd.codec;
2   -
3   -import com.bsth.data.gpsdata.client.pd.protocol.PdMessage;
4   -import org.apache.mina.core.buffer.IoBuffer;
5   -import org.apache.mina.core.session.IoSession;
6   -import org.apache.mina.filter.codec.CumulativeProtocolDecoder;
7   -import org.apache.mina.filter.codec.ProtocolDecoderOutput;
8   -
9   -
10   -public class MessageDecoder extends CumulativeProtocolDecoder {
11   -
12   - @Override
13   - protected boolean doDecode(IoSession session, IoBuffer in,
14   - ProtocolDecoderOutput out) throws Exception {
15   - // TODO Auto-generated method stub
16   - while (in.remaining() > 3) {
17   - in.mark();
18   - byte head1 = in.get(), head2 = in.get(), lenh = in.get(), lenl = in.get();
19   - int len = ((lenh & 0xff) << 8) + (lenl & 0xff);
20   - if ((head1 & 0xff) == 0xfa && (head2 & 0xff) == 0xf5) {
21   - if (in.remaining() > len) {
22   - byte[] bytes = new byte[len + 1];
23   - in.get(bytes);
24   - PdMessage msg = new PdMessage();
25   - msg.read(bytes);
26   - out.write(msg);
27   - /*if ("true".equals(ConfigUtil.getProperty("protocolup", "true"))) {
28   - UpProtocolDataService.getInstance().write(new byte[]{ head1, head2, lenh, lenl });
29   - UpProtocolDataService.getInstance().write(bytes);
30   - }*/
31   - } else {
32   - in.reset();
33   - return false;
34   - }
35   - }
36   - }
37   - return false;
38   - }
39   -
40   - /*private static String toHexString(byte[] bytes) {
41   - StringBuilder sb = new StringBuilder();
42   - for (byte b : bytes) {
43   - sb.append(Integer.toHexString(b & 0xff) + "|");
44   - }
45   - return sb.toString();
46   - }*/
47   -}
  1 +package com.bsth.data.gpsdata.client.pd.codec;
  2 +
  3 +import com.bsth.data.gpsdata.client.pd.protocol.PdMessage;
  4 +import org.apache.mina.core.buffer.IoBuffer;
  5 +import org.apache.mina.core.session.IoSession;
  6 +import org.apache.mina.filter.codec.CumulativeProtocolDecoder;
  7 +import org.apache.mina.filter.codec.ProtocolDecoderOutput;
  8 +
  9 +
  10 +public class MessageDecoder extends CumulativeProtocolDecoder {
  11 +
  12 + @Override
  13 + protected boolean doDecode(IoSession session, IoBuffer in,
  14 + ProtocolDecoderOutput out) throws Exception {
  15 + // TODO Auto-generated method stub
  16 + while (in.remaining() > 3) {
  17 + in.mark();
  18 + byte head1 = in.get(), head2 = in.get(), lenh = in.get(), lenl = in.get();
  19 + int len = ((lenh & 0xff) << 8) + (lenl & 0xff);
  20 + if ((head1 & 0xff) == 0xfa && (head2 & 0xff) == 0xf5) {
  21 + if (in.remaining() > len) {
  22 + byte[] bytes = new byte[len + 1];
  23 + in.get(bytes);
  24 + PdMessage msg = new PdMessage();
  25 + msg.read(bytes);
  26 + out.write(msg);
  27 + /*if ("true".equals(ConfigUtil.getProperty("protocolup", "true"))) {
  28 + UpProtocolDataService.getInstance().write(new byte[]{ head1, head2, lenh, lenl });
  29 + UpProtocolDataService.getInstance().write(bytes);
  30 + }*/
  31 + } else {
  32 + in.reset();
  33 + return false;
  34 + }
  35 + }
  36 + }
  37 + return false;
  38 + }
  39 +
  40 + /*private static String toHexString(byte[] bytes) {
  41 + StringBuilder sb = new StringBuilder();
  42 + for (byte b : bytes) {
  43 + sb.append(Integer.toHexString(b & 0xff) + "|");
  44 + }
  45 + return sb.toString();
  46 + }*/
  47 +}
... ...
src/main/java/com/bsth/data/gpsdata/client/pd/codec/MessageEncoder.java
1   -package com.bsth.data.gpsdata.client.pd.codec;
2   -
3   -import org.apache.mina.core.buffer.IoBuffer;
4   -import org.apache.mina.core.session.IoSession;
5   -import org.apache.mina.filter.codec.ProtocolEncoderAdapter;
6   -import org.apache.mina.filter.codec.ProtocolEncoderOutput;
7   -
8   -
9   -public class MessageEncoder extends ProtocolEncoderAdapter {
10   -
11   - @Override
12   - public void encode(IoSession session, Object message,
13   - ProtocolEncoderOutput out) throws Exception {
14   - // TODO Auto-generated method stub
15   - IoBuffer buf = IoBuffer.allocate(1024).setAutoExpand(true);
16   - buf.put((byte[])message);
17   - buf.flip();
18   - out.write(buf);
19   - /*if ("true".equals(ConfigUtil.getProperty("protocoldown", "true"))) {
20   - DownProtocolDataService.getInstance().write((byte[])message);
21   - }*/
22   - }
23   -
24   -}
  1 +package com.bsth.data.gpsdata.client.pd.codec;
  2 +
  3 +import org.apache.mina.core.buffer.IoBuffer;
  4 +import org.apache.mina.core.session.IoSession;
  5 +import org.apache.mina.filter.codec.ProtocolEncoderAdapter;
  6 +import org.apache.mina.filter.codec.ProtocolEncoderOutput;
  7 +
  8 +
  9 +public class MessageEncoder extends ProtocolEncoderAdapter {
  10 +
  11 + @Override
  12 + public void encode(IoSession session, Object message,
  13 + ProtocolEncoderOutput out) throws Exception {
  14 + // TODO Auto-generated method stub
  15 + IoBuffer buf = IoBuffer.allocate(1024).setAutoExpand(true);
  16 + buf.put((byte[])message);
  17 + buf.flip();
  18 + out.write(buf);
  19 + /*if ("true".equals(ConfigUtil.getProperty("protocoldown", "true"))) {
  20 + DownProtocolDataService.getInstance().write((byte[])message);
  21 + }*/
  22 + }
  23 +
  24 +}
... ...
src/main/java/com/bsth/data/gpsdata/client/pd/codec/PdMessageCodecFactory.java
1   -package com.bsth.data.gpsdata.client.pd.codec;
2   -
3   -import org.apache.mina.core.session.IoSession;
4   -import org.apache.mina.filter.codec.ProtocolCodecFactory;
5   -import org.apache.mina.filter.codec.ProtocolDecoder;
6   -import org.apache.mina.filter.codec.ProtocolEncoder;
7   -
8   -public class PdMessageCodecFactory implements ProtocolCodecFactory {
9   -
10   - private ProtocolEncoder encoder;
11   - private ProtocolDecoder decoder;
12   -
13   - public PdMessageCodecFactory() {
14   - encoder = new MessageEncoder();
15   - decoder = new MessageDecoder();
16   - }
17   -
18   - @Override
19   - public ProtocolEncoder getEncoder(IoSession session) throws Exception {
20   - // TODO Auto-generated method stub
21   - return encoder;
22   - }
23   -
24   - @Override
25   - public ProtocolDecoder getDecoder(IoSession session) throws Exception {
26   - // TODO Auto-generated method stub
27   - return decoder;
28   - }
29   -
30   -}
  1 +package com.bsth.data.gpsdata.client.pd.codec;
  2 +
  3 +import org.apache.mina.core.session.IoSession;
  4 +import org.apache.mina.filter.codec.ProtocolCodecFactory;
  5 +import org.apache.mina.filter.codec.ProtocolDecoder;
  6 +import org.apache.mina.filter.codec.ProtocolEncoder;
  7 +
  8 +public class PdMessageCodecFactory implements ProtocolCodecFactory {
  9 +
  10 + private ProtocolEncoder encoder;
  11 + private ProtocolDecoder decoder;
  12 +
  13 + public PdMessageCodecFactory() {
  14 + encoder = new MessageEncoder();
  15 + decoder = new MessageDecoder();
  16 + }
  17 +
  18 + @Override
  19 + public ProtocolEncoder getEncoder(IoSession session) throws Exception {
  20 + // TODO Auto-generated method stub
  21 + return encoder;
  22 + }
  23 +
  24 + @Override
  25 + public ProtocolDecoder getDecoder(IoSession session) throws Exception {
  26 + // TODO Auto-generated method stub
  27 + return decoder;
  28 + }
  29 +
  30 +}
... ...
src/main/java/com/bsth/data/gpsdata/client/pd/common/ConvertUtil.java
1   -package com.bsth.data.gpsdata.client.pd.common;
2   -
3   -import com.bsth.data.gpsdata.client.common.ThreadLocalDateUtil;
4   -import org.slf4j.Logger;
5   -import org.slf4j.LoggerFactory;
6   -
7   -import java.text.ParseException;
8   -import java.util.Arrays;
9   -import java.util.Calendar;
10   -import java.util.Date;
11   -
12   -
13   -public class ConvertUtil {
14   -
15   - private final static Logger log = LoggerFactory.getLogger(ConvertUtil.class);
16   -
17   - public static int bcd2int(byte[] bytes, int start, int len) {
18   - if (len > 4 || len == 0)
19   - throw new IllegalArgumentException("bcd2int 字节数不符合要求");
20   - String temp = "";
21   - for (int i = 0;i < len;i++) {
22   - int val = bytes[start + i] & 0xff;
23   - if (val < 10) temp += 0;
24   - temp += Integer.toHexString(val);
25   - }
26   - return Integer.parseInt(temp);
27   - }
28   -
29   - public static byte[] int2bcd(int val, int len) {
30   - if (len > 4 || len == 0)
31   - throw new IllegalArgumentException("int2bcd 字节数不符合要求");
32   - byte[] result = new byte[len];
33   - for (int i = len - 1;i > -1;i--) {
34   - result[i] = (byte)Integer.parseInt(val%100 + "", 16);
35   - val = val/100;
36   - }
37   - return result;
38   - }
39   -
40   - public static long bcd2long(byte[] bytes, int start, int len) {
41   - if (len > 8 || len == 0)
42   - throw new IllegalArgumentException("bcd2long 字节数不符合要求");
43   - String temp = "";
44   - for (int i = 0;i < len;i++) {
45   - int val = bytes[start + i] & 0xff;
46   - if (val < 10) temp += 0;
47   - temp += Integer.toHexString(val);
48   - }
49   - return Long.parseLong(temp);
50   - }
51   -
52   - public static byte[] long2bcd(long val, int len) {
53   - if (len > 8 || len == 0)
54   - throw new IllegalArgumentException("long2bcd 字节数不符合要求");
55   - byte[] result = new byte[len];
56   - for (int i = len - 1;i > -1;i--) {
57   - result[i] = (byte)Integer.parseInt(val%100 + "", 16);
58   - val = val/100;
59   - }
60   - return result;
61   - }
62   -
63   - public static String ascii2string(byte[] bytes, int start, int len) {
64   - return new String(Arrays.copyOfRange(bytes, start, start + len));
65   - }
66   -
67   - public static byte[] string2ascii(String val, int len) {
68   - byte[] result = new byte[len];
69   - byte[] bytes = val.getBytes();
70   - if (bytes.length > len && len != 0)
71   - throw new IllegalArgumentException("string2ascii 参数不符合要求");
72   - if (len != 0)
73   - for (int i = 0, l = bytes.length;i < l;i++) result[i] = bytes[i];
74   - else return bytes;
75   - return result;
76   - }
77   -
78   - public static long bcd2timestamp(byte[] bytes, int start) {
79   - String temp = "20";
80   - for (int i = 0;i < 6;i++) {
81   - int val = bytes[start + i] & 0xff;
82   - if (val < 10) temp += 0;
83   - temp += Integer.toHexString(val);
84   - }
85   - Date date = null;
86   - try {
87   - date = ThreadLocalDateUtil.parse(temp);
88   - } catch (ParseException e) {
89   - log.error("协议中时间数据异常:" + temp);
90   - }
91   - if (date != null) return date.getTime();
92   - return -1;
93   - }
94   -
95   - public static byte[] timestamp2bcd(long val) {
96   - byte[] result = new byte[6];
97   - Calendar c = Calendar.getInstance();
98   - c.setTime(new Date(val));
99   - result[0] = (byte)(Integer.parseInt(c.get(Calendar.YEAR)%100 + "", 16));
100   - result[1] = (byte)(Integer.parseInt(c.get(Calendar.MONTH) + 1 + "", 16));
101   - result[2] = (byte)Integer.parseInt(c.get(Calendar.DAY_OF_MONTH) + "", 16);
102   - result[3] = (byte)Integer.parseInt(c.get(Calendar.HOUR_OF_DAY) + "", 16);
103   - result[4] = (byte)Integer.parseInt(c.get(Calendar.MINUTE) + "", 16);
104   - result[5] = (byte)Integer.parseInt(c.get(Calendar.SECOND) + "", 16);
105   - return result;
106   - }
107   -
108   - public static byte[] int2hex(int val, int len) {
109   - if (len < 1)
110   - throw new IllegalArgumentException("int2hex len 参数不符合要求");
111   - byte[] result = new byte[len];
112   - for (int i = 0;i < len;i++) {
113   - result[len - 1 - i] = (byte)(val%100);
114   - val = val/100;
115   - }
116   -
117   - return result;
118   - }
119   -
120   - public static int bytes2int(byte[] bytes, int start, int len) {
121   - int val = 0;
122   - for (int i = 0; i < len; i++) {
123   - int shift = (len - 1 - i) * 8;
124   - val += (bytes[start + i] & 0x0000FF) << shift;
125   - }
126   -
127   - return val;
128   - }
129   -}
  1 +package com.bsth.data.gpsdata.client.pd.common;
  2 +
  3 +import com.bsth.data.gpsdata.client.common.ThreadLocalDateUtil;
  4 +import org.slf4j.Logger;
  5 +import org.slf4j.LoggerFactory;
  6 +
  7 +import java.text.ParseException;
  8 +import java.util.Arrays;
  9 +import java.util.Calendar;
  10 +import java.util.Date;
  11 +
  12 +
  13 +public class ConvertUtil {
  14 +
  15 + private final static Logger log = LoggerFactory.getLogger(ConvertUtil.class);
  16 +
  17 + public static int bcd2int(byte[] bytes, int start, int len) {
  18 + if (len > 4 || len == 0)
  19 + throw new IllegalArgumentException("bcd2int 字节数不符合要求");
  20 + String temp = "";
  21 + for (int i = 0;i < len;i++) {
  22 + int val = bytes[start + i] & 0xff;
  23 + if (val < 10) temp += 0;
  24 + temp += Integer.toHexString(val);
  25 + }
  26 + return Integer.parseInt(temp);
  27 + }
  28 +
  29 + public static byte[] int2bcd(int val, int len) {
  30 + if (len > 4 || len == 0)
  31 + throw new IllegalArgumentException("int2bcd 字节数不符合要求");
  32 + byte[] result = new byte[len];
  33 + for (int i = len - 1;i > -1;i--) {
  34 + result[i] = (byte)Integer.parseInt(val%100 + "", 16);
  35 + val = val/100;
  36 + }
  37 + return result;
  38 + }
  39 +
  40 + public static long bcd2long(byte[] bytes, int start, int len) {
  41 + if (len > 8 || len == 0)
  42 + throw new IllegalArgumentException("bcd2long 字节数不符合要求");
  43 + String temp = "";
  44 + for (int i = 0;i < len;i++) {
  45 + int val = bytes[start + i] & 0xff;
  46 + if (val < 10) temp += 0;
  47 + temp += Integer.toHexString(val);
  48 + }
  49 + return Long.parseLong(temp);
  50 + }
  51 +
  52 + public static byte[] long2bcd(long val, int len) {
  53 + if (len > 8 || len == 0)
  54 + throw new IllegalArgumentException("long2bcd 字节数不符合要求");
  55 + byte[] result = new byte[len];
  56 + for (int i = len - 1;i > -1;i--) {
  57 + result[i] = (byte)Integer.parseInt(val%100 + "", 16);
  58 + val = val/100;
  59 + }
  60 + return result;
  61 + }
  62 +
  63 + public static String ascii2string(byte[] bytes, int start, int len) {
  64 + return new String(Arrays.copyOfRange(bytes, start, start + len));
  65 + }
  66 +
  67 + public static byte[] string2ascii(String val, int len) {
  68 + byte[] result = new byte[len];
  69 + byte[] bytes = val.getBytes();
  70 + if (bytes.length > len && len != 0)
  71 + throw new IllegalArgumentException("string2ascii 参数不符合要求");
  72 + if (len != 0)
  73 + for (int i = 0, l = bytes.length;i < l;i++) result[i] = bytes[i];
  74 + else return bytes;
  75 + return result;
  76 + }
  77 +
  78 + public static long bcd2timestamp(byte[] bytes, int start) {
  79 + String temp = "20";
  80 + for (int i = 0;i < 6;i++) {
  81 + int val = bytes[start + i] & 0xff;
  82 + if (val < 10) temp += 0;
  83 + temp += Integer.toHexString(val);
  84 + }
  85 + Date date = null;
  86 + try {
  87 + date = ThreadLocalDateUtil.parse(temp);
  88 + } catch (ParseException e) {
  89 + log.error("协议中时间数据异常:" + temp);
  90 + }
  91 + if (date != null) return date.getTime();
  92 + return -1;
  93 + }
  94 +
  95 + public static byte[] timestamp2bcd(long val) {
  96 + byte[] result = new byte[6];
  97 + Calendar c = Calendar.getInstance();
  98 + c.setTime(new Date(val));
  99 + result[0] = (byte)(Integer.parseInt(c.get(Calendar.YEAR)%100 + "", 16));
  100 + result[1] = (byte)(Integer.parseInt(c.get(Calendar.MONTH) + 1 + "", 16));
  101 + result[2] = (byte)Integer.parseInt(c.get(Calendar.DAY_OF_MONTH) + "", 16);
  102 + result[3] = (byte)Integer.parseInt(c.get(Calendar.HOUR_OF_DAY) + "", 16);
  103 + result[4] = (byte)Integer.parseInt(c.get(Calendar.MINUTE) + "", 16);
  104 + result[5] = (byte)Integer.parseInt(c.get(Calendar.SECOND) + "", 16);
  105 + return result;
  106 + }
  107 +
  108 + public static byte[] int2hex(int val, int len) {
  109 + if (len < 1)
  110 + throw new IllegalArgumentException("int2hex len 参数不符合要求");
  111 + byte[] result = new byte[len];
  112 + for (int i = 0;i < len;i++) {
  113 + result[len - 1 - i] = (byte)(val%100);
  114 + val = val/100;
  115 + }
  116 +
  117 + return result;
  118 + }
  119 +
  120 + public static int bytes2int(byte[] bytes, int start, int len) {
  121 + int val = 0;
  122 + for (int i = 0; i < len; i++) {
  123 + int shift = (len - 1 - i) * 8;
  124 + val += (bytes[start + i] & 0x0000FF) << shift;
  125 + }
  126 +
  127 + return val;
  128 + }
  129 +}
... ...
src/main/java/com/bsth/data/gpsdata/client/pd/handler/PdClientHandler.java
1   -package com.bsth.data.gpsdata.client.pd.handler;
2   -
3   -import com.bsth.data.gpsdata.client.ClientApp;
4   -import com.bsth.data.gpsdata.client.GpsBeforeBuffer;
5   -import com.bsth.data.gpsdata.client.msg.IMessageBody;
6   -import com.bsth.data.gpsdata.client.pd.protocol.PdMessage;
7   -import com.bsth.data.gpsdata.client.pd.protocol.Pd_41_0;
8   -import com.bsth.data.gpsdata.client.pd.protocol.Pd_42_0;
9   -import org.apache.mina.core.service.IoHandlerAdapter;
10   -import org.apache.mina.core.session.IdleStatus;
11   -import org.apache.mina.core.session.IoSession;
12   -import org.apache.mina.transport.socket.SocketSessionConfig;
13   -import org.slf4j.Logger;
14   -import org.slf4j.LoggerFactory;
15   -import org.springframework.beans.factory.annotation.Autowired;
16   -import org.springframework.stereotype.Service;
17   -
18   -import java.io.IOException;
19   -
20   -
21   -@Service
22   -public class PdClientHandler extends IoHandlerAdapter{
23   -
24   - private final static Logger log = LoggerFactory.getLogger(PdClientHandler.class);
25   -
26   - @Autowired
27   - GpsBeforeBuffer gpsBeforeBuffer;
28   -
29   - @Override
30   - public void sessionCreated(IoSession session) throws Exception {
31   - SocketSessionConfig cfg = (SocketSessionConfig) session.getConfig();
32   - cfg.setSoLinger(0);
33   - }
34   -
35   - @Override
36   - public void sessionOpened(IoSession session) throws Exception {
37   -
38   - }
39   -
40   - @Override
41   - public void sessionClosed(IoSession session) throws Exception {
42   - String deviceId = (String)session.getAttribute("deviceId");
43   - if (deviceId != null) {
44   - //SessionManager.getInstance().unregister(deviceId);
45   - log.info("连网关设备编号:" + deviceId + "断开连接");
46   - log.warn(deviceId + "网关设备注销");
47   -
48   - ClientApp.dconnect(deviceId);
49   - } else {
50   - log.info("连网关设备编号:" + deviceId + "断开连接");
51   - }
52   - }
53   -
54   - @Override
55   - public void sessionIdle(IoSession session, IdleStatus status) throws Exception {
56   - session.closeNow();
57   - }
58   -
59   - @Override
60   - public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
61   - if (cause instanceof IOException) session.closeNow();
62   - log.error("PdClientHandler异常:", cause);
63   - }
64   -
65   - @Override
66   - public void messageReceived(IoSession session, Object message) throws Exception {
67   - PdMessage msg = (PdMessage)message;
68   - IMessageBody body = msg.getMessageBody();
69   - if (body != null) {
70   - //String deviceId = body.getDeviceId();
71   - if (0x31 == msg.getCommandType()) {
72   - //IoSession regSession = SessionManager.getInstance().getSession(deviceId);
73   - //if (regSession != null) regSession.closeNow();
74   - //SessionManager.getInstance().register(deviceId, session);
75   - log.debug("设备编号:" + body.getDeviceId() + "建立连接");
76   - }
77   - else if(0x41 == msg.getCommandType()){
78   - Pd_41_0 pd41 = (Pd_41_0)msg.getMessageBody();
79   - gpsBeforeBuffer.put(pd41.getInfo());
80   - }
81   - else if(0x42 == msg.getCommandType()){
82   - Pd_42_0 pd42 = (Pd_42_0)msg.getMessageBody();
83   - gpsBeforeBuffer.put(pd42.getInfo());
84   - }
85   - }
86   - }
87   -
88   - @Override
89   - public void messageSent(IoSession session, Object message) throws Exception {
90   -
91   - }
92   -}
  1 +package com.bsth.data.gpsdata.client.pd.handler;
  2 +
  3 +import com.bsth.data.gpsdata.client.ClientApp;
  4 +import com.bsth.data.gpsdata.client.GpsBeforeBuffer;
  5 +import com.bsth.data.gpsdata.client.msg.IMessageBody;
  6 +import com.bsth.data.gpsdata.client.pd.protocol.PdMessage;
  7 +import com.bsth.data.gpsdata.client.pd.protocol.Pd_41_0;
  8 +import com.bsth.data.gpsdata.client.pd.protocol.Pd_42_0;
  9 +import org.apache.mina.core.service.IoHandlerAdapter;
  10 +import org.apache.mina.core.session.IdleStatus;
  11 +import org.apache.mina.core.session.IoSession;
  12 +import org.apache.mina.transport.socket.SocketSessionConfig;
  13 +import org.slf4j.Logger;
  14 +import org.slf4j.LoggerFactory;
  15 +import org.springframework.beans.factory.annotation.Autowired;
  16 +import org.springframework.stereotype.Service;
  17 +
  18 +import java.io.IOException;
  19 +
  20 +
  21 +@Service
  22 +public class PdClientHandler extends IoHandlerAdapter{
  23 +
  24 + private final static Logger log = LoggerFactory.getLogger(PdClientHandler.class);
  25 +
  26 + @Autowired
  27 + GpsBeforeBuffer gpsBeforeBuffer;
  28 +
  29 + @Override
  30 + public void sessionCreated(IoSession session) throws Exception {
  31 + SocketSessionConfig cfg = (SocketSessionConfig) session.getConfig();
  32 + cfg.setSoLinger(0);
  33 + }
  34 +
  35 + @Override
  36 + public void sessionOpened(IoSession session) throws Exception {
  37 +
  38 + }
  39 +
  40 + @Override
  41 + public void sessionClosed(IoSession session) throws Exception {
  42 + String deviceId = (String)session.getAttribute("deviceId");
  43 + if (deviceId != null) {
  44 + //SessionManager.getInstance().unregister(deviceId);
  45 + log.info("连网关设备编号:" + deviceId + "断开连接");
  46 + log.warn(deviceId + "网关设备注销");
  47 +
  48 + ClientApp.dconnect(deviceId);
  49 + } else {
  50 + log.info("连网关设备编号:" + deviceId + "断开连接");
  51 + }
  52 + }
  53 +
  54 + @Override
  55 + public void sessionIdle(IoSession session, IdleStatus status) throws Exception {
  56 + session.closeNow();
  57 + }
  58 +
  59 + @Override
  60 + public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
  61 + if (cause instanceof IOException) session.closeNow();
  62 + log.error("PdClientHandler异常:", cause);
  63 + }
  64 +
  65 + @Override
  66 + public void messageReceived(IoSession session, Object message) throws Exception {
  67 + PdMessage msg = (PdMessage)message;
  68 + IMessageBody body = msg.getMessageBody();
  69 + if (body != null) {
  70 + //String deviceId = body.getDeviceId();
  71 + if (0x31 == msg.getCommandType()) {
  72 + //IoSession regSession = SessionManager.getInstance().getSession(deviceId);
  73 + //if (regSession != null) regSession.closeNow();
  74 + //SessionManager.getInstance().register(deviceId, session);
  75 + log.debug("设备编号:" + body.getDeviceId() + "建立连接");
  76 + }
  77 + else if(0x41 == msg.getCommandType()){
  78 + Pd_41_0 pd41 = (Pd_41_0)msg.getMessageBody();
  79 + gpsBeforeBuffer.put(pd41.getInfo());
  80 + }
  81 + else if(0x42 == msg.getCommandType()){
  82 + Pd_42_0 pd42 = (Pd_42_0)msg.getMessageBody();
  83 + gpsBeforeBuffer.put(pd42.getInfo());
  84 + }
  85 + }
  86 + }
  87 +
  88 + @Override
  89 + public void messageSent(IoSession session, Object message) throws Exception {
  90 +
  91 + }
  92 +}
... ...
src/main/java/com/bsth/data/gpsdata/client/pd/protocol/BasicInfo.java
1   -package com.bsth.data.gpsdata.client.pd.protocol;
2   -
3   -
4   -import com.bsth.data.gpsdata.client.pd.common.ConvertUtil;
5   -
6   -import java.nio.ByteBuffer;
7   -import java.util.Date;
8   -
9   -
10   -public class BasicInfo {
11   -
12   - private int cityCode;
13   - private short industryCode;
14   - private short companyCode;
15   - private String deviceId;
16   - private int lineId;
17   - private int driverEmpNo;
18   - private short carparkSerialNo;
19   - private String carparkNo;
20   - private short stopSerialNo;
21   - private String stopNo;
22   - // 经度 bcd 5 0121245333表示经度为121度24.5333分
23   - private long carLon;
24   - // 维度
25   - private int carLat;
26   - private long timestamp;
27   - // 速度(传感器)bcd 2 保留一位小数 km/h
28   - private short speedSensor;
29   - // 速度(gps)bcd 2 保留一位小数 km/h
30   - private short speedGps;
31   - // 方向 bcd 2 0-359.5 保留一位小数
32   - private short direction;
33   - // 车内温度 bcd 2 第一字节为符号 00为正 01为负 后一字节为温度
34   - private short inTemp;
35   - // 营运状态 hex 4高位在前
36   - // 第一字节位 7 GPS有/无效|6 场外/内|5 起终点站外/内|4 上/下行|3 已知/未知|2站外/站内|1 营运/非营运|0 在线路上/不在
37   - // 7=1时其它位无效|0=1时3,4,5无效 第二字节6,7无效|3=1时2,4无效 第二字节6,7无效
38   - // 第二字节位 7 非/标杆点|6 非/中途校时点|5 点/熄火|4 实时/缓存数据|3 门开/关|2 预留|1 非/包车|0预留
39   - // 1=1时 第一字节0-6无效 6,7无效
40   - // 后两个字节保留
41   - private long serviceState;
42   - // 调控状态
43   - private long controlState;
44   - // 累计里程 km 保留两位小数
45   - private int totalMiles;
46   - // 水温
47   - private byte waterTemp;
48   - // 油耗 (第一个字节 + 第二个字节/10)升/百公里
49   - private int oilConsumption;
50   - // 发动机转速 100转/秒
51   - private int engineSpeed;
52   - private float lon;
53   - private float lat;
54   -
55   - private boolean inOutStopFlag = false;
56   -
57   - public void read(byte[] bytes, int idx) {
58   - // TODO Auto-generated method stub
59   - ByteBuffer buf = ByteBuffer.wrap(bytes);
60   - cityCode = ConvertUtil.bcd2int(bytes, idx, 3); idx += 3;
61   - industryCode = (short)(bytes[idx] & 0xff); idx++;
62   - companyCode = (short)(bytes[idx] & 0xff); idx++;
63   - deviceId = ConvertUtil.ascii2string(bytes, idx, 8); idx += 8;
64   - lineId = ConvertUtil.bcd2int(bytes, idx, 3); idx += 3;
65   - driverEmpNo = ConvertUtil.bcd2int(bytes, idx, 4); idx +=4;
66   - carparkSerialNo = (short)(bytes[idx] & 0xff); idx++;
67   - carparkNo = ConvertUtil.ascii2string(bytes, idx, 8); idx += 8;
68   - stopSerialNo = (short)(bytes[idx] & 0xff); idx++;
69   - stopNo = ConvertUtil.ascii2string(bytes, idx, 8).trim(); idx += 8;
70   - carLon = ConvertUtil.bcd2long(bytes, idx, 5); lon = (int)(carLon/1000000) + carLon%1000000/600000f; idx += 5;
71   - carLat = ConvertUtil.bcd2int(bytes, idx, 4); lat = carLat/1000000 + carLat%1000000/600000f; idx += 4;
72   - timestamp = ConvertUtil.bcd2timestamp(bytes, idx); idx += 6;
73   - speedSensor = (short)ConvertUtil.bcd2int(bytes, idx, 2); idx += 2;
74   - speedGps = (short)ConvertUtil.bcd2int(bytes, idx, 2); idx += 2;
75   - direction = (short)(ConvertUtil.bcd2int(bytes, idx, 2)); idx += 2;
76   - inTemp = (short)ConvertUtil.bcd2int(bytes, idx, 2); idx += 2;
77   - serviceState = buf.getInt(idx) & 0xffffffff; idx += 4;
78   - controlState = buf.getInt(idx) & 0xffffffff; idx += 4;
79   - totalMiles = ConvertUtil.bcd2int(bytes, idx, 4); idx += 4;
80   - waterTemp = bytes[idx]; idx++;
81   - oilConsumption = ConvertUtil.bcd2int(bytes, idx, 4); idx += 4;
82   - engineSpeed = buf.getShort(idx) & 0xffff; idx += 2;
83   - }
84   -
85   - public byte[] write() {
86   - ByteBuffer buf = ByteBuffer.allocate(80);
87   - buf.put(ConvertUtil.int2bcd(cityCode, 3));
88   - buf.put((byte)industryCode);
89   - buf.put((byte)companyCode);
90   - buf.put(ConvertUtil.string2ascii(deviceId, 8));
91   - buf.put(ConvertUtil.int2bcd(lineId, 3));
92   - buf.put(ConvertUtil.int2bcd(driverEmpNo, 4));
93   - buf.put((byte)carparkSerialNo);
94   - buf.put(ConvertUtil.string2ascii(carparkNo, 8));
95   - buf.put((byte)stopSerialNo);
96   - buf.put(ConvertUtil.string2ascii(stopNo, 8));
97   - buf.put(ConvertUtil.long2bcd(carLon, 5));
98   - buf.put(ConvertUtil.long2bcd(carLat, 4));
99   - buf.put(ConvertUtil.timestamp2bcd(timestamp));
100   - buf.put(ConvertUtil.int2bcd(speedSensor, 2));
101   - buf.put(ConvertUtil.int2bcd(speedGps, 2));
102   - buf.put(ConvertUtil.int2bcd(direction, 2));
103   - buf.put(ConvertUtil.int2bcd(inTemp, 2));
104   - buf.putInt((int)serviceState);
105   - buf.putInt((int)controlState);
106   - buf.put(ConvertUtil.int2bcd(totalMiles, 4));
107   - buf.put(waterTemp);
108   - buf.put(ConvertUtil.int2bcd(oilConsumption, 2));
109   - buf.putShort((short)engineSpeed);
110   -
111   - return buf.array();
112   - }
113   -
114   - public String getDeviceId() {
115   - // TODO Auto-generated method stub
116   - return deviceId;
117   - }
118   -
119   - public int getCityCode() {
120   - return cityCode;
121   - }
122   -
123   - public short getIndustryCode() {
124   - return industryCode;
125   - }
126   -
127   - public short getCompanyCode() {
128   - return companyCode;
129   - }
130   -
131   - public int getLineId() {
132   - return lineId;
133   - }
134   -
135   - public int getDriverEmpNo() {
136   - return driverEmpNo;
137   - }
138   -
139   - public short getCarparkSerialNo() {
140   - return carparkSerialNo;
141   - }
142   -
143   - public String getCarparkNo() {
144   - return carparkNo;
145   - }
146   -
147   - public short getStopSerialNo() {
148   - return stopSerialNo;
149   - }
150   -
151   - public String getStopNo() {
152   - return stopNo;
153   - }
154   -
155   - public long getCarLon() {
156   - return carLon;
157   - }
158   -
159   - public int getCarLat() {
160   - return carLat;
161   - }
162   -
163   - public long getTimestamp() {
164   - return timestamp;
165   - }
166   -
167   - public short getSpeedSensor() {
168   - return speedSensor;
169   - }
170   -
171   - public short getSpeedGps() {
172   - return speedGps;
173   - }
174   -
175   - public short getDirection() {
176   - return direction;
177   - }
178   -
179   - public short getInTemp() {
180   - return inTemp;
181   - }
182   -
183   - public long getServiceState() {
184   - return serviceState;
185   - }
186   -
187   - public long getControlState() {
188   - return controlState;
189   - }
190   -
191   - public int getTotalMiles() {
192   - return totalMiles;
193   - }
194   -
195   - public byte getWaterTemp() {
196   - return waterTemp;
197   - }
198   -
199   - public int getOilConsumption() {
200   - return oilConsumption;
201   - }
202   -
203   - public int getEngineSpeed() {
204   - return engineSpeed;
205   - }
206   -
207   - public float getLon() {
208   - return lon;
209   - }
210   -
211   - public void setLon(float lon) {
212   - this.lon = lon;
213   - }
214   -
215   - public float getLat() {
216   - return lat;
217   - }
218   -
219   - public void setLat(float lat) {
220   - this.lat = lat;
221   - }
222   -
223   - public void setStopNo(String stopNo) {
224   - this.stopNo = stopNo;
225   - }
226   -
227   - public byte getGpsValid() {
228   - return (byte)(((serviceState & 0x80000000) == 0x80000000) ? 1 : 0);
229   - }
230   -
231   - /**
232   - * 获取车辆在场外/内
233   - * @return -1无效 0场外1场内
234   - */
235   - public byte getInOrOutCarpark() {
236   - if ((serviceState & 0x00020000) == 0x00020000 || (serviceState & 0x80000000) == 0x80000000
237   - || (serviceState & 0x01000000) == 0x01000000) return -1;
238   - return (byte)(((serviceState & 0x40000000) == 0x40000000) ? 1 : 0);
239   - }
240   -
241   - public void setInOrOutCarpark(boolean inOutFlag) {
242   - if (inOutFlag) serviceState |= 0x40000000;
243   - else serviceState &= 0xbfffffff;
244   - }
245   -
246   - /**
247   - * 获取车辆在起终点站外/内
248   - * @return -1无效 0起终点站外1起终点站内
249   - */
250   - public byte getInOrOutStartEnd() {
251   - if ((serviceState & 0x00020000) == 0x00020000 || (serviceState & 0x80000000) == 0x80000000
252   - || (serviceState & 0x01000000) == 0x01000000) return -1;
253   - return (byte)(((serviceState & 0x20000000) == 0x20000000) ? 1 : 0);
254   - }
255   -
256   - /**
257   - * 获取车辆线路上下行
258   - * @return -1无效 0上行 1下行
259   - */
260   - public byte getUpOrDown() {
261   - if ((serviceState & 0x00020000) == 0x00020000 || (serviceState & 0x80000000) == 0x80000000
262   - || (serviceState & 0x01000000) == 0x01000000
263   - || (serviceState & 0x08000000) == 0x08000000) return -1;
264   - return (byte)(((serviceState & 0x10000000) == 0x10000000) ? 1 : 0);
265   - }
266   -
267   - public void setUpOrDown(boolean upOrDown) {
268   - if (!upOrDown) serviceState |= 0x10000000;
269   - else serviceState &= 0xefffffff;
270   - }
271   -
272   - /**
273   - * 获取车辆在站外/内
274   - * @return -1无效 0站外 1站内
275   - */
276   - public byte getInOrOutStop() {
277   - if ((serviceState & 0x00020000) == 0x00020000 || (serviceState & 0x80000000) == 0x80000000
278   - || (serviceState & 0x01000000) == 0x01000000
279   - || (serviceState & 0x08000000) == 0x08000000) return -1;
280   - return (byte)(((serviceState & 0x04000000) == 0x04000000) ? 1 : 0);
281   - }
282   -
283   - public void setInOrOutStop(boolean isInOrOutStop) {
284   - inOutStopFlag = true;
285   - if (isInOrOutStop) serviceState |= 0x04000000;
286   - else serviceState &= 0xfbffffff;
287   - }
288   -
289   - /**
290   - * 获取运营状态
291   - * @return -1无效 0运营 1未运营
292   - */
293   - public byte getService() {
294   - if ((serviceState & 0x00020000) == 0x00020000 || (serviceState & 0x80000000) == 0x80000000) return -1;
295   - return (byte)(((serviceState & 0x02000000) == 0x02000000) ? 1 : 0);
296   - }
297   -
298   - public void setService(boolean service) {
299   - if (!service) serviceState |= 0x02000000;
300   - else serviceState &= 0xfdffffff;
301   - }
302   -
303   - /**
304   - * 获得车辆状态
305   - * @return 0点火 1熄火
306   - */
307   - public byte getVehicleState() {
308   - return (byte)(((serviceState & 0x00200000) == 0x00200000) ? 1 : 0);
309   - }
310   -
311   - public void setInOutStopFlag(boolean inOutStopFlag) {
312   - this.inOutStopFlag = inOutStopFlag;
313   - }
314   -
315   - public boolean getInOutStopFlag() {
316   - return inOutStopFlag;
317   - }
318   -
319   - public String toString() {
320   - Date d = new Date();d.setTime(timestamp);
321   - StringBuilder sb = new StringBuilder();
322   - sb.append("城市代码:").append(cityCode)
323   - .append("行业代码:").append(industryCode)
324   - .append("公司代码:").append(companyCode)
325   - .append("设备号:").append(deviceId)
326   - .append("线路编号:").append(lineId)
327   - .append("驾驶员工号:").append(driverEmpNo)
328   - .append("停车场序列号:").append(carparkSerialNo)
329   - .append("停车场编号:").append(carparkNo)
330   - .append("站点序列号").append(stopSerialNo)
331   - .append("站点编号:").append(stopNo)
332   - .append("经度:").append(carLon)
333   - .append("维度:").append(carLat)
334   - .append("时间戳:").append(d)
335   - .append("速度(传感器):").append(speedSensor)
336   - .append("速度(gps)").append(speedGps)
337   - .append("方向:").append(direction)
338   - .append("车内温度:").append(inTemp)
339   - .append("营运状态:").append(serviceState)
340   - .append("调控状态:").append(controlState)
341   - .append("总里程:").append(totalMiles)
342   - .append("水温:").append(waterTemp)
343   - .append("油耗:").append(oilConsumption)
344   - .append("发动机速度:").append(engineSpeed);
345   -
346   - return sb.toString();
347   - }
348   - /* ----------------------------------------------------- */
349   -
350   - public void setCityCode(int cityCode) {
351   - this.cityCode = cityCode;
352   - }
353   -
354   - public void setIndustryCode(short industryCode) {
355   - this.industryCode = industryCode;
356   - }
357   -
358   - public void setCompanyCode(short companyCode) {
359   - this.companyCode = companyCode;
360   - }
361   -
362   - public void setDeviceId(String deviceId) {
363   - this.deviceId = deviceId;
364   - }
365   -
366   - public void setLineId(int lineId) {
367   - this.lineId = lineId;
368   - }
369   -
370   - public void setDriverEmpNo(int driverEmpNo) {
371   - this.driverEmpNo = driverEmpNo;
372   - }
373   -
374   - public void setCarparkSerialNo(short carparkSerialNo) {
375   - this.carparkSerialNo = carparkSerialNo;
376   - }
377   -
378   - public void setCarparkNo(String carparkNo) {
379   - this.carparkNo = carparkNo;
380   - }
381   -
382   - public void setStopSerialNo(short stopSerialNo) {
383   - this.stopSerialNo = stopSerialNo;
384   - }
385   -
386   - public void setCarLon(long carLon) {
387   - this.carLon = carLon;
388   - }
389   -
390   - public void setCarLat(int carLat) {
391   - this.carLat = carLat;
392   - }
393   -
394   - public void setTimestamp(long timestamp) {
395   - this.timestamp = timestamp;
396   - }
397   -
398   - public void setSpeedSensor(short speedSensor) {
399   - this.speedSensor = speedSensor;
400   - }
401   -
402   - public void setSpeedGps(short speedGps) {
403   - this.speedGps = speedGps;
404   - }
405   -
406   - public void setDirection(short direction) {
407   - this.direction = direction;
408   - }
409   -
410   - public void setInTemp(short inTemp) {
411   - this.inTemp = inTemp;
412   - }
413   -
414   - public void setServiceState(long serviceState) {
415   - this.serviceState = serviceState;
416   - }
417   -
418   - public void setControlState(long controlState) {
419   - this.controlState = controlState;
420   - }
421   -
422   - public void setTotalMiles(int totalMiles) {
423   - this.totalMiles = totalMiles;
424   - }
425   -
426   - public void setWaterTemp(byte waterTemp) {
427   - this.waterTemp = waterTemp;
428   - }
429   -
430   - public void setOilConsumption(int oilConsumption) {
431   - this.oilConsumption = oilConsumption;
432   - }
433   -
434   - public void setEngineSpeed(int engineSpeed) {
435   - this.engineSpeed = engineSpeed;
436   - }
437   -}
  1 +package com.bsth.data.gpsdata.client.pd.protocol;
  2 +
  3 +
  4 +import com.bsth.data.gpsdata.client.pd.common.ConvertUtil;
  5 +
  6 +import java.nio.ByteBuffer;
  7 +import java.util.Date;
  8 +
  9 +
  10 +public class BasicInfo {
  11 +
  12 + private int cityCode;
  13 + private short industryCode;
  14 + private short companyCode;
  15 + private String deviceId;
  16 + private int lineId;
  17 + private int driverEmpNo;
  18 + private short carparkSerialNo;
  19 + private String carparkNo;
  20 + private short stopSerialNo;
  21 + private String stopNo;
  22 + // 经度 bcd 5 0121245333表示经度为121度24.5333分
  23 + private long carLon;
  24 + // 维度
  25 + private int carLat;
  26 + private long timestamp;
  27 + // 速度(传感器)bcd 2 保留一位小数 km/h
  28 + private short speedSensor;
  29 + // 速度(gps)bcd 2 保留一位小数 km/h
  30 + private short speedGps;
  31 + // 方向 bcd 2 0-359.5 保留一位小数
  32 + private short direction;
  33 + // 车内温度 bcd 2 第一字节为符号 00为正 01为负 后一字节为温度
  34 + private short inTemp;
  35 + // 营运状态 hex 4高位在前
  36 + // 第一字节位 7 GPS有/无效|6 场外/内|5 起终点站外/内|4 上/下行|3 已知/未知|2站外/站内|1 营运/非营运|0 在线路上/不在
  37 + // 7=1时其它位无效|0=1时3,4,5无效 第二字节6,7无效|3=1时2,4无效 第二字节6,7无效
  38 + // 第二字节位 7 非/标杆点|6 非/中途校时点|5 点/熄火|4 实时/缓存数据|3 门开/关|2 预留|1 非/包车|0预留
  39 + // 1=1时 第一字节0-6无效 6,7无效
  40 + // 后两个字节保留
  41 + private long serviceState;
  42 + // 调控状态
  43 + private long controlState;
  44 + // 累计里程 km 保留两位小数
  45 + private int totalMiles;
  46 + // 水温
  47 + private byte waterTemp;
  48 + // 油耗 (第一个字节 + 第二个字节/10)升/百公里
  49 + private int oilConsumption;
  50 + // 发动机转速 100转/秒
  51 + private int engineSpeed;
  52 + private float lon;
  53 + private float lat;
  54 +
  55 + private boolean inOutStopFlag = false;
  56 +
  57 + public void read(byte[] bytes, int idx) {
  58 + // TODO Auto-generated method stub
  59 + ByteBuffer buf = ByteBuffer.wrap(bytes);
  60 + cityCode = ConvertUtil.bcd2int(bytes, idx, 3); idx += 3;
  61 + industryCode = (short)(bytes[idx] & 0xff); idx++;
  62 + companyCode = (short)(bytes[idx] & 0xff); idx++;
  63 + deviceId = ConvertUtil.ascii2string(bytes, idx, 8); idx += 8;
  64 + lineId = ConvertUtil.bcd2int(bytes, idx, 3); idx += 3;
  65 + driverEmpNo = ConvertUtil.bcd2int(bytes, idx, 4); idx +=4;
  66 + carparkSerialNo = (short)(bytes[idx] & 0xff); idx++;
  67 + carparkNo = ConvertUtil.ascii2string(bytes, idx, 8); idx += 8;
  68 + stopSerialNo = (short)(bytes[idx] & 0xff); idx++;
  69 + stopNo = ConvertUtil.ascii2string(bytes, idx, 8).trim(); idx += 8;
  70 + carLon = ConvertUtil.bcd2long(bytes, idx, 5); lon = (int)(carLon/1000000) + carLon%1000000/600000f; idx += 5;
  71 + carLat = ConvertUtil.bcd2int(bytes, idx, 4); lat = carLat/1000000 + carLat%1000000/600000f; idx += 4;
  72 + timestamp = ConvertUtil.bcd2timestamp(bytes, idx); idx += 6;
  73 + speedSensor = (short)ConvertUtil.bcd2int(bytes, idx, 2); idx += 2;
  74 + speedGps = (short)ConvertUtil.bcd2int(bytes, idx, 2); idx += 2;
  75 + direction = (short)(ConvertUtil.bcd2int(bytes, idx, 2)); idx += 2;
  76 + inTemp = (short)ConvertUtil.bcd2int(bytes, idx, 2); idx += 2;
  77 + serviceState = buf.getInt(idx) & 0xffffffff; idx += 4;
  78 + controlState = buf.getInt(idx) & 0xffffffff; idx += 4;
  79 + totalMiles = ConvertUtil.bcd2int(bytes, idx, 4); idx += 4;
  80 + waterTemp = bytes[idx]; idx++;
  81 + oilConsumption = ConvertUtil.bcd2int(bytes, idx, 4); idx += 4;
  82 + engineSpeed = buf.getShort(idx) & 0xffff; idx += 2;
  83 + }
  84 +
  85 + public byte[] write() {
  86 + ByteBuffer buf = ByteBuffer.allocate(80);
  87 + buf.put(ConvertUtil.int2bcd(cityCode, 3));
  88 + buf.put((byte)industryCode);
  89 + buf.put((byte)companyCode);
  90 + buf.put(ConvertUtil.string2ascii(deviceId, 8));
  91 + buf.put(ConvertUtil.int2bcd(lineId, 3));
  92 + buf.put(ConvertUtil.int2bcd(driverEmpNo, 4));
  93 + buf.put((byte)carparkSerialNo);
  94 + buf.put(ConvertUtil.string2ascii(carparkNo, 8));
  95 + buf.put((byte)stopSerialNo);
  96 + buf.put(ConvertUtil.string2ascii(stopNo, 8));
  97 + buf.put(ConvertUtil.long2bcd(carLon, 5));
  98 + buf.put(ConvertUtil.long2bcd(carLat, 4));
  99 + buf.put(ConvertUtil.timestamp2bcd(timestamp));
  100 + buf.put(ConvertUtil.int2bcd(speedSensor, 2));
  101 + buf.put(ConvertUtil.int2bcd(speedGps, 2));
  102 + buf.put(ConvertUtil.int2bcd(direction, 2));
  103 + buf.put(ConvertUtil.int2bcd(inTemp, 2));
  104 + buf.putInt((int)serviceState);
  105 + buf.putInt((int)controlState);
  106 + buf.put(ConvertUtil.int2bcd(totalMiles, 4));
  107 + buf.put(waterTemp);
  108 + buf.put(ConvertUtil.int2bcd(oilConsumption, 2));
  109 + buf.putShort((short)engineSpeed);
  110 +
  111 + return buf.array();
  112 + }
  113 +
  114 + public String getDeviceId() {
  115 + // TODO Auto-generated method stub
  116 + return deviceId;
  117 + }
  118 +
  119 + public int getCityCode() {
  120 + return cityCode;
  121 + }
  122 +
  123 + public short getIndustryCode() {
  124 + return industryCode;
  125 + }
  126 +
  127 + public short getCompanyCode() {
  128 + return companyCode;
  129 + }
  130 +
  131 + public int getLineId() {
  132 + return lineId;
  133 + }
  134 +
  135 + public int getDriverEmpNo() {
  136 + return driverEmpNo;
  137 + }
  138 +
  139 + public short getCarparkSerialNo() {
  140 + return carparkSerialNo;
  141 + }
  142 +
  143 + public String getCarparkNo() {
  144 + return carparkNo;
  145 + }
  146 +
  147 + public short getStopSerialNo() {
  148 + return stopSerialNo;
  149 + }
  150 +
  151 + public String getStopNo() {
  152 + return stopNo;
  153 + }
  154 +
  155 + public long getCarLon() {
  156 + return carLon;
  157 + }
  158 +
  159 + public int getCarLat() {
  160 + return carLat;
  161 + }
  162 +
  163 + public long getTimestamp() {
  164 + return timestamp;
  165 + }
  166 +
  167 + public short getSpeedSensor() {
  168 + return speedSensor;
  169 + }
  170 +
  171 + public short getSpeedGps() {
  172 + return speedGps;
  173 + }
  174 +
  175 + public short getDirection() {
  176 + return direction;
  177 + }
  178 +
  179 + public short getInTemp() {
  180 + return inTemp;
  181 + }
  182 +
  183 + public long getServiceState() {
  184 + return serviceState;
  185 + }
  186 +
  187 + public long getControlState() {
  188 + return controlState;
  189 + }
  190 +
  191 + public int getTotalMiles() {
  192 + return totalMiles;
  193 + }
  194 +
  195 + public byte getWaterTemp() {
  196 + return waterTemp;
  197 + }
  198 +
  199 + public int getOilConsumption() {
  200 + return oilConsumption;
  201 + }
  202 +
  203 + public int getEngineSpeed() {
  204 + return engineSpeed;
  205 + }
  206 +
  207 + public float getLon() {
  208 + return lon;
  209 + }
  210 +
  211 + public void setLon(float lon) {
  212 + this.lon = lon;
  213 + }
  214 +
  215 + public float getLat() {
  216 + return lat;
  217 + }
  218 +
  219 + public void setLat(float lat) {
  220 + this.lat = lat;
  221 + }
  222 +
  223 + public void setStopNo(String stopNo) {
  224 + this.stopNo = stopNo;
  225 + }
  226 +
  227 + public byte getGpsValid() {
  228 + return (byte)(((serviceState & 0x80000000) == 0x80000000) ? 1 : 0);
  229 + }
  230 +
  231 + /**
  232 + * 获取车辆在场外/内
  233 + * @return -1无效 0场外1场内
  234 + */
  235 + public byte getInOrOutCarpark() {
  236 + if ((serviceState & 0x00020000) == 0x00020000 || (serviceState & 0x80000000) == 0x80000000
  237 + || (serviceState & 0x01000000) == 0x01000000) return -1;
  238 + return (byte)(((serviceState & 0x40000000) == 0x40000000) ? 1 : 0);
  239 + }
  240 +
  241 + public void setInOrOutCarpark(boolean inOutFlag) {
  242 + if (inOutFlag) serviceState |= 0x40000000;
  243 + else serviceState &= 0xbfffffff;
  244 + }
  245 +
  246 + /**
  247 + * 获取车辆在起终点站外/内
  248 + * @return -1无效 0起终点站外1起终点站内
  249 + */
  250 + public byte getInOrOutStartEnd() {
  251 + if ((serviceState & 0x00020000) == 0x00020000 || (serviceState & 0x80000000) == 0x80000000
  252 + || (serviceState & 0x01000000) == 0x01000000) return -1;
  253 + return (byte)(((serviceState & 0x20000000) == 0x20000000) ? 1 : 0);
  254 + }
  255 +
  256 + /**
  257 + * 获取车辆线路上下行
  258 + * @return -1无效 0上行 1下行
  259 + */
  260 + public byte getUpOrDown() {
  261 + if ((serviceState & 0x00020000) == 0x00020000 || (serviceState & 0x80000000) == 0x80000000
  262 + || (serviceState & 0x01000000) == 0x01000000
  263 + || (serviceState & 0x08000000) == 0x08000000) return -1;
  264 + return (byte)(((serviceState & 0x10000000) == 0x10000000) ? 1 : 0);
  265 + }
  266 +
  267 + public void setUpOrDown(boolean upOrDown) {
  268 + if (!upOrDown) serviceState |= 0x10000000;
  269 + else serviceState &= 0xefffffff;
  270 + }
  271 +
  272 + /**
  273 + * 获取车辆在站外/内
  274 + * @return -1无效 0站外 1站内
  275 + */
  276 + public byte getInOrOutStop() {
  277 + if ((serviceState & 0x00020000) == 0x00020000 || (serviceState & 0x80000000) == 0x80000000
  278 + || (serviceState & 0x01000000) == 0x01000000
  279 + || (serviceState & 0x08000000) == 0x08000000) return -1;
  280 + return (byte)(((serviceState & 0x04000000) == 0x04000000) ? 1 : 0);
  281 + }
  282 +
  283 + public void setInOrOutStop(boolean isInOrOutStop) {
  284 + inOutStopFlag = true;
  285 + if (isInOrOutStop) serviceState |= 0x04000000;
  286 + else serviceState &= 0xfbffffff;
  287 + }
  288 +
  289 + /**
  290 + * 获取运营状态
  291 + * @return -1无效 0运营 1未运营
  292 + */
  293 + public byte getService() {
  294 + if ((serviceState & 0x00020000) == 0x00020000 || (serviceState & 0x80000000) == 0x80000000) return -1;
  295 + return (byte)(((serviceState & 0x02000000) == 0x02000000) ? 1 : 0);
  296 + }
  297 +
  298 + public void setService(boolean service) {
  299 + if (!service) serviceState |= 0x02000000;
  300 + else serviceState &= 0xfdffffff;
  301 + }
  302 +
  303 + /**
  304 + * 获得车辆状态
  305 + * @return 0点火 1熄火
  306 + */
  307 + public byte getVehicleState() {
  308 + return (byte)(((serviceState & 0x00200000) == 0x00200000) ? 1 : 0);
  309 + }
  310 +
  311 + public void setInOutStopFlag(boolean inOutStopFlag) {
  312 + this.inOutStopFlag = inOutStopFlag;
  313 + }
  314 +
  315 + public boolean getInOutStopFlag() {
  316 + return inOutStopFlag;
  317 + }
  318 +
  319 + public String toString() {
  320 + Date d = new Date();d.setTime(timestamp);
  321 + StringBuilder sb = new StringBuilder();
  322 + sb.append("城市代码:").append(cityCode)
  323 + .append("行业代码:").append(industryCode)
  324 + .append("公司代码:").append(companyCode)
  325 + .append("设备号:").append(deviceId)
  326 + .append("线路编号:").append(lineId)
  327 + .append("驾驶员工号:").append(driverEmpNo)
  328 + .append("停车场序列号:").append(carparkSerialNo)
  329 + .append("停车场编号:").append(carparkNo)
  330 + .append("站点序列号").append(stopSerialNo)
  331 + .append("站点编号:").append(stopNo)
  332 + .append("经度:").append(carLon)
  333 + .append("维度:").append(carLat)
  334 + .append("时间戳:").append(d)
  335 + .append("速度(传感器):").append(speedSensor)
  336 + .append("速度(gps)").append(speedGps)
  337 + .append("方向:").append(direction)
  338 + .append("车内温度:").append(inTemp)
  339 + .append("营运状态:").append(serviceState)
  340 + .append("调控状态:").append(controlState)
  341 + .append("总里程:").append(totalMiles)
  342 + .append("水温:").append(waterTemp)
  343 + .append("油耗:").append(oilConsumption)
  344 + .append("发动机速度:").append(engineSpeed);
  345 +
  346 + return sb.toString();
  347 + }
  348 + /* ----------------------------------------------------- */
  349 +
  350 + public void setCityCode(int cityCode) {
  351 + this.cityCode = cityCode;
  352 + }
  353 +
  354 + public void setIndustryCode(short industryCode) {
  355 + this.industryCode = industryCode;
  356 + }
  357 +
  358 + public void setCompanyCode(short companyCode) {
  359 + this.companyCode = companyCode;
  360 + }
  361 +
  362 + public void setDeviceId(String deviceId) {
  363 + this.deviceId = deviceId;
  364 + }
  365 +
  366 + public void setLineId(int lineId) {
  367 + this.lineId = lineId;
  368 + }
  369 +
  370 + public void setDriverEmpNo(int driverEmpNo) {
  371 + this.driverEmpNo = driverEmpNo;
  372 + }
  373 +
  374 + public void setCarparkSerialNo(short carparkSerialNo) {
  375 + this.carparkSerialNo = carparkSerialNo;
  376 + }
  377 +
  378 + public void setCarparkNo(String carparkNo) {
  379 + this.carparkNo = carparkNo;
  380 + }
  381 +
  382 + public void setStopSerialNo(short stopSerialNo) {
  383 + this.stopSerialNo = stopSerialNo;
  384 + }
  385 +
  386 + public void setCarLon(long carLon) {
  387 + this.carLon = carLon;
  388 + }
  389 +
  390 + public void setCarLat(int carLat) {
  391 + this.carLat = carLat;
  392 + }
  393 +
  394 + public void setTimestamp(long timestamp) {
  395 + this.timestamp = timestamp;
  396 + }
  397 +
  398 + public void setSpeedSensor(short speedSensor) {
  399 + this.speedSensor = speedSensor;
  400 + }
  401 +
  402 + public void setSpeedGps(short speedGps) {
  403 + this.speedGps = speedGps;
  404 + }
  405 +
  406 + public void setDirection(short direction) {
  407 + this.direction = direction;
  408 + }
  409 +
  410 + public void setInTemp(short inTemp) {
  411 + this.inTemp = inTemp;
  412 + }
  413 +
  414 + public void setServiceState(long serviceState) {
  415 + this.serviceState = serviceState;
  416 + }
  417 +
  418 + public void setControlState(long controlState) {
  419 + this.controlState = controlState;
  420 + }
  421 +
  422 + public void setTotalMiles(int totalMiles) {
  423 + this.totalMiles = totalMiles;
  424 + }
  425 +
  426 + public void setWaterTemp(byte waterTemp) {
  427 + this.waterTemp = waterTemp;
  428 + }
  429 +
  430 + public void setOilConsumption(int oilConsumption) {
  431 + this.oilConsumption = oilConsumption;
  432 + }
  433 +
  434 + public void setEngineSpeed(int engineSpeed) {
  435 + this.engineSpeed = engineSpeed;
  436 + }
  437 +}
... ...
src/main/java/com/bsth/data/gpsdata/client/pd/protocol/PdFactory.java
1   -package com.bsth.data.gpsdata.client.pd.protocol;
2   -
3   -
4   -import com.bsth.data.gpsdata.client.msg.IMessageBody;
5   -
6   -public class PdFactory {
7   -
8   - public static IMessageBody create(int commandType, byte[] data) {
9   - String pkgName = PdFactory.class.getPackage().getName();
10   - IMessageBody body = null;
11   - try {
12   - Class<?> cls = Class.forName(pkgName + ".Pd_" + Integer.toHexString(commandType).toUpperCase() + "_0");
13   - body = (IMessageBody)cls.newInstance();
14   - body.read(data);
15   - } catch (ClassNotFoundException e) {
16   - // TODO Auto-generated catch block
17   - //e.printStackTrace();
18   - } catch (InstantiationException e) {
19   - // TODO Auto-generated catch block
20   - e.printStackTrace();
21   - } catch (IllegalAccessException e) {
22   - // TODO Auto-generated catch block
23   - e.printStackTrace();
24   - }
25   - return body;
26   - }
27   -}
  1 +package com.bsth.data.gpsdata.client.pd.protocol;
  2 +
  3 +
  4 +import com.bsth.data.gpsdata.client.msg.IMessageBody;
  5 +
  6 +public class PdFactory {
  7 +
  8 + public static IMessageBody create(int commandType, byte[] data) {
  9 + String pkgName = PdFactory.class.getPackage().getName();
  10 + IMessageBody body = null;
  11 + try {
  12 + Class<?> cls = Class.forName(pkgName + ".Pd_" + Integer.toHexString(commandType).toUpperCase() + "_0");
  13 + body = (IMessageBody)cls.newInstance();
  14 + body.read(data);
  15 + } catch (ClassNotFoundException e) {
  16 + // TODO Auto-generated catch block
  17 + //e.printStackTrace();
  18 + } catch (InstantiationException e) {
  19 + // TODO Auto-generated catch block
  20 + e.printStackTrace();
  21 + } catch (IllegalAccessException e) {
  22 + // TODO Auto-generated catch block
  23 + e.printStackTrace();
  24 + }
  25 + return body;
  26 + }
  27 +}
... ...
src/main/java/com/bsth/data/gpsdata/client/pd/protocol/PdMessage.java
1   -package com.bsth.data.gpsdata.client.pd.protocol;
2   -
3   -
4   -import com.bsth.data.gpsdata.client.msg.IMessage;
5   -import com.bsth.data.gpsdata.client.msg.IMessageBody;
6   -
7   -import java.nio.ByteBuffer;
8   -import java.util.Arrays;
9   -
10   -public class PdMessage implements IMessage {
11   -
12   - private short version;
13   - private short serialNo;
14   - private short commandType;
15   - private IMessageBody messageBody;
16   - private byte checkSum;
17   -
18   - public short getVersion() {
19   - return version;
20   - }
21   -
22   - public void setVersion(short version) {
23   - this.version = version;
24   - }
25   -
26   - public short getSerialNo() {
27   - return serialNo;
28   - }
29   -
30   - public void setSerialNo(short serialNo) {
31   - this.serialNo = serialNo;
32   - }
33   -
34   - public short getCommandType() {
35   - return commandType;
36   - }
37   -
38   - public void setCommandType(short commandType) {
39   - this.commandType = commandType;
40   - }
41   -
42   - public IMessageBody getMessageBody() {
43   - return messageBody;
44   - }
45   -
46   - public void setMessageBody(IMessageBody messageBody) {
47   - this.messageBody = messageBody;
48   - }
49   -
50   - public byte getCheckSum() {
51   - return checkSum;
52   - }
53   -
54   - public void setCheckSum(byte checkSum) {
55   - this.checkSum = checkSum;
56   - }
57   -
58   - public void read(byte[] data) {
59   - int idx = 0, len = data.length;
60   - version = (short)(data[idx] & 0xff); idx++;
61   - serialNo = (short)(data[idx] & 0xff); idx++;
62   - commandType = (short)(data[idx] & 0xff); idx++;
63   - byte[] temp = Arrays.copyOfRange(data, idx, len - 1);
64   - checkSum = data[len - 1];
65   - byte sum = 0;
66   - for (int i = 0;i < len - 1;i++) {
67   - sum += data[i];
68   - }
69   - if (sum == checkSum) {
70   - messageBody = PdFactory.create(commandType, temp);
71   - }
72   - }
73   -
74   - public byte[] write() {
75   - byte[] bytes = messageBody.write();
76   - ByteBuffer buf = ByteBuffer.allocate(bytes.length + 8);
77   - buf.put(new byte[] { (byte)0xfa, (byte)0xf5 });
78   - buf.putShort((short)(bytes.length + 3));
79   - buf.put((byte)version);
80   - buf.put((byte)serialNo);
81   - buf.put((byte)commandType);
82   - buf.put(bytes);
83   - checkSum = 0;
84   - checkSum += (byte)version;
85   - checkSum += (byte)serialNo;
86   - checkSum += (byte)commandType;
87   - for (byte b : bytes) {
88   - checkSum += b;
89   - }
90   - buf.put(checkSum);
91   - return buf.array();
92   - }
93   -
94   - public String toString() {
95   - StringBuilder sb = new StringBuilder();
96   - sb.append("报文版本号:").append(version)
97   - .append("报文序列号:").append(serialNo)
98   - .append("报文命令字:0x").append(Integer.toHexString(commandType))
99   - .append("报文主体:(").append(messageBody).append(")")
100   - .append("报文校验和:").append(checkSum);
101   -
102   - return sb.toString();
103   - }
104   -}
  1 +package com.bsth.data.gpsdata.client.pd.protocol;
  2 +
  3 +
  4 +import com.bsth.data.gpsdata.client.msg.IMessage;
  5 +import com.bsth.data.gpsdata.client.msg.IMessageBody;
  6 +
  7 +import java.nio.ByteBuffer;
  8 +import java.util.Arrays;
  9 +
  10 +public class PdMessage implements IMessage {
  11 +
  12 + private short version;
  13 + private short serialNo;
  14 + private short commandType;
  15 + private IMessageBody messageBody;
  16 + private byte checkSum;
  17 +
  18 + public short getVersion() {
  19 + return version;
  20 + }
  21 +
  22 + public void setVersion(short version) {
  23 + this.version = version;
  24 + }
  25 +
  26 + public short getSerialNo() {
  27 + return serialNo;
  28 + }
  29 +
  30 + public void setSerialNo(short serialNo) {
  31 + this.serialNo = serialNo;
  32 + }
  33 +
  34 + public short getCommandType() {
  35 + return commandType;
  36 + }
  37 +
  38 + public void setCommandType(short commandType) {
  39 + this.commandType = commandType;
  40 + }
  41 +
  42 + public IMessageBody getMessageBody() {
  43 + return messageBody;
  44 + }
  45 +
  46 + public void setMessageBody(IMessageBody messageBody) {
  47 + this.messageBody = messageBody;
  48 + }
  49 +
  50 + public byte getCheckSum() {
  51 + return checkSum;
  52 + }
  53 +
  54 + public void setCheckSum(byte checkSum) {
  55 + this.checkSum = checkSum;
  56 + }
  57 +
  58 + public void read(byte[] data) {
  59 + int idx = 0, len = data.length;
  60 + version = (short)(data[idx] & 0xff); idx++;
  61 + serialNo = (short)(data[idx] & 0xff); idx++;
  62 + commandType = (short)(data[idx] & 0xff); idx++;
  63 + byte[] temp = Arrays.copyOfRange(data, idx, len - 1);
  64 + checkSum = data[len - 1];
  65 + byte sum = 0;
  66 + for (int i = 0;i < len - 1;i++) {
  67 + sum += data[i];
  68 + }
  69 + if (sum == checkSum) {
  70 + messageBody = PdFactory.create(commandType, temp);
  71 + }
  72 + }
  73 +
  74 + public byte[] write() {
  75 + byte[] bytes = messageBody.write();
  76 + ByteBuffer buf = ByteBuffer.allocate(bytes.length + 8);
  77 + buf.put(new byte[] { (byte)0xfa, (byte)0xf5 });
  78 + buf.putShort((short)(bytes.length + 3));
  79 + buf.put((byte)version);
  80 + buf.put((byte)serialNo);
  81 + buf.put((byte)commandType);
  82 + buf.put(bytes);
  83 + checkSum = 0;
  84 + checkSum += (byte)version;
  85 + checkSum += (byte)serialNo;
  86 + checkSum += (byte)commandType;
  87 + for (byte b : bytes) {
  88 + checkSum += b;
  89 + }
  90 + buf.put(checkSum);
  91 + return buf.array();
  92 + }
  93 +
  94 + public String toString() {
  95 + StringBuilder sb = new StringBuilder();
  96 + sb.append("报文版本号:").append(version)
  97 + .append("报文序列号:").append(serialNo)
  98 + .append("报文命令字:0x").append(Integer.toHexString(commandType))
  99 + .append("报文主体:(").append(messageBody).append(")")
  100 + .append("报文校验和:").append(checkSum);
  101 +
  102 + return sb.toString();
  103 + }
  104 +}
... ...
src/main/java/com/bsth/data/gpsdata/client/pd/protocol/Pd_31_0.java
1   -package com.bsth.data.gpsdata.client.pd.protocol;
2   -
3   -
4   -import com.bsth.data.gpsdata.client.msg.IMessageBody;
5   -import com.bsth.data.gpsdata.client.pd.common.ConvertUtil;
6   -
7   -import java.nio.ByteBuffer;
8   -import java.util.Date;
9   -
10   -
11   -public class Pd_31_0 implements IMessageBody {
12   -
13   - // bcd 1
14   - private short funCode;
15   - // bcd 3
16   - private int lineId;
17   - // ascii 8
18   - private String deviceId;
19   - // bcd 6 yyMMddhhmmss
20   - private long timestamp;
21   - // hex 8
22   - private String reserved;
23   -
24   - @Override
25   - public void read(byte[] bytes) {
26   - // TODO Auto-generated method stub
27   - int idx = 0;
28   - funCode = (short)(bytes[idx] & 0xff);idx++;
29   - lineId = ConvertUtil.bcd2int(bytes, idx, 3);idx += 3;
30   - deviceId = ConvertUtil.ascii2string(bytes, idx, 8);idx += 8;
31   - timestamp = ConvertUtil.bcd2timestamp(bytes, idx);idx += 6;
32   - reserved = ConvertUtil.ascii2string(bytes, idx, 8);idx += 8;
33   - }
34   -
35   - @Override
36   - public byte[] write() {
37   - // TODO Auto-generated method stub
38   - ByteBuffer buf = ByteBuffer.allocate(26);
39   - buf.put((byte)funCode);
40   - buf.put(ConvertUtil.int2bcd(lineId, 3));
41   - buf.put(deviceId.getBytes());
42   - buf.put(ConvertUtil.timestamp2bcd(timestamp));
43   - buf.put(new byte[]{0,0,0,0,0,0,0,0});
44   - return buf.array();
45   - }
46   -
47   - public short getFunCode() {
48   - return funCode;
49   - }
50   -
51   - public int getLineId() {
52   - return lineId;
53   - }
54   -
55   - public String getDeviceId() {
56   - return deviceId;
57   - }
58   -
59   - public long getTimestamp() {
60   - return timestamp;
61   - }
62   -
63   - public String getReserved() {
64   - return reserved;
65   - }
66   -
67   - public void setFunCode(short funCode) {
68   - this.funCode = funCode;
69   - }
70   -
71   - public void setLineId(int lineId) {
72   - this.lineId = lineId;
73   - }
74   -
75   - public void setDeviceId(String deviceId) {
76   - this.deviceId = deviceId;
77   - }
78   -
79   - public void setTimeStamp(long timestamp) {
80   - this.timestamp = timestamp;
81   - }
82   -
83   - public void setReserved(String reserved) {
84   - this.reserved = reserved;
85   - }
86   -
87   - public String toString() {
88   - Date d = new Date();
89   - d.setTime(timestamp);
90   - StringBuilder sb = new StringBuilder();
91   - sb.append("功能号:").append(Integer.toHexString(funCode))
92   - .append("线路编号:").append(lineId)
93   - .append("设备编号:").append(deviceId)
94   - .append("时间戳:").append(d);
95   - return sb.toString();
96   - }
97   -}
  1 +package com.bsth.data.gpsdata.client.pd.protocol;
  2 +
  3 +
  4 +import com.bsth.data.gpsdata.client.msg.IMessageBody;
  5 +import com.bsth.data.gpsdata.client.pd.common.ConvertUtil;
  6 +
  7 +import java.nio.ByteBuffer;
  8 +import java.util.Date;
  9 +
  10 +
  11 +public class Pd_31_0 implements IMessageBody {
  12 +
  13 + // bcd 1
  14 + private short funCode;
  15 + // bcd 3
  16 + private int lineId;
  17 + // ascii 8
  18 + private String deviceId;
  19 + // bcd 6 yyMMddhhmmss
  20 + private long timestamp;
  21 + // hex 8
  22 + private String reserved;
  23 +
  24 + @Override
  25 + public void read(byte[] bytes) {
  26 + // TODO Auto-generated method stub
  27 + int idx = 0;
  28 + funCode = (short)(bytes[idx] & 0xff);idx++;
  29 + lineId = ConvertUtil.bcd2int(bytes, idx, 3);idx += 3;
  30 + deviceId = ConvertUtil.ascii2string(bytes, idx, 8);idx += 8;
  31 + timestamp = ConvertUtil.bcd2timestamp(bytes, idx);idx += 6;
  32 + reserved = ConvertUtil.ascii2string(bytes, idx, 8);idx += 8;
  33 + }
  34 +
  35 + @Override
  36 + public byte[] write() {
  37 + // TODO Auto-generated method stub
  38 + ByteBuffer buf = ByteBuffer.allocate(26);
  39 + buf.put((byte)funCode);
  40 + buf.put(ConvertUtil.int2bcd(lineId, 3));
  41 + buf.put(deviceId.getBytes());
  42 + buf.put(ConvertUtil.timestamp2bcd(timestamp));
  43 + buf.put(new byte[]{0,0,0,0,0,0,0,0});
  44 + return buf.array();
  45 + }
  46 +
  47 + public short getFunCode() {
  48 + return funCode;
  49 + }
  50 +
  51 + public int getLineId() {
  52 + return lineId;
  53 + }
  54 +
  55 + public String getDeviceId() {
  56 + return deviceId;
  57 + }
  58 +
  59 + public long getTimestamp() {
  60 + return timestamp;
  61 + }
  62 +
  63 + public String getReserved() {
  64 + return reserved;
  65 + }
  66 +
  67 + public void setFunCode(short funCode) {
  68 + this.funCode = funCode;
  69 + }
  70 +
  71 + public void setLineId(int lineId) {
  72 + this.lineId = lineId;
  73 + }
  74 +
  75 + public void setDeviceId(String deviceId) {
  76 + this.deviceId = deviceId;
  77 + }
  78 +
  79 + public void setTimeStamp(long timestamp) {
  80 + this.timestamp = timestamp;
  81 + }
  82 +
  83 + public void setReserved(String reserved) {
  84 + this.reserved = reserved;
  85 + }
  86 +
  87 + public String toString() {
  88 + Date d = new Date();
  89 + d.setTime(timestamp);
  90 + StringBuilder sb = new StringBuilder();
  91 + sb.append("功能号:").append(Integer.toHexString(funCode))
  92 + .append("线路编号:").append(lineId)
  93 + .append("设备编号:").append(deviceId)
  94 + .append("时间戳:").append(d);
  95 + return sb.toString();
  96 + }
  97 +}
... ...
src/main/java/com/bsth/data/gpsdata/client/pd/protocol/Pd_41_0.java
1   -package com.bsth.data.gpsdata.client.pd.protocol;
2   -
3   -
4   -import com.bsth.data.gpsdata.client.msg.IMessageBody;
5   -import com.bsth.data.gpsdata.client.pd.common.ConvertUtil;
6   -
7   -import java.nio.ByteBuffer;
8   -
9   -
10   -public class Pd_41_0 implements IMessageBody {
11   -
12   - private BasicInfo info;
13   - private short leaveStopDis;
14   -
15   - public BasicInfo getInfo() {
16   - return info;
17   - }
18   -
19   - public void setInfo(BasicInfo info) {
20   - this.info = info;
21   - }
22   -
23   - public short getLeaveStopDis() {
24   - return leaveStopDis;
25   - }
26   -
27   - public void setLeaveStopDis(short leaveStopDis) {
28   - this.leaveStopDis = leaveStopDis;
29   - }
30   -
31   - @Override
32   - public void read(byte[] bytes) {
33   - // TODO Auto-generated method stub
34   - int idx = 0;
35   - info = new BasicInfo();
36   - info.read(bytes, idx); idx += 80;
37   - leaveStopDis = (short) ConvertUtil.bcd2int(bytes, idx, 2); idx += 2;
38   - }
39   -
40   - @Override
41   - public byte[] write() {
42   - // TODO Auto-generated method stub
43   - ByteBuffer buf = ByteBuffer.allocate(82);
44   - buf.put(info.write());
45   - buf.put(ConvertUtil.int2bcd(leaveStopDis, 2));
46   -
47   - return buf.array();
48   - }
49   -
50   - @Override
51   - public String getDeviceId() {
52   - // TODO Auto-generated method stub
53   - return info.getDeviceId();
54   - }
55   -
56   - public String toString() {
57   - StringBuilder sb = new StringBuilder();
58   - sb.append("基本数据:").append(info.toString())
59   - .append("离站距离:").append(leaveStopDis);
60   -
61   - return sb.toString();
62   - }
63   -
64   - @Override
65   - public long getTimestamp() {
66   - // TODO Auto-generated method stub
67   - return info.getTimestamp();
68   - }
69   -}
  1 +package com.bsth.data.gpsdata.client.pd.protocol;
  2 +
  3 +
  4 +import com.bsth.data.gpsdata.client.msg.IMessageBody;
  5 +import com.bsth.data.gpsdata.client.pd.common.ConvertUtil;
  6 +
  7 +import java.nio.ByteBuffer;
  8 +
  9 +
  10 +public class Pd_41_0 implements IMessageBody {
  11 +
  12 + private BasicInfo info;
  13 + private short leaveStopDis;
  14 +
  15 + public BasicInfo getInfo() {
  16 + return info;
  17 + }
  18 +
  19 + public void setInfo(BasicInfo info) {
  20 + this.info = info;
  21 + }
  22 +
  23 + public short getLeaveStopDis() {
  24 + return leaveStopDis;
  25 + }
  26 +
  27 + public void setLeaveStopDis(short leaveStopDis) {
  28 + this.leaveStopDis = leaveStopDis;
  29 + }
  30 +
  31 + @Override
  32 + public void read(byte[] bytes) {
  33 + // TODO Auto-generated method stub
  34 + int idx = 0;
  35 + info = new BasicInfo();
  36 + info.read(bytes, idx); idx += 80;
  37 + leaveStopDis = (short) ConvertUtil.bcd2int(bytes, idx, 2); idx += 2;
  38 + }
  39 +
  40 + @Override
  41 + public byte[] write() {
  42 + // TODO Auto-generated method stub
  43 + ByteBuffer buf = ByteBuffer.allocate(82);
  44 + buf.put(info.write());
  45 + buf.put(ConvertUtil.int2bcd(leaveStopDis, 2));
  46 +
  47 + return buf.array();
  48 + }
  49 +
  50 + @Override
  51 + public String getDeviceId() {
  52 + // TODO Auto-generated method stub
  53 + return info.getDeviceId();
  54 + }
  55 +
  56 + public String toString() {
  57 + StringBuilder sb = new StringBuilder();
  58 + sb.append("基本数据:").append(info.toString())
  59 + .append("离站距离:").append(leaveStopDis);
  60 +
  61 + return sb.toString();
  62 + }
  63 +
  64 + @Override
  65 + public long getTimestamp() {
  66 + // TODO Auto-generated method stub
  67 + return info.getTimestamp();
  68 + }
  69 +}
... ...
src/main/java/com/bsth/data/gpsdata/client/pd/protocol/Pd_42_0.java
1   -package com.bsth.data.gpsdata.client.pd.protocol;
2   -
3   -import com.bsth.data.gpsdata.client.msg.IMessageBody;
4   -import com.bsth.data.gpsdata.client.pd.common.ConvertUtil;
5   -
6   -import java.nio.ByteBuffer;
7   -
8   -public class Pd_42_0 implements IMessageBody {
9   -
10   - private BasicInfo info;
11   - // 站间里程 保留两位小数 km
12   - private short stopBetMiles;
13   - private short frontDoorUp;
14   - private short frontDoorDown;
15   - private short backDoorUp;
16   - private short backDoorDown;
17   - // 本站留车人数
18   - private int stay;
19   - // 本站刷卡次数
20   - private short cardCount;
21   - // 本站刷卡金额
22   - private int cardMoney;
23   - // 免费刷卡次数
24   - private short freeCardCount;
25   - // 免费刷卡金额
26   - private int freeCardMoney;
27   - // 总刷卡次数
28   - private int totalCardCount;
29   - // 总数卡金额
30   - private long totalCardMoney;
31   - // 总免费刷卡次数
32   - private int totalFreeCardCount;
33   - // 总免费刷卡金额
34   - private long totalFreeCardMoney;
35   - // 客流站号
36   - private short passengerStopNo;
37   -
38   - @Override
39   - public void read(byte[] bytes) {
40   - // TODO Auto-generated method stub
41   - ByteBuffer buf = ByteBuffer.wrap(bytes);
42   - int idx = 0;
43   - info = new BasicInfo();
44   - info.read(bytes, idx); idx += 80;
45   - stopBetMiles = (short) ConvertUtil.bcd2int(bytes, idx, 2); idx += 2;
46   - frontDoorUp = (short)(buf.get(idx) & 0xff); idx++;
47   - frontDoorDown = (short)(buf.get(idx) & 0xff); idx++;
48   - backDoorUp = (short)(buf.get(idx) & 0xff); idx++;
49   - backDoorDown = (short)(buf.get(idx) & 0xff); idx++;
50   - stay = buf.getShort(idx) & 0xffff; idx += 2;
51   - cardCount = (short)(buf.get(idx) & 0xff); idx++;
52   - cardMoney = buf.getShort(idx) & 0xffff; idx += 2;
53   - freeCardCount = (short)(buf.get(idx) & 0xff); idx++;
54   - freeCardMoney = buf.getShort(idx) & 0xffff; idx += 2;
55   - totalCardCount = buf.getShort(idx) & 0xffff; idx += 2;
56   - totalCardMoney = buf.getInt(idx) & 0xffffffffl; idx += 4;
57   - totalFreeCardCount = buf.getShort(idx) & 0xffff; idx += 2;
58   - totalFreeCardMoney = buf.getInt(idx) & 0xffffffffl; idx += 4;
59   - passengerStopNo = (short)(buf.get(idx) & 0xff); idx++;
60   - }
61   -
62   - @Override
63   - public byte[] write() {
64   - // TODO Auto-generated method stub
65   - ByteBuffer buf = ByteBuffer.allocate(107);
66   - buf.put(info.write());
67   - buf.put(ConvertUtil.int2bcd(stopBetMiles, 2));
68   - buf.put((byte)frontDoorUp);
69   - buf.put((byte)frontDoorDown);
70   - buf.put((byte)backDoorUp);
71   - buf.put((byte)backDoorDown);
72   - buf.putShort((short)stay);
73   - buf.put((byte)cardCount);
74   - buf.putShort((short)cardMoney);
75   - buf.put((byte)freeCardCount);
76   - buf.putShort((short)freeCardMoney);
77   - buf.putShort((short)totalCardCount);
78   - buf.putInt((int)totalCardMoney);
79   - buf.putShort((short)totalFreeCardCount);
80   - buf.putInt((int)totalFreeCardMoney);
81   - buf.put((byte)passengerStopNo);
82   -
83   - return buf.array();
84   - }
85   -
86   - @Override
87   - public String getDeviceId() {
88   - // TODO Auto-generated method stub
89   - return info.getDeviceId();
90   - }
91   -
92   - public BasicInfo getInfo() {
93   - return info;
94   - }
95   -
96   - public short getStopBetMiles() {
97   - return stopBetMiles;
98   - }
99   -
100   - public short getFrontDoorUp() {
101   - return frontDoorUp;
102   - }
103   -
104   - public short getFrontDoorDown() {
105   - return frontDoorDown;
106   - }
107   -
108   - public short getBackDoorUp() {
109   - return backDoorUp;
110   - }
111   -
112   - public short getBackDoorDown() {
113   - return backDoorDown;
114   - }
115   -
116   - public int getStay() {
117   - return stay;
118   - }
119   -
120   - public short getCardCount() {
121   - return cardCount;
122   - }
123   -
124   - public int getCardMoney() {
125   - return cardMoney;
126   - }
127   -
128   - public short getFreeCardCount() {
129   - return freeCardCount;
130   - }
131   -
132   - public int getFreeCardMoney() {
133   - return freeCardMoney;
134   - }
135   -
136   - public int getTotalCardCount() {
137   - return totalCardCount;
138   - }
139   -
140   - public long getTotalCardMoney() {
141   - return totalCardMoney;
142   - }
143   -
144   - public int getTotalFreeCardCount() {
145   - return totalFreeCardCount;
146   - }
147   -
148   - public long getTotalFreeCardMoney() {
149   - return totalFreeCardMoney;
150   - }
151   -
152   - public short getPassengerStopNo() {
153   - return passengerStopNo;
154   - }
155   -
156   - public String toString() {
157   - StringBuilder sb = new StringBuilder();
158   - sb.append("基本数据:").append(info.toString())
159   - .append("站间距离:").append(stopBetMiles)
160   - .append("前门上客:").append(frontDoorUp)
161   - .append("前门下客:").append(frontDoorDown)
162   - .append("后门上客:").append(backDoorUp)
163   - .append("后门下客:").append(backDoorDown)
164   - .append("本站留车人数:").append(stay)
165   - .append("本站刷卡次数:").append(cardCount)
166   - .append("本站刷卡金额:").append(cardMoney)
167   - .append("免费刷卡次数:").append(freeCardCount)
168   - .append("免费刷卡金额:").append(freeCardMoney)
169   - .append("总刷卡次数:").append(totalCardCount)
170   - .append("总数卡金额:").append(totalCardMoney)
171   - .append("总免费刷卡次数:").append(totalFreeCardCount)
172   - .append("总免费刷卡金额:").append(totalFreeCardMoney)
173   - .append("客流站号:").append(passengerStopNo);
174   -
175   - return sb.toString();
176   - }
177   -
178   - @Override
179   - public long getTimestamp() {
180   - // TODO Auto-generated method stub
181   - return info.getTimestamp();
182   - }
183   -}
  1 +package com.bsth.data.gpsdata.client.pd.protocol;
  2 +
  3 +import com.bsth.data.gpsdata.client.msg.IMessageBody;
  4 +import com.bsth.data.gpsdata.client.pd.common.ConvertUtil;
  5 +
  6 +import java.nio.ByteBuffer;
  7 +
  8 +public class Pd_42_0 implements IMessageBody {
  9 +
  10 + private BasicInfo info;
  11 + // 站间里程 保留两位小数 km
  12 + private short stopBetMiles;
  13 + private short frontDoorUp;
  14 + private short frontDoorDown;
  15 + private short backDoorUp;
  16 + private short backDoorDown;
  17 + // 本站留车人数
  18 + private int stay;
  19 + // 本站刷卡次数
  20 + private short cardCount;
  21 + // 本站刷卡金额
  22 + private int cardMoney;
  23 + // 免费刷卡次数
  24 + private short freeCardCount;
  25 + // 免费刷卡金额
  26 + private int freeCardMoney;
  27 + // 总刷卡次数
  28 + private int totalCardCount;
  29 + // 总数卡金额
  30 + private long totalCardMoney;
  31 + // 总免费刷卡次数
  32 + private int totalFreeCardCount;
  33 + // 总免费刷卡金额
  34 + private long totalFreeCardMoney;
  35 + // 客流站号
  36 + private short passengerStopNo;
  37 +
  38 + @Override
  39 + public void read(byte[] bytes) {
  40 + // TODO Auto-generated method stub
  41 + ByteBuffer buf = ByteBuffer.wrap(bytes);
  42 + int idx = 0;
  43 + info = new BasicInfo();
  44 + info.read(bytes, idx); idx += 80;
  45 + stopBetMiles = (short) ConvertUtil.bcd2int(bytes, idx, 2); idx += 2;
  46 + frontDoorUp = (short)(buf.get(idx) & 0xff); idx++;
  47 + frontDoorDown = (short)(buf.get(idx) & 0xff); idx++;
  48 + backDoorUp = (short)(buf.get(idx) & 0xff); idx++;
  49 + backDoorDown = (short)(buf.get(idx) & 0xff); idx++;
  50 + stay = buf.getShort(idx) & 0xffff; idx += 2;
  51 + cardCount = (short)(buf.get(idx) & 0xff); idx++;
  52 + cardMoney = buf.getShort(idx) & 0xffff; idx += 2;
  53 + freeCardCount = (short)(buf.get(idx) & 0xff); idx++;
  54 + freeCardMoney = buf.getShort(idx) & 0xffff; idx += 2;
  55 + totalCardCount = buf.getShort(idx) & 0xffff; idx += 2;
  56 + totalCardMoney = buf.getInt(idx) & 0xffffffffl; idx += 4;
  57 + totalFreeCardCount = buf.getShort(idx) & 0xffff; idx += 2;
  58 + totalFreeCardMoney = buf.getInt(idx) & 0xffffffffl; idx += 4;
  59 + passengerStopNo = (short)(buf.get(idx) & 0xff); idx++;
  60 + }
  61 +
  62 + @Override
  63 + public byte[] write() {
  64 + // TODO Auto-generated method stub
  65 + ByteBuffer buf = ByteBuffer.allocate(107);
  66 + buf.put(info.write());
  67 + buf.put(ConvertUtil.int2bcd(stopBetMiles, 2));
  68 + buf.put((byte)frontDoorUp);
  69 + buf.put((byte)frontDoorDown);
  70 + buf.put((byte)backDoorUp);
  71 + buf.put((byte)backDoorDown);
  72 + buf.putShort((short)stay);
  73 + buf.put((byte)cardCount);
  74 + buf.putShort((short)cardMoney);
  75 + buf.put((byte)freeCardCount);
  76 + buf.putShort((short)freeCardMoney);
  77 + buf.putShort((short)totalCardCount);
  78 + buf.putInt((int)totalCardMoney);
  79 + buf.putShort((short)totalFreeCardCount);
  80 + buf.putInt((int)totalFreeCardMoney);
  81 + buf.put((byte)passengerStopNo);
  82 +
  83 + return buf.array();
  84 + }
  85 +
  86 + @Override
  87 + public String getDeviceId() {
  88 + // TODO Auto-generated method stub
  89 + return info.getDeviceId();
  90 + }
  91 +
  92 + public BasicInfo getInfo() {
  93 + return info;
  94 + }
  95 +
  96 + public short getStopBetMiles() {
  97 + return stopBetMiles;
  98 + }
  99 +
  100 + public short getFrontDoorUp() {
  101 + return frontDoorUp;
  102 + }
  103 +
  104 + public short getFrontDoorDown() {
  105 + return frontDoorDown;
  106 + }
  107 +
  108 + public short getBackDoorUp() {
  109 + return backDoorUp;
  110 + }
  111 +
  112 + public short getBackDoorDown() {
  113 + return backDoorDown;
  114 + }
  115 +
  116 + public int getStay() {
  117 + return stay;
  118 + }
  119 +
  120 + public short getCardCount() {
  121 + return cardCount;
  122 + }
  123 +
  124 + public int getCardMoney() {
  125 + return cardMoney;
  126 + }
  127 +
  128 + public short getFreeCardCount() {
  129 + return freeCardCount;
  130 + }
  131 +
  132 + public int getFreeCardMoney() {
  133 + return freeCardMoney;
  134 + }
  135 +
  136 + public int getTotalCardCount() {
  137 + return totalCardCount;
  138 + }
  139 +
  140 + public long getTotalCardMoney() {
  141 + return totalCardMoney;
  142 + }
  143 +
  144 + public int getTotalFreeCardCount() {
  145 + return totalFreeCardCount;
  146 + }
  147 +
  148 + public long getTotalFreeCardMoney() {
  149 + return totalFreeCardMoney;
  150 + }
  151 +
  152 + public short getPassengerStopNo() {
  153 + return passengerStopNo;
  154 + }
  155 +
  156 + public String toString() {
  157 + StringBuilder sb = new StringBuilder();
  158 + sb.append("基本数据:").append(info.toString())
  159 + .append("站间距离:").append(stopBetMiles)
  160 + .append("前门上客:").append(frontDoorUp)
  161 + .append("前门下客:").append(frontDoorDown)
  162 + .append("后门上客:").append(backDoorUp)
  163 + .append("后门下客:").append(backDoorDown)
  164 + .append("本站留车人数:").append(stay)
  165 + .append("本站刷卡次数:").append(cardCount)
  166 + .append("本站刷卡金额:").append(cardMoney)
  167 + .append("免费刷卡次数:").append(freeCardCount)
  168 + .append("免费刷卡金额:").append(freeCardMoney)
  169 + .append("总刷卡次数:").append(totalCardCount)
  170 + .append("总数卡金额:").append(totalCardMoney)
  171 + .append("总免费刷卡次数:").append(totalFreeCardCount)
  172 + .append("总免费刷卡金额:").append(totalFreeCardMoney)
  173 + .append("客流站号:").append(passengerStopNo);
  174 +
  175 + return sb.toString();
  176 + }
  177 +
  178 + @Override
  179 + public long getTimestamp() {
  180 + // TODO Auto-generated method stub
  181 + return info.getTimestamp();
  182 + }
  183 +}
... ...
src/main/java/com/bsth/data/gpsdata/client/pf/codec/MessageDecoder.java
1   -package com.bsth.data.gpsdata.client.pf.codec;
2   -
3   -import com.bsth.data.gpsdata.client.pf.protocol.PfMessage;
4   -import org.apache.mina.core.buffer.IoBuffer;
5   -import org.apache.mina.core.session.IoSession;
6   -import org.apache.mina.filter.codec.CumulativeProtocolDecoder;
7   -import org.apache.mina.filter.codec.ProtocolDecoderOutput;
8   -
9   -
10   -public class MessageDecoder extends CumulativeProtocolDecoder {
11   -
12   - @Override
13   - protected boolean doDecode(IoSession session, IoBuffer in,
14   - ProtocolDecoderOutput out) throws Exception {
15   - // TODO Auto-generated method stub
16   - while (in.remaining() > 3) {
17   - in.mark();
18   - byte head1 = in.get(), head2 = in.get(), lenh = in.get(), lenl = in.get();
19   - int len = ((lenh & 0xff) << 8) + (lenl & 0xff);
20   - if ((head1 & 0xff) == 0xfa && (head2 & 0xff) == 0xf5) {
21   - if (in.remaining() > len) {
22   - byte[] bytes = new byte[len + 1];
23   - in.get(bytes);
24   - PfMessage msg = new PfMessage();
25   - msg.read(bytes);
26   - out.write(msg);
27   - } else {
28   - in.reset();
29   - return false;
30   - }
31   - }
32   - }
33   - return false;
34   - }
35   -
36   - /*private static String toHexString(byte[] bytes) {
37   - StringBuilder sb = new StringBuilder();
38   - for (byte b : bytes) {
39   - sb.append(Integer.toHexString(b & 0xff) + "|");
40   - }
41   - return sb.toString();
42   - }*/
43   -}
  1 +package com.bsth.data.gpsdata.client.pf.codec;
  2 +
  3 +import com.bsth.data.gpsdata.client.pf.protocol.PfMessage;
  4 +import org.apache.mina.core.buffer.IoBuffer;
  5 +import org.apache.mina.core.session.IoSession;
  6 +import org.apache.mina.filter.codec.CumulativeProtocolDecoder;
  7 +import org.apache.mina.filter.codec.ProtocolDecoderOutput;
  8 +
  9 +
  10 +public class MessageDecoder extends CumulativeProtocolDecoder {
  11 +
  12 + @Override
  13 + protected boolean doDecode(IoSession session, IoBuffer in,
  14 + ProtocolDecoderOutput out) throws Exception {
  15 + // TODO Auto-generated method stub
  16 + while (in.remaining() > 3) {
  17 + in.mark();
  18 + byte head1 = in.get(), head2 = in.get(), lenh = in.get(), lenl = in.get();
  19 + int len = ((lenh & 0xff) << 8) + (lenl & 0xff);
  20 + if ((head1 & 0xff) == 0xfa && (head2 & 0xff) == 0xf5) {
  21 + if (in.remaining() > len) {
  22 + byte[] bytes = new byte[len + 1];
  23 + in.get(bytes);
  24 + PfMessage msg = new PfMessage();
  25 + msg.read(bytes);
  26 + out.write(msg);
  27 + } else {
  28 + in.reset();
  29 + return false;
  30 + }
  31 + }
  32 + }
  33 + return false;
  34 + }
  35 +
  36 + /*private static String toHexString(byte[] bytes) {
  37 + StringBuilder sb = new StringBuilder();
  38 + for (byte b : bytes) {
  39 + sb.append(Integer.toHexString(b & 0xff) + "|");
  40 + }
  41 + return sb.toString();
  42 + }*/
  43 +}
... ...
src/main/java/com/bsth/data/gpsdata/client/pf/codec/MessageEncoder.java
1   -package com.bsth.data.gpsdata.client.pf.codec;
2   -
3   -import org.apache.mina.core.buffer.IoBuffer;
4   -import org.apache.mina.core.session.IoSession;
5   -import org.apache.mina.filter.codec.ProtocolEncoderAdapter;
6   -import org.apache.mina.filter.codec.ProtocolEncoderOutput;
7   -
8   -public class MessageEncoder extends ProtocolEncoderAdapter {
9   -
10   - @Override
11   - public void encode(IoSession session, Object message,
12   - ProtocolEncoderOutput out) throws Exception {
13   - // TODO Auto-generated method stub
14   - IoBuffer buf = IoBuffer.allocate(1024).setAutoExpand(true);
15   - buf.put((byte[])message);
16   - buf.flip();
17   - out.write(buf);
18   - }
19   -
20   -}
  1 +package com.bsth.data.gpsdata.client.pf.codec;
  2 +
  3 +import org.apache.mina.core.buffer.IoBuffer;
  4 +import org.apache.mina.core.session.IoSession;
  5 +import org.apache.mina.filter.codec.ProtocolEncoderAdapter;
  6 +import org.apache.mina.filter.codec.ProtocolEncoderOutput;
  7 +
  8 +public class MessageEncoder extends ProtocolEncoderAdapter {
  9 +
  10 + @Override
  11 + public void encode(IoSession session, Object message,
  12 + ProtocolEncoderOutput out) throws Exception {
  13 + // TODO Auto-generated method stub
  14 + IoBuffer buf = IoBuffer.allocate(1024).setAutoExpand(true);
  15 + buf.put((byte[])message);
  16 + buf.flip();
  17 + out.write(buf);
  18 + }
  19 +
  20 +}
... ...
src/main/java/com/bsth/data/gpsdata/client/pf/codec/PfMessageCodecFactory.java
1   -package com.bsth.data.gpsdata.client.pf.codec;
2   -
3   -import org.apache.mina.core.session.IoSession;
4   -import org.apache.mina.filter.codec.ProtocolCodecFactory;
5   -import org.apache.mina.filter.codec.ProtocolDecoder;
6   -import org.apache.mina.filter.codec.ProtocolEncoder;
7   -
8   -public class PfMessageCodecFactory implements ProtocolCodecFactory {
9   -
10   - private ProtocolEncoder encoder;
11   - private ProtocolDecoder decoder;
12   -
13   - public PfMessageCodecFactory() {
14   - encoder = new MessageEncoder();
15   - decoder = new MessageDecoder();
16   - }
17   -
18   - @Override
19   - public ProtocolEncoder getEncoder(IoSession session) throws Exception {
20   - // TODO Auto-generated method stub
21   - return encoder;
22   - }
23   -
24   - @Override
25   - public ProtocolDecoder getDecoder(IoSession session) throws Exception {
26   - // TODO Auto-generated method stub
27   - return decoder;
28   - }
29   -
30   -}
  1 +package com.bsth.data.gpsdata.client.pf.codec;
  2 +
  3 +import org.apache.mina.core.session.IoSession;
  4 +import org.apache.mina.filter.codec.ProtocolCodecFactory;
  5 +import org.apache.mina.filter.codec.ProtocolDecoder;
  6 +import org.apache.mina.filter.codec.ProtocolEncoder;
  7 +
  8 +public class PfMessageCodecFactory implements ProtocolCodecFactory {
  9 +
  10 + private ProtocolEncoder encoder;
  11 + private ProtocolDecoder decoder;
  12 +
  13 + public PfMessageCodecFactory() {
  14 + encoder = new MessageEncoder();
  15 + decoder = new MessageDecoder();
  16 + }
  17 +
  18 + @Override
  19 + public ProtocolEncoder getEncoder(IoSession session) throws Exception {
  20 + // TODO Auto-generated method stub
  21 + return encoder;
  22 + }
  23 +
  24 + @Override
  25 + public ProtocolDecoder getDecoder(IoSession session) throws Exception {
  26 + // TODO Auto-generated method stub
  27 + return decoder;
  28 + }
  29 +
  30 +}
... ...
src/main/java/com/bsth/data/gpsdata/client/pf/common/ConvertUtil.java
1   -package com.bsth.data.gpsdata.client.pf.common;
2   -
3   -import com.bsth.data.gpsdata.client.common.ThreadLocalDateUtil;
4   -import org.slf4j.Logger;
5   -import org.slf4j.LoggerFactory;
6   -
7   -import java.text.ParseException;
8   -import java.util.Arrays;
9   -import java.util.Calendar;
10   -import java.util.Date;
11   -
12   -
13   -public class ConvertUtil {
14   -
15   - private final static Logger log = LoggerFactory.getLogger(ConvertUtil.class);
16   -
17   - public static int bcd2int(byte[] bytes, int start, int len) {
18   - if (len > 4 || len == 0)
19   - throw new IllegalArgumentException("bcd2int 字节数不符合要求");
20   - String temp = "";
21   - for (int i = 0;i < len;i++) {
22   - int val = bytes[start + i] & 0xff;
23   - if (val < 10) temp += 0;
24   - temp += Integer.toHexString(val);
25   - }
26   - return Integer.parseInt(temp);
27   - }
28   -
29   - public static byte[] int2bcd(int val, int len) {
30   - if (len > 4 || len == 0)
31   - throw new IllegalArgumentException("int2bcd 字节数不符合要求");
32   - byte[] result = new byte[len];
33   - for (int i = len - 1;i > -1;i--) {
34   - result[i] = (byte)Integer.parseInt(val%100 + "", 16);
35   - val = val/100;
36   - }
37   - return result;
38   - }
39   -
40   - public static long bcd2long(byte[] bytes, int start, int len) {
41   - if (len > 8 || len == 0)
42   - throw new IllegalArgumentException("bcd2long 字节数不符合要求");
43   - String temp = "";
44   - for (int i = 0;i < len;i++) {
45   - int val = bytes[start + i] & 0xff;
46   - if (val < 10) temp += 0;
47   - temp += Integer.toHexString(val);
48   - }
49   - return Long.parseLong(temp);
50   - }
51   -
52   - public static byte[] long2bcd(long val, int len) {
53   - if (len > 8 || len == 0)
54   - throw new IllegalArgumentException("long2bcd 字节数不符合要求");
55   - byte[] result = new byte[len];
56   - for (int i = len - 1;i > -1;i--) {
57   - result[i] = (byte)Integer.parseInt(val%100 + "", 16);
58   - val = val/100;
59   - }
60   - return result;
61   - }
62   -
63   - public static String ascii2string(byte[] bytes, int start, int len) {
64   - return new String(Arrays.copyOfRange(bytes, start, start + len));
65   - }
66   -
67   - public static byte[] string2ascii(String val, int len) {
68   - byte[] result = new byte[len];
69   - byte[] bytes = val.getBytes();
70   - if (bytes.length > len && len != 0)
71   - throw new IllegalArgumentException("string2ascii 参数不符合要求");
72   - if (len != 0)
73   - for (int i = 0, l = bytes.length;i < l;i++) result[i] = bytes[i];
74   - else return bytes;
75   - return result;
76   - }
77   -
78   - public static long bcd2timestamp(byte[] bytes, int start) {
79   - String temp = "20";
80   - for (int i = 0;i < 6;i++) {
81   - int val = bytes[start + i] & 0xff;
82   - if (val < 10) temp += 0;
83   - temp += Integer.toHexString(val);
84   - }
85   - Date date = null;
86   - try {
87   - date = ThreadLocalDateUtil.parse(temp);
88   - } catch (ParseException e) {
89   - log.error("协议中时间数据异常:" + temp);
90   - }
91   - if (date != null) return date.getTime();
92   - return -1;
93   - }
94   -
95   - public static byte[] timestamp2bcd(long val) {
96   - byte[] result = new byte[6];
97   - Calendar c = Calendar.getInstance();
98   - c.setTime(new Date(val));
99   - result[0] = (byte)(Integer.parseInt(c.get(Calendar.YEAR)%100 + "", 16));
100   - result[1] = (byte)(Integer.parseInt(c.get(Calendar.MONTH) + 1 + "", 16));
101   - result[2] = (byte)Integer.parseInt(c.get(Calendar.DAY_OF_MONTH) + "", 16);
102   - result[3] = (byte)Integer.parseInt(c.get(Calendar.HOUR_OF_DAY) + "", 16);
103   - result[4] = (byte)Integer.parseInt(c.get(Calendar.MINUTE) + "", 16);
104   - result[5] = (byte)Integer.parseInt(c.get(Calendar.SECOND) + "", 16);
105   - return result;
106   - }
107   -
108   - public static byte[] int2hex(int val, int len) {
109   - if (len < 1)
110   - throw new IllegalArgumentException("int2hex len 参数不符合要求");
111   - byte[] result = new byte[len];
112   - for (int i = 0;i < len;i++) {
113   - result[len - 1 - i] = (byte)(val%100);
114   - val = val/100;
115   - }
116   -
117   - return result;
118   - }
119   -}
  1 +package com.bsth.data.gpsdata.client.pf.common;
  2 +
  3 +import com.bsth.data.gpsdata.client.common.ThreadLocalDateUtil;
  4 +import org.slf4j.Logger;
  5 +import org.slf4j.LoggerFactory;
  6 +
  7 +import java.text.ParseException;
  8 +import java.util.Arrays;
  9 +import java.util.Calendar;
  10 +import java.util.Date;
  11 +
  12 +
  13 +public class ConvertUtil {
  14 +
  15 + private final static Logger log = LoggerFactory.getLogger(ConvertUtil.class);
  16 +
  17 + public static int bcd2int(byte[] bytes, int start, int len) {
  18 + if (len > 4 || len == 0)
  19 + throw new IllegalArgumentException("bcd2int 字节数不符合要求");
  20 + String temp = "";
  21 + for (int i = 0;i < len;i++) {
  22 + int val = bytes[start + i] & 0xff;
  23 + if (val < 10) temp += 0;
  24 + temp += Integer.toHexString(val);
  25 + }
  26 + return Integer.parseInt(temp);
  27 + }
  28 +
  29 + public static byte[] int2bcd(int val, int len) {
  30 + if (len > 4 || len == 0)
  31 + throw new IllegalArgumentException("int2bcd 字节数不符合要求");
  32 + byte[] result = new byte[len];
  33 + for (int i = len - 1;i > -1;i--) {
  34 + result[i] = (byte)Integer.parseInt(val%100 + "", 16);
  35 + val = val/100;
  36 + }
  37 + return result;
  38 + }
  39 +
  40 + public static long bcd2long(byte[] bytes, int start, int len) {
  41 + if (len > 8 || len == 0)
  42 + throw new IllegalArgumentException("bcd2long 字节数不符合要求");
  43 + String temp = "";
  44 + for (int i = 0;i < len;i++) {
  45 + int val = bytes[start + i] & 0xff;
  46 + if (val < 10) temp += 0;
  47 + temp += Integer.toHexString(val);
  48 + }
  49 + return Long.parseLong(temp);
  50 + }
  51 +
  52 + public static byte[] long2bcd(long val, int len) {
  53 + if (len > 8 || len == 0)
  54 + throw new IllegalArgumentException("long2bcd 字节数不符合要求");
  55 + byte[] result = new byte[len];
  56 + for (int i = len - 1;i > -1;i--) {
  57 + result[i] = (byte)Integer.parseInt(val%100 + "", 16);
  58 + val = val/100;
  59 + }
  60 + return result;
  61 + }
  62 +
  63 + public static String ascii2string(byte[] bytes, int start, int len) {
  64 + return new String(Arrays.copyOfRange(bytes, start, start + len));
  65 + }
  66 +
  67 + public static byte[] string2ascii(String val, int len) {
  68 + byte[] result = new byte[len];
  69 + byte[] bytes = val.getBytes();
  70 + if (bytes.length > len && len != 0)
  71 + throw new IllegalArgumentException("string2ascii 参数不符合要求");
  72 + if (len != 0)
  73 + for (int i = 0, l = bytes.length;i < l;i++) result[i] = bytes[i];
  74 + else return bytes;
  75 + return result;
  76 + }
  77 +
  78 + public static long bcd2timestamp(byte[] bytes, int start) {
  79 + String temp = "20";
  80 + for (int i = 0;i < 6;i++) {
  81 + int val = bytes[start + i] & 0xff;
  82 + if (val < 10) temp += 0;
  83 + temp += Integer.toHexString(val);
  84 + }
  85 + Date date = null;
  86 + try {
  87 + date = ThreadLocalDateUtil.parse(temp);
  88 + } catch (ParseException e) {
  89 + log.error("协议中时间数据异常:" + temp);
  90 + }
  91 + if (date != null) return date.getTime();
  92 + return -1;
  93 + }
  94 +
  95 + public static byte[] timestamp2bcd(long val) {
  96 + byte[] result = new byte[6];
  97 + Calendar c = Calendar.getInstance();
  98 + c.setTime(new Date(val));
  99 + result[0] = (byte)(Integer.parseInt(c.get(Calendar.YEAR)%100 + "", 16));
  100 + result[1] = (byte)(Integer.parseInt(c.get(Calendar.MONTH) + 1 + "", 16));
  101 + result[2] = (byte)Integer.parseInt(c.get(Calendar.DAY_OF_MONTH) + "", 16);
  102 + result[3] = (byte)Integer.parseInt(c.get(Calendar.HOUR_OF_DAY) + "", 16);
  103 + result[4] = (byte)Integer.parseInt(c.get(Calendar.MINUTE) + "", 16);
  104 + result[5] = (byte)Integer.parseInt(c.get(Calendar.SECOND) + "", 16);
  105 + return result;
  106 + }
  107 +
  108 + public static byte[] int2hex(int val, int len) {
  109 + if (len < 1)
  110 + throw new IllegalArgumentException("int2hex len 参数不符合要求");
  111 + byte[] result = new byte[len];
  112 + for (int i = 0;i < len;i++) {
  113 + result[len - 1 - i] = (byte)(val%100);
  114 + val = val/100;
  115 + }
  116 +
  117 + return result;
  118 + }
  119 +}
... ...
src/main/java/com/bsth/data/gpsdata/client/pf/handler/PfClientHandler.java
1   -package com.bsth.data.gpsdata.client.pf.handler;
2   -
3   -import com.bsth.data.gpsdata.client.ClientApp;
4   -import com.bsth.data.gpsdata.client.GpsBeforeBuffer;
5   -import com.bsth.data.gpsdata.client.common.Protocol2BizUtil;
6   -import com.bsth.data.gpsdata.client.msg.IMessageBody;
7   -import com.bsth.data.gpsdata.client.pd.protocol.BasicInfo;
8   -import com.bsth.data.gpsdata.client.pf.protocol.PfMessage;
9   -import org.apache.mina.core.service.IoHandlerAdapter;
10   -import org.apache.mina.core.session.IdleStatus;
11   -import org.apache.mina.core.session.IoSession;
12   -import org.slf4j.Logger;
13   -import org.slf4j.LoggerFactory;
14   -import org.springframework.beans.factory.annotation.Autowired;
15   -import org.springframework.stereotype.Service;
16   -
17   -import java.io.IOException;
18   -
19   -@Service
20   -public class PfClientHandler extends IoHandlerAdapter{
21   -
22   - private final static Logger log = LoggerFactory.getLogger(PfClientHandler.class);
23   -
24   - //@Autowired
25   - //private MessageProcessor processor;
26   -
27   - @Autowired
28   - GpsBeforeBuffer gpsBeforeBuffer;
29   -
30   - @Override
31   - public void sessionCreated(IoSession session) throws Exception {
32   -
33   - }
34   -
35   - @Override
36   - public void sessionOpened(IoSession session) throws Exception {
37   -
38   - }
39   -
40   - @Override
41   - public void sessionClosed(IoSession session) throws Exception {
42   - String deviceId = (String)session.getAttribute("deviceId");
43   - if (deviceId != null) {
44   - //SessionManager.getInstance().unregister(deviceId);
45   - log.info("连老网关设备编号:" + deviceId + "断开连接");
46   - log.warn(deviceId + "老网关设备注销");
47   - ClientApp.fconnect(deviceId);
48   - }
49   - }
50   -
51   - @Override
52   - public void sessionIdle(IoSession session, IdleStatus status) throws Exception {
53   - session.closeNow();
54   - }
55   -
56   - @Override
57   - public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
58   - if (cause instanceof IOException) session.closeNow();
59   - log.error("PfClientHandler exceptionCaught", cause);
60   - }
61   -
62   - @Override
63   - public void messageReceived(IoSession session, Object message) throws Exception {
64   - PfMessage msg = (PfMessage)message;
65   - IMessageBody body = msg.getMessageBody();
66   - if (body != null) {
67   - String deviceId = body.getDeviceId();
68   - if (0x1 == msg.getCommandType()) {
69   - log.debug("设备编号:" + body.getDeviceId() + "建立连接");
70   - }
71   -
72   - BasicInfo info = Protocol2BizUtil.getBasicInfoFromMsg(msg);
73   - gpsBeforeBuffer.put(info);
74   - }
75   -
76   - }
77   -
78   - @Override
79   - public void messageSent(IoSession session, Object message) throws Exception {
80   -
81   - }
82   -}
  1 +package com.bsth.data.gpsdata.client.pf.handler;
  2 +
  3 +import com.bsth.data.gpsdata.client.ClientApp;
  4 +import com.bsth.data.gpsdata.client.GpsBeforeBuffer;
  5 +import com.bsth.data.gpsdata.client.common.Protocol2BizUtil;
  6 +import com.bsth.data.gpsdata.client.msg.IMessageBody;
  7 +import com.bsth.data.gpsdata.client.pd.protocol.BasicInfo;
  8 +import com.bsth.data.gpsdata.client.pf.protocol.PfMessage;
  9 +import org.apache.mina.core.service.IoHandlerAdapter;
  10 +import org.apache.mina.core.session.IdleStatus;
  11 +import org.apache.mina.core.session.IoSession;
  12 +import org.slf4j.Logger;
  13 +import org.slf4j.LoggerFactory;
  14 +import org.springframework.beans.factory.annotation.Autowired;
  15 +import org.springframework.stereotype.Service;
  16 +
  17 +import java.io.IOException;
  18 +
  19 +@Service
  20 +public class PfClientHandler extends IoHandlerAdapter{
  21 +
  22 + private final static Logger log = LoggerFactory.getLogger(PfClientHandler.class);
  23 +
  24 + //@Autowired
  25 + //private MessageProcessor processor;
  26 +
  27 + @Autowired
  28 + GpsBeforeBuffer gpsBeforeBuffer;
  29 +
  30 + @Override
  31 + public void sessionCreated(IoSession session) throws Exception {
  32 +
  33 + }
  34 +
  35 + @Override
  36 + public void sessionOpened(IoSession session) throws Exception {
  37 +
  38 + }
  39 +
  40 + @Override
  41 + public void sessionClosed(IoSession session) throws Exception {
  42 + String deviceId = (String)session.getAttribute("deviceId");
  43 + if (deviceId != null) {
  44 + //SessionManager.getInstance().unregister(deviceId);
  45 + log.info("连老网关设备编号:" + deviceId + "断开连接");
  46 + log.warn(deviceId + "老网关设备注销");
  47 + ClientApp.fconnect(deviceId);
  48 + }
  49 + }
  50 +
  51 + @Override
  52 + public void sessionIdle(IoSession session, IdleStatus status) throws Exception {
  53 + session.closeNow();
  54 + }
  55 +
  56 + @Override
  57 + public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
  58 + if (cause instanceof IOException) session.closeNow();
  59 + log.error("PfClientHandler exceptionCaught", cause);
  60 + }
  61 +
  62 + @Override
  63 + public void messageReceived(IoSession session, Object message) throws Exception {
  64 + PfMessage msg = (PfMessage)message;
  65 + IMessageBody body = msg.getMessageBody();
  66 + if (body != null) {
  67 + String deviceId = body.getDeviceId();
  68 + if (0x1 == msg.getCommandType()) {
  69 + log.debug("设备编号:" + body.getDeviceId() + "建立连接");
  70 + }
  71 +
  72 + BasicInfo info = Protocol2BizUtil.getBasicInfoFromMsg(msg);
  73 + gpsBeforeBuffer.put(info);
  74 + }
  75 +
  76 + }
  77 +
  78 + @Override
  79 + public void messageSent(IoSession session, Object message) throws Exception {
  80 +
  81 + }
  82 +}
... ...
src/main/java/com/bsth/data/gpsdata/client/pf/protocol/PfFactory.java
1   -package com.bsth.data.gpsdata.client.pf.protocol;
2   -
3   -
4   -import com.bsth.data.gpsdata.client.msg.IMessageBody;
5   -
6   -public class PfFactory {
7   -
8   - public static IMessageBody create(int commandType, byte[] data) {
9   - String pkgName = PfFactory.class.getPackage().getName();
10   - IMessageBody body = null;
11   - try {
12   - Class<?> cls = Class.forName(pkgName + ".Pf_" + Integer.toHexString(commandType).toUpperCase() + "_0");
13   - body = (IMessageBody)cls.newInstance();
14   - body.read(data);
15   - } catch (ClassNotFoundException e) {
16   - // TODO Auto-generated catch block
17   - //e.printStackTrace();
18   - } catch (InstantiationException e) {
19   - // TODO Auto-generated catch block
20   - e.printStackTrace();
21   - } catch (IllegalAccessException e) {
22   - // TODO Auto-generated catch block
23   - e.printStackTrace();
24   - }
25   - return body;
26   - }
27   -}
  1 +package com.bsth.data.gpsdata.client.pf.protocol;
  2 +
  3 +
  4 +import com.bsth.data.gpsdata.client.msg.IMessageBody;
  5 +
  6 +public class PfFactory {
  7 +
  8 + public static IMessageBody create(int commandType, byte[] data) {
  9 + String pkgName = PfFactory.class.getPackage().getName();
  10 + IMessageBody body = null;
  11 + try {
  12 + Class<?> cls = Class.forName(pkgName + ".Pf_" + Integer.toHexString(commandType).toUpperCase() + "_0");
  13 + body = (IMessageBody)cls.newInstance();
  14 + body.read(data);
  15 + } catch (ClassNotFoundException e) {
  16 + // TODO Auto-generated catch block
  17 + //e.printStackTrace();
  18 + } catch (InstantiationException e) {
  19 + // TODO Auto-generated catch block
  20 + e.printStackTrace();
  21 + } catch (IllegalAccessException e) {
  22 + // TODO Auto-generated catch block
  23 + e.printStackTrace();
  24 + }
  25 + return body;
  26 + }
  27 +}
... ...
src/main/java/com/bsth/data/gpsdata/client/pf/protocol/PfMessage.java
1   -package com.bsth.data.gpsdata.client.pf.protocol;
2   -
3   -import com.bsth.data.gpsdata.client.msg.IMessage;
4   -import com.bsth.data.gpsdata.client.msg.IMessageBody;
5   -
6   -import java.util.Arrays;
7   -
8   -public class PfMessage implements IMessage {
9   -
10   - private short version;
11   - private short serialNo;
12   - private short commandType;
13   - private IMessageBody messageBody;
14   - private byte checkSum;
15   -
16   - public short getVersion() {
17   - return version;
18   - }
19   -
20   - public void setVersion(short version) {
21   - this.version = version;
22   - }
23   -
24   - public short getSerialNo() {
25   - return serialNo;
26   - }
27   -
28   - public void setSerialNo(short serialNo) {
29   - this.serialNo = serialNo;
30   - }
31   -
32   - public short getCommandType() {
33   - return commandType;
34   - }
35   -
36   - public void setCommandType(short commandType) {
37   - this.commandType = commandType;
38   - }
39   -
40   - public IMessageBody getMessageBody() {
41   - return messageBody;
42   - }
43   -
44   - public void setMessageBody(IMessageBody messageBody) {
45   - this.messageBody = messageBody;
46   - }
47   -
48   - public byte getCheckSum() {
49   - return checkSum;
50   - }
51   -
52   - public void setCheckSum(byte checkSum) {
53   - this.checkSum = checkSum;
54   - }
55   -
56   - public void read(byte[] data) {
57   - int idx = 0, len = data.length;
58   - //version = (short)(data[idx] & 0xff); idx++;
59   - //serialNo = (short)(data[idx] & 0xff); idx++;
60   - commandType = (short)(data[idx] & 0xff); idx++;
61   - byte[] temp = Arrays.copyOfRange(data, idx, len - 1);
62   - checkSum = data[len - 1];
63   - if (0xff == (checkSum & 0xff)) {
64   - try {
65   - messageBody = PfFactory.create(commandType, temp);
66   - } catch (Exception e) {
67   -
68   - }
69   - }
70   - }
71   -
72   - public byte[] write() {
73   - return null;
74   - }
75   -
76   - public String toString() {
77   - StringBuilder sb = new StringBuilder();
78   - //sb.append("报文版本号:").append(version)
79   - //.append("报文序列号:").append(serialNo)
80   - sb.append("报文命令字:0x").append(Integer.toHexString(commandType))
81   - .append("报文主体:(").append(messageBody).append(")")
82   - .append("报文校验和:").append(checkSum);
83   -
84   - return sb.toString();
85   - }
86   -}
  1 +package com.bsth.data.gpsdata.client.pf.protocol;
  2 +
  3 +import com.bsth.data.gpsdata.client.msg.IMessage;
  4 +import com.bsth.data.gpsdata.client.msg.IMessageBody;
  5 +
  6 +import java.util.Arrays;
  7 +
  8 +public class PfMessage implements IMessage {
  9 +
  10 + private short version;
  11 + private short serialNo;
  12 + private short commandType;
  13 + private IMessageBody messageBody;
  14 + private byte checkSum;
  15 +
  16 + public short getVersion() {
  17 + return version;
  18 + }
  19 +
  20 + public void setVersion(short version) {
  21 + this.version = version;
  22 + }
  23 +
  24 + public short getSerialNo() {
  25 + return serialNo;
  26 + }
  27 +
  28 + public void setSerialNo(short serialNo) {
  29 + this.serialNo = serialNo;
  30 + }
  31 +
  32 + public short getCommandType() {
  33 + return commandType;
  34 + }
  35 +
  36 + public void setCommandType(short commandType) {
  37 + this.commandType = commandType;
  38 + }
  39 +
  40 + public IMessageBody getMessageBody() {
  41 + return messageBody;
  42 + }
  43 +
  44 + public void setMessageBody(IMessageBody messageBody) {
  45 + this.messageBody = messageBody;
  46 + }
  47 +
  48 + public byte getCheckSum() {
  49 + return checkSum;
  50 + }
  51 +
  52 + public void setCheckSum(byte checkSum) {
  53 + this.checkSum = checkSum;
  54 + }
  55 +
  56 + public void read(byte[] data) {
  57 + int idx = 0, len = data.length;
  58 + //version = (short)(data[idx] & 0xff); idx++;
  59 + //serialNo = (short)(data[idx] & 0xff); idx++;
  60 + commandType = (short)(data[idx] & 0xff); idx++;
  61 + byte[] temp = Arrays.copyOfRange(data, idx, len - 1);
  62 + checkSum = data[len - 1];
  63 + if (0xff == (checkSum & 0xff)) {
  64 + try {
  65 + messageBody = PfFactory.create(commandType, temp);
  66 + } catch (Exception e) {
  67 +
  68 + }
  69 + }
  70 + }
  71 +
  72 + public byte[] write() {
  73 + return null;
  74 + }
  75 +
  76 + public String toString() {
  77 + StringBuilder sb = new StringBuilder();
  78 + //sb.append("报文版本号:").append(version)
  79 + //.append("报文序列号:").append(serialNo)
  80 + sb.append("报文命令字:0x").append(Integer.toHexString(commandType))
  81 + .append("报文主体:(").append(messageBody).append(")")
  82 + .append("报文校验和:").append(checkSum);
  83 +
  84 + return sb.toString();
  85 + }
  86 +}
... ...
src/main/java/com/bsth/data/gpsdata/client/pf/protocol/Pf_1_0.java
1   -package com.bsth.data.gpsdata.client.pf.protocol;
2   -
3   -import com.bsth.data.gpsdata.client.msg.IMessageBody;
4   -import com.bsth.data.gpsdata.client.pd.common.ConvertUtil;
5   -
6   -import java.nio.ByteBuffer;
7   -import java.util.Date;
8   -
9   -
10   -public class Pf_1_0 implements IMessageBody {
11   -
12   - /** 1、车载终端识别码-byte[8] */
13   - private String mtd;
14   - /** 2、司机工号-byte[8] */
15   - private String driver;
16   - /** 3、包车状态-byte[1] */
17   - private int bczt;
18   - /** 4、线路状态-byte[1] */
19   - private int xlzt;
20   - /** 5、线路代码-byte[6] */
21   - private int xldm;
22   - /** 6、营运状态-byte[1] */
23   - private int yyzt;
24   - /** 7、进出站状态-byte[1] */
25   - private int jczzt;
26   - /** 8、站点编号-byte[8] */
27   - private String zdbh;
28   - /** 9、进出停车场状态(0:厂内,1:厂外,2:未知)-byte[1] */
29   - private int jctcczt;
30   - /** 10、停车场编号-byte[8] */
31   - private String tccbh;
32   - /** 11、路段编码-byte[12] */
33   - private String ldbh;
34   - /** 12、上下行状态-byte[1] */
35   - private int sxxzt;
36   - /** 13、速度-byte[1] */
37   - private int speed;
38   - /** 14、初始异常状态-byte[1] */
39   - private int csyczt;
40   - /** 15、结束异常状态-byte[1] */
41   - private int jsyczt;
42   - /** 16、车辆位置经度(纠偏后)-byte[4] */
43   - private double lon;
44   - /** 17、车辆位置维度(纠偏后)-byte[4] */
45   - private double lat;
46   - /** 18、方向-byte[2] */
47   - private int fx;
48   - /** 19、发送时间-byte[4] */
49   - private Date fssj;
50   - /** 20、离下站距离-byte[2] */
51   - private int lxzjl;
52   - /** 21、本站留车人数-byte[2] */
53   - private int bzlcrs;
54   - /** 22、车辆位置经度(未纠偏)-byte[4] */
55   - private double lon_old;
56   - /** 23、车辆位置经度(未纠偏)-byte[4] */
57   - private double lat_old;
58   - /** 24、城建X坐标 */
59   - private double x;
60   - /** 25、城建Y坐标 */
61   - private double y;
62   -
63   - public String getMtd() {
64   - return mtd;
65   - }
66   -
67   - public void setMtd(String mtd) {
68   - this.mtd = mtd;
69   - }
70   -
71   - public String getDriver() {
72   - return driver;
73   - }
74   -
75   - public void setDriver(String driver) {
76   - this.driver = driver;
77   - }
78   -
79   - public int getBczt() {
80   - return bczt;
81   - }
82   -
83   - public void setBczt(int bczt) {
84   - this.bczt = bczt;
85   - }
86   -
87   - public int getXlzt() {
88   - return xlzt;
89   - }
90   -
91   - public void setXlzt(int xlzt) {
92   - this.xlzt = xlzt;
93   - }
94   -
95   - public int getXldm() {
96   - return xldm;
97   - }
98   -
99   - public void setXldm(int xldm) {
100   - this.xldm = xldm;
101   - }
102   -
103   - public int getYyzt() {
104   - return yyzt;
105   - }
106   -
107   - public void setYyzt(int yyzt) {
108   - this.yyzt = yyzt;
109   - }
110   -
111   - public int getJczzt() {
112   - return jczzt;
113   - }
114   -
115   - public void setJczzt(int jczzt) {
116   - this.jczzt = jczzt;
117   - }
118   -
119   - public String getZdbh() {
120   - return zdbh;
121   - }
122   -
123   - public void setZdbh(String zdbh) {
124   - this.zdbh = zdbh;
125   - }
126   -
127   - public int getJctcczt() {
128   - return jctcczt;
129   - }
130   -
131   - public void setJctcczt(int jctcczt) {
132   - this.jctcczt = jctcczt;
133   - }
134   -
135   - public String getTccbh() {
136   - return tccbh;
137   - }
138   -
139   - public void setTccbh(String tccbh) {
140   - this.tccbh = tccbh;
141   - }
142   -
143   - public String getLdbh() {
144   - return ldbh;
145   - }
146   -
147   - public void setLdbh(String ldbh) {
148   - this.ldbh = ldbh;
149   - }
150   -
151   - public int getSxxzt() {
152   - return sxxzt;
153   - }
154   -
155   - public void setSxxzt(int sxxzt) {
156   - this.sxxzt = sxxzt;
157   - }
158   -
159   - public int getSpeed() {
160   - return speed;
161   - }
162   -
163   - public void setSpeed(int speed) {
164   - this.speed = speed;
165   - }
166   -
167   - public int getCsyczt() {
168   - return csyczt;
169   - }
170   -
171   - public void setCsyczt(int csyczt) {
172   - this.csyczt = csyczt;
173   - }
174   -
175   - public int getJsyczt() {
176   - return jsyczt;
177   - }
178   -
179   - public void setJsyczt(int jsyczt) {
180   - this.jsyczt = jsyczt;
181   - }
182   -
183   - public double getLon() {
184   - return lon;
185   - }
186   -
187   - public void setLon(double lon) {
188   - this.lon = lon;
189   - }
190   -
191   - public double getLat() {
192   - return lat;
193   - }
194   -
195   - public void setLat(double lat) {
196   - this.lat = lat;
197   - }
198   -
199   - public int getFx() {
200   - return fx;
201   - }
202   -
203   - public void setFx(int fx) {
204   - this.fx = fx;
205   - }
206   -
207   - public Date getFssj() {
208   - return fssj;
209   - }
210   -
211   - public void setFssj(Date fssj) {
212   - this.fssj = fssj;
213   - }
214   -
215   - public int getLxzjl() {
216   - return lxzjl;
217   - }
218   -
219   - public void setLxzjl(int lxzjl) {
220   - this.lxzjl = lxzjl;
221   - }
222   -
223   - public int getBzlcrs() {
224   - return bzlcrs;
225   - }
226   -
227   - public void setBzlcrs(int bzlcrs) {
228   - this.bzlcrs = bzlcrs;
229   - }
230   -
231   - public double getLon_old() {
232   - return lon_old;
233   - }
234   -
235   - public void setLon_old(double lon_old) {
236   - this.lon_old = lon_old;
237   - }
238   -
239   - public double getLat_old() {
240   - return lat_old;
241   - }
242   -
243   - public void setLat_old(double lat_old) {
244   - this.lat_old = lat_old;
245   - }
246   -
247   - public double getX() {
248   - return x;
249   - }
250   -
251   - public void setX(double x) {
252   - this.x = x;
253   - }
254   -
255   - public double getY() {
256   - return y;
257   - }
258   -
259   - public void setY(double y) {
260   - this.y = y;
261   - }
262   -
263   - public byte[] write() {
264   - return null;
265   - }
266   -
267   - @Override
268   - public void read(byte[] bytes) {
269   - // TODO Auto-generated method stub
270   - int idx = 0;
271   - ByteBuffer buf = ByteBuffer.wrap(bytes);
272   - mtd = ConvertUtil.ascii2string(bytes, idx, 8); idx += 8;
273   - driver = ConvertUtil.ascii2string(bytes, idx, 8); idx += 8;
274   - bczt = buf.get(idx); idx++;
275   - xlzt = buf.get(idx); idx++;
276   - xldm = Integer.parseInt(ConvertUtil.ascii2string(bytes, idx, 6).trim()); idx += 6;
277   - yyzt = buf.get(idx); idx++;
278   - jczzt = buf.get(idx); idx++;
279   - zdbh = ConvertUtil.ascii2string(bytes, idx, 8).trim(); idx += 8;
280   - jctcczt = buf.get(idx); idx++;
281   - tccbh = ConvertUtil.ascii2string(bytes, idx, 8); idx += 8;
282   - ldbh = ConvertUtil.ascii2string(bytes, idx, 12).trim(); idx += 12;
283   - sxxzt = buf.get(idx); idx++;
284   - speed = buf.get(idx)*10; idx++;
285   - csyczt = buf.get(idx); idx++;
286   - jsyczt = buf.get(idx); idx++;
287   - byte flagx = buf.get(idx); idx++;
288   - if (flagx == 0) x = ConvertUtil.bytes2int(bytes, idx, 3)/100.0;
289   - else x = -ConvertUtil.bytes2int(bytes, idx, 3)/100.0;
290   - idx += 3;
291   - byte flagy = buf.get(idx); idx++;
292   - if (flagy == 0) y = ConvertUtil.bytes2int(bytes, idx, 3)/100.0;
293   - else y = -ConvertUtil.bytes2int(bytes, idx, 3)/100.0;
294   - idx += 3;
295   - fx = buf.getShort(idx)*(short)10; idx += 2;
296   - fssj = new Date(ConvertUtil.bytes2int(bytes, idx, 4) * 1000L); idx += 4;
297   - lxzjl = buf.getShort(idx); idx += 2;
298   - bzlcrs = buf.getShort(idx); idx += 2;
299   - lon = ConvertUtil.bytes2int(bytes, idx, 4); idx += 4;
300   - lat = ConvertUtil.bytes2int(bytes, idx, 4); idx += 4;
301   - }
302   -
303   - @Override
304   - public String getDeviceId() {
305   - // TODO Auto-generated method stub
306   - return mtd;
307   - }
308   -
309   - @Override
310   - public long getTimestamp() {
311   - // TODO Auto-generated method stub
312   - return 0;
313   - }
314   -}
  1 +package com.bsth.data.gpsdata.client.pf.protocol;
  2 +
  3 +import com.bsth.data.gpsdata.client.msg.IMessageBody;
  4 +import com.bsth.data.gpsdata.client.pd.common.ConvertUtil;
  5 +
  6 +import java.nio.ByteBuffer;
  7 +import java.util.Date;
  8 +
  9 +
  10 +public class Pf_1_0 implements IMessageBody {
  11 +
  12 + /** 1、车载终端识别码-byte[8] */
  13 + private String mtd;
  14 + /** 2、司机工号-byte[8] */
  15 + private String driver;
  16 + /** 3、包车状态-byte[1] */
  17 + private int bczt;
  18 + /** 4、线路状态-byte[1] */
  19 + private int xlzt;
  20 + /** 5、线路代码-byte[6] */
  21 + private int xldm;
  22 + /** 6、营运状态-byte[1] */
  23 + private int yyzt;
  24 + /** 7、进出站状态-byte[1] */
  25 + private int jczzt;
  26 + /** 8、站点编号-byte[8] */
  27 + private String zdbh;
  28 + /** 9、进出停车场状态(0:厂内,1:厂外,2:未知)-byte[1] */
  29 + private int jctcczt;
  30 + /** 10、停车场编号-byte[8] */
  31 + private String tccbh;
  32 + /** 11、路段编码-byte[12] */
  33 + private String ldbh;
  34 + /** 12、上下行状态-byte[1] */
  35 + private int sxxzt;
  36 + /** 13、速度-byte[1] */
  37 + private int speed;
  38 + /** 14、初始异常状态-byte[1] */
  39 + private int csyczt;
  40 + /** 15、结束异常状态-byte[1] */
  41 + private int jsyczt;
  42 + /** 16、车辆位置经度(纠偏后)-byte[4] */
  43 + private double lon;
  44 + /** 17、车辆位置维度(纠偏后)-byte[4] */
  45 + private double lat;
  46 + /** 18、方向-byte[2] */
  47 + private int fx;
  48 + /** 19、发送时间-byte[4] */
  49 + private Date fssj;
  50 + /** 20、离下站距离-byte[2] */
  51 + private int lxzjl;
  52 + /** 21、本站留车人数-byte[2] */
  53 + private int bzlcrs;
  54 + /** 22、车辆位置经度(未纠偏)-byte[4] */
  55 + private double lon_old;
  56 + /** 23、车辆位置经度(未纠偏)-byte[4] */
  57 + private double lat_old;
  58 + /** 24、城建X坐标 */
  59 + private double x;
  60 + /** 25、城建Y坐标 */
  61 + private double y;
  62 +
  63 + public String getMtd() {
  64 + return mtd;
  65 + }
  66 +
  67 + public void setMtd(String mtd) {
  68 + this.mtd = mtd;
  69 + }
  70 +
  71 + public String getDriver() {
  72 + return driver;
  73 + }
  74 +
  75 + public void setDriver(String driver) {
  76 + this.driver = driver;
  77 + }
  78 +
  79 + public int getBczt() {
  80 + return bczt;
  81 + }
  82 +
  83 + public void setBczt(int bczt) {
  84 + this.bczt = bczt;
  85 + }
  86 +
  87 + public int getXlzt() {
  88 + return xlzt;
  89 + }
  90 +
  91 + public void setXlzt(int xlzt) {
  92 + this.xlzt = xlzt;
  93 + }
  94 +
  95 + public int getXldm() {
  96 + return xldm;
  97 + }
  98 +
  99 + public void setXldm(int xldm) {
  100 + this.xldm = xldm;
  101 + }
  102 +
  103 + public int getYyzt() {
  104 + return yyzt;
  105 + }
  106 +
  107 + public void setYyzt(int yyzt) {
  108 + this.yyzt = yyzt;
  109 + }
  110 +
  111 + public int getJczzt() {
  112 + return jczzt;
  113 + }
  114 +
  115 + public void setJczzt(int jczzt) {
  116 + this.jczzt = jczzt;
  117 + }
  118 +
  119 + public String getZdbh() {
  120 + return zdbh;
  121 + }
  122 +
  123 + public void setZdbh(String zdbh) {
  124 + this.zdbh = zdbh;
  125 + }
  126 +
  127 + public int getJctcczt() {
  128 + return jctcczt;
  129 + }
  130 +
  131 + public void setJctcczt(int jctcczt) {
  132 + this.jctcczt = jctcczt;
  133 + }
  134 +
  135 + public String getTccbh() {
  136 + return tccbh;
  137 + }
  138 +
  139 + public void setTccbh(String tccbh) {
  140 + this.tccbh = tccbh;
  141 + }
  142 +
  143 + public String getLdbh() {
  144 + return ldbh;
  145 + }
  146 +
  147 + public void setLdbh(String ldbh) {
  148 + this.ldbh = ldbh;
  149 + }
  150 +
  151 + public int getSxxzt() {
  152 + return sxxzt;
  153 + }
  154 +
  155 + public void setSxxzt(int sxxzt) {
  156 + this.sxxzt = sxxzt;
  157 + }
  158 +
  159 + public int getSpeed() {
  160 + return speed;
  161 + }
  162 +
  163 + public void setSpeed(int speed) {
  164 + this.speed = speed;
  165 + }
  166 +
  167 + public int getCsyczt() {
  168 + return csyczt;
  169 + }
  170 +
  171 + public void setCsyczt(int csyczt) {
  172 + this.csyczt = csyczt;
  173 + }
  174 +
  175 + public int getJsyczt() {
  176 + return jsyczt;
  177 + }
  178 +
  179 + public void setJsyczt(int jsyczt) {
  180 + this.jsyczt = jsyczt;
  181 + }
  182 +
  183 + public double getLon() {
  184 + return lon;
  185 + }
  186 +
  187 + public void setLon(double lon) {
  188 + this.lon = lon;
  189 + }
  190 +
  191 + public double getLat() {
  192 + return lat;
  193 + }
  194 +
  195 + public void setLat(double lat) {
  196 + this.lat = lat;
  197 + }
  198 +
  199 + public int getFx() {
  200 + return fx;
  201 + }
  202 +
  203 + public void setFx(int fx) {
  204 + this.fx = fx;
  205 + }
  206 +
  207 + public Date getFssj() {
  208 + return fssj;
  209 + }
  210 +
  211 + public void setFssj(Date fssj) {
  212 + this.fssj = fssj;
  213 + }
  214 +
  215 + public int getLxzjl() {
  216 + return lxzjl;
  217 + }
  218 +
  219 + public void setLxzjl(int lxzjl) {
  220 + this.lxzjl = lxzjl;
  221 + }
  222 +
  223 + public int getBzlcrs() {
  224 + return bzlcrs;
  225 + }
  226 +
  227 + public void setBzlcrs(int bzlcrs) {
  228 + this.bzlcrs = bzlcrs;
  229 + }
  230 +
  231 + public double getLon_old() {
  232 + return lon_old;
  233 + }
  234 +
  235 + public void setLon_old(double lon_old) {
  236 + this.lon_old = lon_old;
  237 + }
  238 +
  239 + public double getLat_old() {
  240 + return lat_old;
  241 + }
  242 +
  243 + public void setLat_old(double lat_old) {
  244 + this.lat_old = lat_old;
  245 + }
  246 +
  247 + public double getX() {
  248 + return x;
  249 + }
  250 +
  251 + public void setX(double x) {
  252 + this.x = x;
  253 + }
  254 +
  255 + public double getY() {
  256 + return y;
  257 + }
  258 +
  259 + public void setY(double y) {
  260 + this.y = y;
  261 + }
  262 +
  263 + public byte[] write() {
  264 + return null;
  265 + }
  266 +
  267 + @Override
  268 + public void read(byte[] bytes) {
  269 + // TODO Auto-generated method stub
  270 + int idx = 0;
  271 + ByteBuffer buf = ByteBuffer.wrap(bytes);
  272 + mtd = ConvertUtil.ascii2string(bytes, idx, 8); idx += 8;
  273 + driver = ConvertUtil.ascii2string(bytes, idx, 8); idx += 8;
  274 + bczt = buf.get(idx); idx++;
  275 + xlzt = buf.get(idx); idx++;
  276 + xldm = Integer.parseInt(ConvertUtil.ascii2string(bytes, idx, 6).trim()); idx += 6;
  277 + yyzt = buf.get(idx); idx++;
  278 + jczzt = buf.get(idx); idx++;
  279 + zdbh = ConvertUtil.ascii2string(bytes, idx, 8).trim(); idx += 8;
  280 + jctcczt = buf.get(idx); idx++;
  281 + tccbh = ConvertUtil.ascii2string(bytes, idx, 8); idx += 8;
  282 + ldbh = ConvertUtil.ascii2string(bytes, idx, 12).trim(); idx += 12;
  283 + sxxzt = buf.get(idx); idx++;
  284 + speed = buf.get(idx)*10; idx++;
  285 + csyczt = buf.get(idx); idx++;
  286 + jsyczt = buf.get(idx); idx++;
  287 + byte flagx = buf.get(idx); idx++;
  288 + if (flagx == 0) x = ConvertUtil.bytes2int(bytes, idx, 3)/100.0;
  289 + else x = -ConvertUtil.bytes2int(bytes, idx, 3)/100.0;
  290 + idx += 3;
  291 + byte flagy = buf.get(idx); idx++;
  292 + if (flagy == 0) y = ConvertUtil.bytes2int(bytes, idx, 3)/100.0;
  293 + else y = -ConvertUtil.bytes2int(bytes, idx, 3)/100.0;
  294 + idx += 3;
  295 + fx = buf.getShort(idx)*(short)10; idx += 2;
  296 + fssj = new Date(ConvertUtil.bytes2int(bytes, idx, 4) * 1000L); idx += 4;
  297 + lxzjl = buf.getShort(idx); idx += 2;
  298 + bzlcrs = buf.getShort(idx); idx += 2;
  299 + lon = ConvertUtil.bytes2int(bytes, idx, 4); idx += 4;
  300 + lat = ConvertUtil.bytes2int(bytes, idx, 4); idx += 4;
  301 + }
  302 +
  303 + @Override
  304 + public String getDeviceId() {
  305 + // TODO Auto-generated method stub
  306 + return mtd;
  307 + }
  308 +
  309 + @Override
  310 + public long getTimestamp() {
  311 + // TODO Auto-generated method stub
  312 + return 0;
  313 + }
  314 +}
... ...
src/main/java/com/bsth/data/match/Arrival2Schedule.java deleted 100644 → 0
1   -package com.bsth.data.match;
2   -
3   -import java.util.ArrayList;
4   -import java.util.Collections;
5   -import java.util.List;
6   -import java.util.Set;
7   -
8   -import org.joda.time.format.DateTimeFormat;
9   -import org.joda.time.format.DateTimeFormatter;
10   -import org.slf4j.Logger;
11   -import org.slf4j.LoggerFactory;
12   -import org.springframework.beans.BeansException;
13   -import org.springframework.context.ApplicationContext;
14   -import org.springframework.context.ApplicationContextAware;
15   -import org.springframework.stereotype.Component;
16   -
17   -import com.bsth.data.LineConfigData;
18   -import com.bsth.data.arrival.ArrivalComparator;
19   -import com.bsth.data.arrival.ArrivalData_GPS;
20   -import com.bsth.data.arrival.ArrivalEntity;
21   -import com.bsth.data.schedule.DayOfSchedule;
22   -import com.bsth.data.schedule.ScheduleComparator;
23   -import com.bsth.entity.realcontrol.LineConfig;
24   -import com.bsth.entity.realcontrol.ScheduleRealInfo;
25   -import com.bsth.service.directive.DirectiveService;
26   -import com.bsth.websocket.handler.SendUtils;
27   -import com.google.common.collect.ArrayListMultimap;
28   -
29   -/**
30   - *
31   - * @ClassName: Arrival2Schedule
32   - * @Description: TODO(到离站数据 和 计划班次进行匹配 注意线程安全!!!!)
33   - * @author PanZhao
34   - * @date 2016年8月28日 上午1:13:02
35   - *
36   - */
37   -@Component
38   -public class Arrival2Schedule implements ApplicationContextAware {
39   -
40   - private static DayOfSchedule dayOfSchedule;
41   - private static SendUtils sendUtils;
42   - private static DirectiveService directiveService;
43   - private static LineConfigData lineConfigData;
44   - private final static int ONE_MINUTE = 1000 * 60;
45   - //定一个4小时的范围,基本能对正常班次进行容错。主要防止早上停车场GPS飘导致完成晚上的进场班次
46   - private final static int FOUR_HOURS = 1000 * 60 * 60 * 4;
47   -
48   - private static Logger logger = LoggerFactory.getLogger(Arrival2Schedule.class);
49   -
50   - private static ArrayListMultimap<String, ExpectArrivalEnd> expectMap = ArrayListMultimap.create();
51   -
52   - /**
53   - *
54   - * @Title: start
55   - * @Description: TODO(开始)
56   - * @param @param cars 需要匹配的车辆集合
57   - */
58   - public static void start(Set<String> cars){
59   -
60   - for(String car : cars){
61   - new SchMatchThread(car).start();
62   - }
63   - }
64   -
65   - public static class SchMatchThread extends Thread{
66   - String nbbm;
67   - LineConfig conf;
68   -
69   - public SchMatchThread(String nbbm){
70   - this.nbbm = nbbm;
71   - }
72   -
73   - //排序器
74   - private ScheduleComparator.FCSJ schComparator = new ScheduleComparator.FCSJ();
75   - private ArrivalComparator arrComparator = new ArrivalComparator();
76   - private MatchResultComparator mrComparator = new MatchResultComparator();
77   -
78   - private static DateTimeFormatter fmtyyyyMMddHHmm = DateTimeFormat.forPattern("yyyy-MM-ddHH:mm");
79   -
80   - @Override
81   - public void run() {
82   - //班次列表
83   - List<ScheduleRealInfo> schList = dayOfSchedule.findByNbbm(nbbm);
84   - //进出起终点数据
85   - List<ArrivalEntity> arrList = ArrivalData_GPS.findByNbbm(nbbm);
86   -
87   - if(schList.size() == 0 || arrList.size() == 0)
88   - return;
89   -
90   - conf = lineConfigData.get(schList.get(0).getXlBm());
91   - //排序
92   - Collections.sort(schList, schComparator);
93   - Collections.sort(arrList, arrComparator);
94   - //过滤班次
95   - schList = matchFilter(schList);
96   -
97   - //检查并修正首班出场终点信号,可能会出现走向异常
98   - correctFirstSignal(schList, arrList);
99   -
100   -
101   - //用实际来匹配计划
102   - for(ArrivalEntity arr : arrList){
103   - match(arr, schList);
104   - }
105   - }
106   -
107   - private void match(ArrivalEntity arr, List<ScheduleRealInfo> schList) {
108   -
109   - if(arr.getInOut() == 1)
110   - matchOut(arr, schList);
111   - else if(arr.getInOut() == 0)
112   - matchIn(arr, schList);
113   - }
114   -
115   - private List<ScheduleRealInfo> matchFilter(List<ScheduleRealInfo> schList) {
116   - List<ScheduleRealInfo> list = new ArrayList<>();
117   - for(ScheduleRealInfo sch : schList){
118   - //烂班不匹配
119   - if(sch.isDestroy())
120   - continue;
121   -
122   - //线路配置出站既出场,并且没有里程的不匹配
123   - if(conf.getOutConfig()==2 && sch.getBcsj() == null && sch.getJhlc() == null)
124   - continue;
125   -
126   - list.add(sch);
127   - }
128   - return list;
129   - }
130   -
131   - private void matchOut(ArrivalEntity arr, List<ScheduleRealInfo> schList){
132   - if(arr.getFlag() == -1)
133   - return;
134   -
135   - List<MatchResult> mrs = new ArrayList<>();
136   - ScheduleRealInfo sch;
137   - MatchResult mr;
138   - for(int i = 0; i < schList.size(); i ++){
139   - sch = schList.get(i);
140   - if(!arr.isTcc() && arr.getUpDown() != Integer.parseInt(sch.getXlDir()))
141   - continue;
142   -
143   - if(!arr.getStopNo().equals(sch.getQdzCode()))
144   - continue;
145   -
146   - //班次有实发时间
147   - if(sch.getFcsjActualTime() != null){
148   - //实际发车已经被引用
149   - if(Math.abs(arr.getTs() - sch.getFcsjActualTime()) < ONE_MINUTE)
150   - return;
151   - else
152   - continue;
153   - }
154   - //添加一个匹配结果
155   - mr = new MatchResult();
156   - mr.sch = sch;
157   - mr.ts = arr.getTs();
158   - mr.diff = arr.getTs() - sch.getFcsjT();
159   - mr.success = dayOfSchedule.validStartTime(sch, arr.getTs());
160   -
161   - if(Math.abs(mr.diff) < FOUR_HOURS && mr.success)
162   - mrs.add(mr);
163   - }
164   -
165   - if(mrs.size() > 0){
166   - //排序后的第一个 就是最合适的匹配
167   - Collections.sort(mrs, mrComparator);
168   - mr = mrs.get(0);
169   -
170   - //漂移判定
171   - if(driftCheck(mr, arr)){
172   - carOut(mr);
173   - }
174   - }
175   - }
176   -
177   - private void matchIn(ArrivalEntity inArr, List<ScheduleRealInfo> schList){
178   -
179   - List<MatchResult> mrs = new ArrayList<>();
180   - ScheduleRealInfo sch;
181   - MatchResult mr;
182   - for(int i = 0; i < schList.size(); i ++){
183   - sch = schList.get(i);
184   - if(!inArr.isTcc() && inArr.getUpDown() != Integer.parseInt(sch.getXlDir()))
185   - continue;
186   -
187   - if(!inArr.getStopNo().equals(sch.getZdzCode()))
188   - continue;
189   -
190   - //班次有实达时间
191   - if(sch.getZdsjActualTime() != null){
192   - //实际到达已经被引用
193   - if(Math.abs(inArr.getTs() - sch.getZdsjActualTime()) < ONE_MINUTE)
194   - return;
195   - else
196   - continue;
197   - }
198   -
199   - //添加一个匹配结果
200   - mr = new MatchResult();
201   - mr.sch = sch;
202   - mr.ts = inArr.getTs();
203   - //班次没有里程和运送时间的
204   - if(sch.getZdsj() == null){
205   - if(i < schList.size()-1)
206   - mr.diff = inArr.getTs() - schList.get(i + 1).getDfsjT();
207   - else
208   - mr.diff = inArr.getTs() - sch.getDfsjT();
209   - }
210   - else
211   - mr.diff = inArr.getTs() - sch.getZdsjT();
212   - mr.success = dayOfSchedule.validEndTime(sch, inArr.getTs());
213   - if(Math.abs(mr.diff) < FOUR_HOURS && mr.success)
214   - mrs.add(mr);
215   - }
216   -
217   - if(mrs.size() > 0){
218   - //排序后的第一个 就是最合适的匹配
219   - Collections.sort(mrs, mrComparator);
220   - mr = mrs.get(0);
221   - carInStop(mr);
222   - }
223   - }
224   -
225   - /**
226   - *
227   - * @Title: carOut
228   - * @Description: TODO(车辆发出)
229   - */
230   - public void carOut(MatchResult mr){
231   - ScheduleRealInfo sch = mr.sch;
232   -
233   - if(!isExpectOut(mr))
234   - return;
235   - //设置发车时间
236   - sch.setFcsjActualAll(mr.ts);
237   - //通知客户端
238   - sendUtils.sendFcsj(sch);
239   - //持久化
240   - dayOfSchedule.save(sch);
241   - //车辆当前执行班次
242   - dayOfSchedule.addExecPlan(sch);
243   -
244   - //期望车辆到达的终点
245   - if(sch.getZdsj() != null)
246   - expectMap.put(nbbm, ExpectArrivalEnd.getEndInstance(sch, mr.ts));
247   - }
248   -
249   - /**
250   - *
251   - * @Title: isExpectOut
252   - * @Description: TODO(是否是一个期望的出站匹配结果)
253   - */
254   - private boolean isExpectOut(MatchResult mr){
255   - ScheduleRealInfo sch = mr.sch;
256   - String nbbm = sch.getClZbh();
257   - if(expectMap.containsKey(nbbm)){
258   - List<ExpectArrivalEnd> eads = expectMap.get(nbbm);
259   - for(ExpectArrivalEnd ead : eads){
260   - if(sch.getQdzCode().equals(ead.getEndStation())
261   - || mr.ts > ead.getEndTime()){
262   - expectMap.removeAll(nbbm);
263   - return true;
264   - }
265   - }
266   - return false;
267   - }
268   - return true;
269   - }
270   -
271   - /**
272   - *
273   - * @Title: carInStop
274   - * @Description: TODO(车辆进入终点站)
275   - */
276   - public void carInStop(MatchResult mr){
277   - ScheduleRealInfo sch = mr.sch;
278   - String nbbm=sch.getClZbh();
279   - if(!isExpectIn(mr))
280   - return;
281   -
282   - //如果是进停车场,并且实达时间差值大于 30 分钟,并且之前还有未完成班次。
283   - if(sch.getBcType().equals("in") && Math.abs(mr.diff) > (1000 * 60 * 30)){
284   - int prve_nen = dayOfSchedule.prveNotExecNum(sch);
285   - if(prve_nen > 0)
286   - return;
287   - }
288   -
289   - sch.setZdsjActualAll(mr.ts);
290   - int doneSum = dayOfSchedule.doneSum(nbbm);
291   - ScheduleRealInfo next = dayOfSchedule.next(sch);
292   - if(null != next){
293   - next.setQdzArrDateSJ(sch.getZdsjActual());
294   - //下发调度指令
295   - directiveService.send60Dispatch(next, doneSum, "到站@系统");
296   -
297   - //完成“起点既停车场”的进场班次
298   - if(next.getBcType().equals("in") && next.getJhlc() == null)
299   - next.setFcsjActualAll(mr.ts);
300   -
301   - //套跑 -下发线路切换指令
302   - if(!next.getXlBm().equals(sch.getXlBm()))
303   - directiveService.lineChange(nbbm, next.getXlBm(), "套跑@系统");
304   - }
305   - else//下发文本指令(已结束运营)
306   - directiveService.send60Phrase(nbbm, "到达终点 " + sch.getZdzName() + ",已完成当日所有排班。", "系统");
307   - //通知客户端
308   - sendUtils.sendZdsj(sch, next, doneSum);
309   - //持久化
310   - dayOfSchedule.save(sch);
311   - logger.info(sch.getClZbh() + "移除正在执行班次," + sch.getFcsj());
312   - //移除车辆正在执行班次索引
313   - dayOfSchedule.removeExecPlan(nbbm);
314   - }
315   -
316   - /**
317   - *
318   - * @Title: isExpectOut
319   - * @Description: TODO(是否是一个期望的进站匹配结果)
320   - */
321   - private boolean isExpectIn(MatchResult mr){
322   - ScheduleRealInfo sch = mr.sch;
323   - String nbbm = sch.getClZbh();
324   - if(expectMap.containsKey(nbbm)){
325   - List<ExpectArrivalEnd> eads = expectMap.get(nbbm);
326   - for(ExpectArrivalEnd ead : eads){
327   - if(sch.getZdzCode().equals(ead.getEndStation())
328   - || mr.ts > ead.getEndTime()){
329   - expectMap.removeAll(nbbm);
330   - return true;
331   - }
332   - }
333   - return false;
334   - }
335   - return true;
336   - }
337   -
338   - /**
339   - *
340   - * @Title: correctFirstSignal
341   - * @Description: TODO(检查并纠正首班出场到离站)
342   - */
343   - private final static long TEN_MINUTES = 1000 * 60 * 10;
344   - private void correctFirstSignal(List<ScheduleRealInfo> schList, List<ArrivalEntity> arrList) {
345   - ScheduleRealInfo sch = schList.get(0);
346   - ArrivalEntity arr = arrList.get(0);
347   -
348   - //有里程的出场班次才需要纠正
349   - if(arr.isCorrect() || !sch.getBcType().equals("out") || sch.getJhlc() == null || sch.getBcsj() == null)
350   - return;
351   -
352   - //如果首个进出站信号是出场
353   - if(arr.isOutTcc() && arrList.size() >= 2)
354   - arr = arrList.get(1);
355   - else
356   - return;
357   -
358   - //出场任务 “进终点” 信号才需要纠正
359   - if(arr.getInOut() != 0)
360   - return;
361   -
362   - //在计划终点之前到达,或者之后10分钟内到达
363   - if(arr.getTs() < sch.getZdsjT()
364   - || arr.getTs() - sch.getZdsjT() < TEN_MINUTES){
365   -
366   - int upDown = Integer.parseInt(sch.getXlDir());
367   - //走向不一致,相信班次的走向。纠正进站信号
368   - if(arr.getUpDown() != upDown
369   - && arr.getStopName().equals(sch.getZdzName())){
370   -
371   -
372   - String old = arr.toString();
373   - arr.setUpDown(upDown);
374   - arr.setStopNo(sch.getZdzCode());
375   - arr.setCorrect(true);
376   - arr.setCorrectText(old + " | " + arr.toString());
377   -
378   - logger.info("被纠正的信号:" + arr.getCorrectText());
379   - }
380   - }
381   - }
382   -
383   - /**
384   - *
385   - * @Title: driftCheck
386   - * @Description: TODO(漂移判定)
387   - */
388   - public boolean driftCheck(MatchResult mr, ArrivalEntity arr){
389   - try{
390   - //上行发车,和到达时间比较一下。起点一般不会立即发出
391   - if(mr.sch.getXlDir().equals("0")
392   - && null != mr.sch.getQdzArrDateSJ()){
393   -
394   -
395   - long dt = fmtyyyyMMddHHmm.parseMillis(mr.sch.getRealExecDate() + mr.sch.getQdzArrDateSJ());
396   -
397   - //停站时间少于 计划的3分之1,标记为漂移信号
398   - if((mr.ts - dt < (mr.sch.getDfsjT() - dt) / 3)){
399   - arr.setCorrect(true);
400   - arr.setCorrectText("停站时间太短,标记为信号漂移");
401   - arr.setFlag(-1);
402   -
403   - logger.info("漂移判定:" + arr);
404   - return false;
405   - }
406   - }
407   - }catch(Exception e){
408   - logger.error("", e);
409   - }
410   - return true;
411   - }
412   - }
413   -
414   - @Override
415   - public void setApplicationContext(ApplicationContext arg0) throws BeansException {
416   - sendUtils = arg0.getBean(SendUtils.class);
417   - dayOfSchedule = arg0.getBean(DayOfSchedule.class);
418   - directiveService = arg0.getBean(DirectiveService.class);
419   - lineConfigData = arg0.getBean(LineConfigData.class);
420   - }
421   -
422   - /**
423   - *
424   - * @Title: removeExpect
425   - * @Description: TODO(清除预期站点)
426   - * @param @param nbbm
427   - */
428   - public void removeExpect(String nbbm){
429   - expectMap.removeAll(nbbm);
430   - }
431   -
432   - public static void addExpect(String nbbm, ExpectArrivalEnd eae){
433   - expectMap.put(nbbm, eae);
434   - }
435   -}
src/main/java/com/bsth/data/match/ExpectArrivalEnd.java deleted 100644 → 0
1   -package com.bsth.data.match;
2   -
3   -import com.bsth.entity.realcontrol.ScheduleRealInfo;
4   -
5   -/**
6   - *
7   - * @ClassName: ExpectArrivalEnd
8   - * @Description: TODO(期望车辆在某个时间段到达某个终点或 发出某个起点........)
9   - * @author PanZhao
10   - * @date 2016年11月2日 下午8:04:43
11   - *
12   - */
13   -public class ExpectArrivalEnd {
14   -
15   - private String nbbm;
16   -
17   - private String endStation;
18   -
19   - private Long endTime;
20   -
21   - public static ExpectArrivalEnd getEndInstance(ScheduleRealInfo sch, long t){
22   - ExpectArrivalEnd ead = new ExpectArrivalEnd();
23   - ead.setNbbm(sch.getClZbh());
24   - ead.setEndStation(sch.getZdzCode());
25   - if(sch.getBcType().equals("out"))
26   - ead.setEndTime(sch.getZdsjT());
27   - else{
28   - ead.setEndTime(sch.getZdsjT() - (sch.getDfsjT() - t));
29   - }
30   - return ead;
31   - }
32   -
33   -
34   - public String getNbbm() {
35   - return nbbm;
36   - }
37   -
38   - public void setNbbm(String nbbm) {
39   - this.nbbm = nbbm;
40   - }
41   -
42   - public String getEndStation() {
43   - return endStation;
44   - }
45   -
46   - public void setEndStation(String endStation) {
47   - this.endStation = endStation;
48   - }
49   -
50   - public Long getEndTime() {
51   - return endTime;
52   - }
53   -
54   - public void setEndTime(Long endTime) {
55   - this.endTime = endTime;
56   - }
57   -}
src/main/java/com/bsth/data/match/MatchResult.java deleted 100644 → 0
1   -package com.bsth.data.match;
2   -
3   -import com.bsth.entity.realcontrol.ScheduleRealInfo;
4   -
5   -/**
6   - *
7   - * @ClassName: MatchResult
8   - * @Description: TODO(实际和计划匹配结果)
9   - * @author PanZhao
10   - * @date 2016年8月10日 下午3:55:48
11   - *
12   - */
13   -public class MatchResult {
14   -
15   - /** 班次 */
16   - public ScheduleRealInfo sch;
17   -
18   - /** 时间差 */
19   - public long diff;
20   -
21   - /** 0 进 1 出 */
22   - public int inOut;
23   -
24   - public long ts;
25   -
26   - /** 交配成功 */
27   - public boolean success;
28   -}
src/main/java/com/bsth/data/match/MatchResultComparator.java deleted 100644 → 0
1   -package com.bsth.data.match;
2   -
3   -import java.util.Comparator;
4   -
5   -public class MatchResultComparator implements Comparator<MatchResult>{
6   -
7   - @Override
8   - public int compare(MatchResult o1, MatchResult o2) {
9   - return (int) (Math.abs(o1.diff) - Math.abs(o2.diff));
10   - }
11   -}
src/main/java/com/bsth/data/schedule/DayOfSchedule.java
... ... @@ -1023,4 +1023,8 @@ public class DayOfSchedule implements CommandLineRunner {
1023 1023 Collections.sort(list, schFCSJComparator);
1024 1024 return next(list, sch);
1025 1025 }
  1026 +
  1027 + public ArrayListMultimap<String, ScheduleRealInfo> getLpScheduleMap(){
  1028 + return lpScheduleMap;
  1029 + }
1026 1030 }
1027 1031 \ No newline at end of file
... ...
src/main/java/com/bsth/entity/forecast/Sample.java
1 1 package com.bsth.entity.forecast;
2 2  
3 3  
4   -import java.text.SimpleDateFormat;
5   -import java.util.Date;
6   -
7   -import javax.persistence.Entity;
8   -import javax.persistence.GeneratedValue;
9   -import javax.persistence.Id;
10   -import javax.persistence.Table;
11   -import javax.persistence.Transient;
12   -
  4 +import com.bsth.data.forecast.entity.ArrivalEntity;
13 5 import org.slf4j.Logger;
14 6 import org.slf4j.LoggerFactory;
15 7  
16   -import com.bsth.data.arrival.ArrivalEntity;
  8 +import javax.persistence.*;
17 9  
18 10 /**
19 11 *
... ...
src/main/java/com/bsth/entity/realcontrol/ScheduleRealInfo.java
... ... @@ -200,6 +200,10 @@ public class ScheduleRealInfo {
200 200 /** 是否有补发GPS信号 */
201 201 private boolean reissue;
202 202  
  203 + /** 发车屏 发车顺序号,不持久化,会动态变化 */
  204 + @Transient
  205 + private int fcpSn;
  206 +
203 207 public boolean isDfAuto() {
204 208 return dfAuto;
205 209 }
... ... @@ -912,4 +916,12 @@ public class ScheduleRealInfo {
912 916 public void setLate2(boolean late2) {
913 917 this.late2 = late2;
914 918 }
  919 +
  920 + public int getFcpSn() {
  921 + return fcpSn;
  922 + }
  923 +
  924 + public void setFcpSn(int fcpSn) {
  925 + this.fcpSn = fcpSn;
  926 + }
915 927 }
... ...
src/main/java/com/bsth/repository/LineRepository.java
... ... @@ -38,4 +38,7 @@ public interface LineRepository extends BaseRepository&lt;Line, Integer&gt; {
38 38 List<Line> findLine(String line);
39 39  
40 40 public Line findByLineCode(String string);
  41 +
  42 + @Query(value = " SELECT l FROM Line l where l.company like ?1 and l.brancheCompany like ?2 and l.lineCode like ?3")
  43 + public List<Line> findLineBygsBm(String gsBm, String fgsBm, String line);
41 44 }
... ...
src/main/java/com/bsth/repository/oil/CdlRepository.java
... ... @@ -15,8 +15,6 @@ import com.bsth.repository.BaseRepository;
15 15  
16 16 @Repository
17 17 public interface CdlRepository extends BaseRepository<Cdl, Integer>{
18   - @Transactional
19   - @Modifying
20 18 @Query(value="SELECT * FROM bsth_c_cdl ",nativeQuery=true)
21 19 List<Cdl> obtainCdl();
22 20 }
... ...
src/main/java/com/bsth/repository/oil/CwjyRepository.java
... ... @@ -20,8 +20,6 @@ public interface CwjyRepository extends BaseRepository&lt;Cwjy, Integer&gt;{
20 20 * @param rq
21 21 * @return
22 22 */
23   - @Transactional
24   - @Modifying
25 23 @Query(value="SELECT a.gsdm as gsdm,a.nbbm as nbbm,b.jsy as jsy,b.jzl as jzl ,b.stationid as stationid,"
26 24 + "b.nylx as nylx,b.yj as yj,b.bz as bz,c.jsy as ldgh FROM bsth_c_cwjy a "+
27 25 " left join ( select * from bsth_c_ylxxb b where to_days(b.yyrq)=to_days(?1) and jylx=1) b " +
... ...
src/main/java/com/bsth/repository/oil/CylRepository.java
... ... @@ -13,8 +13,6 @@ import com.bsth.repository.BaseRepository;
13 13  
14 14 @Repository
15 15 public interface CylRepository extends BaseRepository<Cyl, Integer>{
16   - @Transactional
17   - @Modifying
18 16 @Query(value="SELECT * FROM bsth_c_cyl where nbbm like %?1% and gsdm like %?2%",nativeQuery=true)
19 17 List<Cyl> obtainCyl(String nbbm,String gsdm);
20 18 }
... ...
src/main/java/com/bsth/repository/oil/DlbRepository.java
... ... @@ -18,8 +18,6 @@ public interface DlbRepository extends BaseRepository&lt;Dlb, Integer&gt;{
18 18 * @param rq
19 19 * @return
20 20 */
21   - @Transactional
22   - @Modifying
23 21 @Query(value="SELECT a.* FROM bsth_c_dlb a where to_days(?1)-to_days(a.rq)=1"
24 22 + " and jcsx=(select max(b.jcsx) from bsth_c_dlb b where a.nbbm=b.nbbm and "
25 23 + " to_days(?1)-to_days(b.rq)=1 ) and ssgsdm like %?2% and fgsdm like %?3% and "
... ... @@ -30,8 +28,6 @@ public interface DlbRepository extends BaseRepository&lt;Dlb, Integer&gt;{
30 28 * @param rq
31 29 * @return
32 30 */
33   - @Transactional
34   - @Modifying
35 31 @Query(value="SELECT * FROM bsth_c_dlb where to_days(?1)=to_days(rq) and ssgsdm like %?2% "
36 32 + " and fgsdm like %?3%"
37 33 + " and xlbm like %?4% and nbbm like %?5% order by ?6 asc",nativeQuery=true)
... ... @@ -53,8 +49,6 @@ public interface DlbRepository extends BaseRepository&lt;Dlb, Integer&gt;{
53 49 * @param xlbm
54 50 * @return
55 51 */
56   - @Transactional
57   - @Modifying
58 52 @Query(value="select nbbm,count(nbbm) from bsth_c_dlb where to_days(?1)=to_days(rq) and "
59 53 + " ssgsdm like %?2% "
60 54 + " and fgsdm like %?3%"
... ... @@ -62,8 +56,6 @@ public interface DlbRepository extends BaseRepository&lt;Dlb, Integer&gt;{
62 56 + " group by nbbm,rq,ssgsdm,fgsdm,xlbm",nativeQuery=true)
63 57 List<Object[]> checkNbmmNum(String rq, String gsbm,String fgsbm,String xlbm,String nbbm);
64 58  
65   - @Transactional
66   - @Modifying
67 59 @Query(value="select nbbm,sum(cdl*100) as cdl ,sum(zlc*100) as zlc from bsth_c_dlb where to_days(?1)=to_days(rq) and "
68 60 + " ssgsdm like %?2% "
69 61 + " and fgsdm like %?3%"
... ... @@ -81,8 +73,6 @@ public interface DlbRepository extends BaseRepository&lt;Dlb, Integer&gt;{
81 73 + " and s.nbbm in ?5 ")
82 74 List<Object[]> sumDlb(String rq, String gsbm,String fgsbm,String xlbm,List<String> listNbbm);
83 75  
84   - @Transactional
85   - @Modifying
86 76 @Query(value="select ifnull(cdl,0),ifnull(hd,0),ifnull(sh,0) from bsth_c_dlb "
87 77 + " where to_days(?1)=to_days(rq) "
88 78 + " and ssgsdm like %?2% "
... ... @@ -92,8 +82,6 @@ public interface DlbRepository extends BaseRepository&lt;Dlb, Integer&gt;{
92 82 List<Object[]> sumDlb2(String rq, String gsbm,String fgsbm,String xlbm,String nbbm);
93 83  
94 84  
95   - @Transactional
96   - @Modifying
97 85 @Query(value="UPDATE bsth_c_dlb SET " +
98 86 " czcd= ?2,"+
99 87 " jzcd = ?3, " +
... ...
src/main/java/com/bsth/repository/oil/JdlRepository.java
... ... @@ -22,24 +22,16 @@ public interface JdlRepository extends BaseRepository&lt;Jdl, Integer&gt;{
22 22 "?1,?2,?3,?4,str_to_date(?5,'%Y-%m-%d'),?6,?7,?8,?9,str_to_date(?10,'%Y-%m-%d %H:%i:%s'))", nativeQuery=true)
23 23 void insertData(String gsbm, String gsName, String fgsbm, String fgsName, String rq, String nbbm, String jdl, String jdz, String remarks, String createrDate);
24 24  
25   - @Transactional
26   - @Modifying
27 25 @Query(value="SELECT * FROM bsth_c_jdl where gs_bm = ?1 and fgs_bm = ?2 and rq = ?3 and nbbm like %?4%",nativeQuery=true)
28 26 List<Jdl> query(String gsbm, String fgsbm, String rq, String nbbm);
29 27  
30 28  
31   - @Transactional
32   - @Modifying
33 29 @Query(value="SELECT * FROM bsth_c_jdl where rq = ?",nativeQuery=true)
34 30 List<Jdl> JdlList( String rq);
35 31  
36   - @Transactional
37   - @Modifying
38 32 @Query(value="SELECT jdl FROM bsth_c_jdl where gs_bm = ?1 and fgs_bm = ?2 and rq = ?3 and nbbm = ?4 and jdz = ?5",nativeQuery=true)
39 33 List<Double> queryBySame(String gsbm, String fgsbm, String rq, String nbbm, String jdz);
40 34  
41   - @Transactional
42   - @Modifying
43 35 @Query(value="UPDATE bsth_c_jdl set jdl = ?1 where gs_bm = ?2 and fgs_bm = ?3 and rq = ?4 and nbbm = ?5 and jdz = ?6",nativeQuery=true)
44 36 void UpdateJdl(String jdl, String gsbm, String fgsbm, String rq, String nbbm, String jdz);
45 37  
... ...
src/main/java/com/bsth/repository/oil/YlbRepository.java
... ... @@ -19,8 +19,6 @@ public interface YlbRepository extends BaseRepository&lt;Ylb, Integer&gt;{
19 19 * @param rq
20 20 * @return
21 21 */
22   - @Transactional
23   - @Modifying
24 22 @Query(value="SELECT a.* FROM bsth_c_ylb a where to_days(?1)-to_days(a.rq)=1"
25 23 + " and jcsx=(select max(b.jcsx) from bsth_c_ylb b where a.nbbm=b.nbbm and "
26 24 + " to_days(?1)-to_days(b.rq)=1 ) and ssgsdm like %?2% and fgsdm like %?3% and "
... ... @@ -32,8 +30,6 @@ public interface YlbRepository extends BaseRepository&lt;Ylb, Integer&gt;{
32 30 * 获取当天日期前的最大的日期中最大进出顺序的数据
33 31 *
34 32 */
35   - @Transactional
36   - @Modifying
37 33 @Query(value="select y.* from (select max(d.id) as id ,d.nbbm from ("
38 34 + " select b.rq,b.nbbm,max(b.jcsx) as jcsx from ("
39 35 + " select max(t.rq) as rq ,t.nbbm from bsth_c_ylb t "
... ... @@ -55,21 +51,15 @@ public interface YlbRepository extends BaseRepository&lt;Ylb, Integer&gt;{
55 51 * @param rq
56 52 * @return
57 53 */
58   - @Transactional
59   - @Modifying
60 54 @Query(value="SELECT * FROM bsth_c_ylb where to_days(?1)=to_days(rq) and ssgsdm like %?2% "
61 55 + " and fgsdm like %?3%"
62 56 + " and xlbm like %?4% and nbbm like %?5% order by ?6 asc ",nativeQuery=true)
63 57 List<Ylb> obtainYl(String rq,String gsdm,String fgsdm,String xlbm,String nbbm,String px);
64 58  
65 59  
66   - @Transactional
67   - @Modifying
68 60 @Query(value="SELECT * FROM bsth_c_ylb where to_days(?1)=to_days(rq) and nbbm =?2 and jsy=?3 ",nativeQuery=true)
69 61 List<Ylb> queryListYlb(String rq,String nbbm,String jgh);
70 62  
71   - @Transactional
72   - @Modifying
73 63 @Query(value="SELECT * FROM bsth_c_ylb where to_days(?1)=to_days(rq) and nbbm =?2 and jsy=?3 and xlbm=?4 order by ?5 asc",nativeQuery=true)
74 64 List<Ylb> checkYlb(String rq,String nbbm,String jgh,String xlbm,String px);
75 65 /**
... ... @@ -77,8 +67,6 @@ public interface YlbRepository extends BaseRepository&lt;Ylb, Integer&gt;{
77 67 * @param rq
78 68 * @return
79 69 */
80   - @Transactional
81   - @Modifying
82 70 @Query(value="select ifnull(jzl,0),ifnull(zlc,0),ifnull(sh,0) from bsth_c_ylb where nbbm=?1 and rq=?2 and xlbm like %?3% and ssgsdm like %?4% and fgsdm like %?5%",nativeQuery=true)
83 71 List<Object[]> sumLcYl(String nbbm,Date rq,String xlbm,String fgsbm,String gsbm);
84 72  
... ... @@ -89,8 +77,6 @@ public interface YlbRepository extends BaseRepository&lt;Ylb, Integer&gt;{
89 77 * @param xlbm
90 78 * @return
91 79 */
92   - @Transactional
93   - @Modifying
94 80 @Query(value="select nbbm,count(nbbm) from bsth_c_ylb where to_days(?1)=to_days(rq) and "
95 81 + " ssgsdm like %?2% "
96 82 + " and fgsdm like %?3%"
... ... @@ -124,8 +110,6 @@ public interface YlbRepository extends BaseRepository&lt;Ylb, Integer&gt;{
124 110 + " and s.nbbm in ?5 ")
125 111 List<Object[]> sumYlb(String rq, String gsbm,String fgsbm,String xlbm,List<String> listNbbm);
126 112  
127   - @Transactional
128   - @Modifying
129 113 @Query(value="select ifnull(jzl,0),ifnull(yh,0),ifnull(sh,0) from bsth_c_ylb "
130 114 + " where to_days(?1)=to_days(rq) "
131 115 + " and ssgsdm like %?2% "
... ...
src/main/java/com/bsth/repository/oil/YlxxbRepository.java
... ... @@ -17,23 +17,15 @@ public interface YlxxbRepository extends BaseRepository&lt;Ylxxb, Integer&gt;{
17 17 * @param rq
18 18 * @return
19 19 */
20   - @Transactional
21   - @Modifying
22 20 @Query(value="SELECT * FROM bsth_c_ylxxb where to_days(?1)=to_days(yyrq) and nylx=?2 and gsdm like %?3%",nativeQuery=true)
23 21 List<Ylxxb> obtainYlxx(String rq,int nylx,String gsdm);
24 22  
25   - @Transactional
26   - @Modifying
27 23 @Query(value="SELECT * FROM bsth_c_ylxxb where to_days(?1)=to_days(yyrq) and ssgs=?2",nativeQuery=true)
28 24 List<Ylxxb> checkYlxx(String rq,String gs);
29 25  
30   - @Transactional
31   - @Modifying
32 26 @Query(value="SELECT * FROM bsth_c_ylxxb where to_days(?1)=to_days(yyrq) and nbbm =?2 and jylx=1",nativeQuery=true)
33 27 List<Ylxxb> obtainYlxx2(String rq,String nbbm);
34 28  
35   - @Transactional
36   - @Modifying
37 29 @Query(value="select * from bsth_c_ylxxb s where s.nbbm = ?1 and "
38 30 + "to_days(s.yyrq) = to_days(?2)",nativeQuery=true)
39 31 List<Ylxxb> queryListYlxxb(String clZbh,String date);
... ...
src/main/java/com/bsth/service/forecast/SampleServiceImpl.java
1 1 package com.bsth.service.forecast;
2 2  
3   -import java.text.SimpleDateFormat;
4   -import java.util.ArrayList;
5   -import java.util.Collections;
6   -import java.util.Comparator;
7   -import java.util.HashMap;
8   -import java.util.Iterator;
9   -import java.util.List;
10   -import java.util.Map;
11   -
12   -import javax.transaction.Transactional;
13   -
14   -import org.slf4j.Logger;
15   -import org.slf4j.LoggerFactory;
16   -import org.springframework.beans.factory.annotation.Autowired;
17   -import org.springframework.stereotype.Service;
18   -
19 3 import com.bsth.common.ResponseCode;
20 4 import com.bsth.controller.forecast.dto.CreateSampleParam;
21 5 import com.bsth.data.BasicData;
22   -import com.bsth.data.arrival.ArrivalEntity;
23   -import com.bsth.data.arrival.DataLoader;
  6 +import com.bsth.data.forecast.ArrivalDataLoader;
  7 +import com.bsth.data.forecast.entity.ArrivalEntity;
24 8 import com.bsth.entity.forecast.Sample;
25 9 import com.bsth.repository.forecast.SampleRepository;
26 10 import com.bsth.service.forecast.util.CreateByArrivalData;
27 11 import com.bsth.service.impl.BaseServiceImpl;
  12 +import org.slf4j.Logger;
  13 +import org.slf4j.LoggerFactory;
  14 +import org.springframework.beans.factory.annotation.Autowired;
  15 +import org.springframework.stereotype.Service;
  16 +
  17 +import javax.transaction.Transactional;
  18 +import java.text.SimpleDateFormat;
  19 +import java.util.*;
28 20  
29 21 @Service
30 22 public class SampleServiceImpl extends BaseServiceImpl<Sample, Long> implements SampleService{
... ... @@ -80,7 +72,7 @@ public class SampleServiceImpl extends BaseServiceImpl&lt;Sample, Long&gt; implements
80 72 sampleRepository.deleteByLineAndUpdown(param.getLineCode(), param.getUpdown());
81 73  
82 74 //查询到离站数据
83   - DataLoader loader = new DataLoader();
  75 + ArrivalDataLoader loader = new ArrivalDataLoader();
84 76 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
85 77  
86 78 long st = sdf.parse(param.getStartDate()).getTime()
... ...
src/main/java/com/bsth/service/forecast/util/CreateByArrivalData.java
1 1 package com.bsth.service.forecast.util;
2 2  
3   -import java.text.DecimalFormat;
4   -import java.text.ParseException;
5   -import java.text.SimpleDateFormat;
6   -import java.util.ArrayList;
7   -import java.util.Collections;
8   -import java.util.Comparator;
9   -import java.util.Date;
10   -import java.util.HashMap;
11   -import java.util.List;
12   -import java.util.Map;
13   -import java.util.Set;
14   -
15   -import org.slf4j.Logger;
16   -import org.slf4j.LoggerFactory;
17   -import org.springframework.beans.factory.annotation.Autowired;
18   -import org.springframework.context.annotation.Scope;
19   -import org.springframework.stereotype.Component;
20   -
21 3 import com.bsth.controller.forecast.dto.CreateSampleParam;
22 4 import com.bsth.controller.forecast.dto.CreateSampleParam.TimeRange;
23   -import com.bsth.data.arrival.ArrivalComparator;
24   -import com.bsth.data.arrival.ArrivalEntity;
  5 +import com.bsth.data.forecast.ArrivalComparator;
  6 +import com.bsth.data.forecast.entity.ArrivalEntity;
25 7 import com.bsth.entity.StationRoute;
26 8 import com.bsth.entity.forecast.Sample;
27 9 import com.bsth.repository.StationRouteRepository;
28 10 import com.google.common.collect.ArrayListMultimap;
  11 +import org.slf4j.Logger;
  12 +import org.slf4j.LoggerFactory;
  13 +import org.springframework.beans.factory.annotation.Autowired;
  14 +import org.springframework.context.annotation.Scope;
  15 +import org.springframework.stereotype.Component;
  16 +
  17 +import java.text.DecimalFormat;
  18 +import java.text.ParseException;
  19 +import java.text.SimpleDateFormat;
  20 +import java.util.*;
29 21  
30 22 /**
31 23 *
... ...
src/main/java/com/bsth/service/forms/FormsService.java
... ... @@ -35,7 +35,7 @@ public interface FormsService {
35 35  
36 36 public List<Operationservice> operationservice(Map<String, Object> map);
37 37  
38   - public List<Turnoutrate> turnoutrate(Map<String, Object> map);
  38 + public List<Map<String, Object>> turnoutrate(Map<String, Object> map);
39 39  
40 40 public List<Executionrate> executionrate(Map<String, Object> map);
41 41  
... ...
src/main/java/com/bsth/service/forms/impl/FormsServiceImpl.java
... ... @@ -9,14 +9,17 @@ import java.text.SimpleDateFormat;
9 9 import java.util.ArrayList;
10 10 import java.util.Date;
11 11 import java.util.HashMap;
  12 +import java.util.HashSet;
12 13 import java.util.List;
13 14 import java.util.Map;
  15 +import java.util.Set;
14 16  
15 17 import org.springframework.beans.factory.annotation.Autowired;
16 18 import org.springframework.jdbc.core.JdbcTemplate;
17 19 import org.springframework.jdbc.core.RowMapper;
18 20 import org.springframework.stereotype.Service;
19 21  
  22 +import com.bsth.entity.Line;
20 23 import com.bsth.entity.mcy_forms.Linepasswengerflow;
21 24 import com.bsth.entity.mcy_forms.Operationservice;
22 25 import com.bsth.entity.mcy_forms.Shifday;
... ... @@ -27,6 +30,8 @@ import com.bsth.entity.mcy_forms.Vehicleloading;
27 30 import com.bsth.entity.mcy_forms.Waybillday;
28 31 import com.bsth.entity.oil.Ylb;
29 32 import com.bsth.entity.realcontrol.ScheduleRealInfo;
  33 +import com.bsth.entity.schedule.SchedulePlanInfo;
  34 +import com.bsth.repository.LineRepository;
30 35 import com.bsth.repository.oil.YlbRepository;
31 36 import com.bsth.repository.realcontrol.ScheduleRealInfoRepository;
32 37 import com.bsth.data.BasicData;
... ... @@ -60,6 +65,10 @@ public class FormsServiceImpl implements FormsService {
60 65  
61 66 @Autowired
62 67 YlbRepository ylbRepository;
  68 +
  69 + @Autowired
  70 + LineRepository lineRepository;
  71 +
63 72  
64 73 // 行车路单日报表
65 74 @Override
... ... @@ -734,11 +743,13 @@ public class FormsServiceImpl implements FormsService {
734 743  
735 744 // 营运线路出车率统计表
736 745 @Override
737   - public List<Turnoutrate> turnoutrate(Map<String, Object> map) {
  746 + public List<Map<String, Object>> turnoutrate(Map<String, Object> map) {
738 747  
739   - List<Turnoutrate> resList = new ArrayList<Turnoutrate>();
  748 + List<Map<String, Object>> resList = new ArrayList<Map<String, Object>>();
740 749 SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
741 750 SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy年MM月dd日");
  751 + NumberFormat numberFormat = NumberFormat.getInstance();
  752 + numberFormat.setMaximumFractionDigits(2);
742 753 Date d = null;
743 754 Date d1 = null;
744 755 try {
... ... @@ -750,68 +761,134 @@ public class FormsServiceImpl implements FormsService {
750 761 }
751 762 String rq2 = sdf1.format(d);
752 763 String rq3 = sdf1.format(d1);
  764 + String company = map.get("gsdmTurn").toString();
  765 + String subCompany = map.get("fgsdmTurn").toString();
  766 + String line = map.get("line").toString();
  767 + String startDate = map.get("startDate").toString();
  768 + String endDate = map.get("endDate").toString();
753 769  
754 770 rq = rq2 + "-" + rq3;
755 771  
756   - String sql = " select b.xlgs, a.gs_bm,a.gs_name, a.fgs_bm,a.fgs_name , a.xl_bm,b.sbc,b.sxl,b.scl,a.jbc ,a.jxl ,a.jcl,a.gslsbm,a.fgsbm,b.warrant_car,a.bc_type from "
757   - + " (select count(DISTINCT gs_bm) gslsbm, gs_bm, count(DISTINCT fgs_bm) fgsbm,fgs_bm,gs_name,fgs_name ,xl_bm, count(*) as jbc,COUNT(DISTINCT xl_bm) as jxl ,COUNT(DISTINCT cl_zbh) as jcl,bc_type"
758   - + " from bsth_c_s_sp_info" + " where DATE_FORMAT(schedule_date,'%Y-%m-%d') BETWEEN '"+ map.get("startDate").toString() + "' "
759   - + " and '" + map.get("endDate").toString() + "' and xl_bm='"+ map.get("line").toString() + "' "
760   - + " AND gs_bm is not null "
761   - + " AND bc_type NOT IN ('in', 'out')"
762   - + " and gs_bm='"+ map.get("gsdmTurn").toString() + "'"
763   - + " and fgs_bm='"+ map.get("fgsdmTurn").toString() + "'"
764   -// + " GROUP BY gs_bm,fgs_bm,xl_bm,gs_name,fgs_name,bc_type "
765   - + " ) a left JOIN ("
766   - + " SELECT COUNT(*) as xlgs,b.gs_bm,b.fgs_bm,b.xl_bm,b.gs_name,b.fgs_name, b.sbc,b.sxl ,b.scl,t.warrant_car "
767   - + " from bsth_c_line t RIGHT JOIN (select gs_bm,fgs_bm,xl_bm,gs_name,fgs_name, count(*) as sbc,COUNT(DISTINCT xl_bm) as sxl ,COUNT(DISTINCT cl_zbh) as scl,bc_type from bsth_c_s_sp_info_real "
768   - + " where DATE_FORMAT(schedule_date,'%Y-%m-%d') BETWEEN '" + map.get("startDate").toString() + "' and '"
769   - + map.get("endDate").toString() + "' and xl_bm='" + map.get("line").toString()
770   - + "' AND gs_bm is not null "
771   - + " AND bc_type NOT IN ('in', 'out')"
772   -// + " GROUP BY gs_bm,fgs_bm,xl_bm,gs_name,fgs_name,bc_type "
773   - + " ) b ON t.company=b.gs_bm and t.branche_company = b.fgs_bm) b on "
774   - + " a.gs_bm=b.gs_bm and a.fgs_bm=b.fgs_bm and a.xl_bm=b.xl_bm ";
775   - List<Turnoutrate> list = jdbcTemplate.query(sql, new RowMapper<Turnoutrate>() {
  772 + List<ScheduleRealInfo> list = scheduleRealInfoRepository.scheduleByDateAndLineTj(line, startDate, endDate, company, subCompany);
  773 + List<Line> lineList = lineRepository.findLineBygsBm(company, subCompany, line);
  774 +
  775 + String sql = "select * from bsth_c_s_sp_info where gs_bm = '"+company+"' and fgs_bm = '"+subCompany+"' "
  776 + + "and DATE_FORMAT(schedule_date,'%Y-%m-%d') BETWEEN '"+startDate+"' and '"+endDate+"' ";
  777 + if(line.trim().length() != 0){
  778 + sql += "and xl_bm = '"+line+"' ";
  779 + }
  780 + List<SchedulePlanInfo> planList = jdbcTemplate.query(sql, new RowMapper<SchedulePlanInfo>() {
776 781  
777 782 @Override
778   - public Turnoutrate mapRow(ResultSet arg0, int arg1) throws SQLException {
779   - Turnoutrate tu = new Turnoutrate();
780   - NumberFormat numberFormat = NumberFormat.getInstance();
781   - numberFormat.setMaximumFractionDigits(2);
782   - int scl = arg0.getString("scl")!=null&&arg0.getString("scl").trim().length()!=0?Integer.parseInt(arg0.getString("scl")):0;
783   - int jcl = arg0.getString("jcl")!=null&&arg0.getString("jcl").trim().length()!=0?Integer.parseInt(arg0.getString("jcl")):0;
784   - int sbc = arg0.getString("sbc")!=null&&arg0.getString("sbc").trim().length()!=0?Integer.parseInt(arg0.getString("sbc")):0;
785   - int jbc = arg0.getString("jbc")!=null&&arg0.getString("jbc").trim().length()!=0?Integer.parseInt(arg0.getString("jbc")):0;
786   - String result1 = numberFormat.format((float) scl / (float) jcl * 100);
787   - String result2 = numberFormat.format((float) sbc / (float) jbc * 100);
788   - tu.setRq(rq);
789   - if(arg0.getString("gs_name") == null || arg0.getString("gs_name").trim().length() == 0)
790   - return tu;
791   - tu.setGs(arg0.getString("gs_name").toString());
792   - tu.setZhgs(arg0.getString("fgs_name").toString());
793   -// tu.setXl(arg0.getString("xlgs")!=null&&arg0.getString("xlgs").trim().length()!=0?arg0.getString("xlgs"):"0");
794   - tu.setXl(arg0.getString("jxl")!=null&&arg0.getString("jxl").trim().length()!=0?arg0.getString("jxl"):"0");
795   - tu.setXlmc(arg0.getString("sxl")!=null&&arg0.getString("sxl").trim().length()!=0?arg0.getString("sxl"):"0");
796   - tu.setCchjh("" + jcl);
797   - tu.setCchsj("" + scl);
798   - tu.setCchqz(arg0.getString("sxl")!=null&&arg0.getString("sxl").trim().length()!=0?arg0.getString("sxl"):"0");
799   - tu.setChl(result1 + "%");// 出车率
800   - tu.setBcjh("" + jbc);
801   - tu.setBcsj("" + sbc);
802   - tu.setBbzxl(result2 + "%");// 班次执行率
803   - tu.setSm(arg0.getString("gs_name").toString());
804   - tu.setGsgs(arg0.getString("gslsbm").toString());
805   - tu.setFgsgs(arg0.getString("fgsbm").toString());
806   - return tu;
  783 + public SchedulePlanInfo mapRow(ResultSet arg0, int arg1) throws SQLException {
  784 + SchedulePlanInfo schedule = new SchedulePlanInfo();
  785 + schedule.setGsName(arg0.getString("gs_name"));
  786 + schedule.setFgsName(arg0.getString("fgs_name"));
  787 + schedule.setClZbh(arg0.getString("cl_zbh"));
  788 + schedule.setFcsj(arg0.getString("fcsj"));
  789 + schedule.setBcType(arg0.getString("bc_type"));
  790 + schedule.setXlBm(arg0.getString("xl_bm"));
  791 + schedule.setXlName(arg0.getString("xl_name"));
  792 + schedule.setScheduleDate(arg0.getDate("schedule_date"));
  793 + return schedule;
807 794 }
808 795  
809 796 });
810 797  
811   - for(Turnoutrate t : list){
812   - if(t.getGs() != null && t.getGs().trim().length() != 0)
813   - resList.add(t);
  798 +
  799 + for(Line line1 : lineList){
  800 + if(line.trim().length() == 0 || line1.getLineCode().equals(line)){
  801 + Map<String, Object> m = new HashMap<String, Object>();
  802 + m.put("rq", rq);
  803 + m.put("line", line1.getName());
  804 + m.put("xlBm", line1.getLineCode());
  805 + m.put("qz", line1.getWarrantCar()!=null?line1.getWarrantCar():0);
  806 + m.put("sm", "");
  807 + resList.add(m);
  808 + }
  809 + }
  810 + for(Map<String, Object> m : resList){
  811 + String xlBm = m.get("xlBm").toString();
  812 + List<ScheduleRealInfo> reals = new ArrayList<ScheduleRealInfo>();
  813 + List<SchedulePlanInfo> plans = new ArrayList<SchedulePlanInfo>();
  814 + for(ScheduleRealInfo schedule : list){
  815 + if(schedule.getXlBm().equals(xlBm)){
  816 + reals.add(schedule);
  817 + }
  818 + }
  819 + for(SchedulePlanInfo schedule : planList){
  820 + if(schedule.getXlBm().equals(xlBm)){
  821 + plans.add(schedule);
  822 + }
  823 + }
  824 + Set<String> jhcc = new HashSet<String>();
  825 + Set<String> sjcc = new HashSet<String>();
  826 + for(SchedulePlanInfo schedule : plans){
  827 + if(!m.containsKey("gsName") && schedule.getGsName()!=null && schedule.getGsName().trim().length()!=0){
  828 + m.put("gsName", schedule.getGsName());
  829 + }
  830 + if(!m.containsKey("fgsName") && schedule.getFgsName()!=null && schedule.getFgsName().trim().length()!=0){
  831 + m.put("fgsName", schedule.getFgsName());
  832 + }
  833 + jhcc.add(schedule.getClZbh() + sdf.format(schedule.getScheduleDate()));
  834 + }
  835 + for(ScheduleRealInfo schedule : reals){
  836 + if(!m.containsKey("gsName") && schedule.getGsName()!=null && schedule.getGsName().trim().length()!=0){
  837 + m.put("gsName", schedule.getGsName());
  838 + }
  839 + if(!m.containsKey("fgsName") && schedule.getFgsName()!=null && schedule.getFgsName().trim().length()!=0){
  840 + m.put("fgsName", schedule.getFgsName());
  841 + }
  842 + sjcc.add(schedule.getClZbh() + sdf.format(schedule.getScheduleDate()));
  843 + }
  844 + m.put("jhcc", jhcc.size());
  845 + m.put("sjcc", sjcc.size());
  846 + if(jhcc.size() != 0 && sjcc.size() != 0){
  847 + m.put("ccl", numberFormat.format(((float)sjcc.size() / jhcc.size())*100)+"%");
  848 + }else{
  849 + m.put("ccl", "--");
  850 + }
  851 + int jhbc = culateMileageService.culateJhbc(reals, "");
  852 + int sjbc = culateMileageService.culateSjbc(reals, "");
  853 + m.put("jhbc", jhbc);
  854 + m.put("sjbc", sjbc);
  855 + if(jhbc != 0 && sjbc != 0){
  856 + m.put("zxl", numberFormat.format(((float)sjbc / jhbc)*100)+"%");
  857 + }else{
  858 + m.put("zxl", "--");
  859 + }
  860 + }
  861 + Map<String, Object> tempMap = new HashMap<String, Object>();
  862 + int jhcc = 0;
  863 + int sjcc = 0;
  864 + int jhbc = 0;
  865 + int sjbc = 0;
  866 + int qz = 0;
  867 + for(Map<String, Object> m : resList){
  868 + jhcc += Integer.valueOf(m.get("jhcc").toString());
  869 + sjcc += Integer.valueOf(m.get("sjcc").toString());
  870 + jhbc += Integer.valueOf(m.get("jhbc").toString());
  871 + sjbc += Integer.valueOf(m.get("sjbc").toString());
  872 + qz += Integer.valueOf(m.get("qz").toString());
  873 + }
  874 + tempMap.put("rq", "分类汇总");
  875 + tempMap.put("line", "共" + resList.size() + "条线路");
  876 + tempMap.put("jhcc", jhcc);
  877 + tempMap.put("sjcc", sjcc);
  878 + tempMap.put("jhbc", jhbc);
  879 + tempMap.put("sjbc", sjbc);
  880 + tempMap.put("qz", qz);
  881 + if(jhcc != 0 && sjcc != 0){
  882 + tempMap.put("ccl", numberFormat.format(((float)sjcc / jhcc)*100)+"%");
  883 + }else{
  884 + tempMap.put("ccl", "--");
  885 + }
  886 + if(jhbc != 0 && sjbc != 0){
  887 + tempMap.put("zxl", numberFormat.format(((float)sjbc / jhbc)*100)+"%");
  888 + }else{
  889 + tempMap.put("zxl", "--");
814 890 }
  891 + resList.add(tempMap);
815 892  
816 893 return resList;
817 894 }
... ...
src/main/java/com/bsth/service/gps/GpsServiceImpl.java
... ... @@ -2,7 +2,7 @@ package com.bsth.service.gps;
2 2  
3 3 import com.bsth.common.ResponseCode;
4 4 import com.bsth.data.BasicData;
5   -import com.bsth.data.arrival.ArrivalEntity;
  5 +import com.bsth.data.forecast.entity.ArrivalEntity;
6 6 import com.bsth.data.gpsdata.GpsEntity;
7 7 import com.bsth.data.gpsdata.GpsRealData;
8 8 import com.bsth.data.gpsdata.arrival.utils.GeoUtils;
... ...
src/main/java/com/bsth/service/gps/entity/HistoryGps_DTO.java
... ... @@ -2,7 +2,7 @@ package com.bsth.service.gps.entity;
2 2  
3 3 import com.alibaba.fastjson.JSON;
4 4 import com.alibaba.fastjson.JSONObject;
5   -import com.bsth.data.arrival.ArrivalEntity;
  5 +import com.bsth.data.forecast.entity.ArrivalEntity;
6 6 import com.fasterxml.jackson.annotation.JsonIgnore;
7 7 import com.vividsolutions.jts.geom.Coordinate;
8 8 import com.vividsolutions.jts.geom.GeometryFactory;
... ...
src/main/java/com/bsth/service/realcontrol/impl/ScheduleRealInfoServiceImpl.java
... ... @@ -52,6 +52,7 @@ import com.google.common.base.Splitter;
52 52 import com.google.common.collect.Lists;
53 53 import org.apache.commons.lang3.StringEscapeUtils;
54 54 import org.apache.commons.lang3.StringUtils;
  55 +import org.drools.compiler.lang.dsl.DSLMapParser.statement_return;
55 56 import org.joda.time.format.DateTimeFormat;
56 57 import org.joda.time.format.DateTimeFormatter;
57 58 import org.slf4j.Logger;
... ... @@ -812,6 +813,20 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
812 813 // int ljbc = scheduleRealInfoRepository.findLjbc(jName, clZbh, lpName);
813 814 //计算里程和班次数,并放入Map里
814 815 Map<String, Object> map = this.MapById(scheduleRealInfos.get(0).getId());
  816 +
  817 + map.put("jhlc",Arith.add(culateMieageService.culateJhgl(scheduleRealInfos),culateMieageService.culateJhJccgl(scheduleRealInfos)));
  818 + map.put("remMileage",culateMieageService.culateLbgl(lists));
  819 + map.put("addMileage", culateMieageService.culateLjgl(lists));
  820 + double yygl=Arith.add(culateMieageService.culateSjgl(lists),culateMieageService.culateLjgl(lists));
  821 + map.put("yygl", yygl);
  822 + double ksgl=Arith.add(culateMieageService.culateKsgl(lists),culateMieageService.culateJccgl(lists));
  823 + map.put("ksgl",ksgl);
  824 + map.put("realMileage", Arith.add(yygl ,ksgl));
  825 + map.put("jhbc", culateMieageService.culateJhgl(scheduleRealInfos));
  826 + map.put("cjbc", culateMieageService.culateLbbc(lists));
  827 + map.put("ljbc", culateMieageService.culateLjbc(lists, ""));
  828 + int sjbc =culateMieageService.culateLjbc(lists, "")+culateMieageService.culateSjbc(lists, "");
  829 + map.put("sjbc", sjbc);
815 830 // map=new HashMap<String,Object>();
816 831 Map<String, Object> maps;
817 832 for (ScheduleRealInfo scheduleRealInfo : scheduleRealInfos) {
... ... @@ -842,19 +857,6 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
842 857 }
843 858  
844 859  
845   - map.put("jhlc",Arith.add(culateMieageService.culateJhgl(scheduleRealInfos),culateMieageService.culateJhJccgl(scheduleRealInfos)));
846   - map.put("remMileage",culateMieageService.culateLbgl(lists));
847   - map.put("addMileage", culateMieageService.culateLjgl(lists));
848   - double yygl=Arith.add(culateMieageService.culateSjgl(lists),culateMieageService.culateLjgl(lists));
849   - map.put("yygl", yygl);
850   - double ksgl=Arith.add(culateMieageService.culateKsgl(lists),culateMieageService.culateJccgl(lists));
851   - map.put("ksgl",ksgl);
852   - map.put("realMileage", Arith.add(yygl ,ksgl));
853   - map.put("jhbc", culateMieageService.culateJhgl(scheduleRealInfos));
854   - map.put("cjbc", culateMieageService.culateLbbc(lists));
855   - map.put("ljbc", culateMieageService.culateLjbc(lists, ""));
856   - int sjbc =culateMieageService.culateLjbc(lists, "")+culateMieageService.culateSjbc(lists, "");
857   - map.put("sjbc", sjbc);
858 860  
859 861 String path = this.getClass().getResource("/").getPath() + "static/pages/forms/";
860 862  
... ... @@ -4141,7 +4143,7 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
4141 4143 return new ArrayList<Map<String, Object>>();
4142 4144 }
4143 4145  
4144   - public List<ScheduleRealInfo> exportWaybill_pl(List<ScheduleRealInfo> listpl,String date,String jName, String clZbh,String lpName) {
  4146 + public void exportWaybill_pl(List<ScheduleRealInfo> listpl,String date,String jName, String clZbh,String lpName) {
4145 4147 ReportUtils ee = new ReportUtils();
4146 4148 ReportRelatedUtils rru = new ReportRelatedUtils();
4147 4149 List<Iterator<?>> list = new ArrayList<Iterator<?>>();
... ... @@ -4159,6 +4161,21 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
4159 4161 // int cjbc = scheduleRealInfoRepository.findCjbc(jName, clZbh, lpName);
4160 4162 // int ljbc = scheduleRealInfoRepository.findLjbc(jName, clZbh, lpName);
4161 4163 Map<String, Object> map = this.MapById(scheduleRealInfos.get(0).getId());
  4164 + //计算里程和班次数,并放入Map里
  4165 + map.put("jhlc", Arith.add(culateMieageService.culateJhgl(scheduleRealInfos),culateMieageService.culateJhJccgl(scheduleRealInfos)));
  4166 + map.put("remMileage",culateMieageService.culateLbgl(lists));
  4167 + map.put("addMileage", culateMieageService.culateLjgl(lists));
  4168 + double yygl=Arith.add(culateMieageService.culateSjgl(lists),culateMieageService.culateLjgl(lists));
  4169 + map.put("yygl", yygl);
  4170 + double ksgl=Arith.add(culateMieageService.culateKsgl(lists),culateMieageService.culateJccgl(lists));
  4171 + map.put("ksgl",ksgl);
  4172 + map.put("realMileage", Arith.add(yygl ,ksgl));
  4173 + map.put("jhbc", culateMieageService.culateJhgl(scheduleRealInfos));
  4174 + map.put("cjbc", culateMieageService.culateLbbc(lists));
  4175 + map.put("ljbc", culateMieageService.culateLjbc(lists, ""));
  4176 + int sjbc =culateMieageService.culateLjbc(lists, "")+culateMieageService.culateSjbc(lists, "");
  4177 + map.put("sjbc", sjbc);
  4178 +
4162 4179 Map<String, Object> maps;
4163 4180 for (ScheduleRealInfo scheduleRealInfo : scheduleRealInfos) {
4164 4181 maps = new HashMap<String, Object>();
... ... @@ -4187,27 +4204,13 @@ public class ScheduleRealInfoServiceImpl extends BaseServiceImpl&lt;ScheduleRealInf
4187 4204 }
4188 4205 }
4189 4206  
4190   - //计算里程和班次数,并放入Map里
4191   - map.put("jhlc", Arith.add(culateMieageService.culateJhgl(scheduleRealInfos),culateMieageService.culateJhJccgl(scheduleRealInfos)));
4192   - map.put("remMileage",culateMieageService.culateLbgl(lists));
4193   - map.put("addMileage", culateMieageService.culateLjgl(lists));
4194   - double yygl=Arith.add(culateMieageService.culateSjgl(lists),culateMieageService.culateLjgl(lists));
4195   - map.put("yygl", yygl);
4196   - double ksgl=Arith.add(culateMieageService.culateKsgl(lists),culateMieageService.culateJccgl(lists));
4197   - map.put("ksgl",ksgl);
4198   - map.put("realMileage", Arith.add(yygl ,ksgl));
4199   - map.put("jhbc", culateMieageService.culateJhgl(scheduleRealInfos));
4200   - map.put("cjbc", culateMieageService.culateLbbc(lists));
4201   - map.put("ljbc", culateMieageService.culateLjbc(lists, ""));
4202   - int sjbc =culateMieageService.culateLjbc(lists, "")+culateMieageService.culateSjbc(lists, "");
4203   - map.put("sjbc", sjbc);
4204   -
  4207 +
4205 4208 String path = this.getClass().getResource("/").getPath() + "static/pages/forms/";
4206 4209  
4207 4210 list.add(listMap.iterator());
4208 4211 ee.excelReplace(list, new Object[]{map}, path + "mould/waybill_minhang.xls",
4209 4212 path + "export/" + date + "-" + jName + "-" + clZbh + "-" + lpName + "-行车路单.xls");
4210   - return scheduleRealInfos;
  4213 +// return scheduleRealInfos;
4211 4214 }
4212 4215  
4213 4216 @Override
... ...
src/main/resources/application-dev.properties
... ... @@ -6,11 +6,11 @@ spring.jpa.hibernate.ddl-auto= update
6 6 spring.jpa.hibernate.naming_strategy= org.hibernate.cfg.ImprovedNamingStrategy
7 7 #DATABASE
8 8 spring.jpa.database= MYSQL
9   -spring.jpa.show-sql= false
  9 +spring.jpa.show-sql= true
10 10 spring.datasource.driver-class-name= com.mysql.jdbc.Driver
11 11 spring.datasource.url= jdbc:mysql://127.0.0.1/control?useUnicode=true&characterEncoding=utf-8&useSSL=false
12 12 spring.datasource.username= root
13   -spring.datasource.password=
  13 +spring.datasource.password= root
14 14 #spring.datasource.url= jdbc:mysql://192.168.168.117/pd_control?useUnicode=true&characterEncoding=utf-8&useSSL=false
15 15 #spring.datasource.username= root
16 16 #spring.datasource.password= root
... ... @@ -29,7 +29,7 @@ spring.datasource.validation-query=select 1
29 29 ##
30 30 #222.66.0.204:5555
31 31 ##\u5B9E\u65F6gps
32   -http.gps.real.url= http://180.168.57.114:7474/transport_server/rtgps/
  32 +http.gps.real.url= http://114.80.178.12:18080/transport_server/rtgps/
33 33 #http.gps.real.url= http://27.115.69.123:8800/transport_server/rtgps/
34 34 ##\u6D88\u606F\u4E0B\u53D1
35 35 http.send.directive = http://192.168.168.201:9090/transport_server/message/
36 36 \ No newline at end of file
... ...
src/main/resources/static/pages/forms/mould/turnoutrate.xls
No preview for this file type
src/main/resources/static/pages/mforms/turnoutrates/turnoutrate.html
... ... @@ -92,20 +92,20 @@
92 92 <tbody id="tbody">
93 93  
94 94 </tbody>
95   - <tr>
96   - <td colspan="1">分类汇总</td>
97   - <td><span id="total_gs">&nbsp;</span></td>
98   - <td><span id="total_zhgs">&nbsp;</span></td>
99   - <td><span id="total_xlts">&nbsp;</span></td>
100   - <td><span id="total_jh">&nbsp;</span></td>
101   - <td><span id="total_sj">&nbsp;</span></td>
102   - <td><span id="total_qz">&nbsp;</span></td>
103   - <td><span id="total_ccl">&nbsp;</span></td>
104   - <td><span id="total_bcjh">&nbsp;</span></td>
105   - <td><span id="total_bcsj">&nbsp;</span></td>
106   - <td><span id="total_bczxl">&nbsp;</span></td>
107   - <td><span id="total_sm">&nbsp;</span></td>
108   - </tr>
  95 +<!-- <tr> -->
  96 +<!-- <td colspan="1">分类汇总</td> -->
  97 +<!-- <td><span id="total_gs">&nbsp;</span></td> -->
  98 +<!-- <td><span id="total_zhgs">&nbsp;</span></td> -->
  99 +<!-- <td><span id="total_xlts">&nbsp;</span></td> -->
  100 +<!-- <td><span id="total_jh">&nbsp;</span></td> -->
  101 +<!-- <td><span id="total_sj">&nbsp;</span></td> -->
  102 +<!-- <td><span id="total_qz">&nbsp;</span></td> -->
  103 +<!-- <td><span id="total_ccl">&nbsp;</span></td> -->
  104 +<!-- <td><span id="total_bcjh">&nbsp;</span></td> -->
  105 +<!-- <td><span id="total_bcsj">&nbsp;</span></td> -->
  106 +<!-- <td><span id="total_bczxl">&nbsp;</span></td> -->
  107 +<!-- <td><span id="total_sm">&nbsp;</span></td> -->
  108 +<!-- </tr> -->
109 109 </table>
110 110 </div>
111 111 </div>
... ... @@ -197,53 +197,53 @@
197 197 $("#query").on("click",function(){
198 198  
199 199 line = $("#line").val();
200   - startDate1=$("#startDate").val();
201   - endDate1=$("#endDate").val();
  200 + startDate=$("#startDate").val();
  201 + endDate=$("#endDate").val();
202 202 gsdmTurn=$("#gsdmTurn").val();
203 203 fgsdmTurn=$("#fgsdmTurn").val();
204   - if(startDate1!=''&&endDate1!=''){
  204 + if(startDate!=''&&endDate!=''){
205 205 $post('/mcy_forms/turnoutrate',
206   - { gsdmTurn:gsdmTurn,fgsdmTurn:fgsdmTurn, line:line,startDate:$("#startDate").val(),endDate:$("#endDate").val(),type:'query'},function(result){
  206 + { gsdmTurn:gsdmTurn,fgsdmTurn:fgsdmTurn, line:line,startDate:startDate,endDate:endDate,type:'query'},function(result){
207 207 // var result=[];
208 208 // 把数据填充到模版中
209 209 var tbodyHtml = template('turnoutrate',{list:result});
210 210 // 把渲染好的模版html文本追加到表格中
211 211 $('#tbody').html(tbodyHtml);
212   - line = $("#line").val();
213   - startDate = $("#startDate").val();
214   - endDate = $("#endDate").val();
215   - $("#sDate").text(startDate);
216   - $("#eDate").text(endDate);
  212 + line = $("#line").val();
  213 + startDate = $("#startDate").val();
  214 + endDate = $("#endDate").val();
  215 + $("#sDate").text(startDate);
  216 + $("#eDate").text(endDate);
217 217  
218   - var total_xlts = 0,total_jh = 0;
219   - var total_sj = 0,total_qz = 0,total_ccl = 0,total_bcjh = 0;
220   - var total_bcjh = 0,total_bcsj = 0,total_bczxl = 0;
221   - var total_gs=0;
222   - var total_zhgs=0;
223   - $.each(result, function(i, obj) {
224   - total_gs +=Number(obj.gsgs);
225   - total_zhgs +=Number(obj.fgsgs);
226   - total_xlts += Number(obj.xl);
227   - total_jh = Number(obj.cchjh)+Number(total_jh);
228   - total_sj = Number(obj.cchsj)+Number(total_sj);
229   - total_qz = Number(obj.cchqz)+Number(total_qz);
  218 +// var total_xlts = 0,total_jh = 0;
  219 +// var total_sj = 0,total_qz = 0,total_ccl = 0,total_bcjh = 0;
  220 +// var total_bcjh = 0,total_bcsj = 0,total_bczxl = 0;
  221 +// var total_gs=0;
  222 +// var total_zhgs=0;
  223 +// $.each(result, function(i, obj) {
  224 +// total_gs +=Number(obj.gsgs);
  225 +// total_zhgs +=Number(obj.fgsgs);
  226 +// total_xlts += Number(obj.xl);
  227 +// total_jh = Number(obj.cchjh)+Number(total_jh);
  228 +// total_sj = Number(obj.cchsj)+Number(total_sj);
  229 +// total_qz = Number(obj.cchqz)+Number(total_qz);
230 230  
231   - total_ccl =(Number(total_sj)/Number(total_jh))*100;
232   - total_bcjh = Number(obj.bcjh)+Number(total_bcjh);
233   - total_bcsj = Number(obj.bcsj)+Number(total_bcsj);
234   - total_bczxl = (Number(total_bcsj)/Number(total_bcjh))*100;
  231 +// total_ccl =(Number(total_sj)/Number(total_jh))*100;
  232 +// total_bcjh = Number(obj.bcjh)+Number(total_bcjh);
  233 +// total_bcsj = Number(obj.bcsj)+Number(total_bcsj);
  234 +// total_bczxl = (Number(total_bcsj)/Number(total_bcjh))*100;
235 235  
236   - });
237   - $("#total_gs").text(total_gs);
238   - $("#total_zhgs").text(total_zhgs);
239   - $("#total_xlts").text(total_xlts);
240   - $("#total_jh").text(total_jh);
241   - $("#total_sj").text(total_sj);
242   - $("#total_qz").text(total_qz);
243   - $("#total_ccl").text(total_ccl.toFixed(2)+'%');
244   - $("#total_bcjh").text(total_bcjh);
245   - $("#total_bcsj").text(total_bcsj);
246   - $("#total_bczxl").text(total_bczxl.toFixed(2)+'%');
  236 +// });
  237 +// $("#total_gs").text(total_gs);
  238 +// $("#total_zhgs").text(total_zhgs);
  239 +// $("#total_xlts").text(total_xlts);
  240 +// $("#total_jh").text(total_jh);
  241 +// $("#total_sj").text(total_sj);
  242 +// $("#total_qz").text(total_qz);
  243 +// $("#total_ccl").text(total_ccl.toFixed(2)+'%');
  244 +// $("#total_bcjh").text(total_bcjh);
  245 +// $("#total_bcsj").text(total_bcsj);
  246 +// $("#total_bczxl").text(total_bczxl.toFixed(2)+'%');
247 247  
248 248 var temp = {};
249 249 var today_account = 0;
... ... @@ -278,18 +278,23 @@
278 278 <script type="text/html" id="turnoutrate">
279 279 {{each list as obj i}}
280 280 <tr>
281   - <td>{{obj.rq}}</td>
282   - <td>{{obj.gs}}</td>
283   - <td>{{obj.zhgs}}</td>
284   - <td>{{obj.xl}}</td>
285   - <td>{{obj.cchjh}}</td>
286   - <td>{{obj.cchsj}}</td>
287   - <td>{{obj.cchqz}}</td>
288   - <td>{{obj.chl}}</td>
289   - <td>{{obj.bcjh}}</td>
290   - <td>{{obj.bcsj}}</td>
291   - <td>{{obj.bbzxl}}</td>
292   - <td>{{obj.gs}}</td>
  281 + {{if obj.rq == '分类汇总'}}
  282 + <td colspan='3'>{{obj.rq}}</td>
  283 + {{/if}}
  284 + {{if obj.rq != '分类汇总'}}
  285 + <td>{{obj.rq}}</td>
  286 + <td>{{obj.gsName}}</td>
  287 + <td>{{obj.fgsName}}</td>
  288 + {{/if}}
  289 + <td>{{obj.line}}</td>
  290 + <td>{{obj.jhcc}}</td>
  291 + <td>{{obj.sjcc}}</td>
  292 + <td>{{obj.qz}}</td>
  293 + <td>{{obj.ccl}}</td>
  294 + <td>{{obj.jhbc}}</td>
  295 + <td>{{obj.sjbc}}</td>
  296 + <td>{{obj.zxl}}</td>
  297 + <td>{{obj.sm}}</td>
293 298 </tr>
294 299 {{/each}}
295 300 {{if list.length == 0}}
... ...
src/main/resources/static/pages/oil/list_ph.html
... ... @@ -209,7 +209,7 @@
209 209  
210 210 </td>
211 211 <td>
212   - {{obj.jsy}}
  212 + {{obj.jsy}}/{{obj.name}}
213 213 </td>
214 214 <td>
215 215  
... ...
src/main/resources/static/real_control_v2/js/main.js
... ... @@ -169,8 +169,8 @@ var disabled_submit_btn = function (form) {
169 169 function showUpdateDescription() {
170 170 //更新说明
171 171 var updateDescription = {
172   - date: '2017-05-04',
173   - text: '<h5>修复了一个问题,该问题导致在应急停靠时间设置为0的时候,待发时间不会自动调整。</h5>'
  172 + date: '2017-05-07',
  173 + text: '<h5>修复了一个问题,该问题导致在某些特定情况下,报出的发车时间比实际的要晚1~3分钟。</h5>'
174 174 };
175 175  
176 176 var storage = window.localStorage
... ...
src/main/resources/static/real_control_v2/js/minute_timer.js
1   -/** 时钟 */
2   -var gb_minute_timer = (function () {
3   -
4   -
5   - var getServerTime = function (cb) {
6   - function oncallback(jqXHR) {
7   - var time = jqXHR && jqXHR.getResponseHeader("Date");
8   - if (time)
9   - callback(new Date(time))
10   - }
11   -
12   - if ("function" == typeof callback)
13   - $.ajax({
14   - url: "/real_control_v2/assets/imgs/time.gif",
15   - type: "HEAD"
16   - }).done(function (data, textStatus, jqXHR) {
17   - oncallback(jqXHR)
18   - }).fail(function (jqXHR, textStatus, errorThrown) {
19   - oncallback(jqXHR)
20   - })
21   - };
22   -
23   -
24   - setTimeout(function () {
25   - getServerTime(function () {
26   - console.log('cb,,', cb);
27   - });
28   - }, 5000);
29   -
  1 +/** 时钟 */
  2 +var gb_minute_timer = (function () {
  3 +
  4 +
  5 + var getServerTime = function (cb) {
  6 + function oncallback(jqXHR) {
  7 + var time = jqXHR && jqXHR.getResponseHeader("Date");
  8 + if (time)
  9 + callback(new Date(time))
  10 + }
  11 +
  12 + if ("function" == typeof callback)
  13 + $.ajax({
  14 + url: "/real_control_v2/assets/imgs/time.gif",
  15 + type: "HEAD"
  16 + }).done(function (data, textStatus, jqXHR) {
  17 + oncallback(jqXHR)
  18 + }).fail(function (jqXHR, textStatus, errorThrown) {
  19 + oncallback(jqXHR)
  20 + })
  21 + };
  22 +
  23 +
  24 + setTimeout(function () {
  25 + getServerTime(function () {
  26 + console.log('cb,,', cb);
  27 + });
  28 + }, 5000);
  29 +
30 30 })();
31 31 \ No newline at end of file
... ...