From 33785bbe06da21c85744e439fbe03d2ed2e055a4 Mon Sep 17 00:00:00 2001
From: whywhyo <1511349576@qq.com>
Date: 星期二, 23 五月 2023 16:39:24 +0800
Subject: [PATCH] 456
---
zhang-content/src/main/java/com/ruoyi/service/impl/ZInfoUserServiceImpl.java | 378 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 374 insertions(+), 4 deletions(-)
diff --git a/zhang-content/src/main/java/com/ruoyi/service/impl/ZInfoUserServiceImpl.java b/zhang-content/src/main/java/com/ruoyi/service/impl/ZInfoUserServiceImpl.java
index 9fa02f2..5db6910 100644
--- a/zhang-content/src/main/java/com/ruoyi/service/impl/ZInfoUserServiceImpl.java
+++ b/zhang-content/src/main/java/com/ruoyi/service/impl/ZInfoUserServiceImpl.java
@@ -3,6 +3,8 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.core.domain.AjaxResult;
@@ -13,6 +15,9 @@
import com.ruoyi.domain.ZInfoUser;
import com.ruoyi.domain.ZfEvent;
import com.ruoyi.domain.ZfRelation;
+import com.ruoyi.domain.dto.EmpowerDto;
+import com.ruoyi.domain.dto.Genealogy;
+import com.ruoyi.domain.dto.GenealogyExportDto;
import com.ruoyi.domain.dto.UserRelationDto;
import com.ruoyi.mapper.ZInfoUserMapper;
import com.ruoyi.service.ZInfoUserService;
@@ -23,10 +28,7 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
+import java.util.*;
import java.util.stream.Collectors;
/**
@@ -162,5 +164,373 @@
}
}
+ /**
+ * 缁欑敤鎴锋巿鏉冪殑鏂规硶
+ * @param empowerDto
+ * @return
+ */
+ @Override
+ @Transactional
+ public AjaxResult empower(EmpowerDto empowerDto) {
+
+ //寰楀埌dto涓殑淇℃伅
+ String otherUserId = empowerDto.getUserId();
+ String destinationFamilyId = empowerDto.getFamilyId();
+ List<String> authorityList = empowerDto.getAuthorityList();
+
+ String familyId = getMyFamilyId();
+ checkAuthorization(familyId, destinationFamilyId,true);
+
+ //鎺堟潈 //3{2007 1988 1004}
+ String finalStr = getFinalStr(destinationFamilyId, authorityList);
+
+ //鏇存柊琚巿鏉冪敤鎴风殑鏉冮檺
+ LambdaQueryWrapper<ZInfoUser> lqw2 = new LambdaQueryWrapper<>();
+ lqw2.eq(ZInfoUser::getUserId,otherUserId);
+ ZInfoUser otherUser = getOne(lqw2);
+ String secondFamilyId = otherUser.getSecondFamilyId();
+
+ String replaceFamilyId=null;
+
+ boolean save=true;
+
+ if (StringUtils.isNotEmpty(secondFamilyId)){
+ //濡傛灉鍘熸潵灏卞凡缁忔湁琚祴浜堟潈闄愪簡锛岄偅涔堥渶瑕佸垽鏂槸涓嶆槸璺熻繖涓搴彿鏈夊叧鐨勬潈闄�
+
+ //杩欎釜secondFamilyId鏄綋鍓嶇敤鎴风殑瀹屾暣鏉冮檺瀛楁
+ if(secondFamilyId.contains(",")){
+ String[] split = secondFamilyId.split(",");
+ for (int i = 0; i < split.length; i++) {
+ String fid = split[i].substring(0, split[i].indexOf("{"));//浠庢潈闄愬潡涓嬁鍒拌鎺堟潈鐨勫搴彿
+ if(fid.equals(finalStr.substring(0,finalStr.indexOf("{")))){
+ //濡傛灉鍖归厤鍒颁簡瀵瑰簲鐨勫搴彿锛岄偅涔堝氨鏇挎崲鎺夊搴旂殑鏉冮檺鍧楀氨鍙互浜嗭紝涓嶉渶瑕佽拷鍔�
+ save=false;
+ split[i]=finalStr;
+ break;
+ }
+ }
+ List<String> finalList = Arrays.asList(split);
+ StringBuilder stringBuilder = new StringBuilder();
+ for (String s : finalList) {
+ stringBuilder.append(s).append(",");
+ }
+ stringBuilder.deleteCharAt(stringBuilder.length()-1);
+
+ replaceFamilyId = stringBuilder.toString();
+
+ }else {
+ String fid = secondFamilyId.substring(0, secondFamilyId.indexOf("{"));//浠庢潈闄愬潡涓嬁鍒拌鎺堟潈鐨勫搴彿
+ if(fid.equals(finalStr.substring(0,finalStr.indexOf("{")))){
+ //濡傛灉鍖归厤鍒颁簡瀵瑰簲鐨勫搴彿锛岄偅涔堝氨鏇挎崲鎺夊搴旂殑鏉冮檺鍧楀氨鍙互浜嗭紝涓嶉渶瑕佽拷鍔�
+ save=false;
+ replaceFamilyId=finalStr;
+ }
+ }
+
+ if(save){
+ //闇�瑕佽拷鍔�,娌℃湁鍖归厤鍒板搴旂殑瀹跺涵鍙�
+ replaceFamilyId=secondFamilyId+","+finalStr;
+ }else {
+ //涓嶉渶瑕佽拷鍔�
+ }
+
+ }else {
+ //鍘熸潵灏辨病鏈夋潈闄愪簡
+ replaceFamilyId=finalStr;
+ }
+
+ LambdaUpdateWrapper<ZInfoUser> uw = new LambdaUpdateWrapper<>();
+ uw.eq(ZInfoUser::getUserId,otherUserId).set(ZInfoUser::getSecondFamilyId,replaceFamilyId);
+ if (update(null,uw)) {
+ return AjaxResult.success();
+ }else {
+ return AjaxResult.error();
+ }
+
+ }
+
+
+ private void checkAuthorization(String familyId, String destinationFamilyId,boolean flag) {
+ String text=null;
+ if(flag){
+ text="鎺堟潈";
+ }else {
+ text="鍙栨秷鎺堟潈";
+ }
+
+ //瀵规湰浜虹殑瀹跺涵鍙疯繘琛屽鐞�
+ if(familyId.contains(",")){
+ String[] familyIds = familyId.split(",");
+ List<String> idList = Arrays.asList(familyIds);
+ if (!idList.contains(destinationFamilyId)) {
+ throw new RuntimeException("涓嶈兘"+text+"涓嶅睘浜庤嚜宸卞搴殑鏁版嵁");
+ }
+ }else {
+ if (!familyId.equals(destinationFamilyId)){
+ throw new RuntimeException("涓嶈兘"+text+"涓嶅睘浜庤嚜宸卞搴殑鏁版嵁");
+ }
+ }
+ }
+
+ private String getMyFamilyId() {
+ //寰楀埌鑷繁鐨勫搴璱d淇℃伅
+ SysUser user = SecurityUtils.getLoginUser().getUser();
+ Long myUserId = user.getUserId();
+ LambdaQueryWrapper<ZInfoUser> lqw = new LambdaQueryWrapper<>();
+ lqw.eq(ZInfoUser::getUserId,myUserId);
+ ZInfoUser zInfoUser = getOne(lqw);
+ String familyId = zInfoUser.getFamilyId();
+ return familyId;
+ }
+
+ private String getFinalStr(String destinationFamilyId, List<String> authorityList) {
+ String authorityListStr = authorityList.stream().collect(Collectors.joining(" ", "{", "}"));
+ String finalStr= destinationFamilyId +authorityListStr; //3{2007 1988 1004}
+ return finalStr;
+ }
+
+
+ /**
+ * 鑾峰彇瀹舵牴缃�
+ * @return
+ */
+ @Override
+ public AjaxResult listWithTree(Integer depth) {
+
+ List<ZInfoUser> allPeopleList = list();
+ List<ZInfoUser> result = null;
+ try {
+ result = allPeopleList.stream().filter(people -> people.getUserId()!=1&&(people.getFatherId() == 0||people.getMomId()==0))
+ .map(people -> {
+ if(depth>1){
+ people.setIdentity(1);
+ people.setChildList(fillChildren(people, allPeopleList, depth-1));
+ }
+ return people;
+ }).collect(Collectors.toList());
+ } catch (NullPointerException e) {
+ throw new RuntimeException("鎮ㄥ湪鍔犲叆鎴愬憳鐨勬椂鍊欐病鏈夋寚瀹氳鎴愬憳鐨勭埗浜叉垨鑰呮瘝浜�");
+ }
+ return AjaxResult.success(result);
+
+ }
+
+ /**
+ * 鏉′欢鑾峰彇瀹跺涵鎴愬憳
+ * @return
+ */
+ public AjaxResult listWithTreeByCondition(Integer depth,Genealogy genealogy) {
+
+ ZInfoUser zInfoUser = new ZInfoUser();
+ BeanUtils.copyProperties(genealogy,zInfoUser);
+ LambdaQueryWrapper<ZInfoUser> lqw = new LambdaQueryWrapper<>();
+ lqw.eq(zInfoUser.getIdentity()!=null,ZInfoUser::getIdentity,zInfoUser.getIdentity());
+ lqw.eq(zInfoUser.getSex()!=null,ZInfoUser::getSex,zInfoUser.getSex());
+ lqw.like(StringUtils.isNotEmpty(zInfoUser.getNickName()),ZInfoUser::getNickName,zInfoUser.getNickName());
+ lqw.eq(zInfoUser.getBirth()!=null,ZInfoUser::getBirth,zInfoUser.getBirth());
+
+ List<ZInfoUser> allPeopleList = list(lqw);
+ List<ZInfoUser> result = null;
+ try {
+ result = allPeopleList.stream().filter(people -> people.getUserId()!=1&&(people.getFatherId() == 0||people.getMomId()==0))
+ .map(people -> {
+ if(depth>1){
+ people.setIdentity(1);
+ people.setChildList(fillChildren(people, allPeopleList, depth-1));
+ }
+ return people;
+ }).collect(Collectors.toList());
+ } catch (NullPointerException e) {
+ throw new RuntimeException("鎮ㄥ湪鍔犲叆鎴愬憳鐨勬椂鍊欐病鏈夋寚瀹氳鎴愬憳鐨勭埗浜叉垨鑰呮瘝浜�");
+ }
+ return AjaxResult.success(result);
+
+ }
+
+ private List<ZInfoUser> userList = new ArrayList<>();
+
+ /**
+ * 瀹惰氨淇℃伅
+ * @param genealogy
+ * @return
+ */
+ @Override
+ public AjaxResult listGenealogy(Genealogy genealogy,Integer pageNum,Integer pageSize) {
+ List<ZInfoUser> treeList= (List<ZInfoUser>) listWithTreeByCondition(100,genealogy).get("data");
+ recursionFindUser(treeList);
+
+ List<Genealogy> allData = userList.stream().map(
+ zInfoUser -> {
+ Genealogy newGenealogy = new Genealogy();
+ BeanUtils.copyProperties(zInfoUser, newGenealogy);
+
+ if(zInfoUser.getSpouseId()!=null){
+ ZInfoUser spouse = getById(zInfoUser.getSpouseId());
+ newGenealogy.setSpouseName(spouse.getNickName());
+ }
+ return newGenealogy;
+ }
+ ).collect(Collectors.toList());
+
+ List<Genealogy> collect = allData.stream().distinct().sorted(Comparator.comparing(Genealogy::getIdentity)).collect(Collectors.toList());
+ List<Genealogy> resultData= new ArrayList<>();
+
+ for (int i = (pageNum-1)*pageSize; i <pageNum*pageSize+pageSize; i++) {
+ if(i>=collect.size()){
+ break;
+ }
+ resultData.add(collect.get(i));
+ }
+
+ HashMap<String, Object> resultMap = new HashMap<>();
+ resultMap.put("data",resultData);
+ resultMap.put("total",collect.size());
+ resultMap.put("pageNum",pageNum);
+ resultMap.put("pageSize",pageSize);
+
+ return AjaxResult.success(resultMap);
+ }
+
+ @Override
+ public List<Genealogy> selectByIds(Long[] ids) {
+ List<ZInfoUser> zInfoUsers = listByIds(Arrays.asList(ids));
+ ArrayList<Genealogy> result = new ArrayList<>();
+ for (ZInfoUser zInfoUser : zInfoUsers) {
+ Genealogy genealogy = new Genealogy();
+ BeanUtils.copyProperties(zInfoUser,genealogy);
+ if(zInfoUser.getSpouseId()!=null){
+ ZInfoUser spouse = getById(zInfoUser.getSpouseId());
+ genealogy.setSpouseName(spouse.getNickName());
+ }
+ result.add(genealogy);
+ }
+
+ System.out.println("瀵煎嚭鐨勬暟鎹负:"+result);
+ return result;
+
+ }
+
+ @Override
+ public List<Genealogy> selectDatas(List<GenealogyExportDto> params) {
+ ArrayList<Long> ids = new ArrayList<>();
+ for (GenealogyExportDto param : params) {
+ ids.add(param.getId());
+ }
+
+ List<ZInfoUser> zInfoUsers = listByIds(ids);
+ ArrayList<Genealogy> result = new ArrayList<>();
+ for (int i = 0; i < zInfoUsers.size(); i++) {
+ Genealogy genealogy = new Genealogy();
+ BeanUtils.copyProperties(zInfoUsers.get(i),genealogy);
+ genealogy.setIdentity(params.get(i).getIdentity());
+ if(zInfoUsers.get(i).getSpouseId()!=null){
+ ZInfoUser spouse = getById(zInfoUsers.get(i).getSpouseId());
+ genealogy.setSpouseName(spouse.getNickName());
+ }
+ result.add(genealogy);
+
+ }
+ System.out.println("瀵煎嚭鐨勬暟鎹负:"+result);
+ return result;
+
+
+ }
+
+
+ private void recursionFindUser(List<ZInfoUser> treeList){
+ if (treeList==null||treeList.isEmpty()){
+ return;
+ }
+ for (ZInfoUser zInfoUser : treeList) {
+ userList.add(zInfoUser);
+ if (!zInfoUser.getChildList().isEmpty()){
+ recursionFindUser(zInfoUser.getChildList());
+ }
+ }
+ }
+
+ /**
+ * 涓轰簡瀹舵牴缃戙�佹柊澧炴垨鑰呬慨鏀圭埗瀛愬叧绯�
+ * @param fatherId
+ * @param motherId
+ * @return
+ */
+ @Override
+ public AjaxResult addParent(Long fatherId, Long motherId) {
+ SysUser user = SecurityUtils.getLoginUser().getUser();
+ Long userId = user.getUserId();
+ LambdaQueryWrapper<ZInfoUser> zInfoUserLambdaQueryWrapper = new LambdaQueryWrapper<>();
+ zInfoUserLambdaQueryWrapper.eq(ZInfoUser::getUserId,userId);
+ ZInfoUser zInfoUser = getOne(zInfoUserLambdaQueryWrapper);
+
+ zInfoUser.setFatherId(fatherId);
+ zInfoUser.setMomId(motherId);
+
+ updateById(zInfoUser);
+ return AjaxResult.success();
+ }
+
+ @Override
+ public AjaxResult listAllExceptAdmin() {
+ List<ZInfoUser> collect = list().stream().filter(zInfoUser -> zInfoUser.getUserId() != 1).collect(Collectors.toList());
+ return AjaxResult.success(collect);
+
+ }
+
+ @Override
+ public AjaxResult listMySelfAndSpouse(Long id) {
+ LambdaQueryWrapper<ZInfoUser> lqw1 = new LambdaQueryWrapper<>();
+ lqw1.eq(ZInfoUser::getUserId,id);
+ ZInfoUser myself = getOne(lqw1);
+ Long spouseId = myself.getSpouseId();
+
+ LambdaQueryWrapper<ZInfoUser> lqw2 = new LambdaQueryWrapper<>();
+ lqw2.eq(ZInfoUser::getUserId,spouseId);
+ ZInfoUser spouse = getOne(lqw2);
+
+ ArrayList<ZInfoUser> zInfoUsers = new ArrayList<>();
+ zInfoUsers.add(myself);
+ zInfoUsers.add(spouse);
+
+ return AjaxResult.success(zInfoUsers);
+ }
+
+
+
+ /**
+ * 閫掑綊绠楁硶
+ * @param people
+ * @param allPeopleList
+ * @return
+ */
+ private List<ZInfoUser> fillChildren(ZInfoUser people, List<ZInfoUser> allPeopleList, Integer depth) {
+
+ // TODO: 2023-05-05 鎺у埗閫掑綊鐨勬鏁�
+ // if(depth==layer)
+
+ // layer = layer + 1;
+ System.out.println(depth);
+ List<ZInfoUser> collect = allPeopleList.stream().filter(
+ one -> one.getFatherId() == people.getUserId() || one.getMomId() == people.getUserId()
+ ).map(
+ one -> {
+ if(depth==1)
+ return one;
+ else {
+ one.setIdentity(people.getIdentity()+1);
+ List<ZInfoUser> zinfo = fillChildren(one, allPeopleList, depth - 1);
+ one.setChildList(zinfo);
+ System.out.println(one);
+ return one;
+ }
+
+ //return one;
+ }
+ ).collect(Collectors.toList());
+ System.out.println(collect);
+ return collect;
+
+ }
+
}
--
Gitblit v1.9.1