默认接口目录
This commit is contained in:
@@ -18,6 +18,7 @@ import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandl
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
@@ -87,24 +88,35 @@ public class LoadingRole implements CommandLineRunner {
|
||||
|
||||
Method parentNameMethod = annotationClass.getMethod("parentName");
|
||||
String parentName = (String) parentNameMethod.invoke(annotation);
|
||||
|
||||
|
||||
|
||||
String parentId;
|
||||
String parentMenuSql = "select * from sys_menu where title=?"; // 查询菜单是否存在
|
||||
Row parentMenu;
|
||||
// parentMenu = Db.selectOneBySql(parentMenuSql, "默认接口目录");
|
||||
// if (parentMenu == null) {
|
||||
// Db.insertBySql("INSERT INTO `sys_menu` (`type`, `title`) VALUES (?, ?);", 0, "默认接口目录");
|
||||
// }
|
||||
// parentMenu = Db.selectOneBySql(parentMenuSql, "默认接口目录");
|
||||
// if (StrUtil.isNotBlank(parentName)) {
|
||||
// parentMenu = Db.selectOneBySql(parentMenuSql, parentName);
|
||||
// if (parentMenu == null) {
|
||||
// throw new RuntimeException(StrUtil.format("上级菜单不存在, 方法名{}, 方法路径:{}", method.getName(), fullPath));
|
||||
// }
|
||||
// }
|
||||
// parentId = parentMenu.getString("menu_id");
|
||||
parentId = "1";
|
||||
|
||||
Row childMenu;
|
||||
if (StrUtil.isNotBlank(parentName)) {
|
||||
parentMenu = Db.selectOneBySql(parentMenuSql, parentName);
|
||||
if (parentMenu == null) {
|
||||
throw new RuntimeException(StrUtil.format("上级菜单不存在, 方法名{}, 方法路径:{}", method.getName(), fullPath));
|
||||
childMenu = Db.selectOneBySql(parentMenuSql, parentName);
|
||||
if (childMenu == null) {
|
||||
Db.insertBySql("INSERT INTO `sys_menu` (`type`, `pid`,`title`) VALUES (?,?, ?);", 0, parentId, parentName);
|
||||
childMenu = Db.selectOneBySql(parentMenuSql, parentName);
|
||||
}
|
||||
}else {
|
||||
parentMenu = Db.selectOneBySql(parentMenuSql, "默认接口目录");
|
||||
if (parentMenu == null) {
|
||||
Db.insertBySql("INSERT INTO `sys_menu` (`type`, `title`) VALUES (?, ?);", 0, "默认接口目录");
|
||||
}
|
||||
parentMenu = Db.selectOneBySql(parentMenuSql, "默认接口目录");
|
||||
parentId = childMenu.getString("menu_id");
|
||||
}
|
||||
parentId = parentMenu.getString("menu_id");
|
||||
|
||||
for (String s : permissions) {
|
||||
String sql = "select * from sys_menu where permission=?";
|
||||
|
||||
@@ -115,18 +127,18 @@ public class LoadingRole implements CommandLineRunner {
|
||||
String url = menu1.getString("url");
|
||||
String method1 = menu1.getString("method");
|
||||
String permission = menu1.getString("permission");
|
||||
String pid = menu1.getString("pid");
|
||||
String listSql = "select * from sys_roles_menus where menu_id=? and role_id=?";
|
||||
List<Row> count1 = Db.selectListBySql(listSql, menuId, 1L);
|
||||
|
||||
|
||||
|
||||
if (count1.isEmpty()) {
|
||||
sql = "INSERT INTO `sys_roles_menus` (`menu_id`, `role_id`) VALUES (?, ?);";
|
||||
Db.insertBySql(sql, menuId, 1L);
|
||||
log.info("接口菜单添加成功, 菜单名称: {}, 菜单权限: {}", title, permission);
|
||||
}
|
||||
|
||||
if (!title.equals(permissionName) || !fullPath.equals(url) || !httpMethod.equals(method1)) {
|
||||
if (!title.equals(permissionName) || !fullPath.equals(url) || !httpMethod.equals(method1) || !parentId.equals(pid)) {
|
||||
sql = "update sys_menu set title=?, url=?, method=?, pid=? where menu_id=?";
|
||||
Db.updateBySql(sql, permissionName, fullPath, httpMethod, parentId, menuId);
|
||||
log.info("接口菜单修改成功, 旧名称: {}, 新菜单名称: {}", title, permissionName);
|
||||
|
||||
Reference in New Issue
Block a user