<?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.shkj.wms.mapper.BaseAreaMapper">

    <resultMap type="com.shkj.wms.vo.BaseAreaListVo" id="BaseAreaResult">
            <result property="id" column="id"/>
            <result property="storageId" column="storage_id"/>
            <result property="areaCode" column="area_code"/>
            <result property="areaName" column="area_name"/>
            <result property="pickmode" column="pickmode"/>
            <result property="taskmode" column="taskmode"/>
            <result property="pickgroup" column="pickgroup"/>
            <result property="isDouboper" column="is_douboper"/>
            <result property="extend1" column="extend1"/>
            <result property="extend2" column="extend2"/>
            <result property="extend3" column="extend3"/>
            <result property="extend4" column="extend4"/>
            <result property="extend5" column="extend5"/>
            <result property="remark" column="remark"/>
            <result property="branchId" column="branch_id"/>
            <result property="isDel" column="is_del"/>
            <result property="createTime" column="create_time"/>
            <result property="createBy" column="create_by"/>
            <result property="updateTime" column="update_time"/>
            <result property="updateBy" column="update_by"/>

            <result property="storageCode" column="storage_code"/>
            <result property="storageType" column="storage_type"/>
            <result property="storageName" column="storage_name"/>
    </resultMap>

    <resultMap type="com.shkj.wms.vo.BaseAreaNoOtherVo" id="BaseAreaNoOtherResult">
        <result property="id" column="id"/>
        <result property="storageId" column="storage_id"/>
        <result property="areaCode" column="area_code"/>
        <result property="areaName" column="area_name"/>
        <result property="pickmode" column="pickmode"/>
        <result property="taskmode" column="taskmode"/>
        <result property="pickgroup" column="pickgroup"/>
        <result property="isDouboper" column="is_douboper"/>
        <result property="extend1" column="extend1"/>
        <result property="extend2" column="extend2"/>
        <result property="extend3" column="extend3"/>
        <result property="extend4" column="extend4"/>
        <result property="extend5" column="extend5"/>
        <result property="remark" column="remark"/>
        <result property="branchId" column="branch_id"/>
        <result property="isDel" column="is_del"/>
        <result property="createTime" column="create_time"/>
        <result property="createBy" column="create_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="updateBy" column="update_by"/>

        <result property="storageCode" column="storage_code"/>
    </resultMap>

        <select id="queryBaseAreaAndStorageList" resultMap="BaseAreaResult">
                SELECT
                    ba.*,
                    bs.storage_code,
                    bs.storage_type,
                    bs.storage_name
                FROM
                    base_area ba
                LEFT JOIN base_storage bs ON ba.storage_id = bs.id
                where ba.branch_id = #{branchId}
        </select>

    <select id="queryBaseAreaList" resultMap="BaseAreaNoOtherResult">
                SELECT
                    ba.*,
                    bs.storage_code,
                    bs.storage_name
                FROM
                base_area ba
                JOIN base_storage bs ON ba.storage_id = bs.id
                WHERE
                ba.is_del = '0'
                <if test="storageId != null">
                    and ba.storage_id = #{storageId}
                </if>
                <if test="taskmode != null">
                    and ba.task_mode = #{taskmode}
                </if>
                <if test="isActivity != null">
                    and ba.is_activity = #{isActivity}
                </if>
                <if test="areaType != null">
                    and ba.area_type = #{areaType}
                </if>
                <if test="areaCode != null">
                    AND LOWER(ba.area_code) like LOWER(concat('%', #{areaCode}, '%'))
                </if>
                ${branchParams.dataScopeBranch}
                ORDER BY ba.create_time desc
    </select>
</mapper>