From cab1c3131b11bfa6aaef6069c25afa2241af353a Mon Sep 17 00:00:00 2001
From: smartwyy <645583145@qq.com>
Date: Mon, 27 May 2024 00:12:49 +0800
Subject: [PATCH] =?UTF-8?q?=E5=85=85=E7=94=B5=E6=9C=8D=E5=8A=A1?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Entity/DbModel/Station/BatteryOpModel.cs | 67 ++
.../DbModel/Station/BatteryOpModelDetail.cs | 99 +++
.../DbModel/Station/ElecPriceModelVersion.cs | 2 +-
.../Station/ElecPriceModelVersionDetail.cs | 2 +-
.../Autofac/Attribute/ScopeAttribute.cs | 2 +-
Repository/BaseRepository.cs | 675 +++++++++++++++---
.../Station/BatteryOpModelDetailRepository.cs | 13 +
.../Station/BatteryOpModelRepository.cs | 13 +
Repository/Station/BinInfoRepository.cs | 13 +-
Service/Charger/ChargerService.cs | 72 ++
Service/Charger/Client/ChargerClient.cs | 103 ++-
Service/Charger/Client/ClientMgr.cs | 117 ++-
...Handler.cs => QueryBatterySnResHandler.cs} | 25 +-
.../Charger/Handler/RecordChargeHandler.cs | 2 +-
.../Msg/Charger/Resp/QueryBatterySnRes.cs | 2 +-
Service/Init/StaticStationInfo.cs | 57 +-
Service/Station/StationParamConst.cs | 181 ++++-
WebStarter/Controllers/ChargeController.cs | 45 ++
WinFormStarter/Form2.cs | 2 +-
19 files changed, 1305 insertions(+), 187 deletions(-)
create mode 100644 Entity/DbModel/Station/BatteryOpModel.cs
create mode 100644 Entity/DbModel/Station/BatteryOpModelDetail.cs
create mode 100644 Repository/Station/BatteryOpModelDetailRepository.cs
create mode 100644 Repository/Station/BatteryOpModelRepository.cs
create mode 100644 Service/Charger/ChargerService.cs
rename Service/Charger/Handler/{QueryBatteryBasicInfo2ResHandler.cs => QueryBatterySnResHandler.cs} (52%)
create mode 100644 WebStarter/Controllers/ChargeController.cs
diff --git a/Entity/DbModel/Station/BatteryOpModel.cs b/Entity/DbModel/Station/BatteryOpModel.cs
new file mode 100644
index 0000000..fece6bf
--- /dev/null
+++ b/Entity/DbModel/Station/BatteryOpModel.cs
@@ -0,0 +1,67 @@
+using System;
+using System.Linq;
+using System.Text;
+using SqlSugar;
+
+namespace Entity.DbModel.Station
+{
+ ///
+ ///电池运营模型
+ ///
+ [SugarTable("battery_op_model")]
+ public partial class BatteryOpModel
+ {
+ public BatteryOpModel(){
+
+
+ }
+ ///
+ /// Desc:id
+ /// Default:
+ /// Nullable:False
+ ///
+ [SugarColumn(IsPrimaryKey=true,IsIdentity=true,ColumnName="id")]
+ public int Id {get;set;}
+
+ ///
+ /// Desc:模型id
+ /// Default:
+ /// Nullable:True
+ ///
+ [SugarColumn(ColumnName="model_id")]
+ public int? ModelId {get;set;}
+
+ ///
+ /// Desc:创建人
+ /// Default:
+ /// Nullable:True
+ ///
+ [SugarColumn(ColumnName="created_by")]
+ public string CreatedBy {get;set;}
+
+ ///
+ /// Desc:创建时间
+ /// Default:CURRENT_TIMESTAMP
+ /// Nullable:True
+ ///
+ [SugarColumn(ColumnName="created_time")]
+ public DateTime? CreatedTime {get;set;}
+
+ ///
+ /// Desc:更新人
+ /// Default:
+ /// Nullable:True
+ ///
+ [SugarColumn(ColumnName="updated_by")]
+ public string UpdatedBy {get;set;}
+
+ ///
+ /// Desc:更新时间
+ /// Default:CURRENT_TIMESTAMP
+ /// Nullable:True
+ ///
+ [SugarColumn(ColumnName="updated_time")]
+ public DateTime? UpdatedTime {get;set;}
+
+ }
+}
diff --git a/Entity/DbModel/Station/BatteryOpModelDetail.cs b/Entity/DbModel/Station/BatteryOpModelDetail.cs
new file mode 100644
index 0000000..c3213b6
--- /dev/null
+++ b/Entity/DbModel/Station/BatteryOpModelDetail.cs
@@ -0,0 +1,99 @@
+using System;
+using System.Linq;
+using System.Text;
+using SqlSugar;
+
+namespace Entity.DbModel.Station
+{
+ ///
+ ///电池运营模型详情
+ ///
+ [SugarTable("battery_op_model_detail")]
+ public partial class BatteryOpModelDetail
+ {
+ public BatteryOpModelDetail(){
+
+
+ }
+ ///
+ /// Desc:id
+ /// Default:
+ /// Nullable:False
+ ///
+ [SugarColumn(IsPrimaryKey=true,ColumnName="id")]
+ public int Id {get;set;}
+
+ ///
+ /// Desc:模型Id
+ /// Default:
+ /// Nullable:True
+ ///
+ [SugarColumn(ColumnName="model_id")]
+ public int? ModelId {get;set;}
+
+ ///
+ /// Desc:开始时间:06:00:00
+ /// Default:
+ /// Nullable:True
+ ///
+ [SugarColumn(ColumnName="start_time")]
+ public string StartTime {get;set;}
+
+ ///
+ /// Desc:结束时间:06:00:01
+ /// Default:
+ /// Nullable:True
+ ///
+ [SugarColumn(ColumnName="end_time")]
+ public string EndTime {get;set;}
+
+ ///
+ /// Desc:需要电池数量
+ /// Default:
+ /// Nullable:True
+ ///
+ [SugarColumn(ColumnName="battery_count")]
+ public int? BatteryCount {get;set;}
+
+ ///
+ /// Desc:需要电池类型
+ /// Default:
+ /// Nullable:True
+ ///
+ [SugarColumn(ColumnName="battery_type")]
+ public string BatteryType {get;set;}
+
+ ///
+ /// Desc:创建人
+ /// Default:
+ /// Nullable:True
+ ///
+ [SugarColumn(ColumnName="created_by")]
+ public string CreatedBy {get;set;}
+
+ ///
+ /// Desc:创建时间
+ /// Default:CURRENT_TIMESTAMP
+ /// Nullable:True
+ ///
+ [SugarColumn(ColumnName="created_time")]
+ public DateTime? CreatedTime {get;set;}
+
+ ///
+ /// Desc:更新人
+ /// Default:
+ /// Nullable:True
+ ///
+ [SugarColumn(ColumnName="updated_by")]
+ public string UpdatedBy {get;set;}
+
+ ///
+ /// Desc:更新时间
+ /// Default:CURRENT_TIMESTAMP
+ /// Nullable:True
+ ///
+ [SugarColumn(ColumnName="updated_time")]
+ public DateTime? UpdatedTime {get;set;}
+
+ }
+}
diff --git a/Entity/DbModel/Station/ElecPriceModelVersion.cs b/Entity/DbModel/Station/ElecPriceModelVersion.cs
index 6e1ad57..49639fa 100644
--- a/Entity/DbModel/Station/ElecPriceModelVersion.cs
+++ b/Entity/DbModel/Station/ElecPriceModelVersion.cs
@@ -29,7 +29,7 @@ namespace Entity.DbModel.Station
/// Nullable:True
///
[SugarColumn(ColumnName="version")]
- public string Version {get;set;}
+ public int Version {get;set;}
///
/// Desc:生效时间;生效时间(左开右闭)
diff --git a/Entity/DbModel/Station/ElecPriceModelVersionDetail.cs b/Entity/DbModel/Station/ElecPriceModelVersionDetail.cs
index 06d64f0..a25bd21 100644
--- a/Entity/DbModel/Station/ElecPriceModelVersionDetail.cs
+++ b/Entity/DbModel/Station/ElecPriceModelVersionDetail.cs
@@ -26,7 +26,7 @@ namespace Entity.DbModel.Station
/// Nullable:True
///
[SugarColumn(ColumnName = "version")]
- public string Version { get; set; }
+ public int Version { get; set; }
///
/// Desc:开始时间
diff --git a/HybirdFrameworkCore/Autofac/Attribute/ScopeAttribute.cs b/HybirdFrameworkCore/Autofac/Attribute/ScopeAttribute.cs
index 5e34d5a..232b64f 100644
--- a/HybirdFrameworkCore/Autofac/Attribute/ScopeAttribute.cs
+++ b/HybirdFrameworkCore/Autofac/Attribute/ScopeAttribute.cs
@@ -4,7 +4,7 @@ public class ScopeAttribute : System.Attribute
{
public readonly string Scope;
- public ScopeAttribute(string scope)
+ public ScopeAttribute(string scope = "SingleInstance")
{
Scope = scope;
}
diff --git a/Repository/BaseRepository.cs b/Repository/BaseRepository.cs
index b321142..bd65d30 100644
--- a/Repository/BaseRepository.cs
+++ b/Repository/BaseRepository.cs
@@ -7,8 +7,6 @@ namespace Repository;
public abstract class BaseRepository where T : class, new()
{
- private readonly ISqlSugarClient DbBaseClient;
-
//private readonly IUnitOfWork _unitOfWork;
protected BaseRepository(ISqlSugarClient sqlSugar)
{
@@ -16,6 +14,8 @@ public abstract class BaseRepository where T : class, new()
DbBaseClient = sqlSugar;
}
+ public ISqlSugarClient DbBaseClient;
+
///
/// 根据主值查询单条数据
///
@@ -33,7 +33,7 @@ public abstract class BaseRepository where T : class, new()
///
/// 根据主值查询单条数据
///
- /// id(必须指定主键特性 [SugarColumn(IsPrimaryKey=true)]),如果是联合主键,请使用Where条件
+ /// Id(必须指定主键特性 [SugarColumn(IsPrimaryKey=true)]),如果是联合主键,请使用Where条件
/// 是否使用WITH(NOLOCK)
/// 数据实体
public async Task QueryByIdAsync(object objId, bool blUseNoLock = false)
@@ -59,44 +59,6 @@ public abstract class BaseRepository where T : class, new()
.WithNoLockOrNot(blUseNoLock)
.ToList();
}
- public async Task> QueryPageAsync(
- bool isWhere1, Expression> expression1,
- bool isWhere2, Expression> expression2,
- bool isWhere3, Expression> expression3,
- int pageNumber, int pageSize, RefAsync totalNumber,
- PageConfigReq input, bool blUseNoLock = false)
- {
- var page = await DbBaseClient
- .Queryable()
- .WhereIF(isWhere1, expression1)
- .WhereIF(isWhere2, expression2)
- .WhereIF(isWhere3, expression3)
- .OrderBuilder(input)
- .WithNoLockOrNot(blUseNoLock)
- .ToPageListAsync(pageNumber, pageSize, totalNumber);
- return page;
- }
-
- public async Task UpdateAsync(T updateObj, bool ignoreAllNullColumns)
- {
- return await DbBaseClient
- .Updateable(updateObj)
- .IgnoreColumns(ignoreAllNullColumns)
- .ExecuteCommandAsync();
- }
-
- public async Task> QueryByGroupByAsync(
- Expression> expression,
- Expression> expression2
- )
- {
- return await DbBaseClient
- .Queryable()
- .GroupBy(expression)
- .Select(expression2)
- .ToListAsync();
- }
-
///
/// 根据主值列表查询单条数据
@@ -128,6 +90,98 @@ public abstract class BaseRepository where T : class, new()
.ToList();
}
+ ///
+ /// 根据条件查询表单数据(分页)
+ ///
+ /// 页数
+ /// 每页几条数据
+ /// 是否使用WITH(NOLOCK)
+ ///
+ public IPage QueryIPageByCause(QueryPageModel page, Expression> predicate)
+ {
+ if (null == predicate)
+ {
+ return this.QueryIPage(page);
+ }
+ int totalCount = 0;
+
+
+ List pageList = DbBaseClient
+ .Queryable()
+ .Where(predicate)
+ .WithNoLockOrNot(false)
+ .ToPageList(page.Page, page.PageSize, ref totalCount);
+
+
+
+ return new IPage(totalCount, page, pageList);
+ }
+
+ ///
+ /// 根据条件查询表单数据(分页) 异步
+ ///
+ ///
+ ///
+ ///
+ public async Task> QueryIPageByCauseAsync(QueryPageModel page, Expression> predicate)
+ {
+ if (null == predicate)
+ {
+ return await this.QueryIPageAsync(page);
+ }
+ RefAsync totalCount = 0;
+
+
+ List pageList = await DbBaseClient
+ .Queryable()
+ .Where(predicate)
+ .WithNoLockOrNot(false)
+ .ToPageListAsync(page.Page, page.PageSize, totalCount);
+
+
+
+ return new IPage(totalCount, page, pageList);
+ }
+
+
+ ///
+ /// 查询表单所有数据(分页)
+ ///
+ /// 页数
+ /// 每页几条数据
+ /// 是否使用WITH(NOLOCK)
+ ///
+ public IPage QueryIPage(QueryPageModel page)
+ {
+ int totalCount = 0;
+ //page.Page = page.Page == 0 ? 1 : page.Page;//默认第一页 10条数据
+ //page.PageSize = page.PageSize == 0 ? 10 : page.PageSize;
+
+ List pageList = DbBaseClient
+ .Queryable()
+ .WithNoLockOrNot(false)
+ .ToPageList(page.Page, page.PageSize, ref totalCount);
+
+ return new IPage(totalCount, page, pageList);
+ }
+
+ ///
+ /// 查询表单所有数据(分页) 异步
+ ///
+ ///
+ ///
+ public async Task> QueryIPageAsync(QueryPageModel page)
+ {
+ RefAsync totalCount = 0;
+
+ List pageList = await DbBaseClient
+ .Queryable()
+ .WithNoLockOrNot(false)
+ .ToPageListAsync(page.Page, page.PageSize, totalCount);
+
+ return new IPage(totalCount, page, pageList);
+ }
+
///
/// 根据主值列表查询单条数据
///
@@ -186,6 +240,7 @@ public abstract class BaseRepository where T : class, new()
.ToList();
}
+
///
/// 根据条件查询数据
///
@@ -203,6 +258,66 @@ public abstract class BaseRepository where T : class, new()
.WithNoLockOrNot(blUseNoLock)
.ToListAsync();
}
+ public async Task> QueryListByClauseAsync(
+ bool isWhere, Expression> expression,
+ Expression> orderBy,
+ bool blUseNoLock = false)
+ {
+ return await DbBaseClient
+ .Queryable()
+ .OrderBy(orderBy, OrderByType.Asc)
+ .WhereIF(isWhere, expression)
+ .WithNoLockOrNot(blUseNoLock)
+ .Select()
+ .ToListAsync();
+ }
+
+ public async Task> QueryListByClauseAsync(
+ Expression> expression, Expression> expression1
+ )
+ {
+ return await DbBaseClient
+ .Queryable()
+ .Where(expression)
+ .ToListAsync(expression1);
+ }
+
+ public async Task> QueryListBySelectClauseAsync(Expression> selectExpression)
+ {
+ return await DbBaseClient
+ .Queryable()
+ .Select(selectExpression)
+ .ToListAsync();
+ }
+
+ public async Task> QueryListByOrderClauseAsync(Expression> expression)
+ {
+ return await DbBaseClient
+ .Queryable()
+ .OrderBy(expression, OrderByType.Asc)
+ .ToListAsync();
+ }
+ public async Task> QueryListByClauseAsync(
+ Expression>> include1,
+ Expression> expression)
+ {
+ return await DbBaseClient
+ .Queryable()
+ .Includes(include1)
+ .OrderBy(expression, OrderByType.Asc)
+ .ToListAsync();
+ }
+ public async Task> QueryListByInludeClauseAsync(
+ Expression> include1, Expression> expression, Expression> expression2
+ )
+ {
+ return await DbBaseClient
+ .Queryable()
+ .Includes(include1)
+ .Where(expression)
+ .OrderBy(expression2, OrderByType.Asc)
+ .ToListAsync();
+ }
///
/// 根据条件查询数据
@@ -239,6 +354,89 @@ public abstract class BaseRepository where T : class, new()
.WithNoLockOrNot(blUseNoLock)
.ToListAsync();
}
+ public async Task> QueryListByClauseAsync(
+ bool isWhere, Expression> expression,
+ bool isWhere1, Expression> expression1,
+ bool isWhere2, Expression> expression2,
+ Expression> expression3,
+ bool blUseNoLock = false)
+ {
+ return await DbBaseClient
+ .Queryable()
+ .OrderBy(expression3, OrderByType.Asc)
+ .WhereIF(isWhere, expression)
+ .WhereIF(isWhere1, expression1)
+ .WhereIF(isWhere2, expression2)
+ .WithNoLockOrNot(blUseNoLock)
+ .ToListAsync();
+ }
+ public async Task> QueryListByClauseAsync(
+ Expression> expression,
+ bool isWhere1, Expression> expression1,
+ bool isWhere2, Expression> expression2,
+ Expression> expression3,
+ int pageNumber, int pageSize, RefAsync totalNumber,
+ bool blUseNoLock = false)
+ {
+ return await DbBaseClient
+ .Queryable()
+ .OrderBy(expression3, OrderByType.Asc)
+ .Where(expression)
+ .WhereIF(isWhere1, expression1)
+ .WhereIF(isWhere2, expression2)
+ .WithNoLockOrNot(blUseNoLock)
+ .ToPageListAsync(pageNumber, pageSize, totalNumber);
+ }
+ public async Task> QueryTreeByClauseAsync(
+ Expression> expression,
+ Expression>> childListExpression, Expression> parentIdExpression, object rootValue)
+ {
+ return await DbBaseClient
+ .Queryable()
+ .OrderBy(expression, OrderByType.Asc)
+ .ToTreeAsync(childListExpression, parentIdExpression, rootValue);
+ }
+ public async Task> QueryTreeByClauseAsync(
+ Expression> expression,
+ Expression>> childListExpression, Expression> parentIdExpression, object rootValue, object[] childIds)
+ {
+ return await DbBaseClient
+ .Queryable()
+ .OrderBy(expression, OrderByType.Asc)
+ .ToTreeAsync(childListExpression, parentIdExpression, rootValue, childIds);
+ }
+ public async Task> QueryTreeByClauseAsync(
+ Expression> parentIdExpression, object primaryKeyValue, bool isContainOneself = true)
+ {
+ return await DbBaseClient
+ .Queryable()
+ .ToChildListAsync(parentIdExpression, primaryKeyValue, isContainOneself);
+ }
+ public async Task> QueryTreeByClauseAsync(
+ Expression> expression,
+ Expression> expression1,
+ Expression>> childListExpression, Expression> parentIdExpression, object rootValue
+ )
+ {
+ return await DbBaseClient
+ .Queryable()
+ .Where(expression)
+ .OrderBy(expression1, OrderByType.Asc)
+ .ToTreeAsync(childListExpression, parentIdExpression, rootValue);
+ }
+ public async Task> QueryTreeByClauseAsync(
+ Expression> expression,
+ Expression> expression1,
+ Expression>> childListExpression, Expression> parentIdExpression, object rootValue, object[] childIds
+ )
+ {
+ return await DbBaseClient
+ .Queryable()
+ .Where(expression)
+ .OrderBy(expression1, OrderByType.Asc)
+ .ToTreeAsync(childListExpression, parentIdExpression, rootValue, childIds);
+ }
+
///
/// 根据条件查询数据
@@ -277,6 +475,19 @@ public abstract class BaseRepository where T : class, new()
.WithNoLockOrNot(blUseNoLock)
.ToListAsync();
}
+ public async Task> QueryListByClauseAsync(
+ Expression> expression,
+ bool isWhere, Expression> whereIfExpression,
+ Expression> selectExpression
+ )
+ {
+ return await DbBaseClient
+ .Queryable()
+ .Where(expression)
+ .WhereIF(isWhere, whereIfExpression)
+ .Select(selectExpression)
+ .ToListAsync();
+ }
///
/// 根据条件查询一定数量数据
@@ -387,6 +598,47 @@ public abstract class BaseRepository where T : class, new()
.WithNoLockOrNot(blUseNoLock)
.FirstAsync(predicate);
}
+ public async Task> QueryByGroupByAsync(
+ Expression> expression,
+ Expression> expression2
+ )
+ {
+ return await DbBaseClient
+ .Queryable()
+ .GroupBy(expression)
+ .Select(expression2)
+ .ToListAsync();
+ }
+ public async Task> QueryByClauseAsync(Expression> predicate, Expression> selectExpression, bool blUseNoLock = false)
+ {
+ return await DbBaseClient
+ .Queryable()
+ .Where(predicate)
+ .Select(selectExpression)
+ .WithNoLockOrNot(blUseNoLock)
+ .ToListAsync();
+ }
+
+ public async Task UpdateColumnsAsync(
+ T updateObj,
+ Expression> columns
+ )
+ {
+ return await DbBaseClient
+ .Updateable(updateObj)
+ .UpdateColumns(columns)
+ .ExecuteCommandAsync();
+ }
+
+
+ public async Task> QueryListByClauseAsync(
+ Expression> expression)
+ {
+ return await DbBaseClient
+ .Queryable()
+ .Where(expression)
+ .ToListAsync();
+ }
///
/// 根据条件查询数据
@@ -423,6 +675,99 @@ public abstract class BaseRepository where T : class, new()
.WithNoLockOrNot(blUseNoLock)
.FirstAsync(predicate);
}
+ public async Task> QueryByOrderByClauseAsync
+ (
+ Expression> expression,
+ Expression> expression1,
+ bool blUseNoLock = false)
+ {
+ return await DbBaseClient
+ .Queryable()
+ .Where(expression)
+ .OrderBy(expression1, OrderByType.Asc)
+ .WithNoLockOrNot(blUseNoLock)
+ .ToListAsync();
+ }
+ public List QueryByClauseToList(
+ Expression> expression, Expression> expression2,
+ Expression> expression1, bool blUseNoLock = false)
+ {
+ return DbBaseClient
+ .Queryable()
+ .Where(expression)
+ .Where(expression2)
+ .OrderBy(expression1, OrderByType.Asc)
+ .WithNoLockOrNot(blUseNoLock)
+ .ToList();
+ }
+ public List QueryByClauseToList(Expression> expression, Expression> expression2, bool blUseNoLock = false)
+ {
+ return DbBaseClient
+ .Queryable()
+ .Where(expression)
+ .Where(expression2)
+ .WithNoLockOrNot(blUseNoLock)
+ .ToList();
+ }
+ public List QueryByClauseToList(Expression> expression, Expression> expression1, bool blUseNoLock = false)
+ {
+ return DbBaseClient
+ .Queryable()
+ .Where(expression)
+ .OrderBy(expression1, OrderByType.Asc)
+ .WithNoLockOrNot(blUseNoLock)
+ .ToList();
+ }
+ public List QueryByClauseToList(Expression> expression)
+ {
+ return DbBaseClient
+ .Queryable()
+ .Where(expression)
+ .ToList();
+ }
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ public async Task> QueryByClauseAsync(
+ Expression> joinExpression,
+ Expression> whereExpression,
+ Expression> orderExpression,
+ Expression> selectExpression
+ )
+ {
+ return await DbBaseClient
+ .Queryable()
+ .LeftJoin(joinExpression)
+ .Where(whereExpression)
+ .OrderBy(orderExpression, OrderByType.Asc)
+ .Select(selectExpression)
+ .ToListAsync();
+ }
+ public async Task> QueryByClauseAsync(
+ Expression> joinExpression,
+ Expression> whereExpression,
+ bool isWhere, Expression> whereifExpression,
+ Expression> orderExpression,
+ Expression> selectExpression
+ )
+ {
+ return await DbBaseClient
+ .Queryable()
+ .LeftJoin(joinExpression)
+ .Where(whereExpression)
+ .WhereIF(isWhere, whereifExpression)
+ .OrderBy(orderExpression, OrderByType.Asc)
+ .Select(selectExpression)
+ .ToListAsync();
+ }
///
/// 写入实体数据
@@ -435,6 +780,16 @@ public abstract class BaseRepository where T : class, new()
.Insertable(entity)
.ExecuteReturnIdentity();
}
+
+ ///
+ /// 写入或者更新实体数据
+ ///
+ /// 实体数据
+ ///
+ public int InsertOrUpdate(T entity)
+ {
+ return DbBaseClient.Storageable(entity).ExecuteCommand();
+ }
///
/// 写入实体数据
@@ -447,7 +802,12 @@ public abstract class BaseRepository where T : class, new()
.Insertable(entity)
.ExecuteReturnIdentityAsync();
}
-
+ public async Task InsertReturnEntityAsync(T entity)
+ {
+ return await DbBaseClient
+ .Insertable(entity)
+ .ExecuteReturnEntityAsync();
+ }
///
/// 写入实体数据
///
@@ -554,6 +914,64 @@ public abstract class BaseRepository where T : class, new()
return await DbBaseClient.Updateable(entity).ExecuteCommandHasChangeAsync();
}
+ public async Task UpdateAsync(
+ Expression> expression
+ )
+ {
+ return await DbBaseClient
+ .Queryable()
+ .ClearFilter()
+ .AnyAsync(expression);
+ }
+
+ public int Update(Expression> columns,
+ Expression> expression)
+ {
+ return DbBaseClient.Updateable().SetColumns(columns).Where(expression).ExecuteCommand();
+ }
+
+
+ public async Task UpdateAsync(
+ Expression> columns,
+ Expression> expression
+ )
+ {
+ return await DbBaseClient
+ .Updateable()
+ .SetColumns(columns)
+ .Where(expression)
+ .ExecuteCommandAsync();
+ }
+
+ public async Task UpdateAsync(
+ Expression> columns
+ )
+ {
+ return await DbBaseClient
+ .Updateable()
+ .IgnoreColumns(columns)
+ .ExecuteCommandAsync();
+ }
+ public async Task UpdateAsync(
+ T updateObj,
+ bool ignoreAllNullColumns
+ )
+ {
+ return await DbBaseClient
+ .Updateable(updateObj)
+ .IgnoreColumns(ignoreAllNullColumns)
+ .ExecuteCommandAsync();
+ }
+ public async Task UpdateAsync(
+ T updateObj, bool ignoreAllNullColumns, Expression> columns
+ )
+ {
+ return await DbBaseClient
+ .Updateable(updateObj)
+ .IgnoreColumns(ignoreAllNullColumns)
+ .IgnoreColumns(columns)
+ .ExecuteCommandAsync();
+ }
///
/// 更新实体数据
///
@@ -574,6 +992,7 @@ public abstract class BaseRepository where T : class, new()
return await DbBaseClient.Updateable(entity).ExecuteCommandHasChangeAsync();
}
+
///
/// 根据手写条件更新
///
@@ -718,7 +1137,23 @@ public abstract class BaseRepository where T : class, new()
{
return await DbBaseClient.Deleteable(entity).ExecuteCommandHasChangeAsync();
}
-
+ ///
+ /// 新增方法
+ /// 该方法用于:根据角色Id删除用户角色
+ ///
+ ///
+ ///
+ ///
+ ///
+ public async Task DeleteUserRoleByRoleId(
+ Expression> predicate,
+ Expression> selectExpression, Action action)
+ {
+ await DbBaseClient.Queryable()
+ .Where(predicate)
+ .Select(selectExpression)
+ .ForEachAsync(action);
+ }
///
/// 删除数据
///
@@ -1043,99 +1478,100 @@ public abstract class BaseRepository where T : class, new()
{
return await DbBaseClient.Queryable().Where(predicate).WithNoLockOrNot(blUseNoLock).SumAsync(field);
}
- ///
- /// 根据条件查询表单数据(分页)
- ///
- /// 页数
- /// 每页几条数据
- /// 是否使用WITH(NOLOCK)
- ///
- public IPage QueryIPageByCause(QueryPageModel page, Expression> predicate)
- {
- if (null == predicate)
- {
- return this.QueryIPage(page);
- }
- int totalCount = 0;
-
-
- List pageList = DbBaseClient
- .Queryable()
- .Where(predicate)
- .WithNoLockOrNot(false)
- .ToPageList(page.Page, page.PageSize, ref totalCount);
- return new IPage(totalCount, page, pageList);
- }
-
- ///
- /// 根据条件查询表单数据(分页) 异步
- ///
- ///
- ///
- ///
- public async Task> QueryIPageByCauseAsync(QueryPageModel page, Expression> predicate)
+ public async Task> QueryPageByIncludeAsync(Expression> include1,
+ Expression> whereExpression, bool isWhere, Expression> expression,
+ bool isWhere1, Expression> expression1,
+ Expression> orderExpression,
+ //TODO::
+ int pageIndex = 1, int pageSize = 20, RefAsync totalNumber = null, bool blUseNoLock = false)
{
- if (null == predicate)
- {
- return await this.QueryIPageAsync(page);
- }
- RefAsync totalCount = 0;
-
+ var page = await DbBaseClient
+ .Queryable()
+ .Includes(include1)
+ .Where(whereExpression)
+ .WhereIF(isWhere, expression)
+ .WhereIF(isWhere1, expression1)
+ .OrderBy(orderExpression, OrderByType.Asc)
+ .WithNoLockOrNot(blUseNoLock)
+ .ToPageListAsync(pageIndex, pageSize, totalNumber);
+ return page;
+ }
- List pageList = await DbBaseClient
- .Queryable()
- .Where(predicate)
- .WithNoLockOrNot(false)
- .ToPageListAsync(page.Page, page.PageSize, totalCount);
- return new IPage(totalCount, page, pageList);
+ public async Task> QueryPageAsync(
+ bool isWhere1, Expression> expression1,
+ bool isWhere2, Expression> expression2,
+ Expression> orderBy,
+ int pageNumber, int pageSize, RefAsync totalNumber,
+ bool blUseNoLock = false)
+ {
+ var page = await DbBaseClient
+ .Queryable()
+ .OrderBy(orderBy, OrderByType.Asc)
+ .WhereIF(isWhere1, expression1)
+ .WhereIF(isWhere2, expression2)
+ .WithNoLockOrNot(blUseNoLock)
+ .ToPageListAsync(pageNumber, pageSize, totalNumber);
+ return page;
}
-
- ///
- /// 查询表单所有数据(分页)
- ///
- /// 页数
- /// 每页几条数据
- /// 是否使用WITH(NOLOCK)
- ///
- public IPage QueryIPage(QueryPageModel page)
+ public async Task> QueryPageAsync(
+ bool isWhere1, Expression> expression1,
+ bool isWhere2, Expression> expression2,
+ int pageNumber, int pageSize, RefAsync totalNumber,
+ bool blUseNoLock = false)
{
- int totalCount = 0;
- //page.Page = page.Page == 0 ? 1 : page.Page;//默认第一页 10条数据
- //page.PageSize = page.PageSize == 0 ? 10 : page.PageSize;
+ var page = await DbBaseClient
+ .Queryable()
+ .WhereIF(isWhere1, expression1)
+ .WhereIF(isWhere2, expression2)
+ .WithNoLockOrNot(blUseNoLock)
+ .ToPageListAsync(pageNumber, pageSize, totalNumber);
+ return page;
+ }
- List pageList = DbBaseClient
- .Queryable()
- .WithNoLockOrNot(false)
- .ToPageList(page.Page, page.PageSize, ref totalCount);
- return new IPage(totalCount, page, pageList);
+ public async Task> QueryPageAsync(
+ bool isWhere1, Expression> expression1,
+ bool isWhere2, Expression> expression2,
+ bool isWhere3, Expression> expression3,
+ Expression> orderBy,
+ int pageNumber, int pageSize, RefAsync totalNumber,
+ bool blUseNoLock = false)
+ {
+ var page = await DbBaseClient
+ .Queryable()
+ .OrderBy(orderBy, OrderByType.Asc)
+ .WhereIF(isWhere1, expression1)
+ .WhereIF(isWhere2, expression2)
+ .WhereIF(isWhere3, expression3)
+ .WithNoLockOrNot(blUseNoLock)
+ .ToPageListAsync(pageNumber, pageSize, totalNumber);
+ return page;
}
-
- ///
- /// 查询表单所有数据(分页) 异步
- ///
- ///
- ///
- public async Task> QueryIPageAsync(QueryPageModel page)
+ public async Task> QueryPageAsync(
+ bool isWhere1, Expression> expression1,
+ bool isWhere2, Expression> expression2,
+ bool isWhere3, Expression> expression3,
+ int pageNumber, int pageSize, RefAsync totalNumber,
+ PageConfigReq input, bool blUseNoLock = false)
{
- RefAsync