Newer
Older
newfiber-termite / newfiber-termites / newfiber-termites-dataup / src / main / resources / mapper / termite / DeviceInfoMapper.xml
@xiongkai xiongkai 27 days ago 5 KB 统计优化
<?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.newfiber.termite.mapper.DeviceInfoMapper">

    <!-- 通用查询映射结果 -->
    <resultMap type="com.newfiber.termite.domain.DeviceInfo" id="DeviceInfoResult">
        <result property="id" column="id"/>
        <result property="category" column="category"/>
        <result property="projectCode" column="project_code"/>
        <result property="sn" column="sn"/>
        <result property="deviceType" column="device_type"/>
        <result property="locationType" column="location_type"/>
        <result property="location" column="location"/>
        <result property="initialpictu" column="initialpictu"/>
        <result property="extendConfig" column="extend_config"/>
        <result property="lonandlat" column="lonandlat"/>
        <result property="delFlag" column="del_flag"/>
        <result property="lastPicTime" column="last_pic_time"/>
        <result property="lastHeatTime" column="last_heat_time"/>
        <result property="lastMedicateTime" column="last_medicate_time"/>
        <result property="firstWarnDatetime" column="first_warn_datetime"/>
        <result property="druging" column="druging"/>
        <result property="software" column="software"/>
        <result property="hardware" column="hardware"/>
        <result property="voltage" column="voltage"/>
        <result property="temperature" column="temperature"/>
        <result property="rssi" column="rssi"/>
        <result property="ap" column="ap"/>
        <result property="camera" column="camera"/>


        <result property="yesnoant" column="yesnoant" />
        <result property="uploadApi" column="upload_api"/>
        <result property="projectName" column="project_name"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        t.id
    	, t.category
    	, t.project_code
    	, t.sn
        , t.device_type
        , t.location_type
    	, t.location
    	, t.initialpictu
        , t.extend_config
    	, t.lonandlat
    	, t.del_flag
    	, t.last_pic_time
        , t.last_heat_time
        , t.last_medicate_time
    	, t.first_warn_datetime
        , t.druging
        , t.software
        , t.hardware
        , t.voltage
        , t.temperature
        , t.rssi
        , t.ap
        , t.camera

        , tpi.upload_api
        , tpi.project_name
	</sql>

    <sql id="Where_Condition">
        <if test="request.category != null and request.category != ''">
            and t.category = #{request.category}
        </if>
        <if test="request.projectCode != null and request.projectCode != ''">
            and t.project_code = #{request.projectCode}
        </if>
        <if test="request.sn != null and request.sn != ''">
            and t.sn = #{request.sn}
        </if>
        <if test="request.warnFlag != null and request.warnFlag != ''">
            and t.first_warn_datetime is not null
        </if>

        <if test="request.userId != null and request.userId != ''">
            and pu.user_id = #{request.userId}
        </if>
        <if test="request.projectCodeList != null and !request.projectCodeList.isEmpty()">
            and tpi.project_code in
            <foreach item="projectCode" collection="request.projectCodeList" open="(" separator="," close=")">
                #{projectCode}
            </foreach>
        </if>
    </sql>

    <sql id="Join_Table">
        left join ter_project_info tpi on t.project_code = tpi.project_code
        left join ter_project_user pu on tpi.project_code = pu.project_code
    </sql>

    <select id="selectSnByCondition" resultType="com.newfiber.termite.domain.SnDeviceInfo">
        select
        <include refid="Base_Column_List"/>,
        md.yesnoant AS yesnoant,
        md.date AS snDate
        from ter_device_info t
        JOIN ter_device_monitoring_data md ON t.sn = md.sn
        <include refid="Join_Table"/>
        where t.del_flag = 0
        <include refid="Where_Condition"/>
        order by t.${request.orderBy}
    </select>

<!--    <select id="snQuerMonitoryList" resultType="com.newfiber.termite.domain.SnDeviceInfo">-->
<!--        select-->
<!--        <include refid="Base_Column_List"/>,-->
<!--        md.yesnoant AS yesnoant,-->
<!--        md.date AS snDate-->
<!--        from ter_device_info t-->
<!--        JOIN ter_device_monitoring_data md ON t.sn = md.sn-->
<!--        <include refid="Join_Table"/>-->
<!--        where t.del_flag = 0 AND md.sn=#{request.sn}-->
<!--        <include refid="Where_Condition"/>-->
<!--        order by t.${request.orderBy}-->
<!--    </select>-->



    <select id="selectByCondition" resultMap="DeviceInfoResult">
        select
        <include refid="Base_Column_List"/>
        from ter_device_info t
        <include refid="Join_Table"/>
        where t.del_flag = 0
        <include refid="Where_Condition"/>
        order by t.${request.orderBy}
    </select>

    <select id="selectOneById" resultMap="DeviceInfoResult">
        select
        <include refid="Base_Column_List"/>
        from ter_device_info t
        <include refid="Join_Table"/>
        where t.id = #{id} and t.del_flag = 0
    </select>

    <resultMap type="com.newfiber.termite.domain.response.statistic.ProjectStatisticDetail" id="statisticResult">
        <result property="projectCode" column="project_code"/>
        <result property="projectName" column="project_name"/>
        <result property="firstWarnDatetime" column="first_warn_datetime"/>
        <result property="deviceCount" column="deviceCount"/>
    </resultMap>
    <select id="statistic" resultMap="statisticResult">
        select tpi.project_name, t.project_code, count(1) as deviceCount, max(first_warn_datetime) as first_warn_datetime
        from ter_device_info t
        <include refid="Join_Table"/>
        where t.del_flag = 0
        <include refid="Where_Condition"/>
        and (t.project_code != '' or t.project_code != null)
        group by t.project_code, tpi.project_name
    </select>


</mapper>