<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.ym.mec.cms.dal.dao.HelpCenterContentDao">
	<resultMap id="HelpCenterContent" type="com.ym.mec.cms.dal.entity.HelpCenterContent">
		<id column="id_" property="id" jdbcType="INTEGER" />
		<result column="title_" property="title" jdbcType="VARCHAR" />
		<result column="create_on_" property="createOn" jdbcType="TIMESTAMP" />
		<result column="modify_on_" property="modifyOn" jdbcType="TIMESTAMP" />
		<result column="status_" property="status" jdbcType="INTEGER" />
		<result column="order_" property="order" jdbcType="INTEGER" />
		<result column="catalog_id_" property="catalogId" jdbcType="INTEGER" />
		<association property="catalog" 
			javaType="com.ym.mec.cms.dal.entity.HelpCenterCatalog">
			<result column="catalog_id_" property="id" />
			<result column="name_" property="text" />
			<result column="parent_id_" property="parentId" />
		</association>
	</resultMap>

	<resultMap id="HelpCenterContentBlobs" type="com.ym.mec.cms.dal.entity.HelpCenterContent"
		extends="HelpCenterContent">
		<result column="content_" property="content" jdbcType="LONGVARCHAR" />
	</resultMap>
	<!-- 查询条件 -->
	<sql id="queryConditionUnion">
		<where>
			<if test="catalogIds != null">
				and content.catalog_id_ in (${catalogIds})
			</if>
			<if test="title!= null and title != ''">
				and content.title_ like '%' #{title} '%'
			</if>
			<if test="status!= null">
				and content.status_ = #{status}
			</if>
		</where>
	</sql>
	
	<sql id="Base_Column_List">
		id_, title_, catalog_id_, create_on_, modify_on_,status_,order_
	</sql>

	<sql id="Base_Column_List_union">
		content.id_, content.title_, content.catalog_id_,
		content.create_on_,
		content.modify_on_,content.status_,content.content_,content.order_,
		catalog.id_,
		catalog.name_, catalog.parent_id_
	</sql>

	<sql id="Blob_Column_List">
		content_
	</sql>

	<select id="get" resultMap="HelpCenterContentBlobs" parameterType="java.lang.Integer">
		select
		<include refid="Base_Column_List_union" />
		from help_center_content content left join help_center_catalog catalog on
		content.catalog_id_=catalog.id_
		where content.id_ =
		#{id,jdbcType=INTEGER}
	</select>

	<select id="queryPage" parameterType="map" resultMap="HelpCenterContentBlobs">
		select
		<include refid="Base_Column_List_union" />
		from help_center_content content left join help_center_catalog catalog on
		content.catalog_id_=catalog.id_
		<include refid="queryConditionUnion" />
		order by order_ asc
		<include refid="global.limit" />
	</select>

	<select id="findCount" parameterType="map" resultType="int">
		select count(*) from help_center_content content left join help_center_catalog catalog on
		content.catalog_id_=catalog.id_
		<include refid="queryConditionUnion" />
	</select>

	<delete id="delete" parameterType="java.lang.Integer">
		delete from help_center_content
		where id_ = #{id,jdbcType=INTEGER}
	</delete>
	
	<delete id="deleteContentByCatalog" parameterType="java.lang.Integer">
		delete from help_center_content
		where catalog_id_ = #{catalogId,jdbcType=INTEGER}
	</delete>

	<insert id="insert" parameterType="com.ym.mec.cms.dal.entity.HelpCenterContent">
		insert into help_center_content
		(id_, title_, catalog_id_,
		create_on_, modify_on_, content_,status_,order_
		)
		values
		(#{id,jdbcType=INTEGER}, #{title,jdbcType=VARCHAR},
		#{catalogId,jdbcType=INTEGER},
		#{createOn,jdbcType=TIMESTAMP},
		#{modifyOn,jdbcType=TIMESTAMP}, #{content,jdbcType=LONGVARCHAR},#{status,jdbcType=INTEGER},#{order,jdbcType=INTEGER}
		)
	</insert>

	<update id="update" parameterType="com.ym.mec.cms.dal.entity.HelpCenterContent">
		update help_center_content
		<set>
			<if test="title != null">
				title_ = #{title,jdbcType=VARCHAR},
			</if>
			<if test="catalogId != null">
				catalog_id_ = #{catalogId,jdbcType=INTEGER},
			</if>
			<if test="createOn != null">
				create_on_ = #{createOn,jdbcType=TIMESTAMP},
			</if>
			<if test="modifyOn != null">
				modify_on_ = #{modifyOn,jdbcType=TIMESTAMP},
			</if>
			<if test="content != null">
				content_ = #{content,jdbcType=LONGVARCHAR},
			</if>
			<if test="status != null">
				status_ = #{status,jdbcType=INTEGER},
			</if>
			<if test="order != null">
				order_ = #{order,jdbcType=INTEGER},
			</if>
		</set>
		where id_ = #{id,jdbcType=INTEGER}
	</update>

	<update id="updateBlobs" parameterType="com.ym.mec.cms.dal.entity.HelpCenterContent">
		update help_center_content
		set title_ = #{title,jdbcType=VARCHAR},
		catalog_id_ =
		#{catalogId,jdbcType=INTEGER},
		create_on_ =
		#{createOn,jdbcType=TIMESTAMP},
		modify_on_ =
		#{modifyOn,jdbcType=TIMESTAMP},
		content_ =
		#{content,jdbcType=LONGVARCHAR},
		status_= #{status,jdbcType=INTEGER},
		order_= #{order,jdbcType=INTEGER}
		where id_ = #{id,jdbcType=INTEGER}
	</update>

	<update id="updateByKey" parameterType="com.ym.mec.cms.dal.entity.HelpCenterContent">
		update help_center_content
		set title_ = #{title,jdbcType=VARCHAR},
		catalog_id_ =
		#{catalogId,jdbcType=INTEGER},
		create_on_ =
		#{createOn,jdbcType=TIMESTAMP},
		modify_on_ =
		#{modifyOn,jdbcType=TIMESTAMP},
		status_ = #{status,jdbcType=INTEGER},
		order_ = #{order,jdbcType=INTEGER},
		where id_ = #{id,jdbcType=INTEGER}
	</update>
	
	<update id="updateContentByCatalog" parameterType="map">
		update help_center_content set status_=#{status} where catalog_id_=#{catalogId}
	</update>
</mapper>