update modules/core: mod 1 files

This commit is contained in:
jack ning
2025-03-22 12:59:59 +08:00
parent 4279c3f373
commit 99c7f871d3

View File

@@ -132,11 +132,13 @@ public class UserEntity extends BaseEntityNoOrg {
// 添加方法以简化对用户组织和角色的管理
public void addOrganizationRole(RoleEntity role) {
OrganizationEntity organization = this.currentOrganization;
if (organization == null) {
if (organization == null || role == null || role.getId() == null) {
return;
}
// 检查用户组织角色关联是否存在
UserOrganizationRoleEntity uor = userOrganizationRoles.stream()
.filter(u -> u.getOrganization().equals(organization))
.filter(u -> u.getOrganization().getId().equals(organization.getId()))
.findFirst()
.orElseGet(() -> {
UserOrganizationRoleEntity newUor = UserOrganizationRoleEntity.builder()
@@ -146,14 +148,33 @@ public class UserEntity extends BaseEntityNoOrg {
userOrganizationRoles.add(newUor);
return newUor;
});
uor.getRoles().add(role);
// 角色有效期为30天
uor.setStartDate(LocalDateTime.now());
// uor.endDate(LocalDateTime.now().plusDays(30));
//
// if (this.currentOrganization == null) {
// this.currentOrganization = organization;
// }
// 检查角色是否已存在于该用户组织关联中
boolean roleExists = uor.getRoles().stream()
.anyMatch(r -> r.getId().equals(role.getId()));
if (!roleExists) {
// 重要创建一个只包含ID的引用而不使用完整的分离实体
// 这样Hibernate将在必要时从数据库加载角色而不是尝试合并两个分离实例
RoleEntity roleReference = new RoleEntity();
roleReference.setId(role.getId());
uor.getRoles().add(roleReference);
}
// 默认角色有效期为100年过期后需要重新设置
uor.setStartDate(LocalDateTime.now());
uor.setEndDate(LocalDateTime.now().plusYears(100));
// 添加role到currentRoles (如果不存在)
boolean currentRoleExists = currentRoles.stream()
.anyMatch(r -> r.getId().equals(role.getId()));
if (!currentRoleExists) {
// 同样创建一个只包含ID的引用
RoleEntity roleReference = new RoleEntity();
roleReference.setId(role.getId());
currentRoles.add(roleReference);
}
}
public Set<String> getRoleUids() {