/// <summary> /// 同步哨位记录至勤务排班记录 /// </summary> /// <param name="punchLog"></param> public static void Synchronization(PunchLog punchLog) { try { using (var db = new AllInOneContext.AllInOneContext()) { //取当前记录 DutyCheckLog log = db.DutyCheckLog .Include(t => t.DutyCheckSiteSchedule).ThenInclude(t => t.CheckMan).ThenInclude(t => t.Organization) .Include(t => t.DutyCheckSiteSchedule).ThenInclude(t => t.CheckMan).ThenInclude(t => t.PositionType) .Include(t => t.DayPeriod).ThenInclude(t => t.TimePeriods) .FirstOrDefault(p => p.DutyCheckSiteSchedule != null && p.DutyCheckSiteScheduleId.Equals(punchLog.OnDutyStaff.StaffId) && new DateTime(p.PlanDate.Value.Year, p.PlanDate.Value.Month, p.PlanDate.Value.Day, p.TimePeriod.StartTime.Hour, p.TimePeriod.StartTime.Minute, p.TimePeriod.StartTime.Second) <= punchLog.LogTime && new DateTime(p.PlanDate.Value.Year, p.PlanDate.Value.Month, p.PlanDate.Value.Day, p.TimePeriod.EndTime.Hour, p.TimePeriod.EndTime.Minute, p.TimePeriod.EndTime.Second) >= punchLog.LogTime); // if (log == null) { return; } //同步记录 log.MainAppriseId = log.MainAppriseId; log.RecordTime = punchLog.LogTime; log.StatusId = new Guid("24AC9875-C463-47B6-8147-5845874C3CAF"); db.DutyCheckLog.Update(log); db.SaveChanges(); } } catch (Exception ex) { Console.WriteLine("Synchronization is Exception:" + ex.Message); } }
public IActionResult Get(Guid id) { using (var db = new AllInOneContext.AllInOneContext()) { DutyCheckLog data = db.DutyCheckLog .Include(t => t.Apprises).ThenInclude(t => t.DutyCheckAppraise).ThenInclude(t => t.AppraiseICO) .Include(t => t.Apprises).ThenInclude(t => t.DutyCheckAppraise).ThenInclude(t => t.AppraiseType) .Include(t => t.DutyCheckOperation).ThenInclude(t => t.Attachments).ThenInclude(t => t.Attachment) .Include(t => t.DutyCheckOperation).ThenInclude(t => t.Attachments).ThenInclude(t => t.AttachmentType) .Include(t => t.DutyCheckSiteSchedule)/*.ThenInclude(t=>t.CheckDutySite)*/ .Include(t => t.DutyCheckSiteSchedule).ThenInclude(t => t.CheckMan) .Include(t => t.DutyCheckStaff) .Include(t => t.Organization) .Include(t => t.RecordType) .Include(t => t.Status) .Include(t => t.CircularTypes).ThenInclude(t => t.Dispose) .Include(t => t.MainApprise) .FirstOrDefault(p => p.DutyCheckLogId.Equals(id)); if (data == null) { return(NoContent()); } return(new ObjectResult(data)); } }
public IActionResult Add([FromBody] DutyCheckLog model) { try { if (model == null) { return(BadRequest()); } using (var db = new AllInOneContext.AllInOneContext()) { db.DutyCheckLog.Add(model); db.SaveChanges(); return(Created("", "OK")); } } catch (DbUpdateException dbEx) { return(BadRequest(new ApplicationException { ErrorCode = "DBUpdate", ErrorMessage = "数据保存异常:" + dbEx.Message })); } catch (System.Exception ex) { return(BadRequest(new ApplicationException { ErrorCode = "Unknown", ErrorMessage = ex.Message })); } }
public DutyDetail GetDutyDetailByFieldCheck(Guid sentinelId, DateTime time, Guid?staffId) { using (var db = new AllInOneContext.AllInOneContext()) { var Sentinel = db.IPDeviceInfo .FirstOrDefault(p => p.IPDeviceInfoId.Equals(sentinelId)); if (Sentinel == null) { return(null); } //取当前记录 var logs = db.DutyCheckLog .Include(t => t.DutyCheckSiteSchedule).ThenInclude(t => t.CheckMan).ThenInclude(t => t.Organization) .Include(t => t.DutyCheckSiteSchedule).ThenInclude(t => t.CheckMan).ThenInclude(t => t.PositionType) .Include(t => t.DayPeriod).ThenInclude(t => t.TimePeriods) .Where(p => p.DutyCheckSiteSchedule != null && new DateTime(p.PlanDate.Value.Year, p.PlanDate.Value.Month, p.PlanDate.Value.Day, p.TimePeriod.StartTime.Hour, p.TimePeriod.StartTime.Minute, p.TimePeriod.StartTime.Second) <= time && new DateTime(p.PlanDate.Value.Year, p.PlanDate.Value.Month, p.PlanDate.Value.Day, p.TimePeriod.EndTime.Hour, p.TimePeriod.EndTime.Minute, p.TimePeriod.EndTime.Second) >= time); if (logs == null) { return(null); } DutyCheckLog log = null; foreach (DutyCheckLog dcl in logs) //由于DutyCheckSiteScheduleId也可能为空,暂这样处理 { if (dcl.DutyCheckSiteSchedule != null && dcl.DutyCheckSiteSchedule.SiteOrganizationId.Equals(Sentinel.OrganizationId)) { log = dcl; break; } } if (log == null) { return(null); } //取 查哨人员 Staff checkStaff = null; if (staffId != null) { checkStaff = db.Staff.FirstOrDefault(p => p.StaffId.Equals(staffId)); } // DutyDetail dutyDetail = new DutyDetail(); dutyDetail.Sentinelid = sentinelId; dutyDetail.OnDutyStaff = log.DutyCheckSiteSchedule.CheckMan; if (checkStaff != null) { dutyDetail.OffDutyStaff = checkStaff; } return(dutyDetail); } }
public IActionResult ReportToParentOrganization(Guid id) { try { using (var db = new AllInOneContext.AllInOneContext()) { DutyCheckLog data = db.DutyCheckLog .Include(t => t.Organization) .FirstOrDefault(p => p.DutyCheckLogId == id); if (data == null) { return(NoContent()); } Organization org = db.Organization .Include(t => t.ParentOrganization).ThenInclude(t => t.Center) .FirstOrDefault(p => p.OrganizationId.Equals(data.Organization.ParentOrganizationId)); if (org == null || org.Center == null || org.Center.EndPoints == null || org.Center.EndPoints.Count == 0) { if (org == null || org.Center == null || org.Center.EndPoints == null || org.Center.EndPoints.Count == 0) { return(NoContent()); } } string url = string.Format("http://{0}:{1}/PAPS/DutyCheckLog", org.Center.EndPoints[0].IPAddress, org.Center.EndPoints[0].Port); //更新状态 data.StatusId = new Guid("8E392E33-B63E-7801-685A-76634DDFF511"); db.SaveChanges(); // data.OrganizationId = org.OrganizationId; var result = HttpClientHelper.Post <DutyCheckLog>(data, url); if (result.Success) { return(new NoContentResult()); } else { return(BadRequest()); } } } catch (Exception ex) { return(BadRequest(new ApplicationException { ErrorCode = "Unknown", ErrorMessage = ex.Message })); } }
/// <summary> /// 获取网络查勤员数据 /// </summary> /// <param name="model">计划实体</param> /// <param name="time">计划时间</param> /// <param name="tp">时间段</param> /// <param name="staff">人员</param> /// <returns></returns> private static DutyCheckLog GetCheckManLog(Guid organizationId, DateTime time, TimePeriod tp, Guid staffId) { DutyCheckLog log = new DutyCheckLog { DutyCheckLogId = Guid.NewGuid(), TimePeriod = tp, RecordTypeId = new Guid("a0002016-e009-b019-e001-abcd18000002"), //实地查勤 new Guid("359A58FA-0BAB-45A3-ACAF-98EB73228B95"), //网络查勤 PlanDate = time, DutyCheckStaffId = staffId, OrganizationId = organizationId, StatusId = new Guid("361ADFE9-E58A-4C88-B191-B742CC212443"), //未开始 }; return(log); }
public IActionResult UpdateDaySchedule(Guid dutyCheckLogId, Guid staffId) { try { using (var db = new AllInOneContext.AllInOneContext()) { using (var tran = db.Database.BeginTransaction()) { DutyCheckLog log = db.DutyCheckLog .Include(t => t.DutyCheckSiteSchedule) .FirstOrDefault(p => p.DutyCheckLogId.Equals(dutyCheckLogId)); //查询当天的同一时段内是否已存在该人员排班 var list = db.DutyCheckLog .Where(p => p.PlanDate.Equals(log.PlanDate) && p.TimePeriodJson.Equals(log.TimePeriodJson) && p.DutyCheckLogId != dutyCheckLogId && p.DutyCheckStaffId.Equals(staffId)); if (list.Count() != 0) { return(BadRequest(new ApplicationException { ErrorCode = "DBUpdate", ErrorMessage = "同一时段已存在该人员排班" })); } log.DutyCheckStaffId = staffId; if (log.DutyCheckSiteSchedule != null) { log.DutyCheckSiteSchedule.CheckManId = staffId; } db.DutyCheckLog.Update(log); tran.Commit(); return(new NoContentResult()); } } } catch (DbUpdateException dbEx) { return(BadRequest(new ApplicationException { ErrorCode = "DBUpdate", ErrorMessage = "数据保存异常:" + dbEx.Message })); } catch (System.Exception ex) { return(BadRequest(new ApplicationException { ErrorCode = "Unknown", ErrorMessage = ex.Message })); } }
public IActionResult DeleteDutyCheckLog(Guid id) { try { using (var db = new AllInOneContext.AllInOneContext()) { DutyCheckLog data = db.DutyCheckLog.FirstOrDefault(p => p.DutyCheckLogId == id); if (data == null) { return(NoContent()); } db.DutyCheckLog.Remove(data); db.SaveChanges(); return(new NoContentResult()); } } catch (System.Exception ex) { return(BadRequest(new ApplicationException { ErrorCode = "Unknown", ErrorMessage = ex.Message })); } }
public DutyDetail GetDutyDetailBySentinelId(Guid sentinelId) { using (var db = new AllInOneContext.AllInOneContext()) { DateTime time = DateTime.Now; var Sentinel = db.IPDeviceInfo .FirstOrDefault(p => p.IPDeviceInfoId.Equals(sentinelId)); if (Sentinel == null) { return(null); } //取当前记录 var logs = db.DutyCheckLog .Include(t => t.DutyCheckSiteSchedule).ThenInclude(t => t.CheckMan).ThenInclude(t => t.Organization) .Include(t => t.DutyCheckSiteSchedule).ThenInclude(t => t.CheckMan).ThenInclude(t => t.PositionType) .Include(t => t.DayPeriod).ThenInclude(t => t.TimePeriods) .Where(p => p.DutyCheckSiteSchedule != null && new DateTime(p.PlanDate.Value.Year, p.PlanDate.Value.Month, p.PlanDate.Value.Day, p.TimePeriod.StartTime.Hour, p.TimePeriod.StartTime.Minute, p.TimePeriod.StartTime.Second) <= time && new DateTime(p.PlanDate.Value.Year, p.PlanDate.Value.Month, p.PlanDate.Value.Day, p.TimePeriod.EndTime.Hour, p.TimePeriod.EndTime.Minute, p.TimePeriod.EndTime.Second) >= time); if (logs == null) { return(null); } DutyCheckLog log = null; foreach (DutyCheckLog dcl in logs) //由于DutyCheckSiteScheduleId也可能为空,暂这样处理 { if (dcl.DutyCheckSiteSchedule != null && dcl.DutyCheckSiteSchedule.SiteOrganizationId.Equals(Sentinel.OrganizationId)) { log = dcl; break; } } if (log == null) { return(null); } //取前一时段的记录 int day = 0; int oldOrderNo = log.TimePeriod.OrderNo - 1; if (oldOrderNo <= 0) { oldOrderNo = log.DayPeriod.TimePeriods.Max(p => p.OrderNo); day = -1; } TimePeriod oldTimePeriod = log.DayPeriod.TimePeriods.Find(p => p.OrderNo.Equals(oldOrderNo)); // DateTime oldStartTime = new DateTime(time.AddDays(day).Date.Year, time.AddDays(day).Date.Month, time.AddDays(day).Date.Day, oldTimePeriod.StartTime.Hour, oldTimePeriod.StartTime.Minute, oldTimePeriod.StartTime.Second); DateTime oldEndTime = new DateTime(time.AddDays(day).Date.Year, time.AddDays(day).Date.Month, time.AddDays(day).Date.Day, oldTimePeriod.EndTime.Hour, oldTimePeriod.EndTime.Minute, oldTimePeriod.EndTime.Second); DutyCheckLog oldlog = null; var oldlogs = db.DutyCheckLog .Include(t => t.DutyCheckSiteSchedule).ThenInclude(t => t.CheckMan).ThenInclude(t => t.Organization) .Include(t => t.DutyCheckSiteSchedule).ThenInclude(t => t.CheckMan).ThenInclude(t => t.PositionType) .Include(t => t.DayPeriod).ThenInclude(t => t.TimePeriods) .Where(p => p.DutyCheckSiteSchedule != null && new DateTime(p.PlanDate.Value.Year, p.PlanDate.Value.Month, p.PlanDate.Value.Day, p.TimePeriod.StartTime.Hour, p.TimePeriod.StartTime.Minute, p.TimePeriod.StartTime.Second) <= oldStartTime && new DateTime(p.PlanDate.Value.Year, p.PlanDate.Value.Month, p.PlanDate.Value.Day, p.TimePeriod.EndTime.Hour, p.TimePeriod.EndTime.Minute, p.TimePeriod.EndTime.Second) >= oldEndTime); if (oldlogs != null) { foreach (DutyCheckLog dcl in oldlogs) { if (dcl.DutyCheckSiteSchedule != null && dcl.DutyCheckSiteSchedule.SiteOrganizationId.Equals(Sentinel.OrganizationId)) { oldlog = dcl; break; } } } // DutyDetail dutyDetail = new DutyDetail(); dutyDetail.Sentinelid = sentinelId; dutyDetail.OnDutyStaff = log.DutyCheckSiteSchedule.CheckMan; if (oldlog != null) { dutyDetail.OffDutyStaff = oldlog.DutyCheckSiteSchedule.CheckMan; } return(dutyDetail); } }
/// <summary> ///随机获取该组织机构下的一个监控点 /// </summary> /// <param name="organizationId"></param> /// <returns></returns> private CameraView GetCameraView(Guid?organizationId, AllInOneContext.AllInOneContext db, DutyCheckLog log) { CameraView monitorySite = null; if (organizationId == null) { return(monitorySite); } //获取组织机构下所有的监控点View Organization org = db.Organization .Include(t => t.Center) .FirstOrDefault(p => p.OrganizationId.Equals(organizationId)); if (org == null || org.Center == null || org.Center.EndPoints == null || org.Center.EndPoints.Count == 0) { return(monitorySite); } // List <DutyCheckLog> allDutyCheckLogs = GetAllDutyCheckLog(db, org); //判断是否已绑定监控点数据 if (log.DutycheckSiteId != null) { string murl = string.Format("http://{0}:{1}/Resources/MonitorySite/cameraId/{2}", org.Center.EndPoints[0].IPAddress, org.Center.EndPoints[0].Port, log.DutycheckSiteId); MonitorySite ms = HttpClientHelper.GetOne <MonitorySite>(murl); return(ms.ToCameraView()); } string url = string.Format("http://{0}:{1}/Resources/MonitorySite", org.Center.EndPoints[0].IPAddress, org.Center.EndPoints[0].Port); IEnumerable <MonitorySite> monitorySiteT = HttpClientHelper.Get <MonitorySite>(url); //过滤出有效的监控点 monitorySiteT = monitorySiteT.Where(p => p.IsDutycheckSite); //确保所有监控点能覆盖 CameraView randomCameraView = null; if (monitorySiteT == null || monitorySiteT.Count() == 0) { return(randomCameraView); } foreach (MonitorySite cam in monitorySiteT) { var competeLog = allDutyCheckLogs.FirstOrDefault(p => p.DutycheckSiteId.Equals(cam.CameraId)); if (competeLog != null) { continue; } else { randomCameraView = cam.ToCameraView(); break; } } // if (randomCameraView == null) { Random r = new Random(monitorySiteT.Count()); randomCameraView = monitorySiteT.ToArray()[r.Next()].ToCameraView(); } return(randomCameraView); }
public IActionResult GetNextDutyCheckLog(Guid organizationId) { try { if (organizationId == null || organizationId == new Guid()) { return(NoContent()); } //调整方法,原来记录生成的只是组织机构,需匹配生成查勤点 using (var db = new AllInOneContext.AllInOneContext()) { DutyCheckPackage package = db.DutyCheckPackage .Include(t => t.DutyCheckPackLogs).ThenInclude(t => t.DutyCheckLog).ThenInclude(t => t.Status) .FirstOrDefault(p => p.StartTime <= DateTime.Now && p.EndTime >= DateTime.Now && p.PackageStatusId != new Guid("124A8562-EAC8-4C09-8758-A6E312974552")); if (package == null) { return(NoContent()); } //处理已获取,未完成的记录 var getLogs = package.DutyCheckPackLogs.Where(p => p.DutyCheckLog.Status.SystemOptionCode.Equals("16000002")); if (getLogs.Count() > 0) { DutyCheckLog log = db.DutyCheckLog .Include(t => t.Apprises).ThenInclude(t => t.DutyCheckAppraise).ThenInclude(t => t.AppraiseICO) .Include(t => t.Apprises).ThenInclude(t => t.DutyCheckAppraise).ThenInclude(t => t.AppraiseType) .Include(t => t.DutyCheckOperation).ThenInclude(t => t.Attachments).ThenInclude(t => t.Attachment) .Include(t => t.DutyCheckOperation).ThenInclude(t => t.Attachments).ThenInclude(t => t.AttachmentType) .Include(t => t.DutyCheckSiteSchedule).ThenInclude(t => t.SiteOrganization) .Include(t => t.DutyCheckSiteSchedule).ThenInclude(t => t.CheckMan) .Include(t => t.DutyCheckStaff) .Include(t => t.Organization) .Include(t => t.RecordType) .Include(t => t.Status) .Include(t => t.CircularTypes).ThenInclude(t => t.Dispose) .Include(t => t.MainApprise) .FirstOrDefault(p => p.DutyCheckLogId.Equals(getLogs.ToList()[0].DutyCheckLogId)); // CameraView cameraView = GetCameraView(log.DutyCheckSiteSchedule.SiteOrganizationId, db, log); DutyCheckPointView View = new DutyCheckPointView { DutyCheckLog = log, CameraView = cameraView }; return(new ObjectResult(View)); } //从未获取的记录中,返回一个 var noLogs = package.DutyCheckPackLogs.Where(p => p.DutyCheckLog.Status.SystemOptionCode.Equals("16000001")); if (noLogs.Count() > 0) { DutyCheckLog log = db.DutyCheckLog .Include(t => t.Apprises).ThenInclude(t => t.DutyCheckAppraise).ThenInclude(t => t.AppraiseICO) .Include(t => t.Apprises).ThenInclude(t => t.DutyCheckAppraise).ThenInclude(t => t.AppraiseType) .Include(t => t.DutyCheckOperation).ThenInclude(t => t.Attachments).ThenInclude(t => t.Attachment) .Include(t => t.DutyCheckOperation).ThenInclude(t => t.Attachments).ThenInclude(t => t.AttachmentType) .Include(t => t.DutyCheckSiteSchedule).ThenInclude(t => t.SiteOrganization) .Include(t => t.DutyCheckSiteSchedule).ThenInclude(t => t.CheckMan) .Include(t => t.DutyCheckStaff) .Include(t => t.Organization) .Include(t => t.RecordType) .Include(t => t.Status) .Include(t => t.CircularTypes).ThenInclude(t => t.Dispose) .Include(t => t.MainApprise) .FirstOrDefault(p => p.DutyCheckLogId.Equals(noLogs.ToList()[0].DutyCheckLogId)); // CameraView cameraView = GetCameraView(log.DutyCheckSiteSchedule.SiteOrganizationId, db, log); //绑定查勤视频点与查勤记录的关系 if (cameraView != null) { log.DutycheckSiteId = cameraView.CameraId; log.DutycheckSiteName = log.DutyCheckSiteSchedule.SiteOrganization.OrganizationShortName + "-" + cameraView.CameraName; SystemOption so = db.SystemOption.FirstOrDefault(p => p.SystemOptionCode.Equals("16000002")); log.StatusId = so.SystemOptionId; log.Status = null; db.DutyCheckLog.Update(log); db.SaveChanges(); } // DutyCheckPointView View = new DutyCheckPointView { DutyCheckLog = log, CameraView = cameraView }; return(new ObjectResult(View)); } //当前时段已完成,更新查勤包的状态 else { package.PackageStatusId = new Guid("24AC9875-C463-47B6-8147-5845874C3CAF"); db.DutyCheckPackage.Update(package); // return(NoContent()); } } } catch (Exception ex) { _logger.LogError("根据组织机构ID获取下一个查勤数据:Message:{0}\r\n,StackTrace:{1}", ex.Message, ex.StackTrace); return(BadRequest(new ApplicationException { ErrorCode = "Unknown", ErrorMessage = ex.Message })); } }
public IActionResult GetCheckDuty(int fingerPrintNumber, Guid sentinelId) { try { using (var db = new AllInOneContext.AllInOneContext()) { var fingerprint = db.Set <Fingerprint>().FirstOrDefault(p => p.FingerprintNo.Equals(fingerPrintNumber)); if (fingerprint == null) { return(new ObjectResult(new FingerprintOnDuty { FingerprintNumber = fingerPrintNumber, Result = false })); } //查找对应人员 Staff staff = db.Staff .FirstOrDefault(p => p.StaffId.Equals(fingerprint.StaffId)); if (staff == null) { return(new ObjectResult(new FingerprintOnDuty { FingerprintNumber = fingerPrintNumber, Result = false })); } //查找哨位台 var sentry = db.IPDeviceInfo .FirstOrDefault(p => p.IPDeviceInfoId.Equals(sentinelId)); if (sentry == null) { return(new ObjectResult(new FingerprintOnDuty { FingerprintNumber = fingerPrintNumber, Result = false })); } //查找排班情况 var logs = db.DutyCheckLog .Include(t => t.DutyCheckSiteSchedule) .Where(p => p.DutyCheckSiteSchedule != null // && new DateTime(p.PlanDate.Value.Year, p.PlanDate.Value.Month, p.PlanDate.Value.Day, p.TimePeriod.StartTime.Hour, p.TimePeriod.StartTime.Minute, p.TimePeriod.StartTime.Second) <= DateTime.Now && new DateTime(p.PlanDate.Value.Year, p.PlanDate.Value.Month, p.PlanDate.Value.Day, p.TimePeriod.EndTime.Hour, p.TimePeriod.EndTime.Minute, p.TimePeriod.EndTime.Second) >= DateTime.Now); DutyCheckLog log = null; foreach (DutyCheckLog dcl in logs) //由于DutyCheckSiteScheduleId也可能为空,暂这样处理 { if (dcl.DutyCheckSiteSchedule != null && dcl.DutyCheckSiteSchedule.SiteOrganizationId.Equals(sentry.OrganizationId) && dcl.DutyCheckSiteSchedule.CheckManId.Equals(staff.StaffId)) { log = dcl; break; } } if (log == null) { return(new ObjectResult(new FingerprintOnDuty { FingerprintNumber = fingerPrintNumber, Result = false })); } else { return(new ObjectResult(new FingerprintOnDuty { FingerprintNumber = fingerPrintNumber, Result = true })); } } } catch (Exception ex) { _logger.LogError("检查人员是否正常换岗:Message:{0}\r\n,StackTrace:{1}", ex.Message, ex.StackTrace); return(BadRequest(new ApplicationException { ErrorCode = "Unknown", ErrorMessage = ex.Message })); } }
public IActionResult Update([FromBody] DutyCheckLog model) { try { if (model == null) { return(BadRequest()); } using (var db = new AllInOneContext.AllInOneContext()) { DutyCheckLog log = db.DutyCheckLog .Include(t => t.Apprises).ThenInclude(t => t.DutyCheckAppraise).ThenInclude(t => t.AppraiseICO) .Include(t => t.Apprises).ThenInclude(t => t.DutyCheckAppraise).ThenInclude(t => t.AppraiseType) .Include(t => t.DutyCheckOperation).ThenInclude(t => t.Attachments).ThenInclude(t => t.Attachment) .Include(t => t.DutyCheckOperation).ThenInclude(t => t.Attachments).ThenInclude(t => t.AttachmentType) .Include(t => t.DutyCheckSiteSchedule)/*.ThenInclude(t=>t.CheckDutySite)*/ .Include(t => t.DutyCheckSiteSchedule).ThenInclude(t => t.CheckMan) .Include(t => t.DutyCheckStaff) .Include(t => t.Organization) .Include(t => t.RecordType) .Include(t => t.Status) .Include(t => t.CircularTypes).ThenInclude(t => t.Dispose) .Include(t => t.MainApprise) .FirstOrDefault(p => p.DutyCheckLogId.Equals(model.DutyCheckLogId)); if (log == null) { return(BadRequest()); } //转换数据 log.Apprises = model.Apprises; log.CircularTypes = model.CircularTypes; log.Description = model.Description; log.DutyCheckOperationId = model.DutyCheckOperationId; log.DutyCheckSiteScheduleId = model.DutyCheckSiteScheduleId; log.DutyCheckStaffId = model.DutyCheckStaffId; log.MainAppriseId = model.MainAppriseId; log.RecordTime = model.RecordTime; log.StatusId = model.StatusId; // db.DutyCheckLog.Update(log); db.SaveChanges(); //判断是否为查勤包查勤,刷新查勤进度 if (model.RecordTypeId.Equals(new Guid("a0002016-e009-b019-e001-abcd18000001"))) //网络查勤 { CheckPackageProcess(model.OrganizationId); } return(new NoContentResult()); } } catch (DbUpdateException dbEx) { return(BadRequest(new ApplicationException { ErrorCode = "DBUpdate", ErrorMessage = "数据保存异常:" + dbEx.Message })); } catch (System.Exception ex) { return(BadRequest(new ApplicationException { ErrorCode = "Unknown", ErrorMessage = ex.Message })); } }
/// <summary> /// 根据安排表生成实地查勤 /// </summary> /// <param name="dgs"></param> public static bool GetAbsoultedDutyCheckLog(DutyGroupSchedule dgs) { if (dgs == null) { return(false); } bool isOK = false; //补全数据 DutyGroupSchedule model = CompletionData(dgs); //组装网络查勤员数据 Queue <Staff> checkMans = new Queue <Staff>(); //网络查勤员队列 foreach (DutyGroupScheduleDetail detail in model.DutyGroupScheduleDetails) { checkMans.Enqueue(detail.CheckMan); } //取所有哨位信息 Dictionary <Guid, Queue <DutyCheckSiteSchedule> > groupStaff = new Dictionary <Guid, Queue <DutyCheckSiteSchedule> >(); Dictionary <Guid, Queue <DutyCheckSiteSchedule> > allStaffs = new Dictionary <Guid, Queue <DutyCheckSiteSchedule> >(); // foreach (DutyCheckSiteSchedule dss in model.DutyGroupScheduleDetails[0].CheckDutySiteSchedule) { //groupStaff.Add(dss.CheckDutySite.MonitorySiteId, new Queue<DutyCheckSiteSchedule>()); //allStaffs.Add(dss.CheckDutySite.MonitorySiteId, new Queue<DutyCheckSiteSchedule>()); if (dss.CheckDutySiteId != null) { groupStaff.Add(dss.CheckDutySiteId.Value, new Queue <DutyCheckSiteSchedule>()); allStaffs.Add(dss.CheckDutySiteId.Value, new Queue <DutyCheckSiteSchedule>()); } } //取哨位对应的组员信息 foreach (DutyGroupScheduleDetail detail in model.DutyGroupScheduleDetails) { foreach (DutyCheckSiteSchedule dss in detail.CheckDutySiteSchedule) { if (dss.CheckDutySiteId != null) { if (groupStaff.ContainsKey(dss.CheckDutySiteId.Value)) { groupStaff[dss.CheckDutySiteId.Value].Enqueue(dss); } if (allStaffs.ContainsKey(dss.CheckDutySiteId.Value)) { allStaffs[dss.CheckDutySiteId.Value].Enqueue(dss); } } } } //过滤过期的时间 if (model.EndDate <= DateTime.Now) { return(false); } //计算有效天数 int days = (int)(model.EndDate.Date - model.StartDate.Date).TotalDays + 1; if (days <= 0) { Console.WriteLine("生成分组查勤表无效,时间已过期!"); return(false); } DateTime validtime = DateTime.Now; if (model.StartDate <= DateTime.Now && model.EndDate >= DateTime.Now) { for (int i = 0; i < days; i++) { if (model.StartDate.AddDays(i) >= DateTime.Now.Date) { validtime = model.StartDate.AddDays(i); break; } } validtime = new DateTime(validtime.Year, validtime.Month, validtime.Day, 0, 0, 0); } else if (model.StartDate > DateTime.Now) { validtime = new DateTime(model.StartDate.Year, model.StartDate.Month, model.StartDate.Day, 0, 0, 0); } days = (int)(model.EndDate.Date - validtime.Date).TotalDays + 1; if (days == 0) { return(false); } //实际人员轮值总数 int allCount = days * model.Schedule.ScheduleCycle.DayPeriods[0].TimePeriods.Count() - 1; //计算出实际人员的循环情况 for (int i = 0; i < allCount; i++) { foreach (var data in groupStaff) { DutyCheckSiteSchedule staff = groupStaff[data.Key].Dequeue(); //循环进队 allStaffs[data.Key].Enqueue(staff); //重新进队 groupStaff[data.Key].Enqueue(staff); } } //根据时段循环分配组员 List <DutyCheckLog> logs = new List <DutyCheckLog>(); for (int i = 0; i < days; i++) { try { DateTime time = validtime.AddDays(i); foreach (TimePeriod tp in model.Schedule.ScheduleCycle.DayPeriods[0].TimePeriods) { //判断当天的数据,已经失效的时段不再生成记录 if (time == DateTime.Now.Date) { DateTime startTime = new DateTime(time.Year, time.Month, time.Day, tp.StartTime.Hour, tp.StartTime.Minute, tp.StartTime.Second); DateTime endTime = new DateTime(time.Year, time.Month, time.Day, tp.EndTime.Hour, tp.EndTime.Minute, tp.EndTime.Second); if (startTime > DateTime.Now || endTime < DateTime.Now) { continue; } } //组装网络查勤员数据 Staff staff = checkMans.Dequeue(); DutyCheckLog log = GetCheckManLog(model.OrganizationId, time, tp, staff.StaffId); logs.Add(log); checkMans.Enqueue(staff); foreach (var data in allStaffs) { DutyCheckSiteSchedule dss = allStaffs[data.Key].Dequeue(); DutyCheckLog sitelog = GetSiteLog(model, time, tp, dss, model.Schedule.ScheduleCycle.DayPeriods[0].DayPeriodId); logs.Add(sitelog); } } } catch (Exception ex) { isOK = false; return(isOK); } } //实际保存记录 using (var db = new AllInOneContext.AllInOneContext()) { //建立事务 using (var tran = db.Database.BeginTransaction()) { try { //先移除已排班但尚未执行的记录 var del = db.DutyCheckLog .Where(p => p.PlanDate >= model.StartDate && p.PlanDate <= model.EndDate && p.StatusId == new Guid("361ADFE9-E58A-4C88-B191-B742CC212443")); if (del != null && del.Count() != 0) { db.DutyCheckLog.RemoveRange(del.ToList()); db.SaveChanges(); } //新增 foreach (DutyCheckLog log in logs) { string txt = JsonConvert.SerializeObject(log); db.DutyCheckLog.Add(log); } db.SaveChanges(); tran.Commit(); isOK = true; } catch (Exception ex) { isOK = false; } } } return(isOK); }