<?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.TbCfCommentsReplyDao">

    <resultMap type="com.diaoyun.zion.chinafrica.entity.TbCfCommentsReplyEntity" id="tbCfCommentsReplyMap">
        <result property="commentsId" column="comments_id"/>
        <result property="commentId" column="comment_id"/>
        <result property="commentFromId" column="comment_from_id"/>
        <result property="commentFromName" column="comment_from_name"/>
        <result property="commentFromAvatar" column="comment_from_avatar"/>
        <result property="commentToId" column="comment_to_id"/>
        <result property="commentToName" column="comment_to_name"/>
        <result property="commentToAvatar" column="comment_to_avatar"/>
        <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.TbCfCommentsReplyEntity">
		select
			`comments_id`,
			`comment_id`,
			`comment_from_id`,
			`comment_from_name`,
			`comment_from_avatar`,
			`comment_to_id`,
			`comment_to_name`,
			`comment_to_avatar`,
			`content`,
			`create_time`,
			`update_time`
		from tb_cf_comments_reply
		where comments_id = #{id}
	</select>

	<select id="queryList" resultType="com.diaoyun.zion.chinafrica.entity.TbCfCommentsReplyEntity">
		select
    		`comments_id`,
    		`comment_id`,
    		`comment_from_id`,
    		`comment_from_name`,
    		`comment_from_avatar`,
    		`comment_to_id`,
    		`comment_to_name`,
    		`comment_to_avatar`,
    		`content`,
    		`create_time`,
    		`update_time`
		from tb_cf_comments_reply
		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 comments_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_reply
		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.TbCfCommentsReplyEntity">
		insert into tb_cf_comments_reply(
			`comments_id`,
			`comment_id`,
			`comment_from_id`,
			`comment_from_name`,
			`comment_from_avatar`,
			`comment_to_id`,
			`comment_to_name`,
			`comment_to_avatar`,
			`content`,
			`create_time`,
			`update_time`)
		values(
			#{commentsId},
			#{commentId},
			#{commentFromId},
			#{commentFromName},
			#{commentFromAvatar},
			#{commentToId},
			#{commentToName},
			#{commentToAvatar},
			#{content},
			#{createTime},
			#{updateTime})
	</insert>
	 
	<update id="update" parameterType="com.diaoyun.zion.chinafrica.entity.TbCfCommentsReplyEntity">
		update tb_cf_comments_reply 
		<set>
			<if test="commentId != null">`comment_id` = #{commentId}, </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="commentToId != null">`comment_to_id` = #{commentToId}, </if>
			<if test="commentToName != null">`comment_to_name` = #{commentToName}, </if>
			<if test="commentToAvatar != null">`comment_to_avatar` = #{commentToAvatar}, </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 comments_id = #{commentsId}
	</update>
	
	<delete id="delete">
		delete from tb_cf_comments_reply where comments_id = #{value}
	</delete>
	
	<delete id="deleteBatch">
		delete from tb_cf_comments_reply where comments_id in 
		<foreach item="commentsId" collection="array" open="(" separator="," close=")">
			#{commentsId}
		</foreach>
	</delete>

</mapper>