<?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.ibs.list.mapper.CorporateShareholderMapper">
    
    <resultMap type="CorporateShareholder" id="CorporateShareholderResult">
        <result property="socialCreditCode"    column="social_credit_code"    />
        <result property="custType"    column="cust_type"    />
        <result property="percent"    column="percent"    />
        <result property="name"    column="name"    />
        <result property="custIdc"    column="cust_idc"    />
        <result property="customerType"    column="customer_type"    />
        <result property="perCustType"    column="per_cust_type"    />
    </resultMap>

    <sql id="selectCorporateShareholderVo">
        select social_credit_code, cust_type, percent, name, cust_idc, customer_type,per_cust_type from corporate_shareholder
    </sql>

    <select id="selectCorporateShareholderList" parameterType="CorporateShareholder" resultMap="CorporateShareholderResult">
        <include refid="selectCorporateShareholderVo"/>
        <where>  
            <if test="socialCreditCode != null  and socialCreditCode != ''"> and social_credit_code = #{socialCreditCode}</if>
            <if test="custType != null  and custType != ''"> and cust_type = #{custType}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="custIdc != null  and custIdc != ''"> and cust_idc = #{custIdc}</if>
            <if test="customerType != null  and customerType != ''"> and customer_type = #{customerType}</if>
        </where>
    </select>
    
    <select id="selectCorporateShareholderBySocialCreditCode" parameterType="String" resultMap="CorporateShareholderResult">
        <include refid="selectCorporateShareholderVo"/>
        where social_credit_code = #{socialCreditCode}
    </select>

    <insert id="insertCorporateShareholder" parameterType="CorporateShareholder">
        insert into corporate_shareholder
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="socialCreditCode != null">social_credit_code,</if>
            <if test="custType != null">cust_type,</if>
            <if test="percent != null">percent,</if>
            <if test="name != null">name,</if>
            <if test="custIdc != null">cust_idc,</if>
            <if test="customerType != null">customer_type,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="socialCreditCode != null">#{socialCreditCode},</if>
            <if test="custType != null">#{custType},</if>
            <if test="percent != null">#{percent},</if>
            <if test="name != null">#{name},</if>
            <if test="custIdc != null">#{custIdc},</if>
            <if test="customerType != null">#{customerType},</if>
         </trim>
    </insert>

    <update id="updateCorporateShareholder" parameterType="CorporateShareholder">
        update corporate_shareholder
        <trim prefix="SET" suffixOverrides=",">
            <if test="custType != null">cust_type = #{custType},</if>
            <if test="percent != null">percent = #{percent},</if>
            <if test="name != null">name = #{name},</if>
            <if test="custIdc != null">cust_idc = #{custIdc},</if>
            <if test="customerType != null">customerType = #{customerType},</if>
        </trim>
        where social_credit_code = #{socialCreditCode}
    </update>

    <delete id="deleteCorporateShareholderBySocialCreditCode" parameterType="String">
        delete from corporate_shareholder where social_credit_code = #{socialCreditCode}
    </delete>

    <delete id="deleteCorporateShareholderBySocialCreditCodes" parameterType="String">
        delete from corporate_shareholder where social_credit_code in 
        <foreach item="socialCreditCode" collection="array" open="(" separator="," close=")">
            #{socialCreditCode}
        </foreach>
    </delete>
</mapper>