From 5b2f578c9b3283a35aa78f33f70c3dfe692b24d8 Mon Sep 17 00:00:00 2001 From: xins Date: Mon, 25 Sep 2023 18:22:16 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8B=A5=E4=BE=9D=E5=BE=AE=E6=9C=8D=E5=8A=A11.?= =?UTF-8?q?3.5=201=E3=80=81=E7=9B=91=E6=8E=A7=E5=B9=B3=E5=8F=B0=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E4=BF=AE=E6=94=B9=202=E3=80=81tdengine=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1=EF=BC=8C=E4=BF=AE=E6=94=B9tdengine=E6=96=B0=E7=89=88?= =?UTF-8?q?=E6=9C=AClast(*)=E6=98=BE=E7=A4=BA=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tdengine/api/RemoteTdEngineService.java | 4 +- .../tdengine/api/domain/TdReturnDataVo.java | 13 ++ .../tdengine/api/domain/TdSelectDto.java | 2 + .../api/domain/TdSuperTableSelectVo.java | 3 + .../RemoteTdEngineFallbackFactory.java | 3 +- .../common/core/constant/HwDictConstants.java | 6 +- .../core/constant/TdEngineConstants.java | 1 + .../HwMonitorPlatformController.java | 50 +++--- .../business/domain/VO/DeviceControlVo.java | 20 +++ .../domain/VO/DeviceHistoryDataVo.java | 2 + .../ruoyi/business/domain/VO/HwDeviceVo.java | 42 ++--- .../business/service/IHwDeviceService.java | 9 ++ .../service/IHwMonitorPlatformService.java | 21 ++- .../service/impl/HwAlarmInfoServiceImpl.java | 17 +- .../service/impl/HwDeviceServiceImpl.java | 150 +++++++++++++----- .../impl/HwMonitorPlatformServiceImpl.java | 98 +++++++++++- .../mapper/business/HwAlarmInfoMapper.xml | 2 +- .../mapper/business/HwDeviceMapper.xml | 4 +- .../business/HwElectronicFenceMapper.xml | 36 +++++ .../controller/TdEngineController.java | 33 +--- .../ruoyi/tdengine/mapper/TdEngineMapper.java | 3 +- .../tdengine/service/ITdEngineService.java | 8 +- .../service/impl/TdEngineServiceImpl.java | 19 +-- .../mapper/tdengine/TdEngineMapper.xml | 23 ++- ruoyi-ui/src/views/business/device/index.vue | 8 +- 25 files changed, 401 insertions(+), 176 deletions(-) create mode 100644 ruoyi-api/hw-api-tdengine/src/main/java/com/ruoyi/tdengine/api/domain/TdReturnDataVo.java create mode 100644 ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/VO/DeviceControlVo.java diff --git a/ruoyi-api/hw-api-tdengine/src/main/java/com/ruoyi/tdengine/api/RemoteTdEngineService.java b/ruoyi-api/hw-api-tdengine/src/main/java/com/ruoyi/tdengine/api/RemoteTdEngineService.java index abe1207..a146d19 100644 --- a/ruoyi-api/hw-api-tdengine/src/main/java/com/ruoyi/tdengine/api/RemoteTdEngineService.java +++ b/ruoyi-api/hw-api-tdengine/src/main/java/com/ruoyi/tdengine/api/RemoteTdEngineService.java @@ -1,6 +1,5 @@ package com.ruoyi.tdengine.api; - import com.ruoyi.common.core.constant.ServiceNameConstants; import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.hw.validated.tdengine.AddTdSTableColumn; @@ -11,7 +10,6 @@ import org.springframework.cloud.openfeign.FeignClient; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestParam; import java.util.List; import java.util.Map; @@ -47,7 +45,7 @@ public interface RemoteTdEngineService { R>> getLatestDataByTags(@Validated @RequestBody TdSuperTableSelectVo tdSuperTableSelectVo); @PostMapping("/tdengine/getHistoryData") - R>> getHistoryData(@Validated @RequestBody TdHistorySelectDto tdHistorySelectDto); + R getHistoryData(@Validated @RequestBody TdHistorySelectDto tdHistorySelectDto); @PostMapping("/tdengine/getCountOfHistoryData") R getCountOfHistoryData(@Validated @RequestBody TdHistorySelectDto tdHistorySelectDto); diff --git a/ruoyi-api/hw-api-tdengine/src/main/java/com/ruoyi/tdengine/api/domain/TdReturnDataVo.java b/ruoyi-api/hw-api-tdengine/src/main/java/com/ruoyi/tdengine/api/domain/TdReturnDataVo.java new file mode 100644 index 0000000..7d2118a --- /dev/null +++ b/ruoyi-api/hw-api-tdengine/src/main/java/com/ruoyi/tdengine/api/domain/TdReturnDataVo.java @@ -0,0 +1,13 @@ +package com.ruoyi.tdengine.api.domain; + +import lombok.Data; + +import java.util.List; +import java.util.Map; + +@Data +public class TdReturnDataVo { + + public int count; + public List> dataList; +} diff --git a/ruoyi-api/hw-api-tdengine/src/main/java/com/ruoyi/tdengine/api/domain/TdSelectDto.java b/ruoyi-api/hw-api-tdengine/src/main/java/com/ruoyi/tdengine/api/domain/TdSelectDto.java index f985526..81c56e6 100644 --- a/ruoyi-api/hw-api-tdengine/src/main/java/com/ruoyi/tdengine/api/domain/TdSelectDto.java +++ b/ruoyi-api/hw-api-tdengine/src/main/java/com/ruoyi/tdengine/api/domain/TdSelectDto.java @@ -4,6 +4,7 @@ import lombok.Data; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotEmpty; +import java.util.List; /** * @Description: TDengine查询数据入参数据传输对象 @@ -29,5 +30,6 @@ public class TdSelectDto { //tags名称 private String tagsName; + private List schemaFieldValues; } diff --git a/ruoyi-api/hw-api-tdengine/src/main/java/com/ruoyi/tdengine/api/domain/TdSuperTableSelectVo.java b/ruoyi-api/hw-api-tdengine/src/main/java/com/ruoyi/tdengine/api/domain/TdSuperTableSelectVo.java index 16ad660..6922253 100644 --- a/ruoyi-api/hw-api-tdengine/src/main/java/com/ruoyi/tdengine/api/domain/TdSuperTableSelectVo.java +++ b/ruoyi-api/hw-api-tdengine/src/main/java/com/ruoyi/tdengine/api/domain/TdSuperTableSelectVo.java @@ -3,6 +3,7 @@ package com.ruoyi.tdengine.api.domain; import lombok.Data; import javax.validation.constraints.NotBlank; +import java.util.List; /** * @Description: 用于查询超级表最新数据 @@ -46,4 +47,6 @@ public class TdSuperTableSelectVo { private String deviceName; + private List schemaFieldValues; + } diff --git a/ruoyi-api/hw-api-tdengine/src/main/java/com/ruoyi/tdengine/api/factory/RemoteTdEngineFallbackFactory.java b/ruoyi-api/hw-api-tdengine/src/main/java/com/ruoyi/tdengine/api/factory/RemoteTdEngineFallbackFactory.java index dbdfa28..d17f61c 100644 --- a/ruoyi-api/hw-api-tdengine/src/main/java/com/ruoyi/tdengine/api/factory/RemoteTdEngineFallbackFactory.java +++ b/ruoyi-api/hw-api-tdengine/src/main/java/com/ruoyi/tdengine/api/factory/RemoteTdEngineFallbackFactory.java @@ -1,5 +1,6 @@ package com.ruoyi.tdengine.api.factory; +import com.alibaba.fastjson2.JSONObject; import com.ruoyi.common.core.domain.R; import com.ruoyi.tdengine.api.RemoteTdEngineService; import com.ruoyi.tdengine.api.domain.*; @@ -72,7 +73,7 @@ public class RemoteTdEngineFallbackFactory implements FallbackFactory>> getHistoryData(TdHistorySelectDto tdHistorySelectDto) { + public R getHistoryData(TdHistorySelectDto tdHistorySelectDto) { return R.fail("获取历史数据失败:" + throwable.getMessage()); } diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/HwDictConstants.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/HwDictConstants.java index 11e622d..13da9ac 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/HwDictConstants.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/HwDictConstants.java @@ -33,8 +33,12 @@ public class HwDictConstants { public static final String FUNCTION_MODE_SERVICE = "2";//设备模型功能模式服务 public static final String FUNCTION_MODE_EVENT = "3";//设备模型功能模式事件 - public static final String DEVICE_STATUS_PUBLISH = "1";//设备状态:已发布 + public static final String RW_FLAG_RW = "1";//读写 + public static final String RW_FLAG_READ = "2";//只读 + public static final String DEVICE_STATUS_PUBLISH = "1";//设备状态:已发布 + public static final String DEVICE_STATUS_TEST = "0";//设备状态:已发布 + public static final String DEVICE_STATUS_DELETE = "9";//设备状态:已发布 public static final String FENCE_TYPE_DEVICE = "1";//电子围栏规则类型,设备 public static final String FENCE_TYPE_MONITOR_UNIT = "2";//电子围栏规则类型,监控单元 public static final String FENCE_TYPE_SCENE = "3";//电子围栏规则类型,场景 diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/TdEngineConstants.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/TdEngineConstants.java index 3d9a3a3..c3ad950 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/TdEngineConstants.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/TdEngineConstants.java @@ -71,6 +71,7 @@ public class TdEngineConstants { static { DEVICE_DATA_COLUMN_MAP.put(ST_TAG_DEVICECODE, "设备编号"); DEVICE_DATA_COLUMN_MAP.put(ST_TAG_DEVICENAME, "设备名称"); + DEVICE_DATA_COLUMN_MAP.put(DEFAULT_FIRST_FIELD_NAME, "时间"); } /** diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwMonitorPlatformController.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwMonitorPlatformController.java index c6c92b8..bbcb88d 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwMonitorPlatformController.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwMonitorPlatformController.java @@ -11,6 +11,7 @@ import com.ruoyi.common.core.web.domain.AjaxResult; import com.ruoyi.common.core.web.page.TableDataInfo; import com.ruoyi.common.security.annotation.RequiresPermissions; import com.ruoyi.common.security.utils.SecurityUtils; +import com.ruoyi.tdengine.api.domain.TdReturnDataVo; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -89,7 +90,7 @@ public class HwMonitorPlatformController extends BaseController { @PutMapping("/handleAlarmInfo") @RequiresPermissions("business:monitor:alarm") - public AjaxResult handleAlarmInfo(@RequestBody HwAlarmInfo hwAlarmInfo){ + public AjaxResult handleAlarmInfo(@RequestBody HwAlarmInfo hwAlarmInfo) { hwAlarmInfo.setUpdateBy(SecurityUtils.getUsername()); return toAjax(hwAlarmInfoService.updateHwAlarmInfo(hwAlarmInfo)); } @@ -221,7 +222,7 @@ public class HwMonitorPlatformController extends BaseController { } /** - * 根据监控单元ID获取设备信息,分可控制设备和上传数据设备 + * 根据监控单元ID获取设备信息,分可控制设备和上传数据设备(设备监测页面) * * @param monitorUnitId 监控单元id */ @@ -237,6 +238,14 @@ public class HwMonitorPlatformController extends BaseController { } + @RequiresPermissions("business:monitor:deviceMonitor") + @PostMapping("/publishControlCommand") + public AjaxResult publishControlCommand(@RequestBody DeviceControlVo deviceControlVo) { + hwDeviceService.publishControlCommand(deviceControlVo); + return success(); + } + + /** * @description 根据场景ID获取设备模型列表(设备汇总页面) * @author xins @@ -258,14 +267,10 @@ public class HwMonitorPlatformController extends BaseController { @RequiresPermissions("business:monitor:deviceList") @PostMapping("/selectLatestDataByDeviceMode") public AjaxResult selectLatestDataByDeviceMode(@Validated @RequestBody DeviceLatestDataVo deviceLatestData) { - JSONObject returnObj = new JSONObject(); - List> latestDataMaps = hwMonitorPlatformService.selectLatestDataByTags(deviceLatestData); - List deviceDataColumnVos = this.getDeviceDataColumns(latestDataMaps); -// TableDataInfo tableDataInfo = getDataTable(latestDataMaps); - returnObj.put("deviceDataColumns", deviceDataColumnVos); - returnObj.put("latestData", latestDataMaps); + JSONObject returnObj = hwMonitorPlatformService.selectLatestDataByTags(deviceLatestData); return success(returnObj); } + @RequiresPermissions("business:monitor:deviceInfo") @GetMapping("/getDeviceInfo/{deviceId}") public AjaxResult getDeviceInfo(@PathVariable("deviceId") Long deviceId) { @@ -289,32 +294,19 @@ public class HwMonitorPlatformController extends BaseController { @RequiresPermissions("business:monitor:deviceInfo") @PostMapping("/getHistoryData") public AjaxResult getHistoryData(@Validated @RequestBody DeviceHistoryDataVo deviceHistoryData) { -// startPage(); JSONObject returnObj = new JSONObject(); - List> historyDataMaps = hwMonitorPlatformService.getHistoryData(deviceHistoryData); - List deviceDataColumnVos = this.getDeviceDataColumns(historyDataMaps); - TableDataInfo tableDataInfo = getDataTable(historyDataMaps); - returnObj.put("deviceDataColumns", deviceDataColumnVos); - returnObj.put("historyData", tableDataInfo); + TdReturnDataVo returnDataVo = hwMonitorPlatformService.getHistoryData(deviceHistoryData); + if (returnDataVo != null) { + List deviceDataColumnVos = hwMonitorPlatformService. + getDeviceDataColumns(deviceHistoryData.getDeviceModeId(), returnDataVo.getDataList()); + returnObj.put("deviceDataColumns", deviceDataColumnVos); + returnObj.put("historyData", returnDataVo); + } + return success(returnObj); } - private List getDeviceDataColumns(List> latestDataMaps) { - List deviceDataColumnVos = new ArrayList(); - if (latestDataMaps != null && latestDataMaps.size() > 0) { - Map latestDataMap = latestDataMaps.get(0); - for (Map.Entry entry : latestDataMap.entrySet()) { - DeviceDataColumnVo deviceDataColumnVo = new DeviceDataColumnVo(); - String columnKey = entry.getKey(); - deviceDataColumnVo.setColumnKey(columnKey); - deviceDataColumnVo.setColumnName(TdEngineConstants.DEVICE_DATA_COLUMN_MAP.get(columnKey) == null - ? columnKey : TdEngineConstants.DEVICE_DATA_COLUMN_MAP.get(columnKey)); - deviceDataColumnVos.add(deviceDataColumnVo); - } - } - return deviceDataColumnVos; - } /** * 场景选择 diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/VO/DeviceControlVo.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/VO/DeviceControlVo.java new file mode 100644 index 0000000..2bd693a --- /dev/null +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/VO/DeviceControlVo.java @@ -0,0 +1,20 @@ +package com.ruoyi.business.domain.VO; + +import lombok.Data; + +/** + * @Description: 设备控制实体对象 + * @ClassName: DeviceControlVo + * @Author : xins + * @Date :2023-09-25 14:53 + * @Version :1.0 + */ +@Data +public class DeviceControlVo { + private Long deviceId; + private Long deviceModeFunctionId; + private String deviceCode; + private String type; + private Long timestamp; + private String params;//json格式 +} diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/VO/DeviceHistoryDataVo.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/VO/DeviceHistoryDataVo.java index 2484b19..c80a895 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/VO/DeviceHistoryDataVo.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/VO/DeviceHistoryDataVo.java @@ -21,6 +21,8 @@ public class DeviceHistoryDataVo { @NotNull(message="deviceId cannot be null") private Long deviceId; + private Long deviceModeId; + private int limit; //指定从第几条之后输出(例如:limit 2,5,输出第3行到第7行的数据) diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/VO/HwDeviceVo.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/VO/HwDeviceVo.java index 644f9d3..7b0be7a 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/VO/HwDeviceVo.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/VO/HwDeviceVo.java @@ -1,37 +1,29 @@ package com.ruoyi.business.domain.VO; +import com.ruoyi.business.domain.HwDeviceModeFunction; +import lombok.Data; + import java.util.List; import java.util.Map; +/** + * @Description: 设备信息实体类 + * @ClassName: HwDeviceVo + * @Author : xins + * @Date :2023-09-25 15:26 + * @Version :1.0 + */ +@Data public class HwDeviceVo { + private Long deviceId; + + private String deviceCode; private String deviceType;//1、开关属性(控制属性),2、只有采集属性 private String deviceName; - private List> deviceDataMaps; - - - public String getDeviceType() { - return deviceType; - } - - public void setDeviceType(String deviceType) { - this.deviceType = deviceType; - } - - public String getDeviceName() { - return deviceName; - } - - public void setDeviceName(String deviceName) { - this.deviceName = deviceName; - } - - public List> getDeviceDataMaps() { - return deviceDataMaps; - } + private Long deviceModeId; + private Map deviceDataMap;//监测数据 - public void setDeviceDataMaps(List> deviceDataMaps) { - this.deviceDataMaps = deviceDataMaps; - } + private HwDeviceModeFunction deviceModeFunction; } diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwDeviceService.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwDeviceService.java index a862bc6..1446bfd 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwDeviceService.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwDeviceService.java @@ -5,6 +5,7 @@ import java.util.Map; import com.alibaba.fastjson.JSONObject; import com.ruoyi.business.domain.HwDevice; +import com.ruoyi.business.domain.VO.DeviceControlVo; import com.ruoyi.business.domain.VO.DeviceModeVo; import com.ruoyi.business.domain.VO.HwDeviceVo; import com.ruoyi.business.domain.VO.HwMonitorUnitVo; @@ -122,4 +123,12 @@ public interface IHwDeviceService * @return JSONObject */ public JSONObject getOnlineDevicesCount(Long sceneId); + + /** + * @param: deviceControlVo + * @description 下发当网关,主题带设备编号 + * @author xins + * @date 2023-09-25 14:56 + */ + public void publishControlCommand(DeviceControlVo deviceControlVo); } diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwMonitorPlatformService.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwMonitorPlatformService.java index 8f6dd6d..ad618f0 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwMonitorPlatformService.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwMonitorPlatformService.java @@ -1,7 +1,10 @@ package com.ruoyi.business.service; +import com.alibaba.fastjson.JSONObject; +import com.ruoyi.business.domain.VO.DeviceDataColumnVo; import com.ruoyi.business.domain.VO.DeviceHistoryDataVo; import com.ruoyi.business.domain.VO.DeviceLatestDataVo; +import com.ruoyi.tdengine.api.domain.TdReturnDataVo; import java.util.List; import java.util.Map; @@ -20,16 +23,26 @@ public interface IHwMonitorPlatformService { * @description 根据设备模型获取最新数据 * @author xins * @date 2023-09-16 14:49 - * @return List> + * @return JSONObject */ - public List> selectLatestDataByTags(DeviceLatestDataVo deviceLatestDataVo); + public JSONObject selectLatestDataByTags(DeviceLatestDataVo deviceLatestDataVo); /** * @param: deviceHistoryDataVo * @description 获取设备历史数据 * @author xins * @date 2023-09-16 15:14 - * @return List> + * @return TdReturnDataVo */ - public List> getHistoryData(DeviceHistoryDataVo deviceHistoryDataVo); + public TdReturnDataVo getHistoryData(DeviceHistoryDataVo deviceHistoryDataVo); + + /** + * @return List + * @param: deviceModeId + * @param: latestDataMaps + * @description + * @author xins + * @date 2023-09-25 15:40 + */ + public List getDeviceDataColumns(Long deviceModeId, List> latestDataMaps); } diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwAlarmInfoServiceImpl.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwAlarmInfoServiceImpl.java index 312d082..42f07bc 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwAlarmInfoServiceImpl.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwAlarmInfoServiceImpl.java @@ -111,19 +111,26 @@ public class HwAlarmInfoServiceImpl implements IHwAlarmInfoService { */ @Override public List selectAlarmsByAlarmType(Long sceneId) { + //根据报警类型id group获取报警信息 List list = hwAlarmInfoMapper.selectAlarmsByAlarmType(sceneId); + + //获取报警类型,并转成map, HwAlarmType queryAlarmType = new HwAlarmType(); queryAlarmType.setSceneId(sceneId); List alarmTypes = hwAlarmTypeMapper.selectHwAlarmTypeList(queryAlarmType); Map alarmTypeMap = alarmTypes.stream() .collect(Collectors.toMap(HwAlarmType::getAlarmTypeId, alarmType -> alarmType)); + + //从数据库根据alarmtype group获取的报警信息循环去设置报警类型名称 list.stream().forEach(alarmType -> { - alarmType.setAlarmTypeName(alarmTypeMap.get(alarmType.getAlarmTypeId()) == null ? "" - : alarmTypeMap.get(alarmType.getAlarmTypeId()).getAlarmTypeName()); - alarmTypeMap.remove(alarmType.getAlarmTypeId()); + if (alarmType.getAlarmTypeId() != null) { + alarmType.setAlarmTypeName(alarmTypeMap.get(alarmType.getAlarmTypeId()) == null ? "" + : alarmTypeMap.get(alarmType.getAlarmTypeId()).getAlarmTypeName()); + alarmTypeMap.remove(alarmType.getAlarmTypeId()); + } }); - + //以下是补齐其他报警类型没有报警的数据,报警数量为0. Set alarmTypeIds = alarmTypeMap.keySet(); for (Long alarmTypeId : alarmTypeIds) { HwAlarmType alarmType = alarmTypeMap.get(alarmTypeId); @@ -133,8 +140,6 @@ public class HwAlarmInfoServiceImpl implements IHwAlarmInfoService { alarmTypeVo.setAlarmCount(0); list.add(alarmTypeVo); } - return list; - } } diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwDeviceServiceImpl.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwDeviceServiceImpl.java index 8faa0a3..812f75b 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwDeviceServiceImpl.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwDeviceServiceImpl.java @@ -7,6 +7,7 @@ import com.alibaba.nacos.shaded.com.google.gson.JsonObject; import com.ruoyi.business.domain.HwDevice; import com.ruoyi.business.domain.HwDeviceModeFunction; import com.ruoyi.business.domain.HwScene; +import com.ruoyi.business.domain.VO.DeviceControlVo; import com.ruoyi.business.domain.VO.DeviceModeVo; import com.ruoyi.business.domain.VO.HwDeviceVo; import com.ruoyi.business.mapper.HwDeviceMapper; @@ -97,7 +98,11 @@ public class HwDeviceServiceImpl implements IHwDeviceService { */ @Override public List selectLinkDeviceList(Long deviceId) { - return hwDeviceMapper.selectLinkedDevices(deviceId); + List devices = hwDeviceMapper.selectLinkedDevices(deviceId); + for (HwDevice device : devices) { + device.setDevicePic("http://175.27.215.92:9665/statics/2023/09/23/6793e53d7418643c6ea9abe29be2bdce_20230923183352A001.jpg"); + } + return devices; } /** @@ -404,44 +409,94 @@ public class HwDeviceServiceImpl implements IHwDeviceService { Long sceneId = queryHwDevice.getSceneId(); String databaseName = TdEngineConstants.getDatabaseName(sceneId); + queryHwDevice.setDeviceType(HwDictConstants.DEVICE_TYPE_GATEWAY_SUB_EQUIPMENT); List hwDevices = hwDeviceMapper.selectHwDeviceList(queryHwDevice); hwDevices.forEach(hwDevice -> { - Long deviceId = hwDevice.getDeviceId(); + HwDeviceModeFunction queryDeviceModeFunction = new HwDeviceModeFunction(); + queryDeviceModeFunction.setDeviceModeId(hwDevice.getDeviceModeId()); + List deviceModeFunctions = hwDevieModeFunctionMapper.selectHwDeviceModeFunctionList(queryDeviceModeFunction); + String tableName = TdEngineConstants.getDeviceDataTableName(deviceId); TdSelectDto tdSelectDto = new TdSelectDto(); tdSelectDto.setDatabaseName(databaseName); tdSelectDto.setTableName(tableName); - List> deviceLatestDataMapList = (List>) this.remoteTdEngineService.getLatestData(tdSelectDto).getData(); - - HwDeviceModeFunction queryDeviceModeFunction = new HwDeviceModeFunction(); - queryDeviceModeFunction.setDeviceModeId(hwDevice.getDeviceModeId()); - List deviceModeFunctions = hwDevieModeFunctionMapper.selectHwDeviceModeFunctionList(queryDeviceModeFunction); - List dds = deviceModeFunctions.stream() - .filter(dmf -> dmf.getFunctionMode().equals(HwDictConstants.FUNCTION_MODE_ATTRIBUTE) - && dmf.getDataType() != null && String.valueOf(dmf.getDataType()).equals(String.valueOf(DataTypeEnums.TINYINT.getDataCode()))).collect(Collectors.toList()); + List schemaFieldValues = new ArrayList(); + List modeFunctions = new ArrayList<>(); + + deviceModeFunctions.forEach(mf -> { + if (mf.getFunctionMode().equals(HwDictConstants.FUNCTION_MODE_ATTRIBUTE)) { + TdField field = new TdField(); + field.setFieldName(mf.getFunctionIdentifier()); + schemaFieldValues.add(field); + } else if (mf.getFunctionMode().equals(HwDictConstants.FUNCTION_MODE_SERVICE)) { + modeFunctions.add(mf); + } - HwDeviceVo hwDeviceVo = new HwDeviceVo(); - hwDeviceVo.setDeviceName(hwDevice.getDeviceName()); - if (dds != null && dds.size() > 0) { - hwDeviceVo.setDeviceType(HwDictConstants.CONTROL_DEVICE); - HwDeviceModeFunction dd = dds.get(0); - List> ddValueMapList = new ArrayList>(); - Map ddValueMap = new HashMap(); + }); + tdSelectDto.setSchemaFieldValues(schemaFieldValues); + //从tdengine获取此设备的最新数据 + List> deviceLatestDataMapList = + (List>) this.remoteTdEngineService.getLatestData(tdSelectDto).getData(); + + + //获取此设备模型的功能列表 + //获取可控制设备:根据功能是属性的并且属性的数据类型是tinyint类型的(bool类型开关就是用tinyint),并且是读写的 +// List dds = deviceModeFunctions.stream() +// .filter(dmf -> dmf.getFunctionMode().equals(HwDictConstants.FUNCTION_MODE_ATTRIBUTE) +// && dmf.getDataType() != null +// && String.valueOf(dmf.getDataType()) +// .equals(String.valueOf(DataTypeEnums.TINYINT.getDataCode())) +// && dmf.getRwFlag()!=null +// && dmf.getRwFlag().equals(HwDictConstants.RW_FLAG_RW) +// ).collect(Collectors.toList()); + + //转换成map,key为标识符,value为功能名称(主要tdengine存的是标识符,用来下面转换成功能名称) + Map functionIndentifierName = deviceModeFunctions.stream().collect( + Collectors.toMap(HwDeviceModeFunction::getFunctionIdentifier, HwDeviceModeFunction::getFunctionName)); + + //获取可控制设备,根据是否有服务判断 +// List modeFunctions = deviceModeFunctions.stream() +// .filter(dmf -> dmf.getFunctionMode().equals(HwDictConstants.FUNCTION_MODE_SERVICE) +// ).collect(Collectors.toList()); + + if (modeFunctions != null && modeFunctions.size() > 0) { + modeFunctions.forEach(modeFunction -> { + HwDeviceVo hwDeviceVo = new HwDeviceVo(); + hwDeviceVo.setDeviceId(deviceId); + hwDeviceVo.setDeviceType(HwDictConstants.CONTROL_DEVICE); + hwDeviceVo.setDeviceCode(hwDevice.getDeviceCode()); + hwDeviceVo.setDeviceName(hwDevice.getDeviceName()); + hwDeviceVo.setDeviceModeFunction(modeFunction); + controlDeviceVos.add(hwDeviceVo); + }); + } + //将functionIdetifier转换成功能名称 + Map ddValueMap = new HashMap(); + if (deviceLatestDataMapList != null) { deviceLatestDataMapList.forEach(deviceLatestDataMap -> { - ddValueMap.put(dd.getFunctionIdentifier(), deviceLatestDataMap.get(dd.getFunctionIdentifier()) == null - ? 0 : deviceLatestDataMap.get(dd.getFunctionIdentifier())); - }); - ddValueMapList.add(ddValueMap); + Set functionIdentifiers = deviceLatestDataMap.keySet(); + for (String dataFunctionIdentifier : functionIdentifiers) { + if (functionIndentifierName.get(dataFunctionIdentifier) != null) { + ddValueMap.put(functionIndentifierName.get(dataFunctionIdentifier), + deviceLatestDataMap.get(dataFunctionIdentifier)); + } + } - hwDeviceVo.setDeviceDataMaps(ddValueMapList); - controlDeviceVos.add(hwDeviceVo); - } else { - hwDeviceVo.setDeviceType(HwDictConstants.ACQUISITION_DEVICE); - hwDeviceVo.setDeviceDataMaps(deviceLatestDataMapList); - acquisitionDeviceVos.add(hwDeviceVo); + }); } + //不论是否是控制型设备都显示最新数据 + HwDeviceVo hwDeviceVo = new HwDeviceVo(); + hwDeviceVo.setDeviceId(deviceId); + hwDeviceVo.setDeviceModeId(hwDevice.getDeviceModeId()); + hwDeviceVo.setDeviceCode(hwDevice.getDeviceCode()); + hwDeviceVo.setDeviceName(hwDevice.getDeviceName()); + hwDeviceVo.setDeviceType(HwDictConstants.ACQUISITION_DEVICE); + hwDeviceVo.setDeviceDataMap(ddValueMap); + //TODO:去掉下边一行 + ddValueMap.put("ii", "http://175.27.215.92:9665/statics/2023/09/23/6793e53d7418643c6ea9abe29be2bdce_20230923183352A001.jpg"); + acquisitionDeviceVos.add(hwDeviceVo); }); @@ -494,7 +549,7 @@ public class HwDeviceServiceImpl implements IHwDeviceService { jsonObject.put(String.valueOf(key), onlineDeviceCountPerDay.get(key)); } } - redisTemplate.opsForValue().set(HwDictConstants.REDIS_KEY_ONLINE_DEVICE_COUNT_INFO,jsonObject.toString()); + redisTemplate.opsForValue().set(HwDictConstants.REDIS_KEY_ONLINE_DEVICE_COUNT_INFO, jsonObject.toString()); } private Map computeDeviceCountPerDay(Long startTime, Long endTime) { @@ -562,32 +617,45 @@ public class HwDeviceServiceImpl implements IHwDeviceService { /** + * @return String * @param: sceneId * @description 获取最近几天在线设备数量 * @author xins * @date 2023-09-21 9:09 - * @return String */ @Override - public JSONObject getOnlineDevicesCount(Long sceneId){ + public JSONObject getOnlineDevicesCount(Long sceneId) { JSONObject returnObj = new JSONObject(); int onlineDevicesCount = hwDeviceMapper.getOnlineDeviceNum(sceneId); - String onlineDeviceCountJsonStr = redisTemplate.opsForValue().get(HwDictConstants.REDIS_KEY_ONLINE_DEVICE_COUNT_INFO); - JSONObject jsonObject = JSONObject.parseObject(onlineDeviceCountJsonStr); - JSONObject sortedJsonObject = new JSONObject(); - jsonObject.forEach((key,value) ->{ - String dateStrKey = DateUtils.parseDateToStr(DateUtils.MM_DD,new Date(Long.parseLong(key))); - sortedJsonObject.put(dateStrKey,value); - }); - returnObj.put("onlineDevicesTrend",sortedJsonObject); - returnObj.put("onlineDevicesCount",onlineDevicesCount); + + String onlineDeviceCountJsonStr = redisTemplate.opsForValue().get(HwDictConstants.REDIS_KEY_ONLINE_DEVICE_COUNT_INFO); + if (onlineDeviceCountJsonStr != null) { + JSONObject jsonObject = JSONObject.parseObject(onlineDeviceCountJsonStr); + + jsonObject.forEach((key, value) -> { + String dateStrKey = DateUtils.parseDateToStr(DateUtils.MM_DD, new Date(Long.parseLong(key))); + sortedJsonObject.put(dateStrKey, value); + }); + } + + returnObj.put("onlineDevicesTrend", sortedJsonObject); + returnObj.put("onlineDevicesCount", onlineDevicesCount); return returnObj; } - public void publishContrlCommand(String channel,String message){ - redisTemplate.convertAndSend(channel,message); + /** + * @param: deviceControlVo + * @description 下发当网关,主题带设备编号 + * @author xins + * @date 2023-09-25 14:56 + */ + @Override + public void publishControlCommand(DeviceControlVo deviceControlVo) { + String channel = ""; + String message = ""; + redisTemplate.convertAndSend(channel, message); } } diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwMonitorPlatformServiceImpl.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwMonitorPlatformServiceImpl.java index 6c92963..9f5e157 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwMonitorPlatformServiceImpl.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwMonitorPlatformServiceImpl.java @@ -1,20 +1,27 @@ package com.ruoyi.business.service.impl; +import com.alibaba.fastjson.JSONObject; +import com.ruoyi.business.domain.HwDeviceModeFunction; import com.ruoyi.business.domain.VO.DeviceDataColumnVo; import com.ruoyi.business.domain.VO.DeviceHistoryDataVo; import com.ruoyi.business.domain.VO.DeviceLatestDataVo; +import com.ruoyi.business.mapper.HwDeviceModeFunctionMapper; import com.ruoyi.business.service.IHwMonitorPlatformService; import com.ruoyi.common.core.constant.HwDictConstants; import com.ruoyi.common.core.constant.TdEngineConstants; import com.ruoyi.tdengine.api.RemoteTdEngineService; +import com.ruoyi.tdengine.api.domain.TdField; import com.ruoyi.tdengine.api.domain.TdHistorySelectDto; +import com.ruoyi.tdengine.api.domain.TdReturnDataVo; import com.ruoyi.tdengine.api.domain.TdSuperTableSelectVo; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.stream.Collectors; /** * @Description: 监控平台数据处理接口 @@ -28,18 +35,31 @@ public class HwMonitorPlatformServiceImpl implements IHwMonitorPlatformService { @Resource private RemoteTdEngineService remoteTdEngineService; + @Autowired + private HwDeviceModeFunctionMapper deviceModeFunctionMapper; + /** - * @return List> + * @return JSONObject * @param: deviceLatestDataVo * @description 根据设备模型获取最新数据 * @author xins * @date 2023-09-16 14:49 */ @Override - public List> selectLatestDataByTags(DeviceLatestDataVo deviceLatestDataVo) { + public JSONObject selectLatestDataByTags(DeviceLatestDataVo deviceLatestDataVo) { + JSONObject returnObj = new JSONObject(); + Long deviceModeId = deviceLatestDataVo.getDeviceModeId(); + HwDeviceModeFunction queryModeFunction = new HwDeviceModeFunction(); + queryModeFunction.setDeviceModeId(deviceModeId); + queryModeFunction.setFunctionMode(HwDictConstants.FUNCTION_MODE_ATTRIBUTE); + List deviceModeFunctions = deviceModeFunctionMapper.selectHwDeviceModeFunctionList(queryModeFunction); + Map functionIndentifierName = deviceModeFunctions.stream().collect( + Collectors.toMap(HwDeviceModeFunction::getFunctionIdentifier, HwDeviceModeFunction::getFunctionName)); + functionIndentifierName.putAll(TdEngineConstants.DEVICE_DATA_COLUMN_MAP); + TdSuperTableSelectVo tdSuperTableSelectVo = new TdSuperTableSelectVo(); String databaseName = TdEngineConstants.getDatabaseName(deviceLatestDataVo.getSceneId()); - String superTableName = TdEngineConstants.getSuperTableName(deviceLatestDataVo.getDeviceModeId()); + String superTableName = TdEngineConstants.getSuperTableName(deviceModeId); tdSuperTableSelectVo.setDatabaseName(databaseName); tdSuperTableSelectVo.setSuperTableName(superTableName); tdSuperTableSelectVo.setGroupByTagsName(TdEngineConstants.ST_TAG_DEVICECODE);//todo,换成deviceid @@ -52,20 +72,53 @@ public class HwMonitorPlatformServiceImpl implements IHwMonitorPlatformService { tdSuperTableSelectVo.setEndTime(deviceLatestDataVo.getEndTime()); tdSuperTableSelectVo.setOffset(deviceLatestDataVo.getOffset()); tdSuperTableSelectVo.setLimit(deviceLatestDataVo.getLimit()); - return this.remoteTdEngineService.getLatestDataByTags(tdSuperTableSelectVo).getData(); + List schemaFieldValues = new ArrayList(); + List modeFunctions = new ArrayList<>(); + + deviceModeFunctions.forEach(mf -> { + TdField field = new TdField(); + field.setFieldName(mf.getFunctionIdentifier()); + schemaFieldValues.add(field); + + }); + tdSuperTableSelectVo.setSchemaFieldValues(schemaFieldValues); + + List> latestDataMaps = + this.remoteTdEngineService.getLatestDataByTags(tdSuperTableSelectVo).getData(); + + + List deviceDataColumnVos = new ArrayList(); + if (latestDataMaps != null && latestDataMaps.size() > 0) { + Map latestDataMap = latestDataMaps.get(0); + for (Map.Entry entry : latestDataMap.entrySet()) { + DeviceDataColumnVo deviceDataColumnVo = new DeviceDataColumnVo(); + String columnKey = entry.getKey(); + if(!columnKey.equalsIgnoreCase(TdEngineConstants.ST_TAG_DEVICEID) + && !columnKey.equalsIgnoreCase(TdEngineConstants.ST_TAG_DEVICEMODEID)){ + deviceDataColumnVo.setColumnKey(columnKey); + deviceDataColumnVo.setColumnName(functionIndentifierName.get(columnKey) == null + ? columnKey : functionIndentifierName.get(columnKey)); + deviceDataColumnVos.add(deviceDataColumnVo); + } + } + } + + returnObj.put("deviceDataColumns", deviceDataColumnVos); + returnObj.put("latestData", latestDataMaps); + return returnObj; } /** + * @return TdReturnDataVo * @param: deviceHistoryDataVo * @description 获取设备历史数据 * @author xins * @date 2023-09-16 15:14 - * @return List> */ @Override - public List> getHistoryData(DeviceHistoryDataVo deviceHistoryDataVo) { + public TdReturnDataVo getHistoryData(DeviceHistoryDataVo deviceHistoryDataVo) { TdHistorySelectDto tdHistorySelectDto = new TdHistorySelectDto(); tdHistorySelectDto.setDatabaseName(TdEngineConstants.getDatabaseName(deviceHistoryDataVo.getSceneId())); tdHistorySelectDto.setTableName(TdEngineConstants.getDeviceDataTableName(deviceHistoryDataVo.getDeviceId())); @@ -80,7 +133,40 @@ public class HwMonitorPlatformServiceImpl implements IHwMonitorPlatformService { tdHistorySelectDto.setLimit(deviceHistoryDataVo.getLimit()); return this.remoteTdEngineService.getHistoryData(tdHistorySelectDto).getData(); + } + + + /** + * @return List + * @param: deviceModeId + * @param: latestDataMaps + * @description + * @author xins + * @date 2023-09-25 15:40 + */ + @Override + public List getDeviceDataColumns(Long deviceModeId, List> latestDataMaps) { + HwDeviceModeFunction queryModeFunction = new HwDeviceModeFunction(); + queryModeFunction.setDeviceModeId(deviceModeId); + queryModeFunction.setFunctionMode(HwDictConstants.FUNCTION_MODE_ATTRIBUTE); + List deviceModeFunctions = deviceModeFunctionMapper.selectHwDeviceModeFunctionList(queryModeFunction); + Map functionIndentifierName = deviceModeFunctions.stream().collect( + Collectors.toMap(HwDeviceModeFunction::getFunctionIdentifier, HwDeviceModeFunction::getFunctionName)); + functionIndentifierName.putAll(TdEngineConstants.DEVICE_DATA_COLUMN_MAP); + List deviceDataColumnVos = new ArrayList(); + if (latestDataMaps != null && latestDataMaps.size() > 0) { + Map latestDataMap = latestDataMaps.get(0); + for (Map.Entry entry : latestDataMap.entrySet()) { + DeviceDataColumnVo deviceDataColumnVo = new DeviceDataColumnVo(); + String columnKey = entry.getKey(); + deviceDataColumnVo.setColumnKey(columnKey); + deviceDataColumnVo.setColumnName(functionIndentifierName.get(columnKey) == null + ? columnKey : functionIndentifierName.get(columnKey)); + deviceDataColumnVos.add(deviceDataColumnVo); + } + } + return deviceDataColumnVos; } } diff --git a/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwAlarmInfoMapper.xml b/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwAlarmInfoMapper.xml index 37c15c2..a596d1b 100644 --- a/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwAlarmInfoMapper.xml +++ b/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwAlarmInfoMapper.xml @@ -170,7 +170,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - + + and device_status !='9' and device_code like concat('%', #{deviceCode}, '%') and device_name like concat('%', #{deviceName}, '%') and scene_id = #{sceneId} @@ -96,7 +97,6 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and device_mode_id = #{deviceModeId} and access_gw_protocol = #{accessGwProtocol} and active_status = #{activeStatus} - and device_status = #{deviceStatus} and active_time = #{activeTime} and device_pic = #{devicePic} and ip_address = #{ipAddress} diff --git a/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwElectronicFenceMapper.xml b/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwElectronicFenceMapper.xml index f910fc1..7324b3f 100644 --- a/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwElectronicFenceMapper.xml +++ b/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwElectronicFenceMapper.xml @@ -167,4 +167,40 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" from hw_device hd where hd.device_status=1 and (hd.device_type=2 or hd.device_type=3) and hd.scene_id = #{sceneId} + + + delete from hw_fence_target where electronic_fence_id = #{electronicFenceId} + + + + insert into hw_fence_target( electronic_fence_id, target_type, target_id) values + + ( #{item.electronicFenceId}, #{item.targetType}, #{item.targetId}) + + + + + + \ No newline at end of file diff --git a/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/controller/TdEngineController.java b/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/controller/TdEngineController.java index d0bd86b..ed6662d 100644 --- a/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/controller/TdEngineController.java +++ b/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/controller/TdEngineController.java @@ -1,5 +1,6 @@ package com.ruoyi.tdengine.controller; +import com.alibaba.fastjson.JSONObject; import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.hw.validated.tdengine.AddTdSTableColumn; import com.ruoyi.common.core.hw.validated.tdengine.InsertTdTable; @@ -332,7 +333,11 @@ public class TdEngineController { // }else {//查询聚合 // return R.ok(this.tdEngineService.getAggregateData(selectVisualDto)); // } - return R.ok(this.tdEngineService.getHistoryData(tdHistorySelectDto)); + int count = this.tdEngineService.getCountOfHistoryData(tdHistorySelectDto); + TdReturnDataVo returnDataVo = new TdReturnDataVo(); + returnDataVo.setCount(count); + returnDataVo.setDataList(this.tdEngineService.getHistoryData(tdHistorySelectDto)); + return R.ok(returnDataVo); } catch (UncategorizedSQLException e) { String message = e.getCause().getMessage(); try { @@ -347,32 +352,6 @@ public class TdEngineController { } } - /** - * @return R - * @param: tdHistorySelectDto - * @description 获取历史数据数量 - * @author xins - * @date 2023-08-29 17:29 - */ - @PostMapping("/getCountOfHistoryData") - public R getCountOfHistoryData(@Validated @RequestBody TdHistorySelectDto tdHistorySelectDto) { - try { - return R.ok(this.tdEngineService.getCountOfHistoryData(tdHistorySelectDto)); - } catch (UncategorizedSQLException e) { - String message = e.getCause().getMessage(); - try { - message = message.substring(message.lastIndexOf("invalid operation")); - } catch (Exception ex) { - } - log.error(message); - return R.fail(message); - } catch (Exception e) { - log.error(e.getMessage()); - return R.fail(e.getMessage()); - } - } - - /** * @return R * @param: tdSelectDto diff --git a/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/mapper/TdEngineMapper.java b/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/mapper/TdEngineMapper.java index 0b24b91..4cbb0b9 100644 --- a/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/mapper/TdEngineMapper.java +++ b/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/mapper/TdEngineMapper.java @@ -138,8 +138,7 @@ public interface TdEngineMapper { */ List> getHistoryData(TdHistorySelectDto tdHistorySelectDto); - Map getCountOfHistoryData(TdHistorySelectDto tdHistorySelectDto); - + int getCountOfHistoryData(TdHistorySelectDto tdHistorySelectDto); // /** // * 检查表是否存在 diff --git a/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/service/ITdEngineService.java b/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/service/ITdEngineService.java index 8bba645..f950750 100644 --- a/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/service/ITdEngineService.java +++ b/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/service/ITdEngineService.java @@ -116,12 +116,12 @@ public interface ITdEngineService { /** * @param: tdHistorySelectDto - * @description 获取历史记录的数量 + * @description 获取历史数据总数量 * @author xins - * @date 2023-08-29 16:54 - * @return Long + * @date 2023-09-25 16:20 + * @return int */ - public Long getCountOfHistoryData(TdHistorySelectDto tdHistorySelectDto) throws Exception; + public int getCountOfHistoryData(TdHistorySelectDto tdHistorySelectDto); // void initSTableFrame(String msg) throws Exception; diff --git a/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/service/impl/TdEngineServiceImpl.java b/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/service/impl/TdEngineServiceImpl.java index a68de48..3e72fcb 100644 --- a/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/service/impl/TdEngineServiceImpl.java +++ b/ruoyi-modules/hw-tdengine/src/main/java/com/ruoyi/tdengine/service/impl/TdEngineServiceImpl.java @@ -210,26 +210,22 @@ public class TdEngineServiceImpl implements ITdEngineService { // } List> historyDataMaps = this.tdEngineMapper.getHistoryData(tdHistorySelectDto); + return historyDataMaps; } - /** - * @return Long * @param: tdHistorySelectDto - * @description 获取历史记录的数量 + * @description 获取历史数据总数量 * @author xins - * @date 2023-08-29 16:54 + * @date 2023-09-25 16:20 + * @return int */ @Override - public Long getCountOfHistoryData(TdHistorySelectDto tdHistorySelectDto) throws Exception { - Map countMap = this.tdEngineMapper.getCountOfHistoryData(tdHistorySelectDto); - if (countMap == null) { - return 0L; - } - return countMap.get("dataCount"); + public int getCountOfHistoryData(TdHistorySelectDto tdHistorySelectDto){ + int count = this.tdEngineMapper.getCountOfHistoryData(tdHistorySelectDto); + return count; } - // // /** // * 检查数据库表是否存在 @@ -303,5 +299,4 @@ public class TdEngineServiceImpl implements ITdEngineService { // return maps; // } - } diff --git a/ruoyi-modules/hw-tdengine/src/main/resources/mapper/tdengine/TdEngineMapper.xml b/ruoyi-modules/hw-tdengine/src/main/resources/mapper/tdengine/TdEngineMapper.xml index 886679b..72628ab 100644 --- a/ruoyi-modules/hw-tdengine/src/main/resources/mapper/tdengine/TdEngineMapper.xml +++ b/ruoyi-modules/hw-tdengine/src/main/resources/mapper/tdengine/TdEngineMapper.xml @@ -212,7 +212,10 @@ @@ -220,7 +223,9 @@ 也可以用select last_row()--> - - + SELECT count(*) FROM #{databaseName}.#{tableName} - ${firstFieldName} BETWEEN #{startTime} AND #{endTime} + startTime!= 0 "> + and ${firstFieldName} >= #{startTime} + + + and ${firstFieldName} <= #{endTime} diff --git a/ruoyi-ui/src/views/business/device/index.vue b/ruoyi-ui/src/views/business/device/index.vue index d9ef410..3a28373 100644 --- a/ruoyi-ui/src/views/business/device/index.vue +++ b/ruoyi-ui/src/views/business/device/index.vue @@ -79,7 +79,7 @@ - + @@ -159,11 +159,11 @@ - +