From fd317c643b7a2fe318033dcb1826c01cb692b39a Mon Sep 17 00:00:00 2001 From: liguoyang Date: Thu, 11 Apr 2024 14:41:49 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BB=A3=E7=A0=81=E5=A4=8D=E6=9D=82?= =?UTF-8?q?=E5=BA=A6=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/CanteenSettingService.cs | 3 +- .../Services/Implements/AssignmentService.cs | 222 +++++++++--------- 2 files changed, 107 insertions(+), 118 deletions(-) diff --git a/Src/Dlhis.Canteen/Setting/Services/Implements/CanteenSettingService.cs b/Src/Dlhis.Canteen/Setting/Services/Implements/CanteenSettingService.cs index 52685889..81eb9088 100644 --- a/Src/Dlhis.Canteen/Setting/Services/Implements/CanteenSettingService.cs +++ b/Src/Dlhis.Canteen/Setting/Services/Implements/CanteenSettingService.cs @@ -87,8 +87,7 @@ public class CanteenSettingService : ICanteenSettingService var settings = await _context.Queryable() .Where(x => x.Enable) .Where(x => x.TenantId == tenantId) - .Where(x => (x.UniqueType == CanteenSettingUnqiueEnumType.Person && x.UniqueValue == userNo) - || x.UniqueType == CanteenSettingUnqiueEnumType.Tenant) + .Where(x => (x.UniqueType == CanteenSettingUnqiueEnumType.Person && x.UniqueValue == userNo) || x.UniqueType == CanteenSettingUnqiueEnumType.Tenant) .ToListAsync(); //从基地 -> 个人,确保下面循环做到覆盖,并且以个人配置为主 diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/AssignmentService.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/AssignmentService.cs index 7ee84f62..6932bf71 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/AssignmentService.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/AssignmentService.cs @@ -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 _logger; - private readonly RedisCache _redisCache; - public AssignmentService(IDbContext dbContext, ILogger logger, RedisCache redisCache) + public AssignmentService(IDbContext dbContext, + IDataProtectionProvider dataProtectionProvider, + IOptions options, + ILogger logger) { _dbContext = dbContext; + _dataProtectionProvider = dataProtectionProvider; + _faceUrlOptions = options.Value; _logger = logger; - _redisCache = redisCache; } public async Task> DeviceGetTasksAsync(DeviceTaskGetRequest request) @@ -78,7 +79,7 @@ public class AssignmentService : IAssignmentService } var taskIdVs = page.Data.Select(x => new { x.TaskId, x.Version }).ToList(); - Expression> where = LinqExpressionExtensions.False(); + var where = LinqExpressionExtensions.False(); 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().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>().Value; - var dataProtectionProvider = sp.GetService(); + 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 { 1 }, - Doors = new List { 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 { 1 }, + Doors = new List { 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() { - Id = 1, - Name = "小白领", - Enable = true, - Sections = new List() - { 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 { - Id = 1, - Enable = true, - Name = "计划的一部分", - Schedules = new List - { 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(); } ///