<?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-10-11 16:57:03  -->
<mapper namespace="net.northking.cctp.testbug.db.dao.BugManagementDao">


    <!-- 请在本文件内添加自定义SQL语句 -->

    <resultMap id="DetailMap" type="net.northking.cctp.testbug.dto.BugManagementDetailDto">
        <!-- 缺陷id -->
        <id column="bug_id" jdbcType="VARCHAR" property="bugId"/>
        <!-- 缺陷标题 -->
        <result column="bug_title" jdbcType="VARCHAR" property="bugTitle"/>
        <!-- 严重程度:   建议性错误-E类、警告性错误-D类、一般性错误-C类、严重性错误-B类、致命性错误-A类-->
        <result column="bug_grade" jdbcType="CHAR" property="bugGrade"/>
        <!-- 缺陷分类:  1.需求缺陷、2.设计缺陷、3.编码缺陷、4.UI缺陷、5.兼容性缺陷、6.环境缺陷、7.用户体验、8移植缺陷 -->
        <result column="bug_type" jdbcType="VARCHAR" property="bugType"/>
        <!-- 缺陷编码 -->
        <result column="bug_order" jdbcType="VARCHAR" property="bugOrder"/>
        <!-- 缺陷来源：1.执行提交,2.自动化提交,3.手动提交 -->
        <result column="bug_from" jdbcType="VARCHAR" property="bugFrom"/>
        <!-- 紧急程度：1.高、2.中、3.低 -->
        <result column="emergency" jdbcType="VARCHAR" property="emergency"/>
        <!-- 可重现：Y是、N否 -->
        <result column="is_reappear" jdbcType="CHAR" property="isReappear"/>
        <!-- 缺陷状态：1.新建、2.打开、3.已分配、4.拒绝、5.待验证、6.处理中、7.延迟、8.已修复、9.关闭、10.无效、11.重新打开、12.挂起、13.待裁决、14.待完善、15.待分配、16.待修复、17.待审核 -->
        <result column="bug_status" jdbcType="VARCHAR" property="bugStatus"/>
        <!-- 分配给，缺陷接收人 -->
        <result column="receiver" jdbcType="VARCHAR" property="receiver"/>
        <!-- 修复时间 -->
        <result column="repair_time" jdbcType="TIMESTAMP" property="repairTime"/>
        <!-- 修复人 -->
        <result column="repair_user" jdbcType="VARCHAR" property="repairUser"/>
        <!-- 关闭日期 -->
        <result column="close_time" jdbcType="TIMESTAMP" property="closeTime"/>
        <!-- 错误信息描述 -->
        <result column="error_message" jdbcType="LONGVARCHAR" property="errorMessage"/>
        <!-- 自定义字段 -->
        <result column="expands" jdbcType="LONGVARCHAR" property="expands"/>
        <!-- 注释 -->
        <result column="message" jdbcType="LONGVARCHAR" property="message"/>
        <!-- 系统id -->
        <result column="system_id" jdbcType="VARCHAR" property="systemId"/>
        <!-- 轮次id -->
        <result column="round_id" jdbcType="VARCHAR" property="roundId"/>
        <!-- 模块id -->
        <result column="module_id" jdbcType="VARCHAR" property="moduleId"/>
        <!-- 关联用例数 -->
        <result column="case_num" jdbcType="INTEGER" property="caseNum"/>
        <!-- 项目id -->
        <result column="pro_id" jdbcType="VARCHAR" property="proId"/>
        <!-- 创建发现人 -->
        <result column="created_by" jdbcType="VARCHAR" property="createdBy"/>
        <!-- 创建时间 -->
        <result column="created_time" jdbcType="TIMESTAMP" property="createdTime"/>
        <!-- 更新人 -->
        <result column="updated_by" jdbcType="VARCHAR" property="updatedBy"/>
        <!-- 更新时间 -->
        <result column="updated_time" jdbcType="TIMESTAMP" property="updatedTime"/>
        <!-- 租户id -->
        <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
        <!--  -->
        <result column="USER_DEFINED_IDX1" jdbcType="VARCHAR" property="userDefinedIdx1"/>
        <!--  -->
        <result column="USER_DEFINED_IDX2" jdbcType="VARCHAR" property="userDefinedIdx2"/>
        <!--  -->
        <result column="USER_DEFINED_IDX3" jdbcType="VARCHAR" property="userDefinedIdx3"/>
        <!--  -->
        <result column="USER_DEFINED_IDX4" jdbcType="VARCHAR" property="userDefinedIdx4"/>
        <!--  -->
        <result column="USER_DEFINED_IDX5" jdbcType="VARCHAR" property="userDefinedIdx5"/>
        <!--  -->
        <result column="USER_DEFINED_IDX6" jdbcType="VARCHAR" property="userDefinedIdx6"/>
        <!--  -->
        <result column="USER_DEFINED_IDX7" jdbcType="VARCHAR" property="userDefinedIdx7"/>
        <!--  -->
        <result column="USER_DEFINED_IDX8" jdbcType="VARCHAR" property="userDefinedIdx8"/>
        <!--  -->
        <result column="USER_DEFINED_IDX9" jdbcType="VARCHAR" property="userDefinedIdx9"/>
        <!--  -->
        <result column="USER_DEFINED_IDX10" jdbcType="VARCHAR" property="userDefinedIdx10"/>
        <!--  -->
        <result column="USER_DEFINED_IDX11" jdbcType="VARCHAR" property="userDefinedIdx11"/>
        <!--  -->
        <result column="USER_DEFINED_IDX12" jdbcType="VARCHAR" property="userDefinedIdx12"/>
        <!--  -->
        <result column="USER_DEFINED_IDX13" jdbcType="VARCHAR" property="userDefinedIdx13"/>
        <!--  -->
        <result column="USER_DEFINED_IDX14" jdbcType="VARCHAR" property="userDefinedIdx14"/>
        <!--  -->
        <result column="USER_DEFINED_IDX15" jdbcType="VARCHAR" property="userDefinedIdx15"/>
        <!--  -->
        <result column="USER_DEFINED_IDX16" jdbcType="VARCHAR" property="userDefinedIdx16"/>
        <!--  -->
        <result column="USER_DEFINED_IDX17" jdbcType="VARCHAR" property="userDefinedIdx17"/>
        <!--  -->
        <result column="USER_DEFINED_IDX18" jdbcType="VARCHAR" property="userDefinedIdx18"/>
        <!--  -->
        <result column="USER_DEFINED_IDX19" jdbcType="VARCHAR" property="userDefinedIdx19"/>
        <!--  -->
        <result column="USER_DEFINED_IDX20" jdbcType="VARCHAR" property="userDefinedIdx20"/>
        <collection property="bugRecordDetailDtos" ofType="net.northking.cctp.testbug.dto.BugRecordDetailDto"
                    column="{bug_id=bug_id}" select="queryBugRecordByBugId"/>
        <collection property="correlationLinkDetailDtos"
                    ofType="net.northking.cctp.testbug.dto.BugCorrelationLinkDetailDto"
                    column="{bug_id=bug_id}" select="queryBugCorrelationLinkDetailByBugId"/>
        <collection property="bugLogDetailDtos"
                    ofType="net.northking.cctp.testbug.dto.BugLogDetailDto"
                    column="{bug_id=bug_id}" select="queryBugLogDetailByBugId"/>
    </resultMap>

    <select id="pagingQuery" parameterType="net.northking.cctp.testbug.dto.BugManagementQueryDto"
            resultType="net.northking.cctp.testbug.dto.BugManagementDetailDto">
        select
        bm.bug_id bugId
        ,bug_from bugForm
        ,bug_grade bugGrade
        ,bug_title bugTitle
        ,bug_type bugType
        ,bug_order bugOrder
        ,emergency
        ,is_reappear isReappear
        ,bug_status bugStatus
        ,receiver
        ,error_message errorMessage
        ,expands
        ,round_id roundId
        ,module_id moduleId
        ,system_id systemId
        ,case_num caseNum
        ,pro_id proId
        ,created_by createdBy
        ,created_time createdTime
        ,updated_by updatedBy
        ,updated_time updatedTime
        ,tenant_id tenantId
        ,order_seq orderSeq
        ,close_time closeTime
        ,repair_time repairTime
        ,ec.isExit
        from
        <include refid="Table_Name"/> bm
        LEFT JOIN
        (SELECT distinct bug_id,"1" AS isExit from bug_correlation_link
        WHERE link_type='1'
        <if test="tenantId != null and tenantId != ''">
            AND tenant_id=#{tenantId,jdbcType=VARCHAR}
        </if>
        )ec
        ON bm.bug_id=ec.bug_id
        <trim prefix="WHERE" prefixOverrides="AND">
            <if test="bugId != null and bugId != ''">
                AND bm.bug_id=#{bugId,jdbcType=VARCHAR}
            </if>
            <if test="tenantId != null and tenantId != ''">
                AND tenant_id=#{tenantId,jdbcType=VARCHAR}
            </if>
            <if test="bugIds != null and bugIds.size > 0">
                AND bm.bug_id in
                <foreach collection="bugIds" item="id" open="(" close=")" separator="," index="i">
                    #{id,jdbcType=VARCHAR}
                </foreach>
            </if>
            <if test="bugTitle != null and bugTitle != ''">
                AND LOCATE(#{bugTitle,jdbcType=VARCHAR}, bug_title)
            </if>
            <if test="bugFrom != null and bugFrom != ''">
                AND bug_from=#{bugFrom,jdbcType=CHAR}
            </if>
            <if test="bugOrder != null and bugOrder != ''">
                AND LOCATE(#{bugOrder,jdbcType=VARCHAR}, bug_order)
            </if>
            <if test="bugFrom != null and bugFrom != ''">
                AND bug_from = #{bugFrom}
            </if>
            <if test="bugGrades != null and bugGrades.size > 0">
                AND bug_grade in
                <foreach collection="bugGrades" item="bugGrade" open="(" close=")" separator="," index="i">
                    #{bugGrade,jdbcType=CHAR}
                </foreach>
            </if>
            <if test="bugTypes != null and bugTypes.size > 0">
                AND bug_type in
                <foreach collection="bugTypes" item="bugType" open="(" close=")" separator="," index="i">
                    #{bugType,jdbcType=VARCHAR}
                </foreach>
            </if>
            <if test="emergencies != null and emergencies.size > 0">
                AND emergency in
                <foreach collection="emergencies" item="emergency" open="(" close=")" separator="," index="i">
                    #{emergency,jdbcType=VARCHAR}
                </foreach>
            </if>
            <if test="isReappear != null and isReappear != ''">
                AND is_reappear=#{isReappear,jdbcType=CHAR}
            </if>
            <if test="states != null and states.size > 0">
                AND bug_status in
                <foreach collection="states" item="state" open="(" close=")" separator="," index="i">
                    #{state,jdbcType=VARCHAR}
                </foreach>
            </if>
            <if test="createdBys != null and createdBys.size > 0">
                AND created_by in
                <foreach collection="createdBys" item="createdBy" open="(" close=")" separator="," index="i">
                    #{createdBy,jdbcType=VARCHAR}
                </foreach>
            </if>
            <if test="createdTimeStart != null and createdTimeEnd != null">
                AND created_time BETWEEN #{createdTimeStart,jdbcType=TIMESTAMP}
                AND #{createdTimeEnd,jdbcType=TIMESTAMP}
            </if>
            <if test="receivers != null and receivers.size > 0">
                AND receiver in
                <foreach collection="receivers" item="receiver" open="(" close=")" separator="," index="i">
                    #{receiver,jdbcType=VARCHAR}
                </foreach>
            </if>
            <if test="repairTimeStart != null and repairTimeEnd != null">
                AND  repair_time BETWEEN #{repairTimeStart,jdbcType=TIMESTAMP}
                AND #{repairTimeEnd,jdbcType=TIMESTAMP}
            </if>
            <if test="repairUsers != null and repairUsers.size > 0">
                AND repair_user
                <foreach collection="repairUsers" item="repairUser" open="(" close=")" separator="," index="i">
                    #{repairUser,jdbcType=VARCHAR}
                </foreach>
            </if>
            <if test="closeTimeStart != null and closeTimeEnd != null">
                AND close_time BETWEEN #{closeTimeStart,jdbcType=TIMESTAMP}
                AND #{closeTimeEnd,jdbcType=TIMESTAMP}
            </if>
            <if test="errorMessage != null and errorMessage != ''">
                AND LOCATE(#{errorMessage,jdbcType=LONGVARCHAR}, error_message)
            </if>
            <if test="message != null and message != ''">
                AND LOCATE(#{message,jdbcType=LONGVARCHAR}, message)
            </if>
            <if test="systemId != null and systemId != ''">
                AND LOCATE(#{systemId,jdbcType=LONGVARCHAR}, system_id)
            </if>
            <if test="roundId != null and roundId != ''">
                AND LOCATE(#{roundId,jdbcType=LONGVARCHAR}, round_id)
            </if>
            <if test="moduleId != null and moduleId != ''">
                AND LOCATE(#{moduleId,jdbcType=LONGVARCHAR}, module_id)
            </if>
            <if test="projectList != null and projectList.size > 0">
                AND pro_id in
                <foreach collection="projectList" item="projectId" open="(" close=")" separator="," index="i">
                    #{projectId,jdbcType=VARCHAR}
                </foreach>
            </if>
            <if test="deletedProjectList != null and deletedProjectList.size > 0">
                AND pro_id not in
                <foreach collection="deletedProjectList" item="deletedProjectId" open="(" close=")" separator="," index="i">
                    #{deletedProjectId,jdbcType=VARCHAR}
                </foreach>
            </if>
            <if test="proId != null and proId != ''">
                AND pro_id = #{proId}
            </if>
            <if test="USER_DEFINED_IDX1 != null and USER_DEFINED_IDX1 != ''">
                AND LOCATE(#{USER_DEFINED_IDX1,jdbcType=VARCHAR}, USER_DEFINED_IDX1)
            </if>
            <if test="USER_DEFINED_IDX2 != null and USER_DEFINED_IDX2 != ''">
                AND LOCATE(#{USER_DEFINED_IDX2,jdbcType=VARCHAR}, USER_DEFINED_IDX2)
            </if>
            <if test="USER_DEFINED_IDX3 != null and USER_DEFINED_IDX3 != ''">
                AND LOCATE(#{USER_DEFINED_IDX3,jdbcType=VARCHAR}, USER_DEFINED_IDX3)
            </if>
            <if test="USER_DEFINED_IDX4 != null and USER_DEFINED_IDX4 != ''">
                AND LOCATE(#{USER_DEFINED_IDX4,jdbcType=VARCHAR}, USER_DEFINED_IDX4)
            </if>
            <if test="USER_DEFINED_IDX5 != null and USER_DEFINED_IDX5 != ''">
                AND LOCATE(#{USER_DEFINED_IDX5,jdbcType=VARCHAR}, USER_DEFINED_IDX5)
            </if>
            <if test="USER_DEFINED_IDX6 != null and USER_DEFINED_IDX6 != ''">
                AND LOCATE(#{USER_DEFINED_IDX6,jdbcType=VARCHAR}, USER_DEFINED_IDX6)
            </if>
            <if test="USER_DEFINED_IDX7 != null and USER_DEFINED_IDX7 != ''">
                AND LOCATE(#{USER_DEFINED_IDX7,jdbcType=VARCHAR}, USER_DEFINED_IDX7)
            </if>
            <if test="USER_DEFINED_IDX8 != null and USER_DEFINED_IDX8 != ''">
                AND LOCATE(#{USER_DEFINED_IDX8,jdbcType=VARCHAR}, USER_DEFINED_IDX8)
            </if>
            <if test="USER_DEFINED_IDX9 != null and USER_DEFINED_IDX9 != ''">
                AND LOCATE(#{USER_DEFINED_IDX9,jdbcType=VARCHAR}, USER_DEFINED_IDX9)
            </if>
            <if test="USER_DEFINED_IDX10 != null and USER_DEFINED_IDX10 != ''">
                AND LOCATE(#{USER_DEFINED_IDX10,jdbcType=VARCHAR}, USER_DEFINED_IDX10)
            </if>
            <if test="USER_DEFINED_IDX11 != null and USER_DEFINED_IDX11 != ''">
                AND LOCATE(#{USER_DEFINED_IDX11,jdbcType=VARCHAR}, USER_DEFINED_IDX11)
            </if>
            <if test="USER_DEFINED_IDX12 != null and USER_DEFINED_IDX12 != ''">
                AND LOCATE(#{USER_DEFINED_IDX12,jdbcType=VARCHAR}, USER_DEFINED_IDX12)
            </if>
            <if test="USER_DEFINED_IDX13 != null and USER_DEFINED_IDX13 != ''">
                AND LOCATE(#{USER_DEFINED_IDX13,jdbcType=VARCHAR}, USER_DEFINED_IDX13)
            </if>
            <if test="USER_DEFINED_IDX14 != null and USER_DEFINED_IDX14 != ''">
                AND LOCATE(#{USER_DEFINED_IDX14,jdbcType=VARCHAR}, USER_DEFINED_IDX14)
            </if>
            <if test="USER_DEFINED_IDX15 != null and USER_DEFINED_IDX15 != ''">
                AND LOCATE(#{USER_DEFINED_IDX15,jdbcType=VARCHAR}, USER_DEFINED_IDX15)
            </if>
            <if test="USER_DEFINED_IDX16 != null and USER_DEFINED_IDX16 != ''">
                AND LOCATE(#{USER_DEFINED_IDX16,jdbcType=VARCHAR}, USER_DEFINED_IDX16)
            </if>
            <if test="USER_DEFINED_IDX17 != null and USER_DEFINED_IDX17 != ''">
                AND LOCATE(#{USER_DEFINED_IDX17,jdbcType=VARCHAR}, USER_DEFINED_IDX17)
            </if>
            <if test="USER_DEFINED_IDX18 != null and USER_DEFINED_IDX18 != ''">
                AND LOCATE(#{USER_DEFINED_IDX18,jdbcType=VARCHAR}, USER_DEFINED_IDX18)
            </if>
            <if test="USER_DEFINED_IDX19 != null and USER_DEFINED_IDX19 != ''">
                AND LOCATE(#{USER_DEFINED_IDX19,jdbcType=VARCHAR}, USER_DEFINED_IDX19)
            </if>
            <if test="USER_DEFINED_IDX20 != null and USER_DEFINED_IDX20 != ''">
                AND LOCATE(#{USER_DEFINED_IDX20,jdbcType=VARCHAR}, USER_DEFINED_IDX20)
            </if>
        </trim>
    </select>

    <select id="queryBugRecordByBugId" resultType="net.northking.cctp.testbug.dto.BugRecordDetailDto">
        select *
        from bug_record
        where bug_id = #{bug_id}
        order by created_time desc
    </select>

    <select id="queryBugCorrelationLinkDetailByBugId"
            resultType="net.northking.cctp.testbug.dto.BugCorrelationLinkDetailDto">
        select *
        from bug_correlation_link
        where bug_id = #{bug_id}
        order by created_time desc
    </select>

    <select id="queryBugLogDetailByBugId"
            resultType="net.northking.cctp.testbug.dto.BugLogDetailDto">
        select *
        from bug_log
        where bug_id = #{bug_id}
        order by created_time desc
    </select>

    <select id="queryBugCreatedBy" parameterType="java.lang.String"
            resultType="java.lang.String">
        SELECT distinct created_by as userId
        FROM
        <include refid="Table_Name"/>
        WHERE tenant_id = #{tenantId}
        <if test="projectList != null and projectList.size > 0">
            AND pro_id in
            <foreach collection="projectList" item="projectId" open="(" close=")" separator="," index="i">
                #{projectId,jdbcType=VARCHAR}
            </foreach>
        </if>
    </select>

    <select id="queryBugReceiver" parameterType="java.lang.String"
            resultType="java.lang.String">
        SELECT distinct receiver as userId
        FROM
        <include refid="Table_Name"/>
        WHERE tenant_id = #{tenantId}
        <if test="projectList != null and projectList.size > 0">
            AND pro_id in
            <foreach collection="projectList" item="projectId" open="(" close=")" separator="," index="i">
                #{projectId,jdbcType=VARCHAR}
            </foreach>
        </if>
    </select>

    <select id="queryBugInfo" resultType="net.northking.cctp.testbug.db.entity.BugManagement">
        SELECT DISTINCT
        module_id,
        bug_title,
        bug_order
        FROM
        <include refid="Table_Name"/>
        WHERE tenant_id = #{tenantId}
        <if test="projectList != null and projectList.size > 0">
            AND pro_id in
            <foreach collection="projectList" item="projectId" open="(" close=")" separator="," index="i">
                #{projectId,jdbcType=VARCHAR}
            </foreach>
        </if>
        <if test="bugTitle != null and bugTitle != ''">
            AND LOCATE(#{bugTitle,jdbcType=VARCHAR}, bug_title)
        </if>
        <if test="bugOrder != null and bugOrder != ''">
            AND LOCATE(#{bugOrder,jdbcType=VARCHAR}, bug_order)
        </if>
        <if test="moduleId != null and moduleId != ''">
            AND LOCATE(#{moduleId,jdbcType=LONGVARCHAR}, module_id)
        </if>
    </select>

    <update id="synchronizationModule">
        UPDATE  <include refid="Table_Name"/> b
        JOIN cctp_test_bug.bug_correlation_link l
        SET b.module_id = #{moduleName},
            b.updated_by = #{userId}
            WHERE l.link_id = #{caseId}
            AND b.tenant_id = #{tenantId}
            AND l.link_type = '1'
            AND b.case_num = 1
    </update>

    <update id="synchronizationSystem" parameterType="net.northking.cctp.testbug.dto.bus.SynSystem">
        UPDATE
        <include refid="Table_Name"/>
        set system_id = #{owningSystem},
            updated_by = #{updatedBy}
            where pro_id = #{id}
            and tenant_id = #{tenantId}
    </update>

    <select id="findByLinkId" resultMap="DetailMap">
        select distinct m.*,l.link_type linkType,l.link_name linkName
            from <include refid="Table_Name"/> m
            left join bug_correlation_link l on m.bug_id = l.bug_id
            where l.link_id = #{linkId}
            order by m.created_time desc
    </select>

    <select id="queryBugByStatus" resultType="net.northking.cctp.testbug.dto.BugTendencyChartDetailDto">
        SELECT
        tmp.*,
        tmp.solved+tmp.unsolved AS allAmount
        FROM
        (
        SELECT UUID() id,
        pro_id AS proId,
        DATE_FORMAT(updated_time, '%Y-%m-%d') createdTime,
        SUM(CASE WHEN bug_status IN
        <foreach collection="statusList" item="status" open="(" close=")" separator="," index="i">
            #{status,jdbcType=VARCHAR}
        </foreach>
        THEN 1 ELSE 0 END) solved,
        SUM(CASE WHEN bug_status NOT IN
        <foreach collection="statusList" item="status" open="(" close=")" separator="," index="i">
            #{status,jdbcType=VARCHAR}
        </foreach>
        THEN 1 ELSE 0 END) unsolved,
        tenant_id as tenantId
        FROM
        <include refid="Table_Name"/>
        <trim prefix="WHERE" prefixOverrides="AND">
            <if test="proId != null and proId != ''">
                AND pro_id=#{proId}
            </if>
            <if test="tenantId != null and tenantId != ''">
                AND tenant_id=#{tenantId}
            </if>
            <if test="startTime != null and startTime != '' and endTime != null and endTime != '' ">
                AND DATE_FORMAT(updated_time, '%Y-%m-%d') between #{startTime} and #{endTime}
            </if>
        </trim>
        GROUP BY DATE_FORMAT(updated_time, '%Y-%m-%d'))tmp
    </select>

    <select id="pagingQueryFilter" resultMap="DetailMap" parameterType="net.northking.cctp.testbug.dto.BugManagementQueryDto">
        select
        *
        from
        <include refid="Table_Name"/>
        <trim prefix="WHERE" prefixOverrides="AND">
            <!--    根据用例id进行过滤       -->
            <if test="linkId != null and linkId != ''">
                AND bug_id not in(select distinct bug_id from bug_correlation_link where link_id = #{linkId} )
            </if>
            <if test="bugTitle != null and bugTitle != ''">
                AND LOCATE(#{bugTitle,jdbcType=VARCHAR}, bug_title)
            </if>
            <if test="projectList != null and projectList.size > 0">
                AND pro_id in
                <foreach collection="projectList" item="projectId" open="(" close=")" separator="," index="i">
                    #{projectId,jdbcType=VARCHAR}
                </foreach>
            </if>
        </trim>
    </select>

    <select id="queryBugByDicItems" resultType="net.northking.cctp.testbug.dto.BugStatisticsChartAddDto">
        select
        tmp.*
        from
        (
<!--        项目级按人员-->
            (
            SELECT
            UUID() id,
            created_by receiver_name,
            null module_id,
            0 type,
            cctp_test_bug.bug_management.bug_status bug_status_code,
            COUNT(bug_status) AS amount,
            date_format(now(),'%Y-%m-%d') as created_time,
            tenant_id,
            pro_id project_id,
            case bug_status
            <foreach collection="dictItems" item="item">
                when #{item.itemCode} then #{item.itemName}
            </foreach>
            end as bug_status
            FROM
            <include refid="Table_Name"></include>
            where
            <!--date_format(updated_time,'%Y-%m-%d')=date_format(now(),'%Y-%m-%d') and--> tenant_id=#{tenantId}
            GROUP BY created_by,cctp_test_bug.bug_management.bug_status,pro_id
            )
<!--        项目级按模块-->
            union
            (
            SELECT
            UUID() id,
            null receiver_name,
            module_id,
            1 type,
            cctp_test_bug.bug_management.bug_status bug_status_code,
            COUNT(bug_status) AS amount,
            date_format(now(),'%Y-%m-%d') as created_time,
            tenant_id,
            pro_id project_id,
            case bug_status
            <foreach collection="dictItems" item="item">
                when #{item.itemCode} then #{item.itemName}
            </foreach>
            end as bug_status
            from
            <include refid="Table_Name"></include>
            where <!--date_format(updated_time,'%Y-%m-%d')=date_format(now(),'%Y-%m-%d') and--> tenant_id=#{tenantId}
            GROUP BY module_id,cctp_test_bug.bug_management.bug_status,pro_id
            )
            <!--        每日按人员-->
            union
            (
            SELECT
            UUID() id,
            created_by receiver_name,
            null module_id,
            2 type,
            cctp_test_bug.bug_management.bug_status bug_status_code,
            COUNT(bug_status) AS amount,
            date_format(now(),'%Y-%m-%d') as created_time,
            tenant_id,
            pro_id project_id,
            case bug_status
            <foreach collection="dictItems" item="item">
                when #{item.itemCode} then #{item.itemName}
            </foreach>
            end as bug_status
            FROM
            <include refid="Table_Name"></include>
            where
            date_format(created_time,'%Y-%m-%d')=date_format(now(),'%Y-%m-%d') and tenant_id=#{tenantId}
            GROUP BY created_by,cctp_test_bug.bug_management.bug_status,pro_id
            )
            <!--        每日按模块-->
            union
            (
            SELECT
            UUID() id,
            null receiver_name,
            module_id,
            3 type,
            cctp_test_bug.bug_management.bug_status bug_status_code,
            COUNT(bug_status) AS amount,
            date_format(now(),'%Y-%m-%d') as created_time,
            tenant_id,
            pro_id project_id,
            case bug_status
            <foreach collection="dictItems" item="item">
                when #{item.itemCode} then #{item.itemName}
            </foreach>
            end as bug_status
            from
            <include refid="Table_Name"></include>
            where date_format(created_time,'%Y-%m-%d')=date_format(now(),'%Y-%m-%d') and tenant_id=#{tenantId}
            GROUP BY module_id,cctp_test_bug.bug_management.bug_status,pro_id
            )
        )tmp
        where tmp.bug_status is not null
    </select>

    <select id="queryBugByDicItemsByWeek" resultType="net.northking.cctp.testbug.dto.BugStatisticsChartAddDto">
        select
        tmp.*
        from
        (
        <!--每周按人员 -->
        (
        SELECT
        UUID() id,
        created_by receiver_name,
        null module_id,
        4 type,
        cctp_test_bug.bug_management.bug_status bug_status_code,
        COUNT(bug_status) AS amount,
        REPLACE(SUBDATE(CURDATE(),if(DATE_FORMAT(CURDATE(),'%w')=6,0,DATE_FORMAT(CURDATE(),'%w')+1)),"-","") as created_time,
        tenant_id,
        pro_id project_id,
        case bug_status
        <foreach collection="dictItems" item="item">
            when #{item.itemCode} then #{item.itemName}
        </foreach>
        end as bug_status
        FROM
        <include refid="Table_Name"></include>
        where
        (date(created_time) BETWEEN SUBDATE(CURDATE(),if(DATE_FORMAT(CURDATE(),'%w')=6,0,DATE_FORMAT(CURDATE(),'%w')+1)) AND CURDATE()) and tenant_id=#{tenantId}
        GROUP BY created_by,cctp_test_bug.bug_management.bug_status,pro_id
        )
        <!--   每周按模块-->
        union
        (
        SELECT
        UUID() id,
        null receiver_name,
        module_id,
        5 type,
        cctp_test_bug.bug_management.bug_status bug_status_code,
        COUNT(bug_status) AS amount,
        REPLACE(SUBDATE(CURDATE(),if(DATE_FORMAT(CURDATE(),'%w')=6,0,DATE_FORMAT(CURDATE(),'%w')+1)),"-","") as created_time,
        tenant_id,
        pro_id project_id,
        case bug_status
        <foreach collection="dictItems" item="item">
            when #{item.itemCode} then #{item.itemName}
        </foreach>
        end as bug_status
        from
        <include refid="Table_Name"></include>
        where ((date(created_time) BETWEEN SUBDATE(CURDATE(),if(DATE_FORMAT(CURDATE(),'%w')=6,0,DATE_FORMAT(CURDATE(),'%w')+1)) AND CURDATE())) and tenant_id=#{tenantId}
        GROUP BY module_id,cctp_test_bug.bug_management.bug_status,pro_id
        )
        )tmp
        where tmp.bug_status is not null
    </select>

    <select id="findByLinkIdList" resultType="net.northking.cctp.testbug.dto.IsCommitBugDetailDto">
        select distinct
        link_id as linkId,
        case
        when isnull(bug_id)=1 then 0 else 1
        end as isSubmit
        from
        bug_correlation_link
        where link_id in
        <foreach collection="linkIdList" item="linkId" open="(" separator="," close=")" >
            #{linkId}
        </foreach>
        order by bug_id asc
    </select>

    <select id="findTenantIdList" resultType="java.lang.String">
        select
        distinct tenant_id
        from
        <include refid="Table_Name"></include>
    </select>

    <select id="queryBugByDicItems2" resultType="net.northking.cctp.testbug.dto.BugStatisticsChartAddDto">
        select
        tmp.*
        from
        (
        <!--        跨项目按人员-->
        <if test="recordType=='1'.toString()">
            SELECT
            UUID() id,
            b.created_by receiver_name,
            b.bug_status bug_status_code,
            COUNT(b.bug_status) AS amount,
            b.tenant_id,
            case b.bug_status
            <foreach collection="parseArray" item="item">
                when #{item.itemCode} then #{item.itemName}
            </foreach>
            end as bug_status
            FROM
            <include refid="Table_Name"/> b
            where
            date_format(b.created_time,'%Y-%m-%d')&lt;=date_format(now(),'%Y-%m-%d')
            and b.tenant_id=#{tenantId}
            and b.pro_id in
            <foreach collection="projectIdList" item="proId" open="(" close=")" separator="," >
                #{proId}
            </foreach>
            GROUP BY b.created_by,b.bug_status
        </if>
            <!--        跨项目级按子项目-->
        <if test="recordType!='1'.toString()">
            SELECT
            UUID() id,
            b.bug_status bug_status_code,
            COUNT(b.bug_status) AS amount,
            b.tenant_id,
            case b.bug_status
            <foreach collection="parseArray" item="item">
                when #{item.itemCode} then #{item.itemName}
            </foreach>
            end as bug_status
            from
            <include refid="Table_Name" /> b
            where date_format(b.created_time,'%Y-%m-%d')&lt;=date_format(now(),'%Y-%m-%d')
            and b.tenant_id=#{tenantId}
            and b.pro_id in
            <foreach collection="projectIdList" item="proId" open="(" close=")" separator="," >
                #{proId}
            </foreach>
            GROUP BY b.bug_status
        </if>
        )tmp
        where tmp.bug_status_code is not null
    </select>

    <select id="pagingQueryHighDegree" resultType="net.northking.cctp.testbug.dto.BugHighDegreeChartDetailDto">
        SELECT
        distinct
        UUID() id,
        b.pro_id proId,
        b.bug_id bugId,
        b.tenant_id tenantId,
        b.bug_title bugTitle,
        b.emergency,
        b.bug_grade bugGrade,
        b.bug_status bugStatus,
        b.module_id moduleId,
        b.created_by createdBy,
        b.receiver,
        b.bug_order bugOrder
        FROM
        <include refid="Table_Name"></include> b
        <trim prefix="WHERE" prefixOverrides="AND">
            <if test="tenantId != null and tenantId != ''">
                AND b.tenant_id=#{tenantId}
            </if>
            <if test="projectIdList != null and projectIdList.size() != 0">
                AND b.pro_id in
                <foreach collection="projectIdList" item="proId" open="(" separator="," close=")">
                    #{proId}
                </foreach>
            </if>
            <if test="bugOrder != null and bugOrder != ''">
                AND LOCATE(#{bugOrder},b.bug_order)>0
            </if>
            <if test="recordType == '1'.toString()">
                AND b.emergency='1'
            </if>
            <if test="recordType == '2'.toString()">
                AND b.bug_grade IN('A','B')
            </if>
        </trim>
    </select>

    <select id="queryUserBugByProId" resultType="java.lang.Integer">
        select 1 from <include refid="Table_Name"></include>
        where pro_id = #{projectId}
        <if test="userId != '' and userId != null">
            and
            (
            created_by = #{userId}
            or receiver = #{userId}
            )
        </if>
        limit 1
    </select>

    <select id="findBySchedule" resultType="net.northking.cctp.testbug.dto.bus.BugGradeStatisticsAddDto">
        (
        SELECT
        UUID() id,
        b.created_by receiverName,
        b.created_by loginNo,
        null moduleId,
        0 type,
        SUM(case bug_grade when 'A' then 1 ELSE 0 END) A,
        SUM(case bug_grade when 'B' then 1 ELSE 0 END) B,
        SUM(case bug_grade when 'C' then 1 ELSE 0 END) C,
        SUM(case bug_grade when 'D' then 1 ELSE 0 END) D,
        SUM(case bug_grade when 'E' then 1 ELSE 0 END) E,
        date_format(curdate(),'%Y-%m-%d') createdTime,
        b.tenant_id tenantId,
        b.pro_id projectId
        FROM <include refid="Table_Name"/> b
        <!-- where date_format(b.updated_time,'%Y-%m-%d')=date_format(curdate(),'%Y-%m-%d')-->
        GROUP BY b.created_by,b.tenant_id,b.pro_id
        )
        union
        (
        SELECT
        UUID() id,
        b.created_by receiverName,
        b.created_by loginNo,
        null moduleId,
        2 type,
        SUM(case bug_grade when 'A' then 1 ELSE 0 END) A,
        SUM(case bug_grade when 'B' then 1 ELSE 0 END) B,
        SUM(case bug_grade when 'C' then 1 ELSE 0 END) C,
        SUM(case bug_grade when 'D' then 1 ELSE 0 END) D,
        SUM(case bug_grade when 'E' then 1 ELSE 0 END) E,
        date_format(curdate(),'%Y-%m-%d') createdTime,
        b.tenant_id tenantId,
        b.pro_id projectId
        FROM <include refid="Table_Name"/> b
        where date_format(b.created_time,'%Y-%m-%d')=date_format(curdate(),'%Y-%m-%d')
        GROUP BY b.created_by,b.tenant_id,b.pro_id
        )
        union
        (
        SELECT
        UUID() id,
        null receiverName,
        b.created_by loginNo,
        b.module_id moduleId,
        1 type,
        SUM(case b.bug_grade when 'A' then 1 ELSE 0 END) A,
        SUM(case b.bug_grade when 'B' then 1 ELSE 0 END) B,
        SUM(case b.bug_grade when 'C' then 1 ELSE 0 END) C,
        SUM(case b.bug_grade when 'D' then 1 ELSE 0 END) D,
        SUM(case b.bug_grade when 'E' then 1 ELSE 0 END) E,
        date_format(curdate(),'%Y-%m-%d') createdTime,
        b.tenant_id tenantId,
        b.pro_id proId
        FROM <include refid="Table_Name"/> b
<!--        where date_format(b.updated_time,'%Y-%m-%d')=date_format(curdate(),'%Y-%m-%d')-->
        GROUP BY module_id,b.tenant_id,b.pro_id
        )
    </select>
    <select id="findBySchedule2" resultType="net.northking.cctp.testbug.dto.bus.BugTendencyChartTmpAddDto">
        SELECT
        UUID() id,
        COUNT(bug_status) AS amount,
        date_format(now(),'%Y-%m-%d') as createdTime,
        tenant_id tenantId,
        pro_id projectId,
        bug_status bugStatus
        from
        <include refid="Table_Name"/>
        where date_format(updated_time,'%Y-%m-%d')&lt;=date_format(now(),'%Y-%m-%d')
        GROUP BY bug_status,pro_id,tenant_id
    </select>

    <select id="bugValidAndRepairRatio" resultType="net.northking.cctp.testbug.dto.BugValidRepairRatio">
        SELECT
        module_id moduleId,
        SUM(case when `bug_status` != '10' then 1 ELSE 0 END) valid,
        COUNT(1) bugCount,
        concat(round(SUM(case when `bug_status` != '10' then 1 ELSE 0 END) / COUNT(1) * 100,2),'%') validRatio,
        SUM(case `bug_status` when '9' then 1 ELSE 0 END) bugClose,
        concat(IFNULL(round(SUM(case `bug_status` when '9' then 1 ELSE 0 END) / SUM(case when `bug_status` != '10' then 1 ELSE 0 END) * 100,2),0),'%') repairRatio,
        pro_id projectId,
        tenant_id tenantId
        FROM <include refid="Table_Name"/>
        GROUP BY pro_id,module_id
    </select>

    <select id="userBugGrade" resultType="net.northking.cctp.testbug.dto.MidUserBugGrade">
        SELECT
        created_by createdBy,
        SUM(case bug_grade when 'A' then 1 ELSE 0 END) gradeA,
        SUM(case bug_grade when 'B' then 1 ELSE 0 END) gradeB,
        SUM(case bug_grade when 'C' then 1 ELSE 0 END) gradeC,
        SUM(case bug_grade when 'D' then 1 ELSE 0 END) gradeD,
        SUM(case bug_grade when 'E' then 1 ELSE 0 END) gradeE,
        pro_id projectId,
        tenant_id tenantId
        FROM <include refid="Table_Name"/>
        GROUP BY created_by,pro_id
    </select>

    <select id="findAllGroup" resultType="net.northking.cctp.testbug.dto.BugLegacyGradeGroupDto">
        SELECT
            tenant_id tenantId,
            pro_id proId,
            module_id moduleId,
            bug_grade bugGrade,
            bug_status bugStatus,
            COUNT(*) sum
            FROM bug_management
            GROUP BY pro_id,module_id,bug_grade,bug_status
            ORDER BY pro_id,module_id,bug_grade
    </select>

    <select id="findBySchedule3" resultType="net.northking.cctp.testbug.dto.bus.BugLifeCycleChartAddDto">
        SELECT
        bm.*,
        COUNT(*) amount
        FROM
        (SELECT
        UUID() id,
        tenant_id tenantId,
        pro_id projectId,
        case
        when
        (TIMESTAMPDIFF(SECOND,created_time,close_time)/(60*60*24))&lt;=1  then '1d'
        when
        (TIMESTAMPDIFF(SECOND,created_time,close_time)/(60*60*24))&lt;=2 AND (TIMESTAMPDIFF(SECOND,created_time,close_time)/(60*60*24))>1  then '2d'
        when
        (TIMESTAMPDIFF(SECOND,created_time,close_time)/(60*60*24))&lt;=3 AND (TIMESTAMPDIFF(SECOND,created_time,close_time)/(60*60*24))>2  then '3d'
        when
        (TIMESTAMPDIFF(SECOND,created_time,close_time)/(60*60*24))&lt;=4 AND (TIMESTAMPDIFF(SECOND,created_time,close_time)/(60*60*24))>3  then '4d'
        when
        (TIMESTAMPDIFF(SECOND,created_time,close_time)/(60*60*24))&lt;=5 AND (TIMESTAMPDIFF(SECOND,created_time,close_time)/(60*60*24))>4  then '5d'
        when
        (TIMESTAMPDIFF(SECOND,created_time,close_time)/(60*60*24))&lt;=6 AND (TIMESTAMPDIFF(SECOND,created_time,close_time)/(60*60*24))>5  then '6d'
        when
        (TIMESTAMPDIFF(SECOND,created_time,close_time)/(60*60*24))&lt;=7 AND (TIMESTAMPDIFF(SECOND,created_time,close_time)/(60*60*24))>6  then '1w'
        when
        (TIMESTAMPDIFF(SECOND,created_time,close_time)/(60*60*24))&lt;=14 AND (TIMESTAMPDIFF(SECOND,created_time,close_time)/(60*60*24))>7  then '2w'
        when
        (TIMESTAMPDIFF(SECOND,created_time,close_time)/(60*60*24))&lt;=21 AND (TIMESTAMPDIFF(SECOND,created_time,close_time)/(60*60*24))>14  then '3w'
        when
        (TIMESTAMPDIFF(SECOND,created_time,close_time)/(60*60*24))&lt;=28 AND (TIMESTAMPDIFF(SECOND,created_time,close_time)/(60*60*24))>21  then '4w'
        when
        (TIMESTAMPDIFF(SECOND,created_time,close_time)/(60*60*24))>28 then '>4w'
        END lifeTime
        FROM cctp_test_bug.bug_management
        where
        pro_id=#{proId}
        and
        bug_status in
        <foreach collection="endStatusList" item="status" open="(" close=")" separator=",">
            #{status,jdbcType=VARCHAR}
        </foreach>
        and
        close_time is not null
        ) bm
        WHERE bm.lifeTime IS NOT NULL
        GROUP BY bm.lifeTime
    </select>

    <select id="findProIdList" resultType="java.lang.String">
        select
        distinct pro_id
        from
        <include refid="Table_Name"></include>
    </select>

    <select id="queryBugTendencyMessage" resultType="net.northking.cctp.testbug.dto.BugTendencyChartDetailDto">
        SELECT
        tmp.*,
        tmp.solved+tmp.unsolved AS allAmount
        FROM
        (
        SELECT UUID() id,
        pro_id AS projectId,
        DATE_FORMAT(now(), '%Y-%m-%d') createdTime,
        SUM(CASE WHEN bug_status IN
        <foreach collection="statusList" item="status" open="(" close=")" separator="," index="i">
            #{status,jdbcType=VARCHAR}
        </foreach>
        THEN 1 ELSE 0 END) solved,
        SUM(CASE WHEN bug_status NOT IN
        <foreach collection="statusList" item="status" open="(" close=")" separator="," index="i">
            #{status,jdbcType=VARCHAR}
        </foreach>
        THEN 1 ELSE 0 END) unsolved,
        tenant_id as tenantId
        FROM
        <include refid="Table_Name"/>
        <trim prefix="WHERE" prefixOverrides="AND">
            <if test="proId != null and proId != ''">
                AND pro_id=#{proId}
            </if>
            and DATE_FORMAT(updated_time, '%Y-%m-%d')&lt;=DATE_FORMAT(now(), '%Y-%m-%d')
        </trim>
        )tmp
    </select>

    <select id="countBugAmount" resultType="net.northking.cctp.testbug.dto.CountBugDetailDto">
        select
        tmp.projectId,
        <if test="null!=endStatusList and endStatusList.size()>0">
        tmp.closeBugAmount,
        case when tmp.allDays=0 then 0 else convert(tmp.allDays/(tmp.closeBugAmount*60*60*24),decimal(10,2)) end bugAvgLifeCycle,
        </if>
        tmp.validBugAmount,
        tmp.highGradeBugAmount
        from
        (
            select
            pro_id projectId,
            <if test="null!=endStatusList and endStatusList.size()>0">
                sum(case when (bug_status in
                <foreach collection="endStatusList" open="(" item="endStatus" separator="," close=")" >
                    #{endStatus}
                </foreach>
                and close_time is not null)
                then 1 else 0 end) closeBugAmount,
                sum(case when (bug_status in
                <foreach collection="endStatusList" open="(" item="endStatus" separator="," close=")" >
                    #{endStatus}
                </foreach>
                and close_time is not null)
                then TIMESTAMPDIFF(SECOND,created_time,close_time) else 0 end ) allDays,
            </if>
            sum(case when bug_status !='10' then 1 else 0 end) validBugAmount,
            sum(case when bug_grade in ('A','B') then 1 else 0 end) highGradeBugAmount
            from
            <include refid="Table_Name"></include>
            where
            pro_id=#{projectId}
        )tmp
    </select>


    <select id="pageQ" parameterType="net.northking.cctp.testbug.dto.BugManagementQueryDto"
            resultType="net.northking.cctp.testbug.dto.BugManagementDetailDto">
        select
        *
        from
        <include refid="Table_Name"/>
        <trim prefix="WHERE" prefixOverrides="AND">
            <if test="bugId != null and bugId != ''">
                AND bug_id=#{bugId,jdbcType=VARCHAR}
            </if>
            <if test="bugIds != null and bugIds.size > 0">
                AND bug_id in
                <foreach collection="bugIds" item="id" open="(" close=")" separator="," index="i">
                    #{id,jdbcType=VARCHAR}
                </foreach>
            </if>
            <if test="bugTitle != null and bugTitle != ''">
                AND LOCATE(#{bugTitle,jdbcType=VARCHAR}, bug_title)
            </if>
            <if test="bugFrom != null and bugFrom != ''">
                AND bug_from=#{bugFrom,jdbcType=CHAR}
            </if>
            <if test="bugOrder != null and bugOrder != ''">
                AND LOCATE(#{bugOrder,jdbcType=VARCHAR}, bug_order)
            </if>
            <if test="bugFrom != null and bugFrom != ''">
                AND bug_from = #{bugFrom}
            </if>
            <if test="bugGrades != null and bugGrades.size > 0">
                AND bug_grade in
                <foreach collection="bugGrades" item="bugGrade" open="(" close=")" separator="," index="i">
                    #{bugGrade,jdbcType=CHAR}
                </foreach>
            </if>
            <if test="bugTypes != null and bugTypes.size > 0">
                AND bug_type in
                <foreach collection="bugTypes" item="bugType" open="(" close=")" separator="," index="i">
                    #{bugType,jdbcType=VARCHAR}
                </foreach>
            </if>
            <if test="emergencies != null and emergencies.size > 0">
                AND emergency in
                <foreach collection="emergencies" item="emergency" open="(" close=")" separator="," index="i">
                    #{emergency,jdbcType=VARCHAR}
                </foreach>
            </if>
            <if test="isReappear != null and isReappear != ''">
                AND is_reappear=#{isReappear,jdbcType=CHAR}
            </if>
            <if test="states != null and states.size > 0">
                AND bug_status in
                <foreach collection="states" item="state" open="(" close=")" separator="," index="i">
                    #{state,jdbcType=VARCHAR}
                </foreach>
            </if>
            <if test="createdBys != null and createdBys.size > 0">
                AND created_by in
                <foreach collection="createdBys" item="createdBy" open="(" close=")" separator="," index="i">
                    #{createdBy,jdbcType=VARCHAR}
                </foreach>
            </if>
            <if test="createdTimeStart != null and createdTimeEnd != null">
                AND created_time BETWEEN #{createdTimeStart,jdbcType=TIMESTAMP}
                AND #{createdTimeEnd,jdbcType=TIMESTAMP}
            </if>
            <if test="tenantId != null and tenantId != ''">
                AND tenant_id=#{tenantId,jdbcType=VARCHAR}
            </if>
            <if test="receivers != null and receivers.size > 0">
                AND receiver in
                <foreach collection="receivers" item="receiver" open="(" close=")" separator="," index="i">
                    #{receiver,jdbcType=VARCHAR}
                </foreach>
            </if>
            <if test="repairTimeStart != null and repairTimeEnd != null">
                AND  repair_time BETWEEN #{repairTimeStart,jdbcType=TIMESTAMP}
                AND #{repairTimeEnd,jdbcType=TIMESTAMP}
            </if>
            <if test="repairUsers != null and repairUsers.size > 0">
                AND repair_user
                <foreach collection="repairUsers" item="repairUser" open="(" close=")" separator="," index="i">
                    #{repairUser,jdbcType=VARCHAR}
                </foreach>
            </if>
            <if test="closeTimeStart != null and closeTimeEnd != null">
                AND close_time BETWEEN #{closeTimeStart,jdbcType=TIMESTAMP}
                AND #{closeTimeEnd,jdbcType=TIMESTAMP}
            </if>
            <if test="errorMessage != null and errorMessage != ''">
                AND LOCATE(#{errorMessage,jdbcType=LONGVARCHAR}, error_message)
            </if>
            <if test="message != null and message != ''">
                AND LOCATE(#{message,jdbcType=LONGVARCHAR}, message)
            </if>
            <if test="systemId != null and systemId != ''">
                AND LOCATE(#{systemId,jdbcType=LONGVARCHAR}, system_id)
            </if>
            <if test="roundId != null and roundId != ''">
                AND LOCATE(#{roundId,jdbcType=LONGVARCHAR}, round_id)
            </if>
            <if test="moduleId != null and moduleId != ''">
                AND LOCATE(#{moduleId,jdbcType=LONGVARCHAR}, module_id)
            </if>
            <if test="projectList != null and projectList.size > 0">
                AND pro_id in
                <foreach collection="projectList" item="projectId" open="(" close=")" separator="," index="i">
                    #{projectId,jdbcType=VARCHAR}
                </foreach>
            </if>
            <if test="proId != null and proId != ''">
                AND pro_id = #{proId}
            </if>
            <if test="USER_DEFINED_IDX1 != null and USER_DEFINED_IDX1 != ''">
                AND LOCATE(#{USER_DEFINED_IDX1,jdbcType=VARCHAR}, USER_DEFINED_IDX1)
            </if>
            <if test="USER_DEFINED_IDX2 != null and USER_DEFINED_IDX2 != ''">
                AND LOCATE(#{USER_DEFINED_IDX2,jdbcType=VARCHAR}, USER_DEFINED_IDX2)
            </if>
            <if test="USER_DEFINED_IDX3 != null and USER_DEFINED_IDX3 != ''">
                AND LOCATE(#{USER_DEFINED_IDX3,jdbcType=VARCHAR}, USER_DEFINED_IDX3)
            </if>
            <if test="USER_DEFINED_IDX4 != null and USER_DEFINED_IDX4 != ''">
                AND LOCATE(#{USER_DEFINED_IDX4,jdbcType=VARCHAR}, USER_DEFINED_IDX4)
            </if>
            <if test="USER_DEFINED_IDX5 != null and USER_DEFINED_IDX5 != ''">
                AND LOCATE(#{USER_DEFINED_IDX5,jdbcType=VARCHAR}, USER_DEFINED_IDX5)
            </if>
            <if test="USER_DEFINED_IDX6 != null and USER_DEFINED_IDX6 != ''">
                AND LOCATE(#{USER_DEFINED_IDX6,jdbcType=VARCHAR}, USER_DEFINED_IDX6)
            </if>
            <if test="USER_DEFINED_IDX7 != null and USER_DEFINED_IDX7 != ''">
                AND LOCATE(#{USER_DEFINED_IDX7,jdbcType=VARCHAR}, USER_DEFINED_IDX7)
            </if>
            <if test="USER_DEFINED_IDX8 != null and USER_DEFINED_IDX8 != ''">
                AND LOCATE(#{USER_DEFINED_IDX8,jdbcType=VARCHAR}, USER_DEFINED_IDX8)
            </if>
            <if test="USER_DEFINED_IDX9 != null and USER_DEFINED_IDX9 != ''">
                AND LOCATE(#{USER_DEFINED_IDX9,jdbcType=VARCHAR}, USER_DEFINED_IDX9)
            </if>
            <if test="USER_DEFINED_IDX10 != null and USER_DEFINED_IDX10 != ''">
                AND LOCATE(#{USER_DEFINED_IDX10,jdbcType=VARCHAR}, USER_DEFINED_IDX10)
            </if>
            <if test="USER_DEFINED_IDX11 != null and USER_DEFINED_IDX11 != ''">
                AND LOCATE(#{USER_DEFINED_IDX11,jdbcType=VARCHAR}, USER_DEFINED_IDX11)
            </if>
            <if test="USER_DEFINED_IDX12 != null and USER_DEFINED_IDX12 != ''">
                AND LOCATE(#{USER_DEFINED_IDX12,jdbcType=VARCHAR}, USER_DEFINED_IDX12)
            </if>
            <if test="USER_DEFINED_IDX13 != null and USER_DEFINED_IDX13 != ''">
                AND LOCATE(#{USER_DEFINED_IDX13,jdbcType=VARCHAR}, USER_DEFINED_IDX13)
            </if>
            <if test="USER_DEFINED_IDX14 != null and USER_DEFINED_IDX14 != ''">
                AND LOCATE(#{USER_DEFINED_IDX14,jdbcType=VARCHAR}, USER_DEFINED_IDX14)
            </if>
            <if test="USER_DEFINED_IDX15 != null and USER_DEFINED_IDX15 != ''">
                AND LOCATE(#{USER_DEFINED_IDX15,jdbcType=VARCHAR}, USER_DEFINED_IDX15)
            </if>
            <if test="USER_DEFINED_IDX16 != null and USER_DEFINED_IDX16 != ''">
                AND LOCATE(#{USER_DEFINED_IDX16,jdbcType=VARCHAR}, USER_DEFINED_IDX16)
            </if>
            <if test="USER_DEFINED_IDX17 != null and USER_DEFINED_IDX17 != ''">
                AND LOCATE(#{USER_DEFINED_IDX17,jdbcType=VARCHAR}, USER_DEFINED_IDX17)
            </if>
            <if test="USER_DEFINED_IDX18 != null and USER_DEFINED_IDX18 != ''">
                AND LOCATE(#{USER_DEFINED_IDX18,jdbcType=VARCHAR}, USER_DEFINED_IDX18)
            </if>
            <if test="USER_DEFINED_IDX19 != null and USER_DEFINED_IDX19 != ''">
                AND LOCATE(#{USER_DEFINED_IDX19,jdbcType=VARCHAR}, USER_DEFINED_IDX19)
            </if>
            <if test="USER_DEFINED_IDX20 != null and USER_DEFINED_IDX20 != ''">
                AND LOCATE(#{USER_DEFINED_IDX20,jdbcType=VARCHAR}, USER_DEFINED_IDX20)
            </if>
            order by created_time desc
        </trim>
    </select>
    <insert id="add" parameterType="net.northking.cctp.testbug.db.entity.BugManagement">
        insert into
        <include refid="Table_Name"/>
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="bugId != null">
                bug_id,
            </if>
            <if test="bugTitle != null">
                bug_title,
            </if>
            <if test="bugGrade != null">
                bug_grade,
            </if>
            <if test="bugType != null">
                bug_type,
            </if>
            <if test="bugOrder != null">
                bug_order,
            </if>
            <if test="bugFrom != null">
                bug_from,
            </if>
            <if test="emergency != null">
                emergency,
            </if>
            <if test="isReappear != null">
                is_reappear,
            </if>
            <if test="bugStatus != null">
                bug_status,
            </if>
            <if test="receiver != null">
                receiver,
            </if>
            <if test="repairTime != null">
                repair_time,
            </if>
            <if test="repairUser != null">
                repair_user,
            </if>
            <if test="closeTime != null">
                close_time,
            </if>
            <if test="errorMessage != null">
                error_message,
            </if>
            <if test="expands != null">
                expands,
            </if>
            <if test="message != null">
                message,
            </if>
            <if test="systemId != null">
                system_id,
            </if>
            <if test="roundId != null">
                round_id,
            </if>
            <if test="moduleId != null">
                module_id,
            </if>
            <if test="caseNum != null">
                case_num,
            </if>
            <if test="proId != null">
                pro_id,
            </if>
            <if test="createdBy != null">
                created_by,
            </if>
            <if test="createdTime != null">
                created_time,
            </if>
            <if test="updatedBy != null">
                updated_by,
            </if>
            <if test="updatedTime != null">
                updated_time,
            </if>
            <if test="tenantId != null">
                tenant_id,
            </if>
            <if test="orderSeq != null">
                order_seq,
            </if>
            <if test="userDefinedIdx1 != null">
                USER_DEFINED_IDX1,
            </if>
            <if test="userDefinedIdx2 != null">
                USER_DEFINED_IDX2,
            </if>
            <if test="userDefinedIdx3 != null">
                USER_DEFINED_IDX3,
            </if>
            <if test="userDefinedIdx4 != null">
                USER_DEFINED_IDX4,
            </if>
            <if test="userDefinedIdx5 != null">
                USER_DEFINED_IDX5,
            </if>
            <if test="userDefinedIdx6 != null">
                USER_DEFINED_IDX6,
            </if>
            <if test="userDefinedIdx7 != null">
                USER_DEFINED_IDX7,
            </if>
            <if test="userDefinedIdx8 != null">
                USER_DEFINED_IDX8,
            </if>
            <if test="userDefinedIdx9 != null">
                USER_DEFINED_IDX9,
            </if>
            <if test="userDefinedIdx10 != null">
                USER_DEFINED_IDX10,
            </if>
            <if test="userDefinedIdx11 != null">
                USER_DEFINED_IDX11,
            </if>
            <if test="userDefinedIdx12 != null">
                USER_DEFINED_IDX12,
            </if>
            <if test="userDefinedIdx13 != null">
                USER_DEFINED_IDX13,
            </if>
            <if test="userDefinedIdx14 != null">
                USER_DEFINED_IDX14,
            </if>
            <if test="userDefinedIdx15 != null">
                USER_DEFINED_IDX15,
            </if>
            <if test="userDefinedIdx16 != null">
                USER_DEFINED_IDX16,
            </if>
            <if test="userDefinedIdx17 != null">
                USER_DEFINED_IDX17,
            </if>
            <if test="userDefinedIdx18 != null">
                USER_DEFINED_IDX18,
            </if>
            <if test="userDefinedIdx19 != null">
                USER_DEFINED_IDX19,
            </if>
            <if test="userDefinedIdx20 != null">
                USER_DEFINED_IDX20,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="bugId != null">
                #{bugId, jdbcType=VARCHAR},
            </if>
            <if test="bugTitle != null">
                #{bugTitle, jdbcType=VARCHAR},
            </if>
            <if test="bugGrade != null">
                #{bugGrade, jdbcType=CHAR},
            </if>
            <if test="bugType != null">
                #{bugType, jdbcType=VARCHAR},
            </if>
            <if test="bugOrder != null">
                #{bugOrder, jdbcType=VARCHAR},
            </if>
            <if test="bugFrom != null">
                #{bugFrom, jdbcType=VARCHAR},
            </if>
            <if test="emergency != null">
                #{emergency, jdbcType=VARCHAR},
            </if>
            <if test="isReappear != null">
                #{isReappear, jdbcType=CHAR},
            </if>
            <if test="bugStatus != null">
                #{bugStatus, jdbcType=VARCHAR},
            </if>
            <if test="receiver != null">
                #{receiver, jdbcType=VARCHAR},
            </if>
            <if test="repairTime != null">
                #{repairTime, jdbcType=TIMESTAMP},
            </if>
            <if test="repairUser != null">
                #{repairUser, jdbcType=VARCHAR},
            </if>
            <if test="closeTime != null">
                #{closeTime, jdbcType=TIMESTAMP},
            </if>
            <if test="errorMessage != null">
                #{errorMessage, jdbcType=LONGVARCHAR},
            </if>
            <if test="expands != null">
                #{expands, jdbcType=LONGVARCHAR},
            </if>
            <if test="message != null">
                #{message, jdbcType=LONGVARCHAR},
            </if>
            <if test="systemId != null">
                #{systemId, jdbcType=VARCHAR},
            </if>
            <if test="roundId != null">
                #{roundId, jdbcType=VARCHAR},
            </if>
            <if test="moduleId != null">
                #{moduleId, jdbcType=VARCHAR},
            </if>
            <if test="caseNum != null">
                #{caseNum, jdbcType=INTEGER},
            </if>
            <if test="proId != null">
                #{proId, jdbcType=VARCHAR},
            </if>
            <if test="createdBy != null">
                #{createdBy, jdbcType=VARCHAR},
            </if>
            <if test="createdTime != null">
                #{createdTime, jdbcType=TIMESTAMP},
            </if>
            <if test="updatedBy != null">
                #{updatedBy, jdbcType=VARCHAR},
            </if>
            <if test="updatedTime != null">
                #{updatedTime, jdbcType=TIMESTAMP},
            </if>
            <if test="tenantId != null">
                #{tenantId, jdbcType=VARCHAR},
            </if>
            <if test="orderSeq != null">
                #{orderSeq, jdbcType=VARCHAR},
            </if>
            <if test="userDefinedIdx1 != null">
                #{userDefinedIdx1, jdbcType=VARCHAR},
            </if>
            <if test="userDefinedIdx2 != null">
                #{userDefinedIdx2, jdbcType=VARCHAR},
            </if>
            <if test="userDefinedIdx3 != null">
                #{userDefinedIdx3, jdbcType=VARCHAR},
            </if>
            <if test="userDefinedIdx4 != null">
                #{userDefinedIdx4, jdbcType=VARCHAR},
            </if>
            <if test="userDefinedIdx5 != null">
                #{userDefinedIdx5, jdbcType=VARCHAR},
            </if>
            <if test="userDefinedIdx6 != null">
                #{userDefinedIdx6, jdbcType=VARCHAR},
            </if>
            <if test="userDefinedIdx7 != null">
                #{userDefinedIdx7, jdbcType=VARCHAR},
            </if>
            <if test="userDefinedIdx8 != null">
                #{userDefinedIdx8, jdbcType=VARCHAR},
            </if>
            <if test="userDefinedIdx9 != null">
                #{userDefinedIdx9, jdbcType=VARCHAR},
            </if>
            <if test="userDefinedIdx10 != null">
                #{userDefinedIdx10, jdbcType=VARCHAR},
            </if>
            <if test="userDefinedIdx11 != null">
                #{userDefinedIdx11, jdbcType=VARCHAR},
            </if>
            <if test="userDefinedIdx12 != null">
                #{userDefinedIdx12, jdbcType=VARCHAR},
            </if>
            <if test="userDefinedIdx13 != null">
                #{userDefinedIdx13, jdbcType=VARCHAR},
            </if>
            <if test="userDefinedIdx14 != null">
                #{userDefinedIdx14, jdbcType=VARCHAR},
            </if>
            <if test="userDefinedIdx15 != null">
                #{userDefinedIdx15, jdbcType=VARCHAR},
            </if>
            <if test="userDefinedIdx16 != null">
                #{userDefinedIdx16, jdbcType=VARCHAR},
            </if>
            <if test="userDefinedIdx17 != null">
                #{userDefinedIdx17, jdbcType=VARCHAR},
            </if>
            <if test="userDefinedIdx18 != null">
                #{userDefinedIdx18, jdbcType=VARCHAR},
            </if>
            <if test="userDefinedIdx19 != null">
                #{userDefinedIdx19, jdbcType=VARCHAR},
            </if>
            <if test="userDefinedIdx20 != null">
                #{userDefinedIdx20, jdbcType=VARCHAR},
            </if>
        </trim>
    </insert>
</mapper>