<?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.WorkReviewMapper">
    
    <resultMap type="WorkReview" id="WorkReviewResult">
        <result property="reviewId"    column="review_id"    />
        <result property="workId"    column="work_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="reviewerId"    column="reviewer_id"    />
        <result property="reviewerName"    column="reviewer_name"    />
        <result property="workStatus"    column="work_status"    />
        <result property="detail"    column="detail"    />
        <result property="deleteFlag"    column="delete_flag"    />
    </resultMap>

    <sql id="selectWorkReviewVo">
        select review_id, work_id, create_time, reviewer_id, reviewer_name, work_status, detail, delete_flag from work_review
    </sql>

    <select id="selectWorkReviewList" parameterType="WorkReview" resultMap="WorkReviewResult">
        <include refid="selectWorkReviewVo"/>
        <where>  
            <if test="workId != null "> and work_id = #{workId}</if>
            <if test="reviewerId != null "> and reviewer_id = #{reviewerId}</if>
            <if test="reviewerName != null  and reviewerName != ''"> and reviewer_name like concat('%', #{reviewerName}, '%')</if>
            <if test="workStatus != null  and workStatus != ''"> and work_status = #{workStatus}</if>
            <if test="detail != null  and detail != ''"> and detail = #{detail}</if>
            <if test="deleteFlag != null  and deleteFlag != ''"> and delete_flag = #{deleteFlag}</if>
--              and delete_flag = "0"
        </where>
    </select>
    
    <select id="selectWorkReviewByReviewId" parameterType="Long" resultMap="WorkReviewResult">
        <include refid="selectWorkReviewVo"/>
        where review_id = #{reviewId}
    </select>
        
    <insert id="insertWorkReview" parameterType="WorkReview" useGeneratedKeys="true" keyProperty="reviewId">
        insert into work_review
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="workId != null">work_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="reviewerId != null">reviewer_id,</if>
            <if test="reviewerName != null and reviewerName != ''">reviewer_name,</if>
            <if test="workStatus != null and workStatus != ''">work_status,</if>
            <if test="detail != null and detail != ''">detail,</if>
            <if test="deleteFlag != null">delete_flag,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="workId != null">#{workId},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="reviewerId != null">#{reviewerId},</if>
            <if test="reviewerName != null and reviewerName != ''">#{reviewerName},</if>
            <if test="workStatus != null and workStatus != ''">#{workStatus},</if>
            <if test="detail != null and detail != ''">#{detail},</if>
            <if test="deleteFlag != null">#{deleteFlag},</if>
         </trim>
    </insert>

    <update id="updateWorkReview" parameterType="WorkReview">
        update work_review
        <trim prefix="SET" suffixOverrides=",">
            <if test="workId != null">work_id = #{workId},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="reviewerId != null">reviewer_id = #{reviewerId},</if>
            <if test="reviewerName != null and reviewerName != ''">reviewer_name = #{reviewerName},</if>
            <if test="workStatus != null and workStatus != ''">work_status = #{workStatus},</if>
            <if test="detail != null and detail != ''">detail = #{detail},</if>
            <if test="deleteFlag != null">delete_flag = #{deleteFlag},</if>
        </trim>
        where review_id = #{reviewId}
    </update>
    <update id="setWorkReviewDeleteFlag" parameterType="WorkReview">
        update work_review set delete_flag = "1" where work_id = #{workId}
    </update>

    <delete id="deleteWorkReviewByReviewId" parameterType="Long">
        delete from work_review where review_id = #{reviewId}
    </delete>

    <delete id="deleteWorkReviewByReviewIds" parameterType="String">
        delete from work_review where review_id in 
        <foreach item="reviewId" collection="array" open="(" separator="," close=")">
            #{reviewId}
        </foreach>
    </delete>
</mapper>