若依微服务1.5.5

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

@ -1,5 +1,6 @@
package com.ruoyi.tdengine.api; package com.ruoyi.tdengine.api;
import com.ruoyi.common.core.constant.SecurityConstants;
import com.ruoyi.common.core.constant.ServiceNameConstants; import com.ruoyi.common.core.constant.ServiceNameConstants;
import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.hw.validated.tdengine.AddTdSTableColumn; 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.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -18,41 +20,44 @@ import java.util.Map;
public interface RemoteTdEngineService { public interface RemoteTdEngineService {
@PostMapping("/tdengine/createDatabase") @PostMapping("/tdengine/createDatabase")
R<?> createDataBase(@RequestBody String databaseName); R<?> createDataBase(@RequestBody String databaseName, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
@PostMapping("/tdengine/createSuperTable") @PostMapping("/tdengine/createSuperTable")
R<?> createSuperTable(@Validated @RequestBody TdSuperTableVo tdSuperTableVo); R<?> createSuperTable(@Validated @RequestBody TdSuperTableVo tdSuperTableVo, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
@PostMapping("/tdengine/createTable") @PostMapping("/tdengine/createTable")
R<?> createTable(@Validated @RequestBody TdTableVo tdTableVo); R<?> createTable(@Validated @RequestBody TdTableVo tdTableVo, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
@PostMapping("/tdengine/addSuperTableColumn") @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") @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") @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") @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") @PostMapping("/tdengine/getLatestData")
R<?> getLatestData(@Validated @RequestBody TdSelectDto tdSelectDto); R<?> getLatestData(@Validated @RequestBody TdSelectDto tdSelectDto, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
@PostMapping("/tdengine/getLatestDataByTags") @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") @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") @PostMapping("/tdengine/getCountOfHistoryData")
R<?> getCountOfHistoryData(@Validated @RequestBody TdHistorySelectDto tdHistorySelectDto); R<?> getCountOfHistoryData(@Validated @RequestBody TdHistorySelectDto tdHistorySelectDto, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
@PostMapping("/tdengine/getOnlineDevicesGroupByDay") @PostMapping("/tdengine/getOnlineDevicesGroupByDay")
R<?> getOnlineDevicesGroupByDay(@Validated @RequestBody DeviceStatus queryDeviceStatus); R<?> getOnlineDevicesGroupByDay(@Validated @RequestBody DeviceStatus queryDeviceStatus, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
@PostMapping("/tdengine/getLastOnlineDevices") @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) { public RemoteTdEngineService create(Throwable throwable) {
return new RemoteTdEngineService() { return new RemoteTdEngineService() {
@Override @Override
public R<?> createDataBase(String databaseName) { public R<?> createDataBase(String databaseName, String source) {
return R.fail("创建数据库失败:" + throwable.getMessage()); return R.fail("创建数据库失败:" + throwable.getMessage());
} }
@Override @Override
public R<?> createSuperTable(TdSuperTableVo tdSuperTableVo) { public R<?> createSuperTable(TdSuperTableVo tdSuperTableVo, String source) {
return R.fail("创建超级表失败:" + throwable.getMessage()); return R.fail("创建超级表失败:" + throwable.getMessage());
} }
@Override @Override
public R<?> createTable(TdTableVo tdTableVo) { public R<?> createTable(TdTableVo tdTableVo, String source) {
return R.fail("创建子表失败:" + throwable.getMessage()); return R.fail("创建子表失败:" + throwable.getMessage());
} }
@Override @Override
public R<?> addSuperTableColumn(TdSuperTableVo tdSuperTableVo) { public R<?> addSuperTableColumn(TdSuperTableVo tdSuperTableVo, String source) {
return R.fail("添加超级表Column失败:" + throwable.getMessage()); return R.fail("添加超级表Column失败:" + throwable.getMessage());
} }
@Override @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()); return R.fail("删除超级表Column失败:" + throwable.getMessage());
} }
@Override @Override
public R<?> alterTableTag(AlterTagVo alterTagVo) { public R<?> alterTableTag(AlterTagVo alterTagVo, String source) {
return R.fail("修改子表tag值失败:" + throwable.getMessage()); return R.fail("修改子表tag值失败:" + throwable.getMessage());
} }
@Override @Override
public R<?> insertTable(TdTableVo tdTableVo) { public R<?> insertTable(TdTableVo tdTableVo, String source) {
return R.fail("插入数据失败:" + throwable.getMessage()); return R.fail("插入数据失败:" + throwable.getMessage());
} }
@Override @Override
public R<?> getLatestData(TdSelectDto tdSelectDto) { public R<?> getLatestData(TdSelectDto tdSelectDto, String source) {
return R.fail("获取子表最新数据失败:" + throwable.getMessage()); return R.fail("获取子表最新数据失败:" + throwable.getMessage());
} }
@Override @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()); return R.fail("根据tags获取超级表最新数据失败:" + throwable.getMessage());
} }
@Override @Override
public R<TdReturnDataVo> getHistoryData(TdHistorySelectDto tdHistorySelectDto) { public R<TdReturnDataVo> getHistoryData(TdHistorySelectDto tdHistorySelectDto, String source) {
return R.fail("获取历史数据失败:" + throwable.getMessage()); return R.fail("获取历史数据失败:" + throwable.getMessage());
} }
@Override @Override
public R<?> getCountOfHistoryData(TdHistorySelectDto tdHistorySelectDto) { public R<?> getCountOfHistoryData(TdHistorySelectDto tdHistorySelectDto, String source) {
return R.fail("获取历史数据数量失败:" + throwable.getMessage()); return R.fail("获取历史数据数量失败:" + throwable.getMessage());
} }
@Override @Override
public R<?> getOnlineDevicesGroupByDay(DeviceStatus queryDeviceStatus) { public R<?> getOnlineDevicesGroupByDay(DeviceStatus queryDeviceStatus, String source) {
return R.fail("获取设备状态失败:" + throwable.getMessage()); return R.fail("获取设备状态失败:" + throwable.getMessage());
} }
@Override @Override
public R<?> getLastOnlineDevices(DeviceStatus queryDeviceStatus) { public R<?> getLastOnlineDevices(DeviceStatus queryDeviceStatus, String source) {
return R.fail("获取最近设备状态失败:" + throwable.getMessage()); 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 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_SUPER_TABLE_NAME_PREFIX = "st_devicemode_";//超级表名称前缀
public static final String DEFAULT_TABLE_NAME_PREFIX = "t_device_";//数据表名称前缀 public static final String DEFAULT_TABLE_NAME_PREFIX = "t_device_";//数据表名称前缀
@ -85,8 +85,8 @@ public class TdEngineConstants {
* @author xins * @author xins
* @date 2023-09-05 9:42 * @date 2023-09-05 9:42
*/ */
public static String getDatabaseName(Long sceneId) { public static String getDatabaseName() {
return DEFAULT_DB_NAME_PREFIX + sceneId; 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) { public void computeOnlineDevicecCount(@PathVariable("days") int days) {
hwDeviceService.computeOnlineDevicecCount(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)); 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)); 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 String deviceName;
private Long deviceModeId; private Long deviceModeId;
private String devicePic;
private Map<String, Object> deviceDataMap;//监测数据 private Map<String, Object> deviceDataMap;//监测数据
private HwDeviceModeFunction deviceModeFunction; private HwDeviceModeFunction deviceModeFunction;

@ -117,4 +117,12 @@ public interface IHwDeviceModeService
* @return List<HwDeviceModeFunction> * @return List<HwDeviceModeFunction>
*/ */
public List<HwDeviceModeFunction> selectHwDeviceModeFunctionList(HwDeviceModeFunction 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 * @return DevicesInfoVo
*/ */
public DevicesInfoVo getDevicesInfoByMonitorUnitId(Long monitorUnitId); 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.business.service.IHwDeviceModeService;
import com.ruoyi.common.core.constant.Constants; import com.ruoyi.common.core.constant.Constants;
import com.ruoyi.common.core.constant.HwDictConstants; 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.constant.TdEngineConstants;
import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.enums.DataTypeEnums; import com.ruoyi.common.core.enums.DataTypeEnums;
@ -257,23 +258,9 @@ public class HwDeviceModeServiceImpl implements IHwDeviceModeService {
@Override @Override
@Transactional @Transactional
public int updateHwDeviceModeFunction(HwDeviceModeFunction hwDeviceModeFunction) { 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); checkDuplicateIdentifiers(hwDeviceModeFunction);
hwDeviceModeMapper.deleteHwDeviceModeParameterByModeFunctionId(hwDeviceModeFunction.getModeFunctionId());
List<HwDeviceModeFunction> hwDeviceModeFunctions = new ArrayList<>();
hwDeviceModeFunctions.add(hwDeviceModeFunction);
batchInsertHwDeviceModeParameters(hwDeviceModeFunctions);
//与数据库中的数据判断标识符有没有修改如果修改则在tdengine超级表删除老的字段增加修改的字段 //与数据库中的数据判断标识符有没有修改如果修改则在tdengine超级表删除老的字段增加修改的字段
String functionMode = hwDeviceModeFunction.getFunctionMode(); String functionMode = hwDeviceModeFunction.getFunctionMode();
if (functionMode.equals(HwDictConstants.FUNCTION_MODE_ATTRIBUTE)) { if (functionMode.equals(HwDictConstants.FUNCTION_MODE_ATTRIBUTE)) {
@ -284,14 +271,28 @@ public class HwDeviceModeServiceImpl implements IHwDeviceModeService {
String functionIdentifier = hwDeviceModeFunction.getFunctionIdentifier(); String functionIdentifier = hwDeviceModeFunction.getFunctionIdentifier();
Long dbDataType = dbHwDeviceModeFunction.getDataType(); Long dbDataType = dbHwDeviceModeFunction.getDataType();
Long dataType = hwDeviceModeFunction.getDataType(); Long dataType = hwDeviceModeFunction.getDataType();
//标识符或数据类型变化时需要先删除超级表column再增加新的column //标识符或数据类型变化时需要先删除超级表column再增加新的column,删除的column数据将会清空(有事务问题,暂时不支持)
if (!dbFunctionIdentifier.equalsIgnoreCase(functionIdentifier) if (!dbFunctionIdentifier.equalsIgnoreCase(functionIdentifier)
|| !dbDataType.equals(dataType)) { || !dbDataType.equals(dataType)) {
this.dropTdSuperTableColumn(dbHwDeviceModeFunction); // this.dropTdSuperTableColumn(dbHwDeviceModeFunction);
this.addTdSuperTableColumn(hwDeviceModeFunction); // this.addTdSuperTableColumn(hwDeviceModeFunction);
}else{ throw new RuntimeException("标识符和数据类型不支持修改,可删除再新建");
//todo:修改tdengine字符串长度 } 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); return hwDeviceModeMapper.updateHwDeviceModeFunction(hwDeviceModeFunction);
@ -307,6 +308,15 @@ public class HwDeviceModeServiceImpl implements IHwDeviceModeService {
@Transactional @Transactional
public int deleteHwDeviceModeFunctionByModeFunctionId(Long modeFunctionId) { public int deleteHwDeviceModeFunctionByModeFunctionId(Long modeFunctionId) {
HwDeviceModeFunction hwDeviceModeFunction = hwDeviceModeFunctionMapper.selectHwDeviceModeFunctionByModeFunctionId(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); hwDeviceModeMapper.deleteHwDeviceModeParameterByModeFunctionId(modeFunctionId);
int rows = hwDeviceModeMapper.deleteHwDeviceModeFunctionByModeFunctionId(modeFunctionId); int rows = hwDeviceModeMapper.deleteHwDeviceModeFunctionByModeFunctionId(modeFunctionId);
this.dropTdSuperTableColumn(hwDeviceModeFunction); this.dropTdSuperTableColumn(hwDeviceModeFunction);
@ -342,16 +352,37 @@ public class HwDeviceModeServiceImpl implements IHwDeviceModeService {
} }
/** /**
* @return List<HwDeviceModeFunction>
* @param: hwDeviceModeFunction * @param: hwDeviceModeFunction
* @description * @description
* @author xins * @author xins
* @date 2023-10-10 11:19 * @date 2023-10-10 11:19
* @return List<HwDeviceModeFunction>
*/ */
@Override @Override
public List<HwDeviceModeFunction> selectHwDeviceModeFunctionList(HwDeviceModeFunction hwDeviceModeFunction) { public List<HwDeviceModeFunction> selectHwDeviceModeFunctionList(HwDeviceModeFunction hwDeviceModeFunction) {
return hwDeviceModeFunctionMapper.selectHwDeviceModeFunctionList(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 * @param: hwDeviceModeFunction
* @description * @description
@ -394,8 +425,7 @@ public class HwDeviceModeServiceImpl implements IHwDeviceModeService {
private void createTdSuperTable(HwDeviceMode hwDeviceMode) { private void createTdSuperTable(HwDeviceMode hwDeviceMode) {
TdSuperTableVo tdSuperTableVo = new TdSuperTableVo(); TdSuperTableVo tdSuperTableVo = new TdSuperTableVo();
Long sceneId = hwDeviceMode.getSceneId(); String dbName = TdEngineConstants.getDatabaseName();
String dbName = TdEngineConstants.DEFAULT_DB_NAME_PREFIX + sceneId;
String superTableName = TdEngineConstants.DEFAULT_SUPER_TABLE_NAME_PREFIX + hwDeviceMode.getDeviceModeId(); String superTableName = TdEngineConstants.DEFAULT_SUPER_TABLE_NAME_PREFIX + hwDeviceMode.getDeviceModeId();
List<TdField> tagFields = new ArrayList<TdField>(); List<TdField> tagFields = new ArrayList<TdField>();
@ -451,18 +481,17 @@ public class HwDeviceModeServiceImpl implements IHwDeviceModeService {
tdSuperTableVo.setSchemaFields(schemaFields); tdSuperTableVo.setSchemaFields(schemaFields);
tdSuperTableVo.setTagsFields(tagFields); tdSuperTableVo.setTagsFields(tagFields);
R<?> tdReturnMsg = this.remoteTdEngineService.createSuperTable(tdSuperTableVo); R<?> tdReturnMsg = this.remoteTdEngineService.createSuperTable(tdSuperTableVo, SecurityConstants.INNER);
if(tdReturnMsg.getCode() != Constants.SUCCESS){//抛出异常,回滚事务 if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务
throw new RuntimeException(tdReturnMsg.getMsg()); throw new RuntimeException(tdReturnMsg.getMsg());
} }
} }
private void addTdSuperTableColumn(HwDeviceModeFunction hwDeviceModeFunction) { private void modifyTdSuperTableColumn(HwDeviceModeFunction hwDeviceModeFunction) {
String functionMode = hwDeviceModeFunction.getFunctionMode(); String functionMode = hwDeviceModeFunction.getFunctionMode();
if (functionMode.equals(HwDictConstants.FUNCTION_MODE_ATTRIBUTE)) { if (functionMode.equals(HwDictConstants.FUNCTION_MODE_ATTRIBUTE)) {
Long deviceModeId = hwDeviceModeFunction.getDeviceModeId(); Long deviceModeId = hwDeviceModeFunction.getDeviceModeId();
HwDeviceMode hwDeviceMode = hwDeviceModeMapper.selectHwDeviceModeByDeviceModeId(deviceModeId); String dbName = TdEngineConstants.getDatabaseName();
String dbName = TdEngineConstants.DEFAULT_DB_NAME_PREFIX + hwDeviceMode.getSceneId();
String superTableName = TdEngineConstants.DEFAULT_SUPER_TABLE_NAME_PREFIX + deviceModeId; String superTableName = TdEngineConstants.DEFAULT_SUPER_TABLE_NAME_PREFIX + deviceModeId;
TdSuperTableVo tdSuperTableVo = new TdSuperTableVo(); TdSuperTableVo tdSuperTableVo = new TdSuperTableVo();
TdField schemaField = new TdField(); TdField schemaField = new TdField();
@ -478,19 +507,46 @@ public class HwDeviceModeServiceImpl implements IHwDeviceModeService {
tdSuperTableVo.setDatabaseName(dbName); tdSuperTableVo.setDatabaseName(dbName);
tdSuperTableVo.setSuperTableName(superTableName); tdSuperTableVo.setSuperTableName(superTableName);
tdSuperTableVo.setField(schemaField); tdSuperTableVo.setField(schemaField);
R<?> tdReturnMsg = this.remoteTdEngineService.addSuperTableColumn(tdSuperTableVo); R<?> tdReturnMsg = this.remoteTdEngineService.modifySuperTableColumn(tdSuperTableVo, SecurityConstants.INNER);
if(tdReturnMsg.getCode() != Constants.SUCCESS){//抛出异常,回滚事务 if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务
throw new RuntimeException(tdReturnMsg.getMsg()); 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();
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.addSuperTableColumn(tdSuperTableVo, SecurityConstants.INNER);
if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务
throw new RuntimeException(tdReturnMsg.getMsg());
}
}
}
private void dropTdSuperTableColumn(HwDeviceModeFunction hwDeviceModeFunction) { private void dropTdSuperTableColumn(HwDeviceModeFunction hwDeviceModeFunction) {
String functionMode = hwDeviceModeFunction.getFunctionMode(); String functionMode = hwDeviceModeFunction.getFunctionMode();
if (functionMode.equals(HwDictConstants.FUNCTION_MODE_ATTRIBUTE)) { if (functionMode.equals(HwDictConstants.FUNCTION_MODE_ATTRIBUTE)) {
Long deviceModeId = hwDeviceModeFunction.getDeviceModeId(); Long deviceModeId = hwDeviceModeFunction.getDeviceModeId();
HwDeviceMode hwDeviceMode = hwDeviceModeMapper.selectHwDeviceModeByDeviceModeId(deviceModeId); String dbName = TdEngineConstants.getDatabaseName();
String dbName = TdEngineConstants.DEFAULT_DB_NAME_PREFIX + hwDeviceMode.getSceneId();
String superTableName = TdEngineConstants.DEFAULT_SUPER_TABLE_NAME_PREFIX + deviceModeId; String superTableName = TdEngineConstants.DEFAULT_SUPER_TABLE_NAME_PREFIX + deviceModeId;
TdSuperTableVo tdSuperTableVo = new TdSuperTableVo(); TdSuperTableVo tdSuperTableVo = new TdSuperTableVo();
TdField schemaField = new TdField(); TdField schemaField = new TdField();
@ -499,11 +555,12 @@ public class HwDeviceModeServiceImpl implements IHwDeviceModeService {
tdSuperTableVo.setSuperTableName(superTableName); tdSuperTableVo.setSuperTableName(superTableName);
tdSuperTableVo.setField(schemaField); tdSuperTableVo.setField(schemaField);
R<?> tdReturnMsg =this.remoteTdEngineService.dropColumnForSuperTable(tdSuperTableVo); R<?> tdReturnMsg = this.remoteTdEngineService.dropColumnForSuperTable(tdSuperTableVo, SecurityConstants.INNER);
if(tdReturnMsg.getCode() != Constants.SUCCESS){//抛出异常,回滚事务 if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务
throw new RuntimeException(tdReturnMsg.getMsg()); throw new RuntimeException(tdReturnMsg.getMsg());
} }
} }
} }
} }

@ -12,6 +12,7 @@ import com.ruoyi.business.mapper.*;
import com.ruoyi.business.service.IHwDeviceService; import com.ruoyi.business.service.IHwDeviceService;
import com.ruoyi.common.core.constant.Constants; import com.ruoyi.common.core.constant.Constants;
import com.ruoyi.common.core.constant.HwDictConstants; 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.constant.TdEngineConstants;
import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.enums.DataTypeEnums; import com.ruoyi.common.core.enums.DataTypeEnums;
@ -193,7 +194,7 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
*/ */
private void createTdTable(HwDevice hwDevice) { private void createTdTable(HwDevice hwDevice) {
TdTableVo tdTableVo = new TdTableVo(); TdTableVo tdTableVo = new TdTableVo();
String databaseName = TdEngineConstants.getDatabaseName(hwDevice.getSceneId()); String databaseName = TdEngineConstants.getDatabaseName();
String superTableName = TdEngineConstants.getSuperTableName(hwDevice.getDeviceModeId()); String superTableName = TdEngineConstants.getSuperTableName(hwDevice.getDeviceModeId());
String tableName = TdEngineConstants.getDeviceDataTableName(hwDevice.getDeviceId()); String tableName = TdEngineConstants.getDeviceDataTableName(hwDevice.getDeviceId());
@ -204,7 +205,7 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
tdTableVo.setTableName(tableName); tdTableVo.setTableName(tableName);
tdTableVo.setTagsFieldValues(tagsFields); tdTableVo.setTagsFieldValues(tagsFields);
R<?> tdReturnMsg = this.remoteTdEngineService.createTable(tdTableVo); R<?> tdReturnMsg = this.remoteTdEngineService.createTable(tdTableVo, SecurityConstants.INNER);
if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务 if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务
throw new RuntimeException(tdReturnMsg.getMsg()); throw new RuntimeException(tdReturnMsg.getMsg());
} }
@ -225,7 +226,7 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
tdTableVo.setTagsFieldValues(tagsFields); tdTableVo.setTagsFieldValues(tagsFields);
R<?> tdReturnMsg = this.remoteTdEngineService.createTable(tdTableVo); R<?> tdReturnMsg = this.remoteTdEngineService.createTable(tdTableVo, SecurityConstants.INNER);
if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务 if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务
throw new RuntimeException(tdReturnMsg.getMsg()); throw new RuntimeException(tdReturnMsg.getMsg());
} }
@ -390,8 +391,7 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
Map<String, List<HwDeviceVo>> devicesMap = new HashMap<String, List<HwDeviceVo>>(); Map<String, List<HwDeviceVo>> devicesMap = new HashMap<String, List<HwDeviceVo>>();
List<HwDeviceVo> controlDeviceVos = new ArrayList<HwDeviceVo>(); List<HwDeviceVo> controlDeviceVos = new ArrayList<HwDeviceVo>();
List<HwDeviceVo> acquisitionDeviceVos = new ArrayList<HwDeviceVo>(); List<HwDeviceVo> acquisitionDeviceVos = new ArrayList<HwDeviceVo>();
Long sceneId = queryHwDevice.getSceneId(); String databaseName = TdEngineConstants.getDatabaseName();
String databaseName = TdEngineConstants.getDatabaseName(sceneId);
queryHwDevice.setDeviceType(HwDictConstants.DEVICE_TYPE_GATEWAY_SUB_EQUIPMENT); queryHwDevice.setDeviceType(HwDictConstants.DEVICE_TYPE_GATEWAY_SUB_EQUIPMENT);
List<HwDevice> hwDevices = hwDeviceMapper.selectHwDeviceList(queryHwDevice); List<HwDevice> hwDevices = hwDeviceMapper.selectHwDeviceList(queryHwDevice);
@ -411,7 +411,9 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
deviceModeFunctions.forEach(mf -> { deviceModeFunctions.forEach(mf -> {
if (mf.getFunctionMode().equals(HwDictConstants.FUNCTION_MODE_ATTRIBUTE)) { if (mf.getFunctionMode().equals(HwDictConstants.FUNCTION_MODE_ATTRIBUTE)) {
TdField field = new TdField(); 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); schemaFieldValues.add(field);
} else if (mf.getFunctionMode().equals(HwDictConstants.FUNCTION_MODE_SERVICE)) { } else if (mf.getFunctionMode().equals(HwDictConstants.FUNCTION_MODE_SERVICE)) {
modeFunctions.add(mf); modeFunctions.add(mf);
@ -421,7 +423,7 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
tdSelectDto.setSchemaFieldValues(schemaFieldValues); tdSelectDto.setSchemaFieldValues(schemaFieldValues);
//从tdengine获取此设备的最新数据 //从tdengine获取此设备的最新数据
List<Map<String, Object>> deviceLatestDataMapList = 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存的是标识符用来下面转换成功能名称 //转换成mapkey为标识符value为功能名称主要tdengine存的是标识符用来下面转换成功能名称
Map<String, String> functionIndentifierName = deviceModeFunctions.stream().collect( 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() // List<HwDeviceModeFunction> modeFunctions = deviceModeFunctions.stream()
// .filter(dmf -> dmf.getFunctionMode().equals(HwDictConstants.FUNCTION_MODE_SERVICE) // .filter(dmf -> dmf.getFunctionMode().equals(HwDictConstants.FUNCTION_MODE_SERVICE)
@ -451,6 +461,7 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
hwDeviceVo.setDeviceType(HwDictConstants.CONTROL_DEVICE); hwDeviceVo.setDeviceType(HwDictConstants.CONTROL_DEVICE);
hwDeviceVo.setDeviceCode(hwDevice.getDeviceCode()); hwDeviceVo.setDeviceCode(hwDevice.getDeviceCode());
hwDeviceVo.setDeviceName(hwDevice.getDeviceName()); hwDeviceVo.setDeviceName(hwDevice.getDeviceName());
hwDeviceVo.setDevicePic(hwDevice.getDevicePic());
hwDeviceVo.setDeviceModeFunction(modeFunction); hwDeviceVo.setDeviceModeFunction(modeFunction);
controlDeviceVos.add(hwDeviceVo); controlDeviceVos.add(hwDeviceVo);
}); });
@ -462,12 +473,11 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
deviceLatestDataMapList.forEach(deviceLatestDataMap -> { deviceLatestDataMapList.forEach(deviceLatestDataMap -> {
Set<String> functionIdentifiers = deviceLatestDataMap.keySet(); Set<String> functionIdentifiers = deviceLatestDataMap.keySet();
for (String dataFunctionIdentifier : functionIdentifiers) { for (String dataFunctionIdentifier : functionIdentifiers) {
if (functionIndentifierName.get(dataFunctionIdentifier) != null) { if (functionIndentifierNameMap.get(dataFunctionIdentifier) != null) {
ddValueMap.put(functionIndentifierName.get(dataFunctionIdentifier), ddValueMap.put(functionIndentifierNameMap.get(dataFunctionIdentifier),
deviceLatestDataMap.get(dataFunctionIdentifier)); deviceLatestDataMap.get(dataFunctionIdentifier));
} }
} }
}); });
} }
//不论是否是控制型设备都显示最新数据 //不论是否是控制型设备都显示最新数据
@ -609,11 +619,11 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
} }
/** /**
* @return DevicesInfoVo
* @param: monitorUnitId * @param: monitorUnitId
* @description ID线线 * @description ID线线
* @author xins * @author xins
* @date 2023-09-28 14:25 * @date 2023-09-28 14:25
* @return DevicesInfoVo
*/ */
@Override @Override
public DevicesInfoVo getDevicesInfoByMonitorUnitId(Long monitorUnitId) { public DevicesInfoVo getDevicesInfoByMonitorUnitId(Long monitorUnitId) {
@ -655,6 +665,21 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
return devicesInfoVo; 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: hwDevice
* @param: dbDevice * @param: dbDevice
@ -664,7 +689,7 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
*/ */
private void updateTdEngine(HwDevice hwDevice, HwDevice dbDevice) { private void updateTdEngine(HwDevice hwDevice, HwDevice dbDevice) {
String deviceType = hwDevice.getDeviceType(); String deviceType = hwDevice.getDeviceType();
String databaseName = TdEngineConstants.getDatabaseName(hwDevice.getSceneId()); String databaseName = TdEngineConstants.getDatabaseName();
String tableName = TdEngineConstants.getDeviceDataTableName(hwDevice.getDeviceId()); String tableName = TdEngineConstants.getDeviceDataTableName(hwDevice.getDeviceId());
AlterTagVo alterTagVo = new AlterTagVo(); AlterTagVo alterTagVo = new AlterTagVo();
alterTagVo.setDatabaseName(databaseName); alterTagVo.setDatabaseName(databaseName);
@ -676,7 +701,7 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
alterTagVo.setTagName(TdEngineConstants.ST_TAG_DEVICECODE); alterTagVo.setTagName(TdEngineConstants.ST_TAG_DEVICECODE);
alterTagVo.setTagValue("'" + hwDevice.getDeviceCode() + "'"); alterTagVo.setTagValue("'" + hwDevice.getDeviceCode() + "'");
tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo); tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo, SecurityConstants.INNER);
if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务 if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务
throw new RuntimeException(tdReturnMsg.getMsg()); throw new RuntimeException(tdReturnMsg.getMsg());
} }
@ -684,7 +709,7 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
if (!hwDevice.getDeviceName().equals(dbDevice.getDeviceName())) { if (!hwDevice.getDeviceName().equals(dbDevice.getDeviceName())) {
alterTagVo.setTagName(TdEngineConstants.ST_TAG_DEVICENAME); alterTagVo.setTagName(TdEngineConstants.ST_TAG_DEVICENAME);
alterTagVo.setTagValue("'" + hwDevice.getDeviceName() + "'"); alterTagVo.setTagValue("'" + hwDevice.getDeviceName() + "'");
tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo); tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo, SecurityConstants.INNER);
if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务 if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务
throw new RuntimeException(tdReturnMsg.getMsg()); throw new RuntimeException(tdReturnMsg.getMsg());
} }
@ -693,7 +718,7 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
if (!hwDevice.getMonitorUnitId().equals(dbDevice.getMonitorUnitId())) { if (!hwDevice.getMonitorUnitId().equals(dbDevice.getMonitorUnitId())) {
alterTagVo.setTagName(TdEngineConstants.ST_TAG_MONITORUNITID); alterTagVo.setTagName(TdEngineConstants.ST_TAG_MONITORUNITID);
alterTagVo.setTagValue(hwDevice.getMonitorUnitId()); alterTagVo.setTagValue(hwDevice.getMonitorUnitId());
tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo); tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo, SecurityConstants.INNER);
if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务 if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务
throw new RuntimeException(tdReturnMsg.getMsg()); throw new RuntimeException(tdReturnMsg.getMsg());
} }
@ -702,7 +727,7 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
if (!hwDevice.getDeviceModeId().equals(dbDevice.getDeviceModeId())) { if (!hwDevice.getDeviceModeId().equals(dbDevice.getDeviceModeId())) {
alterTagVo.setTagName(TdEngineConstants.ST_TAG_DEVICEMODEID); alterTagVo.setTagName(TdEngineConstants.ST_TAG_DEVICEMODEID);
alterTagVo.setTagValue(hwDevice.getDeviceModeId()); alterTagVo.setTagValue(hwDevice.getDeviceModeId());
tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo); tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo, SecurityConstants.INNER);
if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务 if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务
throw new RuntimeException(tdReturnMsg.getMsg()); throw new RuntimeException(tdReturnMsg.getMsg());
} }
@ -737,14 +762,14 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
//先获取starttime和endtime时间范围内在线的设备状态信息 //先获取starttime和endtime时间范围内在线的设备状态信息
Map<Long, List<DeviceStatus>> groupDeviceStatuMapList = 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) { if (groupDeviceStatuMapList == null) {
groupDeviceStatuMapList = new HashMap<>(); groupDeviceStatuMapList = new HashMap<>();
} }
//获取在endtime之前最后的设备状态信息有些设备会一直在线没有连续的上线下线记录所以要获取最近的设备状态信息来补齐后面的设备在线情况 //获取在endtime之前最后的设备状态信息有些设备会一直在线没有连续的上线下线记录所以要获取最近的设备状态信息来补齐后面的设备在线情况
List<Map<String, Object>> lastDeviceStatuMapList = 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()) { if (lastDeviceStatuMapList == null || lastDeviceStatuMapList.isEmpty()) {
onlineDeviceCountByDay.put(startTime, 0); onlineDeviceCountByDay.put(startTime, 0);
} else { } else {

@ -8,6 +8,7 @@ import com.ruoyi.business.domain.VO.DeviceLatestDataVo;
import com.ruoyi.business.mapper.HwDeviceModeFunctionMapper; import com.ruoyi.business.mapper.HwDeviceModeFunctionMapper;
import com.ruoyi.business.service.IHwMonitorPlatformService; import com.ruoyi.business.service.IHwMonitorPlatformService;
import com.ruoyi.common.core.constant.HwDictConstants; 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.constant.TdEngineConstants;
import com.ruoyi.tdengine.api.RemoteTdEngineService; import com.ruoyi.tdengine.api.RemoteTdEngineService;
import com.ruoyi.tdengine.api.domain.TdField; import com.ruoyi.tdengine.api.domain.TdField;
@ -19,6 +20,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -57,12 +59,20 @@ public class HwMonitorPlatformServiceImpl implements IHwMonitorPlatformService {
Collectors.toMap(HwDeviceModeFunction::getFunctionIdentifier, HwDeviceModeFunction::getFunctionName)); 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);
});
TdSuperTableSelectVo tdSuperTableSelectVo = new TdSuperTableSelectVo(); TdSuperTableSelectVo tdSuperTableSelectVo = new TdSuperTableSelectVo();
String databaseName = TdEngineConstants.getDatabaseName(deviceLatestDataVo.getSceneId()); String databaseName = TdEngineConstants.getDatabaseName();
String superTableName = TdEngineConstants.getSuperTableName(deviceModeId); String superTableName = TdEngineConstants.getSuperTableName(deviceModeId);
tdSuperTableSelectVo.setDatabaseName(databaseName); tdSuperTableSelectVo.setDatabaseName(databaseName);
tdSuperTableSelectVo.setSuperTableName(superTableName); tdSuperTableSelectVo.setSuperTableName(superTableName);
tdSuperTableSelectVo.setGroupByTagsName(TdEngineConstants.ST_TAG_DEVICECODE);//todo,换成deviceid tdSuperTableSelectVo.setGroupByTagsName(TdEngineConstants.ST_TAG_DEVICEID);
if (deviceLatestDataVo.getStartTime() != 0 || deviceLatestDataVo.getEndTime() != 0) { if (deviceLatestDataVo.getStartTime() != 0 || deviceLatestDataVo.getEndTime() != 0) {
tdSuperTableSelectVo.setFirstFieldName(TdEngineConstants.DEFAULT_FIRST_FIELD_NAME); tdSuperTableSelectVo.setFirstFieldName(TdEngineConstants.DEFAULT_FIRST_FIELD_NAME);
} }
@ -70,22 +80,24 @@ public class HwMonitorPlatformServiceImpl implements IHwMonitorPlatformService {
tdSuperTableSelectVo.setDeviceName(deviceLatestDataVo.getDeviceName()); tdSuperTableSelectVo.setDeviceName(deviceLatestDataVo.getDeviceName());
tdSuperTableSelectVo.setStartTime(deviceLatestDataVo.getStartTime()); tdSuperTableSelectVo.setStartTime(deviceLatestDataVo.getStartTime());
tdSuperTableSelectVo.setEndTime(deviceLatestDataVo.getEndTime()); tdSuperTableSelectVo.setEndTime(deviceLatestDataVo.getEndTime());
tdSuperTableSelectVo.setOffset(deviceLatestDataVo.getOffset()); tdSuperTableSelectVo.setOffset(deviceLatestDataVo.getOffset()*deviceLatestDataVo.getLimit());
tdSuperTableSelectVo.setLimit(deviceLatestDataVo.getLimit()); tdSuperTableSelectVo.setLimit(deviceLatestDataVo.getLimit());
List<TdField> schemaFieldValues = new ArrayList<TdField>(); List<TdField> schemaFieldValues = new ArrayList<TdField>();
List<HwDeviceModeFunction> modeFunctions = new ArrayList<>(); List<HwDeviceModeFunction> modeFunctions = new ArrayList<>();
deviceModeFunctions.forEach(mf -> { deviceModeFunctions.forEach(mf -> {
TdField field = new TdField(); TdField field = new TdField();
field.setFieldName(mf.getFunctionIdentifier()); String functionIdentifierTransfer = TdEngineConstants.TDENGINE_KEY_TRANSFER_MAP.get(mf.getFunctionIdentifier());
schemaFieldValues.add(field); String functionIdentifier = functionIdentifierTransfer == null ? mf.getFunctionIdentifier() : functionIdentifierTransfer;
field.setFieldName(functionIdentifier);
schemaFieldValues.add(field);
}); });
tdSuperTableSelectVo.setSchemaFieldValues(schemaFieldValues); tdSuperTableSelectVo.setSchemaFieldValues(schemaFieldValues);
List<Map<String, Object>> latestDataMaps = List<Map<String, Object>> latestDataMaps =
this.remoteTdEngineService.getLatestDataByTags(tdSuperTableSelectVo).getData(); this.remoteTdEngineService.getLatestDataByTags(tdSuperTableSelectVo, SecurityConstants.INNER).getData();
List<DeviceDataColumnVo> deviceDataColumnVos = new ArrayList<DeviceDataColumnVo>(); List<DeviceDataColumnVo> deviceDataColumnVos = new ArrayList<DeviceDataColumnVo>();
@ -94,11 +106,11 @@ public class HwMonitorPlatformServiceImpl implements IHwMonitorPlatformService {
for (Map.Entry<String, Object> entry : latestDataMap.entrySet()) { for (Map.Entry<String, Object> entry : latestDataMap.entrySet()) {
DeviceDataColumnVo deviceDataColumnVo = new DeviceDataColumnVo(); DeviceDataColumnVo deviceDataColumnVo = new DeviceDataColumnVo();
String columnKey = entry.getKey(); String columnKey = entry.getKey();
if(!columnKey.equalsIgnoreCase(TdEngineConstants.ST_TAG_DEVICEID) if (!columnKey.equalsIgnoreCase(TdEngineConstants.ST_TAG_DEVICEID)
&& !columnKey.equalsIgnoreCase(TdEngineConstants.ST_TAG_DEVICEMODEID)){ && !columnKey.equalsIgnoreCase(TdEngineConstants.ST_TAG_DEVICEMODEID)) {
deviceDataColumnVo.setColumnKey(columnKey); deviceDataColumnVo.setColumnKey(columnKey);
deviceDataColumnVo.setColumnName(functionIndentifierName.get(columnKey) == null deviceDataColumnVo.setColumnName(functionIndentifierNameMap.get(columnKey) == null
? columnKey : functionIndentifierName.get(columnKey)); ? columnKey : functionIndentifierNameMap.get(columnKey));
deviceDataColumnVos.add(deviceDataColumnVo); deviceDataColumnVos.add(deviceDataColumnVo);
} }
} }
@ -120,7 +132,7 @@ public class HwMonitorPlatformServiceImpl implements IHwMonitorPlatformService {
@Override @Override
public TdReturnDataVo getHistoryData(DeviceHistoryDataVo deviceHistoryDataVo) { public TdReturnDataVo getHistoryData(DeviceHistoryDataVo deviceHistoryDataVo) {
TdHistorySelectDto tdHistorySelectDto = new TdHistorySelectDto(); TdHistorySelectDto tdHistorySelectDto = new TdHistorySelectDto();
tdHistorySelectDto.setDatabaseName(TdEngineConstants.getDatabaseName(deviceHistoryDataVo.getSceneId())); tdHistorySelectDto.setDatabaseName(TdEngineConstants.getDatabaseName());
tdHistorySelectDto.setTableName(TdEngineConstants.getDeviceDataTableName(deviceHistoryDataVo.getDeviceId())); tdHistorySelectDto.setTableName(TdEngineConstants.getDeviceDataTableName(deviceHistoryDataVo.getDeviceId()));
tdHistorySelectDto.setOrderByFieldName(TdEngineConstants.DEFAULT_FIRST_FIELD_NAME); tdHistorySelectDto.setOrderByFieldName(TdEngineConstants.DEFAULT_FIRST_FIELD_NAME);
tdHistorySelectDto.setSort(TdEngineConstants.DEFAULT_ORDER_BY_MODE); tdHistorySelectDto.setSort(TdEngineConstants.DEFAULT_ORDER_BY_MODE);
@ -129,10 +141,10 @@ public class HwMonitorPlatformServiceImpl implements IHwMonitorPlatformService {
} }
tdHistorySelectDto.setStartTime(deviceHistoryDataVo.getStartTime()); tdHistorySelectDto.setStartTime(deviceHistoryDataVo.getStartTime());
tdHistorySelectDto.setEndTime(deviceHistoryDataVo.getEndTime()); tdHistorySelectDto.setEndTime(deviceHistoryDataVo.getEndTime());
tdHistorySelectDto.setOffset(deviceHistoryDataVo.getOffset()); tdHistorySelectDto.setOffset(deviceHistoryDataVo.getOffset() * deviceHistoryDataVo.getLimit());
tdHistorySelectDto.setLimit(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( Map<String, String> functionIndentifierName = deviceModeFunctions.stream().collect(
Collectors.toMap(HwDeviceModeFunction::getFunctionIdentifier, HwDeviceModeFunction::getFunctionName)); Collectors.toMap(HwDeviceModeFunction::getFunctionIdentifier, HwDeviceModeFunction::getFunctionName));
functionIndentifierName.putAll(TdEngineConstants.DEVICE_DATA_COLUMN_MAP); 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>(); List<DeviceDataColumnVo> deviceDataColumnVos = new ArrayList<DeviceDataColumnVo>();
if (latestDataMaps != null && latestDataMaps.size() > 0) { if (latestDataMaps != null && latestDataMaps.size() > 0) {
@ -161,8 +182,8 @@ public class HwMonitorPlatformServiceImpl implements IHwMonitorPlatformService {
DeviceDataColumnVo deviceDataColumnVo = new DeviceDataColumnVo(); DeviceDataColumnVo deviceDataColumnVo = new DeviceDataColumnVo();
String columnKey = entry.getKey(); String columnKey = entry.getKey();
deviceDataColumnVo.setColumnKey(columnKey); deviceDataColumnVo.setColumnKey(columnKey);
deviceDataColumnVo.setColumnName(functionIndentifierName.get(columnKey) == null deviceDataColumnVo.setColumnName(functionIndentifierNameMap.get(columnKey) == null
? columnKey : functionIndentifierName.get(columnKey)); ? columnKey : functionIndentifierNameMap.get(columnKey));
deviceDataColumnVos.add(deviceDataColumnVo); deviceDataColumnVos.add(deviceDataColumnVo);
} }
} }

@ -1,39 +1,29 @@
package com.ruoyi.business.service.impl; 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.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.ruoyi.business.domain.HwDevice; 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.domain.VO.HwSceneVo;
import com.ruoyi.business.mapper.HwDeviceMapper; 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.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.DateUtils;
import com.ruoyi.common.core.utils.StringUtils; import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.datascope.annotation.DataScope; import com.ruoyi.common.datascope.annotation.DataScope;
import com.ruoyi.common.redis.service.RedisService;
import com.ruoyi.common.security.utils.SecurityUtils; 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 com.ruoyi.tdengine.api.RemoteTdEngineService;
import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service; 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 org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
/** /**
* Service * Service
@ -47,8 +37,6 @@ public class HwSceneServiceImpl implements IHwSceneService {
private HwSceneMapper hwSceneMapper; private HwSceneMapper hwSceneMapper;
@Autowired @Autowired
private HwDeviceMapper hwDeviceMapper; private HwDeviceMapper hwDeviceMapper;
@Resource
private RemoteTdEngineService remoteTdEngineService;
@Autowired @Autowired
private StringRedisTemplate redisTemplate; private StringRedisTemplate redisTemplate;
@ -105,9 +93,7 @@ public class HwSceneServiceImpl implements IHwSceneService {
@Override @Override
@Transactional @Transactional
public int insertHwScene(HwScene hwScene) { public int insertHwScene(HwScene hwScene) {
LoginUser loginUser = SecurityUtils.getLoginUser(); hwScene.setCreateBy(SecurityUtils.getUsername());
SysUser sysUser = loginUser.getSysUser();
hwScene.setCreateBy(sysUser.getUserName());
if (hwScene.getPreserveTime() == null) { if (hwScene.getPreserveTime() == null) {
hwScene.setPreserveTime(new BigDecimal(90)); hwScene.setPreserveTime(new BigDecimal(90));
@ -125,17 +111,17 @@ public class HwSceneServiceImpl implements IHwSceneService {
int rows = hwSceneMapper.insertHwScene(hwScene); int rows = hwSceneMapper.insertHwScene(hwScene);
this.updateDefaultFlag(hwScene); this.updateDefaultFlag(hwScene);
this.createTdDatabase(hwScene); // this.createTdDatabase(hwScene);
return rows; return rows;
} }
private void createTdDatabase(HwScene hwScene) { // private void createTdDatabase(HwScene hwScene) {
String databaseName = TdEngineConstants.getDatabaseName(hwScene.getSceneId()); // String databaseName = TdEngineConstants.getDatabaseName(hwScene.getSceneId());
R<?> tdReturnMsg = this.remoteTdEngineService.createDataBase(databaseName); // R<?> tdReturnMsg = this.remoteTdEngineService.createDataBase(databaseName);
if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务 // if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务
throw new RuntimeException(tdReturnMsg.getMsg()); // 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="deviceModeId != null "> and device_mode_id = #{deviceModeId}</if>
<if test="accessGwProtocol != null "> and access_gw_protocol = #{accessGwProtocol}</if> <if test="accessGwProtocol != null "> and access_gw_protocol = #{accessGwProtocol}</if>
<if test="activeStatus != null and activeStatus != ''"> and active_status = #{activeStatus}</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="activeTime != null "> and active_time = #{activeTime}</if>
<if test="devicePic != null and devicePic != ''"> and device_pic = #{devicePic}</if> <if test="devicePic != null and devicePic != ''"> and device_pic = #{devicePic}</if>
<if test="ipAddress != null and ipAddress != ''"> and ip_address = #{ipAddress}</if> <if test="ipAddress != null and ipAddress != ''"> and ip_address = #{ipAddress}</if>

@ -294,7 +294,7 @@
<select id="selectHwMonitorUnitJoinByMonitorUnitId" parameterType="Long" resultMap="HwMonitorUnitResult"> <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 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} where monitor_unit_id = #{monitorUnitId}
</select> </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); logger.info("Process Data start:{}ms,end:{}ms,Spend Time:{}ms,Data Count:{}", start, end, end - start, processDataCount);
} else if (topic.equals(deviceStatusTopic)) { } else if (topic.equals(deviceStatusTopic)) {
deviceStatusService.handleDeviceStatus(payloadString, clientId); deviceStatusService.handleDeviceStatus(payloadString, clientId);
} else { } else {//测试图片转换使用
dataProcessService.testBase64(payloadString, imagePath, imagePatterns, imageDomain, imagePrefix); dataProcessService.testBase64(payloadString, imagePath, imagePatterns, imageDomain, imagePrefix);
} }
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); 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.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.constant.HwDictConstants; 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.constant.TdEngineConstants;
import com.ruoyi.common.core.domain.R; import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.enums.ResultEnums; import com.ruoyi.common.core.enums.ResultEnums;
@ -77,7 +78,7 @@ public class DataProcessServiceImpl implements IDataProcessService {
*/ */
@Override @Override
public int processBusinessData(String jsonData, String imagePath, public int processBusinessData(String jsonData, String imagePath,
String imagePatterns,String imageDomain,String imagePrefix) { String imagePatterns, String imageDomain, String imagePrefix) {
JSONObject json = JSON.parseObject(jsonData); JSONObject json = JSON.parseObject(jsonData);
Long ts = json.getLong(TdEngineConstants.PAYLOAD_TS); Long ts = json.getLong(TdEngineConstants.PAYLOAD_TS);
String tsStr = String.valueOf(ts); String tsStr = String.valueOf(ts);
@ -87,99 +88,113 @@ public class DataProcessServiceImpl implements IDataProcessService {
JSONArray paramArr = json.getJSONArray(TdEngineConstants.PAYLOAD_PARAM); JSONArray paramArr = json.getJSONArray(TdEngineConstants.PAYLOAD_PARAM);
// System.out.println(this.hwDeviceMapper); // System.out.println(this.hwDeviceMapper);
// System.out.println(this.remoteTdEngineService); // System.out.println(this.remoteTdEngineService);
String deviceCode = "";
for (int i = 0; i < paramArr.size(); i++) { for (int i = 0; i < paramArr.size(); i++) {
JSONObject paramJson = paramArr.getJSONObject(i); try {
JSONObject dataValueJson = paramJson.getJSONObject(TdEngineConstants.PAYLOAD_DATAVALUE); JSONObject paramJson = paramArr.getJSONObject(i);
String deviceCode = dataValueJson.getString(TdEngineConstants.PAYLOAD_DEVICE_CODE).toLowerCase(); JSONObject dataValueJson = paramJson.getJSONObject(TdEngineConstants.PAYLOAD_DATAVALUE);
HwDevice hwDevice = hwDeviceMapper.selectHwDeviceByDeviceCode(deviceCode); deviceCode = dataValueJson.getString(TdEngineConstants.PAYLOAD_DEVICE_CODE).toLowerCase();
Long sceneId = hwDevice.getSceneId(); HwDevice hwDevice = hwDeviceMapper.selectHwDeviceByDeviceCode(deviceCode);
Long deviceId = hwDevice.getDeviceId(); if (hwDevice == null) {
Long monitorUnitId = hwDevice.getMonitorUnitId(); logger.error("此设备【deviceCode:{}】不存在", deviceCode);
Long tenantId = hwDevice.getTenantId(); continue;
String databaseName = TdEngineConstants.DEFAULT_DB_NAME_PREFIX + sceneId; }
String tableName = TdEngineConstants.DEFAULT_TABLE_NAME_PREFIX + deviceId; if (hwDevice.getDeviceStatus().equals(HwDictConstants.DEVICE_STATUS_DELETE)) {
logger.error("此设备【deviceCode:{}】已删除", deviceCode);
continue;
}
dataValueJson.remove(TdEngineConstants.PAYLOAD_DEVICE_CODE); Long sceneId = hwDevice.getSceneId();
TdTableVo tdTableVo = new TdTableVo(); Long deviceId = hwDevice.getDeviceId();
List<TdField> schemaFields = new ArrayList<>(); Long monitorUnitId = hwDevice.getMonitorUnitId();
Long tenantId = hwDevice.getTenantId();
String databaseName = TdEngineConstants.getDatabaseName();
String tableName = TdEngineConstants.DEFAULT_TABLE_NAME_PREFIX + deviceId;
//添加timestamp字段默认字段名称是ts协议上传的key是timestamp dataValueJson.remove(TdEngineConstants.PAYLOAD_DEVICE_CODE);
TdField firstTdField = new TdField(); TdTableVo tdTableVo = new TdTableVo();
firstTdField.setFieldName(TdEngineConstants.DEFAULT_FIRST_FIELD_NAME); List<TdField> schemaFields = new ArrayList<>();
firstTdField.setFieldValue(ts);
schemaFields.add(firstTdField);
Object longitude = null; //添加timestamp字段默认字段名称是ts协议上传的key是timestamp
Object latitude = null; TdField firstTdField = new TdField();
firstTdField.setFieldName(TdEngineConstants.DEFAULT_FIRST_FIELD_NAME);
firstTdField.setFieldValue(ts);
schemaFields.add(firstTdField);
for (Map.Entry<String, Object> entry : dataValueJson.entrySet()) { Object longitude = null;
String key = entry.getKey(); Object latitude = null;
Object value = entry.getValue();
/** for (Map.Entry<String, Object> entry : dataValueJson.entrySet()) {
* keykeyvaluevalue1 String key = entry.getKey();
*/ Object value = entry.getValue();
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; * keykeyvaluevalue1
if (StringUtils.isNotBlank(valueStr)) { */
/** key = TdEngineConstants.TDENGINE_KEY_TRANSFER_MAP.get(key) == null ? key
* , : TdEngineConstants.TDENGINE_KEY_TRANSFER_MAP.get(key);
*/
String[] imagePatternArr = imagePatterns.split(","); if (value instanceof String) {
String extension = ImageUtils.getImageType(valueStr, imagePatternArr); String valueStr = (String) value;
if (StringUtils.isNotBlank(extension)) { if (StringUtils.isNotBlank(valueStr)) {
//保存图片,并返回图片详细地址进行赋值保存 /**
String imageFileName = null; * ,
try { */
imageFileName = ImageUtils.convertBase64ToImage(imagePath, String[] imagePatternArr = imagePatterns.split(",");
valueStr, "device" + deviceId, extension); String extension = ImageUtils.getImageType(valueStr, imagePatternArr);
if (StringUtils.isNotBlank(imageFileName)) { if (StringUtils.isNotBlank(extension)) {
value = imageDomain + imagePrefix + imageFileName; //保存图片,并返回图片详细地址进行赋值保存
System.out.println(value); String imageFileName = null;
}else { try {
continue; 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 tdField = new TdField();
tdField.setFieldName(key); tdField.setFieldName(key);
tdField.setFieldValue(value); tdField.setFieldValue(value);
schemaFields.add(tdField); 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)) { if (key.equalsIgnoreCase(HwDictConstants.DEFAULT_FUNCTION_LONGITUDE_IDENTIFIER)) {
longitude = value; longitude = value;
} else if (key.equalsIgnoreCase(HwDictConstants.DEFAULT_FUNCTION_LATITUDE_IDENTIFIER)) { } else if (key.equalsIgnoreCase(HwDictConstants.DEFAULT_FUNCTION_LATITUDE_IDENTIFIER)) {
latitude = value; latitude = value;
}
} }
} }
}
tdTableVo.setDatabaseName(databaseName); tdTableVo.setDatabaseName(databaseName);
tdTableVo.setTableName(tableName); tdTableVo.setTableName(tableName);
tdTableVo.setSchemaFields(schemaFields); tdTableVo.setSchemaFields(schemaFields);
final R<?> insertResult = this.remoteTdEngineService.insertTable(tdTableVo); final R<?> insertResult = this.remoteTdEngineService.insertTable(tdTableVo, SecurityConstants.INNER);
if (insertResult.getCode() == ResultEnums.SUCCESS.getCode()) { if (insertResult.getCode() == ResultEnums.SUCCESS.getCode()) {
logger.info("Insert data result: {}", insertResult.getMsg()); logger.info("Insert data result: {}", insertResult.getMsg());
} else { } else {
logger.error("Insert data Exception: {},data:{}", insertResult.getMsg(), jsonData); logger.error("Insert data Exception: {},data:{}", insertResult.getMsg(), jsonData);
} }
if (longitude != null && latitude != null) { if (longitude != null && latitude != null) {
checkElectronicFence(deviceId, tenantId, monitorUnitId, sceneId, longitude, latitude, ts); 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.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.constant.HwDictConstants; 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.constant.TdEngineConstants;
import com.ruoyi.dataprocess.domain.HwDevice; import com.ruoyi.dataprocess.domain.HwDevice;
import com.ruoyi.dataprocess.mapper.HwDeviceMapper; import com.ruoyi.dataprocess.mapper.HwDeviceMapper;
@ -68,7 +69,7 @@ public class DeviceStatusServiceImpl implements IDeviceStatusService {
tdTableVo.setSchemaFields(schemaFields); tdTableVo.setSchemaFields(schemaFields);
this.remoteTdEngineService.insertTable(tdTableVo); this.remoteTdEngineService.insertTable(tdTableVo, SecurityConstants.INNER);
//更新设备当前状态信息 //更新设备当前状态信息
String connectStatus = String.valueOf(json.getInteger("connectStatus")); 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.domain.R;
import com.ruoyi.common.core.hw.validated.tdengine.AddTdSTableColumn; import com.ruoyi.common.core.hw.validated.tdengine.AddTdSTableColumn;
import com.ruoyi.common.core.hw.validated.tdengine.InsertTdTable; 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.api.domain.*;
import com.ruoyi.tdengine.service.IDeviceStatusService; import com.ruoyi.tdengine.service.IDeviceStatusService;
import com.ruoyi.tdengine.service.ITdEngineService; import com.ruoyi.tdengine.service.ITdEngineService;
@ -46,6 +47,7 @@ public class TdEngineController {
* @param databaseName * @param databaseName
* @return R<?> * @return R<?>
*/ */
@InnerAuth
@PostMapping("/createDatabase") @PostMapping("/createDatabase")
public R<?> createDataBase(@RequestBody() String databaseName) { public R<?> createDataBase(@RequestBody() String databaseName) {
try { try {
@ -73,6 +75,7 @@ public class TdEngineController {
* @param tdSuperTableVo * @param tdSuperTableVo
* @return R<?> * @return R<?>
*/ */
@InnerAuth
@PostMapping("/createSuperTable") @PostMapping("/createSuperTable")
public R<?> createSuperTable(@Validated @RequestBody TdSuperTableVo tdSuperTableVo) { public R<?> createSuperTable(@Validated @RequestBody TdSuperTableVo tdSuperTableVo) {
//数据库名称 //数据库名称
@ -114,6 +117,7 @@ public class TdEngineController {
* @author xins * @author xins
* @date 2023-08-28 16:17 * @date 2023-08-28 16:17
*/ */
@InnerAuth
@PostMapping("/createTable") @PostMapping("/createTable")
public R<?> createTable(@Validated @RequestBody TdTableVo tdTableVo) { public R<?> createTable(@Validated @RequestBody TdTableVo tdTableVo) {
try { try {
@ -144,6 +148,7 @@ public class TdEngineController {
* @author xins * @author xins
* @date 2023-08-28 17:55 * @date 2023-08-28 17:55
*/ */
@InnerAuth
@PostMapping("/addSuperTableColumn") @PostMapping("/addSuperTableColumn")
public R<?> addSuperTableColumn(@Validated(AddTdSTableColumn.class) @RequestBody TdSuperTableVo tdSuperTableVo) { public R<?> addSuperTableColumn(@Validated(AddTdSTableColumn.class) @RequestBody TdSuperTableVo tdSuperTableVo) {
String databaseName = tdSuperTableVo.getDatabaseName(); 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<?> * @return R<?>
* @param: tdSuperTableVo * @param: tdSuperTableVo
@ -175,6 +213,7 @@ public class TdEngineController {
* @author xins * @author xins
* @date 2023-08-28 17:56 * @date 2023-08-28 17:56
*/ */
@InnerAuth
@PostMapping("/dropSuperTableColumn") @PostMapping("/dropSuperTableColumn")
public R<?> dropColumnForSuperTable(@Validated(AddTdSTableColumn.class) @RequestBody TdSuperTableVo tdSuperTableVo) { public R<?> dropColumnForSuperTable(@Validated(AddTdSTableColumn.class) @RequestBody TdSuperTableVo tdSuperTableVo) {
String databaseName = tdSuperTableVo.getDatabaseName(); String databaseName = tdSuperTableVo.getDatabaseName();
@ -207,6 +246,7 @@ public class TdEngineController {
* @author xins * @author xins
* @date 2023-08-30 11:17 * @date 2023-08-30 11:17
*/ */
@InnerAuth
@PostMapping("/alterTableTag") @PostMapping("/alterTableTag")
public R<?> alterTableTag(@Validated @RequestBody AlterTagVo alterTagVo) { public R<?> alterTableTag(@Validated @RequestBody AlterTagVo alterTagVo) {
String databaseName = alterTagVo.getDatabaseName(); String databaseName = alterTagVo.getDatabaseName();
@ -239,6 +279,7 @@ public class TdEngineController {
* @author xins * @author xins
* @date 2023-08-29 10:04 * @date 2023-08-29 10:04
*/ */
@InnerAuth
@PostMapping("/insertTable") @PostMapping("/insertTable")
public R<?> insertTable(@Validated(InsertTdTable.class) @RequestBody TdTableVo tdTableVo) { public R<?> insertTable(@Validated(InsertTdTable.class) @RequestBody TdTableVo tdTableVo) {
try { try {
@ -270,6 +311,7 @@ public class TdEngineController {
* @author xins * @author xins
* @date 2023-08-29 11:26 * @date 2023-08-29 11:26
*/ */
@InnerAuth
@PostMapping("/getLatestData") @PostMapping("/getLatestData")
public R<?> getLatestData(@Validated @RequestBody TdSelectDto tdSelectDto) { public R<?> getLatestData(@Validated @RequestBody TdSelectDto tdSelectDto) {
try { try {
@ -295,6 +337,7 @@ public class TdEngineController {
* @author xins * @author xins
* @date 2023-08-29 14:51 * @date 2023-08-29 14:51
*/ */
@InnerAuth
@PostMapping("/getLatestDataByTags") @PostMapping("/getLatestDataByTags")
public R<List<Map<String, Object>>> getLatestDataByTags(@Validated @RequestBody TdSuperTableSelectVo tdSelectDto) { public R<List<Map<String, Object>>> getLatestDataByTags(@Validated @RequestBody TdSuperTableSelectVo tdSelectDto) {
try { try {
@ -323,6 +366,7 @@ public class TdEngineController {
* select col from table LIMIT [topnums] * 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] * 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") @PostMapping("/getHistoryData")
public R<?> getHistoryData(@Validated @RequestBody TdHistorySelectDto tdHistorySelectDto) { public R<?> getHistoryData(@Validated @RequestBody TdHistorySelectDto tdHistorySelectDto) {
try { try {
@ -359,6 +403,7 @@ public class TdEngineController {
* @author xins * @author xins
* @date 2023-08-29 11:26 * @date 2023-08-29 11:26
*/ */
@InnerAuth
@PostMapping("/getOnlineDevicesGroupByDay") @PostMapping("/getOnlineDevicesGroupByDay")
public R<?> getOnlineDevicesGroupByDay(@RequestBody DeviceStatus queryDeviceStatus) { public R<?> getOnlineDevicesGroupByDay(@RequestBody DeviceStatus queryDeviceStatus) {
try { try {
@ -388,6 +433,7 @@ public class TdEngineController {
* @author xins * @author xins
* @date 2023-08-29 11:26 * @date 2023-08-29 11:26
*/ */
@InnerAuth
@PostMapping("/getLastOnlineDevices") @PostMapping("/getLastOnlineDevices")
public R<?> getLastOnlineDevices(@RequestBody DeviceStatus queryDeviceStatus) { public R<?> getLastOnlineDevices(@RequestBody DeviceStatus queryDeviceStatus) {
try { try {

@ -67,6 +67,19 @@ public interface TdEngineMapper {
@Param("superTableName") String superTableName, @Param("superTableName") String superTableName,
@Param("addFieldsVo") TdFieldVo addFieldsVo); @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: databaseName
* @param: superTableName * @param: superTableName

@ -56,6 +56,16 @@ public interface ITdEngineService {
public void addSuperTableColumn(String databaseName,String superTableName, TdFieldVo addFieldsVo) throws Exception; 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: databaseName
* @param: superTableName * @param: superTableName

@ -91,6 +91,20 @@ public class TdEngineServiceImpl implements ITdEngineService {
this.tdEngineMapper.addSuperTableColumn(databaseName, superTableName, addFieldsVo); 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: databaseName
* @param: superTableName * @param: superTableName

@ -166,6 +166,18 @@
</if> </if>
</update> </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"> <update id="dropSuperTableColumn">
ALTER STABLE #{databaseName}.#{superTableName} DROP COLUMN ALTER STABLE #{databaseName}.#{superTableName} DROP COLUMN
<if test="dropField.fieldName != null and dropField.fieldName != ''"> <if test="dropField.fieldName != null and dropField.fieldName != ''">

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

@ -60,3 +60,11 @@ export function getEditedScenes(query) {
params: 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-button>
</el-col> </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> <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row> </el-row>
<el-table v-loading="loading" :data="deviceList" @selection-change="handleSelectionChange"> <el-table v-loading="loading" :data="deviceList" @selection-change="handleSelectionChange">
<el-table-column type="selection" width="55" align="center"/> <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="deviceCode"/>
<el-table-column label="设备名称" align="center" prop="deviceName"/> <el-table-column label="设备名称" align="center" prop="deviceName"/>
<el-table-column label="设备类型" align="center" prop="deviceType"> <el-table-column label="设备类型" align="center" prop="deviceType">
@ -375,11 +387,13 @@ import {
getDeviceModes, getDeviceModes,
getGatewayDevices, getGatewayDevices,
changeDeviceStatus, changeDeviceStatus,
publishControlCommand publishControlCommand,
rebuildTdTables
} from "@/api/business/device"; } from "@/api/business/device";
import {getToken} from "@/utils/auth"; import {getToken} from "@/utils/auth";
import Treeselect from "@riophae/vue-treeselect"; import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css"; import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import {rebuildTdSuperTables} from "@/api/business/deviceMode";
export default { export default {
components: {Treeselect}, components: {Treeselect},
@ -737,7 +751,7 @@ export default {
const deviceId = row.deviceId; const deviceId = row.deviceId;
const deviceType = row.deviceType; const deviceType = row.deviceType;
const deviceCode = row.deviceCode; const deviceCode = row.deviceCode;
this.$modal.confirm('是否确认删除设备信息编号为"' + deviceCode + '"的数据项?').then(function () { this.$modal.confirm('是否确认删除设备信息ID为"' + deviceId + '"的数据项?').then(function () {
return delDevice(deviceId,deviceType); return delDevice(deviceId,deviceType);
}).then(() => { }).then(() => {
this.getList(); this.getList();
@ -965,7 +979,16 @@ export default {
}).then(() => { }).then(() => {
this.$modal.msgSuccess("下发指令成功"); this.$modal.msgSuccess("下发指令成功");
}) })
} },
/** 重建表按钮操作 */
handleRebuildTdTables() {
this.$modal.confirm('是否确认重建所有设备监测数据表?').then(function () {
return rebuildTdTables();
}).then(() => {
this.$modal.msgSuccess("重建成功");
}).catch(() => {
});
},
} }
}; };

@ -328,12 +328,14 @@ export default {
handleDeleteEvent(row) { handleDeleteEvent(row) {
if (row.modeFunctionId !== undefined) { if (row.modeFunctionId !== undefined) {
delDeviceModeFunction(row.modeFunctionId).then(res => { this.$modal.confirm('确认要删除么?').then(() => {
this.$modal.msgSuccess(res.msg); delDeviceModeFunction(row.modeFunctionId).then(res => {
if (res.code === 200) { this.$modal.msgSuccess(res.msg);
this.eventsData = this.eventsData.splice(this.eventsData.indexOf(row), 1); if (res.code === 200) {
} this.eventsData = this.eventsData.splice(this.eventsData.indexOf(row), 1);
}); }
});
})
} else { } else {
this.eventsData = this.eventsData.splice(this.eventsData.indexOf(row), 1); this.eventsData = this.eventsData.splice(this.eventsData.indexOf(row), 1);
} }

@ -403,12 +403,14 @@ export default {
const servicesData = this.servicesData; const servicesData = this.servicesData;
if (row.modeFunctionId !== undefined) { if (row.modeFunctionId !== undefined) {
delDeviceModeFunction(row.modeFunctionId).then(res => { this.$modal.confirm('确认要删除么?').then(() => {
this.$modal.msgSuccess(res.msg); delDeviceModeFunction(row.modeFunctionId).then(res => {
if (res.code === 200) { this.$modal.msgSuccess(res.msg);
this.servicesData = servicesData.splice(servicesData.indexOf(row), 1); if (res.code === 200) {
} this.servicesData = servicesData.splice(servicesData.indexOf(row), 1);
}); }
});
})
} else { } else {
this.servicesData = servicesData.splice(servicesData.indexOf(row), 1); this.servicesData = servicesData.splice(servicesData.indexOf(row), 1);
} }

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

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

Loading…
Cancel
Save