<?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.AnalysisGroupByColumnMapper">

    <resultMap id="BaseResultMap" type="com.common.entity.AnalysisGroupByColumn">
        <id column="id" property="id" jdbcType="INTEGER"/>
        <result column="group_by_id" property="groupById" jdbcType="INTEGER"/>
        <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="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="rule_id" property="ruleId" jdbcType="VARCHAR"/>
        <result column="group_id" property="groupId" jdbcType="BIGINT"/>
        <result column="field_id" property="fieldId" jdbcType="BIGINT"/>
        <result column="sort" property="sort" jdbcType="INTEGER"/>
    </resultMap>

    <sql id="Base_Column_List">
        id, group_by_id, data_source, database, table_name, table_alias,
        column_name, column_desc, data_type, base_type, category_id,
        create_dept, del_flag, create_time, update_time, create_by, update_by,
        remark, tenant_id, rule_id, group_id, field_id, sort
    </sql>

    <!-- 根据规则ID查询分组字段配置 -->
    <select id="selectByRuleId" resultMap="BaseResultMap">
        SELECT
        id, group_by_id, data_source, database, table_name,
        table_alias, column_name, column_desc, data_type,
        base_type, category_id, create_dept, del_flag,
        create_time, update_time, create_by, update_by, remark,
        tenant_id, rule_id, group_id, field_id, sort
        FROM analysis_group_by_column
        WHERE rule_id =#{ruleId, jdbcType=OTHER}
        AND del_flag = '0'
        ORDER BY sort ASC
    </select>

    <!-- 根据分组ID查询分组字段配置 -->
    <select id="selectByGroupById" resultMap="BaseResultMap">
        SELECT
        id, group_by_id, data_source, database, table_name,
        table_alias, column_name, column_desc, data_type,
        base_type, category_id, create_dept, del_flag,
        create_time, update_time, create_by, update_by, remark,
        tenant_id, rule_id, group_id, field_id, sort
        FROM analysis_group_by_column
        WHERE group_by_id = #{groupById}
        AND del_flag = '0'
        ORDER BY sort ASC
    </select>

    <!-- 根据用户组ID查询分组字段配置 -->
    <select id="selectByGroupId" resultMap="BaseResultMap">
        SELECT
        id, group_by_id, data_source, database, table_name,
        table_alias, column_name, column_desc, data_type,
        base_type, category_id, create_dept, del_flag,
        create_time, update_time, create_by, update_by, remark,
        tenant_id, rule_id, group_id, field_id, sort
        FROM analysis_group_by_column
        WHERE group_id = #{groupId}
        AND del_flag = '0'
        ORDER BY sort ASC
    </select>

</mapper>
