<?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-17 14:49:08  -->
<mapper namespace="net.northking.cctp.dw.db.dao.MidUserBugGradeDao">
    <insert id="addBatch">
        INSERT INTO
        mid_user_bug_grade(created_by,grade_a,grade_b,grade_c,grade_d,grade_e,project_id,tenant_id)
        SELECT
        created_by,
        cast((SUM(CASE bug_grade WHEN 'A' THEN 1 ELSE 0 END)+0) as signed) grade_a,
        cast((SUM(CASE bug_grade WHEN 'B' THEN 1 ELSE 0 END)+0) as signed) grade_b,
        cast((SUM(CASE bug_grade WHEN 'C' THEN 1 ELSE 0 END)+0) as signed) grade_c,
        cast((SUM(CASE bug_grade WHEN 'D' THEN 1 ELSE 0 END)+0) as signed) grade_d,
        cast((SUM(CASE bug_grade WHEN 'E' THEN 1 ELSE 0 END)+0) as signed) grade_e,
        pro_id project_id,
        tenant_id tenant_id
        FROM syn_bug_info
        WHERE
        tenant_id=#{tenantId}
        and
        pro_id in
        <foreach collection="dataList" item="synBugInfo" open="(" close=")" separator=",">
            #{synBugInfo.projectId}
        </foreach>
        GROUP BY created_by,pro_id
    </insert>

    <delete id="deleteByData">
        delete
        from mid_user_bug_grade
        where
        tenant_id=#{tenantId}
        and project_id in
        <foreach collection="dataList" separator="," close=")" open="(" item="data">
            #{data.projectId}
        </foreach>
    </delete>
</mapper>