<?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.ningdatech.carapi.company.mapper.NdCompanyBlackListMapper">

    <select id="companyBlackList" resultType="com.ningdatech.carapi.company.entity.dto.ResCompanyBlackListDTO">
        SELECT ncbl.company_id AS companyId,
        ncbl.company_name AS companyName,
        ncbl.region_id as regionId,
        ncbl.region_name as regionName
        FROM nd_company_black_list ncbl
        left join nd_company_info c on ncbl.company_id = c.id
        left join nd_region r on ncbl.region_id = r.id
        <where>
            1 = 1
            <if test="po.regionIds != null and po.regionIds.size > 0">
                AND ncbl.region_id in
                <foreach collection="po.regionIds" item="item" open="(" close=")" separator=",">
                    #{item}
                </foreach>
            </if>

            <if test="po.companyName != null and po.companyName != ''">
                AND c.name LIKE CONCAT('%', #{po.companyName},'%')
            </if>
        </where>
        ${po.dataScopeSql}
        GROUP BY ncbl.company_id,ncbl.company_name,ncbl.region_id,ncbl.region_name
        ORDER BY ncbl.company_id DESC
    </select>
    <select id="companyBlackInfoList"
            resultType="com.ningdatech.carapi.company.entity.dto.ResCompanyBlackDetailListDTO">
        SELECT ncbl.type AS type,
        ncbl.black_time AS blackTime,
        ncbl.site AS site,
        ncbl.content AS content
        FROM nd_company_black_list ncbl
        <where>
            ncbl.company_id = #{companyId}
        </where>
        ORDER BY ncbl.id DESC
    </select>
</mapper>
