|
@@ -6,7 +6,9 @@ import cn.hfln.framework.extension.BizException;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.hfln.portal.common.constant.UserConstants;
|
|
|
import com.hfln.portal.common.dto.data.user.AdminUserDto;
|
|
|
-import com.hfln.portal.common.request.web.*;
|
|
|
+import com.hfln.portal.common.request.web.AddAccountParam;
|
|
|
+import com.hfln.portal.common.request.web.AdminModParam;
|
|
|
+import com.hfln.portal.common.request.web.QueryManagerParam;
|
|
|
import com.hfln.portal.common.vo.PageRecord;
|
|
|
import com.hfln.portal.domain.customer.AdminUserType;
|
|
|
import com.hfln.portal.domain.customer.OprLogType;
|
|
@@ -25,7 +27,6 @@ import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
-import org.springframework.util.StringUtils;
|
|
|
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
@@ -49,9 +50,10 @@ public class WebUserGatewayImpl implements WebUserGateway {
|
|
|
|
|
|
// 对 后台超级管理员 和用户超级管理员 进行权限控制
|
|
|
String userType = (String) StpUtil.getSession().get(UserConstants.SA_USER_TYPE);
|
|
|
- log.info("当前登录用户类型:userType:{}", userType);
|
|
|
- if (!AdminUserType.getBgManagerTypes().contains(userType)) {
|
|
|
- throw new BizException(ErrorEnum.USER_INFO_ERROR.getErrorCode(), ErrorEnum.USER_INFO_ERROR.getErrorMessage());
|
|
|
+ Long tenantId = (Long) StpUtil.getSession().get(UserConstants.SA_USER_TENANT_ID);
|
|
|
+ log.info("当前登录用户类型:userType:{}, tenantId:{}", userType, tenantId);
|
|
|
+ if (tenantId != null) {
|
|
|
+ param.setTenantId(tenantId);
|
|
|
}
|
|
|
|
|
|
// 执行分页查询
|
|
@@ -64,8 +66,13 @@ public class WebUserGatewayImpl implements WebUserGateway {
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public void addManager(AddAccountParam param) {
|
|
|
+
|
|
|
+ Long tenantId = (Long) StpUtil.getSession().get(UserConstants.SA_USER_TENANT_ID);
|
|
|
+ if (tenantId != null) {
|
|
|
+ param.setTenantId(tenantId);
|
|
|
+ }
|
|
|
// 1. 检查账号是否已存在
|
|
|
- AdminUserInfo exist = adminUserService.queryByAccount(param.getAccount());
|
|
|
+ AdminUserInfo exist = adminUserService.queryByAccount(param.getTenantId(), param.getAccount());
|
|
|
if (Objects.nonNull(exist)) {
|
|
|
throw new BizException(ErrorEnum.USER_ALREADY_EXISTS.getErrorCode(), ErrorEnum.USER_ALREADY_EXISTS.getErrorMessage());
|
|
|
}
|
|
@@ -73,9 +80,7 @@ public class WebUserGatewayImpl implements WebUserGateway {
|
|
|
// 对 后台超级管理员 和用户超级管理员 进行权限控制
|
|
|
String userType = (String) StpUtil.getSession().get(UserConstants.SA_USER_TYPE);
|
|
|
log.info("当前登录用户类型:userType:{}", userType);
|
|
|
- if (!AdminUserType.getBgManagerTypes().contains(userType)) {
|
|
|
- throw new BizException(ErrorEnum.USER_INFO_ERROR.getErrorCode(), ErrorEnum.USER_INFO_ERROR.getErrorMessage());
|
|
|
- }
|
|
|
+
|
|
|
// 如果创建的用户类型为普通用户,则需要指定租户id
|
|
|
if (AdminUserType.getUserTypes().contains(param.getUserType()) && param.getTenantId() == null) {
|
|
|
throw new BizException(ErrorEnum.USER_INFO_ERROR.getErrorCode(), ErrorEnum.USER_INFO_ERROR.getErrorMessage());
|
|
@@ -101,6 +106,17 @@ public class WebUserGatewayImpl implements WebUserGateway {
|
|
|
@Transactional
|
|
|
public void modManager(AdminModParam param) {
|
|
|
|
|
|
+ Long tenantId = (Long) StpUtil.getSession().get(UserConstants.SA_USER_TENANT_ID);
|
|
|
+ if (tenantId != null) {
|
|
|
+ param.setTenantId(tenantId);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 1. 检查账号是否已存在
|
|
|
+ AdminUserInfo alreadyExst = adminUserService.queryByAccount(param.getTenantId(), param.getAccount());
|
|
|
+ if (Objects.nonNull(alreadyExst) && !alreadyExst.getUserId().equals(param.getUserId())) {
|
|
|
+ throw new BizException(ErrorEnum.USER_ALREADY_EXISTS.getErrorCode(), ErrorEnum.USER_ALREADY_EXISTS.getErrorMessage());
|
|
|
+ }
|
|
|
+
|
|
|
// 1. 根据用户ID查询现有用户信息
|
|
|
AdminUserInfo exist = adminUserService.getById(param.getUserId());
|
|
|
if (Objects.isNull(exist)) {
|
|
@@ -110,9 +126,6 @@ public class WebUserGatewayImpl implements WebUserGateway {
|
|
|
// 对 后台超级管理员 和用户超级管理员 进行权限控制
|
|
|
String userType = (String) StpUtil.getSession().get(UserConstants.SA_USER_TYPE);
|
|
|
log.info("当前登录用户类型:userType:{}", userType);
|
|
|
- if (!AdminUserType.getBgManagerTypes().contains(userType)) {
|
|
|
- throw new BizException(ErrorEnum.USER_INFO_ERROR.getErrorCode(), ErrorEnum.USER_INFO_ERROR.getErrorMessage());
|
|
|
- }
|
|
|
|
|
|
// 如果修改的用户类型为普通用户,则需要指定租户id
|
|
|
if (AdminUserType.getUserTypes().contains(param.getUserType()) && param.getTenantId() == null) {
|
|
@@ -148,113 +161,13 @@ public class WebUserGatewayImpl implements WebUserGateway {
|
|
|
// 对 后台超级管理员 和用户超级管理员 进行权限控制
|
|
|
String userType = (String) StpUtil.getSession().get(UserConstants.SA_USER_TYPE);
|
|
|
log.info("当前登录用户类型:userType:{}", userType);
|
|
|
- if (!AdminUserType.getBgManagerTypes().contains(userType)) {
|
|
|
- throw new BizException(ErrorEnum.USER_INFO_ERROR.getErrorCode(), ErrorEnum.USER_INFO_ERROR.getErrorMessage());
|
|
|
- }
|
|
|
- check(userType, exist.getUserType());
|
|
|
-
|
|
|
- logService.saveLog(userId,OprLogType.DEL_MANAGER.getCode(), exist);
|
|
|
- adminUserService.deleteById(exist.getUserId());
|
|
|
- }
|
|
|
|
|
|
- @Override
|
|
|
- public PageRecord<AdminUserDto> queryClient(ClientQueryParam param) {
|
|
|
- // 对 后台超级管理员 和用户超级管理员 进行权限控制
|
|
|
- String userType = (String) StpUtil.getSession().get(UserConstants.SA_USER_TYPE);
|
|
|
- Long tenantId = (Long) StpUtil.getSession().get(UserConstants.SA_USER_TENANT_ID);
|
|
|
- log.info("当前登录用户类型:userType:{}, tenantId:{}", userType, tenantId);
|
|
|
- if (!StringUtils.hasText(userType) || !AdminUserType.USER_ADMIN.getCode().equals(userType) || tenantId == null) {
|
|
|
- throw new BizException(ErrorEnum.USER_INFO_ERROR.getErrorCode(), ErrorEnum.USER_INFO_ERROR.getErrorMessage());
|
|
|
- }
|
|
|
-
|
|
|
- // 执行分页查询
|
|
|
- Page<AdminUserInfo> userInfoPage = adminUserService.queryClientList(param, tenantId);
|
|
|
- // 换为目标VO
|
|
|
- List<AdminUserDto> targets = CopyUtils.copyList(userInfoPage.getRecords(), AdminUserDto.class);
|
|
|
- return CopyUtils.copyPage(userInfoPage, targets);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void addClient(ClientAddParam param) {
|
|
|
- // 1. 检查账号是否已存在
|
|
|
- AdminUserInfo exist = adminUserService.queryByAccount(param.getAccount());
|
|
|
- if (Objects.nonNull(exist)) {
|
|
|
- throw new BizException(ErrorEnum.USER_ALREADY_EXISTS.getErrorCode(), ErrorEnum.USER_ALREADY_EXISTS.getErrorMessage());
|
|
|
- }
|
|
|
-
|
|
|
- // 对 后台超级管理员 和用户超级管理员 进行权限控制
|
|
|
- String userType = (String) StpUtil.getSession().get(UserConstants.SA_USER_TYPE);
|
|
|
- Long tenantId = (Long) StpUtil.getSession().get(UserConstants.SA_USER_TENANT_ID);
|
|
|
- log.info("当前登录用户类型:userType:{}, tenantId:{}", userType, tenantId);
|
|
|
- if (!AdminUserType.USER_ADMIN.getCode().equals(userType) || tenantId == null) {
|
|
|
- throw new BizException(ErrorEnum.USER_ALREADY_EXISTS.getErrorCode(), ErrorEnum.USER_ALREADY_EXISTS.getErrorMessage());
|
|
|
- }
|
|
|
-
|
|
|
- //2.保存新用户到 admin_user_info 表
|
|
|
- AdminUserInfo adminUserInfo = CopyUtils.copy(param, AdminUserInfo.class);
|
|
|
- adminUserInfo.setPassword(PasswordUtil.encrypt(param.getPassword()));
|
|
|
- adminUserInfo.setUserType(AdminUserType.USER_MANAGER.getCode());
|
|
|
- adminUserService.save(adminUserInfo);
|
|
|
-
|
|
|
- //3.保存用户角色到 tbl_user_role 表
|
|
|
-// TblRole tblRole = tblRoleService.queryByRoleCode(UserConstants.ROLE_USER_MANAGER_DEFAULT);
|
|
|
- TblUserRole userRole = new TblUserRole();
|
|
|
- userRole.setUserId(adminUserInfo.getUserId());
|
|
|
- userRole.setRoleId(param.getRoleId());
|
|
|
- tblUserRoleService.save(userRole);
|
|
|
-
|
|
|
- logService.saveLog(adminUserInfo.getUserId(),OprLogType.ADD_CLIENT.getCode(), adminUserInfo);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void modClient(ClientModParam param) {
|
|
|
- // 1. 检查账号是否已存在
|
|
|
- AdminUserInfo exist = adminUserService.queryByAccount(param.getAccount());
|
|
|
- if (Objects.nonNull(exist)) {
|
|
|
- throw new BizException(ErrorEnum.USER_ALREADY_EXISTS.getErrorCode(), ErrorEnum.USER_ALREADY_EXISTS.getErrorMessage());
|
|
|
- }
|
|
|
-
|
|
|
- // 对 后台超级管理员 和用户超级管理员 进行权限控制
|
|
|
- String userType = (String) StpUtil.getSession().get(UserConstants.SA_USER_TYPE);
|
|
|
- Long tenantId = (Long) StpUtil.getSession().get(UserConstants.SA_USER_TENANT_ID);
|
|
|
- log.info("当前登录用户类型:userType:{}, tenantId:{}", userType, tenantId);
|
|
|
- if (!AdminUserType.USER_ADMIN.getCode().equals(userType) || tenantId == null) {
|
|
|
- throw new BizException(ErrorEnum.USER_ALREADY_EXISTS.getErrorCode(), ErrorEnum.USER_ALREADY_EXISTS.getErrorMessage());
|
|
|
- }
|
|
|
-
|
|
|
- logService.saveLog(param.getUserId(),OprLogType.MOD_CLIENT.getCode(), exist);
|
|
|
- //2.保存新用户到 admin_user_info 表
|
|
|
- BeanUtils.copyProperties(param, exist, "userId");
|
|
|
- exist.setPassword(PasswordUtil.encrypt(param.getPassword()));
|
|
|
- exist.setUserType(AdminUserType.USER_MANAGER.getCode());
|
|
|
- adminUserService.save(exist);
|
|
|
-
|
|
|
- //3.保存用户角色到 tbl_user_role 表
|
|
|
-// TblRole tblRole = tblRoleService.queryByRoleCode(UserConstants.ROLE_USER_MANAGER_DEFAULT);
|
|
|
- TblUserRole userRole = new TblUserRole();
|
|
|
- userRole.setUserId(exist.getUserId());
|
|
|
- userRole.setRoleId(param.getRoleId());
|
|
|
- tblUserRoleService.save(userRole);
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void delClient(Long userId) {
|
|
|
-
|
|
|
- // 1. 根据用户ID查询现有用户信息
|
|
|
- AdminUserInfo exist = adminUserService.getById(userId);
|
|
|
- if (Objects.isNull(exist)) {
|
|
|
- throw new BizException(ErrorEnum.USER_IS_NOT_EXIST.getErrorCode(), ErrorEnum.USER_IS_NOT_EXIST.getErrorMessage());
|
|
|
- }
|
|
|
- // 对 后台超级管理员 和用户超级管理员 进行权限控制
|
|
|
- String userType = (String) StpUtil.getSession().get(UserConstants.SA_USER_TYPE);
|
|
|
- log.info("当前登录用户类型:userType:{}", userType);
|
|
|
- if (AdminUserType.USER_ADMIN.getCode().equals(userType)) {
|
|
|
- throw new BizException(ErrorEnum.OPR_NOT_ALLOWED.getErrorCode(), ErrorEnum.OPR_NOT_ALLOWED.getErrorMessage());
|
|
|
- }
|
|
|
check(userType, exist.getUserType());
|
|
|
|
|
|
logService.saveLog(userId,OprLogType.DEL_MANAGER.getCode(), exist);
|
|
|
adminUserService.deleteById(exist.getUserId());
|
|
|
+
|
|
|
+ tblUserRoleService.delByUserId(exist.getUserId());
|
|
|
}
|
|
|
|
|
|
private void check(String userType, String createdUserType) {
|