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 a146d19..0c3e55d 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,5 +1,6 @@ package com.ruoyi.tdengine.api; +import com.ruoyi.common.core.constant.SecurityConstants; import com.ruoyi.common.core.constant.ServiceNameConstants; import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.hw.validated.tdengine.AddTdSTableColumn; @@ -10,6 +11,7 @@ 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.RequestHeader; import java.util.List; import java.util.Map; @@ -18,41 +20,44 @@ import java.util.Map; public interface RemoteTdEngineService { @PostMapping("/tdengine/createDatabase") - R createDataBase(@RequestBody String databaseName); + R createDataBase(@RequestBody String databaseName, @RequestHeader(SecurityConstants.FROM_SOURCE) String source); @PostMapping("/tdengine/createSuperTable") - R createSuperTable(@Validated @RequestBody TdSuperTableVo tdSuperTableVo); + R createSuperTable(@Validated @RequestBody TdSuperTableVo tdSuperTableVo, @RequestHeader(SecurityConstants.FROM_SOURCE) String source); @PostMapping("/tdengine/createTable") - R createTable(@Validated @RequestBody TdTableVo tdTableVo); + R createTable(@Validated @RequestBody TdTableVo tdTableVo, @RequestHeader(SecurityConstants.FROM_SOURCE) String source); @PostMapping("/tdengine/addSuperTableColumn") - R addSuperTableColumn(@Validated(AddTdSTableColumn.class) @RequestBody TdSuperTableVo tdSuperTableVo); + R addSuperTableColumn(@Validated(AddTdSTableColumn.class) @RequestBody TdSuperTableVo tdSuperTableVo, @RequestHeader(SecurityConstants.FROM_SOURCE) String source); + + @PostMapping("/tdengine/modifySuperTableColumn") + R modifySuperTableColumn(@Validated(AddTdSTableColumn.class) @RequestBody TdSuperTableVo tdSuperTableVo, @RequestHeader(SecurityConstants.FROM_SOURCE) String source); @PostMapping("/tdengine/dropSuperTableColumn") - R dropColumnForSuperTable(@Validated(AddTdSTableColumn.class) @RequestBody TdSuperTableVo tdSuperTableVo); + R dropColumnForSuperTable(@Validated(AddTdSTableColumn.class) @RequestBody TdSuperTableVo tdSuperTableVo, @RequestHeader(SecurityConstants.FROM_SOURCE) String source); @PostMapping("/tdengine/alterTableTag") - public R alterTableTag(@Validated @RequestBody AlterTagVo alterTagVo); + public R alterTableTag(@Validated @RequestBody AlterTagVo alterTagVo, @RequestHeader(SecurityConstants.FROM_SOURCE) String source); @PostMapping("/tdengine/insertTable") - R insertTable(@Validated(InsertTdTable.class) @RequestBody TdTableVo tdTableVo); + R insertTable(@Validated(InsertTdTable.class) @RequestBody TdTableVo tdTableVo, @RequestHeader(SecurityConstants.FROM_SOURCE) String source); @PostMapping("/tdengine/getLatestData") - R getLatestData(@Validated @RequestBody TdSelectDto tdSelectDto); + R getLatestData(@Validated @RequestBody TdSelectDto tdSelectDto, @RequestHeader(SecurityConstants.FROM_SOURCE) String source); @PostMapping("/tdengine/getLatestDataByTags") - R>> getLatestDataByTags(@Validated @RequestBody TdSuperTableSelectVo tdSuperTableSelectVo); + R>> getLatestDataByTags(@Validated @RequestBody TdSuperTableSelectVo tdSuperTableSelectVo, @RequestHeader(SecurityConstants.FROM_SOURCE) String source); @PostMapping("/tdengine/getHistoryData") - R getHistoryData(@Validated @RequestBody TdHistorySelectDto tdHistorySelectDto); + R getHistoryData(@Validated @RequestBody TdHistorySelectDto tdHistorySelectDto, @RequestHeader(SecurityConstants.FROM_SOURCE) String source); @PostMapping("/tdengine/getCountOfHistoryData") - R getCountOfHistoryData(@Validated @RequestBody TdHistorySelectDto tdHistorySelectDto); + R getCountOfHistoryData(@Validated @RequestBody TdHistorySelectDto tdHistorySelectDto, @RequestHeader(SecurityConstants.FROM_SOURCE) String source); @PostMapping("/tdengine/getOnlineDevicesGroupByDay") - R getOnlineDevicesGroupByDay(@Validated @RequestBody DeviceStatus queryDeviceStatus); + R getOnlineDevicesGroupByDay(@Validated @RequestBody DeviceStatus queryDeviceStatus, @RequestHeader(SecurityConstants.FROM_SOURCE) String source); @PostMapping("/tdengine/getLastOnlineDevices") - R getLastOnlineDevices(@Validated @RequestBody DeviceStatus queryDeviceStatus); + R getLastOnlineDevices(@Validated @RequestBody DeviceStatus queryDeviceStatus, @RequestHeader(SecurityConstants.FROM_SOURCE) String source); } 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 d17f61c..f18c87f 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 @@ -28,67 +28,72 @@ public class RemoteTdEngineFallbackFactory implements FallbackFactory createDataBase(String databaseName) { + public R createDataBase(String databaseName, String source) { return R.fail("创建数据库失败:" + throwable.getMessage()); } @Override - public R createSuperTable(TdSuperTableVo tdSuperTableVo) { + public R createSuperTable(TdSuperTableVo tdSuperTableVo, String source) { return R.fail("创建超级表失败:" + throwable.getMessage()); } @Override - public R createTable(TdTableVo tdTableVo) { + public R createTable(TdTableVo tdTableVo, String source) { return R.fail("创建子表失败:" + throwable.getMessage()); } @Override - public R addSuperTableColumn(TdSuperTableVo tdSuperTableVo) { + public R addSuperTableColumn(TdSuperTableVo tdSuperTableVo, String source) { return R.fail("添加超级表Column失败:" + throwable.getMessage()); } @Override - public R dropColumnForSuperTable(TdSuperTableVo tdSuperTableVo) { + public R modifySuperTableColumn(TdSuperTableVo tdSuperTableVo, String source) { + return R.fail("修改超级表Column失败:" + throwable.getMessage()); + } + + @Override + public R dropColumnForSuperTable(TdSuperTableVo tdSuperTableVo, String source) { return R.fail("删除超级表Column失败:" + throwable.getMessage()); } @Override - public R alterTableTag(AlterTagVo alterTagVo) { + public R alterTableTag(AlterTagVo alterTagVo, String source) { return R.fail("修改子表tag值失败:" + throwable.getMessage()); } @Override - public R insertTable(TdTableVo tdTableVo) { + public R insertTable(TdTableVo tdTableVo, String source) { return R.fail("插入数据失败:" + throwable.getMessage()); } @Override - public R getLatestData(TdSelectDto tdSelectDto) { + public R getLatestData(TdSelectDto tdSelectDto, String source) { return R.fail("获取子表最新数据失败:" + throwable.getMessage()); } @Override - public R>> getLatestDataByTags(TdSuperTableSelectVo tdSuperTableSelectVo) { + public R>> getLatestDataByTags(TdSuperTableSelectVo tdSuperTableSelectVo, String source) { return R.fail("根据tags获取超级表最新数据失败:" + throwable.getMessage()); } @Override - public R getHistoryData(TdHistorySelectDto tdHistorySelectDto) { + public R getHistoryData(TdHistorySelectDto tdHistorySelectDto, String source) { return R.fail("获取历史数据失败:" + throwable.getMessage()); } @Override - public R getCountOfHistoryData(TdHistorySelectDto tdHistorySelectDto) { + public R getCountOfHistoryData(TdHistorySelectDto tdHistorySelectDto, String source) { return R.fail("获取历史数据数量失败:" + throwable.getMessage()); } @Override - public R getOnlineDevicesGroupByDay(DeviceStatus queryDeviceStatus) { + public R getOnlineDevicesGroupByDay(DeviceStatus queryDeviceStatus, String source) { return R.fail("获取设备状态失败:" + throwable.getMessage()); } @Override - public R getLastOnlineDevices(DeviceStatus queryDeviceStatus) { + public R getLastOnlineDevices(DeviceStatus queryDeviceStatus, String source) { return R.fail("获取最近设备状态失败:" + throwable.getMessage()); } 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 ee94018..1e853c7 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 @@ -23,7 +23,7 @@ public class TdEngineConstants { public static final String PAYLOAD_DEVICE_CODE = "uid";//协议上传设备编号的key - public static final String DEFAULT_DB_NAME_PREFIX = "db_scene_";//数据库名称前缀 +// public static final String DEFAULT_DB_NAME_PREFIX = "db_scene_";//数据库名称前缀 public static final String DEFAULT_SUPER_TABLE_NAME_PREFIX = "st_devicemode_";//超级表名称前缀 public static final String DEFAULT_TABLE_NAME_PREFIX = "t_device_";//数据表名称前缀 @@ -85,8 +85,8 @@ public class TdEngineConstants { * @author xins * @date 2023-09-05 9:42 */ - public static String getDatabaseName(Long sceneId) { - return DEFAULT_DB_NAME_PREFIX + sceneId; + public static String getDatabaseName() { + return PLATFORM_DB_NAME; } /** diff --git a/ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/enums/BusinessType.java b/ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/enums/BusinessType.java index 12fc1d4..8212b25 100644 --- a/ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/enums/BusinessType.java +++ b/ruoyi-common/ruoyi-common-log/src/main/java/com/ruoyi/common/log/enums/BusinessType.java @@ -65,5 +65,10 @@ public enum BusinessType /** * 下发控制指令 */ - CONTROL + CONTROL, + + /** + * 重建表 + */ + REBUILD } diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwDeviceController.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwDeviceController.java index afa6bc0..ceac203 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwDeviceController.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwDeviceController.java @@ -195,4 +195,12 @@ public class HwDeviceController extends BaseController { public void computeOnlineDevicecCount(@PathVariable("days") int days) { hwDeviceService.computeOnlineDevicecCount(days); } + + @RequiresPermissions("business:device:rebuild") + @Log(title = "设备信息", businessType = BusinessType.REBUILD) + @GetMapping("/rebuildTdTables") + public void rebuildTdTables() { + hwDeviceService.rebuildTdTables(); + } + } diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwDeviceModeController.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwDeviceModeController.java index 00be3c7..d3477fc 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwDeviceModeController.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwDeviceModeController.java @@ -137,4 +137,11 @@ public class HwDeviceModeController extends BaseController { return success(hwSceneService.selectHwSceneList4Select(scene)); } + + @RequiresPermissions("business:deviceMode:rebuild") + @Log(title = "设备模型", businessType = BusinessType.REBUILD) + @GetMapping("/rebuildTdSuperTables") + public void rebuildTdSuperTables() { + hwDeviceModeService.rebuildTdSuperTables(); + } } 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 ff282b8..5aeb495 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 @@ -191,22 +191,6 @@ public class HwMonitorPlatformController extends BaseController { return success(hwMonitorUnitService.selectMonitorTreeList(queryMonitorUnit)); } -// /** -// * -// * 选择场景 -// * @param sceneModeId 场景id -// * @return -// */ -// -// @PostMapping("/selectHwSceneBySceneModeId") -// public TableDataInfo selectHwSceneBySceneModeId(Long sceneModeId){ -// List hwScenes = hwSceneService.selectHwSceneBySceneModeId(sceneModeId); -// return getDataTable(hwScenes); -// } - - // - - /** * 获取监控单元详细信息 */ 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 7b0be7a..39f4e54 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 @@ -23,6 +23,8 @@ public class HwDeviceVo { private String deviceName; private Long deviceModeId; + private String devicePic; + private Map deviceDataMap;//监测数据 private HwDeviceModeFunction deviceModeFunction; diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwDeviceModeService.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwDeviceModeService.java index 4e48328..0d60637 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwDeviceModeService.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwDeviceModeService.java @@ -117,4 +117,12 @@ public interface IHwDeviceModeService * @return List */ public List selectHwDeviceModeFunctionList(HwDeviceModeFunction hwDeviceModeFunction); + + /**重建所有设备模型的超级表 + * @description + * @author xins + * @date 2023-10-10 20:03 + + */ + public void rebuildTdSuperTables(); } 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 af125dd..3525ce1 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 @@ -162,4 +162,11 @@ public interface IHwDeviceService * @return DevicesInfoVo */ public DevicesInfoVo getDevicesInfoByMonitorUnitId(Long monitorUnitId); + + /** + * @description 重建tdengine所有设备表 + * @author xins + * @date 2023-10-10 20:05 + */ + public void rebuildTdTables(); } diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwDeviceModeServiceImpl.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwDeviceModeServiceImpl.java index 73e7b80..e887f27 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwDeviceModeServiceImpl.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwDeviceModeServiceImpl.java @@ -10,6 +10,7 @@ import com.ruoyi.business.mapper.HwDeviceModeMapper; import com.ruoyi.business.service.IHwDeviceModeService; import com.ruoyi.common.core.constant.Constants; import com.ruoyi.common.core.constant.HwDictConstants; +import com.ruoyi.common.core.constant.SecurityConstants; import com.ruoyi.common.core.constant.TdEngineConstants; import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.enums.DataTypeEnums; @@ -257,23 +258,9 @@ public class HwDeviceModeServiceImpl implements IHwDeviceModeService { @Override @Transactional public int updateHwDeviceModeFunction(HwDeviceModeFunction hwDeviceModeFunction) { - //查询是否有已发布的设备关联此设备模型 - HwDevice queryHwDevice = new HwDevice(); - queryHwDevice.setDeviceModeId(hwDeviceModeFunction.getDeviceModeId()); - queryHwDevice.setDeviceStatus(HwDictConstants.DEVICE_STATUS_PUBLISH); - List hwDevices = hwDeviceMapper.selectHwDeviceList(queryHwDevice); - if (hwDevices.size() > 0) { - throw new ServiceException("此设备模型已存在设备,不能修改"); - } - //校验有没有重复标识符 checkDuplicateIdentifiers(hwDeviceModeFunction); - hwDeviceModeMapper.deleteHwDeviceModeParameterByModeFunctionId(hwDeviceModeFunction.getModeFunctionId()); - List hwDeviceModeFunctions = new ArrayList<>(); - hwDeviceModeFunctions.add(hwDeviceModeFunction); - batchInsertHwDeviceModeParameters(hwDeviceModeFunctions); - //与数据库中的数据判断标识符有没有修改,如果修改则在tdengine超级表删除老的字段,增加修改的字段 String functionMode = hwDeviceModeFunction.getFunctionMode(); if (functionMode.equals(HwDictConstants.FUNCTION_MODE_ATTRIBUTE)) { @@ -284,14 +271,28 @@ public class HwDeviceModeServiceImpl implements IHwDeviceModeService { String functionIdentifier = hwDeviceModeFunction.getFunctionIdentifier(); Long dbDataType = dbHwDeviceModeFunction.getDataType(); Long dataType = hwDeviceModeFunction.getDataType(); - //标识符或数据类型变化时需要先删除超级表column,再增加新的column + //标识符或数据类型变化时需要先删除超级表column,再增加新的column,删除的column数据将会清空(有事务问题,暂时不支持) if (!dbFunctionIdentifier.equalsIgnoreCase(functionIdentifier) || !dbDataType.equals(dataType)) { - this.dropTdSuperTableColumn(dbHwDeviceModeFunction); - this.addTdSuperTableColumn(hwDeviceModeFunction); - }else{ - //todo:修改tdengine字符串长度 +// this.dropTdSuperTableColumn(dbHwDeviceModeFunction); +// this.addTdSuperTableColumn(hwDeviceModeFunction); + throw new RuntimeException("标识符和数据类型不支持修改,可删除再新建"); + } else { + if (String.valueOf(dataType).equals(String.valueOf(DataTypeEnums.NCHAR.getDataCode()))) { + int dbDataDefinition = Integer.parseInt(dbHwDeviceModeFunction.getDataDefinition()); + int dataDefinition = Integer.parseInt(hwDeviceModeFunction.getDataDefinition()); + if (dbDataDefinition > dataDefinition) { + throw new ServiceException("数据长度只能改大"); + } else if (dbDataDefinition < dataDefinition) { + this.modifyTdSuperTableColumn(hwDeviceModeFunction); + } + } } + } else { + hwDeviceModeMapper.deleteHwDeviceModeParameterByModeFunctionId(hwDeviceModeFunction.getModeFunctionId()); + List hwDeviceModeFunctions = new ArrayList<>(); + hwDeviceModeFunctions.add(hwDeviceModeFunction); + batchInsertHwDeviceModeParameters(hwDeviceModeFunctions); } return hwDeviceModeMapper.updateHwDeviceModeFunction(hwDeviceModeFunction); @@ -307,6 +308,15 @@ public class HwDeviceModeServiceImpl implements IHwDeviceModeService { @Transactional public int deleteHwDeviceModeFunctionByModeFunctionId(Long modeFunctionId) { HwDeviceModeFunction hwDeviceModeFunction = hwDeviceModeFunctionMapper.selectHwDeviceModeFunctionByModeFunctionId(modeFunctionId); + //查询是否有已发布的设备关联此设备模型 + HwDevice queryHwDevice = new HwDevice(); + queryHwDevice.setDeviceModeId(hwDeviceModeFunction.getDeviceModeId()); + queryHwDevice.setDeviceStatus(HwDictConstants.DEVICE_STATUS_PUBLISH); + List hwDevices = hwDeviceMapper.selectHwDeviceList(queryHwDevice); + if (hwDevices.size() > 0) { + throw new ServiceException("此设备模型已存在已发布状态的设备,不能删除"); + } + hwDeviceModeMapper.deleteHwDeviceModeParameterByModeFunctionId(modeFunctionId); int rows = hwDeviceModeMapper.deleteHwDeviceModeFunctionByModeFunctionId(modeFunctionId); this.dropTdSuperTableColumn(hwDeviceModeFunction); @@ -342,16 +352,37 @@ public class HwDeviceModeServiceImpl implements IHwDeviceModeService { } /** + * @return List * @param: hwDeviceModeFunction * @description 获取设备模型 * @author xins * @date 2023-10-10 11:19 - * @return List */ @Override public List selectHwDeviceModeFunctionList(HwDeviceModeFunction hwDeviceModeFunction) { return hwDeviceModeFunctionMapper.selectHwDeviceModeFunctionList(hwDeviceModeFunction); } + + /** + * 重建所有设备模型的超级表 + * + * @description + * @author xins + * @date 2023-10-10 20:03 + */ + @Override + public void rebuildTdSuperTables() { + HwDeviceMode queryDeviceMode = new HwDeviceMode(); + List deviceModes = hwDeviceModeMapper.selectHwDeviceModeList(queryDeviceMode); + deviceModes.forEach(deviceMode -> { + HwDeviceModeFunction hwDeviceModeFunction = new HwDeviceModeFunction(); + hwDeviceModeFunction.setDeviceModeId(deviceMode.getDeviceModeId()); + List functions = hwDeviceModeFunctionMapper.selectHwDeviceModeFunctionList(hwDeviceModeFunction); + deviceMode.setHwDeviceModeFunctionList(functions); + this.createTdSuperTable(deviceMode); + }); + } + /** * @param: hwDeviceModeFunction * @description 在编辑设备模型添加功能或者编辑功能时判断属性值 @@ -394,8 +425,7 @@ public class HwDeviceModeServiceImpl implements IHwDeviceModeService { private void createTdSuperTable(HwDeviceMode hwDeviceMode) { TdSuperTableVo tdSuperTableVo = new TdSuperTableVo(); - Long sceneId = hwDeviceMode.getSceneId(); - String dbName = TdEngineConstants.DEFAULT_DB_NAME_PREFIX + sceneId; + String dbName = TdEngineConstants.getDatabaseName(); String superTableName = TdEngineConstants.DEFAULT_SUPER_TABLE_NAME_PREFIX + hwDeviceMode.getDeviceModeId(); List tagFields = new ArrayList(); @@ -451,18 +481,44 @@ public class HwDeviceModeServiceImpl implements IHwDeviceModeService { tdSuperTableVo.setSchemaFields(schemaFields); tdSuperTableVo.setTagsFields(tagFields); - R tdReturnMsg = this.remoteTdEngineService.createSuperTable(tdSuperTableVo); - if(tdReturnMsg.getCode() != Constants.SUCCESS){//抛出异常,回滚事务 + R tdReturnMsg = this.remoteTdEngineService.createSuperTable(tdSuperTableVo, SecurityConstants.INNER); + if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务 throw new RuntimeException(tdReturnMsg.getMsg()); } } + private void modifyTdSuperTableColumn(HwDeviceModeFunction hwDeviceModeFunction) { + String functionMode = hwDeviceModeFunction.getFunctionMode(); + if (functionMode.equals(HwDictConstants.FUNCTION_MODE_ATTRIBUTE)) { + Long deviceModeId = hwDeviceModeFunction.getDeviceModeId(); + String dbName = TdEngineConstants.getDatabaseName(); + String superTableName = TdEngineConstants.DEFAULT_SUPER_TABLE_NAME_PREFIX + deviceModeId; + TdSuperTableVo tdSuperTableVo = new TdSuperTableVo(); + TdField schemaField = new TdField(); + String functionIdentifierTransfer = TdEngineConstants.TDENGINE_KEY_TRANSFER_MAP.get(hwDeviceModeFunction.getFunctionIdentifier()); + String functionIdentifier = functionIdentifierTransfer == null ? hwDeviceModeFunction.getFunctionIdentifier() : functionIdentifierTransfer; + schemaField.setFieldName(functionIdentifier); + Long dataType = hwDeviceModeFunction.getDataType(); + schemaField.setDataTypeCode(dataType.intValue()); + //一个integer类型,一个long类型,需要转换为string类型比较 + if (String.valueOf(dataType).equals(String.valueOf(DataTypeEnums.NCHAR.getDataCode()))) { + schemaField.setSize(Integer.valueOf(hwDeviceModeFunction.getDataDefinition())); + } + tdSuperTableVo.setDatabaseName(dbName); + tdSuperTableVo.setSuperTableName(superTableName); + tdSuperTableVo.setField(schemaField); + R tdReturnMsg = this.remoteTdEngineService.modifySuperTableColumn(tdSuperTableVo, SecurityConstants.INNER); + if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务 + throw new RuntimeException(tdReturnMsg.getMsg()); + } + } + } + private void addTdSuperTableColumn(HwDeviceModeFunction hwDeviceModeFunction) { String functionMode = hwDeviceModeFunction.getFunctionMode(); if (functionMode.equals(HwDictConstants.FUNCTION_MODE_ATTRIBUTE)) { Long deviceModeId = hwDeviceModeFunction.getDeviceModeId(); - HwDeviceMode hwDeviceMode = hwDeviceModeMapper.selectHwDeviceModeByDeviceModeId(deviceModeId); - String dbName = TdEngineConstants.DEFAULT_DB_NAME_PREFIX + hwDeviceMode.getSceneId(); + String dbName = TdEngineConstants.getDatabaseName(); String superTableName = TdEngineConstants.DEFAULT_SUPER_TABLE_NAME_PREFIX + deviceModeId; TdSuperTableVo tdSuperTableVo = new TdSuperTableVo(); TdField schemaField = new TdField(); @@ -478,19 +534,19 @@ public class HwDeviceModeServiceImpl implements IHwDeviceModeService { tdSuperTableVo.setDatabaseName(dbName); tdSuperTableVo.setSuperTableName(superTableName); tdSuperTableVo.setField(schemaField); - R tdReturnMsg = this.remoteTdEngineService.addSuperTableColumn(tdSuperTableVo); - if(tdReturnMsg.getCode() != Constants.SUCCESS){//抛出异常,回滚事务 + R tdReturnMsg = this.remoteTdEngineService.addSuperTableColumn(tdSuperTableVo, SecurityConstants.INNER); + if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务 throw new RuntimeException(tdReturnMsg.getMsg()); } } } + private void dropTdSuperTableColumn(HwDeviceModeFunction hwDeviceModeFunction) { String functionMode = hwDeviceModeFunction.getFunctionMode(); if (functionMode.equals(HwDictConstants.FUNCTION_MODE_ATTRIBUTE)) { Long deviceModeId = hwDeviceModeFunction.getDeviceModeId(); - HwDeviceMode hwDeviceMode = hwDeviceModeMapper.selectHwDeviceModeByDeviceModeId(deviceModeId); - String dbName = TdEngineConstants.DEFAULT_DB_NAME_PREFIX + hwDeviceMode.getSceneId(); + String dbName = TdEngineConstants.getDatabaseName(); String superTableName = TdEngineConstants.DEFAULT_SUPER_TABLE_NAME_PREFIX + deviceModeId; TdSuperTableVo tdSuperTableVo = new TdSuperTableVo(); TdField schemaField = new TdField(); @@ -499,11 +555,12 @@ public class HwDeviceModeServiceImpl implements IHwDeviceModeService { tdSuperTableVo.setSuperTableName(superTableName); tdSuperTableVo.setField(schemaField); - R tdReturnMsg =this.remoteTdEngineService.dropColumnForSuperTable(tdSuperTableVo); - if(tdReturnMsg.getCode() != Constants.SUCCESS){//抛出异常,回滚事务 + R tdReturnMsg = this.remoteTdEngineService.dropColumnForSuperTable(tdSuperTableVo, SecurityConstants.INNER); + if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务 throw new RuntimeException(tdReturnMsg.getMsg()); } } } + } 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 0454d9f..fa9d457 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 @@ -12,6 +12,7 @@ import com.ruoyi.business.mapper.*; import com.ruoyi.business.service.IHwDeviceService; import com.ruoyi.common.core.constant.Constants; import com.ruoyi.common.core.constant.HwDictConstants; +import com.ruoyi.common.core.constant.SecurityConstants; import com.ruoyi.common.core.constant.TdEngineConstants; import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.enums.DataTypeEnums; @@ -193,7 +194,7 @@ public class HwDeviceServiceImpl implements IHwDeviceService { */ private void createTdTable(HwDevice hwDevice) { TdTableVo tdTableVo = new TdTableVo(); - String databaseName = TdEngineConstants.getDatabaseName(hwDevice.getSceneId()); + String databaseName = TdEngineConstants.getDatabaseName(); String superTableName = TdEngineConstants.getSuperTableName(hwDevice.getDeviceModeId()); String tableName = TdEngineConstants.getDeviceDataTableName(hwDevice.getDeviceId()); @@ -204,7 +205,7 @@ public class HwDeviceServiceImpl implements IHwDeviceService { tdTableVo.setTableName(tableName); tdTableVo.setTagsFieldValues(tagsFields); - R tdReturnMsg = this.remoteTdEngineService.createTable(tdTableVo); + R tdReturnMsg = this.remoteTdEngineService.createTable(tdTableVo, SecurityConstants.INNER); if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务 throw new RuntimeException(tdReturnMsg.getMsg()); } @@ -225,7 +226,7 @@ public class HwDeviceServiceImpl implements IHwDeviceService { tdTableVo.setTagsFieldValues(tagsFields); - R tdReturnMsg = this.remoteTdEngineService.createTable(tdTableVo); + R tdReturnMsg = this.remoteTdEngineService.createTable(tdTableVo, SecurityConstants.INNER); if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务 throw new RuntimeException(tdReturnMsg.getMsg()); } @@ -390,8 +391,7 @@ public class HwDeviceServiceImpl implements IHwDeviceService { Map> devicesMap = new HashMap>(); List controlDeviceVos = new ArrayList(); List acquisitionDeviceVos = new ArrayList(); - Long sceneId = queryHwDevice.getSceneId(); - String databaseName = TdEngineConstants.getDatabaseName(sceneId); + String databaseName = TdEngineConstants.getDatabaseName(); queryHwDevice.setDeviceType(HwDictConstants.DEVICE_TYPE_GATEWAY_SUB_EQUIPMENT); List hwDevices = hwDeviceMapper.selectHwDeviceList(queryHwDevice); @@ -411,7 +411,9 @@ public class HwDeviceServiceImpl implements IHwDeviceService { deviceModeFunctions.forEach(mf -> { if (mf.getFunctionMode().equals(HwDictConstants.FUNCTION_MODE_ATTRIBUTE)) { TdField field = new TdField(); - field.setFieldName(mf.getFunctionIdentifier()); + String functionIdentifierTransfer = TdEngineConstants.TDENGINE_KEY_TRANSFER_MAP.get(mf.getFunctionIdentifier()); + String functionIdentifier = functionIdentifierTransfer == null ? mf.getFunctionIdentifier() : functionIdentifierTransfer; + field.setFieldName(functionIdentifier); schemaFieldValues.add(field); } else if (mf.getFunctionMode().equals(HwDictConstants.FUNCTION_MODE_SERVICE)) { modeFunctions.add(mf); @@ -421,7 +423,7 @@ public class HwDeviceServiceImpl implements IHwDeviceService { tdSelectDto.setSchemaFieldValues(schemaFieldValues); //从tdengine获取此设备的最新数据 List> deviceLatestDataMapList = - (List>) this.remoteTdEngineService.getLatestData(tdSelectDto).getData(); + (List>) this.remoteTdEngineService.getLatestData(tdSelectDto, SecurityConstants.INNER).getData(); //获取此设备模型的功能列表 @@ -437,8 +439,16 @@ public class HwDeviceServiceImpl implements IHwDeviceService { //转换成map,key为标识符,value为功能名称(主要tdengine存的是标识符,用来下面转换成功能名称) Map functionIndentifierName = deviceModeFunctions.stream().collect( - Collectors.toMap(HwDeviceModeFunction::getFunctionIdentifier, HwDeviceModeFunction::getFunctionName)); + Collectors.toMap(HwDeviceModeFunction::getFunctionIdentifier, + HwDeviceModeFunction::getFunctionName)); + Map functionIndentifierNameMap = new HashMap<>(); + functionIndentifierName.forEach((key, val) -> + { + String keyTransfer = TdEngineConstants.TDENGINE_KEY_TRANSFER_MAP.get(key) == null ? + key : TdEngineConstants.TDENGINE_KEY_TRANSFER_MAP.get(key); + functionIndentifierNameMap.put(keyTransfer, val); + }); //获取可控制设备,根据是否有服务判断 // List modeFunctions = deviceModeFunctions.stream() // .filter(dmf -> dmf.getFunctionMode().equals(HwDictConstants.FUNCTION_MODE_SERVICE) @@ -451,6 +461,7 @@ public class HwDeviceServiceImpl implements IHwDeviceService { hwDeviceVo.setDeviceType(HwDictConstants.CONTROL_DEVICE); hwDeviceVo.setDeviceCode(hwDevice.getDeviceCode()); hwDeviceVo.setDeviceName(hwDevice.getDeviceName()); + hwDeviceVo.setDevicePic(hwDevice.getDevicePic()); hwDeviceVo.setDeviceModeFunction(modeFunction); controlDeviceVos.add(hwDeviceVo); }); @@ -462,12 +473,11 @@ public class HwDeviceServiceImpl implements IHwDeviceService { deviceLatestDataMapList.forEach(deviceLatestDataMap -> { Set functionIdentifiers = deviceLatestDataMap.keySet(); for (String dataFunctionIdentifier : functionIdentifiers) { - if (functionIndentifierName.get(dataFunctionIdentifier) != null) { - ddValueMap.put(functionIndentifierName.get(dataFunctionIdentifier), + if (functionIndentifierNameMap.get(dataFunctionIdentifier) != null) { + ddValueMap.put(functionIndentifierNameMap.get(dataFunctionIdentifier), deviceLatestDataMap.get(dataFunctionIdentifier)); } } - }); } //不论是否是控制型设备都显示最新数据 @@ -609,11 +619,11 @@ public class HwDeviceServiceImpl implements IHwDeviceService { } /** + * @return DevicesInfoVo * @param: monitorUnitId * @description 根据监控单元ID获取设备情况(包括在线和离线设备数量,正常的设备数量和报警的设备数量) * @author xins * @date 2023-09-28 14:25 - * @return DevicesInfoVo */ @Override public DevicesInfoVo getDevicesInfoByMonitorUnitId(Long monitorUnitId) { @@ -655,6 +665,21 @@ public class HwDeviceServiceImpl implements IHwDeviceService { return devicesInfoVo; } + /** + * @description 重建tdengine所有设备表 + * @author xins + * @date 2023-10-10 20:05 + */ + @Override + public void rebuildTdTables() { + HwDevice queryDevice = new HwDevice(); + queryDevice.setDeviceType(HwDictConstants.DEVICE_TYPE_GATEWAY_SUB_EQUIPMENT); + List devices = hwDeviceMapper.selectHwDeviceList(queryDevice); + devices.forEach(device -> { + this.createTdTable(device); + }); + } + /** * @param: hwDevice 前端传的对象 * @param: dbDevice 目前数据库的对象 @@ -664,7 +689,7 @@ public class HwDeviceServiceImpl implements IHwDeviceService { */ private void updateTdEngine(HwDevice hwDevice, HwDevice dbDevice) { String deviceType = hwDevice.getDeviceType(); - String databaseName = TdEngineConstants.getDatabaseName(hwDevice.getSceneId()); + String databaseName = TdEngineConstants.getDatabaseName(); String tableName = TdEngineConstants.getDeviceDataTableName(hwDevice.getDeviceId()); AlterTagVo alterTagVo = new AlterTagVo(); alterTagVo.setDatabaseName(databaseName); @@ -676,7 +701,7 @@ public class HwDeviceServiceImpl implements IHwDeviceService { alterTagVo.setTagName(TdEngineConstants.ST_TAG_DEVICECODE); alterTagVo.setTagValue("'" + hwDevice.getDeviceCode() + "'"); - tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo); + tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo, SecurityConstants.INNER); if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务 throw new RuntimeException(tdReturnMsg.getMsg()); } @@ -684,7 +709,7 @@ public class HwDeviceServiceImpl implements IHwDeviceService { if (!hwDevice.getDeviceName().equals(dbDevice.getDeviceName())) { alterTagVo.setTagName(TdEngineConstants.ST_TAG_DEVICENAME); alterTagVo.setTagValue("'" + hwDevice.getDeviceName() + "'"); - tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo); + tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo, SecurityConstants.INNER); if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务 throw new RuntimeException(tdReturnMsg.getMsg()); } @@ -693,7 +718,7 @@ public class HwDeviceServiceImpl implements IHwDeviceService { if (!hwDevice.getMonitorUnitId().equals(dbDevice.getMonitorUnitId())) { alterTagVo.setTagName(TdEngineConstants.ST_TAG_MONITORUNITID); alterTagVo.setTagValue(hwDevice.getMonitorUnitId()); - tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo); + tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo, SecurityConstants.INNER); if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务 throw new RuntimeException(tdReturnMsg.getMsg()); } @@ -702,7 +727,7 @@ public class HwDeviceServiceImpl implements IHwDeviceService { if (!hwDevice.getDeviceModeId().equals(dbDevice.getDeviceModeId())) { alterTagVo.setTagName(TdEngineConstants.ST_TAG_DEVICEMODEID); alterTagVo.setTagValue(hwDevice.getDeviceModeId()); - tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo); + tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo, SecurityConstants.INNER); if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务 throw new RuntimeException(tdReturnMsg.getMsg()); } @@ -737,14 +762,14 @@ public class HwDeviceServiceImpl implements IHwDeviceService { //先获取starttime和endtime时间范围内在线的设备状态信息 Map> groupDeviceStatuMapList = - (Map>) this.remoteTdEngineService.getOnlineDevicesGroupByDay(queryGroupStatus).getData(); + (Map>) this.remoteTdEngineService.getOnlineDevicesGroupByDay(queryGroupStatus, SecurityConstants.INNER).getData(); if (groupDeviceStatuMapList == null) { groupDeviceStatuMapList = new HashMap<>(); } //获取在endtime之前最后的设备状态信息(有些设备会一直在线,没有连续的上线下线记录,所以要获取最近的设备状态信息来补齐后面的设备在线情况) List> lastDeviceStatuMapList = - (List>) this.remoteTdEngineService.getLastOnlineDevices(queryLastStatus).getData(); + (List>) this.remoteTdEngineService.getLastOnlineDevices(queryLastStatus, SecurityConstants.INNER).getData(); if (lastDeviceStatuMapList == null || lastDeviceStatuMapList.isEmpty()) { onlineDeviceCountByDay.put(startTime, 0); } else { 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 9f5e157..7369464 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 @@ -8,6 +8,7 @@ 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.SecurityConstants; import com.ruoyi.common.core.constant.TdEngineConstants; import com.ruoyi.tdengine.api.RemoteTdEngineService; import com.ruoyi.tdengine.api.domain.TdField; @@ -19,6 +20,7 @@ import org.springframework.stereotype.Service; import javax.annotation.Resource; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.stream.Collectors; @@ -57,12 +59,20 @@ public class HwMonitorPlatformServiceImpl implements IHwMonitorPlatformService { Collectors.toMap(HwDeviceModeFunction::getFunctionIdentifier, HwDeviceModeFunction::getFunctionName)); functionIndentifierName.putAll(TdEngineConstants.DEVICE_DATA_COLUMN_MAP); + Map functionIndentifierNameMap = new HashMap<>(); + functionIndentifierName.forEach((key, val) -> + { + String keyTransfer = TdEngineConstants.TDENGINE_KEY_TRANSFER_MAP.get(key) == null ? + key : TdEngineConstants.TDENGINE_KEY_TRANSFER_MAP.get(key); + functionIndentifierNameMap.put(keyTransfer, val); + }); + TdSuperTableSelectVo tdSuperTableSelectVo = new TdSuperTableSelectVo(); - String databaseName = TdEngineConstants.getDatabaseName(deviceLatestDataVo.getSceneId()); + String databaseName = TdEngineConstants.getDatabaseName(); String superTableName = TdEngineConstants.getSuperTableName(deviceModeId); tdSuperTableSelectVo.setDatabaseName(databaseName); tdSuperTableSelectVo.setSuperTableName(superTableName); - tdSuperTableSelectVo.setGroupByTagsName(TdEngineConstants.ST_TAG_DEVICECODE);//todo,换成deviceid + tdSuperTableSelectVo.setGroupByTagsName(TdEngineConstants.ST_TAG_DEVICEID); if (deviceLatestDataVo.getStartTime() != 0 || deviceLatestDataVo.getEndTime() != 0) { tdSuperTableSelectVo.setFirstFieldName(TdEngineConstants.DEFAULT_FIRST_FIELD_NAME); } @@ -70,22 +80,24 @@ public class HwMonitorPlatformServiceImpl implements IHwMonitorPlatformService { tdSuperTableSelectVo.setDeviceName(deviceLatestDataVo.getDeviceName()); tdSuperTableSelectVo.setStartTime(deviceLatestDataVo.getStartTime()); tdSuperTableSelectVo.setEndTime(deviceLatestDataVo.getEndTime()); - tdSuperTableSelectVo.setOffset(deviceLatestDataVo.getOffset()); + tdSuperTableSelectVo.setOffset(deviceLatestDataVo.getOffset()*deviceLatestDataVo.getLimit()); tdSuperTableSelectVo.setLimit(deviceLatestDataVo.getLimit()); List schemaFieldValues = new ArrayList(); List modeFunctions = new ArrayList<>(); deviceModeFunctions.forEach(mf -> { - TdField field = new TdField(); - field.setFieldName(mf.getFunctionIdentifier()); - schemaFieldValues.add(field); + TdField field = new TdField(); + String functionIdentifierTransfer = TdEngineConstants.TDENGINE_KEY_TRANSFER_MAP.get(mf.getFunctionIdentifier()); + String functionIdentifier = functionIdentifierTransfer == null ? mf.getFunctionIdentifier() : functionIdentifierTransfer; + field.setFieldName(functionIdentifier); + schemaFieldValues.add(field); }); tdSuperTableSelectVo.setSchemaFieldValues(schemaFieldValues); List> latestDataMaps = - this.remoteTdEngineService.getLatestDataByTags(tdSuperTableSelectVo).getData(); + this.remoteTdEngineService.getLatestDataByTags(tdSuperTableSelectVo, SecurityConstants.INNER).getData(); List deviceDataColumnVos = new ArrayList(); @@ -94,11 +106,11 @@ public class HwMonitorPlatformServiceImpl implements IHwMonitorPlatformService { 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)){ + 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)); + deviceDataColumnVo.setColumnName(functionIndentifierNameMap.get(columnKey) == null + ? columnKey : functionIndentifierNameMap.get(columnKey)); deviceDataColumnVos.add(deviceDataColumnVo); } } @@ -120,7 +132,7 @@ public class HwMonitorPlatformServiceImpl implements IHwMonitorPlatformService { @Override public TdReturnDataVo getHistoryData(DeviceHistoryDataVo deviceHistoryDataVo) { TdHistorySelectDto tdHistorySelectDto = new TdHistorySelectDto(); - tdHistorySelectDto.setDatabaseName(TdEngineConstants.getDatabaseName(deviceHistoryDataVo.getSceneId())); + tdHistorySelectDto.setDatabaseName(TdEngineConstants.getDatabaseName()); tdHistorySelectDto.setTableName(TdEngineConstants.getDeviceDataTableName(deviceHistoryDataVo.getDeviceId())); tdHistorySelectDto.setOrderByFieldName(TdEngineConstants.DEFAULT_FIRST_FIELD_NAME); tdHistorySelectDto.setSort(TdEngineConstants.DEFAULT_ORDER_BY_MODE); @@ -129,10 +141,10 @@ public class HwMonitorPlatformServiceImpl implements IHwMonitorPlatformService { } tdHistorySelectDto.setStartTime(deviceHistoryDataVo.getStartTime()); tdHistorySelectDto.setEndTime(deviceHistoryDataVo.getEndTime()); - tdHistorySelectDto.setOffset(deviceHistoryDataVo.getOffset()); + tdHistorySelectDto.setOffset(deviceHistoryDataVo.getOffset() * deviceHistoryDataVo.getLimit()); tdHistorySelectDto.setLimit(deviceHistoryDataVo.getLimit()); - return this.remoteTdEngineService.getHistoryData(tdHistorySelectDto).getData(); + return this.remoteTdEngineService.getHistoryData(tdHistorySelectDto, SecurityConstants.INNER).getData(); } @@ -153,6 +165,15 @@ public class HwMonitorPlatformServiceImpl implements IHwMonitorPlatformService { Map functionIndentifierName = deviceModeFunctions.stream().collect( Collectors.toMap(HwDeviceModeFunction::getFunctionIdentifier, HwDeviceModeFunction::getFunctionName)); functionIndentifierName.putAll(TdEngineConstants.DEVICE_DATA_COLUMN_MAP); + functionIndentifierName.putAll(TdEngineConstants.DEVICE_DATA_COLUMN_MAP); + + Map functionIndentifierNameMap = new HashMap<>(); + functionIndentifierName.forEach((key, val) -> + { + String keyTransfer = TdEngineConstants.TDENGINE_KEY_TRANSFER_MAP.get(key) == null ? + key : TdEngineConstants.TDENGINE_KEY_TRANSFER_MAP.get(key); + functionIndentifierNameMap.put(keyTransfer, val); + }); List deviceDataColumnVos = new ArrayList(); if (latestDataMaps != null && latestDataMaps.size() > 0) { @@ -161,8 +182,8 @@ public class HwMonitorPlatformServiceImpl implements IHwMonitorPlatformService { DeviceDataColumnVo deviceDataColumnVo = new DeviceDataColumnVo(); String columnKey = entry.getKey(); deviceDataColumnVo.setColumnKey(columnKey); - deviceDataColumnVo.setColumnName(functionIndentifierName.get(columnKey) == null - ? columnKey : functionIndentifierName.get(columnKey)); + deviceDataColumnVo.setColumnName(functionIndentifierNameMap.get(columnKey) == null + ? columnKey : functionIndentifierNameMap.get(columnKey)); deviceDataColumnVos.add(deviceDataColumnVo); } } diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwSceneServiceImpl.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwSceneServiceImpl.java index a18645f..ea99200 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwSceneServiceImpl.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwSceneServiceImpl.java @@ -1,39 +1,29 @@ package com.ruoyi.business.service.impl; -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.ruoyi.business.domain.HwDevice; -import com.ruoyi.business.domain.HwSceneMode; +import com.ruoyi.business.domain.HwScene; import com.ruoyi.business.domain.VO.HwSceneVo; import com.ruoyi.business.mapper.HwDeviceMapper; -import com.ruoyi.common.core.constant.Constants; +import com.ruoyi.business.mapper.HwSceneMapper; +import com.ruoyi.business.service.IHwSceneService; import com.ruoyi.common.core.constant.HwDictConstants; -import com.ruoyi.common.core.constant.TdEngineConstants; -import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.utils.DateUtils; import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.datascope.annotation.DataScope; -import com.ruoyi.common.redis.service.RedisService; import com.ruoyi.common.security.utils.SecurityUtils; -import com.ruoyi.system.api.domain.SysUser; -import com.ruoyi.system.api.model.LoginUser; import com.ruoyi.tdengine.api.RemoteTdEngineService; import org.apache.commons.lang3.RandomStringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Service; -import com.ruoyi.business.mapper.HwSceneMapper; -import com.ruoyi.business.domain.HwScene; -import com.ruoyi.business.service.IHwSceneService; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; +import java.math.BigDecimal; +import java.util.List; /** * 场景信息Service业务层处理 @@ -47,8 +37,6 @@ public class HwSceneServiceImpl implements IHwSceneService { private HwSceneMapper hwSceneMapper; @Autowired private HwDeviceMapper hwDeviceMapper; - @Resource - private RemoteTdEngineService remoteTdEngineService; @Autowired private StringRedisTemplate redisTemplate; @@ -105,9 +93,7 @@ public class HwSceneServiceImpl implements IHwSceneService { @Override @Transactional public int insertHwScene(HwScene hwScene) { - LoginUser loginUser = SecurityUtils.getLoginUser(); - SysUser sysUser = loginUser.getSysUser(); - hwScene.setCreateBy(sysUser.getUserName()); + hwScene.setCreateBy(SecurityUtils.getUsername()); if (hwScene.getPreserveTime() == null) { hwScene.setPreserveTime(new BigDecimal(90)); @@ -125,17 +111,17 @@ public class HwSceneServiceImpl implements IHwSceneService { int rows = hwSceneMapper.insertHwScene(hwScene); this.updateDefaultFlag(hwScene); - this.createTdDatabase(hwScene); +// this.createTdDatabase(hwScene); return rows; } - private void createTdDatabase(HwScene hwScene) { - String databaseName = TdEngineConstants.getDatabaseName(hwScene.getSceneId()); - R tdReturnMsg = this.remoteTdEngineService.createDataBase(databaseName); - if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务 - throw new RuntimeException(tdReturnMsg.getMsg()); - } - } +// private void createTdDatabase(HwScene hwScene) { +// String databaseName = TdEngineConstants.getDatabaseName(hwScene.getSceneId()); +// R tdReturnMsg = this.remoteTdEngineService.createDataBase(databaseName); +// if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务 +// throw new RuntimeException(tdReturnMsg.getMsg()); +// } +// } /** * 修改场景信息 diff --git a/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwDeviceMapper.xml b/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwDeviceMapper.xml index 1ad8031..f1c0434 100644 --- a/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwDeviceMapper.xml +++ b/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwDeviceMapper.xml @@ -98,6 +98,7 @@ 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/HwMonitorUnitMapper.xml b/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwMonitorUnitMapper.xml index fa38987..104efda 100644 --- a/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwMonitorUnitMapper.xml +++ b/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwMonitorUnitMapper.xml @@ -294,7 +294,7 @@ diff --git a/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/dataprocess/mqtt/client/config/MqttConfiguration.java b/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/dataprocess/mqtt/client/config/MqttConfiguration.java index 244143f..089beb3 100644 --- a/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/dataprocess/mqtt/client/config/MqttConfiguration.java +++ b/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/dataprocess/mqtt/client/config/MqttConfiguration.java @@ -138,12 +138,12 @@ public class MqttConfiguration { logger.info("Process Data start:{}ms,end:{}ms,Spend Time:{}ms,Data Count:{}", start, end, end - start, processDataCount); } else if (topic.equals(deviceStatusTopic)) { deviceStatusService.handleDeviceStatus(payloadString, clientId); - } else { + } else {//测试图片转换使用 dataProcessService.testBase64(payloadString, imagePath, imagePatterns, imageDomain, imagePrefix); } } catch (Exception e) { e.printStackTrace(); - logger.error("Error processing business data:" + e.getMessage()); + logger.error("Error processing business data,topic:{},start:{},error:{}", topic, start, e.getMessage()); } } }); diff --git a/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/dataprocess/service/impl/DataProcessServiceImpl.java b/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/dataprocess/service/impl/DataProcessServiceImpl.java index 025bcec..4254397 100644 --- a/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/dataprocess/service/impl/DataProcessServiceImpl.java +++ b/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/dataprocess/service/impl/DataProcessServiceImpl.java @@ -4,6 +4,7 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.ruoyi.common.core.constant.HwDictConstants; +import com.ruoyi.common.core.constant.SecurityConstants; import com.ruoyi.common.core.constant.TdEngineConstants; import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.enums.ResultEnums; @@ -77,7 +78,7 @@ public class DataProcessServiceImpl implements IDataProcessService { */ @Override public int processBusinessData(String jsonData, String imagePath, - String imagePatterns,String imageDomain,String imagePrefix) { + String imagePatterns, String imageDomain, String imagePrefix) { JSONObject json = JSON.parseObject(jsonData); Long ts = json.getLong(TdEngineConstants.PAYLOAD_TS); String tsStr = String.valueOf(ts); @@ -87,99 +88,113 @@ public class DataProcessServiceImpl implements IDataProcessService { JSONArray paramArr = json.getJSONArray(TdEngineConstants.PAYLOAD_PARAM); // System.out.println(this.hwDeviceMapper); // System.out.println(this.remoteTdEngineService); + String deviceCode = ""; for (int i = 0; i < paramArr.size(); i++) { - JSONObject paramJson = paramArr.getJSONObject(i); - JSONObject dataValueJson = paramJson.getJSONObject(TdEngineConstants.PAYLOAD_DATAVALUE); - String deviceCode = dataValueJson.getString(TdEngineConstants.PAYLOAD_DEVICE_CODE).toLowerCase(); - HwDevice hwDevice = hwDeviceMapper.selectHwDeviceByDeviceCode(deviceCode); - Long sceneId = hwDevice.getSceneId(); - Long deviceId = hwDevice.getDeviceId(); - Long monitorUnitId = hwDevice.getMonitorUnitId(); - Long tenantId = hwDevice.getTenantId(); - String databaseName = TdEngineConstants.DEFAULT_DB_NAME_PREFIX + sceneId; - String tableName = TdEngineConstants.DEFAULT_TABLE_NAME_PREFIX + deviceId; - - dataValueJson.remove(TdEngineConstants.PAYLOAD_DEVICE_CODE); - TdTableVo tdTableVo = new TdTableVo(); - List schemaFields = new ArrayList<>(); - - //添加timestamp字段,默认字段名称是ts,协议上传的key是timestamp - TdField firstTdField = new TdField(); - firstTdField.setFieldName(TdEngineConstants.DEFAULT_FIRST_FIELD_NAME); - firstTdField.setFieldValue(ts); - schemaFields.add(firstTdField); - - Object longitude = null; - Object latitude = null; - - for (Map.Entry entry : dataValueJson.entrySet()) { - String key = entry.getKey(); - Object value = entry.getValue(); + try { + JSONObject paramJson = paramArr.getJSONObject(i); + JSONObject dataValueJson = paramJson.getJSONObject(TdEngineConstants.PAYLOAD_DATAVALUE); + deviceCode = dataValueJson.getString(TdEngineConstants.PAYLOAD_DEVICE_CODE).toLowerCase(); + HwDevice hwDevice = hwDeviceMapper.selectHwDeviceByDeviceCode(deviceCode); + if (hwDevice == null) { + logger.error("此设备【deviceCode:{}】不存在", deviceCode); + continue; + } + if (hwDevice.getDeviceStatus().equals(HwDictConstants.DEVICE_STATUS_DELETE)) { + logger.error("此设备【deviceCode:{}】已删除", deviceCode); + continue; + } - /** - * 先对key进行转换,例如对于key是value的需要转换成value1; - */ - key = TdEngineConstants.TDENGINE_KEY_TRANSFER_MAP.get(key) == null ? key - : TdEngineConstants.TDENGINE_KEY_TRANSFER_MAP.get(key); - - if (value instanceof String) { - String valueStr = (String) value; - if (StringUtils.isNotBlank(valueStr)) { - /** - * 先判读是否是图片,并获取图片名称, 获取到证明是图片 - */ - String[] imagePatternArr = imagePatterns.split(","); - String extension = ImageUtils.getImageType(valueStr, imagePatternArr); - if (StringUtils.isNotBlank(extension)) { - //保存图片,并返回图片详细地址进行赋值保存 - String imageFileName = null; - try { - imageFileName = ImageUtils.convertBase64ToImage(imagePath, - valueStr, "device" + deviceId, extension); - if (StringUtils.isNotBlank(imageFileName)) { - value = imageDomain + imagePrefix + imageFileName; - System.out.println(value); - }else { - continue; + Long sceneId = hwDevice.getSceneId(); + Long deviceId = hwDevice.getDeviceId(); + Long monitorUnitId = hwDevice.getMonitorUnitId(); + Long tenantId = hwDevice.getTenantId(); + String databaseName = TdEngineConstants.getDatabaseName(); + String tableName = TdEngineConstants.DEFAULT_TABLE_NAME_PREFIX + deviceId; + + dataValueJson.remove(TdEngineConstants.PAYLOAD_DEVICE_CODE); + TdTableVo tdTableVo = new TdTableVo(); + List schemaFields = new ArrayList<>(); + + //添加timestamp字段,默认字段名称是ts,协议上传的key是timestamp + TdField firstTdField = new TdField(); + firstTdField.setFieldName(TdEngineConstants.DEFAULT_FIRST_FIELD_NAME); + firstTdField.setFieldValue(ts); + schemaFields.add(firstTdField); + + Object longitude = null; + Object latitude = null; + + for (Map.Entry entry : dataValueJson.entrySet()) { + String key = entry.getKey(); + Object value = entry.getValue(); + + /** + * 先对key进行转换,例如对于key是value的需要转换成value1; + */ + key = TdEngineConstants.TDENGINE_KEY_TRANSFER_MAP.get(key) == null ? key + : TdEngineConstants.TDENGINE_KEY_TRANSFER_MAP.get(key); + + if (value instanceof String) { + String valueStr = (String) value; + if (StringUtils.isNotBlank(valueStr)) { + /** + * 先判读是否是图片,并获取图片名称, 获取到证明是图片 + */ + String[] imagePatternArr = imagePatterns.split(","); + String extension = ImageUtils.getImageType(valueStr, imagePatternArr); + if (StringUtils.isNotBlank(extension)) { + //保存图片,并返回图片详细地址进行赋值保存 + String imageFileName = null; + try { + imageFileName = ImageUtils.convertBase64ToImage(imagePath, + valueStr, "device" + deviceId, extension); + if (StringUtils.isNotBlank(imageFileName)) { + value = imageDomain + imagePrefix + imageFileName; + } else { + continue; + } + } catch (IOException e) { + logger.error("转换图片错误:" + e.getMessage(), e); } - } catch (IOException e) { - logger.error("转换图片错误:"+e.getMessage(), e); } - } + TdField tdField = new TdField(); + tdField.setFieldName(key); + tdField.setFieldValue(value); + schemaFields.add(tdField); + } + } else { TdField tdField = new TdField(); tdField.setFieldName(key); tdField.setFieldValue(value); schemaFields.add(tdField); - } - } else { - TdField tdField = new TdField(); - tdField.setFieldName(key); - tdField.setFieldValue(value); - schemaFields.add(tdField); - - //经纬度判断 - if (key.equalsIgnoreCase(HwDictConstants.DEFAULT_FUNCTION_LONGITUDE_IDENTIFIER)) { - longitude = value; - } else if (key.equalsIgnoreCase(HwDictConstants.DEFAULT_FUNCTION_LATITUDE_IDENTIFIER)) { - latitude = value; + + //经纬度判断 + if (key.equalsIgnoreCase(HwDictConstants.DEFAULT_FUNCTION_LONGITUDE_IDENTIFIER)) { + longitude = value; + } else if (key.equalsIgnoreCase(HwDictConstants.DEFAULT_FUNCTION_LATITUDE_IDENTIFIER)) { + latitude = value; + } } } - } - tdTableVo.setDatabaseName(databaseName); - tdTableVo.setTableName(tableName); - tdTableVo.setSchemaFields(schemaFields); + tdTableVo.setDatabaseName(databaseName); + tdTableVo.setTableName(tableName); + tdTableVo.setSchemaFields(schemaFields); - final R insertResult = this.remoteTdEngineService.insertTable(tdTableVo); - if (insertResult.getCode() == ResultEnums.SUCCESS.getCode()) { - logger.info("Insert data result: {}", insertResult.getMsg()); - } else { - logger.error("Insert data Exception: {},data:{}", insertResult.getMsg(), jsonData); - } + final R insertResult = this.remoteTdEngineService.insertTable(tdTableVo, SecurityConstants.INNER); + if (insertResult.getCode() == ResultEnums.SUCCESS.getCode()) { + logger.info("Insert data result: {}", insertResult.getMsg()); + } else { + logger.error("Insert data Exception: {},data:{}", insertResult.getMsg(), jsonData); + } + + if (longitude != null && latitude != null) { + checkElectronicFence(deviceId, tenantId, monitorUnitId, sceneId, longitude, latitude, ts); + } - if (longitude != null && latitude != null) { - checkElectronicFence(deviceId, tenantId, monitorUnitId, sceneId, longitude, latitude, ts); + } catch (Exception e) { + logger.error("deviceCode:{},errorMsg:{},data:{}", deviceCode, e.getMessage(), jsonData); } } diff --git a/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/dataprocess/service/impl/DeviceStatusServiceImpl.java b/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/dataprocess/service/impl/DeviceStatusServiceImpl.java index 7a5910e..fdfdfb6 100644 --- a/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/dataprocess/service/impl/DeviceStatusServiceImpl.java +++ b/ruoyi-modules/hw-data-process/src/main/java/com/ruoyi/dataprocess/service/impl/DeviceStatusServiceImpl.java @@ -3,6 +3,7 @@ package com.ruoyi.dataprocess.service.impl; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.ruoyi.common.core.constant.HwDictConstants; +import com.ruoyi.common.core.constant.SecurityConstants; import com.ruoyi.common.core.constant.TdEngineConstants; import com.ruoyi.dataprocess.domain.HwDevice; import com.ruoyi.dataprocess.mapper.HwDeviceMapper; @@ -68,7 +69,7 @@ public class DeviceStatusServiceImpl implements IDeviceStatusService { tdTableVo.setSchemaFields(schemaFields); - this.remoteTdEngineService.insertTable(tdTableVo); + this.remoteTdEngineService.insertTable(tdTableVo, SecurityConstants.INNER); //更新设备当前状态信息 String connectStatus = String.valueOf(json.getInteger("connectStatus")); 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 ed6662d..87b93cd 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 @@ -4,6 +4,7 @@ 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; +import com.ruoyi.common.security.annotation.InnerAuth; import com.ruoyi.tdengine.api.domain.*; import com.ruoyi.tdengine.service.IDeviceStatusService; import com.ruoyi.tdengine.service.ITdEngineService; @@ -46,6 +47,7 @@ public class TdEngineController { * @param databaseName * @return R */ + @InnerAuth @PostMapping("/createDatabase") public R createDataBase(@RequestBody() String databaseName) { try { @@ -73,6 +75,7 @@ public class TdEngineController { * @param tdSuperTableVo * @return R */ + @InnerAuth @PostMapping("/createSuperTable") public R createSuperTable(@Validated @RequestBody TdSuperTableVo tdSuperTableVo) { //数据库名称 @@ -114,6 +117,7 @@ public class TdEngineController { * @author xins * @date 2023-08-28 16:17 */ + @InnerAuth @PostMapping("/createTable") public R createTable(@Validated @RequestBody TdTableVo tdTableVo) { try { @@ -144,6 +148,7 @@ public class TdEngineController { * @author xins * @date 2023-08-28 17:55 */ + @InnerAuth @PostMapping("/addSuperTableColumn") public R addSuperTableColumn(@Validated(AddTdSTableColumn.class) @RequestBody TdSuperTableVo tdSuperTableVo) { String databaseName = tdSuperTableVo.getDatabaseName(); @@ -168,6 +173,39 @@ public class TdEngineController { } } + /** + * @return R + * @param: tdSuperTableVo + * @description 超级表增加列 + * @author xins + * @date 2023-08-28 17:55 + */ + @InnerAuth + @PostMapping("/modifySuperTableColumn") + public R modifySuperTableColumn(@Validated(AddTdSTableColumn.class) @RequestBody TdSuperTableVo tdSuperTableVo) { + String databaseName = tdSuperTableVo.getDatabaseName(); + String superTableName = tdSuperTableVo.getSuperTableName(); + TdField modifyTdField = tdSuperTableVo.getField(); + try { + TdFieldVo modifyTdFieldVo = TdFieldVo.convertField(modifyTdField); + this.tdEngineService.modifySuperTableColumn(databaseName, superTableName, modifyTdFieldVo); + log.info("successfully modified column for superTable {} " , superTableName); + return R.ok("successfully modified column for superTable " + superTableName); + } 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: tdSuperTableVo @@ -175,6 +213,7 @@ public class TdEngineController { * @author xins * @date 2023-08-28 17:56 */ + @InnerAuth @PostMapping("/dropSuperTableColumn") public R dropColumnForSuperTable(@Validated(AddTdSTableColumn.class) @RequestBody TdSuperTableVo tdSuperTableVo) { String databaseName = tdSuperTableVo.getDatabaseName(); @@ -207,6 +246,7 @@ public class TdEngineController { * @author xins * @date 2023-08-30 11:17 */ + @InnerAuth @PostMapping("/alterTableTag") public R alterTableTag(@Validated @RequestBody AlterTagVo alterTagVo) { String databaseName = alterTagVo.getDatabaseName(); @@ -239,6 +279,7 @@ public class TdEngineController { * @author xins * @date 2023-08-29 10:04 */ + @InnerAuth @PostMapping("/insertTable") public R insertTable(@Validated(InsertTdTable.class) @RequestBody TdTableVo tdTableVo) { try { @@ -270,6 +311,7 @@ public class TdEngineController { * @author xins * @date 2023-08-29 11:26 */ + @InnerAuth @PostMapping("/getLatestData") public R getLatestData(@Validated @RequestBody TdSelectDto tdSelectDto) { try { @@ -295,6 +337,7 @@ public class TdEngineController { * @author xins * @date 2023-08-29 14:51 */ + @InnerAuth @PostMapping("/getLatestDataByTags") public R>> getLatestDataByTags(@Validated @RequestBody TdSuperTableSelectVo tdSelectDto) { try { @@ -323,6 +366,7 @@ public class TdEngineController { * 实时数据 select col from table LIMIT [topnums] * 聚合数据 select [avg/max/sum/count..](col) from table where ts between '2017-07-14 02:40:00.000' and '2017-07-14 02:40:00.001' group by col LIMIT [topnums] */ + @InnerAuth @PostMapping("/getHistoryData") public R getHistoryData(@Validated @RequestBody TdHistorySelectDto tdHistorySelectDto) { try { @@ -359,6 +403,7 @@ public class TdEngineController { * @author xins * @date 2023-08-29 11:26 */ + @InnerAuth @PostMapping("/getOnlineDevicesGroupByDay") public R getOnlineDevicesGroupByDay(@RequestBody DeviceStatus queryDeviceStatus) { try { @@ -388,6 +433,7 @@ public class TdEngineController { * @author xins * @date 2023-08-29 11:26 */ + @InnerAuth @PostMapping("/getLastOnlineDevices") public R getLastOnlineDevices(@RequestBody DeviceStatus queryDeviceStatus) { try { 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 4cbb0b9..903760a 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 @@ -67,6 +67,19 @@ public interface TdEngineMapper { @Param("superTableName") String superTableName, @Param("addFieldsVo") TdFieldVo addFieldsVo); + /** + * @param: databaseName + * @param: superTableName + * @param: modifyFieldsVo + * @description 修改超级表列宽(只适用于nchar类型) + * @author xins + * @date 2023-10-11 9:01 + + */ + void modifySuperTableColumn(@Param("databaseName") String databaseName, + @Param("superTableName") String superTableName, + @Param("modifyFieldsVo") TdFieldVo modifyFieldsVo); + /** * @param: databaseName * @param: superTableName 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 f950750..5f2163f 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 @@ -56,6 +56,16 @@ public interface ITdEngineService { public void addSuperTableColumn(String databaseName,String superTableName, TdFieldVo addFieldsVo) throws Exception; + /** + * @param: databaseName + * @param: superTableName + * @param: modifyFieldsVo + * @description 修改超级表列宽(只适用于nchar类型) + * @author xins + * @date 2023-10-11 9:02 + */ + public void modifySuperTableColumn(String databaseName, String superTableName, TdFieldVo modifyFieldsVo) throws Exception; + /** * @param: databaseName * @param: superTableName 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 3e72fcb..c0045d6 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 @@ -91,6 +91,20 @@ public class TdEngineServiceImpl implements ITdEngineService { this.tdEngineMapper.addSuperTableColumn(databaseName, superTableName, addFieldsVo); } + /** + * @param: databaseName + * @param: superTableName + * @param: modifyFieldsVo + * @description 修改超级表列宽(只适用于nchar类型) + * @author xins + * @date 2023-10-11 9:02 + */ + @Override + public void modifySuperTableColumn(String databaseName, String superTableName, TdFieldVo modifyFieldsVo) throws Exception { + this.tdEngineMapper.modifySuperTableColumn(databaseName, superTableName, modifyFieldsVo); + } + + /** * @param: databaseName * @param: superTableName 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 72628ab..3500bed 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 @@ -166,6 +166,18 @@ + + + + ALTER STABLE #{databaseName}.#{superTableName} modify COLUMN + + ${modifyFieldsVo.fieldName} nchar(#{modifyFieldsVo.size}) + + + + + + ALTER STABLE #{databaseName}.#{superTableName} DROP COLUMN diff --git a/ruoyi-ui/src/api/business/device.js b/ruoyi-ui/src/api/business/device.js index 461f1c4..1ea16b5 100644 --- a/ruoyi-ui/src/api/business/device.js +++ b/ruoyi-ui/src/api/business/device.js @@ -113,3 +113,11 @@ export function publishControlCommand(deviceId, type) { data: data }) } + +// 重新生成tdengine所有表 +export function rebuildTdTables() { + return request({ + url: '/business/device/rebuildTdTables', + method: 'get' + }) +} diff --git a/ruoyi-ui/src/api/business/deviceMode.js b/ruoyi-ui/src/api/business/deviceMode.js index d44e6c8..aad8524 100644 --- a/ruoyi-ui/src/api/business/deviceMode.js +++ b/ruoyi-ui/src/api/business/deviceMode.js @@ -60,3 +60,11 @@ export function getEditedScenes(query) { params: query }) } + +// 重新生成tdengine所有超级表 +export function rebuildTdSuperTables() { + return request({ + url: '/business/deviceMode/rebuildTdSuperTables', + method: 'get' + }) +} diff --git a/ruoyi-ui/src/assets/logo/logo.png b/ruoyi-ui/src/assets/logo/logo.png index 2ca0742..18e66f8 100644 Binary files a/ruoyi-ui/src/assets/logo/logo.png and b/ruoyi-ui/src/assets/logo/logo.png differ diff --git a/ruoyi-ui/src/views/business/device/index.vue b/ruoyi-ui/src/views/business/device/index.vue index 15520c1..b68a58c 100644 --- a/ruoyi-ui/src/views/business/device/index.vue +++ b/ruoyi-ui/src/views/business/device/index.vue @@ -109,11 +109,23 @@ >导出 + + 重建表 + + + @@ -375,11 +387,13 @@ import { getDeviceModes, getGatewayDevices, changeDeviceStatus, - publishControlCommand + publishControlCommand, + rebuildTdTables } from "@/api/business/device"; import {getToken} from "@/utils/auth"; import Treeselect from "@riophae/vue-treeselect"; import "@riophae/vue-treeselect/dist/vue-treeselect.css"; +import {rebuildTdSuperTables} from "@/api/business/deviceMode"; export default { components: {Treeselect}, @@ -737,7 +751,7 @@ export default { const deviceId = row.deviceId; const deviceType = row.deviceType; const deviceCode = row.deviceCode; - this.$modal.confirm('是否确认删除设备信息编号为"' + deviceCode + '"的数据项?').then(function () { + this.$modal.confirm('是否确认删除设备信息ID为"' + deviceId + '"的数据项?').then(function () { return delDevice(deviceId,deviceType); }).then(() => { this.getList(); @@ -965,7 +979,16 @@ export default { }).then(() => { this.$modal.msgSuccess("下发指令成功"); }) - } + }, + /** 重建表按钮操作 */ + handleRebuildTdTables() { + this.$modal.confirm('是否确认重建所有设备监测数据表?').then(function () { + return rebuildTdTables(); + }).then(() => { + this.$modal.msgSuccess("重建成功"); + }).catch(() => { + }); + }, } }; diff --git a/ruoyi-ui/src/views/business/deviceMode/deviceModeEvent.vue b/ruoyi-ui/src/views/business/deviceMode/deviceModeEvent.vue index efbf2ad..4e2e540 100644 --- a/ruoyi-ui/src/views/business/deviceMode/deviceModeEvent.vue +++ b/ruoyi-ui/src/views/business/deviceMode/deviceModeEvent.vue @@ -328,12 +328,14 @@ export default { handleDeleteEvent(row) { if (row.modeFunctionId !== undefined) { - delDeviceModeFunction(row.modeFunctionId).then(res => { - this.$modal.msgSuccess(res.msg); - if (res.code === 200) { - this.eventsData = this.eventsData.splice(this.eventsData.indexOf(row), 1); - } - }); + this.$modal.confirm('确认要删除么?').then(() => { + delDeviceModeFunction(row.modeFunctionId).then(res => { + this.$modal.msgSuccess(res.msg); + if (res.code === 200) { + this.eventsData = this.eventsData.splice(this.eventsData.indexOf(row), 1); + } + }); + }) } else { this.eventsData = this.eventsData.splice(this.eventsData.indexOf(row), 1); } diff --git a/ruoyi-ui/src/views/business/deviceMode/deviceModeService.vue b/ruoyi-ui/src/views/business/deviceMode/deviceModeService.vue index 8397bb1..123ce7c 100644 --- a/ruoyi-ui/src/views/business/deviceMode/deviceModeService.vue +++ b/ruoyi-ui/src/views/business/deviceMode/deviceModeService.vue @@ -403,12 +403,14 @@ export default { const servicesData = this.servicesData; if (row.modeFunctionId !== undefined) { - delDeviceModeFunction(row.modeFunctionId).then(res => { - this.$modal.msgSuccess(res.msg); - if (res.code === 200) { - this.servicesData = servicesData.splice(servicesData.indexOf(row), 1); - } - }); + this.$modal.confirm('确认要删除么?').then(() => { + delDeviceModeFunction(row.modeFunctionId).then(res => { + this.$modal.msgSuccess(res.msg); + if (res.code === 200) { + this.servicesData = servicesData.splice(servicesData.indexOf(row), 1); + } + }); + }) } else { this.servicesData = servicesData.splice(servicesData.indexOf(row), 1); } diff --git a/ruoyi-ui/src/views/business/deviceMode/editDeviceMode.vue b/ruoyi-ui/src/views/business/deviceMode/editDeviceMode.vue index d8ab798..b7c5655 100644 --- a/ruoyi-ui/src/views/business/deviceMode/editDeviceMode.vue +++ b/ruoyi-ui/src/views/business/deviceMode/editDeviceMode.vue @@ -260,11 +260,12 @@ - + - +