<?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.ProjectDynamicEntity">
    <typeAlias alias="projectDynamicEntity" type="com.house365.beans.entity.ProjectDynamicEntity" />
    <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>

    <resultMap id="baseAttachment"
               class="com.house365.beans.entity.BaseAttachment">
        <result property="id" column="id" />
        <result property="resourceId" column="resourceId" />
        <result property="resourceType" column="resourceType" />
        <result property="bizType" column="bizType" />
        <result property="name" column="name" />
        <result property="attachmentTypeId" column="attachmentTypeId" />
        <result property="suffix" column="suffix" />
        <result property="size" column="size" />
        <result property="remotePath" column="remotePath" />
        <result property="remoteServerUrlid" column="remoteServerUrlid" />
        <result property="remark" column="remark" />
        <result property="createTime" column="createTime"/>
    </resultMap>


    <!-- 用于分页查询抽取的公共的条件 -->
    <sql id="projectDynamic.queryPage">
        <dynamic prepend="WHERE">

            <isNotNull property="searchFilters">


                <isNotEmpty prepend="AND" property="searchFilters.projectName">
                    <![CDATA[
					pd.projectName $searchFilters.projectName.operation$ #searchFilters.projectName.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.createTime">
                    <![CDATA[
					pd.createTime $searchFilters.createTime.operation$ #searchFilters.createTime.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.createTimeStart">
                    <![CDATA[
					pd.createTime $searchFilters.createTimeStart.operation$ #searchFilters.createTimeStart.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.createTimeEnd">
                    <![CDATA[
					pd.createTime $searchFilters.createTimeEnd.operation$ #searchFilters.createTimeEnd.value#
		            ]]>
                </isNotEmpty>
                <isNotEmpty prepend="AND" property="searchFilters.dynamiccity">
                    <![CDATA[
                    p.city $searchFilters.dynamiccity.operation$ #searchFilters.dynamiccity.value#
                    ]]>
                </isNotEmpty>
            </isNotNull>
        </dynamic>

    </sql>



    <!-- 分页查询指定页记录 -->
    <select id="queryByPage" 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="projectDynamic.queryPage" />
        order by pd.createTime desc
        <![CDATA[
		    LIMIT #paging.startRecord#, #paging.pageSize#
        ]]>
    </select>

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

    </select>

    <!-- 通过resouceType查询 -->
    <select id="queryDynamicPicByResouceType" resultMap="baseAttachment">
        SELECT
              id, resourceId, resourceType,bizType, name, attachmentTypeId, suffix, size, remotePath, remoteServerUrlid, remark, createTime
        <![CDATA[
	        FROM base_attachment
	        WHERE
		        resourceType = #channel# order by resourceId desc
	    ]]>
    </select>

</sqlMap>
