<?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-09-04 09:44:18  -->
<mapper namespace="net.northking.cctp.executePlan.db.dao.AtuPlanScriptLinkMdDao">


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

<!--  <resultMap id="DetailMap" type="net.northking.cctp.executePlan.dto.planScript.A">-->
<!--      &lt;!&ndash; 主键 &ndash;&gt;-->
<!--    <id column="id" jdbcType="BIGINT" property="id"/>-->
<!--                    &lt;!&ndash; 编辑人id &ndash;&gt;-->
<!--    <result column="user_id" jdbcType="VARCHAR" property="userId"/>-->
<!--        &lt;!&ndash; 计划id &ndash;&gt;-->
<!--    <result column="plan_id" jdbcType="VARCHAR" property="planId"/>-->
<!--        &lt;!&ndash; 脚本id &ndash;&gt;-->
<!--    <result column="script_id" jdbcType="VARCHAR" property="scriptId"/>-->
<!--        &lt;!&ndash; 脚本类型;0-接口，1-pcbs，2-pccs，3-安卓，4-ios &ndash;&gt;-->
<!--    <result column="script_type" jdbcType="VARCHAR" property="scriptType"/>-->
<!--    </resultMap>-->

  <select id="pagingQuery" resultMap="BaseResultMap" parameterType="net.northking.cctp.executePlan.db.entity.AtuPlanScriptLinkMd">
    select
    id
    ,user_id
    ,plan_id
    ,script_id
    ,script_type
    from
    <include refid="Table_Name"/>
    <trim prefix="WHERE" prefixOverrides="AND" >
      <if test="id != null">
        AND id = #{id,jdbcType=BIGINT}
      </if>
      <if test="userId != null">
        AND user_id = #{userId,jdbcType=VARCHAR}
      </if>
      <if test="planId != null">
        AND plan_id = #{planId,jdbcType=VARCHAR}
      </if>
      <if test="scriptId != null">
        AND script_id = #{scriptId,jdbcType=VARCHAR}
      </if>
      <if test="scriptType != null">
        AND script_type = #{scriptType,jdbcType=VARCHAR}
      </if>
    </trim>
  </select>

  <select id="queryLinkMdPage" resultType="net.northking.cctp.executePlan.dto.planScript.AtuPlanScriptLinkDto">
    select
    id
    ,user_id
    ,plan_id
    ,script_id
    ,script_type
    from
    <include refid="Table_Name"/>
    <trim prefix="WHERE" prefixOverrides="AND">
      <if test="userId != null">
        AND user_id = #{userId,jdbcType=VARCHAR}
      </if>
      <if test="planId != null">
        AND plan_id = #{planId,jdbcType=VARCHAR}
      </if>
      <if test="scriptList != null and scriptList.size() > 0">
        AND script_id IN
        <foreach collection="scriptList" open="(" index="index" item="item" close=")" separator=",">
          #{item,jdbcType=VARCHAR}
        </foreach>
      </if>
    </trim>
    order by id
  </select>

  <delete id="deleteLinkMd" parameterType="net.northking.cctp.executePlan.dto.planScript.AtuPlanScriptDeleteDto">
    delete from
    <include refid="Table_Name"/>
    where
    plan_id = #{planId,jdbcType=VARCHAR}
    and user_id = #{userId,jdbcType=VARCHAR}
    and script_id in
    <foreach collection="scriptList" item="idItem" open="(" separator="," close=")">
      #{idItem, jdbcType=BIGINT}
    </foreach>
  </delete>

  <insert id="insertMdBatch" parameterType="java.util.List">
    insert into
    <include refid="Table_Name"/>
    <trim prefix="(" suffix=")" suffixOverrides=",">
      user_id,
      plan_id,
      script_id,
      script_type,
    </trim>
    values
    <foreach collection="list" item="item" index="index" separator=",">
      <trim prefix="(" suffix=")" suffixOverrides=",">
        #{item.userId, jdbcType=VARCHAR},
        #{item.planId, jdbcType=VARCHAR},
        #{item.scriptId, jdbcType=VARCHAR},
        #{item.scriptType, jdbcType=VARCHAR},
      </trim>
    </foreach>
  </insert>


</mapper>