| | |
| | | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptRespVO; |
| | | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptSaveReqVO; |
| | | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptSimpleRespVO; |
| | | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptImportExcelVO; |
| | | import cn.iocoder.yudao.module.system.controller.admin.dept.vo.dept.DeptImportRespVO; |
| | | import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; |
| | | import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO; |
| | | import cn.iocoder.yudao.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.Parameters; |
| | | 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 org.springframework.web.multipart.MultipartFile; |
| | | import jakarta.servlet.http.HttpServletResponse; |
| | | |
| | | import jakarta.annotation.Resource; |
| | | import jakarta.validation.Valid; |
| | | import java.io.IOException; |
| | | import java.util.Arrays; |
| | | import java.util.List; |
| | | |
| | | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| | |
| | | return success(BeanUtils.toBean(dept, DeptRespVO.class)); |
| | | } |
| | | |
| | | @GetMapping("/get-import-template") |
| | | @Operation(summary = "获得导入部门模板") |
| | | public void importTemplate(HttpServletResponse response) throws IOException { |
| | | List<DeptImportExcelVO> list = Arrays.asList( |
| | | DeptImportExcelVO.builder().name("研发部").parentPath("总公司").sort(1).status(CommonStatusEnum.ENABLE.getStatus()).build(), |
| | | DeptImportExcelVO.builder().name("财务部").parentPath("总公司").sort(2).status(CommonStatusEnum.ENABLE.getStatus()).build() |
| | | ); |
| | | ExcelUtils.write(response, "部门导入模板.xls", "部门列表", DeptImportExcelVO.class, list); |
| | | } |
| | | |
| | | @PostMapping("/import") |
| | | @Operation(summary = "导入部门") |
| | | @Parameters({ |
| | | @Parameter(name = "file", description = "Excel 文件", required = true), |
| | | @Parameter(name = "updateSupport", description = "是否支持更新,默认为 false", example = "true") |
| | | }) |
| | | @PreAuthorize("@ss.hasPermission('system:dept:import')") |
| | | public CommonResult<DeptImportRespVO> importExcel(@RequestParam("file") MultipartFile file, |
| | | @RequestParam(value = "updateSupport", required = false, defaultValue = "false") Boolean updateSupport) throws Exception { |
| | | List<DeptImportExcelVO> list = ExcelUtils.read(file, DeptImportExcelVO.class); |
| | | return success(deptService.importDeptList(list, updateSupport)); |
| | | } |
| | | |
| | | } |