<?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.project.BmCompanyShareholderMapper">
    
    <resultMap type="BmCompanyShareholder" id="BmCompanyShareholderResult">
        <result property="id"    column="id"    />
        <result property="bmProjectId"    column="bm_project_id"    />
        <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="isDel"    column="is_del"    />
        <result property="name"    column="name"    />
        <result property="equityRatio"    column="equity_ratio"    />
        <result property="idcard"    column="idcard"    />
        <result property="idcardFront"    column="idcard_front"    />
        <result property="idcardBack"    column="idcard_back"    />
    </resultMap>

    <sql id="selectBmCompanyShareholderVo">
        select id, bm_project_id, create_by, create_time, update_by, update_time, is_del, name, equity_ratio, idcard, idcard_front, idcard_back from bm_company_shareholder
    </sql>

    <select id="selectBmCompanyShareholderList" parameterType="BmCompanyShareholder" resultMap="BmCompanyShareholderResult">
        <include refid="selectBmCompanyShareholderVo"/>
        <where>
            is_del = '0'
            <if test="bmProjectId != null "> and bm_project_id = #{bmProjectId}</if>
            <if test="isDel != null "> and is_del = #{isDel}</if>
            <if test="name != null  and name != ''"> and name like concat('%', #{name}, '%')</if>
            <if test="equityRatio != null  and equityRatio != ''"> and equity_ratio = #{equityRatio}</if>
            <if test="idcard != null  and idcard != ''"> and idcard = #{idcard}</if>
            <if test="idcardFront != null  and idcardFront != ''"> and idcard_front = #{idcardFront}</if>
            <if test="idcardBack != null  and idcardBack != ''"> and idcard_back = #{idcardBack}</if>
        </where>
        order by create_time DESC
    </select>
    
    <select id="selectBmCompanyShareholderById" parameterType="Long" resultMap="BmCompanyShareholderResult">
        <include refid="selectBmCompanyShareholderVo"/>
        where id = #{id}
    </select>

    <select id="selectBmCompanyShareholderByProjectId" parameterType="Long" resultMap="BmCompanyShareholderResult">
        <include refid="selectBmCompanyShareholderVo"/>
        where bm_project_id = #{id} and is_del = '0' limit 1
    </select>
        
    <insert id="insertBmCompanyShareholder" parameterType="BmCompanyShareholder" useGeneratedKeys="true" keyProperty="id">
        insert into bm_company_shareholder
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="bmProjectId != null">bm_project_id,</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="isDel != null">is_del,</if>
            <if test="name != null">name,</if>
            <if test="equityRatio != null">equity_ratio,</if>
            <if test="idcard != null">idcard,</if>
            <if test="idcardFront != null">idcard_front,</if>
            <if test="idcardBack != null">idcard_back,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="bmProjectId != null">#{bmProjectId},</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="isDel != null">#{isDel},</if>
            <if test="name != null">#{name},</if>
            <if test="equityRatio != null">#{equityRatio},</if>
            <if test="idcard != null">#{idcard},</if>
            <if test="idcardFront != null">#{idcardFront},</if>
            <if test="idcardBack != null">#{idcardBack},</if>
         </trim>
    </insert>

    <update id="updateBmCompanyShareholder" parameterType="BmCompanyShareholder">
        update bm_company_shareholder
        <trim prefix="SET" suffixOverrides=",">
            <if test="bmProjectId != null">bm_project_id = #{bmProjectId},</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="isDel != null">is_del = #{isDel},</if>
            <if test="name != null">name = #{name},</if>
            <if test="equityRatio != null">equity_ratio = #{equityRatio},</if>
            <if test="idcard != null">idcard = #{idcard},</if>
            <if test="idcardFront != null">idcard_front = #{idcardFront},</if>
            <if test="idcardBack != null">idcard_back = #{idcardBack},</if>
        </trim>
        where id = #{id}
    </update>

<!--    <delete id="deleteBmCompanyShareholderById" parameterType="Long">
        delete from bm_company_shareholder where id = #{id}
    </delete>-->

    <update id="deleteBmCompanyShareholderById" parameterType="Long">
        update bm_company_shareholder set is_del = '1'  where id = #{id}
    </update>

<!--    <delete id="deleteBmCompanyShareholderByIds" parameterType="String">
        delete from bm_company_shareholder where id in 
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>-->

    <update id="deleteBmCompanyShareholderByIds" parameterType="String">
        update bm_company_shareholder set is_del = '1' where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
</mapper>