<?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.mall.mapper.MallShopSupplierMapper">

    <resultMap type="MallShopSupplier" id="MallShopSupplierResult">
        <result property="supplierId"    column="supplier_id"    />
        <result property="shopId"    column="shop_id"    />
        <result property="sysUserId"    column="sys_user_id"    />
        <result property="supplierName"    column="supplier_name"    />
        <result property="supplierPhone"    column="supplier_phone"    />
        <result property="supplierAccount"    column="supplier_account"    />
        <result property="supplierPassword"    column="supplier_password"    />
        <result property="provinceId"    column="province_id"    />
        <result property="provinceName"    column="province_name"    />
        <result property="cityId"    column="city_id"    />
        <result property="cityName"    column="city_name"    />
        <result property="areaId"    column="area_id"    />
        <result property="areaName"    column="area_name"    />
        <result property="address"    column="address"    />
        <result property="longitude"    column="longitude"    />
        <result property="latitude"    column="latitude"    />
        <result property="supplierStatus"    column="supplier_status"    />
        <result property="createAt"    column="create_at"    />
        <result property="updateAt"    column="update_at"    />
        <result property="delFlag"    column="del_flag"    />
    </resultMap>

    <sql id="selectMallShopSupplierVo">
        select supplier_id, shop_id, sys_user_id, supplier_name, supplier_phone, supplier_account, supplier_password, province_id, province_name, city_id, city_name, area_id, area_name, address, longitude, latitude, supplier_status, create_at, update_at, del_flag from mall_shop_supplier
    </sql>

    <select id="selectMallShopSupplierList" parameterType="MallShopSupplier" resultMap="MallShopSupplierResult">
        <include refid="selectMallShopSupplierVo"/>
        <where>
            <if test="shopId != null "> and shop_id = #{shopId}</if>
            <if test="sysUserId != null "> and sys_user_id = #{sysUserId}</if>
            <if test="supplierName != null  and supplierName != ''"> and supplier_name like concat('%', #{supplierName}, '%')</if>
            <if test="supplierPhone != null  and supplierPhone != ''"> and supplier_phone = #{supplierPhone}</if>
            <if test="supplierAccount != null  and supplierAccount != ''"> and supplier_account = #{supplierAccount}</if>
            <if test="supplierPassword != null  and supplierPassword != ''"> and supplier_password = #{supplierPassword}</if>
            <if test="provinceId != null "> and province_id = #{provinceId}</if>
            <if test="provinceName != null  and provinceName != ''"> and province_name like concat('%', #{provinceName}, '%')</if>
            <if test="cityId != null "> and city_id = #{cityId}</if>
            <if test="cityName != null  and cityName != ''"> and city_name like concat('%', #{cityName}, '%')</if>
            <if test="areaId != null "> and area_id = #{areaId}</if>
            <if test="areaName != null  and areaName != ''"> and area_name like concat('%', #{areaName}, '%')</if>
            <if test="address != null  and address != ''"> and address like concat('%', #{address}, '%')</if>
            <if test="longitude != null  and longitude != ''"> and longitude = #{longitude}</if>
            <if test="latitude != null  and latitude != ''"> and latitude = #{latitude}</if>
            <if test="supplierStatus != null "> and supplier_status = #{supplierStatus}</if>
            <if test="createAt != null  and createAt != ''"> and create_at = #{createAt}</if>
            <if test="updateAt != null  and updateAt != ''"> and update_at = #{updateAt}</if>
        </where>
    </select>

    <select id="selectMallShopSupplierBySupplierId" parameterType="Long" resultMap="MallShopSupplierResult">
        <include refid="selectMallShopSupplierVo"/>
        where supplier_id = #{supplierId}
    </select>

    <select id="selectMallShopSupplierByShopId" parameterType="Long" resultType="cascaderVO">
        select supplier_id id,
               supplier_name name,
               supplier_phone phone
        from mall_shop_supplier
        where shop_id = #{shopId} and del_flag = '0'
        order by supplier_id asc
    </select>

    <insert id="insertMallShopSupplier" parameterType="MallShopSupplier" useGeneratedKeys="true" keyProperty="supplierId">
        insert into mall_shop_supplier
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="shopId != null">shop_id,</if>
            <if test="sysUserId != null">sys_user_id,</if>
            <if test="supplierName != null">supplier_name,</if>
            <if test="supplierPhone != null">supplier_phone,</if>
            <if test="supplierAccount != null">supplier_account,</if>
            <if test="supplierPassword != null">supplier_password,</if>
            <if test="provinceId != null">province_id,</if>
            <if test="provinceName != null">province_name,</if>
            <if test="cityId != null">city_id,</if>
            <if test="cityName != null">city_name,</if>
            <if test="areaId != null">area_id,</if>
            <if test="areaName != null">area_name,</if>
            <if test="address != null">address,</if>
            <if test="longitude != null">longitude,</if>
            <if test="latitude != null">latitude,</if>
            <if test="supplierStatus != null">supplier_status,</if>
            <if test="createAt != null">create_at,</if>
            <if test="updateAt != null">update_at,</if>
            <if test="delFlag != null">del_flag,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="shopId != null">#{shopId},</if>
            <if test="sysUserId != null">#{sysUserId},</if>
            <if test="supplierName != null">#{supplierName},</if>
            <if test="supplierPhone != null">#{supplierPhone},</if>
            <if test="supplierAccount != null">#{supplierAccount},</if>
            <if test="supplierPassword != null">#{supplierPassword},</if>
            <if test="provinceId != null">#{provinceId},</if>
            <if test="provinceName != null">#{provinceName},</if>
            <if test="cityId != null">#{cityId},</if>
            <if test="cityName != null">#{cityName},</if>
            <if test="areaId != null">#{areaId},</if>
            <if test="areaName != null">#{areaName},</if>
            <if test="address != null">#{address},</if>
            <if test="longitude != null">#{longitude},</if>
            <if test="latitude != null">#{latitude},</if>
            <if test="supplierStatus != null">#{supplierStatus},</if>
            <if test="createAt != null">#{createAt},</if>
            <if test="updateAt != null">#{updateAt},</if>
            <if test="delFlag != null">#{delFlag},</if>
         </trim>
    </insert>

    <update id="updateMallShopSupplier" parameterType="MallShopSupplier">
        update mall_shop_supplier
        <trim prefix="SET" suffixOverrides=",">
            <if test="shopId != null">shop_id = #{shopId},</if>
            <if test="sysUserId != null">sys_user_id = #{sysUserId},</if>
            <if test="supplierName != null">supplier_name = #{supplierName},</if>
            <if test="supplierPhone != null">supplier_phone = #{supplierPhone},</if>
            <if test="supplierAccount != null">supplier_account = #{supplierAccount},</if>
            <if test="supplierPassword != null">supplier_password = #{supplierPassword},</if>
            <if test="provinceId != null">province_id = #{provinceId},</if>
            <if test="provinceName != null">province_name = #{provinceName},</if>
            <if test="cityId != null">city_id = #{cityId},</if>
            <if test="cityName != null">city_name = #{cityName},</if>
            <if test="areaId != null">area_id = #{areaId},</if>
            <if test="areaName != null">area_name = #{areaName},</if>
            <if test="address != null">address = #{address},</if>
            <if test="longitude != null">longitude = #{longitude},</if>
            <if test="latitude != null">latitude = #{latitude},</if>
            <if test="supplierStatus != null">supplier_status = #{supplierStatus},</if>
            <if test="createAt != null">create_at = #{createAt},</if>
            <if test="updateAt != null">update_at = #{updateAt},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
        </trim>
        where supplier_id = #{supplierId}
    </update>

    <delete id="deleteMallShopSupplierBySupplierId" parameterType="Long">
        delete from mall_shop_supplier where supplier_id = #{supplierId}
    </delete>

    <delete id="deleteMallShopSupplierBySupplierIds" parameterType="String">
        delete from mall_shop_supplier where supplier_id in
        <foreach item="supplierId" collection="array" open="(" separator="," close=")">
            #{supplierId}
        </foreach>
    </delete>

    <select id="selectMallShopSupplierBySupplierName" parameterType="String" resultMap="MallShopSupplierResult">
        <include refid="selectMallShopSupplierVo"/>
        where supplier_name = #{supplierName}
    </select>

    <select id="selectMallShopSupplierBySupplierAccount" parameterType="String" resultMap="MallShopSupplierResult">
        <include refid="selectMallShopSupplierVo"/>
        where supplier_account = #{supplierAccount}
    </select>

    <select id="selectMallShopSupplierBySysUserId" parameterType="Long" resultMap="MallShopSupplierResult">
        <include refid="selectMallShopSupplierVo"/>
        where sys_user_id = #{sysUserId}
    </select>
</mapper>
