Commit 43cfc07d2d7c15834e5d0f71c820fce867bda823
1 parent
2842af2c
update
Showing
19 changed files
with
1989 additions
and
6 deletions
src/main/java/com/bsth/data/BasicData.java
| 1 | 1 | package com.bsth.data; |
| 2 | 2 | |
| 3 | +import java.util.HashMap; | |
| 4 | +import java.util.Iterator; | |
| 5 | +import java.util.Map; | |
| 6 | + | |
| 7 | +import org.slf4j.Logger; | |
| 8 | +import org.slf4j.LoggerFactory; | |
| 9 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 10 | +import org.springframework.stereotype.Component; | |
| 11 | + | |
| 12 | +import com.bsth.entity.CarPark; | |
| 13 | +import com.bsth.entity.Cars; | |
| 14 | +import com.bsth.entity.Line; | |
| 15 | +import com.bsth.entity.Station; | |
| 16 | +import com.bsth.entity.schedule.CarConfigInfo; | |
| 17 | +import com.bsth.repository.CarParkRepository; | |
| 18 | +import com.bsth.repository.CarsRepository; | |
| 19 | +import com.bsth.repository.LineRepository; | |
| 20 | +import com.bsth.repository.StationRepository; | |
| 21 | +import com.bsth.repository.schedule.CarConfigInfoRepository; | |
| 22 | +import com.google.common.collect.BiMap; | |
| 23 | +import com.google.common.collect.HashBiMap; | |
| 24 | +import com.google.common.collect.TreeMultimap; | |
| 25 | + | |
| 3 | 26 | /** |
| 4 | 27 | * |
| 5 | - * @ClassName: BasicData | |
| 6 | - * @Description: TODO(基础的映射数据) | |
| 28 | + * @ClassName: BasicData | |
| 29 | + * @Description: TODO(基础的映射数据) | |
| 7 | 30 | * @author PanZhao |
| 8 | - * @date 2016年8月10日 下午3:27:45 | |
| 31 | + * @date 2016年8月10日 下午3:27:45 | |
| 9 | 32 | * |
| 10 | 33 | */ |
| 34 | +@Component | |
| 11 | 35 | public class BasicData { |
| 12 | 36 | |
| 37 | + //设备号和车辆自编号 (K: 设备编码 ,V:车辆自编号) | |
| 38 | + public static BiMap<String, String> deviceId2NbbmMap; | |
| 39 | + | |
| 40 | + //车辆自编号和公司代码对照 (K: 车辆自编号 ,V:公司代码) | |
| 41 | + public static Map<String, String> nbbm2CompanyCodeMap; | |
| 42 | + | |
| 43 | + //站点编码和名称对照,包括停车场 (K: 站点编码 ,V:站点名称) | |
| 44 | + public static Map<String, String> stationCode2NameMap; | |
| 45 | + | |
| 46 | + //车辆和线路对照 | |
| 47 | + public static Map<String, Line> nbbm2LineMap; | |
| 48 | + | |
| 49 | + //线路和用户对照 用于webSocket定向推送消息(用户进入线调时写入数据) | |
| 50 | + public static TreeMultimap<Integer, String> lineCode2SocketUserMap = TreeMultimap.create(); | |
| 51 | + | |
| 52 | + //线路ID和code 对照 | |
| 53 | + public static BiMap<Integer, Integer> lineId2CodeMap; | |
| 54 | + | |
| 55 | + @Autowired | |
| 56 | + BasicDataLoader basicDataLoader; | |
| 57 | + | |
| 58 | + Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 59 | + | |
| 60 | + /** | |
| 61 | + * | |
| 62 | + * @Title: loadAllData | |
| 63 | + * @Description: TODO(加载所有数据) | |
| 64 | + * @throws | |
| 65 | + */ | |
| 66 | + public int loadAllData(){ | |
| 67 | + try{ | |
| 68 | + basicDataLoader.loadDeviceInfo(); | |
| 69 | + basicDataLoader.loadStationInfo(); | |
| 70 | + basicDataLoader.loadLineInfo(); | |
| 71 | + basicDataLoader.loadNbbm2LineInfo(); | |
| 72 | + }catch(Exception e){ | |
| 73 | + logger.error("加载基础数据时出现异常," , e); | |
| 74 | + } | |
| 75 | + return 0; | |
| 76 | + } | |
| 77 | + | |
| 78 | + @Component | |
| 79 | + public class BasicDataLoader{ | |
| 80 | + | |
| 81 | + @Autowired | |
| 82 | + CarsRepository carsRepository; | |
| 83 | + | |
| 84 | + @Autowired | |
| 85 | + StationRepository stationRepository; | |
| 86 | + | |
| 87 | + @Autowired | |
| 88 | + CarParkRepository carParkRepository; | |
| 89 | + | |
| 90 | + @Autowired | |
| 91 | + CarConfigInfoRepository carConfigInfoRepository; | |
| 92 | + | |
| 93 | + @Autowired | |
| 94 | + LineRepository lineRepository; | |
| 95 | + | |
| 96 | + /** | |
| 97 | + * | |
| 98 | + * @Title: loadDeviceInfo | |
| 99 | + * @Description: TODO(加载设备相关信息) | |
| 100 | + * @throws | |
| 101 | + */ | |
| 102 | + public void loadDeviceInfo(){ | |
| 103 | + BiMap<String, String> deviceId2Nbbm = HashBiMap.create(); | |
| 104 | + //车辆和公司代码对照 | |
| 105 | + Map<String, String> nbbm2CompanyCode = new HashMap<>(); | |
| 106 | + Iterator<Cars> carIterator = carsRepository.findAll().iterator(); | |
| 107 | + Cars car; | |
| 108 | + while(carIterator.hasNext()){ | |
| 109 | + car = carIterator.next(); | |
| 110 | + deviceId2Nbbm.put(car.getEquipmentCode(), car.getInsideCode()); | |
| 111 | + nbbm2CompanyCode.put(car.getInsideCode(), car.getBusinessCode()); | |
| 112 | + } | |
| 113 | + | |
| 114 | + deviceId2NbbmMap = deviceId2Nbbm; | |
| 115 | + nbbm2CompanyCodeMap = nbbm2CompanyCode; | |
| 116 | + } | |
| 117 | + | |
| 118 | + /** | |
| 119 | + * | |
| 120 | + * @Title: loadStationInfo | |
| 121 | + * @Description: TODO(加载站点信息) | |
| 122 | + * @throws | |
| 123 | + */ | |
| 124 | + public void loadStationInfo(){ | |
| 125 | + Map<String, String> stationCode2Name = new HashMap<>(); | |
| 126 | + Iterator<Station> iterator = stationRepository.findAll().iterator(); | |
| 127 | + //站点 | |
| 128 | + Station station; | |
| 129 | + while(iterator.hasNext()){ | |
| 130 | + station = iterator.next(); | |
| 131 | + stationCode2Name.put(station.getStationCod(), station.getStationName()); | |
| 132 | + } | |
| 133 | + //停车场 | |
| 134 | + Iterator<CarPark> iterator2 = carParkRepository.findAll().iterator(); | |
| 135 | + CarPark carPark; | |
| 136 | + while(iterator2.hasNext()){ | |
| 137 | + carPark = iterator2.next(); | |
| 138 | + stationCode2Name.put(carPark.getParkCode(), carPark.getParkName()); | |
| 139 | + } | |
| 140 | + | |
| 141 | + stationCode2NameMap = stationCode2Name; | |
| 142 | + } | |
| 143 | + | |
| 144 | + /** | |
| 145 | + * | |
| 146 | + * @Title: loadNbbm2LineInfo | |
| 147 | + * @Description: TODO(车辆和线路对照) | |
| 148 | + * @throws | |
| 149 | + */ | |
| 150 | + public void loadNbbm2LineInfo(){ | |
| 151 | + Iterator<CarConfigInfo> allIterator = carConfigInfoRepository.findAll().iterator(); | |
| 152 | + Map<String, Line> ccMap = new HashMap<>(); | |
| 153 | + | |
| 154 | + CarConfigInfo cci; | |
| 155 | + while(allIterator.hasNext()){ | |
| 156 | + cci = allIterator.next(); | |
| 157 | + ccMap.put(cci.getCl().getInsideCode(), cci.getXl()); | |
| 158 | + } | |
| 159 | + nbbm2LineMap = ccMap; | |
| 160 | + } | |
| 161 | + | |
| 162 | + /** | |
| 163 | + * | |
| 164 | + * @Title: loadLineInfo | |
| 165 | + * @Description: TODO(加载线路相关信息) | |
| 166 | + * @throws | |
| 167 | + */ | |
| 168 | + public void loadLineInfo(){ | |
| 169 | + Iterator<Line> iterator = lineRepository.findAll().iterator(); | |
| 170 | + | |
| 171 | + Line line; | |
| 172 | + BiMap<Integer, Integer> biMap = HashBiMap.create(); | |
| 173 | + while(iterator.hasNext()){ | |
| 174 | + line = iterator.next(); | |
| 175 | + biMap.put(line.getId(), Integer.parseInt(line.getLineCode())); | |
| 176 | + } | |
| 177 | + | |
| 178 | + lineId2CodeMap = biMap; | |
| 179 | + } | |
| 180 | + } | |
| 13 | 181 | } | ... | ... |
src/main/java/com/bsth/data/DirectiveData.java
src/main/java/com/bsth/data/ScheduleData.java
src/main/java/com/bsth/data/directive/Consts.java
0 → 100644
src/main/java/com/bsth/data/directive/MsgIdGenerator.java
0 → 100644
| 1 | +package com.bsth.data.directive; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * | |
| 5 | + * @ClassName: MsgIdGenerator | |
| 6 | + * @Description: TODO(指令下发 msgId 生成器) | |
| 7 | + * @author PanZhao | |
| 8 | + * @date 2016年6月7日 下午4:38:04 | |
| 9 | + * | |
| 10 | + */ | |
| 11 | +public class MsgIdGenerator { | |
| 12 | + | |
| 13 | + private static int msgId = 1; | |
| 14 | + | |
| 15 | + private final static int MAX_VALUE = Integer.MAX_VALUE - 10; | |
| 16 | + | |
| 17 | + public synchronized static int getMsgId(){ | |
| 18 | + msgId ++; | |
| 19 | + if(msgId == MAX_VALUE) | |
| 20 | + msgId = 0; | |
| 21 | + return msgId; | |
| 22 | + } | |
| 23 | + | |
| 24 | + public static void setMsgId(int maxId){ | |
| 25 | + msgId = maxId; | |
| 26 | + } | |
| 27 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata/GpsRealDataList.java
0 → 100644
| 1 | +package com.bsth.data.gpsdata; | |
| 2 | + | |
| 3 | +import java.io.BufferedReader; | |
| 4 | +import java.io.InputStreamReader; | |
| 5 | +import java.util.ArrayList; | |
| 6 | +import java.util.HashMap; | |
| 7 | +import java.util.List; | |
| 8 | +import java.util.Map; | |
| 9 | +import java.util.NavigableSet; | |
| 10 | + | |
| 11 | +import org.apache.http.HttpEntity; | |
| 12 | +import org.apache.http.client.methods.CloseableHttpResponse; | |
| 13 | +import org.apache.http.client.methods.HttpGet; | |
| 14 | +import org.apache.http.impl.client.CloseableHttpClient; | |
| 15 | +import org.apache.http.impl.client.HttpClients; | |
| 16 | +import org.slf4j.Logger; | |
| 17 | +import org.slf4j.LoggerFactory; | |
| 18 | + | |
| 19 | +import com.alibaba.fastjson.JSON; | |
| 20 | +import com.alibaba.fastjson.JSONObject; | |
| 21 | +import com.bsth.data.BasicData; | |
| 22 | +import com.bsth.util.ConfigUtil; | |
| 23 | +import com.bsth.vehicle.gpsdata.entity.GpsRealData; | |
| 24 | +import com.google.common.collect.TreeMultimap; | |
| 25 | + | |
| 26 | +/** | |
| 27 | + * | |
| 28 | + * @ClassName: GpsRealDataBuffer | |
| 29 | + * @Description: TODO(实时GPS数据集合) | |
| 30 | + * @author PanZhao | |
| 31 | + * @date 2016年8月12日 下午2:04:41 | |
| 32 | + * | |
| 33 | + */ | |
| 34 | +public class GpsRealDataList { | |
| 35 | + | |
| 36 | + private static Map<String, GpsRealData> gpsMap; | |
| 37 | + | |
| 38 | + private static TreeMultimap<Integer, String> lineCode2Devices; | |
| 39 | + | |
| 40 | + // 网关数据接口地址 | |
| 41 | + private static String url; | |
| 42 | + | |
| 43 | + static{ | |
| 44 | + gpsMap = new HashMap<>(); | |
| 45 | + lineCode2Devices = TreeMultimap.create(); | |
| 46 | + url = ConfigUtil.get("http.gps.real.url"); | |
| 47 | + } | |
| 48 | + | |
| 49 | + static Logger logger = LoggerFactory.getLogger(GpsRealDataList.class); | |
| 50 | + | |
| 51 | + public static GpsRealData add(GpsRealData gps) { | |
| 52 | + String device = gps.getDeviceId(); | |
| 53 | + gpsMap.put(device, gps); | |
| 54 | + lineCode2Devices.put(gps.getLineId(), device); | |
| 55 | + return gps; | |
| 56 | + } | |
| 57 | + | |
| 58 | + /** | |
| 59 | + * | |
| 60 | + * @Title: get @Description: TODO(设备号获取GPS) @param @param deviceId @throws | |
| 61 | + */ | |
| 62 | + public static GpsRealData get(String deviceId) { | |
| 63 | + return gpsMap.get(deviceId); | |
| 64 | + } | |
| 65 | + | |
| 66 | + /** | |
| 67 | + * | |
| 68 | + * @Title: get @Description: TODO(线路编码获取GPS集合) @throws | |
| 69 | + */ | |
| 70 | + public static List<GpsRealData> get(Integer lineCode) { | |
| 71 | + NavigableSet<String> set = lineCode2Devices.get(lineCode); | |
| 72 | + | |
| 73 | + List<GpsRealData> rs = new ArrayList<>(); | |
| 74 | + for(String device : set){ | |
| 75 | + rs.add(gpsMap.get(device)); | |
| 76 | + } | |
| 77 | + | |
| 78 | + return rs; | |
| 79 | + } | |
| 80 | + | |
| 81 | + public static void LoadGpsRealData() throws Exception { | |
| 82 | + List<GpsRealData> list = new ArrayList<>(); | |
| 83 | + CloseableHttpClient httpClient = null; | |
| 84 | + | |
| 85 | + try { | |
| 86 | + httpClient = HttpClients.createDefault(); | |
| 87 | + HttpGet get = new HttpGet(url); | |
| 88 | + | |
| 89 | + CloseableHttpResponse response = httpClient.execute(get); | |
| 90 | + | |
| 91 | + try { | |
| 92 | + HttpEntity entity = response.getEntity(); | |
| 93 | + if (null != entity) { | |
| 94 | + // 返回数据量比较大,建议以流的形式读取 | |
| 95 | + BufferedReader br = new BufferedReader(new InputStreamReader(entity.getContent())); | |
| 96 | + StringBuffer stringBuffer = new StringBuffer(); | |
| 97 | + String str = ""; | |
| 98 | + while ((str = br.readLine()) != null) | |
| 99 | + stringBuffer.append(str); | |
| 100 | + | |
| 101 | + JSONObject jsonObj = JSON.parseObject(stringBuffer.toString()); | |
| 102 | + | |
| 103 | + if (jsonObj != null) | |
| 104 | + list = JSON.parseArray(jsonObj.getString("data"), GpsRealData.class); | |
| 105 | + | |
| 106 | + for(GpsRealData gps : list){ | |
| 107 | + gps.setNbbm(BasicData.deviceId2NbbmMap.get(gps)); | |
| 108 | + add(gps); | |
| 109 | + } | |
| 110 | + } else | |
| 111 | + logger.error("result is null"); | |
| 112 | + } finally { | |
| 113 | + response.close(); | |
| 114 | + } | |
| 115 | + | |
| 116 | + } finally { | |
| 117 | + if (null != httpClient) | |
| 118 | + httpClient.close(); | |
| 119 | + } | |
| 120 | + } | |
| 121 | +} | ... | ... |
src/main/java/com/bsth/data/gpsdata/GpsRealEntity.java
0 → 100644
| 1 | +package com.bsth.data.gpsdata; | |
| 2 | + | |
| 3 | +/** | |
| 4 | + * | |
| 5 | + * @ClassName: GpsRealData | |
| 6 | + * @Description: TODO(HTTP接口的实时GPS数据) | |
| 7 | + * @author PanZhao | |
| 8 | + * @date 2016年5月11日 下午4:32:07 | |
| 9 | + * | |
| 10 | + */ | |
| 11 | +public class GpsRealEntity { | |
| 12 | + | |
| 13 | + /** 公司代码 */ | |
| 14 | + private Integer companyCode; | |
| 15 | + | |
| 16 | + /** 线路编码 */ | |
| 17 | + private Integer lineId; | |
| 18 | + | |
| 19 | + /** 设备编码 */ | |
| 20 | + private String deviceId; | |
| 21 | + | |
| 22 | + /** 停车场编码 */ | |
| 23 | + private String carparkNo; | |
| 24 | + | |
| 25 | + /** 站点编码 */ | |
| 26 | + private String stopNo; | |
| 27 | + | |
| 28 | + /** 经度 */ | |
| 29 | + private Float lon; | |
| 30 | + | |
| 31 | + /** 纬度 */ | |
| 32 | + private Float lat; | |
| 33 | + | |
| 34 | + /** 发送时间戳 */ | |
| 35 | + private Long timestamp; | |
| 36 | + | |
| 37 | + /** 速度 */ | |
| 38 | + private Float speed; | |
| 39 | + | |
| 40 | + /** 方向(角度) */ | |
| 41 | + private Float direction; | |
| 42 | + | |
| 43 | + /** 营运状态( 0 营运 ,1 非营运, -1 无效) */ | |
| 44 | + private Integer state; | |
| 45 | + | |
| 46 | + /** 上下行(0 上行 , 1 下行 , -1 无效) */ | |
| 47 | + private Integer upDown; | |
| 48 | + | |
| 49 | + /** 车辆内部编码 */ | |
| 50 | + private String nbbm; | |
| 51 | + | |
| 52 | + /** 站点名称 */ | |
| 53 | + private String stationName; | |
| 54 | + | |
| 55 | + /** 当前班次ID */ | |
| 56 | + private Long currSchId; | |
| 57 | + | |
| 58 | + /** 下一个班次ID */ | |
| 59 | + private Long nextSchId; | |
| 60 | + | |
| 61 | + /** 设备是否在线 */ | |
| 62 | + private boolean online; | |
| 63 | + | |
| 64 | + public Integer getCompanyCode() { | |
| 65 | + return companyCode; | |
| 66 | + } | |
| 67 | + | |
| 68 | + public void setCompanyCode(Integer companyCode) { | |
| 69 | + this.companyCode = companyCode; | |
| 70 | + } | |
| 71 | + | |
| 72 | + public Integer getLineId() { | |
| 73 | + return lineId; | |
| 74 | + } | |
| 75 | + | |
| 76 | + public void setLineId(Integer lineId) { | |
| 77 | + this.lineId = lineId; | |
| 78 | + } | |
| 79 | + | |
| 80 | + public String getDeviceId() { | |
| 81 | + return deviceId; | |
| 82 | + } | |
| 83 | + | |
| 84 | + public void setDeviceId(String deviceId) { | |
| 85 | + this.deviceId = deviceId; | |
| 86 | + } | |
| 87 | + | |
| 88 | + public String getCarparkNo() { | |
| 89 | + return carparkNo; | |
| 90 | + } | |
| 91 | + | |
| 92 | + public void setCarparkNo(String carparkNo) { | |
| 93 | + this.carparkNo = carparkNo; | |
| 94 | + } | |
| 95 | + | |
| 96 | + public String getStopNo() { | |
| 97 | + return stopNo; | |
| 98 | + } | |
| 99 | + | |
| 100 | + public void setStopNo(String stopNo) { | |
| 101 | + this.stopNo = stopNo; | |
| 102 | + } | |
| 103 | + | |
| 104 | + public Float getLon() { | |
| 105 | + return lon; | |
| 106 | + } | |
| 107 | + | |
| 108 | + public void setLon(Float lon) { | |
| 109 | + this.lon = lon; | |
| 110 | + } | |
| 111 | + | |
| 112 | + public Float getLat() { | |
| 113 | + return lat; | |
| 114 | + } | |
| 115 | + | |
| 116 | + public void setLat(Float lat) { | |
| 117 | + this.lat = lat; | |
| 118 | + } | |
| 119 | + | |
| 120 | + public Long getTimestamp() { | |
| 121 | + return timestamp; | |
| 122 | + } | |
| 123 | + | |
| 124 | + public void setTimestamp(Long timestamp) { | |
| 125 | + this.timestamp = timestamp; | |
| 126 | + } | |
| 127 | + | |
| 128 | + public Float getSpeed() { | |
| 129 | + return speed; | |
| 130 | + } | |
| 131 | + | |
| 132 | + public void setSpeed(Float speed) { | |
| 133 | + this.speed = speed; | |
| 134 | + } | |
| 135 | + | |
| 136 | + public Float getDirection() { | |
| 137 | + return direction; | |
| 138 | + } | |
| 139 | + | |
| 140 | + public void setDirection(Float direction) { | |
| 141 | + this.direction = direction; | |
| 142 | + } | |
| 143 | + | |
| 144 | + public Integer getState() { | |
| 145 | + return state; | |
| 146 | + } | |
| 147 | + | |
| 148 | + public void setState(Integer state) { | |
| 149 | + this.state = state; | |
| 150 | + } | |
| 151 | + | |
| 152 | + public Integer getUpDown() { | |
| 153 | + return upDown; | |
| 154 | + } | |
| 155 | + | |
| 156 | + public void setUpDown(Integer upDown) { | |
| 157 | + this.upDown = upDown; | |
| 158 | + } | |
| 159 | + | |
| 160 | + public Long getCurrSchId() { | |
| 161 | + return currSchId; | |
| 162 | + } | |
| 163 | + | |
| 164 | + public void setCurrSchId(Long currSchId) { | |
| 165 | + this.currSchId = currSchId; | |
| 166 | + } | |
| 167 | + | |
| 168 | + public Long getNextSchId() { | |
| 169 | + return nextSchId; | |
| 170 | + } | |
| 171 | + | |
| 172 | + public void setNextSchId(Long nextSchId) { | |
| 173 | + this.nextSchId = nextSchId; | |
| 174 | + } | |
| 175 | + | |
| 176 | + public String getNbbm() { | |
| 177 | + return nbbm; | |
| 178 | + } | |
| 179 | + | |
| 180 | + public void setNbbm(String nbbm) { | |
| 181 | + this.nbbm = nbbm; | |
| 182 | + } | |
| 183 | + | |
| 184 | + public String getStationName() { | |
| 185 | + return stationName; | |
| 186 | + } | |
| 187 | + | |
| 188 | + public void setStationName(String stationName) { | |
| 189 | + this.stationName = stationName; | |
| 190 | + } | |
| 191 | + | |
| 192 | + public boolean isOnline() { | |
| 193 | + return online; | |
| 194 | + } | |
| 195 | + | |
| 196 | + public void setOnline(boolean online) { | |
| 197 | + this.online = online; | |
| 198 | + } | |
| 199 | +} | ... | ... |
src/main/java/com/bsth/entity/directive/D60.java
0 → 100644
| 1 | +package com.bsth.entity.directive; | |
| 2 | + | |
| 3 | +import javax.persistence.Embeddable; | |
| 4 | +import javax.persistence.Entity; | |
| 5 | +import javax.persistence.FetchType; | |
| 6 | +import javax.persistence.GeneratedValue; | |
| 7 | +import javax.persistence.Id; | |
| 8 | +import javax.persistence.ManyToOne; | |
| 9 | +import javax.persistence.NamedAttributeNode; | |
| 10 | +import javax.persistence.NamedEntityGraph; | |
| 11 | +import javax.persistence.NamedEntityGraphs; | |
| 12 | +import javax.persistence.Table; | |
| 13 | +import javax.persistence.Transient; | |
| 14 | + | |
| 15 | +import com.bsth.entity.realcontrol.ScheduleRealInfo; | |
| 16 | +import com.fasterxml.jackson.annotation.JsonIgnore; | |
| 17 | + | |
| 18 | + | |
| 19 | +/** | |
| 20 | + * | |
| 21 | + * @ClassName: D60 | |
| 22 | + * @Description: TODO(调度指令) | |
| 23 | + * @author PanZhao | |
| 24 | + * @date 2016年6月7日 上午10:21:59 | |
| 25 | + * | |
| 26 | + */ | |
| 27 | +@Entity | |
| 28 | +@Table(name = "bsth_v_directive_60") | |
| 29 | +@NamedEntityGraphs({ | |
| 30 | + @NamedEntityGraph(name = "directive60_sch", attributeNodes = { | |
| 31 | + @NamedAttributeNode("sch") | |
| 32 | + }) | |
| 33 | +}) | |
| 34 | +public class D60 extends Directive{ | |
| 35 | + | |
| 36 | + @Id | |
| 37 | + @GeneratedValue | |
| 38 | + private Integer id; | |
| 39 | + | |
| 40 | + /** | |
| 41 | + * 数据 | |
| 42 | + */ | |
| 43 | + private DirectiveData data; | |
| 44 | + | |
| 45 | + /** | |
| 46 | + * 唯一标识 | |
| 47 | + */ | |
| 48 | + @Transient | |
| 49 | + private Integer msgId; | |
| 50 | + | |
| 51 | + /** | |
| 52 | + * 46上行 | |
| 53 | + */ | |
| 54 | + private Short reply46 = -1; | |
| 55 | + | |
| 56 | + /** | |
| 57 | + * 47上行 | |
| 58 | + */ | |
| 59 | + private Short reply47 = -1; | |
| 60 | + | |
| 61 | + /** | |
| 62 | + * 是否是调度指令 | |
| 63 | + * 目前调度指令和消息短语都是短语下发,所以从协议上无法区分 | |
| 64 | + */ | |
| 65 | + private boolean isDispatch; | |
| 66 | + | |
| 67 | + /** | |
| 68 | + * 相关联的班次 | |
| 69 | + */ | |
| 70 | + @JsonIgnore | |
| 71 | + @ManyToOne(fetch = FetchType.LAZY) | |
| 72 | + private ScheduleRealInfo sch; | |
| 73 | + | |
| 74 | + @Embeddable | |
| 75 | + public static class DirectiveData { | |
| 76 | + // 公司代码 | |
| 77 | + private short companyCode; | |
| 78 | + | |
| 79 | + // 设备号 | |
| 80 | + @Transient | |
| 81 | + private String deviceId; | |
| 82 | + | |
| 83 | + // 时间戳 | |
| 84 | + @Transient | |
| 85 | + private Long timestamp; | |
| 86 | + | |
| 87 | + // 保留 默认0 | |
| 88 | + private short instructType = 0; | |
| 89 | + | |
| 90 | + /* | |
| 91 | + * 调度指令 调度指令。 | |
| 92 | + * 0X00表示信息短语 | |
| 93 | + * 0X01表示取消上次指令+调度指令(闹钟有效) | |
| 94 | + * 0x02表示为调度指令(闹钟有效) | |
| 95 | + * 0x03表示运营状态指令(闹钟无效) | |
| 96 | + * 0x04表示其他指令 | |
| 97 | + */ | |
| 98 | + private Short dispatchInstruct; | |
| 99 | + | |
| 100 | + // 唯一标识 | |
| 101 | + private int msgId; | |
| 102 | + | |
| 103 | + // 闹钟 | |
| 104 | + private Long alarmTime; | |
| 105 | + | |
| 106 | + // 多个运营状态字节 | |
| 107 | + private Long serviceState; | |
| 108 | + | |
| 109 | + // 消息文本 | |
| 110 | + private String txtContent; | |
| 111 | + | |
| 112 | + public short getCompanyCode() { | |
| 113 | + return companyCode; | |
| 114 | + } | |
| 115 | + | |
| 116 | + public void setCompanyCode(short companyCode) { | |
| 117 | + this.companyCode = companyCode; | |
| 118 | + } | |
| 119 | + | |
| 120 | + public String getDeviceId() { | |
| 121 | + return deviceId; | |
| 122 | + } | |
| 123 | + | |
| 124 | + public void setDeviceId(String deviceId) { | |
| 125 | + this.deviceId = deviceId; | |
| 126 | + } | |
| 127 | + | |
| 128 | + public Long getTimestamp() { | |
| 129 | + return timestamp; | |
| 130 | + } | |
| 131 | + | |
| 132 | + public void setTimestamp(Long timestamp) { | |
| 133 | + this.timestamp = timestamp; | |
| 134 | + } | |
| 135 | + | |
| 136 | + public short getInstructType() { | |
| 137 | + return instructType; | |
| 138 | + } | |
| 139 | + | |
| 140 | + public void setInstructType(short instructType) { | |
| 141 | + this.instructType = instructType; | |
| 142 | + } | |
| 143 | + | |
| 144 | + public Short getDispatchInstruct() { | |
| 145 | + return dispatchInstruct; | |
| 146 | + } | |
| 147 | + | |
| 148 | + public void setDispatchInstruct(Short dispatchInstruct) { | |
| 149 | + this.dispatchInstruct = dispatchInstruct; | |
| 150 | + } | |
| 151 | + | |
| 152 | + public int getMsgId() { | |
| 153 | + return msgId; | |
| 154 | + } | |
| 155 | + | |
| 156 | + public void setMsgId(int msgId) { | |
| 157 | + this.msgId = msgId; | |
| 158 | + } | |
| 159 | + | |
| 160 | + public Long getAlarmTime() { | |
| 161 | + return alarmTime; | |
| 162 | + } | |
| 163 | + | |
| 164 | + public void setAlarmTime(Long alarmTime) { | |
| 165 | + this.alarmTime = alarmTime; | |
| 166 | + } | |
| 167 | + | |
| 168 | + public Long getServiceState() { | |
| 169 | + return serviceState; | |
| 170 | + } | |
| 171 | + | |
| 172 | + public void setServiceState(Long serviceState) { | |
| 173 | + this.serviceState = serviceState; | |
| 174 | + } | |
| 175 | + | |
| 176 | + public String getTxtContent() { | |
| 177 | + return txtContent; | |
| 178 | + } | |
| 179 | + | |
| 180 | + public void setTxtContent(String txtContent) { | |
| 181 | + this.txtContent = txtContent; | |
| 182 | + } | |
| 183 | + } | |
| 184 | + | |
| 185 | + public Integer getId() { | |
| 186 | + return id; | |
| 187 | + } | |
| 188 | + | |
| 189 | + public void setId(Integer id) { | |
| 190 | + this.id = id; | |
| 191 | + } | |
| 192 | + | |
| 193 | + public short getOperCode() { | |
| 194 | + return operCode; | |
| 195 | + } | |
| 196 | + | |
| 197 | + public void setOperCode(short operCode) { | |
| 198 | + this.operCode = operCode; | |
| 199 | + } | |
| 200 | + | |
| 201 | + public DirectiveData getData() { | |
| 202 | + return data; | |
| 203 | + } | |
| 204 | + | |
| 205 | + public void setData(DirectiveData data) { | |
| 206 | + this.data = data; | |
| 207 | + } | |
| 208 | + | |
| 209 | + public Integer getMsgId() { | |
| 210 | + if(this.msgId != null) | |
| 211 | + return this.msgId; | |
| 212 | + else | |
| 213 | + return this.getData().getMsgId(); | |
| 214 | + } | |
| 215 | + | |
| 216 | + public void setMsgId(Integer msgId) { | |
| 217 | + this.msgId = msgId; | |
| 218 | + } | |
| 219 | + | |
| 220 | + @Override | |
| 221 | + public void setTimestamp(Long timestamp) { | |
| 222 | + if(this.data != null) | |
| 223 | + this.data.setTimestamp(timestamp); | |
| 224 | + | |
| 225 | + this.timestamp = timestamp; | |
| 226 | + } | |
| 227 | + | |
| 228 | + @Override | |
| 229 | + public void setDeviceId(String deviceId) { | |
| 230 | + if(this.data != null) | |
| 231 | + this.data.setDeviceId(deviceId); | |
| 232 | + | |
| 233 | + this.deviceId = deviceId; | |
| 234 | + } | |
| 235 | + | |
| 236 | + public Short getReply46() { | |
| 237 | + return reply46; | |
| 238 | + } | |
| 239 | + | |
| 240 | + public void setReply46(Short reply46) { | |
| 241 | + this.reply46 = reply46; | |
| 242 | + } | |
| 243 | + | |
| 244 | + public Short getReply47() { | |
| 245 | + return reply47; | |
| 246 | + } | |
| 247 | + | |
| 248 | + public void setReply47(Short reply47) { | |
| 249 | + this.reply47 = reply47; | |
| 250 | + } | |
| 251 | + | |
| 252 | + public boolean isDispatch() { | |
| 253 | + return isDispatch; | |
| 254 | + } | |
| 255 | + | |
| 256 | + public void setDispatch(boolean isDispatch) { | |
| 257 | + this.isDispatch = isDispatch; | |
| 258 | + } | |
| 259 | + | |
| 260 | + public ScheduleRealInfo getSch() { | |
| 261 | + return sch; | |
| 262 | + } | |
| 263 | + | |
| 264 | + public void setSch(ScheduleRealInfo sch) { | |
| 265 | + this.sch = sch; | |
| 266 | + } | |
| 267 | +} | ... | ... |
src/main/java/com/bsth/entity/directive/D64.java
0 → 100644
| 1 | +package com.bsth.entity.directive; | |
| 2 | + | |
| 3 | +import javax.persistence.Table; | |
| 4 | +import javax.persistence.Transient; | |
| 5 | +import javax.persistence.Embeddable; | |
| 6 | +import javax.persistence.Entity; | |
| 7 | +import javax.persistence.GeneratedValue; | |
| 8 | +import javax.persistence.Id; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * | |
| 12 | + * @ClassName: D64 | |
| 13 | + * @Description: TODO(线路切换指令) | |
| 14 | + * @author PanZhao | |
| 15 | + * @date 2016年6月8日 下午1:41:15 | |
| 16 | + * | |
| 17 | + */ | |
| 18 | +@Entity | |
| 19 | +@Table(name = "bsth_v_directive_64") | |
| 20 | +public class D64 extends Directive{ | |
| 21 | + | |
| 22 | + @Id | |
| 23 | + @GeneratedValue | |
| 24 | + private Integer id; | |
| 25 | + | |
| 26 | + /** | |
| 27 | + * 设备响应应答字 | |
| 28 | + * 0x06同意 0x15不同意 | |
| 29 | + */ | |
| 30 | + private Short respAck; | |
| 31 | + | |
| 32 | + private LineChangeData data; | |
| 33 | + | |
| 34 | + @Embeddable | |
| 35 | + public static class LineChangeData { | |
| 36 | + | |
| 37 | + private Short cityCode; | |
| 38 | + | |
| 39 | + @Transient | |
| 40 | + private String deviceId; | |
| 41 | + | |
| 42 | + private String lineId; | |
| 43 | + | |
| 44 | + public Short getCityCode() { | |
| 45 | + return cityCode; | |
| 46 | + } | |
| 47 | + | |
| 48 | + public void setCityCode(Short cityCode) { | |
| 49 | + this.cityCode = cityCode; | |
| 50 | + } | |
| 51 | + | |
| 52 | + public String getDeviceId() { | |
| 53 | + return deviceId; | |
| 54 | + } | |
| 55 | + | |
| 56 | + public void setDeviceId(String deviceId) { | |
| 57 | + this.deviceId = deviceId; | |
| 58 | + } | |
| 59 | + | |
| 60 | + public String getLineId() { | |
| 61 | + return lineId; | |
| 62 | + } | |
| 63 | + | |
| 64 | + public void setLineId(String lineId) { | |
| 65 | + this.lineId = lineId; | |
| 66 | + } | |
| 67 | + } | |
| 68 | + | |
| 69 | + public Integer getId() { | |
| 70 | + return id; | |
| 71 | + } | |
| 72 | + | |
| 73 | + public void setId(Integer id) { | |
| 74 | + this.id = id; | |
| 75 | + } | |
| 76 | + | |
| 77 | + public LineChangeData getData() { | |
| 78 | + return data; | |
| 79 | + } | |
| 80 | + | |
| 81 | + public void setData(LineChangeData data) { | |
| 82 | + this.data = data; | |
| 83 | + } | |
| 84 | + | |
| 85 | + public Short getRespAck() { | |
| 86 | + return respAck; | |
| 87 | + } | |
| 88 | + | |
| 89 | + public void setRespAck(Short respAck) { | |
| 90 | + this.respAck = respAck; | |
| 91 | + } | |
| 92 | + | |
| 93 | + @Override | |
| 94 | + public void setDeviceId(String deviceId) { | |
| 95 | + if(this.data != null) | |
| 96 | + this.data.setDeviceId(deviceId); | |
| 97 | + | |
| 98 | + this.deviceId = deviceId; | |
| 99 | + } | |
| 100 | +} | ... | ... |
src/main/java/com/bsth/entity/directive/D80.java
0 → 100644
| 1 | +package com.bsth.entity.directive; | |
| 2 | + | |
| 3 | +import java.util.Date; | |
| 4 | + | |
| 5 | +import javax.persistence.CascadeType; | |
| 6 | +import javax.persistence.Embeddable; | |
| 7 | +import javax.persistence.Entity; | |
| 8 | +import javax.persistence.FetchType; | |
| 9 | +import javax.persistence.GeneratedValue; | |
| 10 | +import javax.persistence.Id; | |
| 11 | +import javax.persistence.NamedAttributeNode; | |
| 12 | +import javax.persistence.NamedEntityGraph; | |
| 13 | +import javax.persistence.NamedEntityGraphs; | |
| 14 | +import javax.persistence.OneToOne; | |
| 15 | +import javax.persistence.Table; | |
| 16 | +import javax.persistence.Transient; | |
| 17 | + | |
| 18 | +/** | |
| 19 | + * | |
| 20 | + * @ClassName: D80 | |
| 21 | + * @Description: TODO(驾驶员上报) | |
| 22 | + * @author PanZhao | |
| 23 | + * @date 2016年6月8日 下午12:36:42 | |
| 24 | + * | |
| 25 | + */ | |
| 26 | +@Entity | |
| 27 | +@Table(name = "bsth_v_report_80") | |
| 28 | +@NamedEntityGraphs({ | |
| 29 | + @NamedEntityGraph(name = "directive80_c0", attributeNodes = { | |
| 30 | + @NamedAttributeNode("c0") | |
| 31 | + }) | |
| 32 | +}) | |
| 33 | +public class D80 { | |
| 34 | + | |
| 35 | + @Id | |
| 36 | + @GeneratedValue | |
| 37 | + private Integer id; | |
| 38 | + | |
| 39 | + /** | |
| 40 | + * 设备编号 | |
| 41 | + */ | |
| 42 | + private String deviceId; | |
| 43 | + | |
| 44 | + /** | |
| 45 | + * 时间戳(ms) | |
| 46 | + */ | |
| 47 | + private Long timestamp; | |
| 48 | + | |
| 49 | + /** | |
| 50 | + * 一级协议 0xC0 | |
| 51 | + */ | |
| 52 | + private Short operCode; | |
| 53 | + | |
| 54 | + private DriverReportData data; | |
| 55 | + | |
| 56 | + /** | |
| 57 | + * c0 回复 | |
| 58 | + */ | |
| 59 | + @OneToOne(cascade = CascadeType.ALL, fetch=FetchType.LAZY) | |
| 60 | + private DC0 c0; | |
| 61 | + | |
| 62 | + /** 调度员是否确认 */ | |
| 63 | + private boolean confirm; | |
| 64 | + | |
| 65 | + /** 处理人 */ | |
| 66 | + private String handleUser; | |
| 67 | + | |
| 68 | + /** 处理结果 0:同意 -1:不同意 */ | |
| 69 | + private int confirmRs; | |
| 70 | + | |
| 71 | + /** 处理时间 */ | |
| 72 | + private Date handleTime; | |
| 73 | + | |
| 74 | + @Embeddable | |
| 75 | + public static class DriverReportData { | |
| 76 | + | |
| 77 | + /** | |
| 78 | + * 0x86 | |
| 79 | + */ | |
| 80 | + private Short operCode2; | |
| 81 | + | |
| 82 | + /** | |
| 83 | + * 请求代码 0xa1 恢复运营 0xa2 申请调档 0xa3 出场请求 0xa5 进场请求 0xa7 加油请求 0x50 车辆故障 0x70 | |
| 84 | + * 路阻报告 0x60 事故报告 0x11 扣证纠纷 0x12 报警 | |
| 85 | + */ | |
| 86 | + private Short requestCode; | |
| 87 | + | |
| 88 | + /** | |
| 89 | + * 线路编码 | |
| 90 | + */ | |
| 91 | + private Integer lineId; | |
| 92 | + | |
| 93 | + /** | |
| 94 | + * 车辆内部编码 | |
| 95 | + */ | |
| 96 | + @Transient | |
| 97 | + private String nbbm; | |
| 98 | + | |
| 99 | + public Short getOperCode2() { | |
| 100 | + return operCode2; | |
| 101 | + } | |
| 102 | + | |
| 103 | + public void setOperCode2(Short operCode2) { | |
| 104 | + this.operCode2 = operCode2; | |
| 105 | + } | |
| 106 | + | |
| 107 | + public Short getRequestCode() { | |
| 108 | + return requestCode; | |
| 109 | + } | |
| 110 | + | |
| 111 | + public void setRequestCode(Short requestCode) { | |
| 112 | + this.requestCode = requestCode; | |
| 113 | + } | |
| 114 | + | |
| 115 | + public Integer getLineId() { | |
| 116 | + return lineId; | |
| 117 | + } | |
| 118 | + | |
| 119 | + public void setLineId(Integer lineId) { | |
| 120 | + this.lineId = lineId; | |
| 121 | + } | |
| 122 | + | |
| 123 | + public String getNbbm() { | |
| 124 | + return nbbm; | |
| 125 | + } | |
| 126 | + | |
| 127 | + public void setNbbm(String nbbm) { | |
| 128 | + this.nbbm = nbbm; | |
| 129 | + } | |
| 130 | + } | |
| 131 | + | |
| 132 | + @Transient | |
| 133 | + private String timeStr; | |
| 134 | + | |
| 135 | + public Integer getId() { | |
| 136 | + return id; | |
| 137 | + } | |
| 138 | + | |
| 139 | + public void setId(Integer id) { | |
| 140 | + this.id = id; | |
| 141 | + } | |
| 142 | + | |
| 143 | + public String getDeviceId() { | |
| 144 | + return deviceId; | |
| 145 | + } | |
| 146 | + | |
| 147 | + public void setDeviceId(String deviceId) { | |
| 148 | + this.deviceId = deviceId; | |
| 149 | + } | |
| 150 | + | |
| 151 | + public Long getTimestamp() { | |
| 152 | + return timestamp; | |
| 153 | + } | |
| 154 | + | |
| 155 | + public void setTimestamp(Long timestamp) { | |
| 156 | + this.timestamp = timestamp; | |
| 157 | + } | |
| 158 | + | |
| 159 | + public Short getOperCode() { | |
| 160 | + return operCode; | |
| 161 | + } | |
| 162 | + | |
| 163 | + public void setOperCode(Short operCode) { | |
| 164 | + this.operCode = operCode; | |
| 165 | + } | |
| 166 | + | |
| 167 | + public DriverReportData getData() { | |
| 168 | + return data; | |
| 169 | + } | |
| 170 | + | |
| 171 | + public void setData(DriverReportData data) { | |
| 172 | + this.data = data; | |
| 173 | + } | |
| 174 | + | |
| 175 | + public DC0 getC0() { | |
| 176 | + return c0; | |
| 177 | + } | |
| 178 | + | |
| 179 | + public void setC0(DC0 c0) { | |
| 180 | + this.c0 = c0; | |
| 181 | + } | |
| 182 | + | |
| 183 | + public boolean isConfirm() { | |
| 184 | + return confirm; | |
| 185 | + } | |
| 186 | + | |
| 187 | + public void setConfirm(boolean confirm) { | |
| 188 | + this.confirm = confirm; | |
| 189 | + } | |
| 190 | + | |
| 191 | + public int getConfirmRs() { | |
| 192 | + return confirmRs; | |
| 193 | + } | |
| 194 | + | |
| 195 | + public void setConfirmRs(int confirmRs) { | |
| 196 | + this.confirmRs = confirmRs; | |
| 197 | + } | |
| 198 | + | |
| 199 | + public String getHandleUser() { | |
| 200 | + return handleUser; | |
| 201 | + } | |
| 202 | + | |
| 203 | + public void setHandleUser(String handleUser) { | |
| 204 | + this.handleUser = handleUser; | |
| 205 | + } | |
| 206 | + | |
| 207 | + public String getTimeStr() { | |
| 208 | + return timeStr; | |
| 209 | + } | |
| 210 | + | |
| 211 | + public void setTimeStr(String timeStr) { | |
| 212 | + this.timeStr = timeStr; | |
| 213 | + } | |
| 214 | + | |
| 215 | + public Date getHandleTime() { | |
| 216 | + return handleTime; | |
| 217 | + } | |
| 218 | + | |
| 219 | + public void setHandleTime(Date handleTime) { | |
| 220 | + this.handleTime = handleTime; | |
| 221 | + } | |
| 222 | +} | ... | ... |
src/main/java/com/bsth/entity/directive/DC0.java
0 → 100644
| 1 | +package com.bsth.entity.directive; | |
| 2 | + | |
| 3 | +import javax.persistence.Embeddable; | |
| 4 | +import javax.persistence.Entity; | |
| 5 | +import javax.persistence.GeneratedValue; | |
| 6 | +import javax.persistence.Id; | |
| 7 | +import javax.persistence.Table; | |
| 8 | + | |
| 9 | +/** | |
| 10 | + * | |
| 11 | + * @ClassName: DC0 | |
| 12 | + * @Description: TODO(C0协议,回复驾驶员上报) | |
| 13 | + * @author PanZhao | |
| 14 | + * @date 2016年7月8日 上午10:19:23 | |
| 15 | + * | |
| 16 | + */ | |
| 17 | +@Entity | |
| 18 | +@Table(name = "bsth_v_C0") | |
| 19 | +public class DC0 { | |
| 20 | + | |
| 21 | + @Id | |
| 22 | + @GeneratedValue | |
| 23 | + private Integer id; | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * 设备号 | |
| 27 | + */ | |
| 28 | + private String deviceId; | |
| 29 | + | |
| 30 | + /** | |
| 31 | + * 时间戳 | |
| 32 | + */ | |
| 33 | + private Long timestamp; | |
| 34 | + | |
| 35 | + /** | |
| 36 | + * 一级协议 | |
| 37 | + */ | |
| 38 | + private Short operCode; | |
| 39 | + | |
| 40 | + private DC0Data data; | |
| 41 | + | |
| 42 | + @Embeddable | |
| 43 | + public static class DC0Data { | |
| 44 | + | |
| 45 | + /** | |
| 46 | + * 二级协议 | |
| 47 | + */ | |
| 48 | + private Short operCode2; | |
| 49 | + | |
| 50 | + /** | |
| 51 | + * 请求应答字 0x06同意 0x15不同意 | |
| 52 | + */ | |
| 53 | + private Short requestAck; | |
| 54 | + | |
| 55 | + public Short getOperCode2() { | |
| 56 | + return operCode2; | |
| 57 | + } | |
| 58 | + | |
| 59 | + public void setOperCode2(Short operCode2) { | |
| 60 | + this.operCode2 = operCode2; | |
| 61 | + } | |
| 62 | + | |
| 63 | + public Short getRequestAck() { | |
| 64 | + return requestAck; | |
| 65 | + } | |
| 66 | + | |
| 67 | + public void setRequestAck(Short requestAck) { | |
| 68 | + this.requestAck = requestAck; | |
| 69 | + } | |
| 70 | + } | |
| 71 | + | |
| 72 | + public Integer getId() { | |
| 73 | + return id; | |
| 74 | + } | |
| 75 | + | |
| 76 | + public void setId(Integer id) { | |
| 77 | + this.id = id; | |
| 78 | + } | |
| 79 | + | |
| 80 | + public String getDeviceId() { | |
| 81 | + return deviceId; | |
| 82 | + } | |
| 83 | + | |
| 84 | + public void setDeviceId(String deviceId) { | |
| 85 | + this.deviceId = deviceId; | |
| 86 | + } | |
| 87 | + | |
| 88 | + public Long getTimestamp() { | |
| 89 | + return timestamp; | |
| 90 | + } | |
| 91 | + | |
| 92 | + public void setTimestamp(Long timestamp) { | |
| 93 | + this.timestamp = timestamp; | |
| 94 | + } | |
| 95 | + | |
| 96 | + public Short getOperCode() { | |
| 97 | + return operCode; | |
| 98 | + } | |
| 99 | + | |
| 100 | + public void setOperCode(Short operCode) { | |
| 101 | + this.operCode = operCode; | |
| 102 | + } | |
| 103 | + | |
| 104 | + public DC0Data getData() { | |
| 105 | + return data; | |
| 106 | + } | |
| 107 | + | |
| 108 | + public void setData(DC0Data data) { | |
| 109 | + this.data = data; | |
| 110 | + } | |
| 111 | +} | ... | ... |
src/main/java/com/bsth/entity/directive/Directive.java
0 → 100644
| 1 | +package com.bsth.entity.directive; | |
| 2 | + | |
| 3 | +import javax.persistence.MappedSuperclass; | |
| 4 | +import javax.persistence.Transient; | |
| 5 | + | |
| 6 | +/** | |
| 7 | + * | |
| 8 | + * @ClassName: Directive | |
| 9 | + * @Description: TODO(指令基础类) | |
| 10 | + * @author PanZhao | |
| 11 | + * @date 2016年7月31日 下午8:35:56 | |
| 12 | + * | |
| 13 | + */ | |
| 14 | +@MappedSuperclass | |
| 15 | +public class Directive { | |
| 16 | + | |
| 17 | + /** | |
| 18 | + * 一级协议 | |
| 19 | + */ | |
| 20 | + protected short operCode; | |
| 21 | + | |
| 22 | + /** | |
| 23 | + * 设备号 | |
| 24 | + */ | |
| 25 | + protected String deviceId; | |
| 26 | + | |
| 27 | + /** | |
| 28 | + * 时间戳 | |
| 29 | + */ | |
| 30 | + protected Long timestamp; | |
| 31 | + | |
| 32 | + /** | |
| 33 | + * 时间 HH:mm | |
| 34 | + */ | |
| 35 | + @Transient | |
| 36 | + private String timeHHmm; | |
| 37 | + | |
| 38 | + /** | |
| 39 | + * 车辆内部编码 | |
| 40 | + */ | |
| 41 | + @Transient | |
| 42 | + private String nbbm; | |
| 43 | + | |
| 44 | + private String errorText; | |
| 45 | + | |
| 46 | + private int httpCode; | |
| 47 | + | |
| 48 | + /** | |
| 49 | + * 发送人 | |
| 50 | + */ | |
| 51 | + private String sender; | |
| 52 | + | |
| 53 | + public short getOperCode() { | |
| 54 | + return operCode; | |
| 55 | + } | |
| 56 | + | |
| 57 | + public void setOperCode(short operCode) { | |
| 58 | + this.operCode = operCode; | |
| 59 | + } | |
| 60 | + | |
| 61 | + public String getDeviceId() { | |
| 62 | + return deviceId; | |
| 63 | + } | |
| 64 | + | |
| 65 | + public void setDeviceId(String deviceId) { | |
| 66 | + this.deviceId = deviceId; | |
| 67 | + } | |
| 68 | + | |
| 69 | + public Long getTimestamp() { | |
| 70 | + return timestamp; | |
| 71 | + } | |
| 72 | + | |
| 73 | + public void setTimestamp(Long timestamp) { | |
| 74 | + this.timestamp = timestamp; | |
| 75 | + } | |
| 76 | + | |
| 77 | + public String getTimeHHmm() { | |
| 78 | + return timeHHmm; | |
| 79 | + } | |
| 80 | + | |
| 81 | + public void setTimeHHmm(String timeHHmm) { | |
| 82 | + this.timeHHmm = timeHHmm; | |
| 83 | + } | |
| 84 | + | |
| 85 | + public String getNbbm() { | |
| 86 | + return nbbm; | |
| 87 | + } | |
| 88 | + | |
| 89 | + public void setNbbm(String nbbm) { | |
| 90 | + this.nbbm = nbbm; | |
| 91 | + } | |
| 92 | + | |
| 93 | + public String getErrorText() { | |
| 94 | + return errorText; | |
| 95 | + } | |
| 96 | + | |
| 97 | + public void setErrorText(String errorText) { | |
| 98 | + this.errorText = errorText; | |
| 99 | + } | |
| 100 | + | |
| 101 | + public int getHttpCode() { | |
| 102 | + return httpCode; | |
| 103 | + } | |
| 104 | + | |
| 105 | + public void setHttpCode(int httpCode) { | |
| 106 | + this.httpCode = httpCode; | |
| 107 | + } | |
| 108 | + | |
| 109 | + public String getSender() { | |
| 110 | + return sender; | |
| 111 | + } | |
| 112 | + | |
| 113 | + public void setSender(String sender) { | |
| 114 | + this.sender = sender; | |
| 115 | + } | |
| 116 | +} | ... | ... |
src/main/java/com/bsth/repository/directive/D60Repository.java
0 → 100644
| 1 | +package com.bsth.repository.directive; | |
| 2 | + | |
| 3 | +import java.util.List; | |
| 4 | + | |
| 5 | +import org.springframework.data.domain.Page; | |
| 6 | +import org.springframework.data.domain.Pageable; | |
| 7 | +import org.springframework.data.jpa.domain.Specification; | |
| 8 | +import org.springframework.data.jpa.repository.EntityGraph; | |
| 9 | +import org.springframework.data.jpa.repository.Query; | |
| 10 | +import org.springframework.stereotype.Repository; | |
| 11 | + | |
| 12 | +import com.bsth.entity.directive.D60; | |
| 13 | +import com.bsth.repository.BaseRepository; | |
| 14 | + | |
| 15 | +@Repository | |
| 16 | +public interface D60Repository extends BaseRepository<D60, Integer>{ | |
| 17 | + | |
| 18 | + @EntityGraph(value = "directive60_sch", type = EntityGraph.EntityGraphType.FETCH) | |
| 19 | + @Query("select d from Directive60 d where d.timestamp > ?1") | |
| 20 | + public List<D60> findByGtTime(Long ts); | |
| 21 | + | |
| 22 | + @Query(value = "SELECT IFNULL(num,0) as maxId from (SELECT MAX(msg_id) as num FROM bsth_v_directive_60) d", nativeQuery = true) | |
| 23 | + Integer maxMsgId(); | |
| 24 | + | |
| 25 | + | |
| 26 | + @EntityGraph(value = "directive60_sch", type = EntityGraph.EntityGraphType.FETCH) | |
| 27 | + @Override | |
| 28 | + Page<D60> findAll(Specification<D60> spec, Pageable pageable); | |
| 29 | + | |
| 30 | + @EntityGraph(value = "directive60_sch", type = EntityGraph.EntityGraphType.FETCH) | |
| 31 | + @Override | |
| 32 | + List<D60> findAll(Specification<D60> spec); | |
| 33 | +} | ... | ... |
src/main/java/com/bsth/repository/directive/D64Repository.java
0 → 100644
src/main/java/com/bsth/repository/directive/D80Repository.java
0 → 100644
| 1 | +package com.bsth.repository.directive; | |
| 2 | + | |
| 3 | +import java.util.List; | |
| 4 | + | |
| 5 | +import org.springframework.data.domain.Page; | |
| 6 | +import org.springframework.data.domain.Pageable; | |
| 7 | +import org.springframework.data.jpa.domain.Specification; | |
| 8 | +import org.springframework.data.jpa.repository.EntityGraph; | |
| 9 | +import org.springframework.data.jpa.repository.Query; | |
| 10 | +import org.springframework.stereotype.Repository; | |
| 11 | + | |
| 12 | +import com.bsth.entity.directive.D80; | |
| 13 | +import com.bsth.repository.BaseRepository; | |
| 14 | + | |
| 15 | +@Repository | |
| 16 | +public interface D80Repository extends BaseRepository<D80, Integer>{ | |
| 17 | + | |
| 18 | + @EntityGraph(value = "directive80_c0", type = EntityGraph.EntityGraphType.FETCH) | |
| 19 | + @Override | |
| 20 | + Page<D80> findAll(Specification<D80> spec, Pageable pageable); | |
| 21 | + | |
| 22 | + @EntityGraph(value = "directive80_c0", type = EntityGraph.EntityGraphType.FETCH) | |
| 23 | + @Query("select d from Directive80 d where d.timestamp > ?1") | |
| 24 | + List<D80> findByGtTime(long timestamp); | |
| 25 | +} | ... | ... |
src/main/java/com/bsth/repository/directive/DC0Repository.java
0 → 100644
src/main/java/com/bsth/service/directive/DirectiveService.java
0 → 100644
| 1 | +package com.bsth.service.directive; | |
| 2 | + | |
| 3 | + | |
| 4 | +import java.util.List; | |
| 5 | +import java.util.Map; | |
| 6 | + | |
| 7 | +import org.springframework.data.domain.Page; | |
| 8 | +import org.springframework.data.domain.PageRequest; | |
| 9 | + | |
| 10 | +import com.bsth.entity.directive.D60; | |
| 11 | +import com.bsth.entity.directive.D80; | |
| 12 | +import com.bsth.entity.realcontrol.ScheduleRealInfo; | |
| 13 | +import com.bsth.service.BaseService; | |
| 14 | + | |
| 15 | +public interface DirectiveService extends BaseService<D60, Integer>{ | |
| 16 | + | |
| 17 | + /** | |
| 18 | + * | |
| 19 | + * @Title: send60Phrase | |
| 20 | + * @Description: TODO(60短语下发) | |
| 21 | + * @param @param nbbm 车辆内部编码 | |
| 22 | + * @param @param text 短语 | |
| 23 | + * @return int 返回类型 | |
| 24 | + * @throws | |
| 25 | + */ | |
| 26 | + int send60Phrase(String nbbm, String text, String sender); | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * | |
| 30 | + * @Title: send60Dispatch | |
| 31 | + * @Description: TODO(调度指令下发) | |
| 32 | + * @param @param sch 要下发的班次 | |
| 33 | + * @param @param finish 已完成的班次数 | |
| 34 | + * @throws | |
| 35 | + */ | |
| 36 | + int send60Dispatch(ScheduleRealInfo sch, int finish, String sender); | |
| 37 | + | |
| 38 | + /** | |
| 39 | + * | |
| 40 | + * @Title: send60Dispatch | |
| 41 | + * @Description: TODO(调度指令下发) | |
| 42 | + * @param @param id 班次ID | |
| 43 | + * @throws | |
| 44 | + */ | |
| 45 | + int send60Dispatch(Long id, String sender); | |
| 46 | + | |
| 47 | + //60营运指令 | |
| 48 | + int send60Operation(String nbbm, int state, int upDown, ScheduleRealInfo sch, String sender); | |
| 49 | + | |
| 50 | + /** | |
| 51 | + * | |
| 52 | + * @Title: lineChange | |
| 53 | + * @Description: TODO(线路切换) | |
| 54 | + * @param @param nbbm 车辆内部编码 | |
| 55 | + * @param @param lineId 新线路编码 | |
| 56 | + * @throws | |
| 57 | + */ | |
| 58 | + int lineChange(String nbbm, Integer lineId, String sender); | |
| 59 | + | |
| 60 | + /** | |
| 61 | + * | |
| 62 | + * @Title: upDownChange | |
| 63 | + * @Description: TODO(切换上下行) | |
| 64 | + * @param @param nbbm 车辆内部编码 | |
| 65 | + * @param @param upDonw 上下行 0 上行 1 下行 | |
| 66 | + * @throws | |
| 67 | + */ | |
| 68 | + int upDownChange(String nbbm, Integer upDown, String sender); | |
| 69 | + | |
| 70 | + /** | |
| 71 | + * | |
| 72 | + * @Title: sendDirectiveState | |
| 73 | + * @Description: TODO(向页面推送班次指令状态) | |
| 74 | + * @throws | |
| 75 | + */ | |
| 76 | + void sendDirectiveToPage(ScheduleRealInfo sch); | |
| 77 | + | |
| 78 | + Map<String, List<D80>> findNoCofm80(String lineCodes); | |
| 79 | + | |
| 80 | + Map<String, Object> reply80(int id, int reply); | |
| 81 | + | |
| 82 | + Map<String, Object> findDirective(String nbbm, int dType, int page, int size); | |
| 83 | + | |
| 84 | + Page<D80> findAll80(Map<String, Object> map, PageRequest pageRequest); | |
| 85 | +} | ... | ... |
src/main/java/com/bsth/service/directive/DirectiveServiceImpl.java
0 → 100644
| 1 | +package com.bsth.service.directive; | |
| 2 | + | |
| 3 | +import java.text.SimpleDateFormat; | |
| 4 | +import java.util.ArrayList; | |
| 5 | +import java.util.Collections; | |
| 6 | +import java.util.Date; | |
| 7 | +import java.util.HashMap; | |
| 8 | +import java.util.List; | |
| 9 | +import java.util.Map; | |
| 10 | + | |
| 11 | +import org.apache.commons.lang3.StringUtils; | |
| 12 | +import org.slf4j.Logger; | |
| 13 | +import org.slf4j.LoggerFactory; | |
| 14 | +import org.springframework.beans.factory.annotation.Autowired; | |
| 15 | +import org.springframework.data.domain.Page; | |
| 16 | +import org.springframework.data.domain.PageRequest; | |
| 17 | +import org.springframework.stereotype.Service; | |
| 18 | + | |
| 19 | +import com.alibaba.fastjson.JSON; | |
| 20 | +import com.alibaba.fastjson.JSONObject; | |
| 21 | +import com.bsth.common.ResponseCode; | |
| 22 | +import com.bsth.entity.directive.D60; | |
| 23 | +import com.bsth.entity.directive.D64; | |
| 24 | +import com.bsth.entity.directive.D80; | |
| 25 | +import com.bsth.entity.directive.DC0; | |
| 26 | +import com.bsth.entity.directive.DC0.DC0Data; | |
| 27 | +import com.bsth.entity.realcontrol.ScheduleRealInfo; | |
| 28 | +import com.bsth.entity.search.CustomerSpecs; | |
| 29 | +import com.bsth.entity.sys.SysUser; | |
| 30 | +import com.bsth.repository.directive.D60Repository; | |
| 31 | +import com.bsth.repository.directive.D64Repository; | |
| 32 | +import com.bsth.repository.directive.D80Repository; | |
| 33 | +import com.bsth.security.util.SecurityUtils; | |
| 34 | +import com.bsth.service.impl.BaseServiceImpl; | |
| 35 | +import com.bsth.service.realcontrol.buffer.ScheduleBuffer; | |
| 36 | +import com.bsth.util.DateUtils; | |
| 37 | +import com.bsth.vehicle.common.CommonMapped; | |
| 38 | +import com.bsth.vehicle.directive.buffer.DirectiveBuffer; | |
| 39 | +import com.bsth.vehicle.directive.entity.Directive; | |
| 40 | +import com.bsth.vehicle.directive.util.DirectiveDataFactory; | |
| 41 | +import com.bsth.vehicle.directive.util.HttpUtils; | |
| 42 | +import com.bsth.vehicle.gpsdata.buffer.GpsRealDataBuffer; | |
| 43 | +import com.bsth.vehicle.gpsdata.entity.GpsRealData; | |
| 44 | +import com.bsth.websocket.handler.RealControlSocketHandler; | |
| 45 | +import com.google.common.base.Splitter; | |
| 46 | + | |
| 47 | +@Service | |
| 48 | +public class DirectiveServiceImpl extends BaseServiceImpl<D60, Integer> implements DirectiveService { | |
| 49 | + | |
| 50 | + Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 51 | + | |
| 52 | + @Autowired | |
| 53 | + D60Repository d60Repository; | |
| 54 | + | |
| 55 | + @Autowired | |
| 56 | + GpsRealDataBuffer gpsRealDataBuffer; | |
| 57 | + | |
| 58 | + @Autowired | |
| 59 | + D64Repository d64Repository; | |
| 60 | + | |
| 61 | + @Autowired | |
| 62 | + RealControlSocketHandler socketHandler; | |
| 63 | + | |
| 64 | + @Autowired | |
| 65 | + D80Repository d80Repository; | |
| 66 | + | |
| 67 | + SimpleDateFormat sdfHHmm = new SimpleDateFormat("HH点mm分"), sdfHHmm2 = new SimpleDateFormat("HH:mm"); | |
| 68 | + | |
| 69 | + static Long schDiff = 1000 * 60 * 60L; | |
| 70 | + | |
| 71 | + @Override | |
| 72 | + public int send60Phrase(String nbbm, String text, String sender) { | |
| 73 | + D60 directive = null; | |
| 74 | + try { | |
| 75 | + directive = create60Data(nbbm, text, (short) 0x00, null); | |
| 76 | + } catch (Exception e) { | |
| 77 | + logger.error("发送消息短语出现异常", e); | |
| 78 | + return -1; | |
| 79 | + } | |
| 80 | + | |
| 81 | + if (null == directive) | |
| 82 | + return -1; | |
| 83 | + | |
| 84 | + // 发送指令 | |
| 85 | + int code = HttpUtils.postJson(JSON.toJSONString(directive)); | |
| 86 | + if(null != sender) | |
| 87 | + directive.setSender(sender); | |
| 88 | + directive.setHttpCode(code); | |
| 89 | + // 添加到缓存,等待入库 | |
| 90 | + //DirectiveBuffer.put(directive); | |
| 91 | + | |
| 92 | + if (code != 0) { | |
| 93 | + directive.setErrorText("网关通讯失败, code: " + code); | |
| 94 | + //DirectiveBuffer.transientList.add(directive); | |
| 95 | + } | |
| 96 | + return code; | |
| 97 | + } | |
| 98 | + | |
| 99 | + @Override | |
| 100 | + public int send60Dispatch(ScheduleRealInfo sch, int finish, String sender) { | |
| 101 | + D60 directive = null; | |
| 102 | + try { | |
| 103 | + // 如果发车时间距当前时间较远,则不发送 | |
| 104 | + /*if (Math.abs(sch.getFcsjT() - System.currentTimeMillis()) > schDiff) { | |
| 105 | + return -2; | |
| 106 | + }*/ | |
| 107 | + | |
| 108 | + String text = "已完成" + finish + "个班次,下一发车时间" + sdfHHmm.format(new Date(sch.getDfsjT())) + ",由" | |
| 109 | + + sch.getQdzName() + "发往" + sch.getZdzName(); | |
| 110 | + | |
| 111 | + ScheduleRealInfo nextSch = ScheduleBuffer.getNext(sch); | |
| 112 | + //下发0x02指令 调度指令(闹钟有效) | |
| 113 | + /*directive = DirectiveDataFactory.createDirective6002(sch.getClZbh(), text, (short) 0x02 | |
| 114 | + , Integer.parseInt(nextSch.getXlDir()), 0, new Date(System.currentTimeMillis() + 1000 * 30));*/ | |
| 115 | + } catch (Exception e) { | |
| 116 | + logger.error("生成调度指令时出现异常", e); | |
| 117 | + return -1; | |
| 118 | + } | |
| 119 | + | |
| 120 | + if (null == directive) | |
| 121 | + return -1; | |
| 122 | + if(null != sender) | |
| 123 | + directive.setSender(sender); | |
| 124 | + else | |
| 125 | + directive.setSender("系统"); | |
| 126 | + | |
| 127 | + // 发送指令 | |
| 128 | + int code = HttpUtils.postJson(JSON.toJSONString(directive)); | |
| 129 | + | |
| 130 | + sch.setDirectiveState(60); | |
| 131 | + // 添加到缓存,等待入库 | |
| 132 | + directive.setDispatch(true); | |
| 133 | + directive.setSch(sch); | |
| 134 | + directive.setHttpCode(code); | |
| 135 | + //DirectiveBuffer.put(directive); | |
| 136 | + | |
| 137 | + if (code == 0) { | |
| 138 | + // 通知页面,消息已发出 | |
| 139 | + sendDirectiveToPage(sch); | |
| 140 | + } else { | |
| 141 | + directive.setErrorText("网关通讯失败, code: " + code); | |
| 142 | + //DirectiveBuffer.transientList.add(directive); | |
| 143 | + } | |
| 144 | + return code; | |
| 145 | + } | |
| 146 | + | |
| 147 | + /** | |
| 148 | + * | |
| 149 | + * @Title: sendDirectiveState @Description: TODO(向页面推送班次指令状态) @throws | |
| 150 | + */ | |
| 151 | + @Override | |
| 152 | + public void sendDirectiveToPage(ScheduleRealInfo sch) { | |
| 153 | + JSONObject json = new JSONObject(); | |
| 154 | + json.put("fn", "directive"); | |
| 155 | + json.put("t", sch); | |
| 156 | + socketHandler.sendMessageToLine(Integer.parseInt(sch.getXlBm()), json.toJSONString()); | |
| 157 | + } | |
| 158 | + | |
| 159 | + @Override | |
| 160 | + public int send60Dispatch(Long id, String sender) { | |
| 161 | + ScheduleRealInfo sch = ScheduleBuffer.findOne(id); | |
| 162 | + // 车辆已完成班次 | |
| 163 | + int finish = ScheduleBuffer.getFinishSchNo(sch.getClZbh()); | |
| 164 | + return send60Dispatch(sch, finish, sender); | |
| 165 | + } | |
| 166 | + | |
| 167 | + @Override | |
| 168 | + public int send60Operation(String nbbm, int state, int upDown, ScheduleRealInfo sch, String sender) { | |
| 169 | + logger.info("切换运营状态, nbbm: " + nbbm + " ,state: " + state + " ,upDown:" + upDown); | |
| 170 | + | |
| 171 | + String text = "切换为 " + (upDown == 0 ? "上行" : "下行") + (state == 0 ? "营运" : "未营运"); | |
| 172 | + D60 directive = /*DirectiveDataFactory.createDirective60(nbbm, text, (short) 0x03, upDown, state)*/null; | |
| 173 | + | |
| 174 | + if (null == directive) | |
| 175 | + return -1; | |
| 176 | + if(null != sender) | |
| 177 | + directive.setSender(sender); | |
| 178 | + else | |
| 179 | + directive.setSender("系统"); | |
| 180 | + // 发送指令 | |
| 181 | + int code = HttpUtils.postJson(JSON.toJSONString(directive)); | |
| 182 | + // 添加到缓存,等待入库 | |
| 183 | + directive.setHttpCode(code); | |
| 184 | + if (null != sch) | |
| 185 | + directive.setSch(sch); | |
| 186 | + //DirectiveBuffer.put(directive); | |
| 187 | + | |
| 188 | + if (code != 0) { | |
| 189 | + directive.setErrorText("网关通讯失败, code: " + code); | |
| 190 | + //DirectiveBuffer.transientList.add(directive); | |
| 191 | + } | |
| 192 | + return code; | |
| 193 | + } | |
| 194 | + | |
| 195 | + /** | |
| 196 | + * 线路切换 | |
| 197 | + */ | |
| 198 | + @Override | |
| 199 | + public int lineChange(String nbbm, Integer lineCode, String sender) { | |
| 200 | + Long t = System.currentTimeMillis(); | |
| 201 | + /*String deviceId = CommonMapped.vehicDeviceBiMap.inverse().get(nbbm); | |
| 202 | + | |
| 203 | + Directive64 change = new Directive64(); | |
| 204 | + LineChangeData data = new LineChangeData(); | |
| 205 | + data.setCityCode(cityCode); | |
| 206 | + data.setDeviceId(deviceId); | |
| 207 | + data.setLineId("00" + String.valueOf(lineCode)); | |
| 208 | + | |
| 209 | + change.setDeviceId(deviceId); | |
| 210 | + change.setOperCode((short) 0X64); | |
| 211 | + change.setTimestamp(t); | |
| 212 | + change.setData(data);*/ | |
| 213 | + D64 d64 = /*DirectiveDataFactory.createDirective64(nbbm, lineCode, t)*/null; | |
| 214 | + | |
| 215 | + if(null != sender) | |
| 216 | + d64.setSender(sender); | |
| 217 | + else | |
| 218 | + d64.setSender("系统"); | |
| 219 | + | |
| 220 | + String deviceId = d64.getDeviceId(); | |
| 221 | + int code = HttpUtils.postJson(JSON.toJSONString(d64)); | |
| 222 | + // 入库 | |
| 223 | + d64.setHttpCode(code); | |
| 224 | + //DirectiveBuffer.changeMap.put(deviceId + '_' + t, d64); | |
| 225 | + | |
| 226 | + // 通知设备刷新线路文件,忽略结果 | |
| 227 | + if (code == 0) | |
| 228 | + HttpUtils.postJson(DirectiveDataFactory.createDeviceRefreshData(deviceId, lineCode)); | |
| 229 | + else | |
| 230 | + d64.setErrorText("网关通讯失败, code: " + code); | |
| 231 | + | |
| 232 | + d64Repository.save(d64); | |
| 233 | + return code; | |
| 234 | + } | |
| 235 | + | |
| 236 | + public D60 create60Data(String nbbm, String text, Short dispatchInstruct, ScheduleRealInfo sch) { | |
| 237 | + | |
| 238 | + String deviceId = CommonMapped.vehicDeviceBiMap.inverse().get(nbbm); | |
| 239 | + if (null == deviceId) { | |
| 240 | + logger.error("没有设备号对照的车辆:" + nbbm); | |
| 241 | + return null; | |
| 242 | + } | |
| 243 | + // 上下行和营运状态 | |
| 244 | + Integer upDown = null, state = null; | |
| 245 | + if (null == sch) { | |
| 246 | + GpsRealData gpsData = gpsRealDataBuffer.findOneByDeviceId(deviceId); | |
| 247 | + if (null == gpsData) { | |
| 248 | + logger.error("没有找到gps对照,无法确认营运状态和上下行:" + nbbm); | |
| 249 | + return null; | |
| 250 | + } | |
| 251 | + upDown = gpsData.getUpDown(); | |
| 252 | + state = gpsData.getState(); | |
| 253 | + } else { | |
| 254 | + upDown = Integer.parseInt(sch.getXlDir()); | |
| 255 | + state = 0; | |
| 256 | + } | |
| 257 | + | |
| 258 | + return /*DirectiveDataFactory.createDirective60(nbbm, text, dispatchInstruct, upDown, state)*/null; | |
| 259 | + } | |
| 260 | + | |
| 261 | +/* public Directive60 createDirective60(String nbbm, String text, Short dispatchInstruct, int upDown, int state) { | |
| 262 | + Long timestamp = System.currentTimeMillis(); | |
| 263 | + | |
| 264 | + Short company = Short.parseShort(CommonMapped.vehicCompanyMap.get(nbbm)); | |
| 265 | + String deviceId = CommonMapped.vehicDeviceBiMap.inverse().get(nbbm); | |
| 266 | + | |
| 267 | + int msgId = MsgIdGenerator.getMsgId(); | |
| 268 | + | |
| 269 | + Directive60 directive = new Directive60(); | |
| 270 | + DirectiveData data = new DirectiveData(); | |
| 271 | + // 一级协议 | |
| 272 | + directive.setOperCode((short) 0x60); | |
| 273 | + // 设备号 | |
| 274 | + directive.setDeviceId(deviceId); | |
| 275 | + // 时间戳 | |
| 276 | + directive.setTimestamp(timestamp); | |
| 277 | + directive.setMsgId(msgId); | |
| 278 | + // 构造数据 | |
| 279 | + data.setDeviceId(deviceId); | |
| 280 | + data.setDispatchInstruct(dispatchInstruct); | |
| 281 | + data.setTimestamp(timestamp); | |
| 282 | + data.setCompanyCode(company); | |
| 283 | + data.setMsgId(msgId); | |
| 284 | + directive.setData(data); | |
| 285 | + long serviceState; | |
| 286 | + try { | |
| 287 | + serviceState = Consts.SERVICE_STATE[upDown][state]; | |
| 288 | + } catch (IndexOutOfBoundsException e) { | |
| 289 | + // 未知营运状态的直接默认为上行非营运 | |
| 290 | + serviceState = Consts.SERVICE_STATE[0][1]; | |
| 291 | + } | |
| 292 | + data.setServiceState(serviceState); | |
| 293 | + data.setTxtContent(text); | |
| 294 | + | |
| 295 | + return directive; | |
| 296 | + }*/ | |
| 297 | + | |
| 298 | + @Override | |
| 299 | + public int upDownChange(String nbbm, Integer upDown, String sender) { | |
| 300 | + return send60Operation(nbbm, 0, upDown, null, sender); | |
| 301 | + } | |
| 302 | + | |
| 303 | + /** | |
| 304 | + * | |
| 305 | + * @Title: createDeviceRefreshData @Description: | |
| 306 | + * TODO(生成设备线路刷新数据包) @param @return 设定文件 @return String 返回类型 @throws | |
| 307 | + */ | |
| 308 | +/* public String createDeviceRefreshData(String deviceId, Integer lineId) { | |
| 309 | + Long t = System.currentTimeMillis(); | |
| 310 | + Map<String, Object> param = new HashMap<String, Object>(); | |
| 311 | + param.put("deviceId", deviceId); | |
| 312 | + param.put("timestamp", t); | |
| 313 | + param.put("operCode", 0Xc0); | |
| 314 | + | |
| 315 | + Map<String, Object> data = new HashMap<String, Object>(); | |
| 316 | + data.put("operCode2", 0xa1); | |
| 317 | + data.put("cityCode", cityCode); | |
| 318 | + data.put("deviceId", deviceId); | |
| 319 | + data.put("timestamp", t); | |
| 320 | + data.put("centerId", 1); | |
| 321 | + data.put("lineId", lineId); | |
| 322 | + data.put("lineVersion", 0); | |
| 323 | + data.put("carparkDataVersion", 0); | |
| 324 | + param.put("data", data); | |
| 325 | + | |
| 326 | + return JSON.toJSONString(param); | |
| 327 | + }*/ | |
| 328 | + | |
| 329 | + @Override | |
| 330 | + public Map<String, List<D80>> findNoCofm80(String lineCodes) { | |
| 331 | + List<String> lineList = Splitter.on(",").trimResults().splitToList(lineCodes); | |
| 332 | + | |
| 333 | + Map<String, List<D80>> rs = new HashMap<>(); | |
| 334 | + for (String code : lineList) { | |
| 335 | + rs.put(code, /*DirectiveBuffer.findNoCofm80(Integer.parseInt(code))*/null); | |
| 336 | + } | |
| 337 | + | |
| 338 | + return rs; | |
| 339 | + } | |
| 340 | + | |
| 341 | + @Override | |
| 342 | + public Map<String, Object> reply80(int id, int reply) { | |
| 343 | + Map<String, Object> rs = new HashMap<>(); | |
| 344 | + | |
| 345 | + D80 d80 = /*DirectiveBuffer.findById80(id)*/null; | |
| 346 | + if (null == d80) { | |
| 347 | + rs.put("status", ResponseCode.ERROR); | |
| 348 | + rs.put("msg", "服务器没有找到对应数据!"); | |
| 349 | + } else if (d80.isConfirm()) { | |
| 350 | + rs.put("status", ResponseCode.ERROR); | |
| 351 | + rs.put("msg", "该数据已经被处理了!"); | |
| 352 | + } else { | |
| 353 | + SysUser user = SecurityUtils.getCurrentUser(); | |
| 354 | + | |
| 355 | + d80.setConfirm(true); | |
| 356 | + d80.setHandleUser(user.getUserName()); | |
| 357 | + d80.setConfirmRs(reply); | |
| 358 | + d80.setHandleTime(new Date()); | |
| 359 | + // 封装C0数据包并回复设备 | |
| 360 | + DC0 c0 = new DC0(); | |
| 361 | + c0.setDeviceId(d80.getDeviceId()); | |
| 362 | + c0.setTimestamp(d80.getTimestamp()); | |
| 363 | + c0.setOperCode((short) 0xC0); | |
| 364 | + | |
| 365 | + DC0Data data = new DC0Data(); | |
| 366 | + data.setOperCode2((short) 0x86); | |
| 367 | + data.setRequestAck((short) (reply == 0 ? 0x06 : 0x15)); | |
| 368 | + | |
| 369 | + c0.setData(data); | |
| 370 | + | |
| 371 | + d80.setC0(c0); | |
| 372 | + // 入库 | |
| 373 | + d80Repository.save(d80); | |
| 374 | + | |
| 375 | + int code = HttpUtils.postJson(JSON.toJSONString(c0)); | |
| 376 | + | |
| 377 | + rs.put("status", ResponseCode.SUCCESS); | |
| 378 | + if (code != 0) | |
| 379 | + rs.put("msg", "发送C0响应指令到车载设备失败,但该操作已经被系统记录!"); | |
| 380 | + | |
| 381 | + // 通知页面 | |
| 382 | + Map<String, Object> sockMap = new HashMap<>(); | |
| 383 | + sockMap.put("fn", "d80Confirm"); | |
| 384 | + sockMap.put("id", d80.getId()); | |
| 385 | + socketHandler.sendMessageToLine(d80.getData().getLineId(), JSON.toJSONString(sockMap)); | |
| 386 | + } | |
| 387 | + | |
| 388 | + return rs; | |
| 389 | + } | |
| 390 | + | |
| 391 | + @Override | |
| 392 | + public Map<String, Object> findDirective(String nbbm, int dType, int page, int size) { | |
| 393 | + Map<String, Object> rsMap = new HashMap<>(); | |
| 394 | + List<Directive> list = null; | |
| 395 | + | |
| 396 | + switch (dType) { | |
| 397 | + case -1: | |
| 398 | + //所有指令 | |
| 399 | + list = DirectiveBuffer.findAll(); | |
| 400 | + break; | |
| 401 | + case 0: | |
| 402 | + //调度指令 | |
| 403 | + list = DirectiveBuffer.findDispatch(); | |
| 404 | + break; | |
| 405 | + case 1: | |
| 406 | + //运营指令 | |
| 407 | + list = DirectiveBuffer.findByDispatchInstruct((short)0x03); | |
| 408 | + break; | |
| 409 | + case 2: | |
| 410 | + //线路切换指令 | |
| 411 | + list = DirectiveBuffer.findLineChange(); | |
| 412 | + break; | |
| 413 | + case 3: | |
| 414 | + //消息短语 | |
| 415 | + list = DirectiveBuffer.findByDispatchInstruct((short)0x00); | |
| 416 | + break; | |
| 417 | + } | |
| 418 | + | |
| 419 | + // 时间倒序 | |
| 420 | + Collections.sort(list, new DirectiveBuffer.DComparator()); | |
| 421 | + if(StringUtils.isNotBlank(nbbm)){ | |
| 422 | + String deviceId = CommonMapped.vehicDeviceBiMap.inverse().get(nbbm); | |
| 423 | + //按车辆过滤 | |
| 424 | + List<Directive> subList = new ArrayList<>(); | |
| 425 | + for(Directive d : list){ | |
| 426 | + if(d.getDeviceId().equals(deviceId)){ | |
| 427 | + subList.add(d); | |
| 428 | + } | |
| 429 | + } | |
| 430 | + list = subList; | |
| 431 | + } | |
| 432 | + | |
| 433 | + int count = list.size(); | |
| 434 | + // 分页 | |
| 435 | + int s = page * size, e = s + size; | |
| 436 | + | |
| 437 | + if (e > count) | |
| 438 | + e = count; | |
| 439 | + | |
| 440 | + List<Directive> rs = list.subList(s, e); | |
| 441 | + | |
| 442 | + // 时间格式化,车辆自编号转换 | |
| 443 | + for (Directive d : rs) { | |
| 444 | + if (d.getTimeHHmm() == null) | |
| 445 | + d.setTimeHHmm(sdfHHmm2.format(new Date(d.getTimestamp()))); | |
| 446 | + if (d.getNbbm() == null) | |
| 447 | + d.setNbbm(CommonMapped.vehicDeviceBiMap.get(d.getDeviceId())); | |
| 448 | + } | |
| 449 | + | |
| 450 | + rsMap.put("list", rs); | |
| 451 | + rsMap.put("totalPages", count % size == 0 ? count / size : count / size + 1); | |
| 452 | + rsMap.put("page", page); | |
| 453 | + return rsMap; | |
| 454 | + } | |
| 455 | + | |
| 456 | + @Override | |
| 457 | + public Page<D80> findAll80(Map<String, Object> map, PageRequest pageRequest) { | |
| 458 | + //默认只查看当天的 | |
| 459 | + map.put("timestamp_gt", DateUtils.getTimestamp()); | |
| 460 | + | |
| 461 | + Object nbbm = map.get("nbbm"); | |
| 462 | + if(null != nbbm && StringUtils.isNotBlank(nbbm.toString())){ | |
| 463 | + map.put("deviceId_eq", CommonMapped.vehicDeviceBiMap.inverse().get(nbbm.toString())); | |
| 464 | + } | |
| 465 | + | |
| 466 | + Page<D80> pageData = d80Repository.findAll(new CustomerSpecs<D80>(map), pageRequest); | |
| 467 | + //格式化时间和转换车辆自编号 | |
| 468 | + List<D80> list = pageData.getContent(); | |
| 469 | + for(D80 d80 : list){ | |
| 470 | + d80.setTimeStr(sdfHHmm2.format(new Date(d80.getTimestamp()))); | |
| 471 | + d80.getData().setNbbm(CommonMapped.vehicDeviceBiMap.get(d80.getDeviceId())); | |
| 472 | + } | |
| 473 | + return pageData; | |
| 474 | + } | |
| 475 | +} | ... | ... |