<?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">
<!--  Copyright (c) 京北方信息技术股份有限公司 Corporation 2021 . All rights reserved. -->
<!--  Mybatis数据库持久层（业务层映射文件）：缺陷遗留及严重等级分布 -->
<!--  version: 1.0  -->
<!--  author:  maven-cctp-plugin    -->
<!--  date:  2021-12-20 10:12:52  -->
<mapper namespace="net.northking.cctp.dw.db.dao.BugLegacyGradeDao">
    <insert id="insertBatch">
        insert into
        bug_legacy_grade(module_id,grade_a,grade_b,grade_c,grade_d,grade_e,project_id,tenant_id)
        select
        s.module_id,
        cast((sum(s.bug_grade='A')+0) as signed)grade_a,
        cast((sum(s.bug_grade='B')+0) as signed)grade_b,
        cast((sum(s.bug_grade='C')+0) as signed)grade_c,
        cast((sum(s.bug_grade='D')+0) as signed)grade_d,
        cast((sum(s.bug_grade='E')+0) as signed)grade_e,
        s.pro_id project_id,
        s.tenant_id
        from syn_bug_info s
        where
        s.bug_status IN (select bug_status_code from bug_template_status b where
        b.project_id in
        <foreach collection="projectIds" item="projectId" open="(" separator="," close=")">
            #{projectId, jdbcType=VARCHAR}
        </foreach>
        and b.is_end_status!=1)
        and
        s.pro_id in
        <foreach collection="projectIds" item="projectId" open="(" separator="," close=")">
            #{projectId, jdbcType=VARCHAR}
        </foreach>
        and
        s.tenant_id=#{tenantId}
        group by s.pro_id, s.module_id
    </insert>

    <select id="getProjectList" resultType="net.northking.cctp.dw.db.entity.BugLegacyGrade">
        select
        tenant_id tenantId,
        pro_id projectId
        from
        syn_bug_info
        group by
        tenant_id,
        pro_id
    </select>

    <delete id="deleteByExampleByProjectIds" parameterType="net.northking.cctp.dw.db.entity.BugLegacyGrade">
        DELETE FROM cctp_dw.bug_legacy_grade WHERE project_id IN
        <foreach collection="projectIds" item="projectId" open="(" separator="," close=")">
            #{projectId, jdbcType=VARCHAR}
        </foreach>
    </delete>
</mapper>