123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- <?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.persistence.mapper.DeviceMapper">
- <!-- 通用查询映射结果 -->
- <resultMap id="BaseResultMap" type="com.bizmatics.model.Device">
- <id column="id" property="id" />
- <result column="device_code" property="deviceCode" />
- <result column="device_name" property="deviceName" />
- <result column="site_id" property="siteId" />
- <result column="device_address" property="deviceAddress" />
- <result column="device_type" property="deviceType" />
- <result column="install_time" property="installTime" />
- <result column="creator" property="creator" />
- <result column="enable" property="enable" />
- </resultMap>
- <select id="selectCount" resultType="java.lang.Integer">
- select count(1)
- from user_site as us
- inner join device_status as ds
- on us.site_id = ds.site_id
- inner join device as d
- on us.site_id = d.site_Id
- <where>
- <if test="userId != null and userId != 0">
- and us.user_id = #{userId}
- </if>
- <if test="siteId != null and siteId != 0">
- and us.site_id = #{siteId}
- </if>
- <if test="deviceStatus != null">
- and ds.device_status = #{deviceStatus}
- </if>
- <if test="startTime != null">
- and ds.status_time >= #{startTime}
- </if>
- <if test="endTime != null">
- and ds.status_time <= #{endTime}
- </if>
- <if test="type != null">
- and d.device_type = #{type}
- </if>
- </where>
- </select>
- <select id="list" resultType="com.bizmatics.model.Device">
- select d.id,d.device_code,d.device_name,d.site_id,d.device_address,d.device_type,d.install_time,ds.device_status as deviceStatus,
- s.installed_capacity as installedCapacity
- from user_site as us
- inner join device_status as ds
- on us.site_id = ds.site_id
- inner join device as d
- on us.site_id = d.site_Id
- inner join site as s
- on s.id = us.site_id
- <where>
- <if test="userId != null and userId != 0">
- and us.user_id = #{userId}
- </if>
- <if test="siteId != null and siteId != 0">
- and us.site_id = #{siteId}
- </if>
- <if test="deviceStatus != null">
- and ds.device_status = #{deviceStatus}
- </if>
- <if test="startTime != null">
- and ds.status_time >= #{startTime}
- </if>
- <if test="endTime != null">
- and ds.status_time <= #{endTime}
- </if>
- <if test="type != null">
- and d.device_type = #{type}
- </if>
- </where>
- </select>
- <select id="DeviceList" resultType="com.bizmatics.model.DeviceList">
- SELECT
- a.*, b.device_status,
- c.loop_meter_address,
- c.rated_voltage,
- c.rated_current,
- c.current_load_rate,
- c.monitoring_equipment_no,
- c.variable_list_id,
- c.quality_analysis
- FROM
- device AS a
- JOIN device_status AS b ON a.device_code = b.device_code
- LEFT JOIN device_attribute AS c ON a.id = c.device_id
- <where>
- a.enable =1
- <if test="siteId != null and siteId != 0">
- and a.site_id = #{siteId}
- </if>
- </where>
- </select>
- <select id="CorrespondDeviceList" resultType="com.bizmatics.model.vo.CorrespondDeviceVO">
- SELECT
- a.id,
- a.device_code,
- a.device_name,
- a.device_address,
- a.install_time,
- b.device_status,
- b.status_time,
- a.site_id,
- c.site_name,
- if (b.device_status=1,timestampdiff(
- HOUR,
- b.status_time,
- now()
- ),null) as offlineDuration,
- if(b.device_status!=1,timestampdiff(
- HOUR,
- a.install_time,
- now()
- ),null) as onlineDuration
- FROM
- device AS a
- JOIN device_status AS b ON a.device_code = b.device_code
- JOIN site AS c ON a.site_id = c.id
- <where>
- a.enable =1
- <if test="deviceName != null and deviceName != ''">
- and a.device_name LIKE CONCAT(CONCAT('%', #{deviceName}), '%')
- </if>
- </where>
- order by a.id desc
- <if test="current != null and current != 0 and startCurrent != null">
- LIMIT #{startCurrent},#{current}
- </if>
- </select>
- </mapper>
|