feat: 新增宠物进化分组接口、OSS图片搬运功能及配置更新
1. 新增皮肤按进化阶段分组的输出DTO 2. 新增宠物相关便捷查询接口并实现对应控制器 3. 新增OSS图片搬运辅助类,实现临时文件迁移逻辑 4. 为商品、宠物相关服务添加OSS图片自动迁移功能 5. 调整微信授权同步逻辑移除异步等待 6. 更新配置文件中的微信密钥和OSS存储信息 7. 注册SDK服务到DI容器
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using QYZH.InteractiveMagazine.Infrastructure.OSS;
|
||||
using QYZH.InteractiveMagazine.IService;
|
||||
using QYZH.InteractiveMagazine.Models.Common;
|
||||
using QYZH.InteractiveMagazine.Models.Dto;
|
||||
@ -12,7 +13,10 @@ namespace QYZH.InteractiveMagazine.Service;
|
||||
/// <summary>
|
||||
/// 商品服务实现
|
||||
/// </summary>
|
||||
public class ProductService(BaseRepository<Product> productRepository, ILogger<ProductService> logger) : BaseRepository<Product>, IProductService
|
||||
public class ProductService(
|
||||
BaseRepository<Product> productRepository,
|
||||
OssService ossService,
|
||||
ILogger<ProductService> logger) : BaseRepository<Product>, IProductService
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
@ -62,6 +66,16 @@ public class ProductService(BaseRepository<Product> productRepository, ILogger<P
|
||||
throw new BusinessException("创建商品失败", 500);
|
||||
}
|
||||
|
||||
// 将 temp 目录下的图片搬运到正式目录
|
||||
if (OssImageHelper.IsTempImage(product.ImageUrl))
|
||||
{
|
||||
var helper = CreateImageHelper();
|
||||
var folder = GetProductFormalFolder(product.Type, product.Id);
|
||||
var formalPath = await helper.MoveToFormalAsync(product.ImageUrl, folder);
|
||||
product.ImageUrl = formalPath;
|
||||
await productRepository.UpdateAsync(product);
|
||||
}
|
||||
|
||||
logger.LogInformation("商品创建成功,商品名称: {Name}, ID: {Id}", input.Name, product.Id);
|
||||
|
||||
return new ProductOutput
|
||||
@ -112,9 +126,18 @@ public class ProductService(BaseRepository<Product> productRepository, ILogger<P
|
||||
throw new BusinessException("商品价格不能为负数", 400);
|
||||
}
|
||||
|
||||
// 将 temp 目录下的新图片搬运到正式目录
|
||||
var newImageUrl = input.ImageUrl;
|
||||
if (OssImageHelper.IsTempImage(newImageUrl))
|
||||
{
|
||||
var helper = CreateImageHelper();
|
||||
var folder = GetProductFormalFolder(Enum.Parse<ProductTypeEnum>(input.Type, true), product.Id);
|
||||
newImageUrl = await helper.MoveToFormalAsync(newImageUrl, folder);
|
||||
}
|
||||
|
||||
product.Name = input.Name.Trim();
|
||||
product.Description = input.Description;
|
||||
product.ImageUrl = input.ImageUrl;
|
||||
product.ImageUrl = newImageUrl;
|
||||
product.Price = input.Price;
|
||||
product.Type = Enum.Parse<ProductTypeEnum>(input.Type, true);
|
||||
product.Status = (int)input.Status;
|
||||
@ -284,4 +307,21 @@ public class ProductService(BaseRepository<Product> productRepository, ILogger<P
|
||||
|
||||
logger.LogInformation("商品上下架状态更新成功,ID: {Id}, SaleStatus: {SaleStatus}", id, product.Status);
|
||||
}
|
||||
|
||||
#region OSS 图片搬运
|
||||
|
||||
private OssImageHelper CreateImageHelper() => new(ossService, logger);
|
||||
|
||||
private static string GetProductFormalFolder(ProductTypeEnum type, long productId)
|
||||
{
|
||||
var typeFolder = type switch
|
||||
{
|
||||
ProductTypeEnum.MakeUpCard => "makeupcard",
|
||||
ProductTypeEnum.PetSkin => "petskin",
|
||||
_ => "other"
|
||||
};
|
||||
return $"product/{typeFolder}/{productId}";
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user