<?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.diaoyun.zion.chinafrica.dao.TbCfCommentsInfoDao">

    <resultMap type="com.diaoyun.zion.chinafrica.entity.TbCfCommentsInfoEntity" id="tbCfCommentsInfoMap">
        <result property="commentId" column="comment_id"/>
        <result property="commentOwnerId" column="comment_owner_id"/>
        <result property="commentFromId" column="comment_from_id"/>  
        <result property="commentFromName" column="comment_from_name"/>
        <result property="commentFromAvatar" column="comment_from_avatar"/>
        <result property="likeNum" column="like_num"/>
        <result property="content" column="content"/>
        <result property="createTime" column="create_time"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

	<select id="queryObject" resultType="com.diaoyun.zion.chinafrica.entity.TbCfCommentsInfoEntity">
		select
			`comment_id`,
			`comment_owner_id`,
			`comment_from_id`,
			`comment_from_name`,
			`comment_from_avatar`,
			`like_num`,
			`content`,
			`create_time`,
			`update_time`
		from tb_cf_comments_info
		where comment_id = #{id}
	</select>

	<select id="queryList" resultType="com.diaoyun.zion.chinafrica.entity.TbCfCommentsInfoEntity">
		select
    		`comment_id`,
    		`comment_owner_id`,
    		`comment_from_id`,
    		`comment_from_name`,
    		`comment_from_avatar`,
    		`like_num`,
    		`content`,
    		`create_time`,
    		`update_time`
		from tb_cf_comments_info
		WHERE 1=1
		<if test="name != null and name.trim() != ''">
			AND name LIKE concat('%',#{name},'%')
		</if>
        <choose>
            <when test="sidx != null and sidx.trim() != ''">
                order by ${sidx} ${order}
            </when>
			<otherwise>
                order by comment_id desc
			</otherwise>
        </choose>
		<if test="offset != null and limit != null">
			limit #{offset}, #{limit}
		</if>
	</select>
	
 	<select id="queryTotal" resultType="int">
		select count(*) from tb_cf_comments_info
		WHERE 1=1
        <if test="name != null and name.trim() != ''">
            AND name LIKE concat('%',#{name},'%')
        </if>
	</select>
	 
	<insert id="save" parameterType="com.diaoyun.zion.chinafrica.entity.TbCfCommentsInfoEntity">
		insert into tb_cf_comments_info(
			`comment_id`,
			`comment_owner_id`,
			`comment_from_id`,
			`comment_from_name`,
			`comment_from_avatar`,
			`like_num`,
			`content`,
			`create_time`,
			`update_time`)
		values(
			#{commentId},
			#{commentOwnerId},
			#{commentFromId},
			#{commentFromName},
			#{commentFromAvatar},
			#{likeNum},
			#{content},
			#{createTime},
			#{updateTime})
	</insert>
	 
	<update id="update" parameterType="com.diaoyun.zion.chinafrica.entity.TbCfCommentsInfoEntity">
		update tb_cf_comments_info 
		<set>
			<if test="commentOwnerId != null">`comment_owner_id` = #{commentOwnerId}, </if>
			<if test="commentFromId != null">`comment_from_id` = #{commentFromId}, </if>
			<if test="commentFromName != null">`comment_from_name` = #{commentFromName}, </if>
			<if test="commentFromAvatar != null">`comment_from_avatar` = #{commentFromAvatar}, </if>
			<if test="likeNum != null">`like_num` = #{likeNum}, </if>
			<if test="content != null">`content` = #{content}, </if>
			<if test="createTime != null">`create_time` = #{createTime}, </if>
			<if test="updateTime != null">`update_time` = #{updateTime}</if>
		</set>
		where comment_id = #{commentId}
	</update>
	
	<delete id="delete">
		delete from tb_cf_comments_info where comment_id = #{value}
	</delete>
	
	<delete id="deleteBatch">
		delete from tb_cf_comments_info where comment_id in 
		<foreach item="commentId" collection="array" open="(" separator="," close=")">
			#{commentId}
		</foreach>
	</delete>

</mapper>