53 lines
1.8 KiB
C#
53 lines
1.8 KiB
C#
using Dlhis.Basic.Device.Services;
|
|
using Dlhis.Basic.Organization.Response;
|
|
using Dlhis.Entity.Basic.Entity;
|
|
using Dlhis.Entity.Device.Entities;
|
|
using Dlhis.Entity.Device.Enums;
|
|
using Kurisu.SqlSugar.Services;
|
|
|
|
namespace Dlhis.Basic.Organization.Services.Implements;
|
|
|
|
public class GainfoPermissions : IGainfoPermissions
|
|
{
|
|
private readonly IGainfoStore _gainfoStore;
|
|
private readonly IDevicePermissionService _devicePermissionService;
|
|
private readonly IDbContext _dbContext;
|
|
|
|
public GainfoPermissions(IGainfoStore gainfoStore, IDevicePermissionService devicePermissionService, IDbContext dbContext)
|
|
{
|
|
_gainfoStore = gainfoStore;
|
|
_devicePermissionService = devicePermissionService;
|
|
_dbContext = dbContext;
|
|
}
|
|
|
|
public async Task<List<GetPlaceByGainfoResponse>> GetPlaceByGainfoAsync(string userNo)
|
|
{
|
|
var gainfo = await _gainfoStore.Queryable()
|
|
.Where(x => x.No == userNo)
|
|
.FirstAsync();
|
|
|
|
if (gainfo == null)
|
|
{
|
|
return new List<GetPlaceByGainfoResponse>();
|
|
}
|
|
|
|
//用户所有deviceCode权限
|
|
var deviceCodes = await _devicePermissionService.GetAssignDeviceCodesAsync(gainfo.No);
|
|
|
|
return await _dbContext.Queryable<DeviceEntity>()
|
|
.LeftJoin<DeviceRegistryEntity>((x, dr) => x.UniqueNo == dr.DeviceUniqueNo)
|
|
.LeftJoin<BusinessPlaceEntity>((x, dr, place) => dr.BusinessPlaceCode == place.Code)
|
|
.Where(x => x.Type == DeviceTypeEnumType.Meal)
|
|
.Where(x => deviceCodes.Contains(x.Code))
|
|
.Where((x, dr) => !string.IsNullOrEmpty(dr.BusinessPlaceCustomCode))
|
|
.Select((x, dr, place) => new GetPlaceByGainfoResponse
|
|
{
|
|
PlaceCode = place.Code,
|
|
PlaceName = place.Name
|
|
})
|
|
.Distinct()
|
|
.ToListAsync();
|
|
|
|
}
|
|
}
|