internal void RecalcMonitorDuration(DateTime CalcDate) { //CalcDate = CalcDate.AddMinutes(-2); MonitorDurationDal DataAccess = new MonitorDurationDal(); List<KPI_UnitEntity> UnitList = KPI_UnitDal.GetAllEntity(); foreach (KPI_UnitEntity Unit in UnitList) { if (String.IsNullOrEmpty(Unit.WorkID)) return; if (UnitIsRunning(Unit.UnitID)) { m_Loger.InfoFormat(String.Format("开始计算{0}操盘时间", Unit.UnitName)); //m_Loger.InfoFormat("开始计算{0}操盘时间", Unit.UnitName); MonitorDurationEntity MonitorDuration = new MonitorDurationEntity(); //DateTime Now = DateTime.Now; String strStartTime = ""; String strEndTime = ""; String Shift = ""; String Period = ""; String strCurrentMinute = CalcDate.ToString("yyyy-MM-dd HH:mm:00"); KPI_WorkDal.GetShiftAndPeriod(Unit.WorkID, strCurrentMinute, ref Shift, ref Period, ref strStartTime, ref strEndTime); DateTime ShiftStartTime = Convert.ToDateTime(strStartTime); DateTime ShiftEndTime = Convert.ToDateTime(strEndTime); MonitorDuration.UnitID = Unit.UnitID; MonitorDuration.Shift = Shift; MonitorDuration.CheckDate = CalcDate.Date; MonitorDuration.Duration = GetRecalcDuration(ShiftStartTime, ShiftEndTime, CalcDate); m_Loger.InfoFormat(String.Format("{0}值值班开始时间{1}值班结束时间{2}当天操盘时长是{3}小时", Shift, ShiftStartTime, ShiftEndTime, MonitorDuration.Duration)); DataAccess.SaveMonitorDuration(MonitorDuration); m_Loger.InfoFormat(String.Format("{0}操盘时间计算结束", Unit.UnitName)); } } }
public void Execute(IJobExecutionContext context) { MonitorDurationEntity MonitorDuration = new MonitorDurationEntity(); DateTime Now = DateTime.Now; decimal Hours = Now.Hour + Now.Minute / 60.0m; String strStartTime = ""; String strEndTime = ""; String Shift = ""; String Period = ""; String strCurrentMinute = Now.AddMinutes(-2).ToString("yyyy-MM-dd HH:mm:00"); try { KPI_WorkDal.GetShiftAndPeriod(WorkID, strCurrentMinute, ref Shift, ref Period, ref strStartTime, ref strEndTime); DateTime ShiftStartTime = Convert.ToDateTime(strStartTime); DateTime CurrentTime = DateTime.Now; TimeSpan Span = CurrentTime - ShiftStartTime; MonitorDuration.Shift = Shift; MonitorDuration.CheckDate = Now.AddMinutes(-1); MonitorDuration.Duration = 0.5m; //if ((Hours > 16.5m) && (Hours <= 24.0m)) MonitorDuration.Duration = 7.5m;//SET @Duration=7.5 //if ((Hours >= 0.0m) && (Hours <= 0.5m)) MonitorDuration.Duration = 0.5m; List<KPI_UnitEntity> Units = KPI_UnitDal.GetAllEntity(); using (MonitorDurationDal DataAccess = new MonitorDurationDal()) { foreach (KPI_UnitEntity Unit in Units) { MonitorDuration.UnitID = Unit.UnitID; DataAccess.SaveMonitorDuration(MonitorDuration); } } } catch (Exception ex) { m_Log.Error("各值监盘时间计算错误", ex); } }