|
@@ -9,6 +9,7 @@ import com.hfln.portal.common.dto.data.user.AdminUserDto;
|
|
|
import com.hfln.portal.common.request.web.*;
|
|
|
import com.hfln.portal.common.vo.PageRecord;
|
|
|
import com.hfln.portal.domain.customer.AdminUserType;
|
|
|
+import com.hfln.portal.domain.customer.OprLogType;
|
|
|
import com.hfln.portal.domain.customer.util.CopyUtils;
|
|
|
import com.hfln.portal.domain.customer.util.PasswordUtil;
|
|
|
import com.hfln.portal.domain.exception.ErrorEnum;
|
|
@@ -17,9 +18,11 @@ import com.hfln.portal.infrastructure.po.AdminUserInfo;
|
|
|
import com.hfln.portal.infrastructure.po.TblRole;
|
|
|
import com.hfln.portal.infrastructure.po.TblUserRole;
|
|
|
import com.hfln.portal.infrastructure.service.AdminUserService;
|
|
|
+import com.hfln.portal.infrastructure.service.TblOprLogService;
|
|
|
import com.hfln.portal.infrastructure.service.TblRoleService;
|
|
|
import com.hfln.portal.infrastructure.service.TblUserRoleService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -39,6 +42,8 @@ public class WebUserGatewayImpl implements WebUserGateway {
|
|
|
private TblUserRoleService tblUserRoleService;
|
|
|
@Autowired
|
|
|
private TblRoleService tblRoleService;
|
|
|
+ @Autowired
|
|
|
+ private TblOprLogService logService;
|
|
|
|
|
|
@Override
|
|
|
public PageRecord<AdminUserDto> queryManager(QueryManagerParam param) {
|
|
@@ -59,7 +64,7 @@ public class WebUserGatewayImpl implements WebUserGateway {
|
|
|
|
|
|
@Override
|
|
|
@Transactional
|
|
|
- public void addAccount(AddAccountParam param) {
|
|
|
+ public void addManager(AddAccountParam param) {
|
|
|
// 1. 检查账号是否已存在
|
|
|
AdminUserInfo exist = adminUserService.queryByAccount(param.getAccount());
|
|
|
if (Objects.nonNull(exist)) {
|
|
@@ -89,6 +94,69 @@ public class WebUserGatewayImpl implements WebUserGateway {
|
|
|
userRole.setUserId(adminUserInfo.getUserId());
|
|
|
userRole.setRoleId(param.getRoleId());
|
|
|
tblUserRoleService.save(userRole);
|
|
|
+
|
|
|
+ logService.saveLog(OprLogType.ADD_MANAGER.getCode(), adminUserInfo);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void modManager(AdminModParam param) {
|
|
|
+
|
|
|
+ // 1. 根据用户ID查询现有用户信息
|
|
|
+ AdminUserInfo exist = adminUserService.getById(param.getUserId());
|
|
|
+ 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.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());
|
|
|
+ }
|
|
|
+ check(userType, param.getUserType());
|
|
|
+
|
|
|
+ logService.saveLog(OprLogType.MOD_MANAGER.getCode(), exist);
|
|
|
+ //2.更新用户信息到 admin_user_info 表
|
|
|
+ //更新密码
|
|
|
+ BeanUtils.copyProperties(param, exist, "userId");
|
|
|
+ exist.setPassword(PasswordUtil.encrypt(param.getPassword()));
|
|
|
+// adminUserService.updateById(exist);
|
|
|
+ adminUserService.updateAllById(exist);
|
|
|
+
|
|
|
+ //3.更新用户角色到 tbl_user_role 表
|
|
|
+ TblUserRole userRole = tblUserRoleService.getByUserId(exist.getUserId());
|
|
|
+ if (Objects.isNull(userRole)) {
|
|
|
+ userRole = new TblUserRole();
|
|
|
+ userRole.setUserId(exist.getUserId());
|
|
|
+ }
|
|
|
+ userRole.setRoleId(param.getRoleId());
|
|
|
+ tblUserRoleService.saveOrUpdate(userRole);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public void delMananger(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.getBgManagerTypes().contains(userType)) {
|
|
|
+ throw new BizException(ErrorEnum.USER_INFO_ERROR.getErrorCode(), ErrorEnum.USER_INFO_ERROR.getErrorMessage());
|
|
|
+ }
|
|
|
+ check(userType, exist.getUserType());
|
|
|
+
|
|
|
+ logService.saveLog(OprLogType.DEL_MANAGER.getCode(), exist);
|
|
|
+ adminUserService.deleteById(exist.getUserId());
|
|
|
}
|
|
|
|
|
|
@Override
|
|
@@ -136,57 +204,68 @@ public class WebUserGatewayImpl implements WebUserGateway {
|
|
|
userRole.setUserId(adminUserInfo.getUserId());
|
|
|
userRole.setRoleId(tblRole.getRoleId());
|
|
|
tblUserRoleService.save(userRole);
|
|
|
+
|
|
|
+ logService.saveLog(OprLogType.ADD_CLIENT.getCode(), adminUserInfo);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public void modManager(AdminModParam param) {
|
|
|
+ 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(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(tblRole.getRoleId());
|
|
|
+ tblUserRoleService.save(userRole);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void delClient(Long userId) {
|
|
|
|
|
|
// 1. 根据用户ID查询现有用户信息
|
|
|
- AdminUserInfo exist = adminUserService.getById(param.getUserId());
|
|
|
+ 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.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());
|
|
|
- }
|
|
|
- check(userType, param.getUserType());
|
|
|
-
|
|
|
- //2.更新用户信息到 admin_user_info 表
|
|
|
- AdminUserInfo adminUserInfo = CopyUtils.copy(param, AdminUserInfo.class);
|
|
|
- // 如果密码不为空则更新密码
|
|
|
- if(StringUtils.hasText(param.getPassword())) {
|
|
|
- adminUserInfo.setPassword(PasswordUtil.encrypt(param.getPassword()));
|
|
|
- } else {
|
|
|
- adminUserInfo.setPassword(exist.getPassword());
|
|
|
+ if (AdminUserType.USER_ADMIN.getCode().equals(userType)) {
|
|
|
+ throw new BizException(ErrorEnum.OPR_NOT_ALLOWED.getErrorCode(), ErrorEnum.OPR_NOT_ALLOWED.getErrorMessage());
|
|
|
}
|
|
|
- adminUserInfo.setUserType(param.getUserType());
|
|
|
- adminUserService.updateById(adminUserInfo);
|
|
|
+ check(userType, exist.getUserType());
|
|
|
|
|
|
- //3.更新用户角色到 tbl_user_role 表
|
|
|
- TblUserRole userRole = tblUserRoleService.getByUserId(param.getUserId());
|
|
|
- if (Objects.isNull(userRole)) {
|
|
|
- userRole = new TblUserRole();
|
|
|
- userRole.setUserId(adminUserInfo.getUserId());
|
|
|
- }
|
|
|
- userRole.setRoleId(param.getRoleId());
|
|
|
- tblUserRoleService.saveOrUpdate(userRole);
|
|
|
+ logService.saveLog(OprLogType.DEL_MANAGER.getCode(), exist);
|
|
|
+ adminUserService.deleteById(exist.getUserId());
|
|
|
}
|
|
|
|
|
|
+
|
|
|
private void check(String userType, String createdUserType) {
|
|
|
AdminUserType currentUserTypeEnum = AdminUserType.getByCode(userType);
|
|
|
AdminUserType createdUserTypeEnum = AdminUserType.getByCode(createdUserType);
|
|
|
if (createdUserTypeEnum != null) {
|
|
|
if (currentUserTypeEnum.getLevel() < createdUserTypeEnum.getLevel()) {
|
|
|
- throw new BizException(ErrorEnum.CREATE_NOT_ALLOWED.getErrorCode(), ErrorEnum.CREATE_NOT_ALLOWED.getErrorMessage());
|
|
|
+ throw new BizException(ErrorEnum.OPR_NOT_ALLOWED.getErrorCode(), ErrorEnum.OPR_NOT_ALLOWED.getErrorMessage());
|
|
|
}
|
|
|
|
|
|
}
|