|
@@ -665,6 +665,66 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
|
|
|
IPage<CommonRatingVo> emptyResult = new Page<>(page1.getCurrent(), page1.getSize(), 0);
|
|
IPage<CommonRatingVo> emptyResult = new Page<>(page1.getCurrent(), page1.getSize(), 0);
|
|
|
return R.data(emptyResult);
|
|
return R.data(emptyResult);
|
|
|
}
|
|
}
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 删除评价后更新店铺评分
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param businessId 店铺ID
|
|
|
|
|
+ */
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void updateStoreScoreAfterDelete(Integer businessId) {
|
|
|
|
|
+ if (businessId == null) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 查询该店铺的所有有效评价
|
|
|
|
|
+ LambdaQueryWrapper<CommonRating> wrapper = new LambdaQueryWrapper<>();
|
|
|
|
|
+ wrapper.eq(CommonRating::getBusinessType, 1)
|
|
|
|
|
+ .eq(CommonRating::getBusinessId, businessId)
|
|
|
|
|
+ .eq(CommonRating::getDeleteFlag, 0)
|
|
|
|
|
+ .eq(CommonRating::getIsShow, 1)
|
|
|
|
|
+ .eq(CommonRating::getAuditStatus, 1);
|
|
|
|
|
+ List<CommonRating> ratings = commonRatingMapper.selectList(wrapper);
|
|
|
|
|
+
|
|
|
|
|
+ int total = ratings.size();
|
|
|
|
|
+ if (total == 0) {
|
|
|
|
|
+ // 没有评价,设置默认评分为0
|
|
|
|
|
+ StoreInfo storeInfo = new StoreInfo();
|
|
|
|
|
+ storeInfo.setId(businessId);
|
|
|
|
|
+ storeInfo.setScoreAvg(0.0);
|
|
|
|
|
+ storeInfo.setScoreOne(0.0);
|
|
|
|
|
+ storeInfo.setScoreTwo(0.0);
|
|
|
|
|
+ storeInfo.setScoreThree(0.0);
|
|
|
|
|
+ storeInfoMapper.updateById(storeInfo);
|
|
|
|
|
+ log.info("店铺无有效评价,重置评分为0,businessId={}", businessId);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 计算平均评分
|
|
|
|
|
+ double scoreSum = ratings.stream().mapToDouble(r -> r.getScore() != null ? r.getScore() : 0.0).sum();
|
|
|
|
|
+ double scoreOneSum = ratings.stream().mapToDouble(r -> r.getScoreOne() != null ? r.getScoreOne() : 0.0).sum();
|
|
|
|
|
+ double scoreTwoSum = ratings.stream().mapToDouble(r -> r.getScoreTwo() != null ? r.getScoreTwo() : 0.0).sum();
|
|
|
|
|
+ double scoreThreeSum = ratings.stream().mapToDouble(r -> r.getScoreThree() != null ? r.getScoreThree() : 0.0).sum();
|
|
|
|
|
+
|
|
|
|
|
+ double scoreAvg = Math.round((scoreSum / total) * 100.0) / 100.0;
|
|
|
|
|
+ double scoreOne = Math.round((scoreOneSum / total) * 100.0) / 100.0;
|
|
|
|
|
+ double scoreTwo = Math.round((scoreTwoSum / total) * 100.0) / 100.0;
|
|
|
|
|
+ double scoreThree = Math.round((scoreThreeSum / total) * 100.0) / 100.0;
|
|
|
|
|
+
|
|
|
|
|
+ StoreInfo storeInfo = new StoreInfo();
|
|
|
|
|
+ storeInfo.setId(businessId);
|
|
|
|
|
+ storeInfo.setScoreAvg(scoreAvg);
|
|
|
|
|
+ storeInfo.setScoreOne(scoreOne);
|
|
|
|
|
+ storeInfo.setScoreTwo(scoreTwo);
|
|
|
|
|
+ storeInfo.setScoreThree(scoreThree);
|
|
|
|
|
+ storeInfoMapper.updateById(storeInfo);
|
|
|
|
|
+
|
|
|
|
|
+ log.info("更新店铺评分成功,businessId={},评价数={},scoreAvg={}", businessId, total, scoreAvg);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("更新店铺评分失败,businessId={},error={}", businessId, e.getMessage());
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/*
|
|
/*
|
|
|
@Override
|
|
@Override
|
|
|
public Double getAverageScore(Integer businessType, Long businessId) {
|
|
public Double getAverageScore(Integer businessType, Long businessId) {
|