<?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 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"    />
    </resultMap>

    <sql id="selectStorageLocationsVo">
        select 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 from storage_locations
    </sql>

    <select id="selectStorageLocationsList" parameterType="StorageLocations" resultMap="StorageLocationsResult">
        <include refid="selectStorageLocationsVo"/>
        where is_used=1
            <if test="locationCode != null  and locationCode != ''"> and location_code = #{locationCode}</if>
            <if test="locationName != null  and locationName != ''"> and location_name like concat('%', #{locationName}, '%')</if>
            <if test="warehousesCode != null  and warehousesCode != ''"> and warehouses_code = #{warehousesCode}</if>
            <if test="locationType != null "> and location_type = #{locationType}</if>
            <if test="zoneCode != null  and zoneCode != ''"> and zone_code = #{zoneCode}</if>
            <if test="rowCode != null  and rowCode != ''"> and row_code = #{rowCode}</if>
            <if test="columnCode != null  and columnCode != ''"> and column_code = #{columnCode}</if>
            <if test="layerCode != null  and layerCode != ''"> and layer_code = #{layerCode}</if>
            <if test="capacity != null "> and capacity = #{capacity}</if>
            <if test="volumeCapacity != null "> and volume_capacity = #{volumeCapacity}</if>
            <if test="allowedHazardLevels != null  and allowedHazardLevels != ''"> and allowed_hazard_levels = #{allowedHazardLevels}</if>
            <if test="allowedCategoryIds != null  and allowedCategoryIds != ''"> and allowed_category_ids = #{allowedCategoryIds}</if>
            <if test="temperatureZone != null  and temperatureZone != ''"> and temperature_zone = #{temperatureZone}</if>
            <if test="isEnabled != null "> and is_enabled = #{isEnabled}</if>
            <if test="sortNo != null "> and sort_no = #{sortNo}</if>
            <if test="createUserCode != null  and createUserCode != ''"> and create_user_code = #{createUserCode}</if>
            <if test="updateUserCode != null  and updateUserCode != ''"> and update_user_code = #{updateUserCode}</if>

    </select>

    <select id="selectStorageLocationsById" parameterType="String" resultMap="StorageLocationsResult">
        <include refid="selectStorageLocationsVo"/>
        where id = #{id}
    </select>
    <select id="selectStorageLocationsByWarehousesCode" parameterType="String" resultMap="StorageLocationsResult">
        <include refid="selectStorageLocationsVo"/>
        where warehouses_code = #{warehousesCode}
    </select>
    <select id="selectStorageLocationsByWarehousesCodes" parameterType="String" resultMap="StorageLocationsResult">
        <include refid="selectStorageLocationsVo"/>
        where warehouses_code in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{warehousesCodes}
        </foreach>
    </select>
<!--    获取库位表 的 location_code 编码 location_name 做成字典-->
    <select id="getMapList" parameterType="StorageLocations" resultType="java.util.Map">
        select location_code, IFNULL(location_name, '') as location_name from storage_locations where is_used = 1
        <if test="warehousesCode != null  and warehousesCode != ''"> and warehouses_code = #{warehousesCode}</if>
    </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>
         </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>
         </trim>
    </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>
        </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>

    <select id="getStorageLocationsList" parameterType="StorageLocations" resultMap="StorageLocationsResult">
        <include refid="selectStorageLocationsVo"/>
        where is_used=1
        <if test="warehousesId != null  and warehousesId != ''"> and warehouses_id = #{warehousesId}</if>
        <if test="locationCode != null  and locationCode != ''"> and location_code = #{locationCode}</if>
        <if test="locationName != null  and locationName != ''"> and location_name like concat('%', #{locationName}, '%')</if>
        <if test="warehousesCode != null  and warehousesCode != ''"> and warehouses_code = #{warehousesCode}</if>
        <if test="locationType != null "> and location_type = #{locationType}</if>
        <if test="zoneCode != null  and zoneCode != ''"> and zone_code = #{zoneCode}</if>
        <if test="rowCode != null  and rowCode != ''"> and row_code = #{rowCode}</if>
        <if test="columnCode != null  and columnCode != ''"> and column_code = #{columnCode}</if>
        <if test="layerCode != null  and layerCode != ''"> and layer_code = #{layerCode}</if>
        <if test="capacity != null "> and capacity = #{capacity}</if>
        <if test="volumeCapacity != null "> and volume_capacity = #{volumeCapacity}</if>
        <if test="allowedHazardLevels != null  and allowedHazardLevels != ''"> and allowed_hazard_levels = #{allowedHazardLevels}</if>
        <if test="allowedCategoryIds != null  and allowedCategoryIds != ''"> and allowed_category_ids = #{allowedCategoryIds}</if>
        <if test="temperatureZone != null  and temperatureZone != ''"> and temperature_zone = #{temperatureZone}</if>
        <if test="isEnabled != null "> and is_enabled = #{isEnabled}</if>
        <if test="sortNo != null "> and sort_no = #{sortNo}</if>
        <if test="createUserCode != null  and createUserCode != ''"> and create_user_code = #{createUserCode}</if>
        <if test="updateUserCode != null  and updateUserCode != ''"> and update_user_code = #{updateUserCode}</if>

    </select>
</mapper>