<?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.home.mapper.HoGlobalCompanyMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.hzs.common.domain.system.home.HoGlobalCompany">
        <id column="PK_ID" property="pkId" />
    <result column="DEL_FLAG" property="delFlag" />
    <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="REGION" property="region" />
        <result column="GLO_PROVINCE" property="gloProvince" />
        <result column="GLO_CITY" property="gloCity" />
        <result column="GLO_COUNTY" property="gloCounty" />
        <result column="COMPANY" property="company" />
        <result column="CONTACTS" property="contacts" />
        <result column="PHONE" property="phone" />
        <result column="EMAIL" property="email" />
        <result column="ADDRESS" property="address" />
        <result column="LANGUAGE_TYPE" property="languageType" />
        <result column="IMAGE" property="image" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        DEL_FLAG,
        PK_COUNTRY,
        CREATION_TIME,
        MODIFIED_TIME,
        PK_CREATOR,
        PK_MODIFIED,
        PK_ID, REGION, GLO_PROVINCE, GLO_CITY, GLO_COUNTY, COMPANY, CONTACTS, PHONE, EMAIL, ADDRESS, LANGUAGE_TYPE
    </sql>

    <!--查询全球分布列表-->
    <select id="queryGlobalCompanyList" parameterType="com.hzs.system.home.vo.HoGlobalCompanyVO"
            resultType="com.hzs.system.home.vo.HoGlobalCompanyVO">
        select  a.PK_ID pkId,
        a.REGION region,
        a.GLO_PROVINCE gloProvince,
        a.GLO_CITY gloCity,
        a.GLO_COUNTY gloCounty,
        a.COMPANY company,
        a.CONTACTS contacts,
        a.PHONE phone,
        a.EMAIL email,
        a.ADDRESS address,
        a.DEL_FLAG delFlag,
        a.PK_COUNTRY pkCountry,
        a.CREATION_TIME creationTime,
        a.MODIFIED_TIME modifiedTime,
        a.PK_CREATOR pkCreator,
        a.PK_MODIFIED pkModified,
        a.LANGUAGE_TYPE languageType,
        a.IMAGE image,
        pr.NAME provinceName,
        ct.NAME cityName,
        co.NAME countyName,
        c.SHORT_NAME shortName,
        ctt.REGION_NAME regionName
        from  HO_GLOBAL_COMPANY a
        LEFT JOIN BD_COUNTRY c on c.PK_ID=a.PK_COUNTRY
        left join BD_AREA pr on pr.PK_ID=a.GLO_PROVINCE
        left join BD_AREA ct on ct.PK_ID=a.GLO_CITY
        left join BD_AREA co on co.PK_ID=a.GLO_COUNTY
        left join BD_CONTINENT ctt on ctt.PK_ID=a.REGION
        WHERE
        a.DEL_FLAG = 0
        <if test="company != null and company !='' ">
            AND a.COMPANY  like '%' || #{company} || '%'
        </if>
        <if test="contacts != null and contacts !='' ">
            AND a.CONTACTS  like '%' || #{contacts} || '%'
        </if>
        <if test="phone != null and phone !='' ">
            AND a.PHONE  like '%' || #{phone} || '%'
        </if>
        <if test="email != null and email !='' ">
            AND a.EMAIL  like '%' || #{email} || '%'
        </if>
        <if test="region != null">
            AND a.REGION = #{region}
        </if>
        <if test="pkCountry != null">
            AND a.PK_COUNTRY = #{pkCountry}
        </if>
        <if test="gloProvince != null">
            AND a.GLO_PROVINCE = #{gloProvince}
        </if>
        <if test="gloCity != null">
            AND a.GLO_CITY = #{gloCity}
        </if>
        <if test="gloCounty != null">
            AND a.GLO_COUNTY = #{gloCounty}
        </if>
        <if test="startDate != null">
            and a.creation_time >= #{startDate, jdbcType=DATE}
        </if>
        <if test="endDate != null">
            and a.creation_time &lt; #{endDate, jdbcType=DATE}
        </if>
        order by a.PK_ID desc
    </select>
     <!--按区域查询-->
    <select id="queryGlobalByContinent" parameterType="com.hzs.system.home.vo.HoGlobalCompanyVO"
            resultType="com.hzs.system.home.vo.HoGlobalCompanyVO">
        select
        a.REGION region,
        ctt.REGION_NAME regionName
        from  HO_GLOBAL_COMPANY a
        INNER JOIN BD_CONTINENT ctt on ctt.PK_ID=a.REGION
        WHERE a.DEL_FLAG = 0
        <if test="pkCountry != null">
            AND a.PK_COUNTRY = #{pkCountry}
        </if>
        GROUP BY a.REGION,ctt.REGION_NAME
        order by a.REGION Asc
    </select>



</mapper>
