fix 出差人员只允许对接人查看

This commit is contained in:
2024-09-24 22:54:12 +08:00
parent 9775052ab2
commit 57c1fd5a76

View File

@@ -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<GainfoService> _logger;
@@ -39,7 +37,6 @@ public class GainfoService : IGainfoService
ICurrentUser currentUser,
ITenantApi tenantApi,
IHangfireApi hangfireApi,
IHainingApi hainingApi,
IDevicePermissionService devicePermissionService,
IGainfoPermissionService gainfoPermissionService,
ILogger<GainfoService> 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<GainfoEntity>();
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<GainfoEntity>()
.And(where)
.Or(gainfo => SqlFunc.Subqueryable<BusinessTripEntity>()
.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<GainfoPageResponse> queryable = request.IsSearchAll
? _dbContext.Queryable<GainfoEntity>().AS("GainfoEntity", "gainfo")
.Where(where)
@@ -117,7 +122,12 @@ public class GainfoService : IGainfoService
.LeftJoin<BasicTypeEntity>((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<OutsourceEntity>().Where(p => p.Code == gainfo.Code).NotAny())
.WhereIF(request.SearchType == GainfoSearchEnumType.Outsource, gainfo => SqlFunc.Subqueryable<OutsourceEntity>().Where(p => p.Code == gainfo.Code).Any()) //&& today >= gainfo.EntryDate && today <= gainfo.ResignationDate
.WhereIF(request.SearchType == GainfoSearchEnumType.Outsource, gainfo =>
SqlFunc.Subqueryable<OutsourceEntity>()
.Where(p => p.Code == gainfo.Code)
.WhereIF(!isAll, p => p.SapCode == jinkoCode)
.Any()
)
.WhereIF(request.SearchType == GainfoSearchEnumType.BusinessTrip, gainfo =>
SqlFunc.Subqueryable<BusinessTripEntity>().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<OutsourceEntity>().Where(x => codes.Contains(x.Code)).Select(x => new { x.Code, x.Supplier }).ToListAsync();
var outsourceInfos = await _dbContext.Queryable<OutsourceEntity>()
.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; });
}