diff --git a/SimpleAdmin.Application/Services/Onboarding/Audit/OnboardingAuditService.cs b/SimpleAdmin.Application/Services/Onboarding/Audit/OnboardingAuditService.cs index 2db0711..68a4909 100644 --- a/SimpleAdmin.Application/Services/Onboarding/Audit/OnboardingAuditService.cs +++ b/SimpleAdmin.Application/Services/Onboarding/Audit/OnboardingAuditService.cs @@ -58,6 +58,22 @@ public class OnboardingAuditService : IOnboardingAuditService var contractStartDate = await ResolveContractStartDate(task.Id); var employee = employeeInfo.Adapt(); + if (string.IsNullOrWhiteSpace(employee.EmployeeNo)) + { + var taskContractIds = await _db.Queryable() + .Where(item => item.TaskId == task.Id) + .Select(item => item.Id) + .ToListAsync(); + + if (taskContractIds.Count > 0) + { + employee.EmployeeNo = await _db.Queryable() + .Where(item => taskContractIds.Contains(item.TaskContractId) && item.VariableCode == "hr.EmployeeNo" && item.VariableValue != null && item.VariableValue != "") + .OrderBy(item => item.SortCode) + .Select(item => item.VariableValue) + .FirstAsync(); + } + } employee.Id = global::SimpleAdmin.Core.Utils.CommonUtils.GetSingleId(); employee.CompanyId = task.CompanyId; employee.DepartmentId = task.DepartmentId; diff --git a/SimpleAdmin.Application/Services/Onboarding/Employee/OnboardingEmployeeService.cs b/SimpleAdmin.Application/Services/Onboarding/Employee/OnboardingEmployeeService.cs index ea2e11f..fc50873 100644 --- a/SimpleAdmin.Application/Services/Onboarding/Employee/OnboardingEmployeeService.cs +++ b/SimpleAdmin.Application/Services/Onboarding/Employee/OnboardingEmployeeService.cs @@ -167,6 +167,40 @@ public class OnboardingEmployeeService : IOnboardingEmployeeService .OrderBy(item => item.CreateTime) .OrderBy(item => item.Id) .ToListAsync(); + + if (string.IsNullOrWhiteSpace(employee.EmployeeNo)) + { + var snapshotEmployeeNo = contractSnapshots + .Select(item => item.EmployeeNo) + .FirstOrDefault(val => !string.IsNullOrWhiteSpace(val)); + + if (string.IsNullOrWhiteSpace(snapshotEmployeeNo)) + { + snapshotEmployeeNo = contractSnapshots + .Select(item => ExtractEmployeeNoFromVariables(item.VariablesJson)) + .FirstOrDefault(val => !string.IsNullOrWhiteSpace(val)); + } + + if (string.IsNullOrWhiteSpace(snapshotEmployeeNo) && contracts.Count > 0) + { + var contractIds = contracts.Select(c => c.Id).ToList(); + snapshotEmployeeNo = await _db.Queryable() + .Where(item => contractIds.Contains(item.TaskContractId) && item.VariableCode == "hr.EmployeeNo" && item.VariableValue != null && item.VariableValue != "") + .OrderBy(item => item.SortCode) + .Select(item => item.VariableValue) + .FirstAsync(); + } + + if (!string.IsNullOrWhiteSpace(snapshotEmployeeNo)) + { + employee.EmployeeNo = snapshotEmployeeNo; + await _db.Updateable() + .SetColumns(item => new ObEmployee { EmployeeNo = snapshotEmployeeNo }) + .Where(item => item.Id == employee.Id && (item.EmployeeNo == null || item.EmployeeNo == "")) + .ExecuteCommandAsync(); + } + } + var materials = await GetEmployeeMaterials(task?.Id); var electronicSignProcess = task == null ? null @@ -858,7 +892,9 @@ public class OnboardingEmployeeService : IOnboardingEmployeeService if (value != null) cell.Value = value; - var templateNumberFormat = worksheet.Cells[1, templateColumn.Index] + // 表头可能因复制粘贴带有日期等显示格式;数据格式应读取模板数据行, + // 未配置时再使用字段类型定义的默认格式,避免薪资数值显示成日期。 + var templateNumberFormat = worksheet.Cells[2, templateColumn.Index] .Style.Numberformat.Format; cell.Style.Numberformat.Format = string.IsNullOrWhiteSpace(templateNumberFormat) || string.Equals( @@ -1113,6 +1149,43 @@ public class OnboardingEmployeeService : IOnboardingEmployeeService } } + private static string ExtractEmployeeNoFromVariables(string variablesJson) + { + if (string.IsNullOrWhiteSpace(variablesJson)) + return null; + + try + { + using var doc = global::System.Text.Json.JsonDocument.Parse(variablesJson); + var root = doc.RootElement; + if (root.ValueKind == global::System.Text.Json.JsonValueKind.Object) + { + foreach (var prop in root.EnumerateObject()) + { + if (string.Equals(prop.Name, "hr.EmployeeNo", StringComparison.OrdinalIgnoreCase)) + { + if (prop.Value.ValueKind == global::System.Text.Json.JsonValueKind.Object + && prop.Value.TryGetProperty("variableValue", out var valProp) + && valProp.ValueKind == global::System.Text.Json.JsonValueKind.String) + { + return valProp.GetString(); + } + if (prop.Value.ValueKind == global::System.Text.Json.JsonValueKind.String) + { + return prop.Value.GetString(); + } + } + } + } + } + catch + { + // 忽略异常 JSON + } + + return null; + } + private static DateTime? ParseDate(string value) { return DateTime.TryParse(value, out var date) ? date.Date : null; diff --git a/SimpleAdmin.Web.Core/Upload/员工导出模版.xlsx b/SimpleAdmin.Web.Core/Upload/员工导出模版.xlsx index 08b352c..ef16bc6 100644 Binary files a/SimpleAdmin.Web.Core/Upload/员工导出模版.xlsx and b/SimpleAdmin.Web.Core/Upload/员工导出模版.xlsx differ