|
|
|
package com.zhonglai.luhui.admin.controller.iot;
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
import com.ruoyi.common.annotation.Log;
|
|
|
|
import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
|
import com.ruoyi.common.core.domain.Message;
|
|
|
|
import com.ruoyi.common.core.domain.MessageCode;
|
|
|
|
import com.ruoyi.common.enums.BusinessType;
|
|
|
|
import com.ruoyi.common.utils.StringUtils;
|
|
|
|
import com.ruoyi.common.utils.html.HttpUtils;
|
|
|
|
import com.ruoyi.system.domain.IotDevice;
|
|
|
|
import com.ruoyi.system.service.IIotDeviceService;
|
|
|
|
import com.ruoyi.system.service.IIotTerminalService;
|
|
|
|
import com.ruoyi.system.service.DeviceControlService;
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
import io.swagger.annotations.ApiImplicitParam;
|
|
|
|
import io.swagger.annotations.ApiImplicitParams;
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
import okhttp3.Response;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
@Api(tags = "设备控制")
|
|
...
|
...
|
@@ -32,19 +22,7 @@ import java.util.Map; |
|
|
|
@RequestMapping("/iot/iotDeviceControl")
|
|
|
|
public class IotDeviceControlController {
|
|
|
|
@Autowired
|
|
|
|
private IIotDeviceService iotDeviceService;
|
|
|
|
@Autowired
|
|
|
|
private IIotTerminalService iIotTerminalService;
|
|
|
|
private String getServiceAdrres(HttpServletResponse response,String imei) throws IOException {
|
|
|
|
IotDevice iotDevice = iotDeviceService.selectIotDeviceByClient_id(imei);
|
|
|
|
response.setCharacterEncoding("UTF-8");
|
|
|
|
if(StringUtils.isEmpty(iotDevice.getListen_service_ip()))
|
|
|
|
{
|
|
|
|
response.getWriter().print(new Message(MessageCode.DEFAULT_FAIL_CODE,"未找到设备监听服务地址"));
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return "http://"+iotDevice.getListen_service_ip()+"device/control/"+imei;
|
|
|
|
}
|
|
|
|
private DeviceControlService deviceControlService;
|
|
|
|
|
|
|
|
@ApiOperation("固件版本更新")
|
|
|
|
@ApiImplicitParams({
|
|
...
|
...
|
@@ -55,20 +33,8 @@ public class IotDeviceControlController { |
|
|
|
@Log(title = "设备控制", businessType = BusinessType.UPDATE)
|
|
|
|
@ResponseBody
|
|
|
|
@PostMapping("/firmwareUp/{imei}")
|
|
|
|
public String firmwareUp(HttpServletResponse response,@PathVariable String imei,String firmwareVersion,Integer code) throws IOException {
|
|
|
|
String url = getServiceAdrres(response,imei);
|
|
|
|
if(null == url)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
Map<String,Object> map = new HashMap<>();
|
|
|
|
Map<String,Object> valueMap = new HashMap<>();
|
|
|
|
valueMap.put("firmwareVersion",firmwareVersion);
|
|
|
|
valueMap.put("code",code);
|
|
|
|
Response response1 = HttpUtils.postJsonBody(url, formBody -> {
|
|
|
|
formBody.put("0", valueMap);
|
|
|
|
});
|
|
|
|
return response1.body().string();
|
|
|
|
public Message firmwareUp(@PathVariable String imei,String firmwareVersion,Integer code) throws IOException {
|
|
|
|
return deviceControlService.firmwareUp(imei,firmwareVersion,code);
|
|
|
|
}
|
|
|
|
|
|
|
|
@ApiOperation("设备重启")
|
|
...
|
...
|
@@ -80,18 +46,8 @@ public class IotDeviceControlController { |
|
|
|
@Log(title = "设备控制", businessType = BusinessType.UPDATE)
|
|
|
|
@ResponseBody
|
|
|
|
@PostMapping("/restart/{imei}/{restart}")
|
|
|
|
public String restart(HttpServletResponse response,@PathVariable String imei ,@PathVariable Integer restart) throws IOException {
|
|
|
|
String url = getServiceAdrres(response,imei);
|
|
|
|
if(null == url)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
Map<String,Object> valueMap = new HashMap<>();
|
|
|
|
valueMap.put("restart",restart);
|
|
|
|
Response response1 = HttpUtils.postJsonBody(url, formBody -> {
|
|
|
|
formBody.put("0",valueMap);
|
|
|
|
});
|
|
|
|
return response1.body().string();
|
|
|
|
public Message restart(@PathVariable String imei ,@PathVariable Integer restart) {
|
|
|
|
return deviceControlService.restart(imei,restart);
|
|
|
|
}
|
|
|
|
|
|
|
|
@ApiOperation("获取指定设备版本信息")
|
|
...
|
...
|
@@ -100,20 +56,8 @@ public class IotDeviceControlController { |
|
|
|
})
|
|
|
|
@ResponseBody
|
|
|
|
@PostMapping("/getFirmwareVersion/{imei}")
|
|
|
|
public String getFirmwareVersion(HttpServletResponse response,@PathVariable String imei) throws IOException {
|
|
|
|
IotDevice iotDevice = iotDeviceService.selectIotDeviceByClient_id(imei);
|
|
|
|
response.setCharacterEncoding("UTF-8");
|
|
|
|
if(StringUtils.isEmpty(iotDevice.getListen_service_ip()))
|
|
|
|
{
|
|
|
|
response.getWriter().print(new Message(MessageCode.DEFAULT_FAIL_CODE,"未找到设备监听服务地址"));
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
String url = "http://"+iotDevice.getListen_service_ip()+"device/getFirmwareVersion/"+iotDevice.getMqtt_username();
|
|
|
|
|
|
|
|
Response response1 = HttpUtils.postFromBody(url, builder -> {
|
|
|
|
}, formBody -> {
|
|
|
|
});
|
|
|
|
return response1.body().string();
|
|
|
|
public Message getFirmwareVersion(@PathVariable String imei) {
|
|
|
|
return deviceControlService.getFirmwareVersion(imei);
|
|
|
|
}
|
|
|
|
|
|
|
|
@ApiOperation("强行断开链接")
|
|
...
|
...
|
@@ -122,20 +66,8 @@ public class IotDeviceControlController { |
|
|
|
})
|
|
|
|
@ResponseBody
|
|
|
|
@PostMapping("/closeSession/{imei}")
|
|
|
|
public String closeSession(HttpServletResponse response,@PathVariable String imei) throws IOException {
|
|
|
|
IotDevice iotDevice = iotDeviceService.selectIotDeviceByClient_id(imei);
|
|
|
|
response.setCharacterEncoding("UTF-8");
|
|
|
|
if(StringUtils.isEmpty(iotDevice.getListen_service_ip()))
|
|
|
|
{
|
|
|
|
response.getWriter().print(new Message(MessageCode.DEFAULT_FAIL_CODE,"未找到设备监听服务地址"));
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
String url = "http://"+iotDevice.getListen_service_ip()+"device/closeSession/"+imei;
|
|
|
|
|
|
|
|
Response response1 = HttpUtils.postFromBody(url, builder -> {
|
|
|
|
}, formBody -> {
|
|
|
|
});
|
|
|
|
return response1.body().string();
|
|
|
|
public Message closeSession(@PathVariable String imei) {
|
|
|
|
return deviceControlService.closeSession(imei);
|
|
|
|
}
|
|
|
|
|
|
|
|
@ApiOperation("删除主机")
|
|
...
|
...
|
@@ -145,28 +77,8 @@ public class IotDeviceControlController { |
|
|
|
@Transactional
|
|
|
|
@ResponseBody
|
|
|
|
@PostMapping("/delIotDevice/{imei}")
|
|
|
|
public String delIotDevice(HttpServletResponse response,@PathVariable String imei) {
|
|
|
|
IotDevice iotDevice = iotDeviceService.selectIotDeviceByClient_id(imei);
|
|
|
|
iotDeviceService.deleteIotDeviceByClient_id(imei);
|
|
|
|
iIotTerminalService.deleteIotTerminalByDeviceId(imei);
|
|
|
|
response.setCharacterEncoding("UTF-8");
|
|
|
|
if(StringUtils.isEmpty(iotDevice.getListen_service_ip()))
|
|
|
|
{
|
|
|
|
return JSONObject.toJSONString(new Message(MessageCode.DEFAULT_SUCCESS_CODE,"删除成功"));
|
|
|
|
}
|
|
|
|
String url = "http://"+iotDevice.getListen_service_ip()+"device/delIotDevice/"+imei;
|
|
|
|
|
|
|
|
try {
|
|
|
|
String str = HttpUtils.getResponseString(HttpUtils.postFromBody(url, builder -> {
|
|
|
|
}, formBody -> {
|
|
|
|
}));
|
|
|
|
if(null != str)
|
|
|
|
{
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
} catch (IOException e) {
|
|
|
|
}
|
|
|
|
return JSONObject.toJSONString(new Message(MessageCode.DEFAULT_SUCCESS_CODE,"删除成功"));
|
|
|
|
public Message delIotDevice(@PathVariable String imei) {
|
|
|
|
return deviceControlService.delIotDevice(imei);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
...
|
...
|
@@ -176,9 +88,8 @@ public class IotDeviceControlController { |
|
|
|
})
|
|
|
|
@ResponseBody
|
|
|
|
@PostMapping("/delIotTerminal/{imei}/{number}")
|
|
|
|
public String delIotTerminal(HttpServletResponse response,@PathVariable String imei,@PathVariable String number) {
|
|
|
|
response.setCharacterEncoding("UTF-8");
|
|
|
|
return iIotTerminalService.deleteIotTerminalById(imei,number);
|
|
|
|
public Message delIotTerminal(@PathVariable String imei,@PathVariable String number) {
|
|
|
|
return deviceControlService.delIotTerminal(imei,number);
|
|
|
|
}
|
|
|
|
|
|
|
|
@ApiOperation(value = "读取属性")
|
|
...
|
...
|
@@ -191,19 +102,8 @@ public class IotDeviceControlController { |
|
|
|
@Log(title = "设备控制", businessType = BusinessType.UPDATE)
|
|
|
|
@ResponseBody
|
|
|
|
@PostMapping("/readAttribute/{imei}/{sensor_number}")
|
|
|
|
public String readAttribute(HttpServletResponse response,@PathVariable String imei,@PathVariable String sensor_number,String attributes) throws IOException {
|
|
|
|
IotDevice iotDevice = iotDeviceService.selectIotDeviceByClient_id(imei);
|
|
|
|
response.setCharacterEncoding("UTF-8");
|
|
|
|
if(StringUtils.isEmpty(iotDevice.getListen_service_ip()))
|
|
|
|
{
|
|
|
|
response.getWriter().print(new Message(MessageCode.DEFAULT_FAIL_CODE,"未找到设备监听服务地址"));
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
String url = "http://"+iotDevice.getListen_service_ip()+"device/read/"+imei;
|
|
|
|
Map<String,Object> map = new HashMap<>();
|
|
|
|
map.put(sensor_number,attributes);
|
|
|
|
Response response1 = HttpUtils.postJsonBody(url, jsonObject -> jsonObject.putAll(map));
|
|
|
|
return response1.body().string();
|
|
|
|
public Message readAttribute(@PathVariable String imei,@PathVariable String sensor_number,String attributes) {
|
|
|
|
return deviceControlService.readAttribute(imei,sensor_number,attributes);
|
|
|
|
}
|
|
|
|
|
|
|
|
@ApiOperation(value = "设置主机自定义参数",notes = "自定义数据模型:\n" +
|
|
...
|
...
|
@@ -222,18 +122,8 @@ public class IotDeviceControlController { |
|
|
|
@Log(title = "设备控制", businessType = BusinessType.UPDATE)
|
|
|
|
@ResponseBody
|
|
|
|
@PostMapping("/upSummary/{imei}")
|
|
|
|
public String upSummary(HttpServletResponse response,@PathVariable String imei,String summary) throws IOException {
|
|
|
|
String url = getServiceAdrres(response,imei);
|
|
|
|
if(null == url)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
Map<String,Object> valueMap = new HashMap<>();
|
|
|
|
valueMap.put("summary",JSONObject.parseObject(summary));
|
|
|
|
Response response1 = HttpUtils.postJsonBody(url,formBody -> {
|
|
|
|
formBody.put("0", valueMap);
|
|
|
|
});
|
|
|
|
return response1.body().string();
|
|
|
|
public Message upSummary(@PathVariable String imei,String summary) {
|
|
|
|
return deviceControlService.upSummary(imei,summary);
|
|
|
|
}
|
|
|
|
|
|
|
|
@ApiOperation(value = "修改指定终端属性",notes = "配置参数模型:\n" +
|
|
...
|
...
|
@@ -251,16 +141,8 @@ public class IotDeviceControlController { |
|
|
|
@Log(title = "设备控制", businessType = BusinessType.UPDATE)
|
|
|
|
@ResponseBody
|
|
|
|
@PostMapping("/upTerminalConfig/{imei}/{number}")
|
|
|
|
public String upTerminalConfig(HttpServletResponse response, @PathVariable String imei,@PathVariable String number,@RequestBody Map<String,Object> config) throws IOException {
|
|
|
|
String url = getServiceAdrres(response,imei);
|
|
|
|
if(null == url)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
Map<String,Object> map = new HashMap<>();
|
|
|
|
map.put(number,config);
|
|
|
|
Response response1 = HttpUtils.postJsonBody(url, jsonObject -> jsonObject.putAll(map));
|
|
|
|
return response1.body().string();
|
|
|
|
public Message upTerminalConfig(@PathVariable String imei,@PathVariable String number,@RequestBody Map<String,Object> config) {
|
|
|
|
return deviceControlService.upTerminalConfig(imei,number,config);
|
|
|
|
}
|
|
|
|
|
|
|
|
@ApiOperation(value = "批量修改终端属性",notes = "批量数据模型:\n" +
|
|
...
|
...
|
@@ -286,22 +168,8 @@ public class IotDeviceControlController { |
|
|
|
@Log(title = "设备控制", businessType = BusinessType.UPDATE)
|
|
|
|
@ResponseBody
|
|
|
|
@PostMapping("/batchUpTerminalConfig/{imei}")
|
|
|
|
public String batchUpTerminalConfig(HttpServletResponse response,@PathVariable String imei,@RequestBody Map<String,Object> map) throws IOException {
|
|
|
|
String url = getServiceAdrres(response,imei);
|
|
|
|
if(null == url)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
Response response1 = HttpUtils.postJsonBody(url, builder -> {
|
|
|
|
|
|
|
|
}, formBody -> {
|
|
|
|
for (String key:map.keySet())
|
|
|
|
{
|
|
|
|
formBody.put(key, map.get(key));
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
return response1.body().string();
|
|
|
|
public Message batchUpTerminalConfig(@PathVariable String imei,@RequestBody Map<String,Object> map) {
|
|
|
|
return deviceControlService.batchUpTerminalConfig(imei,map);
|
|
|
|
}
|
|
|
|
|
|
|
|
} |
...
|
...
|
|