完善秩序册导入
This commit is contained in:
parent
14e6d42c71
commit
22007f557c
@ -89,14 +89,15 @@ public static class NpoiExcelReader
|
|||||||
}
|
}
|
||||||
|
|
||||||
var result = new List<T>();
|
var result = new List<T>();
|
||||||
for (var rowIndex = headerRow.RowNum + 1; rowIndex <= sheet.LastRowNum; rowIndex++)
|
// LastRowNum 会被整表格式残留推到 1048576;只遍历实际存在的行对象。
|
||||||
|
var rowEnumerator = sheet.GetRowEnumerator();
|
||||||
|
while (rowEnumerator.MoveNext())
|
||||||
{
|
{
|
||||||
var row = sheet.GetRow(rowIndex);
|
if (rowEnumerator.Current is not IRow row || row.RowNum <= headerRow.RowNum) continue;
|
||||||
if (row == null) continue;
|
|
||||||
|
|
||||||
var item = new T();
|
var item = new T();
|
||||||
if (item is IExcelRowLocation rowLocation)
|
if (item is IExcelRowLocation rowLocation)
|
||||||
rowLocation.ExcelRowNumber = rowIndex + 1;
|
rowLocation.ExcelRowNumber = row.RowNum + 1;
|
||||||
var hasValue = false;
|
var hasValue = false;
|
||||||
foreach (var (columnIndex, property) in columnProperties)
|
foreach (var (columnIndex, property) in columnProperties)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -506,7 +506,7 @@ public class OrderBookService : IDynamicApiController, ITransient
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 按 项目×组别×场地 生成场次,返回组合键 -> 场次 的映射
|
// 按 项目×组别×场次名称×场地 生成场次,返回组合键 -> 场次 的映射
|
||||||
private async Task<Dictionary<OrderBookSessionKey, EventSession>> EnsureSessionsAsync(
|
private async Task<Dictionary<OrderBookSessionKey, EventSession>> EnsureSessionsAsync(
|
||||||
OrderBookDraft draft, long eventId,
|
OrderBookDraft draft, long eventId,
|
||||||
Dictionary<long, OrderBookProjectContext> projectContext,
|
Dictionary<long, OrderBookProjectContext> projectContext,
|
||||||
@ -518,7 +518,22 @@ public class OrderBookService : IDynamicApiController, ITransient
|
|||||||
.Distinct()
|
.Distinct()
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
|
var existSessions = await _sessionRepository.AsQueryable()
|
||||||
|
.Where(s => !s.DeleteMark && s.EventId == eventId)
|
||||||
|
.ToListAsync();
|
||||||
|
var venueNamesById = venueContext.ToDictionary(x => x.Value.Venue.Id, x => x.Key);
|
||||||
|
var existSessionsByKey = existSessions
|
||||||
|
.Where(s => venueNamesById.ContainsKey(s.VenueId))
|
||||||
|
.GroupBy(s => new OrderBookSessionKey(
|
||||||
|
s.EventProjectId,
|
||||||
|
s.EventProjectGroupId ?? 0,
|
||||||
|
s.SessionName ?? string.Empty,
|
||||||
|
venueNamesById[s.VenueId]))
|
||||||
|
.ToDictionary(x => x.Key, x => x.First());
|
||||||
|
|
||||||
var result = new Dictionary<OrderBookSessionKey, EventSession>();
|
var result = new Dictionary<OrderBookSessionKey, EventSession>();
|
||||||
|
var newSessions = new List<EventSession>();
|
||||||
|
var usedSessionNos = existSessions.Select(s => s.SessionNo).ToHashSet(StringComparer.Ordinal);
|
||||||
var sessionSort = 0;
|
var sessionSort = 0;
|
||||||
foreach (var combo in combos)
|
foreach (var combo in combos)
|
||||||
{
|
{
|
||||||
@ -526,12 +541,7 @@ public class OrderBookService : IDynamicApiController, ITransient
|
|||||||
var vc = venueContext[combo.VenueName];
|
var vc = venueContext[combo.VenueName];
|
||||||
var groupId = combo.EventProjectGroupId;
|
var groupId = combo.EventProjectGroupId;
|
||||||
|
|
||||||
var exist = await _sessionRepository.GetFirstAsync(s =>
|
if (existSessionsByKey.TryGetValue(combo, out var exist))
|
||||||
!s.DeleteMark && s.EventId == eventId &&
|
|
||||||
s.EventProjectId == pc.EventProjectId && s.VenueId == vc.Venue.Id &&
|
|
||||||
s.SessionName == combo.SessionName &&
|
|
||||||
s.EventProjectGroupId == groupId);
|
|
||||||
if (exist != null)
|
|
||||||
{
|
{
|
||||||
if (exist.ScoreRuleId != pc.ScoreRuleId)
|
if (exist.ScoreRuleId != pc.ScoreRuleId)
|
||||||
throw Oops.Bah($"场次【{combo.SessionName}】的规则与导入项目不一致,请先核查历史编排");
|
throw Oops.Bah($"场次【{combo.SessionName}】的规则与导入项目不一致,请先核查历史编排");
|
||||||
@ -539,7 +549,13 @@ public class OrderBookService : IDynamicApiController, ITransient
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
sessionSort++;
|
string sessionNo;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
sessionSort++;
|
||||||
|
sessionNo = $"EP{pc.EventProjectId}-V{vc.Index:00}-{sessionSort:000}";
|
||||||
|
} while (!usedSessionNos.Add(sessionNo));
|
||||||
|
|
||||||
var session = new EventSession
|
var session = new EventSession
|
||||||
{
|
{
|
||||||
Id = _idGenerator.NextId(),
|
Id = _idGenerator.NextId(),
|
||||||
@ -548,7 +564,7 @@ public class OrderBookService : IDynamicApiController, ITransient
|
|||||||
EventProjectGroupId = groupId,
|
EventProjectGroupId = groupId,
|
||||||
VenueId = vc.Venue.Id,
|
VenueId = vc.Venue.Id,
|
||||||
ScoreRuleId = pc.ScoreRuleId,
|
ScoreRuleId = pc.ScoreRuleId,
|
||||||
SessionNo = $"EP{pc.EventProjectId}-V{vc.Index:00}-{sessionSort:000}",
|
SessionNo = sessionNo,
|
||||||
SessionName = combo.SessionName,
|
SessionName = combo.SessionName,
|
||||||
SessionStatus = 0,
|
SessionStatus = 0,
|
||||||
Version = 1,
|
Version = 1,
|
||||||
@ -556,9 +572,12 @@ public class OrderBookService : IDynamicApiController, ITransient
|
|||||||
CreatedUserId = userId,
|
CreatedUserId = userId,
|
||||||
CreatedTime = now
|
CreatedTime = now
|
||||||
};
|
};
|
||||||
await _sessionRepository.InsertAsync(session);
|
newSessions.Add(session);
|
||||||
result[combo] = session;
|
result[combo] = session;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (newSessions.Any())
|
||||||
|
await _sessionRepository.InsertRangeAsync(newSessions);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user