<?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.hzs.system.base.mapper.BdStorehouseAreaMiddleMapper">

    <resultMap id="BdStorehouseAreaMiddleVO" type="com.hzs.system.base.vo.BdStorehouseAreaMiddleVO">
        <id column="PK_ID" property="pkId"/>
        <result column="CREATION_TIME" property="creationTime"/>
        <result column="DEL_FLAG" property="delFlag"/>
        <result column="PK_COUNTRY" property="pkCountry"/>
        <result column="PK_STOREHOUSE" property="pkStorehouse"/>
        <result column="PROVINCE" property="province"/>
        <result column="NAME" property="name"/>
        <result column="provinceVal" property="provinceVal"/>
    </resultMap>

    <!--查询地区绑定仓库列表-->
    <select id="getBdStorehouseAreaMiddleList" parameterType="com.hzs.system.base.vo.BdStorehouseAreaMiddleVO"
            resultMap="BdStorehouseAreaMiddleVO">
        select a.*,
        bse.NAME,
        pr.NAME provinceVal
        from BD_STOREHOUSE_AREA_MIDDLE a
        INNER JOIN BD_STOREHOUSE bse on a.PK_STOREHOUSE=bse.PK_ID
        INNER JOIN BD_AREA pr on pr.PK_ID=a.PROVINCE
        where bse.DEL_FLAG = 0 and a.DEL_FLAG = 0 and pr.DEL_FLAG = 0
        and a.pk_Country =#{pkCountry}
        <if test="pkId != null">
            AND a.PK_ID = #{pkId}
        </if>
        <if test="pkStorehouse != null">
            AND a.PK_STOREHOUSE = #{pkStorehouse}
        </if>
        <if test="provinceVal != null and provinceVal != ''">
            AND pr.NAME like '%' || #{provinceVal} || '%'
        </if>
        <if test="name != null and name != ''">
            AND bse.NAME like '%' || #{name} || '%'
        </if>
    </select>

    <select id="queryBdStorehouseByProvince" resultType="com.hzs.common.domain.system.base.BdStorehouse">
        select bs.pk_id, bs.name, bs.code,bs.pk_corp
        from bd_storehouse bs
        inner join bd_storehouse_area_middle bm
        on bs.pk_id = bm.pk_storehouse
        where bs.del_flag = 0
        and bm.del_flag = 0
        and bs.enable_state = 0
        and bm.province = #{province}
        <if test="type != null">
            and bs.store_type = #{type}
        </if>
    </select>

</mapper>
