GuardLogDao.xml 3.14 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.diligrp.mobsite.getway.dao.grardlog.impl.GuardLogmapperDaoImpl">

	 <resultMap type="guardLog" id="resultMap">
		<id property="id" column="id" />
		<result property="guardId" column="guard_id" />
		 <result property="guardName" column="guard_name" />
		 <result property="status" column="status" />
		 <result property="created" column="created" />
		 <result property="modified" column="modified" />
		 <result property="yn" column="yn" />
	 </resultMap>
	 
	 <sql id="QUERY_WHERE_CLAUSE">
	 	<![CDATA[where 1=1]]>
	 	<if test="guardName != null and guardName != ''"><![CDATA[AND b.guard_name like CONCAT('%',#{guardName},'%')]]></if>
		<if test="status != null and status != ''"><![CDATA[AND b.status = #{status}]]></if>
		<if test="guardId != null and guardId != ''"><![CDATA[AND b.guard_id = #{guardId}]]></if>
	 </sql>
	 
	 <sql id="QUERY_LIMIT_CONDTION">
	 	<if test="startRow != null and startRow &gt;= 0 and pageSize != null and pageSize &gt; 0">
		       <![CDATA[LIMIT #{startRow},#{pageSize}]]>
	    </if>
	 </sql>
	
	<!-- 增加AppPatch -->
	<insert id="save" parameterType="guardLog">
		<![CDATA[
			INSERT INTO T_GUARD_LOG (
						guard_id,
						guard_name,
						status
			) VALUES (
				#{guardId},
				#{guardName},
				#{status}
			)
		]]>
	</insert>

	<select id="listAllByCondition" parameterType="baseQuery" resultMap="resultMap">
		<![CDATA[SELECT
			a.id,
			a.guard_id,
			a.guard_name,
			a.status,
			a.yn,
			a.created,
			a.modified
			FROM T_GUARD_LOG a
		]]>
		<where>
			<![CDATA[a.yn = 1]]>
			and a.guard_id = #{param.guardId}
		</where>
		ORDER BY a.created DESC
	</select>
	
	<select id="listByCondition" parameterType="guardQuery" resultMap="resultMap">
		<![CDATA[
			select b.guard_id,b.guard_name,max(b.status) status
			from (
				select max(created) created from T_GUARD_LOG where yn=1 GROUP BY guard_id 
			) t LEFT JOIN T_GUARD_LOG b on t.created = b.created  
		]]>
		<include refid="QUERY_WHERE_CLAUSE"/>
		<![CDATA[
			GROUP BY guard_name,guard_id 
			order by b.created desc
		]]>
		<include refid="QUERY_LIMIT_CONDTION"/>
	</select>
	
	<select id="countByCondition" parameterType="guardQuery" resultType="int">
		<![CDATA[
		select count(guard_id) from (
			select b.guard_id,b.guard_name,max(b.status) status
			from (
				select max(created) created from T_GUARD_LOG where yn=1 GROUP BY guard_id 
			) t LEFT JOIN T_GUARD_LOG b on t.created = b.created
		]]>
		<include refid="QUERY_WHERE_CLAUSE"/>
		<![CDATA[
			GROUP BY guard_name,guard_id 
		]]>
		) a
	</select>
	
	<select id="listHistoryByCondition" parameterType="guardQuery" resultMap="resultMap">
		<![CDATA[SELECT
			b.id,
			b.guard_id,
			b.guard_name,
			b.created,
			b.status
			FROM T_GUARD_LOG b
		]]>
		<include refid="QUERY_WHERE_CLAUSE"/>
		ORDER BY b.created DESC
		<include refid="QUERY_LIMIT_CONDTION"/>
	</select>
	
	<select id="countHistoryByCondition" parameterType="guardQuery" resultType="int">
		<![CDATA[SELECT
			count(b.id)
			FROM T_GUARD_LOG b
		]]>
		<include refid="QUERY_WHERE_CLAUSE"/>
	</select>
</mapper>