From bc5b780f988e5bab0767b907517e347668b6e871 Mon Sep 17 00:00:00 2001 From: xyc <3422692813@qq.com> Date: Fri, 25 Apr 2025 17:33:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/BusiEvaluateServiceImpl.java | 25 +++++++++++++++++-- .../mapper/busi/BusiEvaluateMapper.xml | 2 +- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/ruoyi-admin/src/main/java/com/ruoyi/busi/service/impl/BusiEvaluateServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/busi/service/impl/BusiEvaluateServiceImpl.java index 3e2ba2b..95fcba7 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/busi/service/impl/BusiEvaluateServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/busi/service/impl/BusiEvaluateServiceImpl.java @@ -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 listByToUserId(Long userId) { - return busiEvaluateMapper.listByToUserId(userId); + List busiEvaluateVOS = busiEvaluateMapper.listByToUserId(userId); + + // 第二步:拆分字符串并统计 + Map 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 diff --git a/ruoyi-admin/src/main/resources/mapper/busi/BusiEvaluateMapper.xml b/ruoyi-admin/src/main/resources/mapper/busi/BusiEvaluateMapper.xml index 9e909e6..00a724e 100644 --- a/ruoyi-admin/src/main/resources/mapper/busi/BusiEvaluateMapper.xml +++ b/ruoyi-admin/src/main/resources/mapper/busi/BusiEvaluateMapper.xml @@ -58,4 +58,4 @@ GROUP BY evaluate order by create_time desc - \ No newline at end of file +