From a9d284b43c40eb1c995b5327ed61431289effae5 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Mon, 6 Jan 2025 10:57:04 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BC=98=E5=8C=96=E6=89=B9=E9=87=8F?= =?UTF-8?q?=E5=A4=84=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/GainfoCardsController.cs | 15 +----- .../Request/GainfoCardEditRequest.cs | 4 +- .../Services/IGainfoCardService.cs | 11 +--- .../Services/Implements/GainfoCardService.cs | 51 ++++++++----------- .../Device/Entities/DeviceTaskEntity.cs | 1 + .../Services/Implements/AssignmentService.cs | 2 - 6 files changed, 28 insertions(+), 56 deletions(-) diff --git a/Src/Dlhis.Basic/Organization/Controllers/GainfoCardsController.cs b/Src/Dlhis.Basic/Organization/Controllers/GainfoCardsController.cs index 82a85b1c..df849686 100644 --- a/Src/Dlhis.Basic/Organization/Controllers/GainfoCardsController.cs +++ b/Src/Dlhis.Basic/Organization/Controllers/GainfoCardsController.cs @@ -45,17 +45,7 @@ public class GainfoCardsController : ControllerBase { return await _gainfoCardService.GetChangeRecordsAsync(userNo); } - - /// - /// 获取卡类型 - /// - /// - [HttpGet("cardTypes")] - public async Task>> GetCardTypesAsync() - { - return await _gainfoCardService.GetCardTypesAsync(); - } - + /// /// 编辑卡类型 /// @@ -63,7 +53,6 @@ public class GainfoCardsController : ControllerBase [HttpPost("cardType")] public async Task EditCardTypeAsync(GainfoCardEditRequest request) { - //string code, int typeId - await _gainfoCardService.EditCardTypeAsync(request.UserCode, request.CardType); + await _gainfoCardService.EditCardTypeAsync(request.UserCodes, request.CardType); } } \ No newline at end of file diff --git a/Src/Dlhis.Basic/Organization/Request/GainfoCardEditRequest.cs b/Src/Dlhis.Basic/Organization/Request/GainfoCardEditRequest.cs index 6c4887cb..378f3481 100644 --- a/Src/Dlhis.Basic/Organization/Request/GainfoCardEditRequest.cs +++ b/Src/Dlhis.Basic/Organization/Request/GainfoCardEditRequest.cs @@ -7,8 +7,8 @@ public class GainfoCardEditRequest /// /// 工号 /// - [Required(ErrorMessage = "工号不能为空")] - public string UserCode { get; set; } + [MinLength(1, ErrorMessage = "工号不能为空")] + public List UserCodes { get; set; } /// /// 卡类型 diff --git a/Src/Dlhis.Basic/Organization/Services/IGainfoCardService.cs b/Src/Dlhis.Basic/Organization/Services/IGainfoCardService.cs index a3e5f425..e1c285ff 100644 --- a/Src/Dlhis.Basic/Organization/Services/IGainfoCardService.cs +++ b/Src/Dlhis.Basic/Organization/Services/IGainfoCardService.cs @@ -1,6 +1,5 @@ using Dlhis.Basic.Organization.Request; using Dlhis.Basic.Organization.Response; -using Kurisu.AspNetCore.CustomClass; namespace Dlhis.Basic.Organization.Services; @@ -20,17 +19,11 @@ public interface IGainfoCardService : IScopeDependency /// Task> GetChangeRecordsAsync(string userNo); - /// - /// 获取卡类型 - /// - /// - Task>> GetCardTypesAsync(); - /// /// 编辑卡类型 /// - /// + /// /// /// - Task EditCardTypeAsync(string code, int typeId); + Task EditCardTypeAsync(List userCodes, int typeId); } \ No newline at end of file diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoCardService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoCardService.cs index ded048d9..8957da51 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoCardService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoCardService.cs @@ -3,7 +3,6 @@ using Dlhis.Basic.Organization.Request; using Dlhis.Basic.Organization.Response; using Dlhis.Entity.Basic.Entity; using Dlhis.Entity.Device.Enums; -using Kurisu.AspNetCore.CustomClass; using Kurisu.AspNetCore.DataAccess.SqlSugar.Services; using Kurisu.AspNetCore.Utils.Extensions; using Mapster; @@ -14,17 +13,17 @@ public class GainfoCardService : IGainfoCardService { private readonly IDbContext _dbContext; private readonly IGainfoStore _gainfoStore; - private readonly IDevicePermissionService _devicePermissionService; + private readonly IDevicePermissionAnalyzeService _devicePermissionAnalyzeService; private readonly IGainfoPermissionService _gainfoPermissionService; public GainfoCardService(IDbContext dbContext, IGainfoStore gainfoStore, - IDevicePermissionService devicePermissionService, + IDevicePermissionAnalyzeService devicePermissionAnalyzeService, IGainfoPermissionService gainfoPermissionService) { _dbContext = dbContext; _gainfoStore = gainfoStore; - _devicePermissionService = devicePermissionService; + _devicePermissionAnalyzeService = devicePermissionAnalyzeService; _gainfoPermissionService = gainfoPermissionService; } @@ -57,36 +56,28 @@ public class GainfoCardService : IGainfoCardService .ToListAsync(); } - public async Task>> GetCardTypesAsync() + + public async Task EditCardTypeAsync(List userCodes, int typeId) { - var r = new List> + var gainfos = await _dbContext.Queryable().Where(x => userCodes.Contains(x.Code)).ToListAsync(); + (gainfos.Count == userCodes.Count).ThrowIfFalse("人员不存在"); + + var result = await _devicePermissionAnalyzeService.GetUserAssignDeviceCodesWithTypeInTenantAsync(gainfos.Select(x => x.No).ToList()); + foreach (var gainfo in gainfos) { - new() - { - Key = "行政卡", Value = "2" - }, - new() - { - Key = "车间卡", Value = "3" - } - }; + var userNo = gainfo.No; + var myDeviceCodes = result[userNo].SelectMany(x => x.AssignTypes.SelectMany(p => p.Codes)).Distinct().ToList(); - return await Task.FromResult(r); - } + var deviceCodes = await _dbContext.Queryable() + .Where(x => myDeviceCodes.Contains(x.Code)) + .Where(x => x.EnableTimePeriod) + .Select(x => x.Code) + .ToListAsync(); - public async Task EditCardTypeAsync(string code, int typeId) - { - var gainfo = await _dbContext.Queryable().Where(x => x.Code == code).SingleAsync(); - gainfo.ThrowIfNull("人员不存在"); - gainfo.CardType = typeId; + await _gainfoPermissionService.ResetPermissionsAsync(userNo, DeviceTaskEnumType.Update, deviceCodes, "卡类型编辑下发"); + gainfo.CardType = typeId; + } - var myDeviceCodes = await _devicePermissionService.GetUserDeviceCodesByNoAsync(gainfo.No); - var deviceCodes = await _dbContext.Queryable() - .Where(x => myDeviceCodes.Contains(x.Code)) - .Where(x => x.EnableTimePeriod) - .Select(x => x.Code) - .ToListAsync(); - - await _gainfoPermissionService.ResetPermissionsAsync(gainfo.No, DeviceTaskEnumType.Update, deviceCodes, "卡类型编辑下发"); + await _dbContext.UpdateAsync(gainfos); } } \ No newline at end of file diff --git a/Src/Dlhis.Entity/Device/Entities/DeviceTaskEntity.cs b/Src/Dlhis.Entity/Device/Entities/DeviceTaskEntity.cs index 41d69385..2317377b 100644 --- a/Src/Dlhis.Entity/Device/Entities/DeviceTaskEntity.cs +++ b/Src/Dlhis.Entity/Device/Entities/DeviceTaskEntity.cs @@ -33,6 +33,7 @@ public class DeviceTaskEntity : SugarBaseEntity, ITenantId, IVersion /// /// 用户档案号 /// + [SugarColumn(IsNullable = true)] public string UserNo { get; set; } /// diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/AssignmentService.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/AssignmentService.cs index 6922436b..7439e54e 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/AssignmentService.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/AssignmentService.cs @@ -262,8 +262,6 @@ public class AssignmentService : IAssignmentService .WhereIF(request.Brand.IsPresent(), (deviceTask, device, deviceTemplate) => deviceTemplate.Brand == request.Brand) .Where((deviceTask, device, deviceTemplate, ga, gaLeave, department, deviceRegistry) => device.HeartbeatInterval == 0 || SqlFunc.DateAdd(deviceRegistry.LastHeartbeatTime, device.HeartbeatInterval, DateType.Second) > DateTime.Now) -#if !DEBUG -#endif .OrderBy(deviceTask => new { deviceTask.CreateTime, Priority = SqlFunc.Desc(deviceTask.Priority) }) .Select((deviceTask, device, deviceTemplate, ga, gaLeave, department) => new TaskDto {