<?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.UserProjectRecommendEntity">
	<typeAlias alias="userProjectRecommendEntity"
			   type="com.house365.beans.entity.UserProjectRecommendEntity"/>
	<resultMap id="userProjectRecommend"
			   class="com.house365.beans.entity.UserProjectRecommendEntity">
		<result property="id" column="id"/>
		<result property="userId" column="user_id"/>
		<result property="userName" column="user_name"/>
		<result property="projectId" column="project_id"/>
		<result property="projectName" column="project_name"/>
		<result property="recommendReason" column="recommend_reason"/>
		<result property="createTime" column="create_time"/>
		<result property="updateTime" column="update_time"/>
		<result property="isDeleted" column="is_deleted"/>
		<result property="channel" column="channel"/>
		<result property="city" column="city"/>
	</resultMap>

	<!-- 用于select查询公用抽取的列 -->
	<sql id="userProjectRecommend.columns">
	    <![CDATA[
        id, user_id, user_name, project_id, project_name, recommend_reason, create_time, update_time, is_deleted, channel, city
	    ]]>
	</sql>

	<!-- 新增记录 -->
	<insert id="save" parameterClass="userProjectRecommendEntity">
		<![CDATA[
	        INSERT INTO user_project_recommend (
	        	id, 
	        	user_id, 
	        	user_name, 
	        	project_id, 
	        	project_name, 
	        	recommend_reason, 
	        	create_time, 
	        	update_time, 
	        	is_deleted, 
	        	channel, 
	        	city
	        ) VALUES (
	        	#id#, 
	        	#userId#, 
	        	#userName#, 
	        	#projectId#, 
	        	#projectName#, 
	        	#recommendReason#, 
	        	#createTime#, 
	        	#updateTime#, 
	        	#isDeleted#, 
	        	#channel#, 
	        	#city#
	        )
	    ]]>
		<selectKey resultClass="java.lang.Integer" type="post"
				   keyProperty="id">
			SELECT LAST_INSERT_ID()
		</selectKey>
	</insert>

	<!-- 通过ID修改 -->
	<update id="update" parameterClass="userProjectRecommendEntity">
	    <![CDATA[
	        UPDATE user_project_recommend SET
		        user_id = #userId#, 
		        user_name = #userName#, 
		        project_id = #projectId#, 
		        project_name = #projectName#, 
		        recommend_reason = #recommendReason#, 
		        create_time = #createTime#, 
		        update_time = #updateTime#, 
		        is_deleted = #isDeleted#, 
		        channel = #channel#, 
		        city = #city#
	        WHERE 
		        id = #id#
	    ]]>
	</update>

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

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

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

	<!-- 用于分页查询抽取的公共的条件 -->
	<sql id="userProjectRecommend.queryPage">
		<dynamic prepend="WHERE">
			<!-- 默认不开启实体作为条件 -->
			<!-- 
		    <isNotNull property="entity">
				<isNotEmpty prepend="AND" property="entity.id">
		            <![CDATA[
					id = #entity.id#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="entity.userId">
		            <![CDATA[
					user_id = #entity.userId#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="entity.userName">
		            <![CDATA[
					user_name = #entity.userName#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="entity.projectId">
		            <![CDATA[
					project_id = #entity.projectId#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="entity.projectName">
		            <![CDATA[
					project_name = #entity.projectName#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="entity.recommendReason">
		            <![CDATA[
					recommend_reason = #entity.recommendReason#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="entity.createTime">
		            <![CDATA[
					create_time = #entity.createTime#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="entity.updateTime">
		            <![CDATA[
					update_time = #entity.updateTime#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="entity.isDeleted">
		            <![CDATA[
					is_deleted = #entity.isDeleted#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="entity.channel">
		            <![CDATA[
					channel = #entity.channel#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="entity.city">
		            <![CDATA[
					city = #entity.city#
		            ]]>
				</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.userId">
					<![CDATA[
					user_id $searchFilters.userId.operation$ #searchFilters.userId.value#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="searchFilters.userName">
					<![CDATA[
					user_name $searchFilters.userName.operation$ #searchFilters.userName.value#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="searchFilters.projectId">
					<![CDATA[
					project_id $searchFilters.projectId.operation$ #searchFilters.projectId.value#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="searchFilters.projectName">
					<![CDATA[
					project_name $searchFilters.projectName.operation$ #searchFilters.projectName.value#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="searchFilters.recommendReason">
					<![CDATA[
					recommend_reason $searchFilters.recommendReason.operation$ #searchFilters.recommendReason.value#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="searchFilters.createTime">
					<![CDATA[
					create_time $searchFilters.createTime.operation$ #searchFilters.createTime.value#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="searchFilters.updateTime">
					<![CDATA[
					update_time $searchFilters.updateTime.operation$ #searchFilters.updateTime.value#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="searchFilters.isDeleted">
					<![CDATA[
					is_deleted $searchFilters.isDeleted.operation$ #searchFilters.isDeleted.value#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="searchFilters.channel">
					<![CDATA[
					channel $searchFilters.channel.operation$ #searchFilters.channel.value#
		            ]]>
				</isNotEmpty>
				<isNotEmpty prepend="AND" property="searchFilters.city">
					<![CDATA[
					city $searchFilters.city.operation$ #searchFilters.city.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_project_recommend
		<include refid="userProjectRecommend.queryPage"/>
	</select>

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

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

	<select id="queryByCondition" parameterClass="map" resultMap="userProjectRecommend">
		SELECT
		<include refid="userProjectRecommend.columns" />
		<![CDATA[
	        FROM user_project_recommend
	        WHERE
		        project_id = #projectId#
		     AND
		        channel = #channel#
		     AND
		        city = #city#
		    AND
		          is_deleted = 0
	    ]]>
	</select>

</sqlMap>