com.github.rexsheng.springboot.faster.system.menu.adapter.MenuController Maven / Gradle / Ivy
The newest version!
package com.github.rexsheng.springboot.faster.system.menu.adapter;
import com.github.rexsheng.springboot.faster.common.constant.CommonConstant;
import com.github.rexsheng.springboot.faster.common.domain.Result;
import com.github.rexsheng.springboot.faster.logging.RequestLog;
import com.github.rexsheng.springboot.faster.request.repeat.annotation.RequestRepeat;
import com.github.rexsheng.springboot.faster.system.menu.application.MenuService;
import com.github.rexsheng.springboot.faster.system.menu.application.dto.AddMenuRequest;
import com.github.rexsheng.springboot.faster.system.menu.application.dto.QueryMenuRequest;
import com.github.rexsheng.springboot.faster.system.menu.application.dto.UpdateMenuRequest;
import com.github.rexsheng.springboot.faster.system.menu.application.dto.ValidateMenuCodeRequest;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.Authentication;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
@RestController
@RequestMapping("/sys/menu")
@Tag(name = "MenuController",description = "菜单管理")
@ConditionalOnProperty(prefix = "app.module.management",name = "controller",havingValue = "true",matchIfMissing = true)
@ConditionalOnClass({Authentication.class, SqlSessionFactoryBean.class})
public class MenuController {
private static Logger logger= LoggerFactory.getLogger(MenuController.class);
@Autowired
private MenuService menuService;
@PreAuthorize("hasAuthority(T(com.github.rexsheng.springboot.faster.common.constant.AuthCodeConstant).ROLE_ASSIGNAUTH)" +
" || hasAuthority(T(com.github.rexsheng.springboot.faster.common.constant.AuthCodeConstant).MENU_EDIT)")
@GetMapping("/tree")
public Result queryMenuTree(){
QueryMenuRequest query=new QueryMenuRequest();
query.setStatus(CommonConstant.STATUS_RUNNING);
query.setExcludeNonParent(true);
return Result.success(menuService.queryList(query));
}
@PreAuthorize("hasAuthority(T(com.github.rexsheng.springboot.faster.common.constant.AuthCodeConstant).MENU_LIST)")
@GetMapping
public Result queryMenuList(@RequestParam(required = false) String menuName){
QueryMenuRequest query=new QueryMenuRequest();
query.setMenuName(menuName);
return Result.success(menuService.queryList(query));
}
@PreAuthorize("hasAuthority(T(com.github.rexsheng.springboot.faster.common.constant.AuthCodeConstant).MENU_ADD)")
@PostMapping
@RequestLog("新增菜单")
public Result addMenu(@RequestBody @Validated AddMenuRequest request){
menuService.add(request);
return Result.success();
}
@PreAuthorize("hasAuthority(T(com.github.rexsheng.springboot.faster.common.constant.AuthCodeConstant).MENU_EDIT)")
@GetMapping("/{id}")
public Result getMenu(@PathVariable Integer id){
return Result.success(menuService.get(id));
}
@PreAuthorize("hasAuthority(T(com.github.rexsheng.springboot.faster.common.constant.AuthCodeConstant).MENU_EDIT)")
@PutMapping("/{id}")
@RequestLog("修改菜单")
public Result updateMenu(@PathVariable Integer id, @RequestBody @Validated UpdateMenuRequest request){
request.setMenuId(id);
menuService.update(request);
return Result.success();
}
@PreAuthorize("hasAuthority(T(com.github.rexsheng.springboot.faster.common.constant.AuthCodeConstant).MENU_EDIT)")
@PutMapping("/{ids}/status/{status}")
@RequestLog("修改菜单状态")
public Result changeMenuValid(@PathVariable Integer[] ids,@PathVariable Boolean status){
menuService.updateStatus(UpdateMenuRequest.of(ids,status?CommonConstant.STATUS_RUNNING:CommonConstant.STATUS_STOP));
return Result.success();
}
@PreAuthorize("hasAuthority(T(com.github.rexsheng.springboot.faster.common.constant.AuthCodeConstant).MENU_DEL)")
@DeleteMapping
@RequestLog("删除菜单")
public Result deleteMenu(@RequestBody Integer[] ids){
menuService.delete(Arrays.asList(ids));
return Result.success();
}
@PreAuthorize("hasAuthority(T(com.github.rexsheng.springboot.faster.common.constant.AuthCodeConstant).MENU_ADD)" +
" || hasAuthority(T(com.github.rexsheng.springboot.faster.common.constant.AuthCodeConstant).MENU_EDIT)")
@PutMapping("/code/valid")
@RequestRepeat(enabled = false)
public Result validMenuCode(@RequestBody ValidateMenuCodeRequest request){
return Result.success(menuService.validCode(request));
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy