|
|
package com.aurora.controller;
|
|
|
|
|
|
import com.aurora.annotation.OptLog;
|
|
|
import com.aurora.model.dto.LabelOptionDTO;
|
|
|
import com.aurora.model.dto.ResourceDTO;
|
|
|
import com.aurora.model.vo.ResultVO;
|
|
|
import com.aurora.service.ResourceService;
|
|
|
import com.aurora.model.vo.ConditionVO;
|
|
|
import com.aurora.model.vo.ResourceVO;
|
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.validation.Valid;
|
|
|
import java.util.List;
|
|
|
|
|
|
import static com.aurora.constant.OptTypeConstant.*;
|
|
|
|
|
|
@Api(tags = "资源模块")
|
|
|
@RestController
|
|
|
public class ResourceController {
|
|
|
|
|
|
@Autowired
|
|
|
private ResourceService resourceService;//调用Service层的资源业务方法
|
|
|
|
|
|
@ApiOperation(value = "查看资源列表")//获取后台管理的资源列表(比如系统的菜单资源、接口资源等)
|
|
|
@GetMapping("/admin/resources")
|
|
|
public ResultVO<List<ResourceDTO>> listResources(ConditionVO conditionVO) {
|
|
|
return ResultVO.ok(resourceService.listResources(conditionVO));
|
|
|
}
|
|
|
|
|
|
@OptLog(optType = DELETE)
|
|
|
@ApiOperation(value = "删除资源")
|
|
|
@DeleteMapping("/admin/resources/{resourceId}")//{resourceId}为路径参数,前端需传入具体的资源ID
|
|
|
public ResultVO<?> deleteResource(@PathVariable("resourceId") Integer resourceId) {
|
|
|
resourceService.deleteResource(resourceId);
|
|
|
return ResultVO.ok();
|
|
|
}
|
|
|
|
|
|
@OptLog(optType = SAVE_OR_UPDATE)
|
|
|
@ApiOperation(value = "新增或修改资源")
|
|
|
@PostMapping("/admin/resources")
|
|
|
public ResultVO<?> saveOrUpdateResource(@RequestBody @Valid ResourceVO resourceVO) {
|
|
|
//ResourceVO resourceVO:封装资源新增、修改的参数,包含资源名称、路径、类型、父资源ID等信息
|
|
|
resourceService.saveOrUpdateResource(resourceVO);
|
|
|
return ResultVO.ok();
|
|
|
}
|
|
|
|
|
|
//获取用于角色分配资源时的选项列表(比如给某个角色配置可访问的资源时,展示所有可选的资源)
|
|
|
@ApiOperation(value = "查看角色资源选项")
|
|
|
@GetMapping("/admin/role/resources")
|
|
|
//返回所有可用的资源选项列表
|
|
|
public ResultVO<List<LabelOptionDTO>> listResourceOption() {
|
|
|
return ResultVO.ok(resourceService.listResourceOption());
|
|
|
}
|
|
|
}
|