fix(content): 修复ContentService.cs编码损坏问题

- 重写整个文件修复UTF-8编码损坏的中文字符
- 所有中文字符串已恢复正确内容
- 修复因PowerShell Set-Content导致的乱码问题
This commit is contained in:
zpc 2026-02-23 13:09:47 +08:00
parent 5e809c6cd1
commit 951536357a

View File

@ -22,14 +22,14 @@ public class ContentService : IContentService
/// </summary>
private static readonly Dictionary<int, string> LinkTypeNames = new()
{
{ 0, "æ—? },
{ 0, "无" },
{ 1, "内部页面" },
{ 2, "外部链接" },
{ 3, "å°<EFBFBD>ç¨åº? }
{ 3, "小程序" }
};
/// <summary>
/// 状æ€<EFBFBD>å<EFBFBD><EFBFBD>称映å°?
/// 状态名称映射
/// </summary>
private static readonly Dictionary<int, string> StatusNames = new()
{
@ -38,19 +38,19 @@ public class ContentService : IContentService
};
/// <summary>
/// 宣传å¾ä½<EFBFBD>ç½®å<EFBFBD><EFBFBD>称映å°?
/// 宣传图位置名称映射
/// </summary>
private static readonly Dictionary<int, string> PositionNames = new()
{
{ 1, "首页底部" },
{ 2, "团队� }
{ 2, "团队页" }
};
/// <summary>
/// 构造函�
/// 构造函数
/// </summary>
/// <param name="dbContext">数据库上下文</param>
/// <param name="logger">日志记录�/param>
/// <param name="logger">日志记录器</param>
public ContentService(
AdminBusinessDbContext dbContext,
ILogger<ContentService> logger)
@ -59,7 +59,7 @@ public class ContentService : IContentService
_logger = logger;
}
#region Banner è½®æ­å¾æ<EFBFBD>ä½?
#region Banner
/// <inheritdoc />
public async Task<PagedResult<BannerDto>> GetBannerListAsync(BannerQueryRequest request)
@ -69,7 +69,7 @@ public class ContentService : IContentService
.AsNoTracking()
.Where(b => !b.IsDeleted);
// 状æ€<EFBFBD>ç­é€?
// 状态筛选
if (request.Status.HasValue)
{
query = query.Where(b => b.Status == request.Status.Value);
@ -142,7 +142,7 @@ public class ContentService : IContentService
throw new BusinessException(ErrorCodes.BannerImageRequired, "图片URL不能为空");
}
// 验è¯<EFBFBD> LinkType 和对应字æ®?
// 验证 LinkType 和对应字段
ValidateLinkType(request.LinkType, request.LinkUrl, request.AppId);
// 创建实体
@ -171,7 +171,7 @@ public class ContentService : IContentService
/// <inheritdoc />
public async Task<bool> UpdateBannerAsync(UpdateBannerRequest request)
{
// 查找轮播�
// 查找轮播图
var banner = await _dbContext.Banners
.Where(b => b.Id == request.Id && !b.IsDeleted)
.FirstOrDefaultAsync();
@ -187,7 +187,7 @@ public class ContentService : IContentService
throw new BusinessException(ErrorCodes.BannerImageRequired, "图片URL不能为空");
}
// 验è¯<EFBFBD> LinkType 和对应字æ®?
// 验证 LinkType 和对应字段
ValidateLinkType(request.LinkType, request.LinkUrl, request.AppId);
// 更新字段
@ -210,7 +210,7 @@ public class ContentService : IContentService
/// <inheritdoc />
public async Task<bool> DeleteBannerAsync(long id)
{
// 查找轮播�
// 查找轮播图
var banner = await _dbContext.Banners
.Where(b => b.Id == id && !b.IsDeleted)
.FirstOrDefaultAsync();
@ -220,7 +220,7 @@ public class ContentService : IContentService
throw new BusinessException(ErrorCodes.BannerNotFound, "轮播图不存在");
}
// 软删�
// 软删除
banner.IsDeleted = true;
banner.UpdateTime = DateTime.Now;
@ -234,7 +234,7 @@ public class ContentService : IContentService
/// <inheritdoc />
public async Task<bool> UpdateBannerStatusAsync(long id, int status)
{
// 查找轮播�
// 查找轮播图
var banner = await _dbContext.Banners
.Where(b => b.Id == id && !b.IsDeleted)
.FirstOrDefaultAsync();
@ -244,13 +244,13 @@ public class ContentService : IContentService
throw new BusinessException(ErrorCodes.BannerNotFound, "轮播图不存在");
}
// 更新状�
// 更新状态
banner.Status = status;
banner.UpdateTime = DateTime.Now;
await _dbContext.SaveChangesAsync();
_logger.LogInformation("æ´æ°è½®æ­å¾çжæ€<EFBFBD>æˆ<EFBFBD>功,ID: {BannerId}, 状æ€? {Status}", id, status);
_logger.LogInformation("更新轮播图状态成功ID: {BannerId}, 状态: {Status}", id, status);
return true;
}
@ -266,7 +266,7 @@ public class ContentService : IContentService
// 获取所有需要更新的轮播图ID
var ids = items.Select(i => i.Id).ToList();
// 批é‡<EFBFBD>查询轮æ­å?
// 批量查询轮播图
var banners = await _dbContext.Banners
.Where(b => ids.Contains(b.Id) && !b.IsDeleted)
.ToListAsync();
@ -291,7 +291,7 @@ public class ContentService : IContentService
#endregion
#region Promotion 宣传徿<EFBFBD>�
#region Promotion
/// <inheritdoc />
public async Task<PagedResult<PromotionDto>> GetPromotionListAsync(PromotionQueryRequest request)
@ -301,13 +301,13 @@ public class ContentService : IContentService
.AsNoTracking()
.Where(p => !p.IsDeleted);
// ä½<EFBFBD>ç½®ç­é€?
// 位置筛选
if (request.Position.HasValue)
{
query = query.Where(p => p.Position == request.Position.Value);
}
// 状æ€<EFBFBD>ç­é€?
// 状态筛选
if (request.Status.HasValue)
{
query = query.Where(p => p.Status == request.Status.Value);
@ -376,7 +376,7 @@ public class ContentService : IContentService
throw new BusinessException(ErrorCodes.PromotionImageRequired, "图片URL不能为空");
}
// 验è¯<EFBFBD> Position å€?
// 验证 Position 值
ValidatePosition(request.Position);
// 创建实体
@ -404,7 +404,7 @@ public class ContentService : IContentService
/// <inheritdoc />
public async Task<bool> UpdatePromotionAsync(UpdatePromotionRequest request)
{
// 查找宣传�
// 查找宣传图
var promotion = await _dbContext.Promotions
.Where(p => p.Id == request.Id && !p.IsDeleted)
.FirstOrDefaultAsync();
@ -420,7 +420,7 @@ public class ContentService : IContentService
throw new BusinessException(ErrorCodes.PromotionImageRequired, "图片URL不能为空");
}
// 验è¯<EFBFBD> Position å€?
// 验证 Position 值
ValidatePosition(request.Position);
// 更新字段
@ -441,7 +441,7 @@ public class ContentService : IContentService
/// <inheritdoc />
public async Task<bool> DeletePromotionAsync(long id)
{
// 查找宣传�
// 查找宣传图
var promotion = await _dbContext.Promotions
.Where(p => p.Id == id && !p.IsDeleted)
.FirstOrDefaultAsync();
@ -451,7 +451,7 @@ public class ContentService : IContentService
throw new BusinessException(ErrorCodes.PromotionNotFound, "宣传图不存在");
}
// 软删�
// 软删除
promotion.IsDeleted = true;
promotion.UpdateTime = DateTime.Now;
@ -465,7 +465,7 @@ public class ContentService : IContentService
/// <inheritdoc />
public async Task<bool> UpdatePromotionStatusAsync(long id, int status)
{
// 查找宣传�
// 查找宣传图
var promotion = await _dbContext.Promotions
.Where(p => p.Id == id && !p.IsDeleted)
.FirstOrDefaultAsync();
@ -475,13 +475,13 @@ public class ContentService : IContentService
throw new BusinessException(ErrorCodes.PromotionNotFound, "宣传图不存在");
}
// 更新状�
// 更新状态
promotion.Status = status;
promotion.UpdateTime = DateTime.Now;
await _dbContext.SaveChangesAsync();
_logger.LogInformation("æ´æ°å®£ä¼ å¾çжæ€<EFBFBD>æˆ<EFBFBD>功,ID: {PromotionId}, 状æ€? {Status}", id, status);
_logger.LogInformation("更新宣传图状态成功ID: {PromotionId}, 状态: {Status}", id, status);
return true;
}
@ -491,7 +491,7 @@ public class ContentService : IContentService
#region
/// <summary>
/// 验è¯<EFBFBD> LinkType 和对应字æ®?
/// 验证 LinkType 和对应字段
/// </summary>
/// <param name="linkType">跳转类型</param>
/// <param name="linkUrl">跳转地址</param>
@ -501,7 +501,7 @@ public class ContentService : IContentService
switch (linkType)
{
case 0:
// 无跳转,ä¸<EFBFBD>需è¦<EFBFBD>验è¯?
// 无跳转,不需要验证
break;
case 1:
case 2:
@ -512,7 +512,7 @@ public class ContentService : IContentService
}
break;
case 3:
// å°<EFBFBD>ç¨åº<EFBFBD>,LinkUrl å’?AppId 都必å¡?
// 小程序LinkUrl 和 AppId 都必填
if (string.IsNullOrWhiteSpace(linkUrl))
{
throw new BusinessException(ErrorCodes.BannerLinkUrlRequired, "跳转地址不能为空");
@ -536,10 +536,10 @@ public class ContentService : IContentService
}
/// <summary>
/// 获å<EFBFBD>状æ€<EFBFBD>å<EFBFBD><EFBFBD>ç§?
/// 获取状态名称
/// </summary>
/// <param name="status">状æ€<EFBFBD>å€?/param>
/// <returns>状æ€<EFBFBD>å<EFBFBD><EFBFBD>ç§?/returns>
/// <param name="status">状态值</param>
/// <returns>状态名称</returns>
private static string GetStatusName(int status)
{
return StatusNames.TryGetValue(status, out var name) ? name : "未知";
@ -548,7 +548,7 @@ public class ContentService : IContentService
/// <summary>
/// 获取位置名称
/// </summary>
/// <param name="position">ä½<EFBFBD>ç½®å€?/param>
/// <param name="position">位置值</param>
/// <returns>位置名称</returns>
private static string GetPositionName(int position)
{
@ -556,23 +556,23 @@ public class ContentService : IContentService
}
/// <summary>
/// 导航状æ€<EFBFBD>å<EFBFBD><EFBFBD>称映å°?
/// 导航状态名称映射
/// </summary>
private static readonly Dictionary<int, string> NavigationStatusNames = new()
{
{ 0, "即将上线" },
{ 1, "已上� }
{ 1, "已上线" }
};
/// <summary>
/// 验è¯<EFBFBD> Position å€?
/// 验证 Position 值
/// </summary>
/// <param name="position">ä½<EFBFBD>ç½®å€?/param>
/// <param name="position">位置值</param>
private void ValidatePosition(int position)
{
if (position != 1 && position != 2)
{
throw new BusinessException(ErrorCodes.ParamError, "ä½<EFBFBD>置值必须为1(é¦é¡µåº•部)æˆ?(团队页ï¼?);
throw new BusinessException(ErrorCodes.ParamError, "位置值必须为1首页底部或2团队页");
}
}
@ -641,7 +641,7 @@ public class ContentService : IContentService
if (nav == null)
{
throw new BusinessException(ErrorCodes.NavigationNotFound, "é¦é¡µå¯¼èˆªä¸<EFBFBD>å­˜åœ?);
throw new BusinessException(ErrorCodes.NavigationNotFound, "首页导航不存在");
}
return nav;
@ -683,7 +683,7 @@ public class ContentService : IContentService
if (entity == null)
{
throw new BusinessException(ErrorCodes.NavigationNotFound, "é¦é¡µå¯¼èˆªä¸<EFBFBD>å­˜åœ?);
throw new BusinessException(ErrorCodes.NavigationNotFound, "首页导航不存在");
}
if (string.IsNullOrWhiteSpace(request.Name))
@ -727,14 +727,14 @@ public class ContentService : IContentService
if (entity == null)
{
throw new BusinessException(ErrorCodes.NavigationNotFound, "é¦é¡µå¯¼èˆªä¸<EFBFBD>å­˜åœ?);
throw new BusinessException(ErrorCodes.NavigationNotFound, "首页导航不存在");
}
entity.Status = status;
entity.UpdateTime = DateTime.Now;
await _dbContext.SaveChangesAsync();
_logger.LogInformation("æ´æ°é¦é¡µå¯¼èˆªçжæ€<EFBFBD>æˆ<EFBFBD>功,ID: {Id}, 状æ€? {Status}", id, status);
_logger.LogInformation("更新首页导航状态成功ID: {Id}, 状态: {Status}", id, status);
return true;
}