<?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.LoanApplicationFjMapper">

    <resultMap type="LoanApplicationFj" id="LoanApplicationFjResult">
        <result property="fjId" column="fj_id"/>
        <result property="loanApplicationId" column="loan_application_id"/>
        <result property="loanApplicationNumber" column="loan_application_number"/>
        <result property="oldName" column="old_name"/>
        <result property="name" column="name"/>
        <result property="url" column="url"/>
        <result property="bigType" column="big_type"/>
        <result property="type" column="type"/>
        <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="selectLoanApplicationFjVo">
        select fj_id,
               loan_application_id,
               loan_application_number,
               old_name,
               name,
               url,
               big_type,
               type,
               create_by,
               create_time,
               update_by,
               update_time,
               remark
        from loan_application_fj
    </sql>

    <select id="selectLoanApplicationFjList" parameterType="LoanApplicationFj" resultMap="LoanApplicationFjResult">
        <include refid="selectLoanApplicationFjVo"/>
        <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="oldName != null  and oldName != ''">and old_name like concat('%', #{oldName}, '%')</if>
            <if test="name != null  and name != ''">and name like concat('%', #{name}, '%')</if>
            <if test="url != null  and url != ''">and url = #{url}</if>
            <if test="type != null  and type != ''">and type = #{type}</if>
            <if test="bigType != null  and bigType != ''">and big_type = #{bigType}</if>
        </where>
        order by create_time
    </select>

    <select id="selectLoanApplicationFjByFjId" parameterType="Long" resultMap="LoanApplicationFjResult">
        <include refid="selectLoanApplicationFjVo"/>
        where fj_id = #{fjId}
    </select>
    <select id="selectLoanApplicationFjByLoanApplicationId" parameterType="LoanApplicationFj"
            resultMap="LoanApplicationFjResult">
        <include refid="selectLoanApplicationFjVo"/>
        <where>
            <if test="loanApplicationId != null ">and loan_application_id = #{loanApplicationId}</if>
        </where>
        order by create_time
    </select>
    <select id="selectLoanApplicationFjByLoanApplicationIdAndType" parameterType="LoanApplicationFj" resultMap="LoanApplicationFjResult">
        <include refid="selectLoanApplicationFjVo"/>
        where loan_application_id = #{loanApplicationId}
        and type in
        <foreach item="type" collection="type" open="(" separator="," close=")">
            #{type}
        </foreach>
    </select>

    <insert id="insertLoanApplicationFj" parameterType="LoanApplicationFj" useGeneratedKeys="true" keyProperty="fjId">
        insert into loan_application_fj
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="loanApplicationId != null">loan_application_id,</if>
            <if test="loanApplicationNumber != null">loan_application_number,</if>
            <if test="oldName != null and oldName != ''">old_name,</if>
            <if test="name != null and name != ''">name,</if>
            <if test="url != null">url,</if>
            <if test="bigType != null">big_type,</if>
            <if test="type != null">type,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="remark != null">remark,</if>
            create_time
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="loanApplicationId != null">#{loanApplicationId},</if>
            <if test="loanApplicationNumber != null">#{loanApplicationNumber},</if>
            <if test="oldName != null and oldName != ''">#{oldName},</if>
            <if test="name != null and name != ''">#{name},</if>
            <if test="url != null">#{url},</if>
            <if test="bigType != null">#{bigType},</if>
            <if test="type != null">#{type},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="remark != null">#{remark},</if>
            sysdate()
        </trim>
    </insert>
    <insert id="batchLoanApplicationFj">
        insert into loan_application_fj(loan_application_id, loan_application_number, old_name, name, url,big_type,
        type, create_by, create_time, update_by, update_time, remark) values
        <foreach item="item" index="index" collection="list" separator=",">
            (#{item.loanApplicationId},#{item.loanApplicationNumber},#{item.oldName},#{item.name},#{item.url},#{item.bigType},#{item.type},#{item.createBy},sysdate(),#{item.updateBy},#{item.updateTime},#{item.remark})
        </foreach>
    </insert>

    <update id="updateLoanApplicationFj" parameterType="LoanApplicationFj">
        update loan_application_fj
        <trim prefix="SET" suffixOverrides=",">
            <if test="loanApplicationId != null">loan_application_id = #{loanApplicationId},</if>
            <if test="loanApplicationNumber != null">loan_application_number = #{loanApplicationNumber},</if>
            <if test="oldName != null and oldName != ''">old_name = #{oldName},</if>
            <if test="name != null and name != ''">name = #{name},</if>
            <if test="url != null">url = #{url},</if>
            <if test="bigType != null">big_type = #{bigType},</if>
            <if test="type != null">type = #{type},</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 fj_id = #{fjId}
    </update>

    <delete id="deleteLoanApplicationFjByFjId" parameterType="Long">
        delete
        from loan_application_fj
        where fj_id = #{fjId}
    </delete>

    <delete id="deleteLoanApplicationFjByFjIds" parameterType="String">
        delete from loan_application_fj where fj_id in
        <foreach item="fjId" collection="array" open="(" separator="," close=")">
            #{fjId}
        </foreach>
    </delete>
    <delete id="deleteLoanApplicationFjByLoanApplicationId" parameterType="Long">
        delete
        from loan_application_fj
        where loan_application_id = #{LoanApplicationId}
    </delete>
    <delete id="deleteLoanApplicationFjByLoanApplicationIdAndType" parameterType="LoanApplicationFj">
        delete
        from loan_application_fj
        where loan_application_id = #{loanApplicationId}
        and type in
        <foreach item="type" collection="type" open="(" separator="," close=")">
            #{type}
        </foreach>
    </delete>
</mapper>