<?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.revoke.mapper.AnnouncementTaskListDetailMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.chinaweal.aiccs.aiccs.revoke.entity.AnnouncementTaskListDetail">
        <id column="ID" property="id" />
        <result column="TASK_LIST_ID" property="taskListId" />
        <result column="PRIPID" property="pripid" />
        <result column="UNISCID" property="uniscid" />
        <result column="REGNO" property="regno" />
        <result column="ENTNAME" property="entname" />
        <result column="ENTTYPE" property="enttype" />
        <result column="INDUSTRYPHY" property="industryphy" />
        <result column="INDUSTRYCO" property="industryco" />
        <result column="REVOKETIME" property="revoketime" />
        <result column="CREATE_USER_ID" property="createUserId" />
        <result column="CREATE_TIME" property="createTime" />
        <result column="UPDATE_USER_ID" property="updateUserId" />
        <result column="UPDATE_TIME" property="updateTime" />
        <result column="DEL_FLAG" property="delFlag" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        ID, TASK_LIST_ID, PRIPID, UNISCID, REGNO, ENTNAME, ENTTYPE, INDUSTRYPHY,INDUSTRYCO, REVOKETIME,
        CREATE_USER_ID, CREATE_TIME, UPDATE_USER_ID, UPDATE_TIME, DEL_FLAG
    </sql>

    <!-- 分页查询公告任务名单详细名录列表（支持联表查询判断是否列异和列严） -->
    <select id="queryPageWithAbnormalAndSeriousIllegal" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM ANNOUNCEMENT_TASK_LIST_DETAIL
        WHERE DEL_FLAG = '0'
        <if test="query.taskListId != null and query.taskListId != ''">
            AND TASK_LIST_ID = #{query.taskListId}
        </if>
        <if test="query.uniscid != null and query.uniscid != ''">
            AND UNISCID LIKE CONCAT('%', #{query.uniscid}, '%')
        </if>
        <if test="query.regno != null and query.regno != ''">
            AND REGNO LIKE CONCAT('%', #{query.regno}, '%')
        </if>
        <if test="query.entname != null and query.entname != ''">
            AND ENTNAME LIKE CONCAT('%', #{query.entname}, '%')
        </if>
        <if test="query.enttype != null and query.enttype != ''">
            AND ENTTYPE = #{query.enttype}
        </if>
        <if test="query.industry != null and query.industry != ''">
            AND INDUSTRY LIKE CONCAT('%', #{query.industry}, '%')
        </if>
        <if test="query.revoketimeStart != null and query.revoketimeStart != ''">
            AND REVOKETIME &gt;= #{query.revoketimeStart}
        </if>
        <if test="query.revoketimeEnd != null and query.revoketimeEnd != ''">
            AND REVOKETIME &lt;= #{query.revoketimeEnd}
        </if>
        <if test="query.isAbnormal != null and query.isAbnormal != ''">
            AND (
                <if test="query.isAbnormal == '1'">
                    EXISTS (
                        SELECT 1 FROM TS_ABN_LIST
                        WHERE PRIPID = ANNOUNCEMENT_TASK_LIST_DETAIL.PRIPID
                        AND OPERATESTATUS = '1'
                    )
                </if>
                <if test="query.isAbnormal == '0'">
                    NOT EXISTS (
                        SELECT 1 FROM TS_ABN_LIST
                        WHERE PRIPID = ANNOUNCEMENT_TASK_LIST_DETAIL.PRIPID
                        AND OPERATESTATUS = '1'
                    )
                </if>
            )
        </if>
        <if test="query.isSeriousIllegal != null and query.isSeriousIllegal != ''">
            AND (
                <if test="query.isSeriousIllegal == '1'">
                    EXISTS (
                        SELECT 1 FROM TS_SER_ILLEGAL_LIST
                        WHERE PRIPID = ANNOUNCEMENT_TASK_LIST_DETAIL.PRIPID
                        AND OPERATESTATUS = '1'
                    )
                </if>
                <if test="query.isSeriousIllegal == '0'">
                    NOT EXISTS (
                        SELECT 1 FROM TS_SER_ILLEGAL_LIST
                        WHERE PRIPID = ANNOUNCEMENT_TASK_LIST_DETAIL.PRIPID
                        AND OPERATESTATUS = '1'
                    )
                </if>
            )
        </if>
        ORDER BY CREATE_TIME DESC
    </select>

</mapper>