<?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.ShareholderFjMapper">
    
    <resultMap type="ShareholderFj" id="ShareholderFjResult">
        <result property="shareholderFjId"    column="shareholder_fj_id"    />
        <result property="loanApplicationId"    column="loan_application_id"    />
        <result property="loanApplicationNumber"    column="loan_application_number"    />
        <result property="shareholderIdCard"    column="shareholder_id_card"    />
        <result property="shareholderName"    column="shareholder_name"    />
        <result property="shareholderFrontName"    column="shareholder_front_name"    />
        <result property="shareholderFrontUrl"    column="shareholder_front_url"    />
        <result property="shareholderBackName"    column="shareholder_back_name"    />
        <result property="shareholderBackUrl"    column="shareholder_back_url"    />
        <result property="shareholderZxName"    column="shareholder_zx_name"    />
        <result property="shareholderZxUrl"    column="shareholder_zx_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="selectShareholderFjVo">
        select shareholder_fj_id, loan_application_id, loan_application_number, shareholder_id_card, shareholder_name,shareholder_front_name, shareholder_front_url,shareholder_back_name, shareholder_back_url,shareholder_zx_name, shareholder_zx_url, create_by, create_time, update_by, update_time, remark from shareholder_fj
    </sql>

    <select id="selectShareholderFjList" parameterType="ShareholderFj" resultMap="ShareholderFjResult">
        <include refid="selectShareholderFjVo"/>
        <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="shareholderIdCard != null  and shareholderIdCard != ''"> and shareholder_id_card = #{shareholderIdCard}</if>
            <if test="shareholderName != null  and shareholderName != ''"> and shareholder_name like concat('%', #{shareholderName}, '%')</if>
            <if test="shareholderFrontUrl != null  and shareholderFrontUrl != ''"> and shareholder_front_url = #{shareholderFrontUrl}</if>
            <if test="shareholderBackUrl != null  and shareholderBackUrl != ''"> and shareholder_back_url = #{shareholderBackUrl}</if>
            <if test="shareholderZxUrl != null  and shareholderZxUrl != ''"> and shareholder_zx_url = #{shareholderZxUrl}</if>
        </where>
        order by create_time
    </select>

    <select id="selectShareholderFjLoanApplicationId" parameterType="ShareholderFj" resultMap="ShareholderFjResult">
        <include refid="selectShareholderFjVo"/>
        <where>
            <if test="loanApplicationId != null "> and loan_application_id = #{loanApplicationId}</if>
        </where>
        order by create_time
    </select>
    
    <select id="selectShareholderFjByShareholderFjId" parameterType="Long" resultMap="ShareholderFjResult">
        <include refid="selectShareholderFjVo"/>
        where shareholder_fj_id = #{shareholderFjId}
    </select>
        
    <insert id="insertShareholderFj" parameterType="ShareholderFj" useGeneratedKeys="true" keyProperty="shareholderFjId">
        insert into shareholder_fj
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="loanApplicationId != null">loan_application_id,</if>
            <if test="loanApplicationNumber != null and loanApplicationNumber != ''">loan_application_number,</if>
            <if test="shareholderIdCard != null and shareholderIdCard != ''">shareholder_id_card,</if>
            <if test="shareholderName != null and shareholderName != ''">shareholder_name,</if>
            <if test="shareholderFrontName != null and shareholderFrontName != ''">shareholder_front_name,</if>
            <if test="shareholderFrontUrl != null and shareholderFrontUrl != ''">shareholder_front_url,</if>
            <if test="shareholderBackName != null and shareholderBackName != ''">shareholder_back_name,</if>
            <if test="shareholderBackUrl != null and shareholderBackUrl != ''">shareholder_back_url,</if>
            <if test="shareholderZxName != null and shareholderZxName != ''" >shareholder_zx_name,</if>
            <if test="shareholderZxUrl != null and shareholderZxUrl != ''">shareholder_zx_url,</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 and loanApplicationNumber != ''">#{loanApplicationNumber},</if>
            <if test="shareholderIdCard != null and shareholderIdCard != ''">#{shareholderIdCard},</if>
            <if test="shareholderName != null and shareholderName != ''">#{shareholderName},</if>
            <if test="shareholderFrontName != null and shareholderFrontName != ''">#{shareholderFrontName},</if>
            <if test="shareholderFrontUrl != null and shareholderFrontUrl != ''">#{shareholderFrontUrl},</if>
            <if test="shareholderBackName != null and shareholderBackName != ''">#{shareholderBackName},</if>
            <if test="shareholderBackUrl != null and shareholderBackUrl != ''">#{shareholderBackUrl},</if>
            <if test="shareholderZxName != null and shareholderZxName != ''">#{shareholderZxName},</if>
            <if test="shareholderZxUrl != null and shareholderZxUrl != ''">#{shareholderZxUrl},</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="batchShareholderFj">
        insert into shareholder_fj(loan_application_id, loan_application_number, shareholder_id_card, shareholder_name,shareholder_front_name, shareholder_front_url,shareholder_back_name, shareholder_back_url,shareholder_zx_name, shareholder_zx_url, create_by, create_time, update_by, update_time, remark) values
        <foreach item="item" index="index" collection="list" separator=",">
            (#{item.loanApplicationId},#{item.loanApplicationNumber},#{item.shareholderIdCard},#{item.shareholderName},#{item.shareholderFrontName},#{item.shareholderFrontUrl},#{item.shareholderBackName},#{item.shareholderBackUrl},#{item.shareholderZxName},#{item.shareholderZxUrl},#{item.createBy},sysdate(),#{item.updateBy},#{item.updateTime},#{item.remark})
        </foreach>
    </insert>

    <update id="updateShareholderFj" parameterType="ShareholderFj">
        update shareholder_fj
        <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="shareholderIdCard != null and shareholderIdCard != ''">shareholder_id_card = #{shareholderIdCard},</if>
            <if test="shareholderName != null and shareholderName != ''">shareholder_name = #{shareholderName},</if>
            <if test="shareholderFrontName != null and shareholderFrontName != ''">shareholder_front_name = #{shareholderFrontName},</if>
            <if test="shareholderFrontUrl != null and shareholderFrontUrl != ''">shareholder_front_url = #{shareholderFrontUrl},</if>
            <if test="shareholderBackName != null and shareholderBackName != ''">shareholder_back_name = #{shareholderBackName},</if>
            <if test="shareholderBackUrl != null and shareholderBackUrl != ''">shareholder_back_url = #{shareholderBackUrl},</if>
            <if test="shareholderZxName != null and shareholderZxName != ''">shareholder_zx_name = #{shareholderZxName},</if>
            <if test="shareholderZxUrl != null and shareholderZxUrl != ''">shareholder_zx_url = #{shareholderZxUrl},</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 shareholder_fj_id = #{shareholderFjId}
    </update>

    <delete id="deleteShareholderFjByShareholderFjId" parameterType="Long">
        delete from shareholder_fj where shareholder_fj_id = #{shareholderFjId}
    </delete>

    <delete id="deleteShareholderFjByShareholderFjIds" parameterType="String">
        delete from shareholder_fj where shareholder_fj_id in 
        <foreach item="shareholderFjId" collection="array" open="(" separator="," close=")">
            #{shareholderFjId}
        </foreach>
    </delete>
    <delete id="deleteShareholderFjByLoanApplicationId" parameterType="Long">
        delete from shareholder_fj where loan_application_id = #{LoanApplicationId}
    </delete>
</mapper>