From 090b503f8de661cb353326b245bdfe8d15503540 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A4=A7=E7=81=B0=E7=81=B0?= Date: Wed, 7 Dec 2022 01:49:30 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BF=AE=E5=A4=8D=E3=80=91=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E5=95=86=E5=93=81=E4=B8=8B=E6=9E=B6=E6=88=96=E8=80=85?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=90=8E=EF=BC=8C=E3=80=90=E6=88=91=E7=9A=84?= =?UTF-8?q?=E8=B6=B3=E8=BF=B9=E3=80=91=E7=BB=9F=E8=AE=A1=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=8F=8A=E5=88=97=E8=A1=A8=E4=B8=8D=E5=87=86=E7=A1=AE=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98=E3=80=82=20=E3=80=90=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E3=80=91=E4=BF=AE=E5=A4=8D=E5=95=86=E5=93=81=E4=B8=8B=E6=9E=B6?= =?UTF-8?q?=E6=88=96=E8=80=85=E5=88=A0=E9=99=A4=E5=90=8E=EF=BC=8C=E3=80=90?= =?UTF-8?q?=E6=88=91=E7=9A=84=E6=94=B6=E8=97=8F=E3=80=91=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=8F=8A=E5=88=97=E8=A1=A8=E4=B8=8D=E5=87=86?= =?UTF-8?q?=E7=A1=AE=E7=9A=84=E9=97=AE=E9=A2=98=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Good/ICoreCmsGoodsCollectionRepository.cs | 10 ++++++ .../Good/ICoreCmsGoodsCollectionServices.cs | 9 ++++++ .../Good/CoreCmsGoodsCollectionRepository.cs | 31 ++++++++++++++++++- .../Good/CoreCmsGoodsCollectionServices.cs | 9 ++++++ .../Controllers/UserController.cs | 2 +- 5 files changed, 59 insertions(+), 2 deletions(-) diff --git a/CoreCms.Net.IRepository/Good/ICoreCmsGoodsCollectionRepository.cs b/CoreCms.Net.IRepository/Good/ICoreCmsGoodsCollectionRepository.cs index dfb5fdf7..2315fa1f 100644 --- a/CoreCms.Net.IRepository/Good/ICoreCmsGoodsCollectionRepository.cs +++ b/CoreCms.Net.IRepository/Good/ICoreCmsGoodsCollectionRepository.cs @@ -23,6 +23,16 @@ namespace CoreCms.Net.IRepository /// public interface ICoreCmsGoodsCollectionRepository : IBaseRepository { + + /// + /// 根据用户序列获取用户的收藏 + /// + /// + /// + + Task GetUserCountAsync(int userId); + + /// /// 重写根据条件查询分页数据 /// diff --git a/CoreCms.Net.IServices/Good/ICoreCmsGoodsCollectionServices.cs b/CoreCms.Net.IServices/Good/ICoreCmsGoodsCollectionServices.cs index 2af16bd1..ffc448b9 100644 --- a/CoreCms.Net.IServices/Good/ICoreCmsGoodsCollectionServices.cs +++ b/CoreCms.Net.IServices/Good/ICoreCmsGoodsCollectionServices.cs @@ -23,6 +23,15 @@ namespace CoreCms.Net.IServices /// public interface ICoreCmsGoodsCollectionServices : IBaseServices { + /// + /// 根据用户序列获取用户的收藏 + /// + /// + /// + + Task GetUserCountAsync(int userId); + + /// /// 检查是否收藏了此商品 /// diff --git a/CoreCms.Net.Repository/Good/CoreCmsGoodsCollectionRepository.cs b/CoreCms.Net.Repository/Good/CoreCmsGoodsCollectionRepository.cs index 5426c9c8..b5a30ae6 100644 --- a/CoreCms.Net.Repository/Good/CoreCmsGoodsCollectionRepository.cs +++ b/CoreCms.Net.Repository/Good/CoreCmsGoodsCollectionRepository.cs @@ -32,6 +32,23 @@ namespace CoreCms.Net.Repository { } + + /// + /// 根据用户序列获取用户的足迹数量 + /// + /// + /// + + public async Task GetUserCountAsync(int userId) + { + var count = await DbClient.Queryable((gc, goods) => + new JoinQueryInfos(JoinType.Left, gc.goodsId == goods.id)) + .Where((gc, goods) => goods.isDel == false && goods.isMarketable == true && gc.userId == userId).With(SqlWith.NoLock).CountAsync(); + return count; + } + + + #region 重写根据条件查询分页数据 /// /// 重写根据条件查询分页数据 @@ -47,7 +64,19 @@ namespace CoreCms.Net.Repository int pageSize = 20) { RefAsync totalCount = 0; - var page = await DbClient.Queryable() + var page = await DbClient.Queryable((gc, goods) => + new JoinQueryInfos(JoinType.Left, gc.goodsId == goods.id)) + .Where((gc, goods) => goods.isDel == false && goods.isMarketable == true) + .Select((gc, goods) => new CoreCmsGoodsCollection + { + id = gc.id, + userId = gc.userId, + goodsId = gc.goodsId, + createTime = gc.createTime, + goodsName = gc.goodsName + }) + .With(SqlWith.NoLock) + .MergeTable() .OrderByIF(orderByExpression != null, orderByExpression, orderByType) .WhereIF(predicate != null, predicate) .Mapper(p => p.goods, p => p.goodsId) diff --git a/CoreCms.Net.Services/Good/CoreCmsGoodsCollectionServices.cs b/CoreCms.Net.Services/Good/CoreCmsGoodsCollectionServices.cs index a771c59a..e99ff3d2 100644 --- a/CoreCms.Net.Services/Good/CoreCmsGoodsCollectionServices.cs +++ b/CoreCms.Net.Services/Good/CoreCmsGoodsCollectionServices.cs @@ -41,6 +41,15 @@ namespace CoreCms.Net.Services _unitOfWork = unitOfWork; } + /// + /// 根据用户序列获取用户的收藏 + /// + /// + /// + public async Task GetUserCountAsync(int userId) + { + return await _dal.GetUserCountAsync(userId); + } /// /// 检查是否收藏了此商品 diff --git a/CoreCms.Net.Web.WebApi/Controllers/UserController.cs b/CoreCms.Net.Web.WebApi/Controllers/UserController.cs index 629a819c..07fb9db0 100644 --- a/CoreCms.Net.Web.WebApi/Controllers/UserController.cs +++ b/CoreCms.Net.Web.WebApi/Controllers/UserController.cs @@ -841,7 +841,7 @@ namespace CoreCms.Net.Web.WebApi.Controllers //足迹 var footPrintCount = await _goodsBrowsingServices.GetUserCountAsync(user.id); //收藏 - var collectionCount = await _goodsCollectionServices.GetCountAsync(p => p.userId == user.id); + var collectionCount = await _goodsCollectionServices.GetUserCountAsync(user.id); if (user.sex != (int)GlobalEnumVars.UserSexTypes.女 && user.sex != (int)GlobalEnumVars.UserSexTypes.男 && user.sex != (int)GlobalEnumVars.UserSexTypes.未知) {