Java Code Examples for com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper#in()

The following examples show how to use com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper#in() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SysMenuServiceImpl.java    From pre with GNU General Public License v3.0 6 votes vote down vote up
@Override
public List<SysMenu> selectMenuTree(Integer uid) {

    LambdaQueryWrapper<SysMenu> sysMenuLambdaQueryWrapper = Wrappers.<SysMenu>query().lambda();
    sysMenuLambdaQueryWrapper.select(SysMenu::getMenuId, SysMenu::getName, SysMenu::getPerms, SysMenu::getPath, SysMenu::getParentId, SysMenu::getComponent, SysMenu::getIsFrame, SysMenu::getIcon, SysMenu::getSort, SysMenu::getType, SysMenu::getDelFlag);
    // 所有人有权限看到 只是没有权限操作而已 暂定这样
    if (uid != 0) {
        List<Integer> menuIdList = roleMenuService.getMenuIdByUserId(uid);
        sysMenuLambdaQueryWrapper.in(SysMenu::getMenuId, menuIdList);
    }
    List<SysMenu> sysMenus = new ArrayList<>();
    List<SysMenu> menus = baseMapper.selectList(sysMenuLambdaQueryWrapper);
    menus.forEach(menu -> {
        if (menu.getParentId() == null || menu.getParentId() == 0) {
            menu.setLevel(0);
            if (PreUtil.exists(sysMenus, menu)) {
                sysMenus.add(menu);
            }
        }
    });
    sysMenus.sort((o1, o2) -> o1.getSort().compareTo(o2.getSort()));
    PreUtil.findChildren(sysMenus, menus, 0);
    return sysMenus;
}
 
Example 2
Source File: SysRolePermissionServiceImpl.java    From Taroco with Apache License 2.0 6 votes vote down vote up
@Override
public IPage<SysPermission> rolePermissionsAdded(final PageQuery<SysPermission> pageQuery, final Integer roleId, final Map<String, Object> params) {
    final Set<Integer> permissionIds = getPermissionIds(roleId);
    if (CollectionUtils.isEmpty(permissionIds)) {
        return new Page<>();
    }
    final SysPermission sysPermission = new SysPermission();
    sysPermission.setDelFlag(CommonConstant.STATUS_NORMAL);
    final LambdaQueryWrapper<SysPermission> wrapper = new LambdaQueryWrapper<>(sysPermission);
    wrapper.in(SysPermission::getId, permissionIds);
    final String perName = "perName";
    if (params.containsKey(perName) && !StringUtils.isEmpty(params.get(perName))) {
        wrapper.like(SysPermission::getName, params.get(perName));
    }
    return sysPermissionService.page(pageQuery, wrapper);
}
 
Example 3
Source File: SysUserRoleServiceImpl.java    From Taroco with Apache License 2.0 6 votes vote down vote up
@Override
public IPage<SysUser> roleMembersAdded(final PageQuery<SysUser> pageQuery, final Integer roleId, final Map<String, Object> params) {
    final Set<Integer> userIds = getUserIds(roleId);
    if (CollectionUtils.isEmpty(userIds)) {
        return new Page<>();
    }
    final SysUser sysUser = new SysUser();
    sysUser.setDelFlag(CommonConstant.STATUS_NORMAL);
    final LambdaQueryWrapper<SysUser> wrapper = new LambdaQueryWrapper<>(sysUser);
    wrapper.in(SysUser::getUserId, userIds);
    final String username = "username";
    if (params.containsKey(username) && !StringUtils.isEmpty(params.get(username))) {
        wrapper.like(SysUser::getUsername, params.get(username));
    }
    return sysUserService.page(pageQuery, wrapper);
}
 
Example 4
Source File: MenuServiceImpl.java    From spring-boot-tutorial with Creative Commons Attribution Share Alike 4.0 International 6 votes vote down vote up
private void delete(List<String> menuIds) {
    List<String> list = new ArrayList<>(menuIds);
    removeByIds(menuIds);

    LambdaQueryWrapper<Menu> queryWrapper = new LambdaQueryWrapper<>();
    queryWrapper.in(Menu::getParentId, menuIds);
    List<Menu> menus = baseMapper.selectList(queryWrapper);
    if (CollectionUtils.isNotEmpty(menus)) {
        List<String> menuIdList = new ArrayList<>();
        menus.forEach(m -> menuIdList.add(String.valueOf(m.getMenuId())));
        list.addAll(menuIdList);
        this.roleMenuService.deleteRoleMenusByMenuId(list);
        this.delete(menuIdList);
    } else {
        this.roleMenuService.deleteRoleMenusByMenuId(list);
    }
}
 
Example 5
Source File: SysDepartServiceImpl.java    From jeecg-cloud with Apache License 2.0 6 votes vote down vote up
/**
 * 根据用户所负责部门ids获取父级部门编码
 * @param departIds
 * @return
 */
private String[] getMyDeptParentOrgCode(String departIds){
	//根据部门id查询所负责部门
	LambdaQueryWrapper<SysDepart> query = new LambdaQueryWrapper<SysDepart>();
	query.eq(SysDepart::getDelFlag, CommonConstant.DEL_FLAG_0.toString());
	query.in(SysDepart::getId, Arrays.asList(departIds.split(",")));
	query.orderByAsc(SysDepart::getOrgCode);
	List<SysDepart> list = this.list(query);
	//查找根部门
	if(list == null || list.size()==0){
		return null;
	}
	String orgCode = this.getMyDeptParentNode(list);
	String[] codeArr = orgCode.split(",");
	return codeArr;
}
 
Example 6
Source File: SysDepartServiceImpl.java    From jeecg-boot with Apache License 2.0 6 votes vote down vote up
/**
 * 根据用户所负责部门ids获取父级部门编码
 * @param departIds
 * @return
 */
private String[] getMyDeptParentOrgCode(String departIds){
	//根据部门id查询所负责部门
	LambdaQueryWrapper<SysDepart> query = new LambdaQueryWrapper<SysDepart>();
	query.eq(SysDepart::getDelFlag, CommonConstant.DEL_FLAG_0.toString());
	query.in(SysDepart::getId, Arrays.asList(departIds.split(",")));
	query.orderByAsc(SysDepart::getOrgCode);
	List<SysDepart> list = this.list(query);
	//查找根部门
	if(list == null || list.size()==0){
		return null;
	}
	String orgCode = this.getMyDeptParentNode(list);
	String[] codeArr = orgCode.split(",");
	return codeArr;
}
 
Example 7
Source File: SysDepartPermissionServiceImpl.java    From jeecg-cloud with Apache License 2.0 5 votes vote down vote up
@Override
public List<SysPermissionDataRule> getPermRuleListByDeptIdAndPermId(String departId, String permissionId) {
    SysDepartPermission departPermission = this.getOne(new QueryWrapper<SysDepartPermission>().lambda().eq(SysDepartPermission::getDepartId, departId).eq(SysDepartPermission::getPermissionId, permissionId));
    if(departPermission != null){
        LambdaQueryWrapper<SysPermissionDataRule> query = new LambdaQueryWrapper<SysPermissionDataRule>();
        query.in(SysPermissionDataRule::getId, Arrays.asList(departPermission.getDataRuleIds().split(",")));
        query.orderByDesc(SysPermissionDataRule::getCreateTime);
        List<SysPermissionDataRule> permRuleList = this.ruleMapper.selectList(query);
        return permRuleList;
    }else{
        return null;
    }
}
 
Example 8
Source File: SysPermissionController.java    From jeecg-cloud with Apache License 2.0 5 votes vote down vote up
/**
 * 查询子菜单
 *
 * @param parentIds 父ID(多个采用半角逗号分割)
 * @return 返回 key-value 的 Map
 */
@GetMapping("/getSystemSubmenuBatch")
public Result getSystemSubmenuBatch(@RequestParam("parentIds") String parentIds) {
	try {
		LambdaQueryWrapper<SysPermission> query = new LambdaQueryWrapper<>();
		List<String> parentIdList = Arrays.asList(parentIds.split(","));
		query.in(SysPermission::getParentId, parentIdList);
		query.eq(SysPermission::getDelFlag, CommonConstant.DEL_FLAG_0);
		query.orderByAsc(SysPermission::getSortNo);
		List<SysPermission> list = sysPermissionService.list(query);
		Map<String, List<SysPermissionTree>> listMap = new HashMap<>();
		for (SysPermission item : list) {
			String pid = item.getParentId();
			if (parentIdList.contains(pid)) {
				List<SysPermissionTree> mapList = listMap.get(pid);
				if (mapList == null) {
					mapList = new ArrayList<>();
				}
				mapList.add(new SysPermissionTree(item));
				listMap.put(pid, mapList);
			}
		}
		return Result.ok(listMap);
	} catch (Exception e) {
		log.error(e.getMessage(), e);
		return Result.error("批量查询子菜单失败:" + e.getMessage());
	}
}
 
Example 9
Source File: SysUserDepartServiceImpl.java    From jeecg-cloud with Apache License 2.0 5 votes vote down vote up
/**
 * 根据用户id查询部门信息
 */
@Override
public List<DepartIdModel> queryDepartIdsOfUser(String userId) {
	LambdaQueryWrapper<SysUserDepart> queryUDep = new LambdaQueryWrapper<SysUserDepart>();
	LambdaQueryWrapper<SysDepart> queryDep = new LambdaQueryWrapper<SysDepart>();
	try {
		queryUDep.eq(SysUserDepart::getUserId, userId);
		List<String> depIdList = new ArrayList<>();
		List<DepartIdModel> depIdModelList = new ArrayList<>();
		List<SysUserDepart> userDepList = this.list(queryUDep);
		if(userDepList != null && userDepList.size() > 0) {
		for(SysUserDepart userDepart : userDepList) {
				depIdList.add(userDepart.getDepId());
			}
		queryDep.in(SysDepart::getId, depIdList);
		List<SysDepart> depList = sysDepartService.list(queryDep);
		if(depList != null || depList.size() > 0) {
			for(SysDepart depart : depList) {
				depIdModelList.add(new DepartIdModel().convertByUserDepart(depart));
			}
		}
		return depIdModelList;
		}
	}catch(Exception e) {
		e.fillInStackTrace();
	}
	return null;
	
	
}
 
Example 10
Source File: MenuHelper.java    From spring-cloud-shop with MIT License 5 votes vote down vote up
/**
 * 通过角色查询当前角色所拥有的权限
 *
 * @param roleIds 角色主键集
 * @return 菜单集
 */
public List<Menu> selectMenuByRoleIds(final List<Long> roleIds) {
    // 角色所属权限编码
    LambdaQueryWrapper<RoleMenu> roleMenuWrapper = new LambdaQueryWrapper<>();
    roleMenuWrapper.eq(RoleMenu::getDeleteStatus, Boolean.FALSE);
    roleMenuWrapper.in(RoleMenu::getRoleId, roleIds);
    List<RoleMenu> roleMenus = roleMenuMapper.selectList(roleMenuWrapper);

    if (CollectionUtils.isEmpty(roleMenus)) {
        return Collections.emptyList();
    }

    List<String> permissions = roleMenus.stream()
            .filter(item -> !StringUtils.isEmpty(item.getPermission()))
            .map(RoleMenu::getPermission)
            .distinct()
            .collect(Collectors.toList());

    if (CollectionUtils.isEmpty(permissions)) {
        return Collections.emptyList();
    }

    LambdaQueryWrapper<Menu> menuWrapper = new LambdaQueryWrapper<>();
    menuWrapper.eq(Menu::getDeleteStatus, Boolean.FALSE);
    menuWrapper.in(Menu::getPermission, permissions);
    menuWrapper.orderByAsc(Menu::getSequence);
    return menuMapper.selectList(menuWrapper);
}
 
Example 11
Source File: SysUserDepartServiceImpl.java    From jeecg-boot-with-activiti with MIT License 5 votes vote down vote up
/**
 * 根据用户id查询部门信息
 */
@Override
public List<DepartIdModel> queryDepartIdsOfUser(String userId) {
	LambdaQueryWrapper<SysUserDepart> queryUDep = new LambdaQueryWrapper<SysUserDepart>();
	LambdaQueryWrapper<SysDepart> queryDep = new LambdaQueryWrapper<SysDepart>();
	try {
		queryUDep.eq(SysUserDepart::getUserId, userId);
		List<String> depIdList = new ArrayList<>();
		List<DepartIdModel> depIdModelList = new ArrayList<>();
		List<SysUserDepart> userDepList = this.list(queryUDep);
		if(userDepList != null && userDepList.size() > 0) {
		for(SysUserDepart userDepart : userDepList) {
				depIdList.add(userDepart.getDepId());
			}
		queryDep.in(SysDepart::getId, depIdList);
		List<SysDepart> depList = sysDepartService.list(queryDep);
		if(depList != null || depList.size() > 0) {
			for(SysDepart depart : depList) {
				depIdModelList.add(new DepartIdModel().convertByUserDepart(depart));
			}
		}
		return depIdModelList;
		}
	}catch(Exception e) {
		e.fillInStackTrace();
	}
	return null;
	
	
}
 
Example 12
Source File: DeptServiceImpl.java    From FEBS-Cloud with Apache License 2.0 5 votes vote down vote up
private void delete(List<String> deptIds) {
    removeByIds(deptIds);
    userDataPermissionService.deleteByDeptIds(deptIds);

    LambdaQueryWrapper<Dept> queryWrapper = new LambdaQueryWrapper<>();
    queryWrapper.in(Dept::getParentId, deptIds);
    List<Dept> depts = baseMapper.selectList(queryWrapper);
    if (CollectionUtils.isNotEmpty(depts)) {
        List<String> deptIdList = new ArrayList<>();
        depts.forEach(d -> deptIdList.add(String.valueOf(d.getDeptId())));
        this.delete(deptIdList);
    }
}
 
Example 13
Source File: SysDepartPermissionServiceImpl.java    From jeecg-boot with Apache License 2.0 5 votes vote down vote up
@Override
public List<SysPermissionDataRule> getPermRuleListByDeptIdAndPermId(String departId, String permissionId) {
    SysDepartPermission departPermission = this.getOne(new QueryWrapper<SysDepartPermission>().lambda().eq(SysDepartPermission::getDepartId, departId).eq(SysDepartPermission::getPermissionId, permissionId));
    if(departPermission != null){
        LambdaQueryWrapper<SysPermissionDataRule> query = new LambdaQueryWrapper<SysPermissionDataRule>();
        query.in(SysPermissionDataRule::getId, Arrays.asList(departPermission.getDataRuleIds().split(",")));
        query.orderByDesc(SysPermissionDataRule::getCreateTime);
        List<SysPermissionDataRule> permRuleList = this.ruleMapper.selectList(query);
        return permRuleList;
    }else{
        return null;
    }
}
 
Example 14
Source File: SysPermissionController.java    From jeecg-boot with Apache License 2.0 5 votes vote down vote up
/**
 * 查询子菜单
 *
 * @param parentIds 父ID(多个采用半角逗号分割)
 * @return 返回 key-value 的 Map
 */
@GetMapping("/getSystemSubmenuBatch")
public Result getSystemSubmenuBatch(@RequestParam("parentIds") String parentIds) {
	try {
		LambdaQueryWrapper<SysPermission> query = new LambdaQueryWrapper<>();
		List<String> parentIdList = Arrays.asList(parentIds.split(","));
		query.in(SysPermission::getParentId, parentIdList);
		query.eq(SysPermission::getDelFlag, CommonConstant.DEL_FLAG_0);
		query.orderByAsc(SysPermission::getSortNo);
		List<SysPermission> list = sysPermissionService.list(query);
		Map<String, List<SysPermissionTree>> listMap = new HashMap<>();
		for (SysPermission item : list) {
			String pid = item.getParentId();
			if (parentIdList.contains(pid)) {
				List<SysPermissionTree> mapList = listMap.get(pid);
				if (mapList == null) {
					mapList = new ArrayList<>();
				}
				mapList.add(new SysPermissionTree(item));
				listMap.put(pid, mapList);
			}
		}
		return Result.ok(listMap);
	} catch (Exception e) {
		log.error(e.getMessage(), e);
		return Result.error("批量查询子菜单失败:" + e.getMessage());
	}
}
 
Example 15
Source File: SysUserDepartServiceImpl.java    From teaching with Apache License 2.0 5 votes vote down vote up
/**
 * 根据用户id查询部门信息
 */
@Override
public List<DepartIdModel> queryDepartIdsOfUser(String userId) {
	LambdaQueryWrapper<SysUserDepart> queryUDep = new LambdaQueryWrapper<SysUserDepart>();
	LambdaQueryWrapper<SysDepart> queryDep = new LambdaQueryWrapper<SysDepart>();
	try {
		queryUDep.eq(SysUserDepart::getUserId, userId);
		List<String> depIdList = new ArrayList<>();
		List<DepartIdModel> depIdModelList = new ArrayList<>();
		List<SysUserDepart> userDepList = this.list(queryUDep);
		if(userDepList != null && userDepList.size() > 0) {
		for(SysUserDepart userDepart : userDepList) {
				depIdList.add(userDepart.getDepId());
			}
		queryDep.in(SysDepart::getId, depIdList);
		List<SysDepart> depList = sysDepartService.list(queryDep);
		if(depList != null || depList.size() > 0) {
			for(SysDepart depart : depList) {
				depIdModelList.add(new DepartIdModel().convertByUserDepart(depart));
			}
		}
		return depIdModelList;
		}
	}catch(Exception e) {
		e.fillInStackTrace();
	}
	return null;
	
	
}
 
Example 16
Source File: SysUserDepartServiceImpl.java    From teaching with Apache License 2.0 5 votes vote down vote up
/**
 * 根据部门code,查询当前部门和下级部门的 用户信息
 */
@Override
public List<SysUser> queryUserByDepCode(String depCode) {
	LambdaQueryWrapper<SysDepart> queryByDepCode = new LambdaQueryWrapper<SysDepart>();
	queryByDepCode.likeRight(SysDepart::getOrgCode,depCode);
	List<SysDepart> sysDepartList = sysDepartService.list(queryByDepCode);
	List<String> depIds = sysDepartList.stream().map(SysDepart::getId).collect(Collectors.toList());

	LambdaQueryWrapper<SysUserDepart> queryUDep = new LambdaQueryWrapper<SysUserDepart>();
	queryUDep.in(SysUserDepart::getDepId, depIds);
	List<String> userIdList = new ArrayList<>();
	List<SysUserDepart> uDepList = this.list(queryUDep);
	if(uDepList != null && uDepList.size() > 0) {
		for(SysUserDepart uDep : uDepList) {
			userIdList.add(uDep.getUserId());
		}
		List<SysUser> userList = (List<SysUser>) sysUserService.listByIds(userIdList);
		//update-begin-author:taoyan date:201905047 for:接口调用查询返回结果不能返回密码相关信息
		for (SysUser sysUser : userList) {
			sysUser.setSalt("");
			sysUser.setPassword("");
		}
		//update-end-author:taoyan date:201905047 for:接口调用查询返回结果不能返回密码相关信息
		return userList;
	}
	return new ArrayList<SysUser>();
}
 
Example 17
Source File: DeptServiceImpl.java    From spring-boot-tutorial with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
private void delete(List<String> deptIds) {
    removeByIds(deptIds);

    LambdaQueryWrapper<Dept> queryWrapper = new LambdaQueryWrapper<>();
    queryWrapper.in(Dept::getParentId, deptIds);
    List<Dept> depts = baseMapper.selectList(queryWrapper);
    if (CollectionUtils.isNotEmpty(depts)) {
        List<String> deptIdList = new ArrayList<>();
        depts.forEach(d -> deptIdList.add(String.valueOf(d.getDeptId())));
        this.delete(deptIdList);
    }
}
 
Example 18
Source File: OauthClientDetailsServiceImpl.java    From FEBS-Cloud with Apache License 2.0 5 votes vote down vote up
@Override
@Transactional(rollbackFor = Exception.class)
public void deleteOauthClientDetails(String clientIds) {
    Object[] clientIdArray = StringUtils.splitByWholeSeparatorPreserveAllTokens(clientIds, StringConstant.COMMA);
    LambdaQueryWrapper<OauthClientDetails> queryWrapper = new LambdaQueryWrapper<>();
    queryWrapper.in(OauthClientDetails::getClientId, clientIdArray);
    boolean removed = this.remove(queryWrapper);
    if (removed) {
        log.info("删除ClientId为({})的Client", clientIds);
        Arrays.stream(clientIdArray).forEach(c -> this.redisClientDetailsService.removeRedisCache(String.valueOf(c)));

    }
}
 
Example 19
Source File: MenuServiceImpl.java    From FEBS-Cloud with Apache License 2.0 5 votes vote down vote up
private void delete(List<String> menuIds) {
    removeByIds(menuIds);

    LambdaQueryWrapper<Menu> queryWrapper = new LambdaQueryWrapper<>();
    queryWrapper.in(Menu::getParentId, menuIds);
    List<Menu> menus = baseMapper.selectList(queryWrapper);
    if (CollectionUtils.isNotEmpty(menus)) {
        List<String> menuIdList = new ArrayList<>();
        menus.forEach(m -> menuIdList.add(String.valueOf(m.getMenuId())));
        this.delete(menuIdList);
    }
}
 
Example 20
Source File: OnlineInterceptor.java    From jeecg-boot with Apache License 2.0 4 votes vote down vote up
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
    // 请求的方法是否有注解
    boolean anno = handler.getClass().isAssignableFrom(HandlerMethod.class);
    if (anno) {
        OnlineAuth onlineAuth = ((HandlerMethod) handler).getMethodAnnotation(OnlineAuth.class);
        if (onlineAuth != null) {
            String requestPath = request.getRequestURI().substring(request.getContextPath().length());
            requestPath = filterUrl(requestPath);
            //1.通过前端请求地址得到code
            String authKey = onlineAuth.value();
            String code = requestPath.substring(requestPath.lastIndexOf(authKey) + authKey.length());
            log.info("拦截请求(" + request.getMethod() + "):" + requestPath + ",");
            if ("form".equals(authKey) && "DELETE".equals(request.getMethod())) {
                code = code.substring(0, code.lastIndexOf("/"));
            }
            List<String> possibleUrl = new ArrayList<>();
            //获取可能的表单地址
            for (String pre : ONLINE_TEST_PRE) {
                possibleUrl.add(pre + code);
            }
            //查询菜单
            LambdaQueryWrapper<SysPermission> query = new LambdaQueryWrapper<SysPermission>();
            query.eq(SysPermission::getDelFlag, 0);
            query.in(SysPermission::getUrl, possibleUrl);
            List<SysPermission> permissionList = sysPermissionService.list(query);

            String username = JwtUtil.getUserNameByToken(request);
            if (permissionList == null || permissionList.size() == 0) {
                //没有配置菜单 找online表单菜单地址
                boolean hasPermission = sysPermissionService.hasPermission(username, ONLINE_FORM);
                if (!hasPermission) {
                    backError(response, authKey);
                    return false;
                }
            } else {
                //找到菜单了
                boolean has = false;
                for (SysPermission p : permissionList) {
                    has = has || sysPermissionService.hasPermission(username, p);
                }
                if (!has) {
                    backError(response, authKey);
                    return false;
                }
            }
        }
    }
    return true;
}