<?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 11:01:46  -->
<mapper namespace="net.northking.cctp.dw.db.dao.BugValidRepairRatioDao">

    <insert id="addBatch">
        insert into
        bug_valid_repair_ratio(module_id,valid,bug_count,valid_ratio,bug_close,repair_ratio,project_id,tenant_id)
        SELECT
        module_id,
        cast((SUM(case when `bug_status` != '10' then 1 ELSE 0 END)+0) as signed)valid,
        COUNT(1) bug_count,
        concat(round(SUM(case when `bug_status` != '10' then 1 ELSE 0 END) / COUNT(1) * 100,2),'%') valid_ratio,
        cast((SUM(case `bug_status` when '9' then 1 ELSE 0 END)+0) as signed)bug_close,
        concat(IFNULL(round(cast(SUM(case `bug_status` when '9' then 1 ELSE 0 END) as signed) /  NULLIF(cast(SUM(case when `bug_status` != '10' then 1 ELSE 0 END) as signed) * 100,0) ,2),0),'%') repair_ratio,
        pro_id project_id,
        tenant_id tenant_id
        FROM syn_bug_info
        WHERE
        pro_id in
        <foreach collection="dataList" item="synBugInfo" open="(" close=")" separator=",">
            #{synBugInfo.proId}
        </foreach>
        and
        tenant_id=#{tenantId}
        GROUP BY module_id,pro_id
    </insert>
    <delete id="deleteData">
        delete
        from bug_valid_repair_ratio
        where
        tenant_id=#{tenantId}
        and
        project_id in
        <foreach collection="dataList" item="synBugInfo" open="(" close=")" separator=",">
            #{synBugInfo.proId}
        </foreach>
    </delete>
</mapper>