<?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-13 14:00:14  -->
<mapper namespace="net.northking.cctp.testbug.db.dao.BugCorrelationLinkDao">


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

  <resultMap id="DetailMap" type="net.northking.cctp.testbug.dto.BugCorrelationLinkDetailDto">
    <!-- 主键 -->
    <id column="id" jdbcType="VARCHAR" property="id"/>
    <!-- 缺陷id -->
    <result column="bug_id" jdbcType="VARCHAR" property="bugId"/>
    <!-- 关联id -->
    <result column="link_id" jdbcType="VARCHAR" property="linkId"/>
    <!-- 关联名 -->
    <result column="link_name" jdbcType="VARCHAR" property="linkName"/>
    <!-- 关联类型：1.案例、2.执行、3.步骤 -->
    <result column="link_type" jdbcType="VARCHAR" property="linkType"/>
    <!-- 创建人 -->
    <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="link_version" jdbcType="VARCHAR" property="linkVersion"/>
    </resultMap>

  <select id="pagingQuery" resultMap="DetailMap" parameterType="net.northking.cctp.testbug.db.entity.BugCorrelationLink">
    select
    id
    ,bug_id
    ,link_id
    ,link_name
    ,link_type
    ,created_by
    ,created_time
    ,updated_by
    ,updated_time
    ,tenant_id
    ,link_version
    from
    <include refid="Table_Name"/>
    <trim prefix="WHERE" prefixOverrides="AND" >
      <if test="id != null">
        AND id = #{id,jdbcType=VARCHAR}
      </if>
      <if test="bugId != null">
        AND bug_id = #{bugId,jdbcType=VARCHAR}
      </if>
      <if test="linkId != null">
        AND link_id = #{linkId,jdbcType=VARCHAR}
      </if>
      <if test="linkName != null">
        AND link_name = #{linkName,jdbcType=VARCHAR}
      </if>
      <if test="linkType != null">
        AND link_type = #{linkType,jdbcType=VARCHAR}
      </if>
      <if test="createdBy != null">
        AND created_by = #{createdBy,jdbcType=VARCHAR}
      </if>
      <if test="createdTime != null">
        AND created_time = #{createdTime,jdbcType=TIMESTAMP}
      </if>
      <if test="updatedBy != null">
        AND updated_by = #{updatedBy,jdbcType=VARCHAR}
      </if>
      <if test="updatedTime != null">
        AND updated_time = #{updatedTime,jdbcType=TIMESTAMP}
      </if>
      <if test="tenantId != null">
        AND tenant_id = #{tenantId,jdbcType=VARCHAR}
      </if>
      <if test="linkVersion != null">
        AND link_version = #{linkVersion,jdbcType=VARCHAR}
      </if>
    </trim>
  </select>

  <select id="findCaseListByBugs" resultType="net.northking.cctp.testbug.db.entity.BugCorrelationLink">
    select
    distinct bug_id
    from
    bug_correlation_link
    where link_type='1'
    AND bug_id in
    <foreach collection="bugList" item="bugId" open="(" separator="," close=")" >
      #{bugId}
    </foreach>
  </select>

  <insert id="pubAdd" parameterType="net.northking.cctp.testbug.db.entity.BugCorrelationLink">
    insert into
    <include refid="Table_Name"/>
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="bugId != null">
        bug_id,
      </if>
      <if test="linkId != null">
        link_id,
      </if>
      <if test="linkName != null">
        link_name,
      </if>
      <if test="linkType != null">
        link_type,
      </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="linkVersion != null">
        link_version,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id, jdbcType=VARCHAR},
      </if>
      <if test="bugId != null">
        #{bugId, jdbcType=VARCHAR},
      </if>
      <if test="linkId != null">
        #{linkId, jdbcType=VARCHAR},
      </if>
      <if test="linkName != null">
        #{linkName, jdbcType=VARCHAR},
      </if>
      <if test="linkType != null">
        #{linkType, 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="linkVersion != null">
        #{linkVersion, jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>

  <delete id="removeByCode" parameterType="String">
    delete from bug_correlation_link where bug_code = #{bugCode,jdbcType=VARCHAR}
  </delete>
</mapper>