Newer
Older
huludao / src / main / resources / mapper / WarnLogDao.xml
<?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.api.pc.dao.WarnLogDao">

    <resultMap type="com.newfiber.api.pc.model.zhz.WarnLog" id="baseResultMap">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result column="site_no" property="siteNo" jdbcType="VARCHAR"/>
        <result column="site_name" property="siteName" jdbcType="VARCHAR"/>
        <result column="factors_ascii" property="factorsAscii" jdbcType="VARCHAR"/>
        <result column="factors_name" property="factorsName" jdbcType="VARCHAR"/>
        <result column="warn_value" property="warnValue" jdbcType="DECIMAL"/>
        <result column="warn_type" property="warnType" jdbcType="INTEGER"/>
        <result column="warn_type_desc" property="warnTypeDesc" jdbcType="VARCHAR"/>
        <result column="tt_time" property="ttTime" jdbcType="TIMESTAMP"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
        <result column="auditor_msg" property="auditorMsg" jdbcType="VARCHAR"/>
        <result column="plat_form" property="platForm" jdbcType="VARCHAR"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        <trim suffixOverrides=",">
            id,
            site_no,
            site_name,
            warn_type,
            warn_type_desc,
            factors_ascii,
            factors_name,
            warn_value,
            tt_time,
            create_time,
            auditor_msg,
            plat_form,
        </trim>
    </sql>

    <sql id="Insert_Query">
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="siteNo != null">
                site_no,
            </if>
            <if test="siteName != null">
                site_name,
            </if>
            <if test="warnType != null">
                warn_type,
            </if>
            <if test="warnTypeDesc != null">
                warn_type_desc,
            </if>
            <if test="factorsAscii != null">
                factors_ascii,
            </if>
            <if test="factorsName != null">
                factors_name,
            </if>
            <if test="warnValue != null">
                warn_value,
            </if>
            <if test="ttTime != null">
                tt_time,
            </if>
            <if test="auditorMsg != null">
                auditor_msg,
            </if>
            <if test="platForm != null">
                plat_form,
            </if>
            <if test="compareWay != null">
                compare_way,
            </if>
            <if test="multiWarnValue != null">
                multi_warn_value,
            </if>
            <if test="conditionType != null">
                condition_type,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="siteNo != null">
                #{siteNo,jdbcType=VARCHAR},
            </if>
            <if test="siteName != null">
                #{siteName,jdbcType=VARCHAR},
            </if>
            <if test="warnType != null">
                #{warnType,jdbcType=INTEGER},
            </if>
            <if test="warnTypeDesc != null">
                #{warnTypeDesc,jdbcType=VARCHAR},
            </if>
            <if test="factorsAscii != null">
                #{factorsAscii,jdbcType=VARCHAR},
            </if>
            <if test="factorsName != null">
                #{factorsName,jdbcType=VARCHAR},
            </if>
            <if test="warnValue != null">
                #{warnValue,jdbcType=DECIMAL},
            </if>
            <if test="ttTime != null">
                #{ttTime,jdbcType=TIMESTAMP},
            </if>
            <if test="auditorMsg != null">
                #{auditorMsg,jdbcType=VARCHAR},
            </if>
            <if test="platForm != null">
                #{platForm,jdbcType=VARCHAR},
            </if>
            <if test="compareWay != null">
                #{compareWay,jdbcType=VARCHAR},
            </if>
            <if test="multiWarnValue != null">
                #{multiWarnValue,jdbcType=VARCHAR},
            </if>
            <if test="conditionType != null">
                #{conditionType,jdbcType=VARCHAR},
            </if>
        </trim>
    </sql>

    <update id="updateOrInsert" parameterType="com.newfiber.api.pc.model.zhz.WarnLog">
        <selectKey keyProperty="count" resultType="int" order="BEFORE">
            select count(*) from warn_temp where site_no = #{siteNo} and factors_ascii = #{factorsAscii} and warn_type = #{warnType}
        </selectKey>

        <if test="count == 0">
            insert into warn_temp
            <include refid="Insert_Query"/>
        </if>

        <if test="count > 0">
            update warn_temp
            <set>
                <if test="warnValue != null">
                    warn_value = #{warnValue},
                </if>
                <if test="ttTime != null">
                    tt_time = #{ttTime,jdbcType = TIMESTAMP},
                </if>
            </set>
            where site_no = #{siteNo} and factors_ascii = #{factorsAscii} and warn_type = #{warnType}
        </if>
    </update>

    <delete id="deleteWarnTemp">
        delete from warn_temp
        where 1 = 1  and site_no = #{siteNo}

        <if test="factorsAscii != null">
            and factors_ascii = #{factorsAscii}
        </if>
        <if test="warnType != null">
            and warn_type = #{warnType}
        </if>
    </delete>

    <select id="getSiteWarnState" parameterType="Map" resultType="com.newfiber.api.pc.model.zhz.WarnLog">
        select  c.site_name,c.site_no,c.factors_ascii,
               case when t.warn_type is null then 0  when t.warn_type = 1 then 1 else 2 end as state,
               max(case when c.WARN_TYPE = 1 THEN c.warn_value else null end) as warn,
               max(case when c.WARN_TYPE = 2 THEN c.warn_value else null end) as alarm
        from warn_config c left join warn_temp t on c.site_no = t.site_no and c.factors_ascii = t.factors_ascii
        where 1 = 1
        <if test="platFrom != null">
            and c.plat_form in
          <foreach collection="platFrom" item="code" open="(" close=")" separator=",">
              #{code}
          </foreach>
        </if>
        <if test="factorsAscii != null">
            and c.factors_ascii = #{factorsAscii}
        </if>
        group by c.site_name,c.site_no,c.factors_ascii,state
    </select>

    <insert id="insertIntoLog" parameterType="com.newfiber.api.pc.model.zhz.WarnLog">
        insert into warn_log
        <include refid="Insert_Query"/>
    </insert>

    <select id="listWarnLog" parameterType="map" resultMap="baseResultMap">
        select w.*,sp.`name`,b.warn_value warnConfigValue from warn_log w left join sys_platform sp on w.plat_form=sp.platform_code
        left join warn_config b on w.warn_type = b.warn_type and w.factors_ascii= b.factors_ascii and w.site_no = b.site_no
        where (w.warn_type = 1 or w.warn_type = 2)
        <if test="siteNo != null and siteNo != ''">
            and w.site_no = #{siteNo}
        </if>
        <if test="platForm != null and platForm != ''">
            and w.plat_form = #{platForm}
        </if>
        <if test="platformCodeList != null and platformCodeList.size() != 0 ">
            and w.plat_form in
            <foreach item="item" index="index" collection="platformCodeList" open="(" separator="," close=")">
                #{item,jdbcType=VARCHAR}
            </foreach>
        </if>
        <if test="factorsAscii != null and factorsAscii != ''">
            and w.factors_ascii = #{factorsAscii}
        </if>
        <if test="warnType != null">
            and w.warn_type = #{warnType}
        </if>
        <if test="startTime != null and endTime != null">
            and w.tt_time between #{startTime} and #{endTime}
        </if>
        <if test="siteName != null and siteName.trim() != ''">
            and concat(w.site_no,w.site_name,w.factors_ascii,w.factors_name,w.warn_type_desc) like concat('%',#{siteName},'%')
        </if>
        order by tt_time desc
    </select>

    <select id="getWarnLogOfPlatform" parameterType="map" resultMap="baseResultMap">
        select w.*
        from warn_log w
        inner join (select site_no,factors_ascii,max(tt_time) maxtt from warn_log
                where tt_time between dateadd(hour,-3,now()) and now()
                group by site_no,factors_ascii
            ) t
        on w.site_no = t.site_no and w.factors_ascii = t.factors_ascii and w.tt_time  = t.maxtt
        <where>
            <if test="platform != null and platform.trim() != ''">
                plat_form = #{platform}
            </if>
        </where>
    </select>

</mapper>