54 lines
1.7 KiB
C#
54 lines
1.7 KiB
C#
using Dlhis.Entity.Canteen.Enums;
|
|
using Dlhis.Middle.Entities;
|
|
using Kurisu.AspNetCore.DataAccess.SqlSugar.Services;
|
|
|
|
namespace Dlhis.Middle.Services.Implements;
|
|
|
|
/// <summary>
|
|
/// 餐饮配置
|
|
/// </summary>
|
|
public class CanteenSettingService : ICanteenSettingService
|
|
{
|
|
private readonly IDbContext _context;
|
|
|
|
public CanteenSettingService(IDbContext context)
|
|
{
|
|
_context = context;
|
|
}
|
|
|
|
public async Task<Dictionary<CanteenSettingItemEnumType, string>> GetUserSettingAsync(string userNo, string tenantId)
|
|
{
|
|
var settings = await _context.Queryable<LocalCanteenSettingEntity>()
|
|
.Where(x => x.Enable)
|
|
.Where(x => x.TenantId == tenantId)
|
|
.Where(x => x.UniqueType == CanteenSettingUnqiueEnumType.Person && x.UniqueValue == userNo || x.UniqueType == CanteenSettingUnqiueEnumType.Tenant)
|
|
.ToListAsync();
|
|
|
|
//从基地 -> 个人,确保下面循环做到覆盖,并且以个人配置为主
|
|
settings = settings.OrderBy(x => x.UniqueType).ToList();
|
|
|
|
var result = new Dictionary<CanteenSettingItemEnumType, string>();
|
|
settings.ForEach(x => { result[x.Item] = x.Value; });
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <inheritdoc />
|
|
public async Task<TimeOnly?> GetBusinessSwitchTimeAsync(string tenantId)
|
|
{
|
|
var setting = await _context.Queryable<LocalCanteenSettingEntity>()
|
|
.Where(x => x.Enable)
|
|
.Where(x => x.TenantId == tenantId)
|
|
.Where(x => x.Item == CanteenSettingItemEnumType.BusinessSwitchTime)
|
|
.FirstAsync();
|
|
|
|
try
|
|
{
|
|
return TimeOnly.Parse(setting.Value);
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return null;
|
|
}
|
|
}
|
|
} |