<?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.BugRecordDao">


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

  <resultMap id="DetailMap" type="net.northking.cctp.testbug.dto.BugRecordDetailDto">
    <!-- 记录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>

  <select id="pagingQuery" resultMap="DetailMap" parameterType="net.northking.cctp.testbug.db.entity.BugRecord">
    select
    RECORD_ID
    ,BUG_ID
    ,RECORD_FIELD
    ,RECORD_VALUE
    ,UPDATED_BY
    ,UPDATED_TIME
    ,CREATED_BY
    ,CREATED_TIME
    ,TENANT_ID
    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="queryByBugIds" resultType="net.northking.cctp.testbug.dto.BugRecordDetailDto">
    select *
      from <include refid="Table_Name"/>
      where BUG_ID in
      <foreach collection="bugIds" item="bugId" open="(" close=")" separator="," index="i">
        #{bugId,jdbcType=VARCHAR}
      </foreach>
      ORDER by created_time desc
  </select>

  <insert id="pubAdd" 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>
</mapper>