<?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.hz.pm.api.dashboard.mapper.CockpitStatsMapper">
    <select id="getSecrecyPasswordGrade" resultType="com.hz.pm.api.dashboard.model.po.SecrecyPasswordGradePO">
        SELECT
            sum(CASE WHEN a.secrecy_grade = 1 THEN 1 ELSE 0 end) monitorSecrecyGrade1Num,
            sum(CASE WHEN a.secrecy_grade = 2 THEN 1 ELSE 0 end) monitorSecrecyGrade2Num,
            sum(CASE WHEN a.secrecy_grade = 3 THEN 1 ELSE 0 end) monitorSecrecyGrade3Num,
            sum(CASE WHEN a.secrecy_grade = 4 THEN 1 ELSE 0 end) monitorSecrecyGrade4Num,
            sum(CASE WHEN a.secrecy_grade = 5 THEN 1 ELSE 0 end) monitorSecrecyGrade5Num,
            sum(CASE WHEN a.password_grade = 1 THEN 1 ELSE 0 end) monitorPasswordGrade1Num,
            sum(CASE WHEN a.password_grade = 2 THEN 1 ELSE 0 end) monitorPasswordGrade2Num,
            sum(CASE WHEN a.password_grade = 3 THEN 1 ELSE 0 end) monitorPasswordGrade3Num,
            sum(CASE WHEN a.password_grade = 4 THEN 1 ELSE 0 end) monitorPasswordGrade4Num,
            sum(CASE WHEN a.password_grade = 5 THEN 1 ELSE 0 end) monitorPasswordGrade5Num
        FROM nd_project_application a
                 LEFT JOIN nd_project p ON a."project_code" = p."project_code"  AND a."project_version"  = p.version
        WHERE p."newest" = 1
          <if test="regionCode != null and regionCode != 'TOTAL'">
              AND p."area_code" =#{regionCode}
          </if>
          <choose>
              <when test="year != null and year != 0">
                  AND p.project_year =#{year}
              </when>
              <otherwise>
                  AND p.project_year in (2021,2022,2023)
              </otherwise>
          </choose>
    </select>
</mapper>
