<?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="net.northking.cctp.project.db.dao.CpProjectEnvDsDao">

  <resultMap id="DetailMap" type="net.northking.cctp.project.dto.env.CpProjectEnvDsDetailDto">
    <!-- 主键 -->
    <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"/>
    <!-- 数据源类型 0-MongoDB，1-mysql，2-Oracle，3-达梦，4-OceanBase，5-db2 -->
    <result column="ds_type" jdbcType="TINYINT" property="dsType"/>
    <!-- 连接名称 -->
    <result column="conn_name" jdbcType="VARCHAR" property="connName"/>
    <!-- 主机 -->
    <result column="conn_host" jdbcType="VARCHAR" property="connHost"/>
    <!-- 端口 -->
    <result column="conn_port" jdbcType="INTEGER" property="connPort"/>
    <!-- 数据库 -->
    <result column="conn_database" jdbcType="VARCHAR" property="connDatabase"/>
    <!-- 用户名 -->
    <result column="conn_username" jdbcType="VARCHAR" property="connUsername"/>
    <!-- 密码 -->
    <result column="conn_password" jdbcType="VARCHAR" property="connPassword"/>
    <!-- 高级属性 -->
    <result column="advanced_config" jdbcType="VARCHAR" property="advancedConfig"/>
    <!-- 描述 -->
    <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>
  <!-- 请在本文件内添加自定义SQL语句 -->

  <select id="pagingQuery" resultMap="DetailMap" parameterType="net.northking.cctp.project.dto.env.CpProjectEnvDsQueryDto">
    select
    id
    ,tenant_id
    ,project_id
    ,env_id
    ,ds_type
    ,conn_name
    ,conn_host
    ,conn_port
    ,conn_database
    ,conn_username
    ,conn_password
    ,advanced_config
    ,memo
    ,created_by
    ,created_time
    ,updated_by
    ,updated_time
    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="dsType != null">
        AND ds_type = #{dsType,jdbcType=TINYINT}
      </if>
      <if test="connName != null">
        AND conn_name = #{connName,jdbcType=VARCHAR}
      </if>
      <if test="connHost != null">
        AND conn_host = #{connHost,jdbcType=VARCHAR}
      </if>
      <if test="connPort != null">
        AND conn_port = #{connPort,jdbcType=INTEGER}
      </if>
      <if test="connDatabase != null">
        AND conn_database = #{connDatabase,jdbcType=VARCHAR}
      </if>
      <if test="connUsername != null">
        AND conn_username = #{connUsername,jdbcType=VARCHAR}
      </if>
      <if test="connPassword != null">
        AND conn_password = #{connPassword,jdbcType=VARCHAR}
      </if>
      <if test="advancedConfig != null">
        AND advanced_config = #{advancedConfig,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>
    </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>

  <select id="queryEnvDsByDto" resultMap="BaseResultMap" parameterType="net.northking.cctp.project.db.entity.CpProjectEnvDs">
    select
    <include refid="Base_Column_List" />
    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="dsType != null">
        AND ds_type = #{dsType,jdbcType=TINYINT}
      </if>
      <if test="connName != null">
        AND conn_name = #{connName,jdbcType=VARCHAR}
      </if>
      <if test="connHost != null">
        AND conn_host = #{connHost,jdbcType=VARCHAR}
      </if>
      <if test="connPort != null">
        AND conn_port = #{connPort,jdbcType=INTEGER}
      </if>
      <if test="connDatabase != null">
        AND conn_database = #{connDatabase,jdbcType=VARCHAR}
      </if>
      <if test="connUsername != null">
        AND conn_username = #{connUsername,jdbcType=VARCHAR}
      </if>
      <if test="connPassword != null">
        AND conn_password = #{connPassword,jdbcType=VARCHAR}
      </if>
      <if test="advancedConfig != null">
        AND advanced_config = #{advancedConfig,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>
    order by created_time desc
  </select>
</mapper>