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;
});
if (await _dbContext.Queryable<OldDeviceGainfoEntity>().Where(x => x.Status != OldDeviceGainfoEnumType.Deleted).AnyAsync())
{
var dCodes = await _dbContext.Queryable<DeviceTaskEntity>()
.LeftJoin<GainfoEntity>((x, ga) => x.UserNo == ga.No)
.Where(x => taskIds.Contains(x.Id))
.Where(x => x.Status == DeviceTaskStatusEnumType.Process)
.Select((x, ga) => new
{
x.DeviceUniqueNo,
ga.Code,
ga.No
})
.ToListAsync();
var oldDeviceGainfoWhere = LinqExpressionExtensions.False<OldDeviceGainfoEntity>();
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)
.Where(oldDeviceGainfoWhere)
.ToListAsync();
oldData.ForEach(d =>
{
var current = dCodes.First(x => x.Code == d.Code);
var task = deviceTasks.FirstOrDefault(x => x.UserNo == current.No && x.DeviceUniqueNo == current.DeviceUniqueNo);
if (task != null)
{
d.Status = task.Status == DeviceTaskStatusEnumType.Success
? OldDeviceGainfoEnumType.Deleted
: OldDeviceGainfoEnumType.Error;
d.Remark = task.ResultMessage;
}
});
await _dbContext.UpdateAsync(oldData);
}
// if (await _dbContext.Queryable<OldDeviceGainfoEntity>().Where(x => x.Status != OldDeviceGainfoEnumType.Deleted).AnyAsync())
// {
// var dCodes = await _dbContext.Queryable<DeviceTaskEntity>()
// .LeftJoin<GainfoEntity>((x, ga) => x.UserNo == ga.No)
// .Where(x => taskIds.Contains(x.Id))
// .Where(x => x.Status == DeviceTaskStatusEnumType.Process)
// .Select((x, ga) => new
// {
// x.DeviceUniqueNo,
// ga.Code,
// ga.No
// })
// .ToListAsync();
//
// var oldDeviceGainfoWhere = LinqExpressionExtensions.False<OldDeviceGainfoEntity>();
// 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)
// .Where(oldDeviceGainfoWhere)
// .ToListAsync();
//
// oldData.ForEach(d =>
// {
// var current = dCodes.First(x => x.Code == d.Code);
// var task = deviceTasks.FirstOrDefault(x => x.UserNo == current.No && x.DeviceUniqueNo == current.DeviceUniqueNo);
// if (task != null)
// {
// d.Status = task.Status == DeviceTaskStatusEnumType.Success
// ? OldDeviceGainfoEnumType.Deleted
// : OldDeviceGainfoEnumType.Error;
//
// d.Remark = task.ResultMessage;
// }
// });
//
// await _dbContext.UpdateAsync(oldData);
// }
await _dbContext.UpdateAsync(deviceTasks);
@@ -409,7 +409,7 @@ public class AssignmentService : IAssignmentService
{
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;
var deviceUniqueNos = tasks.Select(x => x.DeviceUniqueNo).ToList();