<?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="cn.com.tenlion.bigdata.dao.bigdatatemplate.IBigdataTemplateDao">

    <resultMap id="bigdataTemplateDTO" type="cn.com.tenlion.bigdata.pojo.dtos.bigdatatemplate.BigdataTemplateDTO">
        <id column="bigdata_template_id" property="bigdataTemplateId"/>
        <result column="bigdata_template_code" property="bigdataTemplateCode"/>
        <result column="bigdata_template_background_image" property="bigdataTemplateBackgroundImage"/>
        <result column="bigdata_template_title" property="bigdataTemplateTitle"/>
        <result column="bigdata_template_height" property="bigdataTemplateHeight"/>
        <result column="bigdata_template_width" property="bigdataTemplateWidth"/>
        <result column="bigdata_template_publish_status" property="bigdataTemplatePublishStatus"/>
        <result column="bigdata_template_publish_time" property="bigdataTemplatePublishTime"/>
        <result column="bigdata_template_url" property="bigdataTemplateUrl"/>
        <result column="bigdata_template_content" property="bigdataTemplateContent"/>
        <result column="bigdata_template_file" property="bigdataTemplateFile"/>
        <result column="bigdata_template_back" property="bigdataTemplateBack"/>
        <result column="bigdata_template_size" property="bigdataTemplateSize"/>
        <result column="bigdata_template_project" property="bigdataTemplateProject"/>
    </resultMap>

    <update id="updateBigdataTemplateContent" parameterType="map">
        UPDATE
            m_bigdata_template
        SET
            bigdata_template_content = #{bigdataModuleContent}
        WHERE
            bigdata_template_id = #{bigdataTemplateId}  AND is_delete = 0
    </update>

    <select id="querySqlAll" parameterType="java.lang.String" resultType="java.util.HashMap">
        SELECT querySqlResult.* FROM (${_parameter}) querySqlResult
    </select>

    <update id="updateBigdataTemplatePublishStatus" parameterType="map">
        UPDATE
            m_bigdata_template
        SET
            bigdata_template_publish_status = #{bigdataTemplatePublishStatus},
            bigdata_template_publish_time = #{bigdataTemplatePublishTime},
            modifier = #{modifier},
            gmt_modified = #{gmtModified}
        WHERE
            bigdata_template_id = #{bigdataTemplateId}  AND is_delete = 0
    </update>

    <update id="updataBigdataTemplateUrl" parameterType="map">
        UPDATE
            m_bigdata_template
        SET
            bigdata_template_url = #{bigdataTemplateUrl}
        WHERE
            bigdata_template_id = #{bigdataTemplateId}  AND is_delete = 0
    </update>

    <select id="getBigdataTemplateByCode" parameterType="java.lang.String" resultMap="bigdataTemplateDTO">
        SELECT
            t1.bigdata_template_code,
            t1.bigdata_template_background_image,
            t1.bigdata_template_title,
            t1.bigdata_template_height,
            t1.bigdata_template_width,
            t1.bigdata_template_publish_status,
            t1.bigdata_template_publish_time,
            t1.bigdata_template_url,
            t1.bigdata_template_content,
            t1.bigdata_template_id,
            t1.bigdata_template_file,
            t1.bigdata_template_back,
            t1.bigdata_template_size,
            t1.bigdata_template_project
        FROM
            m_bigdata_template t1
        WHERE
            t1.is_delete = 0 AND t1.bigdata_template_code = #{bigdataTemplateCode}
    </select>

    <!-- 新增大数据展示的模板管理 -->
    <insert id="saveBigdataTemplate" parameterType="map">
        INSERT INTO m_bigdata_template(
            bigdata_template_id,
            bigdata_template_code,
            bigdata_template_background_image,
            bigdata_template_title,
            bigdata_template_height,
            bigdata_template_width,
            bigdata_template_publish_status,
            bigdata_template_publish_time,
            bigdata_template_url,
            bigdata_template_content,
            bigdata_template_file,
            bigdata_template_back,
            bigdata_template_size,
            bigdata_template_project,
            creator,
            gmt_create,
            modifier,
            gmt_modified,
            is_delete
        ) VALUES(
            #{bigdataTemplateId},
            #{bigdataTemplateCode},
            #{bigdataTemplateBackgroundImage},
            #{bigdataTemplateTitle},
            #{bigdataTemplateHeight},
            #{bigdataTemplateWidth},
            #{bigdataTemplatePublishStatus},
            #{bigdataTemplatePublishTime},
            #{bigdataTemplateUrl},
            #{bigdataTemplateContent},
            #{bigdataTemplateFile},
            #{bigdataTemplateBack},
            #{bigdataTemplateSize},
            #{bigdataTemplateProject},
            #{creator},
            #{gmtCreate},
            #{modifier},
            #{gmtModified},
            #{isDelete}
        )
    </insert>

    <!-- 删除大数据展示的模板管理 -->
    <update id="removeBigdataTemplate" parameterType="map">
        UPDATE
            m_bigdata_template
        SET
            is_delete = 1,
            modifier = #{modifier},
            gmt_modified = #{gmtModified}
        WHERE
            bigdata_template_id IN
        <foreach collection="bigdataTemplateIds" index="index" open="(" separator="," close=")">
            #{bigdataTemplateIds[${index}]}
        </foreach>
    </update>

    <!-- 删除大数据展示的模板管理（物理） -->
    <update id="deleteBigdataTemplate" parameterType="map">
        DELETE FROM
            m_bigdata_template
        WHERE
            bigdata_template_id IN
        <foreach collection="bigdataTemplateIds" index="index" open="(" separator="," close=")">
            #{bigdataTemplateIds[${index}]}
        </foreach>
    </update>

    <!-- 修改大数据展示的模板管理 -->
    <update id="updateBigdataTemplate" parameterType="map">
        UPDATE
            m_bigdata_template
        SET
        <if test="bigdataTemplateCode != null and bigdataTemplateCode != ''">
            bigdata_template_code = #{bigdataTemplateCode},
        </if>
        <if test="bigdataTemplateBackgroundImage != null and bigdataTemplateBackgroundImage != ''">
            bigdata_template_background_image = #{bigdataTemplateBackgroundImage},
        </if>
        <if test="bigdataTemplateTitle != null and bigdataTemplateTitle != ''">
            bigdata_template_title = #{bigdataTemplateTitle},
        </if>
        <if test="bigdataTemplateHeight != null">
            bigdata_template_height = #{bigdataTemplateHeight},
        </if>
        <if test="bigdataTemplateWidth != null">
            bigdata_template_width = #{bigdataTemplateWidth},
        </if>
        <if test="bigdataTemplateBack != null and bigdataTemplateBack != ''">
            bigdata_template_back = #{bigdataTemplateBack},
        </if>
        <if test="bigdataTemplateSize != null and bigdataTemplateSize != ''">
            bigdata_template_size = #{bigdataTemplateSize},
        </if>
        <if test="bigdataTemplateProject != null and bigdataTemplateProject != ''">
            bigdata_template_project = #{bigdataTemplateProject},
        </if>
            bigdata_template_file = #{bigdataTemplateFile},
            modifier = #{modifier},
            gmt_modified = #{gmtModified}
        WHERE
            bigdata_template_id = #{bigdataTemplateId}
    </update>

    <!-- 大数据展示的模板管理详情 -->
    <select id="getBigdataTemplate" parameterType="map" resultMap="bigdataTemplateDTO">
        SELECT
            t1.bigdata_template_code,
            t1.bigdata_template_background_image,
            t1.bigdata_template_title,
            t1.bigdata_template_height,
            t1.bigdata_template_width,
            t1.bigdata_template_publish_status,
            t1.bigdata_template_publish_time,
            t1.bigdata_template_url,
            t1.bigdata_template_content,
            t1.bigdata_template_id,
            t1.bigdata_template_file,
            t1.bigdata_template_back,
            t1.bigdata_template_size,
            t1.bigdata_template_project
        FROM
            m_bigdata_template t1
        WHERE
            t1.is_delete = 0
        <if test="bigdataTemplateId != null and bigdataTemplateId != ''">
        AND
            t1.bigdata_template_id = #{bigdataTemplateId}
        </if>
        ORDER BY t1.gmt_create
    </select>

    <!-- 大数据展示的模板管理列表 -->
    <select id="listBigdataTemplate" parameterType="map" resultMap="bigdataTemplateDTO">
        SELECT
            t1.bigdata_template_code,
            t1.bigdata_template_background_image,
            t1.bigdata_template_title,
            t1.bigdata_template_height,
            t1.bigdata_template_width,
            t1.bigdata_template_publish_status,
            t1.bigdata_template_publish_time,
            t1.bigdata_template_url,
            t1.bigdata_template_content,
            t1.bigdata_template_id,
            t1.bigdata_template_file,
            t1.bigdata_template_back,
            t1.bigdata_template_size,
            t1.bigdata_template_project
        FROM
            m_bigdata_template t1
        WHERE
            t1.is_delete = 0
        <if test="keywords != null and keywords != ''">
        AND (
            t1.bigdata_template_code LIKE CONCAT('%', #{keywords}, '%')
            OR
            t1.bigdata_template_title LIKE CONCAT('%', #{keywords}, '%')
            <!-- 这里添加其他条件 -->
        )
        </if>
        <if test="bigdataTemplateProject != null and bigdataTemplateProject != ''">
            AND t1.bigdata_template_project = #{bigdataTemplateProject}
        </if>
        <if test="bigdataTemplatePublishStatus != null and bigdataTemplatePublishStatus != ''">
            AND t1.bigdata_template_publish_status = #{bigdataTemplatePublishStatus}
        </if>
        <if test="noGetbigdataTemplateId != null and noGetbigdataTemplateId != ''">
            AND t1.bigdata_template_id != #{noGetbigdataTemplateId} AND t1.bigdata_template_url IS NOT NULL AND t1.bigdata_template_url != '' AND t1.bigdata_template_back = '2'
        </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="bigdataTemplateIds != null and bigdataTemplateIds.size > 0">
        AND
            t1.bigdata_template_id IN
            <foreach collection="bigdataTemplateIds" index="index" open="(" separator="," close=")">
            #{bigdataTemplateIds[${index}]}
            </foreach>
        </if>
        ORDER BY t1.gmt_create
    </select>

    <!-- 大数据展示的模板管理统计  -->
    <select id="countBigdataTemplate" parameterType="map" resultType="Integer">
        SELECT
            COUNT(*)
        FROM
            m_bigdata_template t1
        WHERE
            t1.is_delete = 0
    </select>

</mapper>