ソースを参照

告警模块提交

hym 3 年 前
コミット
bd2d24263c

+ 6 - 0
zoniot-rmcp/zoniot-rmcp-api/src/main/java/com/zcxk/rmcp/api/dto/alarm/AlarmRulePageDto.java

@@ -0,0 +1,6 @@
+package com.zcxk.rmcp.api.dto.alarm;
+
+import com.zcxk.rmcp.api.dto.BasePageDto;
+
+public class AlarmRulePageDto extends BasePageDto {
+}

+ 4 - 0
zoniot-rmcp/zoniot-rmcp-api/src/main/java/com/zcxk/rmcp/api/dto/alarm/AlarmTypeDto.java

@@ -1,4 +1,8 @@
 package com.zcxk.rmcp.api.dto.alarm;
 
+import lombok.Data;
+
+@Data
 public class AlarmTypeDto {
+    private Integer id;
 }

+ 4 - 1
zoniot-rmcp/zoniot-rmcp-core/src/main/java/com/zcxk/rmcp/core/dao/AlarmTypeMapper.java

@@ -1,5 +1,6 @@
 package com.zcxk.rmcp.core.dao;
 
+import com.zcxk.core.common.pojo.UserCondition;
 import com.zcxk.rmcp.api.dto.alarm.AlarmTypeDto;
 import com.zcxk.rmcp.api.dto.alarm.AlarmTypePageDto;
 import com.zcxk.rmcp.core.entity.AlarmType;
@@ -41,7 +42,7 @@ public interface AlarmTypeMapper {
      * @param alarmType 实例对象
      * @return 对象列表
      */
-    List<AlarmTypeDto> selectList(AlarmTypePageDto alarmType);
+    List<AlarmTypeDto> selectList(AlarmTypePageDto alarmType, UserCondition userCondition);
 
     /**
      * 新增数据
@@ -85,4 +86,6 @@ public interface AlarmTypeMapper {
 
 
     List<AlarmType> selectTypesWithRules(List<Integer> ids);
+
+    void delete(List<Integer> ids);
 }

+ 7 - 1
zoniot-rmcp/zoniot-rmcp-core/src/main/java/com/zcxk/rmcp/core/dao/DeviceAlarmRuleMapper.java

@@ -1,5 +1,8 @@
 package com.zcxk.rmcp.core.dao;
 
+import com.zcxk.core.common.pojo.UserCondition;
+import com.zcxk.rmcp.api.dto.alarm.AlarmRuleDto;
+import com.zcxk.rmcp.api.dto.alarm.AlarmRulePageDto;
 import com.zcxk.rmcp.core.entity.DeviceAlarmRule;
 import org.apache.ibatis.annotations.Param;
 
@@ -41,7 +44,7 @@ public interface DeviceAlarmRuleMapper {
      * @param deviceAlarmRule 实例对象
      * @return 对象列表
      */
-    List<DeviceAlarmRule> selectList(DeviceAlarmRule deviceAlarmRule);
+    List<AlarmRuleDto> selectList(AlarmRulePageDto deviceAlarmRule, UserCondition userCondition);
 
     /**
      * 新增数据
@@ -83,4 +86,7 @@ public interface DeviceAlarmRuleMapper {
     int count();
 
 
+    void delete(List<Integer> ids);
+
+    void deleteAll(UserCondition userCondition);
 }

+ 7 - 2
zoniot-rmcp/zoniot-rmcp-core/src/main/java/com/zcxk/rmcp/core/entity/AlarmType.java

@@ -11,12 +11,12 @@ import io.swagger.annotations.ApiModelProperty;
  * 设备告警类型(AlarmType)实体类
  *
  * @author hym
- * @since 2021-07-30 10:57:47
+ * @since 2021-07-30 11:28:50
  */
 @Data
 @ApiModel
 public class AlarmType implements Serializable {
-    private static final long serialVersionUID = 358911974200006071L;
+    private static final long serialVersionUID = -27168393864976552L;
     /**
      * id
      */
@@ -72,4 +72,9 @@ public class AlarmType implements Serializable {
      */
     @ApiModelProperty(value = "租户id")
     private String tenantId;
+    /**
+     * 1启用 0禁用
+     */
+    @ApiModelProperty(value = "1启用 0禁用")
+    private Integer alarmStatus;
 }

+ 202 - 0
zoniot-rmcp/zoniot-rmcp-core/src/main/resources/mapper/AlarmTypeMapper.xml

@@ -0,0 +1,202 @@
+<?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.zcxk.rmcp.core.dao.AlarmTypeMapper">
+    <!-- 结果集 -->
+    <resultMap type="com.zcxk.rmcp.core.entity.AlarmType" id="AlarmTypeMap">
+        <result property="id" column="id" jdbcType="INTEGER"/>
+        <result property="productCategroyId" column="product_categroy_id" jdbcType="INTEGER"/>
+        <result property="deviceTypeId" column="device_type_id" jdbcType="INTEGER"/>
+        <result property="name" column="name" jdbcType="VARCHAR"/>
+        <result property="status" column="status" jdbcType="INTEGER"/>
+        <result property="createDate" column="create_date" jdbcType="TIMESTAMP"/>
+        <result property="createBy" column="create_by" jdbcType="VARCHAR"/>
+        <result property="updateDate" column="update_date" jdbcType="TIMESTAMP"/>
+        <result property="updateBy" column="update_by" jdbcType="VARCHAR"/>
+        <result property="typeDesc" column="type_desc" jdbcType="VARCHAR"/>
+        <result property="tenantId" column="tenant_id" jdbcType="VARCHAR"/>
+        <result property="alarmStatus" column="alarm_status" jdbcType="INTEGER"/>
+    </resultMap>
+
+    <!-- 基本字段 -->
+    <sql id="Base_Column_List">
+        id, product_categroy_id, device_type_id, name, status, create_date, create_by, update_date, update_by, type_desc, tenant_id, alarm_status    </sql>
+
+    <!-- 查询单个 -->
+    <select id="selectById" resultMap="AlarmTypeMap">
+        select
+        <include refid="Base_Column_List"/>
+        from rmcp_alarm_type
+        where id = #{id}
+    </select>
+
+
+    <!-- 查询全部 -->
+    <select id="selectAll" resultMap="AlarmTypeMap">
+        select
+        <include refid="Base_Column_List"/>
+        from rmcp_alarm_type
+    </select>
+
+    <!--通过实体作为筛选条件查询-->
+    <select id="selectList" resultMap="AlarmTypeMap">
+        select
+        <include refid="Base_Column_List"/>
+        from rmcp_alarm_type
+        <where>
+            <if test="id != null">
+                and id = #{id}
+            </if>
+            <if test="productCategroyId != null">
+                and product_categroy_id = #{productCategroyId}
+            </if>
+            <if test="deviceTypeId != null">
+                and device_type_id = #{deviceTypeId}
+            </if>
+            <if test="name != null and name != ''">
+                and name = #{name}
+            </if>
+            <if test="status != null">
+                and status = #{status}
+            </if>
+            <if test="createDate != null">
+                and create_date = #{createDate}
+            </if>
+            <if test="createBy != null and createBy != ''">
+                and create_by = #{createBy}
+            </if>
+            <if test="updateDate != null">
+                and update_date = #{updateDate}
+            </if>
+            <if test="updateBy != null and updateBy != ''">
+                and update_by = #{updateBy}
+            </if>
+            <if test="typeDesc != null and typeDesc != ''">
+                and type_desc = #{typeDesc}
+            </if>
+            <if test="tenantId != null and tenantId != ''">
+                and tenant_id = #{tenantId}
+            </if>
+            <if test="alarmStatus != null">
+                and alarm_status = #{alarmStatus}
+            </if>
+        </where>
+    </select>
+
+    <!-- 新增所有列 -->
+    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
+        insert into rmcp_alarm_type(id, product_categroy_id, device_type_id, name, status, create_date, create_by,
+                                    update_date, update_by, type_desc, tenant_id, alarm_status)
+        values (#{id}, #{productCategroyId}, #{deviceTypeId}, #{name}, #{status}, #{createDate}, #{createBy},
+                #{updateDate}, #{updateBy}, #{typeDesc}, #{tenantId}, #{alarmStatus})
+    </insert>
+
+    <!-- 批量新增 -->
+    <insert id="batchInsert">
+        insert into rmcp_alarm_type(id, product_categroy_id, device_type_id, name, status, create_date, create_by,
+        update_date, update_by, type_desc, tenant_id, alarm_status)
+        values
+        <foreach collection="alarmTypes" item="item" index="index" separator=",">
+            (
+            #{item.id}, #{item.productCategroyId}, #{item.deviceTypeId}, #{item.name}, #{item.status},
+            #{item.createDate}, #{item.createBy}, #{item.updateDate}, #{item.updateBy}, #{item.typeDesc},
+            #{item.tenantId}, #{item.alarmStatus} )
+        </foreach>
+    </insert>
+
+    <!-- 通过主键修改数据 -->
+    <update id="update">
+        update rmcp_alarm_type
+        <set>
+            <if test="productCategroyId != null">
+                product_categroy_id = #{productCategroyId},
+            </if>
+            <if test="deviceTypeId != null">
+                device_type_id = #{deviceTypeId},
+            </if>
+            <if test="name != null and name != ''">
+                name = #{name},
+            </if>
+            <if test="status != null">
+                status = #{status},
+            </if>
+            <if test="createDate != null">
+                create_date = #{createDate},
+            </if>
+            <if test="createBy != null and createBy != ''">
+                create_by = #{createBy},
+            </if>
+            <if test="updateDate != null">
+                update_date = #{updateDate},
+            </if>
+            <if test="updateBy != null and updateBy != ''">
+                update_by = #{updateBy},
+            </if>
+            <if test="typeDesc != null and typeDesc != ''">
+                type_desc = #{typeDesc},
+            </if>
+            <if test="tenantId != null and tenantId != ''">
+                tenant_id = #{tenantId},
+            </if>
+            <if test="alarmStatus != null">
+                alarm_status = #{alarmStatus},
+            </if>
+        </set>
+        where id = #{id}
+    </update>
+
+    <!--通过主键删除-->
+    <delete id="deleteById">
+        delete
+        from rmcp_alarm_type
+        where id = #{id}
+    </delete>
+
+    <!-- 总数 -->
+    <select id="count" resultType="int">
+        select count(*)
+        from rmcp_alarm_type
+    </select>
+    <select id="selectPage" resultMap="AlarmTypeMap">
+        select
+        <include refid="Base_Column_List"/>
+        from rmcp_alarm_type
+        <where>
+            <if test="alarmType.id != null">
+                and id = #{alarmType.id}
+            </if>
+            <if test="alarmType.productCategroyId != null">
+                and product_categroy_id = #{alarmType.productCategroyId}
+            </if>
+            <if test="alarmType.deviceTypeId != null">
+                and device_type_id = #{alarmType.deviceTypeId}
+            </if>
+            <if test="alarmType.name != null and alarmType.name != ''">
+                and name = #{alarmType.name}
+            </if>
+            <if test="alarmType.status != null">
+                and status = #{alarmType.status}
+            </if>
+            <if test="alarmType.createDate != null">
+                and create_date = #{alarmType.createDate}
+            </if>
+            <if test="alarmType.createBy != null and alarmType.createBy != ''">
+                and create_by = #{alarmType.createBy}
+            </if>
+            <if test="alarmType.updateDate != null">
+                and update_date = #{alarmType.updateDate}
+            </if>
+            <if test="alarmType.updateBy != null and alarmType.updateBy != ''">
+                and update_by = #{alarmType.updateBy}
+            </if>
+            <if test="alarmType.typeDesc != null and alarmType.typeDesc != ''">
+                and type_desc = #{alarmType.typeDesc}
+            </if>
+            <if test="alarmType.tenantId != null and alarmType.tenantId != ''">
+                and tenant_id = #{alarmType.tenantId}
+            </if>
+            <if test="alarmType.alarmStatus != null">
+                and alarm_status = #{alarmType.alarmStatus}
+            </if>
+        </where>
+    </select>
+</mapper>

+ 7 - 5
zoniot-rmcp/zoniot-rmcp-web/src/main/java/com/zcxk/rmcp/web/controller/AlarmRuleController.java

@@ -2,7 +2,9 @@ package com.zcxk.rmcp.web.controller;
 
 
 import com.zcxk.core.common.pojo.AjaxMessage;
+import com.zcxk.core.mysql.pageing.Pagination;
 import com.zcxk.rmcp.api.dto.alarm.AlarmRuleDto;
+import com.zcxk.rmcp.api.dto.alarm.AlarmRulePageDto;
 import com.zcxk.rmcp.api.dto.alarm.ConfigDataDto;
 import com.zcxk.rmcp.api.dto.alarm.RuleMeasuringDto;
 import com.zcxk.rmcp.web.service.AlarmRuleService;
@@ -24,12 +26,12 @@ public class AlarmRuleController {
     @Autowired
     private AlarmRuleService deviceAlarmRuleService;
 
-    @GetMapping("/getList")
+    @GetMapping("/getPage")
     @ApiOperation(value = "查询异常规则列表")
-    public AjaxMessage<List<AlarmRuleDto>> getList(
-            @ApiParam(value = "异常类型id", required = true) @RequestParam Integer alarmTypeId
-    ) {
-        List<AlarmRuleDto> list = deviceAlarmRuleService.getList(alarmTypeId);
+    public AjaxMessage<Pagination<AlarmRuleDto>> getList(
+            @ApiParam(value = "异常类型id", required = true) @RequestBody AlarmRulePageDto alarmRulePageDto
+            ) {
+        Pagination<AlarmRuleDto> list = deviceAlarmRuleService.getList(alarmRulePageDto);
         return AjaxMessage.success(list);
     }
 

+ 3 - 1
zoniot-rmcp/zoniot-rmcp-web/src/main/java/com/zcxk/rmcp/web/service/AlarmRuleService.java

@@ -1,13 +1,15 @@
 package com.zcxk.rmcp.web.service;
 
+import com.zcxk.core.mysql.pageing.Pagination;
 import com.zcxk.rmcp.api.dto.alarm.AlarmRuleDto;
+import com.zcxk.rmcp.api.dto.alarm.AlarmRulePageDto;
 import com.zcxk.rmcp.api.dto.alarm.ConfigDataDto;
 import com.zcxk.rmcp.api.dto.alarm.RuleMeasuringDto;
 
 import java.util.List;
 
 public interface AlarmRuleService {
-    List<AlarmRuleDto> getList(Integer alarmTypeId);
+    Pagination<AlarmRuleDto> getList(AlarmRulePageDto alarmTypeId);
 
     void add(AlarmRuleDto deviceAlarmRule);
 

+ 30 - 7
zoniot-rmcp/zoniot-rmcp-web/src/main/java/com/zcxk/rmcp/web/service/impl/AlarmRuleServiceImpl.java

@@ -1,37 +1,60 @@
 package com.zcxk.rmcp.web.service.impl;
 
+import com.github.pagehelper.page.PageMethod;
+import com.zcxk.core.common.util.BeanCopyUtils;
+import com.zcxk.core.mysql.pageing.Pagination;
+import com.zcxk.core.oauth2.util.UserUtil;
 import com.zcxk.rmcp.api.dto.alarm.AlarmRuleDto;
+import com.zcxk.rmcp.api.dto.alarm.AlarmRulePageDto;
 import com.zcxk.rmcp.api.dto.alarm.ConfigDataDto;
 import com.zcxk.rmcp.api.dto.alarm.RuleMeasuringDto;
+import com.zcxk.rmcp.api.dto.measurementSettlement.MeasurementSettlementDto;
+import com.zcxk.rmcp.core.dao.DeviceAlarmRuleMapper;
+import com.zcxk.rmcp.core.entity.DeviceAlarmRule;
 import com.zcxk.rmcp.web.service.AlarmRuleService;
 import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
 
+import javax.annotation.Resource;
 import java.util.List;
 @Service
 public class AlarmRuleServiceImpl implements AlarmRuleService {
+    @Resource
+    private DeviceAlarmRuleMapper deviceAlarmRuleMapper;
     @Override
-    public List<AlarmRuleDto> getList(Integer alarmTypeId) {
-        return null;
+    public Pagination<AlarmRuleDto> getList(AlarmRulePageDto alarmRulePageDto) {
+        PageMethod.startPage(alarmRulePageDto.getPageNum(),alarmRulePageDto.getPageSize());
+        List<AlarmRuleDto>alarmRuleDtos=deviceAlarmRuleMapper.selectList(alarmRulePageDto,
+                UserUtil.getCurrentUser().getUserCondition());
+        if (CollectionUtils.isEmpty(alarmRuleDtos)){
+            return new Pagination<>();
+        }
+        return new Pagination<>(alarmRuleDtos);
     }
 
     @Override
-    public void add(AlarmRuleDto deviceAlarmRule) {
-
+    public void add(AlarmRuleDto alarmRuleDto) {
+        DeviceAlarmRule deviceAlarmRule=new DeviceAlarmRule();
+        BeanCopyUtils.copyProperties(alarmRuleDto, deviceAlarmRule, DeviceAlarmRule.class);
+        deviceAlarmRuleMapper.insert(deviceAlarmRule);
     }
 
     @Override
-    public void edit(AlarmRuleDto deviceAlarmRule) {
-
+    public void edit(AlarmRuleDto alarmRuleDto) {
+        DeviceAlarmRule deviceAlarmRule=new DeviceAlarmRule();
+        BeanCopyUtils.copyProperties(alarmRuleDto, deviceAlarmRule, DeviceAlarmRule.class);
+        deviceAlarmRuleMapper.update(deviceAlarmRule);
     }
 
     @Override
     public void delete(List<Integer> ids) {
-
+        deviceAlarmRuleMapper.delete(ids);
     }
 
     @Override
     public void deleteAll() {
 
+        deviceAlarmRuleMapper.deleteAll( UserUtil.getCurrentUser().getUserCondition());
     }
 
     @Override

+ 35 - 4
zoniot-rmcp/zoniot-rmcp-web/src/main/java/com/zcxk/rmcp/web/service/impl/AlarmTypeServiceImpl.java

@@ -4,6 +4,7 @@ import com.github.pagehelper.PageHelper;
 import com.github.pagehelper.page.PageMethod;
 import com.zcxk.core.common.util.BeanCopyUtils;
 import com.zcxk.core.mysql.pageing.Pagination;
+import com.zcxk.core.oauth2.util.UserUtil;
 import com.zcxk.rmcp.api.dto.alarm.AlarmTypeDto;
 import com.zcxk.rmcp.api.dto.alarm.AlarmTypePageDto;
 import com.zcxk.rmcp.core.dao.AlarmTypeMapper;
@@ -14,6 +15,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
 import javax.annotation.Resource;
+import java.util.ArrayList;
 import java.util.List;
 @Service
 public class AlarmTypeServiceImpl implements AlarmTypeService {
@@ -22,7 +24,8 @@ public class AlarmTypeServiceImpl implements AlarmTypeService {
     @Override
     public Pagination<AlarmTypeDto> getAlarmTypePage(AlarmTypePageDto alarmTypePageDto) {
         PageMethod.startPage(alarmTypePageDto.getPageNum(),alarmTypePageDto.getPageSize());
-        List<AlarmTypeDto> alarmTypes = alarmTypeMapper.selectList(alarmTypePageDto);
+        List<AlarmTypeDto> alarmTypes = alarmTypeMapper.selectList(alarmTypePageDto
+                , UserUtil.getCurrentUser().getUserCondition());
         if (CollectionUtils.isEmpty(alarmTypes)){
             return new Pagination<>();
         }
@@ -32,6 +35,8 @@ public class AlarmTypeServiceImpl implements AlarmTypeService {
     @Override
     public void add(AlarmTypeDto alarmTypeDto) {
         AlarmType alarmType=new AlarmType();
+        alarmType.setStatus(1);
+        alarmType.setAlarmStatus(1);
         BeanCopyUtils.copyProperties(alarmTypeDto, alarmType, AlarmType.class);
         alarmTypeMapper.insert(alarmType);
     }
@@ -45,17 +50,43 @@ public class AlarmTypeServiceImpl implements AlarmTypeService {
 
     @Override
     public int delete(List<Integer> ids) {
-        //alarmTypeMapper.selectTypesWithRules(ids);
-        return 0;
+        List<AlarmType>alarmTypes=alarmTypeMapper.selectTypesWithRules(ids);
+        if(CollectionUtils.isEmpty(alarmTypes)){
+            alarmTypeMapper.delete(ids);
+            return 0;
+        }
+        return 1;
     }
 
     @Override
     public int deleteAll() {
-        return 0;
+        List<AlarmTypeDto>alarmTypeDtos=alarmTypeMapper.selectList(new AlarmTypePageDto(),
+                UserUtil.getCurrentUser().getUserCondition());
+        List<Integer>ids=new ArrayList<>();
+        alarmTypeDtos.forEach(alarmTypeDto -> {
+            ids.add(alarmTypeDto.getId());
+        });
+        List<AlarmType>alarmTypes=alarmTypeMapper.selectTypesWithRules(ids);
+        if(CollectionUtils.isEmpty(alarmTypes)){
+            alarmTypeMapper.delete(ids);
+            return 0;
+        }
+        return 1;
     }
 
     @Override
     public void updateStatus(Integer id) {
+        AlarmType alarmType = alarmTypeMapper.selectById(id);
+        if (alarmType != null) {
+            alarmType.setId(id);
+            if (alarmType.getStatus() == 1) {
+                alarmType.setStatus(2);//禁用
+            } else {
+                alarmType.setStatus(1);//正常
+            }
+           alarmTypeMapper.update(alarmType);
+
+        }
 
     }
 }