Browse Source

添加报警规则删除与查询接口

wubiyu 1 year ago
parent
commit
705adb5363

+ 26 - 5
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/controller/IotAlarmRuleController.java

@@ -1,6 +1,7 @@
 package com.xunmei.iot.controller;
 
 import com.xunmei.common.core.web.domain.AjaxResult;
+import com.xunmei.common.core.web.page.TableDataInfo;
 import com.xunmei.iot.dto.alarm.IotAlarmRuleDto;
 import com.xunmei.iot.service.IotAlarmRuleService;
 import com.xunmei.iot.vo.alarm.IotInitAlarmRuleVo;
@@ -42,14 +43,22 @@ public class IotAlarmRuleController {
     }
 
     @ApiOperation(value = "查询报警规则")
-    @GetMapping(value = "/getRules")
-    public AjaxResult getRules(String alarmType, String ruleName, Integer pageIndex, Integer pageSize){
+    @GetMapping(value = "/getRules/{alarmType}/{pageIndex}/{pageSize}/{ruleName}")
+    public TableDataInfo<IotInitAlarmRuleVo> getRules(@PathVariable String alarmType,
+                                                      @PathVariable String ruleName,
+                                                      @PathVariable Integer pageIndex,
+                                                      @PathVariable Integer pageSize){
         try {
-            List<IotInitAlarmRuleVo> alarmRuleData = iotAlarmRuleService.getAlarmRuleDatas(alarmType,ruleName,pageIndex,pageSize);
-            return AjaxResult.success(alarmRuleData);
+            ruleName = ruleName.trim();
+            if(ruleName.equals("undefined")) ruleName = "";
+            TableDataInfo<IotInitAlarmRuleVo> alarmRuleData = iotAlarmRuleService.getAlarmRuleDatas(alarmType,ruleName,pageIndex,pageSize);
+            return alarmRuleData;
         } catch (Exception e) {
             e.printStackTrace();
-            return AjaxResult.error(e.getMessage());
+            TableDataInfo<IotInitAlarmRuleVo> rh = new TableDataInfo<>();
+            rh.setCode(500);
+            rh.setMsg("获取失败");
+            return rh;
         }
     }
 
@@ -66,5 +75,17 @@ public class IotAlarmRuleController {
         }
     }
 
+    @ApiOperation(value = "修改界面")
+    @GetMapping(value = "/deleteRule/{ruleId}")
+    public AjaxResult deleteRuleById(@PathVariable Long ruleId){
+        try {
+            iotAlarmRuleService.deleteAlarmRule(ruleId);
+            return AjaxResult.success();
+        } catch (Exception e) {
+            e.printStackTrace();
+            return AjaxResult.error(e.getMessage());
+        }
+    }
+
 
 }

+ 4 - 1
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/service/IotAlarmRuleService.java

@@ -2,6 +2,7 @@ package com.xunmei.iot.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
 import com.xunmei.common.core.domain.mediator.domain.IotAlarmRule;
+import com.xunmei.common.core.web.page.TableDataInfo;
 import com.xunmei.iot.dto.alarm.IotAlarmRuleDto;
 import com.xunmei.iot.vo.alarm.IotInitAlarmRuleVo;
 
@@ -34,7 +35,7 @@ public interface IotAlarmRuleService extends IService<IotAlarmRule> {
      * @param pageSize
      * @return {@link IotInitAlarmRuleVo}
      */
-    List<IotInitAlarmRuleVo> getAlarmRuleDatas(String alarmType, String ruleName, Integer pageIndex, Integer pageSize) throws Exception;
+    TableDataInfo<IotInitAlarmRuleVo> getAlarmRuleDatas(String alarmType, String ruleName, Integer pageIndex, Integer pageSize) throws Exception;
 
     /**
      *
@@ -42,4 +43,6 @@ public interface IotAlarmRuleService extends IService<IotAlarmRule> {
      * @throws Exception
      */
     void saveOrUpdateAlarmRule(IotAlarmRuleDto ruleDto)throws Exception;
+
+    void deleteAlarmRule(Long ruleId);
 }

+ 33 - 4
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/service/impl/IotAlarmRuleServiceImpl.java

@@ -3,6 +3,8 @@ package com.xunmei.iot.service.impl;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.xunmei.common.core.domain.mediator.domain.IotAlarmRule;
 import com.xunmei.common.core.domain.mediator.domain.IotAlarmRuleExpress;
@@ -10,6 +12,7 @@ import com.xunmei.common.core.domain.mediator.domain.IotAlarmSystemField;
 import com.xunmei.common.core.util.BeanHelper;
 import com.xunmei.common.core.utils.IDHelper;
 import com.xunmei.common.core.utils.KeyValue;
+import com.xunmei.common.core.web.page.TableDataInfo;
 import com.xunmei.common.security.utils.SecurityUtils;
 import com.xunmei.iot.dto.alarm.IotAlarmRuleDto;
 import com.xunmei.iot.dto.alarm.IotAlarmRuleExpressDto;
@@ -131,19 +134,33 @@ public class IotAlarmRuleServiceImpl extends ServiceImpl<IotAlarmRuleMapper, Iot
     }
 
     @Override
-    public List<IotInitAlarmRuleVo> getAlarmRuleDatas(String alarmType, String ruleName, Integer pageIndex, Integer pageSize) throws Exception {
+    public TableDataInfo<IotInitAlarmRuleVo> getAlarmRuleDatas(String alarmType, String ruleName, Integer pageIndex, Integer pageSize) throws Exception {
         LambdaQueryWrapper<IotAlarmRule> queryWrapper = new LambdaQueryWrapper<>();
-        List<IotAlarmRule> appAlarmRule = this.baseMapper.selectList(queryWrapper);
+        if(alarmType!=null && !alarmType.isEmpty())
+        {
+            queryWrapper.eq(IotAlarmRule::getType,alarmType);
+        }
+        if(ruleName !=null && !ruleName.isEmpty())
+        {
+            queryWrapper.like(IotAlarmRule::getName,ruleName);
+        }
+        Page<IotAlarmRule> page = new Page<>(pageIndex,pageSize);
+
+        IPage<IotAlarmRule> appAlarmRule= this.baseMapper.selectPage(page,queryWrapper);
 
         List<IotInitAlarmRuleVo> datas = new ArrayList<>();
-        appAlarmRule.stream().forEach(i -> {
+        appAlarmRule.getRecords().stream().forEach(i -> {
             try {
                 datas.add(getAlarmRuleData(i.getId()));
             } catch (Exception e) {
                 throw new RuntimeException(e);
             }
         });
-        return datas;
+
+        TableDataInfo<IotInitAlarmRuleVo> pageDatas= TableDataInfo.build(datas);
+        pageDatas.setCode(200);
+        pageDatas.setTotal(appAlarmRule.getTotal());
+        return pageDatas;
     }
 
     @Override
@@ -181,4 +198,16 @@ public class IotAlarmRuleServiceImpl extends ServiceImpl<IotAlarmRuleMapper, Iot
         iotAlarmRuleExpressService.remove(new LambdaQueryWrapper<IotAlarmRuleExpress>().eq(IotAlarmRuleExpress::getRuleId, rule.getId()));
         iotAlarmRuleExpressService.saveBatch(appAlarmRuleExpressesList);
     }
+
+
+    @Override
+    public void deleteAlarmRule(Long ruleId)
+    {
+        LambdaQueryWrapper<IotAlarmRule> queryWrapper = new LambdaQueryWrapper<>();
+        queryWrapper.eq(IotAlarmRule::getId,ruleId);
+        this.baseMapper.delete(queryWrapper);
+        LambdaQueryWrapper<IotAlarmRuleExpress> ruleExpressWrapper = new LambdaQueryWrapper<>();
+        ruleExpressWrapper.eq(IotAlarmRuleExpress::getRuleId,ruleId);
+        iotAlarmRuleExpressService.remove(ruleExpressWrapper);
+    }
 }