<?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.expelled.mapper.ExpelledAuditInfoMapper">

    <select id="listHavedoAuditInfo" resultType="com.chinaweal.aiccs.aiccs.expelled.vo.AuditInfoVo">
        SELECT
            i.ID auditId,
            i.AUDIT_NO auditNo,
            r.ID resultId,
            r.IS_OBJECTION isObjection,
            r.OPINION opinion,
            r.IS_REMOVE isRemove,
            r.AUDIT_OPINION auditOpinion,
            i.REMOVE_DATE removeDate,
            i.REMOVE_ORG_NO removeOrgNo,
            i.REMOVE_ORG_NAME removeOrgName,
            e.ID entId,
            e.BIZ_ID bizId,
            e.EXPELLED_ID expelledId,
            e.NOTICE_NO noticeNo,
            b.ENT_NAME entName,
            b.USCC uscc,
            b.LEREP_NAME lerepName,
            b.ADDRESS address,
            e.SEND_STATUS sendStatus,
            e.SEND_TIME sendTime
        FROM
            EXPELLED_AUDIT_INFO i
            LEFT JOIN EXPELLED_RESULT_INFO r ON i.ID = r.AUDIT_ID
            LEFT JOIN EXPELLED_ENT_INFO e ON r.ENT_ID = e.ID
            LEFT JOIN ENT_BASE_EXPELLED_INFO b ON e.EXPELLED_ID = b.ID
        <where>
            <if test="map.bizType != null and map.bizType != ''">
                AND i.BIZ_TYPE = #{map.bizType}
            </if>
            <if test="map.auditNo != null and map.auditNo != ''">
                AND i.AUDIT_NO = #{map.auditNo}
            </if>
            <if test="map.entName != null and map.entName != ''">
                AND b.ENT_NAME LIKE '%' || #{map.entName} || '%'
            </if>
            <if test="map.uscc != null and map.uscc != ''">
                AND b.USCC = #{map.uscc}
            </if>
            <if test="map.state != null and map.state != ''">
                AND r.STATE = #{map.state}
            </if>
            <if test="map.states != null">
                AND r.STATE IN
                <foreach collection="map.states" item="item" open="(" separator="," close=")">
                    #{item}
                </foreach>
            </if>
        </where>
    </select>

    <select id="listAuditEntBaseInfo" resultType="com.chinaweal.aiccs.aiccs.expelled.vo.AuditInfoVo">
        SELECT
            r.ID resultId,
            e.NOTICE_NO noticeNo,
            b.ENT_NAME entName,
            b.USCC uscc,
            b.LEREP_NAME lerepName,
            b.ADDRESS address,
            r.AUDIT_OPINION auditOpinion
        FROM
            EXPELLED_AUDIT_INFO i
            LEFT JOIN EXPELLED_RESULT_INFO r ON i.ID = r.AUDIT_ID
            LEFT JOIN EXPELLED_ENT_INFO e ON r.ENT_ID = e.ID
            LEFT JOIN ENT_BASE_EXPELLED_INFO b ON e.EXPELLED_ID = b.ID
        <where>
            <if test="map.bizType != null and map.bizType != ''">
                AND i.BIZ_TYPE = #{map.bizType}
            </if>
            <if test="map.auditId != null and map.auditId != ''">
                AND i.ID = #{map.auditId}
            </if>
            <if test="map.auditNo != null and map.auditNo != ''">
                AND i.AUDIT_NO = #{map.auditNo}
            </if>
            <if test="map.entName != null and map.entName != ''">
                AND b.ENT_NAME LIKE '%' || #{map.entName} || '%'
            </if>
            <if test="map.uscc != null and map.uscc != ''">
                AND b.USCC = #{map.uscc}
            </if>
            <if test="map.state != null and map.state != ''">
                AND r.STATE = #{map.state}
            </if>
        </where>
    </select>
</mapper>
