/***********************************************************************
* Project: baifenBinfa
* ProjectName: 百分兵法管理系统
* Web: http://chuanyin.com
* Author:
* Email:
* CreateTime: 2024/7/31 14:49:41
* Description: 暂无
***********************************************************************/
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading.Tasks;
using CoreCms.Net.Caching.Manual;
using CoreCms.Net.Configuration;
using CoreCms.Net.Model.Entities;
using CoreCms.Net.Model.ViewModels.Basics;
using CoreCms.Net.IRepository;
using CoreCms.Net.IRepository.UnitOfWork;
using CoreCms.Net.Model.ViewModels.UI;
using SqlSugar;
namespace CoreCms.Net.Repository
{
///
/// 商品表 接口实现
///
public class DistributionGoodsRepository : BaseRepository, IDistributionGoodsRepository
{
private readonly IUnitOfWork _unitOfWork;
public DistributionGoodsRepository(IUnitOfWork unitOfWork) : base(unitOfWork)
{
_unitOfWork = unitOfWork;
}
#region 实现重写增删改查操作==========================================================
///
/// 重写异步插入方法
///
/// 实体数据
///
public async Task InsertAsync(CoreCmsGoods entity)
{
var jm = new AdminUiCallBack();
var bl = await DbClient.Insertable(entity).ExecuteReturnIdentityAsync() > 0;
jm.code = bl ? 0 : 1;
jm.msg = bl ? GlobalConstVars.CreateSuccess : GlobalConstVars.CreateFailure;
return jm;
}
///
/// 重写异步更新方法
///
///
///
public async Task UpdateAsync(CoreCmsGoods entity)
{
var jm = new AdminUiCallBack();
var oldModel = await DbClient.Queryable().In(entity.id).SingleAsync();
if (oldModel == null)
{
jm.msg = "不存在此信息";
return jm;
}
//事物处理过程开始
oldModel.id = entity.id;
oldModel.bn = entity.bn;
oldModel.name = entity.name;
oldModel.brief = entity.brief;
oldModel.image = entity.image;
oldModel.images = entity.images;
oldModel.video = entity.video;
oldModel.productsDistributionType = entity.productsDistributionType;
oldModel.goodsCategoryId = entity.goodsCategoryId;
oldModel.goodsTypeId = entity.goodsTypeId;
oldModel.goodsSkuIds = entity.goodsSkuIds;
oldModel.goodsParamsIds = entity.goodsParamsIds;
oldModel.brandId = entity.brandId;
oldModel.isNomalVirtual = entity.isNomalVirtual;
oldModel.isMarketable = entity.isMarketable;
oldModel.unit = entity.unit;
oldModel.intro = entity.intro;
oldModel.spesDesc = entity.spesDesc;
oldModel.parameters = entity.parameters;
oldModel.commentsCount = entity.commentsCount;
oldModel.viewCount = entity.viewCount;
oldModel.buyCount = entity.buyCount;
oldModel.uptime = entity.uptime;
oldModel.downtime = entity.downtime;
oldModel.sort = entity.sort;
oldModel.labelIds = entity.labelIds;
oldModel.newSpec = entity.newSpec;
oldModel.openSpec = entity.openSpec;
oldModel.createTime = entity.createTime;
oldModel.updateTime = entity.updateTime;
oldModel.isRecommend = entity.isRecommend;
oldModel.isHot = entity.isHot;
oldModel.isDel = entity.isDel;
oldModel.initialSales = entity.initialSales;
oldModel.areaCode = entity.areaCode;
oldModel.publisherId = entity.publisherId;
oldModel.approverId = entity.approverId;
oldModel.auditStatus = entity.auditStatus;
oldModel.auditTime = entity.auditTime;
//事物处理过程结束
var bl = await DbClient.Updateable(oldModel).ExecuteCommandHasChangeAsync();
jm.code = bl ? 0 : 1;
jm.msg = bl ? GlobalConstVars.EditSuccess : GlobalConstVars.EditFailure;
return jm;
}
///
/// 重写异步更新方法
///
///
///
public async Task UpdateAsync(List entity)
{
var jm = new AdminUiCallBack();
var bl = await DbClient.Updateable(entity).ExecuteCommandHasChangeAsync();
jm.code = bl ? 0 : 1;
jm.msg = bl ? GlobalConstVars.EditSuccess : GlobalConstVars.EditFailure;
return jm;
}
///
/// 重写删除指定ID的数据
///
///
///
public async Task DeleteByIdAsync(object id)
{
var jm = new AdminUiCallBack();
var bl = await DbClient.Deleteable(id).ExecuteCommandHasChangeAsync();
jm.code = bl ? 0 : 1;
jm.msg = bl ? GlobalConstVars.DeleteSuccess : GlobalConstVars.DeleteFailure;
return jm;
}
///
/// 重写删除指定ID集合的数据(批量删除)
///
///
///
public async Task DeleteByIdsAsync(int[] ids)
{
var jm = new AdminUiCallBack();
var bl = await DbClient.Deleteable().In(ids).ExecuteCommandHasChangeAsync();
jm.code = bl ? 0 : 1;
jm.msg = bl ? GlobalConstVars.DeleteSuccess : GlobalConstVars.DeleteFailure;
return jm;
}
#endregion
#region 获取缓存的所有数据==========================================================
///
/// 获取缓存的所有数据
///
///
public async Task> GetCaChe()
{
var list = await DbClient.Queryable().With(SqlWith.NoLock).WithCache().ToListAsync();
return list;
}
#endregion
#region 重写根据条件查询分页数据
///
/// 重写根据条件查询分页数据
///
/// 判断集合
/// 排序方式
/// 当前页面索引
/// 分布大小
///
/// 是否使用WITH(NOLOCK)
///
public async Task> QueryPageAsync(Expression> predicate,
Expression> orderByExpression, OrderByType orderByType, int pageIndex = 1,
int pageSize = 20, bool blUseNoLock = false)
{
RefAsync totalCount = 0;
List page;
if (blUseNoLock)
{
page = await DbClient.Queryable()
.OrderByIF(orderByExpression != null, orderByExpression, orderByType)
.WhereIF(predicate != null, predicate).Select(p => new CoreCmsGoods
{
id = p.id,
bn = p.bn,
name = p.name,
brief = p.brief,
image = p.image,
images = p.images,
video = p.video,
productsDistributionType = p.productsDistributionType,
goodsCategoryId = p.goodsCategoryId,
goodsTypeId = p.goodsTypeId,
goodsSkuIds = p.goodsSkuIds,
goodsParamsIds = p.goodsParamsIds,
brandId = p.brandId,
isNomalVirtual = p.isNomalVirtual,
isMarketable = p.isMarketable,
unit = p.unit,
intro = p.intro,
spesDesc = p.spesDesc,
parameters = p.parameters,
commentsCount = p.commentsCount,
viewCount = p.viewCount,
buyCount = p.buyCount,
uptime = p.uptime,
downtime = p.downtime,
sort = p.sort,
labelIds = p.labelIds,
newSpec = p.newSpec,
openSpec = p.openSpec,
createTime = p.createTime,
updateTime = p.updateTime,
isRecommend = p.isRecommend,
isHot = p.isHot,
isDel = p.isDel,
initialSales = p.initialSales,
areaCode = p.areaCode,
publisherId = p.publisherId,
approverId = p.approverId,
auditStatus = p.auditStatus,
auditTime = p.auditTime,
}).With(SqlWith.NoLock).ToPageListAsync(pageIndex, pageSize, totalCount);
}
else
{
page = await DbClient.Queryable()
.OrderByIF(orderByExpression != null, orderByExpression, orderByType)
.WhereIF(predicate != null, predicate).Select(p => new CoreCmsGoods
{
id = p.id,
bn = p.bn,
name = p.name,
brief = p.brief,
image = p.image,
images = p.images,
video = p.video,
productsDistributionType = p.productsDistributionType,
goodsCategoryId = p.goodsCategoryId,
goodsTypeId = p.goodsTypeId,
goodsSkuIds = p.goodsSkuIds,
goodsParamsIds = p.goodsParamsIds,
brandId = p.brandId,
isNomalVirtual = p.isNomalVirtual,
isMarketable = p.isMarketable,
unit = p.unit,
intro = p.intro,
spesDesc = p.spesDesc,
parameters = p.parameters,
commentsCount = p.commentsCount,
viewCount = p.viewCount,
buyCount = p.buyCount,
uptime = p.uptime,
downtime = p.downtime,
sort = p.sort,
labelIds = p.labelIds,
newSpec = p.newSpec,
openSpec = p.openSpec,
createTime = p.createTime,
updateTime = p.updateTime,
isRecommend = p.isRecommend,
isHot = p.isHot,
isDel = p.isDel,
initialSales = p.initialSales,
areaCode = p.areaCode,
publisherId = p.publisherId,
approverId = p.approverId,
auditStatus = p.auditStatus,
auditTime = p.auditTime,
}).ToPageListAsync(pageIndex, pageSize, totalCount);
}
var list = new PageList(page, pageIndex, pageSize, totalCount);
return list;
}
#endregion
}
}