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

    <resultMap type="com.diaoyun.zion.chinafrica.entity.TbCfFeedbackEntity" id="tbCfFeedbackMap">
        <result property="feedbackId" column="feedback_id"/>
        <result property="question" column="question"/>
        <result property="enableFlag" column="enable_flag"/>
        <result property="createTime" column="create_time"/>
        <result property="questionType" column="question_type"/>
        <result property="sort" column="sort"/>
    </resultMap>

	<select id="queryObject" resultType="com.diaoyun.zion.chinafrica.entity.TbCfFeedbackEntity">
		select
			`feedback_id`,
			`question`,
			`enable_flag`,
			`create_time`,
			`question_type`,
			`sort`
		from tb_cf_feedback
		where feedback_id = #{id}
	</select>

	<select id="queryList" resultType="com.diaoyun.zion.chinafrica.entity.TbCfFeedbackEntity">
		select
    		`feedback_id`,
    		`question`,
    		`enable_flag`,
    		`create_time`,
    		`question_type`,
    		`sort`
		from tb_cf_feedback
		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 feedback_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
		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.TbCfFeedbackEntity">
		insert into tb_cf_feedback(
			`feedback_id`,
			`question`,
			`enable_flag`,
			`create_time`,
			`question_type`,
			`sort`)
		values(
			#{feedbackId},
			#{question},
			#{enableFlag},
			#{createTime},
			#{questionType},
			#{sort})
	</insert>
	 
	<update id="update" parameterType="com.diaoyun.zion.chinafrica.entity.TbCfFeedbackEntity">
		update tb_cf_feedback 
		<set>
			<if test="question != null">`question` = #{question}, </if>
			<if test="enableFlag != null">`enable_flag` = #{enableFlag}, </if>
			<if test="createTime != null">`create_time` = #{createTime}, </if>
			<if test="questionType != null">`question_type` = #{questionType}, </if>
			<if test="sort != null">`sort` = #{sort}</if>
		</set>
		where feedback_id = #{feedbackId}
	</update>
	
	<delete id="delete">
		delete from tb_cf_feedback where feedback_id = #{value}
	</delete>
	
	<delete id="deleteBatch">
		delete from tb_cf_feedback where feedback_id in 
		<foreach item="feedbackId" collection="array" open="(" separator="," close=")">
			#{feedbackId}
		</foreach>
	</delete>

	<!--获取有效的反馈问题-->
	<select id="getFeedbackList" resultType="com.diaoyun.zion.chinafrica.entity.TbCfFeedbackEntity">
		select
    		`feedback_id`,
    		`question`,
    		`enable_flag`,
    		`create_time`,
    		`question_type`,
    		`sort`
		from tb_cf_feedback
		WHERE enable_flag=1 order by sort desc
	</select>

</mapper>