<?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 2022 . All rights reserved. -->
<!--  Mybatis数据库持久层（业务层映射文件）：脚本版本信息表 -->
<!--  version: 1.0  -->
<!--  author:  maven-cctp-plugin    -->
<!--  date:  2022-10-18 17:29:31  -->
<mapper namespace="net.northking.cctp.scriptcase.db.dao.AtuScriptVersionDao">


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

  <resultMap id="DetailMap" type="net.northking.cctp.scriptcase.dto.atuScript.atuScriptVersion.AtuScriptVersionDetailDto">
        <!-- 脚本版本ID -->
    <id column="version_id" jdbcType="INTEGER" property="versionId"/>
                            <!-- 脚本ID -->
    <result column="script_id" jdbcType="VARCHAR" property="scriptId"/>
            <!-- 版本名称 -->
    <result column="version_name" jdbcType="VARCHAR" property="versionName"/>
        <!-- 脚本名称 -->
    <result column="script_name" jdbcType="VARCHAR" property="scriptName"/>
        <!-- 脚本版本内容地址 -->
    <result column="url" jdbcType="VARCHAR" property="url"/>
        <!-- 脚本版本数据地址 -->
    <result column="data_url" jdbcType="VARCHAR" property="dataUrl"/>
        <!-- 系统ID -->
    <result column="project_id" jdbcType="VARCHAR" property="projectId"/>
        <!-- 租户号 -->
    <result column="tenent_id" jdbcType="VARCHAR" property="tenentId"/>
        <!-- 创建人 -->
    <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"/>
    </resultMap>

  <select id="pagingQuery" resultMap="DetailMap" parameterType="net.northking.cctp.scriptcase.db.entity.AtuScriptVersion">
    select
    script_id
    ,version_id
    ,version_name
    ,script_name
    ,url
    ,data_url
    ,project_id
    ,tenent_id
    ,created_by
    ,created_time
    ,updated_by
    ,updated_time
    from
    <include refid="Table_Name"/>
    <trim prefix="WHERE" prefixOverrides="AND" >
      <if test="scriptId != null">
        AND script_id = #{scriptId,jdbcType=VARCHAR}
      </if>
      <if test="versionId != null">
        AND version_id = #{versionId,jdbcType=INTEGER}
      </if>
      <if test="versionName != null">
        AND version_name = #{versionName,jdbcType=VARCHAR}
      </if>
      <if test="scriptName != null">
        AND script_name = #{scriptName,jdbcType=VARCHAR}
      </if>
      <if test="url != null">
        AND url = #{url,jdbcType=VARCHAR}
      </if>
      <if test="dataUrl != null">
        AND data_url = #{dataUrl,jdbcType=VARCHAR}
      </if>
      <if test="projectId != null">
        AND project_id = #{projectId,jdbcType=VARCHAR}
      </if>
      <if test="tenentId != null">
        AND tenent_id = #{tenentId,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>

  <select id="queryByScriptIdAndVersion" resultMap="BaseResultMap">
    select
    script_id
    ,version_id
    ,version_name
    ,script_name
    ,url
    ,data_url
    from
    <include refid="Table_Name"/>
    where script_id = #{scriptId} and version_name = #{scriptVersion}
  </select>

  <select id="queryCountNum" resultType="net.northking.cctp.scriptcase.dto.atuScript.atuScriptVersion.AtuScriptVersionResultDto">
    SELECT
    script_id,
    count(*) AS countNum
    FROM
    <include refid="Table_Name"/>
    GROUP BY
    script_id
  </select>
</mapper>