diff --git a/src/main/java/com/example/zxweb/common/constant/DevConstant.java b/src/main/java/com/example/zxweb/common/constant/DevConstant.java new file mode 100644 index 0000000..282cf36 --- /dev/null +++ b/src/main/java/com/example/zxweb/common/constant/DevConstant.java @@ -0,0 +1,12 @@ +package com.example.zxweb.common.constant; + +/** + * @Description 设备 + * @Author ZhouWenTao + * @Date 2023/9/12 11:35 + */ +public interface DevConstant { + class gateway{ + private String gateway_5lhyslqh="0cefafd2a2ca"; + } +} diff --git a/src/main/java/com/example/zxweb/controller/GatewayController.java b/src/main/java/com/example/zxweb/controller/GatewayController.java index cc0254f..a85a2f9 100644 --- a/src/main/java/com/example/zxweb/controller/GatewayController.java +++ b/src/main/java/com/example/zxweb/controller/GatewayController.java @@ -5,13 +5,19 @@ import com.example.zxweb.common.api.vo.Result; import com.example.zxweb.common.constant.enums.IotApiEnum; import com.example.zxweb.utils.AssertUtils; import com.example.zxweb.utils.IotUtils; +import com.example.zxweb.vo.QueryCelueListVO; import io.swagger.annotations.Api; import lombok.extern.slf4j.Slf4j; +import org.springframework.util.StringUtils; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + /** * @Description * @Author ZhouWenTao @@ -22,17 +28,34 @@ import org.springframework.web.bind.annotation.RestController; @Slf4j @Api(tags = "网关设备管理") public class GatewayController { + //网关设备 + private static final List gatewayDevIdList=new ArrayList<>(Arrays.asList("0cefafd605f7","0cefafd295a4")); /** * 获取网关策略列表 - * @param devid 网关设备id + * @param queryCelueListVO 入参 * @return 结果 */ @GetMapping(value = "/celueListQuery") - public Result celueListQuery(@RequestParam(value = "devid")String devid){ + public Result celueListQuery(QueryCelueListVO queryCelueListVO){ + String devid = queryCelueListVO.getDevid(); AssertUtils.notEmpty(devid,"请输入-[devid]"); String format = String.format("{\"serial\":\"%s\",\"productId\":\"\",\"methodName\":\"celueListQuery\",\"inputData\":{\"devid\":\"%s\"}}", devid,devid); JSONObject requestBody = JSONObject.parseObject(format); JSONObject responseBody = IotUtils.postApi(IotApiEnum.getPathByText("向设备发送方法"), requestBody); - return Result.OK(responseBody); + return jsonObjectToResult(responseBody); + } + + + 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); + } + if (StringUtils.isEmpty(message)) { + return Result.OK(jsonObject.getJSONObject("data")); + } + return Result.OK(message); } } diff --git a/src/main/java/com/example/zxweb/vo/QueryCelueListVO.java b/src/main/java/com/example/zxweb/vo/QueryCelueListVO.java new file mode 100644 index 0000000..d382fd8 --- /dev/null +++ b/src/main/java/com/example/zxweb/vo/QueryCelueListVO.java @@ -0,0 +1,21 @@ +package com.example.zxweb.vo; + +import io.swagger.annotations.ApiModelProperty; +import lombok.Data; + +import java.io.Serializable; + +/** + * @Description + * @Author ZhouWenTao + * @Date 2023/9/12 13:38 + */ +@Data +public class QueryCelueListVO implements Serializable { + @ApiModelProperty(value = "设备id") + private String devid; + @ApiModelProperty(value = "页数") + private Integer pageNo=1; + @ApiModelProperty(value = "分页大小") + private Integer pageSize=10; +}