Merge branch 'sqlsugar-dev' of https://gitee.com/ccnetcore/Yi into sqlsugar-dev

This commit is contained in:
橙子
2022-10-23 22:29:44 +08:00
107 changed files with 1702 additions and 370 deletions

View File

@@ -51,7 +51,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
{
//如果标题为空默认为内容的前20个字符
entity.Title = string.IsNullOrEmpty(entity.Title) ?
(entity.Content.Length > 20 ? entity.Content.Substring(0, 20) : entity.Content) :
(entity.Content?.Length > 20 ? entity.Content.Substring(0, 20) : entity.Content) :
entity.Title;
entity.UserId = HttpContext.GetUserIdInfo();
return base.Add(entity);

View File

@@ -0,0 +1,28 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Yi.Framework.Common.Models;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Repository;
using Yi.Framework.WebCore;
using Yi.Framework.WebCore.AttributeExtend;
using Yi.Framework.WebCore.AuthorizationPolicy;
namespace Yi.Framework.ApiMicroservice.Controllers
{
[ApiController]
[Route("api/[controller]/[action]")]
public class CategoryController : BaseCrudController<CategoryEntity>
{
private ICategoryService _iCategoryService;
public CategoryController(ILogger<CategoryEntity> logger, ICategoryService iCategoryService) : base(logger, iCategoryService)
{
_iCategoryService = iCategoryService;
}
}
}

View File

@@ -0,0 +1,114 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
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;
using Yi.Framework.Repository;
using Yi.Framework.WebCore;
using Yi.Framework.WebCore.AttributeExtend;
using Yi.Framework.WebCore.AuthorizationPolicy;
namespace Yi.Framework.ApiMicroservice.Controllers
{
[ApiController]
[Route("api/[controller]/[action]")]
public class SkuController : BaseSimpleCrudController<SkuEntity>
{
private ISkuService _iSkuService;
public SkuController(ILogger<SkuEntity> logger, ISkuService iSkuService) : base(logger, iSkuService)
{
_iSkuService = iSkuService;
}
/// <summary>
/// 动态条件分页查询
/// </summary>
/// <returns></returns>
[HttpGet]
public async Task<Result> PageList([FromQuery] SkuEntity eneity, [FromQuery] PageParModel page)
{
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

@@ -0,0 +1,28 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Yi.Framework.Common.Models;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Repository;
using Yi.Framework.WebCore;
using Yi.Framework.WebCore.AttributeExtend;
using Yi.Framework.WebCore.AuthorizationPolicy;
namespace Yi.Framework.ApiMicroservice.Controllers
{
[ApiController]
[Route("api/[controller]/[action]")]
public class SpecsController : BaseCrudController<SpecsEntity>
{
private ISpecsService _iSpecsService;
public SpecsController(ILogger<SpecsEntity> logger, ISpecsService iSpecsService) : base(logger, iSpecsService)
{
_iSpecsService = iSpecsService;
}
}
}

View File

@@ -0,0 +1,28 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Yi.Framework.Common.Models;
using Yi.Framework.Interface;
using Yi.Framework.Model.Models;
using Yi.Framework.Repository;
using Yi.Framework.WebCore;
using Yi.Framework.WebCore.AttributeExtend;
using Yi.Framework.WebCore.AuthorizationPolicy;
namespace Yi.Framework.ApiMicroservice.Controllers
{
[ApiController]
[Route("api/[controller]/[action]")]
public class SpecsGroupController : BaseCrudController<SpecsGroupEntity>
{
private ISpecsGroupService _iSpecsGroupService;
public SpecsGroupController(ILogger<SpecsGroupEntity> logger, ISpecsGroupService iSpecsGroupService) : base(logger, iSpecsGroupService)
{
_iSpecsGroupService = iSpecsGroupService;
}
}
}

View File

@@ -0,0 +1,88 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
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;
using Yi.Framework.Repository;
using Yi.Framework.WebCore;
using Yi.Framework.WebCore.AttributeExtend;
using Yi.Framework.WebCore.AuthorizationPolicy;
namespace Yi.Framework.ApiMicroservice.Controllers
{
[ApiController]
[Route("api/[controller]/[action]")]
public class SpuController : BaseSimpleCrudController<SpuEntity>
{
private ISpuService _iSpuService;
public SpuController(ILogger<SpuEntity> logger, ISpuService iSpuService) : base(logger, iSpuService)
{
_iSpuService = iSpuService;
}
/// <summary>
/// 动态条件分页查询
/// </summary>
/// <returns></returns>
[HttpGet]
public async Task<Result> PageList([FromQuery] SpuEntity eneity, [FromQuery] PageParModel page)
{
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

@@ -272,7 +272,7 @@ namespace Yi.Framework.ApiMicroservice.Controllers
public Result SeedDb()
{
var rep = _iUserService._repository;
return Result.Success().SetStatus(DbSeedExtend.Invoer(rep._Db));
return Result.Success().SetStatus(DbSeedExtend.DataInvoer(rep._Db));
}
/// <summary>