<?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-31 16:48:02  -->
<mapper namespace="net.northking.cctp.executePlan.db.dao.AtuPlanScriptLinkDao">


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

  <resultMap id="DetailMap" type="net.northking.cctp.executePlan.dto.planLink.AtuPlanScriptLinkDetailDto">
      <!-- 主键 -->
    <id column="id" jdbcType="BIGINT" property="id"/>
                  <!-- 计划id -->
    <result column="plan_id" jdbcType="VARCHAR" property="planId"/>
        <!-- 脚本id -->
    <result column="script_id" jdbcType="VARCHAR" property="scriptId"/>
        <!-- 脚本类型;0-接口，1-pcbs，2-pccs，3-安卓，4-ios -->
    <result column="script_type" jdbcType="VARCHAR" property="scriptType"/>
    </resultMap>

  <select id="pagingQuery" resultMap="DetailMap" parameterType="net.northking.cctp.executePlan.db.entity.AtuPlanScriptLink">
    select
    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="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="countByScriptIdList" resultType="java.lang.Long">
      select count(1) from <include refid="Table_Name"/> l
      left join atu_plan_info i on i.id = l.plan_id
      where i.is_deleted = 0
      and script_id in
      <foreach collection="scriptIdList" item="scriptId" open="(" separator="," close=")">
        #{scriptId}
      </foreach>
    </select>

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


</mapper>