权限修改
This commit is contained in:
@@ -91,13 +91,14 @@ public class MyStpLogic {
|
||||
* @param loginType 登录类型枚举
|
||||
* @param isAdmin 是否为管理员账号
|
||||
*/
|
||||
public void login(Long id, String account, Long shopId, String shopName, LoginType loginType, boolean isAdmin) {
|
||||
public void login(Long id, String account, Long shopId, String shopName, LoginType loginType, boolean isAdmin, String platForm) {
|
||||
StpLogic logic = getLogic();
|
||||
logic.login(id);
|
||||
if (loginType.equals(LoginType.MANAGER) && shopId == null) {
|
||||
throw new ApiNotPrintException("管理端登录必须传递店铺id");
|
||||
}
|
||||
SaSession session = logic.getSession().set("userId", id).set("isAdmin", isAdmin).set("isManager", loginType.equals(LoginType.MANAGER))
|
||||
.set("platForm", platForm)
|
||||
.set("loginType", loginType).set("account", account);
|
||||
if (shopId != null) {
|
||||
session.set("shopId", shopId);
|
||||
@@ -107,6 +108,12 @@ public class MyStpLogic {
|
||||
}
|
||||
}
|
||||
|
||||
public String getPlatForm() {
|
||||
StpLogic logic = getLogic();
|
||||
Object platForm = logic.getSession().get("platForm");
|
||||
return platForm instanceof String s ? s : "";
|
||||
}
|
||||
|
||||
public void reLogin(long id) {
|
||||
StpLogic logic = getLogic();
|
||||
String token = logic.getTokenValue();
|
||||
|
||||
@@ -6,6 +6,8 @@ import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
*/
|
||||
@@ -64,4 +66,16 @@ public class MenuAddDTO {
|
||||
* 权限表示
|
||||
*/
|
||||
private String permission;
|
||||
/**
|
||||
* 小程序页面路径
|
||||
*/
|
||||
private String miniPath;
|
||||
/**
|
||||
* 小程序组件
|
||||
*/
|
||||
private String miniComponent;
|
||||
/**
|
||||
* 接口路径支持通配符, 多个逗号分割
|
||||
*/
|
||||
private List<MenuApiInfoItemDTO> apiInfo;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.czg.account.dto.menu;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
*/
|
||||
@Data
|
||||
public class MenuApiInfoItemDTO {
|
||||
/**
|
||||
* 请求方式 ALL, POST, GET, DELETE, PUT
|
||||
*/
|
||||
private String method;
|
||||
/**
|
||||
* 接口地址,支持通配符*和?
|
||||
*/
|
||||
private String url;
|
||||
}
|
||||
@@ -6,6 +6,8 @@ import jakarta.validation.constraints.NotEmpty;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
*/
|
||||
@@ -55,7 +57,19 @@ public class MenuEditDTO {
|
||||
*/
|
||||
private String activeMenu;
|
||||
/**
|
||||
* 权限表示
|
||||
* 权限标识
|
||||
*/
|
||||
private String permission;
|
||||
/**
|
||||
* 小程序页面路径
|
||||
*/
|
||||
private String miniPath;
|
||||
/**
|
||||
* 小程序组件
|
||||
*/
|
||||
private String miniComponent;
|
||||
/**
|
||||
* 接口路径支持通配符
|
||||
*/
|
||||
private List<MenuApiInfoItemDTO> apiInfo;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.czg.account.dto.role;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Administrator
|
||||
*/
|
||||
@Data
|
||||
public class RolePermissionDTO {
|
||||
/**
|
||||
* 角色id
|
||||
*/
|
||||
@NotNull
|
||||
private Long roleId;
|
||||
/**
|
||||
* 管理员菜单id
|
||||
*/
|
||||
List<Long> adminMenuIdList;
|
||||
/**
|
||||
* 收银机菜单id
|
||||
*/
|
||||
List<Long> cashMenuIdList;
|
||||
}
|
||||
@@ -131,4 +131,25 @@ public class SysMenu implements Serializable {
|
||||
*/
|
||||
private Long isShop;
|
||||
|
||||
/**
|
||||
* 小程序页面路径
|
||||
*/
|
||||
private String miniPath;
|
||||
/**
|
||||
* 小程序组件
|
||||
*/
|
||||
private String miniComponent;
|
||||
/**
|
||||
* 包含的接口
|
||||
*/
|
||||
private String apiInfo;
|
||||
/**
|
||||
* 接口地址
|
||||
*/
|
||||
private String url;
|
||||
/**
|
||||
* 请求方式
|
||||
*/
|
||||
private String method;
|
||||
|
||||
}
|
||||
|
||||
@@ -37,4 +37,9 @@ public class SysRolesMenus implements Serializable {
|
||||
@Id
|
||||
private Long roleId;
|
||||
|
||||
/**
|
||||
* 0 管理端及小程序 1收银机
|
||||
*/
|
||||
private Integer type;
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.czg.account.service;
|
||||
import com.czg.account.dto.PageDTO;
|
||||
import com.czg.account.dto.role.RoleAddDTO;
|
||||
import com.czg.account.dto.role.RoleEditDTO;
|
||||
import com.czg.account.dto.role.RolePermissionDTO;
|
||||
import com.czg.account.entity.SysRole;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.service.IService;
|
||||
@@ -25,5 +26,7 @@ public interface SysRoleService extends IService<SysRole> {
|
||||
|
||||
Boolean edit(RoleEditDTO roleEditDTO);
|
||||
|
||||
List<Long> getRoleMenu(long loginIdAsLong, Integer id);
|
||||
List<Long> getRoleMenu(long loginIdAsLong, Integer id, Integer type);
|
||||
|
||||
Boolean editPermission(long userId, RolePermissionDTO rolePermissionDTO);
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
|
||||
@@ -32,6 +33,45 @@ public class LoadingRole implements CommandLineRunner {
|
||||
Method method = value.getMethod();
|
||||
|
||||
try {
|
||||
Class<?> controllerClass = method.getDeclaringClass();
|
||||
// 获取类上的 @RequestMapping 路径
|
||||
String classPath = "";
|
||||
if (controllerClass.isAnnotationPresent(RequestMapping.class)) {
|
||||
RequestMapping classMapping = controllerClass.getAnnotation(RequestMapping.class);
|
||||
classPath = classMapping.value().length > 0 ? classMapping.value()[0] : "";
|
||||
}
|
||||
|
||||
// 获取方法上的注解路径和请求方式
|
||||
String methodPaths = "";
|
||||
String httpMethod = "UNKNOWN";
|
||||
|
||||
if (method.isAnnotationPresent(GetMapping.class)) {
|
||||
GetMapping mapping = method.getAnnotation(GetMapping.class);
|
||||
methodPaths = mapping.value().length > 0 ? mapping.value()[0] : "";
|
||||
httpMethod = "GET";
|
||||
} else if (method.isAnnotationPresent(PostMapping.class)) {
|
||||
PostMapping mapping = method.getAnnotation(PostMapping.class);
|
||||
methodPaths = mapping.value().length > 0 ? mapping.value()[0] : "";
|
||||
httpMethod = "POST";
|
||||
} else if (method.isAnnotationPresent(PutMapping.class)) {
|
||||
PutMapping mapping = method.getAnnotation(PutMapping.class);
|
||||
methodPaths = mapping.value().length > 0 ? mapping.value()[0] : "";
|
||||
httpMethod = "PUT";
|
||||
} else if (method.isAnnotationPresent(DeleteMapping.class)) {
|
||||
DeleteMapping mapping = method.getAnnotation(DeleteMapping.class);
|
||||
methodPaths = mapping.value().length > 0 ? mapping.value()[0] : "";
|
||||
httpMethod = "DELETE";
|
||||
} else if (method.isAnnotationPresent(RequestMapping.class)) {
|
||||
RequestMapping mapping = method.getAnnotation(RequestMapping.class);
|
||||
methodPaths = mapping.value().length > 0 ? mapping.value()[0] : "";
|
||||
RequestMethod[] methods = mapping.method();
|
||||
httpMethod = methods.length > 0 ? methods[0].name() : "ALL";
|
||||
}
|
||||
|
||||
// 拼接路径并输出
|
||||
String fullPath = (classPath + "/" + methodPaths).replaceAll("//+", "/");
|
||||
|
||||
|
||||
// 使用反射获取注解(不 import SaAdminCheckPermission)
|
||||
Class<?> annotationClass = Class.forName("com.czg.annotation.SaAdminCheckPermission");
|
||||
Object annotation = AnnotationUtils.getAnnotation(method, (Class) annotationClass);
|
||||
@@ -51,6 +91,8 @@ public class LoadingRole implements CommandLineRunner {
|
||||
if (menu1 != null) {
|
||||
Long menuId = menu1.getLong("menu_id");
|
||||
String title = menu1.getString("title");
|
||||
String url = menu1.getString("url");
|
||||
String method1 = menu1.getString("method");
|
||||
String permission = menu1.getString("permission");
|
||||
String listSql = "select * from sys_roles_menus where menu_id=? and role_id=?";
|
||||
List<Row> count1 = Db.selectListBySql(listSql, menuId, 1L);
|
||||
@@ -61,17 +103,17 @@ public class LoadingRole implements CommandLineRunner {
|
||||
log.info("接口菜单添加成功, 菜单名称: {}, 菜单权限: {}", title, permission);
|
||||
}
|
||||
|
||||
if (StrUtil.isNotBlank(permissionName) && (title == null || !title.equals(permissionName))) {
|
||||
sql = "update sys_menu set title=? where menu_id=?";
|
||||
Db.updateBySql(sql, permissionName, menuId);
|
||||
if (!title.equals(permissionName) || !fullPath.equals(url) || !httpMethod.equals(method1)) {
|
||||
sql = "update sys_menu set title=?, url=?, method=? where menu_id=?";
|
||||
Db.updateBySql(sql, permissionName, fullPath, httpMethod, menuId);
|
||||
log.info("接口菜单修改成功, 旧名称: {}, 新菜单名称: {}", title, permissionName);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
sql = "INSERT INTO `czg_cashier`.`sys_menu` ( `sub_count`, `type`, `title`, `name`, `component`, `menu_sort`, `icon`, `path`, `i_frame`, `cache`, `hidden`, `permission`, `create_by`, `update_by`, `create_time`, `update_time`, `active_menu`, `is_shop`) VALUES " +
|
||||
"(0, 2, ?, NULL, '', 2, '', '', b'0', b'0', b'0', ?, NULL, NULL, ?, NULL, NULL, 0);";
|
||||
Db.insertBySql(sql, StrUtil.isNotBlank(permissionName) ? permissionName : s, s, DateUtil.date());
|
||||
sql = "INSERT INTO `czg_cashier`.`sys_menu` ( `sub_count`, `type`, `title`, `name`, `component`, `menu_sort`, `icon`, `path`, `i_frame`, `cache`, `hidden`, `permission`, `create_by`, `update_by`, `create_time`, `update_time`, `active_menu`, `is_shop`, 'url', 'method') VALUES " +
|
||||
"(0, 2, ?, NULL, '', 2, '', '', b'0', b'0', b'0', ?, NULL, NULL, ?, NULL, NULL, 0, ?, ?);";
|
||||
Db.insertBySql(sql, StrUtil.isNotBlank(permissionName) ? permissionName : s, s, DateUtil.date(), fullPath, httpMethod);
|
||||
sql = "select * from sys_menu where permission=?";
|
||||
Row info = Db.selectOneBySql(sql, s);
|
||||
Long menuId = info.getLong("menu_id");
|
||||
|
||||
Reference in New Issue
Block a user