using System.Collections.Generic; using System.Linq; using NCC.Extend.Entitys.lq_attendance_record; namespace NCC.Extend { /// /// 按自然月从打卡记录中的考勤组名称快照生成展示文案(多月多组按首次出现日期用 → 连接)。 /// public static class AttendanceMonthGroupDisplayHelper { /// /// 根据当月有效打卡记录中的 F_AttendanceGroupName 聚合展示;无任何快照时使用主档分组名称;仍无则「无」。 /// /// 该员工该自然月内的打卡记录(通常已为有效记录) /// 员工主档当前绑定的考勤组名称(兜底) public static string BuildDisplay( IEnumerable monthRecords, string profileAttendanceGroupName) { var list = monthRecords == null ? new List() : monthRecords.Where(r => r != null).ToList(); var orderedNames = list .Where(r => !string.IsNullOrWhiteSpace(r.AttendanceGroupName)) .Select(r => new { Name = r.AttendanceGroupName.Trim(), Date = r.AttendanceDate.Date }) .GroupBy(x => x.Name) .Select(g => new { Name = g.Key, FirstDate = g.Min(x => x.Date) }) .OrderBy(x => x.FirstDate) .Select(x => x.Name) .ToList(); if (orderedNames.Count == 0) { return string.IsNullOrWhiteSpace(profileAttendanceGroupName) ? "无" : profileAttendanceGroupName.Trim(); } return orderedNames.Count == 1 ? orderedNames[0] : string.Join("→", orderedNames); } } }