<?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.ReviewCommentsMapper">
    
    <resultMap type="ReviewComments" id="ReviewCommentsResult">
        <result property="reviewCommentsId"    column="review_comments_id"    />
        <result property="loanApplicationId"    column="loan_application_id"    />
        <result property="loanApplicationNumber"    column="loan_application_number"    />
        <result property="auditSchedule"    column="audit_schedule"    />
        <result property="auditType"    column="audit_type"    />
        <result property="auditView"    column="audit_view"    />
        <result property="auditTime"    column="audit_time"    />
        <result property="reviewTime"    column="review_time"    />
        <result property="imageUrl"    column="image_url"    />
        <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"    />
    </resultMap>

    <sql id="selectReviewCommentsVo">
        select review_comments_id, loan_application_id, loan_application_number,review_time, audit_schedule, audit_type, audit_view, audit_time,  image_url, create_by, create_time, update_by, update_time, remark from review_comments
    </sql>

    <select id="selectReviewCommentsList" parameterType="ReviewComments" resultMap="ReviewCommentsResult">
        <include refid="selectReviewCommentsVo"/>
        <where>  
            <if test="loanApplicationId != null "> and loan_application_id = #{loanApplicationId}</if>
            <if test="loanApplicationNumber != null  and loanApplicationNumber != ''"> and loan_application_number = #{loanApplicationNumber}</if>
            <if test="auditSchedule != null  and auditSchedule != ''"> and audit_schedule = #{auditSchedule}</if>
            <if test="auditType != null  and auditType != ''"> and audit_type = #{auditType}</if>
            <if test="auditView != null  and auditView != ''"> and audit_view = #{auditView}</if>
            <if test="reviewTime != null  "> and review_time = #{reviewTime}</if>
            <if test="auditTime != null "> and audit_time = #{auditTime}</if>
            <if test="imageUrl != null  and imageUrl != ''"> and image_url = #{imageUrl}</if>
        </where>
        order by create_time
    </select>
    
    <select id="selectReviewCommentsByReviewCommentsId" parameterType="Long" resultMap="ReviewCommentsResult">
        <include refid="selectReviewCommentsVo"/>
        where review_comments_id = #{reviewCommentsId}
    </select>
        
    <insert id="insertReviewComments" parameterType="ReviewComments" useGeneratedKeys="true" keyProperty="reviewCommentsId">
        insert into review_comments
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="loanApplicationId != null">loan_application_id,</if>
            <if test="loanApplicationNumber != null and loanApplicationNumber != ''">loan_application_number,</if>
            <if test="auditSchedule != null and auditSchedule != ''">audit_schedule,</if>
            <if test="auditType != null and auditType != ''">audit_type,</if>
            <if test="auditView != null">audit_view,</if>
            <if test="auditTime != null">audit_time,</if>
            <if test="reviewTime != null">review_time,</if>
            <if test="imageUrl != null">image_url,</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="loanApplicationId != null">#{loanApplicationId},</if>
            <if test="loanApplicationNumber != null and loanApplicationNumber != ''">#{loanApplicationNumber},</if>
            <if test="auditSchedule != null and auditSchedule != ''">#{auditSchedule},</if>
            <if test="auditType != null and auditType != ''">#{auditType},</if>
            <if test="auditView != null">#{auditView},</if>
            <if test="auditTime != null">#{auditTime},</if>
            <if test="reviewTime != null">#{reviewTime},</if>
            <if test="imageUrl != null">#{imageUrl},</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="updateReviewComments" parameterType="ReviewComments">
        update review_comments
        <trim prefix="SET" suffixOverrides=",">
            <if test="loanApplicationId != null">loan_application_id = #{loanApplicationId},</if>
            <if test="loanApplicationNumber != null and loanApplicationNumber != ''">loan_application_number = #{loanApplicationNumber},</if>
            <if test="auditSchedule != null and auditSchedule != ''">audit_schedule = #{auditSchedule},</if>
            <if test="auditType != null and auditType != ''">audit_type = #{auditType},</if>
            <if test="auditView != null">audit_view = #{auditView},</if>
            <if test="auditTime != null">audit_time = #{auditTime},</if>
            <if test="reviewTime != null">review_time = #{reviewTime},</if>
            <if test="imageUrl != null">image_url = #{imageUrl},</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 review_comments_id = #{reviewCommentsId}
    </update>

    <delete id="deleteReviewCommentsByReviewCommentsId" parameterType="Long">
        delete from review_comments where review_comments_id = #{reviewCommentsId}
    </delete>

    <delete id="deleteReviewCommentsByReviewCommentsIds" parameterType="String">
        delete from review_comments where review_comments_id in 
        <foreach item="reviewCommentsId" collection="array" open="(" separator="," close=")">
            #{reviewCommentsId}
        </foreach>
    </delete>
    <delete id="deleteReviewCommentsByLoanApplicationIdAndAuditSchedule" parameterType="ReviewComments">
        delete from review_comments where loan_application_id = #{loanApplicationId} and audit_schedule = #{auditSchedule}
    </delete>
</mapper>