add sales order

This commit is contained in:
Timi
2026-09-06 12:09:58 +08:00
parent 41f692aad9
commit f3166f0413
43 changed files with 560 additions and 73 deletions
@@ -49,10 +49,10 @@ public class RoleController {
@RequireCorePermission(CorePermissionCode.ROLE_READ)
@PostMapping("/list")
public PageResult<Role> list(@RequestBody Page<Role> page) {
Set<String> manageableRoleIdSet = listManageableRoleId();
Set<String> visibleRoleIdSet = listVisibleRoleId();
PageResult<Role> result = service.page(page);
if (result.getList() != null) {
result.setList(result.getList().stream().filter(role -> manageableRoleIdSet.contains(role.getId())).toList());
result.setList(result.getList().stream().filter(role -> visibleRoleIdSet.contains(role.getId())).toList());
result.getList().forEach(this::fillRoleDetail);
}
return result;
@@ -83,7 +83,7 @@ public class RoleController {
@PostMapping("/detail")
public Role detail(@RequestParam String id) {
Role role = service.get(id);
requireManageableRole(role.getId());
requireVisibleRole(role.getId());
fillRoleDetail(role);
return role;
}
@@ -105,7 +105,7 @@ public class RoleController {
@RequireCorePermission(CorePermissionCode.ROLE_PERMISSION_READ)
@PostMapping("/permission/grantable/list")
public List<Permission> listGrantableRolePermission(@RequestParam String roleId) {
requireManageableRole(roleId);
requireVisibleRole(roleId);
return service.listGrantableRolePermission(roleId);
}
@@ -137,6 +137,12 @@ public class RoleController {
return service.listGrantableParentRole(roleId);
}
@RequireCorePermission(CorePermissionCode.ROLE_CREATE)
@PostMapping("/parent/create/grantable/list")
public List<Role> listCreateGrantableParentRole(@RequestParam ModuleCode moduleCode) {
return service.listCreateGrantableParentRole(moduleCode);
}
@AOPLog
@RequireCorePermission(CorePermissionCode.ROLE_UPDATE)
@PostMapping("/parent/update")
@@ -197,6 +203,19 @@ public class RoleController {
.collect(Collectors.toSet());
}
private Set<String> listVisibleRoleId() {
Set<String> roleIdSet = listManageableRoleId();
String loginUserId = userLoginService.getRequireLoginUserId();
roleIdSet.addAll(userRoleService.listRoleByUserId(loginUserId).stream().map(Role::getId).toList());
return roleIdSet;
}
private void requireVisibleRole(String roleId) {
if (!listVisibleRoleId().contains(roleId)) {
throw new TimiException(TimiCode.PERMISSION_ERROR);
}
}
private void requireManageableRole(String roleId) {
if (!listManageableRoleId().contains(roleId)) {
throw new TimiException(TimiCode.PERMISSION_ERROR);
@@ -75,6 +75,12 @@ public interface RoleService extends BaseService<Role, String> {
/// @return 角色列表
List<Role> listGrantableParentRole(String roleId);
/// 查询创建模块角色时可选的管理父级角色
///
/// @param moduleCode 目标模块代码
/// @return 角色列表
List<Role> listCreateGrantableParentRole(ModuleCode moduleCode);
/// 修改角色管理父级
///
/// @param role 角色
@@ -83,11 +83,12 @@ public class AuthorizationBoundaryServiceImplement implements AuthorizationBound
@Override
public void checkCanCreateRole(String operatorUserId, Role role) {
checkCorePermission(operatorUserId, CorePermissionCode.ROLE_CREATE);
TimiException.required(role.getModuleCode(), "not found role.moduleCode");
TimiException.required(role.getOwnerType(), "not found role.ownerType");
checkOwnerDefinition(role.getModuleCode(), role.getOwnerType(), role.getOwnerId());
if (authorizationScopeService.isSystemAdmin(operatorUserId)) {
return;
}
TimiException.required(role.getModuleCode(), "not found role.moduleCode");
TimiException.required(role.getOwnerType(), "not found role.ownerType");
TimiException.requiredTrue(!Boolean.TRUE.equals(role.getBuiltin()), "不能创建内置角色");
TimiException.requiredTrue(!Boolean.TRUE.equals(role.getProtectedRole()), "不能创建受保护角色");
checkOwnerScope(operatorUserId, role.getModuleCode(), role.getOwnerType(), role.getOwnerId());
@@ -98,6 +99,11 @@ public class AuthorizationBoundaryServiceImplement implements AuthorizationBound
checkCorePermission(operatorUserId, CorePermissionCode.ROLE_UPDATE);
Role dbRole = roleMapper.selectById(role.getId());
TimiException.required(dbRole, "not found role");
if (role.getOwnerType() != null || role.getOwnerId() != null) {
AuthOwnerType ownerType = TimiJava.defaultIfNull(role.getOwnerType(), dbRole.getOwnerType());
String ownerId = TimiJava.defaultIfEmpty(role.getOwnerId(), dbRole.getOwnerId());
checkOwnerDefinition(dbRole.getModuleCode(), ownerType, ownerId);
}
if (authorizationScopeService.isSystemAdmin(operatorUserId)) {
return;
}
@@ -339,6 +345,12 @@ public class AuthorizationBoundaryServiceImplement implements AuthorizationBound
TimiException.requiredTrue(resolver == null || resolver.canUseOwnerScope(operatorUserId, ownerType, ownerId), "归属范围不在可管理范围内");
}
private void checkOwnerDefinition(ModuleCode moduleCode, AuthOwnerType ownerType, String ownerId) {
if (ownerType == AuthOwnerType.MODULE) {
TimiException.requiredTrue(moduleCode.name().equals(ownerId), "模块级归属 ID 必须等于模块代码");
}
}
private void checkCorePermission(String operatorUserId, CorePermissionCode permissionCode) {
TimiException.requiredTrue(hasPermission(operatorUserId, ModuleCode.CORE, permissionCode.getValue()), "权限不足:%s".formatted(permissionCode.getValue()));
}
@@ -355,6 +355,25 @@ public class RoleServiceImplement extends AbstractEntityService<Role, String> im
.toList();
}
@Override
public List<Role> listCreateGrantableParentRole(ModuleCode moduleCode) {
String loginUserId = userLoginService.getRequireLoginUserId();
if (authorizationScopeService.isSystemAdmin(loginUserId)) {
return mapper.selectAll();
}
Set<String> directOperatorRoleIdSet = userRoleMapper.selectByUserIdList(List.of(loginUserId))
.stream()
.map(UserRole::getRoleId)
.collect(Collectors.toSet());
if (TimiJava.isEmpty(directOperatorRoleIdSet)) {
return List.of();
}
return mapper.selectByIdList(directOperatorRoleIdSet)
.stream()
.filter(role -> role.getModuleCode() == moduleCode)
.toList();
}
@Transactional(TimiServerDBConfig.ROLLBACKER)
@Override
public void updateRoleParent(Role role) {