Explorar o código

Merge remote-tracking branch 'origin/sit' into uat-20260202

dujian hai 1 semana
pai
achega
0417f9fcbf

+ 19 - 0
alien-entity/src/main/java/shop/alien/mapper/CommonRatingMapper.java

@@ -14,6 +14,7 @@ import shop.alien.entity.store.CommonRating;
 import shop.alien.entity.store.vo.StoreInfoScoreVo;
 
 import java.util.Date;
+import java.util.List;
 import java.util.Map;
 
 /**
@@ -45,6 +46,24 @@ public interface CommonRatingMapper extends BaseMapper<CommonRating> {
             "AND business_id = #{businessId}")
     StoreInfoScoreVo getCommentCountAndScoreInfo(@Param("businessType")Integer businessType,@Param("businessId")Integer businessId);
 
+
+
+    @Select("SELECT " +
+            "IFNULL(SUM(score), 0) AS score, " +
+            "IFNULL(SUM(score_one), 0) AS scoreOne, " +
+            "IFNULL(SUM(score_two), 0) AS scoreTwo, " +
+            "IFNULL(SUM(score_three), 0) AS scoreThree, " +
+            "COUNT(0) AS total " +
+            "FROM `common_rating` " +  // FROM 后加空格,避免和表名拼接成 FROM`common_rating`
+            "WHERE business_type = #{businessType} " +
+            "AND delete_flag = 0 " +
+            "AND audit_status = 1 " +
+            "AND business_id = #{businessId}"+
+            "GROUP BY user_id"
+    )
+    List<StoreInfoScoreVo> getStoreInfoScoreNew(@Param("businessType")Integer businessType, @Param("businessId")Integer businessId);
+
+
      /**
      * 获取评价数量
      */

+ 69 - 7
alien-store/src/main/java/shop/alien/store/service/impl/CommonRatingServiceImpl.java

@@ -519,10 +519,18 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
         Double score = commonRating.getScore();
         if(1 == commonRating.getBusinessType()){
             // 更新门店评价信息
+
             StoreInfoScoreVo storeInfoScoreVo = commonRatingMapper.getCommentCountAndScoreInfo(commonRating.getBusinessType(),businessId);
+
+            List<StoreInfoScoreVo>   storeInfoScoreNew = commonRatingMapper.getStoreInfoScoreNew(commonRating.getBusinessType(),businessId);
+
+            Integer commentCount = storeInfoScoreNew.size();
+
             double total = storeInfoScoreVo.getTotal();
             StoreInfo storeInfo = new StoreInfo();
-            if(total >= 10){
+
+            //如果有效条数大于10条,则正常进行平均数计算
+            if(commentCount > 10){
                 double scoreAvg = (total == 0 ? 0 : storeInfoScoreVo.getScore() / total);
                 double scoreOne = (total == 0 ? 0 : storeInfoScoreVo.getScoreOne() / total);
                 double scoreTwo = (total == 0 ? 0 : storeInfoScoreVo.getScoreTwo() / total);
@@ -534,6 +542,41 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
                 storeInfo.setScoreThree(new BigDecimal(scoreThree).setScale(2, RoundingMode.HALF_UP).doubleValue());
                 storeInfoMapper.updateById(storeInfo);
             }
+
+            //如果有效条数=10,则进行特殊处理
+            if(commentCount == 10){
+                //判断首次达到10条还是第N次达到10条
+                StoreInfo storeInfoNew = storeInfoMapper.selectById(businessId);
+                //首次达到10条 平均分是3.0 ,第N次达到10条 4.0
+                if(storeInfoNew.getScoreAvg() == 0){
+                    double scoreAvg = 3.0;
+//                    double scoreOne = 3.0;
+//                    double scoreTwo = 3.0;
+//                    double scoreThree =3.0;
+                    storeInfo.setId(businessId);
+                    storeInfo.setScoreAvg(new BigDecimal(scoreAvg).setScale(2, RoundingMode.HALF_UP).doubleValue());
+                    storeInfoMapper.updateById(storeInfo);
+                }else{
+                    double scoreAvg = 4.0 ;
+                    storeInfo.setId(businessId);
+                    storeInfo.setScoreAvg(new BigDecimal(scoreAvg).setScale(2, RoundingMode.HALF_UP).doubleValue());
+                    storeInfoMapper.updateById(storeInfo);
+                }
+            }
+
+
+//            if(total >= 10){
+//                double scoreAvg = (total == 0 ? 0 : storeInfoScoreVo.getScore() / total);
+//                double scoreOne = (total == 0 ? 0 : storeInfoScoreVo.getScoreOne() / total);
+//                double scoreTwo = (total == 0 ? 0 : storeInfoScoreVo.getScoreTwo() / total);
+//                double scoreThree = (total == 0 ? 0 : storeInfoScoreVo.getScoreThree() / total);
+//                storeInfo.setId(businessId);
+//                storeInfo.setScoreAvg(new BigDecimal(scoreAvg).setScale(2, RoundingMode.HALF_UP).doubleValue());
+//                storeInfo.setScoreOne(new BigDecimal(scoreOne).setScale(2, RoundingMode.HALF_UP).doubleValue());
+//                storeInfo.setScoreTwo(new BigDecimal(scoreTwo).setScale(2, RoundingMode.HALF_UP).doubleValue());
+//                storeInfo.setScoreThree(new BigDecimal(scoreThree).setScale(2, RoundingMode.HALF_UP).doubleValue());
+//                storeInfoMapper.updateById(storeInfo);
+//            }
             // 须用 businessId 查询门店账号:当 total<10 时未执行 storeInfo.setId,storeInfo.getId() 恒为 null,会导致查不到店主、差评通知路径 NPE(好评可提交、差评失败)
             StoreUser storeUser = storeUserMapper.selectOne(new LambdaQueryWrapper<StoreUser>().eq(StoreUser::getStoreId, businessId).eq(StoreUser::getDeleteFlag, 0));
 
@@ -1182,16 +1225,35 @@ public class CommonRatingServiceImpl extends ServiceImpl<CommonRatingMapper, Com
             List<CommonRating> ratings = commonRatingMapper.selectList(wrapper);
             
             int total = ratings.size();
-            if (total == 0) {
+
+            //如果评价数量小于10,则重置评分为3.5   评价=10  重置评分4.0
+            List<StoreInfoScoreVo>   storeInfoScoreNew = commonRatingMapper.getStoreInfoScoreNew(1,businessId);
+            Integer commentCount = storeInfoScoreNew.size();
+
+
+            if (commentCount == 10) {
+                // 没有评价,设置默认评分为0
+                StoreInfo storeInfo = new StoreInfo();
+                storeInfo.setId(businessId);
+                storeInfo.setScoreAvg(4.0);
+//                storeInfo.setScoreOne(3.0);
+//                storeInfo.setScoreTwo(3.0);
+//                storeInfo.setScoreThree(3.0);
+                storeInfoMapper.updateById(storeInfo);
+                log.info("店铺有效评价被删除=10条,重置评分为4.0,businessId={}", businessId);
+                return;
+            }
+
+            if (commentCount < 10) {
                 // 没有评价,设置默认评分为0
                 StoreInfo storeInfo = new StoreInfo();
                 storeInfo.setId(businessId);
-                storeInfo.setScoreAvg(0.0);
-                storeInfo.setScoreOne(0.0);
-                storeInfo.setScoreTwo(0.0);
-                storeInfo.setScoreThree(0.0);
+                storeInfo.setScoreAvg(3.5);
+//                storeInfo.setScoreOne(3.0);
+//                storeInfo.setScoreTwo(3.0);
+//                storeInfo.setScoreThree(3.0);
                 storeInfoMapper.updateById(storeInfo);
-                log.info("店铺无有效评价,重置评分为0,businessId={}", businessId);
+                log.info("店铺有效评价被删除<10条,重置评分为3.5,businessId={}", businessId);
                 return;
             }