<?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.BdStorehouseMapper">

    <sql id="selectBdStorehouseVo">
        select bse.PK_ID         as pkId,
               bse.PK_CREATOR    as pkCreator,
               bse.CREATION_TIME as creationTime,
               bse.PK_MODIFIED   as pkModified,
               bse.MODIFIED_TIME as modifiedTime,
               bse.DEL_FLAG      as delFlag,
               bse.CODE          as code,
               bse.NAME          as name,
               bse.WARE_ADDRESS  as wareAddress,
               bse.CONTACTS      as contacts,
               bse.MOBILE_PHONE  as mobilePhone,
               bse.PROVINCE      as province,
               bse.CITY          as city,
               bse.COUNTY        as county,
               pr.NAME              provinceVal,
               ci.NAME              cityVal,
               co.NAME              countyVal

        FROM BD_STOREHOUSE bse
                 left JOIN BD_AREA pr on pr.PK_ID = bse.PROVINCE
                 left JOIN BD_AREA ci on ci.PK_ID = bse.CITY
                 left JOIN BD_AREA co on co.PK_ID = bse.COUNTY
    </sql>

    <select id="selectBdStorehouseList" parameterType="com.hzs.system.base.vo.BdStorehouseVO"
            resultType="com.hzs.system.base.vo.BdStorehouseVO">
        <include refid="selectBdStorehouseVo"/>
        where bse.DEL_FLAG = 0
        <if test="pkCountry != null">
            and bse.PK_COUNTRY= #{pkCountry}
        </if>
        <if test="code != null and code != ''">
            AND bse.CODE like '%' || #{code} || '%'
        </if>
        <if test="name != null and name != ''">
            AND bse.NAME like '%' || #{name} || '%'
        </if>
        <if test="wareAddress != null and wareAddress != ''">
            AND bse.WARE_ADDRESS like '%' || #{wareAddress} || '%'
        </if>
        <if test="mobilePhone != null and mobilePhone != ''">
            AND bse.MOBILE_PHONE like '%' || #{mobilePhone} || '%'
        </if>
        <if test="contacts != null and contacts != ''">
            AND bse.contacts like '%' || #{contacts} || '%'
        </if>

        <if test="province !=null ">
            AND bse.province = #{province}
        </if>
        <if test="city !=null ">
            AND bse.city = #{city}
        </if>
        <if test="county !=null ">
            AND bse.county = #{county}
        </if>
        <if test="startDate != null and endDate != null">
            and bse.creation_time between #{startDate, jdbcType=TIMESTAMP} and #{endDate, jdbcType=TIMESTAMP}
        </if>
        <if test="pkCorp != null">
            and bse.pk_corp = #{pkCorp}
        </if>
        order by bse.CREATION_TIME desc
    </select>


    <select id="getBdStorehouse" parameterType="com.hzs.common.domain.system.base.BdStorehouse"
            resultType="com.hzs.common.domain.system.base.BdStorehouse">
        select bse.PK_ID as pkId,
        bse.PK_CREATOR as pkCreator,
        bse.CREATION_TIME as creationTime,
        bse.PK_MODIFIED as pkModified,
        bse.MODIFIED_TIME as modifiedTime,
        bse.DEL_FLAG as delFlag,
        bse.CODE as code,
        bse.NAME as name,
        bse.WARE_ADDRESS as wareAddress,
        bse.CONTACTS as contacts,
        bse.MOBILE_PHONE as mobilePhone,
        bse.PK_CORP pkCorp,
        bse.PROVINCE as province,
        bse.CITY as city,
        bse.COUNTY as county
        FROM BD_STOREHOUSE bse
        where bse.DEL_FLAG = 0
        <if test="pkId != null">
            AND bse.PK_ID = #{pkId}
        </if>
        <if test="code != null and code != ''">
            AND bse.CODE = #{code}
        </if>
        <if test="name != null and name != ''">
            AND bse.NAME = #{name}
        </if>
    </select>

    <select id="checkBdStorehouse" parameterType="com.hzs.common.domain.system.base.BdStorehouse"
            resultType="com.hzs.common.domain.system.base.BdStorehouse">
        select bse.PK_ID as pkId,
        bse.PK_CREATOR as pkCreator,
        bse.CREATION_TIME as creationTime,
        bse.PK_MODIFIED as pkModified,
        bse.MODIFIED_TIME as modifiedTime,
        bse.DEL_FLAG as delFlag,
        bse.CODE as code,
        bse.NAME as name,
        bse.WARE_ADDRESS as wareAddress
        FROM BD_STOREHOUSE bse
        where bse.DEL_FLAG = 0
        <if test="pkId != null">
            AND bse.PK_ID != #{pkId}
        </if>
        <if test="code != null and code != ''">
            AND bse.CODE = #{code}
        </if>
        <if test="name != null and name != ''">
            AND bse.NAME = #{name}
        </if>
    </select>


</mapper>
