<?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.StatisticEntity">
    <typeAlias alias="statisticEntity" type="com.house365.beans.entity.StatisticEntity" />
    <resultMap id="statistic" class="com.house365.beans.entity.StatisticEntity">
        <result property="id" column="id" />
        <result property="sort" column="sort" />
        <result property="name" column="name" />
        <result property="group" column="group_name" />
        <result property="performance" column="performance" />
        <result property="buyNum" column="buy_num" />
        <result property="createTime" column="create_time" />
        <result property="creater" column="creater" />
        <result property="reportName" column="report_name" />
        <result property="deptCityId" column="dept_city_id" />
        <result property="filePath" column="file_path" />
        <result property="fileName" column="file_name" />
    </resultMap>

    <!-- 用于select查询公用抽取的列 -->
    <sql id="statistic.columns">
        <![CDATA[
        id, sort, name, group_name, performance, buy_num, create_time, creater, report_name, dept_city_id,file_path,file_name
	    ]]>
    </sql>

    <!-- 新增记录 -->
    <insert id="save" parameterClass="statisticEntity">
        <![CDATA[
	        INSERT INTO statistic (
	        	id, 
	        	sort, 
	        	name, 
	        	group_name,
	        	performance, 
	        	buy_num, 
	        	create_time, 
	        	creater, 
	        	report_name,
	        	dept_city_id,
	        	file_path,
	        	file_name
	        ) VALUES (
	        	#id#, 
	        	#sort#, 
	        	#name#, 
	        	#group#, 
	        	#performance#, 
	        	#buyNum#, 
	        	#createTime#, 
	        	#creater#, 
	        	#reportName#,
	        	#deptCityId#,
	        	#filePath#,
	        	#fileName#
	        )
	    ]]>
        <selectKey resultClass="java.lang.Integer" type="post" keyProperty="id">
            SELECT LAST_INSERT_ID()
        </selectKey>
    </insert>

    <!-- 通过ID修改 -->
    <update id="update" parameterClass="statisticEntity">
        <![CDATA[
	        UPDATE statistic SET
		        sort = #sort#, 
		        name = #name#, 
		        group_name = #group#,
		        performance = #performance#, 
		        buy_num = #buyNum#, 
		        create_time = #createTime#, 
		        creater = #creater#, 
		        report_name = #reportName#,
		        dept_city_id = #deptCityId#,
		        file_path = #filePath#,
		        file_name = #fileName#
	        WHERE 
		        id = #id#
	    ]]>
    </update>

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

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

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

    <!-- 用于分页查询抽取的公共的条件 -->
    <sql id="statistic.queryPage">
        <dynamic prepend="WHERE">
            <!-- 默认不开启实体作为条件 -->
            <isNotNull property="searchFilters">
                <isNotEmpty prepend="AND" property="searchFilters.id">
                    <![CDATA[
					id $searchFilters.id.operation$ #searchFilters.id.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.sort">
                    <![CDATA[
					sort $searchFilters.sort.operation$ #searchFilters.sort.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.name">
                    <![CDATA[
					name $searchFilters.name.operation$ #searchFilters.name.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.group">
                    <![CDATA[
					group_name $searchFilters.group.operation$ #searchFilters.group.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.performance">
                    <![CDATA[
					performance $searchFilters.performance.operation$ #searchFilters.performance.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.buyNum">
                    <![CDATA[
					buy_num $searchFilters.buyNum.operation$ #searchFilters.buyNum.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.createTime">
                    <![CDATA[
					create_time $searchFilters.createTime.operation$ #searchFilters.createTime.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.creater">
                    <![CDATA[
					creater $searchFilters.creater.operation$ #searchFilters.creater.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.reportName">
                    <![CDATA[
					report_name $searchFilters.reportName.operation$ #searchFilters.reportName.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.deptCityId">
                    <![CDATA[
					dept_city_id $searchFilters.deptCityId.operation$ #searchFilters.deptCityId.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.filePath">
                    <![CDATA[
					file_path $searchFilters.filePath.operation$ #searchFilters.filePath.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.fileName">
                    <![CDATA[
					file_name $searchFilters.fileName.operation$ #searchFilters.fileName.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 statistic
        <include refid="statistic.queryPage" />
    </select>

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

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

    <select id="getDistinctReportName" resultClass="java.util.HashMap">
        select distinct sort,report_name,file_path,file_name from statistic where dept_city_id=#city#
    </select>

</sqlMap>
