package com.iailab.module.system.controller.admin.dept; import com.iailab.framework.common.enums.CommonStatusEnum; import com.iailab.framework.common.pojo.CommonResult; import com.iailab.framework.common.util.object.BeanUtils; import com.iailab.module.system.controller.admin.dept.vo.dept.DeptListReqVO; import com.iailab.module.system.controller.admin.dept.vo.dept.DeptRespVO; import com.iailab.module.system.controller.admin.dept.vo.dept.DeptSaveReqVO; import com.iailab.module.system.controller.admin.dept.vo.dept.DeptSimpleRespVO; import com.iailab.module.system.dal.dataobject.dept.DeptDO; import com.iailab.module.system.service.dept.DeptService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.validation.Valid; import java.util.List; import static com.iailab.framework.common.pojo.CommonResult.success; @Tag(name = "管理后台 - 部门") @RestController @RequestMapping("/system/dept") @Validated public class DeptController { @Resource private DeptService deptService; @PostMapping("create") @Operation(summary = "创建部门") @PreAuthorize("@ss.hasPermission('system:dept:create')") public CommonResult createDept(@Valid @RequestBody DeptSaveReqVO createReqVO) { Long deptId = deptService.createDept(createReqVO); return success(deptId); } @PutMapping("update") @Operation(summary = "更新部门") @PreAuthorize("@ss.hasPermission('system:dept:update')") public CommonResult updateDept(@Valid @RequestBody DeptSaveReqVO updateReqVO) { deptService.updateDept(updateReqVO); return success(true); } @DeleteMapping("delete") @Operation(summary = "删除部门") @Parameter(name = "id", description = "编号", required = true, example = "1024") @PreAuthorize("@ss.hasPermission('system:dept:delete')") public CommonResult deleteDept(@RequestParam("id") Long id) { deptService.deleteDept(id); return success(true); } @GetMapping("/list") @Operation(summary = "获取部门列表") @PreAuthorize("@ss.hasPermission('system:dept:query')") public CommonResult> getDeptList(DeptListReqVO reqVO) { List list = deptService.getDeptList(reqVO); return success(BeanUtils.toBean(list, DeptRespVO.class)); } @GetMapping(value = {"/list-all-simple", "/simple-list"}) @Operation(summary = "获取部门精简信息列表", description = "只包含被开启的部门,主要用于前端的下拉选项") public CommonResult> getSimpleDeptList() { List list = deptService.getDeptList( new DeptListReqVO().setStatus(CommonStatusEnum.ENABLE.getStatus())); return success(BeanUtils.toBean(list, DeptSimpleRespVO.class)); } @GetMapping("/get") @Operation(summary = "获得部门信息") @Parameter(name = "id", description = "编号", required = true, example = "1024") @PreAuthorize("@ss.hasPermission('system:dept:query')") public CommonResult getDept(@RequestParam("id") Long id) { DeptDO dept = deptService.getDept(id); return success(BeanUtils.toBean(dept, DeptRespVO.class)); } }