content: package com.fit2cloud.constants;
  
  import com.fit2cloud.common.constants.RoleConstants;
  import com.fit2cloud.constants.PermissionConstants.GROUP;
  import com.fit2cloud.constants.PermissionConstants.OPERATE;
  import com.fit2cloud.dto.module.Menu;
  import com.fit2cloud.dto.module.MenuPermission;
  import com.fit2cloud.dto.module.Menus;
  import com.fit2cloud.service.MenuService;
  import org.springframework.beans.factory.annotation.Value;
  import org.springframework.stereotype.Component;
  
  import jakarta.annotation.Resource;
  import java.util.List;
  
  @Component
  public class MenuConstants {
  
      public static List<Menu> MENUS;
  
      @Resource
      private MenuService menuService;
  
      @Value("${spring.application.name}")
      public void setModule(String module) {
  
          MENUS = MENUS_BUILDER.module(module).build().getMenus();
  
          //推送到redis
          menuService.init(module, MENUS);
  
      }
  
      private static final Menus.Builder MENUS_BUILDER = new Menus.Builder()
              .menu(new Menu.Builder()
                      .name("demo")
                      .title("Demo")
                      .path("/demo")
                      .icon("icon_ecs_outlined")
                      .componentPath("/src/views/demo/index.vue")
                      .redirect("/demo/list")
                      .order(1)
                      .requiredPermission(new MenuPermission.Builder()
                              .role(RoleConstants.ROLE.ADMIN)
                              .permission(GROUP.DEMO, OPERATE.READ)
                      )
                      .requiredPermission(new MenuPermission.Builder()
                              .role(RoleConstants.ROLE.ORGADMIN)
                              .permission(GROUP.DEMO, OPERATE.READ)
                      )
                      .requiredPermission(new MenuPermission.Builder()
                              .role(RoleConstants.ROLE.USER)
                              .permission(GROUP.DEMO, OPERATE.READ)
                      )
                      .childOperationRoute(new Menu.Builder()
                              .name("demo_list")
                              .title("列表")
                              .path("/list")
                              .saveRecent(true)
                              .componentPath("/src/views/demo/list.vue")
                              .requiredPermission(new MenuPermission.Builder()
                                      .role(RoleConstants.ROLE.ADMIN)
                                      .permission(GROUP.DEMO, OPERATE.READ)
                              )
                              .requiredPermission(new MenuPermission.Builder()
                                      .role(RoleConstants.ROLE.ORGADMIN)
                                      .permission(GROUP.DEMO, OPERATE.READ)
                              )
                              .requiredPermission(new MenuPermission.Builder()
                                      .role(RoleConstants.ROLE.USER)
                                      .permission(GROUP.DEMO, OPERATE.READ)
                              )
                      )
              )
  
              //...
              ;
  
  
  }
  