<?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.cm.common.dao.bigdatatemplatearea.IBigdataTemplateAreaDao">

    <resultMap id="bigdataTemplateAreaDTO" type="com.cm.common.pojo.dtos.bigdatatemplatearea.BigdataTemplateAreaDTO">
        <id column="bigdata_template_area_id" property="bigdataTemplateAreaId"/>
        <result column="bigdata_template_id" property="bigdataTemplateId"/>
        <result column="bigdata_module_id" property="bigdataModuleId"/>
        <result column="template_area_jump" property="templateAreaJump"/>
        <result column="template_area_jump_mode" property="templateAreaJumpMode"/>
        <result column="template_area_jump_template_id" property="templateAreaJumpTemplateId"/>
        <result column="template_area_module_data" property="templateAreaModuleData"/>
        <result column="template_area_server_data" property="templateAreaServerData"/>
        <result column="template_area_source" property="templateAreaSource"/>
        <result column="template_area_left" property="templateAreaLeft"/>
        <result column="template_area_top" property="templateAreaTop"/>
        <result column="template_area_down" property="templateAreaDown"/>
        <result column="template_area_right" property="templateAreaRight"/>
        <result column="template_area_height" property="templateAreaHeight"/>
        <result column="template_area_width" property="templateAreaWidth"/>
        <result column="template_area_color" property="templateAreaColor"/>
        <result column="template_area_remark" property="templateAreaRemark"/>
        <result column="template_area_status" property="templateAreaStatus"/>
        <result column="template_area_frequency" property="templateAreaFrequency"/>
        <result column="bigdata_module_name" property="bigdataModuleName"/>
        <result column="bigdata_module_type" property="bigdataModuleType"/>
        <result column="bigdata_module_photo" property="bigdataModulePhoto"/>
        <result column="bigdata_template_title" property="bigdataTemplateTitle"/>
        <result column="bigdata_module_content" property="bigdataModuleContent"/>
        <result column="template_area_jump_template_title" property="templateAreaJumpTemplateTitle"/>
        <result column="bigdata_module_code" property="bigdataModuleCode"/>
        <result column="template_area_file" property="templateAreaFile"/>
        <result column="template_area_jump_url" property="templateAreaJumpUrl"/>
    </resultMap>

    <!-- 修改展览模板区域 -->
    <update id="updateBigdataTemplateAreaPoint" parameterType="map">
        UPDATE
            bigdata_template_area
        SET
            template_area_left = #{templateAreaLeft},
            template_area_top = #{templateAreaTop},
            template_area_down = #{templateAreaDown},
            template_area_right = #{templateAreaRight},
            template_area_height = #{templateAreaHeight},
            template_area_width = #{templateAreaWidth},
            modifier = #{modifier},
            gmt_modified = #{gmtModified}
        WHERE
            bigdata_template_area_id = #{bigdataTemplateAreaId}
    </update>

    <!-- 大数据展示模板的区域设置详情 -->
    <select id="getBigdataTemplateAreaByBigdataTemplateId" parameterType="map" resultMap="bigdataTemplateAreaDTO">
        SELECT
            t1.bigdata_template_area_id,
            t1.bigdata_template_id,
            t1.bigdata_module_id,
            t1.template_area_jump,
            t1.template_area_jump_mode,
            t1.template_area_jump_template_id,
            t1.template_area_module_data,
            t1.template_area_server_data,
            t1.template_area_source,
            t1.template_area_color,
            t1.template_area_remark,
            t1.template_area_status,
            t1.template_area_frequency,
            t1.template_area_left,
            t1.template_area_top,
            t1.template_area_down,
            t1.template_area_right,
            t1.template_area_height,
            t1.template_area_width,
            t2.bigdata_module_name,
            t2.bigdata_module_code,
            t2.bigdata_module_type,
            t2.bigdata_module_photo,
            t2.bigdata_module_content,
            t1.template_area_file,
            t1.template_area_jump_url
        FROM
            bigdata_template_area t1
        LEFT JOIN
            bigdata_module t2
        ON
            t1.bigdata_module_id = t2.bigdata_module_id
        WHERE
            t1.is_delete = 0
        <if test="bigdataTemplateId != null and bigdataTemplateId != ''">
            AND
            t1.bigdata_template_id = #{bigdataTemplateId}
        </if>
        ORDER BY t1.gmt_create
    </select>

    <!-- 新增大数据展示模板的区域设置 -->
    <insert id="saveBigdataTemplateArea" parameterType="map">
        INSERT INTO bigdata_template_area(
            bigdata_template_area_id,
            bigdata_template_id,
            bigdata_module_id,
            template_area_jump,
            template_area_jump_mode,
            template_area_jump_template_id,
            template_area_module_data,
            template_area_server_data,
            template_area_source,
            template_area_left,
            template_area_top,
            template_area_down,
            template_area_right,
            template_area_height,
            template_area_width,
            template_area_color,
            template_area_remark,
            template_area_status,
            template_area_frequency,
            template_area_file,
            template_area_jump_url,
            creator,
            gmt_create,
            modifier,
            gmt_modified,
            is_delete
        ) VALUES(
            #{bigdataTemplateAreaId},
            #{bigdataTemplateId},
            #{bigdataModuleId},
            #{templateAreaJump},
            #{templateAreaJumpMode},
            #{templateAreaJumpTemplateId},
            #{templateAreaModuleData},
            #{templateAreaServerData},
            #{templateAreaSource},
            #{templateAreaLeft},
            #{templateAreaTop},
            #{templateAreaDown},
            #{templateAreaRight},
            #{templateAreaHeight},
            #{templateAreaWidth},
            #{templateAreaColor},
            #{templateAreaRemark},
            #{templateAreaStatus},
            #{templateAreaFrequency},
            #{templateAreaFile},
            #{templateAreaJumpUrl},
            #{creator},
            #{gmtCreate},
            #{modifier},
            #{gmtModified},
            #{isDelete}
        )
    </insert>

    <!-- 删除大数据展示模板的区域设置 -->
    <update id="removeBigdataTemplateArea" parameterType="map">
        UPDATE
            bigdata_template_area
        SET
            is_delete = 1,
            modifier = #{modifier},
            gmt_modified = #{gmtModified}
        WHERE
            bigdata_template_area_id IN
        <foreach collection="bigdataTemplateAreaIds" index="index" open="(" separator="," close=")">
            #{bigdataTemplateAreaIds[${index}]}
        </foreach>
    </update>

    <!-- 删除大数据展示模板的区域设置（物理） -->
    <update id="deleteBigdataTemplateArea" parameterType="map">
        DELETE FROM
            bigdata_template_area
        WHERE
            bigdata_template_area_id IN
        <foreach collection="bigdataTemplateAreaIds" index="index" open="(" separator="," close=")">
            #{bigdataTemplateAreaIds[${index}]}
        </foreach>
    </update>

    <!-- 修改大数据展示模板的区域设置 -->
    <update id="updateBigdataTemplateArea" parameterType="map">
        UPDATE
            bigdata_template_area
        SET
        <if test="bigdataModuleId != null and bigdataModuleId != ''">
            bigdata_module_id = #{bigdataModuleId},
        </if>
        <if test="templateAreaColor != null and templateAreaColor != ''">
            template_area_color = #{templateAreaColor},
        </if>
        <if test="templateAreaJump != null and templateAreaJump != ''">
            template_area_jump = #{templateAreaJump},
        </if>
        <if test="templateAreaJumpMode != null and templateAreaJumpMode != ''">
            template_area_jump_mode = #{templateAreaJumpMode},
        </if>
        <if test="templateAreaModuleData != null and templateAreaModuleData != ''">
            template_area_module_data = #{templateAreaModuleData},
        </if>
        <if test="templateAreaServerData != null and templateAreaServerData != ''">
            template_area_server_data = #{templateAreaServerData},
        </if>
        <if test="templateAreaSource != null and templateAreaSource != ''">
            template_area_source = #{templateAreaSource},
        </if>
        <if test="templateAreaRemark != null and templateAreaRemark != ''">
            template_area_remark = #{templateAreaRemark},
        </if>
            template_area_jump_template_id = #{templateAreaJumpTemplateId},
            template_area_frequency = #{templateAreaFrequency},
            template_area_file = #{templateAreaFile},
            template_area_jump_url = #{templateAreaJumpUrl},
            modifier = #{modifier},
            gmt_modified = #{gmtModified}
        WHERE
            bigdata_template_area_id = #{bigdataTemplateAreaId}
    </update>

    <!-- 大数据展示模板的区域设置详情 -->
    <select id="getBigdataTemplateArea" parameterType="map" resultMap="bigdataTemplateAreaDTO">
        SELECT
            t1.bigdata_template_id,
            t1.bigdata_module_id,
            t1.template_area_jump,
            t1.template_area_jump_mode,
            t1.template_area_jump_template_id,
            t1.template_area_module_data,
            t1.template_area_server_data,
            t1.template_area_source,
            t1.template_area_color,
            t1.template_area_remark,
            t1.template_area_status,
            t1.bigdata_template_area_id,
            t1.template_area_frequency,
            t2.bigdata_module_name,
            t2.bigdata_module_type,
            t2.bigdata_module_photo,
            t3.bigdata_template_title,
            t4.bigdata_template_title AS template_area_jump_template_title,
            t1.template_area_file,
            t1.template_area_jump_url
        FROM
            bigdata_template_area t1
        LEFT JOIN
            bigdata_module t2
        ON
            t1.bigdata_module_id = t2.bigdata_module_id
        LEFT JOIN
            bigdata_template t3
        ON
            t1.bigdata_template_id = t3.bigdata_template_id
        LEFT JOIN
            bigdata_template t4
        ON
            t1.template_area_jump_template_id = t4.bigdata_template_id
        WHERE
            t1.is_delete = 0
        <if test="bigdataTemplateAreaId != null and bigdataTemplateAreaId != ''">
        AND
            t1.bigdata_template_area_id = #{bigdataTemplateAreaId}
        </if>
    </select>

    <!-- 大数据展示模板的区域设置列表 -->
    <select id="listBigdataTemplateArea" parameterType="map" resultMap="bigdataTemplateAreaDTO">
        SELECT
            t1.bigdata_template_id,
            t1.bigdata_module_id,
            t1.template_area_jump,
            t1.template_area_jump_mode,
            t1.template_area_jump_template_id,
            t1.template_area_module_data,
            t1.template_area_server_data,
            t1.template_area_source,
            t1.template_area_color,
            t1.template_area_remark,
            t1.template_area_status,
            t1.bigdata_template_area_id,
            t1.template_area_frequency,
            t1.template_area_file,
            t1.template_area_jump_url
        FROM
            bigdata_template_area t1
        WHERE
            t1.is_delete = 0
        <if test="keywords != null and keywords != ''">
        AND (
            t1.id LIKE CONCAT('%', #{keywords}, '%')
            OR
            t1.bigdata_template_area_id LIKE CONCAT('%', #{keywords}, '%')
            <!-- 这里添加其他条件 -->
        )
        </if>
        <if test="startTime != null and startTime != ''">
        AND
            LEFT(t1.gmt_create, 10) <![CDATA[ >= ]]> #{startTime}
        </if>
        <if test="endTime != null and endTime != ''">
        AND
            LEFT(t1.gmt_create, 10) <![CDATA[ <= ]]> #{endTime}
        </if>
        <if test="bigdataTemplateAreaIds != null and bigdataTemplateAreaIds.size > 0">
        AND
            t1.bigdata_template_area_id IN
            <foreach collection="bigdataTemplateAreaIds" index="index" open="(" separator="," close=")">
            #{bigdataTemplateAreaIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- 大数据展示模板的区域设置统计  -->
    <select id="countBigdataTemplateArea" parameterType="map" resultType="Integer">
        SELECT
            COUNT(*)
        FROM
            bigdata_template_area t1
        WHERE
            t1.is_delete = 0
    </select>

</mapper>