From 373198e1bfd15332eb3c49a4bd8be1ba08021733 Mon Sep 17 00:00:00 2001 From: jianweie code Date: Sun, 7 May 2023 23:10:41 +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=90=8E=E5=8F=B0=E6=94=AF=E4=BB=98=E5=8D=95=E7=94=9F?= =?UTF-8?q?=E6=88=90=E6=A0=A1=E9=AA=8C=E5=A4=B1=E8=B4=A5=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E3=80=82=20=E3=80=90=E4=BC=98=E5=8C=96=E3=80=91?= =?UTF-8?q?=E6=96=B0=E5=A2=9ESqlSugarExtensions=E6=89=A9=E5=B1=95=E7=B1=BB?= =?UTF-8?q?=EF=BC=8C=E5=A2=9E=E5=8A=A0=E6=98=AF=E5=90=A6=E4=BD=BF=E7=94=A8?= =?UTF-8?q?WITH(NoLock)=E6=96=B9=E6=B3=95=E6=89=A9=E5=B1=95=E5=B0=81?= =?UTF-8?q?=E8=A3=85=EF=BC=8C=E5=88=A0=E9=99=A4BaseRepository=E4=B8=AD?= =?UTF-8?q?=E7=9A=84=E4=B8=80=E4=BA=9B=E5=86=97=E4=BD=99=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CoreCms.Net.Repository/BaseRepository.cs | 316 ++++++------------ CoreCms.Net.Repository/SqlSugarExtensions.cs | 19 ++ .../Bill/CoreCmsBillPaymentsServices.cs | 2 +- 3 files changed, 129 insertions(+), 208 deletions(-) create mode 100644 CoreCms.Net.Repository/SqlSugarExtensions.cs diff --git a/CoreCms.Net.Repository/BaseRepository.cs b/CoreCms.Net.Repository/BaseRepository.cs index 2139d2e2..0315e4c2 100644 --- a/CoreCms.Net.Repository/BaseRepository.cs +++ b/CoreCms.Net.Repository/BaseRepository.cs @@ -47,9 +47,7 @@ namespace CoreCms.Net.Repository /// 泛型实体 public T QueryById(object pkValue, bool blUseNoLock = false, bool isDataCache = false, int cacheTimes = int.MaxValue) { - return blUseNoLock - ? DbBaseClient.Queryable().With(SqlWith.NoLock).WithCacheIF(isDataCache, cacheTimes).InSingle(pkValue) - : DbBaseClient.Queryable().WithCacheIF(isDataCache, cacheTimes).InSingle(pkValue); + return DbBaseClient.Queryable().WithNoLockOrNot(blUseNoLock).WithCacheIF(isDataCache, cacheTimes).InSingle(pkValue); } /// @@ -62,9 +60,7 @@ namespace CoreCms.Net.Repository /// 数据实体 public async Task QueryByIdAsync(object objId, bool blUseNoLock = false, bool isDataCache = false, int cacheTimes = int.MaxValue) { - return blUseNoLock - ? await DbBaseClient.Queryable().In(objId).With(SqlWith.NoLock).WithCacheIF(isDataCache, cacheTimes).SingleAsync() - : await DbBaseClient.Queryable().In(objId).WithCacheIF(isDataCache, cacheTimes).SingleAsync(); + return await DbBaseClient.Queryable().In(objId).WithNoLockOrNot(blUseNoLock).WithCacheIF(isDataCache, cacheTimes).SingleAsync(); } /// @@ -77,9 +73,7 @@ namespace CoreCms.Net.Repository /// 缓存时长(分钟) public List QueryByIDs(object[] lstIds, bool blUseNoLock = false, bool isDataCache = false, int cacheTimes = int.MaxValue) { - return blUseNoLock - ? DbBaseClient.Queryable().In(lstIds).With(SqlWith.NoLock).WithCacheIF(isDataCache, cacheTimes).ToList() - : DbBaseClient.Queryable().In(lstIds).WithCacheIF(isDataCache, cacheTimes).ToList(); + return DbBaseClient.Queryable().In(lstIds).WithNoLockOrNot(blUseNoLock).WithCacheIF(isDataCache, cacheTimes).ToList(); } /// @@ -92,9 +86,7 @@ namespace CoreCms.Net.Repository /// 缓存时长(分钟) public async Task> QueryByIDsAsync(object[] lstIds, bool blUseNoLock = false, bool isDataCache = false, int cacheTimes = int.MaxValue) { - return blUseNoLock - ? await DbBaseClient.Queryable().In(lstIds).With(SqlWith.NoLock).WithCacheIF(isDataCache, cacheTimes).ToListAsync() - : await DbBaseClient.Queryable().In(lstIds).WithCacheIF(isDataCache, cacheTimes).ToListAsync(); + return await DbBaseClient.Queryable().In(lstIds).WithNoLockOrNot(blUseNoLock).WithCacheIF(isDataCache, cacheTimes).ToListAsync(); } /// @@ -107,9 +99,7 @@ namespace CoreCms.Net.Repository /// 缓存时长(分钟) public List QueryByIDs(int[] lstIds, bool blUseNoLock = false, bool isDataCache = false, int cacheTimes = int.MaxValue) { - return blUseNoLock - ? DbBaseClient.Queryable().In(lstIds).With(SqlWith.NoLock).WithCacheIF(isDataCache, cacheTimes).ToList() - : DbBaseClient.Queryable().In(lstIds).WithCacheIF(isDataCache, cacheTimes).ToList(); + return DbBaseClient.Queryable().In(lstIds).WithNoLockOrNot(blUseNoLock).WithCacheIF(isDataCache, cacheTimes).ToList(); } /// @@ -122,9 +112,7 @@ namespace CoreCms.Net.Repository /// 缓存时长(分钟) public async Task> QueryByIDsAsync(int[] lstIds, bool blUseNoLock = false, bool isDataCache = false, int cacheTimes = int.MaxValue) { - return blUseNoLock - ? await DbBaseClient.Queryable().In(lstIds).With(SqlWith.NoLock).WithCacheIF(isDataCache, cacheTimes).ToListAsync() - : await DbBaseClient.Queryable().In(lstIds).WithCacheIF(isDataCache, cacheTimes).ToListAsync(); + return await DbBaseClient.Queryable().In(lstIds).WithNoLockOrNot(blUseNoLock).WithCacheIF(isDataCache, cacheTimes).ToListAsync(); } /// @@ -136,9 +124,7 @@ namespace CoreCms.Net.Repository /// public List Query(bool blUseNoLock = false, bool isDataCache = false, int cacheTimes = int.MaxValue) { - return blUseNoLock - ? DbBaseClient.Queryable().With(SqlWith.NoLock).WithCacheIF(isDataCache, cacheTimes).ToList() - : DbBaseClient.Queryable().WithCacheIF(isDataCache, cacheTimes).ToList(); + return DbBaseClient.Queryable().WithNoLockOrNot(blUseNoLock).WithCacheIF(isDataCache, cacheTimes).ToList(); } /// @@ -150,9 +136,7 @@ namespace CoreCms.Net.Repository /// public async Task> QueryAsync(bool blUseNoLock = false, bool isDataCache = false, int cacheTimes = int.MaxValue) { - return blUseNoLock - ? await DbBaseClient.Queryable().With(SqlWith.NoLock).WithCacheIF(isDataCache, cacheTimes).ToListAsync() - : await DbBaseClient.Queryable().WithCacheIF(isDataCache, cacheTimes).ToListAsync(); + return await DbBaseClient.Queryable().WithNoLockOrNot(blUseNoLock).WithCacheIF(isDataCache, cacheTimes).ToListAsync(); } /// @@ -166,18 +150,12 @@ namespace CoreCms.Net.Repository /// 泛型实体集合 public List QueryListByClause(string strWhere, string orderBy = "", bool blUseNoLock = false, bool isDataCache = false, int cacheTimes = int.MaxValue) { - return blUseNoLock - ? DbBaseClient.Queryable() - .OrderByIF(!string.IsNullOrEmpty(orderBy), orderBy) - .WhereIF(!string.IsNullOrEmpty(strWhere), strWhere) - .With(SqlWith.NoLock) - .WithCacheIF(isDataCache, cacheTimes) - .ToList() - : DbBaseClient.Queryable() - .OrderByIF(!string.IsNullOrEmpty(orderBy), orderBy) - .WhereIF(!string.IsNullOrEmpty(strWhere), strWhere) - .WithCacheIF(isDataCache, cacheTimes) - .ToList(); + return DbBaseClient.Queryable() + .OrderByIF(!string.IsNullOrEmpty(orderBy), orderBy) + .WhereIF(!string.IsNullOrEmpty(strWhere), strWhere) + .WithNoLockOrNot(blUseNoLock) + .WithCacheIF(isDataCache, cacheTimes) + .ToList(); } /// @@ -191,18 +169,12 @@ namespace CoreCms.Net.Repository /// 缓存时长(分钟) public async Task> QueryListByClauseAsync(string strWhere, string orderBy = "", bool blUseNoLock = false, bool isDataCache = false, int cacheTimes = int.MaxValue) { - return blUseNoLock - ? await DbBaseClient.Queryable() - .OrderByIF(!string.IsNullOrEmpty(orderBy), orderBy) - .WhereIF(!string.IsNullOrEmpty(strWhere), strWhere) - .With(SqlWith.NoLock) - .WithCacheIF(isDataCache, cacheTimes) - .ToListAsync() - : await DbBaseClient.Queryable() - .OrderByIF(!string.IsNullOrEmpty(orderBy), orderBy) - .WhereIF(!string.IsNullOrEmpty(strWhere), strWhere) - .WithCacheIF(isDataCache, cacheTimes) - .ToListAsync(); + return await DbBaseClient.Queryable() + .OrderByIF(!string.IsNullOrEmpty(orderBy), orderBy) + .WhereIF(!string.IsNullOrEmpty(strWhere), strWhere) + .WithNoLockOrNot(blUseNoLock) + .WithCacheIF(isDataCache, cacheTimes) + .ToListAsync(); } /// @@ -216,18 +188,12 @@ namespace CoreCms.Net.Repository /// 缓存时长(分钟) public List QueryListByClause(Expression> predicate, string orderBy = "", bool blUseNoLock = false, bool isDataCache = false, int cacheTimes = int.MaxValue) { - return blUseNoLock - ? DbBaseClient.Queryable() - .OrderByIF(!string.IsNullOrEmpty(orderBy), orderBy) - .WhereIF(predicate != null, predicate) - .With(SqlWith.NoLock) - .WithCacheIF(isDataCache, cacheTimes) - .ToList() - : DbBaseClient.Queryable() - .OrderByIF(!string.IsNullOrEmpty(orderBy), orderBy) - .WhereIF(predicate != null, predicate) - .WithCacheIF(isDataCache, cacheTimes) - .ToList(); + return DbBaseClient.Queryable() + .OrderByIF(!string.IsNullOrEmpty(orderBy), orderBy) + .WhereIF(predicate != null, predicate) + .WithNoLockOrNot(blUseNoLock) + .WithCacheIF(isDataCache, cacheTimes) + .ToList(); } /// @@ -241,18 +207,12 @@ namespace CoreCms.Net.Repository /// 缓存时长(分钟) public async Task> QueryListByClauseAsync(Expression> predicate, string orderBy = "", bool blUseNoLock = false, bool isDataCache = false, int cacheTimes = int.MaxValue) { - return blUseNoLock - ? await DbBaseClient.Queryable() - .OrderByIF(!string.IsNullOrEmpty(orderBy), orderBy) - .WhereIF(predicate != null, predicate) - .With(SqlWith.NoLock) - .WithCacheIF(isDataCache, cacheTimes) - .ToListAsync() - : await DbBaseClient.Queryable() - .OrderByIF(!string.IsNullOrEmpty(orderBy), orderBy) - .WhereIF(predicate != null, predicate) - .WithCacheIF(isDataCache, cacheTimes) - .ToListAsync(); + return await DbBaseClient.Queryable() + .OrderByIF(!string.IsNullOrEmpty(orderBy), orderBy) + .WhereIF(predicate != null, predicate) + .WithNoLockOrNot(blUseNoLock) + .WithCacheIF(isDataCache, cacheTimes) + .ToListAsync(); } /// @@ -267,18 +227,12 @@ namespace CoreCms.Net.Repository /// 泛型实体集合 public List QueryListByClause(Expression> predicate, Expression> orderByPredicate, OrderByType orderByType, bool blUseNoLock = false, bool isDataCache = false, int cacheTimes = int.MaxValue) { - return blUseNoLock - ? DbBaseClient.Queryable() - .OrderByIF(orderByPredicate != null, orderByPredicate, orderByType) - .WhereIF(predicate != null, predicate) - .With(SqlWith.NoLock) - .WithCacheIF(isDataCache, cacheTimes) - .ToList() - : DbBaseClient.Queryable() - .OrderByIF(orderByPredicate != null, orderByPredicate, orderByType) - .WhereIF(predicate != null, predicate) - .WithCacheIF(isDataCache, cacheTimes) - .ToList(); + return DbBaseClient.Queryable() + .OrderByIF(orderByPredicate != null, orderByPredicate, orderByType) + .WhereIF(predicate != null, predicate) + .WithNoLockOrNot(blUseNoLock) + .WithCacheIF(isDataCache, cacheTimes) + .ToList(); } /// @@ -293,18 +247,12 @@ namespace CoreCms.Net.Repository /// 泛型实体集合 public async Task> QueryListByClauseAsync(Expression> predicate, Expression> orderByPredicate, OrderByType orderByType, bool blUseNoLock = false, bool isDataCache = false, int cacheTimes = int.MaxValue) { - return blUseNoLock - ? await DbBaseClient.Queryable() - .OrderByIF(orderByPredicate != null, orderByPredicate, orderByType) - .WhereIF(predicate != null, predicate) - .With(SqlWith.NoLock) - .WithCacheIF(isDataCache, cacheTimes) - .ToListAsync() - : await DbBaseClient.Queryable() - .OrderByIF(orderByPredicate != null, orderByPredicate, orderByType) - .WhereIF(predicate != null, predicate) - .WithCacheIF(isDataCache, cacheTimes) - .ToListAsync(); + return await DbBaseClient.Queryable() + .OrderByIF(orderByPredicate != null, orderByPredicate, orderByType) + .WhereIF(predicate != null, predicate) + .WithNoLockOrNot(blUseNoLock) + .WithCacheIF(isDataCache, cacheTimes) + .ToListAsync(); } /// @@ -320,20 +268,13 @@ namespace CoreCms.Net.Repository /// public List QueryListByClause(Expression> predicate, int take, Expression> orderByPredicate, OrderByType orderByType, bool blUseNoLock = false, bool isDataCache = false, int cacheTimes = int.MaxValue) { - return blUseNoLock - ? DbBaseClient.Queryable() - .OrderByIF(orderByPredicate != null, orderByPredicate, orderByType) - .WhereIF(predicate != null, predicate) - .Take(take) - .With(SqlWith.NoLock) - .WithCacheIF(isDataCache, cacheTimes) - .ToList() - : DbBaseClient.Queryable() - .OrderByIF(orderByPredicate != null, orderByPredicate, orderByType) - .WhereIF(predicate != null, predicate) - .Take(take) - .WithCacheIF(isDataCache, cacheTimes) - .ToList(); + return DbBaseClient.Queryable() + .OrderByIF(orderByPredicate != null, orderByPredicate, orderByType) + .WhereIF(predicate != null, predicate) + .Take(take) + .WithNoLockOrNot(blUseNoLock) + .WithCacheIF(isDataCache, cacheTimes) + .ToList(); } /// @@ -349,20 +290,13 @@ namespace CoreCms.Net.Repository /// public async Task> QueryListByClauseAsync(Expression> predicate, int take, Expression> orderByPredicate, OrderByType orderByType, bool blUseNoLock = false, bool isDataCache = false, int cacheTimes = int.MaxValue) { - return blUseNoLock - ? await DbBaseClient.Queryable() - .OrderByIF(orderByPredicate != null, orderByPredicate, orderByType) - .WhereIF(predicate != null, predicate) - .Take(take) - .With(SqlWith.NoLock) - .WithCacheIF(isDataCache, cacheTimes) - .ToListAsync() - : await DbBaseClient.Queryable() - .OrderByIF(orderByPredicate != null, orderByPredicate, orderByType) - .WhereIF(predicate != null, predicate) - .Take(take) - .WithCacheIF(isDataCache, cacheTimes) - .ToListAsync(); + return await DbBaseClient.Queryable() + .OrderByIF(orderByPredicate != null, orderByPredicate, orderByType) + .WhereIF(predicate != null, predicate) + .Take(take) + .WithNoLockOrNot(blUseNoLock) + .WithCacheIF(isDataCache, cacheTimes) + .ToListAsync(); } /// @@ -377,20 +311,13 @@ namespace CoreCms.Net.Repository /// public List QueryListByClause(Expression> predicate, int take, string strOrderByFields = "", bool blUseNoLock = false, bool isDataCache = false, int cacheTimes = int.MaxValue) { - return blUseNoLock - ? DbBaseClient.Queryable() - .OrderByIF(!string.IsNullOrEmpty(strOrderByFields), strOrderByFields) - .Where(predicate) - .Take(take) - .With(SqlWith.NoLock) - .WithCacheIF(isDataCache, cacheTimes) - .ToList() - : DbBaseClient.Queryable() - .OrderByIF(!string.IsNullOrEmpty(strOrderByFields), strOrderByFields) - .Where(predicate) - .Take(take) - .WithCacheIF(isDataCache, cacheTimes) - .ToList(); + return DbBaseClient.Queryable() + .OrderByIF(!string.IsNullOrEmpty(strOrderByFields), strOrderByFields) + .Where(predicate) + .Take(take) + .WithNoLockOrNot(blUseNoLock) + .WithCacheIF(isDataCache, cacheTimes) + .ToList(); } /// @@ -405,20 +332,13 @@ namespace CoreCms.Net.Repository /// public async Task> QueryListByClauseAsync(Expression> predicate, int take, string strOrderByFields = "", bool blUseNoLock = false, bool isDataCache = false, int cacheTimes = int.MaxValue) { - return blUseNoLock - ? await DbBaseClient.Queryable() - .OrderByIF(!string.IsNullOrEmpty(strOrderByFields), strOrderByFields) - .Where(predicate) - .Take(take) - .With(SqlWith.NoLock) - .WithCacheIF(isDataCache, cacheTimes) - .ToListAsync() - : await DbBaseClient.Queryable() - .OrderByIF(!string.IsNullOrEmpty(strOrderByFields), strOrderByFields) - .Where(predicate) - .Take(take) - .WithCacheIF(isDataCache, cacheTimes) - .ToListAsync(); + return await DbBaseClient.Queryable() + .OrderByIF(!string.IsNullOrEmpty(strOrderByFields), strOrderByFields) + .Where(predicate) + .Take(take) + .WithNoLockOrNot(blUseNoLock) + .WithCacheIF(isDataCache, cacheTimes) + .ToListAsync(); } /// @@ -431,14 +351,10 @@ namespace CoreCms.Net.Repository /// public T QueryByClause(Expression> predicate, bool blUseNoLock = false, bool isDataCache = false, int cacheTimes = int.MaxValue) { - return blUseNoLock - ? DbBaseClient.Queryable() - .With(SqlWith.NoLock) - .WithCacheIF(isDataCache, cacheTimes) - .First(predicate) - : DbBaseClient.Queryable() - .WithCacheIF(isDataCache, cacheTimes) - .First(predicate); + return DbBaseClient.Queryable() + .WithNoLockOrNot(blUseNoLock) + .WithCacheIF(isDataCache, cacheTimes) + .First(predicate); } /// @@ -451,14 +367,10 @@ namespace CoreCms.Net.Repository /// public async Task QueryByClauseAsync(Expression> predicate, bool blUseNoLock = false, bool isDataCache = false, int cacheTimes = int.MaxValue) { - return blUseNoLock - ? await DbBaseClient.Queryable() - .With(SqlWith.NoLock) - .WithCacheIF(isDataCache, cacheTimes) - .FirstAsync(predicate) - : await DbBaseClient.Queryable() - .WithCacheIF(isDataCache, cacheTimes) - .FirstAsync(predicate); + return await DbBaseClient.Queryable() + .WithNoLockOrNot(blUseNoLock) + .WithCacheIF(isDataCache, cacheTimes) + .FirstAsync(predicate); } /// @@ -473,9 +385,7 @@ namespace CoreCms.Net.Repository /// public T QueryByClause(Expression> predicate, Expression> orderByPredicate, OrderByType orderByType, bool blUseNoLock = false, bool isDataCache = false, int cacheTimes = int.MaxValue) { - return blUseNoLock - ? DbBaseClient.Queryable().OrderBy(orderByPredicate, orderByType).With(SqlWith.NoLock).WithCacheIF(isDataCache, cacheTimes).First(predicate) - : DbBaseClient.Queryable().OrderBy(orderByPredicate, orderByType).WithCacheIF(isDataCache, cacheTimes).First(predicate); + return DbBaseClient.Queryable().OrderBy(orderByPredicate, orderByType).WithNoLockOrNot(blUseNoLock).WithCacheIF(isDataCache, cacheTimes).First(predicate); } /// @@ -490,9 +400,7 @@ namespace CoreCms.Net.Repository /// public async Task QueryByClauseAsync(Expression> predicate, Expression> orderByPredicate, OrderByType orderByType, bool blUseNoLock = false, bool isDataCache = false, int cacheTimes = int.MaxValue) { - return blUseNoLock - ? await DbBaseClient.Queryable().OrderBy(orderByPredicate, orderByType).With(SqlWith.NoLock).WithCacheIF(isDataCache, cacheTimes).FirstAsync(predicate) - : await DbBaseClient.Queryable().OrderBy(orderByPredicate, orderByType).WithCacheIF(isDataCache, cacheTimes).FirstAsync(predicate); + return await DbBaseClient.Queryable().OrderBy(orderByPredicate, orderByType).WithNoLockOrNot(blUseNoLock).WithCacheIF(isDataCache, cacheTimes).FirstAsync(predicate); } @@ -508,9 +416,7 @@ namespace CoreCms.Net.Repository /// public async Task QueryByClauseWithTranLockAsync(Expression> predicate, Expression> orderByPredicate, OrderByType orderByType, bool blUseTranLock = false, bool isDataCache = false, int cacheTimes = int.MaxValue) { - return blUseTranLock - ? await DbBaseClient.Queryable().TranLock(DbLockType.Wait).OrderBy(orderByPredicate, orderByType).WithCacheIF(isDataCache, cacheTimes).FirstAsync(predicate) - : await DbBaseClient.Queryable().OrderBy(orderByPredicate, orderByType).WithCacheIF(isDataCache, cacheTimes).FirstAsync(predicate); + return await DbBaseClient.Queryable().TranLock(DbLockType.Wait).OrderBy(orderByPredicate, orderByType).WithCacheIF(isDataCache, cacheTimes).FirstAsync(predicate); } #endregion @@ -1125,9 +1031,7 @@ namespace CoreCms.Net.Repository /// public bool Exists(Expression> predicate, bool blUseNoLock = false) { - return blUseNoLock - ? DbBaseClient.Queryable().Where(predicate).With(SqlWith.NoLock).Any() - : DbBaseClient.Queryable().Where(predicate).Any(); + return DbBaseClient.Queryable().Where(predicate).WithNoLockOrNot(blUseNoLock).Any(); } /// @@ -1138,9 +1042,7 @@ namespace CoreCms.Net.Repository /// public async Task ExistsAsync(Expression> predicate, bool blUseNoLock = false) { - return blUseNoLock - ? await DbBaseClient.Queryable().Where(predicate).With(SqlWith.NoLock).AnyAsync() - : await DbBaseClient.Queryable().Where(predicate).AnyAsync(); + return await DbBaseClient.Queryable().Where(predicate).WithNoLockOrNot(blUseNoLock).AnyAsync(); } #endregion @@ -1158,7 +1060,7 @@ namespace CoreCms.Net.Repository public int GetCount(Expression> predicate, bool blUseNoLock = false, bool isDataCache = false, int cacheTimes = int.MaxValue) { return blUseNoLock - ? DbBaseClient.Queryable().With(SqlWith.NoLock).WithCacheIF(isDataCache, cacheTimes).Count(predicate) + ? DbBaseClient.Queryable().WithNoLockOrNot(blUseNoLock).WithCacheIF(isDataCache, cacheTimes).Count(predicate) : DbBaseClient.Queryable().WithCacheIF(isDataCache, cacheTimes).Count(predicate); } @@ -1173,7 +1075,7 @@ namespace CoreCms.Net.Repository public async Task GetCountAsync(Expression> predicate, bool blUseNoLock = false, bool isDataCache = false, int cacheTimes = int.MaxValue) { return blUseNoLock - ? await DbBaseClient.Queryable().With(SqlWith.NoLock).WithCacheIF(isDataCache, cacheTimes).CountAsync(predicate) + ? await DbBaseClient.Queryable().WithNoLockOrNot(blUseNoLock).WithCacheIF(isDataCache, cacheTimes).CountAsync(predicate) : await DbBaseClient.Queryable().WithCacheIF(isDataCache, cacheTimes).CountAsync(predicate); } @@ -1189,7 +1091,7 @@ namespace CoreCms.Net.Repository public int GetSum(Expression> predicate, Expression> field, bool blUseNoLock = false, bool isDataCache = false, int cacheTimes = int.MaxValue) { return blUseNoLock - ? DbBaseClient.Queryable().Where(predicate).With(SqlWith.NoLock).WithCacheIF(isDataCache, cacheTimes).Sum(field) + ? DbBaseClient.Queryable().Where(predicate).WithNoLockOrNot(blUseNoLock).WithCacheIF(isDataCache, cacheTimes).Sum(field) : DbBaseClient.Queryable().Where(predicate).WithCacheIF(isDataCache, cacheTimes).Sum(field); } @@ -1206,7 +1108,7 @@ namespace CoreCms.Net.Repository bool blUseNoLock = false, bool isDataCache = false, int cacheTimes = int.MaxValue) { return blUseNoLock - ? await DbBaseClient.Queryable().Where(predicate).With(SqlWith.NoLock).WithCacheIF(isDataCache, cacheTimes).SumAsync(field) + ? await DbBaseClient.Queryable().Where(predicate).WithNoLockOrNot(blUseNoLock).WithCacheIF(isDataCache, cacheTimes).SumAsync(field) : await DbBaseClient.Queryable().Where(predicate).WithCacheIF(isDataCache, cacheTimes).SumAsync(field); } @@ -1223,7 +1125,7 @@ namespace CoreCms.Net.Repository bool blUseNoLock = false, bool isDataCache = false, int cacheTimes = int.MaxValue) { return blUseNoLock - ? DbBaseClient.Queryable().Where(predicate).With(SqlWith.NoLock).WithCacheIF(isDataCache, cacheTimes).Sum(field) + ? DbBaseClient.Queryable().Where(predicate).WithNoLockOrNot(blUseNoLock).WithCacheIF(isDataCache, cacheTimes).Sum(field) : DbBaseClient.Queryable().Where(predicate).WithCacheIF(isDataCache, cacheTimes).Sum(field); } @@ -1240,7 +1142,7 @@ namespace CoreCms.Net.Repository bool blUseNoLock = false, bool isDataCache = false, int cacheTimes = int.MaxValue) { return blUseNoLock - ? await DbBaseClient.Queryable().Where(predicate).With(SqlWith.NoLock).WithCacheIF(isDataCache, cacheTimes).SumAsync(field) + ? await DbBaseClient.Queryable().Where(predicate).WithNoLockOrNot(blUseNoLock).WithCacheIF(isDataCache, cacheTimes).SumAsync(field) : await DbBaseClient.Queryable().Where(predicate).WithCacheIF(isDataCache, cacheTimes).SumAsync(field); } @@ -1257,7 +1159,7 @@ namespace CoreCms.Net.Repository bool blUseNoLock = false, bool isDataCache = false, int cacheTimes = int.MaxValue) { return blUseNoLock - ? DbBaseClient.Queryable().Where(predicate).With(SqlWith.NoLock).WithCacheIF(isDataCache, cacheTimes).Sum(field) + ? DbBaseClient.Queryable().Where(predicate).WithNoLockOrNot(blUseNoLock).WithCacheIF(isDataCache, cacheTimes).Sum(field) : DbBaseClient.Queryable().Where(predicate).WithCacheIF(isDataCache, cacheTimes).Sum(field); } @@ -1274,7 +1176,7 @@ namespace CoreCms.Net.Repository bool blUseNoLock = false, bool isDataCache = false, int cacheTimes = int.MaxValue) { return blUseNoLock - ? await DbBaseClient.Queryable().Where(predicate).With(SqlWith.NoLock).WithCacheIF(isDataCache, cacheTimes).SumAsync(field) + ? await DbBaseClient.Queryable().Where(predicate).WithNoLockOrNot(blUseNoLock).WithCacheIF(isDataCache, cacheTimes).SumAsync(field) : await DbBaseClient.Queryable().Where(predicate).WithCacheIF(isDataCache, cacheTimes).SumAsync(field); } #endregion @@ -1301,7 +1203,7 @@ namespace CoreCms.Net.Repository ? DbBaseClient.Queryable() .OrderByIF(!string.IsNullOrEmpty(orderBy), orderBy) .WhereIF(predicate != null, predicate) - .With(SqlWith.NoLock) + .WithNoLockOrNot(blUseNoLock) .WithCacheIF(isDataCache, cacheTimes) .ToPageList(pageIndex, pageSize, ref totalCount) : DbClient.Queryable() @@ -1333,7 +1235,7 @@ namespace CoreCms.Net.Repository ? await DbBaseClient.Queryable() .OrderByIF(!string.IsNullOrEmpty(orderBy), orderBy) .WhereIF(predicate != null, predicate) - .With(SqlWith.NoLock) + .WithNoLockOrNot(blUseNoLock) .WithCacheIF(isDataCache, cacheTimes) .ToPageListAsync(pageIndex, pageSize, totalCount) : await DbBaseClient.Queryable() @@ -1366,7 +1268,7 @@ namespace CoreCms.Net.Repository ? DbBaseClient.Queryable(). OrderByIF(orderByExpression != null, orderByExpression, orderByType) .WhereIF(predicate != null, predicate) - .With(SqlWith.NoLock) + .WithNoLockOrNot(blUseNoLock) .WithCacheIF(isDataCache, cacheTimes) .ToPageList(pageIndex, pageSize, ref totalCount) : DbBaseClient.Queryable(). @@ -1399,7 +1301,7 @@ namespace CoreCms.Net.Repository ? await DbBaseClient.Queryable() .WhereIF(predicate != null, predicate) .OrderByIF(orderByExpression != null, orderByExpression, orderByType) - .With(SqlWith.NoLock) + .WithNoLockOrNot(blUseNoLock) .WithCacheIF(isDataCache, cacheTimes) .ToPageListAsync(pageIndex, pageSize, totalCount) : await DbBaseClient.Queryable() @@ -1435,10 +1337,10 @@ namespace CoreCms.Net.Repository { if (whereLambda == null) return blUseNoLock - ? DbBaseClient.Queryable(joinExpression).Select(selectExpression).With(SqlWith.NoLock).WithCacheIF(isDataCache, cacheTimes).ToList() + ? DbBaseClient.Queryable(joinExpression).Select(selectExpression).WithNoLockOrNot(blUseNoLock).WithCacheIF(isDataCache, cacheTimes).ToList() : DbBaseClient.Queryable(joinExpression).Select(selectExpression).WithCacheIF(isDataCache, cacheTimes).ToList(); return blUseNoLock - ? DbBaseClient.Queryable(joinExpression).Where(whereLambda).Select(selectExpression).With(SqlWith.NoLock).WithCacheIF(isDataCache, cacheTimes).ToList() + ? DbBaseClient.Queryable(joinExpression).Where(whereLambda).Select(selectExpression).WithNoLockOrNot(blUseNoLock).WithCacheIF(isDataCache, cacheTimes).ToList() : DbBaseClient.Queryable(joinExpression).Where(whereLambda).Select(selectExpression).WithCacheIF(isDataCache, cacheTimes).ToList(); } @@ -1463,10 +1365,10 @@ namespace CoreCms.Net.Repository { if (whereLambda == null) return blUseNoLock - ? await DbBaseClient.Queryable(joinExpression).Select(selectExpression).With(SqlWith.NoLock).WithCacheIF(isDataCache, cacheTimes).ToListAsync() + ? await DbBaseClient.Queryable(joinExpression).Select(selectExpression).WithNoLockOrNot(blUseNoLock).WithCacheIF(isDataCache, cacheTimes).ToListAsync() : await DbBaseClient.Queryable(joinExpression).Select(selectExpression).WithCacheIF(isDataCache, cacheTimes).ToListAsync(); return blUseNoLock - ? await DbBaseClient.Queryable(joinExpression).Where(whereLambda).Select(selectExpression).With(SqlWith.NoLock).WithCacheIF(isDataCache, cacheTimes).ToListAsync() + ? await DbBaseClient.Queryable(joinExpression).Where(whereLambda).Select(selectExpression).WithNoLockOrNot(blUseNoLock).WithCacheIF(isDataCache, cacheTimes).ToListAsync() : await DbBaseClient.Queryable(joinExpression).Where(whereLambda).Select(selectExpression).WithCacheIF(isDataCache, cacheTimes).ToListAsync(); } @@ -1491,10 +1393,10 @@ namespace CoreCms.Net.Repository { if (whereLambda == null) return blUseNoLock - ? DbBaseClient.Queryable(joinExpression).Select(selectExpression).With(SqlWith.NoLock).WithCacheIF(isDataCache, cacheTimes).First() + ? DbBaseClient.Queryable(joinExpression).Select(selectExpression).WithNoLockOrNot(blUseNoLock).WithCacheIF(isDataCache, cacheTimes).First() : DbBaseClient.Queryable(joinExpression).Select(selectExpression).WithCacheIF(isDataCache, cacheTimes).First(); return blUseNoLock - ? DbBaseClient.Queryable(joinExpression).Where(whereLambda).Select(selectExpression).With(SqlWith.NoLock).WithCacheIF(isDataCache, cacheTimes).First() + ? DbBaseClient.Queryable(joinExpression).Where(whereLambda).Select(selectExpression).WithNoLockOrNot(blUseNoLock).WithCacheIF(isDataCache, cacheTimes).First() : DbBaseClient.Queryable(joinExpression).Where(whereLambda).Select(selectExpression).WithCacheIF(isDataCache, cacheTimes).First(); } @@ -1519,10 +1421,10 @@ namespace CoreCms.Net.Repository { if (whereLambda == null) return blUseNoLock - ? await DbBaseClient.Queryable(joinExpression).Select(selectExpression).With(SqlWith.NoLock).WithCacheIF(isDataCache, cacheTimes).FirstAsync() + ? await DbBaseClient.Queryable(joinExpression).Select(selectExpression).WithNoLockOrNot(blUseNoLock).WithCacheIF(isDataCache, cacheTimes).FirstAsync() : await DbBaseClient.Queryable(joinExpression).Select(selectExpression).WithCacheIF(isDataCache, cacheTimes).FirstAsync(); return blUseNoLock - ? await DbBaseClient.Queryable(joinExpression).Where(whereLambda).Select(selectExpression).With(SqlWith.NoLock).WithCacheIF(isDataCache, cacheTimes).FirstAsync() + ? await DbBaseClient.Queryable(joinExpression).Where(whereLambda).Select(selectExpression).WithNoLockOrNot(blUseNoLock).WithCacheIF(isDataCache, cacheTimes).FirstAsync() : await DbBaseClient.Queryable(joinExpression).Where(whereLambda).Select(selectExpression).WithCacheIF(isDataCache, cacheTimes).FirstAsync(); } @@ -1548,10 +1450,10 @@ namespace CoreCms.Net.Repository { if (whereLambda == null) return blUseNoLock - ? DbBaseClient.Queryable(joinExpression).Select(selectExpression).With(SqlWith.NoLock).WithCacheIF(isDataCache, cacheTimes).ToList() + ? DbBaseClient.Queryable(joinExpression).Select(selectExpression).WithNoLockOrNot(blUseNoLock).WithCacheIF(isDataCache, cacheTimes).ToList() : DbBaseClient.Queryable(joinExpression).Select(selectExpression).WithCacheIF(isDataCache, cacheTimes).ToList(); return blUseNoLock - ? DbBaseClient.Queryable(joinExpression).Where(whereLambda).Select(selectExpression).With(SqlWith.NoLock).WithCacheIF(isDataCache, cacheTimes).ToList() + ? DbBaseClient.Queryable(joinExpression).Where(whereLambda).Select(selectExpression).WithNoLockOrNot(blUseNoLock).WithCacheIF(isDataCache, cacheTimes).ToList() : DbBaseClient.Queryable(joinExpression).Where(whereLambda).Select(selectExpression).WithCacheIF(isDataCache, cacheTimes).ToList(); } @@ -1577,10 +1479,10 @@ namespace CoreCms.Net.Repository { if (whereLambda == null) return blUseNoLock - ? await DbBaseClient.Queryable(joinExpression).Select(selectExpression).With(SqlWith.NoLock).WithCacheIF(isDataCache, cacheTimes).ToListAsync() + ? await DbBaseClient.Queryable(joinExpression).Select(selectExpression).WithNoLockOrNot(blUseNoLock).WithCacheIF(isDataCache, cacheTimes).ToListAsync() : await DbBaseClient.Queryable(joinExpression).Select(selectExpression).WithCacheIF(isDataCache, cacheTimes).ToListAsync(); return blUseNoLock - ? await DbBaseClient.Queryable(joinExpression).Where(whereLambda).Select(selectExpression).With(SqlWith.NoLock).WithCacheIF(isDataCache, cacheTimes).ToListAsync() + ? await DbBaseClient.Queryable(joinExpression).Where(whereLambda).Select(selectExpression).WithNoLockOrNot(blUseNoLock).WithCacheIF(isDataCache, cacheTimes).ToListAsync() : await DbBaseClient.Queryable(joinExpression).Where(whereLambda).Select(selectExpression).WithCacheIF(isDataCache, cacheTimes).ToListAsync(); } #endregion diff --git a/CoreCms.Net.Repository/SqlSugarExtensions.cs b/CoreCms.Net.Repository/SqlSugarExtensions.cs new file mode 100644 index 00000000..f725dcd3 --- /dev/null +++ b/CoreCms.Net.Repository/SqlSugarExtensions.cs @@ -0,0 +1,19 @@ +using SqlSugar; + +namespace CoreCms.Net.Repository +{ + internal static class SqlSugarExtensions + { + internal static ISugarQueryable WithNoLockOrNot(this ISugarQueryable query, bool @lock = false) + { + if (@lock) + { + query = query.With(SqlWith.NoLock); + } + + return query; + } + + + } +} diff --git a/CoreCms.Net.Services/Bill/CoreCmsBillPaymentsServices.cs b/CoreCms.Net.Services/Bill/CoreCmsBillPaymentsServices.cs index 403adc51..3f6ccb7b 100644 --- a/CoreCms.Net.Services/Bill/CoreCmsBillPaymentsServices.cs +++ b/CoreCms.Net.Services/Bill/CoreCmsBillPaymentsServices.cs @@ -581,7 +581,7 @@ namespace CoreCms.Net.Services var paymentRelData = new CheckPayDTO(); var sourceStrArr = sourceStr.Split(","); - if (sourceStrArr.Length > 0) + if (sourceStrArr.Length > 1) { var paymentRel = await BatchFormatPaymentRel(sourceStrArr, type, @params); if (paymentRel.status == false)