添加Goods
This commit is contained in:
15
Yi.Framework/Yi.Framework.Interface/IGoodsService.cs
Normal file
15
Yi.Framework/Yi.Framework.Interface/IGoodsService.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Model.Models;
|
||||
using Yi.Framework.Model.Search;
|
||||
|
||||
namespace Yi.Framework.Interface
|
||||
{
|
||||
public interface IGoodsService
|
||||
{
|
||||
PageResult<spu> QuerySpuByPage(int page, int rows, string key, bool? saleable);
|
||||
}
|
||||
}
|
||||
13
Yi.Framework/Yi.Framework.Interface/ISearchService.cs
Normal file
13
Yi.Framework/Yi.Framework.Interface/ISearchService.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Interface
|
||||
{
|
||||
public interface ISearchService
|
||||
{
|
||||
void ImpDataBySpu();
|
||||
}
|
||||
}
|
||||
31
Yi.Framework/Yi.Framework.Model/Search/Goods.cs
Normal file
31
Yi.Framework/Yi.Framework.Model/Search/Goods.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using Nest;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Model.Models;
|
||||
|
||||
namespace Yi.Framework.Model.Search
|
||||
{
|
||||
[ElasticsearchType(IdProperty = "id")]//主键声明,且主键必须是属性
|
||||
public class Goods
|
||||
{
|
||||
public long id { get; set; }
|
||||
|
||||
|
||||
public spu spu { get; set; }
|
||||
public string all; //所有需要被搜索的信息,包括品牌,分类,标题
|
||||
public string subtitle; //子标题
|
||||
public brand brand;
|
||||
public category cid1;
|
||||
public category cid2;
|
||||
public category cid3;
|
||||
public DateTime? createTime;
|
||||
|
||||
|
||||
public HashSet<double> price = new HashSet<double>(); //是所有sku的价格集合。方便根据价格进行筛选过滤
|
||||
public List<sku> skus; //sku信息的json结构数据
|
||||
public Dictionary<string, object> specs = new Dictionary<string, object>(); //可搜索的规格参数,key是参数名,值是参数值
|
||||
}
|
||||
}
|
||||
20
Yi.Framework/Yi.Framework.Model/Search/PageResult.cs
Normal file
20
Yi.Framework/Yi.Framework.Model/Search/PageResult.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Yi.Framework.Model.Search
|
||||
{
|
||||
public class PageResult<T>
|
||||
{
|
||||
public static readonly long serialVersionUID = 4612105649493688532L;
|
||||
public long total; // 总记录数
|
||||
public int totalPages; //总页数
|
||||
public List<T> rows; // 每页显示的数据集合
|
||||
|
||||
public PageResult(long total, List<T> rows)
|
||||
{
|
||||
this.total = total;
|
||||
this.rows = rows;
|
||||
}
|
||||
}
|
||||
}
|
||||
39
Yi.Framework/Yi.Framework.Model/Search/SearchRequest.cs
Normal file
39
Yi.Framework/Yi.Framework.Model/Search/SearchRequest.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Yi.Framework.Model.Search
|
||||
{
|
||||
public class SearchRequest
|
||||
{
|
||||
public static readonly int DEFAULT_PAGE = 1;
|
||||
public static readonly int DEFAULT_SIZE = 20;
|
||||
public string key { get; set; }
|
||||
public int page { get; set; }
|
||||
//排序字段
|
||||
public string sortBy { get; set; }
|
||||
//是否降序
|
||||
public bool descending { get; set; }
|
||||
//过滤字段
|
||||
public Dictionary<string, string> filter = new Dictionary<string, string>();
|
||||
|
||||
public int getPage()
|
||||
{
|
||||
if (page == 0)
|
||||
{
|
||||
return DEFAULT_PAGE;
|
||||
}
|
||||
// 获取页码时做一些校验,不能小于1
|
||||
return Math.Max(DEFAULT_PAGE, page);
|
||||
}
|
||||
|
||||
public int getSize()
|
||||
{
|
||||
return DEFAULT_SIZE;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
31
Yi.Framework/Yi.Framework.Model/Search/SearchResult.cs
Normal file
31
Yi.Framework/Yi.Framework.Model/Search/SearchResult.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Yi.Framework.Model.Models;
|
||||
|
||||
namespace Yi.Framework.Model.Search
|
||||
{
|
||||
public class SearchResult<Goods> : PageResult<Goods>
|
||||
{
|
||||
public List<brand> brands = new List<brand>();
|
||||
public List<category> categories = new List<category>();
|
||||
//规格参数过滤条件
|
||||
public List<Dictionary<string, object>> specs = new List<Dictionary<string, object>>();
|
||||
public SearchResult(long total,
|
||||
int totalPage,
|
||||
List<Goods> items,
|
||||
List<category> categories,
|
||||
List<brand> brands,
|
||||
List<Dictionary<string, object>> specs) : base
|
||||
(total, items)
|
||||
{
|
||||
|
||||
this.categories = categories;
|
||||
this.brands = brands;
|
||||
this.specs = specs;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
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