<?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.project.production.mapper.TMonthlyQualityCommentMapper">
    
    <resultMap type="TMonthlyQualityComment" id="TMonthlyQualityCommentResult">
        <result property="id"    column="id"    />
        <result property="commentType"    column="comment_type"    />
        <result property="qualityComment"    column="quality_comment"    />
        <result property="deptId"    column="dept_id"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createBy"    column="create_by"    />
        <result property="title"    column="title"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="startDate"    column="start_date"    />
        <result property="updateTime"    column="update_time"    />
        <result property="endDate"    column="end_date"    />
        <result property="deptName" column="dept_name" />
    </resultMap>

    <sql id="selectTMonthlyQualityCommentVo">
        select d.id, d.comment_type, d.quality_comment, d.dept_id, d.del_flag, d.create_by, d.title, d.create_time, d.update_by, d.start_date, d.update_time, d.end_date from t_monthly_quality_comment d
      left join sys_dept s on s.dept_id = d.dept_id
    </sql>

    <select id="selectTMonthlyQualityCommentList" parameterType="TMonthlyQualityComment" resultMap="TMonthlyQualityCommentResult">
        <include refid="selectTMonthlyQualityCommentVo"/>
        <where>  
            <if test="commentType != null  and commentType != ''"> and comment_type = #{commentType}</if>
            <if test="qualityComment != null  and qualityComment != ''"> and quality_comment = #{qualityComment}</if>
            <if test="deptId != null "> and dept_id = #{deptId}</if>
            <if test="title != null  and title != ''"> and title = #{title}</if>
            <if test="startDate != null "> and start_date = #{startDate}</if>
            <if test="endDate != null "> and end_date = #{endDate}</if>
            and d.del_flag = 0
        </where>
        <!-- 数据范围过滤 -->
        ${params.dataScope}
    </select>

    <select id="selectTMonthlyQualityCommentByTypeAndDate" parameterType="TMonthlyQualityComment" resultMap="TMonthlyQualityCommentResult">
        <include refid="selectTMonthlyQualityCommentVo"/>
        where d.comment_type = #{commentType} and d.start_date = #{startDate} and d.end_date = #{endDate} and d.del_flag = 0
    </select>
    
    <select id="selectTMonthlyQualityCommentById" parameterType="Long" resultMap="TMonthlyQualityCommentResult">
        <include refid="selectTMonthlyQualityCommentVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertTMonthlyQualityComment" parameterType="TMonthlyQualityComment">
        <selectKey keyProperty="id" resultType="long" order="BEFORE">
            SELECT seq_t_monthly_quality_comment.NEXTVAL as id FROM DUAL
        </selectKey>
        insert into t_monthly_quality_comment
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="commentType != null">comment_type,</if>
            <if test="qualityComment != null">quality_comment,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="title != null">title,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="startDate != null">start_date,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="endDate != null">end_date,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="commentType != null">#{commentType},</if>
            <if test="qualityComment != null">#{qualityComment},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="title != null">#{title},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="startDate != null">#{startDate},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="endDate != null">#{endDate},</if>
         </trim>
    </insert>

    <update id="updateTMonthlyQualityComment" parameterType="TMonthlyQualityComment">
        update t_monthly_quality_comment
        <trim prefix="SET" suffixOverrides=",">
            <if test="commentType != null">comment_type = #{commentType},</if>
            <if test="qualityComment != null">quality_comment = #{qualityComment},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="title != null">title = #{title},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="startDate != null">start_date = #{startDate},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="endDate != null">end_date = #{endDate},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="deleteTMonthlyQualityCommentById" parameterType="Long">
        update t_monthly_quality_comment set del_flag = 2 where id = #{id}
    </update>

    <update id="deleteTMonthlyQualityCommentByIds" parameterType="String">
        update t_monthly_quality_comment set del_flag = 2 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
    
</mapper>