|
@@ -11,6 +11,7 @@ import cn.iocoder.yudao.module.pms.controller.admin.inspect.order.vo.IotInspectO
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.iotmainworkorder.vo.IotMainWorkOrderPageReqVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.maintain.vo.IotMaintainPageReqVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.stat.vo.OrderVo;
|
|
|
+import cn.iocoder.yudao.module.pms.controller.admin.vo.DeviceVO;
|
|
|
import cn.iocoder.yudao.module.pms.controller.admin.vo.IotDevicePageReqVO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.IotDeviceDO;
|
|
|
import cn.iocoder.yudao.module.pms.dal.dataobject.IotProductClassifyDO;
|
|
@@ -46,6 +47,7 @@ import com.google.common.collect.ImmutableMap;
|
|
|
import com.google.common.collect.Lists;
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
import lombok.Data;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
@@ -55,6 +57,7 @@ import org.springframework.web.client.RestTemplate;
|
|
|
import javax.annotation.Resource;
|
|
|
import javax.annotation.security.PermitAll;
|
|
|
import javax.validation.Valid;
|
|
|
+import java.sql.Timestamp;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
@@ -354,37 +357,37 @@ public class IotStaticController {
|
|
|
@Resource
|
|
|
private TDDeviceMapper tdDeviceMapper;
|
|
|
@GetMapping("/td/chart/{deviceName}/{identifier}")
|
|
|
- public CommonResult<JSONArray> getTdChart(@PathVariable("deviceName") String deviceName, @PathVariable("identifier") String identifier, @RequestParam("beginTime") String beginTime, @RequestParam("endTime") String endTime) {
|
|
|
-// if (StringUtils.isBlank(identifier)) {
|
|
|
-// return null;
|
|
|
-// }
|
|
|
-// long current = System.currentTimeMillis();
|
|
|
-// Timestamp start = new Timestamp(current - 1440 * 60 * 1000);
|
|
|
-// Timestamp end = new Timestamp(current);
|
|
|
-// List<DeviceVO> deviceVOS = tdDeviceMapper.selectAllBtTimeAndIdentifier(deviceName.toLowerCase(), identifier, start, end, 1);
|
|
|
-// deviceVOS.forEach(deviceVO->{
|
|
|
-// deviceVO.setTimestamp(deviceVO.getTs().getTime());
|
|
|
-// deviceVO.setValue(Double.valueOf(deviceVO.getLogValue()));
|
|
|
-// });
|
|
|
-// return CommonResult.success(deviceVOS);
|
|
|
- DeviceHistoryParam deviceHistoryParam = new DeviceHistoryParam();
|
|
|
- List<IotDeviceDO> iotDeviceDOS = iotDeviceMapper.selectByCodeIn(ImmutableList.of(deviceName));
|
|
|
- if (CollUtil.isEmpty(iotDeviceDOS)) {return CommonResult.success(new JSONArray());}
|
|
|
- deviceHistoryParam.setDeviceId(iotDeviceDOS.get(0).getYfDeviceId());
|
|
|
- deviceHistoryParam.setSerialNumber(deviceName);
|
|
|
- List<DeviceHistoryParam.IdentifierVO> list = Lists.newArrayList();
|
|
|
- DeviceHistoryParam.IdentifierVO identifierVO = new DeviceHistoryParam.IdentifierVO();
|
|
|
- identifierVO.setIdentifier(identifier);
|
|
|
- identifierVO.setType(1);
|
|
|
- list.add(identifierVO);
|
|
|
- deviceHistoryParam.setIdentifierList(list);
|
|
|
- deviceHistoryParam.setBeginTime(beginTime);
|
|
|
- deviceHistoryParam.setEndTime(endTime);
|
|
|
-
|
|
|
- JSONObject jsonObject = restTemplate.postForObject(yanfanUrl + "/prod-api/data/center/deviceHistory", deviceHistoryParam, JSONObject.class);
|
|
|
- JSONArray object = JSON.parseArray(JSON.toJSONString(jsonObject.get("data")));
|
|
|
-
|
|
|
- return CommonResult.success(object);
|
|
|
+ public CommonResult<List<DeviceVO>> getTdChart(@PathVariable("deviceName") String deviceName, @PathVariable("identifier") String identifier, @RequestParam("beginTime") String beginTime, @RequestParam("endTime") String endTime) {
|
|
|
+ if (StringUtils.isBlank(identifier)) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ long current = System.currentTimeMillis();
|
|
|
+ Timestamp start = new Timestamp(current - 1440 * 60 * 1000);
|
|
|
+ Timestamp end = new Timestamp(current);
|
|
|
+ List<DeviceVO> deviceVOS = tdDeviceMapper.selectAllBtTimeAndIdentifier(deviceName.toLowerCase(), identifier, start, end);
|
|
|
+ deviceVOS.forEach(deviceVO->{
|
|
|
+ deviceVO.setTimestamp(deviceVO.getTs().getTime());
|
|
|
+ deviceVO.setValue(Double.valueOf(deviceVO.getLogValue()));
|
|
|
+ });
|
|
|
+ return CommonResult.success(deviceVOS.stream().sorted(Comparator.comparing(DeviceVO::getTimestamp).reversed()).collect(Collectors.toList()));
|
|
|
+// DeviceHistoryParam deviceHistoryParam = new DeviceHistoryParam();
|
|
|
+// List<IotDeviceDO> iotDeviceDOS = iotDeviceMapper.selectByCodeIn(ImmutableList.of(deviceName));
|
|
|
+// if (CollUtil.isEmpty(iotDeviceDOS)) {return CommonResult.success(new JSONArray());}
|
|
|
+// deviceHistoryParam.setDeviceId(iotDeviceDOS.get(0).getYfDeviceId());
|
|
|
+// deviceHistoryParam.setSerialNumber(deviceName);
|
|
|
+// List<DeviceHistoryParam.IdentifierVO> list = Lists.newArrayList();
|
|
|
+// DeviceHistoryParam.IdentifierVO identifierVO = new DeviceHistoryParam.IdentifierVO();
|
|
|
+// identifierVO.setIdentifier(identifier);
|
|
|
+// identifierVO.setType(1);
|
|
|
+// list.add(identifierVO);
|
|
|
+// deviceHistoryParam.setIdentifierList(list);
|
|
|
+// deviceHistoryParam.setBeginTime(beginTime);
|
|
|
+// deviceHistoryParam.setEndTime(endTime);
|
|
|
+//
|
|
|
+// JSONObject jsonObject = restTemplate.postForObject(yanfanUrl + "/prod-api/data/center/deviceHistory", deviceHistoryParam, JSONObject.class);
|
|
|
+// JSONArray object = JSON.parseArray(JSON.toJSONString(jsonObject.get("data")));
|
|
|
+
|
|
|
+// return CommonResult.success(object);
|
|
|
|
|
|
}
|
|
|
|