From c8a96c5e4ce5d5013a5ec508e2422f40ecdc311e Mon Sep 17 00:00:00 2001
From: zqy <2522236926@qq.com>
Date: 星期四, 25 七月 2024 19:10:59 +0800
Subject: [PATCH] 家族

---
 zhang-content/src/main/java/com/ruoyi/service/impl/ZfClanManageServiceImpl.java |  225 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 218 insertions(+), 7 deletions(-)

diff --git a/zhang-content/src/main/java/com/ruoyi/service/impl/ZfClanManageServiceImpl.java b/zhang-content/src/main/java/com/ruoyi/service/impl/ZfClanManageServiceImpl.java
index b08c7de..7d56973 100644
--- a/zhang-content/src/main/java/com/ruoyi/service/impl/ZfClanManageServiceImpl.java
+++ b/zhang-content/src/main/java/com/ruoyi/service/impl/ZfClanManageServiceImpl.java
@@ -1,28 +1,239 @@
 
 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.ZInfoUser;
 import com.ruoyi.domain.ZfClanManage;
 import com.ruoyi.mapper.ZfClanManageMapper;
-import com.ruoyi.service.ZfClanManageService;
+import com.ruoyi.service.*;
+import org.elasticsearch.action.delete.DeleteRequest;
+import org.elasticsearch.client.RequestOptions;
+import org.elasticsearch.client.RestHighLevelClient;
 import org.springframework.stereotype.Service;
+
+import javax.annotation.Resource;
+import java.io.IOException;
+import java.util.*;
+import java.util.stream.Collectors;
 
 @Service
 public class ZfClanManageServiceImpl extends ServiceImpl<ZfClanManageMapper, ZfClanManage> implements ZfClanManageService {
+
+    @Resource
+    private EsService esSer;
+
+    @Resource
+    ZInfoUserService zInfoUserService;
+
+    @Resource
+    private RestHighLevelClient restHighLevelClient;
+
+    @Resource
+    private ZfClanManageService zfClanManageService;
+
+    @Resource
+    private  ZfClanService zfClanService;
+
+//    @Resource
+//    private ISysUserService iSysUserService;
+
+    private LambdaQueryWrapper<ZfClanManage> buildCondition(ZfClanManage zfClanManage) {
+        LambdaQueryWrapper<ZfClanManage> lqw = new LambdaQueryWrapper<>();
+        lqw.orderByDesc(ZfClanManage::getId);
+        lqw.like(zfClanManage.getClanId() !=null , ZfClanManage::getClanId, zfClanManage.getClanId())
+                .like(zfClanManage.getMemberId() !=null, ZfClanManage::getClanId, zfClanManage.getClanId());
+        return lqw;
+    }
+
+    private LambdaQueryWrapper<ZfClanManage> uniqueCondition(ZfClanManage zfClanManage){
+        LambdaQueryWrapper<ZfClanManage> lqw = new LambdaQueryWrapper<>();
+        lqw.eq(zfClanManage.getClanId() !=null , ZfClanManage::getClanId, zfClanManage.getClanId());
+        lqw.eq(zfClanManage.getMemberId() !=null, ZfClanManage::getMemberId, zfClanManage.getMemberId());
+        return lqw;
+    }
+
+    /**
+     *
+     * 鑾峰彇褰撳墠鐢ㄦ埛鐨剆ysUserId
+     * @return
+     */
+    public Long getUserId(){
+        ZInfoUser myself = zInfoUserService.getMyself();
+
+        return zInfoUserService.getInfoBysysId( myself.getUserId()).getUserId();
+
+    }
+
+
     @Override
-    public AjaxResult selectDataList(ZfClanManage zfClanManage, Integer pageNum, Integer pageSize) {
-        return null;
+    public AjaxResult selectDataList(Integer clanId, Integer pageNo, Integer pageSize) {
+        ZfClanManage zfClanManage = new ZfClanManage();
+        zfClanManage.setClanId(clanId);
+        LambdaQueryWrapper<ZfClanManage> lqw = buildCondition(zfClanManage);
+        List<ZfClanManage> beanRecords = list(lqw);
+        List<HashMap<Integer, String>> zInfoUsers = new ArrayList<>();
+
+        for (ZfClanManage beanRecord:beanRecords) {
+            HashMap<Integer,String> idAndName = new HashMap<>();
+            String name = zInfoUserService.getById(Long.valueOf(beanRecord.getMemberId())).getNickName();
+            idAndName.put(beanRecord.getMemberId(),name);
+            zInfoUsers.add(idAndName);
+        }
+
+        List<HashMap<Integer, String>>  record =  zInfoUsers.stream().skip((pageNo-1)*pageSize).limit(pageSize).collect(Collectors.toList());
+
+        int totalPage = (record.size() -1) / pageSize +1;
+
+        Page<String> zInfoUserPage = new Page<>(pageNo, pageSize,totalPage);
+        HashMap<String, Object> data = MapUtils.getShareResult(zInfoUserPage, record,zInfoUsers.size());
+        return AjaxResult.success(data);
+    }
+
+    @Override
+    public void addA(Integer clanId,Integer memberId,Integer roleId){
+        ZfClanManage zfClanManage = new ZfClanManage();
+        zfClanManage.setClanId(clanId);
+        zfClanManage.setMemberId(memberId);
+        zfClanManage.setRoleId(roleId);
+        addData(zfClanManage);
     }
 
     @Override
     public AjaxResult addData(ZfClanManage zfClanManage) {
-        return null;
+//        LambdaQueryWrapper<ZfClanManage> lqw = uniqueCondition(zfClanManage);
+//        List<ZfClanManage> list = list(lqw);
+//        if(list.size()>0){
+//            throw new RuntimeException("璇峰嬁閲嶅娣诲姞鍚屼竴鎴愬憳");
+//        }
+
+
+//        if (!Long.valueOf(zfClanService.getById(zfClanManage.getClanId()).getAdminId()).equals(getUserId())) {
+//            throw new RuntimeException("鎮ㄤ笉鏄鐞嗗憳,娌℃湁鏉冨姏娣诲姞鎴愬憳");
+//
+//            }
+        /**
+         * 鍦ㄧ敤鎴蜂俊鎭〃娣诲姞瀹舵棌鍙�
+         */
+        ZInfoUser zInfoUser =  zInfoUserService.getById(Long.valueOf(zfClanManage.getMemberId()));
+        zInfoUser.setClanId(zfClanManage.getClanId());
+        zInfoUserService.saveOrUpdate(zInfoUser);
+
+        if (save(zfClanManage)) {
+            EsModel esModel = new EsModel();
+            Integer inte =zfClanManage.getClanId();
+            String uuid = UUID.randomUUID().toString().replace("-","");
+            esModel.setId(uuid);
+            esModel.setCtId(Long.valueOf(inte));
+            esModel.setCtTableName("瀹舵棌绠$悊");
+            esModel.setBy10(zfClanManage.getMemberId());
+
+            esModel.setBy5("/zfClanManage");
+//            esModel.setFid(familyId);
+            esSer.insertTable(esModel);
+//            System.out.println(esModel);
+
+            return AjaxResult.success();
+        } else {
+            return AjaxResult.error();
+
+        }
     }
 
+    /**
+     *閫氳繃id鍒犻櫎
+     */
     @Override
-    public AjaxResult deleteData(Long[] ids) {
-        return null;
+    public AjaxResult deleteData(Integer clanId,Integer id) {
+        ZfClanManage zfClanManage1 = new ZfClanManage();
+        zfClanManage1.setMemberId(id);
+        zfClanManage1.setClanId(clanId);
+        List<ZfClanManage> zfClanManages =list(buildCondition(zfClanManage1));
+//        for (ZfClanManage zfClanManage : zfClanManages) {
+//            if (!zfClanManages.getAdminId().equals(getUserId())) {
+//                throw new RuntimeException("鎮ㄤ笉鏄鐞嗗憳,娌℃湁鏉冨姏鍒犻櫎璇ュ鏃�");
+//            }
+//        }
+
+//        if (!Long.valueOf(zfClanService.getById(zfClanManages.get(0).getClanId()).getAdminId()).equals(getUserId())) {
+//                throw new RuntimeException("鎮ㄤ笉鏄鐞嗗憳,娌℃湁鏉冨姏鍒犻櫎鎴愬憳");
+//            }
+        /**
+         * 鍦ㄧ敤鎴蜂俊鎭〃鍒犻櫎瀹舵棌鍙�
+         */
+        ZInfoUser zInfoUser =  zInfoUserService.getById(Long.valueOf(zfClanManages.get(0).getMemberId()));
+        zInfoUser.setClanId(0);
+        zInfoUserService.saveOrUpdate(zInfoUser);
+
+        if (zfClanManageService.removeByIds(Arrays.asList(zfClanManages.get(0).getId()))) {
+
+            //鍒犻櫎es涓殑鏁版嵁
+            zfClanManages.stream().forEach(zfClanManage -> {
+                EsModel esModel = esSer.findByCtId((zfClanManage.getId().intValue()), "瀹舵棌绠$悊");
+                if (esModel != null) {
+                    DeleteRequest deleteRequest = new DeleteRequest("allsearchdata", esModel.getId());
+                    try {
+                        restHighLevelClient.delete(deleteRequest, RequestOptions.DEFAULT);
+                    } catch (IOException e) {
+                        throw new RuntimeException(e);
+                    }
+                }
+            });
+
+            return AjaxResult.success();
+        } else {
+            return AjaxResult.error();
+        }
     }
 
-}
+    /**
+     *閫氳繃瀹舵棌id鍒犻櫎
+     */
+    @Override
+    public void deleteMember(Long ids) {
+        LambdaQueryWrapper<ZfClanManage> lqw = new LambdaQueryWrapper<>();
+        lqw.eq(ZfClanManage::getClanId,ids);
+        List<ZfClanManage> zfClanManages =list(lqw) ;
+//        for (ZfClanManage zfClanManage : zfClanManages) {
+//            if (!zfClanManages.getAdminId().equals(getUserId())) {
+//                throw new RuntimeException("鎮ㄤ笉鏄鐞嗗憳,娌℃湁鏉冨姏鍒犻櫎璇ュ鏃�");
+//            }
+//        }
+
+//        if (!Long.valueOf(zfClanService.getById(zfClanManages.get(0).getClanId()).getAdminId()).equals(getUserId())) {
+//            throw new RuntimeException("鎮ㄤ笉鏄鐞嗗憳,娌℃湁鏉冨姏鍒犻櫎鎴愬憳");
+//        }
+        List<Integer> id = new ArrayList<>() ;
+        for (ZfClanManage zfClanManage: zfClanManages) {
+            ZInfoUser zInfoUser =  zInfoUserService.getById(Long.valueOf(zfClanManage.getMemberId()));
+            zInfoUser.setClanId(0);
+            System.out.println(zInfoUser);
+            zInfoUserService.saveOrUpdate(zInfoUser);
+            id.add(zfClanManage.getId());
+        }
+        /**
+         * 鍦ㄧ敤鎴蜂俊鎭〃鍒犻櫎瀹舵棌鍙�
+         */
+
+
+
+        if (zfClanManageService.removeByIds(id)) {
+            //鍒犻櫎es涓殑鏁版嵁
+            zfClanManages.stream().forEach(zfClanManage -> {
+                EsModel esModel = esSer.findByCtId((zfClanManage.getId().intValue()), "瀹舵棌绠$悊");
+                if (esModel != null) {
+                    DeleteRequest deleteRequest = new DeleteRequest("allsearchdata", esModel.getId());
+                    try {
+                        restHighLevelClient.delete(deleteRequest, RequestOptions.DEFAULT);
+                    } catch (IOException e) {
+                        throw new RuntimeException(e);
+                    }
+                }
+            });
+
+
+        }}}

--
Gitblit v1.9.1