spu、skus数据测试

This commit is contained in:
陈淳
2022-10-20 18:11:54 +08:00
parent ff7eecee55
commit 30158ac145
8 changed files with 199 additions and 3 deletions

View File

@@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Yi.Framework.Common.Enum;
using Yi.Framework.Common.Models;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
@@ -34,5 +35,80 @@ namespace Yi.Framework.ApiMicroservice.Controllers
{
return Result.Success().SetData(await _iSkuService.SelctPageList(eneity, page));
}
//数据测试
[HttpGet]
public async Task<Result> Test(OperEnum operEnum)
{
switch (operEnum)
{
case OperEnum.Insert:
List<SkuEntity> spus = new();
var sku1 = new SkuEntity()
{
Id = 1,
Stock = 100,
IsDeleted = false,
SpuId = 1,
Price = 1000,
SpecsSkuAllInfo = new List<SpecsSkuAllInfoModel> {
new SpecsSkuAllInfoModel { SpecsGroupName="内存",SpecsName="1GB" } ,
new SpecsSkuAllInfoModel { SpecsGroupName="颜色",SpecsName= "红" } },
};
var sku2 = new SkuEntity()
{
Id = 2,
Stock = 100,
IsDeleted = false,
SpuId = 1,
Price = 4000,
SpecsSkuAllInfo = new List<SpecsSkuAllInfoModel> {
new SpecsSkuAllInfoModel { SpecsGroupName="内存",SpecsName="2GB" } ,
new SpecsSkuAllInfoModel { SpecsGroupName="颜色",SpecsName= "绿" } },
};
var sku3 = new SkuEntity()
{
Id = 3,
Stock = 100,
IsDeleted = false,
SpuId = 2,
Price = 2000,
SpecsSkuAllInfo = new List<SpecsSkuAllInfoModel> {
new SpecsSkuAllInfoModel { SpecsGroupName="内存",SpecsName="3GB" } ,
new SpecsSkuAllInfoModel { SpecsGroupName="颜色",SpecsName= "红" } },
};
var sku4 = new SkuEntity()
{
Id = 4,
Stock = 100,
IsDeleted = false,
SpuId = 2,
Price = 1000,
SpecsSkuAllInfo = new List<SpecsSkuAllInfoModel> {
new SpecsSkuAllInfoModel { SpecsGroupName="内存",SpecsName="2GB" } ,
new SpecsSkuAllInfoModel { SpecsGroupName="颜色",SpecsName= "蓝" } },
};
spus.Add(sku1);
spus.Add(sku2);
spus.Add(sku3);
spus.Add(sku4);
await _iSkuService._repository.InsertRangeAsync(spus);
break;
case OperEnum.Delete:
await _iSkuService._repository.DeleteAsync((u)=>true);
break;
default:
break;
}
return Result.Success();
}
}
}

View File

@@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Yi.Framework.Common.Enum;
using Yi.Framework.Common.Models;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
@@ -34,5 +35,54 @@ namespace Yi.Framework.ApiMicroservice.Controllers
{
return Result.Success().SetData(await _iSpuService.SelctPageList(eneity, page));
}
//数据测试
[HttpGet]
public async Task<Result> Test(OperEnum operEnum)
{
switch (operEnum)
{
case OperEnum.Insert:
List<SpuEntity> spus = new();
var spu1 = new SpuEntity()
{
Id = 1,
SpuName = "华为mate40 5G手机",
IsDeleted = false,
Details = "华为手机就是牛",
Price = "1000-2000",
SpecsSpuAllInfo = new List<SpecsSpuAllInfoModel> {
new SpecsSpuAllInfoModel { SpecsGroupName="内存",SpecsNames=new List<string> { "1GB","2GB","3GB"} } ,
new SpecsSpuAllInfoModel { SpecsGroupName="颜色",SpecsNames=new List<string> { "红","蓝","绿"} } },
};
var spu2 = new SpuEntity()
{
Id = 2,
SpuName = "小米888 8G手机",
IsDeleted = false,
Details = "小米手机就是牛",
Price = "2000-3000",
SpecsSpuAllInfo = new List<SpecsSpuAllInfoModel> {
new SpecsSpuAllInfoModel { SpecsGroupName="内存",SpecsNames=new List<string> { "1GB","2GB","3GB"} } ,
new SpecsSpuAllInfoModel { SpecsGroupName="颜色",SpecsNames=new List<string> { "红","蓝","绿"} } },
};
spus.Add(spu1);
spus.Add(spu2);
await _iSpuService._repository.InsertRangeAsync(spus);
break;
case OperEnum.Delete:
await _iSpuService._repository.DeleteAsync((u) => true);
break;
default:
break;
}
return Result.Success();
}
}
}

View File

@@ -14,7 +14,7 @@ namespace Yi.Framework.Service
{
RefAsync<int> total = 0;
var data = await _repository._DbQueryable
.Includes(spu=>spu.Skus)
.WhereIF(page.StartTime is not null && page.EndTime is not null, u => u.CreateTime >= page.StartTime && u.CreateTime <= page.EndTime)
.WhereIF(enetity.IsDeleted is not null, u => u.IsDeleted == enetity.IsDeleted)
.OrderBy(u => u.CreateTime, OrderByType.Desc)

View File

@@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;
namespace Yi.Framework.WebCore.BuilderExtend
@@ -13,11 +14,14 @@ namespace Yi.Framework.WebCore.BuilderExtend
{
public static void AddJsonFileService(this IMvcBuilder builder)
{
builder.AddJsonOptions(options =>
options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()));
builder.AddNewtonsoftJson(options =>
{
options.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm";
//options.SerializerSettings.Converters.Add(new ValueToStringConverter());
});