| | |
| | | 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; |
| | |
| | | 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; |
| | | |
| | | /** |
| | |
| | | |
| | | } |
| | | |
| | | |
| | | private void checkAuthorization(String familyId, String destinationFamilyId,boolean flag) { |
| | | String text=null; |
| | | if(flag){ |
| | |
| | | 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 |
| | | */ |
| | | @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; |
| | | |
| | | } |
| | | |
| | | |
| | | } |