<?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.bigdatamodule.IBigdataModuleDao">

    <resultMap id="bigdataModuleDTO" type="cn.com.tenlion.bigdata.pojo.dtos.bigdatamodule.BigdataModuleDTO">
        <id column="bigdata_module_id" property="bigdataModuleId"/>
        <result column="bigdata_module_code" property="bigdataModuleCode"/>
        <result column="bigdata_module_photo" property="bigdataModulePhoto"/>
        <result column="bigdata_module_name" property="bigdataModuleName"/>
        <result column="bigdata_module_type" property="bigdataModuleType"/>
        <result column="bigdata_module_type_data_name" property="bigdataModuleTypeDictionaryName"/>
        <result column="bigdata_module_switch" property="bigdataModuleSwitch"/>
        <result column="bigdata_module_switch_data_name" property="bigdataModuleSwitchDictionaryName"/>
        <result column="bigdata_module_content" property="bigdataModuleContent"/>
        <result column="bigdata_module_remark" property="bigdataModuleRemark"/>
        <result column="bigdata_module_module_json" property="bigdataModuleModuleJson"/>
        <result column="bigdata_module_server_json" property="bigdataModuleServerJson"/>
        <result column="bigdata_module_link" property="bigdataModuleLink"/>
    </resultMap>

    <update id="updateBigdataModuleSwitch" parameterType="map">
        UPDATE
            m_bigdata_module
        SET
            bigdata_module_switch = #{bigdataModuleSwitch},
            modifier = #{modifier},
            gmt_modified = #{gmtModified}
        WHERE
            bigdata_module_id = #{bigdataModuleId}  AND is_delete = 0
    </update>

    <select id="getBigdataModuleByCode" parameterType="java.lang.String" resultMap="bigdataModuleDTO">
        SELECT
            t1.bigdata_module_code,
            t1.bigdata_module_remark,
            t1.bigdata_module_photo,
            t1.bigdata_module_name,
            t1.bigdata_module_type,
            t1.bigdata_module_switch,
            t1.bigdata_module_content,
            t1.bigdata_module_id,
            t1.bigdata_module_module_json,
            t1.bigdata_module_server_json,
            t1.bigdata_module_link,
            dt1.data_name bigdata_module_type_data_name
        FROM
            m_bigdata_module t1
        LEFT JOIN
            data_data dt1
        ON
            dt1.data_id = t1.bigdata_module_type
        AND
            dt1.is_delete = 0
        WHERE
            t1.is_delete = 0 AND t1.bigdata_module_code = #{bigdataModuleCode}
    </select>

    <update id="updateBigdataModuleContent" parameterType="map">
        UPDATE
            m_bigdata_module
        SET
            bigdata_module_content = #{bigdataModuleContent},
            modifier = #{modifier},
            gmt_modified = #{gmtModified}
        WHERE
            bigdata_module_id = #{bigdataModuleId}
    </update>

    <!-- 新增大数据展示模块 -->
    <insert id="saveBigdataModule" parameterType="map">
        INSERT INTO m_bigdata_module(
            bigdata_module_id,
            bigdata_module_code,
            bigdata_module_photo,
            bigdata_module_name,
            bigdata_module_type,
            bigdata_module_switch,
            bigdata_module_content,
            bigdata_module_remark,
            bigdata_module_module_json,
            bigdata_module_server_json,
            bigdata_module_link,
            creator,
            gmt_create,
            modifier,
            gmt_modified,
            is_delete
        ) VALUES(
            #{bigdataModuleId},
            #{bigdataModuleCode},
            #{bigdataModulePhoto},
            #{bigdataModuleName},
            #{bigdataModuleType},
            #{bigdataModuleSwitch},
            #{bigdataModuleContent},
            #{bigdataModuleRemark},
            #{bigdataModuleModuleJson},
            #{bigdataModuleServerJson},
            #{bigdataModuleLink},
            #{creator},
            #{gmtCreate},
            #{modifier},
            #{gmtModified},
            #{isDelete}
        )
    </insert>

    <!-- 删除大数据展示模块 -->
    <update id="removeBigdataModule" parameterType="map">
        UPDATE
            m_bigdata_module
        SET
            is_delete = 1,
            modifier = #{modifier},
            gmt_modified = #{gmtModified}
        WHERE
            bigdata_module_id IN
        <foreach collection="bigdataModuleIds" index="index" open="(" separator="," close=")">
            #{bigdataModuleIds[${index}]}
        </foreach>
    </update>

    <!-- 删除大数据展示模块（物理） -->
    <update id="deleteBigdataModule" parameterType="map">
        DELETE FROM
            m_bigdata_module
        WHERE
            bigdata_module_id IN
        <foreach collection="bigdataModuleIds" index="index" open="(" separator="," close=")">
            #{bigdataModuleIds[${index}]}
        </foreach>
    </update>

    <!-- 修改大数据展示模块 -->
    <update id="updateBigdataModule" parameterType="map">
        UPDATE
            m_bigdata_module
        SET
        <if test="bigdataModulePhoto != null and bigdataModulePhoto != ''">
            bigdata_module_photo = #{bigdataModulePhoto},
        </if>
        <if test="bigdataModuleName != null and bigdataModuleName != ''">
            bigdata_module_name = #{bigdataModuleName},
        </if>
        <if test="bigdataModuleType != null and bigdataModuleType != ''">
            bigdata_module_type = #{bigdataModuleType},
        </if>
        <if test="bigdataModuleRemark != null and bigdataModuleRemark != ''">
            bigdata_module_remark = #{bigdataModuleRemark},
        </if>
        <if test="bigdataModuleModuleJson != null and bigdataModuleModuleJson != ''">
            bigdata_module_module_json = #{bigdataModuleModuleJson},
        </if>
        <if test="bigdataModuleServerJson != null and bigdataModuleServerJson != ''">
            bigdata_module_server_json = #{bigdataModuleServerJson},
        </if>
        <if test="bigdataModuleLink != null and bigdataModuleLink != ''">
            bigdata_module_link = #{bigdataModuleLink},
        </if>
            modifier = #{modifier},
            gmt_modified = #{gmtModified}
        WHERE
            bigdata_module_id = #{bigdataModuleId}
    </update>

    <!-- 大数据展示模块详情 -->
    <select id="getBigdataModule" parameterType="map" resultMap="bigdataModuleDTO">
        SELECT
            t1.bigdata_module_code,
            t1.bigdata_module_photo,
            t1.bigdata_module_name,
            t1.bigdata_module_type,
            t1.bigdata_module_switch,
            t1.bigdata_module_content,
            t1.bigdata_module_remark,
            t1.bigdata_module_id,
            t1.bigdata_module_module_json,
            t1.bigdata_module_server_json,
            t1.bigdata_module_link,
            dt1.data_name bigdata_module_type_data_name
        FROM
            m_bigdata_module t1
        LEFT JOIN
            data_data dt1
        ON
            dt1.data_id = t1.bigdata_module_type
        AND
            dt1.is_delete = 0
        WHERE
            t1.is_delete = 0
        <if test="bigdataModuleId != null and bigdataModuleId != ''">
        AND
            t1.bigdata_module_id = #{bigdataModuleId}
        </if>
        ORDER BY t1.gmt_create
    </select>

    <!-- 大数据展示模块列表 -->
    <select id="listBigdataModule" parameterType="map" resultMap="bigdataModuleDTO">
        SELECT
            t1.bigdata_module_code,
            t1.bigdata_module_photo,
            t1.bigdata_module_name,
            t1.bigdata_module_type,
            t1.bigdata_module_switch,
            t1.bigdata_module_content,
            t1.bigdata_module_remark,
            t1.bigdata_module_id,
            t1.bigdata_module_module_json,
            t1.bigdata_module_server_json,
            t1.bigdata_module_link,
            dt1.data_name bigdata_module_type_data_name
        FROM
            m_bigdata_module t1
        LEFT JOIN
            data_data dt1
        ON
            dt1.data_id = t1.bigdata_module_type
        AND
            dt1.is_delete = 0
        WHERE
            t1.is_delete = 0
        <if test="keywords != null and keywords != ''">
        AND (
            t1.bigdata_module_code LIKE CONCAT('%', #{keywords}, '%')
            OR
            t1.bigdata_module_name LIKE CONCAT('%', #{keywords}, '%')
            <!-- 这里添加其他条件 -->
        )
        </if>
        <if test="bigdataModuleLink != null and bigdataModuleLink != ''">
            AND t1.bigdata_module_link = #{bigdataModuleLink}
        </if>
        <if test="bigdataModuleType != null and bigdataModuleType != ''">
            AND t1.bigdata_module_type = #{bigdataModuleType}
        </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="bigdataModuleSwitch != null and bigdataModuleSwitch != ''">
            AND t1.bigdata_module_switch = #{bigdataModuleSwitch}
        </if>
        <if test="bigdataModuleIds != null and bigdataModuleIds.size > 0">
        AND
            t1.bigdata_module_id IN
            <foreach collection="bigdataModuleIds" index="index" open="(" separator="," close=")">
            #{bigdataModuleIds[${index}]}
            </foreach>
        </if>
        ORDER BY t1.gmt_create
    </select>

    <!-- 大数据展示模块统计  -->
    <select id="countBigdataModule" parameterType="map" resultType="Integer">
        SELECT
            COUNT(*)
        FROM
            m_bigdata_module t1
        WHERE
            t1.is_delete = 0
    </select>

</mapper>