diff --git a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs index b6a0719c..6c82dc5f 100644 --- a/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs +++ b/Src/Dlhis.Basic/Organization/Services/Implements/GainfoService.cs @@ -1,5 +1,4 @@ using Dlhis.Basic.Device.Services; -using Dlhis.Basic.Organization.Api; using Dlhis.Basic.Organization.Request; using Dlhis.Basic.Organization.Response; using Dlhis.Entity.Basic.Entity; @@ -28,7 +27,6 @@ public class GainfoService : IGainfoService private readonly ICurrentUser _currentUser; private readonly ITenantApi _tenantApi; private readonly IHangfireApi _hangfireApi; - private readonly IHainingApi _hainingApi; private readonly IDevicePermissionService _devicePermissionService; private readonly IGainfoPermissionService _gainfoPermissionService; private readonly ILogger _logger; @@ -39,7 +37,6 @@ public class GainfoService : IGainfoService ICurrentUser currentUser, ITenantApi tenantApi, IHangfireApi hangfireApi, - IHainingApi hainingApi, IDevicePermissionService devicePermissionService, IGainfoPermissionService gainfoPermissionService, ILogger logger) @@ -50,7 +47,6 @@ public class GainfoService : IGainfoService _currentUser = currentUser; _tenantApi = tenantApi; _hangfireApi = hangfireApi; - _hainingApi = hainingApi; _devicePermissionService = devicePermissionService; _gainfoPermissionService = gainfoPermissionService; _logger = logger; @@ -68,6 +64,11 @@ public class GainfoService : IGainfoService //根据组织架构搜索档案 var where = LinqExpressionExtensions.False(); var factories = _currentUser.GetUserClaim("tenants").Split(",").ToList(); + + var role = _currentUser.GetRole(); + var jinkoCode = _currentUser.GetUserClaim("jinko-code") ?? string.Empty; + var isAll = role is "admin" or "tenant-admin"; + if (request.DepartmentSelections.Any()) { foreach (var item in request.DepartmentSelections) @@ -91,11 +92,15 @@ public class GainfoService : IGainfoService where = Expressionable.Create() .And(where) .Or(gainfo => SqlFunc.Subqueryable() - .Where(p => p.Code == gainfo.Code && factories.Contains(p.Destination) && SqlFunc.DateIsSame(p.BeginDate, today)) - .Any()) + .Where(p => p.Code == gainfo.Code + && factories.Contains(p.Destination) + && SqlFunc.DateIsSame(p.BeginDate, today)) + .Any() + ) .ToExpression(); } + ISugarQueryable queryable = request.IsSearchAll ? _dbContext.Queryable().AS("GainfoEntity", "gainfo") .Where(where) @@ -117,7 +122,12 @@ public class GainfoService : IGainfoService .LeftJoin((gainfo, department, type) => type.Code == SqlFunc.ToString(gainfo.CardType) && type.Type == "timeperiod") .WhereIF(request.SearchType != GainfoSearchEnumType.BusinessTrip && request.DepartmentSelections?.Any() == false, gainfo => factories.Contains(gainfo.Factory)) .WhereIF(request.SearchType == GainfoSearchEnumType.Internal, gainfo => SqlFunc.Subqueryable().Where(p => p.Code == gainfo.Code).NotAny()) - .WhereIF(request.SearchType == GainfoSearchEnumType.Outsource, gainfo => SqlFunc.Subqueryable().Where(p => p.Code == gainfo.Code).Any()) //&& today >= gainfo.EntryDate && today <= gainfo.ResignationDate + .WhereIF(request.SearchType == GainfoSearchEnumType.Outsource, gainfo => + SqlFunc.Subqueryable() + .Where(p => p.Code == gainfo.Code) + .WhereIF(!isAll, p => p.SapCode == jinkoCode) + .Any() + ) .WhereIF(request.SearchType == GainfoSearchEnumType.BusinessTrip, gainfo => SqlFunc.Subqueryable().Where(p => p.Code == gainfo.Code && factories.Contains(p.Destination) && SqlFunc.DateIsSame(p.BeginDate, today)).Any()) .WhereIF(request.Search.IsPresent(), gainfo => @@ -132,14 +142,16 @@ public class GainfoService : IGainfoService CardTypeName = type.Display }, true); - _logger.LogInformation(queryable.ToSqlString()); var page = await queryable.ToPageListAsync(request); //外包人员部门号处理 if (request.SearchType == GainfoSearchEnumType.Outsource) { var codes = page.Data.Select(x => x.Code).ToList(); - var outsourceInfos = await _dbContext.Queryable().Where(x => codes.Contains(x.Code)).Select(x => new { x.Code, x.Supplier }).ToListAsync(); + var outsourceInfos = await _dbContext.Queryable() + .Where(x => codes.Contains(x.Code)) + .Select(x => new { x.Code, x.Supplier }) + .ToListAsync(); page.Data.ForEach(item => { item.DepartmentName = outsourceInfos.FirstOrDefault(x => x.Code == item.Code)?.Supplier; }); }