<?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.lutao.cloud.oil.mapper.SecurityRiskAssessmentMapper">


    <select id="selectRiskAssessmentStatus" resultType="com.lutao.cloud.oil.pojo.vo.SecurityRiskAssessmentVO">

        WITH RankedPlatforms AS (
        SELECT
        ai.app_name AS appName,
        `pi`.`platform_code` AS `platform_code`,
        `pi`.`platform_name` as platform,
        `pi`.`platform_type` AS `platform_type`,
        `pi`.`app_id` AS `app_id`,
        `pi`.`operating_company` AS operatingCompany,
        `pi`.`oil_gas_name` AS oilGasName,
        `t`.`id` AS `id`,
        `t`.`origin_id` AS `origin_id`,
        CASE
        WHEN `t`.`evaluation_object_type` = 1 THEN '固定平台'
        WHEN `t`.`evaluation_object_type` = 2 THEN '钻井平台'
        WHEN `t`.`evaluation_object_type` = 3 THEN '浮式生产储油装置'
        END AS riskAssessmentName,

        `t`.`evaluation_code` AS `evaluationCode`,
        `t`.`total_deduction` AS `total_deduction`,
        `t`.`evaluation_type` AS `evaluation_type`,
        `t`.`score` AS scoringTime ,
        `t`.`risk_rank` AS `risk_rank`,
        CASE
        WHEN t.risk_rank = '004' THEN '低风险'
        WHEN t.risk_rank = '003' THEN '中风险'
        WHEN t.risk_rank = '002' THEN '较高风险'
        WHEN t.risk_rank = '001' THEN '高风险'

        ELSE
        '暂未定级'
        END as riskLevel,

        `t`.`remediation_requirements` AS `remediation_requirements`,
        `t`.`operator` AS `operator`,
        `t`.`pf_id` AS `pf_id`,
        `t`.`create_date` AS `create_date`,
        `t`.`create_by` AS `create_by`,
        `t`.`update_date` AS `update_date`,
        `t`.`update_by` AS `update_by`,
        `t`.`create_time` AS `create_time`,
        `t`.`update_time` AS `update_time`,
        ROW_NUMBER() OVER (PARTITION BY `pi`.`platform_code` ORDER BY `t`.`evaluation_code` DESC) as rn
        FROM
        `platform_info` `pi`
        LEFT JOIN (
        SELECT
        `security_risk_assessment`.*
        FROM
        `security_risk_assessment`
        WHERE
        `security_risk_assessment`.`evaluation_type` = '2'
        AND `security_risk_assessment`.`evaluation_code` LIKE concat(
        '',#{param.year},'%'
        )
        ) `t` ON (`pi`.`platform_code` = `t`.`platform_code`)
        LEFT JOIN app_info ai ON pi.app_id = ai.id
        where pi.delete_flag = '0'
        )
        SELECT *
        FROM RankedPlatforms
        <where>
            <if test="true">
               and rn = 1
            </if>
            <if test="param.platformId != null and param.platformId != ''">
                and platform_code = #{param.platformId}
            </if>
            <if test="param.appId != null and param.appId != ''">
                and app_id = #{param.appId}
            </if>
            <if test="param.operatingCompany != null and param.operatingCompany != ''">
                and operatingCompany = #{param.operatingCompany}
            </if>
            <if test="param.oilGasName != null and param.oilGasName != ''">
                and oilGasName = #{param.oilGasName}
            </if>
            <if test="param.riskLevel != null">
                <choose>
                    <when test="param.riskLevel == 1">
                        and riskLevel = '高风险'
                    </when>
                    <when test="param.riskLevel == 2">
                        and riskLevel = '较高风险'
                    </when>
                    <when test="param.riskLevel == 3">
                        and riskLevel = '中风险'
                    </when>
                    <when test="param.riskLevel == 4">
                        and riskLevel = '低风险'
                    </when>
                    <when test="param.riskLevel == 5">
                        and riskLevel = '暂未定级'
                    </when>
                </choose>
            </if>
            <if test="param.year != null and param.year != ''">
                AND LEFT(evaluationCode, 4) LIKE CONCAT('%',#{param.year},'%')
            </if>
            <if test="param.assessmentObjectType != null">
                <choose>
                    <when test="param.assessmentObjectType == 1">
                        AND evaluation_type = 1
                    </when>
                    <when test="param.assessmentObjectType == 2">
                        AND evaluation_type = 2
                    </when>
                </choose>
            </if>
        </where>
        ORDER BY evaluationCode DESC
    </select>

    <select id="selectProblemRectifySupervision"
            resultType="com.lutao.cloud.oil.pojo.vo.ProblemRectifySupervisionVO">
        SELECT
        ai.app_name as platformName,
        pi.platform_name as facilityName,
        prd.deduction as deduction,
        prd.inspect_content as inspectContent,
        prd.scoring_time as scoringTime
        FROM problem_rectification_detail prd
        LEFT JOIN app_info ai ON prd.app_id = ai.id
        LEFT JOIN platform_info pi ON pi.platform_code = prd.platform_code
        <where>
            pi.delete_flag = '0'
            <if test="platformId != null and platformId != ''">
                and prd.platform_code = #{platformId}
            </if>
            <if test="appId != null and appId != ''">
                and prd.app_id = #{appId}
            </if>
            <if test="operatingCompany != null and operatingCompany != ''">
                and pi.operating_company = #{operatingCompany}
            </if>
            <if test="oilGasName != null and oilGasName != ''">
                and pi.oil_gas_name = #{oilGasName}
            </if>
        </where>
        ORDER BY scoringTime DESC
    </select>
    <select id="selectSecurityRiskAssessmentTimeDistribution"
            resultType="com.lutao.cloud.oil.pojo.vo.SecurityRiskAssessmentTimeDistributionVO">

        SELECT
        COUNT(CASE WHEN MONTH(sra.scoring_time) = 1 THEN 1 END) AS januaryNumber,
        COUNT(CASE WHEN MONTH(sra.scoring_time) = 2 THEN 1 END) AS februaryNumber,
        COUNT(CASE WHEN MONTH(sra.scoring_time) = 3 THEN 1 END) AS marchNumber,
        COUNT(CASE WHEN MONTH(sra.scoring_time) = 4 THEN 1 END) AS aprilNumber,
        COUNT(CASE WHEN MONTH(sra.scoring_time) = 5 THEN 1 END) AS mayNumber,
        COUNT(CASE WHEN MONTH(sra.scoring_time) = 6 THEN 1 END) AS juneNumber,
        COUNT(CASE WHEN MONTH(sra.scoring_time) = 7 THEN 1 END) AS julyNumber,
        COUNT(CASE WHEN MONTH(sra.scoring_time) = 8 THEN 1 END) AS augustNumber,
        COUNT(CASE WHEN MONTH(sra.scoring_time) = 9 THEN 1 END) AS septemberNumber,
        COUNT(CASE WHEN MONTH(sra.scoring_time) = 10 THEN 1 END) AS octoberNumber,
        COUNT(CASE WHEN MONTH(sra.scoring_time) = 11 THEN 1 END) AS novemberNumber,
        COUNT(CASE WHEN MONTH(sra.scoring_time) = 12 THEN 1 END) AS decemberNumber
        FROM problem_rectification_detail sra
        <where>
            <if test="platformId != null and platformId != ''">
                sra.platform_code = #{platformId}
            </if>
            <if test="appId != null and appId != ''">
                and sra.app_id = #{appId}
            </if>
        </where>
    </select>
    <select id="selectSeaPlatformFacility" resultType="com.lutao.cloud.oil.pojo.vo.SeaPlatformFacilityVO">
        SELECT
            ai.app_name ,
            sras.platform_code,
            pi.platform_name as platform,
            sras.score as scoringTime,
            pi.oil_gas_name as oilGasName,
            pi.operating_company as operatingCompany,
            CASE
                WHEN sras.risk_rank = '004' THEN '低风险'
                WHEN sras.risk_rank = '003' THEN '中风险'
                WHEN sras.risk_rank = '002' THEN '较高风险'
                WHEN sras.risk_rank = '001' THEN '高风险'
                ELSE
                    '暂未定级'
                END as riskLevel
        FROM
            security_risk_assessment_summary  sras
                LEFT JOIN platform_info pi ON sras.platform_code = pi.platform_code
                LEFT JOIN app_info ai ON sras.app_id = ai.id
        <where>
            <if test="true">
                pi.delete_flag = '0'
            </if>
            <if test="param.platformId != null and param.platformId != ''">
                and sras.platform_code = #{param.platformId}
            </if>
            <if test="param.appId != null and param.appId != ''">
                and sras.app_id = #{param.appId}
            </if>
            <if test="param.operatingCompany != null and param.operatingCompany != ''">
                and pi.operating_company = #{param.operatingCompany}
            </if>
            <if test="param.oilGasName != null and param.oilGasName != ''">
                and pi.oil_gas_name = #{param.oilGasName}
            </if>
            <if test="param.riskLevel != null">
                <choose>
                    <when test="param.riskLevel == 1">
                        and sras.risk_rank = '001'
                    </when>
                    <when test="param.riskLevel == 2">
                        and sras.risk_rank = '002'
                    </when>
                    <when test="param.riskLevel == 3">
                        and sras.risk_rank = '003'
                    </when>
                    <when test="param.riskLevel == 4">
                        and sras.risk_rank = '004'
                    </when>
                    <when test="param.riskLevel == 5">
                        and sras.risk_rank is null
                    </when>
                </choose>
            </if>
            <if test="param.excludeLowRiskFlag != null">
                <choose>
                    <when test="param.excludeLowRiskFlag == 1">
                        and sras.risk_rank != '004'
                    </when>
                </choose>
            </if>
            <if test="param.year != null and param.year != ''">
                and sras.evaluation_year = #{param.year}
            </if>
            <if test="true">
                and sras.evaluation_type = 2 and sras.evaluation_year = YEAR(NOW())
            </if>
        </where>
        order by scoringTime desc,evaluation_type desc

    </select>
    <select id="getHiddenDangerRectificationRate"
            resultType="com.lutao.cloud.oil.pojo.vo.HiddenDangerRectificationVO">
        SELECT
        ROUND(COALESCE(COUNT(CASE WHEN sra.score &gt; 900 AND prd.hidden_problems_state = '002' THEN 1 END)
        /NULLIF(COUNT(CASE WHEN sra.score &gt; 900 THEN 1 END), 0), 1), 3) AS lowRiskRectifyRate,
        ROUND(COALESCE(COUNT(CASE WHEN sra.score &gt; 850 AND sra.score &lt;= 900 AND prd.hidden_problems_state = '002'
        THEN
        1 END)
        / NULLIF(COUNT(CASE WHEN sra.score &gt; 850 AND sra.score &lt;= 900 THEN 1 END), 0), 1), 3) AS
        mediumRiskRectifyRate,
        ROUND(COALESCE(COUNT(CASE WHEN sra.score &gt; 700 AND sra.score &lt;= 850 AND prd.hidden_problems_state = '002'
        THEN
        1 END)
        / NULLIF(COUNT(CASE WHEN sra.score &gt; 700 AND sra.score &lt;= 850 THEN 1 END), 0), 1), 3) AS
        mediumHighRiskRectifyRate,
        ROUND(COALESCE(COUNT(CASE WHEN sra.score &lt;= 700 AND prd.hidden_problems_state = '002' THEN 1 END)
        / NULLIF(COUNT(CASE WHEN sra.score &lt;= 700 THEN 1 END), 0), 1), 3) AS highRiskRectifyRate
        FROM problem_rectification_detail prd
        LEFT JOIN security_risk_assessment_summary sra ON prd.sra_id = sra.origin_id
        <where>
            <if test="param.platformId != null and param.platformId != ''">
                prd.platform_code = #{param.platformId}
            </if>
            <if test="param.appId != null and param.appId != ''">
                and prd.app_id = #{param.appId}
            </if>
            <choose>
                <when test="param.year != null and param.year != ''">
                    AND sra.evaluation_year = #{param.year}
                </when>
                <otherwise>
                    AND sra.evaluation_year = YEAR(NOW())
                </otherwise>
            </choose>
        </where>
    </select>
    <select id="getAssessmentStrategy" resultType="com.lutao.cloud.oil.pojo.vo.AssessmentReportVO">


    </select>
    <select id="getHiddenDangerNumberNowYear" resultType="java.lang.Integer">
        SELECT COUNT(*)
        FROM problem_rectification_detail prd
        LEFT JOIN security_risk_assessment_summary sra ON prd.sra_id = sra.origin_id
        LEFT JOIN platform_info pi ON prd.platform_code = pi.platform_code
        <where>
            <if test="true">
                pi.delete_flag = '0'
            </if>
            <if test="param.platformId != null and param.platformId != ''">
                and prd.platform_code = #{param.platformId}
            </if>
            <if test="param.appId != null and param.appId != ''">
                and prd.app_id = #{param.appId}
            </if>
            <if test="true">
                AND sra.evaluation_year = #{param.year}
            </if>
        </where>
    </select>
    <select id="getRiskLevelGroup" resultType="com.lutao.cloud.oil.pojo.vo.RiskLevelGroupVO">
        SELECT COUNT(*) AS riskCount,t.riskLevel AS riskLevel FROM
        (
        SELECT
        sra.platform_code AS pcode,
        MAX( pi.platform_name ) AS platform,
        MAX( sra.evaluation_type ) AS evaluation_type,
        MAX( pi.oil_gas_name ) AS oilGasName,
        MAX( pi.operating_company ) AS operatingCompany,
        CASE
        WHEN MAX( sra.score ) &lt;= 700 THEN '高风险'
        WHEN MAX( sra.score ) > 700 AND MAX( sra.score ) &lt;= 850 THEN '较高风险'
        WHEN MAX( sra.score ) > 850 AND MAX( sra.score ) &lt;= 900 THEN '中风险'
        ELSE '低风险'
        END AS riskLevel,
        MAX( sra.score ) AS scoringTime,
        MAX( ai.app_name) AS appName
        FROM security_risk_assessment sra
        LEFT JOIN app_info ai ON sra.app_id = ai.id
        LEFT JOIN platform_info pi ON pi.platform_code = sra.platform_code
        <where>
            pi.delete_flag = '0'
            <if test="param.platformId != null and param.platformId != ''">
                and sra.platform_code = #{param.platformId}
            </if>
            <if test="param.appId != null and param.appId != ''">
                and sra.app_id = #{param.appId}
            </if>
            <if test="param.operatingCompany != null and param.operatingCompany != ''">
                and sra.operating_company = #{param.operatingCompany}
            </if>
            <if test="param.oilGasName != null and param.oilGasName != ''">
                and sra.oil_gas_name = #{param.oilGasName}
            </if>
            <if test="true">
                and LEFT(sra.evaluation_code, 4) LIKE CONCAT('%',#{param.year},'%')
            </if>
        </where>
        GROUP BY
        pcode
        ORDER BY
        MAX( sra.evaluation_type ) DESC,
        MAX( sra.score ) DESC
        ) t

        GROUP BY riskLevel
    </select>
    <select id="getAssessmentNumberNowYear" resultType="java.lang.Integer">
        SELECT COUNT(*) FROM security_risk_assessment
        <where>
            <if test="platformId != null and platformId != ''">
                platform_code = #{platformId}
            </if>
            <if test="appId != null and appId != ''">
                and app_id = #{appId}
            </if>
            <if test="true">
                AND LEFT(evaluation_code, 4) LIKE CONCAT('%',YEAR(CURRENT_DATE),'%')
            </if>
        </where>
    </select>
    <select id="assessmentReportNumber" resultType="java.lang.Integer">
        SELECT COUNT(*) FROM
        (
        SELECT
        sra.platform_code AS pcode,
        MAX( pi.platform_name ) AS platform,
        MAX( sra.evaluation_type ) AS evaluation_type,
        MAX( pi.oil_gas_name ) AS oilGasName,
        MAX( pi.operating_company ) AS operatingCompany,
        CASE
        WHEN MAX( sra.score ) &lt;= 700 THEN '高风险'
        WHEN MAX( sra.score ) > 700 AND MAX( sra.score ) &lt;= 850 THEN '较高风险'
        WHEN MAX( sra.score ) > 850 AND MAX( sra.score ) &lt;= 900 THEN '中风险'
        ELSE '低风险'
        END AS riskLevel,
        MAX( sra.score ) AS scoringTime,
        MAX( ai.app_name) AS appName
        FROM security_risk_assessment sra
        LEFT JOIN app_info ai ON sra.app_id = ai.id
        LEFT JOIN platform_info pi ON pi.platform_code = sra.platform_code
        <where>
            pi.delete_flag = '0'
            <if test="param.platformId != null and param.platformId != ''">
                and sra.platform_code = #{param.platformId}
            </if>
            <if test="param.appId != null and param.appId != ''">
                and sra.app_id = #{param.appId}
            </if>
            <if test="param.operatingCompany != null and param.operatingCompany != ''">
                and sra.operating_company = #{param.operatingCompany}
            </if>
            <if test="param.oilGasName != null and param.oilGasName != ''">
                and sra.oil_gas_name = #{param.oilGasName}
            </if>
            <if test="true">
                and LEFT(sra.evaluation_code, 4) LIKE CONCAT('%',#{param.year},'%')
            </if>
        </where>
        GROUP BY
        pcode
        ORDER BY
        MAX( sra.evaluation_type ) DESC,
        MAX( sra.score ) DESC
        ) t

    </select>
    <select id="getHiddenDangerNumber" resultType="com.lutao.cloud.oil.pojo.vo.HiddenDangerNumberVO">
        SELECT COUNT(CASE
        WHEN sra.score &gt; 900 AND prd.hidden_problems_state = '002'
        THEN 1 END) AS lowRiskRectifyNumber,
        COUNT(CASE WHEN sra.score &gt; 900 THEN 1 END) AS lowRiskNumber,
        COUNT(CASE
        WHEN sra.score &gt; 850 AND sra.score &lt;= 900 AND prd.hidden_problems_state = '002'
        THEN 1 END) AS mediumRiskRectifyNumber,
        COUNT(CASE WHEN sra.score &gt; 850 AND sra.score &lt;= 900 THEN 1 END) AS mediumRiskNumber,
        COUNT(CASE
        WHEN sra.score &gt; 700 AND sra.score &lt;= 850 AND prd.hidden_problems_state = '002'
        THEN 1 END) AS mediumHighRiskRectifyNumber,
        COUNT(CASE WHEN sra.score &gt; 700 AND sra.score &lt;= 850 THEN 1 END) AS mediumHighRiskNumber,
        COUNT(CASE
        WHEN sra.score &lt;= 700 AND prd.hidden_problems_state = '002'
        THEN 1 END) AS highRiskRectifyNumber,
        COUNT(CASE WHEN sra.score &lt;= 700 THEN 1 END) AS highRiskNumber
        FROM problem_rectification_detail prd
        LEFT JOIN security_risk_assessment_summary sra ON prd.sra_id = sra.origin_id
        LEFT JOIN platform_info pi ON prd.platform_code = pi.platform_code
        <where>
            pi.delete_flag = '0'
            <if test="param.platformId != null and param.platformId != ''">
               AND prd.platform_code = #{param.platformId}
            </if>
            <if test="param.appId != null and param.appId != ''">
                and prd.app_id = #{param.appId}
            </if>
            <if test="true">
                AND sra.evaluation_year = #{param.year}
            </if>
        </where>
    </select>
    <select id="getSecurityRiskAssessmentBarList"
            resultType="com.lutao.cloud.oil.pojo.vo.SecurityRiskAssessmentBarList">
        SELECT DISTINCT sra.platform_code,
        sra.score,
        platform_type
        FROM security_risk_assessment sra
        LEFT JOIN platform_info pi ON sra.platform_code = pi.platform_code
        <where>
            pi.delete_flag = '0'
            <if test="param.platformId != null and param.platformId != ''">
                and sra.platform_code = #{param.platformId}
            </if>
            <if test="param.appId != null and param.appId != ''">
                and sra.app_id = #{param.appId}
            </if>
            <if test="true">
                AND LEFT(sra.evaluation_code, 4) LIKE CONCAT('%',#{param.year},'%')
                AND sra.evaluation_type = 2
            </if>
        </where>
    </select>
    <select id="getSecurityRiskAssessmentBarListVO"
            resultType="com.lutao.cloud.oil.pojo.vo.SecurityRiskAssessmentBarListVO">
        SELECT
        a.platform_name AS platform,
        a.oil_gas_name AS oilGasName,
        a.operating_company AS operatingCompany,
        CASE

        WHEN (SELECT sra.risk_rank FROM security_risk_assessment sra WHERE sra.platform_code = a.platform_code and
        LEFT(sra.evaluation_code,4) LIKE concat('%',#{param.year},'%') and sra.evaluation_type = 2 ORDER BY LEFT(sra.evaluation_code,4) LIMIT
        1) = '004' THEN
        '低风险'
        WHEN (SELECT sra.risk_rank FROM security_risk_assessment sra WHERE sra.platform_code = a.platform_code and
        LEFT(sra.evaluation_code,4) LIKE concat('%',#{param.year},'%') and sra.evaluation_type = 2 ORDER BY LEFT(sra.evaluation_code,4) LIMIT
        1) = '003' THEN
        '中风险'
        WHEN (SELECT sra.risk_rank FROM security_risk_assessment sra WHERE sra.platform_code = a.platform_code and
        LEFT(sra.evaluation_code,4) LIKE concat('%',#{param.year},'%') and sra.evaluation_type = 2 ORDER BY LEFT(sra.evaluation_code,4) LIMIT
        1) = '002' THEN
        '较高风险'
        WHEN (SELECT sra.risk_rank FROM security_risk_assessment sra WHERE sra.platform_code = a.platform_code and
        LEFT(sra.evaluation_code,4) LIKE concat('%',#{param.year},'%') and sra.evaluation_type = 2 ORDER BY LEFT(sra.evaluation_code,4) LIMIT
        1) = '001' THEN
        '高风险' ELSE '暂未定级'
        END AS riskLevel,
        (SELECT sra.score FROM security_risk_assessment sra WHERE sra.platform_code = a.platform_code and
        LEFT(sra.evaluation_code,4) LIKE concat('%',#{param.year},'%') and sra.evaluation_type = 2 ORDER BY LEFT(sra.evaluation_code,4) LIMIT
        1) AS scoringTime,
        ai.app_name AS appName,
        a.platform_type
        FROM
        platform_info a
        LEFT JOIN app_info ai ON a.app_id = ai.id
        <where>
            a.delete_flag = '0'
            <if test="param.platformId != null and param.platformId != ''">
                and a.platform_code = #{param.platformId}
            </if>
            <if test="param.appId != null and param.appId != ''">
                and a.app_id = #{param.appId}
            </if>
            <if test="param.operatingCompany != null and param.operatingCompany != ''">
                and a.operating_company = #{param.operatingCompany}
            </if>
            <if test="param.oilGasName != null and param.oilGasName != ''">
                and a.oil_gas_name = #{param.oilGasName}
            </if>
        </where>
    </select>
    <select id="getPlatformsAndAssessmentVO" resultType="com.lutao.cloud.oil.pojo.vo.PlatformsAndAssessmentVO">
        WITH RankedPlatforms AS (
            SELECT
                ai.app_name AS appName,
                `pi`.`platform_code` AS `platformCode`,
                `pi`.`platform_name` as platform,
                `pi`.`platform_type` AS `platformType`,
                `pi`.`app_id` AS `appId`,
                `pi`.`operating_company` AS operatingCompany,
                `pi`.`oil_gas_name` AS oilGasName,
                `t`.`id` AS `id`,
                `t`.`origin_id` AS `originId`,
                `t`.`evaluation_object_type` AS `evaluationObjectType`,
                `t`.`evaluation_code` AS `evaluationCode`,
                `t`.`total_deduction` AS `totalDeduction`,
                `t`.`evaluation_type` AS `evaluationType`,
                `t`.`score` AS scoringTime ,
                `t`.`risk_rank` AS `riskRank`,
                CASE
                    WHEN t.risk_rank = '004' THEN '低风险'
                    WHEN t.risk_rank = '003' THEN '中风险'
                    WHEN t.risk_rank = '002' THEN '较高风险'
                    WHEN t.risk_rank = '001' THEN '高风险'

                    ELSE
                        '暂未定级'
                    END as riskLevel,

                `t`.`remediation_requirements` AS `remediationRequirements`,
                `t`.`operator` AS `operator`,
                ROW_NUMBER() OVER (PARTITION BY `pi`.`platform_code` ORDER BY `t`.`evaluation_code` DESC) as rn
            FROM
                `platform_info` `pi`
                    LEFT JOIN (
                    SELECT
                        `security_risk_assessment`.*
                    FROM
                        `security_risk_assessment`
                    WHERE
                        `security_risk_assessment`.`evaluation_type` = '2'
                      AND `security_risk_assessment`.`evaluation_code` LIKE concat(
                            '',
                            #{param.year},
                            '%'
                        )
                ) `t` ON (`pi`.`platform_code` = `t`.`platform_code`)
                    LEFT JOIN app_info ai ON pi.app_id = ai.id
            where pi.delete_flag = '0'
        )
        SELECT *
        FROM RankedPlatforms
        <where>
            <if test="true">
                and rn = 1
            </if>
            <if test="param.appId != null and param.appId != ''">
                and appId = #{param.appId}
            </if>
            <if test="param.platformId != null and param.platformId != ''">
                and platformCode = #{param.platformId}
            </if>
        </where>
    </select>
</mapper>
