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

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.chinaweal.aiccs.aiccs.revoke.entity.Revokelist">
        <id column="REVLISTID" property="revlistid" />
        <result column="UNISCID" property="uniscid" />
        <result column="PRIPID" property="pripid" />
        <result column="REGNO" property="regno" />
        <result column="ENTNAME" property="entname" />
        <result column="INTOSPONSORID" property="intosponsorid" />
        <result column="INTOSPONSORNAME" property="intosponsorname" />
        <result column="REVOKEDATE" property="revokedate" />
        <result column="REVOKEREA" property="revokeRea" />
        <result column="WRITSID" property="writsid" />
        <result column="CASENO" property="caseno" />
        <result column="STATE" property="state" />
        <result column="LAUPTIME" property="lauptime" />
        <result column="HANDLERID" property="handlerid" />
        <result column="HANDLERNAME" property="handlername" />
        <result column="HANDLERDATE" property="handlerdate" />
        <result column="CANCELWRITSID" property="cancelwritsid" />
        <result column="PUNISHORG" property="punishOrg" />
        <result column="PUNISHORGCN" property="punishOrgCn" />
        <result column="CODE" property="code" />
        <result column="EXCODE" property="exCode" />
        <result column="MESSAGE" property="message" />
        <result column="RETURTIME" property="returnTime" />
    </resultMap>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_List">
        REVLISTID, UNISCID, PRIPID, REGNO, ENTNAME, INTOSPONSORID, REVOKEREA, INTOSPONSORNAME,HANDLERID,HANDLERNAME,
        HANDLERDATE,CANCELWRITSID, REVOKEDATE, WRITSID, CASENO, STATE, LAUPTIME,PUNISHORG,PUNISHORGCN,CODE,EXCODE,MESSAGE,RETURTIME
    </sql>

    <select id="selectRevokeListPage" resultType="com.chinaweal.aiccs.aiccs.revoke.entity.dto.RevokeListDto">
        SELECT w.WRITSNO, r.REVLISTID, r.ENTNAME, r.REGNO, r.UNISCID, r.PRIPID, r.CASENO,r.INTOSPONSORNAME,r.REVOKEDATE,r.STATE,r.REVOKEREA, r.PUNISHORGCN
        FROM revokelist r
        LEFT JOIN tswrit w on w.WRITSID = r.WRITSID
        <where>
            r.STATE = '1'
            <if test="customParamMap != null">
                <if test="customParamMap.regno != '' and customParamMap.regno != null">
                    and r.REGNO = #{customParamMap.regno}
                </if>
                <if test="customParamMap.uniscid != '' and customParamMap.uniscid != null">
                    and r.UNISCID = #{customParamMap.uniscid}
                </if>
                <if test="customParamMap.caseno != '' and customParamMap.caseno != null">
                    and r.CASENO = #{customParamMap.caseno}
                </if>
                <if test="customParamMap.searchName != '' and customParamMap.searchName != null">
                    and r.ENTNAME like concat('%',#{customParamMap.searchName},'%')
                </if>
                <if test="customParamMap.writsno != '' and customParamMap.writsno != null">
                    and w.writsno like concat('%',#{customParamMap.writsno},'%')
                </if>
                <if test="customParamMap.pripid != '' and customParamMap.pripid != null">
                    and r.pripid = #{customParamMap.pripid}
                </if>
            </if>
        </where>
        order by REVOKEDATE desc
    </select>

    <select id="selectUnsyncedRevokelistBySlice" resultMap="BaseResultMap">
        SELECT <include refid="Base_Column_List" />
        FROM revokelist r
        WHERE r.STATE = '1'
          AND r.PRIPID IS NOT NULL
          AND NOT EXISTS (SELECT 1 FROM E_REVOKE e WHERE e.PRIPID = r.PRIPID)
          AND NOT EXISTS (SELECT 1 FROM E_GT_REVOKE g WHERE g.PRIPID = r.PRIPID)
          <if test="lastRevlistId != null and lastRevlistId != ''">
              AND r.REVLISTID &gt; #{lastRevlistId}
          </if>
        ORDER BY r.REVLISTID ASC
        FETCH FIRST #{pageSize} ROWS ONLY
    </select>


</mapper>
