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

    <resultMap type="cn.iocoder.yudao.module.shop.entity.ShopMallPartners" id="ShopMallPartnersResult">
        <result property="partnerId" column="partner_id"/>
        <result property="userId" column="user_id"/>
        <result property="type" column="type"/>
        <result property="partnerName" column="partner_name"/>
        <result property="partnerLogo" column="partner_logo"/>
        <result property="shopImages" column="shop_images"/>
        <result property="contactNumber" column="contact_number"/>
        <result property="address" column="address"/>
        <result property="province" column="province"/>
        <result property="city" column="city"/>
        <result property="area" column="area"/>
        <result property="partnerCategoryId" column="partner_category_id"/>
        <result property="averageScore" column="average_score"/>
        <result property="longitude" column="longitude"/>
        <result property="latitude" column="latitude"/>
        <result property="remark" column="remark"/>
        <result property="workTime" column="work_time"/>
        <result property="salesNum" column="sales_num"/>
        <result property="isBanned" column="is_banned"/>
        <result property="isWorking" column="is_working"/>
        <result property="orderNum" column="order_num"/>
        <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="selectShopMallPartnersVo">
        select partner_id,
               user_id,
               type,
               partner_name,
               partner_logo,
               shop_images,
               contact_number,
               address,
               province,
               city,
               area,
               partner_category_id,
               average_score,
               longitude,
               latitude,
               remark,
               work_time,
               sales_num,
               is_banned,
               is_working,
               order_num,
               create_time,
               creator,
               update_time,
               updater
        from shop_mall_partners
    </sql>

    <select id="selectShopMallPartnersList" parameterType="cn.iocoder.yudao.module.shop.entity.ShopMallPartners" resultType="cn.iocoder.yudao.module.shop.entity.ShopMallPartners">
        select smp.*,su.nickname
        from shop_mall_partners smp
        left join system_users su on su.id = smp.user_id

        order by order_num
    </select>

    <select id="selectShopMallPartnersListWx" parameterType="cn.iocoder.yudao.module.shop.entity.ShopMallPartners" resultType="cn.iocoder.yudao.module.shop.entity.ShopMallPartners">
        select smp.*, su.real_name
        from shop_mall_partners smp
                 left join sys_user su on su.user_id = smp.user_id
        where is_banned != 1
          and type = 'sc'
        order by order_num
    </select>


    <select id="selectShopMallPartnersByPartnerId" parameterType="Long" resultMap="ShopMallPartnersResult">
        <include refid="selectShopMallPartnersVo"/>
        where partner_id = #{partnerId}
    </select>

    <insert id="insertShopMallPartners" parameterType="cn.iocoder.yudao.module.shop.entity.ShopMallPartners" useGeneratedKeys="true"
            keyProperty="partnerId">
        insert into shop_mall_partners
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="userId != null">user_id,</if>
            <if test="type != null">type,</if>
            <if test="partnerName != null">partner_name,</if>
            <if test="partnerLogo != null">partner_logo,</if>
            <if test="shopImages != null">shop_images,</if>
            <if test="contactNumber != null">contact_number,</if>
            <if test="address != null">address,</if>
            <if test="province != null">province,</if>
            <if test="city != null">city,</if>
            <if test="area != null">area,</if>
            <if test="partnerCategoryId != null">partner_category_id,</if>
            <if test="averageScore != null">average_score,</if>
            <if test="longitude != null">longitude,</if>
            <if test="latitude != null">latitude,</if>
            <if test="remark != null">remark,</if>
            <if test="workTime != null">work_time,</if>
            <if test="salesNum != null">sales_num,</if>
            <if test="orderNum != null">order_num,</if>
            <if test="isBanned != null ">is_banned,</if>
            <if test="isWorking != null ">is_working,</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="userId != null">#{userId},</if>
            <if test="type != null">#{type},</if>
            <if test="partnerName != null">#{partnerName},</if>
            <if test="partnerLogo != null">#{partnerLogo},</if>
            <if test="shopImages != null">#{shopImages},</if>
            <if test="contactNumber != null">#{contactNumber},</if>
            <if test="address != null">#{address},</if>
            <if test="province != null">#{province},</if>
            <if test="city != null">#{city},</if>
            <if test="area != null">#{area},</if>
            <if test="partnerCategoryId != null">#{partnerCategoryId},</if>
            <if test="averageScore != null">#{averageScore},</if>
            <if test="longitude != null">#{longitude},</if>
            <if test="latitude != null">#{latitude},</if>
            <if test="remark != null">#{remark},</if>
            <if test="workTime != null">#{workTime},</if>
            <if test="salesNum != null">#{salesNum},</if>
            <if test="orderNum != null">#{orderNum},</if>
            <if test="isBanned != null ">#{isBanned},</if>
            <if test="isWorking != null ">#{isWorking},</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="updateShopMallPartners" parameterType="cn.iocoder.yudao.module.shop.entity.ShopMallPartners">
        update shop_mall_partners
        <trim prefix="SET" suffixOverrides=",">
            <if test="userId != null">user_id = #{userId},</if>
            <if test="type != null">type = #{type},</if>
            <if test="partnerName != null">partner_name = #{partnerName},</if>
            <if test="partnerLogo != null">partner_logo = #{partnerLogo},</if>
            <if test="shopImages != null">shop_images = #{shopImages},</if>
            <if test="contactNumber != null">contact_number = #{contactNumber},</if>
            <if test="address != null">address = #{address},</if>
            <if test="province != null">province = #{province},</if>
            <if test="city != null">city = #{city},</if>
            <if test="area != null">area = #{area},</if>
            <if test="partnerCategoryId != null">partner_category_id = #{partnerCategoryId},</if>
            <if test="averageScore != null">average_score = #{averageScore},</if>
            <if test="longitude != null">longitude = #{longitude},</if>
            <if test="latitude != null">latitude = #{latitude},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="workTime != null">work_time = #{workTime},</if>
            <if test="salesNum != null">sales_num = #{salesNum},</if>
            <if test="orderNum != null">order_num = #{orderNum},</if>
            <if test="isBanned != null ">is_banned=#{isBanned},</if>
            <if test="isWorking != null ">is_working=#{isWorking},</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 partner_id = #{partnerId}
    </update>

    <delete id="deleteShopMallPartnersByPartnerId" parameterType="Long">
        delete
        from shop_mall_partners
        where partner_id = #{partnerId}
    </delete>

    <delete id="deleteShopMallPartnersByPartnerIds" parameterType="String">
        delete from shop_mall_partners where partner_id in
        <foreach item="partnerId" collection="array" open="(" separator="," close=")">
            #{partnerId}
        </foreach>
    </delete>

    <select id="selectShopMallPartnersByUserId"  resultMap="ShopMallPartnersResult">
        <include refid="selectShopMallPartnersVo"/>
        where user_id = #{userId} and `type` = #{type}
    </select>
</mapper>
