<?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.picturestemplate.IPicturesTemplateDao">

    <resultMap id="picturesTemplateDTO" type="cn.com.tenlion.buildingpictures.pojo.dtos.picturestemplate.PicturesTemplateDTO">
        <id column="pictures_template_id" property="picturesTemplateId"/>
        <result column="pictures_template_code" property="picturesTemplateCode"/>
        <result column="pictures_template_background_image" property="picturesTemplateBackgroundImage"/>
        <result column="pictures_template_title" property="picturesTemplateTitle"/>
        <result column="pictures_template_height" property="picturesTemplateHeight"/>
        <result column="pictures_template_width" property="picturesTemplateWidth"/>
        <result column="pictures_template_publish_status" property="picturesTemplatePublishStatus"/>
        <result column="pictures_template_publish_time" property="picturesTemplatePublishTime"/>
        <result column="pictures_template_url" property="picturesTemplateUrl"/>
        <result column="pictures_template_content" property="picturesTemplateContent"/>
        <result column="pictures_template_file" property="picturesTemplateFile"/>
        <result column="pictures_template_back" property="picturesTemplateBack"/>
        <result column="pictures_template_size" property="picturesTemplateSize"/>
        <result column="pictures_template_picture" property="picturesTemplatePicture"/>
        <result column="pictures_template_picture_url" property="picturesTemplatePictureUrl"/>
        <result column="pictures_template_remark" property="picturesTemplateRemark"/>
    </resultMap>

    <resultMap id="picturesTemplateBuildingDTO" type="cn.com.tenlion.buildingpictures.pojo.dtos.picturestemplate.PicturesTemplateBuildingDTO">
        <id column="pictures_template_id" property="picturesTemplateId"/>
        <result column="pictures_template_code" property="picturesTemplateCode"/>
        <result column="pictures_template_background_image" property="picturesTemplateBackgroundImage"/>
        <result column="pictures_template_title" property="picturesTemplateTitle"/>
        <result column="pictures_template_height" property="picturesTemplateHeight"/>
        <result column="pictures_template_width" property="picturesTemplateWidth"/>
        <result column="pictures_template_publish_status" property="picturesTemplatePublishStatus"/>
        <result column="pictures_template_picture" property="picturesTemplatePicture"/>
        <result column="pictures_template_picture_url" property="picturesTemplatePictureUrl"/>
        <result column="pictures_template_remark" property="picturesTemplateRemark"/>
    </resultMap>

    <!-- 供外部接口调用使用 -->
    <select id="get" parameterType="map" resultMap="picturesTemplateBuildingDTO">
        SELECT
            t1.pictures_template_id,
            t1.pictures_template_code,
            t1.pictures_template_background_image,
            t1.pictures_template_title,
            t1.pictures_template_height,
            t1.pictures_template_width,
            t1.pictures_template_publish_status,
            t1.pictures_template_picture,
            t1.pictures_template_picture_url,
            t1.pictures_template_remark
        FROM
            m_pictures_template t1
        WHERE
            t1.is_delete = 0 AND t1.pictures_template_id = #{picturesTemplateId}
    </select>

    <!-- 供外部接口调用使用 -->
    <select id="list" parameterType="map" resultMap="picturesTemplateBuildingDTO">
        SELECT
            t1.pictures_template_id,
            t1.pictures_template_code,
            t1.pictures_template_background_image,
            t1.pictures_template_title,
            t1.pictures_template_height,
            t1.pictures_template_width,
            t1.pictures_template_publish_status,
           /* t1.pictures_template_picture,*/
            t1.pictures_template_picture_url,
            t1.pictures_template_remark
        FROM
            m_pictures_template t1
        WHERE
            t1.is_delete = 0
        <if test="keywords != null and keywords != ''">
            AND (
            t1.pictures_template_code LIKE CONCAT('%', #{keywords}, '%')
            OR
            t1.pictures_template_title LIKE CONCAT('%', #{keywords}, '%')
            <!-- 这里添加其他条件 -->
            )
        </if>
        <if test="picturesTemplatePublishStatus != null and picturesTemplatePublishStatus != ''">
            AND t1.pictures_template_publish_status = #{picturesTemplatePublishStatus}
        </if>
        <if test="picturesTemplateIds != null and picturesTemplateIds.size > 0">
            AND
            t1.pictures_template_id IN
            <foreach collection="picturesTemplateIds" index="index" open="(" separator="," close=")">
                #{picturesTemplateIds[${index}]}
            </foreach>
        </if>
        ORDER BY t1.gmt_create
    </select>

    <update id="updatePicturesTemplatePicture" parameterType="map">
        UPDATE
            m_pictures_template
        SET
            pictures_template_picture = #{picturesTemplatePicture},
            pictures_template_picture_url = #{picturesTemplatePictureUrl}
        WHERE
            pictures_template_id = #{picturesTemplateId}  AND is_delete = 0
    </update>

    <update id="updatePicturesTemplateContent" parameterType="map">
        UPDATE
            m_pictures_template
        SET
            pictures_template_content = #{picturesModuleContent}
        WHERE
            pictures_template_id = #{picturesTemplateId}  AND is_delete = 0
    </update>

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

    <update id="updatePicturesTemplatePublishStatus" parameterType="map">
        UPDATE
            m_pictures_template
        SET
            pictures_template_publish_status = #{picturesTemplatePublishStatus},
            pictures_template_publish_time = #{picturesTemplatePublishTime},
            modifier = #{modifier},
            gmt_modified = #{gmtModified}
        WHERE
            pictures_template_id = #{picturesTemplateId}  AND is_delete = 0
    </update>

    <update id="updataPicturesTemplateUrl" parameterType="map">
        UPDATE
            m_pictures_template
        SET
            pictures_template_url = #{picturesTemplateUrl}
        WHERE
            pictures_template_id = #{picturesTemplateId}  AND is_delete = 0
    </update>

    <select id="getPicturesTemplateByCode" parameterType="java.lang.String" resultMap="picturesTemplateDTO">
        SELECT
            t1.pictures_template_code,
            t1.pictures_template_background_image,
            t1.pictures_template_title,
            t1.pictures_template_height,
            t1.pictures_template_width,
            t1.pictures_template_publish_status,
            t1.pictures_template_publish_time,
            t1.pictures_template_url,
            t1.pictures_template_content,
            t1.pictures_template_id,
            t1.pictures_template_file,
            t1.pictures_template_back,
            t1.pictures_template_size,
            t1.pictures_template_picture,
            t1.pictures_template_picture_url,
            t1.pictures_template_remark
        FROM
            m_pictures_template t1
        WHERE
            t1.is_delete = 0 AND t1.pictures_template_code = #{picturesTemplateCode}
    </select>

    <!-- 新增图片套版的模板管理 -->
    <insert id="savePicturesTemplate" parameterType="map">
        INSERT INTO m_pictures_template(
            pictures_template_id,
            pictures_template_code,
            pictures_template_background_image,
            pictures_template_title,
            pictures_template_height,
            pictures_template_width,
            pictures_template_publish_status,
            pictures_template_publish_time,
            pictures_template_url,
            pictures_template_content,
            pictures_template_file,
            pictures_template_back,
            pictures_template_size,
            pictures_template_picture,
            pictures_template_remark,
            creator,
            gmt_create,
            modifier,
            gmt_modified,
            is_delete
        ) VALUES(
            #{picturesTemplateId},
            #{picturesTemplateCode},
            #{picturesTemplateBackgroundImage},
            #{picturesTemplateTitle},
            #{picturesTemplateHeight},
            #{picturesTemplateWidth},
            #{picturesTemplatePublishStatus},
            #{picturesTemplatePublishTime},
            #{picturesTemplateUrl},
            #{picturesTemplateContent},
            #{picturesTemplateFile},
            #{picturesTemplateBack},
            #{picturesTemplateSize},
            '',
            #{picturesTemplateRemark},
            #{creator},
            #{gmtCreate},
            #{modifier},
            #{gmtModified},
            #{isDelete}
        )
    </insert>

    <!-- 删除图片套版的模板管理 -->
    <update id="removePicturesTemplate" parameterType="map">
        UPDATE
            m_pictures_template
        SET
            is_delete = 1,
            modifier = #{modifier},
            gmt_modified = #{gmtModified}
        WHERE
            pictures_template_id IN
        <foreach collection="picturesTemplateIds" index="index" open="(" separator="," close=")">
            #{picturesTemplateIds[${index}]}
        </foreach>
    </update>

    <!-- 删除图片套版的模板管理（物理） -->
    <update id="deletePicturesTemplate" parameterType="map">
        DELETE FROM
            m_pictures_template
        WHERE
            pictures_template_id IN
        <foreach collection="picturesTemplateIds" index="index" open="(" separator="," close=")">
            #{picturesTemplateIds[${index}]}
        </foreach>
    </update>

    <!-- 修改图片套版的模板管理 -->
    <update id="updatePicturesTemplate" parameterType="map">
        UPDATE
            m_pictures_template
        SET
        <if test="picturesTemplateCode != null and picturesTemplateCode != ''">
            pictures_template_code = #{picturesTemplateCode},
        </if>
        <if test="picturesTemplateBackgroundImage != null and picturesTemplateBackgroundImage != ''">
            pictures_template_background_image = #{picturesTemplateBackgroundImage},
        </if>
        <if test="picturesTemplateTitle != null and picturesTemplateTitle != ''">
            pictures_template_title = #{picturesTemplateTitle},
        </if>
        <if test="picturesTemplateHeight != null">
            pictures_template_height = #{picturesTemplateHeight},
        </if>
        <if test="picturesTemplateWidth != null">
            pictures_template_width = #{picturesTemplateWidth},
        </if>
        <if test="picturesTemplateBack != null and picturesTemplateBack != ''">
            pictures_template_back = #{picturesTemplateBack},
        </if>
        <if test="picturesTemplateSize != null and picturesTemplateSize != ''">
            pictures_template_size = #{picturesTemplateSize},
        </if>
        <if test="picturesTemplateRemark != null and picturesTemplateRemark != ''">
            pictures_template_remark = #{picturesTemplateRemark},
        </if>
            pictures_template_file = #{picturesTemplateFile},
            modifier = #{modifier},
            gmt_modified = #{gmtModified}
        WHERE
            pictures_template_id = #{picturesTemplateId}
    </update>

    <!-- 图片套版的模板管理详情 -->
    <select id="getPicturesTemplate" parameterType="map" resultMap="picturesTemplateDTO">
        SELECT
            t1.pictures_template_code,
            t1.pictures_template_background_image,
            t1.pictures_template_title,
            t1.pictures_template_height,
            t1.pictures_template_width,
            t1.pictures_template_publish_status,
            t1.pictures_template_publish_time,
            t1.pictures_template_url,
            t1.pictures_template_content,
            t1.pictures_template_id,
            t1.pictures_template_file,
            t1.pictures_template_back,
            t1.pictures_template_size,
            t1.pictures_template_picture,
            t1.pictures_template_picture_url,
            t1.pictures_template_remark
        FROM
            m_pictures_template t1
        WHERE
            t1.is_delete = 0
        <if test="picturesTemplateId != null and picturesTemplateId != ''">
        AND
            t1.pictures_template_id = #{picturesTemplateId}
        </if>
        ORDER BY t1.gmt_create
    </select>

    <!-- 图片套版的模板管理列表 -->
    <select id="listPicturesTemplate" parameterType="map" resultMap="picturesTemplateDTO">
        SELECT
            t1.pictures_template_code,
            t1.pictures_template_background_image,
            t1.pictures_template_title,
            t1.pictures_template_height,
            t1.pictures_template_width,
            t1.pictures_template_publish_status,
            t1.pictures_template_publish_time,
            t1.pictures_template_url,
            t1.pictures_template_content,
            t1.pictures_template_id,
            t1.pictures_template_file,
            t1.pictures_template_back,
            t1.pictures_template_size,
            t1.pictures_template_picture,
            t1.pictures_template_picture_url,
            t1.pictures_template_remark
        FROM
            m_pictures_template t1
        WHERE
            t1.is_delete = 0
        <if test="keywords != null and keywords != ''">
        AND (
            t1.pictures_template_code LIKE CONCAT('%', #{keywords}, '%')
            OR
            t1.pictures_template_title LIKE CONCAT('%', #{keywords}, '%')
            <!-- 这里添加其他条件 -->
        )
        </if>
        <if test="picturesTemplatePublishStatus != null and picturesTemplatePublishStatus != ''">
            AND t1.pictures_template_publish_status = #{picturesTemplatePublishStatus}
        </if>
        <if test="noGetpicturesTemplateId != null and noGetpicturesTemplateId != ''">
            AND t1.pictures_template_id != #{noGetpicturesTemplateId} AND t1.pictures_template_url IS NOT NULL AND t1.pictures_template_url != '' AND t1.pictures_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="picturesTemplateIds != null and picturesTemplateIds.size > 0">
        AND
            t1.pictures_template_id IN
            <foreach collection="picturesTemplateIds" index="index" open="(" separator="," close=")">
            #{picturesTemplateIds[${index}]}
            </foreach>
        </if>
        ORDER BY t1.gmt_create
    </select>

    <!-- 图片套版的模板管理统计  -->
    <select id="countPicturesTemplate" parameterType="map" resultType="Integer">
        SELECT
            COUNT(*)
        FROM
            m_pictures_template t1
        WHERE
            t1.is_delete = 0
    </select>

</mapper>