<?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="cn.iocoder.yudao.module.shop.mapper.PartnerDetailMapper">

    <resultMap type="cn.iocoder.yudao.module.shop.entity.PartnerDetail" id="PartnerDetailResult">
        <result property="id"    column="id"    />
        <result property="userId"    column="user_id"    />
        <result property="type"    column="type"    />
        <result property="partnerId"    column="partner_id"    />
        <result property="partnerName"    column="partner_name"    />
        <result property="businessLicense"    column="business_license"    />
        <result property="shopImage"    column="shop_image"    />
        <result property="position"    column="position"    />
        <result property="phone"    column="phone"    />
        <result property="idCardFront"    column="id_card_front"    />
        <result property="idCardBack"    column="id_card_back"    />
        <result property="status"    column="status"    />
        <result property="rejectReason"    column="reject_reason"    />
        <result property="createTime"    column="create_time"    />
        <result property="creator"    column="creator"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updater"    column="updater"    />
    </resultMap>

    <sql id="selectPartnerDetailVo">
        select id, user_id, type, partner_id, partner_name, business_license, shop_image, position, phone, id_card_front, id_card_back, status, reject_reason,create_time, creator, update_time, updater from partner_detail
    </sql>

    <select id="selectPartnerDetailList" parameterType="cn.iocoder.yudao.module.shop.entity.PartnerDetail" resultMap="PartnerDetailResult">
        <include refid="selectPartnerDetailVo"/>
        <where>
            <if test="vo.userId != null "> and user_id = #{vo.userId}</if>
            <if test="vo.type != null  and vo.type != ''"> and type = #{vo.type}</if>
            <if test="vo.partnerId != null "> and partner_id = #{vo.partnerId}</if>
            <if test="vo.partnerName != null  and vo.partnerName != ''"> and partner_name like concat('%', #{vo.partnerName}, '%')</if>
            <if test="vo.businessLicense != null  and vo.businessLicense != ''"> and business_license = #{vo.businessLicense}</if>
            <if test="vo.shopImage != null  and vo.shopImage != ''"> and shop_image = #{vo.shopImage}</if>
            <if test="vo.position != null  and vo.position != ''"> and position = #{vo.position}</if>
            <if test="vo.phone != null  and vo.phone != ''"> and phone = #{vo.phone}</if>
            <if test="vo.idCardFront != null  and vo.idCardFront != ''"> and id_card_front = #{vo.idCardFront}</if>
            <if test="vo.idCardBack != null  and vo.idCardBack != ''"> and id_card_back = #{vo.idCardBack}</if>
            <if test="vo.status != null  and vo.status != ''"> and status = #{vo.status}</if>
        </where>
    </select>

    <select id="selectPartnerDetailById"  resultMap="PartnerDetailResult">
        <include refid="selectPartnerDetailVo"/>
        where id = #{id}
    </select>
    <select id="selectPartnerDetailByUserId"  resultMap="PartnerDetailResult">
        <include refid="selectPartnerDetailVo"/>
        where user_id = #{userId} and `type` = #{type}
    </select>

    <insert id="insertPartnerDetail" parameterType="cn.iocoder.yudao.module.shop.entity.PartnerDetail">
        insert into partner_detail
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="userId != null">user_id,</if>
            <if test="type != null">type,</if>
            <if test="partnerId != null">partner_id,</if>
            <if test="partnerName != null">partner_name,</if>
            <if test="businessLicense != null">business_license,</if>
            <if test="shopImage != null">shop_image,</if>
            <if test="position != null">position,</if>
            <if test="phone != null">phone,</if>
            <if test="idCardFront != null">id_card_front,</if>
            <if test="idCardBack != null">id_card_back,</if>
            <if test="status != null">status,</if>
            <if test="createTime != null">create_time,</if>
            <if test="creator != null">creator,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updater != null">updater,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="userId != null">#{userId},</if>
            <if test="type != null">#{type},</if>
            <if test="partnerId != null">#{partnerId},</if>
            <if test="partnerName != null">#{partnerName},</if>
            <if test="businessLicense != null">#{businessLicense},</if>
            <if test="shopImage != null">#{shopImage},</if>
            <if test="position != null">#{position},</if>
            <if test="phone != null">#{phone},</if>
            <if test="idCardFront != null">#{idCardFront},</if>
            <if test="idCardBack != null">#{idCardBack},</if>
            <if test="status != null">#{status},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="creator != null">#{creator},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updater != null">#{updater},</if>
         </trim>
    </insert>

    <update id="updatePartnerDetail" parameterType="cn.iocoder.yudao.module.shop.entity.PartnerDetail">
        update partner_detail
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="type != null">type = #{type},</if>
            <if test="partnerId != null">partner_id = #{partnerId},</if>
            <if test="partnerName != null">partner_name = #{partnerName},</if>
            <if test="businessLicense != null">business_license = #{businessLicense},</if>
            <if test="shopImage != null">shop_image = #{shopImage},</if>
            <if test="position != null">position = #{position},</if>
            <if test="phone != null">phone = #{phone},</if>
            <if test="idCardFront != null">id_card_front = #{idCardFront},</if>
            <if test="idCardBack != null">id_card_back = #{idCardBack},</if>
            <if test="status != null">status = #{status},</if>
            <if test="rejectReason != null">reject_reason = #{rejectReason},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="creator != null">creator = #{creator},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updater != null">updater = #{updater},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deletePartnerDetailById" parameterType="Long">
        delete from partner_detail where id = #{id}
    </delete>

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