| | |
| | | if (StrUtil.isBlank(importEmployee.getPhone())) { |
| | | throw exception(EMPLOYEE_IMPORT_FIELD_REQUIRED, "手机号"); |
| | | } |
| | | if (importEmployee.getHireDate() == null) { |
| | | throw exception(EMPLOYEE_IMPORT_FIELD_REQUIRED, "入职日期"); |
| | | LocalDate hireDate = parseImportDate(importEmployee.getHireDate()); |
| | | if (hireDate == null) { |
| | | throw exception(EMPLOYEE_IMPORT_FIELD_REQUIRED, "入职日期(格式:2015 或 2015-01-01)"); |
| | | } |
| | | HrmEmployeeSaveReqVO reqVO = new HrmEmployeeSaveReqVO(); |
| | | reqVO.setName(importEmployee.getName()); |
| | |
| | | reqVO.setDeptId(deptId); |
| | | reqVO.setPostIds(CollUtil.isEmpty(postIds) ? null : new ArrayList<>(postIds)); |
| | | reqVO.setRoleIds(CollUtil.isEmpty(roleIds) ? null : new ArrayList<>(roleIds)); |
| | | reqVO.setHireDate(importEmployee.getHireDate()); |
| | | reqVO.setHireDate(hireDate); |
| | | reqVO.setEmployeeStatus(importEmployee.getEmployeeStatus() != null |
| | | ? importEmployee.getEmployeeStatus() : 1); // 默认在职 |
| | | reqVO.setEmail(importEmployee.getEmail()); |
| | | reqVO.setBirthday(importEmployee.getBirthday()); |
| | | reqVO.setBirthday(parseImportDate(importEmployee.getBirthday())); |
| | | reqVO.setIdCard(importEmployee.getIdCard()); |
| | | reqVO.setNation(importEmployee.getNation()); |
| | | reqVO.setMarriageStatus(importEmployee.getMarriageStatus()); |
| | |
| | | return roleIds; |
| | | } |
| | | |
| | | /** |
| | | * 容错解析导入日期文本,支持:2015 / 2015年 / 2015-01 / 2015-01-02 / 2015/1/2 / 2015.1.2 / |
| | | * 2015-01-02 00:00:00 / 20150102,以及 Excel 日期序列号;解析不出返回 null。 |
| | | */ |
| | | private static LocalDate parseImportDate(String raw) { |
| | | if (StrUtil.isBlank(raw)) { |
| | | return null; |
| | | } |
| | | String s = raw.trim(); |
| | | // 去掉时间部分 |
| | | int sp = s.indexOf(' '); |
| | | if (sp > 0) { |
| | | s = s.substring(0, sp); |
| | | } |
| | | // 中文年月日 / 斜杠 / 点 / 下划线 统一成 - 分隔 |
| | | s = s.replace("年", "-").replace("月", "-").replace("日", "") |
| | | .replace("/", "-").replace(".", "-").replace("_", "-").trim(); |
| | | s = s.replaceAll("^-+|-+$", ""); |
| | | if (StrUtil.isBlank(s)) { |
| | | return null; |
| | | } |
| | | try { |
| | | if (s.matches("\\d+")) { |
| | | int len = s.length(); |
| | | if (len == 4) { // 2015 |
| | | return LocalDate.of(Integer.parseInt(s), 1, 1); |
| | | } |
| | | if (len == 5) { // Excel 日期序列号(1900 日期系统,基准 1899-12-30) |
| | | return LocalDate.of(1899, 12, 30).plusDays(Long.parseLong(s)); |
| | | } |
| | | if (len == 6) { // 201506 |
| | | return LocalDate.of(Integer.parseInt(s.substring(0, 4)), Integer.parseInt(s.substring(4, 6)), 1); |
| | | } |
| | | if (len == 8) { // 20150601 |
| | | return LocalDate.of(Integer.parseInt(s.substring(0, 4)), Integer.parseInt(s.substring(4, 6)), Integer.parseInt(s.substring(6, 8))); |
| | | } |
| | | return null; |
| | | } |
| | | String[] parts = s.split("-"); |
| | | if (parts.length == 2) { // 2015-06 |
| | | return LocalDate.of(Integer.parseInt(parts[0]), Integer.parseInt(parts[1]), 1); |
| | | } |
| | | if (parts.length >= 3) { // 2015-06-01 |
| | | return LocalDate.of(Integer.parseInt(parts[0]), Integer.parseInt(parts[1]), Integer.parseInt(parts[2])); |
| | | } |
| | | } catch (Exception e) { |
| | | return null; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | // ========== 转正 ========== |
| | | |
| | | @Override |