<?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-11-15 18:07:55  -->
<mapper namespace="net.northking.cctp.testbug.db.dao.BugCorrelationLinkDao">
  <resultMap id="BaseResultMap" type="net.northking.cctp.testbug.db.entity.BugCorrelationLink">
      <!-- 主键 -->
    <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"/>

    <result column="bug_code" jdbcType="VARCHAR" property="bugCode" />
    <result column="plan_id" jdbcType="VARCHAR" property="planId" />
    <result column="case_id" jdbcType="VARCHAR" property="caseId" />
    </resultMap>

  <sql id="Base_Column_List">
    id
    ,bug_id
    ,link_id
    ,link_name
    ,link_type
    ,created_by
    ,created_time
    ,updated_by
    ,updated_time
    ,tenant_id
    ,link_version
    ,bug_code
    ,plan_id
    ,case_id
  </sql>

  <sql id="Table_Name">
    ${defaultSchema}.bug_correlation_link
  </sql>

  <select id="findByPrimaryKey" parameterType="String" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List"/>
    from
    <include refid="Table_Name"/>
    where id = #{id,jdbcType=VARCHAR}
  </select>

  <select id="findByPrimaryKeys" parameterType="java.util.List">
    select
    <include refid="Base_Column_List"/>
    from
    <include refid="Table_Name"/>
    where id in
    <foreach collection="list" item="idItem" open="(" separator="," close=")">
      #{idItem, jdbcType=VARCHAR}
    </foreach>
  </select>

  <delete id="deleteByPrimaryKey" parameterType="String">
    delete from
    <include refid="Table_Name"/>
    where id = #{id,jdbcType=VARCHAR}
  </delete>

  <delete id="deleteByPrimaryKeys" parameterType="String">
    delete from
    <include refid="Table_Name"/>
    where id in
    <foreach collection="list" item="idItem" open="(" separator="," close=")">
      #{idItem, jdbcType=VARCHAR}
    </foreach>
  </delete>

  <delete id="deleteByExample" parameterType="net.northking.cctp.testbug.db.entity.BugCorrelationLink">
    delete from
    <include refid="Table_Name"/>
    <trim prefix="WHERE" prefixOverrides="AND" >
      <choose>
        <when test="id != null">
          id = #{id,jdbcType=VARCHAR}
        </when>
      </choose>
              <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>
  </delete>

  <insert id="insert" 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>
      <if test="bugCode != null">
        bug_code,
      </if>
      <if test="planId != null">
        plan_id,
      </if>
      <if test="caseId != null">
        case_id,
      </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>
      <if test="bugCode != null">
        #{bugCode, jdbcType=VARCHAR},
      </if>
      <if test="planId != null">
        #{planId, jdbcType=VARCHAR},
      </if>
      <if test="caseId != null">
        #{caseId, jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>

  <insert id="insertByBatch" parameterType="java.util.List">
    insert into
    <include refid="Table_Name"/>
    <trim prefix="(" suffix=")" suffixOverrides=",">
    id,
    bug_id,
    link_id,
    link_name,
    link_type,
    created_by,
    created_time,
    updated_by,
    updated_time,
    tenant_id,
      link_version,
    </trim>
    values
    <foreach collection="list" item="item" index="index" separator=",">
      <trim prefix="(" suffix=")" suffixOverrides=",">
    #{item.id, jdbcType=VARCHAR},
    #{item.bugId, jdbcType=VARCHAR},
    #{item.linkId, jdbcType=VARCHAR},
    #{item.linkName, jdbcType=VARCHAR},
    #{item.linkType, jdbcType=VARCHAR},
    #{item.createdBy, jdbcType=VARCHAR},
    #{item.createdTime, jdbcType=TIMESTAMP},
    #{item.updatedBy, jdbcType=VARCHAR},
    #{item.updatedTime, jdbcType=TIMESTAMP},
    #{item.tenantId, jdbcType=VARCHAR},
        #{item.linkVersion, jdbcType=VARCHAR},
      </trim>
    </foreach>
  </insert>

  <update id="updateByPrimaryKey" parameterType="net.northking.cctp.testbug.db.entity.BugCorrelationLink">
    update
    <include refid="Table_Name"/>
    <set>
      <if test="bugId != null">
        bug_id = #{bugId, jdbcType=VARCHAR},
      </if>
      <if test="linkId != null">
        link_id = #{linkId, jdbcType=VARCHAR},
      </if>
      <if test="linkName != null">
        link_name = #{linkName, jdbcType=VARCHAR},
      </if>
      <if test="linkType != null">
        link_type = #{linkType, jdbcType=VARCHAR},
      </if>
      <if test="createdBy != null">
        created_by = #{createdBy, jdbcType=VARCHAR},
      </if>
      <if test="createdTime != null">
        created_time = #{createdTime, jdbcType=TIMESTAMP},
      </if>
      <if test="updatedBy != null">
        updated_by = #{updatedBy, jdbcType=VARCHAR},
      </if>
      <if test="updatedTime != null">
        updated_time = #{updatedTime, jdbcType=TIMESTAMP},
      </if>
      <if test="tenantId != null">
        tenant_id = #{tenantId, jdbcType=VARCHAR},
      </if>
      <if test="linkVersion != null">
        link_version = #{linkVersion, jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=VARCHAR}
  </update>

  <select id="query" resultMap="BaseResultMap" parameterType="net.northking.cctp.testbug.db.entity.BugCorrelationLink">
    select
    <include refid="Base_Column_List" />
    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="queryCount" resultType="java.lang.Long" parameterType="net.northking.cctp.testbug.db.entity.BugCorrelationLink">
    select count(*) 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>

</mapper>