<?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.StorageLocationsCategoryMapper">
    
    <resultMap type="StorageLocationsCategory" id="StorageLocationsCategoryResult">
        <result property="id"    column="id"    />
        <result property="locationCode"    column="location_code"    />
        <result property="warehousesCode"    column="warehouses_code"    />
        <result property="categoryId"    column="category_id"    />
        <result property="categoryName"    column="category_name"    />
        <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"    />
    </resultMap>

    <sql id="selectStorageLocationsCategoryVo">
        select id, location_code, warehouses_code, category_id, category_name, sort_no, create_time, create_user_code, update_time, update_user_code from storage_locations_category
    </sql>

    <select id="selectStorageLocationsCategoryList" parameterType="StorageLocationsCategory" resultMap="StorageLocationsCategoryResult">
        <include refid="selectStorageLocationsCategoryVo"/>
        <where>  
            <if test="locationCode != null  and locationCode != ''"> and location_code = #{locationCode}</if>
            <if test="warehousesCode != null  and warehousesCode != ''"> and warehouses_code = #{warehousesCode}</if>
            <if test="categoryId != null  and categoryId != ''"> and category_id = #{categoryId}</if>
            <if test="categoryName != null  and categoryName != ''"> and category_name like concat('%', #{categoryName}, '%')</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>
        </where>
    </select>
    
    <select id="selectStorageLocationsCategoryById" parameterType="String" resultMap="StorageLocationsCategoryResult">
        <include refid="selectStorageLocationsCategoryVo"/>
        where id = #{id}
    </select>

    <insert id="insertStorageLocationsCategory" parameterType="StorageLocationsCategory">
        insert into storage_locations_category
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="locationCode != null">location_code,</if>
            <if test="warehousesCode != null">warehouses_code,</if>
            <if test="categoryId != null">category_id,</if>
            <if test="categoryName != null">category_name,</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="warehousesCode != null">#{warehousesCode},</if>
            <if test="categoryId != null">#{categoryId},</if>
            <if test="categoryName != null">#{categoryName},</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="updateStorageLocationsCategory" parameterType="StorageLocationsCategory">
        update storage_locations_category
        <trim prefix="SET" suffixOverrides=",">
            <if test="locationCode != null">location_code = #{locationCode},</if>
            <if test="warehousesCode != null">warehouses_code = #{warehousesCode},</if>
            <if test="categoryId != null">category_id = #{categoryId},</if>
            <if test="categoryName != null">category_name = #{categoryName},</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="deleteStorageLocationsCategoryById" parameterType="String">
        delete from storage_locations_category where id = #{id}
    </delete>

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


</mapper>