From 77d25195f86ae6ac7b021525b9f8d3890eae74e4 Mon Sep 17 00:00:00 2001
From: zqy <2522236926@qq.com>
Date: 星期五, 02 八月 2024 19:57:58 +0800
Subject: [PATCH] 分享

---
 zhang-content/src/main/java/com/ruoyi/service/impl/ZfAncestorServiceImpl.java |   99 +++++++++++++++++++++++++++++--------------------
 1 files changed, 58 insertions(+), 41 deletions(-)

diff --git a/zhang-content/src/main/java/com/ruoyi/service/impl/ZfAncestorServiceImpl.java b/zhang-content/src/main/java/com/ruoyi/service/impl/ZfAncestorServiceImpl.java
index f0f1aa5..158945a 100644
--- a/zhang-content/src/main/java/com/ruoyi/service/impl/ZfAncestorServiceImpl.java
+++ b/zhang-content/src/main/java/com/ruoyi/service/impl/ZfAncestorServiceImpl.java
@@ -10,10 +10,14 @@
 import com.ruoyi.domain.ZfClan;
 import com.ruoyi.mapper.ZfAncestorMapper;
 import com.ruoyi.service.*;
+import org.elasticsearch.action.delete.DeleteRequest;
+import org.elasticsearch.client.RequestOptions;
 import org.elasticsearch.client.RestHighLevelClient;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.io.IOException;
 import java.util.*;
 
 @Service
@@ -111,9 +115,11 @@
         LambdaQueryWrapper<ZfAncestor> lqw = buildCondition(zfAncestor);
         List<ZfAncestor> list = list(lqw);
         Long sysID = 0L;
+        System.out.println("15dniwru/"+list);
         if(list.size()>2){
             throw new RuntimeException("璇峰嬁閲嶅娣诲姞绁栧厛");
         }
+
         else if (list.size() == 1){
             if (list.get(0).getSex().equals(zfAncestor.getSex())){
                 throw new RuntimeException("涓や綅绁栧厛涓嶈兘涓哄悓鎬�");
@@ -203,22 +209,35 @@
     }
 
     @Override
-    public void update(ZfAncestor zfAncestor) {
+    public ZfAncestor update(ZfAncestor zfAncestor) {
         LambdaQueryWrapper<ZfAncestor> lqw = uniqueCondition(zfAncestor);
         List<ZfAncestor> list = list(lqw);
-        System.out.println(list);
+//        System.out.println(list);
         ZInfoUser updateDate =zInfoUserService.getInfoBysysId(zfAncestor.getSysId());
         ZfAncestor zfAncestor1 = new ZfAncestor();
+        ZfAncestor zfAncestor2 = new ZfAncestor();
         zfAncestor1.setId(list.get(0).getId());
         zfAncestor1.setName(zfAncestor.getName());
-        if((updateDate.getSpouseId() != null || updateDate.getSpouseId() != 0) && zfAncestor.getSex() !=null){
+        System.out.println(updateDate);
+        if (zfAncestor.getSex() != null){
+        if(updateDate.getSpouseId() != null && updateDate.getSpouseId() != 0){
             Long spouseId=updateDate.getSpouseId();
             if (zInfoUserService.getById(spouseId).getSex().equals(zfAncestor.getSex())){
-                throw new RuntimeException("绁栧厛涓や綅涓嶈兘涓哄悓鎬�");}
-            zfAncestor.setSex(zfAncestor.getSex());}
+
+                Long spouseSysId = zInfoUserService.getById(spouseId).getSysId();
+                zfAncestor2.setSysId(spouseSysId);
+                Integer spId = list(uniqueCondition(zfAncestor2)).get(0).getId();
+                zfAncestor2.setId(spId);
+                zfAncestor2.setSex(zfAncestor.getSex() == 0? 1: 0);
+                System.out.println(zfAncestor2);
+                zfAncestorService.updateById(zfAncestor2);
+            }}
+            zfAncestor1.setSex(zfAncestor.getSex());}
+//        System.out.println("1841vdndigrrr"+zfAncestor1);
 
             zfAncestorService.updateById(zfAncestor1);
 
+        return zfAncestor2;
     }
 
     /**
@@ -227,47 +246,45 @@
      */
     @Override
     public void deleteMember(Long ids) {
-//        LambdaQueryWrapper<ZfAncestor> lqw = new LambdaQueryWrapper<>();
-//        lqw.eq(ZfAncestor::getClanId,ids);
-//        List<ZfAncestor> zfAncestors =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 (ZfAncestor zfAncestor : zfAncestors) {
-//            ZInfoUser zInfoUser =  zInfoUserService.getById(Long.valueOf(zfAncestor.getMemberId()));
-//            zInfoUser.setClanId(0);
-//            System.out.println(zInfoUser);
-//            zInfoUserService.saveOrUpdate(zInfoUser);
-//            id.add(zfAncestor.getId());
+        LambdaQueryWrapper<ZfAncestor> lqw = new LambdaQueryWrapper<>();
+        lqw.eq(ZfAncestor::getClanId,ids);
+        List<ZfAncestor> zfAncestors =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 (ZfAncestor zfAncestor : zfAncestors) {
+            ZInfoUser zInfoUser =  zInfoUserService.getInfoBysysId(zfAncestor.getSysId());
+            zInfoUser.setClanId(0);
+            zInfoUserService.saveOrUpdate(zInfoUser);
+            id.add(zfAncestor.getId());
+//
+//        }
         /**
          * 鍦ㄧ敤鎴蜂俊鎭〃鍒犻櫎瀹舵棌鍙�
          */
 
 
+        if (zfAncestorService.removeByIds(id)) {
+            //鍒犻櫎es涓殑鏁版嵁
+            zfAncestors.stream().forEach(zfAncestor1 -> {
+                EsModel esModel = esSer.findByCtId((zfAncestor1.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);
+                    }
+                }
+            });
 
-//        if (zfAncestorService.removeByIds(id)) {
-//            //鍒犻櫎es涓殑鏁版嵁
-//            zfAncestors.stream().forEach(zfAncestor -> {
-//                EsModel esModel = esSer.findByCtId((zfAncestor.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