<?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.manage.mapper.BaseLocationMapper">

    <resultMap type="BaseLocation" id="BaseLocationResult">
        <result property="objid" column="objid"/>
        <result property="storeId" column="store_id"/>
        <result property="locationCode" column="location_code"/>
        <result property="storageQuantity" column="storage_quantity"/>
        <result property="isEnable" column="is_enable"/>
        <result property="remark" column="remark"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="stoteTag" column="stote_tag"/>
        <association property="baseStore"   javaType="com.ruoyi.manage.domain.BaseStore"        >
            <result property="storeName" column="store_name"/>
        </association>
    </resultMap>

    <sql id="selectBaseLocationVo">
        select objid,
               bl.store_id,
               location_code,
               storage_quantity,
               bl.is_enable,
               bl.remark,
               bl.create_by,
               bl.create_time,
               bl.update_by,
               bl.update_time,
               stote_tag,
               bs.store_name
        from base_location bl
                 left join base_store bs on bl.store_id = bs.store_id

    </sql>

    <select id="selectBaseLocationList" parameterType="BaseLocation" resultMap="BaseLocationResult">
        <include refid="selectBaseLocationVo"/>
        <where>
            <if test="storeId != null ">and bl.store_id = #{storeId}</if>
            <if test="locationCode != null  and locationCode != ''">and location_code = #{locationCode}</if>
            <if test="isEnable != null  and isEnable != ''">and bl.is_enable = #{isEnable}</if>
            <if test="stoteTag != null ">and stote_tag = #{stoteTag}</if>
        </where>
    </select>

    <select id="selectBaseLocationByObjid" parameterType="Long" resultMap="BaseLocationResult">
        <include refid="selectBaseLocationVo"/>
        where objid = #{objid}
    </select>

    <insert id="insertBaseLocation" parameterType="BaseLocation" useGeneratedKeys="true" keyProperty="objid">
        insert into base_location
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="storeId != null">store_id,</if>
            <if test="locationCode != null">location_code,</if>
            <if test="storageQuantity != null">storage_quantity,</if>
            <if test="isEnable != null">is_enable,</if>
            <if test="remark != null">remark,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="stoteTag != null">stote_tag,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="storeId != null">#{storeId},</if>
            <if test="locationCode != null">#{locationCode},</if>
            <if test="storageQuantity != null">#{storageQuantity},</if>
            <if test="isEnable != null">#{isEnable},</if>
            <if test="remark != null">#{remark},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="stoteTag != null">#{stoteTag},</if>
        </trim>
    </insert>

    <update id="updateBaseLocation" parameterType="BaseLocation">
        update base_location
        <trim prefix="SET" suffixOverrides=",">
            <if test="storeId != null">store_id = #{storeId},</if>
            <if test="locationCode != null">location_code = #{locationCode},</if>
            <if test="storageQuantity != null">storage_quantity = #{storageQuantity},</if>
            <if test="isEnable != null">is_enable = #{isEnable},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="stoteTag != null">stote_tag = #{stoteTag},</if>
        </trim>
        where objid = #{objid}
    </update>

    <delete id="deleteBaseLocationByObjid" parameterType="Long">
        delete
        from base_location
        where objid = #{objid}
    </delete>

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

</mapper>