<?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.tuoheng.admin.mapper.WarehouseMapper">
    
    <resultMap type="com.tuoheng.admin.entity.domain.Warehouse" id="WarehouseResult">
        <result property="id"    column="id"    />
        <result property="tenantId"    column="tenant_id"    />
        <result property="warehouseName"    column="warehouse_name"    />
        <result property="longitude"    column="longitude"    />
        <result property="latitude"    column="latitude"    />
        <result property="location"    column="location"    />
        <result property="createUser"    column="create_user"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateUser"    column="update_user"    />
        <result property="updateTime"    column="update_time"    />
        <result property="mark"    column="mark"    />
    </resultMap>

    <sql id="selectWarehouseVo">
        select id, tenant_id, warehouse_name, longitude, latitude, location, create_user, create_time, update_user, update_time, mark from th_warehouse
    </sql>

    <select id="selectPageList" parameterType="com.tuoheng.admin.entity.request.warehouse.QueryWarehousePageListRequest" resultMap="WarehouseResult">
        SELECT
        w.id,
        w.tenant_id,
        w.warehouse_name,
        w.longitude,
        w.latitude,
        w.location,
        w.create_user,
        w.create_time,
        w.update_user,
        w.update_time,
        w.mark,
        u.realname AS updateUserName
        FROM
        th_warehouse w
        LEFT JOIN sys_user u ON w.update_user = u.id
        <where>
            <if test="1 == 1"> and w.mark = 1 </if>
            <if test="request.tenantId != null and request.tenantId != 0"> and w.tenant_id = #{request.tenantId}</if>
            <if test="request.warehouseName != null and request.warehouseName != ''">
                and w.warehouse_name like concat('%',#{request.warehouseName},'%')
            </if>
        </where>
        order by w.create_time desc
    </select>
    
    <select id="getOneById" parameterType="Integer" resultMap="WarehouseResult">
        <include refid="selectWarehouseVo"/>
        where mark = 1 and id = #{id}
    </select>
        
</mapper>