dd
This commit is contained in:
parent
2a7f1816e4
commit
1233f40833
@ -392,26 +392,46 @@ namespace YD_AllHeartRates.Api.Mqtt
|
||||
foreach (var key in keys)
|
||||
{
|
||||
var data = _caching.Get<JumpRopeData>(key);
|
||||
|
||||
if (data == null || string.IsNullOrWhiteSpace(data.StudentNo)) continue;
|
||||
|
||||
var exist = await dbContext.JumpRopeData
|
||||
.FirstOrDefaultAsync(x => x.StudentNo == data.StudentNo && x.ScoreTime.Date == today);
|
||||
|
||||
if (exist != null && data.JumpValue > exist.JumpValue)
|
||||
if (exist != null)
|
||||
{
|
||||
if (data.JumpValue > exist.JumpValue)
|
||||
{
|
||||
exist.JumpValue = data.JumpValue;
|
||||
exist.ErrorNumber = data.ErrorNumber;
|
||||
exist.QuantityOfElectricity = data.QuantityOfElectricity;
|
||||
exist.ScoreTime = data.ScoreTime;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
dbContext.JumpRopeData.Add(data);
|
||||
}
|
||||
}
|
||||
|
||||
await dbContext.SaveChangesAsync();
|
||||
}
|
||||
catch (DbUpdateException ex)
|
||||
{
|
||||
// 如果是唯一约束冲突,说明有并发插入
|
||||
// 可以忽略或重试更新
|
||||
var existRetry = await dbContext.JumpRopeData
|
||||
.FirstOrDefaultAsync(x => x.StudentNo == data.StudentNo && x.ScoreTime.Date == today);
|
||||
|
||||
if (existRetry != null && data.JumpValue > existRetry.JumpValue)
|
||||
{
|
||||
existRetry.JumpValue = data.JumpValue;
|
||||
existRetry.ErrorNumber = data.ErrorNumber;
|
||||
existRetry.QuantityOfElectricity = data.QuantityOfElectricity;
|
||||
existRetry.ScoreTime = data.ScoreTime;
|
||||
await dbContext.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
_lastJumpRopeSaveTime = DateTime.Now;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
Loading…
x
Reference in New Issue
Block a user