diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml index d92fa4c9..34d4d413 100644 --- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml +++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml @@ -150,6 +150,18 @@ + + + 动态条件分页查询 + + + + + + 动态条件分页查询 + + + 账户管理 diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/Article/ArticleController.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/Article/ArticleController.cs index 50f7ff67..36ee1e7a 100644 --- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/Article/ArticleController.cs +++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/Article/ArticleController.cs @@ -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); diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/Shop/SkuController.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/Shop/SkuController.cs index 22a37906..a0e840b5 100644 --- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/Shop/SkuController.cs +++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/Shop/SkuController.cs @@ -17,12 +17,22 @@ namespace Yi.Framework.ApiMicroservice.Controllers { [ApiController] [Route("api/[controller]/[action]")] - public class SkuController : BaseCrudController + public class SkuController : BaseSimpleCrudController { private ISkuService _iSkuService; public SkuController(ILogger logger, ISkuService iSkuService) : base(logger, iSkuService) { _iSkuService = iSkuService; } + + /// + /// 动态条件分页查询 + /// + /// + [HttpGet] + public async Task PageList([FromQuery] SkuEntity eneity, [FromQuery] PageParModel page) + { + return Result.Success().SetData(await _iSkuService.SelctPageList(eneity, page)); + } } } diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/Shop/SpuController.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/Shop/SpuController.cs index e16727d2..2ee37fc0 100644 --- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/Shop/SpuController.cs +++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/Shop/SpuController.cs @@ -17,12 +17,22 @@ namespace Yi.Framework.ApiMicroservice.Controllers { [ApiController] [Route("api/[controller]/[action]")] - public class SpuController : BaseCrudController + public class SpuController : BaseSimpleCrudController { private ISpuService _iSpuService; public SpuController(ILogger logger, ISpuService iSpuService) : base(logger, iSpuService) { _iSpuService = iSpuService; } + + /// + /// 动态条件分页查询 + /// + /// + [HttpGet] + public async Task PageList([FromQuery] SpuEntity eneity, [FromQuery] PageParModel page) + { + return Result.Success().SetData(await _iSpuService.SelctPageList(eneity, page)); + } } } diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db index 8600b943..befd8906 100644 Binary files a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db and b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db differ diff --git a/Yi.Framework.Net6/Yi.Framework.Interface/ISkuService.cs b/Yi.Framework.Net6/Yi.Framework.Interface/ISkuService.cs new file mode 100644 index 00000000..f1766465 --- /dev/null +++ b/Yi.Framework.Net6/Yi.Framework.Interface/ISkuService.cs @@ -0,0 +1,19 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Yi.Framework.Common.Models; +using Yi.Framework.Model.Models; +using Yi.Framework.Repository; + +namespace Yi.Framework.Interface +{ + public partial interface ISkuService:IBaseService + { + /// + /// 动态条件分页查询 + /// + /// + /// + /// + Task>> SelctPageList(SkuEntity entity, PageParModel page); + } +} diff --git a/Yi.Framework.Net6/Yi.Framework.Interface/ISpuService.cs b/Yi.Framework.Net6/Yi.Framework.Interface/ISpuService.cs new file mode 100644 index 00000000..01532604 --- /dev/null +++ b/Yi.Framework.Net6/Yi.Framework.Interface/ISpuService.cs @@ -0,0 +1,19 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using Yi.Framework.Common.Models; +using Yi.Framework.Model.Models; +using Yi.Framework.Repository; + +namespace Yi.Framework.Interface +{ + public partial interface ISpuService:IBaseService + { + /// + /// 动态条件分页查询 + /// + /// + /// + /// + Task>> SelctPageList(SpuEntity entity, PageParModel page); + } +} diff --git a/Yi.Framework.Net6/Yi.Framework.Model/ModelsTemplate/SpuEntity.cs b/Yi.Framework.Net6/Yi.Framework.Model/ModelsTemplate/SpuEntity.cs index f1b2453d..51db453a 100644 --- a/Yi.Framework.Net6/Yi.Framework.Model/ModelsTemplate/SpuEntity.cs +++ b/Yi.Framework.Net6/Yi.Framework.Model/ModelsTemplate/SpuEntity.cs @@ -27,17 +27,17 @@ namespace Yi.Framework.Model.Models /// 商品名称 /// [SugarColumn(ColumnName="SpuName" )] - public string SpuName { get; set; } + public string? SpuName { get; set; } /// /// 商品详情 /// [SugarColumn(ColumnName="Details" )] - public string Details { get; set; } + public string? Details { get; set; } /// /// 商品价格 /// [SugarColumn(ColumnName="Price" )] - public string Price { get; set; } + public string? Price { get; set; } /// /// 创建者 diff --git a/Yi.Framework.Net6/Yi.Framework.Model/SpuEntity.cs b/Yi.Framework.Net6/Yi.Framework.Model/SpuEntity.cs index cb09b8df..30ef1e5b 100644 --- a/Yi.Framework.Net6/Yi.Framework.Model/SpuEntity.cs +++ b/Yi.Framework.Net6/Yi.Framework.Model/SpuEntity.cs @@ -20,7 +20,7 @@ namespace Yi.Framework.Model.Models public List? SpecsSpuInfo { get; set; } [Navigate(NavigateType.OneToMany, nameof(SkuEntity.SpuId))] - public List? Spus { get; set; } + public List? Skus { get; set; } } public class SpecsSpuAllInfoModel diff --git a/Yi.Framework.Net6/Yi.Framework.Service/SkuService.cs b/Yi.Framework.Net6/Yi.Framework.Service/SkuService.cs new file mode 100644 index 00000000..93bb7fe4 --- /dev/null +++ b/Yi.Framework.Net6/Yi.Framework.Service/SkuService.cs @@ -0,0 +1,25 @@ +using SqlSugar; +using System.Collections.Generic; +using System.Threading.Tasks; +using Yi.Framework.Common.Models; +using Yi.Framework.Interface; +using Yi.Framework.Model.Models; +using Yi.Framework.Repository; + +namespace Yi.Framework.Service +{ + public partial class SkuService : BaseService, ISkuService + { + public async Task>> SelctPageList(SkuEntity enetity, PageParModel page) + { + RefAsync total = 0; + var data = await _repository._DbQueryable + + .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) + .ToPageListAsync(page.PageNum, page.PageSize, total); + return new PageModel>(data, total); + } + } +} diff --git a/Yi.Framework.Net6/Yi.Framework.Service/SpuService.cs b/Yi.Framework.Net6/Yi.Framework.Service/SpuService.cs new file mode 100644 index 00000000..1063ce57 --- /dev/null +++ b/Yi.Framework.Net6/Yi.Framework.Service/SpuService.cs @@ -0,0 +1,25 @@ +using SqlSugar; +using System.Collections.Generic; +using System.Threading.Tasks; +using Yi.Framework.Common.Models; +using Yi.Framework.Interface; +using Yi.Framework.Model.Models; +using Yi.Framework.Repository; + +namespace Yi.Framework.Service +{ + public partial class SpuService : BaseService, ISpuService + { + public async Task>> SelctPageList(SpuEntity enetity, PageParModel page) + { + RefAsync total = 0; + var data = await _repository._DbQueryable + + .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) + .ToPageListAsync(page.PageNum, page.PageSize, total); + return new PageModel>(data, total); + } + } +}