main
周文涛 2 years ago
parent d23e32343e
commit aa38126140

@ -8,10 +8,8 @@ import com.example.zxweb.utils.IotUtils;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Map; import java.util.Map;
@ -26,7 +24,6 @@ import java.util.Map;
@Slf4j @Slf4j
@Api(tags = "设备管理") @Api(tags = "设备管理")
public class IotController { public class IotController {
@ApiOperation(value = "获取单个设备信息") @ApiOperation(value = "获取单个设备信息")
@GetMapping(value = "/devices") @GetMapping(value = "/devices")
public Result<?> devices(@RequestParam(value = "serial",defaultValue = "")String serial,@RequestParam(value = "productId",defaultValue = "")String productId){ public Result<?> devices(@RequestParam(value = "serial",defaultValue = "")String serial,@RequestParam(value = "productId",defaultValue = "")String productId){
@ -36,6 +33,128 @@ public class IotController {
requestBody.put("serial",serial); requestBody.put("serial",serial);
requestBody.put("productId",productId); requestBody.put("productId",productId);
//请求数据 //请求数据
return Result.OK(IotUtils.getApi(IotApiEnum.getPathByText("获取单个设备信息"),requestBody)); return jsonObjectToResult(IotUtils.getApi(IotApiEnum.getPathByText("获取单个设备信息"), requestBody));
}
@ApiOperation(value = "获取设备列表")
@GetMapping("/devices/list")
public Result<?> devicesList(@RequestParam(value = "serial",defaultValue = "")String serial,@RequestParam(value = "productId",defaultValue = "")String productId,
@RequestParam(value = "modelCode",defaultValue = "")String modelCode,@RequestParam(value = "authority",defaultValue = "")String authority,
@RequestParam(value = "pageNo",defaultValue = "1")String pageNo,@RequestParam(value = "pageSize",defaultValue = "10")String pageSize,
@RequestParam(value = "startTime",defaultValue = "")String startTime,@RequestParam(value = "endTime",defaultValue = "")String endTime,
@RequestParam(value = "sort",defaultValue = "")String sort){
AssertUtils.notEmpty(serial,"请输入-[serial]");
JSONObject requestBody=new JSONObject();
requestBody.put("serial",serial);
requestBody.put("productId",productId);
requestBody.put("modelCode",modelCode);
requestBody.put("authority",authority);
requestBody.put("pageNo",pageNo);
requestBody.put("pageSize",pageSize);
requestBody.put("startTime",startTime);
requestBody.put("endTime",endTime);
requestBody.put("sort",sort);
return jsonObjectToResult(IotUtils.getApi(IotApiEnum.getPathByText("获取设备列表"),requestBody));
}
@ApiOperation(value = "查询设备历史数据")
@GetMapping("/devices/datastreams")
public Result<?> devicesDatastreams(@RequestParam(value = "serial",defaultValue = "")String serial,@RequestParam(value = "productId",defaultValue = "")String productId,
@RequestParam(value = "dataStreamName",defaultValue = "")String dataStreamName,
@RequestParam(value = "pageNo",defaultValue = "1")String pageNo,@RequestParam(value = "pageSize",defaultValue = "10")String pageSize,
@RequestParam(value = "startTime",defaultValue = "")String startTime,@RequestParam(value = "endTime",defaultValue = "")String endTime,
@RequestParam(value = "sort",defaultValue = "")String sort){
AssertUtils.notEmpty(serial,"请输入-[serial]");
AssertUtils.notEmpty(dataStreamName,"请输入-[dataStreamName]");
JSONObject requestBody=new JSONObject();
requestBody.put("serial",serial);
requestBody.put("productId",productId);
requestBody.put("dataStreamName",dataStreamName);
requestBody.put("pageNo",pageNo);
requestBody.put("pageSize",pageSize);
requestBody.put("startTime",startTime);
requestBody.put("endTime",endTime);
requestBody.put("sort",sort);
return jsonObjectToResult(IotUtils.getApi(IotApiEnum.getPathByText("查询设备历史数据"),requestBody));
}
@ApiOperation(value = "查询消息是否下达到设备")
@GetMapping("/devices/datastreams/state")
public Result<?> devicesDatastreamsState(@RequestParam(value = "serial",defaultValue = "")String serial,@RequestParam(value = "productId",defaultValue = "")String productId,
@RequestParam(value = "streamCinId",defaultValue = "")String streamCinId){
AssertUtils.notEmpty(serial,"请输入-[serial]");
AssertUtils.notEmpty(productId,"请输入-[productId]");
AssertUtils.notEmpty(streamCinId,"请输入-[streamCinId]");
JSONObject requestBody=new JSONObject();
requestBody.put("serial",serial);
requestBody.put("productId",productId);
requestBody.put("streamCinId",streamCinId);
return jsonObjectToResult(IotUtils.getApi(IotApiEnum.getPathByText("查询消息是否下达到设备"),requestBody));
}
@ApiOperation(value = "查询事件历史数据")
@GetMapping("/devices/events")
public Result<?> devicesEvents(@RequestParam(value = "serial",defaultValue = "")String serial,@RequestParam(value = "productId",defaultValue = "")String productId,
@RequestParam(value = "dataStreamName",defaultValue = "")String dataStreamName,
@RequestParam(value = "pageNo",defaultValue = "1")String pageNo,@RequestParam(value = "pageSize",defaultValue = "10")String pageSize,
@RequestParam(value = "startTime",defaultValue = "")String startTime,@RequestParam(value = "endTime",defaultValue = "")String endTime,
@RequestParam(value = "sort",defaultValue = "")String sort){
AssertUtils.notEmpty(serial,"请输入-[serial]");
AssertUtils.notEmpty(dataStreamName,"请输入-[dataStreamName]");
JSONObject requestBody=new JSONObject();
requestBody.put("serial",serial);
requestBody.put("productId",productId);
requestBody.put("dataStreamName",dataStreamName);
requestBody.put("pageNo",pageNo);
requestBody.put("pageSize",pageSize);
requestBody.put("startTime",startTime);
requestBody.put("endTime",endTime);
requestBody.put("sort",sort);
return jsonObjectToResult(IotUtils.getApi(IotApiEnum.getPathByText("查询事件历史数据"),requestBody));
}
@ApiOperation(value = "向设备发送消息")
@PostMapping("/devices/datastreams")
public Result<?> devicesDatastreams(@RequestBody JSONObject requestBody){
return jsonObjectToResult(IotUtils.postApi(IotApiEnum.getPathByText("向设备发送消息"),requestBody));
}
@ApiOperation(value = "向设备发送方法")
@PostMapping("/devices/methods")
public Result<?> devicesMethods(@RequestBody JSONObject requestBody){
return jsonObjectToResult(IotUtils.postApi(IotApiEnum.getPathByText("向设备发送方法"),requestBody));
}
@ApiOperation(value = "查询方法历史数据")
@GetMapping("/devices/methods")
public Result<?> devicesMethods(@RequestParam(value = "serial",defaultValue = "")String serial,@RequestParam(value = "productId",defaultValue = "")String productId,
@RequestParam(value = "methodName",defaultValue = "")String methodName,
@RequestParam(value = "pageNo",defaultValue = "1")String pageNo,@RequestParam(value = "pageSize",defaultValue = "10")String pageSize,
@RequestParam(value = "startTime",defaultValue = "")String startTime,@RequestParam(value = "endTime",defaultValue = "")String endTime,
@RequestParam(value = "sort",defaultValue = "")String sort){
AssertUtils.notEmpty(serial,"请输入设备序列号-[serial]");
AssertUtils.notEmpty(methodName,"请输入方法名称-[methodName]");
JSONObject requestBody=new JSONObject();
requestBody.put("serial",serial);
requestBody.put("productId",productId);
requestBody.put("dataStreamName",methodName);
requestBody.put("pageNo",pageNo);
requestBody.put("pageSize",pageSize);
requestBody.put("startTime",startTime);
requestBody.put("endTime",endTime);
requestBody.put("sort",sort);
return jsonObjectToResult(IotUtils.getApi(IotApiEnum.getPathByText("查询方法历史数据"),requestBody));
}
public static Result<?> jsonObjectToResult(JSONObject jsonObject) {
Integer code = jsonObject.getInteger("code");
String message = jsonObject.getString("message");
String data = jsonObject.getString("data");
if (code!=0) {
return Result.error(code, StringUtils.isEmpty(message)?data:message);
}
return Result.OK(StringUtils.isEmpty(message)?data:message);
} }
} }

@ -32,4 +32,8 @@ public class IotUtils {
JSONObject responseBody = RestUtil.get(API_PREFIX+apiUrl+sb,null,null,headers); JSONObject responseBody = RestUtil.get(API_PREFIX+apiUrl+sb,null,null,headers);
return responseBody; return responseBody;
} }
public static JSONObject postApi(String apiUrl,JSONObject requestBody){
return RestUtil.post(API_PREFIX+apiUrl,requestBody,headers);
}
} }

Loading…
Cancel
Save