Răsfoiți Sursa

fix 修改逻辑

1 lună în urmă
părinte
comite
4a5901dc14

+ 25 - 21
application-webadmin/src/main/java/com/tourism/webadmin/app/website/controller/TourWebFansController.java

@@ -269,13 +269,13 @@ public class TourWebFansController {
         Set<Long> collect = list.stream().map(TourFans::getAttentionId).collect(Collectors.toSet());
         //关注人id列表
         Set<Long> collecteds = list.stream().map(TourFans::getCreateUserId).collect(Collectors.toSet());
-        List<TourFans> tourFans = tourFansService.list(new LambdaQueryWrapper<TourFans>().in(TourFans::getCreateUserId, userId) .eq(TourFans::getDeleteFlag, 1));
-        List<Long> ids ;
-        if (!tourFans.isEmpty()){
-            ids = tourFans.stream().map(TourFans::getAttentionId).collect(Collectors.toList());
-        }else {
-            ids = new ArrayList<>();
-        }
+//        List<TourFans> tourFans = tourFansService.list(new LambdaQueryWrapper<TourFans>().in(TourFans::getCreateUserId, userId) .eq(TourFans::getDeleteFlag, 1));
+//        List<Long> ids ;
+//        if (!tourFans.isEmpty()){
+//            ids = tourFans.stream().map(TourFans::getAttentionId).collect(Collectors.toList());
+//        }else {
+//            ids = new ArrayList<>();
+//        }
         //根据id查询用户
         List<TourUser> tourUsers = tourUserService.listByIds(collect);
         List<TourUser> tourUserList = tourUserService.listByIds(collecteds);
@@ -290,14 +290,16 @@ public class TourWebFansController {
             List<Map<String, Object>> mapList = tourFansService.listMaps(new QueryWrapper<TourFans>().select("count(*) as num,attention_id").lambda().in(TourFans::getAttentionId, longs) .eq(TourFans::getDeleteFlag, 1).groupBy(TourFans::getAttentionId));
             //设置匹配对应的粉丝数
             dataList.forEach(item->{
+                TourFans one = tourFansService.getOne(new LambdaQueryWrapper<TourFans>().eq(TourFans::getAttentionId, userId).eq(TourFans::getDeleteFlag, 1).eq(TourFans::getCreateUserId, item.getCreateUserId()));
+                TourFans one1 = tourFansService.getOne(new LambdaQueryWrapper<TourFans>().eq(TourFans::getAttentionId, item.getCreateUserId()).eq(TourFans::getDeleteFlag, 1).eq(TourFans::getCreateUserId, userId));
                 //如果双等于说明互关
-                if (Objects.equals(item.getAttentionId(),userId) && ids.contains(item.getCreateUserId())) {
+                if (Objects.nonNull(one) && Objects.nonNull(one1)) {
                     item.setFansStatus("2");
                     item.setFansStatusName("互关");
-                }else if (!Objects.equals(item.getAttentionId(),userId) && ids.contains(item.getCreateUserId())){ //我关注他但是他没关注我说明单向关注
+                }else if (Objects.nonNull(one1) && Objects.isNull(one)){ //我关注他但是他没关注我说明单向关注
                     item.setFansStatus("1");
                     item.setFansStatusName("已关注");
-                }else if (Objects.equals(item.getAttentionId(),userId) && !ids.contains(item.getCreateUserId())){ //他关注了我但是我没关注他说明被关注
+                }else if (Objects.nonNull(one) && Objects.isNull(one1)){ //他关注了我但是我没关注他说明被关注
                     item.setFansStatus("4");
                     item.setFansStatusName("被关注");
                 }else{//都没有说明未关注
@@ -381,14 +383,14 @@ public class TourWebFansController {
         //被关注人id列表
         Set<Long> collect = list.stream().map(TourFans::getAttentionId).collect(Collectors.toSet());
         //查询我关注的人的关注
-        List<TourFans> tourFans = tourFansService.list(new LambdaQueryWrapper<TourFans>().in(TourFans::getCreateUserId, collect) .eq(TourFans::getDeleteFlag, 1));
-        List<Long> longSet;
-        //过去出来我关注的人的关注
-        if (!tourFans.isEmpty()){
-            longSet =  tourFans.stream().map(TourFans::getAttentionId).collect(Collectors.toList());
-        } else {
-            longSet = new ArrayList<>();
-        }
+//        List<TourFans> tourFans = tourFansService.list(new LambdaQueryWrapper<TourFans>().in(TourFans::getCreateUserId, collect) .eq(TourFans::getDeleteFlag, 1));
+//        List<Long> longSet;
+//        过去出来我关注的人的关注
+//        if (!tourFans.isEmpty()){
+//            longSet =  tourFans.stream().map(TourFans::getAttentionId).collect(Collectors.toList());
+//        } else {
+//            longSet = new ArrayList<>();
+//        }
         //关注人id列表
         Set<Long> collecteds = list.stream().map(TourFans::getCreateUserId).collect(Collectors.toSet());
 
@@ -406,14 +408,16 @@ public class TourWebFansController {
             List<Map<String, Object>> mapList = tourFansService.listMaps(new QueryWrapper<TourFans>().select("count(*) as num,attention_id").lambda().in(TourFans::getAttentionId, longs) .eq(TourFans::getDeleteFlag, 1).groupBy(TourFans::getAttentionId));
             //设置匹配对应的粉丝数
             dataList.forEach(item->{
+                TourFans fans = tourFansService.getOne(new LambdaQueryWrapper<TourFans>().eq(TourFans::getAttentionId, item.getAttentionId()).eq(TourFans::getDeleteFlag, 1).eq(TourFans::getCreateUserId, userId));
+                TourFans tourFansServiceOne = tourFansService.getOne(new LambdaQueryWrapper<TourFans>().eq(TourFans::getAttentionId, userId).eq(TourFans::getDeleteFlag, 1).eq(TourFans::getCreateUserId, item.getAttentionId()));
                 //如果双等于说明互关
-                if (longSet.contains(userId) && collect.contains(Long.valueOf(item.getAttentionId()))) {
+                if (Objects.nonNull(fans) && Objects.nonNull(tourFansServiceOne)) {
                     item.setFansStatus("2");
                     item.setFansStatusName("互关");
-                }else if (!longSet.contains(userId) && collect.contains(Long.valueOf(item.getAttentionId()))){ //我关注他但是他没关注我说明单向关注
+                }else if (Objects.nonNull(fans) && !Objects.nonNull(tourFansServiceOne)){ //我关注他但是他没关注我说明单向关注
                     item.setFansStatus("1");
                     item.setFansStatusName("已关注");
-                }else if (longSet.contains(userId) && !collect.contains(Long.valueOf(item.getAttentionId()))){ //他关注了我但是我没关注他说明被关注
+                }else if (!Objects.nonNull(fans) && Objects.nonNull(tourFansServiceOne)){ //他关注了我但是我没关注他说明被关注
                     item.setFansStatus("4");
                     item.setFansStatusName("被关注");
                 }else{//都没有说明未关注