com.didiglobal.logi.security.controller.v1.ProjectController Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of logi-security-spring-boot-starter Show documentation
Show all versions of logi-security-spring-boot-starter Show documentation
logi-security 提供项目大多都需要的一些基础功能(用户、角色、权限、登录、注册、操作记录)
package com.didiglobal.logi.security.controller.v1;
import com.didiglobal.logi.security.common.constant.Constants;
import com.didiglobal.logi.security.common.PagingData;
import com.didiglobal.logi.security.common.PagingResult;
import com.didiglobal.logi.security.common.Result;
import com.didiglobal.logi.security.common.dto.project.ProjectQueryDTO;
import com.didiglobal.logi.security.common.dto.project.ProjectSaveDTO;
import com.didiglobal.logi.security.common.vo.project.ProjectBriefVO;
import com.didiglobal.logi.security.common.vo.project.ProjectDeleteCheckVO;
import com.didiglobal.logi.security.common.vo.project.ProjectVO;
import com.didiglobal.logi.security.exception.LogiSecurityException;
import com.didiglobal.logi.security.service.ProjectService;
import com.didiglobal.logi.security.util.HttpRequestUtil;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
/**
* @author cjm
*/
@RestController
@Api(value = "logi-security-project相关API接口", tags = "logi-security-项目相关API接口")
@RequestMapping(Constants.API_PREFIX_V1 + "/project")
public class ProjectController {
@Autowired
private ProjectService projectService;
@GetMapping("/{id}")
@ApiOperation(value = "获取项目详情", notes = "根据项目id获取项目详情")
@ApiImplicitParam(name = "id", value = "项目id", dataType = "int", required = true)
public Result detail(@PathVariable Integer id) {
try {
ProjectVO projectVO = projectService.getProjectDetailByProjectId(id);
return Result.success(projectVO);
} catch (LogiSecurityException e) {
return Result.fail(e);
}
}
@GetMapping("/{id}/exist")
@ApiOperation(value = "校验项目是否存在", notes = "校验项目是否存在")
@ApiImplicitParam(name = "id", value = "项目id", dataType = "int", required = true)
public Result checkExist(@PathVariable Integer id) {
return Result.buildSucc(projectService.checkProjectExist(id));
}
@PutMapping("/switch/{id}")
@ApiOperation(value = "更改项目运行状态", notes = "调用该接口则项目运行状态被反转")
@ApiImplicitParam(name = "id", value = "项目id", dataType = "int", required = true)
public Result switched(@PathVariable Integer id, HttpServletRequest request) {
projectService.changeProjectStatus(id, HttpRequestUtil.getOperator(request));
return Result.success();
}
@PutMapping
@ApiOperation(value = "更新项目", notes = "根据项目id更新项目信息")
public Result update(@RequestBody ProjectSaveDTO saveDTO, HttpServletRequest request) {
try {
projectService.updateProject(saveDTO, HttpRequestUtil.getOperator(request));
} catch (LogiSecurityException e) {
e.printStackTrace();
return Result.fail(e);
}
return Result.success();
}
@PostMapping
@ApiOperation(value = "创建项目", notes = "创建项目")
public Result create(@RequestBody ProjectSaveDTO saveDTO, HttpServletRequest request) {
try {
ProjectVO projectVO = projectService.createProject(saveDTO, HttpRequestUtil.getOperator(request));
return Result.success(projectVO);
} catch (LogiSecurityException e) {
e.printStackTrace();
return Result.fail(e);
}
}
@GetMapping("/delete/check/{id}")
@ApiOperation(value = "删除项目前的检查", notes = "检查是否有服务引用了该项目、是否有具体资源挂上了该项目")
@ApiImplicitParam(name = "id", value = "项目id", dataType = "int", required = true)
public Result deleteCheck(@PathVariable Integer id) {
ProjectDeleteCheckVO deleteCheckVO = projectService.checkBeforeDelete(id);
return Result.success(deleteCheckVO);
}
@DeleteMapping("/{id}")
@ApiOperation(value = "删除项目", notes = "根据项目id删除项目")
@ApiImplicitParam(name = "id", value = "项目id", dataType = "int", required = true)
public Result delete(@PathVariable Integer id, HttpServletRequest request) {
projectService.deleteProjectByProjectId(id, HttpRequestUtil.getOperator(request));
return Result.success();
}
@PostMapping("/page")
@ApiOperation(value = "分页查询项目列表", notes = "分页和条件查询")
public PagingResult page(@RequestBody ProjectQueryDTO queryDTO) {
PagingData pageProject = projectService.getProjectPage(queryDTO);
return PagingResult.success(pageProject);
}
@GetMapping("/list")
@ApiOperation(value = "获取所有项目简要信息", notes = "获取全部项目简要信息(只返回id、项目名)")
public Result> list() {
List projectBriefVOList = projectService.getProjectBriefList();
return Result.success(projectBriefVOList);
}
@PutMapping("/{id}/owner/{ownerId}")
@ApiOperation(value = "从角色中增加该项目下的负责人", notes = "从角色中增加该项目下的用户")
@ApiImplicitParam(name = "id", value = "角色id", dataType = "int", required = true)
public Result addProjectOwner(@PathVariable Integer id, @PathVariable Integer ownerId, HttpServletRequest request) {
try {
projectService.addProjectOwner(id, ownerId, HttpRequestUtil.getOperator(request));
} catch (LogiSecurityException e) {
return Result.fail(e);
}
return Result.success();
}
@DeleteMapping("/{id}/owner/{ownerId}")
@ApiOperation(value = "从项目中删除该项目下的负责人", notes = "从项目中删除该项目下的负责人")
@ApiImplicitParam(name = "id", value = "角色id", dataType = "int", required = true)
public Result deleteProjectOwner(@PathVariable Integer id, @PathVariable Integer ownerId, HttpServletRequest request) {
try {
projectService.delProjectOwner(id, ownerId, HttpRequestUtil.getOperator(request));
} catch (LogiSecurityException e) {
return Result.fail(e);
}
return Result.success();
}
@PutMapping("/{id}/user/{userId}")
@ApiOperation(value = "从角色中增加该项目下的用户", notes = "从角色中增加该项目下的用户")
@ApiImplicitParam(name = "id", value = "角色id", dataType = "int", required = true)
public Result addProjectUser(@PathVariable Integer id, @PathVariable Integer userId, HttpServletRequest request) {
try {
projectService.addProjectUser(id, userId, HttpRequestUtil.getOperator(request));
} catch (LogiSecurityException e) {
return Result.fail(e);
}
return Result.success();
}
@DeleteMapping("/{id}/user/{userId}")
@ApiOperation(value = "从项目中删除该项目下的用户", notes = "从项目中删除该项目下的用户")
@ApiImplicitParam(name = "id", value = "角色id", dataType = "int", required = true)
public Result deleteProjectUser(@PathVariable Integer id, @PathVariable Integer userId, HttpServletRequest request) {
try {
projectService.delProjectUser(id, userId, HttpRequestUtil.getOperator(request));
} catch (LogiSecurityException e) {
return Result.fail(e);
}
return Result.success();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy