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

    <!-- 通用查询映射结果 -->
    <!--    <resultMap id="BaseResultMap" type="com.chinaweal.aiccs.aiccs.revoke.entity.Tsrevtasklist">-->
    <!--        <id column="TASKLISTID" property="tasklistid" />-->
    <!--        <result column="BUSSTATUS" property="busstatus" />-->
    <!--        <collection column="caseNo"  select="com.chinaweal.aiccs.aiccs.revoke.entity.TsCase" property="caseNo" />-->
    <!--        <collection column="caseName"  select="com.chinaweal.aiccs.aiccs.revoke.entity.TsCase" property="caseName" />-->
    <!--        <collection column="handleOrg"  select="com.chinaweal.aiccs.aiccs.revoke.entity.Tsbizrevlist" property="handleOrg" />-->
    <!--    </resultMap>-->

    <!--    SELECT b.caseNo caseNo, b.caseName caseName, c.handleOrgCn handleOrgCn, a.BUSSTATUS busstatus-->
    <!--    FROM tsrevtasklist a, tscase b, tsbizrevlist c-->
    <!--    where a.CASEID = b.caseId and a.BIZSEQID = c.BIZSEQ and a.BUSTYPE=51;-->

    <!-- 批吊默认查询 -->
    <select id="searchRevBus" resultType="com.chinaweal.aiccs.aiccs.revoke.entity.dto.RevBusDto">
        SELECT m.CASENO, m.caseName, n.handleOrgCn, m.BUSSTATUS, m.setTime, m.BIZSEQID
        FROM (SELECT b.caseNo, b.caseName, a.BUSSTATUS, a.BIZSEQID, b.setTime
              FROM tsrevtasklist a
                       LEFT JOIN tscase b ON a.CASEID = b.caseId
              where a.BUSTYPE = 51
                AND a.AREA_CODE = #{s}) m
                 LEFT JOIN
             (SELECT t.handleOrgCn, b.BIZSEQ
              FROM biz_rev_ent b
                       LEFT JOIN tsbizrevlist t ON t.BIZSEQ = b.BIZSEQ
              GROUP BY b.BIZSEQ) n
             ON m.BIZSEQID = n.BIZSEQ
    </select>

    <!-- 批吊条件查询 -->
    <select id="searchByCondition" resultType="com.chinaweal.aiccs.aiccs.revoke.entity.dto.RevBusDto">
        SELECT 	m.TASKLISTID,m.CASENO, m.caseName, n.handleOrgCn, m.BUSSTATUS, m.setTime, m.BIZSEQID, n.STATUS as
        currentNodeOrBizStatus
        FROM (SELECT a.TASKLISTID,b.caseNo, b.caseName, a.BUSSTATUS, a.BIZSEQID, b.setTime
        FROM tsrevtasklist a
        INNER JOIN tscase b
        ON a.CASEID = b.caseId
        where a.BUSTYPE=51
        <if test=" customParamMap.caseNo != null and customParamMap.caseNo != '' ">
            AND b.caseNo = #{customParamMap.caseNo}
        </if>
        <if test=" customParamMap.caseName != null and customParamMap.caseName != '' ">
            AND b.caseName = #{customParamMap.caseName}
        </if>
        <if test=" customParamMap.setTimeOn != null and customParamMap.setTimeOn != '' ">
            AND b.setTime between #{customParamMap.setTimeOn} and #{customParamMap.setTimeEnd}
        </if>
        ) m
        <!--        <if test=" customParamMap.UNISCID == null and customParamMap.REGNO == null and customParamMap.entName == null">-->
        <!--            LEFT JOIN-->
        <!--        </if>-->
        <!--        <if test=" customParamMap.UNISCID and customParamMap.UNISCID != '' ">-->
        <!--            INNER JOIN-->
        <!--        </if>-->
        <!--        <if test=" customParamMap.REGNO and customParamMap.REGNO != '' ">-->
        <!--            INNER JOIN-->
        <!--        </if>-->
        <!--        <if test=" customParamMap.entName and customParamMap.entName != '' ">-->
        <!--            INNER JOIN-->
        <!--        </if>-->
        <!--        <if test=" customParamMap.punishTimeOn and customParamMap.punishTimeOn != '' ">-->
        <!--     customParamMap.entName and       INNER JOIN-->
        <!--        </if>-->
        INNER JOIN
        (SELECT t.handleOrgCn, b.BIZSEQ, t.STATUS FROM biz_rev_ent b
        LEFT JOIN tsbizrevlist t ON t.BIZSEQ = b.BIZSEQ
        where b.ISREMOVE = '0'
            <if test=" customParamMap.orgNumber != null and customParamMap.orgNumber != '440101' and customParamMap.orgNumber != ''">
                <choose>
                    <when test="customParamMap.orgNumber == '440126'">
                        and (t.handleOrg like '440126%' or t.handleOrg like '440113%')
                    </when>
                    <otherwise>
                        and t.handleOrg like concat(#{customParamMap.orgNumber},'%')
                    </otherwise>
                </choose>
            </if>
            <if test=" customParamMap.UNISCID != null and customParamMap.UNISCID != '' ">
                and b.UNISCID = #{customParamMap.UNISCID}
            </if>
            <if test=" customParamMap.REGNO != null and customParamMap.REGNO != '' ">
                and b.REGNO = #{customParamMap.REGNO}
            </if>
            <if test=" customParamMap.entName != null and customParamMap.entName != '' ">
                and b.ENTNAME like concat('%',#{customParamMap.entName},'%')
            </if>
            <if test=" customParamMap.punishTimeOn != null and customParamMap.punishTimeOn != '' ">
                and b.DECISIONPUBLISHDATE between #{customParamMap.punishTimeOn} and #{customParamMap.punishTimeEnd}
            </if>
        GROUP BY t.handleOrgCn, b.BIZSEQ, t.STATUS) n
        ON m.BIZSEQID = n.BIZSEQ
    </select>

    <!-- 批吊条件查询 -->
    <select id="searchByConditionAll" resultType="com.chinaweal.aiccs.aiccs.revoke.entity.dto.RevBusDto">
        SELECT m.CASENO, m.caseName, n.handleOrgCn, m.BUSSTATUS, m.setTime, m.BIZSEQID, n.STATUS as
        currentNodeOrBizStatus
        FROM (SELECT b.caseNo, b.caseName, a.BUSSTATUS, a.BIZSEQID, b.setTime
        FROM tsrevtasklist a
        INNER JOIN tscase b
        ON a.CASEID = b.caseId
        where a.BUSTYPE=51
        <if test=" caseNo != null and caseNo != '' ">
            AND b.caseNo = #{caseNo}
        </if>
        <if test=" caseName != null and caseName != '' ">
            AND b.caseName = #{caseName}
        </if>
        <if test=" setTimeOn != null and setTimeOn != '' ">
            AND b.setTime between #{setTimeOn} and #{setTimeEnd}
        </if>
        ) m
        INNER JOIN
        (SELECT t.handleOrgCn, b.BIZSEQ, t.STATUS FROM biz_rev_ent b
        LEFT JOIN tsbizrevlist t ON t.BIZSEQ = b.BIZSEQ
        where b.ISREMOVE = '0'
        <if test=" orgNumber != null and orgNumber != '440101' and orgNumber != ''">
            <choose>
                <when test="orgNumber == '440126'">
                    and (t.handleOrg like '440126%' or t.handleOrg like '440113%')
                </when>
                <otherwise>
                    and t.handleOrg like concat(#{orgNumber},'%')
                </otherwise>
            </choose>
        </if>
        <if test=" UNISCID != null and UNISCID != '' ">
            and b.UNISCID = #{UNISCID}
        </if>
        <if test=" REGNO != null and REGNO != '' ">
            and b.REGNO = #{REGNO}
        </if>
        <if test=" entName != null and entName != '' ">
            and b.ENTNAME like concat('%',#{entName},'%')
        </if>
        <if test=" punishTimeOn != null and punishTimeOn != '' ">
            and b.DECISIONPUBLISHDATE between #{punishTimeOn} and #{punishTimeEnd}
        </if>
        GROUP BY t.handleOrgCn, b.BIZSEQ, t.STATUS) n
        ON m.BIZSEQID = n.BIZSEQ
    </select>

    <select id="countOther" resultType="int">
        SELECT count(*)
        FROM biz_rev_ent b, revokelist r
        where b.BIZSEQ = #{id}
          AND b.REVLISTID = r.REVLISTID
          AND r.STATE != '1';
    </select>


</mapper>
