Search in sources :

Example 1 with LambdaQueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project diboot by dibo-software.

the class IamPositionServiceImpl method updateUserPositionRelations.

@Transactional(rollbackFor = Exception.class)
@Override
public boolean updateUserPositionRelations(String userType, Long userId, List<IamUserPosition> userPositionList) {
    if (V.isEmpty(userType) || V.isEmpty(userId)) {
        throw new BusinessException(Status.FAIL_OPERATION, "参数错误");
    }
    // 校验用户ID是否存在
    if (V.notEmpty(userPositionList)) {
        for (IamUserPosition userPosition : userPositionList) {
            userPosition.setUserType(userType);
            userPosition.setUserId(userId);
        }
    }
    // 删除所有旧关联数据
    LambdaQueryWrapper deleteWrapper = Wrappers.<IamUserPosition>lambdaQuery().eq(IamUserPosition::getUserType, userType).eq(IamUserPosition::getUserId, userId);
    long count = iamUserPositionMapper.selectCount(deleteWrapper);
    if (count > 0) {
        iamUserPositionMapper.delete(deleteWrapper);
    }
    // 批量设置新的岗位列表
    if (V.isEmpty(userPositionList)) {
        return true;
    }
    for (IamUserPosition userPosition : userPositionList) {
        userPosition.setId(null);
        iamUserPositionMapper.insert(userPosition);
    }
    return true;
}
Also used : BusinessException(com.diboot.core.exception.BusinessException) IamUserPosition(com.diboot.iam.entity.IamUserPosition) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with LambdaQueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project diboot by dibo-software.

the class IamResourcePermissionServiceImpl method updateMenuAndPermissions.

@Override
@Transactional(rollbackFor = Exception.class)
public void updateMenuAndPermissions(IamResourcePermissionDTO iamResourcePermissionDTO) {
    // 检查是否设置了自身id为parentId,如果设置parentId与自身id相同,将会导致非常严重的潜在隐患
    if (V.equals(iamResourcePermissionDTO.getId(), iamResourcePermissionDTO.getParentId())) {
        throw new BusinessException(Status.FAIL_OPERATION, "不可设置父级菜单资源为自身");
    }
    // 设置menu的接口列表
    if (V.notEmpty(iamResourcePermissionDTO.getApiSetList())) {
        iamResourcePermissionDTO.setApiSet(S.join(iamResourcePermissionDTO.getApiSetList(), ","));
    }
    // 更新menu
    this.updateEntity(iamResourcePermissionDTO);
    List<IamResourcePermissionDTO> permissionList = iamResourcePermissionDTO.getPermissionList();
    permissionList.forEach(p -> {
        p.setParentId(iamResourcePermissionDTO.getId());
        p.setDisplayType(Cons.RESOURCE_PERMISSION_DISPLAY_TYPE.PERMISSION.name());
    });
    // 需要更新的列表
    List<IamResourcePermissionDTO> updatePermissionList = permissionList.stream().filter(p -> V.notEmpty(p.getId())).collect(Collectors.toList());
    // 需要新建的列表
    List<IamResourcePermissionDTO> createPermissionDTOList = permissionList.stream().filter(p -> V.isEmpty(p.getId())).collect(Collectors.toList());
    List<Long> updatePermissionIdList = updatePermissionList.stream().map(IamResourcePermission::getId).collect(Collectors.toList());
    // 批量删除不存在的按钮/权限列表
    List<IamResourcePermission> oldPermissionList = this.getEntityList(Wrappers.<IamResourcePermission>lambdaQuery().eq(IamResourcePermission::getParentId, iamResourcePermissionDTO.getId()).eq(IamResourcePermission::getDisplayType, Cons.RESOURCE_PERMISSION_DISPLAY_TYPE.PERMISSION));
    if (V.notEmpty(oldPermissionList)) {
        LambdaQueryWrapper<IamResourcePermission> deleteWrapper = Wrappers.<IamResourcePermission>lambdaQuery().eq(IamResourcePermission::getParentId, iamResourcePermissionDTO.getId()).eq(IamResourcePermission::getDisplayType, Cons.RESOURCE_PERMISSION_DISPLAY_TYPE.PERMISSION);
        if (V.notEmpty(updatePermissionIdList)) {
            deleteWrapper.notIn(IamResourcePermission::getId, updatePermissionIdList);
        }
        this.deleteEntities(deleteWrapper);
    }
    // 批量新建按钮/权限列表
    if (V.notEmpty(createPermissionDTOList)) {
        List<IamResourcePermission> createPermissionList = BeanUtils.convertList(createPermissionDTOList, IamResourcePermission.class);
        this.createEntities(createPermissionList);
    }
    // 批量更新按钮/权限列表
    if (V.notEmpty(updatePermissionList)) {
        for (IamResourcePermissionDTO updatePermission : updatePermissionList) {
            this.updateEntity(updatePermission);
        }
    }
    // 检测是否有脏数据存在
    if (hasDirtyData()) {
        throw new BusinessException(Status.FAIL_OPERATION, "父级节点不可设置在自己的子节点上");
    }
// 清理脏数据
// this.clearDirtyData();
}
Also used : Wrappers(com.baomidou.mybatisplus.core.toolkit.Wrappers) RelationsBinder(com.diboot.core.binding.RelationsBinder) InvalidResourcePermissionVO(com.diboot.iam.vo.InvalidResourcePermissionVO) java.util(java.util) IamCacheManager(com.diboot.iam.cache.IamCacheManager) Status(com.diboot.core.vo.Status) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) BusinessException(com.diboot.core.exception.BusinessException) IamResourcePermissionMapper(com.diboot.iam.mapper.IamResourcePermissionMapper) Collectors(java.util.stream.Collectors) Slf4j(lombok.extern.slf4j.Slf4j) S(com.diboot.core.util.S) V(com.diboot.core.util.V) Service(org.springframework.stereotype.Service) Cons(com.diboot.iam.config.Cons) IamResourcePermissionService(com.diboot.iam.service.IamResourcePermissionService) IamResourcePermissionDTO(com.diboot.iam.dto.IamResourcePermissionDTO) IamResourcePermissionListVO(com.diboot.iam.vo.IamResourcePermissionListVO) BeanUtils(com.diboot.core.util.BeanUtils) IamResourcePermission(com.diboot.iam.entity.IamResourcePermission) Transactional(org.springframework.transaction.annotation.Transactional) BusinessException(com.diboot.core.exception.BusinessException) IamResourcePermissionDTO(com.diboot.iam.dto.IamResourcePermissionDTO) IamResourcePermission(com.diboot.iam.entity.IamResourcePermission) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with LambdaQueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project diboot by dibo-software.

the class IamAccountServiceImpl method getAuthAccount.

@Override
public String getAuthAccount(String userType, Long userId) {
    LambdaQueryWrapper<IamAccount> queryWrapper = new QueryWrapper<IamAccount>().lambda().select(IamAccount::getAuthAccount).eq(IamAccount::getUserType, userType).eq(IamAccount::getUserId, userId);
    IamAccount account = getSingleEntity(queryWrapper);
    return account != null ? account.getAuthAccount() : null;
}
Also used : IamAccount(com.diboot.iam.entity.IamAccount) QueryWrapper(com.baomidou.mybatisplus.core.conditions.query.QueryWrapper) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)

Example 4 with LambdaQueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project diboot by dibo-software.

the class TestDictBinder method testBinder.

@Test
public void testBinder() {
    // 加载测试数据
    LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
    queryWrapper.in(User::getId, 1001L, 1002L);
    List<User> userList = userService.getEntityList(queryWrapper);
    // 自动绑定
    List<UserVO> voList = Binder.convertAndBindRelations(userList, UserVO.class);
    // 验证绑定结果
    Assert.assertTrue(V.notEmpty(voList));
    for (UserVO vo : voList) {
        // 验证直接关联和通过中间表间接关联的绑定
        Assert.assertNotNull(vo.getGenderLabel());
        System.out.println(JSON.stringify(vo));
    }
    // 单个entity接口测试
    UserVO singleVO = BeanUtils.convert(userList.get(1), UserVO.class);
    Binder.bindRelations(singleVO);
    // 验证直接关联和通过中间表间接关联的绑定
    Assert.assertNotNull(singleVO.getGenderLabel());
    System.out.println(JSON.stringify(singleVO));
}
Also used : User(diboot.core.test.binder.entity.User) UserVO(diboot.core.test.binder.vo.UserVO) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with LambdaQueryWrapper

use of com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper in project diboot by dibo-software.

the class TestEntityListBinder method testComplexBinder.

/**
 * 验证通过中间表间接关联的绑定
 */
@Test
public void testComplexBinder() {
    // 加载测试数据
    LambdaQueryWrapper<User> queryWrapper = new LambdaQueryWrapper<>();
    queryWrapper.in(User::getId, 1001L, 1002L);
    List<User> userList = userService.getEntityList(queryWrapper);
    // 自动绑定
    List<EntityListComplexVO> voList = Binder.convertAndBindRelations(userList, EntityListComplexVO.class);
    // 验证绑定结果
    Assert.assertTrue(V.notEmpty(voList));
    for (EntityListComplexVO vo : voList) {
        // 验证通过中间表间接关联的绑定
        Assert.assertTrue(V.notEmpty(vo.getRoleList()));
        System.out.println(JSON.stringify(vo));
    }
}
Also used : User(diboot.core.test.binder.entity.User) EntityListComplexVO(diboot.core.test.binder.vo.EntityListComplexVO) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)381 Transactional (org.springframework.transaction.annotation.Transactional)60 JSONObject (com.alibaba.fastjson.JSONObject)52 Result (org.jeecg.common.api.vo.Result)50 ArrayList (java.util.ArrayList)42 List (java.util.List)30 Map (java.util.Map)29 Collectors (java.util.stream.Collectors)26 Service (org.springframework.stereotype.Service)24 LoginUser (org.jeecg.common.system.vo.LoginUser)22 SysPermission (org.jeecg.modules.system.entity.SysPermission)22 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)22 QueryWrapper (com.baomidou.mybatisplus.core.conditions.query.QueryWrapper)21 IPage (com.baomidou.mybatisplus.core.metadata.IPage)20 HashMap (java.util.HashMap)20 SysUser (org.jeecg.modules.system.entity.SysUser)20 ApiOperation (io.swagger.annotations.ApiOperation)19 ServiceException (cn.lili.common.exception.ServiceException)18 ServiceImpl (com.baomidou.mybatisplus.extension.service.impl.ServiceImpl)18 Autowired (org.springframework.beans.factory.annotation.Autowired)18