<?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.tourism.common.report.dao.ReportDatasetColumnMapper">
    <resultMap id="BaseResultMap" type="com.tourism.common.report.model.ReportDatasetColumn">
        <id column="column_id" jdbcType="BIGINT" property="columnId"/>
        <result column="column_name" jdbcType="VARCHAR" property="columnName"/>
        <result column="dataset_id" jdbcType="BIGINT" property="datasetId"/>
        <result column="primary_key" jdbcType="BOOLEAN" property="primaryKey"/>
        <result column="column_type" jdbcType="VARCHAR" property="columnType"/>
        <result column="column_show_order" jdbcType="INTEGER" property="columnShowOrder"/>
        <result column="column_comment" jdbcType="VARCHAR" property="columnComment"/>
        <result column="field_name" jdbcType="VARCHAR" property="fieldName"/>
        <result column="field_type" jdbcType="VARCHAR" property="fieldType"/>
        <result column="numeric_precision" jdbcType="INTEGER" property="numericPrecision"/>
        <result column="numeric_scale" jdbcType="INTEGER" property="numericScale"/>
        <result column="dict_id" jdbcType="BIGINT" property="dictId"/>
        <result column="dimension" jdbcType="BOOLEAN" property="dimension"/>
        <result column="image" jdbcType="BOOLEAN" property="image"/>
        <result column="logic_delete" jdbcType="BOOLEAN" property="logicDelete"/>
        <result column="dept_filter" jdbcType="BOOLEAN" property="deptFilter"/>
        <result column="user_filter" jdbcType="BOOLEAN" property="userFilter"/>
        <result column="tenant_filter" jdbcType="BOOLEAN" property="tenantFilter"/>
        <result column="field_kind" jdbcType="INTEGER" property="fieldKind"/>
        <result column="function_body" jdbcType="VARCHAR" property="functionBody"/>
    </resultMap>

    <insert id="insertList">
        INSERT INTO zz_report_dataset_column VALUES
        <foreach collection="list" index="index" item="item" separator="," >
            (#{item.columnId},
            #{item.columnName},
            #{item.datasetId},
            #{item.primaryKey},
            #{item.columnType},
            #{item.columnShowOrder},
            #{item.columnComment},
            #{item.fieldName},
            #{item.fieldType},
            #{item.numericPrecision},
            #{item.numericScale},
            #{item.dictId},
            #{item.dimension},
            #{item.image},
            #{item.logicDelete},
            #{item.deptFilter},
            #{item.userFilter},
            #{item.tenantFilter},
            #{item.fieldKind},
            #{item.functionBody})
        </foreach>
    </insert>

    <!-- 如果有逻辑删除字段过滤，请写到这里 -->
    <sql id="filterRef">
        <!-- 这里必须加上全包名，否则当filterRef被其他Mapper.xml包含引用的时候，就会调用Mapper.xml中的该SQL片段 -->
        <include refid="com.tourism.common.report.dao.ReportDatasetColumnMapper.inputFilterRef"/>
    </sql>

    <!-- 这里仅包含调用接口输入的主表过滤条件 -->
    <sql id="inputFilterRef">
        <if test="reportDatasetColumnFilter != null">
            <if test="reportDatasetColumnFilter.datasetId != null">
                AND zz_report_dataset_column.dataset_id = #{reportDatasetColumnFilter.datasetId}
            </if>
        </if>
    </sql>

    <select id="getReportDatasetColumnList" resultMap="BaseResultMap" parameterType="com.tourism.common.report.model.ReportDatasetColumn">
        SELECT * FROM zz_report_dataset_column
        <where>
            <include refid="filterRef"/>
        </where>
        ORDER BY column_show_order
    </select>
</mapper>
