diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/HwDictConstants.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/HwDictConstants.java index 87657c3..182366e 100644 --- a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/HwDictConstants.java +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/HwDictConstants.java @@ -106,7 +106,7 @@ public class HwDictConstants { public static final String CONTROL_COMMAND_PAYLOAD_TYPE_KEY = "type"; public static final String CONTROL_COMMAND_PAYLOAD_PARAM_KEY = "param"; - public static final String DEVICEMODE_GPS_FLAG_NO="0";//设备模型,非定位模型 + public static final String DEVICEMODE_GPS_FLAG_NO = "0";//设备模型,非定位模型 public static final String TENANT_STATUS_NORMAL = "1";//租户状态:正常 public static final String TENANT_STATUS_DELETED = "9";//租户状态:正常 @@ -116,5 +116,35 @@ public class HwDictConstants { public static final String MONITOR_UNIT_STATUS_NORMAL = "1";//监控单元状态:正常 public static final String MONITORY_UNIT_STATUS_DELETE = "9";//监控单元状态,删除 + public static final String TRIGGER_CONDITION_FUNCTION_IDENTIFIER = "identifier"; + public static final String TRIGGER_DATA_A = "dataA"; + public static final String TRIGGER_DATA_B = "dataB"; + public static final String DATA_MORE_THAN_A = "1"; + public static final String DATA_LESS_THAN_B = "2"; + public static final String DATA_MORE_THAN_A_AND_LESS_THAN_B = "3"; + public static final String DATA_LESS_THAN_A_OR_MORE_THAN_B = "4"; + public static final String DATA_EQUAL_A = "5"; + + public static final Map triggerConditionMap = new HashMap(); + + static { + triggerConditionMap.put(DATA_MORE_THAN_A, "{" + TRIGGER_CONDITION_FUNCTION_IDENTIFIER + "}" + ">" + TRIGGER_DATA_A); + triggerConditionMap.put(DATA_LESS_THAN_B, "{" + TRIGGER_CONDITION_FUNCTION_IDENTIFIER + "}" + "<" + TRIGGER_DATA_A); + triggerConditionMap.put(DATA_MORE_THAN_A_AND_LESS_THAN_B, "{" + TRIGGER_CONDITION_FUNCTION_IDENTIFIER + "}" + ">" + TRIGGER_DATA_A + + " and " + "{" + TRIGGER_CONDITION_FUNCTION_IDENTIFIER + "}" + "<" + TRIGGER_DATA_B); + triggerConditionMap.put(DATA_LESS_THAN_A_OR_MORE_THAN_B, "{" + TRIGGER_CONDITION_FUNCTION_IDENTIFIER + "}" + "<" + TRIGGER_DATA_A + + " or " + "{" + TRIGGER_CONDITION_FUNCTION_IDENTIFIER + "}" + ">" + TRIGGER_DATA_B); + triggerConditionMap.put(DATA_EQUAL_A, "{" + TRIGGER_CONDITION_FUNCTION_IDENTIFIER + "}" + "=" + TRIGGER_DATA_A); + } + + + public static final String ALARM_PUSH_FLAG_NO = "0";//报警推送标识:否 + public static final String ALARM_PUSH_FLAG_YES = "1";//报警推送标识:是 + + public static final String ALARM_RULE_LINK_FLAG_NO = "0";//报警联动标识:否 + public static final String ALARM_RULE_LINK_FLAG_YES = "1";//报警联动标识:是 + + public static final String ALARM_RULE_RULE_TYPE_DEVICEMODE="1";//报警规则规则类型:设备模型 + public static final String ALARM_RULE_RULE_TYPE_DEVICE="2";//报警规则规则类型:设备 } diff --git a/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/RegexUtils.java b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/RegexUtils.java new file mode 100644 index 0000000..a5c7fb6 --- /dev/null +++ b/ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/RegexUtils.java @@ -0,0 +1,51 @@ +package com.ruoyi.common.core.utils; + +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * @Description: 正则表达式通用工具类 + * @ClassName: RegexUtils + * @Author : xins + * @Date :2023-11-06 11:23 + * @Version :1.0 + */ +public class RegexUtils { + + private static final Pattern P_BRACE = Pattern.compile("\\{(.*?)\\}"); + private static final Pattern P_NUMBER = Pattern.compile("[-+]?\\d*\\.?\\d+"); + + public static final String findContentInBrace(String content){ + Matcher matcher = P_BRACE.matcher(content); + + while (matcher.find()) { + String match = matcher.group(1); + return match; + } + return ""; + } + + public static final List findNumberInText(String content){ + Matcher matcher = P_NUMBER.matcher(content); + List numbers = new ArrayList(); + while (matcher.find()) { + String match = matcher.group(); + numbers.add(match); + } + return numbers; + } + + public static void main(String[] args) { + System.out.println(findContentInBrace("{ddd}1{ddeeee}")); + + String str = "abc-123.0def456.1k888.12"; + Pattern pattern =Pattern.compile("[-+]?\\d*\\.?\\d+"); + Matcher matcher = pattern.matcher(str); + + while (matcher.find()) { + System.out.println(matcher.group()); + } + } +} diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwAlarmRuleController.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwAlarmRuleController.java index 08644c6..3447106 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwAlarmRuleController.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/controller/HwAlarmRuleController.java @@ -3,6 +3,10 @@ package com.ruoyi.business.controller; import java.util.List; import java.io.IOException; import javax.servlet.http.HttpServletResponse; + +import com.alibaba.fastjson2.JSONObject; +import com.ruoyi.business.domain.*; +import com.ruoyi.business.service.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; @@ -15,8 +19,6 @@ import org.springframework.web.bind.annotation.RestController; import com.ruoyi.common.log.annotation.Log; import com.ruoyi.common.log.enums.BusinessType; import com.ruoyi.common.security.annotation.RequiresPermissions; -import com.ruoyi.business.domain.HwAlarmRule; -import com.ruoyi.business.service.IHwAlarmRuleService; import com.ruoyi.common.core.web.controller.BaseController; import com.ruoyi.common.core.web.domain.AjaxResult; import com.ruoyi.common.core.utils.poi.ExcelUtil; @@ -24,24 +26,37 @@ import com.ruoyi.common.core.web.page.TableDataInfo; /** * 报警规则Controller - * + * * @author xins - * @date 2023-09-16 + * @date 2023-11-02 */ @RestController @RequestMapping("/alarmRule") -public class HwAlarmRuleController extends BaseController -{ +public class HwAlarmRuleController extends BaseController { @Autowired private IHwAlarmRuleService hwAlarmRuleService; + @Autowired + private IHwSceneService hwSceneService; + + @Autowired + private IHwAlarmLevelService hwAlarmLevelService; + + @Autowired + private IHwAlarmTypeService hwAlarmTypeService; + + @Autowired + private IHwDeviceService hwDeviceService; + + @Autowired + private IHwDeviceModeService hwDeviceModeService; + /** * 查询报警规则列表 */ @RequiresPermissions("business:alarmRule:list") @GetMapping("/list") - public TableDataInfo list(HwAlarmRule hwAlarmRule) - { + public TableDataInfo list(HwAlarmRule hwAlarmRule) { startPage(); List list = hwAlarmRuleService.selectHwAlarmRuleList(hwAlarmRule); return getDataTable(list); @@ -53,8 +68,7 @@ public class HwAlarmRuleController extends BaseController @RequiresPermissions("business:alarmRule:export") @Log(title = "报警规则", businessType = BusinessType.EXPORT) @PostMapping("/export") - public void export(HttpServletResponse response, HwAlarmRule hwAlarmRule) - { + public void export(HttpServletResponse response, HwAlarmRule hwAlarmRule) { List list = hwAlarmRuleService.selectHwAlarmRuleList(hwAlarmRule); ExcelUtil util = new ExcelUtil(HwAlarmRule.class); util.exportExcel(response, list, "报警规则数据"); @@ -65,8 +79,7 @@ public class HwAlarmRuleController extends BaseController */ @RequiresPermissions("business:alarmRule:query") @GetMapping(value = "/{alarmRuleId}") - public AjaxResult getInfo(@PathVariable("alarmRuleId") Long alarmRuleId) - { + public AjaxResult getInfo(@PathVariable("alarmRuleId") Long alarmRuleId) { return success(hwAlarmRuleService.selectHwAlarmRuleByAlarmRuleId(alarmRuleId)); } @@ -76,8 +89,7 @@ public class HwAlarmRuleController extends BaseController @RequiresPermissions("business:alarmRule:add") @Log(title = "报警规则", businessType = BusinessType.INSERT) @PostMapping - public AjaxResult add(@RequestBody HwAlarmRule hwAlarmRule) - { + public AjaxResult add(@RequestBody HwAlarmRule hwAlarmRule) { return toAjax(hwAlarmRuleService.insertHwAlarmRule(hwAlarmRule)); } @@ -87,8 +99,7 @@ public class HwAlarmRuleController extends BaseController @RequiresPermissions("business:alarmRule:edit") @Log(title = "报警规则", businessType = BusinessType.UPDATE) @PutMapping - public AjaxResult edit(@RequestBody HwAlarmRule hwAlarmRule) - { + public AjaxResult edit(@RequestBody HwAlarmRule hwAlarmRule) { return toAjax(hwAlarmRuleService.updateHwAlarmRule(hwAlarmRule)); } @@ -97,9 +108,57 @@ public class HwAlarmRuleController extends BaseController */ @RequiresPermissions("business:alarmRule:remove") @Log(title = "报警规则", businessType = BusinessType.DELETE) - @DeleteMapping("/{alarmRuleIds}") - public AjaxResult remove(@PathVariable Long[] alarmRuleIds) - { + @DeleteMapping("/{alarmRuleIds}") + public AjaxResult remove(@PathVariable Long[] alarmRuleIds) { return toAjax(hwAlarmRuleService.deleteHwAlarmRuleByAlarmRuleIds(alarmRuleIds)); } + + + @RequiresPermissions("business:alarmRule:list") + @GetMapping("/getScenes") + public AjaxResult getScenes(HwScene scene) { + return success(hwSceneService.selectHwSceneList(scene)); + } + + @RequiresPermissions("business:alarmRule:list") + @GetMapping("/getEditedScenes") + public AjaxResult getEditedScenes(HwScene scene) { + return success(hwSceneService.selectHwSceneList4Select(scene)); + } + + + @RequiresPermissions("business:alarmRule:list") + @GetMapping("/getSelectListBySceneId/{sceneId}") + public AjaxResult getSelectListBySceneId(@PathVariable("sceneId") Long sceneId) { + HwAlarmType alarmType = new HwAlarmType(); + alarmType.setSceneId(sceneId); + List alarmTypes = hwAlarmTypeService.selectHwAlarmTypeList(alarmType); + + HwAlarmLevel alarmLevel = new HwAlarmLevel(); + alarmLevel.setSceneId(sceneId); + List alarmLevels = hwAlarmLevelService.selectHwAlarmLevelList(alarmLevel); + + HwDevice device = new HwDevice(); + device.setSceneId(sceneId); + List devices = hwDeviceService.selectHwDeviceListWithDeviceMode(device); + + JSONObject result = new JSONObject(); + result.put("alarmTypes", alarmTypes); + result.put("alarmLevels",alarmLevels); + result.put("devices",devices); + return success(result); + } + + + @RequiresPermissions("business:alarmRule:list") + @GetMapping("/getDeviceModeByDeviceId/{deviceId}") + public AjaxResult getDeviceModeByDeviceId(@PathVariable("deviceId") Long deviceId) { + return success(hwDeviceModeService.selectHwDeviceModeByDeviceId(deviceId)); + } + + @RequiresPermissions("business:alarmRule:list") + @GetMapping("/getModeFunctionParametersByModeFunctionId/{modeFunctionId}") + public AjaxResult getModeFunctionParametersByModeFunctionId(@PathVariable("modeFunctionId") Long modeFunctionId) { + return success(hwDeviceModeService.selectDeviceModeParametersByModeFunctionId(modeFunctionId)); + } } diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/HwAlarmRule.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/HwAlarmRule.java index d9988d1..f6ca2fe 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/HwAlarmRule.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/domain/HwAlarmRule.java @@ -1,5 +1,6 @@ package com.ruoyi.business.domain; +import java.util.List; import org.apache.commons.lang3.builder.ToStringBuilder; import org.apache.commons.lang3.builder.ToStringStyle; import com.ruoyi.common.core.annotation.Excel; @@ -9,13 +10,14 @@ import com.ruoyi.common.core.web.domain.BaseEntity; * 报警规则对象 hw_alarm_rule * * @author xins - * @date 2023-09-16 + * @date 2023-11-03 */ public class HwAlarmRule extends BaseEntity { private static final long serialVersionUID = 1L; - /** 报警规则ID */ + /** 报警规则ID,主键 */ + @Excel(name = "规则ID") private Long alarmRuleId; /** 规则名称 */ @@ -23,101 +25,89 @@ public class HwAlarmRule extends BaseEntity private String alarmRuleName; /** 租户ID,关联hw_tenant的tenant_id */ - @Excel(name = "租户ID,关联hw_tenant的tenant_id") + @Excel(name = "租户ID") private Long tenantId; /** 所属场景,关联hw_scene表的scene_id字段 */ - @Excel(name = "所属场景,关联hw_scene表的scene_id字段") + @Excel(name = "场景ID") private Long sceneId; + /** 语言code,关联表hw_language的language_code字段 */ + @Excel(name = "语言code") + private String languageCode; + /** 报警级别,关联表hw_alarm_level字段alarm_level_id */ - @Excel(name = "报警级别,关联表hw_alarm_level字段alarm_level_id") + @Excel(name = "报警级别ID") private Long alarmLevelId; /** 报警类型,关联表hw_alarm_type字段alarm_type_id */ - @Excel(name = "报警类型,关联表hw_alarm_type字段alarm_type_id") + @Excel(name = "报警类型ID") private Long alarmTypeId; /** 规则类型(1、设备模型,2、设备) */ - @Excel(name = "规则类型", readConverterExp = "1=、设备模型,2、设备") + @Excel(name = "规则类型", readConverterExp = "1=设备模型,2=设备") private String ruleType; - /** 设备,关联表hw_device字段device_id */ - @Excel(name = "设备,关联表hw_device字段device_id") - private Long deviceId; - - /** 设备模型,关联表hw_device_mode字段device_mode_id */ - @Excel(name = "设备模型,关联表hw_device_mode字段device_mode_id") - private Long deviceModeId; - - /** 设备属性,关联表hw_device_mode_function字段mode_function_id */ - @Excel(name = "设备属性,关联表hw_device_mode_function字段mode_function_id") - private Long modeFunctionId; - - /** 触发条件(1、数值大于A,2、数值小于B,3、数值大于A且小于B,4、数值小于A或大于B,5、数值等于A) */ - @Excel(name = "触发条件", readConverterExp = "1=、数值大于A,2、数值小于B,3、数值大于A且小于B,4、数值小于A或大于B,5、数值等于A") - private String triggerCondition; - - /** 触发定义A值 */ - @Excel(name = "触发定义A值") - private String triggerDataA; - - /** 触发定义B值 */ - @Excel(name = "触发定义B值") - private String triggerDataB; - - /** 触发死区 */ - @Excel(name = "触发死区") - private String triggerDeadzone; + /** 规则类型为1设备模型,关联表hw_device_mode字段device_mode_id; + 规则类型为2设备,关联表hw_device字段device_id。 */ + @Excel(name = "设备或设备模型ID") + private Long ruleDeviceId; - /** 触发阈值次数 */ - @Excel(name = "触发阈值次数") - private Long triggerNumber; + /** 一共有几个属性规则 */ + private Long ruleFunctionTotal; - /** 时间范围(单位:分钟) */ - @Excel(name = "时间范围", readConverterExp = "单=位:分钟") - private Long triggerTimeFrame; + /** 表达式,例如:{}>60 or {}<-88 */ + @Excel(name = "触发规则") + private String triggerExpression; /** 联动标识(1、是,0、否) */ - @Excel(name = "联动标识", readConverterExp = "1=、是,0、否") + @Excel(name = "联动标识", readConverterExp = "1=是,0=否") private String linkFlag; - /** 联动类型(1、控制,2、采集) */ - @Excel(name = "联动类型", readConverterExp = "1=、控制,2、采集") - private String linkType; - - /** 联动设备,关联表hw_device字段device_id */ - @Excel(name = "联动设备,关联表hw_device字段device_id") - private Long linkDeviceId; - - /** 联动设备功能,关联表hw_device_mode_function字段mode_function_id */ - @Excel(name = "联动设备功能,关联表hw_device_mode_function字段mode_function_id") - private Long linkDeviceFunctionId; - - /** 联动设备属性值 */ - @Excel(name = "联动设备属性值") - private String linkDeviceFunctionData; - - /** 报警启用状态(1、是,2、否) */ - @Excel(name = "报警启用状态(1、是,2、否)") + /** 报警启用状态(1、是,0、否) */ + @Excel(name = "状态", readConverterExp = "1=启用,0=停用") private String alarmRuleStatus; - /** 报警推送标识(1、是,2、否) */ - @Excel(name = "报警推送标识(1、是,2、否)") + /** 报警推送标识(1、是,0、否) */ + @Excel(name = "报警推送标识", readConverterExp = "1=是,0=否") private String alarmPushFlag; /** 报警推送内容 */ - @Excel(name = "报警推送内容") private String alarmPushContent; /** 恢复正常推送内容 */ - @Excel(name = "恢复正常推送内容") private String alarmRecoverContent; /** 预留字段 */ - @Excel(name = "预留字段") private String alarmRuleField; + /** 报警规则联动信息信息 */ + private List hwAlarmRuleLinkList; + + + public String ruleModeFunctionIdentifier; + + private String triggerCondition; + + private Double triggerDataA; + + private Double triggerDataB; + + @Excel(name = "所属租户") + private String tenantName; + + @Excel(name = "所属场景") + private String sceneName; + + @Excel(name = "报警类型") + private String alarmTypeName; + + @Excel(name = "报警级别") + private String alarmLevelName; + + @Excel(name = "设备") + private String ruleDeviceName; + public void setAlarmRuleId(Long alarmRuleId) { this.alarmRuleId = alarmRuleId; @@ -154,6 +144,15 @@ public class HwAlarmRule extends BaseEntity { return sceneId; } + public void setLanguageCode(String languageCode) + { + this.languageCode = languageCode; + } + + public String getLanguageCode() + { + return languageCode; + } public void setAlarmLevelId(Long alarmLevelId) { this.alarmLevelId = alarmLevelId; @@ -181,176 +180,168 @@ public class HwAlarmRule extends BaseEntity { return ruleType; } - public void setDeviceId(Long deviceId) + public void setRuleDeviceId(Long ruleDeviceId) { - this.deviceId = deviceId; + this.ruleDeviceId = ruleDeviceId; } - public Long getDeviceId() + public Long getRuleDeviceId() { - return deviceId; + return ruleDeviceId; } - public void setDeviceModeId(Long deviceModeId) + public void setRuleFunctionTotal(Long ruleFunctionTotal) { - this.deviceModeId = deviceModeId; + this.ruleFunctionTotal = ruleFunctionTotal; } - public Long getDeviceModeId() + public Long getRuleFunctionTotal() { - return deviceModeId; + return ruleFunctionTotal; } - public void setModeFunctionId(Long modeFunctionId) + public void setTriggerExpression(String triggerExpression) { - this.modeFunctionId = modeFunctionId; + this.triggerExpression = triggerExpression; } - public Long getModeFunctionId() + public String getTriggerExpression() { - return modeFunctionId; + return triggerExpression; } - public void setTriggerCondition(String triggerCondition) + public void setLinkFlag(String linkFlag) { - this.triggerCondition = triggerCondition; + this.linkFlag = linkFlag; } - public String getTriggerCondition() + public String getLinkFlag() { - return triggerCondition; + return linkFlag; } - public void setTriggerDataA(String triggerDataA) + public void setAlarmRuleStatus(String alarmRuleStatus) { - this.triggerDataA = triggerDataA; + this.alarmRuleStatus = alarmRuleStatus; } - public String getTriggerDataA() + public String getAlarmRuleStatus() { - return triggerDataA; + return alarmRuleStatus; } - public void setTriggerDataB(String triggerDataB) + public void setAlarmPushFlag(String alarmPushFlag) { - this.triggerDataB = triggerDataB; + this.alarmPushFlag = alarmPushFlag; } - public String getTriggerDataB() + public String getAlarmPushFlag() { - return triggerDataB; + return alarmPushFlag; } - public void setTriggerDeadzone(String triggerDeadzone) + public void setAlarmPushContent(String alarmPushContent) { - this.triggerDeadzone = triggerDeadzone; + this.alarmPushContent = alarmPushContent; } - public String getTriggerDeadzone() + public String getAlarmPushContent() { - return triggerDeadzone; + return alarmPushContent; } - public void setTriggerNumber(Long triggerNumber) + public void setAlarmRecoverContent(String alarmRecoverContent) { - this.triggerNumber = triggerNumber; + this.alarmRecoverContent = alarmRecoverContent; } - public Long getTriggerNumber() + public String getAlarmRecoverContent() { - return triggerNumber; + return alarmRecoverContent; } - public void setTriggerTimeFrame(Long triggerTimeFrame) + public void setAlarmRuleField(String alarmRuleField) { - this.triggerTimeFrame = triggerTimeFrame; + this.alarmRuleField = alarmRuleField; } - public Long getTriggerTimeFrame() + public String getAlarmRuleField() { - return triggerTimeFrame; + return alarmRuleField; } - public void setLinkFlag(String linkFlag) + + public List getHwAlarmRuleLinkList() { - this.linkFlag = linkFlag; + return hwAlarmRuleLinkList; } - public String getLinkFlag() + public void setHwAlarmRuleLinkList(List hwAlarmRuleLinkList) { - return linkFlag; + this.hwAlarmRuleLinkList = hwAlarmRuleLinkList; } - public void setLinkType(String linkType) - { - this.linkType = linkType; + + public String getRuleModeFunctionIdentifier() { + return ruleModeFunctionIdentifier; } - public String getLinkType() - { - return linkType; + public void setRuleModeFunctionIdentifier(String ruleModeFunctionIdentifier) { + this.ruleModeFunctionIdentifier = ruleModeFunctionIdentifier; } - public void setLinkDeviceId(Long linkDeviceId) - { - this.linkDeviceId = linkDeviceId; + + public String getTriggerCondition() { + return triggerCondition; } - public Long getLinkDeviceId() - { - return linkDeviceId; + public void setTriggerCondition(String triggerCondition) { + this.triggerCondition = triggerCondition; } - public void setLinkDeviceFunctionId(Long linkDeviceFunctionId) - { - this.linkDeviceFunctionId = linkDeviceFunctionId; + + public Double getTriggerDataA() { + return triggerDataA; } - public Long getLinkDeviceFunctionId() - { - return linkDeviceFunctionId; + public void setTriggerDataA(Double triggerDataA) { + this.triggerDataA = triggerDataA; } - public void setLinkDeviceFunctionData(String linkDeviceFunctionData) - { - this.linkDeviceFunctionData = linkDeviceFunctionData; + + public Double getTriggerDataB() { + return triggerDataB; } - public String getLinkDeviceFunctionData() - { - return linkDeviceFunctionData; + public void setTriggerDataB(Double triggerDataB) { + this.triggerDataB = triggerDataB; } - public void setAlarmRuleStatus(String alarmRuleStatus) - { - this.alarmRuleStatus = alarmRuleStatus; + + public String getTenantName() { + return tenantName; } - public String getAlarmRuleStatus() - { - return alarmRuleStatus; + public void setTenantName(String tenantName) { + this.tenantName = tenantName; } - public void setAlarmPushFlag(String alarmPushFlag) - { - this.alarmPushFlag = alarmPushFlag; + + public String getSceneName() { + return sceneName; } - public String getAlarmPushFlag() - { - return alarmPushFlag; + public void setSceneName(String sceneName) { + this.sceneName = sceneName; } - public void setAlarmPushContent(String alarmPushContent) - { - this.alarmPushContent = alarmPushContent; + + public String getAlarmTypeName() { + return alarmTypeName; } - public String getAlarmPushContent() - { - return alarmPushContent; + public void setAlarmTypeName(String alarmTypeName) { + this.alarmTypeName = alarmTypeName; } - public void setAlarmRecoverContent(String alarmRecoverContent) - { - this.alarmRecoverContent = alarmRecoverContent; + + public String getAlarmLevelName() { + return alarmLevelName; } - public String getAlarmRecoverContent() - { - return alarmRecoverContent; + public void setAlarmLevelName(String alarmLevelName) { + this.alarmLevelName = alarmLevelName; } - public void setAlarmRuleField(String alarmRuleField) - { - this.alarmRuleField = alarmRuleField; + + public String getRuleDeviceName() { + return ruleDeviceName; } - public String getAlarmRuleField() - { - return alarmRuleField; + public void setRuleDeviceName(String ruleDeviceName) { + this.ruleDeviceName = ruleDeviceName; } @Override @@ -360,23 +351,14 @@ public class HwAlarmRule extends BaseEntity .append("alarmRuleName", getAlarmRuleName()) .append("tenantId", getTenantId()) .append("sceneId", getSceneId()) + .append("languageCode", getLanguageCode()) .append("alarmLevelId", getAlarmLevelId()) .append("alarmTypeId", getAlarmTypeId()) .append("ruleType", getRuleType()) - .append("deviceId", getDeviceId()) - .append("deviceModeId", getDeviceModeId()) - .append("modeFunctionId", getModeFunctionId()) - .append("triggerCondition", getTriggerCondition()) - .append("triggerDataA", getTriggerDataA()) - .append("triggerDataB", getTriggerDataB()) - .append("triggerDeadzone", getTriggerDeadzone()) - .append("triggerNumber", getTriggerNumber()) - .append("triggerTimeFrame", getTriggerTimeFrame()) + .append("ruleDeviceId", getRuleDeviceId()) + .append("ruleFunctionTotal", getRuleFunctionTotal()) + .append("triggerExpression", getTriggerExpression()) .append("linkFlag", getLinkFlag()) - .append("linkType", getLinkType()) - .append("linkDeviceId", getLinkDeviceId()) - .append("linkDeviceFunctionId", getLinkDeviceFunctionId()) - .append("linkDeviceFunctionData", getLinkDeviceFunctionData()) .append("alarmRuleStatus", getAlarmRuleStatus()) .append("alarmPushFlag", getAlarmPushFlag()) .append("alarmPushContent", getAlarmPushContent()) @@ -387,6 +369,7 @@ public class HwAlarmRule extends BaseEntity .append("updateBy", getUpdateBy()) .append("updateTime", getUpdateTime()) .append("alarmRuleField", getAlarmRuleField()) + .append("hwAlarmRuleLinkList", getHwAlarmRuleLinkList()) .toString(); } } diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwAlarmRuleMapper.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwAlarmRuleMapper.java index d805c36..fb4b659 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwAlarmRuleMapper.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/mapper/HwAlarmRuleMapper.java @@ -2,12 +2,13 @@ package com.ruoyi.business.mapper; import java.util.List; import com.ruoyi.business.domain.HwAlarmRule; +import com.ruoyi.business.domain.HwAlarmRuleLink; /** * 报警规则Mapper接口 * * @author xins - * @date 2023-09-16 + * @date 2023-11-03 */ public interface HwAlarmRuleMapper { @@ -25,7 +26,7 @@ public interface HwAlarmRuleMapper * @param hwAlarmRule 报警规则 * @return 报警规则集合 */ - public List selectHwAlarmRuleList(HwAlarmRule hwAlarmRule); + public List selectHwAlarmRuleJoinList(HwAlarmRule hwAlarmRule); /** * 新增报警规则 @@ -58,4 +59,29 @@ public interface HwAlarmRuleMapper * @return 结果 */ public int deleteHwAlarmRuleByAlarmRuleIds(Long[] alarmRuleIds); + + /** + * 批量删除报警规则联动信息 + * + * @param alarmRuleIds 需要删除的数据主键集合 + * @return 结果 + */ + public int deleteHwAlarmRuleLinkByAlarmRuleIds(Long[] alarmRuleIds); + + /** + * 批量新增报警规则联动信息 + * + * @param hwAlarmRuleLinkList 报警规则联动信息列表 + * @return 结果 + */ + public int batchHwAlarmRuleLink(List hwAlarmRuleLinkList); + + + /** + * 通过报警规则主键删除报警规则联动信息信息 + * + * @param alarmRuleId 报警规则ID + * @return 结果 + */ + public int deleteHwAlarmRuleLinkByAlarmRuleId(Long alarmRuleId); } diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwAlarmLevelService.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwAlarmLevelService.java new file mode 100644 index 0000000..92c673c --- /dev/null +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwAlarmLevelService.java @@ -0,0 +1,61 @@ +package com.ruoyi.business.service; + +import java.util.List; +import com.ruoyi.business.domain.HwAlarmLevel; + +/** + * 报警级别Service接口 + * + * @author xins + * @date 2023-09-15 + */ +public interface IHwAlarmLevelService +{ + /** + * 查询报警级别 + * + * @param alarmLevelId 报警级别主键 + * @return 报警级别 + */ + public HwAlarmLevel selectHwAlarmLevelByAlarmLevelId(Long alarmLevelId); + + /** + * 查询报警级别列表 + * + * @param hwAlarmLevel 报警级别 + * @return 报警级别集合 + */ + public List selectHwAlarmLevelList(HwAlarmLevel hwAlarmLevel); + + /** + * 新增报警级别 + * + * @param hwAlarmLevel 报警级别 + * @return 结果 + */ + public int insertHwAlarmLevel(HwAlarmLevel hwAlarmLevel); + + /** + * 修改报警级别 + * + * @param hwAlarmLevel 报警级别 + * @return 结果 + */ + public int updateHwAlarmLevel(HwAlarmLevel hwAlarmLevel); + + /** + * 批量删除报警级别 + * + * @param alarmLevelIds 需要删除的报警级别主键集合 + * @return 结果 + */ + public int deleteHwAlarmLevelByAlarmLevelIds(Long[] alarmLevelIds); + + /** + * 删除报警级别信息 + * + * @param alarmLevelId 报警级别主键 + * @return 结果 + */ + public int deleteHwAlarmLevelByAlarmLevelId(Long alarmLevelId); +} diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwAlarmRuleService.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwAlarmRuleService.java index 73c42cc..06081de 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwAlarmRuleService.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwAlarmRuleService.java @@ -7,7 +7,7 @@ import com.ruoyi.business.domain.HwAlarmRule; * 报警规则Service接口 * * @author xins - * @date 2023-09-16 + * @date 2023-11-03 */ public interface IHwAlarmRuleService { diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwAlarmTypeService.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwAlarmTypeService.java new file mode 100644 index 0000000..356edeb --- /dev/null +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwAlarmTypeService.java @@ -0,0 +1,61 @@ +package com.ruoyi.business.service; + +import java.util.List; +import com.ruoyi.business.domain.HwAlarmType; + +/** + * 报警类型Service接口 + * + * @author xins + * @date 2023-09-15 + */ +public interface IHwAlarmTypeService +{ + /** + * 查询报警类型 + * + * @param alarmTypeId 报警类型主键 + * @return 报警类型 + */ + public HwAlarmType selectHwAlarmTypeByAlarmTypeId(Long alarmTypeId); + + /** + * 查询报警类型列表 + * + * @param hwAlarmType 报警类型 + * @return 报警类型集合 + */ + public List selectHwAlarmTypeList(HwAlarmType hwAlarmType); + + /** + * 新增报警类型 + * + * @param hwAlarmType 报警类型 + * @return 结果 + */ + public int insertHwAlarmType(HwAlarmType hwAlarmType); + + /** + * 修改报警类型 + * + * @param hwAlarmType 报警类型 + * @return 结果 + */ + public int updateHwAlarmType(HwAlarmType hwAlarmType); + + /** + * 批量删除报警类型 + * + * @param alarmTypeIds 需要删除的报警类型主键集合 + * @return 结果 + */ + public int deleteHwAlarmTypeByAlarmTypeIds(Long[] alarmTypeIds); + + /** + * 删除报警类型信息 + * + * @param alarmTypeId 报警类型主键 + * @return 结果 + */ + public int deleteHwAlarmTypeByAlarmTypeId(Long alarmTypeId); +} diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwDeviceModeService.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwDeviceModeService.java index 0d60637..d0ba61f 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwDeviceModeService.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwDeviceModeService.java @@ -125,4 +125,13 @@ public interface IHwDeviceModeService */ public void rebuildTdSuperTables(); + + /** + * 查询设备模型(报警规则中使用) + * + * @param deviceId 设备模型主键 + * @return 设备模型 + */ + public HwDeviceMode selectHwDeviceModeByDeviceId(Long deviceId); + } diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwDeviceService.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwDeviceService.java index a19a9d0..88461d4 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwDeviceService.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/IHwDeviceService.java @@ -178,4 +178,12 @@ public interface IHwDeviceService * @return JSONObject */ public JSONObject selectDeviceNum(HwDevice device); + + /** + * 查询设备信息列表(只返回网关子设备和直连设备) + * + * @param hwDevice 设备信息 + * @return 设备信息 + */ + public List selectHwDeviceListWithDeviceMode(HwDevice hwDevice); } diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwAlarmLevelServiceImpl.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwAlarmLevelServiceImpl.java new file mode 100644 index 0000000..e0cbb07 --- /dev/null +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwAlarmLevelServiceImpl.java @@ -0,0 +1,96 @@ +package com.ruoyi.business.service.impl; + +import java.util.List; +import com.ruoyi.common.core.utils.DateUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.ruoyi.business.mapper.HwAlarmLevelMapper; +import com.ruoyi.business.domain.HwAlarmLevel; +import com.ruoyi.business.service.IHwAlarmLevelService; + +/** + * 报警级别Service业务层处理 + * + * @author xins + * @date 2023-09-15 + */ +@Service +public class HwAlarmLevelServiceImpl implements IHwAlarmLevelService +{ + @Autowired + private HwAlarmLevelMapper hwAlarmLevelMapper; + + /** + * 查询报警级别 + * + * @param alarmLevelId 报警级别主键 + * @return 报警级别 + */ + @Override + public HwAlarmLevel selectHwAlarmLevelByAlarmLevelId(Long alarmLevelId) + { + return hwAlarmLevelMapper.selectHwAlarmLevelByAlarmLevelId(alarmLevelId); + } + + /** + * 查询报警级别列表 + * + * @param hwAlarmLevel 报警级别 + * @return 报警级别 + */ + @Override + public List selectHwAlarmLevelList(HwAlarmLevel hwAlarmLevel) + { + return hwAlarmLevelMapper.selectHwAlarmLevelList(hwAlarmLevel); + } + + /** + * 新增报警级别 + * + * @param hwAlarmLevel 报警级别 + * @return 结果 + */ + @Override + public int insertHwAlarmLevel(HwAlarmLevel hwAlarmLevel) + { + hwAlarmLevel.setCreateTime(DateUtils.getNowDate()); + return hwAlarmLevelMapper.insertHwAlarmLevel(hwAlarmLevel); + } + + /** + * 修改报警级别 + * + * @param hwAlarmLevel 报警级别 + * @return 结果 + */ + @Override + public int updateHwAlarmLevel(HwAlarmLevel hwAlarmLevel) + { + hwAlarmLevel.setUpdateTime(DateUtils.getNowDate()); + return hwAlarmLevelMapper.updateHwAlarmLevel(hwAlarmLevel); + } + + /** + * 批量删除报警级别 + * + * @param alarmLevelIds 需要删除的报警级别主键 + * @return 结果 + */ + @Override + public int deleteHwAlarmLevelByAlarmLevelIds(Long[] alarmLevelIds) + { + return hwAlarmLevelMapper.deleteHwAlarmLevelByAlarmLevelIds(alarmLevelIds); + } + + /** + * 删除报警级别信息 + * + * @param alarmLevelId 报警级别主键 + * @return 结果 + */ + @Override + public int deleteHwAlarmLevelByAlarmLevelId(Long alarmLevelId) + { + return hwAlarmLevelMapper.deleteHwAlarmLevelByAlarmLevelId(alarmLevelId); + } +} diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwAlarmRuleServiceImpl.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwAlarmRuleServiceImpl.java index bdf057d..8afeeed 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwAlarmRuleServiceImpl.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwAlarmRuleServiceImpl.java @@ -1,96 +1,196 @@ package com.ruoyi.business.service.impl; -import java.util.List; +import com.ruoyi.business.domain.HwAlarmRule; +import com.ruoyi.business.domain.HwAlarmRuleLink; +import com.ruoyi.business.mapper.HwAlarmRuleMapper; +import com.ruoyi.business.service.IHwAlarmRuleService; +import com.ruoyi.common.core.constant.HwDictConstants; import com.ruoyi.common.core.utils.DateUtils; +import com.ruoyi.common.core.utils.RegexUtils; +import com.ruoyi.common.core.utils.StringUtils; +import com.ruoyi.common.datascope.annotation.DataScope; +import com.ruoyi.common.security.utils.SecurityUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import com.ruoyi.business.mapper.HwAlarmRuleMapper; -import com.ruoyi.business.domain.HwAlarmRule; -import com.ruoyi.business.service.IHwAlarmRuleService; +import org.springframework.transaction.annotation.Transactional; + +import java.util.ArrayList; +import java.util.List; /** * 报警规则Service业务层处理 - * + * * @author xins - * @date 2023-09-16 + * @date 2023-11-03 */ @Service -public class HwAlarmRuleServiceImpl implements IHwAlarmRuleService -{ +public class HwAlarmRuleServiceImpl implements IHwAlarmRuleService { @Autowired private HwAlarmRuleMapper hwAlarmRuleMapper; /** * 查询报警规则 - * + * * @param alarmRuleId 报警规则主键 * @return 报警规则 */ @Override - public HwAlarmRule selectHwAlarmRuleByAlarmRuleId(Long alarmRuleId) - { - return hwAlarmRuleMapper.selectHwAlarmRuleByAlarmRuleId(alarmRuleId); + public HwAlarmRule selectHwAlarmRuleByAlarmRuleId(Long alarmRuleId) { + HwAlarmRule alarmRule = hwAlarmRuleMapper.selectHwAlarmRuleByAlarmRuleId(alarmRuleId); + String triggerExpression = alarmRule.getTriggerExpression(); + String triggerCondition = ""; + if (triggerExpression.indexOf("and") > 0) { + triggerCondition = HwDictConstants.DATA_MORE_THAN_A_AND_LESS_THAN_B; + } else if (triggerExpression.indexOf("or") > 0) { + triggerCondition = HwDictConstants.DATA_LESS_THAN_A_OR_MORE_THAN_B; + } else if (triggerExpression.indexOf(">") > 0) { + triggerCondition = HwDictConstants.DATA_MORE_THAN_A; + } else if (triggerExpression.indexOf("<") > 0) { + triggerCondition = HwDictConstants.DATA_LESS_THAN_B; + } else if (triggerExpression.indexOf("=") > 0) { + triggerCondition = HwDictConstants.DATA_EQUAL_A; + } + + alarmRule.setTriggerCondition(triggerCondition); + String ruleModeFunctionIdentifier = RegexUtils.findContentInBrace(triggerExpression); + alarmRule.setRuleModeFunctionIdentifier(ruleModeFunctionIdentifier); + triggerExpression = triggerExpression.replaceAll(ruleModeFunctionIdentifier, ""); + List triggerDataList = RegexUtils.findNumberInText(triggerExpression); + if (triggerDataList.size() == 1) { + alarmRule.setTriggerDataA(Double.valueOf(triggerDataList.get(0))); + } else if (triggerDataList.size() > 1) { + alarmRule.setTriggerDataA(Double.valueOf(triggerDataList.get(0))); + alarmRule.setTriggerDataB(Double.valueOf(triggerDataList.get(1))); + } + + return alarmRule; } /** * 查询报警规则列表 - * + * * @param hwAlarmRule 报警规则 * @return 报警规则 */ @Override - public List selectHwAlarmRuleList(HwAlarmRule hwAlarmRule) - { - return hwAlarmRuleMapper.selectHwAlarmRuleList(hwAlarmRule); + @DataScope(tenantAlias = "har") + public List selectHwAlarmRuleList(HwAlarmRule hwAlarmRule) { + hwAlarmRule.setRuleType(HwDictConstants.ALARM_RULE_RULE_TYPE_DEVICE); + return hwAlarmRuleMapper.selectHwAlarmRuleJoinList(hwAlarmRule); } /** * 新增报警规则 - * + * * @param hwAlarmRule 报警规则 * @return 结果 */ + @Transactional @Override - public int insertHwAlarmRule(HwAlarmRule hwAlarmRule) - { + public int insertHwAlarmRule(HwAlarmRule hwAlarmRule) { + String triggerExpression = this.getTriggerExpression(hwAlarmRule); + hwAlarmRule.setTriggerExpression(triggerExpression); + hwAlarmRule.setAlarmPushFlag(HwDictConstants.ALARM_PUSH_FLAG_NO); hwAlarmRule.setCreateTime(DateUtils.getNowDate()); - return hwAlarmRuleMapper.insertHwAlarmRule(hwAlarmRule); + hwAlarmRule.setTenantId(SecurityUtils.getTenantId()); + hwAlarmRule.setCreateBy(SecurityUtils.getUsername()); + int rows = hwAlarmRuleMapper.insertHwAlarmRule(hwAlarmRule); + insertHwAlarmRuleLink(hwAlarmRule); + return rows; } + /** * 修改报警规则 - * + * * @param hwAlarmRule 报警规则 * @return 结果 */ + @Transactional @Override - public int updateHwAlarmRule(HwAlarmRule hwAlarmRule) - { + public int updateHwAlarmRule(HwAlarmRule hwAlarmRule) { hwAlarmRule.setUpdateTime(DateUtils.getNowDate()); + hwAlarmRule.setUpdateBy(SecurityUtils.getUsername()); + String triggerExpression = this.getTriggerExpression(hwAlarmRule); + hwAlarmRule.setTriggerExpression(triggerExpression); + hwAlarmRuleMapper.deleteHwAlarmRuleLinkByAlarmRuleId(hwAlarmRule.getAlarmRuleId()); + if (hwAlarmRule.getLinkFlag().equals(HwDictConstants.ALARM_RULE_LINK_FLAG_YES)) { + insertHwAlarmRuleLink(hwAlarmRule); + } return hwAlarmRuleMapper.updateHwAlarmRule(hwAlarmRule); } /** * 批量删除报警规则 - * + * * @param alarmRuleIds 需要删除的报警规则主键 * @return 结果 */ + @Transactional @Override - public int deleteHwAlarmRuleByAlarmRuleIds(Long[] alarmRuleIds) - { + public int deleteHwAlarmRuleByAlarmRuleIds(Long[] alarmRuleIds) { +// hwAlarmRuleMapper.deleteHwAlarmRuleLinkByAlarmRuleIds(alarmRuleIds); return hwAlarmRuleMapper.deleteHwAlarmRuleByAlarmRuleIds(alarmRuleIds); } /** * 删除报警规则信息 - * + * * @param alarmRuleId 报警规则主键 * @return 结果 */ + @Transactional @Override - public int deleteHwAlarmRuleByAlarmRuleId(Long alarmRuleId) - { + public int deleteHwAlarmRuleByAlarmRuleId(Long alarmRuleId) { + hwAlarmRuleMapper.deleteHwAlarmRuleLinkByAlarmRuleId(alarmRuleId); return hwAlarmRuleMapper.deleteHwAlarmRuleByAlarmRuleId(alarmRuleId); } + + /** + * 新增报警规则联动信息信息 + * + * @param hwAlarmRule 报警规则对象 + */ + public void insertHwAlarmRuleLink(HwAlarmRule hwAlarmRule) { + List hwAlarmRuleLinkList = hwAlarmRule.getHwAlarmRuleLinkList(); + Long alarmRuleId = hwAlarmRule.getAlarmRuleId(); + if (StringUtils.isNotNull(hwAlarmRuleLinkList)) { + List list = new ArrayList(); + for (HwAlarmRuleLink hwAlarmRuleLink : hwAlarmRuleLinkList) { + hwAlarmRuleLink.setAlarmRuleId(alarmRuleId); + list.add(hwAlarmRuleLink); + } + if (list.size() > 0) { + hwAlarmRuleMapper.batchHwAlarmRuleLink(list); + } + } + } + + /** + * @return String + * @param: alarmRule + * @description 获取报警规则触发表达式 + * @author xins + * @date 2023-11-06 10:49 + */ + private String getTriggerExpression(HwAlarmRule alarmRule) { + String ruleModeFunctionIdentifier = alarmRule.getRuleModeFunctionIdentifier(); + String triggerCondition = alarmRule.getTriggerCondition(); + Double triggerDataA = alarmRule.getTriggerDataA(); + Double triggerDataB = alarmRule.getTriggerDataB(); + + String triggerExpression = HwDictConstants.triggerConditionMap.get(triggerCondition); + if (triggerDataA != null) { + triggerExpression = triggerExpression.replaceAll(HwDictConstants.TRIGGER_DATA_A, String.valueOf(triggerDataA)); + } + + if (triggerDataB != null) { + triggerExpression = triggerExpression.replaceAll(HwDictConstants.TRIGGER_DATA_B, String.valueOf(triggerDataB)); + } + + triggerExpression = triggerExpression.replaceAll(HwDictConstants.TRIGGER_CONDITION_FUNCTION_IDENTIFIER, ruleModeFunctionIdentifier); + + return triggerExpression; + + } } diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwAlarmTypeServiceImpl.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwAlarmTypeServiceImpl.java new file mode 100644 index 0000000..145303b --- /dev/null +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwAlarmTypeServiceImpl.java @@ -0,0 +1,96 @@ +package com.ruoyi.business.service.impl; + +import java.util.List; +import com.ruoyi.common.core.utils.DateUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import com.ruoyi.business.mapper.HwAlarmTypeMapper; +import com.ruoyi.business.domain.HwAlarmType; +import com.ruoyi.business.service.IHwAlarmTypeService; + +/** + * 报警类型Service业务层处理 + * + * @author xins + * @date 2023-09-15 + */ +@Service +public class HwAlarmTypeServiceImpl implements IHwAlarmTypeService +{ + @Autowired + private HwAlarmTypeMapper hwAlarmTypeMapper; + + /** + * 查询报警类型 + * + * @param alarmTypeId 报警类型主键 + * @return 报警类型 + */ + @Override + public HwAlarmType selectHwAlarmTypeByAlarmTypeId(Long alarmTypeId) + { + return hwAlarmTypeMapper.selectHwAlarmTypeByAlarmTypeId(alarmTypeId); + } + + /** + * 查询报警类型列表 + * + * @param hwAlarmType 报警类型 + * @return 报警类型 + */ + @Override + public List selectHwAlarmTypeList(HwAlarmType hwAlarmType) + { + return hwAlarmTypeMapper.selectHwAlarmTypeList(hwAlarmType); + } + + /** + * 新增报警类型 + * + * @param hwAlarmType 报警类型 + * @return 结果 + */ + @Override + public int insertHwAlarmType(HwAlarmType hwAlarmType) + { + hwAlarmType.setCreateTime(DateUtils.getNowDate()); + return hwAlarmTypeMapper.insertHwAlarmType(hwAlarmType); + } + + /** + * 修改报警类型 + * + * @param hwAlarmType 报警类型 + * @return 结果 + */ + @Override + public int updateHwAlarmType(HwAlarmType hwAlarmType) + { + hwAlarmType.setUpdateTime(DateUtils.getNowDate()); + return hwAlarmTypeMapper.updateHwAlarmType(hwAlarmType); + } + + /** + * 批量删除报警类型 + * + * @param alarmTypeIds 需要删除的报警类型主键 + * @return 结果 + */ + @Override + public int deleteHwAlarmTypeByAlarmTypeIds(Long[] alarmTypeIds) + { + return hwAlarmTypeMapper.deleteHwAlarmTypeByAlarmTypeIds(alarmTypeIds); + } + + /** + * 删除报警类型信息 + * + * @param alarmTypeId 报警类型主键 + * @return 结果 + */ + @Override + public int deleteHwAlarmTypeByAlarmTypeId(Long alarmTypeId) + { + return hwAlarmTypeMapper.deleteHwAlarmTypeByAlarmTypeId(alarmTypeId); + } +} diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwDeviceModeServiceImpl.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwDeviceModeServiceImpl.java index 8cd8e6c..e25b422 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwDeviceModeServiceImpl.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwDeviceModeServiceImpl.java @@ -383,6 +383,30 @@ public class HwDeviceModeServiceImpl implements IHwDeviceModeService { }); } + /** + * 查询设备模型(报警规则中使用) + * + * @param deviceId 设备模型主键 + * @return 设备模型 + */ + @Override + public HwDeviceMode selectHwDeviceModeByDeviceId(Long deviceId) { + HwDevice device = hwDeviceMapper.selectHwDeviceByDeviceId(deviceId); + HwDeviceMode deviceMode = hwDeviceModeMapper.selectHwDeviceModeByDeviceModeId(device.getDeviceModeId()); + List deviceModeFunctions = deviceMode.getHwDeviceModeFunctionList(); + //过滤只有数值的属性才可以定义报警规则.或过滤出服务可以添加关联设备 + List filterDeviceModeFunctions = deviceModeFunctions.stream() + .filter(deviceModeFunction -> (deviceModeFunction.getFunctionMode().equals(HwDictConstants.FUNCTION_MODE_ATTRIBUTE) && + deviceModeFunction.getDataType()!=null && (String.valueOf(deviceModeFunction.getDataType()).equals(String.valueOf(DataTypeEnums.INT.getDataCode())) + || String.valueOf(deviceModeFunction.getDataType()).equals(String.valueOf(DataTypeEnums.FLOAT.getDataCode())) + || String.valueOf(deviceModeFunction.getDataType()).equals(String.valueOf(DataTypeEnums.DOUBLE.getDataCode())))) + || (deviceModeFunction.getFunctionMode().equals(HwDictConstants.FUNCTION_MODE_SERVICE))) + .collect(Collectors.toList()); + deviceMode.setHwDeviceModeFunctionList(filterDeviceModeFunctions); + return deviceMode; + } + + /** * @param: hwDeviceModeFunction * @description 在编辑设备模型添加功能或者编辑功能时判断属性值 diff --git a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwDeviceServiceImpl.java b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwDeviceServiceImpl.java index 254f7fe..1e6df61 100644 --- a/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwDeviceServiceImpl.java +++ b/ruoyi-modules/hw-business/src/main/java/com/ruoyi/business/service/impl/HwDeviceServiceImpl.java @@ -3,7 +3,10 @@ package com.ruoyi.business.service.impl; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; -import com.ruoyi.business.domain.*; +import com.ruoyi.business.domain.HwDevice; +import com.ruoyi.business.domain.HwDeviceMode; +import com.ruoyi.business.domain.HwDeviceModeFunction; +import com.ruoyi.business.domain.HwScene; import com.ruoyi.business.domain.VO.DeviceControlVo; import com.ruoyi.business.domain.VO.DeviceModeVo; import com.ruoyi.business.domain.VO.DevicesInfoVo; @@ -31,7 +34,6 @@ import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.util.*; -import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; /** @@ -108,9 +110,6 @@ public class HwDeviceServiceImpl implements IHwDeviceService { @Override public List selectLinkDeviceList(Long deviceId) { List devices = hwDeviceMapper.selectLinkedDevices(deviceId); - for (HwDevice device : devices) { - device.setDevicePic("http://175.27.215.92:9665/statics/2023/09/23/6793e53d7418643c6ea9abe29be2bdce_20230923183352A001.jpg"); - } return devices; } @@ -124,7 +123,7 @@ public class HwDeviceServiceImpl implements IHwDeviceService { @Override public int insertHwDevice(HwDevice hwDevice) { HwDevice duplicateDevice = hwDeviceMapper.selectHwDeviceByDeviceCode(hwDevice.getDeviceCode()); - if(duplicateDevice != null){ + if (duplicateDevice != null) { throw new ServiceException("设备编号已经存在,请修改"); } hwDevice.setCreateTime(DateUtils.getNowDate()); @@ -695,11 +694,11 @@ public class HwDeviceServiceImpl implements IHwDeviceService { /** + * @return JSONObject * @param: device * @description 获取正上设备数量和有报警的设备数量 * @author xins * @date 2023-10-20 10:08 - * @return JSONObject */ @Override public JSONObject selectDeviceNum(HwDevice device) { @@ -768,6 +767,18 @@ public class HwDeviceServiceImpl implements IHwDeviceService { } + /** + * 查询设备信息列表(只返回网关子设备和直连设备) + * + * @param hwDevice 设备信息 + * @return 设备信息 + */ + @Override + @DataScope(tenantAlias = "hd") + public List selectHwDeviceListWithDeviceMode(HwDevice hwDevice) { + return hwDeviceMapper.selectHwDeviceListByMonitor(hwDevice); + } + private Map computeDeviceCountPerDay(Long startTime, Long endTime) { //先增加需要查询的字段名称(由于tdengine用last和last_row查询时字段显示有bug,所以需要设置要查询的字段) List schemaFields = new ArrayList(); diff --git a/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwAlarmRuleMapper.xml b/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwAlarmRuleMapper.xml index 5982648..6f8b592 100644 --- a/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwAlarmRuleMapper.xml +++ b/ruoyi-modules/hw-business/src/main/resources/mapper/business/HwAlarmRuleMapper.xml @@ -9,23 +9,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + - - - - - - - - - + + + - - - - @@ -36,46 +27,77 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + + + + + + + + + + + + + + + + + + + + + - select alarm_rule_id, alarm_rule_name, tenant_id, scene_id, alarm_level_id, alarm_type_id, rule_type, device_id, device_mode_id, mode_function_id, trigger_condition, trigger_data_a, trigger_data_b, trigger_deadzone, trigger_number, trigger_time_frame, link_flag, link_type, link_device_id, link_device_function_id, link_device_function_data, alarm_rule_status, alarm_push_flag, alarm_push_content, alarm_recover_content, remark, create_by, create_time, update_by, update_time, alarm_rule_field from hw_alarm_rule + select alarm_rule_id, alarm_rule_name, tenant_id, scene_id, language_code, alarm_level_id, alarm_type_id, rule_type, rule_device_id, rule_function_total, trigger_expression, link_flag, alarm_rule_status, alarm_push_flag, alarm_push_content, alarm_recover_content, remark, create_by, create_time, update_by, update_time, alarm_rule_field from hw_alarm_rule - + select har.alarm_rule_id,har.alarm_rule_name, har.alarm_type_id,har.alarm_level_id,har.scene_id, + har.link_flag,har.alarm_rule_status,har.alarm_push_flag,har.tenant_id,har.trigger_expression,har.rule_device_id,har.rule_type,har.language_code, + ht.tenant_name,hs.scene_name,hat.alarm_type_name,hal.alarm_level_name,hd.device_name + from hw_alarm_rule har + left join hw_tenant ht on har.tenant_id=ht.tenant_id + left join hw_scene hs on har.scene_id=hs.scene_id + left join hw_alarm_type hat on har.alarm_type_id= hat.alarm_type_id + left join hw_alarm_level hal on har.alarm_level_id = hal.alarm_level_id + left join hw_device hd on har.rule_device_id=hd.device_id + + har.alarm_rule_status !='9' + and har.alarm_rule_name like concat('%', #{alarmRuleName}, '%') + and har.tenant_id = #{tenantId} + and har.scene_id = #{sceneId} + and har.language_code = #{languageCode} + and har.alarm_level_id = #{alarmLevelId} + and har.alarm_type_id = #{alarmTypeId} + and har.rule_type = #{ruleType} + and har.rule_device_id = #{ruleDeviceId} + and har.rule_function_total = #{ruleFunctionTotal} + and har.trigger_expression = #{triggerExpression} + and har.link_flag = #{linkFlag} + and har.alarm_rule_status = #{alarmRuleStatus} + and har.alarm_push_flag = #{alarmPushFlag} + and har.alarm_push_content = #{alarmPushContent} + and har.alarm_recover_content = #{alarmRecoverContent} + and har.alarm_rule_field = #{alarmRuleField} + + + ${params.tenantDataScope} + + order by har.alarm_rule_id desc - + 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, hd.device_name as sub_link_device_name,hdmf.function_name as sub_link_device_mode_function_name + from hw_alarm_rule a + left join hw_alarm_rule_link b on b.alarm_rule_id = a.alarm_rule_id + left join hw_device hd on b.link_device_id = hd.device_id + left join hw_device_mode_function hdmf on b.link_device_function_id=hdmf.mode_function_id + where a.alarm_rule_id = #{alarmRuleId} @@ -84,23 +106,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" alarm_rule_name, tenant_id, scene_id, + language_code, alarm_level_id, alarm_type_id, rule_type, - device_id, - device_mode_id, - mode_function_id, - trigger_condition, - trigger_data_a, - trigger_data_b, - trigger_deadzone, - trigger_number, - trigger_time_frame, + rule_device_id, + rule_function_total, + trigger_expression, link_flag, - link_type, - link_device_id, - link_device_function_id, - link_device_function_data, alarm_rule_status, alarm_push_flag, alarm_push_content, @@ -116,23 +129,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{alarmRuleName}, #{tenantId}, #{sceneId}, + #{languageCode}, #{alarmLevelId}, #{alarmTypeId}, #{ruleType}, - #{deviceId}, - #{deviceModeId}, - #{modeFunctionId}, - #{triggerCondition}, - #{triggerDataA}, - #{triggerDataB}, - #{triggerDeadzone}, - #{triggerNumber}, - #{triggerTimeFrame}, + #{ruleDeviceId}, + #{ruleFunctionTotal}, + #{triggerExpression}, #{linkFlag}, - #{linkType}, - #{linkDeviceId}, - #{linkDeviceFunctionId}, - #{linkDeviceFunctionData}, #{alarmRuleStatus}, #{alarmPushFlag}, #{alarmPushContent}, @@ -152,23 +156,14 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" alarm_rule_name = #{alarmRuleName}, tenant_id = #{tenantId}, scene_id = #{sceneId}, + language_code = #{languageCode}, alarm_level_id = #{alarmLevelId}, alarm_type_id = #{alarmTypeId}, rule_type = #{ruleType}, - device_id = #{deviceId}, - device_mode_id = #{deviceModeId}, - mode_function_id = #{modeFunctionId}, - trigger_condition = #{triggerCondition}, - trigger_data_a = #{triggerDataA}, - trigger_data_b = #{triggerDataB}, - trigger_deadzone = #{triggerDeadzone}, - trigger_number = #{triggerNumber}, - trigger_time_frame = #{triggerTimeFrame}, + rule_device_id = #{ruleDeviceId}, + rule_function_total = #{ruleFunctionTotal}, + trigger_expression = #{triggerExpression}, link_flag = #{linkFlag}, - link_type = #{linkType}, - link_device_id = #{linkDeviceId}, - link_device_function_id = #{linkDeviceFunctionId}, - link_device_function_data = #{linkDeviceFunctionData}, alarm_rule_status = #{alarmRuleStatus}, alarm_push_flag = #{alarmPushFlag}, alarm_push_content = #{alarmPushContent}, @@ -188,9 +183,27 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - delete from hw_alarm_rule where alarm_rule_id in + update hw_alarm_rule set alarm_rule_status='9' where alarm_rule_id in #{alarmRuleId} + + + delete from hw_alarm_rule_link where alarm_rule_id in + + #{alarmRuleId} + + + + + delete from hw_alarm_rule_link where alarm_rule_id = #{alarmRuleId} + + + + insert into hw_alarm_rule_link( rule_link_id, alarm_rule_id, link_type, link_device_id, link_device_function_id, link_device_function_identifier, link_device_function_data) values + + ( #{item.ruleLinkId}, #{item.alarmRuleId}, #{item.linkType}, #{item.linkDeviceId}, #{item.linkDeviceFunctionId}, #{item.linkDeviceFunctionIdentifier}, #{item.linkDeviceFunctionData}) + + \ No newline at end of file