xiaoyi
8 天以前 68317d44b233f28150336bbf3aa3a32400552437
yudao-module-hrm/src/main/java/cn/iocoder/yudao/module/hrm/controller/admin/employee/HrmEmployeeController.java
@@ -201,16 +201,28 @@
    @Operation(summary = "下载员工导入模板")
    @PreAuthorize("@ss.hasPermission('hrm:employee:import')")
    public void importTemplate(HttpServletResponse response) throws IOException {
        // 输出示例数据,方便使用者参考
        // 示例的部门/岗位/角色取当前系统真实数据,避免照抄 demo 里的「研发部」导致匹配失败
        String sampleDept = "请填写部门名称";
        try {
            var depts = deptApi.getDeptList();
            if (depts != null && !depts.isEmpty()) {
                sampleDept = depts.get(0).getName();
            }
        } catch (Exception ignored) {
            // 取不到就保留占位文案,不影响模板下载
        }
        // 岗位未提供简易列表 API,示例用占位文案
        String samplePost = "请填写岗位名称(多个用英文逗号分隔)";
        List<HrmEmployeeImportExcelVO> list = Arrays.asList(
                HrmEmployeeImportExcelVO.builder().name("张三").gender(1).phone("13800138000")
                        .deptName("研发部").postName("部门经理,项目经理").roleNames("普通管理员")
                        .deptName(sampleDept).postName(samplePost).roleNames("普通角色")
                        .hireDate(LocalDate.of(2020, 3, 1)).employeeStatus(1)
                        .idCard("320102199001150011").birthday(LocalDate.of(1990, 1, 15))
                        .nation("汉族").marriageStatus("已婚").age(36).education("本科").politicalStatus("中共党员")
                        .email("zhangsan@example.com").build()
                        .email("zhangsan@example.com").remark("示例数据,导入前请替换").build()
        );
        ExcelUtils.write(response, "员工导入模板.xls", "员工列表", HrmEmployeeImportExcelVO.class, list);
        ExcelUtils.writeTemplate(response, "员工导入模板.xls", "员工列表", HrmEmployeeImportExcelVO.class, list);
    }
    @PostMapping("/import")