Newer
Older
newfiber-termite / newfiber-termites / newfiber-termites-dataup / src / main / resources / mapper / termite / TermiteMapper.xml
@liuyuanye liuyuanye on 16 Oct 5 KB Sql调整
<?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.TermiteMapper">

    <select id="querytermiteData" resultType="com.newfiber.termite.domain.response.TermiteInfoResponse">
        SELECT
        ta.id as deviceId,
        tb.id,
        ta.category,
        ta.sn,
        ta.location,
        ta.lonandlat,
        tb.date,
        tb.yesnoant,
        tb.rtpitcu,
        tb.idenpitcu,
        tb.idencolle,
        tb.druing,
        tb.druing_datetime,
        tb.heating,
        tb.heating_datetime,
        tb.uptime,
        ta.status,
        pu.user_id AS userId,
        case when TIMESTAMPDIFF(minute, uptime, now()) > 1440 then 0 else 1 end as onlineStatus,
        ta.project_code as projectCode,
        pu.project_name as projectName,
        ta.first_warn_datetime as firstWarnDatetime,
        ta.create_time as createTime
        FROM
        `ter_device_info` ta
        JOIN ter_project_user pu ON ta.project_code = pu.project_code
        LEFT JOIN ter_device_monitoring_data_realtime tb ON ta.sn = tb.sn
      where 1=1 and ta.del_flag = 0
        <if test="request.userId != null and request.userId != ''">
            and pu.user_id = #{request.userId}
        </if>
        <if test="request.projectName != null and request.projectName != ''">
            and pu.project_name  like concat('%',#{request.projectName},'%')
        </if>
        <if test="request.sn != null and request.sn != ''">
            and ta.sn  like concat('%',#{request.sn},'%')
        </if>
        <if test="request.uptime != null and request.uptime != ''">
            and tb.uptime  like concat('%',#{request.uptime},'%')
        </if>
        <if test="request.location != null and request.location != ''">
            and ta.location  like concat('%',#{request.location},'%')
        </if>
        <if test="request.yesnoant != null and request.yesnoant != ''">
            and tb.yesnoant =#{request.yesnoant}
        </if>
        <if test="request.idencolle != null and request.idencolle != ''">
            and tb.idencolle =#{request.idencolle}
        </if>
        <if test="request.druing != null and request.druing != ''">
            and tb.druing =#{request.druing}
        </if>
        <if test="request.projectCode != null and request.projectCode != ''">
            and pu.project_code =#{request.projectCode}
        </if>
        <if test="request.category != null and request.category != ''">
            and ta.category =#{request.category}
        </if>
        <if test="request.projectCodeList != null and request.projectCodeList.size > 0">
            and pu.project_code in
            <foreach collection="request.projectCodeList" item="projectCode" index="index" open="(" close=")" separator=",">
                #{projectCode}
            </foreach>
        </if>

        <choose>
            <when test="request.orderBy != null and request.orderBy != ''">
                order by ${request.orderBy}
            </when>
            <otherwise>
                order by  -tb.yesnoant desc, tb.uptime desc
            </otherwise>
        </choose>

    </select>

    <update id="updateMonitorDevice">
        UPDATE `ter_device_info`
        SET
            `project_code` = #{request.projectCode},
            `location_type` = #{request.locationType},
            `location` = #{request.location},
            `lonandlat` = #{request.lonandlat},
            `sn` = #{request.sn}
        WHERE
            `id` =#{request.id};
    </update>

    <select id="queryhistoryData" resultType="com.newfiber.termite.domain.response.TermiteInfoResponse">
        SELECT
            ta.id,
            ta.sn,
            ta.date,
            ta.yesnoant,
            ta.rtpitcu,
            ta.idenpitcu,
            ta.idencolle,
            ta.druing,
            ta.uptime,
            tb.location
        FROM
        ter_device_monitoring_data ta
        left join ter_device_info tb on ta.sn=tb.sn
        where ta.sn=#{request.sn}
        <if test="request.yesnoant != null and request.yesnoant != ''">
            and ta.yesnoant =#{request.yesnoant}
        </if>
        <if test="request.idencolle != null and request.idencolle != ''">
            and ta.idencolle =#{request.idencolle}
        </if>
        <if test="request.druing != null and request.druing != ''">
            and ta.druing =#{request.druing}
        </if>
        <if test="request.category != null and request.category != ''">
            and tb.category = #{request.category}
        </if>
        <if test="request.starttime != null and request.starttime != ''">
            and ta.uptime  &gt;  #{request.starttime}
        </if>

        <if test="request.endtime != null and request.endtime != ''">
            and ta.uptime &lt;  #{request.endtime}
        </if>
        ORDER BY date desc
    </select>

    <select id="querynewphoto" resultType="java.lang.String">
        select rtpitcu from ter_device_monitoring_data where sn=#{sn} order by uptime desc limit 1
    </select>


    <update id="updateModlefirstData">
        UPDATE `ter_device_info`
        SET
            `initialpictu` = #{newphoto}
        WHERE
            `sn` = #{sn}
    </update>

    <resultMap type="com.newfiber.termite.domain.response.DataUpResponse" id="DataUpResponseResult">
        <result property="druing" column="druing"/>
        <result property="heating" column="heating"/>
    </resultMap>
    <select id="queryDataUpResponse" resultMap="DataUpResponseResult">
        select druing, heating from ter_device_monitoring_data where sn=#{sn} order by uptime desc  limit 1
    </select>

    <select id="queryUnitdata" resultType="com.newfiber.termite.domain.dto.UnitInfoDto">
        SELECT
            construction_unit,
            people,
            telephone
        FROM
            `ter_unit_info`
        where is_choose = 1
    </select>
</mapper>