Przeglądaj źródła

运行监控判断表是否存在

lipenghui 2 tygodni temu
rodzic
commit
b10b48d31f

+ 14 - 6
yudao-module-pms/yudao-module-pms-biz/src/main/java/cn/iocoder/yudao/module/pms/controller/admin/stat/IotStaticController.java

@@ -112,6 +112,8 @@ public class IotStaticController {
     private IotOpeationFillMapper iotOpeationFillMapper;
     @Autowired
     private IotDeviceRunLogMapper iotDeviceRunLogMapper;
+    @Autowired
+    private TDDeviceMapper deviceMapper;
 
     @GetMapping("/main/day")
     public CommonResult<Map<String, Object>> getMaintainDay() {
@@ -384,12 +386,18 @@ public class IotStaticController {
         }
         Timestamp start1 = generateTimestamp(beginTime);
         Timestamp end1 = generateTimestamp(endTime);
-        List<DeviceVO> deviceVOS = tdDeviceMapper.selectAllBtTimeAndIdentifier(deviceName.toLowerCase(), identifier, start1, end1);
-        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()));
+        Integer i = deviceMapper.tableIfExist(deviceName.toLowerCase());
+        if (i==1) {
+            List<DeviceVO> deviceVOS = tdDeviceMapper.selectAllBtTimeAndIdentifier(deviceName.toLowerCase(), identifier, start1, end1);
+            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()));
+        } else {
+            List<DeviceVO> deviceVOS = new ArrayList<>();
+            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());}