<?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.BaseStoreMapper">
    
    <resultMap type="BaseStore" id="BaseStoreResult">
        <result property="storeId"    column="store_id"    />
        <result property="storeCode"    column="store_code"    />
        <result property="storeName"    column="store_name"    />
        <result property="isEnable"    column="is_enable"    />
        <result property="valueMin"    column="value_min"    />
        <result property="valueMax"    column="value_max"    />
        <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="storeTag"    column="store_tag"    />
    </resultMap>

    <sql id="selectBaseStoreVo">
        select store_id, store_code, store_name, is_enable, value_min, value_max, remark, create_by, create_time, update_by, update_time, store_tag from base_store
    </sql>

    <select id="selectStore"  resultMap="BaseStoreResult">
        <include refid="selectBaseStoreVo"/>
        where store_tag=1 and is_enable ='Y'
    </select>
       <select id="selectArea" resultMap="BaseStoreResult">
        <include refid="selectBaseStoreVo"/>
        where store_tag=2 and is_enable ='Y'
    </select>

    <select id="selectBaseStoreList" parameterType="BaseStore" resultMap="BaseStoreResult">
    <include refid="selectBaseStoreVo"/>
        <where>  
            <if test="storeCode != null  and storeCode != ''"> and store_code = #{storeCode}</if>
            <if test="storeName != null  and storeName != ''"> and store_name like concat('%', #{storeName}, '%')</if>
            <if test="isEnable != null  and isEnable != ''"> and is_enable = #{isEnable}</if>
            <if test="storeTag != null  and storeTag != ''"> and store_tag = #{storeTag}</if>
        </where>
    </select>
    
    <select id="selectBaseStoreByStoreId" parameterType="Long" resultMap="BaseStoreResult">
        <include refid="selectBaseStoreVo"/>
        where store_id = #{storeId}
    </select>
        
    <insert id="insertBaseStore" parameterType="BaseStore" useGeneratedKeys="true" keyProperty="storeId">
        insert into base_store
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="storeCode != null">store_code,</if>
            <if test="storeName != null">store_name,</if>
            <if test="isEnable != null">is_enable,</if>
            <if test="valueMin != null">value_min,</if>
            <if test="valueMax != null">value_max,</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="storeTag != null">store_tag,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="storeCode != null">#{storeCode},</if>
            <if test="storeName != null">#{storeName},</if>
            <if test="isEnable != null">#{isEnable},</if>
            <if test="valueMin != null">#{valueMin},</if>
            <if test="valueMax != null">#{valueMax},</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="storeTag != null">#{storeTag},</if>
         </trim>
    </insert>

    <update id="updateBaseStore" parameterType="BaseStore">
        update base_store
        <trim prefix="SET" suffixOverrides=",">
            <if test="storeCode != null">store_code = #{storeCode},</if>
            <if test="storeName != null">store_name = #{storeName},</if>
            <if test="isEnable != null">is_enable = #{isEnable},</if>
            <if test="valueMin != null">value_min = #{valueMin},</if>
            <if test="valueMax != null">value_max = #{valueMax},</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="storeTag != null">store_tag = #{storeTag},</if>
        </trim>
        where store_id = #{storeId}
    </update>

    <delete id="deleteBaseStoreByStoreId" parameterType="Long">
        delete from base_store where store_id = #{storeId}
    </delete>

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

</mapper>