<?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.seriousillegal.mapper.TSSerIllegalListMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.chinaweal.aiccs.aiccs.seriousillegal.entity.TSSerIllegalList">
        <id column="ILLEGALLISTID" property="illegallistid" />
        <result column="BIZSEQ" property="bizseq" />
        <result column="ABNLISTID" property="abnlistid" />
        <result column="PRIPID" property="pripid" />
        <result column="REGNO" property="regno" />
        <result column="UNISCID" property="uniscid" />
        <result column="ENTNAME" property="entname" />
        <result column="SERILLREA" property="serillrea" />
        <result column="ABNTIME" property="abntime" />
        <result column="REMEXCPRES" property="remexcpres" />
        <result column="REMDATE" property="remdate" />
        <result column="DECORG" property="decorg" />
        <result column="DECORGCN" property="decorgCn" />
        <result column="AREA_CODE" property="areaCode" />
        <result column="LAUPTIME" property="lauptime" />
        <result column="LOSTCREDITEXPLAIN" property="lostcreditexplain" />
        <result column="LOSTCREDITEXPLAINREM" property="lostcreditexplainrem" />
        <result column="ReconsiderationOrg" property="reconsiderationOrg" />
        <result column="GovernmentOrg" property="governmentOrg" />
        <result column="LitiOrg" property="litiOrg" />
        <result column="intoSponsorIllegal" property="intoSponsorIllegal" />
        <result column="remSponsorIllegal" property="remSponsorIllegal" />
        <result column="batchAndCase" property="batchAndCase" />
        <result column="acceptno" property="acceptno" />
        <result column="operationStatus" property="operationStatus" />
        <result column="writsno" property="writsno" />
        <result column="REMDECORG" property="remdecorg" />
        <result column="REMDECORGCN" property="remdecorgCn" />
        <result column="INTOWRITID" property="intowritid" />
        <result column="REMWRITID" property="remwritid" />
        <result column="intoSponsorIllegalId" property="intoSponsorIllegalId" />
        <result column="ycbizseq" property="ycbizseq" />
        <result column="DECORGCN" property="decorgCn" />
        <result column="REMDECORGCN" property="remdecorgCn" />
        <result column="ISREV" property="isrev" />
        <result column="REVOP" property="revop" />
        <result column="ISHEA" property="ishea" />
        <result column="HEAOP" property="heaop" />
        <result column="JUDDOCTITLE" property="juddoctitle" />
        <result column="JUDDOCNO" property="juddocno" />
        <result column="isshow" property="isshow" />
    </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="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">
        ILLEGALLISTID, BIZSEQ, ABNLISTID, PRIPID, REGNO, ENTNAME, SERILLREA, UNISCID, ABNTIME, REMEXCPRES, REMDATE,
        DECORG, DECORGCN, AREA_CODE, LAUPTIME, LOSTCREDITEXPLAIN, LOSTCREDITEXPLAINREM, ReconsiderationOrg, GovernmentOrg,
        intoSponsorIllegal, remSponsorIllegal, LitiOrg, batchAndCase, operationStatus, REMDECORG, REMDECORGCN, INTOWRITID,
         REMWRITID,intoSponsorIllegalId,ycbizseq,ISREV,REVOP,ISHEA,HEAOP,JUDDOCTITLE,JUDDOCNO,isshow
    </sql>

    <select id="selectEntList" parameterType="com.chinaweal.aiccs.aiccs.seriousillegal.entity.TSSerIllegalList" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from TSSerIllegalList
        where 1=1
        <if test="serIllegalModel.bizseq != null and serIllegalModel.bizseq != ''">
            and bizseq = #{serIllegalModel.bizseq}
        </if>
        <if test="serIllegalModel.abnlistid != null and serIllegalModel.abnlistid != ''">
            and abnlistid = #{serIllegalModel.abnlistid}
        </if>
        <if test="serIllegalModel.regno != null and serIllegalModel.regno != ''">
            and regno = #{serIllegalModel.regno}
        </if>
        <if test="serIllegalModel.entname != null and serIllegalModel.entname != ''">
            and entname = #{serIllegalModel.entname}
        </if>
        <if test="serIllegalModel.pripid != null and serIllegalModel.pripid != ''">
            and pripid = #{serIllegalModel.pripid}
        </if>
        <if test="serIllegalModel.decorg != null and serIllegalModel.decorg != ''">
            and decorg = #{serIllegalModel.decorg}
        </if>
    </select>


    <!--依申请移出查询（列入原因是异常名录期限届满，且满5年未再发生相关情形）-->
    <select id="selectTSSerIllegalApplyByPage" parameterType="com.chinaweal.aiccs.aiccs.seriousillegal.entity.TSSerIllegalList"
            resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from TSSerIllegalList
        where 1=1
        <if test="tsSerIllegalListModel.regno != null and tsSerIllegalListModel.regno != ''">
            and regno = #{tsSerIllegalListModel.regno,jdbcType=VARCHAR}
        </if>
        <if test="tsSerIllegalListModel.entname != null and tsSerIllegalListModel.entname != ''">
            and entname like '%'||#{tsSerIllegalListModel.entname,jdbcType=VARCHAR}||'%'
        </if>
        <if test="tsSerIllegalListModel.decorg != null and tsSerIllegalListModel.decorg != ''">
            and decorg = #{tsSerIllegalListModel.decorg,jdbcType=VARCHAR}
        </if>
        <if test="tsSerIllegalListModel.abntime != null and tsSerIllegalListModel.abntime != '' ">
            and abntime  &gt;= #{tsSerIllegalListModel.abntime,jdbcType=DATE}
        </if>
        <if test="tsSerIllegalListModel.endabntime != '' and tsSerIllegalListModel.endabntime != null ">
            and abntime &lt;= #{tsSerIllegalListModel.endabntime,jdbcType=DATE}
        </if>
        and serillrea='1'
        and remdate is null and lostcreditexplainrem is null
        and DATEADD(year,5,abntime) &lt;=  #{currentDate,jdbcType=DATE}
        order by abntime desc
    </select>


    <!--期限届满移出查询（存在严重违法失信行为，满5年未再发生相关情形）-->
    <select id="selectTSSerIllegalTimeoutByPage" parameterType="com.chinaweal.aiccs.aiccs.seriousillegal.entity.TSSerIllegalList"
            resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from TSSerIllegalList
        where 1=1
        <if test="tsSerIllegalListModel.regno != null and tsSerIllegalListModel.regno != ''">
            and regno = #{tsSerIllegalListModel.regno,jdbcType=VARCHAR}
        </if>
        <if test="tsSerIllegalListModel.entname != null and tsSerIllegalListModel.entname != ''">
            and entname like '%'||#{tsSerIllegalListModel.entname,jdbcType=VARCHAR}|| '%'
        </if>
        <if test="tsSerIllegalListModel.serillrea != null and tsSerIllegalListModel.serillrea != ''">
            and serillrea = #{tsSerIllegalListModel.serillrea,jdbcType=VARCHAR}
        </if>
        <if test="tsSerIllegalListModel.decorg != null and tsSerIllegalListModel.decorg != ''">
            and decorg = #{tsSerIllegalListModel.decorg,jdbcType=VARCHAR}
        </if>
        <if test="tsSerIllegalListModel.abntime != null and tsSerIllegalListModel.abntime != '' ">
            and abntime  &gt;= #{tsSerIllegalListModel.abntime,jdbcType=DATE}
        </if>
        <if test="tsSerIllegalListModel.endabntime != '' and tsSerIllegalListModel.endabntime != null ">
            and abntime &lt;= #{tsSerIllegalListModel.endabntime,jdbcType=DATE}
        </if>
        and serillrea not in ('1')
        and remdate is null and lostcreditexplainrem is null
        and DATEADD(year,5,abntime)  &lt;=  #{currentDate,jdbcType=DATE}
        order by abntime desc
    </select>

    <!--严重违法失信企业名单 异议查询-->
    <select id="selectTSSerIllegalDissentByPage" parameterType="com.chinaweal.aiccs.aiccs.seriousillegal.entity.TSSerIllegalList"
            resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from TSSerIllegalList
        where 1=1
        <if test="tsSerIllegalListModel.regno != null and tsSerIllegalListModel.regno != ''">
            and regno = #{tsSerIllegalListModel.regno,jdbcType=VARCHAR}
        </if>
        <if test="tsSerIllegalListModel.entname != null and tsSerIllegalListModel.entname != ''">
            and entname like '%'||#{tsSerIllegalListModel.entname,jdbcType=VARCHAR}|| '%'
        </if>
        <if test="tsSerIllegalListModel.serillrea != null and tsSerIllegalListModel.serillrea != ''">
            and serillrea = #{tsSerIllegalListModel.serillrea,jdbcType=VARCHAR}
        </if>
        <if test="tsSerIllegalListModel.decorg != null and tsSerIllegalListModel.decorg != ''">
            and decorg = #{tsSerIllegalListModel.decorg,jdbcType=VARCHAR}
        </if>
        <if test="tsSerIllegalListModel.abntime != null and tsSerIllegalListModel.abntime != ''">
            and abntime &gt;= #{tsSerIllegalListModel.abntime,jdbcType=DATE}
        </if>
        <if test="tsSerIllegalListModel.endabntime != '' and tsSerIllegalListModel.endabntime != null ">
            and abntime &lt;= #{tsSerIllegalListModel.endabntime,jdbcType=DATE}
        </if>
        and remdate is null and lostcreditexplainrem is null
        order by abntime desc
    </select>

    <!--严重违法失信企业名单 查询-->
    <select id="selectTSSerIllegalListByPage" parameterType="com.chinaweal.aiccs.aiccs.seriousillegal.entity.TSSerIllegalList"
            resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from TSSerIllegalList
        where 1=1
        <if test="tsSerIllegalListModel.regno != null and tsSerIllegalListModel.regno != ''">
            and regno = #{tsSerIllegalListModel.regno,jdbcType=VARCHAR}
        </if>
        <if test="tsSerIllegalListModel.entname != null and tsSerIllegalListModel.entname != ''">
            and entname like '%'||#{tsSerIllegalListModel.entname,jdbcType=VARCHAR}||'%'
        </if>
        <if test="tsSerIllegalListModel.serillrea != null and tsSerIllegalListModel.serillrea != ''">
            and serillrea = #{tsSerIllegalListModel.serillrea,jdbcType=VARCHAR}
        </if>
        <if test="tsSerIllegalListModel.decorg != null and tsSerIllegalListModel.decorg != ''">
            and decorg like #{tsSerIllegalListModel.decorg,jdbcType=VARCHAR}||'%'
        </if>
        <if test="tsSerIllegalListModel.abntime != null and tsSerIllegalListModel.abntime != ''">
            and abntime &gt;= #{tsSerIllegalListModel.abntime,jdbcType=DATE}
        </if>
        <if test="tsSerIllegalListModel.endabntime != '' and tsSerIllegalListModel.endabntime != null ">
            and abntime &lt;= #{tsSerIllegalListModel.endabntime,jdbcType=DATE}
        </if>
        order by abntime desc
    </select>

    <!--严重违法失信企业‘信用修复移出’ 查询使用-->
    <select id="selectCreditTSSerIllegalByPage" parameterType="com.chinaweal.aiccs.aiccs.seriousillegal.entity.TSSerIllegalList" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from TSSerIllegalList
        where SERILLREA = '1'
        <if test="tsSerIllegalListModel.regno != null and tsSerIllegalListModel.regno != ''">
            and regno = #{tsSerIllegalListModel.regno,jdbcType=VARCHAR}
        </if>
        <if test="tsSerIllegalListModel.entname != null and tsSerIllegalListModel.entname != ''">
            and entname like '%'||#{tsSerIllegalListModel.entname,jdbcType=VARCHAR}||'%'
        </if>
        <if test="tsSerIllegalListModel.serillrea != null and tsSerIllegalListModel.serillrea != ''">
            and serillrea = #{tsSerIllegalListModel.serillrea,jdbcType=VARCHAR}
        </if>
        <if test="tsSerIllegalListModel.decorg != null and tsSerIllegalListModel.decorg != ''">
            and decorg like #{tsSerIllegalListModel.decorg,jdbcType=VARCHAR}||'%'
        </if>
        <if test="tsSerIllegalListModel.abntime != null and tsSerIllegalListModel.abntime != ''">
            and abntime &gt;= #{tsSerIllegalListModel.abntime,jdbcType=DATE}
        </if>
        <if test="tsSerIllegalListModel.endabntime != '' and tsSerIllegalListModel.endabntime != null ">
            and abntime &lt;= #{tsSerIllegalListModel.endabntime,jdbcType=DATE}
        </if>
        order by abntime
    </select>

    <!--严重违法失信企业名单 查询→统计-->
    <select id="selectTSSerIllegalListCountByPage" parameterType="com.chinaweal.aiccs.aiccs.seriousillegal.entity.TSSerIllegalList"
            resultMap="BaseResultMap">
        select
        t1.ILLEGALLISTID, t1.BIZSEQ, t1.ABNLISTID,
        t1.PRIPID, t1.REGNO, t1.ENTNAME,
        t1.SERILLREA, t1.ABNTIME, t1.REMEXCPRES,
        t1.REMDATE, t1.DECORG, t1.LOSTCREDITEXPLAIN, t1.LOSTCREDITEXPLAINREM,
        t1.ReconsiderationOrg, t1.GovernmentOrg, t1.LitiOrg, t1.intoSponsorIllegal, t1.remSponsorIllegal, t1.LAUPTIME
        from TSSerIllegalList t1 RIGHT JOIN TRENTBASE t2 ON t1.PRIPID = t2.PRIPID
        where 1=1
        <if test="tsSerIllegalListModel.regno != null and tsSerIllegalListModel.regno != ''">
            and t1.regno = #{tsSerIllegalListModel.regno,jdbcType=VARCHAR}
        </if>
        <if test="tsSerIllegalListModel.entname != null and tsSerIllegalListModel.entname != ''">
            and t1.entname like '%'||#{tsSerIllegalListModel.entname,jdbcType=VARCHAR}||'%'
        </if>
        <if test="tsSerIllegalListModel.serillrea != null and tsSerIllegalListModel.serillrea != ''">
            and t1.serillrea = #{tsSerIllegalListModel.serillrea,jdbcType=VARCHAR}
        </if>
        <if test="tsSerIllegalListModel.decorg != null and tsSerIllegalListModel.decorg != ''">
            and t1.decorg like #{tsSerIllegalListModel.decorg,jdbcType=VARCHAR}||'%'
        </if>
        <if test="tsSerIllegalListModel.abntime != null and tsSerIllegalListModel.abntime != ''">
            and t1.abntime &gt;= #{tsSerIllegalListModel.abntime,jdbcType=DATE}
        </if>
        <if test="tsSerIllegalListModel.endabntime != '' and tsSerIllegalListModel.endabntime != null ">
            and t1.abntime &lt;= #{tsSerIllegalListModel.endabntime,jdbcType=DATE}
        </if>
        <if test="regorgArrStr != null">
            AND t2.AICID IN
            <foreach collection="regorgArrStr" item="aicId" open="(" separator="," close=")">
                #{aicId}
            </foreach>
        </if>
        <if test="territorialArrStr != null">
            AND t2.LOCALADM IN
            <foreach collection="territorialArrStr" item="territorialOrg" open="(" separator="," close=")">
                #{territorialOrg}
            </foreach>
        </if>
        order by t1.abntime desc
    </select>


    <select id="getSerIllegalModel" parameterType="com.chinaweal.aiccs.aiccs.seriousillegal.entity.TSSerIllegalList"
            resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from TSSerIllegalList
        where 1=1
        <if test="tsSerIllegalListModel.regno != null and tsSerIllegalListModel.regno != ''">
            and regno = #{tsSerIllegalListModel.regno,jdbcType=VARCHAR}
        </if>
        <if test="tsSerIllegalListModel.entname != null and tsSerIllegalListModel.entname != ''">
            and entname = #{tsSerIllegalListModel.entname,jdbcType=VARCHAR}
        </if>
        <if test="tsSerIllegalListModel.pripid != null and tsSerIllegalListModel.pripid != ''">
            and pripid = #{tsSerIllegalListModel.pripid,jdbcType=CHAR}
        </if>
        and remdate is null
        and DATEADD(year,5,abntime)  &lt;=  #{currentDate,jdbcType=DATE}
    </select>

    <!--市场准入调用 以下字段是临时用来接收，需要通过代码进行转化-->
    <select id="selectLimitInfoByPripid" parameterType="java.lang.String" resultMap="BaseResultMap">
        select t1.serillrea, t1.abntime, t1.decorg, t2.WritsNo as EntName
        from TSSerIllegalList t1
                 left join TSWrit t2 on t2.bizseq = t1.bizseq and t2.pripid = t1.pripid
        where t1.pripid = #{pripid,jdbcType=CHAR}
          and t1.remdate is null and t1.lostcreditexplainrem is null and t2.WRITSTYPE = '21'
        order by t1.abntime desc
    </select>

    <!--综合查询>严重违法失信记录-->
    <select id="selectSerIllegalInfoList" resultMap="BaseResultMap">
        select
        <include refid="Base_Column_List"/>
        from TSSerIllegalList
        where PriPID = #{pripid,jdbcType=CHAR} order by ABNTIME
    </select>
    <select id="selectFirstIllegalListRecord" resultMap="BaseResultMap">
        select <include refid="Base_Column_List"/>
        from TSSerIllegalList
        ${ew.customSqlSegment}
        limit 1
    </select>

    <select id="selectUniIllegalTaskListPage" 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, tsbizserillegal 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, tsbizserillegaldiss 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, tsbizserillegal 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.serillrea != null and params.serillrea != ''">
                and exists(select 1 from tsserillegallist ser where ser.pripid = e.pripid and ser.serillrea = #{params.serillrea})
            </if>
        </if>
    </sql>
    <!--统计列入严重违法失信企业个人待办数量-->
    <select id="selectIllegalTaskListCount" resultType="java.lang.Integer">
        select sum(a.c)
        from (
        <!--列入-->
        select count(1) c
        from tstasklist t, tstwfprocessnode n, e_baseinfo e, tsbizserillegal biz
        where t.bizseqid = biz.bizseq and e.pripid = biz.pripid
        <include refid="uniIllegalWhere"/>
        union all
        <!--异议-->
        select count(1) c
        from tstasklist t, tstwfprocessnode n, e_baseinfo e, tsbizserillegaldiss biz
        where t.bizseqid = biz.bizseq and e.pripid = biz.pripid
        <include refid="uniIllegalWhere"/>
        union all
        <!--移出-->
        select count(1) c
        from tstasklist t, tstwfprocessnode n, e_baseinfo e, tsbizserillegal biz
        where t.bizseqid = biz.bizseq and e.pripid = biz.pripid
        <include refid="uniIllegalWhere"/>) a
    </select>

    <select id="selectSerillegalList" parameterType="com.chinaweal.aiccs.aiccs.seriousillegal.entity.TSSerIllegalList" resultMap="BaseResultMap">
        SELECT  t.BIZSEQ,PRIPID, t.REGNO, t.ENTNAME, t.SERILLREA, t.ABNTIME,t.batchAndCase,l.acceptno,
        t.REMEXCPRES, t.REMDATE, t.DECORG, t.AREA_CODE, t.LAUPTIME, t.LOSTCREDITEXPLAIN, t.LOSTCREDITEXPLAINREM,
        t.ReconsiderationOrg, t.GovernmentOrg, t.LitiOrg, t.intoSponsorIllegal, t.remSponsorIllegal
        from tsserillegallist t, tstasklist l where t.BIZSEQ = l.bizseqid and  t.REMDATE is null
        and ((DATEDIFF(NOW(),t.ABNTIME) > 89 and t.batchAndCase = '0') or (DATEDIFF(NOW(),t.ABNTIME) > 59 and t.batchAndCase = '1'))
        <if test="params.regNO != null and params.regNO != ''">
            and t.regno = #{params.regNO,jdbcType=VARCHAR}
        </if>
        <if test="params.entName != null and params.entName != ''">
            and t.entname = #{params.entName,jdbcType=VARCHAR}
        </if>
        <if test="params.acceptno != null and params.acceptno != ''">
            and l.acceptno = #{params.acceptno,jdbcType=CHAR}
        </if>
        ORDER BY t.ABNTIME desc
    </select>

    <select id="queryByPripid" parameterType="String" resultMap="BaseResultMap">
        select * from tsserillegallist where PRIPID = #{pripid} order by LAUPTIME desc
    </select>

    <select id="selecttsSerIllegalAppByMap"  resultMap="BaseResultMap">
        SELECT t.ILLEGALLISTID, t.BIZSEQ, t.ABNLISTID, t.PRIPID, t.REGNO, t.ENTNAME, t.SERILLREA, t.ABNTIME,
        t.REMEXCPRES, t.REMDATE, t.DECORG, w.AREA_CODE as AREA_CODE, t.LAUPTIME, t.LOSTCREDITEXPLAIN, t.LOSTCREDITEXPLAINREM,
        t.ReconsiderationOrg, t.GovernmentOrg, t.LitiOrg, t.intoSponsorIllegal, t.remSponsorIllegal , t.intoSponsorIllegalId,t.ycbizseq,w.writsno as writsno,t.batchAndCase
        from tsserillegallist t
        left join tswrit w on t.BIZSEQ = w.BIZSEQ and t.PRIPID = w.PRIPID and w.WRITSTYPE = '21'
        where 1=1
        <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>
    </select>

    <select id="selecttsSerIllegalAppByid" parameterType="String" resultMap="BaseResultMap">
        select * from tsserillegallist where ILLEGALLISTID = #{illegalListID} order by LAUPTIME desc
    </select>

    <select id="listOutTimeIllegalList" parameterType="String" resultMap="BaseResultMap">
        select t.ILLEGALLISTID, t.BIZSEQ, t.ABNLISTID, t.PRIPID, t.REGNO, t.DECORG, t.DECORGCN, t.SERILLREA
        from tsserillegallist t
        where ABNTIME <![CDATA[<=]]> #{date}  and operationStatus = '0'
    </select>

    <select id="listCancelEnts" resultMap="BaseResultMap">
        select t.ILLEGALLISTID, t.BIZSEQ, t.ABNLISTID, t.PRIPID, t.REGNO, t.DECORG, t.DECORGCN, e.REGSTATE
        from tsserillegallist t left join e_baseinfo e on e.PRIPID = t.PRIPID
        where e.REGSTATE in('3','4') and t.operationStatus = '0'
    </select>

    <select id="queryAbnormalLrList"  resultMap="BaseResultMap">
        SELECT t.ILLEGALLISTID, t.BIZSEQ, t.ABNLISTID, t.PRIPID, t.REGNO, t.ENTNAME, t.SERILLREA, t.ABNTIME,
               t.REMEXCPRES, t.REMDATE, t.DECORG, t.AREA_CODE, t.LAUPTIME, t.LOSTCREDITEXPLAIN, t.LOSTCREDITEXPLAINREM,
               t.ReconsiderationOrg, t.GovernmentOrg, t.LitiOrg, t.intoSponsorIllegal, t.remSponsorIllegal ,w.writsno as writsno
        from tsserillegallist t,tswrit w
        where t.BIZSEQ = w.BIZSEQ
          and t.PRIPID = w.PRIPID
          and w.WRITSTYPE = '21'
          and t.remdate is null
    </select>

    <select id="queryAbnormalYcList"  resultMap="BaseResultMap">
        SELECT t.ILLEGALLISTID, t.BIZSEQ, t.ABNLISTID, t.PRIPID, t.REGNO, t.ENTNAME, t.SERILLREA, t.ABNTIME,
               t.REMEXCPRES, t.REMDATE, t.DECORG, t.AREA_CODE, t.LAUPTIME, t.LOSTCREDITEXPLAIN, t.LOSTCREDITEXPLAINREM,
               t.ReconsiderationOrg, t.GovernmentOrg, t.LitiOrg, t.intoSponsorIllegal, t.remSponsorIllegal ,w.writsno as writsno
        from tsserillegallist t,tswrit w
        where t.BIZSEQ = w.BIZSEQ
          and t.PRIPID = w.PRIPID
          and w.WRITSTYPE = '25'
          and t.remdate is not null
    </select>
    <!-- 严重违法拟列入文书公示   -->
    <select id="queryToIllegalByNameList"  resultType="com.chinaweal.aiccs.aiccs.abnormal.entity.dto.EntWritsDto">
        SELECT w.WRITSNO, w.CREATETIME, W.WRITSTYPE,W.AREA_CODE,w.writsid,e.ENTNAME
        FROM tswrit w
        LEFT JOIN e_baseinfo e on e.PRIPID = w.PRIPID
        WHERE w.WRITSTYPE = '20'
        <if test="params.entName != null and params.entName != ''">
            and e.ENTNAME like concat('%', #{params.entName} ,'%')
        </if>
        ORDER BY w.CREATETIME desc
    </select>
    <!-- 严重违法列入文书公示   -->
    <select id="queryAbnormalLrByNameList"  resultType="com.chinaweal.aiccs.aiccs.abnormal.entity.dto.EntWritsDto">
        SELECT w.WRITSNO, w.CREATETIME, W.WRITSTYPE,W.AREA_CODE,w.writsid,e.ENTNAME
        FROM tswrit w
        LEFT JOIN e_baseinfo e on e.PRIPID = w.PRIPID
        WHERE w.WRITSTYPE = '21'
        <if test="params.entName != null and params.entName != ''">
            and e.ENTNAME like concat('%', #{params.entName} ,'%')
        </if>
        ORDER BY w.CREATETIME desc
    </select>
    <!-- 严重违法移出文书公示   -->
    <select id="queryAbnormalYcByNameList"  resultType="com.chinaweal.aiccs.aiccs.abnormal.entity.dto.EntWritsDto">
        SELECT w.WRITSNO, w.CREATETIME, W.WRITSTYPE,W.AREA_CODE,w.writsid,e.ENTNAME
        FROM tswrit w
        LEFT JOIN e_baseinfo e on e.PRIPID = w.PRIPID
        WHERE w.WRITSTYPE in ('25','53')
        <if test="params.entName != null and params.entName != ''">
            and e.ENTNAME like concat('%', #{params.entName} ,'%')
        </if>
        ORDER BY w.CREATETIME desc
    </select>

    <select id="queryByzdyc" resultMap="BaseResultMap">
        select * from aiccs.tsserillegallist t where operationStatus = '2'
                                                 and REMDATE >= '2021-10-10'
                                                 and REMEXCPRES = '4'
                                                 and remSponsorIllegal = '系统自动移出'
                                                 and abnlistid is not null
    </select>

    <select id="countBySerill" resultType="int">
        select count(*) from aiccs.tsabnlist where
            pripid = #{pripid}
                                               and abntime = #{abntime}
                                               and SPECAUSE = #{SPECAUSE}
                                               and SPEREASONS = #{SPEREASONS}
                                               and OPERATESTATUS = #{OPERATESTATUS}
    </select>
    <select id="queryEBaseinfoInSeriousIllegal"
            resultType="com.chinaweal.aiccs.aiccs.abnormal.entity.EBaseinfo">
        select * from e_baseinfo b
        <where>
            b.ENTTYPE not in ('9500','9910','9100','9200')
            and exists (select 1 from tsserillegallist s where s.PRIPID = b.PRIPID
            and s.OPERATIONSTATUS = '0' and s.REMDATE is null)
            <if test="entity.entname != null and entity.entname != ''">
                and b.ENTNAME = #{entity.entname,jdbcType=VARCHAR}
            </if>
            <if test="entity.searchUscc != null and entity.searchUscc != ''">
                and (b.UNISCID = #{entity.searchUscc} or b.REGNO = #{entity.searchUscc})
            </if>
            <if test="entity.uniscid != null and entity.uniscid != ''">
                and (b.UNISCID = #{entity.uniscid} or b.REGNO = #{entity.uniscid})
            </if>
            <if test="entity.regorg != null and entity.regorg != ''">
                and b.REGORG = #{entity.regorg}
            </if>
        </where>
    </select>

    <insert id="saveabnlistid">
        insert into abnidtb values (#{abnlistid,jdbcType=VARCHAR})
    </insert>
</mapper>
