<?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 2023 . All rights reserved. -->
<!--  Mybatis数据库持久层（底层映射文件）：计划环境关联表 -->
<!--  version: 1.0  -->
<!--  author:  maven-cctp-plugin    -->
<!--  date:  2023-08-30 10:30:29  -->
<mapper namespace="net.northking.cctp.executePlan.db.dao.AtuPlanEnvLinkDao">
  <resultMap id="BaseResultMap" type="net.northking.cctp.executePlan.db.entity.AtuPlanEnvLink">
      <!-- 主键 -->
    <id column="id" jdbcType="BIGINT" property="id"/>
                  <!-- 计划id -->
    <result column="plan_id" jdbcType="VARCHAR" property="planId"/>
        <!-- 环境id -->
    <result column="env_id" jdbcType="VARCHAR" property="envId"/>
        <!-- 排序值 -->
    <result column="sort" jdbcType="INTEGER" property="sort"/>
    </resultMap>

  <sql id="Base_Column_List">
    id
    ,plan_id
    ,env_id
    ,sort
  </sql>

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

  <select id="findByPrimaryKey" parameterType="Long" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List"/>
    from
    <include refid="Table_Name"/>
    where id = #{id,jdbcType=BIGINT}
  </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=BIGINT}
    </foreach>
  </select>

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

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

  <delete id="deleteByExample" parameterType="net.northking.cctp.executePlan.db.entity.AtuPlanEnvLink">
    delete from
    <include refid="Table_Name"/>
    <trim prefix="WHERE" prefixOverrides="AND" >
      <choose>
        <when test="id != null">
          id = #{id,jdbcType=BIGINT}
        </when>
      </choose>
              <if test="id != null">
          AND id=#{id,jdbcType=BIGINT}
        </if>
              <if test="planId != null">
          AND plan_id=#{planId,jdbcType=VARCHAR}
        </if>
              <if test="envId != null">
          AND env_id=#{envId,jdbcType=VARCHAR}
        </if>
              <if test="sort != null">
          AND sort=#{sort,jdbcType=INTEGER}
        </if>
          </trim>
  </delete>

  <insert id="insert" parameterType="net.northking.cctp.executePlan.db.entity.AtuPlanEnvLink">
    insert into
    <include refid="Table_Name"/>
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="planId != null">
        plan_id,
      </if>
      <if test="envId != null">
        env_id,
      </if>
      <if test="sort != null">
        sort,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
          #{id, jdbcType=BIGINT},
      </if>
      <if test="planId != null">
          #{planId, jdbcType=VARCHAR},
      </if>
      <if test="envId != null">
          #{envId, jdbcType=VARCHAR},
      </if>
      <if test="sort != null">
          #{sort, jdbcType=INTEGER},
      </if>
    </trim>
  </insert>

  <insert id="insertByBatch" parameterType="java.util.List">
    insert into
    <include refid="Table_Name"/>
    <trim prefix="(" suffix=")" suffixOverrides=",">
    plan_id,
    env_id,
    sort,
    </trim>
    values
    <foreach collection="list" item="item" index="index" separator=",">
      <trim prefix="(" suffix=")" suffixOverrides=",">
    #{item.planId, jdbcType=VARCHAR},
    #{item.envId, jdbcType=VARCHAR},
    #{item.sort, jdbcType=INTEGER},
      </trim>
    </foreach>
  </insert>

  <update id="updateByPrimaryKey" parameterType="net.northking.cctp.executePlan.db.entity.AtuPlanEnvLink">
    update
    <include refid="Table_Name"/>
    <set>
      <if test="planId != null">
        plan_id = #{planId, jdbcType=VARCHAR},
      </if>
      <if test="envId != null">
        env_id = #{envId, jdbcType=VARCHAR},
      </if>
      <if test="sort != null">
        sort = #{sort, jdbcType=INTEGER},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>

  <select id="query" resultMap="BaseResultMap" parameterType="net.northking.cctp.executePlan.db.entity.AtuPlanEnvLink">
    select
    <include refid="Base_Column_List" />
    from
    <include refid="Table_Name"/>
    <trim prefix="WHERE" prefixOverrides="AND" >
      <if test="id != null">
        AND id = #{id,jdbcType=BIGINT}
      </if>
      <if test="planId != null">
        AND plan_id = #{planId,jdbcType=VARCHAR}
      </if>
      <if test="envId != null">
        AND env_id = #{envId,jdbcType=VARCHAR}
      </if>
      <if test="sort != null">
        AND sort = #{sort,jdbcType=INTEGER}
      </if>
    </trim>
  </select>

  <select id="queryCount" resultType="java.lang.Long" parameterType="net.northking.cctp.executePlan.db.entity.AtuPlanEnvLink">
    select count(*) from
    <include refid="Table_Name"/>
    <trim prefix="WHERE" prefixOverrides="AND" >
      <if test="id != null">
        AND id=#{id,jdbcType=BIGINT}
      </if>
      <if test="planId != null">
        AND plan_id=#{planId,jdbcType=VARCHAR}
      </if>
      <if test="envId != null">
        AND env_id=#{envId,jdbcType=VARCHAR}
      </if>
      <if test="sort != null">
        AND sort=#{sort,jdbcType=INTEGER}
      </if>
    </trim>
  </select>

</mapper>