<?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.ruoyi.system.mapper.FeedbackMapper">
    
    <resultMap type="Feedback" id="FeedbackResult">
        <result property="feedbackId"    column="feedback_id"    />
        <result property="danganId"    column="dangan_id"    />
        <result property="feedbackTheme"    column="feedback_theme"    />
        <result property="content"    column="content"    />
        <result property="userId"    column="user_id"    />
        <result property="userName"    column="user_name"    />
        <result property="feedbackTime"    column="feedback_time"    />
        <result property="status"    column="status"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="remark"    column="remark"    />
        <result property="danganName"    column="dangan_name"    />
        <result property="deptName"    column="dept_name"    />
    </resultMap>

    <sql id="selectFeedbackVo">
         select f.feedback_id, f.dangan_id, f.feedback_theme, f.content, f.user_id,u.user_name, f.feedback_time, f.status, f.create_by, f.create_time, f.update_by, f.update_time, f.remark, da.dangan_name,d.dept_name
        from sys_feedback f
        left join sys_dangan da on da.dangan_id=f.dangan_id
        left join sys_user u on u.user_id = f.user_id
        left join sys_dept d on d.dept_id = u.dept_id
    </sql>

    <select id="selectFeedbackList" parameterType="Feedback" resultMap="FeedbackResult">
        <include refid="selectFeedbackVo"/>
        <where>  
            <if test="danganId != null "> and f.dangan_id = #{danganId}</if>
            <if test="feedbackTheme != null  and feedbackTheme != ''"> and f.feedback_theme = #{feedbackTheme}</if>
            <if test="content != null  and content != ''"> and f.content = #{content}</if>
            <if test="userName != null  and userName != ''"> and u.user_name like concat('%', #{userName}, '%')</if>
            <if test="feedbackTime != null "> and f.feedback_time = #{feedbackTime}</if>
            <if test="status != null  and status != ''"> and f.status = #{status}</if>
            <if test="params.beginTime != null and params.beginTime != ''"><!-- 开始时间检索 -->
                AND to_date(f.feedback_time,'YY-MM-DD') &gt;= to_date(#{params.beginTime},'YY-MM-DD')
            </if>
            <if test="params.endTime != null and params.endTime != ''"><!-- 结束时间检索 -->
                AND to_date(f.feedback_time,'YY-MM-DD') &lt;= to_date(#{params.endTime},'YY-MM-DD')
            </if>
        </where>
    </select>
    
    <select id="selectFeedbackById" parameterType="Long" resultMap="FeedbackResult">
        <include refid="selectFeedbackVo"/>
        where f.feedback_id = #{feedbackId}
    </select>
        
    <insert id="insertFeedback" parameterType="Feedback" useGeneratedKeys="true" keyProperty="feedbackId">
        insert into sys_feedback
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="danganId != null">dangan_id,</if>
            <if test="feedbackTheme != null">feedback_theme,</if>
            <if test="content != null">content,</if>
            <if test="userId != null">user_id,</if>
            <if test="userName != null">user_name,</if>
            <if test="feedbackTime != null">feedback_time,</if>
            <if test="status != null">status,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="danganId != null">#{danganId},</if>
            <if test="feedbackTheme != null">#{feedbackTheme},</if>
            <if test="content != null">#{content},</if>
            <if test="userId != null">#{userId},</if>
            <if test="userName != null">#{userName},</if>
            <if test="feedbackTime != null">#{feedbackTime},</if>
            <if test="status != null">#{status},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
         </trim>
    </insert>

    <update id="updateFeedback" parameterType="Feedback">
        update sys_feedback
        <trim prefix="SET" suffixOverrides=",">
            <if test="danganId != null">dangan_id = #{danganId},</if>
            <if test="feedbackTheme != null">feedback_theme = #{feedbackTheme},</if>
            <if test="content != null">content = #{content},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="userName != null">user_name = #{userName},</if>
            <if test="feedbackTime != null">feedback_time = #{feedbackTime},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="remark != null">remark = #{remark},</if>
        </trim>
        where feedback_id = #{feedbackId}
    </update>

    <delete id="deleteFeedbackById" parameterType="Long">
        delete from sys_feedback where feedback_id = #{feedbackId}
    </delete>

    <delete id="deleteFeedbackByIds" parameterType="String">
        delete from sys_feedback where feedback_id in 
        <foreach item="feedbackId" collection="array" open="(" separator="," close=")">
            #{feedbackId}
        </foreach>
    </delete>

</mapper>