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

    <resultMap id="BaseResultMap" type="com.common.entity.AnalysisGroupBy">
        <id column="id" property="id" jdbcType="BIGINT"/>
        <result column="rule_id" property="ruleId" jdbcType="VARCHAR"/>
        <result column="group_type" property="groupType" jdbcType="INTEGER"/>
        <result column="window_type" property="windowType" jdbcType="VARCHAR"/>
        <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"/>
    </resultMap>

    <resultMap id="WithWindowResultMap" type="com.common.entity.AnalysisGroupBy" extends="BaseResultMap">
        <association property="window" javaType="com.common.entity.AnalysisGroupByWindow"
                     column="id" select="com.common.mapper.AnalysisGroupByWindowMapper.selectByGroupById"/>
    </resultMap>

    <sql id="Base_Column_List">
        id, rule_id, group_type, window_type,
        create_dept, del_flag, create_time, update_time, create_by, update_by,
        remark, tenant_id
    </sql>

    <!-- 根据规则ID查询分组配置 -->
    <select id="selectByRuleId" resultMap="BaseResultMap">
        SELECT
            <include refid="Base_Column_List"/>
        FROM analysis_group_by
        WHERE rule_id = #{ruleId, jdbcType=OTHER}
          AND del_flag = '0'
    </select>

</mapper>
