gx
This commit is contained in:
1 parent
f2caec6083
commit
75d0e85218
16 files changed
+316
-320
No files matched your search
+56
-45
@@ -1,4 +1,4 @@
|
||||
using Asp.Versioning;
|
||||
using Asp.Versioning;
|
||||
using MAX.Framework.Commons;
|
||||
using MAX.Framework.Dtos;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
@@ -8,39 +8,38 @@ using Store.Modules.CloudProduct.Dtos;
|
||||
using Store.Modules.CloudProduct.Entities;
|
||||
using Store.Modules.CloudProduct.ImportConverters;
|
||||
using Store.Modules.CloudProduct.Services;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Text.Json.Nodes;
|
||||
|
||||
namespace Store.Modules.CloudProduct.Controllers
|
||||
{
|
||||
[ApiVersionNeutral]
|
||||
[Route("/CloudProduct/[action]")]
|
||||
public class ProductController : AppControllerBase
|
||||
[Route("/CloudGoods/[action]")]
|
||||
public class GoodsController : AppControllerBase
|
||||
{
|
||||
private readonly IProductService _productService;
|
||||
private readonly IOpenSearchServer _searchServer;
|
||||
private readonly RawDataStorage _rawDataStorage;
|
||||
private readonly IGoodsService _goodsService;
|
||||
private readonly IOpenSearchService _searchService;
|
||||
private readonly IRawDataStorage _rawDataStorage;
|
||||
|
||||
public ProductController(IProductService productService, IOpenSearchServer searchServer, RawDataStorage rawDataStorage)
|
||||
public GoodsController(IGoodsService goodsService, IOpenSearchService searchService, IRawDataStorage rawDataStorage)
|
||||
{
|
||||
_productService = productService;
|
||||
_searchServer = searchServer;
|
||||
_goodsService = goodsService;
|
||||
_searchService = searchService;
|
||||
_rawDataStorage = rawDataStorage;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<string> Time()
|
||||
{
|
||||
return DateTime.Now.ToLongDateString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 搜索
|
||||
/// </summary>
|
||||
/// <param name="keyword"></param>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public async Task<PageData<ProductEntity>> SearchGoods(ProductSearchRequest request)
|
||||
public async Task<PageData<GoodsEntity>> SearchGoods(GoodsSearchRequest request)
|
||||
{
|
||||
// 1. 参数基础校验
|
||||
if (request == null)
|
||||
@@ -125,8 +124,8 @@ namespace Store.Modules.CloudProduct.Controllers
|
||||
throw new AppException("请至少提供一个搜索条件", ResultCode.ValidationError);
|
||||
}
|
||||
|
||||
var result = await _productService.SearchGoods(request);
|
||||
return new PageData<ProductEntity>
|
||||
var result = await _goodsService.SearchGoodsAsync(request);
|
||||
return new PageData<GoodsEntity>
|
||||
{
|
||||
List = result.List,
|
||||
Total = result.Total,
|
||||
@@ -135,29 +134,32 @@ namespace Store.Modules.CloudProduct.Controllers
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 分词搜索,直接返回索引中的商品摘要(路由保持 SearchGoodsToIds 不变)
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
public async Task<PageData<ProductSearchInfo>> SearchGoodsToIds(string keyword, int pageindex = 1, int pagesize = 20)
|
||||
[ActionName("SearchGoodsToIds")]
|
||||
public async Task<PageData<GoodsSearchDocument>> SearchGoodsSummary(string keyword, int pageindex = 1, int pagesize = 20)
|
||||
{
|
||||
|
||||
if (string.IsNullOrWhiteSpace(keyword))
|
||||
{
|
||||
throw new AppException("填写关键字", ResultCode.ValidationError);
|
||||
}
|
||||
var ret = await _searchServer.SearchByTitleAsync(new ProductSearchRequest
|
||||
|
||||
var result = await _searchService.SearchByTitleAsync(new GoodsSearchRequest
|
||||
{
|
||||
Title = keyword,
|
||||
PageIndex = pageindex,
|
||||
PageSize = pagesize,
|
||||
});
|
||||
return new PageData<ProductSearchInfo>
|
||||
|
||||
return new PageData<GoodsSearchDocument>
|
||||
{
|
||||
PageIndex = pageindex,
|
||||
PageSize = pagesize,
|
||||
List = ret.list,
|
||||
Total = ret.Total,
|
||||
List = result.Documents,
|
||||
Total = result.Total,
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -174,15 +176,15 @@ namespace Store.Modules.CloudProduct.Controllers
|
||||
}
|
||||
|
||||
var content = await System.IO.File.ReadAllTextAsync(filePath);
|
||||
var goods = ConverterToGoodsFactory.ConvertContent(content);
|
||||
var goods = GoodsConverterFactory.ConvertContent(content);
|
||||
if (goods == null)
|
||||
{
|
||||
throw new AppException("未找到匹配的转换器,无法解析测试数据");
|
||||
}
|
||||
|
||||
return await _productService.ImportGoodsAsync(new[]
|
||||
return await _goodsService.ImportGoodsAsync(new[]
|
||||
{
|
||||
new GoodsImportItem { ProductEntity = goods, RawData = content }
|
||||
new GoodsImportItem { Goods = goods, RawData = content }
|
||||
});
|
||||
}
|
||||
|
||||
@@ -212,14 +214,14 @@ namespace Store.Modules.CloudProduct.Controllers
|
||||
using var reader = new StreamReader(file.OpenReadStream());
|
||||
var content = await reader.ReadToEndAsync();
|
||||
|
||||
var goods = ConverterToGoodsFactory.ConvertContent(content);
|
||||
var goods = GoodsConverterFactory.ConvertContent(content);
|
||||
if (goods == null)
|
||||
{
|
||||
parseErrors.Add($"{file.FileName}: 未找到匹配的转换器");
|
||||
}
|
||||
else
|
||||
{
|
||||
items.Add(new GoodsImportItem { ProductEntity = goods, RawData = content });
|
||||
items.Add(new GoodsImportItem { Goods = goods, RawData = content });
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -228,8 +230,8 @@ namespace Store.Modules.CloudProduct.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
var result = await _productService.ImportGoodsAsync(items);
|
||||
result.Failed += parseErrors.Count;
|
||||
var result = await _goodsService.ImportGoodsAsync(items);
|
||||
result.FailedCount += parseErrors.Count;
|
||||
result.Errors.InsertRange(0, parseErrors);
|
||||
|
||||
return result;
|
||||
@@ -241,7 +243,7 @@ namespace Store.Modules.CloudProduct.Controllers
|
||||
[HttpGet]
|
||||
public async Task<OpenSearchStatusDto> GetOpenSearchStatus()
|
||||
{
|
||||
return await _searchServer.GetStatusAsync();
|
||||
return await _searchService.GetStatusAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -271,11 +273,11 @@ namespace Store.Modules.CloudProduct.Controllers
|
||||
[HttpPost]
|
||||
public async Task<long> RebuildIndex([FromBody] long[]? ids)
|
||||
{
|
||||
return await _productService.RebuildSearchIndexAsync(ids);
|
||||
return await _goodsService.RebuildSearchIndexAsync(ids);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除商品(按数据库主键 ID)。是否软删除由配置 Delete:SoftDelete 决定,
|
||||
/// 删除商品(按商品编号)。是否软删除由配置 Delete:SoftDelete 决定,
|
||||
/// 软删除将 Status 置 1,硬删除物理删除记录;两种方式都会删除 OpenSearch 中对应文档。
|
||||
/// </summary>
|
||||
[HttpPost]
|
||||
@@ -286,19 +288,28 @@ namespace Store.Modules.CloudProduct.Controllers
|
||||
throw new AppException("请提供要删除的商品ID", ResultCode.ValidationError);
|
||||
}
|
||||
|
||||
return await _productService.DeleteGoodsAsync(ids);
|
||||
}
|
||||
[HttpGet]
|
||||
public async Task<bool> ClearSearch()
|
||||
{
|
||||
return await _searchServer.ClearIndexAsync();
|
||||
}
|
||||
[HttpGet]
|
||||
public async Task<long> GetSearchCount()
|
||||
{
|
||||
return await _searchServer.CountDocumentsAsync();
|
||||
return await _goodsService.DeleteGoodsAsync(ids);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清空并重建搜索索引(路由保持 ClearSearch 不变)。
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
[ActionName("ClearSearch")]
|
||||
public async Task<bool> ClearSearchIndex()
|
||||
{
|
||||
return await _searchService.ClearIndexAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 统计索引中的文档数(路由保持 GetSearchCount 不变)。
|
||||
/// </summary>
|
||||
[HttpGet]
|
||||
[ActionName("GetSearchCount")]
|
||||
public async Task<long> GetSearchDocumentCount()
|
||||
{
|
||||
return await _searchService.CountDocumentsAsync();
|
||||
}
|
||||
|
||||
private async Task<string> GetRawDataOrThrowAsync(long goodsId)
|
||||
{
|
||||
Reference in new issue
Block a user