Newer
Older
newfiber-termite / newfiber-termites / newfiber-termites-dataup / src / main / resources / mapper / termite / DeviceMonitoringDataMapper.xml
@xiongkai xiongkai 19 days ago 4 KB bug修复
<?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.DeviceMonitoringDataMapper">

    <!-- 通用查询映射结果 -->
    <resultMap type="com.newfiber.termite.domain.DeviceMonitoringData" id="DeviceMonitoringDataResult">
        <result property="id" column="id"/>
        <result property="sn" column="sn"/>
        <result property="date" column="date"/>
        <result property="yesnoant" column="yesnoant"/>
        <result property="rtpitcu" column="rtpitcu"/>
        <result property="idenpitcu" column="idenpitcu"/>
        <result property="idencolle" column="idencolle"/>
        <result property="antNumber" column="ant_number"/>
        <result property="otherAntNumber" column="other_ant_number"/>
        <result property="druing" column="druing"/>
        <result property="uptime" column="uptime"/>

        <result property="projectCode" column="project_code"/>
        <result property="location" column="location"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        t.id
    	, t.sn
    	, t.date
    	, t.yesnoant
    	, t.rtpitcu
    	, t.idenpitcu
    	, t.idencolle
        , t.ant_number
        , t.other_ant_number
    	, t.druing
    	, t.uptime

        , di.project_code
        , di.location
        , di.location_type
        , di.lonandlat
	</sql>

    <sql id="Where_Condition">
        <if test="request.sn != null and request.sn != ''">
            and t.sn = #{request.sn}
        </if>
        <if test="request.date != null and request.date != ''">
            and t.date = #{request.date}
        </if>
        <if test="request.yesnoant != null and request.yesnoant != ''">
            and t.yesnoant = #{request.yesnoant}
        </if>
        <if test="request.idencolle != null and request.idencolle != ''">
            and t.idencolle = #{request.idencolle}
        </if>
        <if test="request.druing != null and request.druing != ''">
            and t.druing = #{request.druing}
        </if>
        <if test="request.projectCode != null and request.projectCode != ''">
            and di.project_code = #{request.projectCode}
        </if>
    </sql>

    <sql id="Join_Table">
        left join ter_device_info di on t.sn = di.sn
    </sql>

    <select id="selectByCondition" resultMap="DeviceMonitoringDataResult">
        select
        <include refid="Base_Column_List"/>
        from ter_device_monitoring_data t
        <include refid="Join_Table"/>
        where t.del_flag = 0 and di.project_code is not null
        <include refid="Where_Condition"/>
        order by t.${request.orderBy}
    </select>

    <select id="selectOneById" resultMap="DeviceMonitoringDataResult">
        select
        <include refid="Base_Column_List"/>
        from ter_device_monitoring_data t
        <include refid="Join_Table"/>
        where t.id = #{id} and t.del_flag = 0 and di.project_code is not null limit 1
    </select>

    <select id="listWarinTotalDays" resultType="com.newfiber.termite.domain.response.WarnMonitoringResponseInfo">
        SELECT
        di_min.sn,
        di_min.location,
        di_min.lonandlat,
        di_min.dailyFirstWarnDatetime,
        COUNT(DISTINCT DATE(dm.date)) AS countDays
        FROM
            (SELECT
                 sn,
                 location,
                 lonandlat,
                 MIN(first_warn_datetime) AS dailyFirstWarnDatetime
             FROM
                 ter_device_info
             WHERE
                 project_code = #{projectCode}
             GROUP BY
                 sn,
                 location
            ) AS di_min
                INNER JOIN
            ter_monitoring_warn_record dm ON di_min.sn = dm.sn
        GROUP BY
            di_min.sn,
            di_min.location,
            di_min.lonandlat,
            di_min.dailyFirstWarnDatetime
        ORDER BY
            countDays DESC,
            di_min.sn;
    </select>


    <select id="snWarinTotalDays" resultType="com.newfiber.termite.domain.response.SnWarinTotalDaysResponseInfo">
        SELECT DISTINCT DATE_FORMAT(date, '%Y-%m-%d') AS formatteddate
        FROM ter_monitoring_warn_record
        WHERE sn = #{sn}
        ORDER BY DATE_FORMAT(date, '%Y-%m-%d') DESC;
    </select>

</mapper>