|
...
|
...
|
@@ -8,14 +8,17 @@ import com.ruoyi.common.core.domain.Message; |
|
|
|
import com.ruoyi.common.enums.BusinessType;
|
|
|
|
import com.ruoyi.common.utils.GsonConstructor;
|
|
|
|
import com.zhonglai.luhui.action.BaseController;
|
|
|
|
import com.zhonglai.luhui.device.domain.IotDevice;
|
|
|
|
import com.zhonglai.luhui.device.dto.CommandType;
|
|
|
|
import com.zhonglai.luhui.device.dto.DeviceCommand;
|
|
|
|
import com.zhonglai.luhui.device.service.IIotDeviceService;
|
|
|
|
import com.zhonglai.luhui.rocketmq.service.RocketMqService;
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
|
import io.swagger.annotations.ApiImplicitParam;
|
|
|
|
import io.swagger.annotations.ApiImplicitParams;
|
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
|
import org.springframework.util.StreamUtils;
|
|
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
...
|
...
|
@@ -25,12 +28,15 @@ import org.springframework.web.bind.annotation.RestController; |
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
@Api(tags = "设备控制")
|
|
|
|
@Api(tags = "控制器")
|
|
|
|
@RestController
|
|
|
|
@RequestMapping("/iot/controlDevice")
|
|
|
|
public class ControlDeviceConreoller extends BaseController {
|
|
|
|
@Autowired
|
|
|
|
private RocketMqService rocketMqService;
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
private IIotDeviceService iotDeviceService;
|
|
|
|
@ApiOperation(value = "写指令",notes = "body参数描述:\r\n" +
|
|
|
|
"{\n" +
|
|
|
|
" \"0\":{\n" +
|
|
...
|
...
|
@@ -64,7 +70,45 @@ public class ControlDeviceConreoller extends BaseController { |
|
|
|
deviceCommand.setDeviceId(deviceId);
|
|
|
|
deviceCommand.setCommandType(CommandType.write);
|
|
|
|
deviceCommand.setData(GsonConstructor.get().fromJson(body,JsonObject.class));
|
|
|
|
return control(deviceCommand);
|
|
|
|
|
|
|
|
return deviceControl(deviceCommand);
|
|
|
|
}
|
|
|
|
|
|
|
|
@ApiOperation(value = "读指令",notes = "body参数描述:\r\n" +
|
|
|
|
"{\n" +
|
|
|
|
" \"0\":{\n" +
|
|
|
|
" \"rssi\": -43,\n" +
|
|
|
|
" \"firmware_version\": 1.2,\n" +
|
|
|
|
" \"longitude\": 0,\n" +
|
|
|
|
" \"latitude\": 0,\n" +
|
|
|
|
" \"summary\": {\n" +
|
|
|
|
" \t \"name\": \"wumei-smart\",\n" +
|
|
|
|
" \t \"chip\": \"esp8266\",\n" +
|
|
|
|
" \t \"author\": \"kerwincui\",\n" +
|
|
|
|
" \t \"version\": 1.2,\n" +
|
|
|
|
" \t \"createTime\": \"2022-06-06\"\n" +
|
|
|
|
" }\n" +
|
|
|
|
" },\n" +
|
|
|
|
" \"1\":{\n" +
|
|
|
|
" \"id1\":\"value1\",\n" +
|
|
|
|
" \"id2\":\"value2\",\n" +
|
|
|
|
" \"id3\":\"value3\"\n" +
|
|
|
|
" }\n" +
|
|
|
|
"}")
|
|
|
|
@ApiImplicitParams({
|
|
|
|
@ApiImplicitParam(value = "网关id",name = "deviceId"),
|
|
|
|
})
|
|
|
|
@Log(title = "读指令", businessType = BusinessType.WRITE)
|
|
|
|
@PostMapping("/read/{deviceId}")
|
|
|
|
public AjaxResult read(@PathVariable String deviceId, HttpServletRequest request) throws IOException {
|
|
|
|
|
|
|
|
byte[] bodyBytes = StreamUtils.copyToByteArray(request.getInputStream());
|
|
|
|
String body = new String(bodyBytes, request.getCharacterEncoding());
|
|
|
|
DeviceCommand deviceCommand = new DeviceCommand();
|
|
|
|
deviceCommand.setDeviceId(deviceId);
|
|
|
|
deviceCommand.setCommandType(CommandType.write);
|
|
|
|
deviceCommand.setData(GsonConstructor.get().fromJson(body,JsonObject.class));
|
|
|
|
return deviceControl(deviceCommand);
|
|
|
|
}
|
|
|
|
|
|
|
|
@ApiOperation("更新缓存模型")
|
|
...
|
...
|
@@ -77,7 +121,7 @@ public class ControlDeviceConreoller extends BaseController { |
|
|
|
JsonObject jsonObject = new JsonObject();
|
|
|
|
jsonObject.addProperty("product_id",product_id);
|
|
|
|
deviceCommand.setData(jsonObject);
|
|
|
|
return control(deviceCommand);
|
|
|
|
return sysControl(deviceCommand);
|
|
|
|
}
|
|
|
|
|
|
|
|
@ApiOperation("更新缓存翻译模型")
|
|
...
|
...
|
@@ -90,7 +134,7 @@ public class ControlDeviceConreoller extends BaseController { |
|
|
|
JsonObject jsonObject = new JsonObject();
|
|
|
|
jsonObject.addProperty("product_id",product_id);
|
|
|
|
deviceCommand.setData(jsonObject);
|
|
|
|
return control(deviceCommand);
|
|
|
|
return sysControl(deviceCommand);
|
|
|
|
}
|
|
|
|
|
|
|
|
@ApiOperation("清除网关缓存")
|
|
...
|
...
|
@@ -101,7 +145,7 @@ public class ControlDeviceConreoller extends BaseController { |
|
|
|
DeviceCommand deviceCommand = new DeviceCommand();
|
|
|
|
deviceCommand.setDeviceId(deviceId);
|
|
|
|
deviceCommand.setCommandType(CommandType.cleanDeviceHost);
|
|
|
|
return control(deviceCommand);
|
|
|
|
return sysControl(deviceCommand);
|
|
|
|
}
|
|
|
|
|
|
|
|
@ApiOperation("更新终端缓存")
|
|
...
|
...
|
@@ -118,13 +162,68 @@ public class ControlDeviceConreoller extends BaseController { |
|
|
|
JsonObject jsonObject = new JsonObject();
|
|
|
|
jsonObject.addProperty("sensor_number",sensor_number);
|
|
|
|
deviceCommand.setData(jsonObject);
|
|
|
|
return control(deviceCommand);
|
|
|
|
return sysControl(deviceCommand);
|
|
|
|
}
|
|
|
|
|
|
|
|
@ApiOperation("添加订阅")
|
|
|
|
@ApiImplicitParams({
|
|
|
|
@ApiImplicitParam(value = "监听服务器的ip",name = "ip"),
|
|
|
|
@ApiImplicitParam(value = "产品集合",name = "product_ids"),
|
|
|
|
})
|
|
|
|
@Log(title = "添加订阅", businessType = BusinessType.CAHE)
|
|
|
|
@PostMapping("/addSubscribe")
|
|
|
|
public AjaxResult addSubscribe(String product_ids,String ip) {
|
|
|
|
DeviceCommand deviceCommand = new DeviceCommand();
|
|
|
|
deviceCommand.setCommandType(CommandType.addSubscribe);
|
|
|
|
JsonObject jsonObject = new JsonObject();
|
|
|
|
jsonObject.addProperty("product_ids",product_ids);
|
|
|
|
jsonObject.addProperty("ip",ip);
|
|
|
|
deviceCommand.setData(jsonObject);
|
|
|
|
return sysControl(deviceCommand);
|
|
|
|
}
|
|
|
|
|
|
|
|
@ApiOperation(value = "通知",notes = "body参数描述:\r\n" +
|
|
|
|
"{\n" +
|
|
|
|
" \"1\":{\n" +
|
|
|
|
" \"id1\":\"value1\",\n" +
|
|
|
|
" \"id2\":\"value2\",\n" +
|
|
|
|
" \"id3\":\"value3\"\n" +
|
|
|
|
" }\n" +
|
|
|
|
"}")
|
|
|
|
@ApiImplicitParams({
|
|
|
|
@ApiImplicitParam(value = "网关id",name = "deviceId"),
|
|
|
|
})
|
|
|
|
@Log(title = "通知", businessType = BusinessType.CAHE)
|
|
|
|
@PostMapping("/notice/{deviceId}")
|
|
|
|
public AjaxResult notice(@PathVariable String deviceId, HttpServletRequest request) throws IOException {
|
|
|
|
byte[] bodyBytes = StreamUtils.copyToByteArray(request.getInputStream());
|
|
|
|
String body = new String(bodyBytes, request.getCharacterEncoding());
|
|
|
|
DeviceCommand deviceCommand = new DeviceCommand();
|
|
|
|
deviceCommand.setDeviceId(deviceId);
|
|
|
|
deviceCommand.setCommandType(CommandType.notice);
|
|
|
|
deviceCommand.setData(GsonConstructor.get().fromJson(body,JsonObject.class));
|
|
|
|
return deviceControl(deviceCommand);
|
|
|
|
}
|
|
|
|
|
|
|
|
private AjaxResult deviceControl(DeviceCommand deviceCommand)
|
|
|
|
{
|
|
|
|
IotDevice iotDevice = iotDeviceService.selectIotDeviceByClient_id(deviceCommand.getDeviceId());
|
|
|
|
if(null == iotDevice || iotDevice.getStatus()!=3)
|
|
|
|
{
|
|
|
|
return AjaxResult.error("设备不存在或者不在线");
|
|
|
|
}
|
|
|
|
|
|
|
|
Message message = rocketMqService.send("deviceCommandListen",GsonConstructor.get().toJson(deviceCommand).getBytes(),iotDevice.getOperation_token());
|
|
|
|
if(message.getCode()==1)
|
|
|
|
{
|
|
|
|
return new AjaxResult(HttpStatus.SUCCESS, message.getMessage(), message.getData());
|
|
|
|
}
|
|
|
|
return new AjaxResult(HttpStatus.ERROR, message.getMessage(), message.getData());
|
|
|
|
}
|
|
|
|
|
|
|
|
private AjaxResult control( DeviceCommand deviceCommand)
|
|
|
|
private AjaxResult sysControl(DeviceCommand deviceCommand)
|
|
|
|
{
|
|
|
|
Message message = rocketMqService.send("deviceCommandListen",GsonConstructor.get().toJson(deviceCommand).getBytes());
|
|
|
|
Message message = rocketMqService.send("deviceCommandListen",GsonConstructor.get().toJson(deviceCommand).getBytes(),"SysCommand");
|
|
|
|
if(message.getCode()==1)
|
|
|
|
{
|
|
|
|
return new AjaxResult(HttpStatus.SUCCESS, message.getMessage(), message.getData());
|
...
|
...
|
|