<?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">
<mapper namespace="com.common.mapper.AnalysisFilterMapper">

    <resultMap id="BaseResultMap" type="com.common.entity.AnalysisFilter">
        <id column="id" property="id" jdbcType="INTEGER"/>
        <result column="rule_id" property="ruleId" jdbcType="VARCHAR"/>
        <result column="data_source" property="dataSource" jdbcType="VARCHAR"/>
        <result column="database" property="database" jdbcType="VARCHAR"/>
        <result column="table_name" property="tableName" jdbcType="VARCHAR"/>
        <result column="table_alias" property="tableAlias" jdbcType="VARCHAR"/>
        <result column="column_name" property="columnName" jdbcType="VARCHAR"/>
        <result column="column_desc" property="columnDesc" jdbcType="VARCHAR"/>
        <result column="data_type" property="dataType" jdbcType="VARCHAR"/>
        <result column="fn" property="fn" jdbcType="VARCHAR"/>
        <result column="arguments" property="arguments" jdbcType="VARCHAR"/>
        <result column="operator" property="operator" jdbcType="VARCHAR"/>
        <result column="value" property="value" jdbcType="VARCHAR"/>
        <result column="base_type" property="baseType" jdbcType="INTEGER"/>
        <result column="category_id" property="categoryId" jdbcType="INTEGER"/>
        <result column="create_dept" property="createDept" jdbcType="BIGINT"/>
        <result column="del_flag" property="delFlag" jdbcType="CHAR"/>
        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
        <result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
        <result column="create_by" property="createBy" jdbcType="BIGINT"/>
        <result column="update_by" property="updateBy" jdbcType="BIGINT"/>
        <result column="remark" property="remark" jdbcType="VARCHAR"/>
        <result column="tenant_id" property="tenantId" jdbcType="VARCHAR"/>
        <result column="cond_id" property="condId" jdbcType="INTEGER"/>
        <result column="seq_num" property="seqNum" jdbcType="INTEGER"/>
    </resultMap>

    <sql id="Base_Column_List">
        id, rule_id, data_source, database, table_name, table_alias,
        column_name, column_desc, data_type, fn, arguments, operator, value,
        base_type, category_id, create_dept, del_flag, create_time,
        update_time, create_by, update_by, remark, tenant_id, cond_id, seq_num
    </sql>

    <!-- 根据规则ID查询过滤条件 -->
    <select id="selectByRuleId" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM analysis_filter
        WHERE rule_id  =#{ruleId, jdbcType=OTHER}
        AND del_flag = '0'
    </select>

    <!-- 根据字段ID查询过滤条件 -->
    <select id="selectByFieldId" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM analysis_filter
        WHERE field_id = #{fieldId}
        AND del_flag = '0'
    </select>

    <!-- 根据条件ID查询过滤条件（与where_condition表关联） -->
    <select id="selectByCondId" resultMap="BaseResultMap">
        SELECT
        <include refid="Base_Column_List"/>
        FROM analysis_filter
        WHERE cond_id = #{condId}
        AND del_flag = '0'
        ORDER BY seq_num ASC
    </select>

</mapper>
