<?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">
  <resultMap id="BaseResultMap" type="net.northking.cctp.dw.db.entity.BugTemplateStatus">
      <!-- 主键 -->
    <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>

  <sql id="Base_Column_List">
    id
    ,project_id
    ,bug_status_code
    ,bug_status
    ,idx
    ,tenant_id
    ,is_end_status
  </sql>

  <sql id="Table_Name">
    ${defaultSchema}.bug_template_status
  </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.dw.db.entity.BugTemplateStatus">
    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="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>
  </delete>

  <insert id="insert" parameterType="net.northking.cctp.dw.db.entity.BugTemplateStatus">
    insert into
    <include refid="Table_Name"/>
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="projectId != null">
        project_id,
      </if>
      <if test="bugStatusCode != null">
        bug_status_code,
      </if>
      <if test="bugStatus != null">
        bug_status,
      </if>
      <if test="idx != null">
        idx,
      </if>
      <if test="tenantId != null">
        tenant_id,
      </if>
      <if test="isEndStatus != null">
        is_end_status,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
          #{id, jdbcType=VARCHAR},
      </if>
      <if test="projectId != null">
          #{projectId, jdbcType=VARCHAR},
      </if>
      <if test="bugStatusCode != null">
          #{bugStatusCode, jdbcType=VARCHAR},
      </if>
      <if test="bugStatus != null">
          #{bugStatus, jdbcType=VARCHAR},
      </if>
      <if test="idx != null">
          #{idx, jdbcType=VARCHAR},
      </if>
      <if test="tenantId != null">
        #{tenantId,jdbcType=VARCHAR}
      </if>
      <if test="isEndStatus != null">
        #{isEndStatus,jdbcType=INTEGER}
      </if>
    </trim>
  </insert>

  <insert id="insertByBatch" parameterType="java.util.List">
    insert into
    <include refid="Table_Name"/>
    <trim prefix="(" suffix=")" suffixOverrides=",">
    id,
    project_id,
    bug_status_code,
    bug_status,
    idx,
    tenant_id,
    is_end_status,
    </trim>
    values
    <foreach collection="list" item="item" index="index" separator=",">
      <trim prefix="(" suffix=")" suffixOverrides=",">
    #{item.id, jdbcType=VARCHAR},
    #{item.projectId, jdbcType=VARCHAR},
    #{item.bugStatusCode, jdbcType=VARCHAR},
    #{item.bugStatus, jdbcType=VARCHAR},
    #{item.idx, jdbcType=VARCHAR},
    #{item.tenantId,jdbcType=VARCHAR},
    #{item.isEndStatus,jdbcType=INTEGER},
      </trim>
    </foreach>
  </insert>

  <update id="updateByPrimaryKey" parameterType="net.northking.cctp.dw.db.entity.BugTemplateStatus">
    update
    <include refid="Table_Name"/>
    <set>
      <if test="projectId != null">
        project_id = #{projectId, jdbcType=VARCHAR},
      </if>
      <if test="bugStatusCode != null">
        bug_status_code = #{bugStatusCode, jdbcType=VARCHAR},
      </if>
      <if test="bugStatus != null">
        bug_status = #{bugStatus, jdbcType=VARCHAR},
      </if>
      <if test="idx != null">
        idx = #{idx, jdbcType=VARCHAR},
      </if>
      <if test="tenantId != null">
        tenant_id=#{tenantId,jdbcType=VARCHAR},
      </if>
      <if test="isEndStatus != null">
        is_end_status=#{isEndStatus,jdbcType=INTEGER},
      </if>
    </set>
    where id = #{id,jdbcType=VARCHAR}
  </update>

  <select id="query" resultMap="BaseResultMap" parameterType="net.northking.cctp.dw.db.entity.BugTemplateStatus">
    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="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>

  <select id="queryCount" resultType="java.lang.Long" parameterType="net.northking.cctp.dw.db.entity.BugTemplateStatus">
    select count(*) 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>

</mapper>