<?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.zbf.system.mapper.TBaseStorageAreaMapper">

    <resultMap type="TBaseStorageArea" id="TBaseStorageAreaResult">
            <result property="id"    column="id"    />
            <result property="storageAreaId"    column="storage_area_id"    />
            <result property="storageAreaName"    column="storage_area_name"    />
            <result property="storageAreaShortName"    column="storage_area_short_name"    />
            <result property="pyName"    column="py_name"    />
            <result property="storageId"    column="storage_id"    />
            <result property="sort"    column="sort"    />
            <result property="status"    column="status"    />
            <result property="remark"    column="remark"    />
            <result property="createTime"    column="create_time"    />
            <result property="createBy"    column="create_by"    />
            <result property="updateTime"    column="update_time"    />
            <result property="updateBy"    column="update_by"    />
    </resultMap>

    <sql id="selectTBaseStorageAreaVo">
        select id, storage_area_id, storage_area_name, storage_area_short_name, py_name, storage_id, sort, status, remark, create_time, create_by, update_time, update_by from t_base_storage_area d
    </sql>
    <select id="selectTBaseStorageAreaList" parameterType="TBaseStorageArea" resultMap="TBaseStorageAreaResult">
        <include refid="selectTBaseStorageAreaVo"/>
        <where>
                        <if test="storageAreaId != null  and storageAreaId != ''"> and storage_area_id = #{storageAreaId}</if>
                        <if test="storageAreaName != null  and storageAreaName != ''"> and storage_area_name like concat('%', #{storageAreaName}, '%')</if>
                        <if test="storageAreaShortName != null  and storageAreaShortName != ''"> and storage_area_short_name like concat('%', #{storageAreaShortName}, '%')</if>
                        <if test="pyName != null  and pyName != ''"> and py_name like concat('%', #{pyName}, '%')</if>
                        <if test="storageId != null  and storageId != ''"> and storage_id = #{storageId}</if>
                        <if test="sort != null "> and sort = #{sort}</if>
                        <if test="status != null "> and status = #{status}</if>
                        <if test="selectIds !=null and selectIds.length>0">
                            and id in
                            <foreach collection="selectIds" item="itemId" open="(" close=")" separator=",">
                                #{itemId}
                            </foreach>
                        </if>
            ${params.dataScope}
        </where>
        order by id asc
    </select>

    <select id="selectTBaseStorageAreaById" parameterType="Long" resultMap="TBaseStorageAreaResult">
            <include refid="selectTBaseStorageAreaVo"/>
            where id = #{id}
    </select>

    <insert id="insertTBaseStorageArea" parameterType="TBaseStorageArea">
        insert into t_base_storage_area
        <trim prefix="(" suffix=")" suffixOverrides=",">
                    <if test="id != null">id,</if>
                    <if test="storageAreaId != null and storageAreaId != ''">storage_area_id,</if>
                    <if test="storageAreaName != null">storage_area_name,</if>
                    <if test="storageAreaShortName != null">storage_area_short_name,</if>
                    <if test="pyName != null">py_name,</if>
                    <if test="storageId != null">storage_id,</if>
                    <if test="sort != null">sort,</if>
                    <if test="status != null">status,</if>
                    <if test="remark != null">remark,</if>
                    <if test="createTime != null">create_time,</if>
                    <if test="createBy != null">create_by,</if>
                    <if test="updateTime != null">update_time,</if>
                    <if test="updateBy != null">update_by,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                    <if test="id != null">#{id},</if>
                    <if test="storageAreaId != null and storageAreaId != ''">#{storageAreaId},</if>
                    <if test="storageAreaName != null">#{storageAreaName},</if>
                    <if test="storageAreaShortName != null">#{storageAreaShortName},</if>
                    <if test="pyName != null">#{pyName},</if>
                    <if test="storageId != null">#{storageId},</if>
                    <if test="sort != null">#{sort},</if>
                    <if test="status != null">#{status},</if>
                    <if test="remark != null">#{remark},</if>
                    <if test="createTime != null">#{createTime},</if>
                    <if test="createBy != null">#{createBy},</if>
                    <if test="updateTime != null">#{updateTime},</if>
                    <if test="updateBy != null">#{updateBy},</if>
        </trim>
    </insert>

    <update id="updateTBaseStorageArea" parameterType="TBaseStorageArea">
        update t_base_storage_area
        <trim prefix="SET" suffixOverrides=",">
                    <if test="storageAreaId != null and storageAreaId != ''">storage_area_id = #{storageAreaId},</if>
                    <if test="storageAreaName != null">storage_area_name = #{storageAreaName},</if>
                    <if test="storageAreaShortName != null">storage_area_short_name = #{storageAreaShortName},</if>
                    <if test="pyName != null">py_name = #{pyName},</if>
                    <if test="storageId != null">storage_id = #{storageId},</if>
                    <if test="sort != null">sort = #{sort},</if>
                    <if test="status != null">status = #{status},</if>
                    <if test="remark != null">remark = #{remark},</if>
                    <if test="createTime != null">create_time = #{createTime},</if>
                    <if test="createBy != null">create_by = #{createBy},</if>
                    <if test="updateTime != null">update_time = #{updateTime},</if>
                    <if test="updateBy != null">update_by = #{updateBy},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="enableTBaseStorageAreaByIds" parameterType="String">
        update t_base_storage_area set status=0 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
    <update id="disabledTBaseStorageAreaByIds" parameterType="String">
        update t_base_storage_area set status=1 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

    <delete id="deleteTBaseStorageAreaById" parameterType="Long">
        delete from t_base_storage_area  where id = #{id}
    </delete>

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