/// <summary> /// 刷新出勤记录 /// </summary> /// <returns></returns> public List <Incard> refershIncard(CommuteCopy ruleCopy, User tokenUser) { var todayZeroClockSeconds = (int)new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0, 0).Subtract(new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds; var tomorrowZeroClockSeconds = todayZeroClockSeconds + 24 * 60 * 60; var todayZeroSeconds = (int)DateTime.Now.Subtract(new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds; var tomorrowZeroSeconds = todayZeroSeconds + 24 * 60 * 60; // 重新汇总当天打卡情况 var incardSeris = (from s in this.oaContext.incardSerialNumbers where s.inputTime >= todayZeroClockSeconds && s.inputTime <= tomorrowZeroClockSeconds && s.UserId == tokenUser.id select s).ToList(); var query = (from c in this.oaContext.incards where c.inputTime >= todayZeroClockSeconds && c.inputTime <= tomorrowZeroClockSeconds select c).ToList(); Console.WriteLine(todayZeroClockSeconds + ":" + tomorrowZeroClockSeconds + "->" + query.Count); query.ForEach(c => { this.oaContext.incards.Remove(c); }); this.oaContext.SaveChanges(); if (ruleCopy.putCardNumber == 2) { // 早班有效打卡 var normalMorning = (from c in incardSeris where c.time >= ruleCopy.beginPunchInterval1 && c.time <= ruleCopy.morningWorkTime orderby c.time ascending select c).FirstOrDefault(); if (normalMorning != null) { this.addIncard(InCardTimeType.First, IncardTimeResult.Normal, tokenUser.id, tokenUser.companyId, normalMorning.time); } else { // 早班迟到卡 var lateMorning = (from c in incardSeris where c.time >= ruleCopy.morningWorkTime && c.time <= ruleCopy.morningGoOffWork orderby c.time ascending select c).FirstOrDefault(); if (lateMorning != null) { this.addIncard(InCardTimeType.First, IncardTimeResult.Late, tokenUser.id, tokenUser.companyId, lateMorning.time); } } var normalAfternoon = (from c in incardSeris where c.time >= ruleCopy.afternoonGoOffWork && ruleCopy.endPunchInterval4 >= c.time select c).FirstOrDefault(); if (normalAfternoon != null) { this.addIncard(InCardTimeType.Fourth, IncardTimeResult.Normal, tokenUser.id, tokenUser.companyId, normalAfternoon.time); } else { var lateAfternoon = (from c in incardSeris where c.time >= ruleCopy.beginPunchInterval4 select c).FirstOrDefault(); if (lateAfternoon != null) { this.addIncard(InCardTimeType.Fourth, IncardTimeResult.Early, tokenUser.id, tokenUser.companyId, lateAfternoon.time); } } } var incards = (from i in this.oaContext.incards where i.inputTime >= todayZeroSeconds && i.inputTime < tomorrowZeroSeconds select i).ToList(); return(incards); }
/// <summary> /// 获取用户公司打卡规则 /// </summary> /// <param name="tokenUser"></param> /// <returns></returns> public CommuteCopy getUserCompanyCommuteCopy(User tokenUser) { var todayZeroClockSeconds = (int)new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0, 0).Subtract(new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds; var tomorrowZeroClockSeconds = todayZeroClockSeconds + 24 * 60 * 60; var todayZeroSeconds = (int)DateTime.Now.Subtract(new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds; var tomorrowZeroSeconds = todayZeroSeconds + 24 * 60 * 60; var copyRules = (from rule in this.oaContext.commuteCopys where rule.companyId == tokenUser.companyId && rule.datatime == todayZeroSeconds select rule).ToList(); if (copyRules.Count <= 0) { var rule = (from c in this.oaContext.commutes where c.companyId == tokenUser.companyId select c).FirstOrDefault(); if (rule != null) { var ruleCopy = (from c in this.oaContext.commuteCopys where c.companyId == rule.companyId select c).FirstOrDefault(); if (ruleCopy == null) { var zeroDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0); ruleCopy = new CommuteCopy { companyId = rule.companyId, morningWorkTime = rule.morningWorkTime, morningGoOffWork = rule.morningGoOffWork, afternoonWorkTime = rule.afternoonWorkTime, afternoonGoOffWork = rule.afternoonGoOffWork, beginPunchInterval1 = rule.beginPunchInterval1, endPunchInterval1 = rule.endPunchInterval1, beginPunchInterval2 = rule.beginPunchInterval2, endPunchInterval2 = rule.endPunchInterval2, beginPunchInterval3 = rule.beginPunchInterval3, endPunchInterval3 = rule.endPunchInterval3, beginPunchInterval4 = rule.beginPunchInterval4, endPunchInterval4 = rule.endPunchInterval4, datatime = todayZeroSeconds, putCardNumber = rule.putCardNumber, }; this.oaContext.commuteCopys.Add(ruleCopy); this.oaContext.SaveChanges(); return(ruleCopy); } else { return(ruleCopy); } } else { return(null); } } else { return(copyRules[0]); } }