<?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.yeejoin.amos.boot.module.jxiop.biz.mapper2.IdxBizTableMapper">
    <select id="getSelectOptions" resultType="java.util.Map">
        SELECT
            DISTINCT ${column} AS text,
            <if test="valueColumn != null and valueColumn != ''">
                MAX(${valueColumn}) AS value
            </if>
            <if test="valueColumn == null or valueColumn == ''">
                MAX(${column}) AS value
            </if>
        FROM
            ${tableName}
        WHERE
            ${column} IS NOT NULL AND ${column} != ''
            <if test="isFx != null and isFx != ''">
                AND TAG_CODE = '分析变量'
            </if>
            <if test="conditionColumn != null and conditionColumn != '' and conditionValue != null and conditionValue != ''">
                AND ${conditionColumn} = #{conditionValue}
            </if>
            <if test="gatewayIds != null">
                <if test="gatewayIds.size() > 0">
                    AND ORG_CODE IN
                    <foreach collection="gatewayIds" item="item" open="(" separator="," close=")">
                        #{item}
                    </foreach>
                </if>
                <if test="gatewayIds.size() == 0">
                    AND 1 = 2
                </if>
            </if>
            <if test="filters != null">
                <if test="filters.size() > 0">
                    <foreach collection="filters" item="item">
                        AND ${item.column} = #{item.value}
                    </foreach>
                </if>
            </if>
        GROUP BY
            ${column}
    </select>
</mapper>
