|
@@ -1,16 +1,21 @@
|
|
|
package com.kxmall.web.controller.rider.service.impl;
|
|
|
|
|
|
+import cn.hutool.core.collection.CollUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.kxmall.common.core.domain.PageQuery;
|
|
|
import com.kxmall.common.core.page.TableDataInfo;
|
|
|
import com.kxmall.common.exception.ServiceException;
|
|
|
+import com.kxmall.common.utils.StreamUtil;
|
|
|
import com.kxmall.common.utils.StringUtils;
|
|
|
import com.kxmall.order.domain.KxStoreAppraise;
|
|
|
import com.kxmall.order.domain.bo.KxStoreAppraiseBo;
|
|
|
import com.kxmall.order.domain.vo.KxStoreAppraiseVo;
|
|
|
import com.kxmall.order.mapper.KxStoreAppraiseMapper;
|
|
|
+import com.kxmall.product.domain.KxStoreProduct;
|
|
|
+import com.kxmall.product.domain.vo.KxStoreProductVo;
|
|
|
+import com.kxmall.product.mapper.KxStoreProductMapper;
|
|
|
import com.kxmall.rider.domain.KxRiderOrder;
|
|
|
import com.kxmall.rider.mapper.KxRiderOrderMapper;
|
|
|
import com.kxmall.web.controller.rider.service.RiderReviewService;
|
|
@@ -18,6 +23,7 @@ import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.List;
|
|
@@ -36,6 +42,7 @@ public class RiderReviewServiceImpl implements RiderReviewService {
|
|
|
|
|
|
private final KxStoreAppraiseMapper appraiseMapper;
|
|
|
private final KxRiderOrderMapper riderOrderMapper;
|
|
|
+ private final KxStoreProductMapper kxStoreProductMapper;
|
|
|
|
|
|
@Override
|
|
|
public TableDataInfo<KxStoreAppraiseVo> queryPageList(KxStoreAppraiseBo bo, PageQuery pageQuery) {
|
|
@@ -47,7 +54,7 @@ public class RiderReviewServiceImpl implements RiderReviewService {
|
|
|
}
|
|
|
|
|
|
LambdaQueryWrapper<KxStoreAppraise> lqw = buildQueryWrapper(bo);
|
|
|
- lqw.in(KxStoreAppraise::getOrderId, orderIds);
|
|
|
+ lqw.in(KxStoreAppraise::getOrderId, orderIds).eq(KxStoreAppraise::getState, 1);
|
|
|
|
|
|
// 添加评分筛选条件
|
|
|
if (bo.getMinRating() != null) {
|
|
@@ -60,6 +67,11 @@ public class RiderReviewServiceImpl implements RiderReviewService {
|
|
|
lqw.orderByDesc(KxStoreAppraise::getCreateTime);
|
|
|
|
|
|
Page<KxStoreAppraiseVo> result = appraiseMapper.selectVoPage(new Page<>(pageQuery.getPageNum(), pageQuery.getPageSize()), lqw);
|
|
|
+ if (CollUtil.isNotEmpty(result.getRecords())) {
|
|
|
+ List<Long> productIds = result.getRecords().stream().map(KxStoreAppraiseVo::getProductId).collect(Collectors.toList());
|
|
|
+ Map<Long, String> storeNameMap = kxStoreProductMapper.selectVoBatchIds(productIds).stream().collect(Collectors.toMap(KxStoreProductVo::getId, KxStoreProductVo::getStoreName, (old, newV) -> newV));
|
|
|
+ result.getRecords().forEach(appraise -> appraise.setProductName(storeNameMap.get(appraise.getProductId())));
|
|
|
+ }
|
|
|
return TableDataInfo.build(result);
|
|
|
}
|
|
|
|
|
@@ -83,16 +95,13 @@ public class RiderReviewServiceImpl implements RiderReviewService {
|
|
|
@Override
|
|
|
public Map<String, Object> getRiderReviewStats(Long riderId) {
|
|
|
Map<String, Object> stats = new HashMap<>();
|
|
|
-
|
|
|
+ stats.put("totalReviews", 0);
|
|
|
+ stats.put("averageRating", 0.0);
|
|
|
+
|
|
|
// 获取该骑手配送的所有订单ID
|
|
|
List<Long> orderIds = getRiderOrderIds(riderId);
|
|
|
|
|
|
if (orderIds.isEmpty()) {
|
|
|
- stats.put("totalReviews", 0);
|
|
|
- stats.put("averageRating", 0.0);
|
|
|
- stats.put("goodReviews", 0);
|
|
|
- stats.put("mediumReviews", 0);
|
|
|
- stats.put("badReviews", 0);
|
|
|
return stats;
|
|
|
}
|
|
|
|
|
@@ -102,40 +111,14 @@ public class RiderReviewServiceImpl implements RiderReviewService {
|
|
|
|
|
|
List<KxStoreAppraise> appraises = appraiseMapper.selectList(lqw);
|
|
|
|
|
|
- if (appraises.isEmpty()) {
|
|
|
- stats.put("totalReviews", 0);
|
|
|
- stats.put("averageRating", 0.0);
|
|
|
- stats.put("goodReviews", 0);
|
|
|
- stats.put("mediumReviews", 0);
|
|
|
- stats.put("badReviews", 0);
|
|
|
- return stats;
|
|
|
+ if (CollUtil.isNotEmpty(appraises)) {
|
|
|
+ long count = appraises.stream().filter(StreamUtil.distinctByKey(KxStoreAppraise::getOrderId)).count();
|
|
|
+ stats.put("totalReviews", count);
|
|
|
+ double sum = appraises.stream().mapToDouble(KxStoreAppraise::getScore).sum();
|
|
|
+ BigDecimal avg = BigDecimal.valueOf(sum).divide(BigDecimal.valueOf(count), 2, RoundingMode.HALF_UP);
|
|
|
+ stats.put("averageRating", avg);
|
|
|
}
|
|
|
-
|
|
|
- // 计算统计数据
|
|
|
- int totalReviews = appraises.size();
|
|
|
- double averageRating = appraises.stream()
|
|
|
- .mapToLong(KxStoreAppraise::getScore)
|
|
|
- .average()
|
|
|
- .orElse(0.0);
|
|
|
-
|
|
|
- long goodReviews = appraises.stream()
|
|
|
- .filter(a -> a.getScore() >= 4)
|
|
|
- .count();
|
|
|
-
|
|
|
- long mediumReviews = appraises.stream()
|
|
|
- .filter(a -> a.getScore() == 3)
|
|
|
- .count();
|
|
|
-
|
|
|
- long badReviews = appraises.stream()
|
|
|
- .filter(a -> a.getScore() <= 2)
|
|
|
- .count();
|
|
|
-
|
|
|
- stats.put("totalReviews", totalReviews);
|
|
|
- stats.put("averageRating", BigDecimal.valueOf(averageRating).setScale(1, BigDecimal.ROUND_HALF_UP).doubleValue());
|
|
|
- stats.put("goodReviews", goodReviews);
|
|
|
- stats.put("mediumReviews", mediumReviews);
|
|
|
- stats.put("badReviews", badReviews);
|
|
|
-
|
|
|
+
|
|
|
return stats;
|
|
|
}
|
|
|
|