比如用户里面包含 所属公司 所属项目,部门,角色,这样UserWrapper里面查询转换的时候就会出现每一个用户都需要根据用户所属这些的id查询相关信息,如果100个用户就会出现 几百个sql执行,请问是我理解的有问题吗?或者这种问题应该如何解决?下面我贴出来UserWrapper代码
@Override public UserVO entityVO(User user) { UserVO userVO = BeanUtil.copy(user, UserVO.class); assert userVO != null; ListroleName = SysCache.getRoleNames(user.getRoleId()); List deptName = SysCache.getDeptNames(user.getDeptId()); if(StringUtil.isEmpty(user.getCompanyCode())){ userVO.setCompanyName("未分配"); }else{ List companyName = SysCache.getCompanyName(user.getCompanyCode()); userVO.setCompanyName(Func.join(companyName)); } userVO.setRoleName(Func.join(roleName)); userVO.setDeptName(Func.join(deptName)); userVO.setSexName(DictCache.getValue("sex", Func.toInt(user.getSex()))); Project project = null; if(user.getId()!= null){ project = SysCache.getProjectByUserId(user.getId()); } if(StringUtil.isEmpty(project)){ userVO.setProjectCode("0L"); userVO.setProjectName("未分配"); }else{ userVO.setProjectCode(project.getProjectCode()+""); userVO.setProjectName(project.getProjectName()); } return userVO; } @Override public List listVO(List list) { List collect = list.stream().map(this::entityVO).collect(Collectors.toList()); return collect; } @Override public IPage pageVO(IPage pages) { IPage userVOIPage = super.pageVO(pages); userVOIPage.setRecords(userVOIPage.getRecords().stream().map(this::entityVO).collect(Collectors.toList())); return userVOIPage; }
扫一扫访问 Blade技术社区 移动端