/// <summary> /// 作業時間の記録に利用するためのタスクを取得します /// </summary> /// <param name="ymd">日付</param> /// <returns></returns> public WorkTaskTableRow[] SelectPlaned(YmdString ymd, bool containsCompleted) { string where; object param; if (containsCompleted) { where = @" ( id IN ( SELECT worktaskid FROM worktaskscompleted WHERE registdatetime BETWEEN @start AND @end ) OR NOT EXISTS ( SELECT 1 FROM worktaskscompleted WHERE worktaskid = worktasks.id ) )"; param = new { start = ymd.ToDateTime().Value, end = ymd.ToDateTime().Value.AddDays(1).AddMinutes(-1) }; } else { where = @" NOT EXISTS ( SELECT 1 FROM worktaskscompleted WHERE worktaskid = worktasks.id )"; param = new object(); } return(SelectCore(where, param).ToArray()); }
/// <summary> /// 指定した日付の予定をタスクとして取り込みます /// </summary> /// <param name="ymdString">取り込み対象日付</param> /// <returns></returns> public async Task <WorkTask[]> ImportToTaskAsync(YmdString ymdString) { try { _Logger.Info($"[ScheduleImporter] ▼スケジュール取り込み開始 target=[{ymdString}]"); // イベントの取得 var fromDateTime = ymdString.ToDateTime().Value; var toDateTime = fromDateTime.AddDays(1).AddMinutes(-1); var targetKinds = _WorkTaskBuilderConfig.EventMappers.Select(e => e.EventKind).ToArray(); var events = await _ScheduledEventRepository.FetchScheduledEventsAsync(targetKinds, fromDateTime, toDateTime); if (events == null) { _Logger.Error("[ScheduleImporter] unknown error"); return(Array.Empty <WorkTask>()); } // 未登録のイベントを取り込み var registedWorkTasks = _WorkTaskRepository.SelectByImportKeys(events.Select(e => e.Id).ToArray()); var list = new List <WorkTask>(); var builder = new WorkTaskBuilder(_WorkTaskBuilderConfig, _ScheduleTitleMaps); foreach (var @event in events) { // 登録済みは無視する if (registedWorkTasks.Any(t => t.ImportKey == @event.Id)) { continue; } // 未登録ならスケジュールに合わせて登録 (WorkTask workTask, ImportedTask importedTask) = builder.Build(@event); workTask = _WorkTaskRepository.AddForSchedule(workTask, importedTask); list.Add(workTask); var newWorkingTime = WorkingTimeRange.FromScheduledEvent(workTask.Id, @event); _WorkingTimeRangeRepository.Add(newWorkingTime); } return(list.ToArray()); } finally { _Logger.Info($"[ScheduleImporter] ▲スケジュール取り込み終了 target=[{ymdString}]"); } }
public async Task <WorkTask[]> ImportToTaskAsync(YmdString ymdString) { // イベントの取得 var fromDateTime = ymdString.ToDateTime().Value; var toDateTime = fromDateTime.AddDays(1).AddMinutes(-1); var targetKinds = _WorkTaskBuilderConfig.EventMappers.Select(e => e.EventKind).ToArray(); var events = await _ScheduledEventRepository.FetchScheduledEventsAsync(targetKinds, fromDateTime, toDateTime); if (events == null) { return(new WorkTask[0]); } // 未登録のイベントを取り込み var registedWorkTasks = _WorkTaskRepository.SelectByImportKeys(events.Select(e => e.Id).ToArray()); var list = new List <WorkTask>(); var builder = new WorkTaskBuilder(_WorkTaskBuilderConfig, _ScheduleTitleMaps); foreach (var @event in events) { // 登録済みは無視する if (registedWorkTasks.Any(t => t.ImportKey == @event.Id)) { continue; } // 未登録ならスケジュールに合わせて登録 var workTask = builder.Build(@event); workTask = _WorkTaskRepository.Add(workTask); list.Add(workTask); var newWorkingTime = WorkingTimeRange.FromScheduledEvent(workTask.Id, @event); _WorkingTimeRangeRepository.Add(newWorkingTime); } return(list.ToArray()); }