Newer
Older
newfiber-termite / newfiber-termites / newfiber-termites-dataup / src / main / resources / mapper / termite / TermiteMapper.xml
@xiongkai xiongkai on 22 May 7 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.TermiteMapper">


    <insert id="addtermiteData">

        INSERT INTO `ter_device_monitoring_data` ( `sn`, `date`,`druing`,`rtpitcu`,`uptime`,`software`,`hardware`,`temperature`,`voltage`,`rssi`,`ap`,`camera`)
        VALUES
            ( #{sn}, #{datadate},#{druing}, #{url}, #{uptime},#{software},#{hardware},#{temperature},#{voltage},#{rssi},#{ap},#{camera});
    </insert>


    <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.uptime,
        ta.project_code as projectCode,
        th.project_name as projectName
        FROM
        `ter_device_info` ta
        left join ter_project_info th on ta.project_code =th.project_code
        LEFT JOIN (
        SELECT
        id,
        sn,
        date,
        yesnoant,
        rtpitcu,
        idenpitcu,
        idencolle,
        druing,
        uptime
        FROM
        ( SELECT DISTINCT id,sn, date, yesnoant, rtpitcu, idenpitcu, idencolle, druing, uptime FROM ter_device_monitoring_data ORDER BY date DESC ) AS tn
        GROUP BY
        sn
        ORDER BY
        date
        ) tb ON ta.sn = tb.sn
      where 1=1
        <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 th.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 th.project_code in
            <foreach collection="request.projectCodeList" item="projectCode" index="index" open="(" close=")" separator=",">
                #{projectCode}
            </foreach>
        </if>
      order by  -tb.yesnoant desc
    </select>

    <select id="queryMonitorData" resultType="com.newfiber.termite.domain.response.TermiteInfoResponse">
        SELECT
            ta.id as deviceId,
            tb.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.id=#{request.id}
    </select>

    <update id="updateMonitorData">

        UPDATE `ter_device_monitoring_data`
        SET
            `yesnoant` = #{request.yesnoant},
            `idencolle` = #{request.idencolle},
            `druing` = #{request.druing}
        WHERE
            `id` =#{request.id};
    </update>


    <update id="updateMonitorDevice">
        UPDATE `ter_device_info`
        SET
            `project_code` = #{request.projectCode},
            `location` = #{request.location},
            `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,
        ta.software,
        ta.hardware,
        ta.voltage,
        ta.temperature,
        ta.rssi,
               ta.ap,
               ta.camera
        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.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>



    <insert id="insertMonitorDevice">

        INSERT INTO `ter_device_info` ( `sn`, `location`, `lonandlat`,`project_code`, `category` )
        VALUES
            ( #{request.sn}, #{request.location}, #{request.lonandlat},#{request.projectCode} ,#{request.category});
    </insert>

    <update id="removeMonitorDevice">
        UPDATE `ter_device_info`
        SET
            `del_flag` = '1'
        WHERE
            `id` = #{id};
    </update>


    <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>

    <update id="updatephotoIdentify">
        UPDATE `ter_device_monitoring_data`
        SET
            `yesnoant` = #{yesnoant},
            `idenpitcu` = #{url}
        WHERE
            `id` = #{id};
    </update>



    <select id="queryNeeddurding" resultType="java.lang.String">

select druing 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>
    <select id="queryAlarmdata" resultType="com.newfiber.termite.domain.dto.AlarmDataDto">

        select ta.sn,ta.dataTime,tdi.location  from
            (select  sn,max(`date`) as dataTime  from ter_device_monitoring_data
             where idencolle=1 and yesnoant =1 group by sn order BY `date`  desc) ta
                left join ter_device_info tdi  on ta.sn=tdi.sn where tdi.project_code=#{projectCode}
    </select>



    <update id="updateDeviceLastUpTime">
        UPDATE `ter_device_info`
        SET
            `last_pic_time` = #{lastDate}
        WHERE
            `sn` = #{sn};
    </update>


    <select id="queryDeviceData" resultType="com.newfiber.termite.domain.dto.DeviceInfoDto">
        select ta.sn,ta.last_pic_time as lastPicTime  from ter_device_info ta where ta.project_code=#{projectCode}
    </select>
</mapper>