<?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.chinaweal.aiccs.aiccs.abnormal.mapper.EBaseinfoMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.chinaweal.aiccs.aiccs.abnormal.entity.EBaseinfo">
        <id column="PRIPID" property="pripid" />
        <result column="UNISCID" property="uniscid" />
        <result column="ENTNAME" property="entname" />
        <result column="REGNO" property="regno" />
        <result column="ENTTYPE" property="enttype" />
        <result column="ENTTYPE_CN" property="enttypeCn" />
        <result column="INDUSTRYPHY" property="industryphy" />
        <result column="INDUSTRYCO" property="industryco" />
        <result column="ESTDATE" property="estdate" />
        <result column="REGORG" property="regorg" />
        <result column="REGORG_CN" property="regorgCn" />
        <result column="OPSCOTYPE" property="opscotype" />
        <result column="OPSCOTYPE_CN" property="opscotypeCn" />
        <result column="OPSCOPE" property="opscope" />
        <result column="OPFROM" property="opfrom" />
        <result column="OPTO" property="opto" />
        <result column="REGSTATE" property="regstate" />
        <result column="REGSTATE_CN" property="regstateCn" />
        <result column="DOMDISTRICT" property="domdistrict" />
        <result column="DOM" property="dom" />
        <result column="REGCAP" property="regcap" />
        <result column="REGCAPCUR" property="regcapcur" />
        <result column="REGCAPCUR_CN" property="regcapcurCn" />
        <result column="REGCAPUSD" property="regcapusd" />
        <result column="RECCAP" property="reccap" />
        <result column="RECCAPUSD" property="reccapusd" />
        <result column="COUNTRY" property="country" />
        <result column="EMPNUM" property="empnum" />
        <result column="TOWN" property="town" />
        <result column="NAME" property="name" />
        <result column="REPORTTYPE" property="reporttype" />
        <result column="APPRDATE" property="apprdate" />
        <result column="s_ext_fromnode" property="sExtFromnode" />
        <result column="s_ext_datatime" property="sExtDatatime" />
        <result column="industry_name" property="industryName" />
        <result column="rev_date" property="revDate" />
        <result column="phone" property="phone" />
        <result column="email" property="email" />
        <result column="address" property="address" />
        <result column="website" property="website" />
        <result column="regulatory" property="regulatory" />
        <result column="regulatory_name" property="regulatoryName" />
        <result column="open_from" property="openFrom" />
        <result column="open_to" property="openTo" />
        <result column="score" property="score" />
        <result column="level" property="level" />
        <result column="update_by" property="updateBy" />
        <result column="update_time" property="updateTime" />
        <result column="create_by" property="createBy" />
        <result column="create_time" property="createTime" />
        <result column="label" property="label" />
        <result column="branch" property="branch" />
        <result column="investment" property="investment" />
        <result column="traname" property="traname" />
        <result column="fundam" property="fundam" />
        <result column="compform" property="compform" />
        <result column="compform_cn" property="compformCn" />
        <result column="localadm" property="localadm" />
        <result column="oplocdistrict" property="oplocdistrict" />
        <result column="oploc" property="oploc" />
        <result column="tel" property="tel" />
        <result column="postalcode" property="postalcode" />
        <result column="region" property="region" />
        <result column="street_long" property="streetLong" />
        <result column="street_name" property="streetName" />

        <result column="ACCEPTREGORG" property="acceptRegorg" />
        <result column="ACCEPTREGORG_CN" property="acceptregorgCn" />
        <result column="SUPORG" property="suporg" />
        <result column="SUPORG_CN" property="suporgCn" />
    </resultMap>
    <!-- 通用查询映射结果 -->
    <resultMap id="ComplexEntInfoMap" type="com.chinaweal.aiccs.aiccs.abnormal.entity.dto.ComplexEntInfoDto">
        <id column="PRIPID" property="pripid" />
        <result column="UNISCID" property="uniscid" />
        <result column="ENTNAME" property="entname" />
        <result column="REGNO" property="regno" />
        <result column="ENTTYPE" property="enttype" />
        <result column="ENTTYPE_CN" property="enttypeCn" />
        <result column="INDUSTRYPHY" property="industryphy" />
        <result column="INDUSTRYCO" property="industryco" />
        <result column="ESTDATE" property="estdate" />
        <result column="REGORG" property="regorg" />
        <result column="REGORG_CN" property="regorgCn" />
        <result column="OPSCOTYPE" property="opscotype" />
        <result column="OPSCOTYPE_CN" property="opscotypeCn" />
        <result column="OPSCOPE" property="opscope" />
        <result column="OPFROM" property="opfrom" />
        <result column="OPTO" property="opto" />
        <result column="REGSTATE" property="regstate" />
        <result column="REGSTATE_CN" property="regstateCn" />
        <result column="DOMDISTRICT" property="domdistrict" />
        <result column="DOM" property="dom" />
        <result column="REGCAP" property="regcap" />
        <result column="REGCAPCUR" property="regcapcur" />
        <result column="REGCAPCUR_CN" property="regcapcurCn" />
        <result column="REGCAPUSD" property="regcapusd" />
        <result column="RECCAP" property="reccap" />
        <result column="RECCAPUSD" property="reccapusd" />
        <result column="COUNTRY" property="country" />
        <result column="EMPNUM" property="empnum" />
        <result column="TOWN" property="town" />
        <result column="NAME" property="name" />
        <result column="REPORTTYPE" property="reporttype" />
        <result column="APPRDATE" property="apprdate" />
        <result column="s_ext_fromnode" property="sExtFromnode" />
        <result column="s_ext_datatime" property="sExtDatatime" />
        <result column="industry_name" property="industryName" />
        <result column="rev_date" property="revDate" />
        <result column="phone" property="phone" />
        <result column="email" property="email" />
        <result column="address" property="address" />
        <result column="website" property="website" />
        <result column="regulatory" property="regulatory" />
        <result column="regulatory_name" property="regulatoryName" />
        <result column="open_from" property="openFrom" />
        <result column="open_to" property="openTo" />
        <result column="score" property="score" />
        <result column="level" property="level" />
        <result column="update_by" property="updateBy" />
        <result column="update_time" property="updateTime" />
        <result column="create_by" property="createBy" />
        <result column="create_time" property="createTime" />
        <result column="label" property="label" />
        <result column="branch" property="branch" />
        <result column="investment" property="investment" />
        <result column="traname" property="traname" />
        <result column="fundam" property="fundam" />
        <result column="compform" property="compform" />
        <result column="compform_cn" property="compformCn" />
        <result column="localadm" property="localadm" />
        <result column="oplocdistrict" property="oplocdistrict" />
        <result column="oploc" property="oploc" />
        <result column="tel" property="tel" />
        <result column="postalcode" property="postalcode" />
        <result column="region" property="region" />
        <result column="street_long" property="streetLong" />
        <result column="street_name" property="streetName" />
    </resultMap>
    <resultMap id="toIncludeAbnMap" type="com.chinaweal.aiccs.aiccs.abnormal.entity.EBaseinfo">
        <id column="PRIPID" property="pripid" />
        <result column="UNISCID" property="uniscid" />
        <result column="ENTNAME" property="entname" />
        <result column="REGNO" property="regno" />
        <result column="ENTTYPE" property="enttype" />
        <result column="ENTTYPE_CN" property="enttypeCn" />
        <result column="INDUSTRYPHY" property="industryphy" />
        <result column="INDUSTRYCO" property="industryco" />
        <result column="ESTDATE" property="estdate" />
        <result column="REGORG" property="regorg" />
        <result column="REGORG_CN" property="regorgCn" />
        <result column="OPSCOTYPE" property="opscotype" />
        <result column="OPSCOTYPE_CN" property="opscotypeCn" />
        <result column="OPSCOPE" property="opscope" />
        <result column="OPFROM" property="opfrom" />
        <result column="OPTO" property="opto" />
        <result column="REGSTATE" property="regstate" />
        <result column="REGSTATE_CN" property="regstateCn" />
        <result column="DOMDISTRICT" property="domdistrict" />
        <result column="DOM" property="dom" />
        <result column="REGCAP" property="regcap" />
        <result column="REGCAPCUR" property="regcapcur" />
        <result column="REGCAPCUR_CN" property="regcapcurCn" />
        <result column="REGCAPUSD" property="regcapusd" />
        <result column="RECCAP" property="reccap" />
        <result column="RECCAPUSD" property="reccapusd" />
        <result column="COUNTRY" property="country" />
        <result column="EMPNUM" property="empnum" />
        <result column="TOWN" property="town" />
        <result column="NAME" property="name" />
        <result column="REPORTTYPE" property="reporttype" />
        <result column="APPRDATE" property="apprdate" />
        <result column="s_ext_fromnode" property="sExtFromnode" />
        <result column="s_ext_datatime" property="sExtDatatime" />
        <result column="industry_name" property="industryName" />
        <result column="rev_date" property="revDate" />
        <result column="phone" property="phone" />
        <result column="email" property="email" />
        <result column="address" property="address" />
        <result column="website" property="website" />
        <result column="regulatory" property="regulatory" />
        <result column="regulatory_name" property="regulatoryName" />
        <result column="open_from" property="openFrom" />
        <result column="open_to" property="openTo" />
        <result column="score" property="score" />
        <result column="level" property="level" />
        <result column="update_by" property="updateBy" />
        <result column="update_time" property="updateTime" />
        <result column="create_by" property="createBy" />
        <result column="create_time" property="createTime" />
        <result column="label" property="label" />
        <result column="branch" property="branch" />
        <result column="investment" property="investment" />
        <result column="traname" property="traname" />
        <result column="fundam" property="fundam" />
        <result column="compform" property="compform" />
        <result column="compform_cn" property="compformCn" />
        <result column="localadm" property="localadm" />
        <result column="oplocdistrict" property="oplocdistrict" />
        <result column="oploc" property="oploc" />
        <result column="tel" property="tel" />
        <result column="postalcode" property="postalcode" />
        <result column="region" property="region" />
        <result column="street_long" property="streetLong" />
        <result column="street_name" property="streetName" />
    </resultMap>

    <resultMap id="EBaseinfoExcel" type="com.chinaweal.aiccs.aiccs.abnormal.entity.excel.EBaseinfoExcel">
        <result column="UNISCID" property="uniscid" />
        <result column="ENTNAME" property="entname" />
        <result column="REGNO" property="regno" />
        <result column="ENTTYPE" property="enttype" />
        <result column="ENTTYPE_CN" property="enttypeCn" />
        <result column="INDUSTRYPHY" property="industryphy" />
        <result column="INDUSTRYCO" property="industryco" />
        <result column="ESTDATE" property="estdate" />
        <result column="REGORG" property="regorg" />
        <result column="REGORG_CN" property="regorgCn" />
        <result column="OPSCOTYPE" property="opscotype" />
        <result column="OPSCOTYPE_CN" property="opscotypeCn" />
        <result column="OPSCOPE" property="opscope" />
        <result column="OPFROM" property="opfrom" />
        <result column="OPTO" property="opto" />
        <result column="REGSTATE" property="regstate" />
        <result column="REGSTATE_CN" property="regstateCn" />
        <result column="DOMDISTRICT" property="domdistrict" />
        <result column="DOM" property="dom" />
        <result column="REGCAP" property="regcap" />
        <result column="REGCAPCUR" property="regcapcur" />
        <result column="REGCAPCUR_CN" property="regcapcurCn" />
        <result column="REGCAPUSD" property="regcapusd" />
        <result column="RECCAP" property="reccap" />
        <result column="RECCAPUSD" property="reccapusd" />
        <result column="COUNTRY" property="country" />
        <result column="EMPNUM" property="empnum" />
        <result column="TOWN" property="town" />
        <result column="industry_name" property="industryName" />
        <result column="phone" property="phone" />
        <result column="email" property="email" />
        <result column="address" property="address" />
        <result column="website" property="website" />
        <result column="regulatory" property="regulatory" />
        <result column="regulatory_name" property="regulatoryName" />
        <result column="open_from" property="openFrom" />
        <result column="open_to" property="openTo" />
        <result column="score" property="score" />
        <result column="level" property="level" />
        <result column="branch" property="branch" />
        <result column="investment" property="investment" />
        <result column="traname" property="traname" />
        <result column="fundam" property="fundam" />
        <result column="compform" property="compform" />
        <result column="compform_cn" property="compformCn" />
        <result column="localadm" property="localadm" />
        <result column="oplocdistrict" property="oplocdistrict" />
        <result column="oploc" property="oploc" />
        <result column="tel" property="tel" />
        <result column="postalcode" property="postalcode" />
        <result column="region" property="region" />
        <result column="street_long" property="streetLong" />
        <result column="street_name" property="streetName" />
    </resultMap>

    <resultMap id="ComprehensiveStatistics" type="com.chinaweal.aiccs.aiccs.abnormal.entity.dto.ComprehensiveStatistics">
        <result column="name" property="name" />
        <result column="num" property="num" />
    </resultMap>

    <resultMap id="ComprehensiveStat" type="com.chinaweal.aiccs.aiccs.abnormal.entity.dto.ComprehensiveStat">
        <result column="orgn" property="orgn" />
        <result column="orgunitname" property="orgunitname" />
        <result column="abnlrnum" property="abnlrnum" />
        <result column="abnycnum" property="abnycnum" />
        <result column="abnyynum" property="abnyynum" />
        <result column="leglrnum" property="leglrnum" />
        <result column="legyynum" property="legyynum" />
        <result column="legycnum" property="legycnum" />
        <result column="ualfknum" property="ualfknum" />
        <result column="mytrnum" property="mytrnum" />
        <result column="wtcznum" property="wtcznum" />
        <result column="legxfnum" property="legxfnum" />
        <result column="xyfxyynum" property="xyfxyynum" />
        <result column="abnkwnum" property="abnkwnum" />
        <result column="legkwnum" property="legkwnum" />
        <result column="pldxnum" property="pldxnum" />
        <result column="cxnum" property="cxnum" />
        <result column="fynum" property="fynum" />
        <result column="susnum" property="susnum" />
        <result column="locknum" property="locknum" />
        <result column="unlocknum" property="unlocknum" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        PRIPID, UNISCID, ENTNAME, REGNO, ENTTYPE, ENTTYPE_CN, INDUSTRYPHY, INDUSTRYCO, ESTDATE, REGORG, REGORG_CN, OPSCOTYPE, OPSCOTYPE_CN, OPSCOPE, OPFROM, OPTO, REGSTATE, REGSTATE_CN, DOMDISTRICT, DOM, REGCAP, REGCAPCUR, REGCAPCUR_CN, REGCAPUSD, RECCAP, RECCAPUSD, COUNTRY, EMPNUM, TOWN, NAME, REPORTTYPE, APPRDATE, s_ext_fromnode, s_ext_datatime, industry_name, rev_date, phone, email, address, website, regulatory, regulatory_name, open_from, open_to, score, level, update_by, update_time, create_by, create_time, label, branch, investment, traname, fundam, compform, compform_cn, localadm, oplocdistrict, oploc, tel, postalcode, region, street_long, street_name, ACCEPTREGORG, ACCEPTREGORG_CN, SUPORG, SUPORG_CN
    </sql>
    <sql id="E_Base_Column_List">
        e.PRIPID, e.UNISCID, e.ENTNAME, e.REGNO, e.ENTTYPE, e.ENTTYPE_CN, e.INDUSTRYPHY, e.INDUSTRYCO, e.ESTDATE, e.REGORG, e.REGORG_CN, e.OPSCOTYPE, e.OPSCOTYPE_CN, e.OPSCOPE, e.OPFROM, e.OPTO, e.REGSTATE, e.REGSTATE_CN, e.DOMDISTRICT, e.DOM, e.REGCAP, e.REGCAPCUR, e.REGCAPCUR_CN, e.REGCAPUSD, e.RECCAP, e.RECCAPUSD, e.COUNTRY, e.EMPNUM, e.TOWN, e.NAME, e.REPORTTYPE, e.APPRDATE, e.s_ext_fromnode, e.s_ext_datatime, e.industry_name, e.rev_date, e.phone, e.email, e.address, e.website, e.regulatory, e.regulatory_name, e.open_from, e.open_to, e.score, e.level, e.update_by, e.update_time, e.create_by, e.create_time, e.label, e.branch, e.investment, e.traname, e.fundam, e.compform, e.compform_cn, e.localadm, e.oplocdistrict, e.oploc, e.tel, e.postalcode, e.region, e.street_long, e.street_name, e.ACCEPTREGORG, e.ACCEPTREGORG_CN, e.SUPORG, e.SUPORG_CN
    </sql>
    <update id="clearRegulatory">
        update aiccs.e_baseinfo
        set regulatory_temp = null,
            regulatory_name_temp = null,
            sareacode_temp = null,
            sareaname_temp = null,
            suporg = null,
            update_time = CURRENT_TIMESTAMP,
            update_by = 'system'
        where pripid = #{pripid}
    </update>
    <update id="updateRegulatory">
        update aiccs.e_baseinfo e
        set
            regulatory_temp = #{orgNumber},
            suporg = #{orgNumber},
            regulatory_name_temp = (select orgUnitName from cxaicorg.t_orgunits where orgNumber = #{orgNumber}),
            sareacode_temp = #{sliceId},
            sareaname_temp = #{sliceName},
            update_time = CURRENT_TIMESTAMP,
            update_by = 'system'
        where e.pripid = #{pripid}
    </update>
    <update id="updateEntAreaSliceInfo">
        update aiccs.e_baseinfo e
        set
        <if test="areaSlice.orgNumber != null and areaSlice.orgNumber != ''">
            regulatory_temp = #{areaSlice.orgNumber},
            suporg = #{areaSlice.orgNumber},
            regulatory_name_temp = (select orgUnitName from cxaicorg.t_orgunits where orgNumber = #{areaSlice.orgNumber}),
        </if>
        sareacode_temp = #{areaSlice.sliceId},
        sareaname_temp = #{areaSlice.sliceName},
        update_time = CURRENT_TIMESTAMP,
        update_by = 'system'
        where e.pripid = #{pripid}
    </update>
    <select id="selectComplexEntInfoPage" resultMap="ComplexEntInfoMap">
        select <include refid="E_Base_Column_List"/>
        from aiccs.e_baseinfo e
        <where>
            <if test="params != null">
                <if test="params.entName != null and params.entName neq ''">
                    and e.ENTNAME like concat('%', #{params.entName}, '%')
                </if>
                <if test="params.uniscid != null and params.uniscid neq ''">
                    and (e.UNISCID = #{params.uniscid} or e.REGNO = #{params.uniscid})
                </if>
                <if test="params.leRepName != null and params.leRepName neq ''">
                    and e.name like concat('%', #{params.leRepName}, '%')
                </if>
                <if test="params.regOrg != null and params.regOrg neq ''">
                    and e.REGORG = #{params.regOrg}
                </if>
                <if test="params.addr != null and params.addr neq ''">
                    and e.DOM like concat('%', #{params.addr}, '%')
                </if>
                <if test="params.opscope != null and params.opscope neq ''">
                    and e.opscope like concat('%', #{params.opscope}, '%')
                </if>
                <if test="params.estDateStart != null and params.estDateStart neq ''">
                    and e.ESTDATE <![CDATA[>=]]> STR_TO_DATE(#{params.estDateStart}, '%Y-%m-%d')
                </if>
                <if test="params.estDateEnd != null and params.estDateEnd neq ''">
                    and e.ESTDATE <![CDATA[<=]]> STR_TO_DATE(#{params.estDateEnd}, '%Y-%m-%d')
                </if>
                <if test="params.apprDateStart != null and params.apprDateStart neq ''">
                    and e.APPRDATE <![CDATA[>=]]> STR_TO_DATE(#{params.apprDateStart}, '%Y-%m-%d')
                </if>
                <if test="params.apprDateEnd != null and params.apprDateEnd neq ''">
                    and e.APPRDATE <![CDATA[>=]]> STR_TO_DATE(#{params.apprDateEnd}, '%Y-%m-%d')
                </if>
                <if test="params.riskLevel != null and params.riskLevel neq ''">
                    and e.level = #{params.riskLevel}
                </if>
            </if>
        </where>
    </select>

    <select id="selectNbAndDom" resultMap="BaseResultMap">
        SELECT t.UNISCID,t.entname,t.DOM,t.ENTTYPE,t.NAME,t.ESTDATE,t.REGNO,t.PRIPID
        FROM e_baseinfo t LEFT JOIN trentbaseinfo b ON  t.PRIPID = b.entityno
        <if test="customParamMap.reportYear != null and customParamMap.reportYear neq ''">
            and b.ReportYear in
            <foreach collection="customParamMap.reportYear" item="each" separator="," open="(" close=")">
                #{each}
            </foreach>
        </if>
        <if test="customParamMap.searchDom != null and customParamMap.searchDom neq ''">
            and b.addressNot=#{customParamMap.searchDom}
        </if>
        where
        b.entityno is null
        and t.Enttype not in ('9100', '9200', '9910')
        <if test="customParamMap.searchName != null and customParamMap.searchName neq ''">
            and t.entname like concat('%', #{customParamMap.searchName}, '%')
        </if>
        <if test="customParamMap.searchUscc != null and customParamMap.searchUscc neq ''">
            and (t.UNISCID like concat('%', #{customParamMap.searchUscc}, '%') or t.REGNO like concat('%', #{customParamMap.searchUscc}, '%'))
        </if>
        <if test="customParamMap.regulatory1 != null and customParamMap.regulatory1 neq ''">
            and t.regulatory like concat(#{customParamMap.regulatory1}, '%')
        </if>
        <if test="customParamMap.regulatory2 != null and customParamMap.regulatory2 neq ''">
            and t.regulatory = #{customParamMap.regulatory2}
        </if>
    </select>

    <select id="selectToIncludeAbnPage" resultType="com.chinaweal.aiccs.aiccs.abnormal.entity.dto.ToIncludeAbnDto">
        <choose>
            <when test="customParamMap.reportYear != null and customParamMap.reportYear neq ''">
                SELECT e.UNISCID,e.entname,e.DOM,e.ENTTYPE,e.ENTTYPE_CN,e.NAME,e.ESTDATE,e.REGNO,e.PRIPID,e.oploc,t.includeType, e.REGORG, GROUP_CONCAT(t.REPORTYEAR ORDER BY t.REPORTYEAR desc) as REPORTYEAR, t.regEntryUserName, t.toIncludeId
                from toincludeabn t LEFT JOIN e_baseinfo e on t.PRIPID = e.PRIPID
            </when>
            <otherwise>
                SELECT e.UNISCID,e.entname,e.DOM,e.ENTTYPE,e.ENTTYPE_CN,e.NAME,e.ESTDATE,e.REGNO,e.PRIPID,e.oploc,t.includeType, e.REGORG, t.reportYear, t.regEntryUserName, t.toIncludeId
                from toincludeabn t  LEFT JOIN e_baseinfo e on t.PRIPID = e.PRIPID
            </otherwise>
        </choose>
        <where>
            <if test="customParamMap.searchName != null and customParamMap.searchName neq ''">
                and e.entname like concat('%', #{customParamMap.searchName}, '%')
            </if>
            <if test="customParamMap.regEntryUserName != null and customParamMap.regEntryUserName neq ''">
                and t.regEntryUserName like concat('%', #{customParamMap.regEntryUserName}, '%')
            </if>
            <if test="customParamMap.uniscid != null and customParamMap.uniscid neq ''">
                and e.UNISCID = #{customParamMap.uniscid}
            </if>
            <if test="customParamMap.regno != null and customParamMap.regno neq ''">
                and e.regno = #{customParamMap.regno}
            </if>
            <if test="customParamMap.entertype != null and customParamMap.entertype neq ''">
                <if test="customParamMap.entertype eq 'individual' ">
                    and e.ENTTYPE in ('9910')
                </if>
                <if test="customParamMap.entertype eq 'farmer' ">
                    and e.ENTTYPE in ('9100','9200')
                </if>
                <if test="customParamMap.entertype eq 'company' ">
                    and e.ENTTYPE not in('9100', '9200', '9910')
                </if>
            </if>
            <if test="customParamMap.searchDom != null and customParamMap.searchDom neq ''">
                and e.DOM like concat('%', #{customParamMap.searchDom}, '%')
            </if>
            <if test="customParamMap.searchOploc != null and customParamMap.searchOploc neq ''">
                and e.oploc like concat('%', #{customParamMap.searchOploc}, '%')
            </if>
            <if test="customParamMap.includeType != null and customParamMap.includeType neq ''">
                and t.includeType = #{customParamMap.includeType}
            </if>
            <if test="customParamMap.regulatory1 != null and customParamMap.regulatory1 neq ''">
                <if test="customParamMap.entertype eq 'individual' ">
                    and e.localadm like concat(#{customParamMap.regulatory1}, '%')
                </if>
                <if test="customParamMap.entertype neq 'individual' ">
                    and e.regulatory like concat(#{customParamMap.regulatory1}, '%')
                </if>
            </if>
            <if test="customParamMap.regulatory2 != null and customParamMap.regulatory2 neq ''">
                <if test="customParamMap.entertype eq 'individual' ">
                    and e.localadm = #{customParamMap.regulatory2}
                </if>
                <if test="customParamMap.entertype neq 'individual' ">
                    and e.regulatory = #{customParamMap.regulatory2}
                </if>
            </if>
            and t.state = '0'
            <if test="customParamMap.reportYear != null and customParamMap.reportYear neq ''">
                and t.includeType = '1'
                group by t.PRIPID
                having REPORTYEAR like concat('%',#{customParamMap.reportYear}, '%')
            </if>
        </where>
    </select>

    <select id="comprehensiveQuery" resultMap="BaseResultMap">
        select * from e_baseinfo eb where 1=1
        <if test="customParamMap.uniscid != null and customParamMap.uniscid neq ''">
            and (eb.UNISCID = #{customParamMap.uniscid} or eb.REGNO = #{customParamMap.uniscid})
        </if>
        <if test="customParamMap.entName != null and customParamMap.entName neq ''">
            and eb.entname like concat('%', #{customParamMap.entName}, '%')
        </if>
        <if test="customParamMap.address != null and customParamMap.address neq ''">
            and eb.dom like concat('%', #{customParamMap.address}, '%')
        </if>
        <if test="customParamMap.name != null and customParamMap.name neq ''">
            and eb.name like concat('%', #{customParamMap.name}, '%')
        </if>
        <if test="customParamMap.OPSCOPE != null and customParamMap.OPSCOPE neq ''">
            and eb.opscope like concat('%', #{customParamMap.OPSCOPE}, '%')
        </if>
        <if test="customParamMap.INDUSTRYPHY != null and customParamMap.INDUSTRYPHY neq ''">
            and eb.industryphy = #{customParamMap.INDUSTRYPHY}
        </if>
        <if test="customParamMap.regorg != null and customParamMap.regorg neq ''">
            and eb.regorg = #{customParamMap.regorg}
        </if>
        <if test="customParamMap.risklevel != null and customParamMap.risklevel neq ''">
            and eb.level = #{customParamMap.risklevel}
        </if>
        <if test="customParamMap.eststartDate != null and customParamMap.eststartDate != '' ">
            and eb.estdate &gt;= #{customParamMap.eststartDate}
        </if>
        <if test="customParamMap.estendDate != null and customParamMap.estendDate != '' ">
            and eb.estdate &lt;= #{customParamMap.estendDate}
        </if>
        <if test="customParamMap.ENTTYPE != null and customParamMap.ENTTYPE neq ''">
            <if test="customParamMap.ENTTYPE eq 'individual' ">
                and eb.ENTTYPE in ('9910')
            </if>
            <if test="customParamMap.ENTTYPE eq 'farmer' ">
                and eb.ENTTYPE in ('9100','9200')
            </if>
            <if test="customParamMap.ENTTYPE eq 'company' ">
                and eb.ENTTYPE not in('9100', '9200', '9910')
            </if>
        </if>
        <if test="customParamMap.REGSTATE != null and customParamMap.REGSTATE != '' ">
            and eb.REGSTATE = #{customParamMap.REGSTATE}
        </if>
        <if test="customParamMap.regulatory1 != null and customParamMap.regulatory1 neq '' and customParamMap.contain != null and customParamMap.contain neq '' ">
            <if test="customParamMap.contain eq 'contain1' ">
                and eb.regulatory like concat(#{customParamMap.regulatory1}, '%')
            </if>
            <if test="customParamMap.contain eq 'contain0' ">
                and eb.regulatory = #{customParamMap.regulatory1}
            </if>
        </if>
        <if test="customParamMap.regulatory2 != null and customParamMap.regulatory2 neq ''">
            and eb.regulatory = #{customParamMap.regulatory2}
        </if>
    </select>

    <select id="queryCphStatistics" parameterType="java.util.Map" resultMap="ComprehensiveStatistics">
        select 'tsabnlist' as name, count(1) num from tsabnlist where 1=1
        <if test="customParamMap.startDate != null and customParamMap.startDate != '' and customParamMap.endDate != null and customParamMap.endDate != ''">
            and (ABNTIME &gt;= #{customParamMap.startDate} and ABNTIME &lt;= #{customParamMap.endDate})
            or (remdate &gt;= #{customParamMap.startDate} and remdate &lt;= #{customParamMap.endDate})
        </if>
        union all
        select 'entlock' as name, count(1) num from entlock e where 1=1
        <if test="customParamMap.startDate != null and customParamMap.startDate != '' and customParamMap.endDate != null and customParamMap.endDate != ''">
            and (date_format( locktime,'%Y-%m-%d') &gt;= #{customParamMap.startDate} and date_format( locktime,'%Y-%m-%d') &lt;= #{customParamMap.endDate})
            or (date_format( unlocktime,'%Y-%m-%d') &gt;= #{customParamMap.startDate} and date_format( unlocktime,'%Y-%m-%d') &lt;= #{customParamMap.endDate})
        </if>
        union all
        select 'eOtCase' as name, count(1) num from e_ot_case eoc where 1=1
        <if test="customParamMap.startDate != null and customParamMap.startDate != '' and customParamMap.endDate != null and customParamMap.endDate != ''">
            and PENDECISSDATE &gt;= #{customParamMap.startDate} and PENDECISSDATE &lt;= #{customParamMap.endDate}
        </if>
        union all
        select 'tsserillegallist' as name, count(1) num from tsserillegallist where 1=1
        <if test="customParamMap.startDate != null and customParamMap.startDate != '' and customParamMap.endDate != null and customParamMap.endDate != ''">
            and (ABNTIME &gt;= #{customParamMap.startDate} and ABNTIME &lt;= #{customParamMap.endDate})
            or (remdate &gt;= #{customParamMap.startDate} and remdate &lt;= #{customParamMap.endDate})
        </if>
        union all
        select 'eSusnateOperreg' as name, count(1) num from e_susnate_operreg where 1=1
        <if test="customParamMap.startDate != null and customParamMap.startDate != '' and customParamMap.endDate != null and customParamMap.endDate != ''">
            and juddate &gt;= #{customParamMap.startDate} and juddate &lt;= #{customParamMap.endDate}
        </if>
        union all
        select 'revokelist' as name, count(1) num from revokelist where 1=1
        <if test="customParamMap.startDate != null and customParamMap.startDate != '' and customParamMap.endDate != null and customParamMap.endDate != ''">
            and revokedate &gt;= #{customParamMap.startDate} and revokedate &lt;= #{customParamMap.endDate}
        </if>
    </select>

    <select id="queryCphStatSplit" parameterType="java.util.Map" resultMap="ComprehensiveStat">
        select orgn, orgunitname,
        <if test="customParamMap.bustype == 'abnormal' ">
            sum(abnlrnum) as abnlrnum,
            sum(abnycnum) as abnycnum,
            sum(abnycnumon) as abnycnumon,
            sum(abnycnumoff) as abnycnumoff,
            sum(abnyynum) as abnyynum
        </if>
        <if test="customParamMap.bustype == 'illegal' ">
            sum(leglrnum) as leglrnum,
            sum(legyynum) as legyynum,
            sum(legycnum) as legycnum,
            sum(legycnumon) as legycnumon,
            sum(legycnumoff) as legycnumoff
        </if>
        from (
        select rs2.orgn, rs2.orgunitname,
        <if test="customParamMap.bustype == 'abnormal' ">
            rs1.abnlrnum,
            rs1.abnycnum,
            rs1.abnycnumon,
            rs1.abnycnumoff,
            rs1.abnyynum
        </if>
        <if test="customParamMap.bustype == 'illegal' ">
            rs1.leglrnum,
            rs1.legyynum,
            rs1.legycnum,
            rs1.legycnumon,
            rs1.legycnumoff
        </if>
        from (
        select SIGNUSERID,
        <if test="customParamMap.bustype == 'abnormal' ">
            count(case when bustype in ('5','13','11') then 1 else null end) as abnlrnum,
            count(case when bustype in ('7','14','12') then 1 else null end) as abnycnum,
            count(case when bustype in ('7','14','12') and origin='1' then 1 else null end) as abnycnumon,
            count(case when bustype in ('7','14','12') and (origin is null or origin!='1') then 1 else null end) as abnycnumoff,
            count(case when bustype='6' then 1 else null end) as abnyynum
        </if>
        <if test="customParamMap.bustype == 'illegal' ">
            count(case when bustype='15' then 1 else null end) as leglrnum,
            count(case when bustype='16' then 1 else null end) as legyynum,
            count(case when bustype='17' then 1 else null end) as legycnum,
            count(case when bustype='17' and origin='1' then 1 else null end) as legycnumon,
            count(case when bustype='17' and (origin is null or origin!='1') then 1 else null end) as legycnumoff
        </if>
        from
        (select BIZSEQID,BUSTYPE,max(SIGNUSERID) SIGNUSERID from aiccs.tstasklist where BUSSTATUS !=4
        <if test="customParamMap.busstatus == 1 ">
            and BUSSTATUS = '2'
        </if>
        <if test="customParamMap.busstatus == 2 ">
            and BUSSTATUS = '0'
        </if>
        <if test="customParamMap.startDate != null and customParamMap.startDate != '' ">
            and date_format(SIGNTIME,'%Y-%m-%d') &gt;= #{customParamMap.startDate}
        </if>
        <if test="customParamMap.endDate != null and customParamMap.endDate != '' ">
            and date_format(SIGNTIME,'%Y-%m-%d') &lt;= #{customParamMap.endDate}
        </if>
        group by bizseqid,BUSTYPE
        ) t2
        group by SIGNUSERID
        ) rs1 left join (
        select rs.*, tog.orgunitname from (
        select tu.userid, left(tog.orgNumber,6) as orgn from cxaicorg.t_users tu
        left join cxaicorg.t_orgunits tog on tu.orgunitid = tog.orgunitid
        ) rs left join cxaicorg.t_orgunits tog on rs.orgn = tog.orgNumber
        )rs2 on rs1.SIGNUSERID = rs2.userid
        where rs2.orgn is not null and rs2.orgunitname is not null
        ) jg group by orgn, orgunitname
        order by orgn asc
    </select>

    <select id="queryCphStat" parameterType="java.util.Map" resultMap="ComprehensiveStat">
        select orgn, orgunitname,
        sum(abnlrnum) as abnlrnum,
        sum(abnycnum) as abnycnum,
        sum(abnycnumon) as abnycnumon,
        sum(abnycnumoff) as abnycnumoff,
        sum(abnyynum) as abnyynum,
        sum(leglrnum) as leglrnum,
        sum(legyynum) as legyynum,
        sum(legycnum) as legycnum,
        sum(legycnumon) as legycnumon,
        sum(legycnumoff) as legycnumoff,
        sum(penxfnum) as penxfnum,
        sum(penxfnumon) as penxfnumon,
        sum(penxfnumoff) as penxfnumoff,
        sum(ualfknum) as ualfknum,
        sum(mytrnum) as mytrnum,
        sum(wtcznum) as wtcznum,
        sum(legxfnum) as legxfnum,
        sum(xyfxyynum) as xyfxyynum,
        sum(abnkwnum) as abnkwnum,
        sum(legkwnum) as legkwnum,
        sum(pldxnum) as pldxnum,
        sum(cxnum) as cxnum,
        sum(fynum) as fynum,
        sum(susnum) as susnum,
        sum(locknum) as locknum,
        sum(unlocknum) as unlocknum
        from (
        select rs2.orgn, rs2.orgunitname,
        rs1.abnlrnum,
        rs1.abnycnum,
        rs1.abnycnumon,
        rs1.abnycnumoff,
        rs1.abnyynum,
        rs1.leglrnum,
        rs1.legyynum,
        rs1.legycnum,
        rs1.legycnumon,
        rs1.legycnumoff,
        rs1.penxfnum,
        rs1.penxfnumon,
        rs1.penxfnumoff,
        rs1.ualfknum,
        rs1.mytrnum,
        rs1.wtcznum,
        rs1.legxfnum,
        rs1.xyfxyynum,
        rs1.abnkwnum,
        rs1.legkwnum,
        rs1.pldxnum,
        rs1.cxnum,
        rs1.fynum,
        rs1.susnum,
        rs1.locknum,
        rs1.unlocknum
        from (
        select SIGNUSERID,
        count(case when bustype in ('5','13','11') then 1 else null end) as abnlrnum,
        count(case when bustype in ('7','14','12') then 1 else null end) as abnycnum,
        count(case when bustype in ('7','14','12') and origin='1' then 1 else null end) as abnycnumon,
        count(case when bustype in ('7','14','12') and (origin is null or origin!='1') then 1 else null end) as abnycnumoff,
        count(case when bustype='6' then 1 else null end) as abnyynum,
        count(case when bustype='15' then 1 else null end) as leglrnum,
        count(case when bustype='16' then 1 else null end) as legyynum,
        count(case when bustype='17' then 1 else null end) as legycnum,
        count(case when bustype='17' and origin='1' then 1 else null end) as legycnumon,
        count(case when bustype='17' and (origin is null or origin!='1') then 1 else null end) as legycnumoff,
        count(case when bustype='27' then 1 else null end) as penxfnum,
        count(case when bustype='27' and origin='1' then 1 else null end) as penxfnumon,
        count(case when bustype='27' and (origin is null or origin!='1') then 1 else null end) as penxfnumoff,
        count(case when bustype='30' then 1 else null end) as ualfknum,
        count(case when bustype='31' then 1 else null end) as mytrnum,
        count(case when bustype='32' then 1 else null end) as wtcznum,
        count(case when bustype='33' then 1 else null end) as legxfnum,
        count(case when bustype='36' then 1 else null end) as xyfxyynum,
        count(case when bustype='40' then 1 else null end) as abnkwnum,
        count(case when bustype='41' then 1 else null end) as legkwnum,
        count(case when bustype='51' then 1 else null end) as pldxnum,
        count(case when bustype='52' then 1 else null end) as cxnum,
        count(case when bustype='53' then 1 else null end) as fynum,
        count(case when bustype='54' then 1 else null end) as susnum,
        count(case when bustype='61' then 1 else null end) as locknum,
        count(case when bustype='62' then 1 else null end) as unlocknum
        from
        (select BIZSEQID,BUSTYPE,max(SIGNUSERID) SIGNUSERID,origin from aiccs.tstasklist where BUSSTATUS !=4
        <if test="customParamMap.busstatus == 1 ">
            and BUSSTATUS = '2'
        </if>
        <if test="customParamMap.busstatus == 2 ">
            and BUSSTATUS = '0'
        </if>
        <if test="customParamMap.startDate != null and customParamMap.startDate != '' ">
            and date_format(SIGNTIME,'%Y-%m-%d') &gt;= #{customParamMap.startDate}
        </if>
        <if test="customParamMap.endDate != null and customParamMap.endDate != '' ">
            and date_format(SIGNTIME,'%Y-%m-%d') &lt;= #{customParamMap.endDate}
        </if>
        group by bizseqid,BUSTYPE,origin
        ) t2
        group by SIGNUSERID
        ) rs1 left join (
        select rs.*, tog.orgunitname from (
        select tu.userid,
        <choose>
            <when test="customParamMap.regionId == null or customParamMap.regionId == '150000' ">
                left(tog.orgNumber,4)||'00'
            </when>
            <when test="customParamMap.regionId.length() == 6 and customParamMap.regionId.endsWith('00')">
                left(tog.orgNumber,6)
            </when>
            <otherwise>
                tog.orgNumber
            </otherwise>
        </choose>
        as orgn from cxaicorg.t_users tu
        left join cxaicorg.t_orgunits tog on tu.orgunitid = tog.orgunitid
        ) rs left join cxaicorg.t_orgunits tog on rs.orgn = tog.orgNumber
        )rs2 on rs1.SIGNUSERID = rs2.userid
        where rs2.orgn is not null and rs2.orgunitname is not null
        <choose>
            <when test="customParamMap.regionId == null or customParamMap.regionId == '150000' ">
                and rs2.orgn like '15%'
            </when>
            <when test="customParamMap.regionId.length() == 6 and customParamMap.regionId.endsWith('00')">
                and rs2.orgn like left(#{customParamMap.regionId},4)||'%'
            </when>
            <when test="customParamMap.regionId.length() == 6">
                and rs2.orgn like left(#{customParamMap.regionId},6)||'%'
            </when>
            <otherwise>
                and rs2.orgn like #{customParamMap.regionId}||'%'
            </otherwise>
        </choose>
        ) jg group by orgn, orgunitname
        order by orgn asc
    </select>

    <select id="selectSDCWandTwoYearsAbnlist" resultType="com.chinaweal.aiccs.aiccs.abnormal.entity.dto.AbnEntDto">
        select e.REGNO, e.PRIPID, e.UNISCID, e.ENTNAME, e.ENTTYPE, e.lerep, t.ABNTIME,t.ABNLISTID,t.SPEREASONS
        FROM tsabnlist t
        left JOIN e_baseinfo e on t.PRIPID = e.pripid
        left join trentbaseinfo tr on e.REGNO = tr.REGISTNO
        WHERE t.SPEREASONS LIKE '%联系%' and t.ENTTYPE not in ('9910','4530','4531','4532','4533','5400','5410','5420','5430','6400','6410','6420','6430') and t.OPERATESTATUS = '1' and e.REGSTATE = '1'
        <if test="customParamMap.yearReport != null and customParamMap.yearReport != '' ">
            and tr.REPORTYEAR = #{customParamMap.yearReport}
        </if>
        <if test="customParamMap.abntime != null and customParamMap.abntime != '' ">
            and t.abntime &lt; #{customParamMap.abntime}
        </if>
        <if test="customParamMap.regno != null and customParamMap.regno != '' ">
            and e.regno = #{customParamMap.regno}
        </if>
        <if test="customParamMap.uniscid != null and customParamMap.uniscid != '' ">
            and e.uniscid = #{customParamMap.uniscid}
        </if>
    </select>

    <select id="selectNoReportTwoYearsPage" resultType="com.chinaweal.aiccs.aiccs.abnormal.entity.dto.NoAnnualReportEntDto">
        SELECT e.REGNO, e.PRIPID, e.UNISCID, e.ENTNAME, e.ENTTYPE, e.REGSTATE, e.REGSTATE_CN, e.lerep, n.REPORTYEAR
        from noannualreport n
        left JOIN e_baseinfo e on n.PRIPID = e.PRIPID
        LEFT JOIN noannualreport b on n.PRIPID = b.PRIPID
        WHERE n.REPORTYEAR ='2020' and b.REPORTYEAR = '2019' and e.REGSTATE = '1' and e.ENTTYPE not in ('9910','4530','4531','4532','4533','5400','5410','5420','5430','6400','6410','6420','6430')
        <if test="customParamMap.regno != null and customParamMap.regno != '' ">
            and e.regno = #{customParamMap.regno}
        </if>
        <if test="customParamMap.uniscid != null and customParamMap.uniscid != '' ">
            and e.uniscid = #{customParamMap.uniscid}
        </if>
    </select>

    <!--实地查无列异两年及是否独资查询   -->
    <select id="selectSDCWandTwoYearsPage" resultType="com.chinaweal.aiccs.aiccs.abnormal.entity.EBaseinfo">
        <choose>
            <when test="customParamMap.isGRDZ eq 'GRDZ'">
                SELECT <include refid="E_Base_Column_List"/>
                FROM (SELECT DISTINCT PRIPID
                FROM tsabnlist t
                WHERE t.ENTTYPE in
                <foreach collection="customParamMap.sole" item="each" separator="," open="(" close=")">
                    #{each}
                </foreach>
                and t.SPECAUSE = '4' and t.OPERATESTATUS = '1'
                <if test="customParamMap.abntime != null and customParamMap.abntime != '' ">
                    and t.abntime &lt; #{customParamMap.abntime}
                </if>
                ) m
                LEFT JOIN e_baseinfo e on m.pripid = e.PRIPID
                INNER JOIN trentbaseinfo tr on e.REGNO = tr.REGISTNO
            </when>
            <otherwise>
                SELECT <include refid="E_Base_Column_List"/>
                FROM (SELECT DISTINCT PRIPID
                FROM tsabnlist t
                WHERE t.ENTTYPE in
                <foreach collection="customParamMap.company" item="each" separator="," open="(" close=")">
                    #{each}
                </foreach>
                and t.SPECAUSE = '4' and t.OPERATESTATUS = '1'
                <if test="customParamMap.abntime != null and customParamMap.abntime != '' ">
                    and t.abntime &lt; #{customParamMap.abntime}
                </if>
                ) m
                LEFT JOIN e_baseinfo e on m.pripid = e.PRIPID
                INNER JOIN trentbaseinfo tr on e.REGNO = tr.REGISTNO
            </otherwise>
        </choose>
        where 1=1
        <if test="customParamMap.yearReport != null and customParamMap.yearReport != '' ">
            and tr.REPORTYEAR = #{customParamMap.yearReport}
        </if>
        <if test="customParamMap.regno != null and customParamMap.regno != '' ">
            and e.regno = #{customParamMap.regno}
        </if>
        <if test="customParamMap.uniscid != null and customParamMap.uniscid != '' ">
            and e.uniscid = #{customParamMap.uniscid}
        </if>
        <!--登记机关-->
        <if test="customParamMap.regorgFinal != null and customParamMap.regorgFinal != '' ">
            and e.regorg like concat(#{customParamMap.regorgFinal}, '%')
        </if>
        <!--企业名称-->
        <if test="customParamMap.entName != null and customParamMap.entName != '' ">
            and e.ENTNAME like concat('%', #{customParamMap.entName}, '%')
        </if>
        <!--法定代表人-->
        <if test="customParamMap.name != null and customParamMap.name != '' ">
            and e.LEREP = #{customParamMap.name}
        </if>
        <!--管理片区-->
        <if test="customParamMap.regulatoryList != null and customParamMap.regulatoryList.size() > 0 ">
            and e.sareacode_temp in
            <foreach collection="customParamMap.regulatoryList" index="index" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <!--主体类型筛选-->
        <!--企业-->
        <if test="customParamMap.enttype != null and customParamMap.enttype == 'company'">
            and e.enttype not in
            ('8000','8100','8200','8300','9000','9100','9200','9910','99100','99101','99102','99103','9999')
        </if>
        <!--个体户-->
        <if test="customParamMap.enttype != null and customParamMap.enttype == 'individual'">
            and e.enttype in ('9910','99100','99101','99102','99103','9999')
        </if>
        <!--农合-->
        <if test="customParamMap.enttype != null and customParamMap.enttype == 'farmer'">
            and e.enttype in ('9100','9200')
        </if>
        <!--主体状态市局标准-->
        <if test="customParamMap.entStatus != null and customParamMap.entStatus != ''">
            and e.entstatus = #{customParamMap.entStatus}
        </if>
        <!--主体状态国标-->
        <if test="customParamMap.regstate != null and customParamMap.regstate != ''">
            and e.regstate = #{customParamMap.regstate}
        </if>
        <!--经营地址-->
        <if test="customParamMap.dom != null and customParamMap.dom != '' ">
            and e.DOM like concat('%', #{customParamMap.dom}, '%')
        </if>
        <!--成立日期-->
        <if test="customParamMap.eststartDate != null and customParamMap.eststartDate != '' and customParamMap.estendDate != null and customParamMap.estendDate != ''">
            and e.ESTDATE BETWEEN #{customParamMap.eststartDate} and #{customParamMap.estendDate}
        </if>
        <!--核准日期-->
        <if test="customParamMap.apprDatestart != null and customParamMap.apprDatestart != '' and customParamMap.apprDateend != null and customParamMap.apprDateend != ''">
            and e.APPRDATE BETWEEN #{customParamMap.apprDatestart} and #{customParamMap.apprDateend}
        </if>
        <!--风险监管级别-->
        <if test="customParamMap.risklevel != null and customParamMap.risklevel != '' ">
            and e.level = #{customParamMap.risklevel}
        </if>
        <!--是否年报-->
        <if test="customParamMap.isnb != null and customParamMap.isnb != '' and customParamMap.nbyear != null and customParamMap.nbyear != ''">
            <if test="customParamMap.isnb == 'y'.toString()">
                and tr.REPORTYEAR >= #{customParamMap.nbyear}
            </if>
            <if test="customParamMap.isnb == 'n'.toString()">
                and tr.REPORTYEAR &lt; #{customParamMap.nbyear}
            </if>
        </if>
    </select>

    <!--连续未年报及主体是否独资查询 -->
    <select id="selectNoReportPage" resultType="com.chinaweal.aiccs.aiccs.abnormal.entity.EBaseinfo">
        SELECT <include refid="E_Base_Column_List"/>
        FROM (SELECT PRIPID FROM noannualreport
        where
        <if test="customParamMap.reportYear != null and customParamMap.reportYear neq ''">
            reportYear in
            <foreach collection="customParamMap.reportYear" item="each" separator="," open="(" close=")">
                #{each}
            </foreach>
        </if>
        GROUP BY PRIPID
        <if test="customParamMap.yearSize != null">
            HAVING count(1) = #{customParamMap.yearSize}
        </if>
        ) m
        LEFT JOIN e_baseinfo e on m.pripid = e.PRIPID
        LEFT JOIN trentbaseinfo tr on e.REGNO = tr.REGISTNO
        where 1=1
        <if test="customParamMap.isGRDZ eq 'NOGRDZ'">
            and e.ENTTYPE in
            <foreach collection="customParamMap.company" item="each" separator="," open="(" close=")">
                #{each}
            </foreach>
        </if>
        <if test="customParamMap.isGRDZ eq 'GRDZ'">
            and e.ENTTYPE in
            <foreach collection="customParamMap.sole" item="each" separator="," open="(" close=")">
                #{each}
            </foreach>
        </if>
        <if test="customParamMap.yearReport != null and customParamMap.yearReport != '' ">
            and tr.REPORTYEAR = #{customParamMap.yearReport}
        </if>
        <if test="customParamMap.regno != null and customParamMap.regno != '' ">
            and e.regno = #{customParamMap.regno}
        </if>
        <if test="customParamMap.uniscid != null and customParamMap.uniscid != '' ">
            and e.uniscid = #{customParamMap.uniscid}
        </if>
        <if test="customParamMap.regorg != null and customParamMap.regorg != '' ">
            and e.regorg like concat(#{customParamMap.regorg}, '%')
        </if>
    </select>

    <!--两年未年报实地查无及主体是否独资查询 -->
    <select id="selectWnbAndSdcwPage" resultType="com.chinaweal.aiccs.aiccs.abnormal.entity.EBaseinfo">
        <choose>
            <when test="customParamMap.isGRDZ eq 'GRDZ'">
                SELECT <include refid="E_Base_Column_List"/>
                FROM (select n.pripid
                from noannualreport n
                INNER JOIN tsabnlist t on n.PRIPID = t.PRIPID

                WHERE n.reportYear not in
                <foreach collection="customParamMap.reportYear" item="each" separator="," open="(" close=")">
                    #{each}
                </foreach>
                and t.specause = '4' and t.OPERATESTATUS = '1' and t.ENTTYPE in
                <foreach collection="customParamMap.sole" item="each" separator="," open="(" close=")">
                    #{each}
                </foreach>
                ) m
                LEFT JOIN e_baseinfo e on m.pripid = e.PRIPID
                INNER JOIN trentbaseinfo tr on e.REGNO = tr.REGISTNO
            </when>
            <otherwise>
                SELECT <include refid="E_Base_Column_List"/>
                FROM (select n.pripid
                from noannualreport n
                INNER JOIN tsabnlist t on n.PRIPID = t.PRIPID
                WHERE n.reportYear not in
                <foreach collection="customParamMap.reportYear" item="each" separator="," open="(" close=")">
                    #{each}
                </foreach>
                and t.specause = '4' and t.OPERATESTATUS = '1' and t.ENTTYPE in
                <foreach collection="customParamMap.company" item="each" separator="," open="(" close=")">
                    #{each}
                </foreach>
                ) m
                LEFT JOIN e_baseinfo e on m.pripid = e.PRIPID
                INNER JOIN trentbaseinfo tr on e.REGNO = tr.REGISTNO
            </otherwise>
        </choose>
        where 1=1
        <if test="customParamMap.yearReport != null and customParamMap.yearReport != '' ">
            and tr.REPORTYEAR = #{customParamMap.yearReport}
        </if>
        <if test="customParamMap.regno != null and customParamMap.regno != '' ">
            and e.regno = #{customParamMap.regno}
        </if>
        <if test="customParamMap.uniscid != null and customParamMap.uniscid != '' ">
            and e.uniscid = #{customParamMap.uniscid}
        </if>
        <!--登记机关-->
        <if test="customParamMap.regorgFinal != null and customParamMap.regorgFinal != '' ">
            and e.regorg like concat(#{customParamMap.regorgFinal}, '%')
        </if>
        <!--企业名称-->
        <if test="customParamMap.entName != null and customParamMap.entName != '' ">
            and e.ENTNAME like concat('%', #{customParamMap.entName}, '%')
        </if>
        <!--法定代表人-->
        <if test="customParamMap.name != null and customParamMap.name != '' ">
            and e.LEREP = #{customParamMap.name}
        </if>
        <!--管理片区-->
        <if test="customParamMap.regulatoryList != null and customParamMap.regulatoryList.size() > 0 ">
            and e.sareacode_temp in
            <foreach collection="customParamMap.regulatoryList" index="index" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <!--主体类型筛选-->
        <!--企业-->
        <if test="customParamMap.enttype != null and customParamMap.enttype == 'company'">
            and e.enttype not in
            ('8000','8100','8200','8300','9000','9100','9200','9910','99100','99101','99102','99103','9999')
        </if>
        <!--个体户-->
        <if test="customParamMap.enttype != null and customParamMap.enttype == 'individual'">
            and e.enttype in ('9910','99100','99101','99102','99103','9999')
        </if>
        <!--农合-->
        <if test="customParamMap.enttype != null and customParamMap.enttype == 'farmer'">
            and e.enttype in ('9100','9200')
        </if>
        <!--主体状态市局标准-->
        <if test="customParamMap.entStatus != null and customParamMap.entStatus != ''">
            and e.entstatus = #{customParamMap.entStatus}
        </if>
        <!--主体状态国标-->
        <if test="customParamMap.regstate != null and customParamMap.regstate != ''">
            and e.regstate = #{customParamMap.regstate}
        </if>
        <!--经营地址-->
        <if test="customParamMap.dom != null and customParamMap.dom != '' ">
            and e.DOM like concat('%', #{customParamMap.dom}, '%')
        </if>
        <!--成立日期-->
        <if test="customParamMap.eststartDate != null and customParamMap.eststartDate != '' and customParamMap.estendDate != null and customParamMap.estendDate != ''">
            and e.ESTDATE BETWEEN #{customParamMap.eststartDate} and #{customParamMap.estendDate}
        </if>
        <!--核准日期-->
        <if test="customParamMap.apprDatestart != null and customParamMap.apprDatestart != '' and customParamMap.apprDateend != null and customParamMap.apprDateend != ''">
            and e.APPRDATE BETWEEN #{customParamMap.apprDatestart} and #{customParamMap.apprDateend}
        </if>
        <!--风险监管级别-->
        <if test="customParamMap.risklevel != null and customParamMap.risklevel != '' ">
            and e.level = #{customParamMap.risklevel}
        </if>
        <!--是否年报-->
        <if test="customParamMap.isnb != null and customParamMap.isnb != '' and customParamMap.nbyear != null and customParamMap.nbyear != ''">
            <if test="customParamMap.isnb == 'y'.toString()">
                and tr.REPORTYEAR >= #{customParamMap.nbyear}
            </if>
            <if test="customParamMap.isnb == 'n'.toString()">
                and tr.REPORTYEAR &lt; #{customParamMap.nbyear}
            </if>
        </if>
    </select>

    <select id="selectYearReport" resultType="com.chinaweal.aiccs.aiccs.abnormal.entity.EBaseinfo">
        select <include refid="E_Base_Column_List"/>
        from e_baseinfo e
        INNER JOIN  crgs.trentbaseinfo tr on e.REGNO = tr.RegistNo
        where 1=1
        <if test="customParamMap.isGRDZ eq 'NOGRDZ'">
            and e.ENTTYPE in
            <foreach collection="customParamMap.company" item="each" separator="," open="(" close=")">
                #{each}
            </foreach>
        </if>
        <if test="customParamMap.isGRDZ eq 'GRDZ'">
            and e.ENTTYPE in
            <foreach collection="customParamMap.sole" item="each" separator="," open="(" close=")">
                #{each}
            </foreach>
        </if>
        <if test="customParamMap.yearReport != null and customParamMap.yearReport != '' ">
            and tr.REPORTYEAR = #{customParamMap.yearReport}
        </if>
        <if test="customParamMap.regno != null and customParamMap.regno != '' ">
            and e.regno = #{customParamMap.regno}
        </if>
        <if test="customParamMap.uniscid != null and customParamMap.uniscid != '' ">
            and e.uniscid = #{customParamMap.uniscid}
        </if>
        <if test="customParamMap.regorg != null and customParamMap.regorg != '' ">
            and e.regorg like concat(#{customParamMap.regorg}, '%')
        </if>
    </select>

    <select id="selectYearReportAll" resultType="com.chinaweal.aiccs.aiccs.abnormal.entity.excel.EBaseinfoExcel">
        select <include refid="E_Base_Column_List"/>
        from e_baseinfo e
        INNER JOIN  crgs.trentbaseinfo tr on e.REGNO = tr.RegistNo
        where 1=1
        <if test="customParamMap.isGRDZ eq 'NOGRDZ'">
            and e.ENTTYPE in
            <foreach collection="customParamMap.company" item="each" separator="," open="(" close=")">
                #{each}
            </foreach>
        </if>
        <if test="customParamMap.isGRDZ eq 'GRDZ'">
            and e.ENTTYPE in
            <foreach collection="customParamMap.sole" item="each" separator="," open="(" close=")">
                #{each}
            </foreach>
        </if>
        <if test="customParamMap.yearReport != null and customParamMap.yearReport != '' ">
            and tr.REPORTYEAR = #{customParamMap.yearReport}
        </if>
        <if test="customParamMap.regno != null and customParamMap.regno != '' ">
            and e.regno = #{customParamMap.regno}
        </if>
        <if test="customParamMap.uniscid != null and customParamMap.uniscid != '' ">
            and e.uniscid = #{customParamMap.uniscid}
        </if>
        <if test="customParamMap.regorg != null and customParamMap.regorg != '' ">
            and e.regorg like concat(#{customParamMap.regorg}, '%')
        </if>
    </select>
    <!-- 失信异常名单-企业查询 -->
    <select id="selectBlackForEnt" resultType="java.util.Map">
        select
        eb.PRIPID as "企业主键",
        eb.UNISCID as "统一社会信用代码",
        eb.ENTNAME as "企业名称",
        (case when exists (select 1 from tsserillegallist ts where ts.PRIPID = eb.PRIPID and ts.REMDATE is null)
        or exists (select 1 from tsabnlist ta where ta.PRIPID = eb.PRIPID and ta.REMDATE is null)
        or exists (select 1 from revokelist r where r.PRIPID = eb.PRIPID and r.STATE = '1' )
        then '异常' else '移出' end) as "状态"
        from e_baseinfo eb
        where (exists ( select 1 from tsserillegallist ts where ts.PRIPID = eb.PRIPID)
        or exists ( select 1 from tsabnlist ta where ta.PRIPID = eb.PRIPID)
        or exists ( select 1 from revokelist r where r.PRIPID = eb.PRIPID and r.STATE != '2'))
        <if test="uscc != null and uscc != '' ">
            and eb.UNISCID = #{uscc}
        </if>
        <if test="entName != null and entName != '' ">
            and eb.ENTNAME like concat('%', #{entName}, '%')
        </if>
    </select>

    <!-- 失信异常企业名单-根据自然人查询 -->
    <select id="getEntBlackForPerson" resultType="java.util.Map">
        select
        ep.PRIPID as "企业主键",
        eb.UNISCID as "统一社会信用代码",
        eb.ENTNAME as "企业名称",
        (select name from trbasecode t where t.CODEID = 'CA19' and t.CODE = eb.REGSTATE) as "状态"
        from e_baseinfo eb, crgs.e_pri_person ep
        where eb.PRIPID = ep.PRIPID
        <if test="cerNo != null and cerNo != '' ">
            and ep.CERNO = #{cerNo}
        </if>
    </select>

    <!--  失信异常名单-自然人查询 -->
    <select id="selectBlackForPerson" resultType="java.util.Map">
        select
        ep.NAME as "姓名",
        ep.CERNO as "身份证号码",
        '异常' as "状态"
        from crgs.e_pri_person ep
        where (exists ( select 1 from crgs.e_li_black elb where elb.CERNO = ep.CERNO )
        or exists ( select 1 from crgs.t_laolai_gr tlg where tlg.CARDNUM = ep.CERNO ))
        <if test="cerNo != null and cerNo != '' ">
            and ep.CERNO = #{cerNo}
        </if>
        <if test="name != null and name != '' ">
            and ep.NAME like concat('%', #{name}, '%')
        </if>
    </select>

    <!--  失信异常名单-统计 -->
    <select id="statistics" resultType="java.util.Map">
        select
            '广州市市场监督管理局' as "单位名称",
            经营异常列入数量分组 as "经营异常列入数量-分组(农专、个体户、企业)",
            经营异常移出数量 as "经营异常-移出数量",
            IFNULL(concat((经营异常列入数量 - 经营异常同比列入数量)/经营异常同比列入数量 * 100, '%'), '0%') as "经营异常-同比增长率",
            IFNULL(concat((经营异常列入数量 - 经营异常环比列入数量)/经营异常环比列入数量 * 100, '%'), '0%')  as "经营异常-环比增长率",
            严重违法列入数量分组 as "严重违法列入数量-分组(农专、个体户、企业)",
            严重违法移出数量 as "严重违法-移出数量",
            IFNULL(concat((严重违法列入数量 - 严重违法同比列入数量)/严重违法同比列入数量 * 100, '%'), '0%') as "严重违法-同比增长率",
            IFNULL(concat((严重违法列入数量 - 严重违法环比列入数量)/严重违法环比列入数量 * 100, '%'), '0%')  as "严重违法-环比增长率",
            批量吊销列入数量 as "批量吊销-列入数量",
            IFNULL(concat((批量吊销列入数量 - 批量吊销同比列入数量)/批量吊销同比列入数量 * 100, '%'), '0%') as "批量吊销-同比增长率",
            IFNULL(concat((批量吊销列入数量 - 批量吊销环比列入数量)/批量吊销环比列入数量 * 100, '%'), '0%')  as "批量吊销-环比增长率"
        from
            (
                select
                    (select concat_ws(',', sum(NH), sum(GTH), sum(QY)) from (select (case when ENTTYPE in ('9100', '9200') then 1 else 0 end) as "NH", (case when ENTTYPE = '9910' then 1 else 0 end) as "GTH", (case when ENTTYPE not in ('9100', '9200', '9910') then 1 else 0 end) as "QY" from tsabnlist ta where ta.ABNTIME between #{startDate} and #{endDate} group by ta.PRIPID, ta.ENTTYPE) tmp ) as "经营异常列入数量分组",
                    (select count(distinct ta.PRIPID) from tsabnlist ta where ta.ABNTIME between #{startDate} and #{endDate}) as "经营异常列入数量", -- 列入数量
                    (select count(distinct ta.PRIPID) from tsabnlist ta where ta.ABNTIME between #{yearOnYearStartDate} and #{yearOnYearEndDate}) as "经营异常同比列入数量", -- 同比列入数量
                    (select count(distinct ta.PRIPID) from tsabnlist ta where ta.ABNTIME between #{chainRatioStartDate} and #{chainRatioEndDate}) as "经营异常环比列入数量", -- 环比列入数量
                    (select count(distinct ta.PRIPID) from tsabnlist ta where ta.REMDATE between #{startDate} and #{endDate}) as "经营异常移出数量", -- 移出数量

                    (select concat_ws(',', sum(NH), sum(GTH), sum(QY)) from (select (case when eb.ENTTYPE in ('9100', '9200') then 1 else 0 end) as "NH", (case when eb.ENTTYPE = '9910' then 1 else 0 end) as "GTH", (case when eb.ENTTYPE not in ('9100', '9200', '9910') then 1 else 0 end) as "QY" from tsserillegallist ts, e_baseinfo eb where ts.PRIPID = eb.PRIPID and  ts.ABNTIME between #{startDate} and #{endDate} group by ts.PRIPID, eb.ENTTYPE) tmp) as "严重违法列入数量分组",
                    (select count(distinct ta.PRIPID) from tsserillegallist ta where ta.ABNTIME between #{startDate} and #{endDate}) as "严重违法列入数量", -- 列入数量
                    (select count(distinct ta.PRIPID) from tsserillegallist ta where ta.ABNTIME between #{yearOnYearStartDate} and #{yearOnYearEndDate}) as "严重违法同比列入数量", -- 同比列入数量
                    (select count(distinct ta.PRIPID) from tsserillegallist ta where ta.ABNTIME between #{chainRatioStartDate} and #{chainRatioEndDate}) as "严重违法环比列入数量", -- 环比列入数量
                    (select count(distinct ta.PRIPID) from tsserillegallist ta where ta.REMDATE between #{startDate} and #{endDate}) as "严重违法移出数量", -- 移出数量

                    (select count(distinct r.PRIPID) from revokelist r where r.REVOKEDATE between #{startDate} and #{endDate}) as "批量吊销列入数量", -- 批量吊销列入数量
                    (select count(distinct r.PRIPID) from revokelist r where r.REVOKEDATE between #{yearOnYearStartDate} and #{yearOnYearEndDate}) as "批量吊销同比列入数量", -- 批量吊销
                    (select count(distinct r.PRIPID) from revokelist r where r.REVOKEDATE between #{startDate} and #{endDate}) as "批量吊销环比列入数量" -- 批量吊销环比列入数量
            ) temp;
    </select>

    <select id="getAddressAbnPage" resultMap="BaseResultMap">
        select e.PRIPID, e.UNISCID, e.ENTNAME, e.REGNO, e.LEREP, e.ACCEPTREGORG, e.ACCEPTREGORG_CN, e.SUPORG, e.SUPORG_CN, e.REGORG, e.REGORG_CN, e.DOM ,e.oploc
        from e_baseinfo e
        <where>
            e.REGSTATE = '1'
            <if test='customParamMap.entertype =="individual"'>
                and EXISTS (SELECT 1 FROM tsabnlist t WHERE t.pripid = e.pripid and t.specause = '3' and t.OPERATESTATUS = '1')
            </if>
            <if test='customParamMap.entertype =="company"'>
                and EXISTS (SELECT 1 FROM tsabnlist t WHERE t.pripid = e.pripid and t.specause = '4' and t.OPERATESTATUS = '1')
            </if>
            <if test='customParamMap.entertype =="farmer"'>
                and EXISTS (SELECT 1 FROM tsabnlist t WHERE t.pripid = e.pripid and t.specause = '3' and t.OPERATESTATUS = '1')
            </if>
            <if  test="customParamMap.pripids != null and customParamMap.pripids != ''">
                and pripid in
                <foreach collection="customParamMap.pripids" item="each" open="(" separator="," close=")">
                    #{each}
                </foreach>
            </if>
        </where>
        order by pripid asc
    </select>

    <select id="selectIdPage" resultMap="BaseResultMap">
        select * from e_baseinfo e
        <where>
            <if test="beginId != null and beginId != ''">
                and e.PRIPID &gt; #{beginId}
            </if>
        </where>
        order by e.pripid asc
        limit ${pageSize}
    </select>
    <select id="getNotExistsAddress" resultMap="BaseResultMap">
        select pripid, (case when e.address is null then e.dom else e.address end) as address
        from e_baseinfo e
        <where>
            <if test="pripid != null">
                and e.pripid &lt; #{pripid}
            </if>
        </where>
        order by e.pripid desc
        limit ${pageSize}
    </select>

    <select id="queryBypripids" resultMap="EBaseinfoExcel">
        select * from aiccs.e_baseinfo eb
        <where>
            <if test="pripids != null">
                pripid in
                <foreach collection="pripids" item="each" separator="," open="(" close=")">
                    #{each}
                </foreach>
            </if>
        </where>
    </select>

    <select id="countabnlrnum" resultType="int">
        select COALESCE(sum(zs),0) zs from (
        select distinct BIZSEQID,BUSTYPE,SIGNUSERID, date_format(SIGNTIME,'%Y-%m-%d') as SIGNTIME, rs.zs, rs2.orgn
        from aiccs.tstasklist ts
        left join  (
        select BIZSEQ,count(*) as zs from aiccs.tsbizspelist t
        where exists (select 1 from aiccs.tstasklist t2 where t.BIZSEQ = t2.BIZSEQID )
        group by BIZSEQ
        ) rs on ts.bizseqid = rs.bizseq
        left join (
        select tu.userid, left(tog.orgNumber,6) as orgn from cxaicorg.t_users tu
        left join cxaicorg.t_orgunits tog on tu.orgunitid = tog.orgunitid
        ) rs2 on ts.SIGNUSERID = rs2.userid
        where ts.BUSSTATUS !=4
        and ts.BUSTYPE in ('5','13','11','71','72','73')
        <if test="customParamMap.busstatus == 1 ">
            and ts.busstatus = '2'
        </if>
        <if test="customParamMap.busstatus == 2 ">
            and ts.busstatus = '0'
        </if>
        <if test="customParamMap.startDate != null and customParamMap.startDate != '' ">
            and date_format(ts.SIGNTIME,'%Y-%m-%d') &gt;= #{customParamMap.startDate}
        </if>
        <if test="customParamMap.endDate != null and customParamMap.endDate != '' ">
            and date_format(ts.SIGNTIME,'%Y-%m-%d') &lt;= #{customParamMap.endDate}
        </if>
        and exists (select 1 from aiccs.tsbizspelist tsb where ts.bizseqid = tsb.bizseq and tsb.isremove = '0')
        and orgn = #{orgn}
        ) rs3
    </select>

    <select id="countleglrnum" resultType="int">
        select COALESCE(sum(zs),0) zs from (
        select distinct BIZSEQID,BUSTYPE,SIGNUSERID, date_format(SIGNTIME,'%Y-%m-%d') as SIGNTIME, rs.zs, rs2.orgn
        from aiccs.tstasklist ts
        left join  (
        select BIZSEQ,count(*) as zs from aiccs.tsbizserillegal t
        where exists (select 1 from aiccs.tstasklist t2 where t.BIZSEQ = t2.BIZSEQID )
        group by BIZSEQ
        ) rs on ts.bizseqid = rs.bizseq
        left join (
        select tu.userid, left(tog.orgNumber,6) as orgn from cxaicorg.t_users tu
        left join cxaicorg.t_orgunits tog on tu.orgunitid = tog.orgunitid
        ) rs2 on ts.SIGNUSERID = rs2.userid
        where ts.BUSSTATUS !=4
        and ts.BUSTYPE = '15'
        <if test="customParamMap.busstatus == 1 ">
            and ts.busstatus = '2'
        </if>
        <if test="customParamMap.busstatus == 2 ">
            and ts.busstatus = '0'
        </if>
        <if test="customParamMap.startDate != null and customParamMap.startDate != '' ">
            and date_format(ts.SIGNTIME,'%Y-%m-%d') &gt;= #{customParamMap.startDate}
        </if>
        <if test="customParamMap.endDate != null and customParamMap.endDate != '' ">
            and date_format(ts.SIGNTIME,'%Y-%m-%d') &lt;= #{customParamMap.endDate}
        </if>
        and exists (select 1 from aiccs.tsbizserillegal tsb where ts.bizseqid = tsb.bizseq)
        and orgn = #{orgn}
        ) rs3
    </select>

    <select id="countlocknum" resultType="int">
        select COALESCE(sum(zs),0) zs from (
        select distinct BIZSEQID,BUSTYPE,SIGNUSERID, date_format(SIGNTIME,'%Y-%m-%d') as SIGNTIME, rs.zs, rs2.orgn
        from aiccs.tstasklist ts
        left join  (
        select BIZSEQ,count(*) as zs from aiccs.tsbizPunishLock t
        where exists (select 1 from aiccs.tstasklist t2 where t.BIZSEQ = t2.BIZSEQID )
        group by BIZSEQ
        ) rs on ts.bizseqid = rs.bizseq
        left join (
        select tu.userid, left(tog.orgNumber,6) as orgn from cxaicorg.t_users tu
        left join cxaicorg.t_orgunits tog on tu.orgunitid = tog.orgunitid
        ) rs2 on ts.SIGNUSERID = rs2.userid
        where ts.BUSSTATUS !=4
        and ts.BUSTYPE = '61'
        <if test="customParamMap.busstatus == 1 ">
            and ts.busstatus = '2'
        </if>
        <if test="customParamMap.busstatus == 2 ">
            and ts.busstatus = '0'
        </if>
        <if test="customParamMap.startDate != null and customParamMap.startDate != '' ">
            and date_format(ts.SIGNTIME,'%Y-%m-%d') &gt;= #{customParamMap.startDate}
        </if>
        <if test="customParamMap.endDate != null and customParamMap.endDate != '' ">
            and date_format(ts.SIGNTIME,'%Y-%m-%d') &lt;= #{customParamMap.endDate}
        </if>
        and exists (select 1 from aiccs.tsbizPunishLock tsb where ts.bizseqid = tsb.bizseq)
        and orgn = #{orgn}
        ) rs3
    </select>

    <select id="countunlocknum" resultType="int">
        select COALESCE(sum(zs),0) zs from (
        select distinct BIZSEQID,BUSTYPE,SIGNUSERID, date_format(SIGNTIME,'%Y-%m-%d') as SIGNTIME, rs.zs, rs2.orgn
        from aiccs.tstasklist ts
        left join  (
        select BIZSEQ,count(*) as zs from aiccs.tsbizpunishunlock t
        where exists (select 1 from aiccs.tstasklist t2 where t.BIZSEQ = t2.BIZSEQID )
        group by BIZSEQ
        ) rs on ts.bizseqid = rs.bizseq
        left join (
        select tu.userid, left(tog.orgNumber,6) as orgn from cxaicorg.t_users tu
        left join cxaicorg.t_orgunits tog on tu.orgunitid = tog.orgunitid
        ) rs2 on ts.SIGNUSERID = rs2.userid
        where ts.BUSSTATUS !=4
        and ts.BUSTYPE = '62'
        <if test="customParamMap.busstatus == 1 ">
            and ts.busstatus = '2'
        </if>
        <if test="customParamMap.busstatus == 2 ">
            and ts.busstatus = '0'
        </if>
        <if test="customParamMap.startDate != null and customParamMap.startDate != '' ">
            and date_format(ts.SIGNTIME,'%Y-%m-%d') &gt;= #{customParamMap.startDate}
        </if>
        <if test="customParamMap.endDate != null and customParamMap.endDate != '' ">
            and date_format(ts.SIGNTIME,'%Y-%m-%d') &lt;= #{customParamMap.endDate}
        </if>
        and exists (select 1 from aiccs.tsbizpunishunlock tsb where ts.bizseqid = tsb.bizseq)
        and orgn = #{orgn}
        ) rs3
    </select>

    <select id="countpldxnum" resultType="int">
        select COALESCE(sum(zs),0) zs from (
        select distinct BIZSEQID,BUSTYPE,SIGNUSERID, date_format(SIGNTIME,'%Y-%m-%d') as SIGNTIME, rs.zs, rs2.orgn
        from aiccs.tsrevtasklist ts
        left join  (
        select BIZSEQ,count(*) as zs from aiccs.tsbizrevlist t
        group by BIZSEQ
        ) rs on ts.bizseqid = rs.bizseq
        left join (
        select tu.userid, left(tog.orgNumber,6) as orgn from cxaicorg.t_users tu
        left join cxaicorg.t_orgunits tog on tu.orgunitid = tog.orgunitid
        ) rs2 on ts.SIGNUSERID = rs2.userid
        where ts.BUSSTATUS !=4
        and ts.BUSTYPE = '51'
        <if test="customParamMap.busstatus == 1 ">
            and ts.busstatus = '2'
        </if>
        <if test="customParamMap.busstatus == 2 ">
            and ts.busstatus = '0'
        </if>
        <if test="customParamMap.startDate != null and customParamMap.startDate != '' ">
            and date_format(ts.SIGNTIME,'%Y-%m-%d') &gt;= #{customParamMap.startDate}
        </if>
        <if test="customParamMap.endDate != null and customParamMap.endDate != '' ">
            and date_format(ts.SIGNTIME,'%Y-%m-%d') &lt;= #{customParamMap.endDate}
        </if>
        and orgn = #{orgn}
        ) rs3
    </select>
    <select id="selectByEntname" resultMap="BaseResultMap">
        select e.* from entlock ent left join e_baseinfo e on ent.ENTNAME=e.ENTNAME where ent.ENTNAME=#{entname}
    </select>

    <select id="selectAddress" resultMap="BaseResultMap">
        select address,REGORG,REGSTATE from e_baseinfo e where entname=#{entname}
    </select>

    <select id="queryForNb" resultMap="BaseResultMap">
        select e.* from aiccs.qynbly q left join aiccs.e_baseinfo e on q.uniscid = e.uniscid
        where regstate in ('1','7') and regorg = #{regorg}
    </select>

    <select id="querynzForNb" resultMap="BaseResultMap">
        select e.* from aiccs.nznbly q left join aiccs.e_baseinfo e on q.uniscid = e.uniscid
        where regstate in ('1','7') and regorg = #{regorg}
    </select>

    <select id="querygtForNb" resultMap="BaseResultMap">
        select e.* from aiccs.gtnbly q left join aiccs.e_baseinfo e on q.uniscid = e.uniscid
        where regstate in ('1','7') and left(regorg,6) = #{regorg}
    </select>

    <select id="querybyperson" resultMap="BaseResultMap">
        select eb.* from crgs.e_pri_person ep
                             left join aiccs.e_baseinfo eb on ep.pripid = eb.pripid
        where ep.name = #{name} and ep.cerno = #{cerno}
    </select>

    <select id="querybyoperator" resultMap="BaseResultMap">
        select eb.* from crgs.e_pb_operator ep
                             left join aiccs.e_baseinfo eb on ep.pripid = eb.pripid
        where ep.name = #{name} and ep.cerno = #{cerno}
    </select>

    <select id="getLevelFromCrgs" resultType="java.lang.String">
        select t.level from CRGS.t_company_details t where t.pripid = #{pripid}
    </select>

    <select id="queryTREntByPripid" resultType="com.chinaweal.aiccs.aiccs.abnormal.entity.TREntBaseInfo">
        select * from tREntBaseInfo
        where entityno = #{pripid} and dstate != '2' and reportyear = TO_CHAR(YEAR(CURRENT_TIMESTAMP)-1) limit 1
    </select>

    <select id="queryCipByPripid" resultType="com.chinaweal.aiccs.aiccs.abnormal.entity.Cipentliaisons">
        select * from cipEntLiaisons where entityno = #{pripid} and Dstate = '0'
        order by updateDate desc limit 1
    </select>

    <select id="queryEAlterByPripid" resultType="com.chinaweal.aiccs.crgs.moveinDetails.entity.EAlterRecoder">
        select * from E_ALTER_RECODER where pripid = #{pripid}
        union all
        select *, null as create_time, null as update_time from E_GT_ALTER_RECODER
        where pripid = #{pripid} ORDER by ALTDATE desc
    </select>

    <select id="queryEAlterByEntNo" resultType="com.chinaweal.aiccs.crgs.moveinDetails.entity.EAlterRecoder">
        select * from E_ALTER_RECODER where pripid = #{pripid} order by ALTDATE desc
    </select>

    <!--  查询法人电话号码 -->
    <select id="queryEpriPersonList" resultType="java.util.Map">
        select
            tel as "phone"
        from crgs.e_pri_person
        where pripid = #{pripid} and lerepsign = '1'
    </select>

    <select id="listIndividualLocaladm" resultType="java.util.Map">
        SELECT aeb.pripid as "pripid",aeb.ENTNAME as "entname",aeb.regulatory_name_temp as "regulatoryName",aeb.regulatory_temp as "regulatory",
               pb.LOCALADM as "pdRegulatory",t.ORGUNITNAME as "pdRegulatoryName"
        FROM AICCS.E_BASEINFO aeb LEFT JOIN CRGS.E_PB_BASEINFO pb ON aeb.PRIPID = pb.PRIPID
                                  LEFT join cxaicorg.t_orgunits t ON pb.LOCALADM = t.ORGNUMBER
        WHERE aeb.ENTTYPE in('9910','9500') AND aeb.REGSTATE = '1'
          AND (
            aeb.REGULATORY_TEMP IS NULL
                OR aeb.REGULATORY_TEMP IN ('440104','440105','440106','440110','440111','440112','440121','440122','440125','440126','440103','44010300','440115','440129',
                                           '44010400','44010500','44010600','44011000','44011100','44011200','44012100','44012200','44012500','44012600','44011500','44012900',
                                           '440101','440100','44010100','44010000')
            )
    </select>

    <!-- 强制注销企业查询结果映射 -->
    <resultMap id="QzzxEntDtoMap" type="com.chinaweal.aiccs.aiccs.abnormal.entity.vo.QzzxEntDto">
        <result column="busName" property="busName" />
        <result column="uniscid" property="uniscid" />
        <result column="regno" property="regno" />
        <result column="regulatoryNameTemp" property="regulatoryNameTemp" />
        <result column="REGORG_CN" property="REGORG_CN" />
        <result column="REGSTATE_CN" property="REGSTATE_CN" />
    </resultMap>

    <!-- 查询强制注销企业列表 -->
    <select id="queryForcedLogoutEntList" resultMap="QzzxEntDtoMap">
        SELECT
        eb.ENTNAME as busName,
        eb.UNISCID as uniscid,
        eb.REGNO as regno,
        eb.ACCEPTREGORG_CN as regulatoryNameTemp,
        eb.REGORG_CN as REGORG_CN,
        eb.REGSTATE_CN as REGSTATE_CN
        FROM CRGS.E_BASEINFO eb
        WHERE  <![CDATA[ eb.APPRDATE <= ADD_MONTHS(SYSDATE, -36) ]]>
        AND (eb.ENTTYPE LIKE '1%' OR eb.ENTTYPE LIKE '2%')
        AND eb.PRIPID NOT IN (SELECT PRIPID FROM AICCS.B_LOCK_ENTITY WHERE PRIPID IS NOT NULL and LOCK_TYPE in ('003','004')
        and LOCK_STATE = '1' and DELETE_FLAG = '0')
        AND eb.PRIPID NOT IN (SELECT PRIPID FROM AICCS.E_SP_PLEDGE WHERE PRIPID IS NOT NULL )
        AND eb.PRIPID NOT IN (
        -- 满足以下两种情况之一的PRIPID
        SELECT PRIPID
        FROM FORCE_LOGOUT_NOTICE_DETAIL fld
        WHERE
        -- 情况1：未有拟强制注销记录（isRemove=0）
        fld.isRemove = '0'
        OR
        -- 情况2：拟强制注销结果为终止或恢复，且结果日期+3年早于当前日期
        (fld.forceRes IN ('3', '5')
        AND <![CDATA[ ADD_MONTHS(fld.FORCERESDATE, 36) < SYSDATE ]]>
        )
        )
        <if test="customParamMap.uniscid != null and customParamMap.uniscid != ''">
            AND eb.UNISCID  = #{customParamMap.uniscid}
        </if>
        <if test="customParamMap.entname != null and customParamMap.entname != ''">
            AND eb.ENTNAME LIKE CONCAT('%', #{customParamMap.entname}, '%')
        </if>
        <if test="customParamMap.queryRegorg != null and customParamMap.queryRegorg != ''">
            AND eb.REGORG LIKE CONCAT('%', #{customParamMap.queryRegorg}, '%')
        </if>
        <if test="customParamMap.entType != null and customParamMap.entType != ''">
            <choose>
                <!-- 推荐：外层用双引号，内层值也用双引号 -->
                <when test='customParamMap.entType == "0"'>
                    AND eb.REGSTATE IN ('2')
                </when>
                <when test='customParamMap.entType == "1"'>
                    AND eb.REGSTATE IN ('8')
                </when>
                <when test='customParamMap.entType == "2"'>
                    AND eb.REGSTATE IN ('5')
                </when>
            </choose>
        </if>
    </select>


    <select id="exportQzzxEntList" resultMap="QzzxEntDtoMap">
        SELECT
        eb.ENTNAME as busName,
        eb.UNISCID as uniscid,
        eb.REGNO as regno,
        eb.ACCEPTREGORG_CN as regulatoryNameTemp,
        eb.REGORG_CN as REGORG_CN,
        eb.REGSTATE_CN as REGSTATE_CN
        FROM CRGS.E_BASEINFO eb
        WHERE  <![CDATA[ eb.APPRDATE <= ADD_MONTHS(SYSDATE, -36) ]]>
        AND (eb.ENTTYPE LIKE '1%' OR eb.ENTTYPE LIKE '2%')
        AND eb.PRIPID NOT IN (SELECT PRIPID FROM AICCS.B_LOCK_ENTITY WHERE PRIPID IS NOT NULL and LOCK_TYPE in ('003','004')
        and LOCK_STATE = '1' and DELETE_FLAG = '0')
        AND eb.PRIPID NOT IN (SELECT PRIPID FROM AICCS.E_SP_PLEDGE WHERE PRIPID IS NOT NULL )
        AND eb.PRIPID NOT IN (
        -- 满足以下两种情况之一的PRIPID
        SELECT PRIPID
        FROM FORCE_LOGOUT_NOTICE_DETAIL fld
        WHERE
        -- 情况1：未有拟强制注销记录（isRemove=0）
        fld.isRemove = '0'
        OR
        -- 情况2：拟强制注销结果为终止或恢复，且结果日期+3年早于当前日期
        (fld.forceRes IN ('3', '5')
        AND <![CDATA[ ADD_MONTHS(fld.FORCERESDATE, 36) < SYSDATE ]]>
        )
        )
        <if test="paramMap.regorg != null and paramMap.regorg != ''">
            AND eb.REGORG LIKE CONCAT('%', #{paramMap.regorg}, '%')
        </if>
        <if test="paramMap.entType != null and paramMap.entType != ''">
            <choose>
                <!-- 推荐：外层用双引号，内层值也用双引号 -->
                <when test='paramMap.entType == "0"'>
                    AND eb.REGSTATE IN ('2', '5')
                </when>
                <when test='paramMap.entType == "1"'>
                    <!-- 补充 entType=1 时的条件（避免空分支） -->
                    AND eb.PRIPID = 'fsdfdg343435gdgfd'
                </when>
            </choose>
        </if>
    </select>


</mapper>
