|
|
|
@ -8,6 +8,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
|
import com.supervision.police.domain.SystemUser;
|
|
|
|
|
import com.supervision.police.domain.SystemUserRoleRelation;
|
|
|
|
|
import com.supervision.police.dto.user.*;
|
|
|
|
|
import com.supervision.police.service.SystemUserRoleRelationService;
|
|
|
|
|
import com.supervision.police.service.SystemUserService;
|
|
|
|
@ -37,7 +38,6 @@ public class SystemUserServiceImpl extends ServiceImpl<SystemUserMapper, SystemU
|
|
|
|
|
private final SystemUserRoleRelationService userRoleRelationManageService;
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
public LoginResVO login(LoginReqVO reqVO) {
|
|
|
|
|
|
|
|
|
|
// 校验用户信息是否正确
|
|
|
|
@ -63,7 +63,7 @@ public class SystemUserServiceImpl extends ServiceImpl<SystemUserMapper, SystemU
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
@Transactional(transactionManager = "dataSourceTransactionManager",rollbackFor = Exception.class)
|
|
|
|
|
public String saveUserInfo(UserInfoReqVo userInfoReqVo) {
|
|
|
|
|
Assert.notEmpty(userInfoReqVo.getAccount(), "账号不能为空");
|
|
|
|
|
Assert.notEmpty(userInfoReqVo.getUserName(), "姓名不能为空");
|
|
|
|
@ -71,7 +71,7 @@ public class SystemUserServiceImpl extends ServiceImpl<SystemUserMapper, SystemU
|
|
|
|
|
Assert.notEmpty(userInfoReqVo.getRoleIdList(), "角色不能为空");
|
|
|
|
|
|
|
|
|
|
Long count = super.lambdaQuery().eq(SystemUser::getAccount, userInfoReqVo.getAccount()).count();
|
|
|
|
|
Assert.isTrue(count == 0, "用户名已存在");
|
|
|
|
|
Assert.isTrue(count == 0, "账号已存在");
|
|
|
|
|
|
|
|
|
|
SystemUser systemUser = userInfoReqVo.toSystemUser();
|
|
|
|
|
// 设置默认密码
|
|
|
|
@ -81,7 +81,7 @@ public class SystemUserServiceImpl extends ServiceImpl<SystemUserMapper, SystemU
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
|
|
@Transactional(transactionManager = "dataSourceTransactionManager",rollbackFor = Exception.class)
|
|
|
|
|
public void updateUserInfo(UserInfoReqVo userInfoReqVo) {
|
|
|
|
|
|
|
|
|
|
Assert.notEmpty(userInfoReqVo.getId(), "用户id不能为空");
|
|
|
|
@ -110,6 +110,7 @@ public class SystemUserServiceImpl extends ServiceImpl<SystemUserMapper, SystemU
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(transactionManager = "dataSourceTransactionManager",rollbackFor = Exception.class)
|
|
|
|
|
public Boolean deleteUser(String id) {
|
|
|
|
|
|
|
|
|
|
Assert.notEmpty(id, "用户id不能为空");
|
|
|
|
@ -126,26 +127,27 @@ public class SystemUserServiceImpl extends ServiceImpl<SystemUserMapper, SystemU
|
|
|
|
|
@Override
|
|
|
|
|
public IPage<UserInfoDTO> list(String userName, String roleId, String roleName, Integer pageNum, Integer pageSize) {
|
|
|
|
|
|
|
|
|
|
List<UserRoleDTO> userRoleDTOS = new ArrayList<>();
|
|
|
|
|
List<UserRoleDTO> userRoleFilterList = new ArrayList<>();
|
|
|
|
|
// 先对角色进行判断
|
|
|
|
|
if (StrUtil.isNotEmpty(roleId) || StrUtil.isNotEmpty(roleName)){
|
|
|
|
|
userRoleDTOS = userRoleRelationManageService.listUserRole(null, roleId, roleName);
|
|
|
|
|
if (CollUtil.isEmpty(userRoleDTOS)){
|
|
|
|
|
userRoleFilterList = userRoleRelationManageService.listUserRole(null, roleId, roleName);
|
|
|
|
|
if (CollUtil.isEmpty(userRoleFilterList)){
|
|
|
|
|
return Page.of(pageNum, pageSize, 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//构建查询条件
|
|
|
|
|
//查询用户数据
|
|
|
|
|
Page<SystemUser> userInfoPage = super.page(Page.of(pageNum, pageSize),
|
|
|
|
|
new LambdaQueryWrapper<SystemUser>()
|
|
|
|
|
.eq(StrUtil.isNotEmpty(userName), SystemUser::getUserName, userName)
|
|
|
|
|
.in(CollUtil.isNotEmpty(userRoleDTOS), SystemUser::getId, userRoleDTOS.stream().map(UserRoleDTO::getUserId).toList()));
|
|
|
|
|
.in(CollUtil.isNotEmpty(userRoleFilterList), SystemUser::getId, userRoleFilterList.stream().map(UserRoleDTO::getUserId).toList()));
|
|
|
|
|
|
|
|
|
|
if (CollUtil.isEmpty(userInfoPage.getRecords())){
|
|
|
|
|
return Page.of(pageNum, pageSize, userInfoPage.getTotal());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Map<String, List<UserRoleDTO>> userRoleMap = userRoleDTOS.stream().collect(Collectors.groupingBy(UserRoleDTO::getUserId, Collectors.toList()));
|
|
|
|
|
List<UserRoleDTO> userRoleList = userRoleRelationManageService.listUserRoleByUserIdList(userInfoPage.getRecords().stream().map(SystemUser::getId).toList());
|
|
|
|
|
Map<String, List<UserRoleDTO>> userRoleMap = userRoleList.stream().collect(Collectors.groupingBy(UserRoleDTO::getUserId, Collectors.toList()));
|
|
|
|
|
|
|
|
|
|
return userInfoPage.convert(systemUser -> new UserInfoDTO(systemUser,userRoleMap));
|
|
|
|
|
}
|
|
|
|
|