package shop.alien.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import shop.alien.entity.store.LifeLog;
import shop.alien.entity.store.vo.FeedbackLogVo;

import java.util.List;

/**
 * 日志
 */
@Mapper
public interface LifeLogMapper extends BaseMapper<LifeLog> {

    /**
     * 根据反馈ID查询操作日志列表
     * @param feedbackId 反馈ID
     * @return 日志列表
     */
    @Select("SELECT l.id, l.type, l.context, l.created_time AS createdTime, " +
            "CASE l.type " +
            "   WHEN 0 THEN '问题解决状态' " +
            "   WHEN 1 THEN '分配跟踪人员' " +
            "   WHEN 2 THEN '创建反馈工单' " +
            "   WHEN 3 THEN '回复用户' " +
            "END AS typeName, " +
            "s.user_name AS operatorName " +
            "FROM life_log l " +
            "LEFT JOIN life_sys s ON l.created_user_id = s.id " +
            "WHERE l.feedback_id = #{feedbackId} AND l.delete_flag = 0 " +
            "ORDER BY l.created_time DESC")
    List<FeedbackLogVo> selectLogsByFeedbackId(@Param("feedbackId") Integer feedbackId);
}