You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
105 lines
3.7 KiB
Java
105 lines
3.7 KiB
Java
package com.supervision.police.service.impl;
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
import cn.hutool.core.lang.Assert;
|
|
import cn.hutool.core.util.StrUtil;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.supervision.police.domain.SystemUserRoleRelation;
|
|
import com.supervision.police.dto.user.RoleMenuDTO;
|
|
import com.supervision.police.dto.user.UserRoleDTO;
|
|
import com.supervision.police.service.SystemUserRoleRelationService;
|
|
import com.supervision.police.mapper.SystemUserRoleRelationMapper;
|
|
import lombok.RequiredArgsConstructor;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
/**
|
|
* @author Administrator
|
|
* @description 针对表【system_user_role_relation(用户角色关联表)】的数据库操作Service实现
|
|
* @createDate 2024-07-31 11:02:43
|
|
*/
|
|
@Slf4j
|
|
@Service
|
|
@RequiredArgsConstructor
|
|
public class SystemUserRoleRelationServiceImpl extends ServiceImpl<SystemUserRoleRelationMapper, SystemUserRoleRelation>
|
|
implements SystemUserRoleRelationService{
|
|
|
|
@Override
|
|
public List<UserRoleDTO> listUserRole(String userId, String roleId, String roleName) {
|
|
return super.getBaseMapper().listUserRole(userId,roleId,roleName);
|
|
}
|
|
|
|
@Override
|
|
@Transactional(transactionManager = "dataSourceTransactionManager",rollbackFor = Exception.class)
|
|
public List<SystemUserRoleRelation> saveUserRoleRelation(String userId, List<String> roleIdList) {
|
|
Assert.notEmpty(userId, "用户id不能为空");
|
|
|
|
if (CollUtil.isEmpty(roleIdList)){
|
|
log.info("saveUserRoleRelation:userId:{},roleList is empty",userId);
|
|
return CollUtil.newArrayList();
|
|
}
|
|
|
|
List<SystemUserRoleRelation> userRoleList = roleIdList.stream().map(roleId -> {
|
|
SystemUserRoleRelation userRole = new SystemUserRoleRelation();
|
|
userRole.setRoleId(roleId);
|
|
userRole.setUserId(userId);
|
|
return userRole;
|
|
}).toList();
|
|
userRoleList.forEach(super::save);
|
|
return userRoleList;
|
|
}
|
|
|
|
@Override
|
|
@Transactional(transactionManager = "dataSourceTransactionManager",rollbackFor = Exception.class)
|
|
public List<SystemUserRoleRelation> updateUserRoleRelation(String userId, List<String> roleIdList) {
|
|
Assert.notEmpty(userId, "用户id不能为空");
|
|
|
|
super.lambdaUpdate().eq(SystemUserRoleRelation::getUserId,userId).remove();
|
|
|
|
if (CollUtil.isEmpty(roleIdList)){
|
|
log.info("updateUserRoleRelation:userId:{},roleList is empty",userId);
|
|
return CollUtil.newArrayList();
|
|
}
|
|
return saveUserRoleRelation(userId,roleIdList);
|
|
}
|
|
|
|
@Override
|
|
public void deleteUserRoleRelation(String userId) {
|
|
super.lambdaUpdate().eq(SystemUserRoleRelation::getUserId,userId).remove();
|
|
}
|
|
|
|
@Override
|
|
public List<RoleMenuDTO> listUserRoleMenu(String userId) {
|
|
if (StrUtil.isEmpty(userId)){
|
|
return new ArrayList<>();
|
|
}
|
|
|
|
return super.getBaseMapper().listUserRoleMenu(userId);
|
|
}
|
|
|
|
@Override
|
|
public List<UserRoleDTO> listUserRoleByUserIdList(List<String> userIdList) {
|
|
if (CollUtil.isEmpty(userIdList)){
|
|
return new ArrayList<>();
|
|
}
|
|
|
|
return super.getBaseMapper().listUserRoleByUserIdList(userIdList);
|
|
}
|
|
|
|
@Override
|
|
public List<SystemUserRoleRelation> listUserRoleByRoleIdList(List<String> roleIdList) {
|
|
if (CollUtil.isEmpty(roleIdList)){
|
|
return CollUtil.newArrayList();
|
|
}
|
|
return super.lambdaQuery().in(SystemUserRoleRelation::getRoleId,roleIdList).list();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|