若依微服务1.2.4

1、TDengine服务完善
2、设备管理新增时在tdengine创建表,在redis存储用户名和密码
3、监控平台接口修改
master
xins 2 years 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_GATEWAY_SUB_EQUIPMENT = "2";//网关子设备
public static final String DEVICE_TYPE_DIRECT_CONNECT_DEVICE = "3";//直连设备 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 * @date 2023-09-16 14:42
* @return String * @return String
*/ */
public static String getSupertTableName(Long deviceModeId) { public static String getSuperTableName(Long deviceModeId) {
return DEFAULT_SUPER_TABLE_NAME_PREFIX + deviceModeId; return DEFAULT_SUPER_TABLE_NAME_PREFIX + deviceModeId;
} }
public static String getTableName(Long deviceId) {
return DEFAULT_TABLE_NAME_PREFIX + deviceId;
}
/** /**
* @param: deviceId * @param: deviceId
* @return String * @return String

@ -17,6 +17,8 @@ import com.ruoyi.common.core.constant.HwDictConstants;
import com.ruoyi.common.security.utils.SecurityUtils; import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.system.api.domain.SysDept; import com.ruoyi.system.api.domain.SysDept;
import com.ruoyi.system.api.domain.SysRole; 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.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
@ -104,6 +106,10 @@ public class HwDeviceController extends BaseController
@PostMapping @PostMapping
public AjaxResult add(@RequestBody HwDevice hwDevice) 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)); return toAjax(hwDeviceService.insertHwDevice(hwDevice));
} }
@ -115,6 +121,7 @@ public class HwDeviceController extends BaseController
@PutMapping @PutMapping
public AjaxResult edit(@RequestBody HwDevice hwDevice) public AjaxResult edit(@RequestBody HwDevice hwDevice)
{ {
hwDevice.setUpdateBy(SecurityUtils.getUsername());
return toAjax(hwDeviceService.updateHwDevice(hwDevice)); return toAjax(hwDeviceService.updateHwDevice(hwDevice));
} }

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

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

@ -80,4 +80,12 @@ public interface HwDeviceMapper
public List<HwDevice> selectLinkedDevices(Long deviceId); 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.DeviceModeVo;
import com.ruoyi.business.domain.VO.HwDeviceVo; import com.ruoyi.business.domain.VO.HwDeviceVo;
import com.ruoyi.business.domain.VO.HwMonitorUnitVo; 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); public Map<String,List<HwDeviceVo>> getDevicesByMonitor(HwDevice queryHwDevice);
/**
* ,join
*
* @param hwDevice
* @return
*/
public List<HwDevice> selectHwDeviceJoinList(HwDevice hwDevice);
} }

@ -1,31 +1,44 @@
package com.ruoyi.business.service.impl; package com.ruoyi.business.service.impl;
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.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 org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import com.ruoyi.business.domain.HwDeviceModeFunction;
import com.ruoyi.business.domain.VO.DeviceModeVo;
import com.ruoyi.business.domain.VO.HwDeviceVo;
import com.ruoyi.business.mapper.HwDeviceModeFunctionMapper;
import com.ruoyi.common.core.constant.HwDictConstants;
import com.ruoyi.common.core.constant.TdEngineConstants;
import com.ruoyi.common.core.enums.DataTypeEnums;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.NumberUtils;
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.TdSelectDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.business.mapper.HwDeviceMapper;
import com.ruoyi.business.domain.HwDevice;
import com.ruoyi.business.service.IHwDeviceService;
/** /**
* Service * Service
* *
@ -37,9 +50,13 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
@Autowired @Autowired
private HwDeviceMapper hwDeviceMapper; private HwDeviceMapper hwDeviceMapper;
@Autowired @Autowired
private HwSceneMapper hwSceneMapper;
@Autowired
private HwDeviceModeFunctionMapper hwDevieModeFunctionMapper; private HwDeviceModeFunctionMapper hwDevieModeFunctionMapper;
@Autowired @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) { public HwDevice selectHwDeviceJoinByDeviceId(Long deviceId) {
return hwDeviceMapper.selectHwDeviceJoinByDeviceId(deviceId); return hwDeviceMapper.selectHwDeviceJoinByDeviceId(deviceId);
} }
/** /**
* *
* *
@ -93,11 +111,116 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
* @param hwDevice * @param hwDevice
* @return * @return
*/ */
@Transactional
@Override @Override
public int insertHwDevice(HwDevice hwDevice) { public int insertHwDevice(HwDevice hwDevice) {
hwDevice.setCreateTime(DateUtils.getNowDate()); 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;
}
return hwDeviceMapper.insertHwDevice(hwDevice); /**
* @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);
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 * @param hwDevice
* @return * @return
*/ */
@Transactional
@Override @Override
public int updateHwDevice(HwDevice hwDevice) { 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()); 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 tdSelectDto = new TdSelectDto();
tdSelectDto.setDatabaseName(databaseName); tdSelectDto.setDatabaseName(databaseName);
tdSelectDto.setTableName(tableName); 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(); HwDeviceModeFunction queryDeviceModeFunction = new HwDeviceModeFunction();
queryDeviceModeFunction.setDeviceModeId(hwDevice.getDeviceModeId()); queryDeviceModeFunction.setDeviceModeId(hwDevice.getDeviceModeId());

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

@ -54,7 +54,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</resultMap> </resultMap>
<sql id="selectHwSceneVo"> <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> </sql>
<select id="selectHwSceneVoList" parameterType="HwSceneVo" resultMap="HwSceneVoResult"> <select id="selectHwSceneVoList" parameterType="HwSceneVo" resultMap="HwSceneVoResult">

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

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

Loading…
Cancel
Save