From e87dd964f231b571f414b55572b6969c662e61e8 Mon Sep 17 00:00:00 2001
From: longz <longzhaoz@qq.com>
Date: 星期一, 20 七月 2026 20:01:29 +0800
Subject: [PATCH] fix: 补齐合作商内置角色
---
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysRoleController.java | 45 ++++++++++++++++++++++++++++++++++++---------
1 files changed, 36 insertions(+), 9 deletions(-)
diff --git a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysRoleController.java b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysRoleController.java
index c82449f..275c851 100644
--- a/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysRoleController.java
+++ b/ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysRoleController.java
@@ -65,6 +65,10 @@
public class SysRoleController extends BaseController {
private static final String INDEPENDENT_PARTNER_ROLE_NAME = "独立合作商";
private static final String INDEPENDENT_PARTNER_ROLE_KEY = "independent_partner";
+ private static final String SITE_OWNER_ROLE_NAME = "场地方";
+ private static final String SITE_OWNER_ROLE_KEY = "site_owner";
+ private static final String SERVICE_PROVIDER_ROLE_NAME = "服务商";
+ private static final String SERVICE_PROVIDER_ROLE_KEY = "service_provider";
private static final String OWN_SITE_NAME = "自有电站";
private static final String SYSTEM_ROLE_REMARK = "系统内置角色";
@@ -91,31 +95,46 @@
@Resource
private SiteClient siteClient;
- private void ensureIndependentPartnerRole() {
+ private void ensureBuiltinRoles() {
+ ensureSystemRole(INDEPENDENT_PARTNER_ROLE_NAME, INDEPENDENT_PARTNER_ROLE_KEY, getIndependentPartnerMenuIds());
+ ensureSystemRole(SITE_OWNER_ROLE_NAME, SITE_OWNER_ROLE_KEY, new HashSet<>());
+ ensureSystemRole(SERVICE_PROVIDER_ROLE_NAME, SERVICE_PROVIDER_ROLE_KEY, new HashSet<>());
+ }
+
+ private void ensureSystemRole(String roleName, String roleKey, Set<Long> menuIds) {
SysRole role = roleService.getOne(new LambdaQueryWrapper<SysRole>()
- .eq(SysRole::getRoleKey, INDEPENDENT_PARTNER_ROLE_KEY)
+ .eq(SysRole::getRoleKey, roleKey)
.eq(SysRole::getDelFlag, 0)
.last("LIMIT 1"));
if (role == null) {
role = roleService.getOne(new LambdaQueryWrapper<SysRole>()
- .eq(SysRole::getRoleName, INDEPENDENT_PARTNER_ROLE_NAME)
+ .eq(SysRole::getRoleName, roleName)
.eq(SysRole::getDelFlag, 0)
.last("LIMIT 1"));
}
if (role != null) {
+ if (!roleKey.equals(role.getRoleKey())
+ || !"0".equals(role.getStatus())
+ || !SYSTEM_ROLE_REMARK.equals(role.getRemark())) {
+ role.setRoleKey(roleKey);
+ role.setStatus("0");
+ role.setRemark(SYSTEM_ROLE_REMARK);
+ role.setUpdateBy(SecurityUtils.getUsername());
+ role.setUpdateTime(new Date());
+ roleService.updateById(role);
+ }
return;
}
SysRole newRole = new SysRole();
- newRole.setRoleName(INDEPENDENT_PARTNER_ROLE_NAME);
- newRole.setRoleKey(INDEPENDENT_PARTNER_ROLE_KEY);
+ newRole.setRoleName(roleName);
+ newRole.setRoleKey(roleKey);
newRole.setDataScope("5");
newRole.setStatus("0");
newRole.setDelFlag("0");
newRole.setRemark(SYSTEM_ROLE_REMARK);
newRole.setCreateBy(SecurityUtils.getUsername());
newRole.setCreateTime(new Date());
- Set<Long> menuIds = getIndependentPartnerMenuIds();
newRole.setMenuIds(menuIds.toArray(new Long[0]));
roleService.insertRole(newRole);
}
@@ -155,15 +174,23 @@
|| INDEPENDENT_PARTNER_ROLE_NAME.equals(role.getRoleName()));
}
+ private boolean isPartnerBuiltinRole(SysRole role) {
+ return role != null && (isIndependentPartnerRole(role)
+ || SITE_OWNER_ROLE_KEY.equals(role.getRoleKey())
+ || SITE_OWNER_ROLE_NAME.equals(role.getRoleName())
+ || SERVICE_PROVIDER_ROLE_KEY.equals(role.getRoleKey())
+ || SERVICE_PROVIDER_ROLE_NAME.equals(role.getRoleName()));
+ }
+
private boolean isSystemBuiltinRole(SysRole role) {
- return role != null && (role.isAdmin() || isIndependentPartnerRole(role));
+ return role != null && (role.isAdmin() || isPartnerBuiltinRole(role));
}
private void fillRoleV2Info(SysRole role) {
if (role == null) {
return;
}
- boolean partnerRole = isIndependentPartnerRole(role);
+ boolean partnerRole = isPartnerBuiltinRole(role);
role.setPartnerRole(partnerRole);
role.setSystemRole(isSystemBuiltinRole(role));
if (partnerRole) {
@@ -191,7 +218,7 @@
@GetMapping("/listPage")
@ApiOperation(value = "获取角色列表", tags = {"管理后台-角色管理"})
public AjaxResult listPage(String name, BasePage basePage) {
- ensureIndependentPartnerRole();
+ ensureBuiltinRoles();
PageInfo<SysRole> pageInfo = new PageInfo<>(basePage.getPageCurr(), basePage.getPageSize());
LambdaQueryWrapper<SysRole> wrapper = new LambdaQueryWrapper<SysRole>().eq(SysRole::getStatus, 0).eq(SysRole::getDelFlag, 0);
if (StringUtils.isNotEmpty(name)) {
--
Gitblit v1.7.1