fix 代码复杂度调整
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
using Dlhis.Entity.Basic.Entity;
|
||||
using Dlhis.Entity.Device.Entities;
|
||||
using Dlhis.Entity.Device.Enums;
|
||||
using System.Linq.Expressions;
|
||||
using Dlhis.ScheduledTask.TaskAssignment.Request;
|
||||
using Dlhis.ScheduledTask.TaskAssignment.Response;
|
||||
using Kurisu.AspNetCore.Scope;
|
||||
using Kurisu.AspNetCore.Utils.Extensions;
|
||||
using Kurisu.SqlSugar.Services;
|
||||
using Microsoft.AspNetCore.DataProtection;
|
||||
@@ -14,22 +12,25 @@ using Kurisu.SqlSugar.Extensions;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Kurisu.Core.CustomClass;
|
||||
using Kurisu.AspNetCore;
|
||||
using Kurisu.AspNetCore.Utils;
|
||||
using Org.BouncyCastle.Asn1.Ocsp;
|
||||
|
||||
namespace Dlhis.ScheduledTask.TaskAssignment.Services.Implements;
|
||||
|
||||
public class AssignmentService : IAssignmentService
|
||||
{
|
||||
private readonly IDbContext _dbContext;
|
||||
private readonly IDataProtectionProvider _dataProtectionProvider;
|
||||
private readonly FaceUrlOptions _faceUrlOptions;
|
||||
private readonly ILogger<AssignmentService> _logger;
|
||||
private readonly RedisCache _redisCache;
|
||||
|
||||
public AssignmentService(IDbContext dbContext, ILogger<AssignmentService> logger, RedisCache redisCache)
|
||||
public AssignmentService(IDbContext dbContext,
|
||||
IDataProtectionProvider dataProtectionProvider,
|
||||
IOptions<FaceUrlOptions> options,
|
||||
ILogger<AssignmentService> logger)
|
||||
{
|
||||
_dbContext = dbContext;
|
||||
_dataProtectionProvider = dataProtectionProvider;
|
||||
_faceUrlOptions = options.Value;
|
||||
_logger = logger;
|
||||
_redisCache = redisCache;
|
||||
}
|
||||
|
||||
public async Task<List<DeviceTaskToDeviceByDeviceResponse>> DeviceGetTasksAsync(DeviceTaskGetRequest request)
|
||||
@@ -78,7 +79,7 @@ public class AssignmentService : IAssignmentService
|
||||
}
|
||||
|
||||
var taskIdVs = page.Data.Select(x => new { x.TaskId, x.Version }).ToList();
|
||||
Expression<Func<DeviceTaskEntity, bool>> where = LinqExpressionExtensions.False<DeviceTaskEntity>();
|
||||
var where = LinqExpressionExtensions.False<DeviceTaskEntity>();
|
||||
taskIdVs.ForEach(p =>
|
||||
{
|
||||
where = where.Or(x => x.Id == p.TaskId && x.Version == p.Version && x.Status != DeviceTaskStatusEnumType.Success);
|
||||
@@ -91,10 +92,7 @@ public class AssignmentService : IAssignmentService
|
||||
.Where(where)
|
||||
.ExecuteCommandAsync();
|
||||
|
||||
if (taskIdVs.Count != effecet)
|
||||
{
|
||||
throw new VersionExceptions("更新错误");
|
||||
}
|
||||
(taskIdVs.Count != effecet).ThrowIfTrue("获取任务失败");
|
||||
|
||||
return page.Data;
|
||||
|
||||
@@ -113,12 +111,12 @@ public class AssignmentService : IAssignmentService
|
||||
|
||||
var logInfos = await _dbContext.Queryable<DeviceUploadLogEntity>().Select(it => new
|
||||
{
|
||||
Index2 = SqlFunc.RowNumber(SqlFunc.Desc(it.Id), it.DeviceUniqueNo),
|
||||
RowNumber = SqlFunc.RowNumber(SqlFunc.Desc(it.Id), it.DeviceUniqueNo),
|
||||
it.DeviceUniqueNo,
|
||||
it.RaiseDateTime
|
||||
})
|
||||
.MergeTable()
|
||||
.Where(it => it.Index2 == 1)
|
||||
.Where(it => it.RowNumber == 1)
|
||||
.ToListAsync();
|
||||
|
||||
foreach (var item in deviceNos)
|
||||
@@ -128,86 +126,79 @@ public class AssignmentService : IAssignmentService
|
||||
}
|
||||
}
|
||||
|
||||
//申请新的请求域
|
||||
return Scoped.Request.Value.Create((sp) =>
|
||||
{
|
||||
var faceUrlOptions = sp.GetService<IOptions<FaceUrlOptions>>().Value;
|
||||
var dataProtectionProvider = sp.GetService<IDataProtectionProvider>();
|
||||
var timeLimitedDataProtector = _dataProtectionProvider
|
||||
.CreateProtector("down:face")
|
||||
.ToTimeLimitedDataProtector();
|
||||
|
||||
var timeLimitedDataProtector = dataProtectionProvider
|
||||
.CreateProtector("down:face")
|
||||
.ToTimeLimitedDataProtector();
|
||||
return data.GroupBy(x => new { x.Brand, x.DeviceUniqueNo, x.DeviceConnectionInfo, x.FuncStr })
|
||||
.Select(x =>
|
||||
{
|
||||
var b = x.Key.Brand;
|
||||
var d = x.Key.DeviceUniqueNo;
|
||||
var dc = x.Key.DeviceConnectionInfo ?? "{}";
|
||||
var func = x.Key.FuncStr ?? "[]";
|
||||
|
||||
return data.GroupBy(x => new { x.Brand, x.DeviceUniqueNo, x.DeviceConnectionInfo, x.FuncStr })
|
||||
.Select(x =>
|
||||
var jobj = new JObject
|
||||
{
|
||||
var b = x.Key.Brand;
|
||||
var d = x.Key.DeviceUniqueNo;
|
||||
var dc = x.Key.DeviceConnectionInfo ?? "{}";
|
||||
var func = x.Key.FuncStr ?? "[]";
|
||||
|
||||
var jobj = new JObject
|
||||
{
|
||||
{ "connectionInfo", JToken.Parse(dc) },
|
||||
{ "function", JArray.Parse(func) }
|
||||
};
|
||||
};
|
||||
|
||||
return new DeviceTaskToDeviceByDeviceResponse
|
||||
return new DeviceTaskToDeviceByDeviceResponse
|
||||
{
|
||||
Brand = b,
|
||||
DeviceUniqueNo = d,
|
||||
DeviceInfo = jobj,
|
||||
Tasks = x.AsEnumerable().Select(item =>
|
||||
{
|
||||
Brand = b,
|
||||
DeviceUniqueNo = d,
|
||||
DeviceInfo = jobj,
|
||||
Tasks = x.AsEnumerable().Select(item =>
|
||||
var key = $"face:{item.UserCode}";
|
||||
var token = item.Type == DeviceTaskEnumType.Delete
|
||||
? string.Empty
|
||||
: timeLimitedDataProtector.Protect(key, TimeSpan.FromSeconds(_faceUrlOptions.Limit));
|
||||
|
||||
var dto = new TaskCombineDto
|
||||
{
|
||||
var key = $"face:{item.UserCode}";
|
||||
var token = item.Type == DeviceTaskEnumType.Delete
|
||||
? string.Empty
|
||||
: timeLimitedDataProtector.Protect(key, TimeSpan.FromSeconds(faceUrlOptions.Limit));
|
||||
TaskId = item.TaskId,
|
||||
Type = item.Type,
|
||||
};
|
||||
|
||||
var dto = new TaskCombineDto
|
||||
{
|
||||
TaskId = item.TaskId,
|
||||
Type = item.Type,
|
||||
};
|
||||
|
||||
|
||||
switch (dto.Type)
|
||||
{
|
||||
case DeviceTaskEnumType.Add:
|
||||
case DeviceTaskEnumType.Delete:
|
||||
case DeviceTaskEnumType.Update:
|
||||
switch (dto.Type)
|
||||
{
|
||||
case DeviceTaskEnumType.Add:
|
||||
case DeviceTaskEnumType.Delete:
|
||||
case DeviceTaskEnumType.Update:
|
||||
{
|
||||
dto.Info = new UserToDeviceResponse
|
||||
{
|
||||
dto.Info = new UserToDeviceResponse
|
||||
UserId = item.UserId.Value,
|
||||
UserNo = item.UserNo,
|
||||
UserCode = item.UserCode,
|
||||
UserName = item.UserName,
|
||||
DepartmentNo = item.DepartmentNo,
|
||||
DepartmentName = item.DepartmentName,
|
||||
CardNo = item.Type == DeviceTaskEnumType.Delete ? string.Empty : item.CardNo,
|
||||
Face = item.Type == DeviceTaskEnumType.Delete ? string.Empty : _faceUrlOptions.Url + token,//下发才附带照片信息
|
||||
ValidDatePeriod = new DatePeriod
|
||||
{
|
||||
UserId = item.UserId.Value,
|
||||
UserNo = item.UserNo,
|
||||
UserCode = item.UserCode,
|
||||
UserName = item.UserName,
|
||||
DepartmentNo = item.DepartmentNo,
|
||||
DepartmentName = item.DepartmentName,
|
||||
CardNo = item.Type == DeviceTaskEnumType.Delete ? string.Empty : item.CardNo,
|
||||
Face = item.Type == DeviceTaskEnumType.Delete ? string.Empty : faceUrlOptions.Url + token,//下发才附带照片信息
|
||||
ValidDatePeriod = new DatePeriod
|
||||
{
|
||||
Start = DateOnly.FromDateTime(DateTime.Now.AddDays(-1)),
|
||||
End = DateOnly.FromDateTime(DateTime.Now.AddYears(20)),
|
||||
},
|
||||
TimePeriods = new List<int> { 1 },
|
||||
Doors = new List<int> { 1 },
|
||||
Schedule = 1
|
||||
};
|
||||
}
|
||||
break;
|
||||
case DeviceTaskEnumType.TimePeriodAdd:
|
||||
case DeviceTaskEnumType.TimePeriodDelete:
|
||||
Start = DateOnly.FromDateTime(DateTime.Now.AddDays(-1)),
|
||||
End = DateOnly.FromDateTime(DateTime.Now.AddYears(20)),
|
||||
},
|
||||
TimePeriods = new List<int> { 1 },
|
||||
Doors = new List<int> { 1 },
|
||||
Schedule = 1
|
||||
};
|
||||
}
|
||||
break;
|
||||
case DeviceTaskEnumType.TimePeriodAdd:
|
||||
case DeviceTaskEnumType.TimePeriodDelete:
|
||||
{
|
||||
dto.Info = new TimePeriodToDeviceResponse
|
||||
{
|
||||
dto.Info = new TimePeriodToDeviceResponse
|
||||
Id = 1,
|
||||
Name = "小白领",
|
||||
Enable = true,
|
||||
Sections = new List<TimePeriodWeekDaySection>()
|
||||
{
|
||||
Id = 1,
|
||||
Name = "小白领",
|
||||
Enable = true,
|
||||
Sections = new List<TimePeriodWeekDaySection>()
|
||||
{
|
||||
new()
|
||||
{
|
||||
DayOfWeek= DayOfWeek.Monday,
|
||||
@@ -220,20 +211,20 @@ public class AssignmentService : IAssignmentService
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
break;
|
||||
case DeviceTaskEnumType.ScheduleAdd:
|
||||
case DeviceTaskEnumType.ScheduleDelete:
|
||||
}
|
||||
};
|
||||
}
|
||||
break;
|
||||
case DeviceTaskEnumType.ScheduleAdd:
|
||||
case DeviceTaskEnumType.ScheduleDelete:
|
||||
{
|
||||
dto.Info = new ScheduleToDeviceResponse
|
||||
{
|
||||
dto.Info = new ScheduleToDeviceResponse
|
||||
Id = 1,
|
||||
Enable = true,
|
||||
Name = "计划的一部分",
|
||||
Schedules = new List<ScheduleDto>
|
||||
{
|
||||
Id = 1,
|
||||
Enable = true,
|
||||
Name = "计划的一部分",
|
||||
Schedules = new List<ScheduleDto>
|
||||
{
|
||||
new()
|
||||
{
|
||||
Name = "国庆节",
|
||||
@@ -243,34 +234,33 @@ public class AssignmentService : IAssignmentService
|
||||
End = new DateTime(2024,10,7)
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
break;
|
||||
}
|
||||
};
|
||||
}
|
||||
break;
|
||||
|
||||
case DeviceTaskEnumType.UploadRecord:
|
||||
case DeviceTaskEnumType.UploadRecord:
|
||||
{
|
||||
dto.Info = new UploadRecordToDeviceResponse
|
||||
{
|
||||
dto.Info = new UploadRecordToDeviceResponse
|
||||
DateTimePeriod = new DateTimePeriod
|
||||
{
|
||||
DateTimePeriod = new DateTimePeriod
|
||||
{
|
||||
Start = deviceUploadInfos[d] ?? DateTime.Now,
|
||||
End = DateTime.Now.AddDays(1)
|
||||
}
|
||||
};
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
Start = deviceUploadInfos[d] ?? DateTime.Now,
|
||||
End = DateTime.Now.AddDays(1)
|
||||
}
|
||||
};
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return dto;
|
||||
})
|
||||
.ToList()
|
||||
};
|
||||
return dto;
|
||||
|
||||
}).ToList();
|
||||
});
|
||||
}).ToList()
|
||||
};
|
||||
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user