<?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.kxs.store.biz.mapper.KxsWarehouseMapper">

    <resultMap type="com.kxs.store.api.model.KxsWarehouse" id="KxsWarehouseMap">
        <result column="id" property="id" />
        <result column="create_time" property="createTime" />
        <result column="update_time" property="updateTime" />
        <result column="del_flag" property="delFlag" />
        <result column="version" property="version" />
        <result column="user_id" property="userId" />
        <result column="brand_id" property="brandId" />
        <result column="contacts" property="contacts" />
        <result column="warehouse_phone" property="warehousePhone" />
        <result column="warehouse_address" property="warehouseAddress" />
        <result column="warehouse_no" property="warehouseNo" />
        <result column="warehouse_admin_id" property="warehouseAdminId" />
        <result column="warehouse_type" property="warehouseType" />
        <result column="pid" property="pid" />
        <result column="pledge_amount" property="pledgeAmount" />
        <result column="status" property="status" />
        <result column="create_by" property="createBy" />
        <result column="admin_email" property="adminEmail" />
        <result column="file_url" property="fileUrl" />
        <result column="province" property="province" />
        <result column="city" property="city" />
        <result column="area" property="area" />
        <result column="warehouse_name" property="warehouseName" />
        <result column="brand_name" property="brandName" />
        <result column="update_by" property="updateBy" />
        <result column="remark" property="remark" />
        <result column="warehouse_user_name" property="warehouseUserName" />
        <result column="warehouse_user_code" property="warehouseUserCode" />

    </resultMap>
    <select id="searchList" resultType="com.kxs.store.api.vo.kxsapp.store.StoreSearchListVO">
        select a.id, a.user_id, a.contacts, a.warehouse_phone, a.warehouse_address, a.warehouse_no, a.status, a.province, a.city, a.area, a.warehouse_type, a.warehouse_name,a.brand_id,
        stock.stock_num
        from kxs_warehouse a
        left join kxs_warehouse_stock stock on a.id = stock.warehouse_id
        <where>
            and a.del_flag = 0
            <if test="query.brandId != null">
                and a.brand_id = #{query.brandId}
            </if>
            <if test="query.whsUserIds != null">
                and a.user_id in
                <foreach collection="query.whsUserIds" item="userId" index="index" open="(" close=")" separator=",">
                    #{userId}
                </foreach>
            </if>
            <if test="query.keyword != null and query.keyword != ''">
                and a.warehouse_name like concat('%' #{query.keyword}, '%')
            </if>
        </where>

    </select>
    <select id="userStoreList" resultType="com.kxs.store.api.vo.kxsapp.store.StoreListVO">
        select id, brand_id, warehouse_phone, warehouse_no, warehouse_name, brand_name
        from kxs_warehouse
        where user_id = #{userId}
          and del_flag = 0
    </select>


</mapper>
