<?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-24 16:58:38  -->
<mapper namespace="net.northking.cctp.dataPool.db.dao.DataRuleDao">


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

  <resultMap id="DetailMap" type="net.northking.cctp.dataPool.dto.dataRule.DataRuleDetailDto">
      <!-- 规则id -->
    <id column="rule_id" jdbcType="VARCHAR" property="ruleId"/>
                                <!-- 规则名称 -->
    <result column="name" jdbcType="VARCHAR" property="name"/>
        <!-- 规则类型 -->
    <result column="type" jdbcType="VARCHAR" property="type"/>
        <!-- 正则表达式、脚本编码 -->
    <result column="content_expression" jdbcType="LONGVARCHAR" property="contentExpression"/>
        <!-- 资源包集合 -->
    <result column="jar_ids" jdbcType="VARCHAR" property="jarIds"/>
        <!-- 系统id -->
    <result column="pro_id" jdbcType="VARCHAR" property="proId"/>
        <!-- 租户id -->
    <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.dataPool.db.entity.DataRule">
    select
    rule_id
    ,name
    ,type
    ,content_expression
    ,jar_ids
    ,pro_id
    ,tenant_id
    ,created_by
    ,created_time
    ,updated_by
    ,updated_time
    from
    <include refid="Table_Name"/>
    <trim prefix="WHERE" prefixOverrides="AND" >
      <if test="ruleId != null">
        AND rule_id = #{ruleId,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="contentExpression != null">
        AND content_expression = #{contentExpression,jdbcType=LONGVARCHAR}
      </if>
      <if test="jarIds != null">
        AND jar_ids = #{jarIds,jdbcType=VARCHAR}
      </if>
      <if test="proId != null">
        AND pro_id = #{proId,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="queryRuleByName" parameterType="net.northking.cctp.dataPool.dto.dataRule.DataRuleUpdateDto" resultType="integer">
    select count(0) from
    <include refid="Table_Name"/>
    <trim prefix="WHERE" prefixOverrides="AND" >
      <if test="ruleId != null">
        AND rule_id &lt;&gt; #{ruleId,jdbcType=VARCHAR}
      </if>
      <if test="name != null">
        AND name = #{name,jdbcType=VARCHAR}
      </if>
      <if test="proId != null">
        AND pro_id = #{proId,jdbcType=VARCHAR}
      </if>
    </trim>
  </select>
  <select id="getDataRules" resultMap="DetailMap" parameterType="net.northking.cctp.common.http.QueryByPage">
    select
    <include refid="Base_Column_List"/>
    from
    <include refid="Table_Name"/>
    <trim prefix="WHERE" prefixOverrides="AND" >
      <if test="query.name != null and query.name != ''">
        AND LOCATE(#{query.name,jdbcType=VARCHAR},name) &gt; 0
      </if>
      <if test="query.type != null and query.type != ''">
        AND type = #{query.type,jdbcType=VARCHAR}
      </if>
      <if test="query.tenantId != null and query.tenantId != ''">
        AND tenant_id = #{query.tenantId,jdbcType=VARCHAR}
      </if>
      <if test="query.proIds != null and query.proIds.size > 0">
        AND pro_id IN
        <foreach collection="query.proIds" open="(" index="index" item="item" close=")" separator=",">
          #{item,jdbcType=VARCHAR}
        </foreach>
      </if>
      <if test="query.creatorIds != null and query.creatorIds.size > 0">
        AND created_by IN
        <foreach collection="query.creatorIds" open="(" index="index" item="item" close=")" separator=",">
          #{item,jdbcType=VARCHAR}
        </foreach>
      </if>
    </trim>
    order by created_time desc
  </select>

  <select id="queryByIdSet" resultMap="DetailMap">
    select
    <include refid="Base_Column_List"/>
    from
    <include refid="Table_Name"/>
    where rule_id in
    <foreach collection="idSet" item="id" open="(" separator="," close=")">
      #{id}
    </foreach>
  </select>
</mapper>