更新
This commit is contained in:
parent
458c45a454
commit
bc5b780f98
@ -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
|
||||
|
||||
@ -58,4 +58,4 @@
|
||||
GROUP BY evaluate
|
||||
order by create_time desc
|
||||
</select>
|
||||
</mapper>
|
||||
</mapper>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user