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

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.chinaweal.aiccs.aiccs.seriousillegal.entity.TSForIllOperatingList">
        <id column="serialId" property="serialId" />
        <result column="pripid" property="pripid" />
        <result column="regNo" property="regNo" />
        <result column="entName" property="entName" />
        <result column="entType" property="entType" />
        <result column="address" property="address" />
        <result column="leRepName" property="leRepName" />
        <result column="abnTime" property="abnTime" />
        <result column="speCause" property="speCause" />
        <result column="speReasons" property="speReasons" />
        <result column="intoSponsor" property="intoSponsor" />
        <result column="AREA_CODE" property="areaCode" />
        <result column="operationStatus" property="operationStatus" />
        <result column="lauptime" property="lauptime" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        serialId, pripid, regNo, entName, entType, address, leRepName, abnTime, speCause, serReasons, intoSponsor, AREA_CODE, operationStatus, lauptime
    </sql>

    <select id="listOutTimeAbnList" parameterType="String" resultMap="BaseResultMap">
        select abnlistid, pripid, regNo, entName, entType, abnTime, speCause, speReasons, UNISCID, intoSponsor, AREA_CODE, '0' as operationStatus
        from tsabnlist abn
        where abntime = #{date}
        and operatestatus = '1'
        and enttype not in ('9100', '9200', '9910')
        and not exists(select 1 from tsforilloperatinglist list where list.abnlistid = abn.abnlistid and list.operationStatus = '0')
    </select>

    <select id="listOutTimeToAbnList" parameterType="String" resultMap="BaseResultMap">
        select pripid, regNo, entName, entType, abnTime, speCause, speReasons, intoSponsor, AREA_CODE, '0' as operationStatus
        from tsabnlist abn
        where abntime &lt; #{date} and operatestatus = '1'
        and not exists(select 1 from tsforilloperatinglist list where list.pripid = abn.pripid and list.operationStatus = '0')
    </select>

    <select id="listRelationEnt" resultType="com.chinaweal.aiccs.aiccs.seriousillegal.entity.TSForIllOperatingList">
        select tf.* from tsforilloperatinglist tf left join e_baseinfo e on tf.pripid = e.pripid
        where tf.speCause in ('1','3','2','5') and tf.operationStatus = '0'
        <if test="map.uniscid != null and map.uniscid !='' ">
            and tf.UNISCID = #{map.uniscid}
        </if>
        <if test="map.regno != null and map.regno !='' ">
            and tf.regno = #{map.regno}
        </if>
        <if test="map.searchName != null and map.searchName !='' ">
            and tf.entName like concat('%', #{map.searchName}, '%')
        </if>
        <if test="map.abnTime != null and map.abnTime !='' ">
            and tf.abnTime = #{map.abnTime}
        </if>
        <if test="map.speCause != null and map.speCause !='' ">
            and tf.speCause = #{map.speCause}
        </if>
        <if test="map.acceptRegorg != null and map.acceptRegorg !='' ">
            and e.acceptRegorg = #{map.acceptRegorg}
        </if>
        <if test="map.regorg != null and map.regorg !='' ">
            and e.regorg like concat(#{map.regorg}, '%')
        </if>
    </select>

</mapper>
