diff --git a/Src/Dlhis.Basic/Device/Request/DeviceHeartbeatRequest.cs b/Src/Dlhis.Basic/Device/Request/DeviceHeartbeatRequest.cs index 2ca25f0a..9bc6b216 100644 --- a/Src/Dlhis.Basic/Device/Request/DeviceHeartbeatRequest.cs +++ b/Src/Dlhis.Basic/Device/Request/DeviceHeartbeatRequest.cs @@ -1,7 +1,12 @@ -namespace Dlhis.Basic.Device.Request +using System.ComponentModel.DataAnnotations; + +namespace Dlhis.Basic.Device.Request; + +public class DeviceHeartbeatRequest { - public class DeviceHeartbeatRequest - { - public string UniqueNo { get; set; } - } + /// + /// 设备唯一号 + /// + [Required(ErrorMessage = "设备唯一号")] + public string UniqueNo { get; set; } } diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceConnectService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceConnectService.cs index 0b47a842..75559b76 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceConnectService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceConnectService.cs @@ -82,10 +82,11 @@ public class DeviceConnectService : IDeviceConnectService //todo 通知设备重新获取 } + [IgnoreTenant] public async Task HeartbeatAsync(DeviceHeartbeatRequest request) { var registry = await _dbContext.Queryable().Where(x => x.DeviceUniqueNo == request.UniqueNo).FirstAsync(); - registry.ThrowIfNull($"{request.UniqueNo}的设备注册信息不存在,心跳无效"); + registry.ThrowIfNull($"注册信息不存在,无法发起心跳"); registry.LastHeartbeatTime = DateTime.Now; await _dbContext.UpdateAsync(registry); diff --git a/Src/Dlhis.Basic/Dlhis.Basic.csproj b/Src/Dlhis.Basic/Dlhis.Basic.csproj index 5068697a..507dbc49 100644 --- a/Src/Dlhis.Basic/Dlhis.Basic.csproj +++ b/Src/Dlhis.Basic/Dlhis.Basic.csproj @@ -17,7 +17,7 @@ - + diff --git a/Src/Dlhis.Basic/Organization/Controllers/GainfosController.cs b/Src/Dlhis.Basic/Organization/Controllers/GainfosController.cs index 816456e7..6167d106 100644 --- a/Src/Dlhis.Basic/Organization/Controllers/GainfosController.cs +++ b/Src/Dlhis.Basic/Organization/Controllers/GainfosController.cs @@ -94,7 +94,7 @@ public class GainfosController : ControllerBase /// 上传人脸照片 /// /// - [HttpPost("face")] + [HttpPost("face")] public async Task UploadFaceAsync(GainfoUploadFaceRequest request) { await _gainfoService.UploadFaceAsync(request); diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs index 0ff54cbf..3bb56197 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs @@ -11,6 +11,7 @@ using Kurisu.Core.DataAccess.Dto; using Kurisu.Core.User.Abstractions; using Kurisu.SqlSugar.Attributes; using Kurisu.SqlSugar.Extensions; +using Kurisu.SqlSugar.Options; using Kurisu.SqlSugar.Services; using Mapster; using Microsoft.AspNetCore.DataProtection; @@ -159,44 +160,46 @@ public class GainfoService : IGainfoService return gainfo; } - - //-------------------------------------------help methods ------------------------------------------------ - - /// - /// 递归获取部门No - /// - /// - /// - private async Task> GetRecursionDepartmentNosAsync(List departmentNos) + public async Task GetFaceAsync(string token) { - if (departmentNos == null || departmentNos.Count == 0) + return await Scoped.Request.Value.CreateAsync(async (sp) => { - return new List(); - } + var timeLimitedDataProtector = sp.GetService() + .CreateProtector("down:face") + .ToTimeLimitedDataProtector(); - var departments = await _dbContext.Queryable().ToListAsync(); - var currentNos = departments.Where(x => departmentNos.Contains(x.No)).ToList(); - - foreach (var item in currentNos) - { - RecursionGetNext(item.No, departments, departmentNos); - } - - return departmentNos.Distinct().ToList(); - - void RecursionGetNext(string currentCode, List departments, List result) - { - var next = departments.Where(x => x.PNo == currentCode).ToList(); - foreach (var item in next) + try { - result.Add(item.No); - } + var password = timeLimitedDataProtector.Unprotect(token); + var userCode = password.Split(':')[1]; - foreach (var item in next) - { - RecursionGetNext(item.No, departments, result); + var configuration = sp.GetService(); + var faceConnectionString = configuration.GetSection("SqlSugarOptions:FaceConnectionString").Value; + if (faceConnectionString.IsEmpty()) + { + _logger.LogWarning("暂不支持获取人脸"); + return new NotFoundResult(); + } + + //todo 切换连接字符串 + var dbContext = sp.GetService(); + dbContext.Client.CurrentConnectionConfig.ConnectionString = faceConnectionString; + var face = await dbContext.Queryable().Where(x => x.UserCode == userCode).SingleAsync(); + + if (face == null) + { + _logger.LogWarning("学工号:{userCode}不存在人脸照片", userCode); + return new NotFoundResult(); + } + + return new FileContentResult(Convert.FromBase64String(face.Face), "image/png"); } - } + catch (Exception ex) + { + _logger.LogError(ex, "获取人脸失败:" + ex.Message); + return new NotFoundResult(); + } + }); } public async Task UploadFaceAsync(GainfoUploadFaceRequest request) @@ -248,45 +251,7 @@ public class GainfoService : IGainfoService }); } - public async Task GetFaceAsync(string token) - { - return await Scoped.Request.Value.CreateAsync(async (sp) => - { - var timeLimitedDataProtector = sp.GetService() - .CreateProtector("down:face") - .ToTimeLimitedDataProtector(); - try - { - var password = timeLimitedDataProtector.Unprotect(token); - var userCode = password.Split(':')[1]; - - var configuration = sp.GetService(); - var faceConnectionString = configuration.GetSection("SqlSugarOptions:FaceConnectionString").Value; - if (faceConnectionString.IsEmpty()) - { - throw new UserFriendlyException("暂不支持获取人脸"); - } - - var dbContext = sp.GetService(); - //todo 切换连接字符串 - dbContext.Client.CurrentConnectionConfig.ConnectionString = faceConnectionString; - var face = await dbContext.Queryable().Where(x => x.UserCode == userCode).SingleAsync(); - - if (face == null) - { - return new NotFoundResult(); - } - - return new FileContentResult(Convert.FromBase64String(face.Face), "image/png"); - - } - catch (Exception) - { - return new NotFoundResult(); - } - }); - } public async Task GetFaceByUserCodeAsync(string userCode) { @@ -297,7 +262,7 @@ public class GainfoService : IGainfoService { var configuration = sp.GetService(); - var faceConnectionString = configuration.GetSection("SqlSugarOptions:FaceConnectionString").Value; + var faceConnectionString = configuration.GetSection($"{nameof(SqlSugarOptions)}:FaceConnectionString").Value; if (faceConnectionString.IsEmpty()) { throw new UserFriendlyException("暂不支持获取人脸"); @@ -327,6 +292,7 @@ public class GainfoService : IGainfoService return faceUrl + token; }); } + public async Task> GetFaceByUserCodesAsync(GetFaceByUserCodesRequest request) { var faceDictionary = new Dictionary(); @@ -338,4 +304,44 @@ public class GainfoService : IGainfoService } return faceDictionary; } + + + //-------------------------------------------help methods ------------------------------------------------ + + /// + /// 递归获取部门No + /// + /// + /// + private async Task> GetRecursionDepartmentNosAsync(List departmentNos) + { + if (departmentNos == null || departmentNos.Count == 0) + { + return new List(); + } + + var departments = await _dbContext.Queryable().ToListAsync(); + var currentNos = departments.Where(x => departmentNos.Contains(x.No)).ToList(); + + foreach (var item in currentNos) + { + RecursionGetNext(item.No, departments, departmentNos); + } + + return departmentNos.Distinct().ToList(); + + void RecursionGetNext(string currentCode, List departments, List result) + { + var next = departments.Where(x => x.PNo == currentCode).ToList(); + foreach (var item in next) + { + result.Add(item.No); + } + + foreach (var item in next) + { + RecursionGetNext(item.No, departments, result); + } + } + } } diff --git a/Src/Dlhis.Basic/Properties/launchSettings.json b/Src/Dlhis.Basic/Properties/launchSettings.json index 2321b0e1..d18d6e46 100644 --- a/Src/Dlhis.Basic/Properties/launchSettings.json +++ b/Src/Dlhis.Basic/Properties/launchSettings.json @@ -7,7 +7,7 @@ "ASPNETCORE_ENVIRONMENT": "Development" }, "dotnetRunMessages": true, - "applicationUrl": "http://localhost:5002" + "applicationUrl": "http://*:5002" } }, "$schema": "https://json.schemastore.org/launchsettings.json" diff --git a/Src/Dlhis.Canteen/Dlhis.Canteen.csproj b/Src/Dlhis.Canteen/Dlhis.Canteen.csproj index aea8e0df..36fc7e42 100644 --- a/Src/Dlhis.Canteen/Dlhis.Canteen.csproj +++ b/Src/Dlhis.Canteen/Dlhis.Canteen.csproj @@ -35,7 +35,7 @@ - + diff --git a/Src/Dlhis.Common/Dlhis.Common.csproj b/Src/Dlhis.Common/Dlhis.Common.csproj index 858c0607..484aa417 100644 --- a/Src/Dlhis.Common/Dlhis.Common.csproj +++ b/Src/Dlhis.Common/Dlhis.Common.csproj @@ -25,7 +25,7 @@ - + diff --git a/Src/Dlhis.ScheduledTask/Dlhis.ScheduledTask.csproj b/Src/Dlhis.ScheduledTask/Dlhis.ScheduledTask.csproj index 4036554b..b93d3f71 100644 --- a/Src/Dlhis.ScheduledTask/Dlhis.ScheduledTask.csproj +++ b/Src/Dlhis.ScheduledTask/Dlhis.ScheduledTask.csproj @@ -20,9 +20,8 @@ - + - diff --git a/Src/Dlhis.ScheduledTask/Properties/launchSettings.json b/Src/Dlhis.ScheduledTask/Properties/launchSettings.json index fd368e29..a6ea1802 100644 --- a/Src/Dlhis.ScheduledTask/Properties/launchSettings.json +++ b/Src/Dlhis.ScheduledTask/Properties/launchSettings.json @@ -5,7 +5,7 @@ "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" }, - "applicationUrl": "http://localhost:5010" + "applicationUrl": "http://*:5010" } } } \ No newline at end of file diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/AssignmentService.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/AssignmentService.cs index e447b532..333436f5 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/AssignmentService.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/AssignmentService.cs @@ -120,8 +120,8 @@ public class AssignmentService : IAssignmentService { var b = x.Key.Brand; var d = x.Key.DeviceUniqueNo; - var dc = x.Key.DeviceConnectionInfo??"{}"; - var func = x.Key.FuncStr??"[]"; + var dc = x.Key.DeviceConnectionInfo ?? "{}"; + var func = x.Key.FuncStr ?? "[]"; var jobj = new JObject { @@ -262,37 +262,34 @@ public class AssignmentService : IAssignmentService public async Task UpdateDeviceTaskStatusAsync(List requests) { + var taskIds = requests.Select(x => x.TaskId).ToList(); + var deviceTasks = await _dbContext.Queryable() + .Where(x => taskIds.Contains(x.Id)) + .Where(x => x.Status == DeviceTaskStatusEnumType.Process) + .ToListAsync(); + + taskIds = deviceTasks.Select(x => x.Id).ToList(); + + requests = requests.Where(x => taskIds.Contains(x.TaskId)).ToList(); + + deviceTasks.ForEach(x => + { + + }); + + var now = DateTime.Now; + var tasks = new List(requests.Count); foreach (var request in requests) { - //for (int i = 0; i < 5; i++) - //{ + var deviceTask = deviceTasks.First(x => x.Id == request.TaskId); - - // if (effect == 0) - // { - // continue; - // } - - // return; - //} - - //throw new UserFriendlyException("操作失败,请重试"); - - var deviceTask = await _dbContext.Queryable().Where(x => x.Id == request.TaskId).SingleAsync(); - deviceTask.ThrowIfNull("设备任务不存在"); - (deviceTask.Status != DeviceTaskStatusEnumType.Process) - .ThrowIfTrue($"任务状态[{deviceTask.Status.GetDescription()}]有误"); - - var status = request.IsSuccess ? DeviceTaskStatusEnumType.Success : DeviceTaskStatusEnumType.Error; - - var effect = await _dbContext.Updateable() - .SetColumns(x => x.Status == status) - .SetColumns(x => x.ResultMessage == request.ResultMessage) - .SetColumns(x => x.Version == x.Version + 1) - .SetColumns(x => x.ModifiedTime == DateTime.Now) - .Where(x => x.Id == request.TaskId && x.Version == deviceTask.Version) - .ExecuteCommandAsync(); + deviceTask.Status = request.IsSuccess ? DeviceTaskStatusEnumType.Success : DeviceTaskStatusEnumType.Error; + deviceTask.ResultMessage = request.ResultMessage; + deviceTask.ModifiedTime = now; + tasks.Add(deviceTask); } + + await _dbContext.UpdateAsync(tasks); } diff --git a/Src/Dlhis.Sys/Dlhis.Sys.csproj b/Src/Dlhis.Sys/Dlhis.Sys.csproj index d4dad1e0..2fa7f453 100644 --- a/Src/Dlhis.Sys/Dlhis.Sys.csproj +++ b/Src/Dlhis.Sys/Dlhis.Sys.csproj @@ -17,7 +17,7 @@ - + diff --git a/Src/Dlhis.User/Dlhis.User.csproj b/Src/Dlhis.User/Dlhis.User.csproj index 03eba4f8..fa15b059 100644 --- a/Src/Dlhis.User/Dlhis.User.csproj +++ b/Src/Dlhis.User/Dlhis.User.csproj @@ -17,7 +17,7 @@ - +