using Dlhis.Entity.Basic.Entity; using Dlhis.Entity.Canteen.Enums; using Kurisu.AspNetCore.DataAccess.SqlSugar.Services; using Mapster; namespace Dlhis.Middle.Services.Implements; /// /// 餐饮配置 /// public class CanteenSettingService : ICanteenSettingService { private readonly IDbContext _context; public CanteenSettingService(IDbContext context) { _context = context; } public async Task> GetUserSettingAsync(string userNo, string tenantId) { var settings = await _context.Queryable() .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(); settings.ForEach(x => { result[x.Item] = x.Value; }); return result; } public async Task GetBusinessSwitchTimeAsync(string tenantId) { var setting = await _context.Queryable() .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; } } //*********************************************** help methods ***************************************************// /// /// 检验参数 /// /// /// /// /// private static bool IsValidFormat(string value, CanteenSettingItemEnumType? type = null) { try { //判断0/1 if (type == CanteenSettingItemEnumType.AllowSendAtMeal || type == CanteenSettingItemEnumType.AllowRepeatInOneShift || type == CanteenSettingItemEnumType.AllowNoBalance || type == CanteenSettingItemEnumType.AllowCrossTenant) { var intvaule = int.Parse(value); if (intvaule == 0 || intvaule == 1) { return true; } else { return false; } } if (type == CanteenSettingItemEnumType.BusinessSwitchTime) { var timeOnly = value.Adapt(); return timeOnly.Minute == 0 && timeOnly.Second == 0; } //mapster value.Adapt(); } catch (Exception) { return false; } return true; } }