com.baomidou.mybatisplus.core.toolkit.CollectionUtils Java Examples

The following examples show how to use com.baomidou.mybatisplus.core.toolkit.CollectionUtils. 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: SqlLogInterceptor.java    From blade-tool with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 获取sql语句开头部分
 *
 * @param sql ignore
 * @return ignore
 */
private int indexOfSqlStart(String sql) {
	String upperCaseSql = sql.toUpperCase();
	Set<Integer> set = new HashSet<>();
	set.add(upperCaseSql.indexOf("SELECT "));
	set.add(upperCaseSql.indexOf("UPDATE "));
	set.add(upperCaseSql.indexOf("INSERT "));
	set.add(upperCaseSql.indexOf("DELETE "));
	set.remove(-1);
	if (CollectionUtils.isEmpty(set)) {
		return -1;
	}
	List<Integer> list = new ArrayList<>(set);
	list.sort(Comparator.naturalOrder());
	return list.get(0);
}
 
Example #2
Source File: ParameterServiceImpl.java    From zuihou-admin-boot with Apache License 2.0 6 votes vote down vote up
@Override
@Transactional(rollbackFor = Exception.class)
public boolean removeByIds(Collection<? extends Serializable> idList) {
    if (CollectionUtils.isEmpty(idList)) {
        return true;
    }
    List<Parameter> parameterList = super.listByIds(idList);
    if (parameterList.isEmpty()) {
        return true;
    }
    boolean bool = SqlHelper.retBool(getBaseMapper().deleteBatchIds(idList));
    if (bool) {
        String[] cacheKeys = parameterList.stream().map((item) -> buildTenantKey(item.getKey())).toArray(String[]::new);
        channel.evict(getRegion(), cacheKeys);

        parameterList.forEach((model -> {
            SpringUtils.publishEvent(new ParameterUpdateEvent(
                    new ParameterUpdate(model.getKey(), model.getValue(), null, BaseContextHandler.getTenant())
            ));
        }));
    }
    return bool;
}
 
Example #3
Source File: ParameterServiceImpl.java    From zuihou-admin-cloud with Apache License 2.0 6 votes vote down vote up
@Override
@Transactional(rollbackFor = Exception.class)
public boolean removeByIds(Collection<? extends Serializable> idList) {
    if (CollectionUtils.isEmpty(idList)) {
        return true;
    }
    List<Parameter> parameterList = super.listByIds(idList);
    if (parameterList.isEmpty()) {
        return true;
    }
    boolean bool = SqlHelper.retBool(getBaseMapper().deleteBatchIds(idList));
    if (bool) {
        String[] cacheKeys = parameterList.stream().map((item) -> buildTenantKey(item.getKey())).toArray(String[]::new);
        channel.evict(getRegion(), cacheKeys);

        parameterList.forEach((model -> {
            SpringUtils.publishEvent(new ParameterUpdateEvent(
                    new ParameterUpdate(model.getKey(), model.getValue(), null, BaseContextHandler.getTenant())
            ));
        }));
    }
    return bool;
}
 
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: MyPage.java    From pybbs with GNU Affero General Public License v3.0 5 votes vote down vote up
public Page<T> setDescs(List<String> descs) {
    if (CollectionUtils.isNotEmpty(descs)) {
        this.descs = (String[]) descs.toArray(new String[0]);
    }

    return this;
}
 
Example #6
Source File: MyPage.java    From pybbs with GNU Affero General Public License v3.0 5 votes vote down vote up
public Page<T> setAscs(List<String> ascs) {
    if (CollectionUtils.isNotEmpty(ascs)) {
        this.ascs = (String[]) ascs.toArray(new String[0]);
    }

    return this;
}
 
Example #7
Source File: RoleResourceService.java    From SpringCloud with Apache License 2.0 5 votes vote down vote up
@Override
@Transactional
public boolean saveBatch(String roleId, Set<String> resourceIds) {
    if (CollectionUtils.isEmpty(resourceIds))
        return false;
    removeByRoleId(roleId);
    Set<RoleResource> userRoles = resourceIds.stream().map(resourceId -> new RoleResource(roleId, resourceId)).collect(Collectors.toSet());
    return saveBatch(userRoles);
}
 
Example #8
Source File: UserRoleService.java    From SpringCloud with Apache License 2.0 5 votes vote down vote up
@Override
@Transactional
public boolean saveBatch(String userId, Set<String> roleIds) {
    if (CollectionUtils.isEmpty(roleIds))
        return false;
    removeByUserId(userId);
    Set<UserRole> userRoles = roleIds.stream().map(roleId -> new UserRole(userId, roleId)).collect(Collectors.toSet());
    return saveBatch(userRoles);
}
 
Example #9
Source File: CollUtil.java    From albedo with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 从list中取第一条数据返回对应List中泛型的单个结果
 *
 * @param list ignore
 * @param <E>  ignore
 * @return ignore
 */
public static <E> E getObject(List<E> list) {
	if (CollectionUtils.isNotEmpty(list)) {
		int size = list.size();
		if (size > 1) {
			log.warn(String.format("Warn: execute Method There are  %s results.", size));
		}
		return list.get(0);
	}
	return null;
}
 
Example #10
Source File: UserServiceImpl.java    From spring-boot-tutorial with Creative Commons Attribution Share Alike 4.0 International 5 votes vote down vote up
@Override
public User findUserDetailList(String username) {
    User param = new User();
    param.setUsername(username);
    List<User> users = this.baseMapper.findUserDetail(param);
    return CollectionUtils.isNotEmpty(users) ? users.get(0) : null;
}
 
Example #11
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 #12
Source File: CriteriaQuery.java    From open-cloud with MIT License 5 votes vote down vote up
public String getSelect() {
    StringBuffer str = new StringBuffer();
    String sqlSelect = getSqlSelect();
    if (ObjectUtils.isNotEmpty(sqlSelect)) {
        select.add(String.join(",", sqlSelect));
    }
    if (CollectionUtils.isEmpty(select)) {
        select.add("*");
    }
    return String.join(",", select);
}
 
Example #13
Source File: UserServiceImpl.java    From FEBS-Cloud with Apache License 2.0 5 votes vote down vote up
@Override
public SystemUser findUserDetail(String username) {
    SystemUser param = new SystemUser();
    param.setUsername(username);
    List<SystemUser> users = this.baseMapper.findUserDetail(param);
    return CollectionUtils.isNotEmpty(users) ? users.get(0) : null;
}
 
Example #14
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 #15
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 #16
Source File: GeneratorConfigServiceImpl.java    From FEBS-Cloud with Apache License 2.0 4 votes vote down vote up
@Override
public GeneratorConfig findGeneratorConfig() {
    List<GeneratorConfig> generatorConfigs = this.baseMapper.selectList(null);
    return CollectionUtils.isNotEmpty(generatorConfigs) ? generatorConfigs.get(0) : null;
}
 
Example #17
Source File: Assert.java    From supplierShop with MIT License 4 votes vote down vote up
public static void notEmpty(Collection<?> collection, IErrorCode errorCode) {
    if (CollectionUtils.isNotEmpty(collection)) {
        Assert.fail(errorCode);
    }
}