监测平台系统离线规则功能模块实现

breach-zhy
马雪伟 2 months ago
parent 8b3e911b0c
commit b0df88a88f

@ -22,4 +22,21 @@ public class HwOfflineRuleController extends BaseController {
List<HwOfflineRule> hwOfflineRules = hwOfflineRuleService.selectRuleList(hwOfflineRule);
return getDataTable(hwOfflineRules);
}
@GetMapping("/{offlineRuleId}")
public HwOfflineRule selectOfflineRuleById(@PathVariable("offlineRuleId") Long offlineRuleId){
HwOfflineRule hwOfflineRule = hwOfflineRuleService.selectOfflineRuleById(offlineRuleId);
return hwOfflineRule;
}
@DeleteMapping("/{offlineRuleId}")
public int deleteOfflineRuleById(@PathVariable("offlineRuleId") Long offlineRuleId){
return hwOfflineRuleService.deleteOfflineRuleById(offlineRuleId);
}
@PostMapping
public int addOfflineRule(@RequestBody HwOfflineRule hwOfflineRule){
return hwOfflineRuleService.addOfflineRule(hwOfflineRule);
}
}

@ -26,6 +26,14 @@ public class BeaconDevice {
private String ifAlarm;
private String monitorUnitName;
private Boolean alarmElectronFence;
public Boolean getAlarmElectronFence() {
return alarmElectronFence;
}
public void setAlarmElectronFence(Boolean alarmElectronFence) {
this.alarmElectronFence = alarmElectronFence;
}
public String getIfAlarm() {
return ifAlarm;

@ -3,6 +3,8 @@ package com.ruoyi.business.mapper;
import java.util.List;
import com.ruoyi.business.domain.HwAlarmRule;
import com.ruoyi.business.domain.HwAlarmRuleLink;
import com.ruoyi.business.domain.HwDevice;
import com.ruoyi.business.domain.HwDeviceMode;
/**
* Mapper
@ -18,7 +20,7 @@ public interface HwAlarmRuleMapper
* @param alarmRuleId
* @return
*/
public HwAlarmRule selectHwAlarmRuleByAlarmRuleId(Long alarmRuleId);
public List<HwAlarmRule> selectHwAlarmRuleByAlarmRuleId(Long alarmRuleId);
/**
*
@ -92,4 +94,6 @@ public interface HwAlarmRuleMapper
* @return
*/
public int deleteHwAlarmRuleLinkByAlarmRuleId(Long alarmRuleId);
HwDeviceMode selectModeByDeviceId(Long deviceId);
}

@ -172,4 +172,6 @@ public interface HwDeviceMapper
Long selectDeviceIfAlarm(Long deviceId);
List<HwDevice> getDeviceByModel(Long modelId);
Long selectDeviceIfAlarmElectronFence(Long deviceId);
}

@ -9,4 +9,9 @@ public interface HwOfflineRuleMapper {
List<HwOfflineRule> selectHwOfflineRuleJoinList(HwOfflineRule hwOfflineRule);
HwOfflineRule selectOfflineRuleById(Long offlineRuleId);
int deleteOfflineRuleById(Long offlineRuleId);
int addOfflineRule(HwOfflineRule hwOfflineRule);
}

@ -6,4 +6,10 @@ import java.util.List;
public interface HwOfflineRuleService {
List<HwOfflineRule> selectRuleList(HwOfflineRule hwOfflineRule);
HwOfflineRule selectOfflineRuleById(Long offlineRuleId);
int deleteOfflineRuleById(Long offlineRuleId);
int addOfflineRule(HwOfflineRule hwOfflineRule);
}

@ -3,6 +3,7 @@ package com.ruoyi.business.service.impl;
import com.ruoyi.business.domain.HwAlarmInfo;
import com.ruoyi.business.domain.HwAlarmRule;
import com.ruoyi.business.domain.HwAlarmRuleLink;
import com.ruoyi.business.domain.HwDeviceMode;
import com.ruoyi.business.mapper.HwAlarmInfoMapper;
import com.ruoyi.business.mapper.HwAlarmRuleMapper;
import com.ruoyi.business.service.IHwAlarmRuleService;
@ -40,7 +41,17 @@ public class HwAlarmRuleServiceImpl implements IHwAlarmRuleService {
*/
@Override
public HwAlarmRule selectHwAlarmRuleByAlarmRuleId(Long alarmRuleId) {
HwAlarmRule alarmRule = hwAlarmRuleMapper.selectHwAlarmRuleByAlarmRuleId(alarmRuleId);
List<HwAlarmRule> alarmRules = hwAlarmRuleMapper.selectHwAlarmRuleByAlarmRuleId(alarmRuleId);
ArrayList<Long> ruleDeviceIds = new ArrayList<>();
for (HwAlarmRule rule : alarmRules) {
ruleDeviceIds.add(rule.getRuleDeviceId());
}
HwDeviceMode hwDeviceMode = hwAlarmRuleMapper.selectModeByDeviceId(ruleDeviceIds.get(0));
HwAlarmRule alarmRule = alarmRules.get(0);
alarmRule.setRuleDeviceIds(ruleDeviceIds);
alarmRule.setDeviceModeId(hwDeviceMode.getDeviceModeId());
alarmRule.setDeviceModeName(alarmRule.getDeviceModeName());
// HwAlarmRule alarmRule = hwAlarmRuleMapper.selectHwAlarmRuleByAlarmRuleId(alarmRuleId);
String triggerExpression = alarmRule.getTriggerExpression();
String triggerCondition = "";
if (triggerExpression.indexOf("and") > 0) {
@ -106,6 +117,7 @@ public class HwAlarmRuleServiceImpl implements IHwAlarmRuleService {
public List<HwAlarmRule> selectHwAlarmRuleJoinList(HwAlarmRule hwAlarmRule) {
hwAlarmRule.setRuleType(HwDictConstants.ALARM_RULE_RULE_TYPE_DEVICE);
return hwAlarmRuleMapper.selectHwAlarmRuleJoinList(hwAlarmRule);
}
/**
@ -145,25 +157,32 @@ public class HwAlarmRuleServiceImpl implements IHwAlarmRuleService {
@Transactional
@Override
public int updateHwAlarmRule(HwAlarmRule hwAlarmRule) {
hwAlarmRule.setUpdateTime(DateUtils.getNowDate());
hwAlarmRule.setUpdateBy(SecurityUtils.getUsername());
HwAlarmInfo queryAlarmInfo = new HwAlarmInfo();
queryAlarmInfo.setAlarmInfoType(HwDictConstants.ALARM_INFO_TYPE_DEVICE);
queryAlarmInfo.setAlarmReleatedId(hwAlarmRule.getAlarmRuleId());
List<HwAlarmInfo> alarmInfos = hwAlarmInfoMapper.selectHwAlarmInfoList(queryAlarmInfo);
if (alarmInfos == null || alarmInfos.isEmpty()) {//没有关联报警信息,才能修改表达式
String triggerExpression = this.getTriggerExpression(hwAlarmRule);
hwAlarmRule.setTriggerExpression(triggerExpression);
} else {
hwAlarmRule.setTriggerExpression(null);
}
List<Long> ruleDeviceIds = hwAlarmRule.getRuleDeviceIds();
int updateRows = 0;
for (Long ruleDeviceId : ruleDeviceIds) {
hwAlarmRule.setRuleDeviceId(ruleDeviceId);
hwAlarmRule.setUpdateTime(DateUtils.getNowDate());
hwAlarmRule.setUpdateBy(SecurityUtils.getUsername());
HwAlarmInfo queryAlarmInfo = new HwAlarmInfo();
queryAlarmInfo.setAlarmInfoType(HwDictConstants.ALARM_INFO_TYPE_DEVICE);
queryAlarmInfo.setAlarmReleatedId(hwAlarmRule.getAlarmRuleId());
List<HwAlarmInfo> alarmInfos = hwAlarmInfoMapper.selectHwAlarmInfoList(queryAlarmInfo);
if (alarmInfos == null || alarmInfos.isEmpty()) {//没有关联报警信息,才能修改表达式
String triggerExpression = this.getTriggerExpression(hwAlarmRule);
hwAlarmRule.setTriggerExpression(triggerExpression);
} else {
hwAlarmRule.setTriggerExpression(null);
}
hwAlarmRuleMapper.deleteHwAlarmRuleLinkByAlarmRuleId(hwAlarmRule.getAlarmRuleId());
if (hwAlarmRule.getLinkFlag().equals(HwDictConstants.ALARM_RULE_LINK_FLAG_YES)) {
insertHwAlarmRuleLink(hwAlarmRule);
hwAlarmRuleMapper.deleteHwAlarmRuleLinkByAlarmRuleId(hwAlarmRule.getAlarmRuleId());
if (hwAlarmRule.getLinkFlag().equals(HwDictConstants.ALARM_RULE_LINK_FLAG_YES)) {
insertHwAlarmRuleLink(hwAlarmRule);
}
int row = hwAlarmRuleMapper.updateHwAlarmRule(hwAlarmRule);
updateRows += row;
}
return hwAlarmRuleMapper.updateHwAlarmRule(hwAlarmRule);
return updateRows;
}
/**

@ -1183,6 +1183,8 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
beaconDevice.setMonitorUnitName(hwDevices.get(i).getMonitorUnitName());
//查询是否报警
Long integer = hwDeviceMapper.selectDeviceIfAlarm(hwDevices.get(i).getDeviceId());
Long integer1 = hwDeviceMapper.selectDeviceIfAlarmElectronFence(hwDevices.get(i).getDeviceId());
Boolean alarmElectronFence = false;
String ifAlarm = new String();
if (integer>0){
//正常
@ -1191,7 +1193,11 @@ public class HwDeviceServiceImpl implements IHwDeviceService {
else {
ifAlarm="0";
}
if (integer1>0){
alarmElectronFence = true;
}
beaconDevice.setIfAlarm(ifAlarm);
beaconDevice.setAlarmElectronFence(alarmElectronFence);
lists.add(beaconDevice);
}
}

@ -16,4 +16,19 @@ public class HwOfflineRuleServiceImpl implements HwOfflineRuleService {
List<HwOfflineRule> hwOfflineRules = hwOfflineRuleMapper.selectHwOfflineRuleJoinList(hwOfflineRule);
return hwOfflineRules;
}
@Override
public HwOfflineRule selectOfflineRuleById(Long offlineRuleId) {
return hwOfflineRuleMapper.selectOfflineRuleById(offlineRuleId);
}
@Override
public int deleteOfflineRuleById(Long offlineRuleId) {
return hwOfflineRuleMapper.deleteOfflineRuleById(offlineRuleId);
}
@Override
public int addOfflineRule(HwOfflineRule hwOfflineRule) {
return hwOfflineRuleMapper.addOfflineRule(hwOfflineRule);
}
}

@ -129,6 +129,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
left join hw_device_mode_function hdmf on b.link_device_function_id=hdmf.mode_function_id
where a.alarm_rule_id = #{alarmRuleId}
</select>
<select id="selectModeByDeviceId" resultType="com.ruoyi.business.domain.HwDeviceMode"
parameterType="java.lang.Long">
select b.device_mode_id device_mode_id,b.device_mode_name device_mode_name from hw_device a left join hw_device_mode b on a.device_mode_id = b.device_mode_id where a.device_id = #{deviceId}
</select>
<insert id="insertHwAlarmRule" parameterType="HwAlarmRule" useGeneratedKeys="true" keyProperty="alarmRuleId">
insert into hw_alarm_rule

@ -62,10 +62,29 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<result property="err" column="err"/>
</resultMap>
<select id="selectDeviceModeNameVo" resultMap="DeviceModeVoResult">
SELECT concat(c.scene_name,'',b.device_mode_name) as device_mode_name ,a.sum as sum FROM hw_device_mode b
LEFT JOIN (SELECT device_mode_id,count(*) as sum FROM hw_device GROUP BY device_mode_id order by sum desc
) a on a.device_mode_id = b.device_mode_id left join hw_scene c on b.scene_id = c.scene_id
-- SELECT b.device_mode_name as device_mode_name ,a.sum as sum FROM hw_device_mode b
-- LEFT JOIN (SELECT device_mode_id,count(*) as sum FROM hw_device where device_status !=9 GROUP BY device_mode_id order by sum desc
-- ) a on a.device_mode_id = b.device_mode_id left join hw_scene c on b.scene_id = c.scene_id
select a.device_mode_name,sum(a.sum) sum from (select
b.device_mode_name as device_mode_name ,
a.sum as sum
from
hw_device_mode b
left join (
select
device_mode_id,
count(*) as sum
from
hw_device
where device_status !=9
group by
device_mode_id
order by
sum desc
) a on
a.device_mode_id = b.device_mode_id
left join hw_scene c on
b.scene_id = c.scene_id) a group by a.device_mode_name
</select>
<select id="selectDeviceByDeviceModeByDeviceModeFunction" parameterType="Long" resultType="String">
select count(*) from hw_device_mode_function where device_mode_id =
@ -478,5 +497,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
select count(*) from
(select * from hw_alarm_info where device_id = #{deviceId} and handle_status = 0) as a
</select>
<select id="selectDeviceIfAlarmElectronFence" resultType="java.lang.Long" parameterType="java.lang.Long">
select count(*) from
(select * from hw_alarm_info where device_id = #{deviceId} and handle_status = 0 and alarm_info_type = 4) as a
</select>
</mapper>

@ -195,6 +195,9 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<delete id="deleteHwAlarmRuleLinkByAlarmRuleId" parameterType="Long">
delete from hw_alarm_rule_link where alarm_rule_id = #{alarmRuleId}
</delete>
<delete id="deleteOfflineRuleById" parameterType="java.lang.Long">
update hw_offline_rule set deleted_flag = 1
</delete>
<insert id="batchHwAlarmRuleLink">
insert into hw_alarm_rule_link( rule_link_id, alarm_rule_type, alarm_rule_id, link_type, link_device_id, link_device_function_id, link_device_function_identifier, link_device_function_data) values
@ -202,7 +205,59 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
( #{item.ruleLinkId}, #{item.alarmRuleType}, #{item.alarmRuleId}, #{item.linkType}, #{item.linkDeviceId}, #{item.linkDeviceFunctionId}, #{item.linkDeviceFunctionIdentifier}, #{item.linkDeviceFunctionData})
</foreach>
</insert>
<insert id="addOfflineRule" parameterType="com.ruoyi.business.domain.HwOfflineRule">
insert into hw_offline_rule
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="offlineRuleName != null and offlineRuleName != ''">offline_rule_name,</if>
<if test="tenantId != null">tenant_id,</if>
<if test="sceneId != null">scene_id,</if>
<if test="alarmLevelId != null">alarm_level_id,</if>
<if test="ruleType != null and ruleType != ''">rule_type,</if>
<if test="offlineTime != null">offline_time,</if>
<if test="offlineNumberTime != null">offline_number_time,</if>
<if test="offlineNumber != null">offline_number,</if>
<if test="triggerTimeFrame != null">trigger_time_frame,</if>
<if test="consumeTraffic != null">consume_traffic,</if>
<if test="batteryLevel != null">battery_level,</if>
<if test="powerDownFlag != null">power_down_flag,</if>
<if test="linkFlag != null and linkFlag != ''">link_flag,</if>
<if test="alarmRuleStatus != null and alarmRuleStatus != ''">alarm_rule_status,</if>
<if test="alarmPushFlag != null and alarmPushFlag != ''">alarm_push_flag,</if>
<if test="alarmPushContent != null">alarm_push_content,</if>
<if test="alarmRecoverContent != null">alarm_recover_content,</if>
<if test="remark != null">remark,</if>
<if test="createBy != null">create_by,</if>
<if test="createTime != null">create_time,</if>
<if test="updateBy != null">update_by,</if>
<if test="updateTime != null">update_time,</if>
<if test="offlineRuleField != null">offline_rule_field,</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="offlineRuleName != null and offlineRuleName != ''">#{offlineRuleName},</if>
<if test="tenantId != null">#{tenantId},</if>
<if test="sceneId != null">#{sceneId},</if>
<if test="alarmLevelId != null">#{alarmLevelId},</if>
<if test="ruleType != null and ruleType != ''">#{ruleType},</if>
<if test="offlineTime != null">#{offlineTime},</if>
<if test="offlineNumberTime != null">#{offlineNumberTime},</if>
<if test="offlineNumber != null">#{offlineNumber},</if>
<if test="triggerTimeFrame != null">#{triggerTimeFrame},</if>
<if test="consumeTraffic != null">#{consumeTraffic},</if>
<if test="batteryLevel != null">#{batteryLevel},</if>
<if test="powerDownFlag != null">#{powerDownFlag},</if>
<if test="linkFlag != null and linkFlag != ''">#{linkFlag},</if>
<if test="alarmRuleStatus != null and alarmRuleStatus != ''">#{alarmRuleStatus},</if>
<if test="alarmPushFlag != null and alarmPushFlag != ''">#{alarmPushFlag},</if>
<if test="alarmPushContent != null">#{alarmPushContent},</if>
<if test="alarmRecoverContent != null">#{alarmRecoverContent},</if>
<if test="remark != null">#{remark},</if>
<if test="createBy != null">#{createBy},</if>
<if test="createTime != null">#{createTime},</if>
<if test="updateBy != null">#{updateBy},</if>
<if test="updateTime != null">#{updateTime},</if>
<if test="offlineRuleField != null">#{offlineRuleField},</if>
</trim>
</insert>
<select id="selectHwOfflineRuleJoinList" parameterType="HwOfflineRule" resultMap="HwOfflineRuleResult">
@ -212,7 +267,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
left join hw_scene hs on hor.scene_id=hs.scene_id
left join hw_alarm_level hal on hor.alarm_level_id=hal.alarm_level_id
<where>
hor.deleted_flag = '0'
hor.deleted_flag = 0
<if test="offlineRuleName != null and offlineRuleName != ''">and hor.offline_rule_name like concat('%',
#{offlineRuleName}, '%')
</if>
@ -238,5 +293,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
</select>
<select id="selectRuleList" resultType="com.ruoyi.business.domain.HwOfflineRule"
parameterType="com.ruoyi.business.domain.HwOfflineRule"></select>
<select id="selectOfflineRuleById" resultType="com.ruoyi.business.domain.HwOfflineRule"
parameterType="java.lang.Long">
select hor.offline_rule_id,hor.offline_rule_name,hor.tenant_id,hor.scene_id,hor.alarm_level_id,hor.rule_type,hor.link_flag,hor.alarm_rule_status,
ht.tenant_name,hs.scene_name,hal.alarm_level_name
from hw_offline_rule hor left join hw_tenant ht on hor.tenant_id = ht.tenant_id
left join hw_scene hs on hor.scene_id=hs.scene_id
left join hw_alarm_level hal on hor.alarm_level_id=hal.alarm_level_id
<where>
hor.deleted_flag = 0
and hor.offline_rule_id = #{offlineRuleId}
</where>
order by hor.offline_rule_id desc
</select>
</mapper>
Loading…
Cancel
Save