This commit is contained in:
xyc 2025-04-25 17:33:30 +08:00
parent 458c45a454
commit bc5b780f98
2 changed files with 24 additions and 3 deletions

View File

@ -14,7 +14,9 @@ import com.ruoyi.system.service.ISysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
/**
* 评价Service业务层处理
@ -45,7 +47,26 @@ public class BusiEvaluateServiceImpl extends ServiceImpl<BusiEvaluateMapper,Busi
**/
@Override
public List<BusiEvaluateVO> listByToUserId(Long userId) {
return busiEvaluateMapper.listByToUserId(userId);
List<BusiEvaluateVO> busiEvaluateVOS = busiEvaluateMapper.listByToUserId(userId);
// 第二步拆分字符串并统计
Map<String, Long> countMap = busiEvaluateVOS.stream()
.filter(Objects::nonNull)
.flatMap(s -> Arrays.stream(s.getEvaluate().split(",")))
.map(String::trim)
.filter(s -> !s.isEmpty())
.collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));
// 第三步封装为 VO 列表
return countMap.entrySet().stream()
.map(entry -> {
BusiEvaluateVO vo = new BusiEvaluateVO();
vo.setEvaluate(entry.getKey());
vo.setNum(entry.getValue().intValue());
return vo;
})
.sorted(Comparator.comparingInt(BusiEvaluateVO::getNum).reversed())
.collect(Collectors.toList());
}
@Override

View File

@ -58,4 +58,4 @@
GROUP BY evaluate
order by create_time desc
</select>
</mapper>
</mapper>