<?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.ProjectEntity">
    <typeAlias alias="projectEntity" type="com.house365.beans.entity.ProjectEntity" />
    <typeAlias alias="projectDynamicEntity" type="com.house365.beans.entity.ProjectDynamicEntity" />
    <resultMap id="project" class="com.house365.beans.entity.ProjectEntity">
        <result property="id" column="id" />
        <result property="contractCode" column="contractCode" />
        <result property="projectCode" column="projectCode" />
        <result property="projectName" column="projectName" />
        <result property="buildingId" column="buildingId" />
        <result property="buildingName" column="buildingName" />
        <result property="status" column="status" />
        <result property="showStatus" column="showStatus" />
        <result property="manager" column="manager" />
        <result property="type" column="type" />
        <result property="business" column="business" />
        <result property="kfs" column="kfs" />
        <result property="city" column="city" />
        <result property="cityName" column="cityName" />
        <result property="district" column="district" />
        <result property="address" column="address" />
        <result property="startTime" column="startTime" />
        <result property="source" column="source" />
        <result property="jitInfo" column="jitInfo" />
        <result property="hireMoney" column="hireMoney" />
        <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" />
        <result property="shorttel" column="shorttel" />
    </resultMap>

    <resultMap id="projectDynamic" class="com.house365.beans.entity.ProjectDynamicEntity">
        <result property="id" column="id" />
        <result property="projectId" column="projectId" />
        <result property="projectName" column="projectName" />
        <result property="createUserid" column="createUserid" />
        <result property="createUsername" column="createUsername" />
        <result property="createTime" column="createTime" />
        <result property="dynamicId" column="dynamicId" />
        <result property="dynamicContent" column="dynamicContent" />
    </resultMap>

    <!-- 用于select查询公用抽取的列 -->
    <sql id="project.columns">
        <![CDATA[
        id, contractCode, projectCode, projectName, buildingId, buildingName, status,showStatus, manager, type,
        business, kfs,city,cityName,district, address, startTime, source, jitInfo, hireMoney, createUserid,
        createUsername, createTime, createIp, updateUserid, updateUsername, updateTime, updateIp, shorttel
	    ]]>
    </sql>

    <!-- 新增记录 -->
    <insert id="save" parameterClass="projectEntity">
        <![CDATA[
	        INSERT INTO project (
	        	id,
	        	contractCode,
	        	projectCode,
	        	projectName,
	        	buildingId,
	        	buildingName,
	        	status,
	        	showStatus,
	        	manager,
	        	type,
	        	business,
	        	kfs,
	        	city,
	        	cityName,
	        	district,
	        	address,
	        	startTime,
	        	source,
	        	jitInfo,
	        	hireMoney,
	        	createUserid,
	        	createUsername,
	        	createTime,
	        	createIp,
	        	updateUserid,
	        	updateUsername,
	        	updateTime,
	        	updateIp,
	        	shorttel
	        ) VALUES (
	        	#id#,
	        	#contractCode#,
	        	#projectCode#,
	        	#projectName#,
	        	#buildingId#,
	        	#buildingName#,
	        	#status#,
	        	#showStatus#,
	        	#manager#,
	        	#type#,
	        	#business#,
	        	#kfs#,
	        	#city#,
	        	#cityName#,
	        	#district#,
	        	#address#,
	        	#startTime#,
	        	#source#,
	        	#jitInfo#,
	        	#hireMoney#,
	        	#createUserid#,
	        	#createUsername#,
	        	#createTime#,
	        	#createIp#,
	        	#updateUserid#,
	        	#updateUsername#,
	        	#updateTime#,
	        	#updateIp#,
	        	#shorttel#
	        )
	    ]]>
        <selectKey resultClass="java.lang.Integer" type="post" keyProperty="id">
            SELECT LAST_INSERT_ID()
        </selectKey>
    </insert>

    <update id="updateHotline">
        UPDATE project set updateIp=#shorttel# where buildingId=#buildingId#
    </update>

    <!-- 通过ID修改 -->
    <update id="update" parameterClass="projectEntity">
        UPDATE project
        <dynamic prepend="SET">
            <isNotEmpty prepend="," property="contractCode">
                <![CDATA[
					contractCode = #contractCode#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="projectCode">
                <![CDATA[
					projectCode = #projectCode#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="projectName">
                <![CDATA[
					projectName = #projectName#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="buildingId">
                <![CDATA[
					buildingId = #buildingId#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="buildingName">
                <![CDATA[
					buildingName = #buildingName#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="status">
                <![CDATA[
					status = #status#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="showStatus">
                <![CDATA[
					showStatus = #showStatus#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="manager">
                <![CDATA[
					manager = #manager#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="type">
                <![CDATA[
					type = #type#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="business">
                <![CDATA[
					business = #business#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="kfs">
                <![CDATA[
					kfs = #kfs#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="city">
                <![CDATA[
					city = #city#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="cityName">
                <![CDATA[
					cityName = #cityName#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="district">
                <![CDATA[
					district = #district#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="address">
                <![CDATA[
					address = #address#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="startTime">
                <![CDATA[
					startTime = #startTime#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="source">
                <![CDATA[
					source = #source#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="jitInfo">
                <![CDATA[
					jitInfo = #jitInfo#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="hireMoney">
                <![CDATA[
					hireMoney = #hireMoney#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="createUserid">
                <![CDATA[
					createUserid = #createUserid#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="createUsername">
                <![CDATA[
					createUsername = #createUsername#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="createTime">
                <![CDATA[
					createTime = #createTime#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="createIp">
                <![CDATA[
					createIp = #createIp#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="updateUserid">
                <![CDATA[
					updateUserid = #updateUserid#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="updateUsername">
                <![CDATA[
					updateUsername = #updateUsername#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="updateTime">
                <![CDATA[
					updateTime = #updateTime#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="updateIp">
                <![CDATA[
					updateIp = #updateIp#
		            ]]>
            </isNotEmpty>
            <isNotEmpty prepend="," property="shorttel">
                <![CDATA[
					shorttel = #shorttel#
		            ]]>
            </isNotEmpty>
        </dynamic>
        WHERE
        id = #id#
    </update>

    <update id="updateSaler">
        UPDATE project_saler a,project b set a.channel = b.type where a.projectId = b.buildingId and a.projectName = b.buildingName and a.channel != b.type
    </update>

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

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

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

    <!-- 用于分页查询抽取的公共的条件 -->
    <sql id="project.queryPage">
        <dynamic prepend="WHERE">
            <!-- 默认不开启实体作为条件 -->
            <!--
            <isNotNull property="entity">
                <isNotEmpty prepend="AND" property="entity.id">
                    <![CDATA[
                    id = #entity.id#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="entity.contractCode">
                    <![CDATA[
                    contractCode = #entity.contractCode#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="entity.projectCode">
                    <![CDATA[
                    projectCode = #entity.projectCode#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="entity.projectName">
                    <![CDATA[
                    projectName = #entity.projectName#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="entity.buildingId">
                    <![CDATA[
                    buildingId = #entity.buildingId#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="entity.buildingName">
                    <![CDATA[
                    buildingName = #entity.buildingName#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="entity.status">
                    <![CDATA[
                    status = #entity.status#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="entity.manager">
                    <![CDATA[
                    manager = #entity.manager#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="entity.type">
                    <![CDATA[
                    type = #entity.type#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="entity.kfs">
                    <![CDATA[
                    kfs = #entity.kfs#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="entity.address">
                    <![CDATA[
                    address = #entity.address#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="entity.startTime">
                    <![CDATA[
                    startTime = #entity.startTime#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="entity.source">
                    <![CDATA[
                    source = #entity.source#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="entity.jitInfo">
                    <![CDATA[
                    jitInfo = #entity.jitInfo#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="entity.hireMoney">
                    <![CDATA[
                    hireMoney = #entity.hireMoney#
                    ]]>
                </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.contractCode">
                    <![CDATA[
					contractCode $searchFilters.contractCode.operation$ #searchFilters.contractCode.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.projectCode">
                    <![CDATA[
					projectCode $searchFilters.projectCode.operation$ #searchFilters.projectCode.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.projectName">
                    <![CDATA[
					projectName $searchFilters.projectName.operation$ #searchFilters.projectName.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.buildingId">
                    <![CDATA[
					buildingId $searchFilters.buildingId.operation$ #searchFilters.buildingId.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.buildingName">
                    <![CDATA[
					buildingName $searchFilters.buildingName.operation$ #searchFilters.buildingName.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.status">
                    <![CDATA[
					status $searchFilters.status.operation$ #searchFilters.status.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.showStatus">
                    <![CDATA[
					showStatus $searchFilters.showStatus.operation$ #searchFilters.showStatus.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.manager">
                    <![CDATA[
					manager $searchFilters.manager.operation$ #searchFilters.manager.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.type">
                    <![CDATA[
					type $searchFilters.type.operation$ #searchFilters.type.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.business">
                    <![CDATA[
					business $searchFilters.business.operation$ #searchFilters.business.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.kfs">
                    <![CDATA[
					kfs $searchFilters.kfs.operation$ #searchFilters.kfs.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.district">
                    <![CDATA[
					district $searchFilters.district.operation$ #searchFilters.district.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.address">
                    <![CDATA[
					address $searchFilters.address.operation$ #searchFilters.address.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.startTime">
                    <![CDATA[
					startTime $searchFilters.startTime.operation$ #searchFilters.startTime.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.source">
                    <![CDATA[
					source $searchFilters.source.operation$ #searchFilters.source.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.jitInfo">
                    <![CDATA[
					jitInfo $searchFilters.jitInfo.operation$ #searchFilters.jitInfo.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.hireMoney">
                    <![CDATA[
					hireMoney $searchFilters.hireMoney.operation$ #searchFilters.hireMoney.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.createTimeStart">
                    <![CDATA[
					createTime $searchFilters.createTimeStart.operation$ #searchFilters.createTimeStart.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.createTimeEnd">
                    <![CDATA[
					createTime $searchFilters.createTimeEnd.operation$ #searchFilters.createTimeEnd.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.filterExsit">
                    <![CDATA[
					id not in (select distinct project_id from customer_project where customer_id=$searchFilters.filterExsit.value$)
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.proName">
                    <![CDATA[
					projectName like '%' #searchFilters.proName.value# '%'
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.dynamiccity">
                    <![CDATA[
                    p.city $searchFilters.dynamiccity.operation$ #searchFilters.dynamiccity.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 project
        <include refid="project.queryPage" />
    </select>

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

    <select id="getByContractCode" resultMap="project">
        SELECT
        <include refid="project.columns" />
        <![CDATA[
	        FROM project WHERE contractCode = #contractCode#
	    ]]>
    </select>

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

    <!-- <select id="queryByPage" resultClass="projectEntity">
        select
        p.id, p.contractCode, p.projectCode, p.projectName, p.buildingId, p.buildingName, p.status, p.manager, p.type,p.business, p.kfs,p.city,p.cityName,p.district,
        p.address, p.startTime,   p.createUsername, p.createTime,p.projectName,u.name as userName,u.id as userId
        from project p join project_user pu on p.id = pu.projectId join user u on pu.userId = u.id
        <dynamic prepend="WHERE">
            <isNotNull property="searchFilters">
                <isNotEmpty prepend="AND" property="searchFilters.userId">
                    <![CDATA[
                    u.id $searchFilters.userId.operation$ #searchFilters.userId.value#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.projectName">
                    <![CDATA[
                    p.projectName $searchFilters.projectName.operation$ #searchFilters.projectName.value#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.status">
                    <![CDATA[
                    p.status $searchFilters.status.operation$ #searchFilters.status.value#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.business">
                    <![CDATA[
                    p.business $searchFilters.business.operation$ #searchFilters.business.value#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.city">
                    <![CDATA[
                    p.city $searchFilters.city.operation$ #searchFilters.city.value#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.cityName">
                    <![CDATA[
                    p.cityName $searchFilters.cityName.operation$ #searchFilters.cityName.value#
                    ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.createTime">
                    <![CDATA[
                    p.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>
        <![CDATA[
            LIMIT #paging.startRecord#, #paging.pageSize#
        ]]>
    </select> -->
    <select id="queryCustomerProject" resultMap="project" parameterClass="java.lang.Integer">
        <![CDATA[
		    SELECT distinct * FROM project where id in (select project_id from customer_project where customer_id=$customerId$ order by create_time desc)
	    ]]>
    </select>

    <select id="getDynamicById" parameterClass="com.house365.beans.entity.ProjectDynamicEntity" resultMap="projectDynamic">
        <![CDATA[
            select id,projectId,projectName,createUserid,createUsername,createTime,dynamicId,dynamicContent
            from project_dynamic
            where projectId =#projectId#
            ORDER BY id desc
            limit #pageNo#, #pageSize#
	    ]]>
    </select>

    <insert id="saveDynamic" parameterClass="com.house365.beans.entity.ProjectDynamicEntity">
        <![CDATA[
	        INSERT INTO project_dynamic (
	        	id,
	        	projectId,
	        	createUserid,
	        	createUsername,
	        	createTime,
	        	dynamicId,
	        	dynamicContent,
	        	projectName
	        ) VALUES (
	        	#id#,
	        	#projectId#,
	        	#createUserid#,
	        	#createUsername#,
	        	#createTime#,
	        	#dynamicId#,
	        	#dynamicContent#,
	        	#projectName#
	        )
	    ]]>
        <selectKey resultClass="java.lang.Integer" type="post" keyProperty="id">
            SELECT LAST_INSERT_ID()
        </selectKey>
    </insert>

    <!-- 分页查询指定页记录 -->
    <select id="getDynamicList" resultMap="projectDynamic">
        SELECT
        pd.id,pd.projectId,pd.projectName,pd.createUserid,pd.createUsername,pd.createTime,pd.dynamicId,pd.dynamicContent
        <![CDATA[
	        FROM project_dynamic pd inner join project p on pd.projectId=p.id
	    ]]>
        <include refid="project.queryPage" />
        <![CDATA[
		    LIMIT #paging.startRecord#, #paging.pageSize#
        ]]>
    </select>

    <select id="getDynamicList_count" resultClass="int">
        SELECT count(*) FROM project_dynamic pd inner join project p on pd.projectId=p.id
        <include refid="project.queryPage" />

    </select>


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

    <select id="queryByConditions" parameterClass="map" resultMap="project">
        SELECT
        <include refid="project.columns" />
        <![CDATA[
	        FROM project
	        WHERE
		        id = #projectId#
	    ]]>
    </select>

</sqlMap>
