<?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-10-06 16:08:57  -->
<mapper namespace="net.northking.cctp.project.db.dao.CpProjectEnvSysDao">


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

  <resultMap id="DetailMap" type="net.northking.cctp.project.dto.env.CpProjectEnvSysDetailDto">
      <!-- 主键 -->
    <id column="id" jdbcType="VARCHAR" property="id"/>
                                  <!-- 租户id -->
    <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
        <!-- 系统id -->
    <result column="project_id" jdbcType="VARCHAR" property="projectId"/>
        <!-- 环境id -->
    <result column="env_id" jdbcType="VARCHAR" property="envId"/>
        <!-- 被测系统地址 -->
    <result column="sys_url" jdbcType="VARCHAR" property="sysUrl"/>
        <!-- 系统名称 -->
    <result column="sys_name" jdbcType="VARCHAR" property="sysName"/>
        <!-- 描述 -->
    <result column="memo" jdbcType="VARCHAR" property="memo"/>
        <!-- 创建人 -->
    <result column="created_by" jdbcType="VARCHAR" property="createdBy"/>
        <!-- 创建时间 -->
    <result column="created_time" jdbcType="TIMESTAMP" property="createdTime"/>
        <!-- 修改人 -->
    <result column="updated_by" jdbcType="VARCHAR" property="updatedBy"/>
        <!-- 修改时间 -->
    <result column="updated_time" jdbcType="TIMESTAMP" property="updatedTime"/>
        <!-- 是否删除 -->
    <result column="is_deleted" jdbcType="TINYINT" property="deleted"/>
    </resultMap>

    <select id="pagingQuery" resultMap="DetailMap" parameterType="net.northking.cctp.project.db.entity.CpProjectEnvSys">
    select
    id
    ,tenant_id
    ,project_id
    ,env_id
    ,sys_url
    ,sys_name
    ,memo
    ,created_by
    ,created_time
    ,updated_by
    ,updated_time
    ,is_deleted
    from
    <include refid="Table_Name"/>
    <trim prefix="WHERE" prefixOverrides="AND" >
      <if test="id != null">
        AND id = #{id,jdbcType=VARCHAR}
      </if>
      <if test="tenantId != null">
        AND tenant_id = #{tenantId,jdbcType=VARCHAR}
      </if>
      <if test="projectId != null">
        AND project_id = #{projectId,jdbcType=VARCHAR}
      </if>
      <if test="envId != null">
        AND env_id = #{envId,jdbcType=VARCHAR}
      </if>
      <if test="sysUrl != null">
        AND sys_url = #{sysUrl,jdbcType=VARCHAR}
      </if>
      <if test="sysName != null">
        AND sys_name = #{sysName,jdbcType=VARCHAR}
      </if>
      <if test="memo != null">
        AND memo = #{memo,jdbcType=VARCHAR}
      </if>
      <if test="createdBy != null">
        AND created_by = #{createdBy,jdbcType=VARCHAR}
      </if>
      <if test="createdTime != null">
        AND created_time = #{createdTime,jdbcType=TIMESTAMP}
      </if>
      <if test="updatedBy != null">
        AND updated_by = #{updatedBy,jdbcType=VARCHAR}
      </if>
      <if test="updatedTime != null">
        AND updated_time = #{updatedTime,jdbcType=TIMESTAMP}
      </if>
      <if test="deleted != null">
        AND is_deleted = #{deleted,jdbcType=TINYINT}
      </if>
    </trim>
  </select>

  <delete id="deleteByProjectIdNoInEnvIds">
    delete from <include refid="Table_Name"/>
    where tenant_id = #{tenantId} and project_id = #{projectId}
    and env_id not in
    <foreach collection="envIds" item="envId" open="(" separator="," close=")">
      #{envId}
    </foreach>
  </delete>
</mapper>