<?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-02 16:13:19  -->
<mapper namespace="net.northking.cctp.scriptcase.db.dao.HisUseComponentDao">


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

  <resultMap id="DetailMap" type="net.northking.cctp.scriptcase.dto.component.HisUseComponentDetailDto">
      <!-- 主键 -->
    <id column="id" jdbcType="VARCHAR" property="id"/>
                              <!-- 使用组件id -->
    <result column="com_id" jdbcType="VARCHAR" property="comId"/>
        <!-- 系统空间 -->
    <result column="project_id" jdbcType="VARCHAR" property="projectId"/>
        <!-- 组件类别，0-基础，1-业务 -->
    <result column="com_type" jdbcType="INTEGER" property="comType"/>
        <!-- 顺序 -->
    <result column="order_seq" jdbcType="INTEGER" property="orderSeq"/>
        <!-- 创建人 -->
    <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="tenant_id" jdbcType="VARCHAR" property="tenantId"/>
    </resultMap>

  <select id="pagingQuery" resultMap="DetailMap" parameterType="net.northking.cctp.scriptcase.db.entity.HisUseComponent">
    select
    id
    ,com_id
    ,project_id
    ,com_type
    ,order_seq
    ,created_by
    ,created_time
    ,updated_by
    ,updated_time
    ,tenant_id
    from
    <include refid="Table_Name"/>
    <trim prefix="WHERE" prefixOverrides="AND" >
      <if test="id != null">
        AND id = #{id,jdbcType=VARCHAR}
      </if>
      <if test="comId != null">
        AND com_id = #{comId,jdbcType=VARCHAR}
      </if>
      <if test="projectId != null">
        AND project_id = #{projectId,jdbcType=VARCHAR}
      </if>
      <if test="comType != null">
        AND com_type = #{comType,jdbcType=INTEGER}
      </if>
      <if test="orderSeq != null">
        AND order_seq = #{orderSeq,jdbcType=INTEGER}
      </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="tenantId != null">
        AND tenant_id = #{tenantId,jdbcType=VARCHAR}
      </if>
    </trim>
  </select>

  <select id="reduceOrderSeqByUser" parameterType="net.northking.cctp.scriptcase.db.entity.HisUseComponent">
    update
    <include refid="Table_Name"/>
    <set>
      order_seq = order_seq - 1
    </set>
    where
    tenant_id = #{tenantId,jdbcType=VARCHAR}
    and project_id = #{projectId,jdbcType=VARCHAR}
    AND record_type = #{recordType,jdbcType=INTEGER}
    and created_by = #{createdBy,jdbcType=VARCHAR}
    and order_seq > #{orderSeq,jdbcType=INTEGER}
  </select>

  <select id="addOrderSeqByUser" parameterType="net.northking.cctp.scriptcase.db.entity.HisUseComponent">
    update
    <include refid="Table_Name"/>
    <set>
      order_seq = order_seq + 1
    </set>
    where
    tenant_id = #{tenantId,jdbcType=VARCHAR}
    and project_id = #{projectId,jdbcType=VARCHAR}
    and created_by = #{createdBy,jdbcType=VARCHAR}
    AND record_type = #{recordType,jdbcType=INTEGER}
    <if test="orderSeq != null">
      and order_seq &lt; #{orderSeq,jdbcType=INTEGER}
    </if>
  </select>
</mapper>