<?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 2022 . All rights reserved. -->
<!--  Mybatis数据库持久层（业务层映射文件）： -->
<!--  version: 1.0  -->
<!--  author:  maven-cctp-plugin    -->
<!--  date:  2022-01-17 11:02:43  -->
<mapper namespace="net.northking.cctp.dw.db.dao.BugTemplateStatusDao">


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

    <resultMap id="DetailMap" type="net.northking.cctp.dw.dto.BugTemplateStatusDetailDto">
        <!-- 主键 -->
        <id column="id" jdbcType="VARCHAR" property="id"/>
        <!-- 项目id -->
        <result column="project_id" jdbcType="VARCHAR" property="projectId"/>
        <!-- 缺陷状态码 -->
        <result column="bug_status_code" jdbcType="VARCHAR" property="bugStatusCode"/>
        <!-- 缺陷状态名 -->
        <result column="bug_status" jdbcType="VARCHAR" property="bugStatus"/>
        <!--  -->
        <result column="idx" jdbcType="VARCHAR" property="idx"/>
        <!-- 租户id -->
        <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
        <!-- 是否终态：0非终态,1终态-->
        <result column="is_end_status" jdbcType="INTEGER" property="isEndStatus"/>
    </resultMap>

    <select id="pagingQuery" resultMap="DetailMap" parameterType="net.northking.cctp.dw.db.entity.BugTemplateStatus">
        select
        id
        ,project_id
        ,bug_status_code
        ,bug_status
        ,idx
        ,tenant_id
        ,is_end_status
        from
        <include refid="Table_Name"/>
        <trim prefix="WHERE" prefixOverrides="AND">
            <if test="id != null">
                AND id = #{id,jdbcType=VARCHAR}
            </if>
            <if test="projectId != null">
                AND project_id = #{projectId,jdbcType=VARCHAR}
            </if>
            <if test="bugStatusCode != null">
                AND bug_status_code = #{bugStatusCode,jdbcType=VARCHAR}
            </if>
            <if test="bugStatus != null">
                AND bug_status = #{bugStatus,jdbcType=VARCHAR}
            </if>
            <if test="idx != null">
                AND idx = #{idx,jdbcType=VARCHAR}
            </if>
            <if test="tenantId != null">
                AND tenant_id=#{tenantId,jdbcType=VARCHAR}
            </if>
            <if test="isEndStatus != null">
                AND is_end_status=#{isEndStatus,jdbcType=INTEGER}
            </if>
        </trim>
    </select>

    <delete id="deleteByProIdList">
        delete
        from
        <include refid="Table_Name"/>
        where project_id in
        <foreach collection="proIdList" open="(" item="proId" separator="," close=")">
            #{proId}
        </foreach>
    </delete>

    <update id="updateBugStatusByCode">
        update
        <include refid="Table_Name"/>
        set bug_status = #{itemName}
        where bug_status_code = #{itemCode}
        and project_id in
        <foreach collection="proIdList" open="(" item="proId" separator="," close=")">
            #{proId}
        </foreach>
    </update>


</mapper>