<?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.inventory.mapper.StorageLocationsMapper">

    <!-- 原有基础ResultMap - 仅添加新字段映射 -->
    <resultMap type="StorageLocations" id="StorageLocationsResult">
        <result property="id"    column="id"    />
        <result property="locationCode"    column="location_code"    />
        <result property="locationName"    column="location_name"    />
        <result property="warehousesCode"    column="warehouses_code"    />
        <result property="locationType"    column="location_type"    />
        <result property="zoneCode"    column="zone_code"    />
        <result property="rowCode"    column="row_code"    />
        <result property="columnCode"    column="column_code"    />
        <result property="layerCode"    column="layer_code"    />
        <result property="capacity"    column="capacity"    />
        <result property="volumeCapacity"    column="volume_capacity"    />
        <result property="allowedHazardLevels"    column="allowed_hazard_levels"    />
        <result property="allowedCategoryIds"    column="allowed_category_ids"    />
        <result property="temperatureZone"    column="temperature_zone"    />
        <result property="isEnabled"    column="is_enabled"    />
        <result property="isUsed"    column="is_used"    />
        <result property="sortNo"    column="sort_no"    />
        <result property="createTime"    column="create_time"    />
        <result property="createUserCode"    column="create_user_code"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateUserCode"    column="update_user_code"    />
        <result property="warehousesId"    column="warehouses_id"    />
        <!-- 新增字段映射 -->
        <result property="putawayOrder" column="putaway_order" />
        <result property="pickingOrder" column="picking_order" />
        <result property="LocationUsage" column="location_usage" />
        <result property="locationHandling" column="location_handling" />
        <result property="turnoverDemand" column="turnover_demand" />
        <result property="pickingArea" column="picking_area" />
        <result property="allowMixedProducts" column="allow_mixed_products" />
        <result property="allowMixedBatches" column="allow_mixed_batches" />
        <!-- 新增loading_area字段映射 -->
        <result property="loadingArea" column="loading_area" />
    </resultMap>

    <!-- 关联仓库表的ResultMap - 继承基础ResultMap（自动包含新字段） -->
    <resultMap type="StorageLocations" id="StorageLocationsWithWarehousesResult" extends="StorageLocationsResult">
        <result property="warehousesName" column="warehouses_name"/>
        <result property="warehousesAddress" column="warehouses_address"/>
        <result property="warehousesManager" column="warehouses_manager"/>
        <result property="warehousesPhone" column="warehouses_phone"/>
    </resultMap>

    <!-- 重构：整合is_used=1条件，新增表别名sl -->
    <sql id="selectStorageLocationsVo">
        select sl.id, sl.location_code, sl.location_name, sl.warehouses_code, sl.location_type,
               sl.zone_code, sl.row_code, sl.column_code, sl.layer_code, sl.capacity,
               sl.volume_capacity, sl.allowed_hazard_levels, sl.allowed_category_ids,
               sl.temperature_zone, sl.is_enabled, sl.is_used, sl.sort_no,
               sl.create_time, sl.create_user_code, sl.update_time, sl.update_user_code, sl.warehouses_id,
               -- 新增字段查询
               sl.putaway_order, sl.picking_order, sl.location_usage,
               sl.location_handling, sl.turnover_demand, sl.picking_area,
               sl.allow_mixed_products, sl.allow_mixed_batches,
               -- 新增loading_area字段查询
               sl.loading_area
        from storage_locations sl
        where sl.is_used = 1
    </sql>

    <!-- 关联仓库表的查询片段（继承is_used=1条件） -->
    <sql id="selectStorageLocationsWithWarehousesVo">
        select sl.id, sl.location_code, sl.location_name, sl.warehouses_code, sl.location_type,
               sl.zone_code, sl.row_code, sl.column_code, sl.layer_code, sl.capacity,
               sl.volume_capacity, sl.allowed_hazard_levels, sl.allowed_category_ids,
               sl.temperature_zone, sl.is_enabled, sl.is_used, sl.sort_no,
               sl.create_time, sl.create_user_code, sl.update_time, sl.update_user_code, sl.warehouses_id,
               -- 新增字段查询
               sl.putaway_order, sl.picking_order, sl.location_usage,
               sl.location_handling, sl.turnover_demand, sl.picking_area,
               sl.allow_mixed_products, sl.allow_mixed_batches,
               -- 新增loading_area字段查询
               sl.loading_area,
               w.warehouses_name
        from storage_locations sl
                 left join warehouses w on sl.warehouses_id = w.id
        where sl.is_used = 1
    </sql>

    <!-- 原有列表查询（简化：移除重复的is_used=1，条件改为and开头） -->
    <select id="selectStorageLocationsList" parameterType="StorageLocations" resultMap="StorageLocationsWithWarehousesResult">
        <include refid="selectStorageLocationsWithWarehousesVo"/>
        <if test="locationCode != null  and locationCode != ''"> and sl.location_code like concat('%', #{locationCode}, '%')</if>
        <if test="locationName != null  and locationName != ''"> and sl.location_name like concat('%', #{locationName}, '%')</if>
        <if test="warehousesCode != null  and warehousesCode != ''"> and sl.warehouses_code = #{warehousesCode}</if>
        <if test="locationType != null "> and sl.location_type = #{locationType}</if>
        <if test="zoneCode != null  and zoneCode != ''"> and sl.zone_code like concat('%', #{zoneCode}, '%')</if>
        <if test="rowCode != null  and rowCode != ''"> and sl.row_code = #{rowCode}</if>
        <if test="columnCode != null  and columnCode != ''"> and sl.column_code = #{columnCode}</if>
        <if test="layerCode != null  and layerCode != ''"> and sl.layer_code = #{layerCode}</if>
        <if test="capacity != null "> and sl.capacity = #{capacity}</if>
        <if test="volumeCapacity != null "> and sl.volume_capacity = #{volumeCapacity}</if>
        <if test="allowedHazardLevels != null  and allowedHazardLevels != ''"> and sl.allowed_hazard_levels = #{allowedHazardLevels}</if>
        <if test="allowedCategoryIds != null  and allowedCategoryIds != ''"> and sl.allowed_category_ids = #{allowedCategoryIds}</if>
        <if test="temperatureZone != null  and temperatureZone != ''"> and sl.temperature_zone = #{temperatureZone}</if>
        <if test="isEnabled != null "> and sl.is_enabled = #{isEnabled}</if>
        <if test="sortNo != null "> and sl.sort_no = #{sortNo}</if>
        <if test="createUserCode != null  and createUserCode != ''"> and sl.create_user_code = #{createUserCode}</if>
        <if test="updateUserCode != null  and updateUserCode != ''"> and sl.update_user_code = #{updateUserCode}</if>
        <if test="putawayOrder != null "> and sl.putaway_order = #{putawayOrder}</if>
        <if test="pickingOrder != null "> and sl.picking_order = #{pickingOrder}</if>
        <if test="LocationUsage != null  and LocationUsage != ''"> and sl.location_usage = #{LocationUsage}</if>
        <if test="locationHandling != null  and locationHandling != ''"> and sl.location_handling = #{locationHandling}</if>
        <if test="turnoverDemand != null  and turnoverDemand != ''"> and sl.turnover_demand = #{turnoverDemand}</if>
        <if test="pickingArea != null  and pickingArea != ''"> and sl.picking_area like concat('%', #{pickingArea}, '%')</if>
        <if test="warehousesId != null  and warehousesId != ''"> and sl.warehouses_id = #{warehousesId}</if>
        <if test="allowMixedProducts != null "> and sl.allow_mixed_products = #{allowMixedProducts}</if>
        <if test="allowMixedBatches != null "> and sl.allow_mixed_batches = #{allowMixedBatches}</if>
        <!-- 新增loading_area查询条件 -->
        <if test="loadingArea != null  and loadingArea != ''"> and sl.loading_area like concat('%', #{loadingArea}, '%')</if>
        order by sl.sort_no desc
    </select>

    <!-- 关联仓库表的列表查询（简化） -->
    <select id="selectStorageLocationsWithWarehousesList" parameterType="StorageLocations" resultMap="StorageLocationsWithWarehousesResult">
        <include refid="selectStorageLocationsWithWarehousesVo"/>
        <if test="locationCode != null  and locationCode != ''"> and sl.location_code = #{locationCode}</if>
        <if test="locationName != null  and locationName != ''"> and sl.location_name like concat('%', #{locationName}, '%')</if>
        <if test="warehousesCode != null  and warehousesCode != ''"> and sl.warehouses_code = #{warehousesCode}</if>
        <if test="locationType != null "> and sl.location_type = #{locationType}</if>
        <if test="zoneCode != null  and zoneCode != ''"> and sl.zone_code = #{zoneCode}</if>
        <if test="warehousesName != null  and warehousesName != ''"> and w.warehouses_name like concat('%', #{warehousesName}, '%')</if>
        <if test="warehousesManager != null  and warehousesManager != ''"> and w.warehouses_manager = #{warehousesManager}</if>

        <if test="warehousesId != null  and warehousesId != ''"> and sl.warehouses_id = #{warehousesId}</if>
        <if test="putawayOrder != null "> and sl.putaway_order = #{putawayOrder}</if>
        <if test="pickingOrder != null "> and sl.picking_order = #{pickingOrder}</if>
        <if test="LocationUsage != null  and LocationUsage != ''"> and sl.location_usage = #{LocationUsage}</if>
        <if test="locationHandling != null  and locationHandling != ''"> and sl.location_handling = #{locationHandling}</if>
        <if test="turnoverDemand != null  and turnoverDemand != ''"> and sl.turnover_demand = #{turnoverDemand}</if>
        <if test="pickingArea != null  and pickingArea != ''"> and sl.picking_area = #{pickingArea}</if>
        <if test="allowMixedProducts != null "> and sl.allow_mixed_products = #{allowMixedProducts}</if>
        <if test="allowMixedBatches != null "> and sl.allow_mixed_batches = #{allowMixedBatches}</if>
        <!-- 新增loading_area查询条件 -->
        <if test="loadingArea != null  and loadingArea != ''"> and sl.loading_area = #{loadingArea}</if>
        <!-- 按sort_no降序排序 -->
        order by sl.sort_no desc
    </select>

    <!-- 根据ID查询（调整：保留where，单独条件） -->
    <select id="selectStorageLocationsById" parameterType="String" resultMap="StorageLocationsResult">
        select sl.id, sl.location_code, sl.location_name, sl.warehouses_code, sl.location_type,
               sl.zone_code, sl.row_code, sl.column_code, sl.layer_code, sl.capacity,
               sl.volume_capacity, sl.allowed_hazard_levels, sl.allowed_category_ids,
               sl.temperature_zone, sl.is_enabled, sl.is_used, sl.sort_no,
               sl.create_time, sl.create_user_code, sl.update_time, sl.update_user_code, sl.warehouses_id,
               -- 新增字段查询
               sl.putaway_order, sl.picking_order, sl.location_usage,
               sl.location_handling, sl.turnover_demand, sl.picking_area,
               sl.allow_mixed_products, sl.allow_mixed_batches,
               -- 新增loading_area字段查询
               sl.loading_area
        from storage_locations sl
        where sl.id = #{id}
    </select>

    <select id="selectStorageLocationsByNameAndWarehouse" resultMap="StorageLocationsResult">
        select sl.id, sl.location_code, sl.location_name, sl.warehouses_code, sl.location_type,
               sl.zone_code, sl.row_code, sl.column_code, sl.layer_code, sl.capacity,
               sl.volume_capacity, sl.allowed_hazard_levels, sl.allowed_category_ids,
               sl.temperature_zone, sl.is_enabled, sl.is_used, sl.sort_no,
               sl.create_time, sl.create_user_code, sl.update_time, sl.update_user_code, sl.warehouses_id
        from storage_locations sl
        where sl.is_used = 1
          and sl.location_name = #{locationName}
          and sl.warehouses_id = #{warehouseId}
            limit 1
    </select>

    <!-- 关联仓库表的ID查询 -->
    <select id="selectStorageLocationsByIdWithWarehouses" parameterType="String" resultMap="StorageLocationsWithWarehousesResult">
        select sl.id, sl.location_code, sl.location_name, sl.warehouses_code, sl.location_type,
               sl.zone_code, sl.row_code, sl.column_code, sl.layer_code, sl.capacity,
               sl.volume_capacity, sl.allowed_hazard_levels, sl.allowed_category_ids,
               sl.temperature_zone, sl.is_enabled, sl.is_used, sl.sort_no,
               sl.create_time, sl.create_user_code, sl.update_time, sl.update_user_code, sl.warehouses_id,
               -- 新增字段查询
               sl.putaway_order, sl.picking_order, sl.location_usage,
               sl.location_handling, sl.turnover_demand, sl.picking_area,
               sl.allow_mixed_products, sl.allow_mixed_batches,
               -- 新增loading_area字段查询
               sl.loading_area,
               w.warehouses_name, w.warehouses_address, w.warehouses_manager, w.warehouses_phone
        from storage_locations sl
                 left join warehouses w on sl.warehouses_code = w.warehouses_code
        where sl.id = #{id}
    </select>

    <!-- 根据仓库编码查询（简化） -->
    <select id="selectStorageLocationsByWarehousesCode" parameterType="String" resultMap="StorageLocationsResult">
        <include refid="selectStorageLocationsVo"/>
        and sl.warehouses_code = #{warehousesCode}
        <!-- 按sort_no降序排序 -->
        order by sl.sort_no desc
    </select>

    <!-- 关联仓库表的仓库编码查询（简化） -->
    <select id="selectStorageLocationsByWarehousesCodeWithWarehouses" parameterType="String" resultMap="StorageLocationsWithWarehousesResult">
        <include refid="selectStorageLocationsWithWarehousesVo"/>
        and sl.warehouses_code = #{warehousesCode}
        <!-- 按sort_no降序排序 -->
        order by sl.sort_no desc
    </select>

    <!-- 根据仓库编码列表查询（简化） -->
    <select id="selectStorageLocationsByWarehousesCodes" parameterType="String" resultMap="StorageLocationsResult">
        <include refid="selectStorageLocationsVo"/>
        and sl.warehouses_code in
        <foreach item="id" collection="list" open="(" separator="," close=")">
            #{id}
        </foreach>
        <!-- 按sort_no降序排序 -->
        order by sl.sort_no desc
    </select>

    <!-- 关联仓库表的编码列表查询（简化） -->
    <select id="selectStorageLocationsByWarehousesCodesWithWarehouses" parameterType="String" resultMap="StorageLocationsWithWarehousesResult">
        <include refid="selectStorageLocationsWithWarehousesVo"/>
        and sl.warehouses_code in
        <foreach item="id" collection="list" open="(" separator="," close=")">
            #{id}
        </foreach>
        <!-- 按sort_no降序排序 -->
        order by sl.sort_no desc
    </select>

    <!--    获取库位表 的 location_code 编码 location_name 做成字典-->
    <select id="getMapList" parameterType="StorageLocations" resultType="java.util.Map">
        select id, IFNULL(location_name, '') as location_name from storage_locations where is_used = 1
        <if test="warehousesCode != null  and warehousesCode != ''"> and warehouses_id = #{warehousesCode}</if>
        <!-- 按sort_no降序排序 -->
        order by sort_no desc
    </select>

    <!-- 关联仓库的字典查询 -->
    <select id="getMapListWithWarehouses" parameterType="StorageLocations" resultType="java.util.Map">
        select sl.location_code, IFNULL(sl.location_name, '') as location_name, IFNULL(w.warehouses_name, '') as warehouses_name
        from storage_locations sl
        left join warehouses w on sl.warehouses_code = w.warehouses_code
        where sl.is_used = 1
        <if test="warehousesCode != null  and warehousesCode != ''"> and sl.warehouses_code = #{warehousesCode}</if>
        <!-- 按sort_no降序排序 -->
        order by sl.sort_no desc
    </select>

    <!-- 原有新增/更新/删除方法（仅添加新字段） -->
    <insert id="insertStorageLocations" parameterType="StorageLocations">
        insert into storage_locations
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="locationCode != null">location_code,</if>
            <if test="locationName != null">location_name,</if>
            <if test="warehousesCode != null">warehouses_code,</if>
            <if test="locationType != null">location_type,</if>
            <if test="zoneCode != null">zone_code,</if>
            <if test="rowCode != null">row_code,</if>
            <if test="columnCode != null">column_code,</if>
            <if test="layerCode != null">layer_code,</if>
            <if test="capacity != null">capacity,</if>
            <if test="volumeCapacity != null">volume_capacity,</if>
            <if test="allowedHazardLevels != null">allowed_hazard_levels,</if>
            <if test="allowedCategoryIds != null">allowed_category_ids,</if>
            <if test="temperatureZone != null">temperature_zone,</if>
            <if test="isEnabled != null">is_enabled,</if>
            <if test="isUsed != null">is_used,</if>
            <if test="sortNo != null">sort_no,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createUserCode != null">create_user_code,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateUserCode != null">update_user_code,</if>
            <if test="warehousesId != null">warehouses_id,</if>
            <!-- 新增字段插入 -->
            <if test="putawayOrder != null">putaway_order,</if>
            <if test="pickingOrder != null">picking_order,</if>
            <if test="LocationUsage != null">location_usage,</if>
            <if test="locationHandling != null">location_handling,</if>
            <if test="turnoverDemand != null">turnover_demand,</if>
            <if test="pickingArea != null">picking_area,</if>
            <if test="allowMixedProducts != null">allow_mixed_products,</if>
            <if test="allowMixedBatches != null">allow_mixed_batches,</if>
            <!-- 新增loading_area字段插入 -->
            <if test="loadingArea != null">loading_area,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">#{id},</if>
            <if test="locationCode != null">#{locationCode},</if>
            <if test="locationName != null">#{locationName},</if>
            <if test="warehousesCode != null">#{warehousesCode},</if>
            <if test="locationType != null">#{locationType},</if>
            <if test="zoneCode != null">#{zoneCode},</if>
            <if test="rowCode != null">#{rowCode},</if>
            <if test="columnCode != null">#{columnCode},</if>
            <if test="layerCode != null">#{layerCode},</if>
            <if test="capacity != null">#{capacity},</if>
            <if test="volumeCapacity != null">#{volumeCapacity},</if>
            <if test="allowedHazardLevels != null">#{allowedHazardLevels},</if>
            <if test="allowedCategoryIds != null">#{allowedCategoryIds},</if>
            <if test="temperatureZone != null">#{temperatureZone},</if>
            <if test="isEnabled != null">#{isEnabled},</if>
            <if test="isUsed != null">#{isUsed},</if>
            <if test="sortNo != null">#{sortNo},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createUserCode != null">#{createUserCode},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateUserCode != null">#{updateUserCode},</if>
            <if test="warehousesId != null">#{warehousesId},</if>
            <!-- 新增字段值 -->
            <if test="putawayOrder != null">#{putawayOrder},</if>
            <if test="pickingOrder != null">#{pickingOrder},</if>
            <if test="LocationUsage != null">#{LocationUsage},</if>
            <if test="locationHandling != null">#{locationHandling},</if>
            <if test="turnoverDemand != null">#{turnoverDemand},</if>
            <if test="pickingArea != null">#{pickingArea},</if>
            <if test="allowMixedProducts != null">#{allowMixedProducts},</if>
            <if test="allowMixedBatches != null">#{allowMixedBatches},</if>
            <!-- 新增loading_area字段值 -->
            <if test="loadingArea != null">#{loadingArea},</if>
        </trim>
    </insert>

    <!-- 新增批量插入库位信息方法 -->
    <insert id="batchInsertStorageLocations" parameterType="java.util.List">
        insert into storage_locations (
        id, location_code, location_name, warehouses_code, location_type,
        zone_code, row_code, column_code, layer_code, capacity,
        volume_capacity, allowed_hazard_levels, allowed_category_ids, temperature_zone,
        is_enabled, is_used, sort_no, create_time, create_user_code,
        update_time, update_user_code, warehouses_id, putaway_order, picking_order,
        location_usage, location_handling, turnover_demand, picking_area,
        allow_mixed_products, allow_mixed_batches,
        -- 新增loading_area字段
        loading_area
        ) VALUES
        <foreach collection="list" item="item" separator=",">
            (
            #{item.id}, #{item.locationCode}, #{item.locationName}, #{item.warehousesCode}, #{item.locationType},
            #{item.zoneCode}, #{item.rowCode}, #{item.columnCode}, #{item.layerCode}, #{item.capacity},
            #{item.volumeCapacity}, #{item.allowedHazardLevels}, #{item.allowedCategoryIds}, #{item.temperatureZone},
            #{item.isEnabled}, #{item.isUsed}, #{item.sortNo}, #{item.createTime}, #{item.createUserCode},
            #{item.updateTime}, #{item.updateUserCode}, #{item.warehousesId}, #{item.putawayOrder}, #{item.pickingOrder},
            #{item.LocationUsage}, #{item.locationHandling}, #{item.turnoverDemand}, #{item.pickingArea},
            #{item.allowMixedProducts}, #{item.allowMixedBatches},
            -- 新增loading_area字段值
            #{item.loadingArea}
            )
        </foreach>
    </insert>

    <update id="updateStorageLocations" parameterType="StorageLocations">
        update storage_locations
        <trim prefix="SET" suffixOverrides=",">
            <if test="locationCode != null">location_code = #{locationCode},</if>
            <if test="locationName != null">location_name = #{locationName},</if>
            <if test="warehousesCode != null">warehouses_code = #{warehousesCode},</if>
            <if test="locationType != null">location_type = #{locationType},</if>
            <if test="zoneCode != null">zone_code = #{zoneCode},</if>
            <if test="rowCode != null">row_code = #{rowCode},</if>
            <if test="columnCode != null">column_code = #{columnCode},</if>
            <if test="layerCode != null">layer_code = #{layerCode},</if>
            <if test="capacity != null">capacity = #{capacity},</if>
            <if test="volumeCapacity != null">volume_capacity = #{volumeCapacity},</if>
            <if test="allowedHazardLevels != null">allowed_hazard_levels = #{allowedHazardLevels},</if>
            <if test="allowedCategoryIds != null">allowed_category_ids = #{allowedCategoryIds},</if>
            <if test="temperatureZone != null">temperature_zone = #{temperatureZone},</if>
            <if test="isEnabled != null">is_enabled = #{isEnabled},</if>
            <if test="isUsed != null">is_used = #{isUsed},</if>
            <if test="sortNo != null">sort_no = #{sortNo},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createUserCode != null">create_user_code = #{createUserCode},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateUserCode != null">update_user_code = #{updateUserCode},</if>
            <!-- 新增字段更新 -->
            <if test="putawayOrder != null">putaway_order = #{putawayOrder},</if>
            <if test="pickingOrder != null">picking_order = #{pickingOrder},</if>
            <if test="LocationUsage != null">location_usage = #{LocationUsage},</if>
            <if test="locationHandling != null">location_handling = #{locationHandling},</if>
            <if test="turnoverDemand != null">turnover_demand = #{turnoverDemand},</if>
            <if test="pickingArea != null">picking_area = #{pickingArea},</if>
            <if test="allowMixedProducts != null">allow_mixed_products = #{allowMixedProducts},</if>
            <if test="allowMixedBatches != null">allow_mixed_batches = #{allowMixedBatches},</if>
            <!-- 新增loading_area字段更新 -->
            <if test="loadingArea != null">loading_area = #{loadingArea},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteStorageLocationsById" parameterType="String">
        update storage_locations set is_used = 0 where id = #{id}
    </delete>

    <delete id="deleteStorageLocationsByIds" parameterType="String">
        update storage_locations set is_used = 0 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <!-- getStorageLocationsList 简化 -->
    <select id="getStorageLocationsList" parameterType="StorageLocations" resultMap="StorageLocationsResult">
        <include refid="selectStorageLocationsVo"/>
        <if test="warehousesId != null  and warehousesId != ''"> and sl.warehouses_id = #{warehousesId}</if>
        <if test="locationCode != null  and locationCode != ''"> and sl.location_code = #{locationCode}</if>
        <if test="locationName != null  and locationName != ''"> and sl.location_name like concat('%', #{locationName}, '%')</if>
        <if test="warehousesCode != null  and warehousesCode != ''"> and sl.warehouses_code = #{warehousesCode}</if>
        <if test="locationType != null "> and sl.location_type = #{locationType}</if>
        <if test="zoneCode != null  and zoneCode != ''"> and sl.zone_code = #{zoneCode}</if>
        <if test="rowCode != null  and rowCode != ''"> and sl.row_code = #{rowCode}</if>
        <if test="columnCode != null  and columnCode != ''"> and sl.column_code = #{columnCode}</if>
        <if test="layerCode != null  and layerCode != ''"> and sl.layer_code = #{layerCode}</if>
        <if test="capacity != null "> and sl.capacity = #{capacity}</if>
        <if test="volumeCapacity != null "> and sl.volume_capacity = #{volumeCapacity}</if>
        <if test="allowedHazardLevels != null  and allowedHazardLevels != ''"> and sl.allowed_hazard_levels = #{allowedHazardLevels}</if>
        <if test="allowedCategoryIds != null  and allowedCategoryIds != ''"> and sl.allowed_category_ids = #{allowedCategoryIds}</if>
        <if test="temperatureZone != null  and temperatureZone != ''"> and sl.temperature_zone = #{temperatureZone}</if>
        <if test="isEnabled != null "> and sl.is_enabled = #{isEnabled}</if>
        <if test="sortNo != null "> and sl.sort_no = #{sortNo}</if>
        <if test="createUserCode != null  and createUserCode != ''"> and sl.create_user_code = #{createUserCode}</if>
        <if test="updateUserCode != null  and updateUserCode != ''"> and sl.update_user_code = #{updateUserCode}</if>
        <!-- 新增字段查询条件 -->
        <if test="putawayOrder != null "> and sl.putaway_order = #{putawayOrder}</if>
        <if test="pickingOrder != null "> and sl.picking_order = #{pickingOrder}</if>
        <if test="LocationUsage != null  and LocationUsage != ''"> and sl.location_usage = #{LocationUsage}</if>
        <if test="locationHandling != null  and locationHandling != ''"> and sl.location_handling = #{locationHandling}</if>
        <if test="turnoverDemand != null  and turnoverDemand != ''"> and sl.turnover_demand = #{turnoverDemand}</if>
        <if test="pickingArea != null  and pickingArea != ''"> and sl.picking_area = #{pickingArea}</if>
        <if test="allowMixedProducts != null "> and sl.allow_mixed_products = #{allowMixedProducts}</if>
        <if test="allowMixedBatches != null "> and sl.allow_mixed_batches = #{allowMixedBatches}</if>
        <!-- 新增loading_area查询条件 -->
        <if test="loadingArea != null  and loadingArea != ''"> and sl.loading_area = #{loadingArea}</if>
        <!-- 按sort_no降序排序 -->
        order by sl.sort_no desc
    </select>

    <!-- 关联仓库的getStorageLocationsList -->
    <select id="getStorageLocationsListWithWarehouses" parameterType="StorageLocations" resultMap="StorageLocationsWithWarehousesResult">
        <include refid="selectStorageLocationsWithWarehousesVo"/>
        <if test="warehousesId != null  and warehousesId != ''"> and sl.warehouses_id = #{warehousesId}</if>
        <if test="locationCode != null  and locationCode != ''"> and sl.location_code = #{locationCode}</if>
        <if test="locationName != null  and locationName != ''"> and sl.location_name like concat('%', #{locationName}, '%')</if>
        <if test="warehousesCode != null  and warehousesCode != ''"> and sl.warehouses_code = #{warehousesCode}</if>
        <if test="locationType != null "> and sl.location_type = #{locationType}</if>
        <if test="zoneCode != null  and zoneCode != ''"> and sl.zone_code = #{zoneCode}</if>
        <if test="warehousesName != null  and warehousesName != ''"> and w.warehouses_name like concat('%', #{warehousesName}, '%')</if>
        <!-- 新增字段查询条件 -->
        <if test="putawayOrder != null "> and sl.putaway_order = #{putawayOrder}</if>
        <if test="pickingOrder != null "> and sl.picking_order = #{pickingOrder}</if>
        <if test="LocationUsage != null  and LocationUsage != ''"> and sl.location_usage = #{LocationUsage}</if>
        <if test="locationHandling != null  and locationHandling != ''"> and sl.location_handling = #{locationHandling}</if>
        <if test="turnoverDemand != null  and turnoverDemand != ''"> and sl.turnover_demand = #{turnoverDemand}</if>
        <if test="pickingArea != null  and pickingArea != ''"> and sl.picking_area = #{pickingArea}</if>
        <if test="allowMixedProducts != null "> and sl.allow_mixed_products = #{allowMixedProducts}</if>
        <if test="allowMixedBatches != null "> and sl.allow_mixed_batches = #{allowMixedBatches}</if>
        <!-- 新增loading_area查询条件 -->
        <if test="loadingArea != null  and loadingArea != ''"> and sl.loading_area = #{loadingArea}</if>
        <!-- 按sort_no降序排序 -->
        order by sl.sort_no desc
    </select>

</mapper>