<?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.UserSourceStatisticsEntity">
    <typeAlias alias="userSourceStatisticsEntity" type="com.house365.beans.entity.UserSourceStatisticsEntity" />
    <resultMap id="userSourceStatistics" class="com.house365.beans.entity.UserSourceStatisticsEntity">
        <result property="id" column="id" />
        <result property="projectId" column="projectId" />
        <result property="projectName" column="projectName" />
        <result property="objectType" column="objectType" />
        <result property="customerStatus" column="customerStatus" />
        <result property="customerNum" column="customerNum" />
        <result property="sourceId" column="sourceId" />
        <result property="sourceName" column="sourceName" />
        <result property="city" column="city" />
        <result property="cityName" column="cityName" />
        <result property="dayBaseRatio" column="dayBaseRatio" />
        <result property="createTime" column="createTime" />
    </resultMap>

    <!-- 用于select查询公用抽取的列 -->
    <sql id="userSourceStatistics.columns">
        <![CDATA[
        id, projectId, projectName, objectType, customerStatus, customerNum, sourceId, sourceName, city, cityName, dayBaseRatio, createTime
	    ]]>
    </sql>

    <!-- 新增记录 -->
    <insert id="save" parameterClass="userSourceStatisticsEntity">
        <![CDATA[
	        INSERT INTO user_source_statistics (
	        	id, 
	        	projectId, 
	        	projectName, 
	        	objectType, 
	        	customerStatus, 
	        	customerNum, 
	        	sourceId, 
	        	sourceName, 
	        	city, 
	        	cityName, 
	        	dayBaseRatio, 
	        	createTime
	        ) VALUES (
	        	#id#, 
	        	#projectId#, 
	        	#projectName#, 
	        	#objectType#, 
	        	#customerStatus#, 
	        	#customerNum#, 
	        	#sourceId#, 
	        	#sourceName#, 
	        	#city#, 
	        	#cityName#, 
	        	#dayBaseRatio#, 
	        	#createTime#
	        )
	    ]]>
        <selectKey resultClass="java.lang.Integer" type="post" keyProperty="id">
            SELECT LAST_INSERT_ID()
        </selectKey>
    </insert>

    <!-- 通过ID修改 -->
    <update id="update" parameterClass="userSourceStatisticsEntity">
        <![CDATA[
	        UPDATE user_source_statistics SET
		        projectId = #projectId#, 
		        projectName = #projectName#, 
		        objectType = #objectType#, 
		        customerStatus = #customerStatus#, 
		        customerNum = #customerNum#, 
		        sourceId = #sourceId#, 
		        sourceName = #sourceName#, 
		        city = #city#, 
		        cityName = #cityName#, 
		        dayBaseRatio = #dayBaseRatio#, 
		        createTime = #createTime#
	        WHERE 
		        id = #id#
	    ]]>
    </update>

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

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

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

    <!-- 用于分页查询抽取的公共的条件 -->
    <sql id="userSourceStatistics.queryPage">
        <dynamic prepend="WHERE">
            <!-- 默认不开启实体作为条件 -->
            <!--
            <isNotNull property="entity">
                <isNotEmpty prepend="AND" property="entity.id">
                    <![CDATA[
                    id = #entity.id#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="entity.projectId">
                    <![CDATA[
                    projectId = #entity.projectId#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="entity.projectName">
                    <![CDATA[
                    projectName = #entity.projectName#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="entity.objectType">
                    <![CDATA[
                    objectType = #entity.objectType#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="entity.customerStatus">
                    <![CDATA[
                    customerStatus = #entity.customerStatus#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="entity.customerNum">
                    <![CDATA[
                    customerNum = #entity.customerNum#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="entity.sourceId">
                    <![CDATA[
                    sourceId = #entity.sourceId#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="entity.sourceName">
                    <![CDATA[
                    sourceName = #entity.sourceName#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="entity.city">
                    <![CDATA[
                    city = #entity.city#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="entity.cityName">
                    <![CDATA[
                    cityName = #entity.cityName#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="entity.dayBaseRatio">
                    <![CDATA[
                    dayBaseRatio = #entity.dayBaseRatio#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="entity.createTime">
                    <![CDATA[
                    createTime = #entity.createTime#
                    ]]>
                </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.projectId">
                    <![CDATA[
					projectId $searchFilters.projectId.operation$ #searchFilters.projectId.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.projectName">
                    <![CDATA[
					projectName $searchFilters.projectName.operation$ #searchFilters.projectName.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.objectType">
                    <![CDATA[
					objectType $searchFilters.objectType.operation$ #searchFilters.objectType.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.customerStatus">
                    <![CDATA[
					customerStatus $searchFilters.customerStatus.operation$ #searchFilters.customerStatus.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.customerNum">
                    <![CDATA[
					customerNum $searchFilters.customerNum.operation$ #searchFilters.customerNum.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.sourceId">
                    <![CDATA[
					sourceId $searchFilters.sourceId.operation$ #searchFilters.sourceId.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.sourceName">
                    <![CDATA[
					sourceName $searchFilters.sourceName.operation$ #searchFilters.sourceName.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>
                <isNotEmpty prepend="AND" property="searchFilters.dayBaseRatio">
                    <![CDATA[
					dayBaseRatio $searchFilters.dayBaseRatio.operation$ #searchFilters.dayBaseRatio.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.createTime">
                    <![CDATA[
					createTime $searchFilters.createTime.operation$ #searchFilters.createTime.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 user_source_statistics
        <include refid="userSourceStatistics.queryPage" />
    </select>

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

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


    <sql id="userSourceStatistics.queryPage1">
        <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.projectId">
                    <![CDATA[
					projectId $searchFilters.projectId.operation$ #searchFilters.projectId.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.projectIds">
                    projectId $searchFilters.projectIds.operation$
                    <iterate open="(" close=")" conjunction="," property="searchFilters.projectIds.value">
                        #searchFilters.projectIds.value[]#
                    </iterate>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.projectName">
                    <![CDATA[
					projectName $searchFilters.projectName.operation$ #searchFilters.projectName.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.objectType">
                    <![CDATA[
					objectType $searchFilters.objectType.operation$ #searchFilters.objectType.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.customerStatus">
                    <![CDATA[
					customerStatus $searchFilters.customerStatus.operation$ #searchFilters.customerStatus.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.customerNum">
                    <![CDATA[
					customerNum $searchFilters.customerNum.operation$ #searchFilters.customerNum.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.sourceId">
                    <![CDATA[
					sourceId $searchFilters.sourceId.operation$ #searchFilters.sourceId.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.sourceName">
                    <![CDATA[
					sourceName $searchFilters.sourceName.operation$ #searchFilters.sourceName.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>
                <isNotEmpty prepend="AND" property="searchFilters.dayBaseRatio">
                    <![CDATA[
					dayBaseRatio $searchFilters.dayBaseRatio.operation$ #searchFilters.dayBaseRatio.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.createTime">
                    <![CDATA[
					createTime $searchFilters.createTime.operation$ #searchFilters.createTime.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.andCreateTime">
                    <![CDATA[
					createTime $searchFilters.andCreateTime.operation$ #searchFilters.andCreateTime.value#
		            ]]>
                </isNotEmpty>
            </isNotNull>
        </dynamic>
    </sql>

    <select id="statisticCustomer" resultClass="java.util.HashMap">
        <![CDATA[
        select a.*,d.name deptname, (
        select IFNULL(sum(customernum),0) customerNum1 from user_source_statistics a1
        where a1.cityname=a.cityname and a1.customerStatus=a.customerStatus and a1.projectName=a.projectName
        and DATE_FORMAT(DATE_ADD(a1.createTime,INTERVAL 1 DAY),'%Y%m%d')=DATE_FORMAT(a.createTime,'%Y%m%d')
        ) prenum from (
		SELECT min(id) id,cityname,customerStatus,DATE_FORMAT(createTime,'%Y%m%d') createTime,
		projectid,projectName,IFNULL(sum(customernum),0) customerNum
		FROM user_source_statistics
		]]>
        <include refid="userSourceStatistics.queryPage1" />
        <![CDATA[
		group by projectid,cityname,customerStatus,DATE_FORMAT(createTime,'%Y%m%d'),projectName
        ]]>
        <dynamic prepend="ORDER BY">
            <isNotNull property="orderColumn">
                <![CDATA[
				$orderColumn$
				]]>
                <isNotNull property="orderMode">
                    $orderMode$
                </isNotNull>
            </isNotNull>
        </dynamic>
        <![CDATA[
		    LIMIT #paging.startRecord#, #paging.pageSize#
        ]]>
        ) a,user u,department d where a.projectid=u.id and u.deptId=d.id
    </select>

    <select id="countStatisticCustomer" resultClass="int">
        select count(0) from (
        SELECT min(id) id,cityname,customerStatus,createTime,projectName,IFNULL(sum(customernum),0) customerNum
        FROM user_source_statistics
        <include refid="userSourceStatistics.queryPage1" />
        <![CDATA[
        group by cityname,customerStatus,DATE_FORMAT(createTime,'%Y%m%d'),projectName) a
        ]]>
    </select>

    <select id="statisticCustomerByWeek" resultClass="java.util.HashMap">
        <![CDATA[
        select a.*,d.name deptname, (
        select IFNULL(sum(customernum),0) customerNum1 from user_source_statistics a1
        where a1.cityname=a.cityname and a1.customerStatus=a.customerStatus and a1.projectName=a.projectName
        and DATE_FORMAT(DATE_ADD(a1.createTime,INTERVAL 1 WEEK),'%Y%u')=a.createTime
        ) prenum from (
		SELECT min(id) id,cityname,customerStatus,DATE_FORMAT(createTime,'%Y%u') createTime,
		projectid,projectName,IFNULL(sum(customernum),0) customerNum
		FROM user_source_statistics
		]]>
        <include refid="userSourceStatistics.queryPage1" />
        <![CDATA[
		group by projectid,cityname,customerStatus,DATE_FORMAT(createTime,'%Y%u'),projectName
        ]]>
        <dynamic prepend="ORDER BY">
            <isNotNull property="orderColumn">
                <![CDATA[
				$orderColumn$
				]]>
                <isNotNull property="orderMode">
                    $orderMode$
                </isNotNull>
            </isNotNull>
        </dynamic>
        <![CDATA[
		    LIMIT #paging.startRecord#, #paging.pageSize#
        ]]>
        ) a,user u,department d where a.projectid=u.id and u.deptId=d.id
    </select>

    <select id="countStatisticCustomerByWeek" resultClass="int">
        select count(0) from (
        SELECT min(id) id,cityname,customerStatus,createTime,projectName,IFNULL(sum(customernum),0) customerNum
        FROM user_source_statistics
        <include refid="userSourceStatistics.queryPage1" />
        <![CDATA[
        group by cityname,customerStatus,DATE_FORMAT(createTime,'%Y%u'),projectName) a
        ]]>
    </select>

    <select id="statisticCustomerByMonth" resultClass="java.util.HashMap">
        <![CDATA[
        select a.*,d.name deptname, (
        select IFNULL(sum(customernum),0) customerNum1 from user_source_statistics a1
        where a1.cityname=a.cityname and a1.customerStatus=a.customerStatus and a1.projectName=a.projectName
        and DATE_FORMAT(DATE_ADD(a1.createTime,INTERVAL 1 MONTH),'%Y%m')=a.createTime
        ) prenum from (
		SELECT min(id) id,cityname,customerStatus,DATE_FORMAT(createTime,'%Y%m') createTime,
		projectid,projectName,IFNULL(sum(customernum),0) customerNum
		FROM user_source_statistics
		]]>
        <include refid="userSourceStatistics.queryPage1" />
        <![CDATA[
		group by projectid,cityname,customerStatus,DATE_FORMAT(createTime,'%Y%m'),projectName
        ]]>
        <dynamic prepend="ORDER BY">
            <isNotNull property="orderColumn">
                <![CDATA[
				$orderColumn$
				]]>
                <isNotNull property="orderMode">
                    $orderMode$
                </isNotNull>
            </isNotNull>
        </dynamic>
        <![CDATA[
		    LIMIT #paging.startRecord#, #paging.pageSize#
        ]]>
        ) a,user u,department d where a.projectid=u.id and u.deptId=d.id
    </select>

    <select id="countStatisticCustomerByMonth" resultClass="int">
        select count(0) from (
        SELECT min(id) id,cityname,customerStatus,createTime,projectName,IFNULL(sum(customernum),0) customerNum
        FROM user_source_statistics
        <include refid="userSourceStatistics.queryPage1" />
        <![CDATA[
        group by cityname,customerStatus,DATE_FORMAT(createTime,'%Y%m'),projectName) a
        ]]>
    </select>


    <select id="statisticStatusSource" resultClass="java.util.HashMap">
        <![CDATA[
        select a.*, (
        select IFNULL(sum(customernum),0) customerNum1 from user_source_statistics a1
        where a1.cityname=a.cityname and a1.customerStatus=a.customerStatus and a1.sourcename=a.sourcename
        and DATE_FORMAT(DATE_ADD(a1.createTime,INTERVAL 1 DAY),'%Y%m%d')=a.createTime
        ) prenum from (
		SELECT min(id) id,cityname,customerStatus,sourcename,DATE_FORMAT(createTime,'%Y%m%d') createTime,IFNULL(sum(customernum),0) customerNum
		FROM user_source_statistics
		]]>
        <include refid="userSourceStatistics.queryPage1" />
        <![CDATA[
		group by cityname,customerStatus,sourcename,DATE_FORMAT(createTime,'%Y%m%d')
        ]]>
        <dynamic prepend="ORDER BY">
            <isNotNull property="orderColumn">
                <![CDATA[
				$orderColumn$
				]]>
                <isNotNull property="orderMode">
                    $orderMode$
                </isNotNull>
            </isNotNull>
        </dynamic>
        <![CDATA[
		    LIMIT #paging.startRecord#, #paging.pageSize#
        ]]>
        ) a
    </select>

    <select id="countStatusSource" resultClass="int">
        select count(0) from (
        SELECT min(id) id,cityname,customerStatus,sourcename,DATE_FORMAT(createTime,'%Y%m%d')
        createTime,IFNULL(sum(customernum),0) customerNum
        FROM user_source_statistics
        <include refid="userSourceStatistics.queryPage1" />
        <![CDATA[
        group by cityname,customerStatus,sourcename,DATE_FORMAT(createTime,'%Y%m%d')) a
        ]]>
    </select>

    <select id="statisticStatusSourceByWeek" resultClass="java.util.HashMap">
        <![CDATA[
        select a.*, (
        select IFNULL(sum(customernum),0) customerNum1 from user_source_statistics a1
        where a1.cityname=a.cityname and a1.customerStatus=a.customerStatus and a1.sourcename=a.sourcename
        and DATE_FORMAT(DATE_ADD(a1.createTime,INTERVAL 1 WEEK),'%Y%u')=a.createTime
        ) prenum from (
		SELECT min(id) id,cityname,customerStatus,sourcename,DATE_FORMAT(createTime,'%Y%u') createTime,IFNULL(sum(customernum),0) customerNum
		FROM user_source_statistics
		]]>
        <include refid="userSourceStatistics.queryPage1" />
        <![CDATA[
		group by cityname,customerStatus,sourcename,DATE_FORMAT(createTime,'%Y%u')
        ]]>
        <dynamic prepend="ORDER BY">
            <isNotNull property="orderColumn">
                <![CDATA[
				$orderColumn$
				]]>
                <isNotNull property="orderMode">
                    $orderMode$
                </isNotNull>
            </isNotNull>
        </dynamic>
        <![CDATA[
		    LIMIT #paging.startRecord#, #paging.pageSize#
        ]]>
        ) a
    </select>

    <select id="countStatusSourceByWeek" resultClass="int">
        select count(0) from (
        SELECT min(id) id,cityname,customerStatus,sourcename,DATE_FORMAT(createTime,'%Y%u')
        createTime,IFNULL(sum(customernum),0) customerNum
        FROM user_source_statistics
        <include refid="userSourceStatistics.queryPage1" />
        <![CDATA[
        group by cityname,customerStatus,sourcename,DATE_FORMAT(createTime,'%Y%u')) a
        ]]>
    </select>

    <select id="statisticStatusSourceByMonth" resultClass="java.util.HashMap">
        <![CDATA[
        select a.*, (
        select IFNULL(sum(customernum),0) customerNum1 from user_source_statistics a1
        where a1.cityname=a.cityname and a1.customerStatus=a.customerStatus and a1.sourcename=a.sourcename
        and DATE_FORMAT(DATE_ADD(a1.createTime,INTERVAL 1 MONTH),'%Y%m')=a.createTime
        ) prenum from (
		SELECT min(id) id,cityname,customerStatus,sourcename,DATE_FORMAT(createTime,'%Y%m') createTime,IFNULL(sum(customernum),0) customerNum
		FROM user_source_statistics
		]]>
        <include refid="userSourceStatistics.queryPage1" />
        <![CDATA[
		group by cityname,customerStatus,sourcename,DATE_FORMAT(createTime,'%Y%m')
        ]]>
        <dynamic prepend="ORDER BY">
            <isNotNull property="orderColumn">
                <![CDATA[
				$orderColumn$
				]]>
                <isNotNull property="orderMode">
                    $orderMode$
                </isNotNull>
            </isNotNull>
        </dynamic>
        <![CDATA[
		    LIMIT #paging.startRecord#, #paging.pageSize#
        ]]>
        ) a
    </select>

    <select id="countStatusSourceByMonth" resultClass="int">
        select count(0) from (
        SELECT min(id) id,cityname,customerStatus,sourcename,DATE_FORMAT(createTime,'%Y%m')
        createTime,IFNULL(sum(customernum),0) customerNum
        FROM user_source_statistics
        <include refid="userSourceStatistics.queryPage1" />
        <![CDATA[
        group by cityname,customerStatus,sourcename,DATE_FORMAT(createTime,'%Y%m')) a
        ]]>
    </select>


    <!--客户转化分析-->

    <select id="transCustomer" resultClass="java.util.HashMap">
        <![CDATA[
        SELECT customerStatus,IFNULL(sum(customernum),0) customerNum
        FROM user_source_statistics
        ]]>
        <include refid="userSourceStatistics.queryPage1" />
        <![CDATA[
        group by customerStatus
        ]]>
        <dynamic prepend="ORDER BY">
            <isNotNull property="orderColumn">
                <![CDATA[
				$orderColumn$
				]]>
                <isNotNull property="orderMode">
                    $orderMode$
                </isNotNull>
            </isNotNull>
        </dynamic>
        <![CDATA[
		    LIMIT #paging.startRecord#, #paging.pageSize#
        ]]>
    </select>

    <select id="countTransCustomer" resultClass="int">
        select count(0) from (
        SELECT customerStatus,IFNULL(sum(customernum),0) customerNum FROM user_source_statistics
        <include refid="userSourceStatistics.queryPage1" />
        <![CDATA[
        group by customerStatus) a
        ]]>
    </select>

    <select id="transCustomerByWeek" resultClass="java.util.HashMap">
        <![CDATA[
		SELECT customerStatus,IFNULL(sum(customernum),0) customerNum
		FROM user_source_statistics
		]]>
        <include refid="userSourceStatistics.queryPage1" />
        <![CDATA[
		group by customerStatus
        ]]>
        <dynamic prepend="ORDER BY">
            <isNotNull property="orderColumn">
                <![CDATA[
				$orderColumn$
				]]>
                <isNotNull property="orderMode">
                    $orderMode$
                </isNotNull>
            </isNotNull>
        </dynamic>
        <![CDATA[
		    LIMIT #paging.startRecord#, #paging.pageSize#
        ]]>
    </select>

    <select id="countTransCustomerByWeek" resultClass="int">
        select count(0) from (
        SELECT customerStatus,IFNULL(sum(customernum),0) customerNum
        FROM user_source_statistics
        <include refid="userSourceStatistics.queryPage1" />
        <![CDATA[
        group by customerStatus) a
        ]]>
    </select>

    <select id="transCustomerByMonth" resultClass="java.util.HashMap">
        <![CDATA[
		SELECT customerStatus,IFNULL(sum(customernum),0) customerNum
		FROM user_source_statistics
		]]>
        <include refid="userSourceStatistics.queryPage1" />
        <![CDATA[
		group by customerStatus
        ]]>
        <dynamic prepend="ORDER BY">
            <isNotNull property="orderColumn">
                <![CDATA[
				$orderColumn$
				]]>
                <isNotNull property="orderMode">
                    $orderMode$
                </isNotNull>
            </isNotNull>
        </dynamic>
        <![CDATA[
		    LIMIT #paging.startRecord#, #paging.pageSize#
        ]]>
    </select>

    <select id="countTransCustomerByMonth" resultClass="int">
        select count(0) from (
        SELECT customerStatus,IFNULL(sum(customernum),0) customerNum
        FROM user_source_statistics
        <include refid="userSourceStatistics.queryPage1" />
        <![CDATA[
        group by customerStatus) a
        ]]>
    </select>

    <update id="updateProjectName">
        update user_source_statistics b inner join (select id,realname from user) a on a.id=b.projectid
        set b.projectName=a.realname
    </update>
    <update id="updateSourceName">
        update user_source_statistics b inner join (select id,source_name from customer_source) a on a.id=b.sourceid
        set b.sourcename=a.source_name
    </update>
    <update id="updateCityName">
        update user_source_statistics b inner join (select descripition,name from department) a on a.descripition=b.city
        set b.cityname=a.name
    </update>

    <delete id="deleteByDate">
        delete from user_source_statistics where createTime = #startDateStr#
    </delete>

</sqlMap>
