feat: 实现情绪记录功能和聊天历史查看
- 完成情绪记录生成功能,支持AI分析聊天内容生成情绪记录 - 实现聊天页面历史记录查看,支持分页和搜索 - 修改日记页面展示情绪记录而非普通日记 - 添加情绪记录的增删改查API - 优化前端UI,添加情绪强度显示和详细信息展示 - 修复SCSS变量缺失问题
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
package com.emotion.controller;
|
||||
|
||||
import com.emotion.common.Result;
|
||||
import com.emotion.service.AIChatService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 情绪总结控制器
|
||||
*
|
||||
* @author emotion-museum
|
||||
* @date 2025-07-25
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/api/emotion-summary")
|
||||
@Tag(name = "情绪总结管理", description = "用户情绪记录总结和分析功能")
|
||||
public class EmotionSummaryController {
|
||||
|
||||
@Autowired
|
||||
private AIChatService aiChatService;
|
||||
|
||||
@Operation(summary = "生成用户当天的情绪记录总结", description = "基于用户当天的聊天记录生成情绪分析和记录")
|
||||
@PostMapping("/generate/{userId}")
|
||||
public Result<Map<String, Object>> generateEmotionSummary(
|
||||
@Parameter(description = "用户ID") @PathVariable String userId) {
|
||||
|
||||
log.info("收到生成情绪记录总结请求: userId={}", userId);
|
||||
|
||||
try {
|
||||
// 调用AI服务生成情绪总结
|
||||
Map<String, Object> result = aiChatService.generateEmotionSummary(userId);
|
||||
|
||||
if ((Boolean) result.get("success")) {
|
||||
log.info("情绪记录总结生成成功: userId={}", userId);
|
||||
return Result.success(result, "情绪记录总结生成成功");
|
||||
} else {
|
||||
String message = (String) result.get("message");
|
||||
log.warn("情绪记录总结生成失败: userId={}, message={}", userId, message);
|
||||
return Result.error(message);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("生成情绪记录总结时发生异常: userId={}", userId, e);
|
||||
return Result.error("生成情绪记录总结失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "获取用户情绪记录总结状态", description = "检查用户今天是否已经生成过情绪记录")
|
||||
@GetMapping("/status/{userId}")
|
||||
public Result<Map<String, Object>> getEmotionSummaryStatus(
|
||||
@Parameter(description = "用户ID") @PathVariable String userId) {
|
||||
|
||||
log.info("查询用户情绪记录总结状态: userId={}", userId);
|
||||
|
||||
try {
|
||||
// 这里可以添加检查用户今天是否已经生成过情绪记录的逻辑
|
||||
// 暂时返回基本状态信息
|
||||
Map<String, Object> status = Map.of(
|
||||
"userId", userId,
|
||||
"canGenerate", true,
|
||||
"message", "可以生成情绪记录总结"
|
||||
);
|
||||
|
||||
return Result.success(status);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("查询情绪记录总结状态时发生异常: userId={}", userId, e);
|
||||
return Result.error("查询状态失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user