优化
This commit is contained in:
@@ -35,67 +35,7 @@ public interface EmotionAnalysisService extends IService<EmotionAnalysis> {
|
||||
* 根据消息ID查询情绪分析记录
|
||||
*/
|
||||
EmotionAnalysis getByMessageId(String messageId);
|
||||
|
||||
/**
|
||||
* 根据主要情绪查询分析记录
|
||||
*/
|
||||
List<EmotionAnalysis> getByPrimaryEmotion(String primaryEmotion);
|
||||
|
||||
/**
|
||||
* 根据情绪极性查询分析记录
|
||||
*/
|
||||
List<EmotionAnalysis> getByPolarity(String polarity);
|
||||
|
||||
/**
|
||||
* 根据用户ID和情绪类型查询分析记录
|
||||
*/
|
||||
List<EmotionAnalysis> getByUserIdAndEmotion(String userId, String primaryEmotion);
|
||||
|
||||
/**
|
||||
* 根据时间范围查询情绪分析记录
|
||||
*/
|
||||
List<EmotionAnalysis> getByUserIdAndTimeRange(String userId, LocalDateTime startTime, LocalDateTime endTime);
|
||||
|
||||
/**
|
||||
* 统计用户的情绪分析记录数量
|
||||
*/
|
||||
Long countByUserId(String userId);
|
||||
|
||||
/**
|
||||
* 统计指定情绪类型的记录数量
|
||||
*/
|
||||
Long countByPrimaryEmotion(String primaryEmotion);
|
||||
|
||||
/**
|
||||
* 统计用户指定情绪类型的记录数量
|
||||
*/
|
||||
Long countByUserIdAndEmotion(String userId, String primaryEmotion);
|
||||
|
||||
/**
|
||||
* 查询用户最近的情绪分析记录
|
||||
*/
|
||||
List<EmotionAnalysis> getRecentByUserId(String userId, Integer limit);
|
||||
|
||||
/**
|
||||
* 查询高置信度的情绪分析记录
|
||||
*/
|
||||
List<EmotionAnalysis> getByMinConfidence(Double minConfidence);
|
||||
|
||||
/**
|
||||
* 查询用户的平均情绪强度
|
||||
*/
|
||||
Double getAvgIntensityByUserId(String userId);
|
||||
|
||||
/**
|
||||
* 查询用户指定时间段的平均情绪强度
|
||||
*/
|
||||
Double getAvgIntensityByUserIdAndTimeRange(String userId, LocalDateTime startTime, LocalDateTime endTime);
|
||||
|
||||
/**
|
||||
* 查询用户最常见的情绪类型
|
||||
*/
|
||||
String getMostFrequentEmotionByUserId(String userId);
|
||||
|
||||
|
||||
/**
|
||||
* 创建情绪分析记录
|
||||
*/
|
||||
@@ -138,30 +78,4 @@ public interface EmotionAnalysisService extends IService<EmotionAnalysis> {
|
||||
* 删除情绪分析记录
|
||||
*/
|
||||
boolean deleteEmotionAnalysis(String id);
|
||||
|
||||
/**
|
||||
* 根据主要情绪查询分析记录响应
|
||||
*/
|
||||
List<EmotionAnalysisResponse> getEmotionAnalysisResponsesByPrimaryEmotion(String primaryEmotion);
|
||||
|
||||
/**
|
||||
* 根据情绪极性查询分析记录响应
|
||||
*/
|
||||
List<EmotionAnalysisResponse> getEmotionAnalysisResponsesByPolarity(String polarity);
|
||||
|
||||
/**
|
||||
* 根据用户ID和情绪类型查询分析记录响应
|
||||
*/
|
||||
List<EmotionAnalysisResponse> getEmotionAnalysisResponsesByUserIdAndEmotion(String userId, String primaryEmotion);
|
||||
|
||||
/**
|
||||
* 根据时间范围查询用户情绪分析记录响应
|
||||
*/
|
||||
List<EmotionAnalysisResponse> getEmotionAnalysisResponsesByUserIdAndTimeRange(String userId,
|
||||
LocalDateTime startTime, LocalDateTime endTime);
|
||||
|
||||
/**
|
||||
* 查询用户最近的情绪分析记录响应
|
||||
*/
|
||||
List<EmotionAnalysisResponse> getEmotionAnalysisResponsesRecentByUserId(String userId, Integer limit);
|
||||
}
|
||||
+7
-142
@@ -84,106 +84,6 @@ public class EmotionAnalysisServiceImpl extends ServiceImpl<EmotionAnalysisMappe
|
||||
return this.getOne(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EmotionAnalysis> getByPrimaryEmotion(String primaryEmotion) {
|
||||
LambdaQueryWrapper<EmotionAnalysis> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(EmotionAnalysis::getPrimaryEmotion, primaryEmotion)
|
||||
.eq(EmotionAnalysis::getIsDeleted, 0)
|
||||
.orderByDesc(EmotionAnalysis::getCreateTime);
|
||||
return this.list(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EmotionAnalysis> getByPolarity(String polarity) {
|
||||
LambdaQueryWrapper<EmotionAnalysis> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(EmotionAnalysis::getPolarity, polarity)
|
||||
.eq(EmotionAnalysis::getIsDeleted, 0)
|
||||
.orderByDesc(EmotionAnalysis::getCreateTime);
|
||||
return this.list(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EmotionAnalysis> getByUserIdAndEmotion(String userId, String primaryEmotion) {
|
||||
LambdaQueryWrapper<EmotionAnalysis> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(EmotionAnalysis::getCreateBy, userId)
|
||||
.eq(EmotionAnalysis::getPrimaryEmotion, primaryEmotion)
|
||||
.eq(EmotionAnalysis::getIsDeleted, 0)
|
||||
.orderByDesc(EmotionAnalysis::getCreateTime);
|
||||
return this.list(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EmotionAnalysis> getByUserIdAndTimeRange(String userId, LocalDateTime startTime, LocalDateTime endTime) {
|
||||
LambdaQueryWrapper<EmotionAnalysis> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(EmotionAnalysis::getCreateBy, userId)
|
||||
.between(EmotionAnalysis::getCreateTime, startTime, endTime)
|
||||
.eq(EmotionAnalysis::getIsDeleted, 0)
|
||||
.orderByDesc(EmotionAnalysis::getCreateTime);
|
||||
return this.list(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long countByUserId(String userId) {
|
||||
LambdaQueryWrapper<EmotionAnalysis> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(EmotionAnalysis::getCreateBy, userId)
|
||||
.eq(EmotionAnalysis::getIsDeleted, 0);
|
||||
return this.count(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long countByPrimaryEmotion(String primaryEmotion) {
|
||||
LambdaQueryWrapper<EmotionAnalysis> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(EmotionAnalysis::getPrimaryEmotion, primaryEmotion)
|
||||
.eq(EmotionAnalysis::getIsDeleted, 0);
|
||||
return this.count(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long countByUserIdAndEmotion(String userId, String primaryEmotion) {
|
||||
LambdaQueryWrapper<EmotionAnalysis> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(EmotionAnalysis::getCreateBy, userId)
|
||||
.eq(EmotionAnalysis::getPrimaryEmotion, primaryEmotion)
|
||||
.eq(EmotionAnalysis::getIsDeleted, 0);
|
||||
return this.count(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EmotionAnalysis> getRecentByUserId(String userId, Integer limit) {
|
||||
LambdaQueryWrapper<EmotionAnalysis> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.eq(EmotionAnalysis::getCreateBy, userId)
|
||||
.eq(EmotionAnalysis::getIsDeleted, 0)
|
||||
.orderByDesc(EmotionAnalysis::getCreateTime)
|
||||
.last("LIMIT " + limit);
|
||||
return this.list(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EmotionAnalysis> getByMinConfidence(Double minConfidence) {
|
||||
LambdaQueryWrapper<EmotionAnalysis> wrapper = new LambdaQueryWrapper<>();
|
||||
wrapper.ge(EmotionAnalysis::getConfidence, minConfidence)
|
||||
.eq(EmotionAnalysis::getIsDeleted, 0)
|
||||
.orderByDesc(EmotionAnalysis::getConfidence);
|
||||
return this.list(wrapper);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double getAvgIntensityByUserId(String userId) {
|
||||
// 这里需要自定义SQL查询平均值,暂时返回0
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Double getAvgIntensityByUserIdAndTimeRange(String userId, LocalDateTime startTime, LocalDateTime endTime) {
|
||||
// 这里需要自定义SQL查询平均值,暂时返回0
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMostFrequentEmotionByUserId(String userId) {
|
||||
// 这里需要自定义SQL查询最频繁的情绪,暂时返回null
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EmotionAnalysis createEmotionAnalysis(String messageId, String userId, String primaryEmotion,
|
||||
String polarity, Double intensity, Double confidence) {
|
||||
@@ -287,48 +187,6 @@ public class EmotionAnalysisServiceImpl extends ServiceImpl<EmotionAnalysisMappe
|
||||
return this.removeById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EmotionAnalysisResponse> getEmotionAnalysisResponsesByPrimaryEmotion(String primaryEmotion) {
|
||||
List<EmotionAnalysis> analyses = getByPrimaryEmotion(primaryEmotion);
|
||||
return analyses.stream()
|
||||
.map(this::convertToResponse)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EmotionAnalysisResponse> getEmotionAnalysisResponsesByPolarity(String polarity) {
|
||||
List<EmotionAnalysis> analyses = getByPolarity(polarity);
|
||||
return analyses.stream()
|
||||
.map(this::convertToResponse)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EmotionAnalysisResponse> getEmotionAnalysisResponsesByUserIdAndEmotion(String userId,
|
||||
String primaryEmotion) {
|
||||
List<EmotionAnalysis> analyses = getByUserIdAndEmotion(userId, primaryEmotion);
|
||||
return analyses.stream()
|
||||
.map(this::convertToResponse)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EmotionAnalysisResponse> getEmotionAnalysisResponsesByUserIdAndTimeRange(String userId,
|
||||
LocalDateTime startTime, LocalDateTime endTime) {
|
||||
List<EmotionAnalysis> analyses = getByUserIdAndTimeRange(userId, startTime, endTime);
|
||||
return analyses.stream()
|
||||
.map(this::convertToResponse)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<EmotionAnalysisResponse> getEmotionAnalysisResponsesRecentByUserId(String userId, Integer limit) {
|
||||
List<EmotionAnalysis> analyses = getRecentByUserId(userId, limit);
|
||||
return analyses.stream()
|
||||
.map(this::convertToResponse)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建PageResult对象
|
||||
*/
|
||||
@@ -355,6 +213,13 @@ public class EmotionAnalysisServiceImpl extends ServiceImpl<EmotionAnalysisMappe
|
||||
if (analysis.getUpdateTime() != null) {
|
||||
response.setUpdateTime(analysis.getUpdateTime().format(DATE_TIME_FORMATTER));
|
||||
}
|
||||
// 处理Double类型转换
|
||||
if (analysis.getIntensity() != null) {
|
||||
response.setIntensity(analysis.getIntensity().doubleValue());
|
||||
}
|
||||
if (analysis.getConfidence() != null) {
|
||||
response.setConfidence(analysis.getConfidence().doubleValue());
|
||||
}
|
||||
return response;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user