<?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.ground.supplier.mapper.ThSupplierApplyMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.hzs.common.domain.ground.supplier.ThSupplierApply">
        <id column="PK_ID" property="pkId" />
        <result column="CREATION_TIME" property="creationTime" />
        <result column="MODIFIED_TIME" property="modifiedTime" />
        <result column="DEL_FLAG" property="delFlag" />
        <result column="PK_CREATOR" property="pkCreator" />
        <result column="PK_MODIFIED" property="pkModified" />
        <result column="PK_COUNTRY" property="pkCountry" />
        <result column="NAME" property="name" />
        <result column="SHORT_NAME" property="shortName" />
        <result column="LEGAL_BODY" property="legalBody" />
        <result column="LINK_MAN" property="linkMan" />
        <result column="TAXPAYERID" property="taxpayerid" />
        <result column="PROVINCE" property="province" />
        <result column="CITY" property="city" />
        <result column="COUNTY" property="county" />
        <result column="ADDRESS" property="address" />
        <result column="APTITUDE1" property="aptitude1" />
        <result column="APTITUDE2" property="aptitude2" />
        <result column="APTITUDE3" property="aptitude3" />
        <result column="APTITUDE4" property="aptitude4" />
        <result column="APTITUDE5" property="aptitude5" />
        <result column="APTITUDE6" property="aptitude6" />
        <result column="APTITUDE7" property="aptitude7" />
        <result column="APTITUDE8" property="aptitude8" />
        <result column="VALID_PERIOD" property="validPeriod" />
        <result column="SETTLE_TYPE" property="settleType" />
        <result column="PK_MEMBER" property="pkMember" />
        <result column="CERTIFICATE" property="certificate" />
        <result column="TRADE_SCOPE" property="tradeScope" />
        <result column="EDIT_TYPE" property="editType" />
        <result column="APPROVE_STATUS" property="approveStatus" />
        <result column="TH_BUSINESS_CODE" property="thBusinessCode" />

    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        CREATION_TIME,
        MODIFIED_TIME,
        DEL_FLAG,
        PK_CREATOR,
        PK_MODIFIED,
        PK_COUNTRY,
        PK_ID, NAME, SHORT_NAME, LEGAL_BODY, LINK_MAN, TAXPAYERID, PROVINCE, CITY, COUNTY, ADDRESS, APTITUDE1, APTITUDE2, APTITUDE3, APTITUDE4, APTITUDE5, APTITUDE6, APTITUDE7, APTITUDE8, VALID_PERIOD, SETTLE_TYPE, PK_MEMBER, CERTIFICATE, TRADE_SCOPE
    </sql>



<!--    供应商申请列表 -->
    <select id="queryThSupplierApplyList" resultType="com.hzs.ground.supplier.vo.ThSupplierApplyVO">
        select
        tsa.pk_id pkId,
        tsa.name name,
        tsa.short_name shortName,
        tsa.legal_body legalBody,
        tsa.link_man linkMan,
        tsa.taxpayerid taxpayerid,
        tsa.address address,
        tsa.valid_period validPeriod,
        tsa.settle_type settleType,
        tsa.pk_member pkMember,
        tsa.trade_scope tradeScope,
        tsa.creation_time creationTime,
        p.name provinceName,
        c.name cityName,
        co.name countyName,
        tsa.APPROVE_STATUS approveStatus,
        tsa.aptitude1,
        tsa.aptitude2,
        tsa.aptitude3,
        tsa.aptitude4,
        tsa.aptitude5,
        tsa.aptitude6,
        tsa.aptitude7,
        tsa.aptitude8,
        tsa.certificate
        from TH_SUPPLIER_APPLY tsa
        LEFT JOIN BD_AREA p on p.PK_ID=tsa.PROVINCE and p.del_flag=0
        LEFT JOIN BD_AREA c on c.PK_ID=tsa.CITY  and c.del_flag=0
        LEFT JOIN BD_AREA co on co.PK_ID=tsa.COUNTY and co.del_flag=0
        where tsa.del_flag=0
        <if test="pkCountry != null">
            and tsa.pk_country=#{pkCountry}
        </if>
        <if test="pkCreator != null">
            and tsa.PK_CREATOR=#{pkCreator}
        </if>
        <if test="name != null and name != ''">
            and tsa.NAME like #{name} || '%'
        </if>

        order by tsa.pk_id desc
    </select>

<!--    查询登录管理员是否为供应商-->
    <select id="queryThSupplierApplyUserList" resultType="java.lang.Integer">
        select  count(1)  from sys_user su
        where su.del_flag=0 and su.user_type = 9
        <if test="useId != null">
            and su.USER_ID=#{useId}
        </if>
    </select>



<!--    供应商申请审批查看-->
    <select id="queryThSupplierApplyByCode" resultType="com.hzs.ground.supplier.vo.ThSupplierApplyVO">
        select
        tsa.pk_id pkId,
        tsa.name name,
        tsa.short_name shortName,
        tsa.legal_body legalBody,
        tsa.link_man linkMan,
        tsa.taxpayerid taxpayerid,
        tsa.address address,
        tsa.valid_period validPeriod,
        tsa.settle_type settleType,
        tsa.pk_member pkMember,
        tsa.trade_scope tradeScope,
        tsa.creation_time creationTime,
        tsa.PK_CREATOR pkCreator,
        p.name provinceName,
        c.name cityName,
        co.name countyName,
        tsa.province,
        tsa.city,
        tsa.county,
        tsa.APTITUDE1,
        tsa.APTITUDE2,
        tsa.APTITUDE3,
        tsa.APTITUDE4,
        tsa.APTITUDE5,
        tsa.APTITUDE6,
        tsa.APTITUDE7,
        tsa.APTITUDE8,
        tsa.CERTIFICATE CERTIFICATE

        from TH_SUPPLIER_APPLY tsa
        LEFT JOIN BD_AREA p on p.PK_ID=tsa.PROVINCE
        LEFT JOIN BD_AREA c on c.PK_ID=tsa.CITY
        LEFT JOIN BD_AREA co on co.PK_ID=tsa.COUNTY
        where tsa.del_flag=0
        and p.del_flag=0
        and c.del_flag=0
        and co.del_flag=0
        <if test="pkCountry != null">
            and tsa.pk_country=#{pkCountry}
        </if>
        <if test=" businessCode!='' and businessCode != null">
            and tsa.TH_BUSINESS_CODE=#{businessCode}
        </if>

    </select>


</mapper>
