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

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.chinaweal.aiccs.aiccs.abnormal.entity.TSAbnList">
        <id column="ABNLISTID" property="abnlistid" />
        <result column="PRIPID" property="pripid" />
        <result column="REGNO" property="regno" />
        <result column="ENTNAME" property="entname" />
        <result column="ENTTYPE" property="enttype" />
        <result column="SPECAUSE" property="specause" />
        <result column="ABNTIME" property="abntime" />
        <result column="SPEREASONS" property="spereasons" />
        <result column="REMEXCPRES" property="remexcpres" />
        <result column="REMDATE" property="remdate" />
        <result column="REMREASONS" property="remreasons" />
        <result column="remDecorg" property="remDecorg" />
        <result column="intoDecorg" property="intoDecorg" />
        <result column="AREA_CODE" property="areaCode" />
        <result column="LAUPTIME" property="lauptime" />
        <result column="OPERATESTATUS" property="operatestatus" />
        <result column="ReconsiderationOrg" property="reconsiderationOrg" />
        <result column="GovernmentOrg" property="governmentOrg" />
        <result column="LitiOrg" property="litiOrg" />
        <result column="intoSponsor" property="intoSponsor" />
        <result column="remSponsor" property="remSponsor" />
        <result column="intoRemark" property="intoRemark" />
        <result column="remRemark" property="remRemark" />
        <result column="writsno" property="writsno" />
        <result column="intowritid" property="intowritid" />
        <result column="remwritid" property="remwritid" />
        <result column="DECORG" property="decorg" />
        <result column="REDECORG" property="reDecorg" />
        <result column="LEREP" property="lerep" />
        <result column="CERTYPE" property="certype" />
        <result column="CERNO" property="cerno" />
        <result column="caseSource" property="caseSource"/>
        <result column="contactEntity" property="contactEntity"/>
        <result column="contactMethodOrg" property="contactMethodOrg"/>
    </resultMap>

    <resultMap id="ReasonEntTypeMap" type="com.chinaweal.aiccs.aiccs.abnormal.entity.dto.ReasonEntTypeDto">
        <result column="reason" property="reason"/>
        <result column="entType" property="entType"/>
        <result column="amount" property="amount"/>
    </resultMap>

    <resultMap id="AbnormalTaskCountMap" type="com.chinaweal.aiccs.aiccs.abnormal.entity.dto.AbnormalTaskCountDto">
        <result column="bustype" property="bustype"/>
        <result column="amount" property="amount"/>
    </resultMap>

    <resultMap id="uniTaskListMap" type="com.chinaweal.aiccs.common.base.entity.dto.task.UniTaskListDto">
        <result column="pripid" property="pripid"/>
        <result column="entname" property="entName"/>
        <result column="uniscid" property="uniscid"/>
        <result column="regno" property="regNo"/>
        <result column="UNISCID" property="uniscid"/>
        <result column="leRepName" property="leRepName"/>
        <result column="enttype" property="enttype"/>
        <result column="address" property="address"/>
        <result column="opscope" property="opscope"/>
        <result column="tasklistid" property="taskListId"/>
        <result column="workflowid" property="workflowId"/>
        <result column="bizseq" property="bizseq"/>
        <result column="bustype" property="bustype"/>
        <result column="currNodeId" property="currNodeId"/>
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        ABNLISTID, PRIPID, REGNO, UNISCID, ENTNAME, ENTTYPE, SPECAUSE, ABNTIME, SPEREASONS, REMEXCPRES, REMDATE, REMREASONS, AREA_CODE, LAUPTIME, OPERATESTATUS,
        ReconsiderationOrg, GovernmentOrg, LitiOrg, intoSponsor, remSponsor, intoRemark, remRemark, intoDecorg, remDecorg,DECORG,remwritid,intowritid, REDECORG,
        LEREP, CERTYPE, CERNO,caseSource,contactEntity,contactMethodOrg
    </sql>

    <!--个体工商户经营异常查询-->
    <select id="selectIndividualByPageList" parameterType="com.chinaweal.aiccs.aiccs.abnormal.entity.TSAbnList"
            resultMap="BaseResultMap">
        select
        AbnListID,
        PriPID,
        RegNO,
        EntName,
        EntType,
        SpeCause,
        AbnTime,
        SpeReasons,
        RemExcpRes,
        RemDate,
        RemReasons,
        DecOrg,
        ReconsiderationOrg,
        GovernmentOrg,
        LitiOrg,
        intoSponsor,
        remSponsor,
        LaUpTime,
        OperateStatus
        from TSAbnList where 1=1
        <if test="tsAbnListModel.regno != null and tsAbnListModel.regno != ''">
            and regno = #{tsAbnListModel.regno}
        </if>
        <if test="tsAbnListModel.entname != null and tsAbnListModel.entname != ''">
            and entname like '%'||#{tsAbnListModel.entname}|| '%'
        </if>
        <if test="tsAbnListModel.decorg != null and tsAbnListModel.decorg != ''">
            and decorg = #{tsAbnListModel.decorg}
        </if>
        <if test="tsAbnListModel.specause != null and tsAbnListModel.specause != ''">
            and specause = #{tsAbnListModel.specause}
        </if>
        <if test="tsAbnListModel.abntime != null and tsAbnListModel.abntime != ''">
            and abntime &gt;= #{tsAbnListModel.abntime}
        </if>
        <if test="tsAbnListModel.endabntime != null and tsAbnListModel.endabntime != ''">
            and abntime &lt;= #{tsAbnListModel.endabntime}
        </if>
        and  operatestatus ='1'
        and remdate is null
        and enttype = '9910'
        order by AbnTime desc
    </select>

    <!--农合经营异常查询-->
    <select id="selectFarmerByPageList" parameterType="com.chinaweal.aiccs.aiccs.abnormal.entity.TSAbnList"
            resultMap="BaseResultMap">
        select
        AbnListID,
        PriPID,
        RegNO,
        EntName,
        EntType,
        SpeCause,
        AbnTime,
        SpeReasons,
        RemExcpRes,
        RemDate,
        RemReasons,
        DecOrg,
        ReconsiderationOrg,
        GovernmentOrg,
        LitiOrg,
        intoSponsor,
        remSponsor,
        LaUpTime,
        OperateStatus
        from TSAbnList where 1=1
        <if test="tsAbnListModel.regno != null and tsAbnListModel.regno != ''">
            and regno = #{tsAbnListModel.regno}
        </if>
        <if test="tsAbnListModel.entname != null and tsAbnListModel.entname != ''">
            and entname like '%'||#{tsAbnListModel.entname}|| '%'
        </if>
        <if test="tsAbnListModel.decorg != null and tsAbnListModel.decorg != ''">
            and decorg = #{tsAbnListModel.decorg}
        </if>
        <if test="tsAbnListModel.specause != null and tsAbnListModel.specause != ''">
            and specause = #{tsAbnListModel.specause}
        </if>
        <if test="tsAbnListModel.abntime != null and tsAbnListModel.abntime != ''">
            and abntime &gt;= #{tsAbnListModel.abntime}
        </if>
        <if test="tsAbnListModel.endabntime != null and tsAbnListModel.endabntime != ''">
            and abntime &lt;= #{tsAbnListModel.endabntime}
        </if>
        and  operatestatus ='1'
        and remdate is null
        and enttype in ('9100','9200','9000')
        order by AbnTime desc
    </select>

    <!--企业经营异常查询-->
    <select id="selectTSAbnByPageList" parameterType="com.chinaweal.aiccs.aiccs.abnormal.entity.TSAbnList"
            resultMap="BaseResultMap">
        select
        AbnListID,
        PriPID,
        RegNO,
        EntName,
        EntType,
        SpeCause,
        AbnTime,
        SpeReasons,
        RemExcpRes,
        RemDate,
        RemReasons,
        DecOrg,
        ReconsiderationOrg,
        GovernmentOrg,
        LitiOrg,
        intoSponsor,
        remSponsor,
        LaUpTime,
        OperateStatus
        from TSAbnList where 1=1
        <if test="tsAbnListModel.regno != null and tsAbnListModel.regno != ''">
            and regno = #{tsAbnListModel.regno}
        </if>
        <if test="tsAbnListModel.entname != null and tsAbnListModel.entname != ''">
            and entname like '%'||#{tsAbnListModel.entname}|| '%'
        </if>
        <if test="tsAbnListModel.decorg != null and tsAbnListModel.decorg != ''">
            and decorg = #{tsAbnListModel.decorg}
        </if>
        <if test="tsAbnListModel.specause != null and tsAbnListModel.specause != ''">
            and specause = #{tsAbnListModel.specause}
        </if>
        <if test="tsAbnListModel.abntime != null and tsAbnListModel.abntime != ''">
            and abntime &gt;= #{tsAbnListModel.abntime}
        </if>
        <if test="tsAbnListModel.endabntime != null and tsAbnListModel.endabntime != ''">
            and abntime &lt;= #{tsAbnListModel.endabntime}
        </if>
        and  operatestatus ='1'
        and remdate is null
        and enttype not in ('9910','9100','9200','9000')
        order by AbnTime desc
    </select>

    <!--企业异常名录统计查询-->
    <select id="removeselectByPagebnlist" parameterType="com.chinaweal.aiccs.aiccs.abnormal.entity.TSAbnList"
            resultMap="BaseResultMap">
        select
        AbnListID,
        PriPID,
        RegNO,
        EntName,
        EntType,
        SpeCause,
        AbnTime,
        SpeReasons,
        RemExcpRes,
        RemDate,
        RemReasons,
        DecOrg,
        ReconsiderationOrg,
        GovernmentOrg,
        LitiOrg,
        intoSponsor,
        remSponsor,
        LaUpTime,
        OperateStatus
        from TSAbnList where operatestatus in ('0','1')
        <if test="tsAbnListModel.regno != null and tsAbnListModel.regno != ''">
            and regno = #{tsAbnListModel.regno}
        </if>
        <if test="tsAbnListModel.entname != null and tsAbnListModel.entname != ''">
            and entname like '%'||#{tsAbnListModel.entname}||'%'
        </if>
        <if test="tsAbnListModel.abntime != null and tsAbnListModel.abntime != '' ">
            and abntime &gt;= #{tsAbnListModel.abntime}
        </if>
        <if test="tsAbnListModel.endabntime != null and tsAbnListModel.endabntime != '' ">
            and abntime &lt;= #{tsAbnListModel.endabntime}
        </if>
        <if test="tsAbnListModel.specause != null and tsAbnListModel.specause != ''">
            and specause = #{tsAbnListModel.specause}
        </if>
        <!--<if test="tsAbnListModel.decorg != null and tsAbnListModel.decorg != ''">-->
        <!--and decorg like #{tsAbnListModel.decorg}||'%'-->
        <!--</if>-->
        <if test="decorgArr != null">
            AND decorg IN
            <foreach collection="decorgArr" item="decorg" open="(" separator="," close=")">
                #{decorg}
            </foreach>
        </if>
        and enttype not in ('9910','9100','9200','9000')
        order by abntime desc
    </select>

    <!--个体工商户异常名录统计查询-->
    <select id="removeIndividualByPagebnlist" parameterType="com.chinaweal.aiccs.aiccs.abnormal.entity.TSAbnList"
            resultMap="BaseResultMap">
        select
        AbnListID,
        PriPID,
        RegNO,
        EntName,
        EntType,
        SpeCause,
        AbnTime,
        SpeReasons,
        RemExcpRes,
        RemDate,
        RemReasons,
        DecOrg,
        ReconsiderationOrg,
        GovernmentOrg,
        LitiOrg,
        intoSponsor,
        remSponsor,
        LaUpTime,
        OperateStatus
        from TSAbnList where operatestatus in ('0','1')
        <if test="tsAbnListModel.regno != null and tsAbnListModel.regno != ''">
            and regno = #{tsAbnListModel.regno}
        </if>
        <if test="tsAbnListModel.entname != null and tsAbnListModel.entname != ''">
            and entname like '%'||#{tsAbnListModel.entname}|| '%'
        </if>
        <if test="tsAbnListModel.abntime != null and tsAbnListModel.abntime != '' ">
            and abntime &gt;= #{tsAbnListModel.abntime}
        </if>
        <if test="tsAbnListModel.endabntime != null and tsAbnListModel.endabntime != '' ">
            and abntime &lt;= #{tsAbnListModel.endabntime}
        </if>
        <if test="tsAbnListModel.specause != null and tsAbnListModel.specause != ''">
            and specause = #{tsAbnListModel.specause}
        </if>
        <!--<if test="tsAbnListModel.decorg != null and tsAbnListModel.decorg != ''">-->
        <!--and decorg like #{tsAbnListModel.decorg}||'%'-->
        <!--</if>-->
        <if test="decorgArr != null">
            AND decorg IN
            <foreach collection="decorgArr" item="decorg" open="(" separator="," close=")">
                #{decorg}
            </foreach>
        </if>
        and enttype = '9910'
        order by abntime desc
    </select>

    <!--农合异常名录统计查询-->
    <select id="removeFarmerByPagebnlist" parameterType="com.chinaweal.aiccs.aiccs.abnormal.entity.TSAbnList"
            resultMap="BaseResultMap">
        select
        AbnListID,
        PriPID,
        RegNO,
        EntName,
        EntType,
        SpeCause,
        AbnTime,
        SpeReasons,
        RemExcpRes,
        RemDate,
        RemReasons,
        DecOrg,
        ReconsiderationOrg,
        GovernmentOrg,
        LitiOrg,
        intoSponsor,
        remSponsor,
        LaUpTime,
        OperateStatus
        from TSAbnList where operatestatus in ('0','1')
        <if test="tsAbnListModel.regno != null and tsAbnListModel.regno != ''">
            and regno = #{tsAbnListModel.regno}
        </if>
        <if test="tsAbnListModel.entname != null and tsAbnListModel.entname != ''">
            and entname like '%'||#{tsAbnListModel.entname}|| '%'
        </if>
        <if test="tsAbnListModel.abntime != null and tsAbnListModel.abntime != '' ">
            and abntime &gt;= #{tsAbnListModel.abntime}
        </if>
        <if test="tsAbnListModel.endabntime != null and tsAbnListModel.endabntime != '' ">
            and abntime &lt;= #{tsAbnListModel.endabntime}
        </if>
        <if test="tsAbnListModel.specause != null and tsAbnListModel.specause != ''">
            and specause = #{tsAbnListModel.specause}
        </if>
        <!--<if test="tsAbnListModel.decorg != null and tsAbnListModel.decorg != ''">-->
        <!--and decorg like #{tsAbnListModel.decorg}||'%'-->
        <!--</if>-->
        <if test="decorgArr != null">
            AND decorg IN
            <foreach collection="decorgArr" item="decorg" open="(" separator="," close=")">
                #{decorg}
            </foreach>
        </if>
        and enttype in ('9100','9200','9000')
        order by abntime desc
    </select>

    <!--查询列入异常名录决定机构-->
    <select id="selectPrpid"  parameterType="java.lang.String" resultMap="BaseResultMap">
        select
            AbnListID,
            PriPID,
            RegNO,
            EntName,
            EntType,
            SpeCause,
            AbnTime,
            SpeReasons,
            RemExcpRes,
            RemDate,
            RemReasons,
            DecOrg,
            ReconsiderationOrg,
            GovernmentOrg,
            LitiOrg,
            intoSponsor,
            remSponsor,
            LaUpTime,
            OperateStatus
        from TSAbnList where PriPID = #{pripid,jdbcType=CHAR}
    </select>

    <!--查询异常名录表里同一家企业所有记录-->
    <select id="selectEntList" parameterType="java.lang.String" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from TSAbnList where PriPID = #{pripid,jdbcType=CHAR} order by AbnTime
    </select>

    <!--异常名录中 期限届满列入严重违法失信 查询-->
    <select id="selectTSAbnByTimeoutByPage" parameterType="com.chinaweal.aiccs.aiccs.abnormal.entity.TSAbnList"
            resultMap="BaseResultMap">
        select AbnListID,PriPID,RegNO,EntName,EntType,SpeCause,AbnTime,SpeReasons,RemExcpRes,
        RemDate,RemReasons,DecOrg,ReconsiderationOrg,GovernmentOrg,LitiOrg,intoSponsor,remSponsor,LaUpTime,OperateStatus
        from TSAbnList where operatestatus ='1' and remdate is null
        <if test="tsAbnListModel.regno != null and tsAbnListModel.regno != ''">
            and regno = #{tsAbnListModel.regno}
        </if>
        <if test="tsAbnListModel.entname != null and tsAbnListModel.entname != ''">
            and entname like '%'||#{tsAbnListModel.entname}|| '%'
        </if>
        <if test="tsAbnListModel.decorg != null and tsAbnListModel.decorg != ''">
            and decorg = #{tsAbnListModel.decorg}
        </if>
        <if test="tsAbnListModel.abntime != null and tsAbnListModel.abntime != ''">
            and abntime &gt;= #{tsAbnListModel.abntime}
        </if>
        <if test="tsAbnListModel.endabntime != null and tsAbnListModel.endabntime != ''">
            and abntime &lt;= #{tsAbnListModel.endabntime}
        </if>
        <!--列入异常名录满3年前60日-->
        and DATEADD(day,-60,DATEADD(year,3,abntime)) &lt;= #{currentDate,jdbcType=TIMESTAMP}
        order by abntime desc
    </select>

    <select id="selectAbnListByPage" parameterType="com.chinaweal.aiccs.aiccs.abnormal.entity.TSAbnList"
            resultMap="BaseResultMap">
        select
        AbnListID,
        PriPID,
        RegNO,
        EntName,
        EntType,
        SpeCause,
        AbnTime,
        SpeReasons,
        RemExcpRes,
        RemDate,
        RemReasons,
        DecOrg,
        ReconsiderationOrg,
        GovernmentOrg,
        LitiOrg,
        intoSponsor,
        remSponsor,
        LaUpTime,
        OperateStatus
        from TSAbnList where operatestatus ='1' and remdate is null
        <if test="tsAbnListModel.regno != null and tsAbnListModel.regno != ''">
            and regno = #{tsAbnListModel.regno}
        </if>
        <if test="tsAbnListModel.entname != null and tsAbnListModel.entname != ''">
            and entname like '%'||#{tsAbnListModel.entname}|| '%'
        </if>
        <if test="tsAbnListModel.decorg != null and tsAbnListModel.decorg != ''">
            and decorg = #{tsAbnListModel.decorg}
        </if>
        <if test="tsAbnListModel.abntime != null and tsAbnListModel.abntime != ''">
            and abntime &gt;= #{tsAbnListModel.abntime}
        </if>
        <if test="tsAbnListModel.endabntime != null and tsAbnListModel.endabntime != ''">
            and abntime &lt;= #{tsAbnListModel.endabntime}
        </if>
        order by AbnTime desc
    </select>

    <!--市场准入调用 以下字段是临时用来接收，需要通过代码进行转化-->
    <select id="selectLimitInfoByPripid" parameterType="java.lang.String" resultMap="BaseResultMap">
        select t1.SpeCause, t1.ABNTIME, t1.DecOrg, t3.WritsNo as SpeReasons, t1.EntType
        from TSAbnList t1
                 left join TSBizSpeList t2 on  t2.SpeListID = t1.AbnListID
                 left join TSWrit t3 on t2.BizSeq = t3.BizSeq and t3.PriPID = t1.PriPID
        where t1.PriPID = #{pripid,jdbcType=CHAR}
          and t1.operatestatus in ('1','4') and t1.remdate is null and t3.WRITSTYPE = '11'
        order by t1.AbnTime desc
    </select>

    <select id="getTSAbnList" resultMap="BaseResultMap" parameterType="com.chinaweal.aiccs.aiccs.abnormal.entity.TSAbnList">
        select
        <include refid="Base_Column_List"/>
        from TSAbnList
        <where>
            <if test="tsAbnListModel.pripid!=null and tsAbnListModel.pripid!=''">
                and pripid = #{tsAbnListModel.pripid}
            </if>
            <if test="tsAbnListModel.regno!=null and  tsAbnListModel.regno!=''">
                and regno = #{tsAbnListModel.regno}
            </if>
            <if test="tsAbnListModel.entname!=null and tsAbnListModel.entname!=''">
                and entname = #{tsAbnListModel.entname}
            </if>
        </where>
        and  operatestatus ='1'
        and remdate is null
        and DATEADD(year,3,abntime) &lt;= #{currentDate,jdbcType=TIMESTAMP}
        order by LaUpTime desc
    </select>

    <select id="getDissentListPage" resultType="com.chinaweal.aiccs.aiccs.abnormal.entity.vo.DissentListVo">
        select ABNLISTID, PRIPID, REGNO, UNISCID, ENTNAME, ENTTYPE, SPECAUSE, ABNTIME, SPEREASONS,AREA_CODE, LAUPTIME, intoDecorg,DECORG
        from tsabnlist t
        <where>
            <if test="customParamMap != null">
                <if test="customParamMap.pripids != null and customParamMap.pripids != '' ">
                    and t.pripid in
                    <foreach collection="customParamMap.pripids" item="each" separator="," open="(" close=")">
                        #{each}
                    </foreach>
                </if>
                <if test="customParamMap.uniscid != null and customParamMap.uniscid != '' ">
                    and t.uniscid = #{customParamMap.uniscid}
                </if>
                <if test="customParamMap.regno != null and customParamMap.regno != '' ">
                    and t.regno = #{customParamMap.regno}
                </if>
                <if test="customParamMap.specause != null and customParamMap.specause != '' ">
                    and t.SPECAUSE = #{customParamMap.specause}
                </if>
                <if test="customParamMap.startDate != null and customParamMap.startDate != '' ">
                    and t.ABNTIME &gt;= #{customParamMap.startDate}
                </if>
                <if test="customParamMap.endDate != null and customParamMap.endDate != '' ">
                    and t.ABNTIME &lt;= #{customParamMap.endDate}
                </if>
                <if test="customParamMap.entertype != null and customParamMap.entertype != '' ">
                    <if test='customParamMap.entertype =="individual" '>
                        and t.ENTTYPE in ('9910')
                    </if>
                    <if test=" customParamMap.entertype == 'farmer'.toString() ">
                        and t.ENTTYPE in ('9100','9200')
                    </if>
                    <if test=" customParamMap.entertype == 'company'.toString() ">
                        and t.ENTTYPE not in ('9910','9100','9200')
                    </if>
                </if>
            </if>
            <if test="customParamMap.searchtype != null and customParamMap.searchtype == 'yy'.toString() ">
                and ( t.OPERATESTATUS = '1' or t.OPERATESTATUS = '0' )
            </if>
            <if test="customParamMap.searchtype == null">
                and t.OPERATESTATUS = '1'
            </if>
            AND not exists (SELECT 1 FROM tsbizremlist ts WHERE t.ABNLISTID = ts.ABNLISTID AND status IN ('9', '1'))
        </where>
        order by LAUPTIME, pripid desc
    </select>

    <select id="getRemDissentListPage" resultType="com.chinaweal.aiccs.aiccs.abnormal.entity.vo.DissentListVo">
        select ABNLISTID, PRIPID, REGNO, UNISCID, ENTNAME, ENTTYPE, SPECAUSE, ABNTIME, SPEREASONS,AREA_CODE, LAUPTIME, intoDecorg,DECORG
        from tsabnlist t
        <where>
            <if test="customParamMap != null">
                <if test="customParamMap.pripids != null and customParamMap.pripids != '' ">
                    and t.pripid in
                    <foreach collection="customParamMap.pripids" item="each" separator="," open="(" close=")">
                        #{each}
                    </foreach>
                </if>
                <if test="customParamMap.uniscid != null and customParamMap.uniscid != '' ">
                    and t.uniscid = #{customParamMap.uniscid}
                </if>
                <if test="customParamMap.regno != null and customParamMap.regno != '' ">
                    and t.regno = #{customParamMap.regno}
                </if>
                <if test="customParamMap.specause != null and customParamMap.specause != '' ">
                    and t.SPECAUSE = #{customParamMap.specause}
                </if>
                <if test="customParamMap.startDate != null and customParamMap.startDate != '' ">
                    and t.ABNTIME &gt;= #{customParamMap.startDate}
                </if>
                <if test="customParamMap.endDate != null and customParamMap.endDate != '' ">
                    and t.ABNTIME &lt;= #{customParamMap.endDate}
                </if>
                <if test="customParamMap.entertype != null and customParamMap.entertype != '' ">
                    <if test='customParamMap.entertype =="individual" '>
                        and t.ENTTYPE in ('9910')
                    </if>
                    <if test=" customParamMap.entertype == 'farmer'.toString() ">
                        and t.ENTTYPE in ('9100','9200')
                    </if>
                    <if test=" customParamMap.entertype == 'company'.toString() ">
                        and t.ENTTYPE not in ('9910','9100','9200')
                    </if>
                </if>
            </if>
            and t.OPERATESTATUS = '0'
        </where>
        order by LAUPTIME, pripid desc
    </select>

    <!--统计移出名录的数据pripid-->
    <select id="listRemovedPripid" resultType="java.lang.String">
        select pripid
        from tsabnlist abn
        where remdate <![CDATA[>=]]> #{beginDate} and operatestatus = '0'
    </select>
    <select id="selectFirstAbnormalList" resultMap="BaseResultMap">
        select <include refid="Base_Column_List"/>
        from tsabnlist abn
        ${ew.customSqlSegment}
        limit 1
    </select>


    <select id="statisticSpeCauseAndEntType" resultMap="ReasonEntTypeMap">
        SELECT
        biz.SPECAUSE as reason,
        (
        case
        when biz.ENTTYPE = '9910' then '个体户'
        when biz.ENTTYPE in ('9100', '9200') then '农合'
        else '企业' end
        ) as enttype,
        count(1) as amount
        FROM
        tstasklist t,
        tstwfprocessnode n,
        tsbizspelist biz,
        e_baseinfo e
        where t.workflowid = n.processid and n.status = 0
        and biz.PRIPID = e.PRIPID
        <if test="params != null">
            <if test="params.nodeId != null and params.nodeId != ''">
                and n.CURRENTNODE = #{params.nodeId}
            </if>
            <if test="params.curUserId != null and params.curUserId != ''">
                and n.CURRUSERID = #{params.curUserId}
            </if>
        </if>
        GROUP BY biz.SPECAUSE, biz.enttype
    </select>

    <select id="statisticAbnormalTaskCount" resultMap="AbnormalTaskCountMap">
        select count(1) as amount,
        (case
        when t.bustype in ('5', '11', '13') then '列入'
        when t.bustype in ('6', '18', '19') then '异议'
        else '移出' end
        ) as bustype
        from tstasklist t,
        tstwfprocessnode n
        where t.workflowid = n.processid
        and n.status = 0
        and t.bustype in ('5', '6', '7','11','12','13','14', '18', '19')
        <if test="params != null">
            <if test="params.nodeId != null and params.nodeId != ''">
                and n.CURRENTNODE = #{params.nodeId}
            </if>
            <if test="params.curUserId != null and params.curUserId != ''">
                and n.CURRUSERID = #{params.curUserId}
            </if>
        </if>
        group by bustype
    </select>

    <select id="selectAbnormalTaskListPage" resultMap="uniTaskListMap">
        <!--列入-->
        select t.tasklistid, t.workflowid, t.bizseqid as bizseq, e.pripid, e.entname as entName, e.uniscid,
        e.regno as regNo, e.name as leRepName, e.enttype, e.opscope,t.bustype, e.dom as address, n.currentnode as currNodeId
        from tstasklist t, tstwfprocessnode n, e_baseinfo e, tsbizspelist biz
        where t.bizseqid = biz.bizseq and e.pripid = biz.pripid
        <if test="params != null">
            <if test="params.entType == '企业'">

            </if>
        </if>
        <include refid="uniIllegalWhere"/>
        union all
        <!--异议-->
        select t.tasklistid, t.workflowid, t.bizseqid as bizseq, e.pripid, e.entname as entName, e.uniscid,
        e.regno as regNo, e.name as leRepName, e.enttype, e.opscope,t.bustype, e.dom as address, n.currentnode as currNodeId
        from tstasklist t, tstwfprocessnode n, e_baseinfo e, tsbizdissent biz
        where t.bizseqid = biz.bizseq and e.pripid = biz.pripid
        <include refid="uniIllegalWhere"/>
        union all
        <!--移出-->
        select t.tasklistid, t.workflowid, t.bizseqid as bizseq, e.pripid, e.entname as entName, e.uniscid,
        e.regno as regNo, e.name as leRepName, e.enttype, e.opscope, t.bustype, e.dom as address, n.currentnode as currNodeId
        from tstasklist t, tstwfprocessnode n, e_baseinfo e, tsbizremlist biz
        where t.bizseqid = biz.bizseq and e.pripid = biz.pripid
        <include refid="uniIllegalWhere"/>
    </select>
    <sql id="uniIllegalWhere">
        and t.workflowid = n.processid and n.status = 0
        <if test="params != null">
            <if test="params.curUserId != null and params.curUserId != ''">
                and n.curruserid = #{params.curUserId}
            </if>
            <if test="params.name != null and params.name != ''">
                and e.entname like concat('%', #{params.name} ,'%')
            </if>
            <if test="params.uscc != null and params.uscc != ''">
                and (
                e.uniscid like concat('%', #{params.uscc} ,'%')
                or
                e.regno like concat('%', #{params.uscc} ,'%')
                )
            </if>
            <if test="params.leRepName != null and params.leRepName != ''">
                and e.leRepName like concat('%', #{params.leRepName} ,'%')
            </if>
            <if test="params.regOrg != null and params.regOrg != ''">
                and e.regorg = #{params.regOrg}
            </if>
            <if test="params.entType != null">
                <if test="params.entType eq '企业'">
                    and e.enttype not in ('8000','8100','8200','8300','9000','9100','9200','9910','99100','99101','99102','99103', '9999')
                </if>
                <if test="params.entType eq '个体户'">
                    and e.enttype in ('9910', '9999')
                </if>
                <if test="params.entType eq '农舍'">
                    and e.enttype in ('9100', '9200')
                </if>
            </if>
            <if test="params.serillrea != null and params.serillrea != ''">
                and exists(select 1 from tsbizspelist ser where ser.pripid = e.pripid and ser.specause = #{params.serillrea})
            </if>
        </if>
    </sql>
    <select id="queryTSAbnByREMDATE" parameterType="String" resultMap="BaseResultMap">
        select * from tsabnlist t where OPERATESTATUS = '0'
                                    and SPECAUSE ='4'
                                    and REMDATE > DATE_SUB(CURDATE(), INTERVAL 1 YEAR)
                                    and PRIPID = #{pripid}
    </select>

    <select id="queryOneByPripid" parameterType="String" resultMap="BaseResultMap">
        select * from tsabnlist t where PRIPID = #{pripid} order by LAUPTIME desc limit 0,1
    </select>

    <select id="getTSAbnListByMap" resultType="com.chinaweal.aiccs.aiccs.abnormal.entity.TSAbnList">
        select
        <include refid="Base_Column_List"/>
        from tsabnlist
        <where>
            <if test="params.uniscid != null and params.uniscid != '' ">
                and uniscid = #{params.uniscid}
            </if>
            <if test="params.regno != null and params.regno != '' ">
                and regno = #{params.regno}
            </if>
            <if test="params.entType != null">
                <if test="params.entType eq 'individual'">
                    and enttype in ('9910', '9999')
                </if>
                <if test="params.entType eq 'farmer'">
                    and enttype not in ('9910', '9999','8000','8100','8200','8300','9000','99100','99101','99102','99103', '9999')
                </if>
            </if>
            and OPERATESTATUS = '1'
        </where>
        order by LAUPTIME desc
    </select>

    <select id="selectTsAbnbyMap" resultType="com.chinaweal.aiccs.aiccs.abnormal.entity.TSAbnList">
        select
        t.ABNLISTID, t.PRIPID, t.REGNO, t.UNISCID, t.ENTNAME, t.ENTTYPE, t.SPECAUSE, t.ABNTIME, t.SPEREASONS, t.REMEXCPRES, t.REMDATE,
        t.REMREASONS, t.AREA_CODE, t.LAUPTIME, t.OPERATESTATUS,t.ReconsiderationOrg, t.GovernmentOrg, t.LitiOrg, t.intoSponsor,
        t.remSponsor, t.intoRemark, t.remRemark, t.intoDecorg, t.remDecorg,w.writsno as writsno
        from tsabnlist t,tswrit w
        where t.BIZSEQ = w.BIZSEQ
        and t.PRIPID = w.PRIPID
        and w.WRITSTYPE = '11'
        <if test="params.bizseq != null and params.bizseq != ''">
            and t.BIZSEQ = #{params.bizseq,jdbcType=VARCHAR}
        </if>
        <if test="params.pripid != null and params.pripid != ''">
            and t.PRIPID = #{params.pripid,jdbcType=VARCHAR}
        </if>
        order by t.LAUPTIME desc
    </select>

    <select id="queryByAbnlistid" parameterType="String" resultMap="BaseResultMap">
        select * from tsabnlist where abnlistid = #{abnlistid} order by LAUPTIME desc
    </select>

    <select id="selectTSAbnListByPageList" parameterType="java.util.Map" resultMap="BaseResultMap">
        select <include refid="Base_Column_List"/>
        from TSAbnList where operatestatus ='1' and SPECAUSE != '1' and remdate is null
        <if test="params.entName != null and params.entName != ''">
            and entname like concat('%', #{params.entName} ,'%')
        </if>
        <if test="params.abnTime != null and params.abnTime != ''">
            and abntime = #{params.abnTime}
        </if>
        order by AbnTime desc
    </select>

    <select id="selectAbnListByPripid" resultType="com.chinaweal.aiccs.aiccs.abnormal.entity.TSAbnList">
        select
        <include refid="Base_Column_List"/>
        from tsabnlist WHERE abntime &gt;= #{newAbnTime,jdbcType=VARCHAR} and abntime &lt;= #{abnTime,jdbcType=VARCHAR}
        and PRIPID = #{pripid,jdbcType=VARCHAR}
    </select>

    <!-- 主体已注销的异常名录记录 -->
    <select id="selectCancelEntList" resultMap="BaseResultMap">
        select t.ABNLISTID, t.PRIPID, t.REGNO, t.DECORG, t.intoDecorg,t.intoRemark
        from tsabnlist t left join e_baseinfo e on e.PRIPID = t.PRIPID
        where e.REGSTATE in ('3','4') and t.OPERATESTATUS = '1' and e.ENTTYPE not in ('9100','9200')
    </select>

    <!-- 主体已撤销的异常名录记录 -->
    <select id="selectDeregEntList" resultMap="BaseResultMap">
        select t.ABNLISTID, t.PRIPID, t.REGNO, t.DECORG, t.intoDecorg,t.intoRemark
        from tsabnlist t left join e_baseinfo e on e.PRIPID = t.PRIPID
        where e.REGSTATE = '5' and t.OPERATESTATUS = '1' and e.ENTTYPE not in ('9100','9200')
          and ( t.intoRemark is null || t.intoRemark not like '%主体已撤销登记%')
    </select>

    <select id="selectByRemDate" resultType="String">
        select distinct pripid from tsabnlist t
        <where>
            <if test="params.uniscid != null and params.uniscid != '' ">
                and uniscid = #{params.uniscid}
            </if>
            <if test="params.regno != null and params.regno != '' ">
                and regno = #{params.regno}
            </if>
            <if test="params.remDateStart != null and params.remDateStart != '' ">
                and REMDATE &gt;= #{params.remDateStart}
            </if>
            <if test="params.remDateEnd != null and params.remDateEnd != '' ">
                and REMDATE &lt;= #{params.remDateEnd}
            </if>
            <if test="params.xzqh !=null and params.xzqh != '' ">
                and REDECORG like concat( #{params.xzqh}, '%')
            </if>
        </where>
    </select>

    <select id="queryByPripidAndDate" resultMap="BaseResultMap">
        select * from aiccs.tsabnlist where pripid = #{pripid}
                                        and date_format(abntime, '%Y-%m-%d') = #{date}
    </select>

    <select id="statistics" resultType="Map">
        select DECORG , count(1) as sl from (
        select case when DECORG = '440114' then '440121' else DECORG end as DECORG from aiccs.tsbizspelist t
        where
        bizseq in
        <foreach collection="bizseqs" item="each" separator="," open="(" close=")">
            #{each}
        </foreach>
        and isremove = '0'
        and endapply = '1'
        ) rs
        group by DECORG
    </select>

    <insert id="saveAbnBatch">
        INSERT INTO tsabnlist ( ABNLISTID, PRIPID, REGNO, UNISCID, ENTNAME, ENTTYPE, SPECAUSE, ABNTIME, SPEREASONS,
        intoDecorg, DECORG, AREA_CODE, OPERATESTATUS, intoSponsor, intoRemark, INTOWRITID, LEREP, CERTYPE, CERNO,
        caseSource,contactEntity,contactMethodOrg )
        VALUES
        <foreach collection="list" index="index" item="item" separator=",">
            ( #{item.abnlistid,jdbcType=VARCHAR},
            #{item.pripid,jdbcType=VARCHAR},
            #{item.regno,jdbcType=VARCHAR},
            #{item.uniscid,jdbcType=VARCHAR},
            #{item.entname,jdbcType=VARCHAR},
            #{item.enttype,jdbcType=VARCHAR},
            #{item.specause,jdbcType=VARCHAR},
            #{item.abntime,jdbcType=TIMESTAMP},
            #{item.spereasons,jdbcType=VARCHAR},
            #{item.intoDecorg,jdbcType=VARCHAR},
            #{item.decorg,jdbcType=VARCHAR},
            #{item.areaCode,jdbcType=VARCHAR},
            #{item.operatestatus,jdbcType=VARCHAR},
            #{item.intoSponsor,jdbcType=VARCHAR},
            #{item.intoRemark,jdbcType=VARCHAR},
            #{item.intowritid,jdbcType=VARCHAR},
            #{item.lerep,jdbcType=VARCHAR},
            #{item.certype,jdbcType=VARCHAR},
            #{item.cerno,jdbcType=VARCHAR},
            #{item.caseSource,jdbcType=VARCHAR},
            #{item.contactEntity,jdbcType=VARCHAR},
            #{item.contactMethodOrg,jdbcType=VARCHAR}
            )
        </foreach>
    </insert>

    <select id="checknb" resultType="int">
        select count(*) from aiccs.trentbaseinfo where entityno = #{entityno} and reportYear = #{reportYear}
    </select>
</mapper>
