<?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-29 11:40:19  -->
<mapper namespace="net.northking.cctp.scriptcase.db.dao.AtuGlobalVariableDao">


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

  <resultMap id="DetailMap" type="net.northking.cctp.scriptcase.dto.atuscriptrecord.AtuGlobalVariableDetailDto">
      <!--  -->
    <id column="id" jdbcType="VARCHAR" property="id"/>
                                      <!-- 变量名称 -->
    <result column="name" jdbcType="VARCHAR" property="name"/>
        <!-- 数据类型 -->
    <result column="data_type" jdbcType="VARCHAR" property="dataType"/>
        <!-- 默认值 -->
    <result column="default_value" jdbcType="VARCHAR" property="defaultValue"/>
        <!-- 描述 -->
    <result column="memo" jdbcType="VARCHAR" property="memo"/>
        <!-- 是否被删除：0-未删除、1-已删除 -->
    <result column="is_delete" jdbcType="BIT" property="delete"/>
        <!-- 变量类型：0-全局变量、1-脚本变量 -->
    <result column="variable_type" jdbcType="BIT" property="variableType"/>
        <!-- 脚本变量时必填、全局变量时为空 -->
    <result column="script_id" jdbcType="VARCHAR" property="scriptId"/>
        <!-- 租户id -->
    <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
        <!-- 系统id -->
    <result column="project_id" jdbcType="VARCHAR" property="projectId"/>
        <!-- 更新人 -->
    <result column="updated_by" jdbcType="VARCHAR" property="updatedBy"/>
        <!-- 更新时间 -->
    <result column="updated_time" jdbcType="TIMESTAMP" property="updatedTime"/>
        <!-- 创建人 -->
    <result column="created_by" jdbcType="VARCHAR" property="createdBy"/>
        <!-- 创建时间 -->
    <result column="created_time" jdbcType="TIMESTAMP" property="createdTime"/>
    <result column="desc" jdbcType="VARCHAR" property="desc"/>
    <!-- 创建时间 -->
    <result column="type" jdbcType="VARCHAR" property="type"/>
    </resultMap>

  <select id="pagingQuery" resultMap="DetailMap" parameterType="net.northking.cctp.scriptcase.db.entity.AtuGlobalVariable">
    select
    id
    ,name
    ,data_type type
    ,default_value
    ,memo `desc`
    ,is_delete
    ,variable_type
    ,script_id
    ,tenant_id
    ,project_id
    ,updated_by
    ,updated_time
    ,created_by
    ,created_time
    from
    <include refid="Table_Name"/>
    <trim prefix="WHERE" prefixOverrides="AND" >
      <if test="id != null">
        AND id = #{id,jdbcType=VARCHAR}
      </if>
      <if test="name != null">
        AND name = #{name,jdbcType=VARCHAR}
      </if>
      <if test="dataType != null">
        AND data_type = #{dataType,jdbcType=VARCHAR}
      </if>
      <if test="defaultValue != null">
        AND default_value = #{defaultValue,jdbcType=VARCHAR}
      </if>
      <if test="memo != null">
        AND memo = #{memo,jdbcType=VARCHAR}
      </if>
      <if test="delete != null">
        AND is_delete = #{delete,jdbcType=BIT}
      </if>
      <if test="variableType != null">
        AND variable_type = #{variableType,jdbcType=BIT}
      </if>
      <if test="scriptId != null">
        AND script_id = #{scriptId,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="updatedBy != null">
        AND updated_by = #{updatedBy,jdbcType=VARCHAR}
      </if>
      <if test="updatedTime != null">
        AND updated_time = #{updatedTime,jdbcType=TIMESTAMP}
      </if>
      <if test="createdBy != null">
        AND created_by = #{createdBy,jdbcType=VARCHAR}
      </if>
      <if test="createdTime != null">
        AND created_time = #{createdTime,jdbcType=TIMESTAMP}
      </if>
      and is_delete=0
    </trim>
  </select>

  <select id="queryVariable" parameterType="net.northking.cctp.scriptcase.db.entity.AtuGlobalVariable"
          resultType="net.northking.cctp.scriptcase.db.entity.AtuGlobalVariable">
    SELECT
    <include refid="Base_Column_List" />
    FROM
    <include refid="Table_Name" />
    WHERE 1=1
    <if test="name!=null">
      and `name` = #{name,jdbcType=VARCHAR}
    </if>
    <if test="projectId!=null">
      AND `project_id` = #{projectId,jdbcType=VARCHAR}
    </if>
    <if test="delete!=null">
      AND `is_delete` = #{delete,jdbcType=BIT}
    </if>
    <if test="variableType!=null">
      AND variable_type = #{variableType,jdbcType=BIT}
    </if>
    <if test="scriptId != null">
      AND script_id = #{scriptId,jdbcType=VARCHAR}
    </if>
    ORDER BY updated_time ASC LIMIT 1
  </select>
  
  <update id="updateGlobalValue" parameterType="net.northking.cctp.scriptcase.db.entity.AtuGlobalVariable">
    UPDATE
    <include refid="Table_Name" />
    SET
    default_value = #{defaultValue,jdbcType=VARCHAR}
    WHERE
    `name` = #{name,jdbcType=VARCHAR}
    AND `project_id` = #{projectId,jdbcType=VARCHAR}
    AND `is_delete` = #{delete,jdbcType=BIT}
    AND variable_type = #{variableType,jdbcType=BIT}
  </update>
</mapper>