<?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.storlead.sales.mapper.customer.RecordCommentMapper">

        <!-- 通用查询映射结果 -->
        <resultMap id="BaseResultMap" type="com.storlead.sales.pojo.entity.customer.RecordCommentEntity">
                    <id column="id" property="id" />
                <result column="create_time" property="createTime" />
                <result column="update_time" property="updateTime" />
                <result column="is_delete" property="isDelete" />
                <result column="enabled" property="enabled" />
                <result column="create_by" property="createBy" />
                <result column="owner_by" property="ownerBy" />
                <result column="update_by" property="updateBy" />
                <result column="sort" property="sort" />
                    <result column="record_id" property="recordId" />
                    <result column="type" property="type" />
                    <result column="staff_id" property="staffId" />
                    <result column="top_id" property="topId" />
                    <result column="parent_id" property="parentId" />
                    <result column="content" property="content" />
                    <result column="score" property="score" />
        </resultMap>

        <!-- 通用查询结果列 -->
        <sql id="Base_Column_List">
                create_time,
                update_time,
                is_delete,
                enabled,
                create_by,
                owner_by,
                update_by,
                sort,
            id, record_id, type, staff_id, top_id, parent_id, content, score
        </sql>


    <update id="removeByParentid">
        UPDATE record_comment set is_delete = 1 WHERE id in (select id from (
                                                                                select t1.id,
                                                                                       if(find_in_set(parent_id, @pids) > 0, @pids := concat(@pids, ',', id), 0) as ischild
                                                                                from (
                                                                                         select id,parent_id from record_comment t where t.is_delete = 0 order by parent_id, id
                                                                                     ) t1,
                                                                                     (select @pids := #{id}) t2
                                                                            ) t3 where ischild != 0
        )
    </update>


    <!--	<select id="getList" resultMap="BaseResultMap">-->

    <!--	</select>-->
    <select id="getChildComment" resultType="com.storlead.sales.pojo.vo.customer.RecordCommentVO">
        SELECT sc.id,sc.record_id,sc.type,sc.staff_id,u.real_name AS staff_name,u.avatar AS staff_photo,sc.content,
        sc.top_id,sc.parent_id,sc.create_time,up.real_name AS staff_parent_name,sc.owner_by
        FROM `record_comment` sc
        LEFT JOIN user u ON sc.staff_id = u.id
        LEFT JOIN `record_comment` scp ON scp.id = sc.parent_id
        LEFT JOIN user up ON scp.staff_id = up.id
        WHERE sc.top_id IN
        <foreach collection="recordParentIds" index="index" item="id" separator="," close=")" open="(">
            #{id}
        </foreach>
        AND sc.is_delete = 0
        ORDER BY sc.create_time ASC
    </select>

</mapper>
