Commit 5b9bc6179a760765932a91c837e5cc38045c4247
1 parent
8e8799a6
update...
Showing
2 changed files
with
150 additions
and
6 deletions
src/main/java/com/bsth/controller/realcontrol/ServiceDataInterface.java
| 1 | 1 | package com.bsth.controller.realcontrol; |
| 2 | 2 | |
| 3 | +import com.alibaba.fastjson.JSON; | |
| 4 | +import com.alibaba.fastjson.JSONObject; | |
| 5 | +import com.bsth.data.BasicData; | |
| 6 | +import com.bsth.data.directive.DayOfDirectives; | |
| 7 | +import com.bsth.data.directive.DirectiveCreator; | |
| 8 | +import com.bsth.data.directive.GatewayHttpUtils; | |
| 9 | +import com.bsth.data.gpsdata.GpsEntity; | |
| 10 | +import com.bsth.data.gpsdata.GpsRealData; | |
| 3 | 11 | import com.bsth.data.schedule.DayOfSchedule; |
| 12 | +import com.bsth.entity.directive.D60; | |
| 4 | 13 | import com.bsth.entity.realcontrol.ScheduleRealInfo; |
| 14 | +import com.bsth.repository.directive.D60Repository; | |
| 15 | +import com.google.common.base.Splitter; | |
| 5 | 16 | import org.apache.commons.lang3.StringUtils; |
| 17 | +import org.slf4j.Logger; | |
| 18 | +import org.slf4j.LoggerFactory; | |
| 6 | 19 | import org.springframework.beans.factory.annotation.Autowired; |
| 7 | -import org.springframework.web.bind.annotation.RequestMapping; | |
| 8 | -import org.springframework.web.bind.annotation.RequestParam; | |
| 9 | -import org.springframework.web.bind.annotation.RestController; | |
| 20 | +import org.springframework.web.bind.annotation.*; | |
| 10 | 21 | |
| 11 | -import java.util.ArrayList; | |
| 12 | -import java.util.List; | |
| 22 | +import java.util.*; | |
| 13 | 23 | |
| 14 | 24 | /** |
| 15 | 25 | * 对外的营运数据接口 |
| ... | ... | @@ -21,9 +31,56 @@ public class ServiceDataInterface { |
| 21 | 31 | |
| 22 | 32 | private final static String SECRE_KEY = "dVPHJkWUt5FhMT7jrM2dLV7QvlHAmZFd42rs1P0usBx8A7HZki"; |
| 23 | 33 | |
| 34 | + Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 35 | + | |
| 24 | 36 | @Autowired |
| 25 | 37 | DayOfSchedule dayOfSchedule; |
| 26 | 38 | |
| 39 | + @Autowired | |
| 40 | + DayOfDirectives dayOfDirectives; | |
| 41 | + | |
| 42 | + @Autowired | |
| 43 | + D60Repository d60Repository; | |
| 44 | + | |
| 45 | + @Autowired | |
| 46 | + GpsRealData gpsRealData; | |
| 47 | + | |
| 48 | + /** | |
| 49 | + * 获取车辆 和 当前执行班次对照信息 | |
| 50 | + * @return | |
| 51 | + */ | |
| 52 | + @RequestMapping("/execSchList") | |
| 53 | + public List<JSONObject> execSchList(@RequestParam String secretKey){ | |
| 54 | + if (StringUtils.isEmpty(secretKey) || !secretKey.equals(SECRE_KEY)) | |
| 55 | + return null; | |
| 56 | + | |
| 57 | + List<JSONObject> rs = new ArrayList<>(); | |
| 58 | + Collection<ScheduleRealInfo> list = dayOfSchedule.execPlanMap().values(); | |
| 59 | + | |
| 60 | + JSONObject obj; | |
| 61 | + for(ScheduleRealInfo sch : list){ | |
| 62 | + obj = new JSONObject(); | |
| 63 | + obj.put("clZbh", sch.getClZbh()); | |
| 64 | + obj.put("jGh", sch.getjGh()); | |
| 65 | + obj.put("sGh", sch.getsGh()); | |
| 66 | + obj.put("lpName", sch.getLpName()); | |
| 67 | + obj.put("xlBm", sch.getXlBm()); | |
| 68 | + obj.put("xlName", sch.getXlName()); | |
| 69 | + obj.put("xlDir", sch.getXlDir()); | |
| 70 | + obj.put("qdzName", sch.getQdzName()); | |
| 71 | + obj.put("zdzName", sch.getZdzName()); | |
| 72 | + obj.put("fcsj", sch.getFcsj()); | |
| 73 | + obj.put("dfsj", sch.getDfsj()); | |
| 74 | + obj.put("zdsj", sch.getZdsj()); | |
| 75 | + obj.put("bcType", sch.getBcType()); | |
| 76 | + obj.put("remarks", sch.getRemark()); | |
| 77 | + obj.put("status", sch.getStatus()); | |
| 78 | + | |
| 79 | + rs.add(obj); | |
| 80 | + } | |
| 81 | + return rs; | |
| 82 | + } | |
| 83 | + | |
| 27 | 84 | @RequestMapping("/getCurrentDayPlan") |
| 28 | 85 | public List<ScheduleRealInfo> getCurrentDayPlan( |
| 29 | 86 | @RequestParam String companyId, |
| ... | ... | @@ -98,4 +155,87 @@ public class ServiceDataInterface { |
| 98 | 155 | } |
| 99 | 156 | return rs; |
| 100 | 157 | } |
| 158 | + | |
| 159 | + /** | |
| 160 | + * 向指定的车辆下发消息短语 | |
| 161 | + * @param nbbm | |
| 162 | + * @param txt | |
| 163 | + * @return | |
| 164 | + */ | |
| 165 | + @RequestMapping(value = "/send60Phrase", method = RequestMethod.POST) | |
| 166 | + public int send60Phrase(@RequestBody Map<String, String> map,@RequestParam String secretKey){ | |
| 167 | + try{ | |
| 168 | + String nbbm = map.get("nbbm"); | |
| 169 | + String txt = map.get("txt"); | |
| 170 | + String sender = map.get("sender"); | |
| 171 | + if(txt.length() > 50) | |
| 172 | + txt = txt.substring(0, 50); | |
| 173 | + if (StringUtils.isEmpty(secretKey) || !secretKey.equals(SECRE_KEY)) | |
| 174 | + return -500; | |
| 175 | + | |
| 176 | + //车辆和设备号对照 | |
| 177 | + String deviceId = BasicData.deviceId2NbbmMap.inverse().get(nbbm); | |
| 178 | + if(StringUtils.isEmpty(deviceId)) | |
| 179 | + return -404; | |
| 180 | + | |
| 181 | + //检查设备是否在线 | |
| 182 | + long t = System.currentTimeMillis(); | |
| 183 | + GpsEntity gps = gpsRealData.get(deviceId); | |
| 184 | + if(null == gps || (t - gps.getServerTimestamp()) > 1000 * 60 * 5) | |
| 185 | + return -405; | |
| 186 | + | |
| 187 | + Short dispatchInstruct = 0;//消息短语 | |
| 188 | + D60 d60 = new DirectiveCreator().createD60(nbbm, txt, dispatchInstruct, gps.getUpDown(), gps.getState(), gps.getLineId()); | |
| 189 | + d60.setSender(sender); | |
| 190 | + // 发送指令 | |
| 191 | + int code = GatewayHttpUtils.postJson(JSON.toJSONString(d60)); | |
| 192 | + d60.setHttpCode(code); | |
| 193 | + | |
| 194 | + if (code == 0) { | |
| 195 | + // 添加到缓存 | |
| 196 | + dayOfDirectives.put60(d60, true); | |
| 197 | + } else { | |
| 198 | + d60.setErrorText("网关通讯失败, code: " + code); | |
| 199 | + d60Repository.save(d60); | |
| 200 | + dayOfDirectives.put60(d60, false); | |
| 201 | + } | |
| 202 | + | |
| 203 | + return d60.getMsgId(); | |
| 204 | + }catch (Exception e){ | |
| 205 | + logger.error("", e); | |
| 206 | + return -500; | |
| 207 | + } | |
| 208 | + } | |
| 209 | + | |
| 210 | + /** | |
| 211 | + * 根据msg id 查询指令响应情况 | |
| 212 | + * @param msgIDs | |
| 213 | + * @return | |
| 214 | + */ | |
| 215 | + @RequestMapping("/findD60Reply") | |
| 216 | + public List<Map<String, Object>> findD60Reply(@RequestParam String msgIds){ | |
| 217 | + List<Map<String, Object>> rs = new ArrayList<>(); | |
| 218 | + try{ | |
| 219 | + Map<String, Object> map = new HashMap(); | |
| 220 | + | |
| 221 | + List<String> ids = Splitter.on(",").splitToList(msgIds); | |
| 222 | + D60 d60; | |
| 223 | + for(String id : ids){ | |
| 224 | + if(StringUtils.isEmpty(id)) | |
| 225 | + continue; | |
| 226 | + | |
| 227 | + d60 = dayOfDirectives.get(Integer.parseInt(id)); | |
| 228 | + if(null == d60) | |
| 229 | + continue; | |
| 230 | + | |
| 231 | + map.put("msgId", d60.getMsgId()); | |
| 232 | + map.put("deviceReplyTime", d60.getReply46Time()); | |
| 233 | + map.put("jsyReplyTime", d60.getReply47Time()); | |
| 234 | + rs.add(map); | |
| 235 | + } | |
| 236 | + }catch (Exception e){ | |
| 237 | + logger.error("", e); | |
| 238 | + } | |
| 239 | + return rs; | |
| 240 | + } | |
| 101 | 241 | } | ... | ... |
src/main/java/com/bsth/data/directive/DayOfDirectives.java
| ... | ... | @@ -197,7 +197,11 @@ public class DayOfDirectives { |
| 197 | 197 | public Collection<D64> all64(){ |
| 198 | 198 | return d64Map.values(); |
| 199 | 199 | } |
| 200 | - | |
| 200 | + | |
| 201 | + public D60 get(Integer msgId){ | |
| 202 | + return d60Map.get(msgId); | |
| 203 | + } | |
| 204 | + | |
| 201 | 205 | public Collection<Directive> all(){ |
| 202 | 206 | List<Directive> all = new ArrayList<>(); |
| 203 | 207 | all.addAll(d60Map.values()); | ... | ... |