Search in sources :

Example 1 with IamUserPosition

use of com.diboot.iam.entity.IamUserPosition 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)

Aggregations

LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)1 BusinessException (com.diboot.core.exception.BusinessException)1 IamUserPosition (com.diboot.iam.entity.IamUserPosition)1 Transactional (org.springframework.transaction.annotation.Transactional)1