com.github.rexsheng.springboot.faster.system.dept.adapter.DeptController Maven / Gradle / Ivy
The newest version!
package com.github.rexsheng.springboot.faster.system.dept.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.system.dept.application.DeptService;
import com.github.rexsheng.springboot.faster.system.dept.application.dto.AddDeptRequest;
import com.github.rexsheng.springboot.faster.system.dept.application.dto.QueryDeptRequest;
import com.github.rexsheng.springboot.faster.system.dept.application.dto.UpdateDeptRequest;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
@RestController
@RequestMapping("/sys/dept")
@Tag(name = "DeptController",description = "部门管理")
@ConditionalOnProperty(prefix = "app.module.management",name = "controller",havingValue = "true",matchIfMissing = true)
@ConditionalOnClass(SqlSessionFactoryBean.class)
public class DeptController {
private static Logger logger= LoggerFactory.getLogger(DeptController.class);
@Resource
private DeptService deptService;
@PreAuthorize("hasAuthority(T(com.github.rexsheng.springboot.faster.common.constant.AuthCodeConstant).DEPT_EDIT)" +
" || hasAuthority(T(com.github.rexsheng.springboot.faster.common.constant.AuthCodeConstant).USER_LIST)" +
" || hasAuthority(T(com.github.rexsheng.springboot.faster.common.constant.AuthCodeConstant).USER_ADD)" +
" || hasAuthority(T(com.github.rexsheng.springboot.faster.common.constant.AuthCodeConstant).USER_EDIT)")
@GetMapping("/tree")
@Operation(summary = "查询部门,返回树形结构")
public Result queryDeptTree(){
QueryDeptRequest query=new QueryDeptRequest();
query.setStatus(CommonConstant.STATUS_RUNNING);
query.setExcludeNonParent(true);
return Result.success(deptService.queryList(query));
}
@PreAuthorize("hasAuthority(T(com.github.rexsheng.springboot.faster.common.constant.AuthCodeConstant).DEPT_LIST)")
@GetMapping
@Operation(summary = "查询部门列表")
public Result queryDeptList(@Parameter(name = "deptName",description = "部门名称", in = ParameterIn.QUERY, required = false, schema = @Schema(type = "string", required = false, example = "请输入部门名称"))
@RequestParam(required = false) String deptName){
QueryDeptRequest query=new QueryDeptRequest();
query.setDeptName(deptName);
return Result.success(deptService.queryList(query));
}
@PreAuthorize("hasAuthority(T(com.github.rexsheng.springboot.faster.common.constant.AuthCodeConstant).DEPT_ADD)")
@PostMapping
@RequestLog("新增部门")
@Operation(summary = "新增部门")
public Result addDept(@RequestBody @Validated AddDeptRequest request){
deptService.add(request);
return Result.success();
}
@PreAuthorize("hasAuthority(T(com.github.rexsheng.springboot.faster.common.constant.AuthCodeConstant).DEPT_EDIT)")
@GetMapping("/{id}")
@Operation(summary = "获取单个部门信息")
public Result getDept(@PathVariable Integer id){
return Result.success(deptService.get(id));
}
@PreAuthorize("hasAuthority(T(com.github.rexsheng.springboot.faster.common.constant.AuthCodeConstant).DEPT_EDIT)")
@PutMapping("/{id}")
@RequestLog("修改部门")
@Operation(summary = "修改部门")
public Result updateDept(@PathVariable Integer id, @RequestBody @Validated UpdateDeptRequest request){
request.setDeptId(id);
deptService.update(request);
return Result.success();
}
@PreAuthorize("hasAuthority(T(com.github.rexsheng.springboot.faster.common.constant.AuthCodeConstant).DEPT_EDIT)")
@PutMapping("/{ids}/status/{status}")
@RequestLog("修改部门状态")
@Operation(summary = "修改部门状态")
public Result changeDeptValid(@Parameter(description = "部门ID列表") @PathVariable Integer[] ids,@PathVariable Boolean status){
deptService.updateStatus(UpdateDeptRequest.of(ids,status?CommonConstant.STATUS_RUNNING:CommonConstant.STATUS_STOP));
return Result.success();
}
@PreAuthorize("hasAuthority(T(com.github.rexsheng.springboot.faster.common.constant.AuthCodeConstant).DEPT_DEL)")
@DeleteMapping
@RequestLog("删除部门")
@Operation(summary = "删除部门")
public Result deleteDept(@RequestBody Integer[] ids){
deptService.delete(Arrays.asList(ids));
return Result.success();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy