From 4d6feaf54c97f51cec105bb7c96831379f4f1efb Mon Sep 17 00:00:00 2001 From: whywhyo <1511349576@qq.com> Date: 星期六, 10 六月 2023 23:59:54 +0800 Subject: [PATCH] 123 --- zhang-content/src/main/java/com/ruoyi/service/impl/ZInfoUserServiceImpl.java | 224 ++++++++++++++++++++++++++++++++++++++++++------------- 1 files changed, 169 insertions(+), 55 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 ae53517..6e8139c 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 @@ -15,8 +15,7 @@ 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.UserRelationDto; +import com.ruoyi.domain.dto.*; import com.ruoyi.mapper.ZInfoUserMapper; import com.ruoyi.service.ZInfoUserService; import com.ruoyi.service.ZfRelationService; @@ -26,10 +25,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; /** @@ -46,6 +42,9 @@ @Autowired private ZfRelationService zfRelationService; + + @Autowired + private ZInfoUserService zInfoUserService; @Override public AjaxResult selectInfoList(ZInfoUser zInfoUser, Integer pageNum, Integer pageSize) { @@ -94,55 +93,24 @@ } @Override - public AjaxResult searchMyRelation(Long userId) { + public AjaxResult searchMyRelation() { + + SysUser user = SecurityUtils.getLoginUser().getUser(); + Long userId = user.getUserId(); LambdaQueryWrapper<ZfRelation> lqw = new LambdaQueryWrapper<>(); lqw.eq(ZfRelation::getMyId,userId); - List<ZfRelation> relationList = zfRelationService.list(lqw); - ArrayList<UserRelationDto> otherUserList = new ArrayList<>(); - - relationList.stream().map( - (relation)->{ - Long otherId = relation.getOtherId(); - ZInfoUser otherUser = getById(otherId); - UserRelationDto userRelationDto = new UserRelationDto(); - BeanUtils.copyProperties(otherUser,userRelationDto); - userRelationDto.setRelation(relation.getRelation()); - userRelationDto.setId(relation.getId()); - otherUserList.add(userRelationDto); - return relation; - } - ).collect(Collectors.toList()); - - return AjaxResult.success(otherUserList); - } - - /** - * 妫�鏌ヤ紶鍏ュ鏂圭殑id鏄惁瀛樺湪 - * @param zfRelation - */ - private void checkRelation(ZfRelation zfRelation){ - - LambdaQueryWrapper<ZInfoUser> lqw = new LambdaQueryWrapper<>(); - lqw.eq(ZInfoUser::getUserId, zfRelation.getOtherId()); - - ZInfoUser zInfoUser2 = getOne(lqw); - if (zInfoUser2==null){ - throw new RuntimeException("瀵规柟鐨刬d涓嶅瓨鍦�"); - } + List<ZfRelation> list = zfRelationService.list(lqw); + return AjaxResult.success(list); } @Override @Transactional public AjaxResult addRelation(ZfRelation zfRelation) { - checkRelation(zfRelation); - - //鑾峰彇鑷繁鐨刬d骞朵紶鍏� SysUser user = SecurityUtils.getLoginUser().getUser(); Long userId = user.getUserId(); zfRelation.setMyId(userId); - zfRelationService.save(zfRelation); return AjaxResult.success(); } @@ -150,19 +118,14 @@ @Override @Transactional public AjaxResult updateRelation(ZfRelation zfRelation) { - checkRelation(zfRelation); zfRelationService.updateById(zfRelation); return AjaxResult.success(); } @Override public AjaxResult deleteRelation(Long[] ids) { - boolean flag = zfRelationService.removeByIds(Arrays.asList(ids)); - if (flag){ - return AjaxResult.success(); - }else { - return AjaxResult.error(); - } + zfRelationService.removeByIds(Arrays.asList(ids)); + return AjaxResult.success(); } /** @@ -303,7 +266,10 @@ try { result = allPeopleList.stream().filter(people -> people.getUserId()!=1&&(people.getFatherId() == 0||people.getMomId()==0)) .map(people -> { - people.setChildList(fillChildren(people, allPeopleList)); + if(depth>1){ + people.setIdentity(1); + people.setChildList(fillChildren(people, allPeopleList, depth-1)); + } return people; }).collect(Collectors.toList()); } catch (NullPointerException e) { @@ -311,6 +277,140 @@ } 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()); + } + } } /** @@ -359,25 +459,39 @@ return AjaxResult.success(zInfoUsers); } + + /** * 閫掑綊绠楁硶 * @param people * @param allPeopleList * @return */ - private List<ZInfoUser> fillChildren(ZInfoUser people, List<ZInfoUser> allPeopleList) { + 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 -> { - one.setChildList(fillChildren(one, allPeopleList)); - return 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