|
@@ -1,5 +1,8 @@
|
|
|
package com.welampiot.controller;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
import com.welampiot.common.BaseResult;
|
|
|
import com.welampiot.common.InterfaceResultEnum;
|
|
|
import com.welampiot.dto.*;
|
|
@@ -81,6 +84,8 @@ public class MapController{
|
|
|
private ManholeService manholeService;
|
|
|
@Autowired
|
|
|
private LampInfoLogService lampInfoLogService;
|
|
|
+ @Autowired
|
|
|
+ private WifiService wifiService;
|
|
|
|
|
|
@PostMapping("/getIlluminance")
|
|
|
private BaseResult getIlluminance(HttpServletRequest request){
|
|
@@ -1901,4 +1906,129 @@ public class MapController{
|
|
|
}
|
|
|
return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,lampInfoVO);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取WiFi信息
|
|
|
+ * @param request lampPoleId
|
|
|
+ * @return wifi信息
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/wifiInfo", method = RequestMethod.POST)
|
|
|
+ public BaseResult<?> wifiInfo(HttpServletRequest request) throws JsonProcessingException {
|
|
|
+ Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
|
|
|
+ Integer lampPoleId = (Integer) toolUtils.getRequestContent(request,"lampPoleId",1);
|
|
|
+ if (lampPoleId == 0) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
|
|
|
+ WifiDTO wifiDTO = wifiService.getWifiInfoByLampPoleId(lampPoleId);
|
|
|
+ if (wifiDTO == null) return toolUtils.response(InterfaceResultEnum.PARAM_FAIL,version);
|
|
|
+ String sendTopic = "/WEGW2/ReadIn/" + wifiDTO.getNum();
|
|
|
+ String resTopic = "/WEGW2/ReadOut/" + wifiDTO.getNum();
|
|
|
+ String cmd = "0001B10B";
|
|
|
+ String cmd1 = "0001AA01";
|
|
|
+ byte[] bytes = toolUtils.hexString2Bytes(cmd);
|
|
|
+ byte[] bytes1 = toolUtils.hexString2Bytes(cmd1);
|
|
|
+ String resCmd = toolUtils.sendMqttCmd(sendTopic, bytes, resTopic);
|
|
|
+ String resCmd1 = toolUtils.sendMqttCmd(sendTopic, bytes1, resTopic);
|
|
|
+ System.out.println("resCmd:" + resCmd);
|
|
|
+ System.out.println("resCmd1:" + resCmd1);
|
|
|
+ String jsonStr ="{ " + resCmd.substring(bytes.length);
|
|
|
+ String jsonStr1 ="{ " + resCmd1.substring(bytes1.length);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(jsonStr);
|
|
|
+ JSONObject jsonObject1 = JSONObject.parseObject(jsonStr1);
|
|
|
+ String name = jsonObject.getString("B1");
|
|
|
+ Integer type = jsonObject.getInteger("B2");
|
|
|
+ String wifiPwd = jsonObject.getString("B3");
|
|
|
+ Integer wifiStatus = jsonObject.getInteger("B4");
|
|
|
+ Long allDownTraffic = jsonObject.getLong("B6");
|
|
|
+ Integer dayDownTraffic = jsonObject.getInteger("B8");
|
|
|
+ Integer allConn = jsonObject.getInteger("B9");
|
|
|
+ Integer dayConn = jsonObject.getInteger("BA");
|
|
|
+ String wifiVersion = jsonObject1.getString("AA");
|
|
|
+ StringBuilder stringBuilder = new StringBuilder(wifiVersion);
|
|
|
+ if (stringBuilder.charAt(stringBuilder.length() - 1) == '\n') {
|
|
|
+ stringBuilder.deleteCharAt(stringBuilder.length() - 1);
|
|
|
+ }
|
|
|
+ wifiVersion = stringBuilder.toString();
|
|
|
+ JSONArray deviceList = jsonObject.getJSONArray("BB");
|
|
|
+ List<WifiDeviceDTO> list = new ArrayList<>();
|
|
|
+ for (Object o : deviceList) {
|
|
|
+ JSONObject deviceObject = JSONObject.parseObject(o.toString());
|
|
|
+ WifiDeviceDTO wifiDeviceDTO = JSONObject.toJavaObject(deviceObject, WifiDeviceDTO.class);
|
|
|
+ list.add(wifiDeviceDTO);
|
|
|
+ }
|
|
|
+ WifiInfoVO wifiInfoVO = new WifiInfoVO();
|
|
|
+ wifiInfoVO.setDeviceList(list);
|
|
|
+ wifiInfoVO.setWifiId(wifiDTO.getNum());
|
|
|
+ wifiInfoVO.setWifiName(name);
|
|
|
+ wifiInfoVO.setWifiType(type);
|
|
|
+ wifiInfoVO.setWifiPwd(wifiPwd);
|
|
|
+ wifiInfoVO.setWifiStatus(wifiStatus);
|
|
|
+ wifiInfoVO.setTotalOnlineCount(allConn);
|
|
|
+ wifiInfoVO.setDayOnlineCount(dayConn);
|
|
|
+ wifiInfoVO.setWifiVersion(wifiVersion);
|
|
|
+ wifiInfoVO.setTotalFlow(allDownTraffic);
|
|
|
+ wifiInfoVO.setDayFlow(dayDownTraffic);
|
|
|
+ wifiInfoVO.setNetType(wifiDTO.getNetType());
|
|
|
+ if (wifiDTO.getNetType() == 1) {
|
|
|
+ wifiInfoVO.setWifiNet("ETH");
|
|
|
+ } else {
|
|
|
+ wifiInfoVO.setWifiNet("4G");
|
|
|
+ }
|
|
|
+ switch (wifiDTO.getModel()) {
|
|
|
+ case "6":
|
|
|
+ wifiInfoVO.setWifiModel("WE-GW-G600");
|
|
|
+ break;
|
|
|
+ case "5":
|
|
|
+ wifiInfoVO.setWifiModel("WE-GW-G260");
|
|
|
+ break;
|
|
|
+ case "4":
|
|
|
+ wifiInfoVO.setWifiModel("WE-XA-G20");
|
|
|
+ break;
|
|
|
+ case "3":
|
|
|
+ wifiInfoVO.setWifiModel("WE-GW-G300");
|
|
|
+ break;
|
|
|
+ case "2":
|
|
|
+ wifiInfoVO.setWifiModel("WE-GW-G40");
|
|
|
+ break;
|
|
|
+ case "1":
|
|
|
+ wifiInfoVO.setWifiModel("WE-GW-G200");
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ wifiInfoVO.setWifiModel("WE-GW-G100");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version,wifiInfoVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 修改WiFi信息
|
|
|
+ * @param request lampPoleId
|
|
|
+ * @return 修改WiFi名,密码以及安全类型
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/wifiSave", method = RequestMethod.POST)
|
|
|
+ public BaseResult<?> wifiSave(HttpServletRequest request) {
|
|
|
+ Integer version = (Integer) toolUtils.getRequestContent(request,"version",1);
|
|
|
+ Integer lampPoleId = (Integer) toolUtils.getRequestContent(request,"lampPoleId",1);
|
|
|
+ if (lampPoleId == 0) return toolUtils.response(InterfaceResultEnum.LACK_PARAM_ERROR,version);
|
|
|
+ WifiDTO wifiDTO = wifiService.getWifiInfoByLampPoleId(lampPoleId);
|
|
|
+ if (wifiDTO == null) return toolUtils.response(InterfaceResultEnum.PARAM_FAIL,version);
|
|
|
+ String wifiName = (String) toolUtils.getRequestContent(request,"wifiName",2);
|
|
|
+ Integer wifiType = (Integer) toolUtils.getRequestContent(request,"wifiType",1);
|
|
|
+ String wifiPwd = (String) toolUtils.getRequestContent(request,"wifiPwd",2);
|
|
|
+ if (wifiName.length() == 0)
|
|
|
+ return toolUtils.response(InterfaceResultEnum.LACK_WIFI_NAME_ERROR,version);
|
|
|
+ if (wifiPwd.length() == 0)
|
|
|
+ return toolUtils.response(InterfaceResultEnum.LACK_WIFI_PWD_ERROR,version);
|
|
|
+ if (String.valueOf(wifiType).length() == 0)
|
|
|
+ return toolUtils.response(InterfaceResultEnum.LACK_WIFI_TYPE_ERROR,version);
|
|
|
+ if (wifiName.length() > 30)
|
|
|
+ return toolUtils.response(InterfaceResultEnum.WIFI_NAME_LENGTH_ERROR,version);
|
|
|
+ if (wifiPwd.length() < 8 || wifiPwd.length() > 30)
|
|
|
+ return toolUtils.response(InterfaceResultEnum.WIFI_PWD_LENGTH_ERROR,version);
|
|
|
+ String sendTopic = "/WEGW2/WriteIn/" + wifiDTO.getNum();
|
|
|
+ String resTopic = "/WEGW2/WriteOut/" + wifiDTO.getNum();
|
|
|
+ String cmd = "0001{\"B1\":\"" + wifiName + "\",\"B2\":" + wifiType + ",\"B3\":\"" + wifiPwd + "\"}";
|
|
|
+ System.out.println("cmd:" + cmd);
|
|
|
+ String resCmd = toolUtils.sendMqttCmd(sendTopic, cmd, resTopic);
|
|
|
+ System.out.println("resCmd:" + resCmd);
|
|
|
+ return toolUtils.response(InterfaceResultEnum.OPERATION_SUCCESS,version);
|
|
|
+ }
|
|
|
}
|