mi-assessment/server/MiAssessment/src/MiAssessment.Core/Services/BusinessService.cs
2026-02-09 14:45:06 +08:00

59 lines
1.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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;
}
}