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

    <resultMap type="com.diaoyun.zion.chinafrica.entity.TbCfFeedbackRecordEntity" id="tbCfFeedbackRecordMap">
        <result property="recordId" column="record_id"/>
        <result property="userId" column="user_id"/>
        <result property="feedbackId" column="feedback_id"/>
        <result property="answer" column="answer"/>
        <result property="createTime" column="create_time"/>
    </resultMap>

	<select id="queryObject" resultType="com.diaoyun.zion.chinafrica.entity.TbCfFeedbackRecordEntity">
		select
			`record_id`,
			`user_id`,
			`feedback_id`,
			`answer`,
			`create_time`
		from tb_cf_feedback_record
		where record_id = #{id}
	</select>

	<select id="queryList" resultType="com.diaoyun.zion.chinafrica.entity.TbCfFeedbackRecordEntity">
		select
    		`record_id`,
    		`user_id`,
    		`feedback_id`,
    		`answer`,
    		`create_time`
		from tb_cf_feedback_record
		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 record_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_feedback_record
		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.TbCfFeedbackRecordEntity">
		insert into tb_cf_feedback_record(
			`record_id`,
			`user_id`,
			`feedback_id`,
			`answer`,
			`create_time`)
		values(
			#{recordId},
			#{userId},
			#{feedbackId},
			#{answer},
			#{createTime})
	</insert>
	 
	<update id="update" parameterType="com.diaoyun.zion.chinafrica.entity.TbCfFeedbackRecordEntity">
		update tb_cf_feedback_record 
		<set>
			<if test="userId != null">`user_id` = #{userId}, </if>
			<if test="feedbackId != null">`feedback_id` = #{feedbackId}, </if>
			<if test="answer != null">`answer` = #{answer}, </if>
			<if test="createTime != null">`create_time` = #{createTime}</if>
		</set>
		where record_id = #{recordId}
	</update>
	
	<delete id="delete">
		delete from tb_cf_feedback_record where record_id = #{value}
	</delete>
	
	<delete id="deleteBatch">
		delete from tb_cf_feedback_record where record_id in 
		<foreach item="recordId" collection="array" open="(" separator="," close=")">
			#{recordId}
		</foreach>
	</delete>

	<!--批量保存反馈-->
	<insert id="saveBatch" parameterType="com.diaoyun.zion.chinafrica.entity.TbCfFeedbackRecordEntity">
		insert into tb_cf_feedback_record(
			`record_id`,
			`user_id`,
			`feedback_id`,
			`answer`,
			`create_time`)
		values
		<foreach collection="list" item="item" index="index" separator=",">
			(
			#{item.recordId},
			#{item.userId},
			#{item.feedbackId},
			#{item.answer},
			#{item.createTime})
		</foreach>
	</insert>

</mapper>