<?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.CoreAtlasManagementDetailsCommentMapper">
    <resultMap id="commentMap" type="com.yida.data.school.vo.atlas.AtlasDetailsCommentSelectPageVO">
        <id column="id" property="id"/>
        <result column="content" property="content"/>
        <result column="create_date" property="createDate"/>
        <result column="check_status" property="checkStatus"/>
        <result column="user_id" property="userId"/>
        <result column="user_name" property="userName"/>
        <result column="nick_name" property="nickName"/>
        <association property="replyCount" select="getReplyCount" column="id" javaType="java.lang.Integer"
                     jdbcType="INTEGER"/>
        <association property="replyNotCheckCount" select="getReplyNotCheckCount" column="id"
                     javaType="java.lang.Integer" jdbcType="INTEGER"/>
    </resultMap>

    <!-- app分页查询图集作品评论列表接口 -->
    <select id="appListAtlasWorkCommentPage"
            resultType="com.yida.data.school.vo.atlas.app.AppAtlasWorkCommentPageVO">
        select id,
        content,
        create_date,
        user_id,
        user_name,
        nick_name
        from core_atlas_management_details_comment
        where del_flag = 0
        and check_status = '1'
        and core_atlas_management_details_id = #{dto.atlasDetailsId}
        order by create_date desc
    </select>

    <!-- 查询作品评论列表数据 -->
    <select id="listAtlasDetailsCommentPage"
            resultMap="commentMap">
        select id,
        content,
        create_date,
        check_status,
        user_id,
        user_name,
        nick_name
        from core_atlas_management_details_comment
        where del_flag = 0
        <if test='dto.checkStatus != null and dto.checkStatus != ""'>
            and check_status = #{dto.checkStatus}
        </if>
        <if test='dto.content != null and dto.content != ""'>
            and content like concat('%', #{dto.content}, '%')
        </if>
        and core_atlas_management_details_id = #{dto.atlasDetailsId}
        order by create_date desc
    </select>

    <!-- 查询评论回复数量 -->
    <select id="getReplyCount" parameterType="java.lang.Integer"
            resultType="java.lang.Integer">
        select
        count(id)
        from
        core_atlas_management_details_comment_reply
        where del_flag = 0
        and core_atlas_management_details_comment_id = #{id}
    </select>

    <!-- 查询评论回复未审核数量 -->
    <select id="getReplyNotCheckCount" parameterType="java.lang.Integer"
            resultType="java.lang.Integer">
        select
        count(id)
        from
        core_atlas_management_details_comment_reply
        where del_flag = 0
        and core_atlas_management_details_comment_id = #{id}
        and check_status not in ('1')
    </select>
</mapper>