main
周文涛 2 years ago
parent ad461c9faf
commit ac98d3d8fb

@ -148,6 +148,20 @@ public class IotController {
return jsonObjectToResult(IotUtils.getApi(IotApiEnum.getPathByText("查询方法历史数据"),requestBody));
}
@ApiOperation(value = "查询方法历史数据(最新一条)")
@GetMapping("/devices/methods/news")
public Result<?> devicesMethodsNews(@RequestParam(value = "serial",defaultValue = "")String serial,
@RequestParam(value = "methodName",defaultValue = "")String methodName,
@RequestParam(value = "sort",defaultValue = "")String sort){
AssertUtils.notEmpty(serial,"请输入设备序列号-[serial]");
//AssertUtils.notEmpty(methodName,"请输入方法名称-[methodName]");
JSONObject requestBody=new JSONObject();
requestBody.put("serial",serial);
requestBody.put("methodName",methodName);
requestBody.put("sort",sort);
return Result.OK(IotUtils.devicesMethodsNews(requestBody));
}
public static Result<?> jsonObjectToResult(JSONObject jsonObject) {
Integer code = jsonObject.getInteger("code");
String message = jsonObject.getString("message");

@ -1,9 +1,15 @@
package com.example.zxweb.utils;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.zxweb.common.constant.enums.IotApiEnum;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.List;
/**
* @Description ios
* @Author ZhouWenTao
@ -16,6 +22,31 @@ public class IotUtils {
private static final JSONObject headers=JSONObject.parseObject("{\"x-consumer-username\":\"dwVendor\",\"appCode\":\"42142fd0jkbf4515853b7fcec64748f6\"}");
public static List<JSONObject> devicesMethodsNews(JSONObject queryData){
String serial = queryData.getString("serial");
String[] serials = serial.split(",");
List<JSONObject> list=new ArrayList<>();
for (String s : serials) {
String url = API_PREFIX + IotApiEnum.getPathByText("查询方法历史数据") + "?serial=" + s;
if (!StringUtils.isEmpty(queryData.getString("methodName"))) {
url+="&methodName="+queryData.getString("methodName");
}
JSONObject jsonObject = RestUtil.get(url, null, null, headers);
Integer code = jsonObject.getInteger("code");
if (code==0) {
if (jsonObject.getJSONObject("data")==null) {
continue;
}
JSONArray jsonArray = jsonObject.getJSONObject("data").getJSONArray("methods");
if (CollectionUtils.isEmpty(jsonArray)) {
continue;
}
list.add(jsonArray.getJSONObject(0));
}
}
return list;
}
public static JSONObject getApi(String apiUrl,JSONObject queryData) {
StringBuilder sb=new StringBuilder();

Loading…
Cancel
Save