From 538fe7c4b456c15595959a77f1e60f38139cbd08 Mon Sep 17 00:00:00 2001 From: liguoyang Date: Thu, 7 Mar 2024 21:34:04 +0800 Subject: [PATCH] =?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()