<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE sqlMap PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
    "http://ibatis.apache.org/dtd/sql-map-2.dtd">
<sqlMap namespace="com.house365.beans.entity.NoticeEntity">
    <typeAlias alias="noticeEntity" type="com.house365.beans.entity.NoticeEntity" />
    <resultMap id="notice" class="com.house365.beans.entity.NoticeEntity">
        <result property="id" column="id" />
        <result property="title" column="title" />
        <result property="content" column="content" />
        <result property="top" column="top" />
        <result property="red" column="red" />
        <result property="city" column="city" />
        <result property="cityName" column="cityName" />
        <result property="createUserid" column="createUserid" />
        <result property="createUsername" column="createUsername" />
        <result property="createTime" column="createTime" />
        <result property="createIp" column="createIp" />
        <result property="updateUserid" column="updateUserid" />
        <result property="updateUsername" column="updateUsername" />
        <result property="updateTime" column="updateTime" />
        <result property="updateIp" column="updateIp" />
    </resultMap>

    <!-- 用于select查询公用抽取的列 -->
    <sql id="notice.columns">
        <![CDATA[
        id, title, content, top, red,city,cityName, createUserid, createUsername, createTime, createIp, updateUserid, updateUsername, updateTime, updateIp
	    ]]>
    </sql>

    <!-- 新增记录 -->
    <insert id="save" parameterClass="noticeEntity">
        <![CDATA[
	        INSERT INTO notice (
	        	id, 
	        	title, 
	        	content, 
	        	top, 
	        	red,
	        	city,
	        	cityName,
	        	createUserid, 
	        	createUsername, 
	        	createTime, 
	        	createIp, 
	        	updateUserid, 
	        	updateUsername, 
	        	updateTime, 
	        	updateIp
	        ) VALUES (
	        	#id#, 
	        	#title#, 
	        	#content#, 
	        	#top#, 
	        	#red#,
	        	#city#,
	        	#cityName#,
	        	#createUserid#, 
	        	#createUsername#, 
	        	#createTime#, 
	        	#createIp#, 
	        	#updateUserid#, 
	        	#updateUsername#, 
	        	#updateTime#, 
	        	#updateIp#
	        )
	    ]]>
        <selectKey resultClass="java.lang.Integer" type="post" keyProperty="id">
            SELECT LAST_INSERT_ID()
        </selectKey>
    </insert>

    <!-- 通过ID修改 -->
    <update id="update" parameterClass="noticeEntity">
        <![CDATA[
	        UPDATE notice SET
		        title = #title#, 
		        content = #content#, 
		        top = #top#, 
		        red = #red#, 
		        createUserid = #createUserid#, 
		        createUsername = #createUsername#, 
		        createTime = #createTime#, 
		        createIp = #createIp#, 
		        updateUserid = #updateUserid#, 
		        updateUsername = #updateUsername#, 
		        updateTime = #updateTime#, 
		        updateIp = #updateIp#,
		        city = #city#,
		        cityName = #cityName#
	        WHERE 
		        id = #id#
	    ]]>
    </update>

    <!-- 通过ID删除 -->
    <delete id="delete">
        <![CDATA[
	        DELETE FROM notice WHERE
	        id = #id#
	    ]]>
    </delete>

    <!-- 通过ID列表批量删除 -->
    <delete id="deleteByIds" parameterClass="java.lang.String">
        <![CDATA[
	        DELETE FROM notice WHERE
	        id IN ($ids$)
	    ]]>
    </delete>

    <!-- 通过ID查询 -->
    <select id="getById" resultMap="notice">
        SELECT
        <include refid="notice.columns" />
        <![CDATA[
	        FROM notice 
	        WHERE 
		        id = #id#
	    ]]>
    </select>

    <!-- 用于分页查询抽取的公共的条件 -->
    <sql id="notice.queryPage">
        <dynamic prepend="WHERE">
            <!-- 默认不开启实体作为条件 -->
            <!--
            <isNotNull property="entity">
                <isNotEmpty prepend="AND" property="entity.id">
                    <![CDATA[
                    id = #entity.id#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="entity.title">
                    <![CDATA[
                    title = #entity.title#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="entity.content">
                    <![CDATA[
                    content = #entity.content#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="entity.top">
                    <![CDATA[
                    top = #entity.top#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="entity.red">
                    <![CDATA[
                    red = #entity.red#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="entity.createUserid">
                    <![CDATA[
                    createUserid = #entity.createUserid#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="entity.createUsername">
                    <![CDATA[
                    createUsername = #entity.createUsername#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="entity.createTime">
                    <![CDATA[
                    createTime = #entity.createTime#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="entity.createIp">
                    <![CDATA[
                    createIp = #entity.createIp#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="entity.updateUserid">
                    <![CDATA[
                    updateUserid = #entity.updateUserid#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="entity.updateUsername">
                    <![CDATA[
                    updateUsername = #entity.updateUsername#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="entity.updateTime">
                    <![CDATA[
                    updateTime = #entity.updateTime#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="entity.updateIp">
                    <![CDATA[
                    updateIp = #entity.updateIp#
                    ]]>
                </isNotEmpty>
            </isNotNull>
             -->
            <isNotNull property="searchFilters">
                <isNotEmpty prepend="AND" property="searchFilters.id">
                    <![CDATA[
					id $searchFilters.id.operation$ #searchFilters.id.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.title">
                    <![CDATA[
					title $searchFilters.title.operation$ #searchFilters.title.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.content">
                    <![CDATA[
					content $searchFilters.content.operation$ #searchFilters.content.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.top">
                    <![CDATA[
					top $searchFilters.top.operation$ #searchFilters.top.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.red">
                    <![CDATA[
					red $searchFilters.red.operation$ #searchFilters.red.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.createUserid">
                    <![CDATA[
					createUserid $searchFilters.createUserid.operation$ #searchFilters.createUserid.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.createUsername">
                    <![CDATA[
					createUsername $searchFilters.createUsername.operation$ #searchFilters.createUsername.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.createTime">
                    <![CDATA[
					createTime $searchFilters.createTime.operation$ #searchFilters.createTime.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.createIp">
                    <![CDATA[
					createIp $searchFilters.createIp.operation$ #searchFilters.createIp.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.updateUserid">
                    <![CDATA[
					updateUserid $searchFilters.updateUserid.operation$ #searchFilters.updateUserid.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.updateUsername">
                    <![CDATA[
					updateUsername $searchFilters.updateUsername.operation$ #searchFilters.updateUsername.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.updateTime">
                    <![CDATA[
					updateTime $searchFilters.updateTime.operation$ #searchFilters.updateTime.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.updateIp">
                    <![CDATA[
					updateIp $searchFilters.updateIp.operation$ #searchFilters.updateIp.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.city">
                    <![CDATA[
					city $searchFilters.city.operation$ #searchFilters.city.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.cityName">
                    <![CDATA[
					cityName $searchFilters.cityName.operation$ #searchFilters.cityName.value#
		            ]]>
                </isNotEmpty>
            </isNotNull>
        </dynamic>
        <dynamic prepend="ORDER BY">
            <isNotNull property="orderColumn">
                <![CDATA[
				$orderColumn$
				]]>
                <isNotNull property="orderMode">
                    $orderMode$
                </isNotNull>
            </isNotNull>
        </dynamic>
    </sql>

    <!-- 为分页查询符合条件的记录数 -->
    <select id="queryByPage_count" resultClass="int">
        SELECT count(*) FROM notice
        <include refid="notice.queryPage" />
    </select>

    <!-- 分页查询指定页记录 -->
    <select id="queryByPage" resultMap="notice">
        SELECT
        <include refid="notice.columns" />
        <![CDATA[
	        FROM notice 
	    ]]>
        <include refid="notice.queryPage" />
        <![CDATA[
		    LIMIT #paging.startRecord#, #paging.pageSize#
        ]]>
    </select>

    <!-- 查询所有记录 -->
    <select id="queryAll" resultMap="notice">
        SELECT
        <include refid="notice.columns" />
        <![CDATA[
		    FROM notice
	    ]]>
        <include refid="notice.queryPage" />
    </select>
</sqlMap>
