|
|
@ -2,6 +2,7 @@ package com.ruoyi.web.service.impl; |
|
|
|
|
|
|
|
import cn.hutool.core.date.DateTime; |
|
|
|
import cn.hutool.core.date.DateUtil; |
|
|
|
import cn.hutool.core.util.CharsetUtil; |
|
|
|
import cn.hutool.core.util.HexUtil; |
|
|
|
import cn.hutool.core.util.StrUtil; |
|
|
|
import cn.hutool.http.HttpRequest; |
|
|
@ -44,12 +45,13 @@ public class OnenetEquipServiceImpl implements IOnenetEquipService { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public List<OnenetEquipVo.EquipList> selectOnenetEquipList(OnenetEquip onenetEquip) { |
|
|
|
public OnenetEquipVo.EquipListTotal selectOnenetEquipList(OnenetEquipDto.QureyEquipParam qureyEquipParam) { |
|
|
|
OnenetConfig onenetConfigExample = new OnenetConfig(); |
|
|
|
onenetConfigExample.setConfigKey("onenet_api_key"); |
|
|
|
|
|
|
|
List<OnenetConfig> onenetConfigs = onenetConfigMapper.selectOnenetConfigList(onenetConfigExample); |
|
|
|
List<OnenetEquipVo.EquipList> list = new ArrayList<>(); |
|
|
|
OnenetEquipVo.EquipListTotal equipListTotal = new OnenetEquipVo.EquipListTotal(); |
|
|
|
|
|
|
|
if (onenetConfigs.size() > 0){ |
|
|
|
OnenetConfig onenetConfig = onenetConfigs.get(0); |
|
|
|
|
|
|
@ -60,19 +62,24 @@ public class OnenetEquipServiceImpl implements IOnenetEquipService { |
|
|
|
|
|
|
|
HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<MultiValueMap<String, Object>>(null,headers); |
|
|
|
|
|
|
|
HashMap<String, String> paramMap = new HashMap<>(); |
|
|
|
paramMap.put("page", "1"); |
|
|
|
paramMap.put("per_page", "10"); |
|
|
|
HashMap<String, Object> paramMap = new HashMap<>(); |
|
|
|
paramMap.put("page", qureyEquipParam.getPageNum()); |
|
|
|
paramMap.put("per_page", qureyEquipParam.getPageSize()); |
|
|
|
if (!StrUtil.hasEmpty(qureyEquipParam.getKey_words())){ |
|
|
|
paramMap.put("key_words", qureyEquipParam.getKey_words()); |
|
|
|
} |
|
|
|
|
|
|
|
RestTemplate restTemplate = new RestTemplate(); |
|
|
|
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, httpEntity, String.class, paramMap); |
|
|
|
String response = HttpRequest.get(url).header("api-key", onenetConfig.getConfigValue()).form(paramMap).execute().body(); |
|
|
|
|
|
|
|
String body = response.getBody(); |
|
|
|
JSONObject json1 = JSON.parseObject(body); |
|
|
|
JSONObject json1 = JSON.parseObject(response); |
|
|
|
JSONObject json2 = json1.getJSONObject("data"); |
|
|
|
JSONArray devices = json2.getJSONArray("devices"); |
|
|
|
int total = json2.getInteger("total_count"); |
|
|
|
equipListTotal.setTotal(total); |
|
|
|
|
|
|
|
if (devices.size() > 0){ |
|
|
|
List<OnenetEquipVo.EquipList> list = new ArrayList<>(); |
|
|
|
|
|
|
|
for (int i = 0; i < devices.size(); i++) { |
|
|
|
JSONObject device = devices.getJSONObject(i); |
|
|
|
|
|
|
@ -89,12 +96,12 @@ public class OnenetEquipServiceImpl implements IOnenetEquipService { |
|
|
|
list.add(onenetEquipData); |
|
|
|
} |
|
|
|
// list = JSON.parseArray(devices.toJSONString(),OnenetEquip.class);
|
|
|
|
|
|
|
|
return list; |
|
|
|
equipListTotal.setEquipLists(list); |
|
|
|
return equipListTotal; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return list; |
|
|
|
return equipListTotal; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@ -163,30 +170,34 @@ public class OnenetEquipServiceImpl implements IOnenetEquipService { |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public List<OnenetEquipVo.EquipData> selectEquipDatas(OnenetEquipDto.EquipDataParam equipDataParam) { |
|
|
|
public OnenetEquipVo.EquipDataTotal selectEquipDatas(OnenetEquipDto.EquipDataParam equipDataParam) { |
|
|
|
OnenetConfig onenetConfigExample = new OnenetConfig(); |
|
|
|
onenetConfigExample.setConfigKey("onenet_api_key"); |
|
|
|
|
|
|
|
List<OnenetConfig> onenetConfigs = onenetConfigMapper.selectOnenetConfigList(onenetConfigExample); |
|
|
|
List<OnenetEquipVo.EquipData> onenetEquipVoList = new ArrayList<>(); |
|
|
|
|
|
|
|
OnenetEquipVo.EquipDataTotal equipDataTotal = new OnenetEquipVo.EquipDataTotal(); |
|
|
|
|
|
|
|
if (onenetConfigs.size() > 0) { |
|
|
|
HashMap<String, String> uriParams = new HashMap<>(); |
|
|
|
if (!StrUtil.hasEmpty(equipDataParam.getStart())){ |
|
|
|
uriParams.put("start", equipDataParam.getStart()); |
|
|
|
} |
|
|
|
if (!StrUtil.hasEmpty(equipDataParam.getEnd())){ |
|
|
|
uriParams.put("end", equipDataParam.getEnd()); |
|
|
|
} |
|
|
|
HashMap<String, Object> paramMap = new HashMap<>(); |
|
|
|
|
|
|
|
String uriParam = HttpUtil.toParams(uriParams); |
|
|
|
if (!StrUtil.hasEmpty(equipDataParam.getEquipDataTime())){ |
|
|
|
|
|
|
|
String url = "http://api.heclouds.com/devices/" + equipDataParam.getObj_id() +"/datapoints?" + uriParam; |
|
|
|
paramMap.put("start", equipDataParam.getEquipDataTime()[0]); |
|
|
|
paramMap.put("end", equipDataParam.getEquipDataTime()[1]); |
|
|
|
} |
|
|
|
|
|
|
|
String url = "http://api.heclouds.com/devices/" + equipDataParam.getObj_id() +"/datapoints"; |
|
|
|
|
|
|
|
OnenetConfig onenetConfig = onenetConfigs.get(0); |
|
|
|
// String response = HttpRequest.get(url).header("api-key", onenetConfig.getConfigValue()).execute().body();
|
|
|
|
|
|
|
|
String response = "{\"errno\":0,\"data\":{\"count\":1,\"datastreams\":[{\"datapoints\":[{\"at\":\"2023-01-09 17:47:15.969\",\"value\":\"68C00866472059908495852F015100FFFE0A6464220901002310010014731641646400000065014E000000000000182301091747150503000002015116\"}, {\"at\":\"2023-01-09 17:47:15.969\",\"value\":\"68C00866472059908495852F015100FFFE0A6464220901002310010014731641646400000065014E000000000000182301091747150503000002015116\"}],\"id\":\"3200_0_5750\"}]},\"error\":\"succ\"}"; |
|
|
|
// String response = HttpRequest.get(url).header("api-key", onenetConfig.getConfigValue()).form(paramMap).execute().body();
|
|
|
|
|
|
|
|
String response = "{\"errno\":0,\"data\":{\"count\":1,\"datastreams\":[{\"datapoints\":[" + |
|
|
|
"{\"at\":\"2023-01-09 17:47:15.969\",\"value\":\"68C00866472059908495852F015100FFFE0A6464220901002310010014731641646400000065014E000000000000182301091747150503000002015116\"}, " + |
|
|
|
"{\"at\":\"2023-01-09 17:47:15.969\",\"value\":\"68C00866472059908495852F015100FFFE0A6464220901002310010014731641646400000065014E000000000000182301091747150503000002015116\"}, " + |
|
|
|
"{\"at\":\"2023-01-09 17:47:15.969\",\"value\":\"68C00866472059908495852F015100FFFE0A6464220901002310010014731641646400000065014E000000000000182301091747150503000002015116\"}" + |
|
|
|
"],\"id\":\"3200_0_5750\"}]},\"error\":\"succ\"}"; |
|
|
|
|
|
|
|
JSONObject responseJson = JSON.parseObject(response); |
|
|
|
|
|
|
@ -196,6 +207,7 @@ public class OnenetEquipServiceImpl implements IOnenetEquipService { |
|
|
|
JSONArray dataArray = dataJson.getJSONArray("datastreams"); |
|
|
|
JSONArray datapoints = dataArray.getJSONObject(0).getJSONArray("datapoints"); |
|
|
|
|
|
|
|
List<OnenetEquipVo.EquipData> onenetEquipVoList = new ArrayList<>(); |
|
|
|
|
|
|
|
for (int i = 0; i < datapoints.size(); i++) { |
|
|
|
JSONObject datapoint = datapoints.getJSONObject(i); |
|
|
@ -270,10 +282,11 @@ public class OnenetEquipServiceImpl implements IOnenetEquipService { |
|
|
|
onenetEquipVoList.add(equipDataVo); |
|
|
|
} |
|
|
|
|
|
|
|
equipDataTotal.setEquipDataList(onenetEquipVoList); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return onenetEquipVoList; |
|
|
|
return equipDataTotal; |
|
|
|
} |
|
|
|
|
|
|
|
public String hexToBin(String hexS){ |
|
|
|