若依微服务1.9.8

tdengine:
增加获取设备状态信息列表接口
dataprocess:
离线报警处理
dev 1.9.8
xins 1 year ago
parent c167b547ad
commit c14cf38b86

@ -60,4 +60,7 @@ public interface RemoteTdEngineService {
@PostMapping("/tdengine/getLastOnlineDevices")
R<?> getLastOnlineDevices(@Validated @RequestBody DeviceStatus queryDeviceStatus, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
@PostMapping("/tdengine/getDeviceStatusList")
R<List<Map<String, Object>>> getDeviceStatusList(@Validated @RequestBody DeviceStatus queryDeviceStatus, @RequestHeader(SecurityConstants.FROM_SOURCE) String source);
}

@ -19,9 +19,9 @@ public class DeviceStatus extends BaseEntity {
private String deviceCode;
private int deviceType;
private Integer deviceType;
private int onlineStatus;
private Integer onlineStatus;
private Long sceneId;
@ -54,19 +54,19 @@ public class DeviceStatus extends BaseEntity {
this.deviceCode = deviceCode;
}
public int getDeviceType() {
public Integer getDeviceType() {
return deviceType;
}
public void setDeviceType(int deviceType) {
public void setDeviceType(Integer deviceType) {
this.deviceType = deviceType;
}
public int getOnlineStatus() {
public Integer getOnlineStatus() {
return onlineStatus;
}
public void setOnlineStatus(int onlineStatus) {
public void setOnlineStatus(Integer onlineStatus) {
this.onlineStatus = onlineStatus;
}

@ -97,6 +97,11 @@ public class RemoteTdEngineFallbackFactory implements FallbackFactory<RemoteTdEn
return R.fail("获取最近设备状态失败:" + throwable.getMessage());
}
@Override
public R<List<Map<String, Object>>> getDeviceStatusList(DeviceStatus queryDeviceStatus, String source) {
return R.fail("获取设备状态信息失败:" + throwable.getMessage());
}
};
}
}

@ -18,6 +18,8 @@ public class HwAlarmRuleLink extends BaseEntity
/** 报警规则关联ID主键 */
private Long ruleLinkId;
private String alarmRuleType;
/** 报警规则ID关联hw_alarm_rule的alarm_rule_id */
@Excel(name = "报警规则ID关联hw_alarm_rule的alarm_rule_id")
private Long alarmRuleId;
@ -42,6 +44,7 @@ public class HwAlarmRuleLink extends BaseEntity
@Excel(name = "联动设备服务的参数值json格式保存")
private String linkDeviceFunctionData;
private String linkDeviceCode;
private String linkDeviceName;
private String linkDeviceModeFunctionName;
@ -56,6 +59,15 @@ public class HwAlarmRuleLink extends BaseEntity
{
return ruleLinkId;
}
public String getAlarmRuleType() {
return alarmRuleType;
}
public void setAlarmRuleType(String alarmRuleType) {
this.alarmRuleType = alarmRuleType;
}
public void setAlarmRuleId(Long alarmRuleId)
{
this.alarmRuleId = alarmRuleId;
@ -111,6 +123,14 @@ public class HwAlarmRuleLink extends BaseEntity
return linkDeviceFunctionData;
}
public String getLinkDeviceCode() {
return linkDeviceCode;
}
public void setLinkDeviceCode(String linkDeviceCode) {
this.linkDeviceCode = linkDeviceCode;
}
public String getLinkDeviceName() {
return linkDeviceName;
}

@ -0,0 +1,338 @@
package com.ruoyi.dataprocess.domain;
import com.ruoyi.common.core.annotation.Excel;
import com.ruoyi.common.core.web.domain.BaseEntity;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import java.math.BigDecimal;
import java.util.List;
/**
* 线 hw_offline_rule
*
* @author xins
* @date 2023-11-13
*/
public class HwOfflineRule extends BaseEntity
{
private static final long serialVersionUID = 1L;
/** 离线报警规则ID */
@Excel(name = "离线报警规则ID")
private Long offlineRuleId;
/** 离线报警规则名称 */
@Excel(name = "离线报警规则名称")
private String offlineRuleName;
/** 租户ID关联hw_tenant的tenant_id */
@Excel(name = "租户ID")
private Long tenantId;
/** 所属场景关联hw_scene表的scene_id字段 */
@Excel(name = "所属场景ID")
private Long sceneId;
/** 报警级别关联表hw_alarm_level字段alarm_level_id */
@Excel(name = "报警级别ID")
private Long alarmLevelId;
/** 规则类型1设备,2监控单元,3场景 */
@Excel(name = "规则类型", readConverterExp = "1=设备,2=监控单元,3=场景")
private String ruleType;
/** 离线时间(单位:秒,大于此时间的) */
@Excel(name = "离线时间(单位:秒)")
private Long offlineTime;
/** 几分钟内掉线次数的分钟 */
@Excel(name = "几分钟内掉线次数的分钟")
private Long offlineNumberTime;
/** 几分钟内掉线次数的次数 */
@Excel(name = "几分钟内掉线次数的次数")
private Long offlineNumber;
/** 无线信号强度小于等于1=极弱,2=弱,3=中,4=强,5=极强) */
private String triggerTimeFrame;
/** 当月消耗流量(大于) */
private Long consumeTraffic;
/** 电池电量(小于),范围是0.01-1 */
private BigDecimal batteryLevel;
/** 设备掉电报警1=是,0=否) */
private String powerDownFlag;
/** 联动标识1是,0否 */
@Excel(name = "联动标识", readConverterExp = "1=是,0=否")
private String linkFlag;
/** 报警启用状态(1是,0否 */
@Excel(name = "状态(1=启用,0=禁用)")
private String alarmRuleStatus;
/** 报警推送标识(1是,0否 */
private String alarmPushFlag;
/** 报警推送内容 */
private String alarmPushContent;
/** 恢复正常推送内容 */
private String alarmRecoverContent;
/** 预留字段 */
private String offlineRuleField;
/** 报警规则联动信息信息 */
private List<HwAlarmRuleLink> hwAlarmRuleLinkList;
@Excel(name = "租户名称")
private String tenantName;
@Excel(name = "场景名称")
private String sceneName;
@Excel(name = "报警级别名称")
private String alarmLevelName;
public void setOfflineRuleId(Long offlineRuleId)
{
this.offlineRuleId = offlineRuleId;
}
public Long getOfflineRuleId()
{
return offlineRuleId;
}
public void setOfflineRuleName(String offlineRuleName)
{
this.offlineRuleName = offlineRuleName;
}
public String getOfflineRuleName()
{
return offlineRuleName;
}
public void setTenantId(Long tenantId)
{
this.tenantId = tenantId;
}
public Long getTenantId()
{
return tenantId;
}
public void setSceneId(Long sceneId)
{
this.sceneId = sceneId;
}
public Long getSceneId()
{
return sceneId;
}
public void setAlarmLevelId(Long alarmLevelId)
{
this.alarmLevelId = alarmLevelId;
}
public Long getAlarmLevelId()
{
return alarmLevelId;
}
public void setRuleType(String ruleType)
{
this.ruleType = ruleType;
}
public String getRuleType()
{
return ruleType;
}
public void setOfflineTime(Long offlineTime)
{
this.offlineTime = offlineTime;
}
public Long getOfflineTime()
{
return offlineTime;
}
public void setOfflineNumberTime(Long offlineNumberTime)
{
this.offlineNumberTime = offlineNumberTime;
}
public Long getOfflineNumberTime()
{
return offlineNumberTime;
}
public void setOfflineNumber(Long offlineNumber)
{
this.offlineNumber = offlineNumber;
}
public Long getOfflineNumber()
{
return offlineNumber;
}
public void setTriggerTimeFrame(String triggerTimeFrame)
{
this.triggerTimeFrame = triggerTimeFrame;
}
public String getTriggerTimeFrame()
{
return triggerTimeFrame;
}
public void setConsumeTraffic(Long consumeTraffic)
{
this.consumeTraffic = consumeTraffic;
}
public Long getConsumeTraffic()
{
return consumeTraffic;
}
public void setBatteryLevel(BigDecimal batteryLevel)
{
this.batteryLevel = batteryLevel;
}
public BigDecimal getBatteryLevel()
{
return batteryLevel;
}
public void setPowerDownFlag(String powerDownFlag)
{
this.powerDownFlag = powerDownFlag;
}
public String getPowerDownFlag()
{
return powerDownFlag;
}
public void setLinkFlag(String linkFlag)
{
this.linkFlag = linkFlag;
}
public String getLinkFlag()
{
return linkFlag;
}
public void setAlarmRuleStatus(String alarmRuleStatus)
{
this.alarmRuleStatus = alarmRuleStatus;
}
public String getAlarmRuleStatus()
{
return alarmRuleStatus;
}
public void setAlarmPushFlag(String alarmPushFlag)
{
this.alarmPushFlag = alarmPushFlag;
}
public String getAlarmPushFlag()
{
return alarmPushFlag;
}
public void setAlarmPushContent(String alarmPushContent)
{
this.alarmPushContent = alarmPushContent;
}
public String getAlarmPushContent()
{
return alarmPushContent;
}
public void setAlarmRecoverContent(String alarmRecoverContent)
{
this.alarmRecoverContent = alarmRecoverContent;
}
public String getAlarmRecoverContent()
{
return alarmRecoverContent;
}
public void setOfflineRuleField(String offlineRuleField)
{
this.offlineRuleField = offlineRuleField;
}
public String getOfflineRuleField()
{
return offlineRuleField;
}
public List<HwAlarmRuleLink> getHwAlarmRuleLinkList()
{
return hwAlarmRuleLinkList;
}
public void setHwAlarmRuleLinkList(List<HwAlarmRuleLink> hwAlarmRuleLinkList)
{
this.hwAlarmRuleLinkList = hwAlarmRuleLinkList;
}
public String getTenantName() {
return tenantName;
}
public void setTenantName(String tenantName) {
this.tenantName = tenantName;
}
public String getSceneName() {
return sceneName;
}
public void setSceneName(String sceneName) {
this.sceneName = sceneName;
}
public String getAlarmLevelName() {
return alarmLevelName;
}
public void setAlarmLevelName(String alarmLevelName) {
this.alarmLevelName = alarmLevelName;
}
@Override
public String toString() {
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
.append("offlineRuleId", getOfflineRuleId())
.append("offlineRuleName", getOfflineRuleName())
.append("tenantId", getTenantId())
.append("sceneId", getSceneId())
.append("alarmLevelId", getAlarmLevelId())
.append("ruleType", getRuleType())
.append("offlineTime", getOfflineTime())
.append("offlineNumberTime", getOfflineNumberTime())
.append("offlineNumber", getOfflineNumber())
.append("triggerTimeFrame", getTriggerTimeFrame())
.append("consumeTraffic", getConsumeTraffic())
.append("batteryLevel", getBatteryLevel())
.append("powerDownFlag", getPowerDownFlag())
.append("linkFlag", getLinkFlag())
.append("alarmRuleStatus", getAlarmRuleStatus())
.append("alarmPushFlag", getAlarmPushFlag())
.append("alarmPushContent", getAlarmPushContent())
.append("alarmRecoverContent", getAlarmRecoverContent())
.append("remark", getRemark())
.append("createBy", getCreateBy())
.append("createTime", getCreateTime())
.append("updateBy", getUpdateBy())
.append("updateTime", getUpdateTime())
.append("offlineRuleField", getOfflineRuleField())
.append("hwAlarmRuleLinkList", getHwAlarmRuleLinkList())
.toString();
}
}

@ -0,0 +1,34 @@
package com.ruoyi.dataprocess.mapper;
import com.ruoyi.dataprocess.domain.HwAlarmRuleLink;
import com.ruoyi.dataprocess.domain.HwOfflineRule;
import java.util.List;
/**
* 线Mapper
*
* @author xins
* @date 2023-11-13
*/
public interface HwOfflineRuleMapper
{
/**
* 线
*
* @param deviceId Id
* @return 线
*/
public HwOfflineRule selectHwOfflineRuleByDeviceId(Long deviceId);
/**
* 线
*
* @param sceneId Id
* @return 线
*/
public HwOfflineRule selectHwOfflineRuleBySceneId(Long sceneId);
}

@ -0,0 +1,38 @@
package com.ruoyi.dataprocess.service;
import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.constant.HwDictConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
@Service
public class CommanHandleService {
@Autowired
private StringRedisTemplate redisTemplate;
/**
* @param: controlCommandTopic
* @param: subDeviceCode
* @param: serviceFunctionIdentifier
* @description
* @author xins
* @date 2023-11-07 16:28
*/
public void publishControlCommand(String controlCommandTopic, String subDeviceCode, String serviceFunctionIdentifier) {
JSONObject controlCommandJson = new JSONObject();
JSONObject payloadJson = new JSONObject();
JSONObject paramJson = new JSONObject();
paramJson.put(HwDictConstants.CONTROL_COMMAND_PAYLOAD_UID_KEY, subDeviceCode);//子设备或直连设备设备编号
payloadJson.put(HwDictConstants.CONTROL_COMMAND_PAYLOAD_MID_KEY, "");
payloadJson.put(HwDictConstants.CONTROL_COMMAND_PAYLOAD_TIMESTAMP_KEY, System.currentTimeMillis() / 1000);//单位s
payloadJson.put(HwDictConstants.CONTROL_COMMAND_PAYLOAD_TYPE_KEY, serviceFunctionIdentifier);
payloadJson.put(HwDictConstants.CONTROL_COMMAND_PAYLOAD_PARAM_KEY, paramJson);
controlCommandJson.put(HwDictConstants.CONTROL_COMMAND_TOPIC_KEY, controlCommandTopic);
controlCommandJson.put(HwDictConstants.CONTROL_COMMAND_PAYLOAD_KEY, payloadJson.toString());
redisTemplate.convertAndSend(HwDictConstants.CONTROL_COMMAND_REDIS_KEY, controlCommandJson.toString());
}
}

@ -17,6 +17,7 @@ import com.ruoyi.dataprocess.amap.PositionVo;
import com.ruoyi.dataprocess.common.ImageUtils;
import com.ruoyi.dataprocess.domain.*;
import com.ruoyi.dataprocess.mapper.*;
import com.ruoyi.dataprocess.service.CommanHandleService;
import com.ruoyi.dataprocess.service.IDataProcessService;
import com.ruoyi.tdengine.api.RemoteTdEngineService;
import com.ruoyi.tdengine.api.domain.TdField;
@ -50,7 +51,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
* @Version :1.0
*/
@Service
public class DataProcessServiceImpl implements IDataProcessService {
public class DataProcessServiceImpl extends CommanHandleService implements IDataProcessService {
private static final Logger logger = LoggerFactory.getLogger(DataProcessServiceImpl.class);
@Resource
@ -71,9 +72,6 @@ public class DataProcessServiceImpl implements IDataProcessService {
@Autowired
private HwAlarmRuleMapper hwAlarmRuleMapper;
@Autowired
private StringRedisTemplate redisTemplate;
/**
* @param: jsonData
* @param: imagePath ruoyifile
@ -409,6 +407,7 @@ public class DataProcessServiceImpl implements IDataProcessService {
hwAlarmInfoMapper.insertHwAlarmInfo(alarmInfo);
this.insertHwAlarmDetail(alarmInfo);
this.handleAlarmLink(alarmRule, topic, subDeviceCode);
break;
}
}
}
@ -444,40 +443,15 @@ public class DataProcessServiceImpl implements IDataProcessService {
* @date 2023-11-07 16:39
*/
private void handleAlarmLink(HwAlarmRule alarmRule, String topic, String subDeviceCode) {
String controlCommandTopic = topic.replace(HwDictConstants.TOPIC_TYPE_DATA_POSTFIX, HwDictConstants.TOPIC_TYPE_COMMAND_POSTFIX);
if (alarmRule.getLinkFlag().equals(HwDictConstants.ALARM_RULE_LINK_FLAG_YES)) {
List<HwAlarmRuleLink> alarmRuleLinks = alarmRule.getHwAlarmRuleLinkList();
alarmRuleLinks.forEach(alarmRuleLink -> {
this.publishControlCommand(topic, subDeviceCode, alarmRuleLink.getLinkDeviceFunctionIdentifier());
this.publishControlCommand(controlCommandTopic, subDeviceCode, alarmRuleLink.getLinkDeviceFunctionIdentifier());
});
}
}
/**
* @param: topic
* @param: subDeviceCode
* @param: serviceFunctionIdentifier
* @description
* @author xins
* @date 2023-11-07 16:28
*/
private void publishControlCommand(String topic, String subDeviceCode, String serviceFunctionIdentifier) {
JSONObject controlCommandJson = new JSONObject();
String controlCommandTopic = topic.replace(HwDictConstants.TOPIC_TYPE_DATA_POSTFIX, HwDictConstants.TOPIC_TYPE_COMMAND_POSTFIX);
JSONObject payloadJson = new JSONObject();
JSONObject paramJson = new JSONObject();
paramJson.put(HwDictConstants.CONTROL_COMMAND_PAYLOAD_UID_KEY, subDeviceCode);//子设备或直连设备设备编号
payloadJson.put(HwDictConstants.CONTROL_COMMAND_PAYLOAD_MID_KEY, "");
payloadJson.put(HwDictConstants.CONTROL_COMMAND_PAYLOAD_TIMESTAMP_KEY, System.currentTimeMillis() / 1000);//单位s
payloadJson.put(HwDictConstants.CONTROL_COMMAND_PAYLOAD_TYPE_KEY, serviceFunctionIdentifier);
payloadJson.put(HwDictConstants.CONTROL_COMMAND_PAYLOAD_PARAM_KEY, paramJson);
controlCommandJson.put(HwDictConstants.CONTROL_COMMAND_TOPIC_KEY, controlCommandTopic);
controlCommandJson.put(HwDictConstants.CONTROL_COMMAND_PAYLOAD_KEY, payloadJson.toString());
redisTemplate.convertAndSend(HwDictConstants.CONTROL_COMMAND_REDIS_KEY, controlCommandJson.toString());
}
@Override
public void testBase64(String jsonData, String imagePath, String imagePatterns, String imageDomain, String imagePrefix) {
JSONObject json = JSON.parseObject(jsonData);

@ -5,10 +5,16 @@ import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.core.constant.HwDictConstants;
import com.ruoyi.common.core.constant.SecurityConstants;
import com.ruoyi.common.core.constant.TdEngineConstants;
import com.ruoyi.dataprocess.domain.HwDevice;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.dataprocess.domain.*;
import com.ruoyi.dataprocess.mapper.HwAlarmInfoMapper;
import com.ruoyi.dataprocess.mapper.HwDeviceMapper;
import com.ruoyi.dataprocess.mapper.HwOfflineRuleMapper;
import com.ruoyi.dataprocess.service.CommanHandleService;
import com.ruoyi.dataprocess.service.IDeviceStatusService;
import com.ruoyi.tdengine.api.RemoteTdEngineService;
import com.ruoyi.tdengine.api.domain.DeviceStatus;
import com.ruoyi.tdengine.api.domain.TdField;
import com.ruoyi.tdengine.api.domain.TdTableVo;
import org.springframework.beans.factory.annotation.Autowired;
@ -18,6 +24,7 @@ import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
/**
* @Description:
@ -27,11 +34,14 @@ import java.util.List;
* @Version :1.0
*/
@Service
public class DeviceStatusServiceImpl implements IDeviceStatusService {
public class DeviceStatusServiceImpl extends CommanHandleService implements IDeviceStatusService {
@Autowired
private HwDeviceMapper hwDeviceMapper;
@Autowired
private HwOfflineRuleMapper hwOfflineRuleMapper;
@Autowired
private HwAlarmInfoMapper hwAlarmInfoMapper;
@Resource
private RemoteTdEngineService remoteTdEngineService;
@ -81,6 +91,88 @@ public class DeviceStatusServiceImpl implements IDeviceStatusService {
}
hwDeviceMapper.updateHwDevice(hwDevice);
if (connectStatus.equals(HwDictConstants.DEVICE_ONLINE_STATUS_OFFLINE)) {
this.checkOfflineAlarm(hwDevice);
}
}
}
/**
* @param: device
* @description 线
* @author xins
* @date 2023-11-14 16:01
*/
private void checkOfflineAlarm(HwDevice device) {
Long deviceId = device.getDeviceId();
Long sceneId = device.getSceneId();
HwOfflineRule offlineRule = hwOfflineRuleMapper.selectHwOfflineRuleByDeviceId(deviceId);
if (offlineRule == null) {
offlineRule = hwOfflineRuleMapper.selectHwOfflineRuleBySceneId(sceneId);
}
if (offlineRule != null) {
Long offlineNumberTime = offlineRule.getOfflineNumberTime();//分钟
Long offlineNumber = offlineRule.getOfflineNumber();
if (offlineNumber > 1) {
Long currentTime = System.currentTimeMillis();
Long startTime = currentTime - offlineNumberTime * 60 * 1000;
DeviceStatus queryDeviceStatus = new DeviceStatus();
queryDeviceStatus.setDeviceId(deviceId);
queryDeviceStatus.setStartTime(startTime);
queryDeviceStatus.setEndTime(currentTime);
queryDeviceStatus.setOnlineStatus(0);
R<List<Map<String, Object>>> deviceStatusListR = this.remoteTdEngineService.getDeviceStatusList(queryDeviceStatus, SecurityConstants.INNER);
List<Map<String, Object>> deviceStatusList = deviceStatusListR.getData();
//在几分钟时间内离线几次的报警信息保存
if (deviceStatusList != null && deviceStatusList.size() > offlineNumber) {
insertHwAlarmInfo(device, offlineRule, deviceId);
}
} else {//只要离线就报警
insertHwAlarmInfo(device, offlineRule, deviceId);
}
}
}
private void insertHwAlarmInfo(HwDevice device, HwOfflineRule offlineRule, Long deviceId) {
Date currentDate = new Date();
HwAlarmInfo alarmInfo = new HwAlarmInfo();
alarmInfo.setAlarmInfoType(HwDictConstants.ALARM_INFO_TYPE_OFFLINE);
alarmInfo.setAlarmReleatedId(offlineRule.getOfflineRuleId());
alarmInfo.setDeviceId(deviceId);
alarmInfo.setTenantId(device.getTenantId());
alarmInfo.setSceneId(device.getSceneId());
alarmInfo.setMonitorUnitId(device.getMonitorUnitId());
alarmInfo.setAlarmLevelId(offlineRule.getAlarmLevelId());
alarmInfo.setHandleStatus(HwDictConstants.ALARM_HANDLE_STATUS_NO);
alarmInfo.setAlarmTime(currentDate);
alarmInfo.setCreateTime(currentDate);
hwAlarmInfoMapper.insertHwAlarmInfo(alarmInfo);
this.handleAlarmLink(offlineRule, device.getDeviceCode());
}
/**
* @param: offlineRule
* @param: deviceCode
* @description
* @author xins
* @date 2023-11-07 16:39
*/
private void handleAlarmLink(HwOfflineRule offlineRule, String deviceCode) {
String controlCommandTopic = StringUtils
.format(HwDictConstants.CONTROL_COMMAND_TOPIC_VALUE, deviceCode);
if (offlineRule.getLinkFlag().equals(HwDictConstants.ALARM_RULE_LINK_FLAG_YES)) {
List<HwAlarmRuleLink> offlineRuleLinks = offlineRule.getHwAlarmRuleLinkList();
offlineRuleLinks.forEach(offlineRuleLink -> {
this.publishControlCommand(controlCommandTopic, deviceCode, offlineRuleLink.getLinkDeviceFunctionIdentifier());
});
}
}
}

@ -59,7 +59,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select a.alarm_rule_id, a.alarm_rule_name, a.tenant_id, a.scene_id, a.language_code, a.alarm_level_id, a.alarm_type_id, a.rule_type, a.rule_device_id, a.rule_function_total, a.trigger_expression, a.link_flag, a.alarm_rule_status, a.alarm_push_flag, a.alarm_push_content, a.alarm_recover_content, a.remark, a.create_by, a.create_time, a.update_by, a.update_time, a.alarm_rule_field,
b.rule_link_id as sub_rule_link_id, b.alarm_rule_id as sub_alarm_rule_id, b.link_type as sub_link_type, b.link_device_id as sub_link_device_id, b.link_device_function_id as sub_link_device_function_id, b.link_device_function_identifier as sub_link_device_function_identifier, b.link_device_function_data as sub_link_device_function_data
from hw_alarm_rule a
left join hw_alarm_rule_link b on b.alarm_rule_id = a.alarm_rule_id
left join hw_alarm_rule_link b on b.alarm_rule_id = a.alarm_rule_id and b.alarm_rule_type=1
<where>
<if test="alarmRuleName != null and alarmRuleName != ''"> and a.alarm_rule_name like concat('%', #{alarmRuleName}, '%')</if>
<if test="tenantId != null "> and a.tenant_id = #{tenantId}</if>

@ -0,0 +1,118 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ruoyi.dataprocess.mapper.HwOfflineRuleMapper">
<resultMap type="HwOfflineRule" id="HwOfflineRuleResult">
<result property="offlineRuleId" column="offline_rule_id"/>
<result property="offlineRuleName" column="offline_rule_name"/>
<result property="tenantId" column="tenant_id"/>
<result property="sceneId" column="scene_id"/>
<result property="alarmLevelId" column="alarm_level_id"/>
<result property="ruleType" column="rule_type"/>
<result property="offlineTime" column="offline_time"/>
<result property="offlineNumberTime" column="offline_number_time"/>
<result property="offlineNumber" column="offline_number"/>
<result property="triggerTimeFrame" column="trigger_time_frame"/>
<result property="consumeTraffic" column="consume_traffic"/>
<result property="batteryLevel" column="battery_level"/>
<result property="powerDownFlag" column="power_down_flag"/>
<result property="linkFlag" column="link_flag"/>
<result property="alarmRuleStatus" column="alarm_rule_status"/>
<result property="alarmPushFlag" column="alarm_push_flag"/>
<result property="alarmPushContent" column="alarm_push_content"/>
<result property="alarmRecoverContent" column="alarm_recover_content"/>
<result property="remark" column="remark"/>
<result property="createBy" column="create_by"/>
<result property="createTime" column="create_time"/>
<result property="updateBy" column="update_by"/>
<result property="updateTime" column="update_time"/>
<result property="offlineRuleField" column="offline_rule_field"/>
<result property="tenantName" column="tenant_name"/>
<result property="sceneName" column="scene_name"/>
<result property="alarmLevelName" column="alarm_level_name"/>
</resultMap>
<resultMap id="HwOfflineRuleHwAlarmRuleLinkResult" type="HwOfflineRule" extends="HwOfflineRuleResult">
<collection property="hwAlarmRuleLinkList" notNullColumn="sub_rule_link_id" javaType="java.util.List"
resultMap="HwAlarmRuleLinkResult"/>
</resultMap>
<resultMap type="HwAlarmRuleLink" id="HwAlarmRuleLinkResult">
<result property="ruleLinkId" column="sub_rule_link_id"/>
<result property="alarmRuleType" column="sub_alarm_rule_type"/>
<result property="alarmRuleId" column="sub_alarm_rule_id"/>
<result property="linkType" column="sub_link_type"/>
<result property="linkDeviceId" column="sub_link_device_id"/>
<result property="linkDeviceFunctionId" column="sub_link_device_function_id"/>
<result property="linkDeviceFunctionIdentifier" column="sub_link_device_function_identifier"/>
<result property="linkDeviceFunctionData" column="sub_link_device_function_data"/>
<result property="linkDeviceCode" column="sub_link_device_code"/>
</resultMap>
<select id="selectHwOfflineRuleByDeviceId" parameterType="Long" resultMap="HwOfflineRuleHwAlarmRuleLinkResult">
select a.offline_rule_id,
a.rule_type,
a.offline_time,
a.offline_number_time,
a.offline_number,
a.alarm_level_id,
a.trigger_time_frame,
a.consume_traffic,
a.battery_level,
a.power_down_flag,
a.link_flag,
a.alarm_rule_status,
a.alarm_push_flag,
a.alarm_push_content,
b.rule_link_id as sub_rule_link_id,
b.alarm_rule_type as sub_alarm_rule_type,
b.alarm_rule_id as sub_alarm_rule_id,
b.link_type as sub_link_type,
b.link_device_id as sub_link_device_id,
b.link_device_function_identifier as sub_link_device_function_identifier,
b.link_device_function_data as sub_link_device_function_data,
hd.device_code as sub_link_device_code
from hw_offline_rule a
left join hw_alarm_rule_link b on b.alarm_rule_id = a.offline_rule_id and b.alarm_rule_type = 2
left join hw_device hd on b.link_device_id = hd.device_id
where exists (select 1
from hw_offline_target hot
where hot.offline_rule_id = a.offline_rule_id
and hot.target_type = '1'
and hot.target_id = #{deviceId}) limit 1
</select>
<select id="selectHwOfflineRuleBySceneId" parameterType="Long" resultMap="HwOfflineRuleHwAlarmRuleLinkResult">
select a.offline_rule_id,
a.rule_type,
a.offline_time,
a.offline_number_time,
a.offline_number,
a.alarm_level_id,
a.trigger_time_frame,
a.consume_traffic,
a.battery_level,
a.power_down_flag,
a.link_flag,
a.alarm_rule_status,
a.alarm_push_flag,
a.alarm_push_content,
b.rule_link_id as sub_rule_link_id,
b.alarm_rule_type as sub_alarm_rule_type,
b.alarm_rule_id as sub_alarm_rule_id,
b.link_type as sub_link_type,
b.link_device_id as sub_link_device_id,
b.link_device_function_identifier as sub_link_device_function_identifier,
b.link_device_function_data as sub_link_device_function_data,
hd.device_code as sub_link_device_code
from hw_offline_rule a
left join hw_alarm_rule_link b on b.alarm_rule_id = a.offline_rule_id and b.alarm_rule_type = 2
left join hw_device hd on b.link_device_id = hd.device_id
where a.scene_id = #{sceneId} limit 1
</select>
</mapper>

@ -398,7 +398,7 @@ public class TdEngineController {
/**
* @return R<?>
* @param: tdSelectDto
* @param: queryDeviceStatus
* @description 线
* @author xins
* @date 2023-08-29 11:26
@ -428,7 +428,7 @@ public class TdEngineController {
/**
* @return R<?>
* @param: tdSelectDto
* @param: queryDeviceStatus
* @description 线
* @author xins
* @date 2023-08-29 11:26
@ -453,4 +453,32 @@ public class TdEngineController {
}
}
/**
* @return R<?>
* @param: tdSelectDto
* @description 线
* @author xins
* @date 2023-08-29 11:26
*/
@InnerAuth
@PostMapping("/getDeviceStatusList")
public R<List<Map<String, Object>>> getDeviceStatusList(@RequestBody DeviceStatus queryDeviceStatus) {
try {
List<Map<String,Object>> deviceStatusMapList = this.deviceStatusService.getDeviceStatusList(queryDeviceStatus);
return R.ok(deviceStatusMapList);
} 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());
}
}
}

@ -32,4 +32,13 @@ public interface DeviceStatusMapper {
*/
List<Map<String, Object>> getLastOnlineDevices(DeviceStatus deviceStatus);
/**
* @param: deviceStatus
* @description
* @author xins
* @date 2023-09-05 11:43
* @return List<DeviceStatus>
*/
List<Map<String, Object>> getDeviceStatusList(DeviceStatus deviceStatus);
}

@ -24,4 +24,13 @@ public interface IDeviceStatusService {
* @date 2023-09-05 13:23
*/
public List<Map<String, Object>> getLastOnlineDevices(DeviceStatus queryDeviceStatus);
/**
* @return List<Map<String, Object>>
* @param: DeviceStatus
* @description
* @author xins
* @date 2023-09-05 13:23
*/
public List<Map<String, Object>> getDeviceStatusList(DeviceStatus queryDeviceStatus);
}

@ -66,12 +66,8 @@ public class DeviceStatusServiceImpl implements IDeviceStatusService {
List<Map<String, Object>> deviceStatusMap = deviceStatusMapper.getLastOnlineDevices(queryDeviceStatus);
List<Map<String, Object>> filterMaps = new ArrayList<>();
//tdengine在select时row会带着括号需要将括号过滤掉
for (Map<String, Object> latestMap : deviceStatusMap) {
Set<String> kk = latestMap.keySet();
for(String k : kk){
System.out.println(k+"==="+latestMap.get(k));
}
Map<String, Object> filterMap = latestMap.entrySet()
.stream()
.filter(entry -> entry.getValue() != null)
@ -84,4 +80,21 @@ public class DeviceStatusServiceImpl implements IDeviceStatusService {
return filterMaps;
}
/**
* @return List<Map<String, Object>>
* @param: DeviceStatus
* @description
* @author xins
* @date 2023-09-05 13:23
*/
@Override
public List<Map<String, Object>> getDeviceStatusList(DeviceStatus queryDeviceStatus) {
Map<String, Object> params = queryDeviceStatus.getParams();
params.put("databaseName", TdEngineConstants.PLATFORM_DB_NAME);
params.put("tableName", TdEngineConstants.getDeviceStatusTableName(queryDeviceStatus.getDeviceId()));
List<Map<String, Object>> deviceStatusMap = deviceStatusMapper.getDeviceStatusList(queryDeviceStatus);
return deviceStatusMap;
}
}

@ -26,5 +26,20 @@
</select>
<select id="getDeviceStatusList" parameterType="com.ruoyi.tdengine.api.domain.DeviceStatus" resultType="java.util.Map" >
select ts,onlinestatus from #{params.databaseName}.#{params.tableName}
<where>
<if test="startTime!= null and startTime != 0">
and ts &gt; #{startTime}
</if>
<if test="endTime!= null and endTime != 0">
and ts &lt; #{endTime}
</if>
<if test="onlineStatus!= null">
and onlinestatus = #{onlineStatus}
</if>
</where>
</select>
</mapper>

Loading…
Cancel
Save