59 lines
1.7 KiB
C#
59 lines
1.7 KiB
C#
using MiAssessment.Core.Interfaces;
|
||
using MiAssessment.Model.Data;
|
||
using MiAssessment.Model.Models.Business;
|
||
using Microsoft.EntityFrameworkCore;
|
||
using Microsoft.Extensions.Logging;
|
||
|
||
namespace MiAssessment.Core.Services;
|
||
|
||
/// <summary>
|
||
/// 业务详情服务实现
|
||
/// </summary>
|
||
public class BusinessService : IBusinessService
|
||
{
|
||
private readonly MiAssessmentDbContext _dbContext;
|
||
private readonly ILogger<BusinessService> _logger;
|
||
|
||
/// <summary>
|
||
/// 构造函数
|
||
/// </summary>
|
||
/// <param name="dbContext">数据库上下文</param>
|
||
/// <param name="logger">日志记录器</param>
|
||
public BusinessService(
|
||
MiAssessmentDbContext dbContext,
|
||
ILogger<BusinessService> logger)
|
||
{
|
||
_dbContext = dbContext;
|
||
_logger = logger;
|
||
}
|
||
|
||
/// <inheritdoc />
|
||
public async Task<BusinessDetailDto?> GetDetailAsync(long id)
|
||
{
|
||
_logger.LogDebug("获取业务详情,ID: {Id}", id);
|
||
|
||
var businessPage = await _dbContext.BusinessPages
|
||
.AsNoTracking()
|
||
.Where(b => b.Id == id && b.Status == 1 && !b.IsDeleted)
|
||
.Select(b => new BusinessDetailDto
|
||
{
|
||
Id = b.Id,
|
||
Title = b.Title,
|
||
ImageUrl = b.ImageUrl,
|
||
ShowButton = b.ShowButton,
|
||
ButtonText = b.ButtonText,
|
||
ButtonLink = b.ButtonLink
|
||
})
|
||
.FirstOrDefaultAsync();
|
||
|
||
if (businessPage == null)
|
||
{
|
||
_logger.LogDebug("业务页面不存在或已禁用,ID: {Id}", id);
|
||
return null;
|
||
}
|
||
|
||
_logger.LogDebug("获取到业务详情,ID: {Id}, Title: {Title}", id, businessPage.Title);
|
||
return businessPage;
|
||
}
|
||
}
|