若依微服务1.2.4

1、TDengine服务完善
2、设备管理新增时在tdengine创建表,在redis存储用户名和密码
3、监控平台接口修改
dev 1.2.4
xins 1 year ago
parent bfd9bf573b
commit 22e1c58338

@ -54,5 +54,6 @@ public class HwDictConstants {
public static final String DEVICE_TYPE_GATEWAY_SUB_EQUIPMENT = "2";//网关子设备
public static final String DEVICE_TYPE_DIRECT_CONNECT_DEVICE = "3";//直连设备
public static final String REDIS_KEY_DEVICE_INFO = "hw_device_info";//保存设备用户名和密码等信息的redis的key
}

@ -85,10 +85,14 @@ public class TdEngineConstants {
* @date 2023-09-16 14:42
* @return String
*/
public static String getSupertTableName(Long deviceModeId) {
public static String getSuperTableName(Long deviceModeId) {
return DEFAULT_SUPER_TABLE_NAME_PREFIX + deviceModeId;
}
public static String getTableName(Long deviceId) {
return DEFAULT_TABLE_NAME_PREFIX + deviceId;
}
/**
* @param: deviceId
* @return String

@ -17,6 +17,8 @@ import com.ruoyi.common.core.constant.HwDictConstants;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.system.api.domain.SysDept;
import com.ruoyi.system.api.domain.SysRole;
import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
@ -104,6 +106,10 @@ public class HwDeviceController extends BaseController
@PostMapping
public AjaxResult add(@RequestBody HwDevice hwDevice)
{
LoginUser loginUser = SecurityUtils.getLoginUser();
SysUser user = loginUser.getSysUser();
hwDevice.setTenantId(user.getTenantId());
hwDevice.setCreateBy(user.getUserName());
return toAjax(hwDeviceService.insertHwDevice(hwDevice));
}
@ -115,6 +121,7 @@ public class HwDeviceController extends BaseController
@PutMapping
public AjaxResult edit(@RequestBody HwDevice hwDevice)
{
hwDevice.setUpdateBy(SecurityUtils.getUsername());
return toAjax(hwDeviceService.updateHwDevice(hwDevice));
}

@ -179,15 +179,14 @@ public class HwMonitorPlatformController extends BaseController {
* @return list
* @throws
*/
@GetMapping("/treeList{sceneId}")
public TableDataInfo treeList(@PathVariable("sceneId") Long sceneId) {
HwMonitorUnit hwMonitorUnit = new HwMonitorUnit();
hwMonitorUnit.setSceneId(sceneId);
List<HwMonitorUnit> hwMonitorUnits = hwMonitorUnitService.selectHwMonitorUnitList(hwMonitorUnit);
List<HwMonitorUnit> list = hwMonitorUnitService.selectTreeList(hwMonitorUnits);
return getDataTable(list);
@GetMapping("/treeList/{sceneId}")
public AjaxResult monitorUnitTree(@PathVariable("sceneId") Long sceneId)
{
HwMonitorUnit queryMonitorUnit = new HwMonitorUnit();
queryMonitorUnit.setSceneId(sceneId);
return success(hwMonitorUnitService.selectMonitorTreeList(queryMonitorUnit));
}
// /**
// *
// * 选择场景

@ -1,6 +1,7 @@
package com.ruoyi.business.domain;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
@ -13,323 +14,350 @@ import com.ruoyi.common.core.web.domain.BaseEntity;
* @author xins
* @date 2023-09-13
*/
public class HwDevice extends BaseEntity
{
public class HwDevice extends BaseEntity {
private static final long serialVersionUID = 1L;
/** 设备ID */
/**
* ID
*/
private Long deviceId;
/** 设备编号 */
/**
*
*/
@Excel(name = "设备编号")
private String deviceCode;
/** 设备名称 */
/**
*
*/
@Excel(name = "设备名称")
private String deviceName;
/** 所属场景关联hw_scene表的scene_id字段 */
/**
* hw_scenescene_id
*/
@Excel(name = "所属场景关联hw_scene表的scene_id字段")
private Long sceneId;
/** 所属监控单元关联表hw_monitor_unit字段monitor_unit_id */
/**
* hw_monitor_unitmonitor_unit_id
*/
@Excel(name = "所属监控单元关联表hw_monitor_unit字段monitor_unit_id")
private Long monitorUnitId;
/** 设备类型1网关设备2网关子设备3直连设备 */
/**
* 123
*/
@Excel(name = "设备类型", readConverterExp = "1=网关设备2网关子设备3直连设备")
private String deviceType;
/** 联网方式(1:Wi-Fi2、蜂窝(2G/3G/4G/5G),3、以太网4、其他) */
/**
* (1:Wi-Fi2(2G/3G/4G/5G),34)
*/
@Excel(name = "联网方式(1:Wi-Fi2、蜂窝(2G/3G/4G/5G),3、以太网4、其他)")
private String networkingMode;
/** 接入协议1、MQTT */
/**
* 1MQTT
*/
@Excel(name = "接入协议", readConverterExp = "1=、MQTT")
private Long accessProtocol;
/** 数据格式1、Json */
/**
* 1Json
*/
@Excel(name = "数据格式", readConverterExp = "1=、Json")
private Long dataFormat;
/** 关联设备hw_device表中国的device_id */
/**
* hw_devicedevice_id
*/
@Excel(name = "关联设备hw_device表中国的device_id")
private Long releatedDeviceId;
/** 设备模型关联表hw_device_mode的字段device_mode_id */
/**
* hw_device_modedevice_mode_id
*/
@Excel(name = "设备模型关联表hw_device_mode的字段device_mode_id")
private Long deviceModeId;
/** 1Modbus
OPC-UA,Modbus */
/**
* 1Modbus
* OPC-UA,Modbus
*/
@Excel(name = "接入网关协议", readConverterExp = "1=、Modbus")
private Long accessGwProtocol;
/** 激活状态1、激活0、未激活 */
/**
* 10
*/
@Excel(name = "激活状态", readConverterExp = "1=、激活0、未激活")
private String activeStatus;
/** 设备状态0、测试1、发布9、删除 */
/**
* 019
*/
@Excel(name = "设备状态", readConverterExp = "0=、测试1、发布9、删除")
private String deviceStatus;
/** 设备激活时间 */
/**
*
*/
@JsonFormat(pattern = "yyyy-MM-dd")
@Excel(name = "设备激活时间", width = 30, dateFormat = "yyyy-MM-dd")
private Date activeTime;
/** 设备图片地址(如果为空则可以使用设备模型图片) */
/**
* 使
*/
@Excel(name = "设备图片地址", readConverterExp = "如=果为空则可以使用设备模型图片")
private String devicePic;
/** 网络地址 */
/**
*
*/
@Excel(name = "网络地址")
private String ipAddress;
/** 预留字段设备所在区域ID关联表hw_area字段area_id) */
/**
* IDhw_areaarea_id)
*/
@Excel(name = "预留字段设备所在区域ID关联表hw_area字段area_id)")
private Long areaId;
/** 预留字段设备位置手动定位在地图上选择设备所在的固定位置自动定位设备自动定位位置关联网关自动定位位置。目前仅G780V2(固件版本V2.2.0之后)、PLCNET510、G800 V2和ModbusRTU(云端轮询)定位型变量支持选择自动定位功能)) */
/**
* G780V2(V2.2.0)PLCNET510G800 V2ModbusRTU()
*/
@Excel(name = "预留字段,设备位置", readConverterExp = "手=动定位(在地图上选择设备所在的固定位置")
private String deviceLocation;
/** 当前固件版本(Linux系统) */
/**
* (Linux)
*/
@Excel(name = "当前固件版本(Linux系统)")
private String currentModuleVersion;
/** 当前单片机固件版本 */
/**
*
*/
@Excel(name = "当前单片机固件版本")
private String currentSinglechipVersion;
/** 预留字段 */
/**
*
*/
@Excel(name = "预留字段")
private String deviceField;
/** 租户ID关联hw_tenant的tenant_id */
/**
* IDhw_tenanttenant_id
*/
@Excel(name = "租户ID关联hw_tenant的tenant_id")
private Long tenantId;
/** 在线状态1、在线0、离线 */
/**
* 线1线0线
*/
@Excel(name = "在线状态", readConverterExp = "1=、在线0、离线")
private String onlineStatus;
private String monitorUnitName;
public void setDeviceId(Long deviceId)
{
private String sceneName;
private String deviceModeName;
private String tenantName;
public void setDeviceId(Long deviceId) {
this.deviceId = deviceId;
}
public Long getDeviceId()
{
public Long getDeviceId() {
return deviceId;
}
public void setDeviceCode(String deviceCode)
{
public void setDeviceCode(String deviceCode) {
this.deviceCode = deviceCode;
}
public String getDeviceCode()
{
public String getDeviceCode() {
return deviceCode;
}
public void setDeviceName(String deviceName)
{
public void setDeviceName(String deviceName) {
this.deviceName = deviceName;
}
public String getDeviceName()
{
public String getDeviceName() {
return deviceName;
}
public void setSceneId(Long sceneId)
{
public void setSceneId(Long sceneId) {
this.sceneId = sceneId;
}
public Long getSceneId()
{
public Long getSceneId() {
return sceneId;
}
public void setMonitorUnitId(Long monitorUnitId)
{
public void setMonitorUnitId(Long monitorUnitId) {
this.monitorUnitId = monitorUnitId;
}
public Long getMonitorUnitId()
{
public Long getMonitorUnitId() {
return monitorUnitId;
}
public void setDeviceType(String deviceType)
{
public void setDeviceType(String deviceType) {
this.deviceType = deviceType;
}
public String getDeviceType()
{
public String getDeviceType() {
return deviceType;
}
public void setNetworkingMode(String networkingMode)
{
public void setNetworkingMode(String networkingMode) {
this.networkingMode = networkingMode;
}
public String getNetworkingMode()
{
public String getNetworkingMode() {
return networkingMode;
}
public void setAccessProtocol(Long accessProtocol)
{
public void setAccessProtocol(Long accessProtocol) {
this.accessProtocol = accessProtocol;
}
public Long getAccessProtocol()
{
public Long getAccessProtocol() {
return accessProtocol;
}
public void setDataFormat(Long dataFormat)
{
public void setDataFormat(Long dataFormat) {
this.dataFormat = dataFormat;
}
public Long getDataFormat()
{
public Long getDataFormat() {
return dataFormat;
}
public void setReleatedDeviceId(Long releatedDeviceId)
{
public void setReleatedDeviceId(Long releatedDeviceId) {
this.releatedDeviceId = releatedDeviceId;
}
public Long getReleatedDeviceId()
{
public Long getReleatedDeviceId() {
return releatedDeviceId;
}
public void setDeviceModeId(Long deviceModeId)
{
public void setDeviceModeId(Long deviceModeId) {
this.deviceModeId = deviceModeId;
}
public Long getDeviceModeId()
{
public Long getDeviceModeId() {
return deviceModeId;
}
public void setAccessGwProtocol(Long accessGwProtocol)
{
public void setAccessGwProtocol(Long accessGwProtocol) {
this.accessGwProtocol = accessGwProtocol;
}
public Long getAccessGwProtocol()
{
public Long getAccessGwProtocol() {
return accessGwProtocol;
}
public void setActiveStatus(String activeStatus)
{
public void setActiveStatus(String activeStatus) {
this.activeStatus = activeStatus;
}
public String getActiveStatus()
{
public String getActiveStatus() {
return activeStatus;
}
public void setDeviceStatus(String deviceStatus)
{
public void setDeviceStatus(String deviceStatus) {
this.deviceStatus = deviceStatus;
}
public String getDeviceStatus()
{
public String getDeviceStatus() {
return deviceStatus;
}
public void setActiveTime(Date activeTime)
{
public void setActiveTime(Date activeTime) {
this.activeTime = activeTime;
}
public Date getActiveTime()
{
public Date getActiveTime() {
return activeTime;
}
public void setDevicePic(String devicePic)
{
public void setDevicePic(String devicePic) {
this.devicePic = devicePic;
}
public String getDevicePic()
{
public String getDevicePic() {
return devicePic;
}
public void setIpAddress(String ipAddress)
{
public void setIpAddress(String ipAddress) {
this.ipAddress = ipAddress;
}
public String getIpAddress()
{
public String getIpAddress() {
return ipAddress;
}
public void setAreaId(Long areaId)
{
public void setAreaId(Long areaId) {
this.areaId = areaId;
}
public Long getAreaId()
{
public Long getAreaId() {
return areaId;
}
public void setDeviceLocation(String deviceLocation)
{
public void setDeviceLocation(String deviceLocation) {
this.deviceLocation = deviceLocation;
}
public String getDeviceLocation()
{
public String getDeviceLocation() {
return deviceLocation;
}
public void setCurrentModuleVersion(String currentModuleVersion)
{
public void setCurrentModuleVersion(String currentModuleVersion) {
this.currentModuleVersion = currentModuleVersion;
}
public String getCurrentModuleVersion()
{
public String getCurrentModuleVersion() {
return currentModuleVersion;
}
public void setCurrentSinglechipVersion(String currentSinglechipVersion)
{
public void setCurrentSinglechipVersion(String currentSinglechipVersion) {
this.currentSinglechipVersion = currentSinglechipVersion;
}
public String getCurrentSinglechipVersion()
{
public String getCurrentSinglechipVersion() {
return currentSinglechipVersion;
}
public void setDeviceField(String deviceField)
{
public void setDeviceField(String deviceField) {
this.deviceField = deviceField;
}
public String getDeviceField()
{
public String getDeviceField() {
return deviceField;
}
public void setTenantId(Long tenantId)
{
public void setTenantId(Long tenantId) {
this.tenantId = tenantId;
}
public Long getTenantId()
{
public Long getTenantId() {
return tenantId;
}
public void setOnlineStatus(String onlineStatus)
{
public void setOnlineStatus(String onlineStatus) {
this.onlineStatus = onlineStatus;
}
public String getOnlineStatus()
{
public String getOnlineStatus() {
return onlineStatus;
}
@ -341,6 +369,30 @@ public class HwDevice extends BaseEntity
this.monitorUnitName = monitorUnitName;
}
public String getSceneName() {
return sceneName;
}
public void setSceneName(String sceneName) {
this.sceneName = sceneName;
}
public String getDeviceModeName() {
return deviceModeName;
}
public void setDeviceModeName(String deviceModeName) {
this.deviceModeName = deviceModeName;
}
public String getTenantName() {
return tenantName;
}
public void setTenantName(String tenantName) {
this.tenantName = tenantName;
}
@Override
public String toString() {
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)

@ -80,4 +80,12 @@ public interface HwDeviceMapper
public List<HwDevice> selectLinkedDevices(Long deviceId);
/**
* ,join
*
* @param hwDevice
* @return
*/
public List<HwDevice> selectHwDeviceJoinList(HwDevice hwDevice);
}

@ -7,6 +7,7 @@ import com.ruoyi.business.domain.HwDevice;
import com.ruoyi.business.domain.VO.DeviceModeVo;
import com.ruoyi.business.domain.VO.HwDeviceVo;
import com.ruoyi.business.domain.VO.HwMonitorUnitVo;
import com.ruoyi.common.datascope.annotation.DataScope;
/**
@ -95,4 +96,12 @@ public interface IHwDeviceService
*/
public Map<String,List<HwDeviceVo>> getDevicesByMonitor(HwDevice queryHwDevice);
/**
* ,join
*
* @param hwDevice
* @return
*/
public List<HwDevice> selectHwDeviceJoinList(HwDevice hwDevice);
}

@ -1,30 +1,43 @@
package com.ruoyi.business.service.impl;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.nacos.shaded.com.google.gson.JsonElement;
import com.ruoyi.business.domain.HwDevice;
import com.ruoyi.business.domain.HwDeviceModeFunction;
import com.ruoyi.business.domain.HwScene;
import com.ruoyi.business.domain.VO.DeviceModeVo;
import com.ruoyi.business.domain.VO.HwDeviceVo;
import com.ruoyi.business.mapper.HwDeviceMapper;
import com.ruoyi.business.mapper.HwDeviceModeFunctionMapper;
import com.ruoyi.business.mapper.HwSceneMapper;
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.TdEngineConstants;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.enums.DataTypeEnums;
import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.NumberUtils;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.datascope.annotation.DataScope;
import com.ruoyi.tdengine.api.RemoteTdEngineService;
import com.ruoyi.tdengine.api.domain.TdHistorySelectDto;
import com.ruoyi.tdengine.api.domain.AlterTagVo;
import com.ruoyi.tdengine.api.domain.TdField;
import com.ruoyi.tdengine.api.domain.TdSelectDto;
import com.ruoyi.tdengine.api.domain.TdTableVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import com.ruoyi.business.mapper.HwDeviceMapper;
import com.ruoyi.business.domain.HwDevice;
import com.ruoyi.business.service.IHwDeviceService;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* Service
@ -37,9 +50,13 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
@Autowired
private HwDeviceMapper hwDeviceMapper;
@Autowired
private HwSceneMapper hwSceneMapper;
@Autowired
private HwDeviceModeFunctionMapper hwDevieModeFunctionMapper;
@Autowired
private RemoteTdEngineService remoteTdEgineService;
private RemoteTdEngineService remoteTdEngineService;
@Autowired
private StringRedisTemplate redisTemplate;
/**
*
@ -64,6 +81,7 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
public HwDevice selectHwDeviceJoinByDeviceId(Long deviceId) {
return hwDeviceMapper.selectHwDeviceJoinByDeviceId(deviceId);
}
/**
*
*
@ -93,11 +111,116 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
* @param hwDevice
* @return
*/
@Transactional
@Override
public int insertHwDevice(HwDevice hwDevice) {
hwDevice.setCreateTime(DateUtils.getNowDate());
String deviceType = hwDevice.getDeviceType();
int deviceId = hwDeviceMapper.insertHwDevice(hwDevice);
if (deviceType.equals(HwDictConstants.DEVICE_TYPE_GATEWAY_DEVICE)) {
this.updateMqttAuth(hwDevice);
} else if (deviceType.equals(HwDictConstants.DEVICE_TYPE_DIRECT_CONNECT_DEVICE)) {
this.updateMqttAuth(hwDevice);
this.createTdTable(hwDevice);
} else if (deviceType.equals(HwDictConstants.DEVICE_TYPE_GATEWAY_SUB_EQUIPMENT)) {
this.createTdTable(hwDevice);
}
return deviceId;
}
/**
* @param: hwDevice
* @description redis
* @author xins
* @date 2023-09-19 10:06
*/
private void updateMqttAuth(HwDevice hwDevice) {
try {
HwScene scene = hwSceneMapper.selectHwSceneBySceneId(hwDevice.getSceneId());
String modeAccount = scene.getModeAccount();
String modeKey = scene.getModeKey();
if (StringUtils.isNotEmpty(modeAccount) && StringUtils.isNotEmpty(modeKey)) {
String deviceInfoStr = redisTemplate.opsForValue().get(HwDictConstants.REDIS_KEY_DEVICE_INFO);
JSONArray deviceInfoJsonArr = new JSONArray();
// JSONObject deviceInfoJson;
if (StringUtils.isNotEmpty(deviceInfoStr)) {
deviceInfoJsonArr = JSON.parseArray(deviceInfoStr);
}
boolean redisUpdated = false;//是否更新已有的值
for (Object deviceInfoObj : deviceInfoJsonArr) {
JSONObject deviceInfoJson = (JSONObject) deviceInfoObj;
if (deviceInfoJson.getString("deviceCode").equals(hwDevice.getDeviceCode())) {
deviceInfoJson.put("username", modeAccount);
deviceInfoJson.put("password", modeKey);
redisUpdated = true;
}
}
if (!redisUpdated) {
JSONObject deviceInfoJson = new JSONObject();
deviceInfoJson.put("deviceCode", hwDevice.getDeviceCode());
deviceInfoJson.put("username", modeAccount);
deviceInfoJson.put("password", modeKey);
deviceInfoJsonArr.add(deviceInfoJson);
}
redisTemplate.opsForValue().set(HwDictConstants.REDIS_KEY_DEVICE_INFO, deviceInfoJsonArr.toJSONString());
}
} catch (Exception e) {
throw new RuntimeException(e.getMessage());
}
}
/**
* @param: hwDevice
* @description tdenginetable
* @author xins
* @date 2023-09-19 10:07
*/
private void createTdTable(HwDevice hwDevice) {
TdTableVo tdTableVo = new TdTableVo();
String databaseName = TdEngineConstants.getDatabaseName(1L);
String superTableName = TdEngineConstants.getSuperTableName(hwDevice.getDeviceModeId());
String tableName = TdEngineConstants.getTableName(hwDevice.getDeviceId());
List<TdField> tagsFields = new ArrayList<>();
TdField deviceIdTag = new TdField();
deviceIdTag.setFieldName(TdEngineConstants.ST_TAG_DEVICEID);
deviceIdTag.setFieldValue(hwDevice.getDeviceId());
tagsFields.add(deviceIdTag);
return hwDeviceMapper.insertHwDevice(hwDevice);
TdField deviceCodeTag = new TdField();
deviceCodeTag.setFieldName(TdEngineConstants.ST_TAG_DEVICECODE);
deviceCodeTag.setFieldValue(hwDevice.getDeviceCode());
deviceCodeTag.setDataTypeCode(DataTypeEnums.NCHAR.getDataCode());
tagsFields.add(deviceCodeTag);
TdField deviceNameTag = new TdField();
deviceNameTag.setFieldName(TdEngineConstants.ST_TAG_DEVICENAME);
deviceNameTag.setFieldValue(hwDevice.getDeviceName());
deviceNameTag.setDataTypeCode(DataTypeEnums.NCHAR.getDataCode());
tagsFields.add(deviceNameTag);
TdField deviceModeIdTag = new TdField();
deviceModeIdTag.setFieldName(TdEngineConstants.ST_TAG_DEVICEMODEID);
deviceModeIdTag.setFieldValue(hwDevice.getDeviceModeId());
tagsFields.add(deviceModeIdTag);
TdField monitorUnitIdTag = new TdField();
monitorUnitIdTag.setFieldName(TdEngineConstants.ST_TAG_MONITORUNITID);
monitorUnitIdTag.setFieldValue(hwDevice.getMonitorUnitId());
tagsFields.add(monitorUnitIdTag);
tdTableVo.setDatabaseName(databaseName);
tdTableVo.setSuperTableName(superTableName);
tdTableVo.setTableName(tableName);
tdTableVo.setTagsFieldValues(tagsFields);
R<?> tdReturnMsg = this.remoteTdEngineService.createTable(tdTableVo);
if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务
throw new RuntimeException(tdReturnMsg.getMsg());
}
}
/**
@ -147,10 +270,72 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
* @param hwDevice
* @return
*/
@Transactional
@Override
public int updateHwDevice(HwDevice hwDevice) {
HwDevice dbDevice = hwDeviceMapper.selectHwDeviceByDeviceId(hwDevice.getDeviceId());
if (dbDevice.getDeviceStatus().equals(HwDictConstants.DEVICE_STATUS_PUBLISH)) {
throw new ServiceException("已发布状态不能修改");
}
hwDevice.setUpdateTime(DateUtils.getNowDate());
return hwDeviceMapper.updateHwDevice(hwDevice);
int rows = hwDeviceMapper.updateHwDevice(hwDevice);
this.updateTdEngine(hwDevice, dbDevice);
return rows;
}
/**
* @param: hwDevice
* @param: dbDevice
* @description TdEnginetag
* @author xins
* @date 2023-09-19 10:55
*/
private void updateTdEngine(HwDevice hwDevice, HwDevice dbDevice) {
String deviceType = hwDevice.getDeviceType();
String databaseName = TdEngineConstants.getDatabaseName(1L);//TODO
String tableName = TdEngineConstants.getTableName(hwDevice.getDeviceId());
AlterTagVo alterTagVo = new AlterTagVo();
alterTagVo.setDatabaseName(databaseName);
alterTagVo.setTableName(tableName);
R<?> tdReturnMsg;
if (deviceType.equals(HwDictConstants.DEVICE_TYPE_DIRECT_CONNECT_DEVICE)
|| deviceType.equals(HwDictConstants.DEVICE_TYPE_GATEWAY_SUB_EQUIPMENT)) {
if (!hwDevice.getDeviceCode().equals(dbDevice.getDeviceCode())) {
alterTagVo.setTagName(TdEngineConstants.ST_TAG_DEVICECODE);
alterTagVo.setTagValue("'"+hwDevice.getDeviceCode()+"'");
tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo);
if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务
throw new RuntimeException(tdReturnMsg.getMsg());
}
}
if (!hwDevice.getDeviceName().equals(dbDevice.getDeviceName())) {
alterTagVo.setTagName(TdEngineConstants.ST_TAG_DEVICENAME);
alterTagVo.setTagValue("'"+hwDevice.getDeviceName()+"'");
tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo);
if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务
throw new RuntimeException(tdReturnMsg.getMsg());
}
}
if (!hwDevice.getMonitorUnitId().equals(dbDevice.getMonitorUnitId())) {
alterTagVo.setTagName(TdEngineConstants.ST_TAG_MONITORUNITID);
alterTagVo.setTagValue(hwDevice.getMonitorUnitId());
tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo);
if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务
throw new RuntimeException(tdReturnMsg.getMsg());
}
}
if (!hwDevice.getDeviceModeId().equals(dbDevice.getDeviceModeId())) {
alterTagVo.setTagName(TdEngineConstants.ST_TAG_DEVICEMODEID);
alterTagVo.setTagValue(hwDevice.getDeviceModeId());
tdReturnMsg = this.remoteTdEngineService.alterTableTag(alterTagVo);
if (tdReturnMsg.getCode() != Constants.SUCCESS) {//抛出异常,回滚事务
throw new RuntimeException(tdReturnMsg.getMsg());
}
}
}
}
/**
@ -198,7 +383,7 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
TdSelectDto tdSelectDto = new TdSelectDto();
tdSelectDto.setDatabaseName(databaseName);
tdSelectDto.setTableName(tableName);
List<Map<String, Object>> deviceLatestDataMapList = (List<Map<String, Object>>) this.remoteTdEgineService.getLatestData(tdSelectDto).getData();
List<Map<String, Object>> deviceLatestDataMapList = (List<Map<String, Object>>) this.remoteTdEngineService.getLatestData(tdSelectDto).getData();
HwDeviceModeFunction queryDeviceModeFunction = new HwDeviceModeFunction();
queryDeviceModeFunction.setDeviceModeId(hwDevice.getDeviceModeId());

@ -39,10 +39,10 @@ public class HwMonitorPlatformServiceImpl implements IHwMonitorPlatformService {
public List<Map<String, Object>> selectLatestDataByTags(DeviceLatestDataVo deviceLatestDataVo) {
TdSuperTableSelectVo tdSuperTableSelectVo = new TdSuperTableSelectVo();
String databaseName = TdEngineConstants.getDatabaseName(deviceLatestDataVo.getSceneId());
String superTableName = TdEngineConstants.getSupertTableName(deviceLatestDataVo.getDeviceModeId());
String superTableName = TdEngineConstants.getSuperTableName(deviceLatestDataVo.getDeviceModeId());
tdSuperTableSelectVo.setDatabaseName(databaseName);
tdSuperTableSelectVo.setSuperTableName(superTableName);
tdSuperTableSelectVo.setGroupByTagsName(TdEngineConstants.ST_TAG_DEVICEID);
tdSuperTableSelectVo.setGroupByTagsName(TdEngineConstants.ST_TAG_DEVICECODE);//todo,换成deviceid
if (deviceLatestDataVo.getStartTime() != 0 || deviceLatestDataVo.getEndTime() != 0) {
tdSuperTableSelectVo.setFirstFieldName(TdEngineConstants.DEFAULT_FIRST_FIELD_NAME);
}

@ -54,7 +54,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap>
<sql id="selectHwSceneVo">
select scene_id, scene_name, tenant_id, scene_mode_id, scene_pic, default_flag, scene_status, auth_mode, mode_account, mode_key, mode_secret, preserve_time, test_preserve_time, remark, create_by, create_time, update_by, update_time, scene_environment, scene_field from hw_scene
select scene_id, scene_name, tenant_id, scene_mode_id, scene_pic, default_flag, scene_status, auth_mode, mode_account, mode_key, mode_secret, preserve_time, test_preserve_time, remark, create_by, create_time, update_by, update_time, scene_environment, scene_field from hw_scene hs
</sql>
<select id="selectHwSceneVoList" parameterType="HwSceneVo" resultMap="HwSceneVoResult">

@ -110,11 +110,11 @@
<update id="createTable">
create table if not exists #{databaseName}.#{tableName}
using #{databaseName}.#{superTableName}
<foreach item="item" collection="tagsFieldValues" separator=","
open="(" close=")" index="">${item.fieldName}</foreach>
tags
<foreach item="item" collection="tagsFieldValues" separator=","
open="(" close=")" index="">
${item.fieldValue}
</foreach>
open="(" close=")" index="">#{item.fieldValue}</foreach>
</update>
@ -174,7 +174,7 @@
</update>
<update id="alterTableTag">
ALTER TABLE #{databaseName}.#{tableName} SET TAG #{tagName}=#{tagValue};
ALTER TABLE #{databaseName}.#{tableName} SET TAG #{tagName}=${tagValue};
</update>

@ -110,30 +110,6 @@
>新增
</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="success"
plain
icon="el-icon-edit"
size="mini"
:disabled="single"
@click="handleUpdate"
v-hasPermi="['business:device:edit']"
>修改
</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="danger"
plain
icon="el-icon-delete"
size="mini"
:disabled="multiple"
@click="handleDelete"
v-hasPermi="['business:device:remove']"
>删除
</el-button>
</el-col>
<el-col :span="1.5">
<el-button
type="warning"
@ -176,8 +152,8 @@
<template slot-scope="scope">
<el-switch
v-model="scope.row.deviceStatus"
active-value="0"
inactive-value="1"
active-value="1"
inactive-value="0"
@change="handleDeviceStatusChange(scope.row)"
></el-switch>
</template>
@ -228,7 +204,7 @@
<el-input v-model="form.deviceName" placeholder="请输入设备名称"/>
</el-form-item>
<el-form-item label="设备类型" prop="networkingMode">
<el-select v-model="form.deviceType" placeholder="请选择设备类型" @input="deviceTypeChange">
<el-select v-model="form.deviceType" placeholder="请选择设备类型" @input="deviceTypeChange" :disabled="deviceTypeDisabled">
<el-option
v-for="dict in dict.type.hw_device_type"
:key="dict.value"
@ -357,7 +333,7 @@
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="primary" @click="submitForm"> </el-button>
<el-button type="primary" @click="submitForm" v-if="confirmBtnVisible"> </el-button>
<el-button @click="cancel"> </el-button>
</div>
</el-dialog>
@ -434,7 +410,7 @@ export default {
editedDeviceModes: [],
//
editedGatewayDevices: [],
deviceTypeDisabled:true,
subDeviceVisible: false,//
deviceVisible: false,//
@ -442,8 +418,16 @@ export default {
DEVICE_TYPE_GATEWAY_SUB_EQUIPMENT: "2",//
DEVICE_TYPE_DIRECT_CONNECT_DEVICE: "3",//
DEVICE_ACCESS_PROTOCOL_WIFI: "1",//WIFI
DEVICE_ACCESS_PROTOCOL_MQTT: 1,//,MQTT
DEVICE_NETWORKING_MODE_WIFI: "1",// WIFI
DEVICE_DATA_FORMAT_JSON: 1,// JSON
DEVICE_STATUS_PUBLISHED: "1",//:
ACTIVE_STATUS_INACTIVE: "0",//
confirmBtnVisible : true,
//
title: "",
//
@ -556,6 +540,8 @@ export default {
},
//
reset() {
this.subDeviceVisible = true;
this.deviceVisible = false;
this.form = {
deviceId: null,
deviceCode: null,
@ -602,18 +588,23 @@ export default {
},
/** 新增按钮操作 */
handleAdd() {
this.deviceTypeDisabled = false;
this.fileList = [];
this.reset();
this.subDeviceVisible = true;
this.open = true;
this.title = "添加设备信息";
},
/** 修改按钮操作 */
handleUpdate(row) {
this.deviceTypeDisabled = true;
this.reset();
this.fileList = [];
const deviceId = row.deviceId || this.ids
getDevice(deviceId).then(response => {
if(response.data.deviceStatus===this.DEVICE_STATUS_PUBLISHED){
this.confirmBtnVisible = false;
}
if (response.data.devicePic != null) {
let previewFile = {};
@ -622,7 +613,8 @@ export default {
}
this.getEditedMonitorTree(response.data.sceneId);
if (response.data.deviceType === this.DEVICE_TYPE_GATEWAY_DEVICE || response.data.deviceType === this.DEVICE_TYPE_DIRECT_CONNECT_DEVICE) {
if (response.data.deviceType === this.DEVICE_TYPE_GATEWAY_DEVICE
|| response.data.deviceType === this.DEVICE_TYPE_DIRECT_CONNECT_DEVICE) {
this.subDeviceVisible = false;
this.deviceVisible = true;
} else {
@ -832,8 +824,9 @@ export default {
if (deviceType === this.DEVICE_TYPE_GATEWAY_DEVICE || deviceType === this.DEVICE_TYPE_DIRECT_CONNECT_DEVICE) {
this.form.releatedDeviceId = null;
this.form.deviceModeId = null;
this.form.accessProtocol = this.DEVICE_ACCESS_PROTOCOL_WIFI;
this.form.networkingMode = "1";
this.form.accessProtocol = this.DEVICE_ACCESS_PROTOCOL_MQTT;
this.form.networkingMode = this.DEVICE_NETWORKING_MODE_WIFI;
this.form.dataFormat = this.DEVICE_DATA_FORMAT_JSON;
this.deviceVisible = true;
this.subDeviceVisible = false;
} else {
@ -871,12 +864,12 @@ export default {
//
handleDeviceStatusChange(row) {
if(row.deviceStatus==='0' && row.activeStatus === '0'){
if(row.deviceStatus==='1' && row.activeStatus === '0'){
this.$modal.msgSuccess("激活后才能修改为发布状态");
row.deviceStatus = row.deviceStatus === "0" ? "1" : "0";
return;
}
let text = row.deviceStatus === "1" ? "测试" : "发布";
let text = row.deviceStatus === "0" ? "测试" : "发布";
this.$modal.confirm('确认要改为'+text+'状态吗?').then(function () {
return changeDeviceStatus(row.deviceId, row.deviceStatus);
}).then(() => {
@ -885,7 +878,6 @@ export default {
row.deviceStatus = row.deviceStatus === "0" ? "1" : "0";
});
},
}
};
</script>

Loading…
Cancel
Save