mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2025-12-06 20:13:26 +08:00
添加项目文件。
This commit is contained in:
185
CoreCms.Net.Repository/Shop/CoreCmsAreaRepository.cs
Normal file
185
CoreCms.Net.Repository/Shop/CoreCmsAreaRepository.cs
Normal file
@@ -0,0 +1,185 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms
|
||||
* ProjectName: 核心内容管理系统
|
||||
* Web: https://www.corecms.net
|
||||
* Author: 大灰灰
|
||||
* Email: jianweie@163.com
|
||||
* CreateTime: 2021/1/31 21:45:10
|
||||
* 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
|
||||
{
|
||||
/// <summary>
|
||||
/// 地区表 接口实现
|
||||
/// </summary>
|
||||
public class CoreCmsAreaRepository : BaseRepository<CoreCmsArea>, ICoreCmsAreaRepository
|
||||
{
|
||||
public CoreCmsAreaRepository(IUnitOfWork unitOfWork) : base(unitOfWork)
|
||||
{
|
||||
}
|
||||
|
||||
#region 实现重写增删改查操作==========================================================
|
||||
|
||||
/// <summary>
|
||||
/// 重写异步插入方法
|
||||
/// </summary>
|
||||
/// <param name="entity">实体数据</param>
|
||||
/// <returns></returns>
|
||||
public new async Task<AdminUiCallBack> InsertAsync(CoreCmsArea 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;
|
||||
if (bl)
|
||||
{
|
||||
await UpdateCaChe();
|
||||
}
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重写异步更新方法
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
public new async Task<AdminUiCallBack> UpdateAsync(CoreCmsArea entity)
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
|
||||
var oldModel = await DbClient.Queryable<CoreCmsArea>().In(entity.id).SingleAsync();
|
||||
if (oldModel == null)
|
||||
{
|
||||
jm.msg = "不存在此信息";
|
||||
return jm;
|
||||
}
|
||||
//事物处理过程开始
|
||||
//oldModel.id = entity.id;
|
||||
//oldModel.parentId = entity.parentId;
|
||||
//oldModel.depth = entity.depth;
|
||||
oldModel.name = entity.name;
|
||||
oldModel.postalCode = entity.postalCode;
|
||||
oldModel.sort = entity.sort;
|
||||
|
||||
//事物处理过程结束
|
||||
var bl = await DbClient.Updateable(oldModel).ExecuteCommandHasChangeAsync();
|
||||
jm.code = bl ? 0 : 1;
|
||||
jm.msg = bl ? GlobalConstVars.EditSuccess : GlobalConstVars.EditFailure;
|
||||
if (bl)
|
||||
{
|
||||
await UpdateCaChe();
|
||||
}
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重写异步更新方法
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
public new async Task<AdminUiCallBack> UpdateAsync(List<CoreCmsArea> entity)
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
|
||||
var bl = await DbClient.Updateable(entity).ExecuteCommandHasChangeAsync();
|
||||
jm.code = bl ? 0 : 1;
|
||||
jm.msg = bl ? GlobalConstVars.EditSuccess : GlobalConstVars.EditFailure;
|
||||
if (bl)
|
||||
{
|
||||
await UpdateCaChe();
|
||||
}
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重写删除指定ID的数据
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public new async Task<AdminUiCallBack> DeleteByIdAsync(object id)
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
|
||||
var bl = await DbClient.Deleteable<CoreCmsArea>(id).ExecuteCommandHasChangeAsync();
|
||||
jm.code = bl ? 0 : 1;
|
||||
jm.msg = bl ? GlobalConstVars.DeleteSuccess : GlobalConstVars.DeleteFailure;
|
||||
if (bl)
|
||||
{
|
||||
await UpdateCaChe();
|
||||
}
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重写删除指定ID集合的数据(批量删除)
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <returns></returns>
|
||||
public new async Task<AdminUiCallBack> DeleteByIdsAsync(int[] ids)
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
|
||||
var bl = await DbClient.Deleteable<CoreCmsArea>().In(ids).ExecuteCommandHasChangeAsync();
|
||||
jm.code = bl ? 0 : 1;
|
||||
jm.msg = bl ? GlobalConstVars.DeleteSuccess : GlobalConstVars.DeleteFailure;
|
||||
if (bl)
|
||||
{
|
||||
await UpdateCaChe();
|
||||
}
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 获取缓存的所有数据==========================================================
|
||||
|
||||
/// <summary>
|
||||
/// 获取缓存的所有数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<List<CoreCmsArea>> GetCaChe()
|
||||
{
|
||||
var cache = ManualDataCache.Instance.Get<List<CoreCmsArea>>(GlobalConstVars.CacheCoreCmsArea);
|
||||
if (cache != null)
|
||||
{
|
||||
return cache;
|
||||
}
|
||||
return await UpdateCaChe();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新cache
|
||||
/// </summary>
|
||||
public async Task<List<CoreCmsArea>> UpdateCaChe()
|
||||
{
|
||||
|
||||
var list = await DbClient.Queryable<CoreCmsArea>().OrderBy(p=>p.sort).With(SqlWith.NoLock).ToListAsync();
|
||||
ManualDataCache.Instance.Set(GlobalConstVars.CacheCoreCmsArea, list);
|
||||
return list;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
170
CoreCms.Net.Repository/Shop/CoreCmsClerkRepository.cs
Normal file
170
CoreCms.Net.Repository/Shop/CoreCmsClerkRepository.cs
Normal file
@@ -0,0 +1,170 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms
|
||||
* ProjectName: 核心内容管理系统
|
||||
* Web: https://www.corecms.net
|
||||
* Author: 大灰灰
|
||||
* Email: jianweie@163.com
|
||||
* CreateTime: 2021/1/31 21:45:10
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
using CoreCms.Net.Configuration;
|
||||
using CoreCms.Net.IRepository;
|
||||
using CoreCms.Net.IRepository.UnitOfWork;
|
||||
using CoreCms.Net.Model.Entities;
|
||||
using CoreCms.Net.Model.ViewModels.Basics;
|
||||
using CoreCms.Net.Model.ViewModels.UI;
|
||||
using CoreCms.Net.Utility.Extensions;
|
||||
using SqlSugar;
|
||||
|
||||
namespace CoreCms.Net.Repository
|
||||
{
|
||||
/// <summary>
|
||||
/// 店铺店员关联表 接口实现
|
||||
/// </summary>
|
||||
public class CoreCmsClerkRepository : BaseRepository<CoreCmsClerk>, ICoreCmsClerkRepository
|
||||
{
|
||||
public CoreCmsClerkRepository(IUnitOfWork unitOfWork) : base(unitOfWork)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
#region 获取门店关联用户分页数据
|
||||
/// <summary>
|
||||
/// 获取门店关联用户分页数据
|
||||
/// </summary>
|
||||
/// <param name="predicate">判断集合</param>
|
||||
/// <param name="orderByType">排序方式</param>
|
||||
/// <param name="pageIndex">当前页面索引</param>
|
||||
/// <param name="pageSize">分布大小</param>
|
||||
/// <param name="orderByExpression"></param>
|
||||
/// <param name="blUseNoLock">是否使用WITH(NOLOCK)</param>
|
||||
/// <returns></returns>
|
||||
public async Task<IPageList<StoreClerkDto>> QueryStoreClerkDtoPageAsync(Expression<Func<StoreClerkDto, bool>> predicate,
|
||||
Expression<Func<StoreClerkDto, object>> orderByExpression, OrderByType orderByType, int pageIndex = 1,
|
||||
int pageSize = 20, bool blUseNoLock = false)
|
||||
{
|
||||
RefAsync<int> totalCount = 0;
|
||||
List<StoreClerkDto> page;
|
||||
if (blUseNoLock)
|
||||
{
|
||||
page = await DbClient.Queryable<CoreCmsClerk, CoreCmsStore, CoreCmsUser>((p, sst, ccu) => new JoinQueryInfos(
|
||||
JoinType.Left, p.storeId == sst.id,
|
||||
JoinType.Left, p.userId == ccu.id
|
||||
))
|
||||
.Select((p, sst, ccu) => new StoreClerkDto
|
||||
{
|
||||
id = p.id,
|
||||
storeId = p.storeId,
|
||||
userId = p.userId,
|
||||
isDel = p.isDel,
|
||||
createTime = p.createTime,
|
||||
updateTime = p.updateTime,
|
||||
storeName = sst.storeName,
|
||||
nickName = ccu.nickName,
|
||||
mobile = ccu.mobile,
|
||||
avatarImage = ccu.avatarImage,
|
||||
}).With(SqlWith.NoLock)
|
||||
.MergeTable()
|
||||
.OrderByIF(orderByExpression != null, orderByExpression, orderByType)
|
||||
.WhereIF(predicate != null, predicate)
|
||||
.ToPageListAsync(pageIndex, pageSize, totalCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
page = await DbClient.Queryable<CoreCmsClerk, CoreCmsStore, CoreCmsUser>((p, sst, ccu) => new JoinQueryInfos(
|
||||
JoinType.Left, p.storeId == sst.id,
|
||||
JoinType.Left, p.userId == ccu.id
|
||||
))
|
||||
.Select((p, sst, ccu) => new StoreClerkDto
|
||||
{
|
||||
id = p.id,
|
||||
storeId = p.storeId,
|
||||
userId = p.userId,
|
||||
isDel = p.isDel,
|
||||
createTime = p.createTime,
|
||||
updateTime = p.updateTime,
|
||||
storeName = sst.storeName,
|
||||
nickName = ccu.nickName,
|
||||
mobile = ccu.mobile,
|
||||
avatarImage = ccu.avatarImage,
|
||||
})
|
||||
.MergeTable()
|
||||
.OrderByIF(orderByExpression != null, orderByExpression, orderByType)
|
||||
.WhereIF(predicate != null, predicate)
|
||||
.ToPageListAsync(pageIndex, pageSize, totalCount);
|
||||
}
|
||||
var list = new PageList<StoreClerkDto>(page, pageIndex, pageSize, totalCount);
|
||||
return list;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region 获取单个门店用户数据
|
||||
/// <summary>
|
||||
/// 获取单个门店用户数据
|
||||
/// </summary>
|
||||
/// <param name="predicate">判断集合</param>
|
||||
/// <param name="blUseNoLock">是否使用WITH(NOLOCK)</param>
|
||||
/// <returns></returns>
|
||||
public async Task<StoreClerkDto> QueryStoreClerkDtoByClauseAsync(Expression<Func<StoreClerkDto, bool>> predicate, bool blUseNoLock = false)
|
||||
{
|
||||
StoreClerkDto obj;
|
||||
if (blUseNoLock)
|
||||
{
|
||||
obj = await DbClient.Queryable<CoreCmsClerk, CoreCmsStore, CoreCmsUser>((p, sst, ccu) => new JoinQueryInfos(
|
||||
JoinType.Left, p.storeId == sst.id,
|
||||
JoinType.Left, p.userId == ccu.id
|
||||
))
|
||||
.Select((p, sst, ccu) => new StoreClerkDto
|
||||
{
|
||||
id = p.id,
|
||||
storeId = p.storeId,
|
||||
userId = p.userId,
|
||||
isDel = p.isDel,
|
||||
createTime = p.createTime,
|
||||
updateTime = p.updateTime,
|
||||
storeName = sst.storeName,
|
||||
nickName = ccu.nickName,
|
||||
mobile = ccu.mobile,
|
||||
avatarImage = ccu.avatarImage,
|
||||
}).With(SqlWith.NoLock)
|
||||
.MergeTable()
|
||||
.FirstAsync(predicate);
|
||||
}
|
||||
else
|
||||
{
|
||||
obj = await DbClient.Queryable<CoreCmsClerk, CoreCmsStore, CoreCmsUser>((p, sst, ccu) => new JoinQueryInfos(
|
||||
JoinType.Left, p.storeId == sst.id,
|
||||
JoinType.Left, p.userId == ccu.id
|
||||
))
|
||||
.Select((p, sst, ccu) => new StoreClerkDto
|
||||
{
|
||||
id = p.id,
|
||||
storeId = p.storeId,
|
||||
userId = p.userId,
|
||||
isDel = p.isDel,
|
||||
createTime = p.createTime,
|
||||
updateTime = p.updateTime,
|
||||
storeName = sst.storeName,
|
||||
nickName = ccu.nickName,
|
||||
mobile = ccu.mobile,
|
||||
avatarImage = ccu.avatarImage,
|
||||
})
|
||||
.MergeTable()
|
||||
.FirstAsync(predicate);
|
||||
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
31
CoreCms.Net.Repository/Shop/CoreCmsLogisticsRepository.cs
Normal file
31
CoreCms.Net.Repository/Shop/CoreCmsLogisticsRepository.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms
|
||||
* ProjectName: 核心内容管理系统
|
||||
* Web: https://www.corecms.net
|
||||
* Author: 大灰灰
|
||||
* Email: jianweie@163.com
|
||||
* CreateTime: 2021/1/31 21:45:10
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using CoreCms.Net.Configuration;
|
||||
using CoreCms.Net.IRepository;
|
||||
using CoreCms.Net.IRepository.UnitOfWork;
|
||||
using CoreCms.Net.Model.Entities;
|
||||
using CoreCms.Net.Model.ViewModels.UI;
|
||||
|
||||
namespace CoreCms.Net.Repository
|
||||
{
|
||||
/// <summary>
|
||||
/// 物流公司表 接口实现
|
||||
/// </summary>
|
||||
public class CoreCmsLogisticsRepository : BaseRepository<CoreCmsLogistics>, ICoreCmsLogisticsRepository
|
||||
{
|
||||
public CoreCmsLogisticsRepository(IUnitOfWork unitOfWork) : base(unitOfWork)
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
92
CoreCms.Net.Repository/Shop/CoreCmsNoticeRepository.cs
Normal file
92
CoreCms.Net.Repository/Shop/CoreCmsNoticeRepository.cs
Normal file
@@ -0,0 +1,92 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms
|
||||
* ProjectName: 核心内容管理系统
|
||||
* Web: https://www.corecms.net
|
||||
* Author: 大灰灰
|
||||
* Email: jianweie@163.com
|
||||
* CreateTime: 2021/1/31 21:45:10
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
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
|
||||
{
|
||||
/// <summary>
|
||||
/// 公告表 接口实现
|
||||
/// </summary>
|
||||
public class CoreCmsNoticeRepository : BaseRepository<CoreCmsNotice>, ICoreCmsNoticeRepository
|
||||
{
|
||||
public CoreCmsNoticeRepository(IUnitOfWork unitOfWork) : base(unitOfWork)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重写根据条件查询分页数据
|
||||
/// </summary>
|
||||
/// <param name="predicate">判断集合</param>
|
||||
/// <param name="orderByType">排序方式</param>
|
||||
/// <param name="pageIndex">当前页面索引</param>
|
||||
/// <param name="pageSize">分布大小</param>
|
||||
/// <param name="orderByExpression"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<IPageList<CoreCmsNotice>> QueryPageAsync(Expression<Func<CoreCmsNotice, bool>> predicate,
|
||||
Expression<Func<CoreCmsNotice, object>> orderByExpression, OrderByType orderByType, int pageIndex = 1,
|
||||
int pageSize = 20)
|
||||
{
|
||||
RefAsync<int> totalCount = 0;
|
||||
var page = await DbClient.Queryable<CoreCmsNotice>()
|
||||
.OrderByIF(orderByExpression != null, orderByExpression, orderByType)
|
||||
.WhereIF(predicate != null, predicate).Select(p => new CoreCmsNotice
|
||||
{
|
||||
id = p.id,
|
||||
title = p.title,
|
||||
type = p.type,
|
||||
sort = p.sort,
|
||||
isDel = p.isDel,
|
||||
createTime = p.createTime
|
||||
}).ToPageListAsync(pageIndex, pageSize, totalCount);
|
||||
var list = new PageList<CoreCmsNotice>(page, pageIndex, pageSize, totalCount);
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取列表首页用
|
||||
/// </summary>
|
||||
/// <param name="predicate">判断集合</param>
|
||||
/// <param name="orderByType">排序方式</param>
|
||||
/// <param name="pageIndex">当前页面索引</param>
|
||||
/// <param name="pageSize">分布大小</param>
|
||||
/// <param name="orderByExpression"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<List<CoreCmsNotice>> QueryListAsync(Expression<Func<CoreCmsNotice, bool>> predicate,
|
||||
Expression<Func<CoreCmsNotice, object>> orderByExpression, OrderByType orderByType, int pageIndex = 1,
|
||||
int pageSize = 20)
|
||||
{
|
||||
var list = await DbClient.Queryable<CoreCmsNotice>().OrderByIF(orderByExpression != null, orderByExpression, orderByType)
|
||||
.WhereIF(predicate != null, predicate).Select(p => new CoreCmsNotice
|
||||
{
|
||||
id = p.id,
|
||||
title = p.title,
|
||||
type = p.type,
|
||||
sort = p.sort,
|
||||
isDel = p.isDel,
|
||||
createTime = p.createTime
|
||||
}).ToPageListAsync(pageIndex, pageSize);
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
26
CoreCms.Net.Repository/Shop/CoreCmsPagesItemsRepository.cs
Normal file
26
CoreCms.Net.Repository/Shop/CoreCmsPagesItemsRepository.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms
|
||||
* ProjectName: 核心内容管理系统
|
||||
* Web: https://www.corecms.net
|
||||
* Author: 大灰灰
|
||||
* Email: jianweie@163.com
|
||||
* CreateTime: 2021/1/31 21:45:10
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
using CoreCms.Net.IRepository;
|
||||
using CoreCms.Net.IRepository.UnitOfWork;
|
||||
using CoreCms.Net.Model.Entities;
|
||||
|
||||
namespace CoreCms.Net.Repository
|
||||
{
|
||||
/// <summary>
|
||||
/// 单页内容 接口实现
|
||||
/// </summary>
|
||||
public class CoreCmsPagesItemsRepository : BaseRepository<CoreCmsPagesItems>, ICoreCmsPagesItemsRepository
|
||||
{
|
||||
public CoreCmsPagesItemsRepository(IUnitOfWork unitOfWork) : base(unitOfWork)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
264
CoreCms.Net.Repository/Shop/CoreCmsPagesRepository.cs
Normal file
264
CoreCms.Net.Repository/Shop/CoreCmsPagesRepository.cs
Normal file
@@ -0,0 +1,264 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms
|
||||
* ProjectName: 核心内容管理系统
|
||||
* Web: https://www.corecms.net
|
||||
* Author: 大灰灰
|
||||
* Email: jianweie@163.com
|
||||
* CreateTime: 2021/1/31 21:45:10
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using CoreCms.Net.Configuration;
|
||||
using CoreCms.Net.IRepository;
|
||||
using CoreCms.Net.IRepository.UnitOfWork;
|
||||
using CoreCms.Net.Loging;
|
||||
using CoreCms.Net.Model.Entities;
|
||||
using CoreCms.Net.Model.FromBody;
|
||||
using CoreCms.Net.Model.ViewModels.UI;
|
||||
using CoreCms.Net.Utility.Extensions;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using SqlSugar;
|
||||
|
||||
namespace CoreCms.Net.Repository
|
||||
{
|
||||
/// <summary>
|
||||
/// 单页 接口实现
|
||||
/// </summary>
|
||||
public class CoreCmsPagesRepository : BaseRepository<CoreCmsPages>, ICoreCmsPagesRepository
|
||||
{
|
||||
public CoreCmsPagesRepository(IUnitOfWork unitOfWork) : base(unitOfWork)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 重写异步插入方法
|
||||
/// </summary>
|
||||
/// <param name="entity">实体数据</param>
|
||||
/// <returns></returns>
|
||||
public new async Task<AdminUiCallBack> InsertAsync(CoreCmsPages entity)
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
|
||||
var have = await DbClient.Queryable<CoreCmsPages>().Where(p => p.code == entity.code).With(SqlWith.NoLock).AnyAsync();
|
||||
if (have)
|
||||
{
|
||||
jm.msg = "存在相同【区域编码】请更正";
|
||||
return jm;
|
||||
}
|
||||
|
||||
entity.code = entity.code.Trim();
|
||||
|
||||
var id = await DbClient.Insertable(entity).ExecuteReturnIdentityAsync();
|
||||
var bl = id > 0;
|
||||
|
||||
if (bl && entity.type == 1)
|
||||
{
|
||||
//如果设为新默认,则修改其他为非默认。
|
||||
await DbClient.Updateable<CoreCmsPages>().Where(p => p.type == 1 && p.id != id).SetColumns(p => new CoreCmsPages() { type = 2 }).ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
jm.code = bl ? 0 : 1;
|
||||
jm.msg = bl ? GlobalConstVars.CreateSuccess : GlobalConstVars.CreateFailure;
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重写异步更新方法
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
public new async Task<AdminUiCallBack> UpdateAsync(CoreCmsPages entity)
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
|
||||
var have = await DbClient.Queryable<CoreCmsPages>().Where(p => p.code == entity.code && p.id != entity.id).With(SqlWith.NoLock).AnyAsync();
|
||||
if (have)
|
||||
{
|
||||
jm.msg = "存在相同【区域编码】请更正";
|
||||
return jm;
|
||||
}
|
||||
var oldModel = await DbClient.Queryable<CoreCmsPages>().In(entity.id).SingleAsync();
|
||||
if (oldModel == null)
|
||||
{
|
||||
jm.msg = "不存在此信息";
|
||||
return jm;
|
||||
}
|
||||
//事物处理过程开始
|
||||
var oldType = oldModel.type;
|
||||
var newType = entity.type;
|
||||
|
||||
oldModel.code = entity.code;
|
||||
oldModel.name = entity.name;
|
||||
oldModel.description = entity.description;
|
||||
oldModel.layout = entity.layout;
|
||||
oldModel.type = entity.type;
|
||||
|
||||
//事物处理过程结束
|
||||
var bl = await DbClient.Updateable(oldModel).ExecuteCommandHasChangeAsync();
|
||||
|
||||
if (bl)
|
||||
{
|
||||
//如果不是默认的情况下
|
||||
if (oldType == 1 && newType != 1)
|
||||
{
|
||||
//判断修改当前,而是否其他有默认
|
||||
var haveDefault = await DbClient.Queryable<CoreCmsPages>().Where(p => p.type == 1 && p.id != oldModel.id).With(SqlWith.NoLock).AnyAsync();
|
||||
//如果不存在,则当前不能调整为非默认。
|
||||
if (!haveDefault)
|
||||
{
|
||||
await DbClient.Updateable<CoreCmsPages>().Where(p => p.id == oldModel.id).SetColumns(p => new CoreCmsPages() { type = 1 }).ExecuteCommandAsync();
|
||||
}
|
||||
}
|
||||
//如果设为新默认,则修改其他为非默认。
|
||||
if (newType == 1)
|
||||
{
|
||||
await DbClient.Updateable<CoreCmsPages>().Where(p => p.id != oldModel.id).SetColumns(p => new CoreCmsPages() { type = 2 }).ExecuteCommandAsync();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
jm.code = bl ? 0 : 1;
|
||||
jm.msg = bl ? GlobalConstVars.EditSuccess : GlobalConstVars.EditFailure;
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重写删除指定ID的数据
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<AdminUiCallBack> DeleteByIdAsync(int id)
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
|
||||
var model = await DbClient.Queryable<CoreCmsPages>().Where(p => p.id == id).FirstAsync();
|
||||
if (model == null)
|
||||
{
|
||||
jm.msg = GlobalConstVars.DataisNo;
|
||||
return jm;
|
||||
}
|
||||
if (model.type == 1)
|
||||
{
|
||||
jm.msg = "默认页面禁止删除";
|
||||
return jm;
|
||||
}
|
||||
|
||||
var count = await DbClient.Queryable<CoreCmsPages>().CountAsync();
|
||||
if (count == 1)
|
||||
{
|
||||
jm.msg = "只有一个页面了,别删了。";
|
||||
return jm;
|
||||
}
|
||||
|
||||
var bl = await DbClient.Deleteable<CoreCmsPages>(id).ExecuteCommandHasChangeAsync();
|
||||
if (bl)
|
||||
{
|
||||
await DbClient.Deleteable<CoreCmsPagesItems>().Where(p => p.pageCode == model.code).ExecuteCommandAsync();
|
||||
}
|
||||
jm.code = bl ? 0 : 1;
|
||||
jm.msg = bl ? GlobalConstVars.DeleteSuccess : GlobalConstVars.DeleteFailure;
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 复制一个同样的数据
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<AdminUiCallBack> CopyByIdAsync(int id)
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
|
||||
var model = await DbClient.Queryable<CoreCmsPages>().Where(p => p.id == id).FirstAsync();
|
||||
if (model == null)
|
||||
{
|
||||
jm.msg = GlobalConstVars.DataisNo;
|
||||
return jm;
|
||||
}
|
||||
var oldCode = model.code;
|
||||
model.type = 2;
|
||||
model.code = model.code + DateTime.Now.ToString("yyyyMMddHHmmssfffff");
|
||||
model.name = model.name + "(复制)";
|
||||
|
||||
var items = await DbClient.Queryable<CoreCmsPagesItems>().Where(p => p.pageCode == oldCode).ToListAsync();
|
||||
foreach (var item in items)
|
||||
{
|
||||
item.pageCode = model.code;
|
||||
}
|
||||
|
||||
var bl = await DbClient.Insertable<CoreCmsPages>(model).ExecuteReturnIdentityAsync() > 0;
|
||||
if (bl)
|
||||
{
|
||||
await DbClient.Insertable<CoreCmsPagesItems>(items).ExecuteCommandAsync();
|
||||
}
|
||||
jm.code = bl ? 0 : 1;
|
||||
jm.msg = bl ? GlobalConstVars.DeleteSuccess : GlobalConstVars.DeleteFailure;
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#region 更新设计==========================================================
|
||||
|
||||
/// <summary>
|
||||
/// 更新设计
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<AdminUiCallBack> UpdateDesignAsync(FmPagesUpdate entity)
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
|
||||
var bl = false;
|
||||
|
||||
var oldModel = await DbClient.Queryable<CoreCmsPages>().Where(p => p.code == entity.pageCode).SingleAsync();
|
||||
if (oldModel == null)
|
||||
{
|
||||
jm.msg = "不存在此信息";
|
||||
return jm;
|
||||
}
|
||||
//事物处理过程开始
|
||||
|
||||
bl = await DbClient.Deleteable<CoreCmsPagesItems>().Where(p => p.pageCode == entity.pageCode).ExecuteCommandHasChangeAsync();
|
||||
var list = new List<CoreCmsPagesItems>();
|
||||
var count = 0;
|
||||
entity.datalist.ForEach(p =>
|
||||
{
|
||||
var model = new CoreCmsPagesItems
|
||||
{
|
||||
widgetCode = p.sType,
|
||||
pageCode = entity.pageCode,
|
||||
positionId = count,
|
||||
sort = count + 1,
|
||||
parameters = p.sValue
|
||||
};
|
||||
list.Add(model);
|
||||
count++;
|
||||
});
|
||||
|
||||
if (list.Any())
|
||||
{
|
||||
bl = await DbClient.Insertable(list).ExecuteCommandAsync() > 0;
|
||||
}
|
||||
//事物处理过程结束
|
||||
jm.code = bl ? 0 : 1;
|
||||
jm.msg = bl ? GlobalConstVars.EditSuccess : GlobalConstVars.EditFailure;
|
||||
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,236 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms
|
||||
* ProjectName: 核心内容管理系统
|
||||
* Web: https://www.corecms.net
|
||||
* Author: 大灰灰
|
||||
* Email: jianweie@163.com
|
||||
* CreateTime: 2021/1/31 21:45:10
|
||||
* 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
|
||||
{
|
||||
/// <summary>
|
||||
/// 商城服务说明 接口实现
|
||||
/// </summary>
|
||||
public class CoreCmsServiceDescriptionRepository : BaseRepository<CoreCmsServiceDescription>, ICoreCmsServiceDescriptionRepository
|
||||
{
|
||||
public CoreCmsServiceDescriptionRepository(IUnitOfWork unitOfWork) : base(unitOfWork)
|
||||
{
|
||||
}
|
||||
|
||||
#region 实现重写增删改查操作==========================================================
|
||||
|
||||
/// <summary>
|
||||
/// 重写异步插入方法
|
||||
/// </summary>
|
||||
/// <param name="entity">实体数据</param>
|
||||
/// <returns></returns>
|
||||
public new async Task<AdminUiCallBack> InsertAsync(CoreCmsServiceDescription 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;
|
||||
if (bl)
|
||||
{
|
||||
await UpdateCaChe();
|
||||
}
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重写异步更新方法
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
public new async Task<AdminUiCallBack> UpdateAsync(CoreCmsServiceDescription entity)
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
|
||||
var oldModel = await DbClient.Queryable<CoreCmsServiceDescription>().In(entity.id).SingleAsync();
|
||||
if (oldModel == null)
|
||||
{
|
||||
jm.msg = "不存在此信息";
|
||||
return jm;
|
||||
}
|
||||
//事物处理过程开始
|
||||
oldModel.id = entity.id;
|
||||
oldModel.title = entity.title;
|
||||
oldModel.type = entity.type;
|
||||
oldModel.description = entity.description;
|
||||
oldModel.isShow = entity.isShow;
|
||||
oldModel.sortId = entity.sortId;
|
||||
|
||||
//事物处理过程结束
|
||||
var bl = await DbClient.Updateable(oldModel).ExecuteCommandHasChangeAsync();
|
||||
jm.code = bl ? 0 : 1;
|
||||
jm.msg = bl ? GlobalConstVars.EditSuccess : GlobalConstVars.EditFailure;
|
||||
if (bl)
|
||||
{
|
||||
await UpdateCaChe();
|
||||
}
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重写异步更新方法
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
public new async Task<AdminUiCallBack> UpdateAsync(List<CoreCmsServiceDescription> entity)
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
|
||||
var bl = await DbClient.Updateable(entity).ExecuteCommandHasChangeAsync();
|
||||
jm.code = bl ? 0 : 1;
|
||||
jm.msg = bl ? GlobalConstVars.EditSuccess : GlobalConstVars.EditFailure;
|
||||
if (bl)
|
||||
{
|
||||
await UpdateCaChe();
|
||||
}
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重写删除指定ID的数据
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public new async Task<AdminUiCallBack> DeleteByIdAsync(object id)
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
|
||||
var bl = await DbClient.Deleteable<CoreCmsServiceDescription>(id).ExecuteCommandHasChangeAsync();
|
||||
jm.code = bl ? 0 : 1;
|
||||
jm.msg = bl ? GlobalConstVars.DeleteSuccess : GlobalConstVars.DeleteFailure;
|
||||
if (bl)
|
||||
{
|
||||
await UpdateCaChe();
|
||||
}
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重写删除指定ID集合的数据(批量删除)
|
||||
/// </summary>
|
||||
/// <param name="ids"></param>
|
||||
/// <returns></returns>
|
||||
public new async Task<AdminUiCallBack> DeleteByIdsAsync(int[] ids)
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
|
||||
var bl = await DbClient.Deleteable<CoreCmsServiceDescription>().In(ids).ExecuteCommandHasChangeAsync();
|
||||
jm.code = bl ? 0 : 1;
|
||||
jm.msg = bl ? GlobalConstVars.DeleteSuccess : GlobalConstVars.DeleteFailure;
|
||||
if (bl)
|
||||
{
|
||||
await UpdateCaChe();
|
||||
}
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 获取缓存的所有数据==========================================================
|
||||
|
||||
/// <summary>
|
||||
/// 获取缓存的所有数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task<List<CoreCmsServiceDescription>> GetCaChe()
|
||||
{
|
||||
var cache = ManualDataCache.Instance.Get<List<CoreCmsServiceDescription>>(GlobalConstVars.CacheCoreCmsServiceDescription);
|
||||
if (cache != null)
|
||||
{
|
||||
return cache;
|
||||
}
|
||||
return await UpdateCaChe();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新cache
|
||||
/// </summary>
|
||||
public async Task<List<CoreCmsServiceDescription>> UpdateCaChe()
|
||||
{
|
||||
var list = await DbClient.Queryable<CoreCmsServiceDescription>().With(SqlWith.NoLock).ToListAsync();
|
||||
ManualDataCache.Instance.Set(GlobalConstVars.CacheCoreCmsServiceDescription, list);
|
||||
return list;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 重写根据条件查询分页数据
|
||||
/// <summary>
|
||||
/// 重写根据条件查询分页数据
|
||||
/// </summary>
|
||||
/// <param name="predicate">判断集合</param>
|
||||
/// <param name="orderByType">排序方式</param>
|
||||
/// <param name="pageIndex">当前页面索引</param>
|
||||
/// <param name="pageSize">分布大小</param>
|
||||
/// <param name="orderByExpression"></param>
|
||||
/// <param name="blUseNoLock">是否使用WITH(NOLOCK)</param>
|
||||
/// <returns></returns>
|
||||
public new async Task<IPageList<CoreCmsServiceDescription>> QueryPageAsync(Expression<Func<CoreCmsServiceDescription, bool>> predicate,
|
||||
Expression<Func<CoreCmsServiceDescription, object>> orderByExpression, OrderByType orderByType, int pageIndex = 1,
|
||||
int pageSize = 20, bool blUseNoLock = false)
|
||||
{
|
||||
RefAsync<int> totalCount = 0;
|
||||
List<CoreCmsServiceDescription> page;
|
||||
if (blUseNoLock)
|
||||
{
|
||||
page = await DbClient.Queryable<CoreCmsServiceDescription>()
|
||||
.OrderByIF(orderByExpression != null, orderByExpression, orderByType)
|
||||
.WhereIF(predicate != null, predicate).Select(p => new CoreCmsServiceDescription
|
||||
{
|
||||
id = p.id,
|
||||
title = p.title,
|
||||
type = p.type,
|
||||
description = p.description,
|
||||
isShow = p.isShow,
|
||||
sortId = p.sortId,
|
||||
|
||||
}).With(SqlWith.NoLock).ToPageListAsync(pageIndex, pageSize, totalCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
page = await DbClient.Queryable<CoreCmsServiceDescription>()
|
||||
.OrderByIF(orderByExpression != null, orderByExpression, orderByType)
|
||||
.WhereIF(predicate != null, predicate).Select(p => new CoreCmsServiceDescription
|
||||
{
|
||||
id = p.id,
|
||||
title = p.title,
|
||||
type = p.type,
|
||||
description = p.description,
|
||||
isShow = p.isShow,
|
||||
sortId = p.sortId,
|
||||
|
||||
}).ToPageListAsync(pageIndex, pageSize, totalCount);
|
||||
}
|
||||
var list = new PageList<CoreCmsServiceDescription>(page, pageIndex, pageSize, totalCount);
|
||||
return list;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
40
CoreCms.Net.Repository/Shop/CoreCmsSettingRepository.cs
Normal file
40
CoreCms.Net.Repository/Shop/CoreCmsSettingRepository.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms
|
||||
* ProjectName: 核心内容管理系统
|
||||
* Web: https://www.corecms.net
|
||||
* Author: 大灰灰
|
||||
* Email: jianweie@163.com
|
||||
* CreateTime: 2021/1/31 21:45:10
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using CoreCms.Net.Caching;
|
||||
using CoreCms.Net.Caching.Manual;
|
||||
using CoreCms.Net.Configuration;
|
||||
using CoreCms.Net.IRepository;
|
||||
using CoreCms.Net.IRepository.UnitOfWork;
|
||||
using CoreCms.Net.Model.Entities;
|
||||
using CoreCms.Net.Model.FromBody;
|
||||
using CoreCms.Net.Model.ViewModels.Basics;
|
||||
using CoreCms.Net.Model.ViewModels.UI;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using SqlSugar;
|
||||
|
||||
namespace CoreCms.Net.Repository
|
||||
{
|
||||
/// <summary>
|
||||
/// 店铺设置表 接口实现
|
||||
/// </summary>
|
||||
public class CoreCmsSettingRepository : BaseRepository<CoreCmsSetting>, ICoreCmsSettingRepository
|
||||
{
|
||||
public CoreCmsSettingRepository(IUnitOfWork unitOfWork) : base(unitOfWork)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
276
CoreCms.Net.Repository/Shop/CoreCmsShipRepository.cs
Normal file
276
CoreCms.Net.Repository/Shop/CoreCmsShipRepository.cs
Normal file
@@ -0,0 +1,276 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms
|
||||
* ProjectName: 核心内容管理系统
|
||||
* Web: https://www.corecms.net
|
||||
* Author: 大灰灰
|
||||
* Email: jianweie@163.com
|
||||
* CreateTime: 2021/1/31 21:45:10
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
using CoreCms.Net.Caching.Manual;
|
||||
using CoreCms.Net.Configuration;
|
||||
using CoreCms.Net.IRepository;
|
||||
using CoreCms.Net.IRepository.UnitOfWork;
|
||||
using CoreCms.Net.Loging;
|
||||
using CoreCms.Net.Model.Entities;
|
||||
using CoreCms.Net.Model.ViewModels.Basics;
|
||||
using CoreCms.Net.Model.ViewModels.UI;
|
||||
using CoreCms.Net.Utility.Extensions;
|
||||
using CoreCms.Net.Utility.Helper;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using SqlSugar;
|
||||
|
||||
namespace CoreCms.Net.Repository
|
||||
{
|
||||
/// <summary>
|
||||
/// 配送方式表 接口实现
|
||||
/// </summary>
|
||||
public class CoreCmsShipRepository : BaseRepository<CoreCmsShip>, ICoreCmsShipRepository
|
||||
{
|
||||
public CoreCmsShipRepository(IUnitOfWork unitOfWork) : base(unitOfWork)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
#region 实现重写增删改查操作==========================================================
|
||||
|
||||
/// <summary>
|
||||
/// 重写异步插入方法
|
||||
/// </summary>
|
||||
/// <param name="entity">实体数据</param>
|
||||
/// <returns></returns>
|
||||
public new async Task<AdminUiCallBack> InsertAsync(CoreCmsShip entity)
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
|
||||
var logistics = await DbClient.Queryable<CoreCmsLogistics>().FirstAsync(p => p.logiCode == entity.logiCode);
|
||||
if (logistics != null)
|
||||
{
|
||||
entity.logiName = logistics.logiName;
|
||||
}
|
||||
var id = await DbClient.Insertable(entity).ExecuteReturnIdentityAsync();
|
||||
var bl = id > 0;
|
||||
|
||||
if (bl && entity.isDefault == true)
|
||||
{
|
||||
await DbClient.Updateable<CoreCmsShip>().SetColumns(p => p.isDefault == false).Where(p => p.isDefault == true && p.id != id).ExecuteCommandAsync();
|
||||
}
|
||||
|
||||
jm.code = bl ? 0 : 1;
|
||||
jm.msg = bl ? GlobalConstVars.CreateSuccess : GlobalConstVars.CreateFailure;
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 重写异步更新方法
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
public new async Task<AdminUiCallBack> UpdateAsync(CoreCmsShip entity)
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
|
||||
if (entity.isDefault == false)
|
||||
{
|
||||
var otherHave = await DbClient.Queryable<CoreCmsShip>().AnyAsync(p => p.isDefault == true && p.id != entity.id);
|
||||
if (otherHave == false)
|
||||
{
|
||||
jm.msg = "请保持一个默认配送方式";
|
||||
return jm;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
var oldModel = await DbClient.Queryable<CoreCmsShip>().In(entity.id).SingleAsync();
|
||||
if (oldModel == null)
|
||||
{
|
||||
jm.msg = "不存在此信息";
|
||||
return jm;
|
||||
}
|
||||
|
||||
//事物处理过程开始
|
||||
//oldModel.id = entity.id;
|
||||
oldModel.name = entity.name;
|
||||
oldModel.isCashOnDelivery = entity.isCashOnDelivery;
|
||||
oldModel.firstUnit = entity.firstUnit;
|
||||
oldModel.continueUnit = entity.continueUnit;
|
||||
oldModel.isdefaultAreaFee = entity.isdefaultAreaFee;
|
||||
oldModel.areaType = entity.areaType;
|
||||
oldModel.firstunitPrice = entity.firstunitPrice;
|
||||
oldModel.continueunitPrice = entity.continueunitPrice;
|
||||
oldModel.exp = entity.exp;
|
||||
oldModel.logiName = entity.logiName;
|
||||
oldModel.logiCode = entity.logiCode;
|
||||
oldModel.isDefault = entity.isDefault;
|
||||
oldModel.sort = entity.sort;
|
||||
oldModel.status = entity.status;
|
||||
oldModel.isfreePostage = entity.isfreePostage;
|
||||
oldModel.areaFee = entity.areaFee;
|
||||
oldModel.goodsMoney = entity.goodsMoney;
|
||||
|
||||
var logistics = await DbClient.Queryable<CoreCmsLogistics>().FirstAsync(p => p.logiCode == oldModel.logiCode);
|
||||
if (logistics != null)
|
||||
{
|
||||
oldModel.logiName = logistics.logiName;
|
||||
}
|
||||
|
||||
//事物处理过程结束
|
||||
var bl = await DbClient.Updateable(oldModel).ExecuteCommandHasChangeAsync();
|
||||
jm.code = bl ? 0 : 1;
|
||||
jm.msg = bl ? GlobalConstVars.EditSuccess : GlobalConstVars.EditFailure;
|
||||
|
||||
if (bl && entity.isDefault == true)
|
||||
{
|
||||
await DbClient.Updateable<CoreCmsShip>().SetColumns(p => p.isDefault == false).Where(p => p.isDefault == true && p.id != oldModel.id).ExecuteCommandAsync();
|
||||
}
|
||||
return jm;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 重写删除指定ID的数据
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<AdminUiCallBack> DeleteByIdAsync(int id)
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
|
||||
var isDefault = await DbClient.Queryable<CoreCmsShip>().AnyAsync(p => p.isDefault == true && p.id == id);
|
||||
if (isDefault)
|
||||
{
|
||||
jm.msg = "默认方式禁止删除";
|
||||
}
|
||||
var bl = await DbClient.Deleteable<CoreCmsShip>(id).ExecuteCommandHasChangeAsync();
|
||||
jm.code = bl ? 0 : 1;
|
||||
jm.msg = bl ? GlobalConstVars.DeleteSuccess : GlobalConstVars.DeleteFailure;
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 设置是否默认
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="isDefault"></param>
|
||||
/// <returns></returns>
|
||||
public async Task<AdminUiCallBack> SetIsDefault(int id, bool isDefault)
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
|
||||
if (isDefault == false)
|
||||
{
|
||||
var otherHave = await DbClient.Queryable<CoreCmsShip>().AnyAsync(p => p.isDefault == true && p.id != id);
|
||||
if (otherHave == false)
|
||||
{
|
||||
jm.msg = "请保持一个默认配送方式";
|
||||
return jm;
|
||||
}
|
||||
}
|
||||
//事物处理过程结束
|
||||
var bl = await DbClient.Updateable<CoreCmsShip>().SetColumns(p => p.isDefault == isDefault).Where(p => p.id == id).ExecuteCommandHasChangeAsync();
|
||||
jm.code = bl ? 0 : 1;
|
||||
jm.msg = bl ? GlobalConstVars.EditSuccess : GlobalConstVars.EditFailure;
|
||||
|
||||
if (bl && isDefault == true)
|
||||
{
|
||||
await DbClient.Updateable<CoreCmsShip>().SetColumns(p => p.isDefault == false).Where(p => p.isDefault == true && p.id != id).ExecuteCommandAsync();
|
||||
}
|
||||
return jm;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#region 重写根据条件查询分页数据
|
||||
/// <summary>
|
||||
/// 重写根据条件查询分页数据
|
||||
/// </summary>
|
||||
/// <param name="predicate">判断集合</param>
|
||||
/// <param name="orderByType">排序方式</param>
|
||||
/// <param name="pageIndex">当前页面索引</param>
|
||||
/// <param name="pageSize">分布大小</param>
|
||||
/// <param name="orderByExpression"></param>
|
||||
/// <param name="blUseNoLock">是否使用WITH(NOLOCK)</param>
|
||||
/// <returns></returns>
|
||||
public new async Task<IPageList<CoreCmsShip>> QueryPageAsync(Expression<Func<CoreCmsShip, bool>> predicate,
|
||||
Expression<Func<CoreCmsShip, object>> orderByExpression, OrderByType orderByType, int pageIndex = 1,
|
||||
int pageSize = 20, bool blUseNoLock = false)
|
||||
{
|
||||
RefAsync<int> totalCount = 0;
|
||||
List<CoreCmsShip> page;
|
||||
if (blUseNoLock)
|
||||
{
|
||||
page = await DbClient.Queryable<CoreCmsShip>()
|
||||
.OrderByIF(orderByExpression != null, orderByExpression, orderByType)
|
||||
.WhereIF(predicate != null, predicate).Select(p => new CoreCmsShip
|
||||
{
|
||||
id = p.id,
|
||||
name = p.name,
|
||||
isCashOnDelivery = p.isCashOnDelivery,
|
||||
firstUnit = p.firstUnit,
|
||||
continueUnit = p.continueUnit,
|
||||
isdefaultAreaFee = p.isdefaultAreaFee,
|
||||
areaType = p.areaType,
|
||||
firstunitPrice = p.firstunitPrice,
|
||||
continueunitPrice = p.continueunitPrice,
|
||||
exp = p.exp,
|
||||
logiName = p.logiName,
|
||||
logiCode = p.logiCode,
|
||||
isDefault = p.isDefault,
|
||||
sort = p.sort,
|
||||
status = p.status,
|
||||
isfreePostage = p.isfreePostage,
|
||||
areaFee = p.areaFee,
|
||||
goodsMoney = p.goodsMoney,
|
||||
|
||||
}).With(SqlWith.NoLock).ToPageListAsync(pageIndex, pageSize, totalCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
page = await DbClient.Queryable<CoreCmsShip>()
|
||||
.OrderByIF(orderByExpression != null, orderByExpression, orderByType)
|
||||
.WhereIF(predicate != null, predicate).Select(p => new CoreCmsShip
|
||||
{
|
||||
id = p.id,
|
||||
name = p.name,
|
||||
isCashOnDelivery = p.isCashOnDelivery,
|
||||
firstUnit = p.firstUnit,
|
||||
continueUnit = p.continueUnit,
|
||||
isdefaultAreaFee = p.isdefaultAreaFee,
|
||||
areaType = p.areaType,
|
||||
firstunitPrice = p.firstunitPrice,
|
||||
continueunitPrice = p.continueunitPrice,
|
||||
exp = p.exp,
|
||||
logiName = p.logiName,
|
||||
logiCode = p.logiCode,
|
||||
isDefault = p.isDefault,
|
||||
sort = p.sort,
|
||||
status = p.status,
|
||||
isfreePostage = p.isfreePostage,
|
||||
areaFee = p.areaFee,
|
||||
goodsMoney = p.goodsMoney,
|
||||
|
||||
}).ToPageListAsync(pageIndex, pageSize, totalCount);
|
||||
}
|
||||
var list = new PageList<CoreCmsShip>(page, pageIndex, pageSize, totalCount);
|
||||
return list;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
275
CoreCms.Net.Repository/Shop/CoreCmsStoreRepository.cs
Normal file
275
CoreCms.Net.Repository/Shop/CoreCmsStoreRepository.cs
Normal file
@@ -0,0 +1,275 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms
|
||||
* ProjectName: 核心内容管理系统
|
||||
* Web: https://www.corecms.net
|
||||
* Author: 大灰灰
|
||||
* Email: jianweie@163.com
|
||||
* CreateTime: 2021/1/31 21:45:10
|
||||
* Description: 暂无
|
||||
***********************************************************************/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq.Expressions;
|
||||
using System.Threading.Tasks;
|
||||
using CoreCms.Net.Configuration;
|
||||
using CoreCms.Net.IRepository;
|
||||
using CoreCms.Net.IRepository.UnitOfWork;
|
||||
using CoreCms.Net.Loging;
|
||||
using CoreCms.Net.Model.Entities;
|
||||
using CoreCms.Net.Model.ViewModels.Basics;
|
||||
using CoreCms.Net.Model.ViewModels.UI;
|
||||
using SqlSugar;
|
||||
|
||||
namespace CoreCms.Net.Repository
|
||||
{
|
||||
/// <summary>
|
||||
/// 门店表 接口实现
|
||||
/// </summary>
|
||||
public class CoreCmsStoreRepository : BaseRepository<CoreCmsStore>, ICoreCmsStoreRepository
|
||||
{
|
||||
|
||||
|
||||
public CoreCmsStoreRepository(IUnitOfWork unitOfWork) : base(unitOfWork)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 重写异步插入方法
|
||||
/// </summary>
|
||||
/// <param name="entity">实体数据</param>
|
||||
/// <returns></returns>
|
||||
public new async Task<AdminUiCallBack> InsertAsync(CoreCmsStore entity)
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
|
||||
var isDefaultObj = DbClient.Queryable<CoreCmsStore>().Where(p => p.isDefault == true).Any();
|
||||
if (isDefaultObj && entity.isDefault == true)
|
||||
{
|
||||
await DbClient.Updateable<CoreCmsStore>().SetColumns(it => it.isDefault == false).Where(p => p.id > 0).ExecuteCommandAsync(); ;
|
||||
}
|
||||
else if (!isDefaultObj)
|
||||
{
|
||||
entity.isDefault = true;
|
||||
}
|
||||
entity.createTime = DateTime.Now;
|
||||
entity.updateTime = DateTime.Now;
|
||||
entity.distance = 0;
|
||||
if (entity.coordinate.Contains(","))
|
||||
{
|
||||
var latlong = entity.coordinate.Split(",");
|
||||
entity.latitude = latlong[0];
|
||||
entity.longitude = latlong[1];
|
||||
}
|
||||
|
||||
var id = await DbClient.Insertable(entity).ExecuteReturnIdentityAsync();
|
||||
var bl = id > 0;
|
||||
|
||||
jm.code = bl ? 0 : 1;
|
||||
jm.msg = bl ? GlobalConstVars.CreateSuccess : GlobalConstVars.CreateFailure;
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 重写异步更新方法方法
|
||||
/// </summary>
|
||||
/// <param name="entity"></param>
|
||||
/// <returns></returns>
|
||||
public new async Task<AdminUiCallBack> UpdateAsync(CoreCmsStore entity)
|
||||
{
|
||||
var jm = new AdminUiCallBack();
|
||||
|
||||
var oldModel = await DbClient.Queryable<CoreCmsStore>().In(entity.id).SingleAsync();
|
||||
if (oldModel == null)
|
||||
{
|
||||
jm.msg = "不存在此信息";
|
||||
return jm;
|
||||
}
|
||||
//事物处理过程开始
|
||||
oldModel.storeName = entity.storeName;
|
||||
oldModel.mobile = entity.mobile;
|
||||
oldModel.linkMan = entity.linkMan;
|
||||
oldModel.logoImage = entity.logoImage;
|
||||
oldModel.areaId = entity.areaId;
|
||||
oldModel.address = entity.address;
|
||||
oldModel.coordinate = entity.coordinate;
|
||||
oldModel.latitude = entity.latitude;
|
||||
oldModel.longitude = entity.longitude;
|
||||
oldModel.updateTime = entity.updateTime;
|
||||
oldModel.isDefault = entity.isDefault;
|
||||
|
||||
if (entity.coordinate.Contains(","))
|
||||
{
|
||||
var latlong = entity.coordinate.Split(",");
|
||||
oldModel.latitude = latlong[0];
|
||||
oldModel.longitude = latlong[1];
|
||||
}
|
||||
|
||||
var isDefaultObj = DbClient.Queryable<CoreCmsStore>().Where(p => p.isDefault == true).Any();
|
||||
if (isDefaultObj && entity.isDefault == true)
|
||||
{
|
||||
await DbClient.Updateable<CoreCmsStore>().SetColumns(it => it.isDefault == false).Where(p => p.id > 0).ExecuteCommandAsync();
|
||||
}
|
||||
else if (!isDefaultObj)
|
||||
{
|
||||
oldModel.isDefault = true;
|
||||
}
|
||||
|
||||
//事物处理过程结束
|
||||
var bl = await DbClient.Updateable(oldModel).ExecuteCommandHasChangeAsync();
|
||||
jm.code = bl ? 0 : 1;
|
||||
jm.msg = bl ? GlobalConstVars.EditSuccess : GlobalConstVars.EditFailure;
|
||||
|
||||
return jm;
|
||||
}
|
||||
|
||||
|
||||
#region Sql根据条件查询分页数据带距离
|
||||
|
||||
/// <summary>
|
||||
/// Sql根据条件查询分页数据带距离
|
||||
/// </summary>
|
||||
/// <param name="predicate">判断集合</param>
|
||||
/// <param name="orderByType">排序方式</param>
|
||||
/// <param name="pageIndex">当前页面索引</param>
|
||||
/// <param name="pageSize">分布大小</param>
|
||||
/// <param name="orderByExpression"></param>
|
||||
/// <param name="latitude">纬度</param>
|
||||
/// <param name="longitude">精度</param>
|
||||
/// <returns></returns>
|
||||
public async Task<IPageList<CoreCmsStore>> QueryPageAsyncByCoordinate(Expression<Func<CoreCmsStore, bool>> predicate,
|
||||
Expression<Func<CoreCmsStore, object>> orderByExpression, OrderByType orderByType, int pageIndex = 1,
|
||||
int pageSize = 20, decimal latitude = 0, decimal longitude = 0)
|
||||
{
|
||||
RefAsync<int> totalCount = 0;
|
||||
|
||||
//MySql与SqlServer查询语句相同
|
||||
List<CoreCmsStore> page;
|
||||
if (latitude > 0 && longitude > 0)
|
||||
{
|
||||
var sqrt = "SQRT(power(SIN((" + latitude + "*PI()/180-(CoreCmsStore.latitude)*PI()/180)/2),2)+COS(" + latitude + "*PI()/180)*COS((CoreCmsStore.latitude)*PI()/180)*power(SIN((" + longitude + "*PI()/180-(CoreCmsStore.longitude)*PI()/180)/2),2))";
|
||||
var sql = "SELECT id, storeName, mobile, linkMan, logoImage, areaId, address, coordinate, latitude, longitude, isDefault, createTime, updateTime, ROUND(6378.138*2*ASIN(" + sqrt + ")*1000,2) AS distance FROM CoreCmsStore";
|
||||
|
||||
page = await DbClient.SqlQueryable<CoreCmsStore>(sql)
|
||||
.WhereIF(predicate != null, predicate)
|
||||
.OrderByIF(orderByExpression != null, orderByExpression, orderByType)
|
||||
.Select(p => new CoreCmsStore
|
||||
{
|
||||
id = p.id,
|
||||
storeName = p.storeName,
|
||||
mobile = p.mobile,
|
||||
linkMan = p.linkMan,
|
||||
logoImage = p.logoImage,
|
||||
areaId = p.areaId,
|
||||
address = p.address,
|
||||
coordinate = p.coordinate,
|
||||
latitude = p.latitude,
|
||||
longitude = p.longitude,
|
||||
isDefault = p.isDefault,
|
||||
createTime = p.createTime,
|
||||
updateTime = p.updateTime,
|
||||
distance = Convert.ToDecimal(p.distance)
|
||||
}).ToPageListAsync(pageIndex, pageSize, totalCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
page = await DbClient.Queryable<CoreCmsStore>()
|
||||
.WhereIF(predicate != null, predicate)
|
||||
.OrderByIF(orderByExpression != null, orderByExpression, orderByType)
|
||||
.Select(p => new CoreCmsStore
|
||||
{
|
||||
id = p.id,
|
||||
storeName = p.storeName,
|
||||
mobile = p.mobile,
|
||||
linkMan = p.linkMan,
|
||||
logoImage = p.logoImage,
|
||||
areaId = p.areaId,
|
||||
address = p.address,
|
||||
coordinate = p.coordinate,
|
||||
latitude = p.latitude,
|
||||
longitude = p.longitude,
|
||||
isDefault = p.isDefault,
|
||||
createTime = p.createTime,
|
||||
updateTime = p.updateTime,
|
||||
distance = Convert.ToDecimal(p.distance)
|
||||
}).ToPageListAsync(pageIndex, pageSize, totalCount);
|
||||
}
|
||||
|
||||
var list = new PageList<CoreCmsStore>(page, pageIndex, pageSize, totalCount);
|
||||
return list;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region 根据用户序列获取单个门店数据
|
||||
|
||||
/// <summary>
|
||||
/// 根据用户序列获取单个门店数据
|
||||
/// </summary>
|
||||
/// <param name="userId">用户序列</param>
|
||||
/// <param name="blUseNoLock">是否使用WITH(NOLOCK)</param>
|
||||
/// <returns></returns>
|
||||
public async Task<CoreCmsStore> GetStoreByUserId(int userId, bool blUseNoLock = false)
|
||||
{
|
||||
CoreCmsStore obj;
|
||||
if (blUseNoLock)
|
||||
{
|
||||
obj = await DbClient.Queryable<CoreCmsStore, CoreCmsClerk>((p, clerks) => new JoinQueryInfos(
|
||||
JoinType.Left, p.id == clerks.storeId
|
||||
))
|
||||
.Where((p, clerks) => clerks.userId == userId)
|
||||
.Select((p, clerks) => new CoreCmsStore
|
||||
{
|
||||
id = p.id,
|
||||
storeName = p.storeName,
|
||||
mobile = p.mobile,
|
||||
linkMan = p.linkMan,
|
||||
logoImage = p.logoImage,
|
||||
areaId = p.areaId,
|
||||
address = p.address,
|
||||
coordinate = p.coordinate,
|
||||
latitude = p.latitude,
|
||||
longitude = p.longitude,
|
||||
isDefault = p.isDefault,
|
||||
createTime = p.createTime,
|
||||
updateTime = p.updateTime,
|
||||
}).With(SqlWith.NoLock)
|
||||
.FirstAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
obj = await DbClient.Queryable<CoreCmsStore, CoreCmsClerk>((p, clerks) => new JoinQueryInfos(
|
||||
JoinType.Left, p.id == clerks.storeId
|
||||
))
|
||||
.Where((p, clerks) => clerks.userId == userId)
|
||||
.Select((p, clerks) => new CoreCmsStore
|
||||
{
|
||||
id = p.id,
|
||||
storeName = p.storeName,
|
||||
mobile = p.mobile,
|
||||
linkMan = p.linkMan,
|
||||
logoImage = p.logoImage,
|
||||
areaId = p.areaId,
|
||||
address = p.address,
|
||||
coordinate = p.coordinate,
|
||||
latitude = p.latitude,
|
||||
longitude = p.longitude,
|
||||
isDefault = p.isDefault,
|
||||
createTime = p.createTime,
|
||||
updateTime = p.updateTime,
|
||||
})
|
||||
.FirstAsync();
|
||||
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user