Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
4ae8d71866
|
|
@ -1,29 +1,12 @@
|
|||
package com.czg;
|
||||
|
||||
import com.czg.account.entity.SysMenu;
|
||||
import com.czg.account.entity.SysRolesMenus;
|
||||
import com.czg.account.service.SysMenuService;
|
||||
import com.czg.account.service.SysRolesMenusService;
|
||||
import com.czg.annotation.SaAdminCheckPermission;
|
||||
import com.mybatisflex.core.dialect.DbType;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
|
||||
import org.mybatis.spring.annotation.MapperScan;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||
import org.springframework.web.method.HandlerMethod;
|
||||
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/**
|
||||
* @author ww
|
||||
|
|
@ -34,51 +17,9 @@ import java.util.Map;
|
|||
@MapperScan("com.czg.service.account.mapper")
|
||||
@EnableDubbo
|
||||
@Slf4j
|
||||
public class AccountApplication implements CommandLineRunner {
|
||||
public class AccountApplication{
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(AccountApplication.class, args);
|
||||
}
|
||||
@Autowired
|
||||
private RequestMappingHandlerMapping requestMappingHandlerMapping;
|
||||
@Autowired
|
||||
private SysMenuService sysMenuService;
|
||||
@Autowired
|
||||
private SysRolesMenusService sysRolesMenusService;
|
||||
|
||||
|
||||
|
||||
public void run(String... args) {
|
||||
Map<RequestMappingInfo, HandlerMethod> handlerMethods = this.requestMappingHandlerMapping.getHandlerMethods();
|
||||
handlerMethods.forEach((key, value) -> {
|
||||
Method method = value.getMethod();
|
||||
SaAdminCheckPermission annotation = AnnotationUtils.getAnnotation(method, SaAdminCheckPermission.class);
|
||||
if (annotation == null) return;
|
||||
for (String s : annotation.value()) {
|
||||
SysMenu menu1 = sysMenuService.queryChain().eq(SysMenu::getPermission, s).one();
|
||||
if (menu1 !=null) {
|
||||
long count1 = sysRolesMenusService.queryChain().eq(SysRolesMenus::getMenuId, menu1.getMenuId()).eq(SysRolesMenus::getRoleId, 1L).count();
|
||||
if (count1 == 0) {
|
||||
SysRolesMenus sysRolesMenus = new SysRolesMenus();
|
||||
sysRolesMenus.setMenuId(menu1.getMenuId());
|
||||
sysRolesMenus.setRoleId(1L);
|
||||
sysRolesMenusService.save(sysRolesMenus);
|
||||
log.info("接口菜单添加成功, 菜单名称: {}, 菜单权限: {}", menu1.getName(), menu1.getPermission());
|
||||
}
|
||||
continue;
|
||||
}
|
||||
SysMenu sysMenu = new SysMenu();
|
||||
sysMenu.setPermission(s);
|
||||
sysMenu.setName(s);
|
||||
sysMenu.setType(2);
|
||||
sysMenuService.save(sysMenu);
|
||||
SysRolesMenus sysRolesMenus = new SysRolesMenus();
|
||||
sysRolesMenus.setMenuId(sysMenu.getMenuId());
|
||||
sysRolesMenus.setRoleId(1L);
|
||||
sysRolesMenusService.save(sysRolesMenus);
|
||||
log.info("接口菜单添加成功, 菜单名称: {}, 菜单权限: {}", sysMenu.getName(), sysMenu.getPermission());
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import com.czg.resp.CzgResult;
|
|||
import com.czg.sa.StpKit;
|
||||
import com.czg.utils.PageUtil;
|
||||
import com.mybatisflex.core.paginate.Page;
|
||||
import com.mybatisflex.core.query.QueryMethods;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import jakarta.annotation.Resource;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
|
@ -49,11 +50,12 @@ public class ShopTableController {
|
|||
* 权限标识: shopTable:list
|
||||
* @param areaId 区域id
|
||||
* @param tableCode 桌码
|
||||
* @param status 台桌状态
|
||||
* @return 台桌列表
|
||||
*/
|
||||
@SaAdminCheckPermission("shopTable:list")
|
||||
@GetMapping
|
||||
public CzgResult<Page<ShopTable>> list(Integer areaId, String tableCode) {
|
||||
public CzgResult<Page<ShopTable>> list(Integer areaId, String tableCode, String status, String name) {
|
||||
QueryWrapper queryWrapper = new QueryWrapper().eq(ShopTable::getShopId, StpKit.USER.getShopId());
|
||||
if (areaId != null) {
|
||||
queryWrapper.eq(ShopTable::getAreaId, areaId);
|
||||
|
|
@ -62,6 +64,14 @@ public class ShopTableController {
|
|||
if (StrUtil.isNotBlank(tableCode)) {
|
||||
queryWrapper.like(ShopTable::getTableCode, tableCode);
|
||||
}
|
||||
|
||||
if (StrUtil.isNotBlank(status)) {
|
||||
queryWrapper.eq(ShopTable::getStatus, status);
|
||||
}
|
||||
|
||||
if (StrUtil.isNotBlank(name)) {
|
||||
queryWrapper.like(ShopTable::getName, name);
|
||||
}
|
||||
return CzgResult.success(shopTableService.page(PageUtil.buildPage(), queryWrapper));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,82 @@
|
|||
package com.czg;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.mybatisflex.core.row.Db;
|
||||
import com.mybatisflex.core.row.Row;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
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.method.HandlerMethod;
|
||||
import org.springframework.web.servlet.mvc.method.RequestMappingInfo;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
@SuppressWarnings("all")
|
||||
@ConditionalOnClass(name = "com.czg.annotation.SaAdminCheckPermission")
|
||||
public class LoadingRole implements CommandLineRunner {
|
||||
@Autowired
|
||||
private RequestMappingHandlerMapping requestMappingHandlerMapping;
|
||||
|
||||
public void run(String... args) {
|
||||
Map<RequestMappingInfo, HandlerMethod> handlerMethods = this.requestMappingHandlerMapping.getHandlerMethods();
|
||||
handlerMethods.forEach((key, value) -> {
|
||||
Method method = value.getMethod();
|
||||
|
||||
try {
|
||||
// 使用反射获取注解(不 import SaAdminCheckPermission)
|
||||
Class<?> annotationClass = Class.forName("com.czg.annotation.SaAdminCheckPermission");
|
||||
Object annotation = AnnotationUtils.getAnnotation(method, (Class) annotationClass);
|
||||
|
||||
if (annotation == null) return;
|
||||
|
||||
// 通过反射获取注解的 value() 方法
|
||||
Method valueMethod = annotationClass.getMethod("value");
|
||||
String[] permissions = (String[]) valueMethod.invoke(annotation);
|
||||
|
||||
for (String s : permissions) {
|
||||
String sql = "select * from sys_menu where permission=?";
|
||||
Row menu1 = Db.selectOneBySql(sql, s);
|
||||
if (menu1 != null) {
|
||||
Long menuId = menu1.getLong("menu_id");
|
||||
String name = menu1.getString("name");
|
||||
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);
|
||||
|
||||
if (count1.isEmpty()) {
|
||||
sql = "INSERT INTO `sys_roles_menus` (`menu_id`, `role_id`) VALUES (?, ?);";
|
||||
Db.insertBySql(sql, menu1, 1L);
|
||||
log.info("接口菜单添加成功, 菜单名称: {}, 菜单权限: {}", name, permission);
|
||||
}
|
||||
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, s, s, DateUtil.date());
|
||||
sql = "select * from sys_menu where permission=?";
|
||||
Row info = Db.selectOneBySql(sql, s);
|
||||
Long menuId = info.getLong("menu_id");
|
||||
|
||||
sql = "INSERT INTO `sys_roles_menus` (`menu_id`, `role_id`) VALUES (?, ?);";
|
||||
Db.insertBySql(sql, menuId, 1L);
|
||||
|
||||
log.info("接口菜单添加成功, 菜单名称: {}, 菜单权限: {}", s, s);
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
log.warn("SaAdminCheckPermission 注解未找到,跳过权限检查");
|
||||
} catch (Exception e) {
|
||||
log.error("获取 SaAdminCheckPermission 注解失败", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue