Explorar o código

bugfix:动态显示商家浮窗字段

刘云鑫 hai 2 meses
pai
achega
a0104f7f7e

+ 12 - 0
alien-entity/src/main/java/shop/alien/entity/store/vo/LifeUserDynamicsVo.java

@@ -68,4 +68,16 @@ public class LifeUserDynamicsVo extends LifeUserDynamics {
 
     @ApiModelProperty(value = "商家名称")
     private String storeName;
+
+    @ApiModelProperty(value = "评分")
+    private Double scoreAvg;
+
+     @ApiModelProperty(value = "行业")
+    private String businessSection;
+
+    @ApiModelProperty(value = "评价数量")
+    private String ratingCount;
+
+    @ApiModelProperty(value = "评价类型")
+    private String businessTypeName;
 }

+ 2 - 2
alien-entity/src/main/java/shop/alien/mapper/LifeUserDynamicsMapper.java

@@ -23,7 +23,7 @@ public interface LifeUserDynamicsMapper extends BaseMapper<LifeUserDynamics> {
             "where lud.delete_flag = 0 and lud.enable_status = 0 and lud.draft = 0 and " +
             "not exists (select 1 from life_user_violation luv where luv.delete_flag = 0 and luv.processing_status = 1 " +
             "AND luv.dynamics_id = lud.id) order by lud.created_time desc) " +
-            "select dynamice.*, info.store_name userName, user.head_img userImage, info.id storeUserId, user.id storeOrUserId, 0 isExpert " +
+            "select dynamice.*, info.store_name userName, user.head_img userImage, info.id storeUserId, user.id storeOrUserId, 0 isExpert, info.score_avg scoreAvg, info.business_section businessSection, info.business_type_name businessTypeName " +
             "from dynamice " +
             "join store_user user on dynamice.phone = user.phone and user.delete_flag = 0 " +
             "and user.status = 0 and user.logout_flag = 0 " +
@@ -33,7 +33,7 @@ public interface LifeUserDynamicsMapper extends BaseMapper<LifeUserDynamics> {
             "where dynamice.flag = 'store' " +
             "union " +
             "select dynamice.*, user.user_name userName, user.user_image userImage, user.id storeUserId, user.id storeOrUserId, " +
-            "IF(lue.expert_code IS NOT NULL , 1, 0) AS isExpert " +
+            "IF(lue.expert_code IS NOT NULL , 1, 0) AS isExpert, 0 scoreAvg, 0 businessSection, 0 businessTypeName " +
             "from dynamice " +
             "join life_user user on dynamice.phone = user.user_phone and user.delete_flag = 0 " +
             "and user.logout_flag = 0 " +

+ 33 - 0
alien-store/src/main/java/shop/alien/store/service/LifeUserDynamicsService.java

@@ -54,6 +54,8 @@ public class LifeUserDynamicsService extends ServiceImpl<LifeUserDynamicsMapper,
 
     private final CommonCommentMapper commonCommentMapper;
 
+    private final CommonRatingService commonRatingService;
+
     public int addLiulanCount(String id) {
         LambdaUpdateWrapper<LifeUserDynamics> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
         lambdaUpdateWrapper.eq(LifeUserDynamics::getId, id);
@@ -157,13 +159,38 @@ public class LifeUserDynamicsService extends ServiceImpl<LifeUserDynamicsMapper,
         // 查询动态数据并按类型过滤
         List<LifeUserDynamicsVo> lifeUserDynamicsVoList = lifeUserDynamicsMapper.getLifeUserDynamicsList();
 
+        // 店铺id
+        // TODO 可以优化小驴:优化方案直接sql分组查询评价数量,避免循环查询
+        List<String> storeUserIdList = new ArrayList<>();
+        Map<String, Integer> commitCountMap = new HashMap<>();
         //对lifeUserDynamicsVoList数据进行处理,当type为2的时候,把userName的数值赋值到storeName
         lifeUserDynamicsVoList.forEach(item -> {
             if (item.getType().equals("2")) {
                 item.setStoreName(item.getUserName());
+                storeUserIdList.add(item.getStoreUserId());
             }
         });
 
+        for (String storeId : storeUserIdList) {
+            Integer totalCount = 0;
+            double storeScore;
+            Object ratingObj =  commonRatingService.getRatingCount(Integer.parseInt(storeId), 1);
+            if (ratingObj != null) {
+                Map<String, Object> ratingMap = (Map<String, Object>) ratingObj;
+                Object totalCountObj = ratingMap.get("totalCount");
+                if (totalCountObj != null) {
+                    // 安全转换为整数
+                    try {
+                        totalCount = Integer.parseInt(totalCountObj.toString().trim());
+                    } catch (NumberFormatException e) {
+                        totalCount = 0; // 转换失败时默认值
+                    }
+                } else {
+                    totalCount = 0;
+                }
+            }
+            commitCountMap.put(storeId, totalCount);
+        }
         if (!StringUtils.isEmpty(type)) {
             lifeUserDynamicsVoList = lifeUserDynamicsVoList.stream().filter(item -> type.equals(item.getType())).collect(Collectors.toList());
         }
@@ -207,6 +234,12 @@ public class LifeUserDynamicsService extends ServiceImpl<LifeUserDynamicsMapper,
         // 设置动态对象的状态信息:是否关注对方、是否被关注、是否点赞及评论数量
         // 设置.imagePath。视频为mp4+jpg格式,图片为jpg/png格式。
         for (LifeUserDynamicsVo vo : lifeUserDynamicsVoList) {
+            // 设置评价数量
+            if (commitCountMap.containsKey(vo.getStoreUserId())) {
+                vo.setRatingCount(commitCountMap.get(vo.getStoreUserId()).toString());
+            } else {
+                vo.setRatingCount("0");
+            }
             if (followList.contains(vo.getPhoneId())) {
                 vo.setIsFollowThis("1");
             } else {