|
|
@@ -1,5 +1,6 @@
|
|
|
package com.zhongshu.card.server.core.service.org;
|
|
|
|
|
|
+import com.github.microservice.auth.client.constant.AuthConstant;
|
|
|
import com.github.microservice.auth.client.content.ResultState;
|
|
|
import com.github.microservice.auth.client.model.AuthResourcesNameModel;
|
|
|
import com.github.microservice.auth.client.model.RoleGroupModel;
|
|
|
@@ -13,9 +14,13 @@ import com.zhongshu.card.client.utils.type.DataState;
|
|
|
import com.zhongshu.card.client.utils.type.EditType;
|
|
|
import com.zhongshu.card.client.utils.type.RoleType;
|
|
|
import com.zhongshu.card.server.core.dao.org.OrganizationDao;
|
|
|
+import com.zhongshu.card.server.core.dao.org.OrganizationUserDao;
|
|
|
import com.zhongshu.card.server.core.dao.org.RoleDao;
|
|
|
+import com.zhongshu.card.server.core.dao.org.UserCountDao;
|
|
|
import com.zhongshu.card.server.core.domain.org.Organization;
|
|
|
+import com.zhongshu.card.server.core.domain.org.OrganizationUser;
|
|
|
import com.zhongshu.card.server.core.domain.org.Role;
|
|
|
+import com.zhongshu.card.server.core.domain.org.UserAccount;
|
|
|
import com.zhongshu.card.server.core.service.base.SuperService;
|
|
|
import com.zhongshu.card.server.core.util.BeanUtils;
|
|
|
import com.zhongshu.card.server.core.util.CommonUtil;
|
|
|
@@ -54,6 +59,12 @@ public class RoleServiceImpl extends SuperService {
|
|
|
@Autowired
|
|
|
private AuthResourcesNameService authResourcesNameService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ UserCountDao userCountDao;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ OrganizationUserDao organizationUserDao;
|
|
|
+
|
|
|
/**
|
|
|
* 添加/编辑角色
|
|
|
*
|
|
|
@@ -355,6 +366,53 @@ public class RoleServiceImpl extends SuperService {
|
|
|
return ResultContent.buildSuccess(roleModel);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 得到当前用户单企业的权限
|
|
|
+ *
|
|
|
+ * @param oid
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public ResultContent getOrganizationAuth(String oid) {
|
|
|
+ if (StringUtils.isEmpty(oid)) {
|
|
|
+ oid = getCurrentOid();
|
|
|
+ }
|
|
|
+ String userId = getCurrentUserId();
|
|
|
+ Set<String> auth = new HashSet<>();
|
|
|
+ var roleGroupModels = roleService.listRoleGroupFromOrganizationUser(oid, userId).getContent();
|
|
|
+ if (!CollectionUtils.isEmpty(roleGroupModels)) {
|
|
|
+ roleGroupModels.stream().forEach(roleGroup -> {
|
|
|
+ if (!CollectionUtils.isEmpty(roleGroup.getRoleId())) {
|
|
|
+ roleGroup.getRoleId().stream().forEach(it -> {
|
|
|
+ var role = roleService.getRole(it).getContent();
|
|
|
+ if (role != null && !CollectionUtils.isEmpty(role.getAuth())) {
|
|
|
+ auth.addAll(role.getAuth());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotEmpty(oid)) {
|
|
|
+ UserAccount userAccount = userCountDao.findTopByUserId(userId);
|
|
|
+ Organization organization = organizationDao.findTopByOid(oid);
|
|
|
+ if (ObjectUtils.isNotEmpty(userAccount) && ObjectUtils.isNotEmpty(organization)) {
|
|
|
+ OrganizationUser enterpriseUser = organizationUserDao.findTopByOrganizationAndUser(organization, userAccount);
|
|
|
+ if (ObjectUtils.isNotEmpty(enterpriseUser)) {
|
|
|
+ List<Role> roles = enterpriseUser.getRoles();
|
|
|
+ if (ObjectUtils.isNotEmpty(roles)) {
|
|
|
+ List<Role> _list = roles.stream().filter(it -> {
|
|
|
+ return it.getIsAdmin();
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ // 如果角色是管理员角色,就把 Admin权限标识返回
|
|
|
+ if (ObjectUtils.isNotEmpty(_list)) {
|
|
|
+ auth.add(AuthConstant.Admin);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ResultContent.buildSuccess(auth);
|
|
|
+ }
|
|
|
+
|
|
|
public RoleModel toModel(Role role) {
|
|
|
RoleModel roleModel = new RoleModel();
|
|
|
if (ObjectUtils.isNotEmpty(role)) {
|