/// <summary> /// 更新刷卡时间1 /// </summary> /// <param name="currentAttendData"></param> /// <param name="slodCardTime"></param> /// <param name="cardtime"></param> /// <returns></returns> private int UpdateSlotCardTime1(AttendSlodFingerDataCurrentMonthModel currentAttendData, DateTime slodCardTime, string cardtime) { var ctimes = cardtime.Split(',').ToList(); if (ctimes.Count >= 2) { ctimes.Sort(); string cardTimeStr = currentAttendData.AttendanceDate.ToDateStr() + " " + ctimes[ctimes.Count - 1]; return(irep.Update(f => f.Id_Key == currentAttendData.Id_Key, u => new AttendSlodFingerDataCurrentMonthModel { //重新调整刷卡时间2 //SlotCardTime1 = ctimes[0], SlotCardTime2 = cardTimeStr, SlotCardTime = currentAttendData.SlotCardTime == null || currentAttendData.SlotCardTime.Length == 0 ? slodCardTime.ToString("HH:mm") : cardtime, })); } else { return(irep.Update(f => f.Id_Key == currentAttendData.Id_Key, u => new AttendSlodFingerDataCurrentMonthModel { //刷卡时间1若有就不进行更新,反之则进行更新 SlotCardTime1 = currentAttendData.SlotCardTime1 == null || currentAttendData.SlotCardTime1.Length == 0 ? slodCardTime.ToString("yyyy-MM-dd HH:mm") : currentAttendData.SlotCardTime1, SlotCardTime = currentAttendData.SlotCardTime == null || currentAttendData.SlotCardTime.Length == 0 ? slodCardTime.ToString("HH:mm") : cardtime, })); } }
/// <summary> /// 更新刷卡时间2 /// </summary> /// <param name="currentAttendData"></param> /// <param name="slodCardTime"></param> /// <param name="cardtime"></param> /// <returns></returns> private int UpdateSlotCardTime2(AttendSlodFingerDataCurrentMonthModel currentAttendData, DateTime slodCardTime, string cardtime) { return(irep.Update(f => f.Id_Key == currentAttendData.Id_Key, u => new AttendSlodFingerDataCurrentMonthModel { //直接进行更新替代 SlotCardTime2 = slodCardTime.ToString("yyyy-MM-dd HH:mm"), SlotCardTime = currentAttendData.SlotCardTime == null || currentAttendData.SlotCardTime.Length == 0 ? slodCardTime.ToString("HH:mm") : cardtime })); }
/// <summary> /// 关于异常的旷工或者迟到处理 /// </summary> /// <param name="record"></param> /// <param name="e"></param> /// <returns></returns> private int HandleAbsentAboutException(int record, AttendSlodFingerDataCurrentMonthModel e) { record += this.irep.Update(w => w.WorkerId == e.WorkerId && w.AttendanceDate == e.AttendanceDate, u => new AttendSlodFingerDataCurrentMonthModel { SlotExceptionMark = 1, SlotExceptionMemo = e.SlotExceptionMemo, HandleSlotExceptionStatus = e.HandleSlotExceptionStatus }); return(record); }
/// <summary> /// 关于异常的漏刷卡处理 /// </summary> /// <param name="record"></param> /// <param name="e"></param> /// <returns></returns> private int HandleForgetSlotAboutException(int record, AttendSlodFingerDataCurrentMonthModel e) { record += this.irep.Update(w => w.WorkerId == e.WorkerId && w.AttendanceDate == e.AttendanceDate, u => new AttendSlodFingerDataCurrentMonthModel { SlotCardTime1 = e.SlotCardTime1, SlotCardTime2 = e.SlotCardTime2, SlotCardTime = e.SlotCardTime, SlotExceptionMark = 1, SlotExceptionMemo = e.SlotExceptionMemo, ForgetSlotReason = e.ForgetSlotReason, HandleSlotExceptionStatus = e.HandleSlotExceptionStatus }); return(record); }
/// <summary> /// 分析处理白天数据 /// </summary> /// <param name="slotExceptionType"></param> /// <param name="currentTime"></param> /// <param name="dayAmstart"></param> /// <param name="dayAmend"></param> private void AnalogDayAttendData(AttendSlodFingerDataCurrentMonthModel attendSd, ref string slotExceptionType, DateTime currentTime, DateTime dayAmstart, DateTime dayAmend) { if (currentTime > dayAmstart && currentTime < dayAmend) { MergeSlotExceptionType(ref slotExceptionType, "迟到"); } else if (currentTime > dayAmend) { //先判定是否有请假状况 if (attendSd.LeaveMark == 0) { MergeSlotExceptionType(ref slotExceptionType, "旷工"); } } }
/// <summary> /// 关于异常的请假处理 /// </summary> /// <param name="record"></param> /// <param name="e"></param> /// <returns></returns> private int HandleAskLeaveAboutException(int record, AttendSlodFingerDataCurrentMonthModel e) { record += this.irep.Update(w => w.WorkerId == e.WorkerId && w.AttendanceDate == e.AttendanceDate, u => new AttendSlodFingerDataCurrentMonthModel { LeaveHours = e.LeaveHours, LeaveMark = e.LeaveHours < 0.01 ? 0 : 1, LeaveType = e.LeaveType, LeaveTimeRegion = e.LeaveTimeRegion, LeaveDescription = "请假处理,假别:" + e.LeaveType, LeaveMemo = e.LeaveMemo, SlotExceptionMark = 1, SlotExceptionMemo = e.SlotExceptionMemo, HandleSlotExceptionStatus = e.HandleSlotExceptionStatus }); return(record); }
/// <summary> /// 合并考勤时间 /// </summary> /// <param name="currentAttendData"></param> /// <param name="slodCardTime"></param> /// <returns></returns> private int MergeAttendTime(AttendSlodFingerDataCurrentMonthModel currentAttendData, DateTime slodCardTime) { int record = 0; //若请假流程在前,则会先有考勤数据记录,但没有考勤时间,所以从刷卡时间1开始填写 currentAttendData.SlotCardTime = ConcatSlotCardTime(currentAttendData.SlotCardTime, slodCardTime); if (currentAttendData.SlotCardTime1 == null || currentAttendData.SlotCardTime1.Length == 0) { record = UpdateSlotCardTime1(currentAttendData, slodCardTime, currentAttendData.SlotCardTime); } else { record = UpdateSlotCardTime2(currentAttendData, slodCardTime, currentAttendData.SlotCardTime); } return(record); }
/// <summary> /// 分析刷卡时间 /// </summary> /// <param name="slotExceptionType"></param> /// <param name="classType"></param> /// <param name="day"></param> /// <param name="year"></param> /// <param name="month"></param> /// <param name="slotCardTime"></param> private void AnalogSlotCardTime(AttendSlodFingerDataCurrentMonthModel attendSd, ref string slotExceptionType, string classType, int day, int year, int month, string slotCardTime) { string exceptionType = slotExceptionType; //分析时间 string[] slotTimes = slotCardTime.Split(','); if (slotTimes != null && slotTimes.Length > 0) { if (slotTimes.Length > 3)//有三次以上刷卡记录,不做处理 { //MergeSlotExceptionType(ref slotExceptionType, "多次刷卡"); } slotTimes.ToList().ForEach(st => { string[] ttimes = st.Split(':'); if (ttimes != null && ttimes.Length == 2)//分析刷卡具体时间 { int h = ttimes[0].ToInt(); int m = ttimes[1].ToInt(); //组合当前刷卡时间 DateTime currentTime = new DateTime(year, month, day, h, m, 0); //白班迟到时间区间7:51--7:55 DateTime dayAmstand = new DateTime(year, month, day, 7, 50, 0);//上班时间 DateTime dayAmstart = new DateTime(year, month, day, 7, 51, 0); DateTime dayAmend = new DateTime(year, month, day, 7, 55, 0); //晚班迟到时间区间19:51--19:55 DateTime dayPmstart = new DateTime(year, month, day, 19, 51, 0); DateTime dayPmend = new DateTime(year, month, day, 19, 55, 0); DateTime dayPmstand = new DateTime(year, month, day, 19, 50, 0); if (classType == "白班") { AnalogDayAttendData(attendSd, ref exceptionType, currentTime, dayAmstart, dayAmend); } else if (classType == "晚班") { AnalogNightAttendData(attendSd, ref exceptionType, currentTime, dayPmstart, dayPmend); } } }); } slotExceptionType = exceptionType; }
private AttendSlodFingerDataCurrentMonthModel CreateAttendDataModel(AttendFingerPrintDataInTimeModel attendTimeMdl, ArWorkerInfo worker, DateTime slodCardTime) { var mdl = new AttendSlodFingerDataCurrentMonthModel() { AttendanceDate = attendTimeMdl.SlodCardDate, WorkerId = worker.WorkerId, CardID = attendTimeMdl.CardID, CardType = attendTimeMdl.CardType, ClassType = worker.ClassType, Department = worker.Department, WorkerName = worker.Name, WeekDay = attendTimeMdl.SlodCardDate.DayOfWeek.ToString().ToChineseWeekDay(), LeaveHours = 0, LeaveMark = 0, YearMonth = slodCardTime.ToString("yyyyMM"), SlotCardTime = slodCardTime.ToString("HH:mm"), HandleSlotExceptionStatus = 0, SlotExceptionMark = 0, OpSign = "init", OpPerson = "system", }; return(mdl); }
/// <summary> /// 返回有异常的数据 /// </summary> public List <AttendSlodFingerDataCurrentMonthModel> AutoHandleExceptionSlotData(string yearMonth) { List <AttendSlodFingerDataCurrentMonthModel> attendExceptionSlodDatas = new List <AttendSlodFingerDataCurrentMonthModel>(); string[] dfields = yearMonth.Split('-'); if (dfields.Length != 2) { return(attendExceptionSlodDatas); } int qurYear = dfields[0].Trim().ToInt(), qurMonth = dfields[1].Trim().ToInt(); //考勤数据中没有处理过异常的数据集 List <AttendSlodFingerDataCurrentMonthModel> attendSlotDatas = this.irep.Entities.Where(e => e.HandleSlotExceptionStatus == 0 && e.YearMonth == yearMonth).ToList(); if (attendSlotDatas == null || attendSlotDatas.Count == 0) { return(attendExceptionSlodDatas); } //本月考勤中所有员工列表 List <AttendSlodWorkerModel> attendSlodWorkers = this.GetAttendSlodWorkers(qurYear, qurMonth); AttendClassTypeSetter classTypeSetter = new AttendClassTypeSetter(); //获取本月份的日期天数 int daysInMonths = DateTime.DaysInMonth(qurYear, qurMonth); Dictionary <string, string> dicClassTypes = new Dictionary <string, string>(); //一天的中间时间 DateTime dayMiddleTime; DateTime currentDay; string workerId; //工号 string classType; //班别 string slotExceptionType = string.Empty; //刷卡异常类别 AttendClassTypeDetailModel ctdMdl = null; //每个人考勤数据 List <AttendSlodFingerDataCurrentMonthModel> attendSlotDatasOfWorker = null; AttendSlodFingerDataCurrentMonthModel attendSd = null; attendSlodWorkers.ForEach(worker => { attendSlotDatasOfWorker = attendSlotDatas.Where(m => m.WorkerId == worker.WorkerId).ToList(); while (worker.AttendDateStart <= worker.AttendDateEnd) { currentDay = worker.AttendDateStart; //每天的考勤数据 attendSd = attendSlotDatasOfWorker.FirstOrDefault(d => d.AttendanceDate == currentDay); if (attendSd == null)//如果不存在考勤数据 { //初始化该日期的考勤数据 ctdMdl = classTypeSetter.GetClassTypeDetailModel(attendSd.WorkerId, attendSd.AttendanceDate); var mdl = new AttendSlodFingerDataCurrentMonthModel() { AttendanceDate = currentDay, WorkerId = worker.WorkerId, CardID = "", CardType = "", ClassType = ctdMdl == null ? "白班" : ctdMdl.ClassType, Department = worker.Department, WorkerName = worker.WorkerName, WeekDay = currentDay.DayOfWeek.ToString().ToChineseWeekDay(), LeaveHours = 0, LeaveMark = 0, YearMonth = currentDay.ToString("yyyyMM"), SlotCardTime = currentDay.ToString("HH:mm"), HandleSlotExceptionStatus = 0, SlotExceptionMark = 0, OpSign = "init", OpPerson = "system", }; this.irep.Insert(mdl); } else { //存在的话则进行检测处理 workerId = attendSd.WorkerId; //刷卡异常类型 slotExceptionType = string.Empty; classType = attendSd.ClassType; //时间点 int hour = classType == "白班" ? 12 : 24; int day = attendSd.AttendanceDate.Day; int year = attendSd.AttendanceDate.Year; int month = attendSd.AttendanceDate.Month; //中间时间 dayMiddleTime = new DateTime(year, month, day, hour, 0, 0); string slotCardTime = attendSd.SlotCardTime;//刷卡时间 if (slotCardTime == null || slotCardTime.Length < 5) { if (attendSd.LeaveMark == 0) //如果有请假的话,则不做旷工标志处理 { MergeSlotExceptionType(ref slotExceptionType, "旷工"); //标志异常考勤信息为旷工 } } else { if (attendSd.SlotCardTime1 == null || attendSd.SlotCardTime2 == null)//刷卡时间不完整的情况分析 { if (attendSd.LeaveMark == 0) { MergeSlotExceptionType(ref slotExceptionType, "漏刷卡"); } else { MergeSlotExceptionType(ref slotExceptionType, "请假漏刷"); } } //继续分析刷卡时间都全面的情况 else { //在都完整的情况下,分析考勤异常情况 AnalogSlotCardTime(attendSd, ref slotExceptionType, classType, day, year, month, slotCardTime); } } attendSd.SlotExceptionType = slotExceptionType; attendSd.SlotExceptionMark = slotExceptionType != null && slotExceptionType.Length >= 2 ? 1 : 0; attendSd.HandleSlotExceptionStatus = attendSd.SlotExceptionMark == 1 ? 1 : -1; //若有异常,则状态为1,没有异常则状态为-1代表已经检测过 //同步到数据库中 this.irep.Update(f => f.WorkerId == attendSd.WorkerId && f.AttendanceDate == attendSd.AttendanceDate, u => new AttendSlodFingerDataCurrentMonthModel { HandleSlotExceptionStatus = attendSd.HandleSlotExceptionStatus, SlotExceptionType = slotExceptionType, SlotExceptionMark = attendSd.SlotExceptionMark }); } //日期递增 worker.AttendDateStart = worker.AttendDateStart.AddDays(1); } }); attendExceptionSlodDatas = attendSlotDatas.Where(e => e.HandleSlotExceptionStatus == 1).OrderBy(o => o.AttendanceDate).ToList(); return(attendExceptionSlodDatas); }
/// <summary> /// 初次插入数据 /// </summary> /// <param name="attendTimeMdl"></param> /// <param name="worker"></param> /// <param name="slodCardTime"></param> /// <returns></returns> private int InitAttendData(AttendFingerPrintDataInTimeModel attendTimeMdl, ArWorkerInfo worker, DateTime slodCardTime, out AttendSlodFingerDataCurrentMonthModel initMdl, DateTime middleTime) { initMdl = null; int record = 0; var mdl = CreateAttendDataModel(attendTimeMdl, worker, slodCardTime); //首次赋值需要加中间判定时间 if (slodCardTime > middleTime) { mdl.SlotCardTime2 = slodCardTime.ToString("yyyy-MM-dd HH:mm"); } else { mdl.SlotCardTime1 = slodCardTime.ToString("yyyy-MM-dd HH:mm"); } record = irep.Insert(mdl); if (record == 1) { initMdl = CreateAttendDataModel(attendTimeMdl, worker, slodCardTime); initMdl.Id_Key = mdl.Id_Key; initMdl.SlotCardTime1 = mdl.SlotCardTime1; } return(record); }