From 46f46c73ef2cf1719f0de7c0258e6bcd4335966c Mon Sep 17 00:00:00 2001 From: whywhyo <1511349576@qq.com> Date: 星期二, 25 七月 2023 22:37:08 +0800 Subject: [PATCH] 519648 --- zhang-content/src/main/java/com/ruoyi/service/impl/ZInfoUserServiceImpl.java | 346 +++++++++++++++++++++++++++++++++------------------------ 1 files changed, 200 insertions(+), 146 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 5db6910..4455abc 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,19 +15,19 @@ 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.domain.dto.*; import com.ruoyi.mapper.ZInfoUserMapper; import com.ruoyi.service.ZInfoUserService; +import com.ruoyi.service.ZfFamilyService; import com.ruoyi.service.ZfRelationService; +import com.ruoyi.service.ZfRoleService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import javax.annotation.Resource; import java.util.*; import java.util.stream.Collectors; @@ -45,6 +45,15 @@ @Autowired private ZfRelationService zfRelationService; + + @Autowired + private ZInfoUserService zInfoUserService; + + @Resource + private ZfFamilyService zfFamilyService; + + @Resource + private ZfRoleService zfRoleService; @Override public AjaxResult selectInfoList(ZInfoUser zInfoUser, Integer pageNum, Integer pageSize) { @@ -93,55 +102,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(); } @@ -149,105 +127,105 @@ @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(); } - /** - * 缁欑敤鎴锋巿鏉冪殑鏂规硶 - * @param empowerDto - * @return - */ - @Override - @Transactional - public AjaxResult empower(EmpowerDto empowerDto) { +// @Override +// public AjaxResult empower(EmpowerDto empowerDto) { +// return null; +// } - //寰楀埌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(); - } - - } +// /** +// * 缁欑敤鎴锋巿鏉冪殑鏂规硶 +// * @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) { @@ -272,14 +250,14 @@ } } - private String getMyFamilyId() { + private Long 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(); + Long familyId = zInfoUser.getFamilyId(); return familyId; } @@ -299,18 +277,38 @@ 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("鎮ㄥ湪鍔犲叆鎴愬憳鐨勬椂鍊欐病鏈夋寚瀹氳鎴愬憳鐨勭埗浜叉垨鑰呮瘝浜�"); - } +// try { +// result = allPeopleList.stream().filter(people -> people.getUserId()!=1&&(people.getFatherId() == 0||people.getMomId()==0)) +// .map(people -> { +// if(depth>1){ +// people.setIdentity(1); +// //鏍规嵁閰嶅伓id鏌ヨ閰嶅伓鐨勬暟鎹紝灏佽濂戒竴璧疯繑鍥� +// Long spouseId = people.getSpouseId(); +// ZInfoUser spouse = zInfoUserService.getById(spouseId); +// spouse.setIdentity(1); +// people.setSpouse(spouse); +// people.setChildList(fillChildren(people, allPeopleList, depth-1)); +// } +// return people; +// }).collect(Collectors.toList()); +// } catch (NullPointerException e) { +// throw new RuntimeException("鎮ㄥ湪鍔犲叆鎴愬憳鐨勬椂鍊欐病鏈夋寚瀹氳鎴愬憳鐨勭埗浜叉垨鑰呮瘝浜�"); +// } + result = allPeopleList.stream().filter(people -> people.getUserId()!=1&&(people.getFatherId() == 0||people.getMomId()==0)&&people.getIsMyFamily()==1) + .map(people -> { + if(depth>1){ + people.setIdentity(1); + //鏍规嵁閰嶅伓id鏌ヨ閰嶅伓鐨勬暟鎹紝灏佽濂戒竴璧疯繑鍥� + Long spouseId = people.getSpouseId(); + ZInfoUser spouse = zInfoUserService.getById(spouseId); + spouse.setIdentity(1); + people.setSpouse(spouse); + people.setChildList(fillChildren(people, allPeopleList, depth-1)); + } + return people; + }).collect(Collectors.toList()); + + return AjaxResult.success(result); } @@ -436,6 +434,55 @@ } + @Override + public ZInfoUser getInfoById(Long userId) { + ZInfoUser user = getById(userId); + Long familyId = user.getFamilyId(); + String familyName = zfFamilyService.getById(familyId).getName(); + String roleName = zfRoleService.getById(user.getRoleId()).getName(); + user.setFamilyName(familyName); + user.setRoleName(roleName); + return user; + } + +// @Override +// public ZInfoUser getInfoById(Long userId) { +// +// ZInfoUser user = getById(userId); +// +// //鐢ㄩ�楀彿闅斿紑鐨勫搴璱d +// String familyId = user.getFamilyId(); +// +// //鍦ㄨ嚜宸卞搴腑瑙掕壊鐨刬d +// Long roleId = user.getRoleId(); +// +// ArrayList<String> familyList = new ArrayList<>(); +// +// //濉厖鎵�灞炲搴� +// if(familyId.contains(",")){ +// String[] familyIds = familyId.split(","); +// for (String id : familyIds) { +// familyList.add(zfFamilyService.getById(id).getName()); +// } +// }else { +// familyList.add(zfFamilyService.getById(familyId).getName()); +// } +// +// user.setFamilyList(familyList); +// +// //濉厖鎵�鍦ㄥ搴殑瑙掕壊 +// user.setRole(zfRoleService.getById(roleId).getName()); +// +// return user; +// } + + @Override + public ZInfoUser getMyself() { + SysUser user = SecurityUtils.getLoginUser().getUser(); + Long userId = user.getUserId(); + return getById(userId); + } + private void recursionFindUser(List<ZInfoUser> treeList){ if (treeList==null||treeList.isEmpty()){ @@ -511,13 +558,20 @@ // layer = layer + 1; System.out.println(depth); List<ZInfoUser> collect = allPeopleList.stream().filter( - one -> one.getFatherId() == people.getUserId() || one.getMomId() == people.getUserId() + one -> (one.getFatherId() == people.getUserId() || one.getMomId() == people.getUserId()) && (people.getIsMyFamily() == 1) ).map( one -> { if(depth==1) return one; else { one.setIdentity(people.getIdentity()+1); + //鏍规嵁閰嶅伓id鏌ヨ閰嶅伓鐨勬暟鎹紝灏佽濂戒竴璧疯繑鍥� + Long spouseId = one.getSpouseId(); + if(spouseId!=null){ + ZInfoUser spouse = zInfoUserService.getById(spouseId); + spouse.setIdentity(people.getIdentity()+1); + one.setSpouse(spouse); + } List<ZInfoUser> zinfo = fillChildren(one, allPeopleList, depth - 1); one.setChildList(zinfo); System.out.println(one); -- Gitblit v1.9.1