若依微服务1.5.5

tdengine:增加修改超级表字段nchar类型长度;增加innerauth
dataprocess:增加异常处理;根据tdengine的innerauth修改
business:监控平台获取历史数据,最新数据修改;设备模型修改和删除逻辑修改;设备模型可修改属性nchar类型长度。
dev 1.5.5
xins 12 months ago
parent 66e611796e
commit 36c11cc52b

@ -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<List<Map<String, Object>>> getLatestDataByTags(@Validated @RequestBody TdSuperTableSelectVo tdSuperTableSelectVo);
R<List<Map<String, Object>>> getLatestDataByTags(@Validated @RequestBody TdSuperTableSelectVo tdSuperTableSelectVo, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
@PostMapping("/tdengine/getHistoryData")
R<TdReturnDataVo> getHistoryData(@Validated @RequestBody TdHistorySelectDto tdHistorySelectDto);
R<TdReturnDataVo> 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);
}

@ -28,67 +28,72 @@ public class RemoteTdEngineFallbackFactory implements FallbackFactory<RemoteTdEn
public RemoteTdEngineService create(Throwable throwable) {
return new RemoteTdEngineService() {
@Override
public R<?> 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<List<Map<String, Object>>> getLatestDataByTags(TdSuperTableSelectVo tdSuperTableSelectVo) {
public R<List<Map<String, Object>>> getLatestDataByTags(TdSuperTableSelectVo tdSuperTableSelectVo, String source) {
return R.fail("根据tags获取超级表最新数据失败:" + throwable.getMessage());
}
@Override
public R<TdReturnDataVo> getHistoryData(TdHistorySelectDto tdHistorySelectDto) {
public R<TdReturnDataVo> 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());
}

@ -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;
}
/**

@ -65,5 +65,10 @@ public enum BusinessType
/**
*
*/
CONTROL
CONTROL,
/**
*
*/
REBUILD
}

@ -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();
}
}

@ -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();
}
}

@ -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<HwScene> hwScenes = hwSceneService.selectHwSceneBySceneModeId(sceneModeId);
// return getDataTable(hwScenes);
// }
//
/**
*
*/

@ -23,6 +23,8 @@ public class HwDeviceVo {
private String deviceName;
private Long deviceModeId;
private String devicePic;
private Map<String, Object> deviceDataMap;//监测数据
private HwDeviceModeFunction deviceModeFunction;

@ -117,4 +117,12 @@ public interface IHwDeviceModeService
* @return List<HwDeviceModeFunction>
*/
public List<HwDeviceModeFunction> selectHwDeviceModeFunctionList(HwDeviceModeFunction hwDeviceModeFunction);
/**
* @description
* @author xins
* @date 2023-10-10 20:03
*/
public void rebuildTdSuperTables();
}

@ -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();
}

@ -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<HwDevice> hwDevices = hwDeviceMapper.selectHwDeviceList(queryHwDevice);
if (hwDevices.size() > 0) {
throw new ServiceException("此设备模型已存在设备,不能修改");
}
//校验有没有重复标识符
checkDuplicateIdentifiers(hwDeviceModeFunction);
hwDeviceModeMapper.deleteHwDeviceModeParameterByModeFunctionId(hwDeviceModeFunction.getModeFunctionId());
List<HwDeviceModeFunction> 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<HwDeviceModeFunction> 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<HwDevice> 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<HwDeviceModeFunction>
* @param: hwDeviceModeFunction
* @description
* @author xins
* @date 2023-10-10 11:19
* @return List<HwDeviceModeFunction>
*/
@Override
public List<HwDeviceModeFunction> 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<HwDeviceMode> deviceModes = hwDeviceModeMapper.selectHwDeviceModeList(queryDeviceMode);
deviceModes.forEach(deviceMode -> {
HwDeviceModeFunction hwDeviceModeFunction = new HwDeviceModeFunction();
hwDeviceModeFunction.setDeviceModeId(deviceMode.getDeviceModeId());
List<HwDeviceModeFunction> 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<TdField> tagFields = new ArrayList<TdField>();
@ -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());
}
}
}
}

@ -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<String, List<HwDeviceVo>> devicesMap = new HashMap<String, List<HwDeviceVo>>();
List<HwDeviceVo> controlDeviceVos = new ArrayList<HwDeviceVo>();
List<HwDeviceVo> acquisitionDeviceVos = new ArrayList<HwDeviceVo>();
Long sceneId = queryHwDevice.getSceneId();
String databaseName = TdEngineConstants.getDatabaseName(sceneId);
String databaseName = TdEngineConstants.getDatabaseName();
queryHwDevice.setDeviceType(HwDictConstants.DEVICE_TYPE_GATEWAY_SUB_EQUIPMENT);
List<HwDevice> 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<Map<String, Object>> deviceLatestDataMapList =
(List<Map<String, Object>>) this.remoteTdEngineService.getLatestData(tdSelectDto).getData();
(List<Map<String, Object>>) this.remoteTdEngineService.getLatestData(tdSelectDto, SecurityConstants.INNER).getData();
//获取此设备模型的功能列表
@ -437,8 +439,16 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
//转换成mapkey为标识符value为功能名称主要tdengine存的是标识符用来下面转换成功能名称
Map<String, String> functionIndentifierName = deviceModeFunctions.stream().collect(
Collectors.toMap(HwDeviceModeFunction::getFunctionIdentifier, HwDeviceModeFunction::getFunctionName));
Collectors.toMap(HwDeviceModeFunction::getFunctionIdentifier,
HwDeviceModeFunction::getFunctionName));
Map<String, String> 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<HwDeviceModeFunction> 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<String> 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<HwDevice> 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<Long, List<DeviceStatus>> groupDeviceStatuMapList =
(Map<Long, List<DeviceStatus>>) this.remoteTdEngineService.getOnlineDevicesGroupByDay(queryGroupStatus).getData();
(Map<Long, List<DeviceStatus>>) this.remoteTdEngineService.getOnlineDevicesGroupByDay(queryGroupStatus, SecurityConstants.INNER).getData();
if (groupDeviceStatuMapList == null) {
groupDeviceStatuMapList = new HashMap<>();
}
//获取在endtime之前最后的设备状态信息有些设备会一直在线没有连续的上线下线记录所以要获取最近的设备状态信息来补齐后面的设备在线情况
List<Map<String, Object>> lastDeviceStatuMapList =
(List<Map<String, Object>>) this.remoteTdEngineService.getLastOnlineDevices(queryLastStatus).getData();
(List<Map<String, Object>>) this.remoteTdEngineService.getLastOnlineDevices(queryLastStatus, SecurityConstants.INNER).getData();
if (lastDeviceStatuMapList == null || lastDeviceStatuMapList.isEmpty()) {
onlineDeviceCountByDay.put(startTime, 0);
} else {

@ -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<String, String> 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<TdField> schemaFieldValues = new ArrayList<TdField>();
List<HwDeviceModeFunction> 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<Map<String, Object>> latestDataMaps =
this.remoteTdEngineService.getLatestDataByTags(tdSuperTableSelectVo).getData();
this.remoteTdEngineService.getLatestDataByTags(tdSuperTableSelectVo, SecurityConstants.INNER).getData();
List<DeviceDataColumnVo> deviceDataColumnVos = new ArrayList<DeviceDataColumnVo>();
@ -94,11 +106,11 @@ public class HwMonitorPlatformServiceImpl implements IHwMonitorPlatformService {
for (Map.Entry<String, Object> 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<String, String> 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<String, String> 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<DeviceDataColumnVo> deviceDataColumnVos = new ArrayList<DeviceDataColumnVo>();
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);
}
}

@ -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());
// }
// }
/**
*

@ -98,6 +98,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<if test="deviceModeId != null "> and device_mode_id = #{deviceModeId}</if>
<if test="accessGwProtocol != null "> and access_gw_protocol = #{accessGwProtocol}</if>
<if test="activeStatus != null and activeStatus != ''"> and active_status = #{activeStatus}</if>
<if test="deviceStatus != null and deviceStatus != ''"> and device_status = #{deviceStatus}</if>
<if test="activeTime != null "> and active_time = #{activeTime}</if>
<if test="devicePic != null and devicePic != ''"> and device_pic = #{devicePic}</if>
<if test="ipAddress != null and ipAddress != ''"> and ip_address = #{ipAddress}</if>

@ -294,7 +294,7 @@
<select id="selectHwMonitorUnitJoinByMonitorUnitId" parameterType="Long" resultMap="HwMonitorUnitResult">
select hmu.monitor_unit_id,hmu.monitor_unit_name,hmu.monitor_unit_status,hmut.monitor_unit_type_name
select hmu.monitor_unit_id,hmu.monitor_unit_name,hmu.monitor_unit_status,hmut.monitor_unit_type_name,hmu.monitor_pic
from hw_monitor_unit hmu left join hw_monitor_unit_type hmut on hmu.monitor_unit_type_id=hmut.monitor_unit_type_id
where monitor_unit_id = #{monitorUnitId}
</select>

@ -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());
}
}
});

@ -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<TdField> 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<String, Object> 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;
}
/**
* keykeyvaluevalue1
*/
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<TdField> 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<String, Object> entry : dataValueJson.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
/**
* keykeyvaluevalue1
*/
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);
}
}

@ -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"));

@ -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<List<Map<String, Object>>> 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 {

@ -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

@ -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

@ -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

@ -166,6 +166,18 @@
</if>
</update>
<update id="modifySuperTableColumn">
ALTER STABLE #{databaseName}.#{superTableName} modify COLUMN
<if test="modifyFieldsVo.fieldName != null and modifyFieldsVo.fieldName != '' and modifyFieldsVo.size != null">
${modifyFieldsVo.fieldName} nchar(#{modifyFieldsVo.size})
</if>
</update>
<update id="dropSuperTableColumn">
ALTER STABLE #{databaseName}.#{superTableName} DROP COLUMN
<if test="dropField.fieldName != null and dropField.fieldName != ''">

@ -113,3 +113,11 @@ export function publishControlCommand(deviceId, type) {
data: data
})
}
// 重新生成tdengine所有表
export function rebuildTdTables() {
return request({
url: '/business/device/rebuildTdTables',
method: 'get'
})
}

@ -60,3 +60,11 @@ export function getEditedScenes(query) {
params: query
})
}
// 重新生成tdengine所有超级表
export function rebuildTdSuperTables() {
return request({
url: '/business/deviceMode/rebuildTdSuperTables',
method: 'get'
})
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

@ -109,11 +109,23 @@
>导出
</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="primary"
plain
icon="el-icon-plus"
size="mini"
@click="handleRebuildTdTables"
v-hasPermi="['business:device:rebuild']"
>重建表
</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<el-table v-loading="loading" :data="deviceList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center"/>
<el-table-column label="设备ID" align="center" prop="deviceId"/>
<el-table-column label="设备编号" align="center" prop="deviceCode"/>
<el-table-column label="设备名称" align="center" prop="deviceName"/>
<el-table-column label="设备类型" align="center" prop="deviceType">
@ -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(() => {
});
},
}
};

@ -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);
}

@ -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);
}

@ -260,11 +260,12 @@
<el-input v-model="form.functionName" placeholder="请输入功能名称" maxlength="30"/>
</el-form-item>
<el-form-item label="标识符" prop="functionIdentifier">
<el-input v-model="form.functionIdentifier" placeholder="请输入标识符" maxlength="20"/>
<el-input v-model="form.functionIdentifier" placeholder="请输入标识符" maxlength="20"
:disabled="editDisable"/>
</el-form-item>
<el-form-item label="数据类型" prop="dataType">
<el-select v-model="form.dataType" placeholder="请选择数据类型">
<el-select v-model="form.dataType" placeholder="请选择数据类型" :disabled="editDisable">
<el-option
v-for="dict in dict.type.hw_mode_function_data_type"
:key="dict.value"
@ -349,7 +350,7 @@
</template>
<script>
import {addDeviceMode, getDeviceMode, updateDeviceMode,getEditedScenes} from "@/api/business/deviceMode";
import {addDeviceMode, getDeviceMode, updateDeviceMode, getEditedScenes} from "@/api/business/deviceMode";
import deviceModeService from "./deviceModeService";
import deviceModeEvent from "./deviceModeEvent";
import {
@ -456,6 +457,7 @@ export default {
//
IDENTIFIER_LATITUDE: 'latitude',
editDisable: true,
//ID
deviceModeId: '',
//
@ -578,6 +580,7 @@ export default {
/** 新增属性按钮操作 */
handleAdd() {
this.reset();
this.editDisable = false;
this.open = true;
this.title = "添加设备模型属性";
},
@ -610,6 +613,7 @@ export default {
},
handleUpdateAttribute(row) {
// this.reset();
this.editDisable = true;
this.attributeDataIndex = this.attributesData.indexOf(row);
this.convertParameterDefinition(row);
this.form = JSON.parse(JSON.stringify(row));//
@ -629,12 +633,18 @@ export default {
handleDeleteAttribute(row) {
if (row.modeFunctionId !== undefined) {
delDeviceModeFunction(row.modeFunctionId).then(res => {
this.$modal.msgSuccess(res.msg);
if (res.code === 200) {
this.attributesData.splice(this.attributesData.indexOf(row), 1);
}
});
if (this.attributesData.length <= 1) {
this.$modal.msgWarning("最少一个属性");
return;
}
this.$modal.confirm('删除属性之前上报此属性的数据会清除,确认要删除么?').then(() => {
delDeviceModeFunction(row.modeFunctionId).then(res => {
this.$modal.msgSuccess(res.msg);
if (res.code === 200) {
this.attributesData.splice(this.attributesData.indexOf(row), 1);
}
});
})
} else {
this.attributesData.splice(this.attributesData.indexOf(row), 1);
}

@ -82,6 +82,17 @@
>导出
</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="primary"
plain
icon="el-icon-plus"
size="mini"
@click="handleRebuildTdSuperTables"
v-hasPermi="['business:deviceMode:rebuild']"
>重建超级表
</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
@ -134,7 +145,7 @@
</template>
<script>
import {listDeviceMode, getDeviceMode, delDeviceMode, addDeviceMode, updateDeviceMode,getScenes} from "@/api/business/deviceMode";
import {listDeviceMode, getDeviceMode, delDeviceMode, addDeviceMode, updateDeviceMode,getScenes,rebuildTdSuperTables} from "@/api/business/deviceMode";
import {getLanguages} from "@/api/basic/language";
export default {
@ -297,7 +308,6 @@ export default {
handleAdd() {
const params = {pageNum: this.queryParams.pageNum};
this.$tab.openPage("添加设备模型", '/deviceMode/mode-add/index', params);
},
/** 修改按钮操作 */
handleUpdate(row) {
@ -391,7 +401,17 @@ export default {
this.download('business/deviceMode/exportFunction', {
}, `deviceModeFunction_${new Date().getTime()}.xlsx`)
}
},
/** 重建超级表按钮操作 */
handleRebuildTdSuperTables() {
this.$modal.confirm('是否确认重建所有设备监测数据超级表?').then(function () {
return rebuildTdSuperTables();
}).then(() => {
this.$modal.msgSuccess("重建成功");
}).catch(() => {
});
},
}
};
</script>

Loading…
Cancel
Save