<?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.unis.policy.info.modular.alPolicyFileReport.mapper.AlPolicyFileReportMapper">
    <select id="selectMyMapsPage" resultType="java.util.Map">
        <if test="policyType == 1" >
        SELECT
        a.id AS "id",
        a.title AS "title",
        b. NAME AS "sysOrgName",
        a.reporter AS "reporter",
        a.contact_info AS "contactInfo",
        DATE_FORMAT(a.report_date, '%Y-%m-%d') AS "reportDate",
        a. STATUS AS "status",
        c.id as "requestId",
        c.audit_status as "auditStatus",
        DATE_FORMAT(c.audit_time, '%Y-%m-%d %T') AS "auditTime",
        d.name as "auditUserName"
        FROM
        biz_al_policy_file_report a
        LEFT JOIN sys_org b ON a.sys_org_id = b.ID
        LEFT JOIN biz_audit_request c on a.id = c.request_id AND c.type = 1 and c.step = 1 -- 合法性审核
        LEFT JOIN sys_user d on c.audit_user_id = d.ID
        </if>
        <if test="policyType == 2" >
            SELECT
            a.id AS "id",
            a.title AS "title",
            b. NAME AS "sysOrgName",
            a.reporter AS "reporter",
            a.contact_info AS "contactInfo",
            DATE_FORMAT(a.report_date, '%Y-%m-%d') AS "reportDate",
            a. STATUS AS "status",
            d.id as "requestId",
            d.audit_status as "auditStatus",
            DATE_FORMAT(d.audit_time, '%Y-%m-%d %T') AS "auditTime",
            e.name as "auditUserName"
            FROM
            biz_al_policy_file_report a
            LEFT JOIN sys_org b ON a.sys_org_id = b.ID
            inner JOIN biz_audit_request c on a.id = c.request_id AND c.type = 1 and c.step = 1 and c.audit_status = 1 -- 合法性审核通过
            left JOIN biz_audit_request d on a.id = d.request_id AND d.type = 1 and d.step = 2  -- 过会审核
            LEFT JOIN sys_user e on d.audit_user_id = e.ID
        </if>
        <if test="policyType == 3" >
            SELECT
            a.id AS "id",
            a.title AS "title",
            b. NAME AS "sysOrgName",
            a.reporter AS "reporter",
            a.contact_info AS "contactInfo",
            DATE_FORMAT(a.report_date, '%Y-%m-%d') AS "reportDate",
            a. STATUS AS "status"
            FROM
            biz_al_policy_file_report a
            LEFT JOIN sys_org b ON a.sys_org_id = b.ID
        </if>
        <if test="ew.sqlSegment != null and ew.sqlSegment != ''">
            where ${ew.sqlSegment}
        </if>
        order by a.report_date desc
    </select>
    <select id="getReportsByCurUser" resultType="java.util.Map">
    SELECT
            a.id AS "id",
            a.title AS "title"
        FROM
            biz_al_policy_file_report a
        LEFT JOIN biz_audit_request c ON a.id = c.request_id
        AND c.type = 1
        AND c.step = 1 -- 合法性审核
        WHERE
            a. STATUS = 1
        AND c.request_id IS NULL
        <if test="ew.sqlSegment != null and ew.sqlSegment != ''">
            and  ${ew.sqlSegment}
        </if>
        ORDER BY a.create_time desc
    </select>
</mapper>