<?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.platform.dao.FeedbackDao">

    <resultMap type="com.platform.entity.FeedbackEntity" id="feedbackMap">
        <result property="msgId" column="msg_id"/>
        <result property="userId" column="user_id"/>
        <result property="userName" column="user_name"/>
		<result property="nickName" column="nick_name"/>
        <result property="mobile" column="mobile"/>
        <result property="feedType" column="feed_Type"/>
        <result property="content" column="content"/>
        <result property="addTime" column="add_time"/>
        <result property="status" column="status"/>
    </resultMap>

	<select id="queryObject" resultType="com.platform.entity.FeedbackEntity">
		select
			`msg_id`,
			`user_id`,
			`user_name`,
			`mobile`,
			`feed_Type`,
			`content`,
			`add_time`,
			`status`
		from nideshop_feedback
		where msg_id = #{id}
	</select>

	<select id="queryList" resultType="com.platform.entity.FeedbackEntity">
		select
		a.`msg_id`,
		a.`user_id`,
		a.`user_name`,
		a.`mobile`,
		a.`feed_Type`,
		a.`content`,
		a.`add_time`,
		a.`status`,
		b.nickname as nick_name
		from nideshop_feedback a LEFT JOIN nideshop_user b on a.user_id = b.id
		WHERE 1=1
		<if test="name != null and name.trim() != ''">
			AND a.user_name LIKE concat('%',#{name},'%')
		</if>
        <choose>
            <when test="sidx != null and sidx.trim() != ''">
                order by ${sidx} ${order}
            </when>
			<otherwise>
                order by a.msg_id desc
			</otherwise>
        </choose>
		<if test="offset != null and limit != null">
			limit #{offset}, #{limit}
		</if>
	</select>
	
 	<select id="queryTotal" resultType="int">
		select count(*) from nideshop_feedback
		WHERE 1=1
        <if test="name != null and name.trim() != ''">
            AND user_name LIKE concat('%',#{name},'%')
        </if>
	</select>
	 
	<insert id="save" parameterType="com.platform.entity.FeedbackEntity" useGeneratedKeys="true" keyProperty="msgId">
		insert into nideshop_feedback(
			`user_id`,
			`user_name`,
			`mobile`,
			`feed_Type`,
			`content`,
			`add_time`,
			`status` )
		values(
			#{userId},
			#{userName},
			#{mobile},
			#{feedType},
			#{content},
			#{addTime},
			#{status})
	</insert>
	 
	<update id="update" parameterType="com.platform.entity.FeedbackEntity">
		update nideshop_feedback 
		<set>
			<if test="userId != null">`user_id` = #{userId}, </if>
			<if test="userName != null">`user_name` = #{userName}, </if>
			<if test="mobile != null">`mobile` = #{mobile}, </if>
			<if test="feedType != null">`feed_Type` = #{feedType}, </if>
			<if test="content != null">`content` = #{content}, </if>
			<if test="addTime != null">`add_time` = #{addTime}, </if>
			<if test="status != null">`status` = #{status}, </if>
		</set>
		where msg_id = #{msgId}
	</update>
	
	<delete id="delete">
		delete from nideshop_feedback where msg_id = #{value}
	</delete>
	
	<delete id="deleteBatch">
		delete from nideshop_feedback where msg_id in 
		<foreach item="msgId" collection="array" open="(" separator="," close=")">
			#{msgId}
		</foreach>
	</delete>

</mapper>