diff --git a/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs b/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs index e24cc7b7..31002554 100644 --- a/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs +++ b/Src/Dlhis.Basic/Device/Controllers/DevicesController.cs @@ -19,17 +19,14 @@ public class DevicesController : ControllerBase private readonly IDeviceService _deviceService; private readonly IDeviceTemplateService _deviceTemplateService; private readonly IDeviceConnectService _deviceConnectService; - private readonly IConfiguration _configuration; public DevicesController(IDeviceService deviceService, IDeviceTemplateService deviceTemplateService, - IDeviceConnectService deviceConnectService, - IConfiguration configuration) + IDeviceConnectService deviceConnectService) { _deviceService = deviceService; _deviceTemplateService = deviceTemplateService; _deviceConnectService = deviceConnectService; - _configuration = configuration; } /// @@ -106,20 +103,6 @@ public class DevicesController : ControllerBase await _deviceService.SaveAsync(request); } - /// - /// 获取激活码 - /// - /// - [HttpPost("resigter-code")] - public object GetRegisterCode() - { - return new - { - AppId = _configuration.GetSection("RegisterAppId").Value, - Key = _configuration.GetSection("RegisterCode").Value - }; - } - /// /// 获取尚未设置营业点的设备 /// diff --git a/Src/Dlhis.Basic/Device/Dtos/DeviceTimePeriodDto.cs b/Src/Dlhis.Basic/Device/Dtos/DeviceTimePeriodDto.cs deleted file mode 100644 index 982077ad..00000000 --- a/Src/Dlhis.Basic/Device/Dtos/DeviceTimePeriodDto.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace Dlhis.Basic.Device.Dtos; - -public class DeviceTimePeriodDto -{ - public int CardType { get; set; } - public TimeOnly OnStart { get; set; } - public TimeOnly OnEnd { get; set; } - - public TimeOnly OffStart { get; set; } - public TimeOnly OffEnd { get; set; } -} \ No newline at end of file diff --git a/Src/Dlhis.Basic/Device/Request/DeviceTimePeriodSaveRequest.cs b/Src/Dlhis.Basic/Device/Request/DeviceTimePeriodSaveRequest.cs index 90b5042a..f8199a86 100644 --- a/Src/Dlhis.Basic/Device/Request/DeviceTimePeriodSaveRequest.cs +++ b/Src/Dlhis.Basic/Device/Request/DeviceTimePeriodSaveRequest.cs @@ -1,22 +1,23 @@ using System.ComponentModel.DataAnnotations; using Dlhis.Entity.Device.Enums; +using Dlhis.Entity.Device.Models; namespace Dlhis.Basic.Device.Request; -public class DeviceTimePeriodSaveRequest : IValidatableObject +public class DeviceTimePeriodSaveRequest { public long? Id { get; set; } /// /// 卡类型 timeperiod /// - [Range(2, 3)] + [Range(2, 3, ErrorMessage = "卡类型有误")] public int CardType { get; set; } /// /// 分配类型 DeviceTimePeriodAssignEnumType /// - [EnumDataType(typeof(DeviceTimePeriodAssignEnumType))] + [EnumDataType(typeof(DeviceTimePeriodAssignEnumType), ErrorMessage = "时段分配类型有误")] public DeviceTimePeriodAssignEnumType AssignType { get; set; } /// @@ -26,46 +27,9 @@ public class DeviceTimePeriodSaveRequest : IValidatableObject public Guid Value { get; set; } /// - /// 上班开始 + /// 星期配置 /// - [Required] - public TimeOnly OnStart { get; set; } - - /// - /// 上班结束 - /// - [Required] - public TimeOnly OnEnd { get; set; } - - /// - /// 下班开始 - /// - [Required] - public TimeOnly OffStart { get; set; } - - /// - /// 下班结束 - /// - [Required] - public TimeOnly OffEnd { get; set; } - - /// - public IEnumerable Validate(ValidationContext validationContext) - { - if (OnStart >= OnEnd) - { - yield return new ValidationResult("上班时段范围有误", new[] { nameof(OnStart) }); - } - - if (OffStart >= OffEnd) - { - yield return new ValidationResult("下班时段范围有误", new[] { nameof(OffStart) }); - } - - - if (OnEnd >= OffStart) - { - yield return new ValidationResult("上下班时段范围有误", new[] { nameof(OnEnd) }); - } - } + [MinLength(7, ErrorMessage = "配置有误")] + [MaxLength(7, ErrorMessage = "配置有误")] + public List Sections { get; set; } } \ No newline at end of file diff --git a/Src/Dlhis.Basic/Device/Response/DeviceTimePeriodResponse.cs b/Src/Dlhis.Basic/Device/Response/DeviceTimePeriodResponse.cs index 676571b4..70f919e9 100644 --- a/Src/Dlhis.Basic/Device/Response/DeviceTimePeriodResponse.cs +++ b/Src/Dlhis.Basic/Device/Response/DeviceTimePeriodResponse.cs @@ -1,16 +1,25 @@ using Dlhis.Entity.Device.Enums; +using Dlhis.Entity.Device.Models; namespace Dlhis.Basic.Device.Response; -public class DeviceTimePeriodResponse +public class DeviceTimePeriodResponse { - public long Id { get; set; } + /// + /// 名称 + /// + public string Name { get; set; } /// /// 卡类型 /// public int CardType { get; set; } + /// + /// 卡类型描述 + /// + public string CardTypeDesc { get; set; } + /// /// 分配类型 /// @@ -22,27 +31,7 @@ public class DeviceTimePeriodResponse public Guid Value { get; set; } /// - /// 名称 + /// 时段信息 /// - public string Name { get; set; } - - /// - /// 上班开始 - /// - public TimeOnly OnStart { get; set; } - - /// - /// 上班结束 - /// - public TimeOnly OnEnd { get; set; } - - /// - /// 下班开始 - /// - public TimeOnly OffStart { get; set; } - - /// - /// 下班结束 - /// - public TimeOnly OffEnd { get; set; } + public List Sections { get; set; } } \ No newline at end of file diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DeviceTimePeriodService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DeviceTimePeriodService.cs index 9a903db8..442a30d0 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DeviceTimePeriodService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DeviceTimePeriodService.cs @@ -1,4 +1,3 @@ -using Dlhis.Basic.Device.Dtos; using Dlhis.Basic.Device.Request; using Dlhis.Basic.Device.Response; using Dlhis.Entity.Basic.Entity; @@ -25,17 +24,24 @@ public class DeviceTimePeriodService : IDeviceTimePeriodService /// public async Task> GetPageAsync(DeviceTimePeriodPageRequest request) { - var page = await _dbContext.Queryable() + var pageOri = await _dbContext.Queryable() .Where(x => x.AssignType == request.AssignType) - .Select() .ToPageListAsync(request); + var page = pageOri.Adapt>(); + var values = page.Data.Select(x => x.Value); var data = request.AssignType == DeviceTimePeriodAssignEnumType.Device ? await _dbContext.Queryable().Where(x => values.Contains(x.Code)).Select(x => new { x.Code, Name = x.DeployPlace }).ToListAsync() : await _dbContext.Queryable().Where(x => values.Contains(x.Code)).Select(x => new { x.Code, x.Name }).ToListAsync(); - page.Data.ForEach(item => { item.Name = data.FirstOrDefault(x => x.Code == item.Value)?.Name; }); + var basicTypes = await _dbContext.Queryable().Where(x => x.Type == "timeperiod").ToListAsync(); + + page.Data.ForEach(item => + { + item.Name = data.FirstOrDefault(x => x.Code == item.Value)?.Name; + item.CardTypeDesc = basicTypes.FirstOrDefault(x => x.Code == item.CardType.ToString())?.Display; + }); return page; } @@ -49,8 +55,7 @@ public class DeviceTimePeriodService : IDeviceTimePeriodService var existsData = request.AssignType == DeviceTimePeriodAssignEnumType.Device ? await _dbContext.Queryable().Where(x => x.Code == request.Value).AnyAsync() : await _dbContext.Queryable().Where(x => x.Code == request.Value).AnyAsync(); - existsData.ThrowIfFalse("数据不匹配"); - + existsData.ThrowIfFalse("数据不匹配分配类型"); (await _dbContext.Queryable() .Where(x => x.CardType == request.CardType) @@ -103,10 +108,10 @@ public class DeviceTimePeriodService : IDeviceTimePeriodService var deviceUniqueNo = device.UniqueNo; before.TryGetValue(deviceUniqueNo, out var beforeDtos); - beforeDtos ??= new List(0); + beforeDtos ??= new List(0); current.TryGetValue(deviceUniqueNo, out var currentDtos); - currentDtos ??= new List(0); + currentDtos ??= new List(0); if (beforeDtos.Count != currentDtos.Count) { @@ -138,7 +143,7 @@ public class DeviceTimePeriodService : IDeviceTimePeriodService var c = currentDtos.First(x => x.CardType == cardType); - if (b.OnStart != c.OnStart || b.OnEnd != c.OnEnd || b.OffStart != c.OffStart || b.OffEnd != c.OffEnd) + if (b.ToJson() != c.ToJson()) { tasks.Add(new DeviceTaskEntity { @@ -161,7 +166,7 @@ public class DeviceTimePeriodService : IDeviceTimePeriodService await _dbContext.InsertAsync(tasks); } - private async Task>> GetSettingsAsync() + private async Task>> GetSettingsAsync() { var timePeriods = await _dbContext.Queryable().ToListAsync(); @@ -178,11 +183,11 @@ public class DeviceTimePeriodService : IDeviceTimePeriodService { var tSettings = timePeriods .Where(item => item.AssignType == DeviceTimePeriodAssignEnumType.Template && item.Value == x.TemplateCode) - .Adapt>(); + .ToList(); var dSettings = timePeriods .Where(item => item.AssignType == DeviceTimePeriodAssignEnumType.Device && item.Value == x.Code) - .Adapt>(); + .ToList(); foreach (var setting in dSettings) { diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoFaceService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoFaceService.cs index 5ac85a27..e08538fc 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoFaceService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoFaceService.cs @@ -262,6 +262,10 @@ public class GainfoFaceService : IGainfoFaceService Face = request.Face }; + face.CreatedBy = _currentUser.GetIntSubjectId(); + face.CreateTime = DateTime.Now; + face.ModifiedBy = _currentUser.GetIntSubjectId(); + face.ModifiedTime = DateTime.Now; await _faceDbContext.InsertAsync(face); } else @@ -271,7 +275,9 @@ public class GainfoFaceService : IGainfoFaceService _logger.LogWarning("相同的人脸照片更新忽略"); return; } - + + face.ModifiedBy = _currentUser.GetIntSubjectId(); + face.ModifiedTime = DateTime.Now; face.Face = request.Face; await _faceDbContext.UpdateAsync(face); } diff --git a/Src/Dlhis.Basic/Properties/launchSettings.json b/Src/Dlhis.Basic/Properties/launchSettings.json index 9a6f2460..3a2eaf2f 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" }, "Docker": { "commandName": "Docker", diff --git a/Src/Dlhis.Entity/Basic/Entity/GainfoEntity.cs b/Src/Dlhis.Entity/Basic/Entity/GainfoEntity.cs index 70bff5e0..5ebc92f8 100644 --- a/Src/Dlhis.Entity/Basic/Entity/GainfoEntity.cs +++ b/Src/Dlhis.Entity/Basic/Entity/GainfoEntity.cs @@ -195,7 +195,7 @@ public class GainfoEntity : SugarBaseEntity [SugarColumn(ColumnDescription = "卡类型", IsNullable = true)] - public string CardType { get; set; } + public int? CardType { get; set; } } /// diff --git a/Src/Dlhis.Entity/Device/Entities/DeviceTimePeriodEntity.cs b/Src/Dlhis.Entity/Device/Entities/DeviceTimePeriodEntity.cs index 61d41503..bccbfafe 100644 --- a/Src/Dlhis.Entity/Device/Entities/DeviceTimePeriodEntity.cs +++ b/Src/Dlhis.Entity/Device/Entities/DeviceTimePeriodEntity.cs @@ -1,4 +1,5 @@ using Dlhis.Entity.Device.Enums; +using Dlhis.Entity.Device.Models; using Kurisu.AspNetCore.DataAccess.Entity; using Kurisu.AspNetCore.DataAccess.SqlSugar; using Mapster; @@ -40,28 +41,10 @@ public class DeviceTimePeriodEntity : SugarBaseEntity, ITenantId public Guid Value { get; set; } /// - /// 上班开始 + /// 时段信息 /// - [SugarColumn(IsNullable = false, ColumnDescription = "上班开始")] - public TimeOnly OnStart { get; set; } - - /// - /// 上班结束 - /// - [SugarColumn(IsNullable = false, ColumnDescription = "上班结束")] - public TimeOnly OnEnd { get; set; } - - /// - /// 下班开始 - /// - [SugarColumn(IsNullable = false, ColumnDescription = "下班开始")] - public TimeOnly OffStart { get; set; } - - /// - /// 下班结束 - /// - [SugarColumn(IsNullable = false, ColumnDescription = "下班结束")] - public TimeOnly OffEnd { get; set; } + [SugarColumn(IsJson = true, ColumnDataType = "varchar(1000)")] + public List Sections { get; set; } [SugarColumn(IsNullable = false, UniqueGroupNameList = new[] { "unique_DeviceTimePeriod_cardType_assignType_value" })] diff --git a/Src/Dlhis.Entity/Device/Entities/DeviceUploadLogEntity.cs b/Src/Dlhis.Entity/Device/Entities/DeviceUploadLogEntity.cs index 6572ee84..ffa5a474 100644 --- a/Src/Dlhis.Entity/Device/Entities/DeviceUploadLogEntity.cs +++ b/Src/Dlhis.Entity/Device/Entities/DeviceUploadLogEntity.cs @@ -42,6 +42,12 @@ public class DeviceUploadLogEntity : SugarBaseEntity, ITenantId [SugarColumn(ColumnDataType = "bit")] public bool Sync { get; set; } + /// + /// 是否有效 + /// + [SugarColumn(ColumnDataType = "bit")] + public bool Status { get; set; } + [SugarColumn(IndexGroupNameList = new string[] { "idx_DeviceUploadLog_TenantId" })] public string TenantId { get; set; } diff --git a/Src/Dlhis.Entity/Device/Models/DeviceTimePeriod.cs b/Src/Dlhis.Entity/Device/Models/DeviceTimePeriod.cs new file mode 100644 index 00000000..4c2b31e0 --- /dev/null +++ b/Src/Dlhis.Entity/Device/Models/DeviceTimePeriod.cs @@ -0,0 +1,8 @@ +using Kurisu.AspNetCore.CustomClass; + +namespace Dlhis.Entity.Device.Models; + +public class DeviceTimePeriod : TimePeriod +{ + public bool Enable { get; set; } +} \ No newline at end of file diff --git a/Src/Dlhis.Entity/Device/Models/DeviceWeekDayTimePeriod.cs b/Src/Dlhis.Entity/Device/Models/DeviceWeekDayTimePeriod.cs new file mode 100644 index 00000000..62e818e6 --- /dev/null +++ b/Src/Dlhis.Entity/Device/Models/DeviceWeekDayTimePeriod.cs @@ -0,0 +1,14 @@ +namespace Dlhis.Entity.Device.Models; + +public class DeviceWeekDayTimePeriod +{ + /// + /// 星期 + /// + public DayOfWeek DayOfWeek { get; set; } + + /// + /// 时段 + /// + public List TimePeriods { get; set; } +} \ No newline at end of file diff --git a/Src/Dlhis.ScheduledTask/Common/Services/Implements/GainfoUpdateService.cs b/Src/Dlhis.ScheduledTask/Common/Services/Implements/GainfoUpdateService.cs index 9458008d..747cd761 100644 --- a/Src/Dlhis.ScheduledTask/Common/Services/Implements/GainfoUpdateService.cs +++ b/Src/Dlhis.ScheduledTask/Common/Services/Implements/GainfoUpdateService.cs @@ -266,7 +266,7 @@ public class GainfoUpdateService : IGainfoUpdateService CostId = item.KOSTL, EntryDate = item.createdate, ResignationDate = item.ZLZRQ, - CardType = item.ZZ_KLX, + CardType = Convert.ToInt32(item.ZZ_KLX), Workplace = _tenants.FirstOrDefault(x => x.Name == item.ZZ_GZDJDNM)?.Code ?? item.ZZ_GZDJDNM, Factory = _tenants.FirstOrDefault(x => x.Name == item.ZZ_GZDCQNM)?.Code ?? item.ZZ_GZDCQNM, }; @@ -326,7 +326,7 @@ public class GainfoUpdateService : IGainfoUpdateService ResignationDate = item.ZLZRQ, Workplace = workplace, Factory = factory, - CardType = item.ZZ_KLX + CardType = Convert.ToInt32(item.ZZ_KLX) }).Where(x => x.Code == item.ename).ExecuteCommandAsync(); await _identityUserSyncService.SyncAccountAsync(gainfo.Code, gainfo.Name, gainfo.IdNo, factory); } diff --git a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Request/DeviceUploadLogUploadRequest.cs b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Request/DeviceUploadLogUploadRequest.cs index 69ca192b..d5376696 100644 --- a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Request/DeviceUploadLogUploadRequest.cs +++ b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Request/DeviceUploadLogUploadRequest.cs @@ -24,11 +24,6 @@ public class DeviceUploadLogUploadRequest /// 记录序号 /// public string SerialNo { get; set; } - - - // /// - // /// 记录类型 - // /// - // [EnumDataType(typeof(DeviceUploadLogTypeEnumType))] - // public DeviceUploadLogTypeEnumType Type { get; set; } = DeviceUploadLogTypeEnumType.Attendance; + + public bool Status { get; set; } } diff --git a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Response/DeviceUploadLogResponse.cs b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Response/DeviceUploadLogResponse.cs index df493226..6d821847 100644 --- a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Response/DeviceUploadLogResponse.cs +++ b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Response/DeviceUploadLogResponse.cs @@ -55,5 +55,13 @@ public class DeviceUploadLogResponse [JsonIgnore] public string OriginUserUniqueNo { get; set; } + /// + /// 是否同步sap + /// public bool Sync { get; set; } + + /// + /// 是否有效 + /// + public bool Status { get; set; } } diff --git a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs index f34a4d9f..37ad4278 100644 --- a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs +++ b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Services/Implements/DeviceUploadLogService.cs @@ -32,6 +32,7 @@ public class DeviceUploadLogService : IDeviceUploadLogService return await _dbContext.Queryable() .LeftJoin((log, d) => log.DeviceUniqueNo == d.UniqueNo) .Where(log => log.UserUniqueNo == jinkoCode) + .Where(log => log.Status) .WhereIF(request.DateTimePeriod.HasValue(), log => log.RaiseDateTime >= request.DateTimePeriod.Start && log.RaiseDateTime <= request.DateTimePeriod.End) .Where((log, d) => d.Type == DeviceTypeEnumType.Attendance || (d.Type == DeviceTypeEnumType.Door && d.AsAttendance)) .OrderBy(log => log.RaiseDateTime) @@ -46,6 +47,7 @@ public class DeviceUploadLogService : IDeviceUploadLogService SerialNo = log.SerialNo, DeployPlace = d.DeployPlace, Sync = log.Sync, + Status = log.Status }) .ToListAsync(); } @@ -88,6 +90,7 @@ public class DeviceUploadLogService : IDeviceUploadLogService UserName = ga.Name, DeployPlace = device.DeployPlace, Sync = deviceUp.Sync, + Status = deviceUp.Status, }) .ToPageListAsync(request); } @@ -122,7 +125,8 @@ public class DeviceUploadLogService : IDeviceUploadLogService ? DeviceUploadLogTypeEnumType.Attendance : DeviceUploadLogTypeEnumType.Door, - TenantId = device.TenantId + TenantId = device.TenantId, + Status = request.Status }); } diff --git a/Src/Dlhis.ScheduledTask/Jobs/SyncOriginCardInfoJob.cs b/Src/Dlhis.ScheduledTask/Jobs/SyncOriginCardInfoJob.cs index 09c88635..39d064ff 100644 --- a/Src/Dlhis.ScheduledTask/Jobs/SyncOriginCardInfoJob.cs +++ b/Src/Dlhis.ScheduledTask/Jobs/SyncOriginCardInfoJob.cs @@ -36,6 +36,7 @@ public class SyncOriginCardInfoJob : BaseJob .Where(x => deviceUniqueNos.Contains(x.DeviceUniqueNo)) .Where(x => !string.IsNullOrEmpty(x.UserUniqueNo)) .Where(x => x.Sync == false) + .Where(x => x.Status) .Where(x => SqlFunc.Subqueryable().Where(p => p.Code == x.UserUniqueNo).NotAny()) .Select((x, device) => new UploadAttendanceRequest { diff --git a/Src/Dlhis.ScheduledTask/Program.cs b/Src/Dlhis.ScheduledTask/Program.cs index f275e167..de8f3289 100644 --- a/Src/Dlhis.ScheduledTask/Program.cs +++ b/Src/Dlhis.ScheduledTask/Program.cs @@ -1,3 +1,4 @@ +using Dlhis.ScheduledTask.Common.Services; using Kurisu.AspNetCore.Startup; using Kurisu.AspNetCore.Utils.Extensions; @@ -24,5 +25,8 @@ public class Startup : DefaultStartup public override void Configure(IApplicationBuilder app, IWebHostEnvironment env) { base.Configure(app, env); + + + var token = app.ApplicationServices.GetService().IssueToken(); } } \ No newline at end of file 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/Controllers/AssignmentsController.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Controllers/AssignmentsController.cs index fdcbf37f..0f20bfe0 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Controllers/AssignmentsController.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Controllers/AssignmentsController.cs @@ -55,16 +55,4 @@ public class AssignmentsController : ControllerBase { await _assignmentService.UpdateDeviceTaskStatusAsync(requests); } - - /// - /// 获取新人脸照片 - /// - /// - /// - [HttpGet("renewfaceurl")] - [IgnoreTenant] - public async Task RenewFaceUrlAsync(long taskId) - { - return await _assignmentService.RenewFaceUrlAsync(taskId); - } } diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Dto/TaskDto.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Dto/TaskDto.cs index c724c2f2..d9af2b3e 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Dto/TaskDto.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Dto/TaskDto.cs @@ -1,4 +1,5 @@ -using Dlhis.Entity.Device.Enums; +using Dlhis.Entity.Device.Entities; +using Dlhis.Entity.Device.Enums; namespace Dlhis.ScheduledTask.TaskAssignment.Dto; @@ -23,5 +24,17 @@ public class TaskDto public int Version { get; set; } + /// + /// 是否启用时段码 + /// + public bool EnableTimePeriod { get; set; } + + /// + /// 卡类型 + /// + public int CardType { get; set; } + public DeviceTaskStatusEnumType Status { get; set; } -} + + public List TimePeriods { get; set; } +} \ No newline at end of file diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Response/TimePeriodWeekDaySection.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Response/TimePeriodWeekDaySection.cs index 932891b9..3caeabe5 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Response/TimePeriodWeekDaySection.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Response/TimePeriodWeekDaySection.cs @@ -1,4 +1,4 @@ -using Kurisu.AspNetCore.CustomClass; +using Dlhis.Entity.Device.Models; namespace Dlhis.ScheduledTask.TaskAssignment.Response; @@ -12,5 +12,5 @@ public class TimePeriodWeekDaySection /// /// 时段区间 最多4个 /// - public List TimePeriods { get; set; } + public List TimePeriods { get; set; } } diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Services/IAssignmentService.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Services/IAssignmentService.cs index 0e241174..9a725a9e 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Services/IAssignmentService.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Services/IAssignmentService.cs @@ -19,11 +19,4 @@ public interface IAssignmentService : IScopeDependency /// /// Task UpdateDeviceTaskStatusAsync(List requests); - - /// - /// 获取新人脸照片 - /// - /// - /// - Task RenewFaceUrlAsync(long taskId); } diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/AssignmentService.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/AssignmentService.cs index 63547016..a1ce09a6 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/AssignmentService.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/AssignmentService.cs @@ -1,6 +1,7 @@ using Dlhis.Entity.Basic.Entity; using Dlhis.Entity.Device.Entities; using Dlhis.Entity.Device.Enums; +using Dlhis.Entity.Device.Models; using Dlhis.ScheduledTask.TaskAssignment.Request; using Dlhis.ScheduledTask.TaskAssignment.Response; using Kurisu.AspNetCore.Utils.Extensions; @@ -8,12 +9,12 @@ using Microsoft.AspNetCore.DataProtection; using Microsoft.Extensions.Options; using SqlSugar; using Newtonsoft.Json.Linq; -using Kurisu.AspNetCore; using Kurisu.AspNetCore.Utils; using Dlhis.ScheduledTask.TaskAssignment.Dto; using Kurisu.AspNetCore.CustomClass; using Kurisu.AspNetCore.DataAccess.SqlSugar.Extensions; using Kurisu.AspNetCore.DataAccess.SqlSugar.Services; +using Mapster; namespace Dlhis.ScheduledTask.TaskAssignment.Services.Implements; @@ -37,6 +38,8 @@ public class AssignmentService : IAssignmentService var data = await GetDataAsync(request); if (data.IsEmpty()) return new List(); + await HandlerOldDeviceGainfoAsync(data); + await HandlerTimePeriodAsync(data); var deviceUploadInfos = await GetDeviceUploadRecordInfosAsync(data); var timeLimitedDataProtector = _dataProtectionProvider @@ -90,14 +93,14 @@ public class AssignmentService : IAssignmentService UserName = item.UserName, DepartmentNo = item.DepartmentNo, DepartmentName = item.DepartmentName, - CardNo = item.Type == DeviceTaskEnumType.Delete ? string.Empty : item.CardNo, + CardNo = 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 }, + TimePeriods = new List { item.CardType }, Doors = new List { 1 }, Schedule = 1 }; @@ -106,27 +109,22 @@ public class AssignmentService : IAssignmentService case DeviceTaskEnumType.TimePeriodAdd: case DeviceTaskEnumType.TimePeriodDelete: { - dto.Info = new TimePeriodToDeviceResponse + dto.Info = item.TimePeriods.Select(t => new TimePeriodToDeviceResponse { - Id = 1, - Name = "小白领", + Id = t.CardType, + Name = t.CardType == 2 ? "行政卡" : "车间卡", Enable = true, - Sections = new List + Sections = t.Sections.Select(s => new TimePeriodWeekDaySection { - new() + DayOfWeek = s.DayOfWeek, + TimePeriods = s.TimePeriods.Select(p => new DeviceTimePeriod { - DayOfWeek = DayOfWeek.Monday, - TimePeriods = new List - { - new() - { - Start = TimeOnly.Parse("08:00:00"), - End = TimeOnly.Parse("17:30:00") - } - } - } - } - }; + Enable = p.Enable, + Start = p.Enable ? p.Start : new TimeOnly(00, 00, 00), + End = p.Enable ? p.End : new TimeOnly(00, 00, 00), + }).ToList() + }).ToList() + }); } break; case DeviceTaskEnumType.ScheduleAdd: @@ -173,33 +171,6 @@ public class AssignmentService : IAssignmentService }).ToList(); } - /// - /// 获取新token - /// - /// - /// - /// - public async Task RenewFaceUrlAsync(long taskId) - { - var task = await _dbContext.Queryable().Where(x => x.Id == taskId).FirstAsync(); - task.ThrowIfNull("该任务不存在"); - (task.Status != DeviceTaskStatusEnumType.Process).ThrowIfTrue($"设备任务下发状态需为{DeviceTaskStatusEnumType.Process.GetDescription()}"); - - var faceUrlOptions = App.GetServiceProvider(true).GetService>().Value; - var dataProtectionProvider = App.GetServiceProvider(true).GetService(); - - var timeLimitedDataProtector = dataProtectionProvider - .CreateProtector("down:face") - .ToTimeLimitedDataProtector(); - - var userCode = await _dbContext.Queryable().Where(x => x.No == task.UserNo).Select(x => x.Code).SingleAsync(); - - var key = $"face:{userCode}"; - var token = timeLimitedDataProtector.Protect(key, TimeSpan.FromSeconds(faceUrlOptions.Limit)); - - return faceUrlOptions.Url + token; - } - public async Task UpdateDeviceTaskStatusAsync(List requests) { @@ -290,8 +261,12 @@ public class AssignmentService : IAssignmentService .WhereIF(factories.Any(), (deviceTask, device) => factories.Contains(deviceTask.TenantId)) .WhereIF(request.Types.IsPresent(), deviceTask => request.Types.Contains(deviceTask.Type)) .WhereIF(request.Brand.IsPresent(), (deviceTask, device, deviceTemplate) => deviceTemplate.Brand == request.Brand) - .Where((deviceTask, device, deviceTemplate, ga, gaLeave, department, gainfoEx, deviceRegistry) => + +#if !DEBUG + .Where((deviceTask, device, deviceTemplate, ga, gaLeave, department, gainfoEx, deviceRegistry) => device.HeartbeatInterval == 0 || SqlFunc.DateAdd(deviceRegistry.LastHeartbeatTime, device.HeartbeatInterval, DateType.Second) > DateTime.Now) +#endif + .OrderBy(deviceTask => new { Priority = SqlFunc.Desc(deviceTask.Priority), deviceTask.CreateTime }) .Select((deviceTask, device, deviceTemplate, ga, gaLeave, department, gainfoEx) => new TaskDto { @@ -313,7 +288,13 @@ public class AssignmentService : IAssignmentService DepartmentName = department.Name, CardNo = ga.CardNo, Version = deviceTask.Version, - Status = deviceTask.Status + Status = deviceTask.Status, + EnableTimePeriod = device.EnableTimePeriod, + CardType = device.EnableTimePeriod + ? SqlFunc.IsNullOrEmpty(ga.CardType) + ? 1 + : SqlFunc.ToInt32(ga.CardType) + : 1 }) .ToPageListAsync(request); @@ -338,28 +319,17 @@ public class AssignmentService : IAssignmentService throw new VersionExceptions("version exceptions"); } - if (await _dbContext.Queryable().Where(x => x.Status != OldDeviceGainfoEnumType.Deleted).AnyAsync()) - { - var oldDeviceGainfoWhere = LinqExpressionExtensions.False(); - page.Data.ForEach(item => { oldDeviceGainfoWhere = oldDeviceGainfoWhere.Or(x => x.Code == item.UserCode && x.DeviceUniqueNo == item.DeviceUniqueNo); }); - var oldData = await _dbContext.Queryable().Where(x => x.Status == OldDeviceGainfoEnumType.Wait || x.Status == OldDeviceGainfoEnumType.Error) - .Where(oldDeviceGainfoWhere) - .ToListAsync(); - - page.Data.ForEach(item => - { - var o = oldData.FirstOrDefault(x => x.Code == item.UserCode && x.DeviceUniqueNo == item.DeviceUniqueNo); - if (o != null) - item.OldUserNo = o.No; - }); - } - return page.Data; }, 5); return data; } + /// + /// 处理获取上传记录的任务 + /// + /// + /// private async Task> GetDeviceUploadRecordInfosAsync(List data) { if (data.All(x => x.Type != DeviceTaskEnumType.UploadRecord)) @@ -383,4 +353,65 @@ public class AssignmentService : IAssignmentService return result; } + + /// + /// 处理老档案数据 + /// + /// + private async Task HandlerOldDeviceGainfoAsync(List data) + { + if (await _dbContext.Queryable().Where(x => x.Status != OldDeviceGainfoEnumType.Deleted).AnyAsync()) + { + var oldDeviceGainfoWhere = LinqExpressionExtensions.False(); + data.ForEach(item => { oldDeviceGainfoWhere = oldDeviceGainfoWhere.Or(x => x.Code == item.UserCode && x.DeviceUniqueNo == item.DeviceUniqueNo); }); + var oldData = await _dbContext.Queryable().Where(x => x.Status == OldDeviceGainfoEnumType.Wait || x.Status == OldDeviceGainfoEnumType.Error) + .Where(oldDeviceGainfoWhere) + .ToListAsync(); + + data.ForEach(item => + { + var o = oldData.FirstOrDefault(x => x.Code == item.UserCode && x.DeviceUniqueNo == item.DeviceUniqueNo); + if (o != null) + item.OldUserNo = o.No; + }); + } + } + + + private async Task HandlerTimePeriodAsync(List data) + { + var tasks = data.Where(x => x.EnableTimePeriod).Where(x => x.Type is DeviceTaskEnumType.TimePeriodAdd or DeviceTaskEnumType.TimePeriodDelete).ToList(); + var deviceUniqueNos = tasks.Select(x => x.DeviceUniqueNo).ToList(); + + var devices = await _dbContext.Queryable().Where(x => deviceUniqueNos.Contains(x.UniqueNo)).ToListAsync(); + var templateCodes = devices.Select(x => x.TemplateCode).Distinct().ToList(); + var deviceCodes = devices.Select(x => x.Code).Distinct().ToList(); + var settings = await _dbContext.Queryable() + .Where(x => (x.AssignType == DeviceTimePeriodAssignEnumType.Template && templateCodes.Contains(x.Value)) + || (x.AssignType == DeviceTimePeriodAssignEnumType.Device && deviceCodes.Contains(x.Value))) + .ToListAsync(); + + + data.ForEach(item => + { + var templateCode = devices.FirstOrDefault(x => x.UniqueNo == item.DeviceUniqueNo)?.TemplateCode; + var code = devices.FirstOrDefault(x => x.UniqueNo == item.DeviceUniqueNo)?.Code; + + var tSettings = settings.Where(x => x.AssignType == DeviceTimePeriodAssignEnumType.Template).Where(x => x.Value == templateCode).ToList(); + var dSettings = settings.Where(x => x.AssignType == DeviceTimePeriodAssignEnumType.Device).Where(x => x.Value == code).ToList(); + + foreach (var setting in dSettings) + { + var s = tSettings.FirstOrDefault(x => x.CardType == setting.CardType); + if (s != null) + { + tSettings.Remove(s); + } + + tSettings.Add(setting); + } + + item.TimePeriods = tSettings; + }); + } } \ No newline at end of file diff --git a/Src/Dlhis.ScheduledTask/appsettings.Development.json b/Src/Dlhis.ScheduledTask/appsettings.Development.json index 4466d061..bfd5a43d 100644 --- a/Src/Dlhis.ScheduledTask/appsettings.Development.json +++ b/Src/Dlhis.ScheduledTask/appsettings.Development.json @@ -10,7 +10,7 @@ "BasicRequestUrl": "http://localhost:5002" }, "FaceUrlOptions": { - "Url": "http://localhost:5002/api/gainfos/face?token=", + "Url": "http://192.168.199.115:5002/api/gainfos/face?token=", "Limit": 7200 }, "SwaggerOptions": {