/***********************************************************************
* Project: baifenBinfa
* ProjectName: 百分兵法管理系统
* Web: http://chuanyin.com
* Author:
* Email:
* CreateTime: 202403/02
* Description: 暂无
***********************************************************************/
using System;
using System.Linq.Expressions;
using System.Threading.Tasks;
using CoreCms.Net.IRepository;
using CoreCms.Net.IRepository.UnitOfWork;
using CoreCms.Net.Model.Entities;
using CoreCms.Net.Model.ViewModels.Basics;
using SqlSugar;
namespace CoreCms.Net.Repository
{
///
/// 商品浏览记录表 接口实现
///
public class CoreCmsGoodsBrowsingRepository : BaseRepository, ICoreCmsGoodsBrowsingRepository
{
public CoreCmsGoodsBrowsingRepository(IUnitOfWork unitOfWork) : base(unitOfWork)
{
}
///
/// 根据用户序列获取用户的足迹数量
///
///
///
public async Task GetUserCountAsync(int userId)
{
var count = await DbClient.Queryable((gb, goods) =>
new JoinQueryInfos(JoinType.Left, gb.goodsId == goods.id))
.Where((gb, goods) => goods.isDel == false && goods.isMarketable == true && gb.userId == userId).With(SqlWith.NoLock).CountAsync();
return count;
}
///
/// 重写根据条件查询分页数据
///
/// 判断集合
/// 排序方式
/// 当前页面索引
/// 分布大小
///
///
public async Task> QueryPageAsync(
Expression> predicate,
Expression> orderByExpression, OrderByType orderByType,
int pageIndex = 1,
int pageSize = 20)
{
RefAsync totalCount = 0;
var page = await DbClient.Queryable((gb, goods) =>
new JoinQueryInfos(JoinType.Left, gb.goodsId == goods.id))
.Where((gb, goods) => goods.isDel == false && goods.isMarketable == true)
.Select((gb, goods) => new CoreCmsGoodsBrowsing
{
id = gb.id,
goodsId = gb.goodsId,
userId = gb.userId,
goodsName = gb.goodsName,
createTime = gb.createTime,
isdel = gb.isdel,
goodImage = goods.image
//isCollection = SqlFunc.Subqueryable().Where(p => p.userId == gb.userId && p.goodsId == gb.goodsId).Any()
})
.With(SqlWith.NoLock)
.MergeTable()
.OrderByIF(orderByExpression != null, orderByExpression, orderByType)
.WhereIF(predicate != null, predicate).ToPageListAsync(pageIndex, pageSize, totalCount);
var list = new PageList(page, pageIndex, pageSize, totalCount);
return list;
}
}
}