<?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.unis.crk.basic.mapper.BasicWarehouseMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.unis.crk.basic.entity.BasicWarehouse">
        <id column="warehouse_id" property="warehouseId"/>
        <result column="depot_id" property="depotId"/>
        <result column="depot_name" property="depotName"/>
        <result column="storehouse_id" property="storehouseId"/>
        <result column="warehouse_code" property="warehouseCode"/>
        <result column="warehouse_name" property="warehouseName"/>
        <result column="warehouse_use_time" property="warehouseUseTime"/>
        <result column="warehouse_status" property="warehouseStatus"/>
        <result column="store_way" property="storeWay"/>
        <result column="length" property="length"/>
        <result column="width" property="width"/>
        <result column="heigth" property="heigth"/>
        <result column="contact_number" property="contactNumber"/>
        <result column="warehouse_capacity" property="warehouseCapacity"/>
        <result column="dutyStoreman" property="dutyStoreman"/>
        <result column="remark" property="remark"/>
        <result column="ware_img" property="wareImg"/>
        <result column="createName" property="createName"/>
        <result column="updateName" property="updateName"/>
        <result column="createDate" property="createDate"/>
        <result column="updateDate" property="updateDate"/>
        <result column="del_flag" property="delFlag"/>
        <result column="org_id" property="orgId"/>
        <result column="library_type" property="libraryType"/>
        <result column="updatetime" property="updatetime"/>
        <result column="hwbm" property="hwbm"/>
    </resultMap>

    <select id="getWarehouseList" resultType="java.util.Map">
        SELECT
	warehouse_name AS "warehouse_name",
	storehouse_id AS "storehouse_id",
	warehouse_id AS "warehouse_id"
FROM
	basic_warehouse
WHERE
	del_flag != '0'
AND org_id = #{unitId}
UNION ALL
	SELECT
		storageTank_name AS "warehouse_name",
		id AS "storehouse_id",
		id AS "warehouse_id"
	FROM
		basic_tank
	WHERE
		org_id = #{unitId}
	AND del_flag != 2
    </select>
    <select id="getWarehouseListByCclx" resultType="java.util.Map">
        SELECT
            warehouse_name AS "warehouse_name",
            storehouse_id AS "storehouse_id",
            warehouse_id AS "warehouse_id"
        FROM
            basic_warehouse
        WHERE
            del_flag != '0'
AND org_id = #{unitId}
and storehouse_id in(
        select storehouse_id from basic_storehouse
        where org_id = #{unitId}
        AND library_type != '1'
        <choose>
            <when test="cclx==9528">
                and cclx in ('952851','952855')
            </when>
            <otherwise>
                and cclx = #{cclx}
            </otherwise>
        </choose>
        )
        UNION ALL
        SELECT
            storageTank_name AS "warehouse_name",
            id AS "storehouse_id",
            id AS "warehouse_id"
        FROM
            basic_tank
        WHERE
            org_id = #{unitId}
          AND del_flag != 2
    </select>

    <select id="selectMyMapsPage" resultType="java.util.Map">
        SELECT
        a.warehouse_id,
        a.depot_id,
        a.depot_name,
        a.storehouse_id,
        a.warehouse_code,
        a.warehouse_name,
        a.warehouse_use_time,
        a.warehouse_status,
        a.store_way,
        a.length,
        a.width,
        a.heigth,
        a.contact_number,
        a.warehouse_capacity,
        a.dutyStoreman,
        a.remark,
        a.ware_img,
        a.createName,
        a.updateName,
        a.createDate,
        a.updateDate,
        a.del_flag,
        a.org_id,
        a.library_type,
        a.updatetime,
        a.hwbm,
        a.crk_status,
        b.storehouse_name
        FROM basic_warehouse  a LEFT JOIN basic_storehouse b on a.storehouse_id = b.storehouse_id
        <if test="ew.sqlSegment != null and ew.sqlSegment != ''">
            where ${ew.sqlSegment}
        </if>
    </select>
</mapper>
