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

    <!-- 通用查询映射结果 -->
    <resultMap id="BdCubasdocExt" type="com.hzs.common.domain.system.base.ext.BdCubasdocExt">
        <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="CUST_CODE" property="custCode"/>
        <result column="CUST_NAME" property="custName"/>
        <result column="CUST_TYPE" property="custType"/>
        <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="TRADE_SCOPE" property="tradeScope"/>
        <result column="PROVINCE_NAME" property="provinceName"/>
        <result column="CITY_NAME" property="cityName"/>
        <result column="COUNTY_NAME" property="countyName"/>
        <result column="PK_SUPPLIER" property="pkSupplier"/>
        <result column="PK_USER" property="pkUser"/>
    </resultMap>

    <select id="queryCubasdocByCondition" resultMap="BdCubasdocExt">
        select bc.*,ba.name province_name,bt.name city_name,bn.name county_name from bd_cubasdoc bc
        left join bd_area ba
        on bc.province=ba.pk_id and ba.del_flag=0
        left join bd_area bt
        on bc.city=bt.pk_id and bt.del_flag=0
        left join bd_area bn
        on bc.county=bn.pk_id and bn.del_flag=0
        where bc.del_flag=0
        <if test="cubasdocParam.pkCreator != null">
            and bc.PK_CREATOR= #{cubasdocParam.pkCreator}
        </if>
        <if test="cubasdocParam.pkCountry != null">
            and bc.pk_country= #{cubasdocParam.pkCountry}
        </if>
        <if test="cubasdocParam.pkUser != null">
            and bc.pk_user= #{cubasdocParam.pkUser}
        </if>
        <if test="cubasdocParam.pkId != null">
            and bc.pk_id = #{cubasdocParam.pkId}
        </if>
        <if test="cubasdocParam.custName != null and cubasdocParam.custName != ''">
            and bc.cust_name=#{cubasdocParam.custName}
        </if>
        <if test="cubasdocParam.custTypeList != null and cubasdocParam.custTypeList.size >0">
            and bc.cust_type in
            <foreach item="item" collection="cubasdocParam.custTypeList" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        ORDER BY bc.CREATION_TIME DESC
    </select>

    <select id="querySupplierByProduct" resultMap="BdCubasdocExt">
        select bc.*,ba.name province_name,bt.name city_name,bn.name county_name from bd_cubasdoc bc
        left join bd_area ba
        on bc.province=ba.pk_id and ba.del_flag=0
        left join bd_area bt
        on bc.city=bt.pk_id and bt.del_flag=0
        left join bd_area bn
        on bc.county=bn.pk_id and bn.del_flag=0
        where bc.del_flag=0
        and bc.PK_SUPPLIER is not null
        <if test="cubasdocParam.pkCreator != null">
            and bc.PK_CREATOR= #{cubasdocParam.pkCreator}
        </if>
        <if test="cubasdocParam.pkCountry != null">
            and bc.pk_country= #{cubasdocParam.pkCountry}
        </if>
        <if test="cubasdocParam.pkUser != null">
            and bc.pk_user= #{cubasdocParam.pkUser}
        </if>
        <if test="cubasdocParam.pkId != null">
            and bc.pk_id = #{cubasdocParam.pkId}
        </if>
        <if test="cubasdocParam.custName != null and cubasdocParam.custName != ''">
            and bc.cust_name=#{cubasdocParam.custName}
        </if>
        <if test="cubasdocParam.custTypeList != null and cubasdocParam.custTypeList.size >0">
            and bc.cust_type in
            <foreach item="item" collection="cubasdocParam.custTypeList" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        ORDER BY bc.CREATION_TIME 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>

</mapper>
