<?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:56  -->
<mapper namespace="net.northking.cctp.testbug.db.dao.BugRecordDao">
  <resultMap id="BaseResultMap" type="net.northking.cctp.testbug.db.entity.BugRecord">
      <!-- 记录id -->
    <id column="record_id" jdbcType="VARCHAR" property="recordId"/>
                            <!-- 缺陷id -->
    <result column="bug_id" jdbcType="VARCHAR" property="bugId"/>
        <!-- 变更字段 -->
    <result column="record_field" jdbcType="VARCHAR" property="recordField"/>
        <!-- 变更值 -->
    <result column="record_value" jdbcType="VARCHAR" property="recordValue"/>
        <!-- 变更人 -->
    <result column="updated_by" jdbcType="VARCHAR" property="updatedBy"/>
        <!-- 变更时间 -->
    <result column="updated_time" jdbcType="TIMESTAMP" property="updatedTime"/>
        <!-- 创建人 -->
    <result column="created_by" jdbcType="VARCHAR" property="createdBy"/>
        <!-- 创建时间 -->
    <result column="created_time" jdbcType="TIMESTAMP" property="createdTime"/>
        <!-- 租户id -->
    <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
    </resultMap>

  <sql id="Base_Column_List">
    record_id
    ,bug_id
    ,record_field
    ,record_value
    ,updated_by
    ,updated_time
    ,created_by
    ,created_time
    ,tenant_id
  </sql>

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

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

  <select id="findByPrimaryKeys" parameterType="java.util.List">
    select
    <include refid="Base_Column_List"/>
    from
    <include refid="Table_Name"/>
    where record_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 record_id = #{recordId,jdbcType=VARCHAR}
  </delete>

  <delete id="deleteByPrimaryKeys" parameterType="String">
    delete from
    <include refid="Table_Name"/>
    where record_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.BugRecord">
    delete from
    <include refid="Table_Name"/>
    <trim prefix="WHERE" prefixOverrides="AND" >
      <choose>
        <when test="recordId != null">
          record_id = #{recordId,jdbcType=VARCHAR}
        </when>
      </choose>
              <if test="recordId != null">
          AND record_id=#{recordId,jdbcType=VARCHAR}
        </if>
              <if test="bugId != null">
          AND bug_id=#{bugId,jdbcType=VARCHAR}
        </if>
              <if test="recordField != null">
          AND record_field=#{recordField,jdbcType=VARCHAR}
        </if>
              <if test="recordValue != null">
          AND record_value=#{recordValue,jdbcType=VARCHAR}
        </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="createdBy != null">
          AND created_by=#{createdBy,jdbcType=VARCHAR}
        </if>
              <if test="createdTime != null">
          AND created_time=#{createdTime,jdbcType=TIMESTAMP}
        </if>
              <if test="tenantId != null">
          AND tenant_id=#{tenantId,jdbcType=VARCHAR}
        </if>
          </trim>
  </delete>

  <insert id="insert" parameterType="net.northking.cctp.testbug.db.entity.BugRecord">
    insert into
    <include refid="Table_Name"/>
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="recordId != null">
        record_id,
      </if>
      <if test="bugId != null">
        bug_id,
      </if>
      <if test="recordField != null">
        record_field,
      </if>
      <if test="recordValue != null">
        record_value,
      </if>
      <if test="updatedBy != null">
        updated_by,
      </if>
      <if test="updatedTime != null">
        updated_time,
      </if>
      <if test="createdBy != null">
        created_by,
      </if>
      <if test="createdTime != null">
        created_time,
      </if>
      <if test="tenantId != null">
        tenant_id,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="recordId != null">
          #{recordId, jdbcType=VARCHAR},
      </if>
      <if test="bugId != null">
          #{bugId, jdbcType=VARCHAR},
      </if>
      <if test="recordField != null">
          #{recordField, jdbcType=VARCHAR},
      </if>
      <if test="recordValue != null">
          #{recordValue, jdbcType=VARCHAR},
      </if>
      <if test="updatedBy != null">
          #{updatedBy, jdbcType=VARCHAR},
      </if>
      <if test="updatedTime != null">
          #{updatedTime, jdbcType=TIMESTAMP},
      </if>
      <if test="createdBy != null">
          #{createdBy, jdbcType=VARCHAR},
      </if>
      <if test="createdTime != null">
          #{createdTime, jdbcType=TIMESTAMP},
      </if>
      <if test="tenantId != null">
          #{tenantId, jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>

  <insert id="insertByBatch" parameterType="java.util.List">
    insert into
    <include refid="Table_Name"/>
    <trim prefix="(" suffix=")" suffixOverrides=",">
    record_id,
    bug_id,
    record_field,
    record_value,
    updated_by,
    updated_time,
    created_by,
    created_time,
    tenant_id,
    </trim>
    values
    <foreach collection="list" item="item" index="index" separator=",">
      <trim prefix="(" suffix=")" suffixOverrides=",">
    #{item.recordId, jdbcType=VARCHAR},
    #{item.bugId, jdbcType=VARCHAR},
    #{item.recordField, jdbcType=VARCHAR},
    #{item.recordValue, jdbcType=VARCHAR},
    #{item.updatedBy, jdbcType=VARCHAR},
    #{item.updatedTime, jdbcType=TIMESTAMP},
    #{item.createdBy, jdbcType=VARCHAR},
    #{item.createdTime, jdbcType=TIMESTAMP},
    #{item.tenantId, jdbcType=VARCHAR},
      </trim>
    </foreach>
  </insert>

  <update id="updateByPrimaryKey" parameterType="net.northking.cctp.testbug.db.entity.BugRecord">
    update
    <include refid="Table_Name"/>
    <set>
      <if test="bugId != null">
        bug_id = #{bugId, jdbcType=VARCHAR},
      </if>
      <if test="recordField != null">
        record_field = #{recordField, jdbcType=VARCHAR},
      </if>
      <if test="recordValue != null">
        record_value = #{recordValue, jdbcType=VARCHAR},
      </if>
      <if test="updatedBy != null">
        updated_by = #{updatedBy, jdbcType=VARCHAR},
      </if>
      <if test="updatedTime != null">
        updated_time = #{updatedTime, jdbcType=TIMESTAMP},
      </if>
      <if test="createdBy != null">
        created_by = #{createdBy, jdbcType=VARCHAR},
      </if>
      <if test="createdTime != null">
        created_time = #{createdTime, jdbcType=TIMESTAMP},
      </if>
      <if test="tenantId != null">
        tenant_id = #{tenantId, jdbcType=VARCHAR},
      </if>
    </set>
    where record_id = #{recordId,jdbcType=VARCHAR}
  </update>

  <select id="query" resultMap="BaseResultMap" parameterType="net.northking.cctp.testbug.db.entity.BugRecord">
    select
    <include refid="Base_Column_List" />
    from
    <include refid="Table_Name"/>
    <trim prefix="WHERE" prefixOverrides="AND" >
      <if test="recordId != null">
        AND record_id = #{recordId,jdbcType=VARCHAR}
      </if>
      <if test="bugId != null">
        AND bug_id = #{bugId,jdbcType=VARCHAR}
      </if>
      <if test="recordField != null">
        AND record_field = #{recordField,jdbcType=VARCHAR}
      </if>
      <if test="recordValue != null">
        AND record_value = #{recordValue,jdbcType=VARCHAR}
      </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="createdBy != null">
        AND created_by = #{createdBy,jdbcType=VARCHAR}
      </if>
      <if test="createdTime != null">
        AND created_time = #{createdTime,jdbcType=TIMESTAMP}
      </if>
      <if test="tenantId != null">
        AND tenant_id = #{tenantId,jdbcType=VARCHAR}
      </if>
    </trim>
  </select>

  <select id="queryCount" resultType="java.lang.Long" parameterType="net.northking.cctp.testbug.db.entity.BugRecord">
    select count(*) from
    <include refid="Table_Name"/>
    <trim prefix="WHERE" prefixOverrides="AND" >
      <if test="recordId != null">
        AND record_id=#{recordId,jdbcType=VARCHAR}
      </if>
      <if test="bugId != null">
        AND bug_id=#{bugId,jdbcType=VARCHAR}
      </if>
      <if test="recordField != null">
        AND record_field=#{recordField,jdbcType=VARCHAR}
      </if>
      <if test="recordValue != null">
        AND record_value=#{recordValue,jdbcType=VARCHAR}
      </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="createdBy != null">
        AND created_by=#{createdBy,jdbcType=VARCHAR}
      </if>
      <if test="createdTime != null">
        AND created_time=#{createdTime,jdbcType=TIMESTAMP}
      </if>
      <if test="tenantId != null">
        AND tenant_id=#{tenantId,jdbcType=VARCHAR}
      </if>
    </trim>
  </select>

</mapper>