fix null操作异常

This commit is contained in:
2025-01-16 12:30:30 +08:00
parent d817ba03ce
commit fe8971de95

View File

@@ -194,42 +194,42 @@ public class AssignmentService : IAssignmentService
task.ModifiedTime = now; task.ModifiedTime = now;
}); });
if (await _dbContext.Queryable<OldDeviceGainfoEntity>().Where(x => x.Status != OldDeviceGainfoEnumType.Deleted).AnyAsync()) // if (await _dbContext.Queryable<OldDeviceGainfoEntity>().Where(x => x.Status != OldDeviceGainfoEnumType.Deleted).AnyAsync())
{ // {
var dCodes = await _dbContext.Queryable<DeviceTaskEntity>() // var dCodes = await _dbContext.Queryable<DeviceTaskEntity>()
.LeftJoin<GainfoEntity>((x, ga) => x.UserNo == ga.No) // .LeftJoin<GainfoEntity>((x, ga) => x.UserNo == ga.No)
.Where(x => taskIds.Contains(x.Id)) // .Where(x => taskIds.Contains(x.Id))
.Where(x => x.Status == DeviceTaskStatusEnumType.Process) // .Where(x => x.Status == DeviceTaskStatusEnumType.Process)
.Select((x, ga) => new // .Select((x, ga) => new
{ // {
x.DeviceUniqueNo, // x.DeviceUniqueNo,
ga.Code, // ga.Code,
ga.No // ga.No
}) // })
.ToListAsync(); // .ToListAsync();
//
var oldDeviceGainfoWhere = LinqExpressionExtensions.False<OldDeviceGainfoEntity>(); // var oldDeviceGainfoWhere = LinqExpressionExtensions.False<OldDeviceGainfoEntity>();
dCodes.ForEach(item => { oldDeviceGainfoWhere = oldDeviceGainfoWhere.Or(x => x.Code == item.Code && x.DeviceUniqueNo == item.DeviceUniqueNo); }); // dCodes.ForEach(item => { oldDeviceGainfoWhere = oldDeviceGainfoWhere.Or(x => x.Code == item.Code && x.DeviceUniqueNo == item.DeviceUniqueNo); });
var oldData = await _dbContext.Queryable<OldDeviceGainfoEntity>().Where(x => x.Status == OldDeviceGainfoEnumType.Wait) // var oldData = await _dbContext.Queryable<OldDeviceGainfoEntity>().Where(x => x.Status == OldDeviceGainfoEnumType.Wait)
.Where(oldDeviceGainfoWhere) // .Where(oldDeviceGainfoWhere)
.ToListAsync(); // .ToListAsync();
//
oldData.ForEach(d => // oldData.ForEach(d =>
{ // {
var current = dCodes.First(x => x.Code == d.Code); // var current = dCodes.First(x => x.Code == d.Code);
var task = deviceTasks.FirstOrDefault(x => x.UserNo == current.No && x.DeviceUniqueNo == current.DeviceUniqueNo); // var task = deviceTasks.FirstOrDefault(x => x.UserNo == current.No && x.DeviceUniqueNo == current.DeviceUniqueNo);
if (task != null) // if (task != null)
{ // {
d.Status = task.Status == DeviceTaskStatusEnumType.Success // d.Status = task.Status == DeviceTaskStatusEnumType.Success
? OldDeviceGainfoEnumType.Deleted // ? OldDeviceGainfoEnumType.Deleted
: OldDeviceGainfoEnumType.Error; // : OldDeviceGainfoEnumType.Error;
//
d.Remark = task.ResultMessage; // d.Remark = task.ResultMessage;
} // }
}); // });
//
await _dbContext.UpdateAsync(oldData); // await _dbContext.UpdateAsync(oldData);
} // }
await _dbContext.UpdateAsync(deviceTasks); await _dbContext.UpdateAsync(deviceTasks);
@@ -409,7 +409,7 @@ public class AssignmentService : IAssignmentService
{ {
try try
{ {
var tasks = data.Where(x => x.EnableTimePeriod).Where(x => x.Type is DeviceTaskEnumType.TimePeriodAdd or DeviceTaskEnumType.TimePeriodDelete).ToList(); var tasks = data.Where(x => x.Type is DeviceTaskEnumType.TimePeriodAdd or DeviceTaskEnumType.TimePeriodDelete).ToList();
if (tasks.IsEmpty()) return; if (tasks.IsEmpty()) return;
var deviceUniqueNos = tasks.Select(x => x.DeviceUniqueNo).ToList(); var deviceUniqueNos = tasks.Select(x => x.DeviceUniqueNo).ToList();