Newer
Older
huludao / src / main / resources / mapper / ProWarnLogDao.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.monitoring.ProWarnLogDao">
	
	<!-- 可根据自己的需求,是否要使用 -->
    <resultMap type="com.newfiber.api.pc.model.entity.ProWarnLogEntity" id="proWarnLogMap">
            <result property="id" column="id"/>
            <result property="siteNo" column="site_no"/>
            <result property="siteName" column="site_name"/>
            <result property="warnType" column="warn_type"/>
            <result property="warnTypeDesc" column="warn_type_desc"/>
            <result property="factorsAscii" column="factors_ascii"/>
            <result property="factorsName" column="factors_name"/>
            <result property="warnValue" column="warn_value"/>
            <result property="ttTime" column="tt_time"/>
            <result property="createTime" column="create_time"/>
        </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
	    </trim>
	</sql>
	
	<!-- 获取报警日志表列表 -->
	<select id="queryList" resultType="ProWarnLogEntity">
		select
		<include refid="Base_Column_List" />
		from pro_warn_log
        <choose>
            <when test="sidx != null and sidx.trim() != ''">
                order by ${sidx} ${order}
            </when>
			<otherwise>
                order by id desc
			</otherwise>
        </choose>
	</select>

	<select id="listBySiteNoAndTime" resultType="ProWarnLogEntity">
		select
		a.id,
		a.site_no,
		a.site_name,
		a.warn_type,
		a.warn_type_desc,
		a.factors_ascii,
		a.factors_name,
		a.warn_value,
		a.tt_time,
		a.create_time,
		(case when b.type_id = "3" then true else false end ) as flag
		from pro_warn_log a,pro_site_info b where a.site_no = b.site_no
		<if test="siteNo != null">
			and a.site_no = #{siteNo}
		</if>
		<if test="warnType != null">
			and a.warn_type = #{warnType}
		</if>
		<if test="fuzzyQuery != null and fuzzyQuery.trim() != ''">
			and concat(a.factors_ascii,a.factors_name) like concat('%',#{fuzzyQuery},'%')
		</if>
		<if test="startTime != null and endTime != null">
			and a.tt_time between #{startTime} and #{endTime}
		</if>
		order by a.tt_time desc
	</select>

	<select id="listlatestData" resultType="ProWarnLogEntity">
		SELECT w.id,w.site_no,w.site_name,w.warn_type,w.warn_type_desc,w.factors_ascii,w.factors_name,w.warn_value,w.tt_time,w.create_time
		FROM pro_warn_log w
		INNER JOIN
		(SELECT site_no,factors_ascii,warn_type,MAX(tt_time) maxtt FROM pro_warn_log GROUP BY site_no,factors_ascii,warn_type) t
		ON w.site_no = t.site_no AND w.factors_ascii = t.factors_ascii AND w.warn_type = t.warn_type AND w.tt_time = t.maxtt
		WHERE 1 = 1
		and w.tt_time BETWEEN DATE_SUB(NOW(),INTERVAL 10 MINUTE) AND NOW()
		AND w.site_no = #{siteNo}
	</select>

	<select id="getWarnCount" resultType="int">
		select count(t.tt_time) from
		(select tt_time from pro_warn_log
			where site_no = #{siteNo} and tt_time >= #{startTime} and tt_time &lt; #{endTime} group by tt_time) t
	</select>

	<update id="updateBatch" parameterType="Map">
		update pro_warn_log SET warn_type = #{type} ,auditor_msg = #{msg},warn_type_desc = #{typeDes}
		WHERE 1=1
		<if test="ids != null and ids.size() >0">
			AND id in
			<foreach collection="ids" item="id" separator="," open="(" close=")">
				#{id}
			</foreach>
		</if>
	</update>
</mapper>