自动载入权限实现
This commit is contained in:
parent
77803e0b36
commit
9470735feb
|
|
@ -33,7 +33,7 @@ public class MerchantRegisterController {
|
||||||
* @return 激活码列表
|
* @return 激活码列表
|
||||||
*/
|
*/
|
||||||
@SaAdminCheckRole("管理员")
|
@SaAdminCheckRole("管理员")
|
||||||
@SaAdminCheckPermission("merchantRegister:list")
|
@SaAdminCheckPermission(value = "merchantRegister:list", name = "激活码列表")
|
||||||
@GetMapping
|
@GetMapping
|
||||||
public CzgResult<Page<MerchantRegister>> get(PageDTO pageDTO, Integer state, String startTime, String endTime) {
|
public CzgResult<Page<MerchantRegister>> get(PageDTO pageDTO, Integer state, String startTime, String endTime) {
|
||||||
return CzgResult.success(merchantRegisterService.get(pageDTO, state, startTime, endTime));
|
return CzgResult.success(merchantRegisterService.get(pageDTO, state, startTime, endTime));
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,8 @@ public @interface SaAdminCheckPermission {
|
||||||
@AliasFor(annotation = SaCheckPermission.class)
|
@AliasFor(annotation = SaCheckPermission.class)
|
||||||
String [] value() default {};
|
String [] value() default {};
|
||||||
|
|
||||||
|
String name() default "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 验证模式:AND | OR,默认AND
|
* 验证模式:AND | OR,默认AND
|
||||||
* @return 验证模式
|
* @return 验证模式
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.czg;
|
package com.czg;
|
||||||
|
|
||||||
import cn.hutool.core.date.DateUtil;
|
import cn.hutool.core.date.DateUtil;
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
import com.mybatisflex.core.row.Db;
|
import com.mybatisflex.core.row.Db;
|
||||||
import com.mybatisflex.core.row.Row;
|
import com.mybatisflex.core.row.Row;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
@ -41,12 +42,15 @@ public class LoadingRole implements CommandLineRunner {
|
||||||
Method valueMethod = annotationClass.getMethod("value");
|
Method valueMethod = annotationClass.getMethod("value");
|
||||||
String[] permissions = (String[]) valueMethod.invoke(annotation);
|
String[] permissions = (String[]) valueMethod.invoke(annotation);
|
||||||
|
|
||||||
|
Method nameMethod = annotationClass.getMethod("name");
|
||||||
|
String permissionName = (String) nameMethod.invoke(annotation);
|
||||||
|
|
||||||
for (String s : permissions) {
|
for (String s : permissions) {
|
||||||
String sql = "select * from sys_menu where permission=?";
|
String sql = "select * from sys_menu where permission=?";
|
||||||
Row menu1 = Db.selectOneBySql(sql, s);
|
Row menu1 = Db.selectOneBySql(sql, s);
|
||||||
if (menu1 != null) {
|
if (menu1 != null) {
|
||||||
Long menuId = menu1.getLong("menu_id");
|
Long menuId = menu1.getLong("menu_id");
|
||||||
String name = menu1.getString("name");
|
String title = menu1.getString("title");
|
||||||
String permission = menu1.getString("permission");
|
String permission = menu1.getString("permission");
|
||||||
String listSql = "select * from sys_roles_menus where menu_id=? and role_id=?";
|
String listSql = "select * from sys_roles_menus where menu_id=? and role_id=?";
|
||||||
List<Row> count1 = Db.selectListBySql(listSql, menuId, 1L);
|
List<Row> count1 = Db.selectListBySql(listSql, menuId, 1L);
|
||||||
|
|
@ -54,14 +58,20 @@ public class LoadingRole implements CommandLineRunner {
|
||||||
if (count1.isEmpty()) {
|
if (count1.isEmpty()) {
|
||||||
sql = "INSERT INTO `sys_roles_menus` (`menu_id`, `role_id`) VALUES (?, ?);";
|
sql = "INSERT INTO `sys_roles_menus` (`menu_id`, `role_id`) VALUES (?, ?);";
|
||||||
Db.insertBySql(sql, menu1, 1L);
|
Db.insertBySql(sql, menu1, 1L);
|
||||||
log.info("接口菜单添加成功, 菜单名称: {}, 菜单权限: {}", name, permission);
|
log.info("接口菜单添加成功, 菜单名称: {}, 菜单权限: {}", title, permission);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StrUtil.isNotBlank(permissionName) && !title.equals(permissionName)) {
|
||||||
|
sql = "update sys_menu set title=? where menu_id=?";
|
||||||
|
Db.updateBySql(sql, permissionName, menuId);
|
||||||
|
log.info("接口菜单修改成功, 旧名称: {}, 新菜单名称: {}", title, permissionName);
|
||||||
}
|
}
|
||||||
continue;
|
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 " +
|
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);";
|
"(0, 2, ?, NULL, '', 2, '', '', b'0', b'0', b'0', ?, NULL, NULL, ?, NULL, NULL, 0);";
|
||||||
Db.insertBySql(sql, s, s, DateUtil.date());
|
Db.insertBySql(sql, StrUtil.isNotBlank(permissionName) ? permissionName : s, s, DateUtil.date());
|
||||||
sql = "select * from sys_menu where permission=?";
|
sql = "select * from sys_menu where permission=?";
|
||||||
Row info = Db.selectOneBySql(sql, s);
|
Row info = Db.selectOneBySql(sql, s);
|
||||||
Long menuId = info.getLong("menu_id");
|
Long menuId = info.getLong("menu_id");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue