zqy
2024-07-31 2723e04976f006ace42c6c53627b87e1cc95ff07
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("两位祖先不能为同性");
@@ -240,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);
//                    }
//                }
//            });
//
//
//        }}
        }}}
        }