using System; using NCC.Extend.Entitys.Dto.LqAttendanceSummary; using NCC.Extend.Entitys.Enum; using NCC.Extend.Entitys.lq_attendance_summary; using Newtonsoft.Json; namespace NCC.Extend { /// /// 考勤汇总员工确认状态与快照 /// public static class AttendanceSummaryConfirmHelper { public const string SignedPolicyOverwrite = "overwrite"; public const string SignedPolicyIgnore = "ignore"; public static bool IsSigned(int? status) { return status == (int)AttendanceSummaryConfirmStatusEnum.已签字确认; } public static bool IsSigned(LqAttendanceSummaryEntity entity) { return entity != null && IsSigned(entity.ConfirmStatus); } public static string StatusName(int? status) { if (status == (int)AttendanceSummaryConfirmStatusEnum.已发送待确认) { return "待确认"; } if (status == (int)AttendanceSummaryConfirmStatusEnum.已签字确认) { return "已确认"; } return "未发送"; } public static void ResetToUnsent(LqAttendanceSummaryEntity entity) { if (entity == null) { return; } entity.ConfirmStatus = (int)AttendanceSummaryConfirmStatusEnum.未发送; entity.SendTime = null; entity.SendUserId = null; entity.SendUserName = null; entity.ConfirmTime = null; entity.SignatureImage = null; entity.ConfirmSnapshotJson = null; } public static DateTime? ResolveDeadline(DateTime? sendTime) { return sendTime.HasValue ? sendTime.Value.Date.AddDays(1) : (DateTime?)null; } public static bool IsExpired(DateTime? sendTime, int confirmStatus, DateTime now) { var deadline = ResolveDeadline(sendTime); return confirmStatus == (int)AttendanceSummaryConfirmStatusEnum.已发送待确认 && deadline.HasValue && now >= deadline.Value; } public static void FillDeadline(LqAttendanceSummaryListOutput item, DateTime now) { if (item == null) { return; } item.confirmDeadline = ResolveDeadline(item.sendTime); item.confirmExpired = IsExpired(item.sendTime, item.confirmStatus, now); } public static AttendanceSummaryConfirmSnapshot FromListItem(LqAttendanceSummaryListOutput item) { if (item == null) { return new AttendanceSummaryConfirmSnapshot(); } return new AttendanceSummaryConfirmSnapshot { userName = item.userName, organizeName = item.organizeName, year = item.year, month = item.month, attendanceGroupDisplay = item.attendanceGroupDisplay, expectedAttendanceDays = item.expectedAttendanceDays, actualAttendanceDays = item.actualAttendanceDays, workDays = item.workDays, leaveDays = item.leaveDays, restDays = item.restDays, monthEntitledRestDays = item.monthEntitledRestDays, monthOnDutyDays = item.monthOnDutyDays, monthCompositeWorkDays = item.monthCompositeWorkDays, monthPaidLeaveDays = item.monthPaidLeaveDays, monthLeaveDaysTotal = item.monthLeaveDaysTotal, monthLateEarlyDays = item.monthLateEarlyDays, monthAbsenteeismDays = item.monthAbsenteeismDays, monthSupplementDays = item.monthSupplementDays, monthSupplementCount = item.monthSupplementCount, monthBlockingSupplementDays = item.monthBlockingSupplementDays, monthIsFullAttendance = item.monthIsFullAttendance, monthLateDeductionAmount = item.monthLateDeductionAmount, monthLeaveDeductionAmount = item.monthLeaveDeductionAmount, monthAbsenteeismDeductionAmount = item.monthAbsenteeismDeductionAmount, monthMissingCardCount = item.monthMissingCardCount, monthMissingCardDeductionAmount = item.monthMissingCardDeductionAmount, monthSupplementDeductionAmount = item.monthSupplementDeductionAmount, monthPunchApplyDeductionAmount = item.monthPunchApplyDeductionAmount, abnormalDays = item.abnormalDays, lateCount = item.lateCount, lateMinutes = item.lateMinutes, earlyLeaveCount = item.earlyLeaveCount, earlyLeaveMinutes = item.earlyLeaveMinutes, personalLeaveDays = item.personalLeaveDays, sickLeaveDays = item.sickLeaveDays, annualLeaveDays = item.annualLeaveDays, marriageLeaveDays = item.marriageLeaveDays, funeralLeaveDays = item.funeralLeaveDays, welfareLeaveDays = item.welfareLeaveDays, paidVacationDays = item.paidVacationDays, cumulativeRestDays = item.cumulativeRestDays }; } public static void ApplySnapshot(LqAttendanceSummaryListOutput item, string snapshotJson) { if (item == null || string.IsNullOrWhiteSpace(snapshotJson)) { return; } try { var snap = JsonConvert.DeserializeObject(snapshotJson); if (snap == null) { return; } if (!string.IsNullOrWhiteSpace(snap.userName)) item.userName = snap.userName; if (!string.IsNullOrWhiteSpace(snap.organizeName)) item.organizeName = snap.organizeName; if (!string.IsNullOrWhiteSpace(snap.attendanceGroupDisplay)) { item.attendanceGroupDisplay = snap.attendanceGroupDisplay; } item.expectedAttendanceDays = snap.expectedAttendanceDays; item.actualAttendanceDays = snap.actualAttendanceDays; item.workDays = snap.workDays; item.leaveDays = snap.leaveDays; item.restDays = snap.restDays; item.monthEntitledRestDays = snap.monthEntitledRestDays; item.monthOnDutyDays = snap.monthOnDutyDays; item.monthCompositeWorkDays = snap.monthCompositeWorkDays; item.monthPaidLeaveDays = snap.monthPaidLeaveDays; item.monthLeaveDaysTotal = snap.monthLeaveDaysTotal; item.monthLateEarlyDays = snap.monthLateEarlyDays; item.monthAbsenteeismDays = snap.monthAbsenteeismDays; item.monthSupplementDays = snap.monthSupplementDays; item.monthSupplementCount = snap.monthSupplementCount; item.monthBlockingSupplementDays = snap.monthBlockingSupplementDays; item.monthIsFullAttendance = snap.monthIsFullAttendance; item.monthLateDeductionAmount = snap.monthLateDeductionAmount; item.monthLeaveDeductionAmount = snap.monthLeaveDeductionAmount; item.monthAbsenteeismDeductionAmount = snap.monthAbsenteeismDeductionAmount; item.monthMissingCardCount = snap.monthMissingCardCount; item.monthMissingCardDeductionAmount = snap.monthMissingCardDeductionAmount; item.monthSupplementDeductionAmount = snap.monthSupplementDeductionAmount; item.monthPunchApplyDeductionAmount = snap.monthPunchApplyDeductionAmount; item.abnormalDays = snap.abnormalDays; item.lateCount = snap.lateCount; item.lateMinutes = snap.lateMinutes; item.earlyLeaveCount = snap.earlyLeaveCount; item.earlyLeaveMinutes = snap.earlyLeaveMinutes; item.personalLeaveDays = snap.personalLeaveDays; item.sickLeaveDays = snap.sickLeaveDays; item.annualLeaveDays = snap.annualLeaveDays; item.marriageLeaveDays = snap.marriageLeaveDays; item.funeralLeaveDays = snap.funeralLeaveDays; item.welfareLeaveDays = snap.welfareLeaveDays; item.paidVacationDays = snap.paidVacationDays; item.cumulativeRestDays = snap.cumulativeRestDays; if (item.cumulativeRestDays == 0m) { item.cumulativeRestDays = AttendanceSummaryMonthMetricsHelper.CalcCumulativeRestDays( snap.paidVacationDays, snap.personalLeaveDays, snap.sickLeaveDays, snap.welfareLeaveDays, snap.annualLeaveDays, snap.marriageLeaveDays, snap.funeralLeaveDays); } } catch (JsonException) { } } } }