using HoneyBox.Core.Interfaces; using HoneyBox.Model.Data; using HoneyBox.Model.Models.FloatBall; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; namespace HoneyBox.Core.Services; /// /// 悬浮球服务实现 /// public class FloatBallService : IFloatBallService { private readonly HoneyBoxDbContext _dbContext; private readonly ILogger _logger; public FloatBallService( HoneyBoxDbContext dbContext, ILogger logger) { _dbContext = dbContext; _logger = logger; } /// public async Task> GetEnabledFloatBallsAsync() { try { var floatBalls = await _dbContext.FloatBallConfigs .Where(f => f.Status == 1) .Select(f => new FloatBallResponse { Id = f.Id, Type = f.Type, Image = f.Image, LinkUrl = f.LinkUrl, PositionX = f.PositionX, PositionY = f.PositionY, Width = f.Width, Height = f.Height, Effect = f.Effect, Title = f.Title, ImageDetails = f.ImageDetails, ImageBj = f.ImageBj, ImageDetailsX = f.ImageDetailsX, ImageDetailsY = f.ImageDetailsY, ImageDetailsW = f.ImageDetailsW, ImageDetailsH = f.ImageDetailsH }) .ToListAsync(); return floatBalls; } catch (Exception ex) { _logger.LogError(ex, "Failed to get enabled float ball configurations"); throw; } } }