작업 시간 업데이트 기능 추가 및 이슈 데이터 저장 확인.
This commit is contained in:
@@ -94,16 +94,20 @@ public class AppDbService
|
||||
}
|
||||
#endregion Table: Configs
|
||||
|
||||
|
||||
public async Task UpsertJiraIssueAsync(JiraIssue issue, CancellationToken ct = default)
|
||||
#region Table: JiraIssues
|
||||
public async Task<(bool isInserted, bool isUpdated)> UpsertJiraIssueAsync(JiraIssue issue, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
var existing = await _db.JiraIssues.FindAsync([issue.Key], ct);
|
||||
|
||||
bool isInserted = false;
|
||||
bool isUpdated = false;
|
||||
|
||||
if (existing == null)
|
||||
{
|
||||
_db.JiraIssues.Add(issue);
|
||||
isInserted = true;
|
||||
_log.Debug("Inserting new Jira issue: {key}", issue.Key);
|
||||
}
|
||||
else
|
||||
@@ -122,6 +126,7 @@ public class AppDbService
|
||||
existing.NeedNotify = issue.NeedNotify;
|
||||
|
||||
_db.JiraIssues.Update(existing);
|
||||
isUpdated = true;
|
||||
_log.Debug("Updating existing Jira issue: {key}", issue.Key);
|
||||
}
|
||||
else
|
||||
@@ -131,6 +136,7 @@ public class AppDbService
|
||||
}
|
||||
|
||||
await _db.SaveChangesAsync(ct);
|
||||
return (isInserted, isUpdated);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -139,27 +145,29 @@ public class AppDbService
|
||||
}
|
||||
}
|
||||
|
||||
public async Task UpsertJiraIssuesBatchAsync(IEnumerable<JiraIssue> issues, CancellationToken ct = default)
|
||||
public async Task<(List<string> inserted, List<string> updated)> UpsertJiraIssuesBatchAsync(IEnumerable<JiraIssue> issues, CancellationToken ct = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
var issueList = issues.ToList();
|
||||
if (!issueList.Any())
|
||||
return;
|
||||
return (new List<string>(), new List<string>());
|
||||
|
||||
var keys = issueList.Select(i => i.Key).ToList();
|
||||
var existingIssues = await _db.JiraIssues
|
||||
.Where(ji => keys.Contains(ji.Key))
|
||||
.ToDictionaryAsync(ji => ji.Key, ct);
|
||||
|
||||
int insertCount = 0, updateCount = 0, skipCount = 0;
|
||||
var insertedKeys = new List<string>();
|
||||
var updatedKeys = new List<string>();
|
||||
int skipCount = 0;
|
||||
|
||||
foreach (var issue in issueList)
|
||||
{
|
||||
if (!existingIssues.TryGetValue(issue.Key, out var existing))
|
||||
{
|
||||
_db.JiraIssues.Add(issue);
|
||||
insertCount++;
|
||||
insertedKeys.Add(issue.Key);
|
||||
}
|
||||
else if (issue.Updated > existing.Updated)
|
||||
{
|
||||
@@ -175,7 +183,7 @@ public class AppDbService
|
||||
existing.NeedNotify = issue.NeedNotify;
|
||||
|
||||
_db.JiraIssues.Update(existing);
|
||||
updateCount++;
|
||||
updatedKeys.Add(issue.Key);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -185,7 +193,9 @@ public class AppDbService
|
||||
|
||||
await _db.SaveChangesAsync(ct);
|
||||
_log.Information("Batch completed: {insert} inserted, {update} updated, {skip} skipped out of {total} issues",
|
||||
insertCount, updateCount, skipCount, issueList.Count);
|
||||
insertedKeys.Count, updatedKeys.Count, skipCount, issueList.Count);
|
||||
|
||||
return (insertedKeys, updatedKeys);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -193,4 +203,5 @@ public class AppDbService
|
||||
throw;
|
||||
}
|
||||
}
|
||||
#endregion Table: JiraIssues
|
||||
}
|
||||
|
||||
@@ -16,9 +16,9 @@ public static class JiraIssueMapper
|
||||
Status = issue.fields.status?.description ?? string.Empty,
|
||||
Assignee = issue.fields.assignee?.displayName ?? string.Empty,
|
||||
Manager = issue.fields.reporter?.displayName ?? string.Empty,
|
||||
Due = issue.fields.duedate?.ToUniversalTime() ?? DateTimeOffset.MinValue,
|
||||
Updated = issue.fields.UpdatedAt,
|
||||
Published = DateTimeOffset.MinValue,
|
||||
Due = issue.fields.duedate?.ToUniversalTime() ?? DateTimeOffset.MinValue.ToUniversalTime(),
|
||||
Updated = issue.fields.UpdatedAt.ToUniversalTime(),
|
||||
Published = DateTimeOffset.MinValue.ToUniversalTime(),
|
||||
ObjectId = null,
|
||||
NeedNotify = 0
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user