mirror of
https://gitee.com/ccnetcore/Yi
synced 2026-03-19 16:06:36 +08:00
添加Goods
This commit is contained in:
19
Yi.Framework/Yi.Framework.Service/GoodsService.cs
Normal file
19
Yi.Framework/Yi.Framework.Service/GoodsService.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Model.Search;
|
||||
|
||||
namespace Yi.Framework.Service
|
||||
{
|
||||
public class GoodsService : IGoodsService
|
||||
{
|
||||
public PageResult<spu> QuerySpuByPage(int page, int rows, string key, bool? saleable)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
62
Yi.Framework/Yi.Framework.Service/SearchService.cs
Normal file
62
Yi.Framework/Yi.Framework.Service/SearchService.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Interface;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Model.Search;
|
||||
|
||||
namespace Yi.Framework.Service
|
||||
{
|
||||
public class SearchService : ISearchService
|
||||
{
|
||||
private IGoodsService _goodsService;
|
||||
public SearchService(IGoodsService goodsService)
|
||||
{
|
||||
_goodsService = goodsService;
|
||||
}
|
||||
public void ImpDataBySpu()
|
||||
{
|
||||
ImportToEs();
|
||||
}
|
||||
private void ImportToEs()
|
||||
{
|
||||
int page = 1;
|
||||
int size;
|
||||
int rows = 100;
|
||||
do
|
||||
{
|
||||
List<Goods> goodsList = new List<Goods>();
|
||||
// 上架商品
|
||||
PageResult<spu> result = _goodsService.QuerySpuByPage(page, rows, null, true);
|
||||
List<spu> spus = result.rows;
|
||||
size = spus.Count;
|
||||
foreach (var spu in spus)
|
||||
{
|
||||
try
|
||||
{
|
||||
Goods g = BuildGoods(spu);
|
||||
// 处理好的数据添加到集合中
|
||||
goodsList.Add(g);
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine(e.Message);
|
||||
continue;//部分数据不严格
|
||||
}
|
||||
}
|
||||
// 存入es,先留着,不写
|
||||
//_elasticSearchService.Send(goodsList);
|
||||
page++;
|
||||
} while (size == 100);
|
||||
}
|
||||
|
||||
private Goods BuildGoods(spu spu)
|
||||
{
|
||||
Goods goods = new Goods();
|
||||
return goods;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user