| | |
| | | package com.zy.asrs.ws; |
| | | |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.core.common.R; |
| | | import com.core.common.SpringUtils; |
| | | import com.zy.asrs.controller.CrnController; |
| | | import com.zy.asrs.controller.RgvController; |
| | | import com.zy.asrs.controller.BasMapController; |
| | | import com.zy.asrs.controller.ConsoleController; |
| | | import lombok.Data; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.stereotype.Component; |
| | |
| | | */ |
| | | @OnMessage |
| | | public void onMessage(String message, Session session) throws IOException { |
| | | // log.info("收到来自连接:" + sessionId + "的信息:" + message); |
| | | Object resObj = null; |
| | | String url = null; |
| | | try { |
| | | JSONObject req = JSON.parseObject(message); |
| | | url = req.getString("url"); |
| | | if (url == null) { |
| | | return; |
| | | } |
| | | if (url.startsWith("/basMap/lev/") && url.endsWith("/auth")) { |
| | | String[] segs = url.split("/"); |
| | | Integer lev = null; |
| | | for (int i = 0; i < segs.length; i++) { |
| | | if ("lev".equals(segs[i]) && i + 1 < segs.length) { |
| | | try { |
| | | lev = Integer.parseInt(segs[i + 1]); |
| | | } catch (Exception ignore) {} |
| | | break; |
| | | } |
| | | } |
| | | BasMapController basMapController = SpringUtils.getBean(BasMapController.class); |
| | | R r = basMapController.getByLev(lev); |
| | | resObj = r; |
| | | } else if ("/console/latest/data/station".equals(url)) { |
| | | ConsoleController consoleController = SpringUtils.getBean(ConsoleController.class); |
| | | resObj = consoleController.stationLatestData(); |
| | | } else if ("/console/latest/data/crn".equals(url)) { |
| | | ConsoleController consoleController = SpringUtils.getBean(ConsoleController.class); |
| | | resObj = consoleController.crnLatestData(); |
| | | } else if ("/console/latest/data/rgv".equals(url)) { |
| | | ConsoleController consoleController = SpringUtils.getBean(ConsoleController.class); |
| | | resObj = consoleController.rgvLatestData(); |
| | | } else if ("/crn/table/crn/state".equals(url)) { |
| | | resObj = SpringUtils.getBean(CrnController.class).crnStateTable(); |
| | | } else if ("/rgv/table/rgv/state".equals(url)) { |
| | | resObj = SpringUtils.getBean(RgvController.class).rgvStateTable(); |
| | | } |
| | | } catch (Exception e) { |
| | | R err = R.error(e.getMessage()); |
| | | JSONObject out = new JSONObject(); |
| | | out.put("url", "error"); |
| | | out.put("data", JSON.toJSONString(err)); |
| | | this.sendMessage(out.toJSONString()); |
| | | return; |
| | | } |
| | | if (resObj != null && url != null) { |
| | | JSONObject out = new JSONObject(); |
| | | out.put("url", url); |
| | | out.put("data", JSON.toJSONString(resObj)); |
| | | this.sendMessage(out.toJSONString()); |
| | | } |
| | | } |
| | | |
| | | /** |