| | |
| | | @GetMapping("/get-import-template") |
| | | @Operation(summary = "获得导入部门模板") |
| | | public void importTemplate(HttpServletResponse response) throws IOException { |
| | | // 示例的上级部门取当前真实根部门,避免照抄 demo 里的「总公司」导致找不到上级 |
| | | List<DeptDO> allDepts = deptService.getDeptList(new DeptListReqVO()); |
| | | String rootPath = allDepts.stream() |
| | | .filter(d -> d.getParentId() == null || d.getParentId() == 0) |
| | | .map(DeptDO::getName) |
| | | .findFirst() |
| | | .orElse("请填写上级部门全路径"); |
| | | |
| | | 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() |
| | | DeptImportExcelVO.builder().name("示例部门A").parentPath(rootPath).sort(1) |
| | | .status(CommonStatusEnum.ENABLE.getStatus()).build(), |
| | | DeptImportExcelVO.builder().name("示例部门B").parentPath(rootPath).sort(2) |
| | | .status(CommonStatusEnum.ENABLE.getStatus()).build() |
| | | ); |
| | | ExcelUtils.write(response, "部门导入模板.xls", "部门列表", DeptImportExcelVO.class, list); |
| | | ExcelUtils.writeTemplate(response, "部门导入模板.xls", "部门列表", DeptImportExcelVO.class, list); |
| | | } |
| | | |
| | | @PostMapping("/import") |