优化
This commit is contained in:
+6
-116
@@ -8,14 +8,10 @@ import com.emotion.dto.request.EmotionAnalysisUpdateRequest;
|
||||
import com.emotion.dto.response.EmotionAnalysisResponse;
|
||||
import com.emotion.service.EmotionAnalysisService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.validation.Valid;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -25,7 +21,7 @@ import java.util.List;
|
||||
* @date 2025-07-23
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/emotion-analysis")
|
||||
@RequestMapping("/emotionAnalysis")
|
||||
public class EmotionAnalysisController {
|
||||
|
||||
@Autowired
|
||||
@@ -34,25 +30,15 @@ public class EmotionAnalysisController {
|
||||
/**
|
||||
* 分页查询情绪分析记录
|
||||
*/
|
||||
@GetMapping("/page")
|
||||
@GetMapping(value = "/page")
|
||||
public Result<PageResult<EmotionAnalysisResponse>> getPage(@Validated EmotionAnalysisPageRequest request) {
|
||||
return Result.success(emotionAnalysisService.getPageWithResponse(request));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户ID分页查询情绪分析记录
|
||||
*/
|
||||
@GetMapping("/user/page")
|
||||
public Result<PageResult<EmotionAnalysisResponse>> getPageByUserId(
|
||||
@RequestParam String userId,
|
||||
@Validated EmotionAnalysisPageRequest request) {
|
||||
return Result.success(emotionAnalysisService.getPageByUserIdWithResponse(userId, request));
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据ID获取情绪分析记录
|
||||
*/
|
||||
@GetMapping
|
||||
@GetMapping(value = "/detail")
|
||||
public Result<EmotionAnalysisResponse> getById(@RequestParam String id) {
|
||||
EmotionAnalysisResponse response = emotionAnalysisService.getEmotionAnalysisResponseById(id);
|
||||
if (response == null) {
|
||||
@@ -61,22 +47,10 @@ public class EmotionAnalysisController {
|
||||
return Result.success(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据消息ID获取情绪分析记录
|
||||
*/
|
||||
@GetMapping("/message")
|
||||
public Result<EmotionAnalysisResponse> getByMessageId(@RequestParam String messageId) {
|
||||
EmotionAnalysisResponse response = emotionAnalysisService.getEmotionAnalysisResponseByMessageId(messageId);
|
||||
if (response == null) {
|
||||
return Result.notFound("情绪分析记录不存在");
|
||||
}
|
||||
return Result.success(response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建情绪分析记录
|
||||
*/
|
||||
@PostMapping
|
||||
@PostMapping(value = "/create")
|
||||
public Result<EmotionAnalysisResponse> create(@RequestBody @Valid EmotionAnalysisCreateRequest request) {
|
||||
return Result.success(emotionAnalysisService.createEmotionAnalysisWithResponse(request));
|
||||
}
|
||||
@@ -84,7 +58,7 @@ public class EmotionAnalysisController {
|
||||
/**
|
||||
* 更新情绪分析记录
|
||||
*/
|
||||
@PutMapping
|
||||
@PutMapping(value = "/update")
|
||||
public Result<EmotionAnalysisResponse> update(@RequestBody @Valid EmotionAnalysisUpdateRequest request) {
|
||||
EmotionAnalysisResponse response = emotionAnalysisService.updateEmotionAnalysisWithResponse(request);
|
||||
if (response == null) {
|
||||
@@ -96,7 +70,7 @@ public class EmotionAnalysisController {
|
||||
/**
|
||||
* 删除情绪分析记录
|
||||
*/
|
||||
@DeleteMapping
|
||||
@DeleteMapping(value = "/delete")
|
||||
public Result<Void> delete(@RequestParam String id) {
|
||||
boolean deleted = emotionAnalysisService.deleteEmotionAnalysis(id);
|
||||
if (!deleted) {
|
||||
@@ -104,88 +78,4 @@ public class EmotionAnalysisController {
|
||||
}
|
||||
return Result.success();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据主要情绪查询分析记录
|
||||
*/
|
||||
@GetMapping("/emotion")
|
||||
public Result<List<EmotionAnalysisResponse>> getByPrimaryEmotion(@RequestParam String primaryEmotion) {
|
||||
List<EmotionAnalysisResponse> responses = emotionAnalysisService
|
||||
.getEmotionAnalysisResponsesByPrimaryEmotion(primaryEmotion);
|
||||
return Result.success(responses);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据情绪极性查询分析记录
|
||||
*/
|
||||
@GetMapping("/polarity")
|
||||
public Result<List<EmotionAnalysisResponse>> getByPolarity(@RequestParam String polarity) {
|
||||
List<EmotionAnalysisResponse> responses = emotionAnalysisService
|
||||
.getEmotionAnalysisResponsesByPolarity(polarity);
|
||||
return Result.success(responses);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据用户ID和情绪类型查询分析记录
|
||||
*/
|
||||
@GetMapping("/user/emotion")
|
||||
public Result<List<EmotionAnalysisResponse>> getByUserIdAndEmotion(
|
||||
@RequestParam String userId,
|
||||
@RequestParam String primaryEmotion) {
|
||||
List<EmotionAnalysisResponse> responses = emotionAnalysisService
|
||||
.getEmotionAnalysisResponsesByUserIdAndEmotion(userId, primaryEmotion);
|
||||
return Result.success(responses);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据时间范围查询用户情绪分析记录
|
||||
*/
|
||||
@GetMapping("/user/time-range")
|
||||
public Result<List<EmotionAnalysisResponse>> getByUserIdAndTimeRange(
|
||||
@RequestParam String userId,
|
||||
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime startTime,
|
||||
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") LocalDateTime endTime) {
|
||||
List<EmotionAnalysisResponse> responses = emotionAnalysisService
|
||||
.getEmotionAnalysisResponsesByUserIdAndTimeRange(userId, startTime, endTime);
|
||||
return Result.success(responses);
|
||||
}
|
||||
|
||||
/**
|
||||
* 统计用户的情绪分析记录数量
|
||||
*/
|
||||
@GetMapping("/user/count")
|
||||
public Result<Long> countByUserId(@RequestParam String userId) {
|
||||
Long count = emotionAnalysisService.countByUserId(userId);
|
||||
return Result.success(count);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询用户最近的情绪分析记录
|
||||
*/
|
||||
@GetMapping("/user/recent")
|
||||
public Result<List<EmotionAnalysisResponse>> getRecentByUserId(
|
||||
@RequestParam String userId,
|
||||
@RequestParam(defaultValue = "10") Integer limit) {
|
||||
List<EmotionAnalysisResponse> responses = emotionAnalysisService
|
||||
.getEmotionAnalysisResponsesRecentByUserId(userId, limit);
|
||||
return Result.success(responses);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询用户的平均情绪强度
|
||||
*/
|
||||
@GetMapping("/user/avg-intensity")
|
||||
public Result<Double> getAvgIntensityByUserId(@RequestParam String userId) {
|
||||
Double avgIntensity = emotionAnalysisService.getAvgIntensityByUserId(userId);
|
||||
return Result.success(avgIntensity);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询用户最常见的情绪类型
|
||||
*/
|
||||
@GetMapping("/user/most-frequent-emotion")
|
||||
public Result<String> getMostFrequentEmotionByUserId(@RequestParam String userId) {
|
||||
String emotion = emotionAnalysisService.getMostFrequentEmotionByUserId(userId);
|
||||
return Result.success(emotion);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user