From 990fc247bc45d8982a22d6987d34a85347e8e1d2 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Thu, 7 Mar 2024 17:26:46 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fix=20type=E4=BF=AE=E6=94=B9=E4=B8=BA?= =?UTF-8?q?=E8=AE=BE=E5=A4=87=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Request/DeviceTaskAssignmentRequest.cs | 9 ++++++++- .../Services/Implements/DeviceTaskAssignmentService.cs | 9 +++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Request/DeviceTaskAssignmentRequest.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Request/DeviceTaskAssignmentRequest.cs index d41b722e..fee03043 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Request/DeviceTaskAssignmentRequest.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Request/DeviceTaskAssignmentRequest.cs @@ -6,11 +6,18 @@ namespace Dlhis.ScheduledTask.TaskAssignment.Request; public class DeviceTaskAssignmentRequest : PageDto { + /// + /// 设备类型 + /// + [EnumDataType(typeof(DeviceTypeEnumType))] + public DeviceTypeEnumType? Type { get; set; } + + /// /// 任务类型 /// [EnumDataType(typeof(DeviceTaskEnumType))] - public DeviceTaskEnumType? Type { get; set; } + public DeviceTaskEnumType? TaskType { get; set; } /// /// 任务下发状态 diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs index 979f2b17..f194ca21 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs @@ -27,13 +27,14 @@ public class DeviceTaskAssignmentService : IDeviceTaskAssignmentService { var page = await _dbContext.Queryable() .LeftJoin((deviceTask, ga) => deviceTask.UserNo == ga.No) - .LeftJoin((deviceTask, ga,device) => deviceTask.DeviceUniqueNo == device.UniqueNo) - .WhereIF(!request.Search.IsEmpty(), (deviceTask, ga,device) => deviceTask.UserNo == request.Search || ga.Name.Contains(request.Search) || ga.Code == request.Search || deviceTask.DeviceUniqueNo == request.Search || deviceTask.ModifiedTime.ToString("yyyy-MM-dd").Contains(request.Search)) - .WhereIF(request.Type.HasValue, deviceTask => deviceTask.Type == request.Type) + .LeftJoin((deviceTask, ga, device) => deviceTask.DeviceUniqueNo == device.UniqueNo) + .WhereIF(!request.Search.IsEmpty(), (deviceTask, ga, device) => deviceTask.UserNo == request.Search || ga.Name.Contains(request.Search) || ga.Code == request.Search || deviceTask.DeviceUniqueNo == request.Search || deviceTask.ModifiedTime.ToString("yyyy-MM-dd").Contains(request.Search)) + .WhereIF(request.TaskType.HasValue, deviceTask => deviceTask.Type == request.TaskType) + .WhereIF(request.Type.HasValue, (deviceTask, ga, device) => device.Type == request.Type) .WhereIF(request.Status.HasValue, deviceTask => deviceTask.Status == request.Status) .Where(deviceTask => 1 == 1) .OrderBy(deviceTask => deviceTask.CreateTime, OrderByType.Desc) - .Select((deviceTask, ga,device) => new DeviceTaskAssignmentResponse + .Select((deviceTask, ga, device) => new DeviceTaskAssignmentResponse { Id = deviceTask.Id, DeviceUniqueNo = deviceTask.DeviceUniqueNo, From 538fe7c4b456c15595959a77f1e60f38139cbd08 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Thu, 7 Mar 2024 21:34:04 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fix=20=E4=BC=98=E5=8C=96=E6=A1=A3=E6=A1=88?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Organization/Request/GainfoPageRequest.cs | 4 +-- .../Request/TenantDepartmentRequest.cs | 14 +++++++++++ .../Services/Implements/GainfoService.cs | 25 ++++++++++++------- .../Request/DeviceUploadLogPageRequest.cs | 24 +++++++++--------- .../Implements/DeviceTaskAssignmentService.cs | 7 +++++- .../Services/Implements/TenantService.cs | 16 ++++++------ 6 files changed, 59 insertions(+), 31 deletions(-) create mode 100644 Src/Dlhis.Basic/Organization/Request/TenantDepartmentRequest.cs diff --git a/Src/Dlhis.Basic/Organization/Request/GainfoPageRequest.cs b/Src/Dlhis.Basic/Organization/Request/GainfoPageRequest.cs index 37cc810f..c9a13210 100644 --- a/Src/Dlhis.Basic/Organization/Request/GainfoPageRequest.cs +++ b/Src/Dlhis.Basic/Organization/Request/GainfoPageRequest.cs @@ -13,7 +13,7 @@ public class GainfoPageRequest : PageDto public GainfoStatusEnumType? Status { get; set; } = GainfoStatusEnumType.Working; /// - /// 部门号(部门树传入) + /// 部门选择 /// - public List DepartmentNos { get; set; } + public List DepartmentSelections { get; set; } = new List(); } diff --git a/Src/Dlhis.Basic/Organization/Request/TenantDepartmentRequest.cs b/Src/Dlhis.Basic/Organization/Request/TenantDepartmentRequest.cs new file mode 100644 index 00000000..b2bff024 --- /dev/null +++ b/Src/Dlhis.Basic/Organization/Request/TenantDepartmentRequest.cs @@ -0,0 +1,14 @@ +using System.ComponentModel.DataAnnotations; + +namespace Dlhis.Basic.Organization.Request; + +public class TenantDepartmentRequest +{ + [Required] + public string Tenant { get; set; } + + /// + /// 部门号(部门树传入) + /// + public List DepartmentNos { get; set; } +} diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs index 7997ceb8..c7ceda84 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs @@ -4,19 +4,17 @@ using Dlhis.Basic.Organization.Response; using Dlhis.Entity.Basic.Entity; using Dlhis.Entity.Basic.Enums; using Dlhis.Entity.Device.Enums; -using Kurisu.AspNetCore.Scope; -using Kurisu.AspNetCore.UnifyResultAndValidation; using Kurisu.AspNetCore.Utils; using Kurisu.AspNetCore.Utils.Extensions; using Kurisu.Core.DataAccess.Dto; using Kurisu.Core.User.Abstractions; using Kurisu.SqlSugar.Extensions; -using Kurisu.SqlSugar.Options; using Kurisu.SqlSugar.Services; using Mapster; using Microsoft.AspNetCore.DataProtection; using Microsoft.AspNetCore.Mvc; using System.IdentityModel.Tokens.Jwt; +using System.Linq.Expressions; namespace Dlhis.Basic.Organization.Services.Implements; @@ -57,10 +55,22 @@ public class GainfoService : IGainfoService /// public async Task> GetPageAsync(GainfoPageRequest request) { - request.DepartmentNos = await GetRecursionDepartmentNosAsync(request.DepartmentNos); + var currentTenantId = _currentUser.GetStringTenantId(); + + //根据组织架构搜索档案 + Expression> where = LinqExpressionExtension.False(); + foreach (var item in request.DepartmentSelections) + { + var depts = await GetRecursionDepartmentNosAsync(item.DepartmentNos); + if (depts.Any()) + where = where.Or(gainfo => gainfo.Factory == item.Tenant && depts.Contains(gainfo.DepartmentNo)); + else + where = where.Or(gainfo => gainfo.Factory == item.Tenant); + } var page = await _gainfoStore.Queryable(request.Status) - .WhereIF(request.DepartmentNos.IsPresent(), gainfo => request.DepartmentNos.Contains(gainfo.DepartmentNo)) + .WhereIF(request.DepartmentSelections.IsPresent(), where) + .WhereIF(request.DepartmentSelections.IsEmpty(), gainfo => gainfo.Factory == currentTenantId) .WhereIF(request.Search.IsPresent(), gainfo => gainfo.Name.Contains(request.Search) || gainfo.Code.Contains(request.Search) @@ -574,13 +584,10 @@ public class GainfoService : IGainfoService 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) { + result.Add(item.No); RecursionGetNext(item.No, departments, result); } } diff --git a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Request/DeviceUploadLogPageRequest.cs b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Request/DeviceUploadLogPageRequest.cs index 37aef592..670a5411 100644 --- a/Src/Dlhis.ScheduledTask/DeviceUploadLog/Request/DeviceUploadLogPageRequest.cs +++ b/Src/Dlhis.ScheduledTask/DeviceUploadLog/Request/DeviceUploadLogPageRequest.cs @@ -20,7 +20,7 @@ public class DeviceUploadLogPageRequest : PageDto, IValidatableObject public IEnumerable Validate(ValidationContext validationContext) { - var now = DateTime.Now; + var today = DateTime.Today; if (SearchDateTimeDimension.HasValue) { //重新赋值 @@ -28,37 +28,37 @@ public class DeviceUploadLogPageRequest : PageDto, IValidatableObject if (SearchDateTimeDimension == DateTimeSearchEnumType.Day) { - SearchDateTimePeriod.Start = new DateTime(now.Year, now.Month, now.Day, 0, 0, 1); - SearchDateTimePeriod.End = new DateTime(now.Year, now.Month, now.Day, 23, 59, 59); + SearchDateTimePeriod.Start = today; + SearchDateTimePeriod.End = today.AddDays(1).AddSeconds(-1); } else if (SearchDateTimeDimension == DateTimeSearchEnumType.Week) { - SearchDateTimePeriod.Start = now.AddDays(1 - (int)now.DayOfWeek); + SearchDateTimePeriod.Start = today.AddDays(1 - (int)today.DayOfWeek); SearchDateTimePeriod.End = SearchDateTimePeriod.Start.Value.AddDays(6); } else if (SearchDateTimeDimension == DateTimeSearchEnumType.Month) { - SearchDateTimePeriod.Start = new DateTime(now.Year, now.Month, 1); + SearchDateTimePeriod.Start = new DateTime(today.Year, today.Month, 1); SearchDateTimePeriod.End = SearchDateTimePeriod.Start.Value.AddMonths(1).AddDays(-1); } else if (SearchDateTimeDimension == DateTimeSearchEnumType.Season) { - SearchDateTimePeriod.Start = now.AddMonths(0 - ((now.Month - 1) % 3)); - SearchDateTimePeriod.End = now.AddMonths(3 - ((now.Month - 1) % 3)).AddMonths(1).AddDays(-1); + SearchDateTimePeriod.Start = new DateTime(today.Year, today.Month, 1).AddMonths(2 - ((today.Month - 1) % 3)); + SearchDateTimePeriod.End = SearchDateTimePeriod.Start.Value.AddMonths(2); } else if (SearchDateTimeDimension == DateTimeSearchEnumType.HalfOfYear) { - SearchDateTimePeriod.Start = now.AddDays(-180); - SearchDateTimePeriod.End = now; + SearchDateTimePeriod.Start = today.AddDays(-180); + SearchDateTimePeriod.End = today; } else if (SearchDateTimeDimension == DateTimeSearchEnumType.Year) { - SearchDateTimePeriod.Start = new DateTime(now.Year, 1, 1); + SearchDateTimePeriod.Start = new DateTime(today.Year, 1, 1); SearchDateTimePeriod.End = SearchDateTimePeriod.Start.Value.AddYears(1).AddDays(-1); } - SearchDateTimePeriod.Start = SearchDateTimePeriod.Start.Value.Date; - SearchDateTimePeriod.End = SearchDateTimePeriod.End.Value.Date; + SearchDateTimePeriod.Start = SearchDateTimePeriod.Start.Value; + SearchDateTimePeriod.End = SearchDateTimePeriod.End.Value; } yield break; diff --git a/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs b/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs index f194ca21..2b8d28f8 100644 --- a/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs +++ b/Src/Dlhis.ScheduledTask/TaskAssignment/Services/Implements/DeviceTaskAssignmentService.cs @@ -28,7 +28,12 @@ public class DeviceTaskAssignmentService : IDeviceTaskAssignmentService var page = await _dbContext.Queryable() .LeftJoin((deviceTask, ga) => deviceTask.UserNo == ga.No) .LeftJoin((deviceTask, ga, device) => deviceTask.DeviceUniqueNo == device.UniqueNo) - .WhereIF(!request.Search.IsEmpty(), (deviceTask, ga, device) => deviceTask.UserNo == request.Search || ga.Name.Contains(request.Search) || ga.Code == request.Search || deviceTask.DeviceUniqueNo == request.Search || deviceTask.ModifiedTime.ToString("yyyy-MM-dd").Contains(request.Search)) + .WhereIF(!request.Search.IsEmpty(), (deviceTask, ga, device) => + deviceTask.UserNo == request.Search + || ga.Name.Contains(request.Search) + || ga.Code == request.Search + || deviceTask.DeviceUniqueNo == request.Search + ) .WhereIF(request.TaskType.HasValue, deviceTask => deviceTask.Type == request.TaskType) .WhereIF(request.Type.HasValue, (deviceTask, ga, device) => device.Type == request.Type) .WhereIF(request.Status.HasValue, deviceTask => deviceTask.Status == request.Status) diff --git a/Src/Dlhis.Sys/Identity/Services/Implements/TenantService.cs b/Src/Dlhis.Sys/Identity/Services/Implements/TenantService.cs index 9302cc6e..ecb8795b 100644 --- a/Src/Dlhis.Sys/Identity/Services/Implements/TenantService.cs +++ b/Src/Dlhis.Sys/Identity/Services/Implements/TenantService.cs @@ -1,5 +1,4 @@ -using Dlhis.Entity.Basic.Entity; -using Dlhis.Entity.Sys.Entities; +using Dlhis.Entity.Sys.Entities; using Dlhis.Sys.Identity.Request; using Dlhis.Sys.Identity.Response; using Kurisu.AspNetCore.Utils.Extensions; @@ -71,23 +70,26 @@ public class TenantService : ITenantService public async Task> GetMyTenantsAsync() { var userId = _currentUser.GetIntSubjectId(); + var tenantId = _currentUser.GetStringTenantId(); + var myTenants = await _dbContext.Queryable() .LeftJoin((ut, t) => ut.TenantCode == t.Code) .Where(ut => ut.UserId == userId) .Select((ut, t) => new TenantResponse { Id = t.Id, + PCode = t.PCode, Code = t.Code, Name = t.Name, }) .ToListAsync(); - if (myTenants.IsEmpty()) - { - myTenants = await GetListAsync(); - } + var currentTenant = myTenants.First(x => x.Code == tenantId); + var otherTenants = myTenants.Where(x => x.Code != tenantId); - return myTenants; + var result = new List { currentTenant }; + result.AddRange(otherTenants); + return result; } public async Task> GetTreeAsync() From 4fa49efeac4de2281c15b696c0e3c0530f84d6fe Mon Sep 17 00:00:00 2001 From: liguoyang Date: Fri, 8 Mar 2024 10:30:29 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix=20=E6=9D=83=E9=99=90=E5=88=86=E9=85=8Dt?= =?UTF-8?q?enantId=E9=94=99=E8=AF=AF=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/DevicePermissionService.cs | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs b/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs index 91019ab8..d46ac987 100644 --- a/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs +++ b/Src/Dlhis.Basic/Device/Services/Implements/DevicePermissionService.cs @@ -27,23 +27,23 @@ public class DevicePermissionService : IDevicePermissionService public async Task AssignAsync(DevicePermissionSaveReuqest reuqest) { + var tenantId = reuqest.AssignType == AssignTypeEnumType.Department ? reuqest.TenantId : _currentUser.GetStringTenantId(); + + //删除当前匹配的基地权限 + var p = await _dbContext.Queryable() + .Where(x => x.AssignType == reuqest.AssignType) + .Where(x => x.AssignValue == reuqest.AssignValue) + .Where(x => x.UniqueType == reuqest.UniqueType) + .Where(x => x.TenantId == tenantId) + .ToListAsync(); + + await _dbContext.DeleteReallyAsync(p); + await GenerateDeviceTasksAsync(async () => { - //删除当前匹配的基地权限 - var p = await _dbContext.Queryable() - .Where(x => x.AssignType == reuqest.AssignType) - .Where(x => x.AssignValue == reuqest.AssignValue) - .Where(x => x.UniqueType == reuqest.UniqueType) - .WhereIF(reuqest.AssignType == AssignTypeEnumType.Department, x => x.TenantId == reuqest.TenantId) - .ToListAsync(); - - await _dbContext.DeleteReallyAsync(p); - //保存配置的权限 if (reuqest.Codes.IsPresent()) { - var tenantId = reuqest.AssignType == AssignTypeEnumType.Department ? reuqest.TenantId : _currentUser.GetStringSubjectId(); - var devicePermissions = reuqest.Codes.Select(code => new DevicePermissionEntity { AssignType = reuqest.AssignType,