<?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-11-04 09:57:41  -->
<mapper namespace="net.northking.cctp.scriptcase.db.dao.AtuElementInfoDao">


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

  <resultMap id="DetailMap" type="net.northking.cctp.scriptcase.dto.elementLibrary.AtuElementInfoDetailDto">
      <!-- 元素ID -->
    <id column="id" jdbcType="VARCHAR" property="id"/>
                                        <!-- 元素分组ID -->
    <result column="group_id" jdbcType="VARCHAR" property="groupId"/>
        <!-- 元素名称 -->
    <result column="name" jdbcType="VARCHAR" property="name"/>
        <!-- 元素类型 -->
    <result column="type" jdbcType="VARCHAR" property="type"/>
        <!-- 元素获取方式 -->
    <result column="fetch_type" jdbcType="VARCHAR" property="fetchType"/>
        <!-- 元素属性表达式 -->
    <result column="fetch_value" jdbcType="VARCHAR" property="fetchValue"/>
        <!-- 元素备选获取方式 -->
    <result column="second_ftype" jdbcType="VARCHAR" property="secondFtype"/>
        <!-- 元素备选属性表达式 -->
    <result column="second_fvalue" jdbcType="VARCHAR" property="secondFvalue"/>
        <!-- 是否删除 -->
    <result column="is_deleted" jdbcType="VARCHAR" property="isDeleted"/>
        <!-- 系统ID -->
    <result column="project_id" jdbcType="VARCHAR" property="projectId"/>
        <!-- 租户号 -->
    <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
        <!-- 创建人 -->
    <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.AtuElementInfo">
    select
    id
    ,group_id
    ,name
    ,type
    ,fetch_type
    ,fetch_value
    ,second_ftype
    ,second_fvalue
    ,is_deleted
    ,project_id
    ,tenant_id
    ,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="groupId != null">
        AND group_id = #{groupId,jdbcType=VARCHAR}
      </if>
      <if test="name != null">
        AND name = #{name,jdbcType=VARCHAR}
      </if>
      <if test="type != null">
        AND type = #{type,jdbcType=VARCHAR}
      </if>
      <if test="fetchType != null">
        AND fetch_type = #{fetchType,jdbcType=VARCHAR}
      </if>
      <if test="fetchValue != null">
        AND fetch_value = #{fetchValue,jdbcType=VARCHAR}
      </if>
      <if test="secondFtype != null">
        AND second_ftype = #{secondFtype,jdbcType=VARCHAR}
      </if>
      <if test="secondFvalue != null">
        AND second_fvalue = #{secondFvalue,jdbcType=VARCHAR}
      </if>
      <if test="isDeleted != null">
        AND is_deleted = #{isDeleted,jdbcType=VARCHAR}
      </if>
      <if test="projectId != null">
        AND project_id = #{projectId,jdbcType=VARCHAR}
      </if>
      <if test="tenantId != null">
        AND tenant_id = #{tenantId,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="queryByIds" resultType="net.northking.cctp.scriptcase.db.entity.AtuElementInfo" parameterType="list">
    select
    <include refid="Base_Column_List"/>
    from
    <include refid="Table_Name"/>
    where is_deleted = '0'
    <if test="ids != null and ids.size() > 0">
      and id in
      <foreach collection="ids" open="(" item="item" index="index" separator="," close=")">
        #{item,jdbcType=VARCHAR}
      </foreach>
    </if>
  </select>
  <select id="queryElementList" resultMap="DetailMap" parameterType="net.northking.cctp.scriptcase.dto.elementLibrary.AtuElementInfoQueryDto">
    select
    <include refid="Base_Column_List"/>
    from
    <include refid="Table_Name"/>
    where is_deleted = '0'
    <if test="query.groupId != null">
      AND group_id = #{query.groupId,jdbcType=VARCHAR}
    </if>
    <if test="query.name != null">
      AND LOCATE(#{query.name,jdbcType=VARCHAR},name) &gt; 0
    </if>
    <if test="query.type != null">
      AND type = #{query.type,jdbcType=VARCHAR}
    </if>
    <if test="query.fetchType != null">
      AND second_ftype = #{query.fetchType,jdbcType=VARCHAR}
    </if>
    <if test="query.proIds != null and query.proIds.size() > 0">
      AND project_id in
      <foreach collection="query.proIds" open="(" index="index" item="item" separator="," close=")">
        #{item,jdbcType=VARCHAR}
      </foreach>
    </if>
    <if test="query.groupIds != null and query.groupIds.size() > 0">
      AND group_id IN
      <foreach collection="query.groupIds" open="(" index="index" item="item" close=")" separator=",">
        #{item,jdbcType=VARCHAR}
      </foreach>
    </if>
    <if test="query.tenantId != null">
      AND tenant_id = #{query.tenantId,jdbcType=VARCHAR}
    </if>
    <if test="query.updatedBys != null and query.updatedBys.size > 0">
      AND updated_by IN
      <foreach collection="query.updatedBys" open="(" index="index" item="item" close=")" separator=",">
        #{item,jdbcType=VARCHAR}
      </foreach>
    </if>

    <if test="query.updateBy != null and query.updateBy != ''">
      AND updated_by =#{query.updateBy}
    </if>

    <if test="query.createBys != null and query.createBys.size > 0">
      AND created_by IN
      <foreach collection="query.createBys" open="(" index="index" item="item" close=")" separator=",">
        #{item,jdbcType=VARCHAR}
      </foreach>
    </if>

    <if test="query.creatorId != null and query.creatorId != ''">
      AND created_by =#{query.creatorId}
    </if>

    <if test="query.startCreatedTime!=null">
      and created_time <![CDATA[>=]]> #{query.startCreatedTime}
    </if>
    <if test="query.endCreatedTime!=null">
      and created_time <![CDATA[<=]]> #{query.endCreatedTime}
    </if>
    <if test="query.startUpdatedTime!=null">
      and updated_time <![CDATA[>=]]> #{query.startUpdatedTime}
    </if>
    <if test="query.endUpdatedTime!=null">
      and updated_time <![CDATA[<=]]> #{query.endUpdatedTime}
    </if>
    order by created_time desc
  </select>

    <select id="selectCreatorByProject" resultType="java.lang.String">
      SELECT created_by FROM atu_element_info
      WHERE is_deleted = 0 AND project_id =  #{projectId}
      GROUP BY created_by
    </select>
    <select id="selectUpdaterByProject" resultType="java.lang.String">
      SELECT updated_by FROM atu_element_info
      WHERE is_deleted = 0 AND project_id =  #{projectId}
      GROUP BY updated_by
    </select>
  <select id="findByName" resultType="net.northking.cctp.scriptcase.db.entity.AtuElementInfo">
    select
    <include refid="Base_Column_List"/>
    from
    <include refid="Table_Name"/>
    where is_deleted = '0'
    and name = #{name}
    and project_id = #{projectId}
  </select>
  <select id="findByNameButNotSelf" resultType="net.northking.cctp.scriptcase.db.entity.AtuElementInfo">
    select
    <include refid="Base_Column_List"/>
    from
    <include refid="Table_Name"/>
    where is_deleted = '0'
    and id != #{id}
    and name = #{name}
    and project_id = #{projectId}
  </select>
  <update id="deleteElementBatch" parameterType="net.northking.cctp.scriptcase.db.entity.AtuElementInfo">
    update
    <include refid="Table_Name"/>
    <set>
      is_deleted = '1'
      <if test="element.updatedBy != null and element.updatedBy != ''">
        , updated_by = #{element.updatedBy}
      </if>
      <if test="element.updatedTime != null">
        , updated_time = #{element.updatedTime, jdbcType=TIMESTAMP}
      </if>
    </set>
    where id IN
    <foreach collection="ids" open="(" index="index" item="item" close=")" separator=",">
      #{item,jdbcType=VARCHAR}
    </foreach>
  </update>
</mapper>