<?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.zbkj.service.dao.StoreProductProblemDao">

    <select id="getResponseList" resultType="com.zbkj.common.response.ProductProblemResponse">
        select
            c.id majorId,
            u.uid userId,
            u.nickname nickName,
            u.avatar,
            c.title,
            c.content,
            DATE_FORMAT(c.create_time, '%Y-%m-%d %H:%i:%s') createTime,
            (select count(1) from eb_store_product_problem c1 where c1.top_id = c.id and c1.top_id <![CDATA[ <> ]]> 0 and c1.is_del = 0) sonNum
        from eb_store_product_problem c
        LEFT JOIN eb_user u on c.uid = u.uid
        where FIND_IN_SET(#{id}, business_id) and parent_id = 0 and c.is_del = 0 ORDER BY c.create_time DESC
    </select>

    <select id="getSonResponseList" resultType="com.zbkj.common.response.ProductProblemResponse">
        select
            a.id majorId,
            u.uid userId,
            u.nickname nickName,
            u.avatar,
            a.title,
            a.content,
            DATE_FORMAT(a.create_time, '%Y-%m-%d %H:%i:%s') createTime,
            u1.nickname beReplier
        from eb_store_product_problem as a
        left join eb_store_product_problem a1 on a.parent_id = a1.id
        left join eb_user u on a.uid = u.uid
        left join eb_user u1 on a1.uid = u1.uid
        where a.top_id = #{id} and a.is_del = 0
        order by a.create_time
    </select>

</mapper>
