From f89ec4f39d08069d62c81062ca02a5507b24a622 Mon Sep 17 00:00:00 2001
From: zqy <2522236926@qq.com>
Date: 星期五, 10 一月 2025 22:40:27 +0800
Subject: [PATCH] 修改bug

---
 zhang-content/src/main/java/com/ruoyi/service/impl/ZfShareDataServiceImpl.java |   86 ++++++++++++++++++++++++++++++++++---------
 1 files changed, 68 insertions(+), 18 deletions(-)

diff --git a/zhang-content/src/main/java/com/ruoyi/service/impl/ZfShareDataServiceImpl.java b/zhang-content/src/main/java/com/ruoyi/service/impl/ZfShareDataServiceImpl.java
index 6f80223..6074162 100644
--- a/zhang-content/src/main/java/com/ruoyi/service/impl/ZfShareDataServiceImpl.java
+++ b/zhang-content/src/main/java/com/ruoyi/service/impl/ZfShareDataServiceImpl.java
@@ -1,11 +1,9 @@
 package com.ruoyi.service.impl;
 
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
-import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.core.domain.entity.EsModel;
-import com.ruoyi.common.utils.MapUtils;
 import com.ruoyi.domain.*;
 import com.ruoyi.mapper.ZfShareDataMapper;
 import com.ruoyi.service.EsService;
@@ -19,10 +17,8 @@
 
 import javax.annotation.Resource;
 import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
+import java.util.*;
+import java.util.stream.Collectors;
 
 @Service
 public class ZfShareDataServiceImpl extends ServiceImpl<ZfShareDataMapper, ZfShareData> implements ZfShareDataService {
@@ -34,11 +30,8 @@
     private RestHighLevelClient restHighLevelClient;
 
     @Resource
-    private ZfClanService zfClanService;
-
-
-    @Resource
     private EsService esSer;
+
     private LambdaQueryWrapper<ZfShareData> buildCondition(Long userId) {
         LambdaQueryWrapper<ZfShareData> lqw = new LambdaQueryWrapper<>();
         lqw.orderByDesc(ZfShareData::getId);
@@ -54,7 +47,7 @@
     }
 
     @Override
-    public List<ZfShareData> selectList() {
+    public List<ZfShareData> selectList(ZfShareData zfShareData) {
         LambdaQueryWrapper<ZfShareData> lqw = buildCondition(getUserId());
 
         return list(lqw);
@@ -75,7 +68,7 @@
         return myself.getUserId();
 
     }
-
+    @Override
     public Long getSource(Long userId){
         LambdaQueryWrapper<ZfShareData> lqw = new LambdaQueryWrapper<>();
         lqw.orderByDesc(ZfShareData::getId);
@@ -85,6 +78,16 @@
         }
         return getSource(list(lqw).get(0).getUserId().longValue());
     }
+    @Override
+    public Long getEnd(Long userId){
+        LambdaQueryWrapper<ZfShareData> lqw1 = new LambdaQueryWrapper<>();
+        lqw1.eq(ZfShareData::getUserId,userId);
+        if (list(lqw1).size() == 0){
+            return userId;
+        }
+        return getEnd(list(lqw1).get(list(lqw1).size()-1).getSharedId().longValue());
+    }
+
     @Override
     public AjaxResult addData(Long[] userIds) {
 
@@ -129,22 +132,61 @@
         }
     }
 
+
+    private LambdaQueryWrapper<ZfShareData> selectByUserId(List<Long> userId) {
+        LambdaQueryWrapper<ZfShareData> lqw = new LambdaQueryWrapper<>();
+        lqw.in(ZfShareData::getSharedId,userId);
+        return lqw;
+    }
+
+    private LambdaQueryWrapper<ZfShareData> selectBySharedId(List<Long> userId) {
+        LambdaQueryWrapper<ZfShareData> lqw = new LambdaQueryWrapper<>();
+        lqw.in(ZfShareData::getUserId,userId);
+        return lqw;
+    }
+
+    @Override
+    public List<Long> getAllPerson(List<Long> userIds){
+        List<ZfShareData> lists = new ArrayList<>(list(selectByUserId(userIds)));
+        lists.addAll(list(selectBySharedId(userIds)));
+
+        if (userIds.contains(getEnd(getSource(userIds.get(0))))){
+            return userIds;
+        }
+
+        return getAllPerson(lists.stream().map(ZfShareData::getSharedId).map(Integer::longValue).collect(Collectors.toList()));
+
+    }
+
     @Override
     public AjaxResult setAdmin(Long userId,Long id) {
-        List<ZfShareData> list = list(buildCondition(getSource(userId)));
-        list.addAll(getShareId(userId));
-        for (ZfShareData zfShareData1:list){
+        Long source = getSource(userId);
+        List<Long> all = getAllPerson(Collections.singletonList(source));
+        List<Long> collect = all.stream().distinct().collect(Collectors.toList());
+        collect.add(source);
+
+        List<ZfShareData> list = list(selectByUserId(collect));
+        list.addAll(list(selectBySharedId(collect)));
+        List<ZfShareData> collect1 = list.stream().distinct().collect(Collectors.toList());
+        for (ZfShareData zfShareData1:collect1){
             zfShareData1.setMasterAccount(id.intValue());
             updateById(zfShareData1);
         }
+
         return AjaxResult.success();
     }
 
     @Override
     public AjaxResult allUser(Long id) {
-        List<ZfShareData> list = list(buildCondition(getSource(id)));
-        list.addAll(getShareId(id));
-        for (ZfShareData zfShareData1:list){
+        Long source = getSource(id);
+        List<Long> all = getAllPerson(Collections.singletonList(source));
+        List<Long> collect = all.stream().distinct().collect(Collectors.toList());
+        collect.add(source);
+
+        List<ZfShareData> list = list(selectByUserId(collect));
+        list.addAll(list(selectBySharedId(collect)));
+        List<ZfShareData> collect1 = list.stream().distinct().collect(Collectors.toList());
+        for (ZfShareData zfShareData1:collect1){
             zfShareData1.setMasterAccount(0);
             updateById(zfShareData1);
         }
@@ -158,4 +200,12 @@
         lqw.eq(ZfShareData::getSharedId,id);
         return list(lqw);
     }
+
+    @Override
+    public List<ZfShareData> getByShareId(List<Long> id) {
+        LambdaQueryWrapper<ZfShareData> lqw = new LambdaQueryWrapper<>();
+        lqw.orderByDesc(ZfShareData::getId);
+        lqw.in(ZfShareData::getSharedId,id);
+        return list(lqw);
+    }
 }

--
Gitblit v1.9.1