Commit fc6d7ea5 authored by KeYong's avatar KeYong

更新

parent d7b0565f
package com.yeejoin.equipmanage.common.vo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.Date;
import java.util.List;
/**
* @author keyong
* @title: TopographyAlarmVo
* <pre>
* @description: TODO
* </pre>
* @date 2022/01/12 18:57
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class IotIndexResVo {
private Long id;
private String name;
private String nameKey;
private String unit;
private List<Date> times;
private List<IotDataVO> iotData;
}
package com.yeejoin.equipmanage.common.vo;
import lombok.Data;
/**
* @author keyong
* @title: IotDataVO
* <pre>
* @description: 物联系统发送的增量数据封装VO
* </pre>
* @date 2021/1/7 17:44
*/
@Data
public class IotTrendDataVO {
private String key;
private Object value;
}
......@@ -29,6 +29,8 @@ public class TopographyIotIndexTrendVo {
private String unit;
private List<Date> times;
private IotDataVO iotData;
}
......@@ -15,6 +15,7 @@ import com.yeejoin.equipmanage.common.entity.vo.EquipmentIndexVO;
import com.yeejoin.equipmanage.common.enums.TopoNodeTypeEnum;
import com.yeejoin.equipmanage.common.utils.*;
import com.yeejoin.equipmanage.common.vo.*;
import com.yeejoin.equipmanage.fegin.IotFeign;
import com.yeejoin.equipmanage.mapper.*;
import com.yeejoin.equipmanage.service.*;
import com.yeejoin.equipmanage.service.impl.TopographyNodeDetailService;
......@@ -22,6 +23,7 @@ import com.yeejoin.equipmanage.service.impl.TopographyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import liquibase.pro.packaged.S;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
......@@ -36,6 +38,8 @@ import org.typroject.tyboot.core.restful.doc.TycloudOperation;
import org.typroject.tyboot.core.restful.utils.ResponseHelper;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;
......@@ -91,6 +95,8 @@ public class TopographyController extends AbstractBaseController {
EquipmentSpecificIndexMapper equipmentSpecificIndexMapper;
@Autowired
IEquipmentService iEquipmentService;
@Autowired
IotFeign iotFeign;
@Value("${iot.vehicle.track}")
private String iotServerName;
......@@ -807,16 +813,16 @@ public class TopographyController extends AbstractBaseController {
/***
*
* 根拓补节点id查询当前节点物联数据记录
* 根拓补节点id查询当前节点物联指标趋势
*
* **/
@RequestMapping(value = "/equipment/tren", method = RequestMethod.GET)
@TycloudOperation(ApiLevel = UserType.AGENCY)
@ApiOperation(httpMethod = "GET", value = "根据节点id查询当前节点物联数据记录", notes = "根据节点id查询当前节点物联数据记录")
@ApiOperation(httpMethod = "GET", value = "根据节点id查询当前节点物联指标趋势", notes = "根据节点id查询当前节点物联指标趋势")
public ResponseModel getEquipmentIndexTrendInfo(@RequestParam(required = false) String id,
@RequestParam(required = false) String equipSpeId,
@RequestParam(required = false) String beginDate,
@RequestParam(required = false) String endDate) {
@RequestParam(required = false) String endDate) throws ParseException {
String eqpId;
if (StringUtil.isNotEmpty(equipSpeId)) {
eqpId = equipSpeId;
......@@ -845,53 +851,75 @@ public class TopographyController extends AbstractBaseController {
headers.set("product", getProduct());
headers.set("token", getToken());
headers.set("appKey", getAppKey());
HttpEntity httpEntity = new HttpEntity<>(lonAndLatEntityVo, headers);
ResponseEntity<FeignClientResult> feignClientResult = null;
ResponseModel entity = null;
try {
feignClientResult = restTemplate.exchange("http://" + url
+ "/iot/v1/livedata/list?timeStart=" + beginDate + "&timeEnd=" + endDate + "&productKey=" + prefix + "&deviceName=" + suffix,
HttpMethod.GET, httpEntity, FeignClientResult.class);
entity = iotFeign.selectList(getAppKey(), getProduct(), getToken(), beginDate, endDate, prefix, suffix);
} catch (Exception e) {
e.printStackTrace();
}
if (null != feignClientResult && feignClientResult.getBody().getStatus() == 200) {
if (null != feignClientResult.getBody().getResult()) {
String json = JSON.toJSONString(feignClientResult.getBody().getResult());
JSONObject jsonObject = JSONObject.parseObject(json);
Iterator it = jsonObject.entrySet().iterator();
List<IotDataVO> iotDatalist = new ArrayList<IotDataVO>();
while (it.hasNext()) {
IotDataVO iotDataVO = new IotDataVO();
Map.Entry<String, Object> entry = (Map.Entry<String, Object>) it.next();
if (!"name".equals(entry.getKey()) || !"deviceName".equals(entry.getKey()) || !"time".equals(entry.getKey())) {
iotDataVO.setKey(entry.getKey());
iotDataVO.setValue(entry.getValue());
if (200 == entity.getStatus() && StringUtil.isNotEmpty(entity.getResult())) {
String json = JSON.toJSONString(entity.getResult());
List<Map<String, String>> listObject = (List<Map<String, String>>) JSONArray.parse(json);
List<IotDataVO> vos = new ArrayList<>();
for(Map<String, String> mapList : listObject){
for (Map.Entry entry : mapList.entrySet()){
if (!"name".equals(entry.getKey()) && !"deviceName".equals(entry.getKey())) {
IotDataVO vo = new IotDataVO();
vo.setKey(String.valueOf(entry.getKey()));
vo.setValue(String.valueOf(entry.getValue()));
vos.add(vo);
}
iotDatalist.add(iotDataVO);
}
List<EquipmentSpecificIndex> indexes = equipmentSpecificIndexMapper.getEquipmentSpeIndexByIotCodeAndTrend(iotCode);
if (0 <indexes.size()) {
List<TopographyIotIndexTrendVo> list = new ArrayList<>();
indexes.forEach(x -> {
iotDatalist.forEach(iotDataVO -> {
if (x.getNameKey().equals(iotDataVO.getKey())) {
TopographyIotIndexTrendVo vo = new TopographyIotIndexTrendVo();
vo.setId(x.getId());
vo.setName(x.getIndexName());
vo.setNameKey(x.getNameKey());
vo.setUnit(x.getIndexUnitName());
vo.setIotData(iotDataVO);
list.add(vo);
}
});
}
List<IotDataVO> timeList = vos.stream().filter(x -> x.getKey().equals("time")).collect(Collectors.toList());
List<Date> dates = new ArrayList<>();
for (IotDataVO vo : timeList) {
SimpleDateFormat sdf = new SimpleDateFormat(DateUtils.DATE_TIME_T_PATTERN);
dates.add(sdf.parse(String.valueOf(vo.getValue())));
}
List<EquipmentSpecificIndex> indexes = equipmentSpecificIndexMapper.getEquipmentSpeIndexByIotCodeAndTrend(iotCode);
if (0 <indexes.size()) {
List<TopographyIotIndexTrendVo> list = new ArrayList<>();
vos.forEach(iotDataVO -> {
indexes.forEach(x -> {
if (x.getNameKey().equals(iotDataVO.getKey())) {
TopographyIotIndexTrendVo vo = new TopographyIotIndexTrendVo();
vo.setId(x.getId());
vo.setName(x.getIndexName());
vo.setNameKey(x.getNameKey());
vo.setUnit(x.getIndexUnitName());
vo.setTimes(dates);
vo.setIotData(iotDataVO);
list.add(vo);
}
});
Map<Long, List<TopographyIotIndexTrendVo>> resMap = list.stream().collect(Collectors.groupingBy(x -> x.getId()));
return CommonResponseUtil.success(resMap);
}
});
List<IotIndexResVo> res = new ArrayList<>();
Long equId = 0L;
String name = "";
String nameKey = "";
String unit = "";
IotIndexResVo vo = new IotIndexResVo();
if (0 < list.size()) {
List<IotDataVO> dataVOS = new ArrayList<>();
for (TopographyIotIndexTrendVo trendVo : list) {
dataVOS.add(trendVo.getIotData());
equId = trendVo.getId();
name = trendVo.getName();
nameKey = trendVo.getNameKey();
unit = trendVo.getUnit();
}
vo.setId(equId);
vo.setName(name);
vo.setNameKey(nameKey);
vo.setUnit(unit);
vo.setTimes(dates);
vo.setIotData(dataVOS);
res.add(vo);
}
return CommonResponseUtil.success(res);
}
} else {
logger.error("注:iotCode为 (" + iotCode + ") 的装备不存在于物联系统中!");
return CommonResponseUtil.success();
}
return CommonResponseUtil.success();
}
......
package com.yeejoin.equipmanage.fegin;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.typroject.tyboot.core.restful.utils.ResponseModel;
/**
* @author DELL
*/
@FeignClient(name = "${iot.vehicle.track}", path = "iot", configuration = {FeignConfiguration.class})
public interface IotFeign {
@RequestMapping(value = "/v1/livedata/list", method = RequestMethod.GET, consumes = "application/json")
ResponseModel selectList(
@RequestHeader("appKey") String appKey,
@RequestHeader("product") String product,
@RequestHeader("token") String token,
@RequestParam(value = "timeStart") String beginDate,
@RequestParam(value = "timeEnd") String endDate,
@RequestParam(value = "productKey") String productKey,
@RequestParam(value = "deviceName") String deviceName);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment