|
@@ -1,5 +1,6 @@
|
|
|
package com.gree.mall.manager.logic.admin;
|
|
|
|
|
|
+import com.alibaba.excel.util.StringUtils;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
@@ -9,8 +10,11 @@ import com.gree.mall.manager.exception.RemoteServiceException;
|
|
|
import com.gree.mall.manager.logic.common.CommonLogic;
|
|
|
import com.gree.mall.manager.plus.entity.AdminRole;
|
|
|
import com.gree.mall.manager.plus.entity.AdminUser;
|
|
|
+import com.gree.mall.manager.plus.entity.AdminUserModuleRela;
|
|
|
import com.gree.mall.manager.plus.service.AdminRoleService;
|
|
|
+import com.gree.mall.manager.plus.service.AdminUserModuleRelaService;
|
|
|
import com.gree.mall.manager.plus.service.AdminUserService;
|
|
|
+import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
@@ -18,16 +22,16 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
@Service
|
|
|
+@RequiredArgsConstructor
|
|
|
public class AdminRoleLogic {
|
|
|
|
|
|
- @Autowired
|
|
|
- AdminRoleService adminRoleService;
|
|
|
- @Autowired
|
|
|
- AdminUserService adminUserService;
|
|
|
- @Autowired
|
|
|
- CommonLogic commonLogic;
|
|
|
+ private final AdminRoleService adminRoleService;
|
|
|
+ private final AdminUserService adminUserService;
|
|
|
+ private final CommonLogic commonLogic;
|
|
|
+ private final AdminUserModuleRelaService adminUserModuleRelaService;
|
|
|
|
|
|
|
|
|
/**
|
|
@@ -37,30 +41,44 @@ public class AdminRoleLogic {
|
|
|
AdminUserCom adminUser = commonLogic.getAdminUser(request);
|
|
|
List<String> companyWechatIds = adminUser.getAdminCompanyIds();
|
|
|
|
|
|
- Integer type = adminRoleService.getById(adminUser.getRoleId()).getType();
|
|
|
- if("admin".equals(adminUser.getUserName())){
|
|
|
- type = RoleTypeEnum.ADMIN.getCode();
|
|
|
- }
|
|
|
+ Integer userType = this.checkUserType(adminUser);
|
|
|
|
|
|
return adminRoleService.lambdaQuery()
|
|
|
- .le(AdminRole::getType, type)
|
|
|
.in(CollectionUtils.isNotEmpty(companyWechatIds), AdminRole::getCompanyWechatId, companyWechatIds)
|
|
|
- .orderByDesc(AdminRole::getType)
|
|
|
+ .eq(userType > 0, AdminRole::getType, userType)
|
|
|
+ .orderByAsc(AdminRole::getType)
|
|
|
.page(new Page<>(pageNo, pageSize));
|
|
|
}
|
|
|
|
|
|
+ private Integer checkUserType(AdminUserCom adminUser) {
|
|
|
+ int userType = 0;
|
|
|
+ if (adminUser.getType() == 1 || adminUser.getType() == 3) {
|
|
|
+ userType = 1;
|
|
|
+ } else if (adminUser.getType() == 2 || adminUser.getType() == 4) {
|
|
|
+ userType = 2;
|
|
|
+ }
|
|
|
+ return userType;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 新增角色
|
|
|
*/
|
|
|
public void add(HttpServletRequest request, AdminRole adminRole) {
|
|
|
+ AdminUserCom adminUser = commonLogic.getAdminUser(request);
|
|
|
|
|
|
- //默认部门角色
|
|
|
- adminRole.setType(RoleTypeEnum.WEBSIT.getCode());
|
|
|
+ if (Objects.isNull(adminRole.getType())) {
|
|
|
+ throw new RemoteServiceException("适用机构不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (adminUser.getType() != 0 && adminRole.getType() == 0) {
|
|
|
+ throw new RemoteServiceException("适用机构参数异常");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isNotBlank(adminRole.getParentRoleId())) {
|
|
|
+ final AdminRole parentRole = adminRoleService.getById(adminRole.getParentRoleId());
|
|
|
+ adminRole.setParentRoleName(parentRole.getName());
|
|
|
+ }
|
|
|
|
|
|
- AdminUserCom adminUser = commonLogic.getAdminUser(request);
|
|
|
- adminRole.setCompanyWechatId(adminUser.getLoginCompanyWechatId());
|
|
|
- adminRole.setCompanyName(adminUser.getLoginCompanyName());
|
|
|
- adminRole.setCreateTime(new Date());
|
|
|
adminRoleService.save(adminRole);
|
|
|
}
|
|
|
|
|
@@ -69,11 +87,37 @@ public class AdminRoleLogic {
|
|
|
*/
|
|
|
@Transactional
|
|
|
public void update(AdminRole adminRole) {
|
|
|
- adminRoleService.updateById(adminRole);
|
|
|
+ AdminUserCom adminUser = commonLogic.getAdminUser();
|
|
|
+
|
|
|
+ final AdminRole oldData = adminRoleService.getById(adminRole.getAdminRoleId());
|
|
|
+ // 父级角色id不为空查询父级角色名填充
|
|
|
+ if (StringUtils.isNotBlank(adminRole.getParentRoleId())) {
|
|
|
+ final AdminRole parentRole = adminRoleService.getById(adminRole.getParentRoleId());
|
|
|
+ adminRole.setParentRoleName(parentRole.getName());
|
|
|
+ }
|
|
|
|
|
|
if (adminRole.getName() != null) {
|
|
|
- adminUserService.lambdaUpdate().set(AdminUser::getRoleName, adminRole.getName())
|
|
|
- .eq(AdminUser::getRoleId, adminRole.getAdminRoleId()).update();
|
|
|
+ // 更新账号使用对应的角色名
|
|
|
+ adminUserService.lambdaUpdate()
|
|
|
+ .set(AdminUser::getRoleName, adminRole.getName())
|
|
|
+ .eq(AdminUser::getRoleId, adminRole.getAdminRoleId())
|
|
|
+ .update();
|
|
|
+
|
|
|
+ // 更新所有子级的父级角色名
|
|
|
+ adminRoleService.lambdaUpdate()
|
|
|
+ .set(AdminRole::getParentRoleName, adminRole.getName())
|
|
|
+ .eq(AdminRole::getParentRoleId, adminRole.getAdminRoleId())
|
|
|
+ .update();
|
|
|
+ }
|
|
|
+
|
|
|
+ adminRoleService.updateById(adminRole);
|
|
|
+
|
|
|
+ // 本次编辑与历史父级不一致
|
|
|
+ if (!adminRole.getParentRoleId().equals(oldData.getParentRoleId())) {
|
|
|
+ // 清空角色已选权限
|
|
|
+ adminUserModuleRelaService.lambdaUpdate()
|
|
|
+ .eq(AdminUserModuleRela::getAdminRoleId, oldData.getAdminRoleId())
|
|
|
+ .remove();
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -81,6 +125,13 @@ public class AdminRoleLogic {
|
|
|
* 删除角色
|
|
|
*/
|
|
|
public void delete(String adminRoleId) throws RemoteServiceException {
|
|
|
+ final Integer isOpen = adminRoleService.lambdaQuery()
|
|
|
+ .eq(AdminRole::getAdminRoleId, adminRoleId)
|
|
|
+ .eq(AdminRole::getIsOpen, false)
|
|
|
+ .count();
|
|
|
+ if (isOpen > 0) {
|
|
|
+ throw new RemoteServiceException("该角色不允许删除");
|
|
|
+ }
|
|
|
//不允许删除使用该角色的帐号
|
|
|
Integer count = adminUserService.lambdaQuery().eq(AdminUser::getRoleId, adminRoleId).count();
|
|
|
if (count > 0) {
|