优化
This commit is contained in:
+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