123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- <?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.bizmatics.mhfire.persistence.mapper.DeviceMapper">
- <!-- 通用查询映射结果 -->
- <resultMap id="BaseResultMap" type="com.bizmatics.mhfire.model.Device">
- <id column="id" property="id" />
- <result column="name" property="name" />
- <result column="code" property="code" />
- <result column="device_type" property="deviceType" />
- <result column="create_time" property="createTime" />
- <result column="longitude" property="longitude" />
- <result column="latitude" property="latitude" />
- <result column="device_flag" property="deviceFlag" />
- <result column="del_flag" property="delFlag" />
- <result column="firm" property="firm" />
- <result column="describe" property="describe" />
- <result column="address" property="address" />
- <result column="device_duty" property="deviceDuty" />
- <result column="property" property="property" />
- </resultMap>
- <select id="selectCollect" resultType="com.bizmatics.mhfire.persistence.mapper.vo.DeviceCollectVO">
- select d.device_type as deviceType,count(d.id) as deviceCount,count(da.id) as alertCount,
- count(if(d.device_flag = 1, 1, null)) as lineCount,
- (
- select
- ROUND(COUNT(CASE WHEN dd.device_flag=1 THEN dd.device_flag END)/COUNT(*),2) AS rate_a
- FROM device as dd
- where dd.device_type = d.device_type
- ) as lineRate,
- (
- select
- ROUND(COUNT(CASE WHEN dan.id != null THEN dan.id END)/COUNT(*),2) AS rate_a
- FROM device as dd
- left join device_alert as dan
- on dd.`code` = dan.device_code
- where dd.device_type = d.device_type
- ) as alertRate,
- (
- select
- ROUND(COUNT(CASE WHEN dan.aj_flag=3 THEN dan.aj_flag END)/COUNT(*),2)
- FROM device_aj as dan
- where dan.device_type = d.device_type
- ) as checkRate
- from device as d
- left join device_alert as da
- on d.code = da.device_code
- left join device_aj as aj
- on d.code = aj.device_code
- <where>
- <if test="deviceType != null and deviceType != ''">
- and d.device_type = #{deviceType}
- </if>
- <if test="deviceCode != null and deviceCode != ''">
- and d.code = #{deviceCode}
- </if>
- <if test="startTime != null and endTime != null ">
- and d.create_time between #{startTime} and #{endTime}
- </if>
- </where>
- GROUP BY d.device_type
- </select>
- <select id="selectCollectOne" resultType="com.bizmatics.mhfire.persistence.mapper.vo.DeviceCollectVO">
- select d.device_type as deviceType,count(d.id) as deviceCount,count(da.id) as alertCount,
- count(if(d.device_flag = 1, 1, null)) as lineCount,
- (
- select
- ROUND(COUNT(CASE WHEN dd.device_flag=1 THEN dd.device_flag END)/COUNT(*),2) AS rate_a
- FROM device as dd
- where dd.device_type = d.device_type
- ) as lineRate,
- (
- select
- ROUND(COUNT(CASE WHEN dan.id != null THEN dan.id END)/COUNT(*),2) AS rate_a
- FROM device as dd
- left join device_alert as dan
- on dd.`code` = dan.device_code
- where dd.device_type = d.device_type
- ) as alertRate,
- (
- select
- ROUND(COUNT(CASE WHEN dan.aj_flag=3 THEN dan.aj_flag END)/COUNT(*),2)
- FROM device_aj as dan
- where dan.device_type = d.device_type
- ) as checkRate
- from device as d
- left join device_alert as da
- on d.code = da.device_code
- left join device_aj as aj
- on d.code = aj.device_code
- <where>
- <if test="deviceType != null and deviceType != ''">
- and d.device_type = #{deviceType}
- </if>
- <if test="deviceCode != null and deviceCode != ''">
- and d.code = #{deviceCode}
- </if>
- <if test="startTime != null and endTime != null ">
- and d.create_time between #{startTime} and #{endTime}
- </if>
- </where>
- </select>
- </mapper>
|