【新增】增加易联云小票打印机后台配置表【CoreCmsPrinter】,取消使用配置文件配置,并且支持多台打印机绑定不同门店,实现不同门店不同打印机打单。

This commit is contained in:
大灰灰
2022-09-17 02:54:50 +08:00
parent 1fc786d39c
commit 790237fa6c
52 changed files with 3209 additions and 387 deletions

View File

@@ -0,0 +1,209 @@
/***********************************************************************
* Project: CoreCms
* ProjectName: 核心内容管理系统
* Web: https://www.corecms.net
* Author: 大灰灰
* Email: jianweie@163.com
* CreateTime: 2022/9/16 20:41:09
* 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 CoreCmsPrinterRepository : BaseRepository<CoreCmsPrinter>, ICoreCmsPrinterRepository
{
private readonly IUnitOfWork _unitOfWork;
public CoreCmsPrinterRepository(IUnitOfWork unitOfWork) : base(unitOfWork)
{
_unitOfWork = unitOfWork;
}
#region ==========================================================
/// <summary>
/// 重写异步插入方法
/// </summary>
/// <param name="entity">实体数据</param>
/// <returns></returns>
public async Task<AdminUiCallBack> InsertAsync(CoreCmsPrinter entity)
{
var jm = new AdminUiCallBack();
entity.createTime = DateTime.Now;
var bl = await DbClient.Insertable(entity).RemoveDataCache().ExecuteReturnIdentityAsync() > 0;
jm.code = bl ? 0 : 1;
jm.msg = bl ? GlobalConstVars.CreateSuccess : GlobalConstVars.CreateFailure;
return jm;
}
/// <summary>
/// 重写异步更新方法
/// </summary>
/// <param name="entity"></param>
/// <returns></returns>
public async Task<AdminUiCallBack> UpdateAsync(CoreCmsPrinter entity)
{
var jm = new AdminUiCallBack();
var oldModel = await DbClient.Queryable<CoreCmsPrinter>().In(entity.id).SingleAsync();
if (oldModel == null)
{
jm.msg = "不存在此信息";
return jm;
}
//事物处理过程开始
//oldModel.id = entity.id;
oldModel.name = entity.name;
oldModel.code = entity.code;
oldModel.clientId = entity.clientId;
oldModel.clientSecret = entity.clientSecret;
oldModel.machineCode = entity.machineCode;
oldModel.msign = entity.msign;
oldModel.printerName = entity.printerName;
oldModel.phone = entity.phone;
//oldModel.accessToken = entity.accessToken;
//oldModel.refreshToken = entity.refreshToken;
//oldModel.expiresIn = entity.expiresIn;
//oldModel.expiressEndTime = entity.expiressEndTime;
//oldModel.parameters = entity.parameters;
//oldModel.createTime = entity.createTime;
oldModel.isDefault = entity.isDefault;
oldModel.isOpen = entity.isOpen;
oldModel.storeId = entity.storeId;
//事物处理过程结束
var bl = await DbClient.Updateable(oldModel).RemoveDataCache().ExecuteCommandHasChangeAsync();
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(object id)
{
var jm = new AdminUiCallBack();
var bl = await DbClient.Deleteable<CoreCmsPrinter>(id).RemoveDataCache().ExecuteCommandHasChangeAsync();
jm.code = bl ? 0 : 1;
jm.msg = bl ? GlobalConstVars.DeleteSuccess : GlobalConstVars.DeleteFailure;
return jm;
}
#endregion
#region ==========================================================
/// <summary>
/// 获取缓存的所有数据
/// </summary>
/// <returns></returns>
public async Task<List<CoreCmsPrinter>> GetCaChe()
{
var cache = await DbClient.Queryable<CoreCmsPrinter>().With(SqlWith.NoLock).WithCache().ToListAsync();
return cache;
}
#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 async Task<IPageList<CoreCmsPrinter>> QueryPageAsync(Expression<Func<CoreCmsPrinter, bool>> predicate,
Expression<Func<CoreCmsPrinter, object>> orderByExpression, OrderByType orderByType, int pageIndex = 1,
int pageSize = 20, bool blUseNoLock = false)
{
RefAsync<int> totalCount = 0;
List<CoreCmsPrinter> page;
if (blUseNoLock)
{
page = await DbClient.Queryable<CoreCmsPrinter>()
.OrderByIF(orderByExpression != null, orderByExpression, orderByType)
.WhereIF(predicate != null, predicate).Select(p => new CoreCmsPrinter
{
id = p.id,
name = p.name,
code = p.code,
clientId = p.clientId,
clientSecret = p.clientSecret,
machineCode = p.machineCode,
msign = p.msign,
printerName = p.printerName,
phone = p.phone,
accessToken = p.accessToken,
refreshToken = p.refreshToken,
expiresIn = p.expiresIn,
expiressEndTime = p.expiressEndTime,
parameters = p.parameters,
createTime = p.createTime,
isDefault = p.isDefault,
isOpen = p.isOpen,
storeId = p.storeId,
}).With(SqlWith.NoLock).ToPageListAsync(pageIndex, pageSize, totalCount);
}
else
{
page = await DbClient.Queryable<CoreCmsPrinter>()
.OrderByIF(orderByExpression != null, orderByExpression, orderByType)
.WhereIF(predicate != null, predicate).Select(p => new CoreCmsPrinter
{
id = p.id,
name = p.name,
code = p.code,
clientId = p.clientId,
clientSecret = p.clientSecret,
machineCode = p.machineCode,
msign = p.msign,
printerName = p.printerName,
phone = p.phone,
accessToken = p.accessToken,
refreshToken = p.refreshToken,
expiresIn = p.expiresIn,
expiressEndTime = p.expiressEndTime,
parameters = p.parameters,
createTime = p.createTime,
isDefault = p.isDefault,
isOpen = p.isOpen,
storeId = p.storeId,
}).ToPageListAsync(pageIndex, pageSize, totalCount);
}
var list = new PageList<CoreCmsPrinter>(page, pageIndex, pageSize, totalCount);
return list;
}
#endregion
}
}