<?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.buildingpictures.dao.picturestemplatearea.IPicturesTemplateAreaDao">

    <resultMap id="picturesTemplateAreaDTO" type="cn.com.tenlion.buildingpictures.pojo.dtos.picturestemplatearea.PicturesTemplateAreaDTO">
        <id column="pictures_template_area_id" property="picturesTemplateAreaId"/>
        <result column="pictures_template_id" property="picturesTemplateId"/>
        <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="pictures_template_title" property="picturesTemplateTitle"/>
        <result column="template_area_file" property="templateAreaFile"/>
        <result column="template_area_server_link" property="templateAreaServerLink"/>
        <result column="pictures_template_code" property="picturesTemplateCode"/>
        <result column="template_area_font_center" property="templateAreaFontCenter"/>
        <result column="template_area_font_size" property="templateAreaFontSize"/>
        <result column="template_area_font_bold" property="templateAreaFontBold"/>
        <result column="template_area_font_family" property="templateAreaFontFamily"/>
        <result column="template_area_font_color" property="templateAreaFontColor"/>
        <result column="template_area_font_value" property="templateAreaFontValue"/>
        <result column="template_area_name" property="templateAreaName"/>
        <result column="template_area_type" property="templateAreaType"/>
        <result column="template_area_font_length" property="templateAreaFontLength"/>
</resultMap>

    <resultMap id="picturesTemplateAreaBuildingDTO" type="cn.com.tenlion.buildingpictures.pojo.dtos.picturestemplatearea.PicturesTemplateAreaBuildingDTO">
        <id column="pictures_template_area_id" property="picturesTemplateAreaId"/>
        <result column="pictures_template_id" property="picturesTemplateId"/>
        <result column="template_area_name" property="templateAreaName"/>
        <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_server_link" property="templateAreaServerLink"/>
        <result column="template_area_font_family" property="templateAreaFontFamily"/>
        <result column="template_area_font_color" property="templateAreaFontColor"/>
        <result column="template_area_font_size" property="templateAreaFontSize"/>
        <result column="template_area_font_length" property="templateAreaFontLength"/>
        <result column="template_area_font_bold" property="templateAreaFontBold"/>
        <result column="template_area_font_center" property="templateAreaFontCenter"/>
        <result column="template_area_font_value" property="templateAreaFontValue"/>
        <result column="template_area_file" property="templateAreaFile"/>
        <result column="template_area_type" property="templateAreaType"/>
        <result column="template_area_remark" property="templateAreaRemark"/>
    </resultMap>

    <!-- 供外部接口调用使用 -->
    <select id="list" parameterType="map" resultMap="picturesTemplateAreaBuildingDTO">
        SELECT
            t1.pictures_template_area_id,
            t1.pictures_template_id,
            t1.template_area_name,
            t1.template_area_source,
            t1.template_area_left,
            t1.template_area_top,
            t1.template_area_down,
            t1.template_area_right,
            t1.template_area_height,
            t1.template_area_width,
            t1.template_area_color,
            t1.template_area_server_link,
            t1.template_area_font_family,
            t1.template_area_font_color,
            t1.template_area_font_size,
            t1.template_area_font_bold,
            t1.template_area_font_center,
            t1.template_area_font_value,
            t1.template_area_file,
            t1.template_area_type,
            t1.template_area_remark,
            t1.template_area_font_length
        FROM
            m_pictures_template_area t1
        WHERE
            t1.is_delete = 0
        <if test="keywords != null and keywords != ''">
            AND (
            t1.template_area_name LIKE CONCAT('%', #{keywords}, '%')
            OR
            t1.template_area_source LIKE CONCAT('%', #{keywords}, '%')
            <!-- 这里添加其他条件 -->
            )
        </if>
        <if test="picturesTemplateId != null and picturesTemplateId != ''">
            AND t1.pictures_template_id = #{picturesTemplateId}
        </if>
        <if test="picturesTemplateAreaIds != null and picturesTemplateAreaIds.size > 0">
            AND
            t1.pictures_template_area_id IN
            <foreach collection="picturesTemplateAreaIds" index="index" open="(" separator="," close=")">
                #{picturesTemplateAreaIds[${index}]}
            </foreach>
        </if>
        order by t1.gmt_create
    </select>

    <update id="updatePicturesTemplateAreaFontLength" parameterType="map">
        UPDATE
             m_pictures_template_area
        SET
            template_area_font_length = #{templateAreaFontLength}
        WHERE
            pictures_template_area_id = #{picturesTemplateAreaId}
    </update>

    <update id="updatePicturesTemplateAreaAll" parameterType="map">
        UPDATE
            m_pictures_template_area
        SET
            modifier = #{modifier},
        <if test="templateAreaFontColor != null and templateAreaFontColor != ''">
            template_area_font_color = #{templateAreaFontColor},
        </if>
        <if test="templateAreaFontFamily != null and templateAreaFontFamily != ''">
            template_area_font_family = #{templateAreaFontFamily},
        </if>
        <if test="templateAreaFontBold != null and templateAreaFontBold != ''">
            template_area_font_bold = #{templateAreaFontBold},
        </if>
        <if test="templateAreaFontSize != null and templateAreaFontSize != ''">
            template_area_font_size = #{templateAreaFontSize},
        </if>
        <if test="templateAreaFontCenter != null and templateAreaFontCenter != ''">
            template_area_font_center = #{templateAreaFontCenter},
        </if>
            gmt_modified = #{gmtModified}
        WHERE
            pictures_template_id = #{picturesTemplateId}
    </update>

    <!-- 修改展览模板区域配置 -->
    <update id="updatePicturesTemplateAreaPointModuleData" parameterType="map">
        UPDATE
            m_pictures_template_area
        SET
            template_area_module_data = #{templateAreaModuleData},
            modifier = #{modifier},
            gmt_modified = #{gmtModified}
        WHERE
            pictures_template_area_id = #{picturesTemplateAreaId}
    </update>

    <!-- 修改展览模板区域 -->
    <update id="updatePicturesTemplateAreaPoint" parameterType="map">
        UPDATE
            m_pictures_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
            pictures_template_area_id = #{picturesTemplateAreaId}
    </update>

    <!-- 图片套版模板的区域设置详情 -->
    <select id="getPicturesTemplateAreaByPicturesTemplateCode" parameterType="java.lang.String" resultMap="picturesTemplateAreaDTO">
        SELECT
        t1.pictures_template_area_id,
        t1.pictures_template_id,
        t1.template_area_source,
        t1.template_area_color,
        t1.template_area_remark,
        t1.template_area_status,
        t1.template_area_left,
        t1.template_area_top,
        t1.template_area_down,
        t1.template_area_right,
        t1.template_area_height,
        t1.template_area_width,
        t1.template_area_file,
        t1.template_area_server_link,
        t1.template_area_font_center,
        t1.template_area_font_size,
        t1.template_area_font_bold,
        t1.template_area_font_family,
        t1.template_area_font_color,
        t1.template_area_font_value,
        t1.template_area_name,
        t1.template_area_type,
        t1.template_area_font_length,
        t2.pictures_template_code
        FROM
        m_pictures_template_area t1
        LEFT JOIN
        m_pictures_template t2
        ON
        t1.pictures_template_id = t2.pictures_template_id
        WHERE
        t1.is_delete = 0 AND t2.pictures_template_code = #{picturesTemplateCode}
        ORDER BY t1.gmt_create
    </select>


    <!-- 图片套版模板的区域设置详情 -->
    <select id="getPicturesTemplateAreaByPicturesTemplateId" parameterType="map" resultMap="picturesTemplateAreaDTO">
        SELECT
            t1.pictures_template_area_id,
            t1.pictures_template_id,
            t1.template_area_source,
            t1.template_area_color,
            t1.template_area_remark,
            t1.template_area_status,
            t1.template_area_left,
            t1.template_area_top,
            t1.template_area_down,
            t1.template_area_right,
            t1.template_area_height,
            t1.template_area_width,
            t1.template_area_file,
            t1.template_area_server_link,
            t1.template_area_font_center,
            t1.template_area_font_size,
            t1.template_area_font_bold,
            t1.template_area_font_family,
            t1.template_area_font_color,
            t1.template_area_font_value,
            t1.template_area_name,
            t1.template_area_type,
            t1.template_area_font_length
        FROM
        m_pictures_template_area t1
        WHERE
            t1.is_delete = 0
        <if test="picturesTemplateId != null and picturesTemplateId != ''">
            AND
            t1.pictures_template_id = #{picturesTemplateId}
        </if>
        <if test="templateAreaSource != null and templateAreaSource != ''">
            AND
            t1.template_area_source = #{templateAreaSource}
        </if>
        ORDER BY t1.gmt_create
    </select>

    <!-- 新增图片套版模板的区域设置 -->
    <insert id="savePicturesTemplateArea" parameterType="map">
        INSERT INTO m_pictures_template_area(
            pictures_template_area_id,
            pictures_template_id,
            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_file,
            template_area_server_link,
            template_area_font_center,
            template_area_font_size,
            template_area_font_bold,
            template_area_font_family,
            template_area_font_color,
            template_area_font_value,
            template_area_name,
            template_area_type,
            template_area_font_length,
            creator,
            gmt_create,
            modifier,
            gmt_modified,
            is_delete
        ) VALUES(
            #{picturesTemplateAreaId},
            #{picturesTemplateId},
            #{templateAreaSource},
            #{templateAreaLeft},
            #{templateAreaTop},
            #{templateAreaDown},
            #{templateAreaRight},
            #{templateAreaHeight},
            #{templateAreaWidth},
            #{templateAreaColor},
            #{templateAreaRemark},
            #{templateAreaStatus},
            #{templateAreaFile},
            #{templateAreaServerLink},
            #{templateAreaFontCenter},
            #{templateAreaFontSize},
            #{templateAreaFontBold},
            #{templateAreaFontFamily},
            #{templateAreaFontColor},
            #{templateAreaFontValue},
            #{templateAreaName},
            #{templateAreaType},
            #{templateAreaFontLength},
            #{creator},
            #{gmtCreate},
            #{modifier},
            #{gmtModified},
            #{isDelete}
        )
    </insert>

    <!-- 删除图片套版模板的区域设置 -->
    <update id="removePicturesTemplateArea" parameterType="map">
        UPDATE
        m_pictures_template_area
        SET
            is_delete = 1,
            modifier = #{modifier},
            gmt_modified = #{gmtModified}
        WHERE
            pictures_template_area_id IN
        <foreach collection="picturesTemplateAreaIds" index="index" open="(" separator="," close=")">
            #{picturesTemplateAreaIds[${index}]}
        </foreach>
    </update>

    <!-- 删除图片套版模板的区域设置（物理） -->
    <update id="deletePicturesTemplateArea" parameterType="map">
        DELETE FROM
        m_pictures_template_area
        WHERE
            pictures_template_area_id IN
        <foreach collection="picturesTemplateAreaIds" index="index" open="(" separator="," close=")">
            #{picturesTemplateAreaIds[${index}]}
        </foreach>
    </update>

    <!-- 修改图片套版模板的区域设置 -->
    <update id="updatePicturesTemplateArea" parameterType="map">
        UPDATE
        m_pictures_template_area
        SET
        <if test="templateAreaColor != null and templateAreaColor != ''">
            template_area_color = #{templateAreaColor},
        </if>
        <if test="templateAreaSource != null and templateAreaSource != ''">
            template_area_source = #{templateAreaSource},
        </if>
        <if test="templateAreaFontCenter != null and templateAreaFontCenter != ''">
            template_area_font_center = #{templateAreaFontCenter},
        </if>
        <if test="templateAreaFontSize != null and templateAreaFontSize != ''">
            template_area_font_size = #{templateAreaFontSize},
        </if>
        <if test="templateAreaFontBold != null and templateAreaFontBold != ''">
            template_area_font_bold = #{templateAreaFontBold},
        </if>
        <if test="templateAreaFontFamily != null and templateAreaFontFamily != ''">
            template_area_font_family = #{templateAreaFontFamily},
        </if>
        <if test="templateAreaFontColor != null and templateAreaFontColor != ''">
            template_area_font_color = #{templateAreaFontColor},
        </if>
        <if test="templateAreaName != null and templateAreaName != ''">
            template_area_name = #{templateAreaName},
        </if>
        <if test="templateAreaType != null and templateAreaType != ''">
            template_area_type = #{templateAreaType},
        </if>
        <if test="templateAreaFontLength != null and templateAreaFontLength != ''">
            template_area_font_length = #{templateAreaFontLength},
        </if>
            template_area_font_value = #{templateAreaFontValue},
            template_area_remark = #{templateAreaRemark},
            template_area_file = #{templateAreaFile},
            template_area_server_link = #{templateAreaServerLink},
            modifier = #{modifier},
            gmt_modified = #{gmtModified}
        WHERE
            pictures_template_area_id = #{picturesTemplateAreaId}
    </update>

    <!-- -停止使用 2021年7月1日14:52:48 -->
    <select id="getPicturesTemplateIdGroupByPicturesModuleId" parameterType="map" resultMap="picturesTemplateAreaDTO">
        SELECT
            t1.pictures_template_id,
            t1.template_area_source,
            t1.template_area_color,
            t1.template_area_remark,
            t1.template_area_status,
            t1.pictures_template_area_id,
            t3.pictures_template_title,
            t3.pictures_template_code,
            t1.template_area_file,
            t1.template_area_server_link,
            t1.template_area_font_center,
            t1.template_area_font_size,
            t1.template_area_font_bold,
            t1.template_area_font_family,
            t1.template_area_font_color,
            t1.template_area_font_value,
            t1.template_area_name,
            t1.template_area_type,
            t1.template_area_font_length
        FROM
        m_pictures_template_area t1
        LEFT JOIN
        m_pictures_template t3
        ON
        t1.pictures_template_id = t3.pictures_template_id
        WHERE
        t1.is_delete = 0 AND t1.pictures_module_id = #{picturesModuleId}
        GROUP BY t1.pictures_template_id
    </select>

    <!-- 图片套版模板的区域设置详情 -->
    <select id="getPicturesTemplateArea" parameterType="map" resultMap="picturesTemplateAreaDTO">
        SELECT
            t1.pictures_template_area_id,
            t1.pictures_template_id,
            t1.template_area_source,
            t1.template_area_left,
            t1.template_area_top,
            t1.template_area_down,
            t1.template_area_right,
            t1.template_area_height,
            t1.template_area_width,
            t1.template_area_color,
            t1.template_area_remark,
            t1.template_area_status,
            t3.pictures_template_title,
            t1.template_area_file,
            t1.template_area_server_link,
            t1.template_area_font_center,
            t1.template_area_font_size,
            t1.template_area_font_bold,
            t1.template_area_font_family,
            t1.template_area_font_color,
            t1.template_area_font_value,
            t1.template_area_name,
            t1.template_area_type,
            t1.template_area_font_length
        FROM
            m_pictures_template_area t1
        LEFT JOIN
            m_pictures_template t3
        ON
            t1.pictures_template_id = t3.pictures_template_id
        WHERE
            t1.is_delete = 0
        <if test="picturesTemplateAreaId != null and picturesTemplateAreaId != ''">
        AND
            t1.pictures_template_area_id = #{picturesTemplateAreaId}
        </if>
    </select>

    <!-- 图片套版模板的区域设置列表 -->
    <select id="listPicturesTemplateArea" parameterType="map" resultMap="picturesTemplateAreaDTO">
        SELECT
            t1.pictures_template_area_id,
            t1.pictures_template_id,
            t1.template_area_source,
            t1.template_area_left,
            t1.template_area_top,
            t1.template_area_down,
            t1.template_area_right,
            t1.template_area_height,
            t1.template_area_width,
            t1.template_area_color,
            t1.template_area_remark,
            t1.template_area_status,
            t1.template_area_file,
            t1.template_area_server_link,
            t1.template_area_font_center,
            t1.template_area_font_size,
            t1.template_area_font_bold,
            t1.template_area_font_family,
            t1.template_area_font_color,
            t1.template_area_font_value,
            t1.template_area_name,
            t1.template_area_type,
            t1.template_area_font_length
        FROM
            m_pictures_template_area t1
        WHERE
            t1.is_delete = 0
        <if test="keywords != null and keywords != ''">
        AND (
            t1.id LIKE CONCAT('%', #{keywords}, '%')
            OR
            t1.pictures_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="picturesTemplateAreaIds != null and picturesTemplateAreaIds.size > 0">
        AND
            t1.pictures_template_area_id IN
            <foreach collection="picturesTemplateAreaIds" index="index" open="(" separator="," close=")">
            #{picturesTemplateAreaIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- 图片套版模板的区域设置统计  -->
    <select id="countPicturesTemplateArea" parameterType="map" resultType="Integer">
        SELECT
            COUNT(*)
        FROM
            m_pictures_template_area t1
        WHERE
            t1.is_delete = 0
    </select>

</mapper>