package cn.iocoder.yudao.module.zhuguang.controller.admin.basic_info; import org.springframework.web.bind.annotation.*; import jakarta.annotation.Resource; import org.springframework.validation.annotation.Validated; import org.springframework.security.access.prepost.PreAuthorize; import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Operation; import jakarta.validation.constraints.*; import jakarta.validation.*; import jakarta.servlet.http.*; import java.util.*; import java.io.IOException; import cn.iocoder.yudao.framework.common.pojo.PageParam; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.util.object.BeanUtils; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog; import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*; import cn.iocoder.yudao.module.zhuguang.controller.admin.basic_info.vo.*; import cn.iocoder.yudao.module.zhuguang.dal.dataobject.basic_info.DepartmentDO; import cn.iocoder.yudao.module.zhuguang.dal.dataobject.basic_info.SpecialtyDO; import cn.iocoder.yudao.module.zhuguang.service.basic_info.DepartmentService; @Tag(name = "管理后台 - 系") @RestController @RequestMapping("/zhuguang/department") @Validated public class DepartmentController { @Resource private DepartmentService departmentService; @PostMapping("/create") @Operation(summary = "创建系") @PreAuthorize("@ss.hasPermission('zhuguang:department:create')") public CommonResult createDepartment(@Valid @RequestBody DepartmentSaveReqVO createReqVO) { return success(departmentService.createDepartment(createReqVO)); } @PutMapping("/update") @Operation(summary = "更新系") @PreAuthorize("@ss.hasPermission('zhuguang:department:update')") public CommonResult updateDepartment(@Valid @RequestBody DepartmentSaveReqVO updateReqVO) { departmentService.updateDepartment(updateReqVO); return success(true); } @DeleteMapping("/delete") @Operation(summary = "删除系") @Parameter(name = "id", description = "编号", required = true) @PreAuthorize("@ss.hasPermission('zhuguang:department:delete')") public CommonResult deleteDepartment(@RequestParam("id") Long id) { departmentService.deleteDepartment(id); return success(true); } @GetMapping("/get") @Operation(summary = "获得系") @Parameter(name = "id", description = "编号", required = true, example = "1024") @PreAuthorize("@ss.hasPermission('zhuguang:department:query')") public CommonResult getDepartment(@RequestParam("id") Long id) { DepartmentDO department = departmentService.getDepartment(id); return success(BeanUtils.toBean(department, DepartmentRespVO.class)); } @GetMapping("/page") @Operation(summary = "获得系分页") @PreAuthorize("@ss.hasPermission('zhuguang:department:query')") public CommonResult> getDepartmentPage(@Valid DepartmentPageReqVO pageReqVO) { PageResult pageResult = departmentService.getDepartmentPage(pageReqVO); return success(BeanUtils.toBean(pageResult, DepartmentRespVO.class)); } @GetMapping("/export-excel") @Operation(summary = "导出系 Excel") @PreAuthorize("@ss.hasPermission('zhuguang:department:export')") @ApiAccessLog(operateType = EXPORT) public void exportDepartmentExcel(@Valid DepartmentPageReqVO pageReqVO, HttpServletResponse response) throws IOException { pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE); List list = departmentService.getDepartmentPage(pageReqVO).getList(); // 导出 Excel ExcelUtils.write(response, "系.xls", "数据", DepartmentRespVO.class, BeanUtils.toBean(list, DepartmentRespVO.class)); } // ==================== 子表(专业) ==================== @GetMapping("/specialty/list-by-department-id") @Operation(summary = "获得专业列表") @Parameter(name = "departmentId", description = "系的ID") @PreAuthorize("@ss.hasPermission('zhuguang:department:query')") public CommonResult> getSpecialtyListByDepartmentId(@RequestParam("departmentId") Long departmentId) { return success(departmentService.getSpecialtyListByDepartmentId(departmentId)); } }