<?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.yida.data.school.atlas.mapper.CoreAtlasManagementMapper">
    <!-- 查询图集列表数据 -->
    <select id="listAtlasPage" resultType="com.yida.data.school.vo.atlas.AtlasSelectPageVO">
        select
        id,
        atlas_name, atlas_cover_img_url, atlas_background_img_url, atlas_Introduction,
        enable_status, access_num, like_num, forward_num, comment_num, create_date, school_id
        FROM core_atlas_management
        <where>
            del_flag = 0
            <if test="dto.atlasName != null and dto.atlasName != ''">
                and instr(atlas_name, #{dto.atlasName})
            </if>
            <if test="dto.enableStatus != null">
                and enable_status = #{dto.enableStatus}
            </if>
            <choose>
                <when test="dto.startCreateDate != null and dto.endCreateDate != null">
                    and create_date between #{dto.startCreateDate} and #{dto.endCreateDate}
                </when>
                <when test="dto.startCreateDate != null">
                    and create_date &gt; #{dto.startCreateDate}
                </when>
                <when test="dto.endCreateDate != null">
                    and create_date &lt; #{dto.endCreateDate}
                </when>
            </choose>
            and school_id = #{dto.schoolId}
        </where>
        ORDER BY enable_status, update_date desc
    </select>

    <!-- 增加图集的总评论数 -->
    <update id="updateCommentCount">
        update core_atlas_management
        set comment_num = comment_num + #{changeCount}
        where id = #{atlasId}
    </update>

    <!-- 增加图集的总点赞数 -->
    <update id="updateLikeCount">
        update core_atlas_management
        set like_num = like_num + #{changeCount}
        where id = #{atlasId}
    </update>
</mapper>