|
|
@@ -117,6 +117,16 @@ public class RoleServiceImpl extends SuperService {
|
|
|
admin.setOrganizationId(oid);
|
|
|
com.github.microservice.auth.client.content.ResultContent<String> updateRoleGroupAdmin = roleService.updateRoleGroup(admin);
|
|
|
String groupId = updateRoleGroupAdmin.getContent();
|
|
|
+ if (StringUtils.isEmpty(groupId)) {
|
|
|
+ com.github.microservice.auth.client.content.ResultContent<RoleGroupModel> groupContent = roleService
|
|
|
+ .getRoleGroupByName(param.getName(), oid);
|
|
|
+ if (groupContent.isSuccess()) {
|
|
|
+ RoleGroupModel roleGroupModel = groupContent.getContent();
|
|
|
+ if (roleGroupModel != null) {
|
|
|
+ groupId = roleGroupModel.getId();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
com.github.microservice.auth.client.model.RoleModel roleModel = new com.github.microservice.auth.client.model.RoleModel();
|
|
|
roleModel.setOrganizationId(oid);
|
|
|
@@ -125,6 +135,7 @@ public class RoleServiceImpl extends SuperService {
|
|
|
// 添加角色
|
|
|
com.github.microservice.auth.client.content.ResultContent<String> updateRole = roleService.updateRole(roleModel);
|
|
|
String roleId = updateRole.getContent();
|
|
|
+
|
|
|
// 把角色绑定到角色组
|
|
|
roleService.addRoleToRoleGroup(groupId, new String[]{updateRole.getContent()});
|
|
|
|
|
|
@@ -166,8 +177,13 @@ public class RoleServiceImpl extends SuperService {
|
|
|
roleService.updateRole(roleModel);
|
|
|
}
|
|
|
}
|
|
|
- // 编辑本地角色
|
|
|
- BeanUtils.copyProperties(param, role, "roleType");
|
|
|
+ if (role.getRoleType() == RoleType.BuildIn) {
|
|
|
+ // 编辑本地角色
|
|
|
+ BeanUtils.copyProperties(param, role, "roleType", "name", "code", "roleInitType", "isVisitor");
|
|
|
+ } else {
|
|
|
+ // 编辑本地角色
|
|
|
+ BeanUtils.copyProperties(param, role, "roleType", "roleInitType", "isVisitor");
|
|
|
+ }
|
|
|
initUpdateEntity(role);
|
|
|
roleDao.save(role);
|
|
|
}
|
|
|
@@ -701,67 +717,97 @@ public class RoleServiceImpl extends SuperService {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 初始机构的管理员角色
|
|
|
+ * 初始机构、项目的默认角色
|
|
|
*
|
|
|
* @param organization
|
|
|
* @return
|
|
|
*/
|
|
|
public ResultContent initOrgManagerRole(Organization organization) {
|
|
|
if (ObjectUtils.isNotEmpty(organization)) {
|
|
|
- Role adminRole = roleDao.findTopByNameAndOid(CardSystemDefault.DEFAULT_ROLE_NAME, organization.getOid());
|
|
|
- if (ObjectUtils.isEmpty(adminRole)) {
|
|
|
- Set<String> auth = Set.of(AuthConstant.Admin);
|
|
|
+ List<RoleInit> initRoles = CardSystemDefault.initRoles;
|
|
|
+ if (ObjectUtils.isNotEmpty(initRoles)) {
|
|
|
+ for (RoleInit roleInit : initRoles) {
|
|
|
+ initRole(organization, roleInit);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return ResultContent.buildSuccess();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initRole(Organization organization, RoleInit roleInit) {
|
|
|
+ String name = roleInit.getName();
|
|
|
+ Role tempRole = roleDao.findTopByNameAndOid(name, organization.getOid());
|
|
|
+ if (ObjectUtils.isEmpty(tempRole)) {
|
|
|
+ Set<String> auth = new HashSet<>();
|
|
|
+ if (roleInit.getIsAdmin() != null && roleInit.getIsAdmin()) {
|
|
|
+ auth = Set.of(AuthConstant.Admin);
|
|
|
if (organization.getAuthType().equals(AuthType.Platform)) {
|
|
|
auth = Set.of(AuthConstant.SuperAdmin);
|
|
|
}
|
|
|
+ } else {
|
|
|
+ auth = roleInit.getAuth();
|
|
|
+ }
|
|
|
|
|
|
- String defaultName = CardSystemDefault.DEFAULT_ROLE_NAME;
|
|
|
- String defaultReMark = CardSystemDefault.DEFAULT_ROLE_NAME;
|
|
|
- String oid = organization.getOid();
|
|
|
- // 权限中心: 角色组
|
|
|
- RoleGroupModel admin = new RoleGroupModel();
|
|
|
- admin.setName(defaultName);
|
|
|
- admin.setRemark(defaultReMark);
|
|
|
- admin.setOrganizationId(oid);
|
|
|
- admin.setIdentity(auth);
|
|
|
- com.github.microservice.auth.client.content.ResultContent<String> updateRoleGroupAdmin = roleService.updateRoleGroup(admin);
|
|
|
- String groupId = updateRoleGroupAdmin.getContent();
|
|
|
- log.info("初始权限中心角色组成功:{}", groupId);
|
|
|
-
|
|
|
- if (!StringUtils.isEmpty(groupId)) {
|
|
|
- // 权限中心: 角色信息
|
|
|
- com.github.microservice.auth.client.model.RoleModel roleModel = new com.github.microservice.auth.client.model.RoleModel();
|
|
|
- roleModel.setOrganizationId(oid);
|
|
|
- roleModel.setName(defaultName);
|
|
|
- roleModel.setRemark(defaultReMark);
|
|
|
- roleModel.setAuth(auth);
|
|
|
- com.github.microservice.auth.client.content.ResultContent<String> updateRole = roleService.updateRole(roleModel);
|
|
|
-
|
|
|
- log.info("权限中心:初始角色和角色组关系成功");
|
|
|
- String roleId = updateRole.getContent();
|
|
|
- roleService.addRoleToRoleGroup(groupId, new String[]{roleId});
|
|
|
-
|
|
|
- // 添加本地机构角色信息
|
|
|
- adminRole = new Role();
|
|
|
- if (organization.getAuthType().equals(AuthType.Platform)) {
|
|
|
- adminRole.setCode(AuthConstant.SuperAdmin);
|
|
|
- } else {
|
|
|
- adminRole.setCode(AuthConstant.Admin);
|
|
|
+ String defaultName = name;
|
|
|
+ String defaultReMark = name;
|
|
|
+ String oid = organization.getOid();
|
|
|
+ // 权限中心: 角色组
|
|
|
+ RoleGroupModel admin = new RoleGroupModel();
|
|
|
+ admin.setName(defaultName);
|
|
|
+ admin.setRemark(defaultReMark);
|
|
|
+ admin.setOrganizationId(oid);
|
|
|
+ admin.setIdentity(auth);
|
|
|
+ com.github.microservice.auth.client.content.ResultContent<String> updateRoleGroupAdmin = roleService.updateRoleGroup(admin);
|
|
|
+ String groupId = updateRoleGroupAdmin.getContent();
|
|
|
+ log.info("初始权限中心角色组成功:{}", groupId);
|
|
|
+ if (StringUtils.isEmpty(groupId)) {
|
|
|
+ com.github.microservice.auth.client.content.ResultContent<RoleGroupModel> groupContent = roleService.getRoleGroupByName(defaultName, oid);
|
|
|
+ if (groupContent.isSuccess()) {
|
|
|
+ RoleGroupModel roleGroupModel = groupContent.getContent();
|
|
|
+ if (roleGroupModel != null) {
|
|
|
+ groupId = roleGroupModel.getId();
|
|
|
}
|
|
|
- adminRole.setAuth(auth);
|
|
|
- adminRole.setOid(oid);
|
|
|
- adminRole.setRoleGroupId(groupId);
|
|
|
- adminRole.setName(defaultName);
|
|
|
- adminRole.setRemark(defaultReMark);
|
|
|
- adminRole.setRoleType(RoleType.BuildIn);
|
|
|
- adminRole.setIsAdmin(Boolean.TRUE);
|
|
|
- adminRole.setRoleId(roleId);
|
|
|
- adminRole.setAuthType(organization.getAuthType());
|
|
|
- roleDao.save(adminRole);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(groupId)) {
|
|
|
+ // 权限中心: 角色信息
|
|
|
+ com.github.microservice.auth.client.model.RoleModel roleModel = new com.github.microservice.auth.client.model.RoleModel();
|
|
|
+ roleModel.setOrganizationId(oid);
|
|
|
+ roleModel.setName(defaultName);
|
|
|
+ roleModel.setRemark(defaultReMark);
|
|
|
+ roleModel.setAuth(auth);
|
|
|
+ com.github.microservice.auth.client.content.ResultContent<String> updateRole = roleService.updateRole(roleModel);
|
|
|
+
|
|
|
+ log.info("权限中心:初始角色和角色组关系成功");
|
|
|
+ String roleId = updateRole.getContent();
|
|
|
+ roleService.addRoleToRoleGroup(groupId, new String[]{roleId});
|
|
|
+
|
|
|
+ // 添加本地机构角色信息
|
|
|
+ tempRole = new Role();
|
|
|
+ tempRole.setRoleId(roleId);
|
|
|
+ tempRole.setAuth(auth);
|
|
|
+ tempRole.setOid(oid);
|
|
|
+ tempRole.setRoleGroupId(groupId);
|
|
|
+ tempRole.setName(defaultName);
|
|
|
+ tempRole.setRemark(defaultReMark);
|
|
|
+ }
|
|
|
}
|
|
|
- return ResultContent.buildSuccess();
|
|
|
+ String code = roleInit.getCode();
|
|
|
+ if (roleInit.getIsAdmin() != null && roleInit.getIsAdmin()) {
|
|
|
+ if (organization.getAuthType().equals(AuthType.Platform)) {
|
|
|
+ code = AuthConstant.SuperAdmin;
|
|
|
+ } else {
|
|
|
+ code = AuthConstant.Admin;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ tempRole.setCode(code);
|
|
|
+ tempRole.setRoleType(roleInit.getRoleType());
|
|
|
+ tempRole.setIsAdmin(roleInit.getIsAdmin());
|
|
|
+ tempRole.setIsVisitor(roleInit.getIsVisitor());
|
|
|
+ tempRole.setRoleInitType(roleInit.getRoleInitType());
|
|
|
+ tempRole.setAuthType(organization.getAuthType());
|
|
|
+ roleDao.save(tempRole);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -774,6 +820,16 @@ public class RoleServiceImpl extends SuperService {
|
|
|
return roleDao.findByOidAndIsAdmin(oid, Boolean.TRUE);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 得到游客角色
|
|
|
+ *
|
|
|
+ * @param oid
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public List<Role> getVisitorRoles(String oid) {
|
|
|
+ return roleDao.findByOidAndIsVisitor(oid, Boolean.TRUE);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 用户移除角色
|
|
|
*
|