<?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.iocoder.yudao.module.knowledge.mapper.TExpertZoneCommentMapper">

    <resultMap type="cn.iocoder.yudao.module.knowledge.entity.TExpertZoneComment" id="tExpertZoneCommentMap">
            <result property="id" column="id"/>
            <result property="expertZoneId" column="expert_zone_id"/>
            <result property="commentLevel" column="comment_level"/>
            <result property="commentContent" column="comment_content"/>
            <result property="userId" column="user_id"/>
            <result property="createTime" column="create_time"/>
            <result property="updateTime" column="update_time"/>
            <result property="deptId" column="dept_id"/>
            <result property="identityId" column="identity_id"/>
            <result property="deleted" column="deleted"/>
    </resultMap>

    <!-- 用于select查询公用抽取的列 -->
    <sql id="columns">
        id,expert_zone_id,comment_level,comment_content,user_id,create_time,update_time,dept_id,identity_id,deleted,comment_type,comment_username
    </sql>
    <select id="findList" resultMap="tExpertZoneCommentMap">
        select
        <include refid="columns"/>
        from t_expert_zone_comment
        <where>
            deleted = 0
                    <if test="params.expertZoneId != null">
                      and  expert_zone_id = #{params.expertZoneId}
                    </if>
                    <if test="params.commentLevel != null and params.commentLevel != ''">
                        and    comment_level = #{params.commentLevel}
                    </if>
                    <if test="params.commentContent != null and params.commentContent != ''">
                        and    comment_content = #{params.commentContent}
                    </if>
                    <if test="params.userId != null">
                        and  user_id = #{params.userId}
                    </if>
                    <if test="params.pid == null">
                        and  pid is NULL
                    </if>
                    <if test="params.createTime != null">
                        and  create_time = #{params.createTime}
                    </if>
        </where>
        ORDER BY create_time ASC
    </select>
    <select id="selectTotalByZoneId" resultType="java.lang.Integer">
        SELECT COUNT(1) FROM t_expert_zone_comment WHERE expert_zone_id = #{zoneId} AND deleted = 0
    </select>
    <select id="selectList" resultType="cn.iocoder.yudao.module.knowledge.entity.TExpertZoneComment">
        select
        <include refid="columns"/>
        from t_expert_zone_comment
        <where>
            deleted = 0
            <if test="params.expertZoneId != null">
                and  expert_zone_id = #{params.expertZoneId}
            </if>
            <if test="params.commentLevel != null and params.commentLevel != ''">
                and    comment_level = #{params.commentLevel}
            </if>
            <if test="params.commentContent != null and params.commentContent != ''">
                and    comment_content = #{params.commentContent}
            </if>
            <if test="params.userId != null">
                and  user_id = #{params.userId}
            </if>
            <if test="params.pid != null">
                and  pid = #{params.pid}
            </if>
            <if test="params.createTime != null">
                and  create_time = #{params.createTime}
            </if>
        </where>
        ORDER BY create_time ASC
    </select>

</mapper>
