<?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">
<mapper namespace="io.metersphere.project.mapper.CustomFieldTemplateMapper">
  <resultMap id="BaseResultMap" type="io.metersphere.project.domain.CustomFieldTemplate">
    <id column="id" jdbcType="VARCHAR" property="id" />
    <result column="field_id" jdbcType="VARCHAR" property="fieldId" />
    <result column="template_id" jdbcType="VARCHAR" property="templateId" />
    <result column="scene" jdbcType="VARCHAR" property="scene" />
    <result column="required" jdbcType="BIT" property="required" />
    <result column="pos" jdbcType="INTEGER" property="pos" />
    <result column="custom_data" jdbcType="VARCHAR" property="customData" />
    <result column="key" jdbcType="VARCHAR" property="key" />
  </resultMap>
  <resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="io.metersphere.project.domain.CustomFieldTemplate">
    <result column="default_value" jdbcType="LONGVARBINARY" property="defaultValue" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <where>
      <foreach collection="oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause">
    <where>
      <foreach collection="example.oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List">
    id, field_id, template_id, scene, required, pos, custom_data, `key`
  </sql>
  <sql id="Blob_Column_List">
    default_value
  </sql>
  <select id="selectByExampleWithBLOBs" parameterType="io.metersphere.project.domain.CustomFieldTemplateExample" resultMap="ResultMapWithBLOBs">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    ,
    <include refid="Blob_Column_List" />
    from custom_field_template
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByExample" parameterType="io.metersphere.project.domain.CustomFieldTemplateExample" resultMap="BaseResultMap">
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from custom_field_template
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.String" resultMap="ResultMapWithBLOBs">
    select 
    <include refid="Base_Column_List" />
    ,
    <include refid="Blob_Column_List" />
    from custom_field_template
    where id = #{id,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String">
    delete from custom_field_template
    where id = #{id,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteByExample" parameterType="io.metersphere.project.domain.CustomFieldTemplateExample">
    delete from custom_field_template
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="io.metersphere.project.domain.CustomFieldTemplate">
    insert into custom_field_template (id, field_id, template_id, 
      scene, required, pos, custom_data, 
      `key`, default_value)
    values (#{id,jdbcType=VARCHAR}, #{fieldId,jdbcType=VARCHAR}, #{templateId,jdbcType=VARCHAR}, 
      #{scene,jdbcType=VARCHAR}, #{required,jdbcType=BIT}, #{pos,jdbcType=INTEGER}, #{customData,jdbcType=VARCHAR}, 
      #{key,jdbcType=VARCHAR}, #{defaultValue,jdbcType=LONGVARBINARY})
  </insert>
  <insert id="insertSelective" parameterType="io.metersphere.project.domain.CustomFieldTemplate">
    insert into custom_field_template
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="fieldId != null">
        field_id,
      </if>
      <if test="templateId != null">
        template_id,
      </if>
      <if test="scene != null">
        scene,
      </if>
      <if test="required != null">
        required,
      </if>
      <if test="pos != null">
        pos,
      </if>
      <if test="customData != null">
        custom_data,
      </if>
      <if test="key != null">
        `key`,
      </if>
      <if test="defaultValue != null">
        default_value,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=VARCHAR},
      </if>
      <if test="fieldId != null">
        #{fieldId,jdbcType=VARCHAR},
      </if>
      <if test="templateId != null">
        #{templateId,jdbcType=VARCHAR},
      </if>
      <if test="scene != null">
        #{scene,jdbcType=VARCHAR},
      </if>
      <if test="required != null">
        #{required,jdbcType=BIT},
      </if>
      <if test="pos != null">
        #{pos,jdbcType=INTEGER},
      </if>
      <if test="customData != null">
        #{customData,jdbcType=VARCHAR},
      </if>
      <if test="key != null">
        #{key,jdbcType=VARCHAR},
      </if>
      <if test="defaultValue != null">
        #{defaultValue,jdbcType=LONGVARBINARY},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="io.metersphere.project.domain.CustomFieldTemplateExample" resultType="java.lang.Long">
    select count(*) from custom_field_template
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    update custom_field_template
    <set>
      <if test="record.id != null">
        id = #{record.id,jdbcType=VARCHAR},
      </if>
      <if test="record.fieldId != null">
        field_id = #{record.fieldId,jdbcType=VARCHAR},
      </if>
      <if test="record.templateId != null">
        template_id = #{record.templateId,jdbcType=VARCHAR},
      </if>
      <if test="record.scene != null">
        scene = #{record.scene,jdbcType=VARCHAR},
      </if>
      <if test="record.required != null">
        required = #{record.required,jdbcType=BIT},
      </if>
      <if test="record.pos != null">
        pos = #{record.pos,jdbcType=INTEGER},
      </if>
      <if test="record.customData != null">
        custom_data = #{record.customData,jdbcType=VARCHAR},
      </if>
      <if test="record.key != null">
        `key` = #{record.key,jdbcType=VARCHAR},
      </if>
      <if test="record.defaultValue != null">
        default_value = #{record.defaultValue,jdbcType=LONGVARBINARY},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExampleWithBLOBs" parameterType="map">
    update custom_field_template
    set id = #{record.id,jdbcType=VARCHAR},
      field_id = #{record.fieldId,jdbcType=VARCHAR},
      template_id = #{record.templateId,jdbcType=VARCHAR},
      scene = #{record.scene,jdbcType=VARCHAR},
      required = #{record.required,jdbcType=BIT},
      pos = #{record.pos,jdbcType=INTEGER},
      custom_data = #{record.customData,jdbcType=VARCHAR},
      `key` = #{record.key,jdbcType=VARCHAR},
      default_value = #{record.defaultValue,jdbcType=LONGVARBINARY}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    update custom_field_template
    set id = #{record.id,jdbcType=VARCHAR},
      field_id = #{record.fieldId,jdbcType=VARCHAR},
      template_id = #{record.templateId,jdbcType=VARCHAR},
      scene = #{record.scene,jdbcType=VARCHAR},
      required = #{record.required,jdbcType=BIT},
      pos = #{record.pos,jdbcType=INTEGER},
      custom_data = #{record.customData,jdbcType=VARCHAR},
      `key` = #{record.key,jdbcType=VARCHAR}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="io.metersphere.project.domain.CustomFieldTemplate">
    update custom_field_template
    <set>
      <if test="fieldId != null">
        field_id = #{fieldId,jdbcType=VARCHAR},
      </if>
      <if test="templateId != null">
        template_id = #{templateId,jdbcType=VARCHAR},
      </if>
      <if test="scene != null">
        scene = #{scene,jdbcType=VARCHAR},
      </if>
      <if test="required != null">
        required = #{required,jdbcType=BIT},
      </if>
      <if test="pos != null">
        pos = #{pos,jdbcType=INTEGER},
      </if>
      <if test="customData != null">
        custom_data = #{customData,jdbcType=VARCHAR},
      </if>
      <if test="key != null">
        `key` = #{key,jdbcType=VARCHAR},
      </if>
      <if test="defaultValue != null">
        default_value = #{defaultValue,jdbcType=LONGVARBINARY},
      </if>
    </set>
    where id = #{id,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKeyWithBLOBs" parameterType="io.metersphere.project.domain.CustomFieldTemplate">
    update custom_field_template
    set field_id = #{fieldId,jdbcType=VARCHAR},
      template_id = #{templateId,jdbcType=VARCHAR},
      scene = #{scene,jdbcType=VARCHAR},
      required = #{required,jdbcType=BIT},
      pos = #{pos,jdbcType=INTEGER},
      custom_data = #{customData,jdbcType=VARCHAR},
      `key` = #{key,jdbcType=VARCHAR},
      default_value = #{defaultValue,jdbcType=LONGVARBINARY}
    where id = #{id,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="io.metersphere.project.domain.CustomFieldTemplate">
    update custom_field_template
    set field_id = #{fieldId,jdbcType=VARCHAR},
      template_id = #{templateId,jdbcType=VARCHAR},
      scene = #{scene,jdbcType=VARCHAR},
      required = #{required,jdbcType=BIT},
      pos = #{pos,jdbcType=INTEGER},
      custom_data = #{customData,jdbcType=VARCHAR},
      `key` = #{key,jdbcType=VARCHAR}
    where id = #{id,jdbcType=VARCHAR}
  </update>
</mapper>