<?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.monitoring.WranLogMapper"> <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="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> <select id="listWarnLog" parameterType="map" resultMap="baseResultMap"> select w.*,sp.`name`,b.warn_value warnConfigValue from nf_monitor.warn_log w left join nf_monitor.sys_platform sp on w.plat_form=sp.platform_code left join nf_monitor.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 limit #{current},#{size} </select> <select id="warnLogCount" resultType="long"> select COUNT(w.id) from nf_monitor.warn_log w left join nf_monitor.sys_platform sp on w.plat_form=sp.platform_code left join nf_monitor.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> </select> <select id="selectPage" resultMap="baseResultMap"> select w.*,sp.`name`,b.warn_value warnConfigValue from nf_monitor.warn_log w left join nf_monitor.sys_platform sp on w.plat_form=sp.platform_code left join nf_monitor.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="obj != null"> <if test="obj.platForm != null and obj.platForm != ''"> and w.plat_form = #{obj.platForm} </if> <if test="obj.startTime != null and obj.endTime != null"> and w.tt_time between #{obj.startTime} and #{obj.endTime} </if> <if test="obj.siteName != null and obj.siteName.trim() != ''"> and concat(w.site_no,w.site_name,w.factors_ascii,w.factors_name,w.warn_type_desc) like concat('%',#{obj.siteName},'%') </if> </if> order by tt_time desc limit #{current},#{size} </select> <select id="selectCount" resultType="java.lang.Long"> select COUNT(w.id) from nf_monitor.warn_log w left join nf_monitor.sys_platform sp on w.plat_form=sp.platform_code left join nf_monitor.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="obj != null"> <if test="obj.platForm != null and obj.platForm != ''"> and w.plat_form = #{obj.platForm} </if> <if test="obj.startTime != null and obj.endTime != null"> and w.tt_time between #{obj.startTime} and #{obj.endTime} </if> <if test="obj.siteName != null and obj.siteName.trim() != ''"> and concat(w.site_no,w.site_name,w.factors_ascii,w.factors_name,w.warn_type_desc) like concat('%',#{obj.siteName},'%') </if> </if> </select> <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> <insert id="insertIntoLog" parameterType="com.newfiber.api.pc.model.zhz.WarnLog"> insert into device_alarm(site_no,`name`,address,record_time,create_time,`depth`,alarm_desc,alarm_name,alarm_type) values(#{warnLog.siteNo},#{warnLog.address},#{warnLog.address},#{warnLog.recordTime},#{warnLog.recordTime},#{warnLog.depth},#{warnLog.alarmDesc},#{warnLog.alarmName},#{warnLog.alarmType}) </insert> <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> <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>