<?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.config.mapper.BdDeliveryCentreMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.hzs.common.domain.system.config.BdDeliveryCentre">
        <id column="PK_ID" property="pkId" />
    <result column="PK_COUNTRY" property="pkCountry" />
    <result column="CREATION_TIME" property="creationTime" />
    <result column="MODIFIED_TIME" property="modifiedTime" />
    <result column="PK_CREATOR" property="pkCreator" />
    <result column="PK_MODIFIED" property="pkModified" />
    <result column="DEL_FLAG" property="delFlag" />
        <result column="DELIVERY_NAME" property="deliveryName" />
        <result column="DELIVERY_GRADE" property="deliveryGrade" />
        <result column="CONTACTS" property="contacts" />
        <result column="MOBILE_PHONE" property="mobilePhone" />
        <result column="PROVINCE" property="province" />
        <result column="CITY" property="city" />
        <result column="COUNTY" property="county" />
        <result column="ADDRESS" property="address" />
        <result column="USAGE_STATUS" property="usageStatus" />
        <result column="PK_SUBSIDY" property="pkSubsidy" />
    </resultMap>

    <resultMap id="BdDeliveryCentreVO" type="com.hzs.system.config.vo.BdDeliveryCentreVO">
        <id column="PK_ID" property="pkId" />
        <result column="PK_COUNTRY" property="pkCountry" />
        <result column="CREATION_TIME" property="creationTime" />
        <result column="MODIFIED_TIME" property="modifiedTime" />
        <result column="PK_CREATOR" property="pkCreator" />
        <result column="PK_MODIFIED" property="pkModified" />
        <result column="DEL_FLAG" property="delFlag" />
        <result column="DELIVERY_NAME" property="deliveryName" />
        <result column="DELIVERY_GRADE" property="deliveryGrade" />
        <result column="DELIVERY_GRADEVAL" property="deliveryGradeVal" />
        <result column="CONTACTS" property="contacts" />
        <result column="MOBILE_PHONE" property="mobilePhone" />
        <result column="PROVINCE" property="province" />
        <result column="CITY" property="city" />
        <result column="COUNTY" property="county" />
        <result column="ADDRESS" property="address" />
        <result column="USAGE_STATUS" property="usageStatus" />
        <result column="SHORT_NAME" property="shortName" />
        <result column="PROVINCE_NAME" property="provinceName" />
        <result column="CITY_NAME" property="cityName" />
        <result column="COUNTY_NAME" property="countyName" />
        <result column="PK_SUBSIDY" property="pkSubsidy" />


    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        PK_COUNTRY,
        CREATION_TIME,
        MODIFIED_TIME,
        PK_CREATOR,
        PK_MODIFIED,
        DEL_FLAG,
        PK_ID, DELIVERY_NAME, DELIVERY_GRADE, CONTACTS, MOBILE_PHONE, PROVINCE, CITY, COUNTY, ADDRESS
    </sql>
     <!--查询配送中心列表-->
    <select id="queryDeliveryCentreList" parameterType="com.hzs.system.config.vo.BdDeliveryCentreVO"
            resultType="com.hzs.system.config.vo.BdDeliveryCentreVO">
        SELECT
        a.PK_ID,
        a.DELIVERY_NAME,
        a.DELIVERY_GRADE,
        a.CONTACTS,
        a.MOBILE_PHONE,
        a.PROVINCE,
        a.PK_SUBSIDY,
        pr.NAME PROVINCE_NAME,
        a.CITY,
        ct.NAME CITY_NAME,
        a.COUNTY,
        co.NAME COUNTY_NAME,
        a.ADDRESS,
        a.PK_COUNTRY,
        a.CREATION_TIME,
        a.MODIFIED_TIME,
        a.PK_CREATOR,
        a.PK_MODIFIED,
        a.DEL_FLAG,
        a.USAGE_STATUS,
        b.SHOP_NAME as DELIVERY_GRADEVAL,
        c.SHORT_NAME
        FROM
        BD_DELIVERY_CENTRE a
        LEFT JOIN BD_SHOP b ON a.DELIVERY_GRADE = b.PK_ID
        LEFT JOIN BD_COUNTRY c on c.PK_ID=a.PK_COUNTRY
        left join BD_AREA pr on pr.PK_ID=a.PROVINCE
        left join BD_AREA ct on ct.PK_ID=a.CITY
        left join BD_AREA co on co.PK_ID=a.COUNTY
        WHERE
        a.DEL_FLAG = 0
        AND b.DEL_FLAG =0
        <if test="deliveryName != null and deliveryName !='' ">
            AND a.DELIVERY_NAME  like '%' || #{deliveryName} || '%'
        </if>
        <if test="contacts != null and contacts !='' ">
            AND a.CONTACTS  like '%' || #{contacts} || '%'
        </if>
        <if test="mobilePhone != null and mobilePhone !='' ">
            AND a.MOBILE_PHONE  like '%' || #{mobilePhone} || '%'
        </if>
        <if test="deliveryGrade != null">
            AND a.DELIVERY_GRADE = #{deliveryGrade}
        </if>
        order by a.PK_ID desc
    </select>



</mapper>
