充电服务

zw
smartwyy 6 months ago
parent a005c14fee
commit cab1c3131b

@ -0,0 +1,67 @@
using System;
using System.Linq;
using System.Text;
using SqlSugar;
namespace Entity.DbModel.Station
{
///<summary>
///电池运营模型
///</summary>
[SugarTable("battery_op_model")]
public partial class BatteryOpModel
{
public BatteryOpModel(){
}
/// <summary>
/// Desc:id
/// Default:
/// Nullable:False
/// </summary>
[SugarColumn(IsPrimaryKey=true,IsIdentity=true,ColumnName="id")]
public int Id {get;set;}
/// <summary>
/// Desc:模型id
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName="model_id")]
public int? ModelId {get;set;}
/// <summary>
/// Desc:创建人
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName="created_by")]
public string CreatedBy {get;set;}
/// <summary>
/// Desc:创建时间
/// Default:CURRENT_TIMESTAMP
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName="created_time")]
public DateTime? CreatedTime {get;set;}
/// <summary>
/// Desc:更新人
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName="updated_by")]
public string UpdatedBy {get;set;}
/// <summary>
/// Desc:更新时间
/// Default:CURRENT_TIMESTAMP
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName="updated_time")]
public DateTime? UpdatedTime {get;set;}
}
}

@ -0,0 +1,99 @@
using System;
using System.Linq;
using System.Text;
using SqlSugar;
namespace Entity.DbModel.Station
{
///<summary>
///电池运营模型详情
///</summary>
[SugarTable("battery_op_model_detail")]
public partial class BatteryOpModelDetail
{
public BatteryOpModelDetail(){
}
/// <summary>
/// Desc:id
/// Default:
/// Nullable:False
/// </summary>
[SugarColumn(IsPrimaryKey=true,ColumnName="id")]
public int Id {get;set;}
/// <summary>
/// Desc:模型Id
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName="model_id")]
public int? ModelId {get;set;}
/// <summary>
/// Desc:开始时间06:00:00
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName="start_time")]
public string StartTime {get;set;}
/// <summary>
/// Desc:结束时间06:00:01
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName="end_time")]
public string EndTime {get;set;}
/// <summary>
/// Desc:需要电池数量
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName="battery_count")]
public int? BatteryCount {get;set;}
/// <summary>
/// Desc:需要电池类型
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName="battery_type")]
public string BatteryType {get;set;}
/// <summary>
/// Desc:创建人
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName="created_by")]
public string CreatedBy {get;set;}
/// <summary>
/// Desc:创建时间
/// Default:CURRENT_TIMESTAMP
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName="created_time")]
public DateTime? CreatedTime {get;set;}
/// <summary>
/// Desc:更新人
/// Default:
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName="updated_by")]
public string UpdatedBy {get;set;}
/// <summary>
/// Desc:更新时间
/// Default:CURRENT_TIMESTAMP
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName="updated_time")]
public DateTime? UpdatedTime {get;set;}
}
}

@ -29,7 +29,7 @@ namespace Entity.DbModel.Station
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName="version")]
public string Version {get;set;}
public int Version {get;set;}
/// <summary>
/// Desc:生效时间;生效时间(左开右闭)

@ -26,7 +26,7 @@ namespace Entity.DbModel.Station
/// Nullable:True
/// </summary>
[SugarColumn(ColumnName = "version")]
public string Version { get; set; }
public int Version { get; set; }
/// <summary>
/// Desc:开始时间

@ -4,7 +4,7 @@ public class ScopeAttribute : System.Attribute
{
public readonly string Scope;
public ScopeAttribute(string scope)
public ScopeAttribute(string scope = "SingleInstance")
{
Scope = scope;
}

@ -7,8 +7,6 @@ namespace Repository;
public abstract class BaseRepository<T> where T : class, new()
{
private readonly ISqlSugarClient DbBaseClient;
//private readonly IUnitOfWork _unitOfWork;
protected BaseRepository(ISqlSugarClient sqlSugar)
{
@ -16,6 +14,8 @@ public abstract class BaseRepository<T> where T : class, new()
DbBaseClient = sqlSugar;
}
public ISqlSugarClient DbBaseClient;
/// <summary>
/// 根据主值查询单条数据
/// </summary>
@ -33,7 +33,7 @@ public abstract class BaseRepository<T> where T : class, new()
/// <summary>
/// 根据主值查询单条数据
/// </summary>
/// <param name="objId">id必须指定主键特性 [SugarColumn(IsPrimaryKey=true)]如果是联合主键请使用Where条件</param>
/// <param name="objId">Id必须指定主键特性 [SugarColumn(IsPrimaryKey=true)]如果是联合主键请使用Where条件</param>
/// <param name="blUseNoLock">是否使用WITH(NOLOCK)</param>
/// <returns>数据实体</returns>
public async Task<T> QueryByIdAsync(object objId, bool blUseNoLock = false)
@ -59,44 +59,6 @@ public abstract class BaseRepository<T> where T : class, new()
.WithNoLockOrNot(blUseNoLock)
.ToList();
}
public async Task<List<T>> QueryPageAsync(
bool isWhere1, Expression<Func<T, bool>> expression1,
bool isWhere2, Expression<Func<T, bool>> expression2,
bool isWhere3, Expression<Func<T, bool>> expression3,
int pageNumber, int pageSize, RefAsync<int> totalNumber,
PageConfigReq input, bool blUseNoLock = false)
{
var page = await DbBaseClient
.Queryable<T>()
.WhereIF(isWhere1, expression1)
.WhereIF(isWhere2, expression2)
.WhereIF(isWhere3, expression3)
.OrderBuilder(input)
.WithNoLockOrNot(blUseNoLock)
.ToPageListAsync(pageNumber, pageSize, totalNumber);
return page;
}
public async Task<int> UpdateAsync(T updateObj, bool ignoreAllNullColumns)
{
return await DbBaseClient
.Updateable(updateObj)
.IgnoreColumns(ignoreAllNullColumns)
.ExecuteCommandAsync();
}
public async Task<List<TResult>> QueryByGroupByAsync<TResult>(
Expression<Func<T, object>> expression,
Expression<Func<T, TResult>> expression2
)
{
return await DbBaseClient
.Queryable<T>()
.GroupBy(expression)
.Select(expression2)
.ToListAsync();
}
/// <summary>
/// 根据主值列表查询单条数据
@ -128,6 +90,98 @@ public abstract class BaseRepository<T> where T : class, new()
.ToList();
}
/// <summary>
/// 根据条件查询表单数据(分页)
/// </summary>
/// <param name="page"> 页数</param>
/// <param name="pageSize">每页几条数据</param>
/// <param name="blUseNoLock">是否使用WITH(NOLOCK)</param>
/// <returns></returns>
public IPage<T> QueryIPageByCause(QueryPageModel page, Expression<Func<T, bool>> predicate)
{
if (null == predicate)
{
return this.QueryIPage(page);
}
int totalCount = 0;
List<T> pageList = DbBaseClient
.Queryable<T>()
.Where(predicate)
.WithNoLockOrNot(false)
.ToPageList(page.Page, page.PageSize, ref totalCount);
return new IPage<T>(totalCount, page, pageList);
}
/// <summary>
/// 根据条件查询表单数据(分页) 异步
/// </summary>
/// <param name="page"></param>
/// <param name="predicate"></param>
/// <returns></returns>
public async Task<IPage<T>> QueryIPageByCauseAsync(QueryPageModel page, Expression<Func<T, bool>> predicate)
{
if (null == predicate)
{
return await this.QueryIPageAsync(page);
}
RefAsync<int> totalCount = 0;
List<T> pageList = await DbBaseClient
.Queryable<T>()
.Where(predicate)
.WithNoLockOrNot(false)
.ToPageListAsync(page.Page, page.PageSize, totalCount);
return new IPage<T>(totalCount, page, pageList);
}
/// <summary>
/// 查询表单所有数据(分页)
/// </summary>
/// <param name="page"> 页数</param>
/// <param name="pageSize">每页几条数据</param>
/// <param name="blUseNoLock">是否使用WITH(NOLOCK)</param>
/// <returns></returns>
public IPage<T> QueryIPage(QueryPageModel page)
{
int totalCount = 0;
//page.Page = page.Page == 0 ? 1 : page.Page;//默认第一页 10条数据
//page.PageSize = page.PageSize == 0 ? 10 : page.PageSize;
List<T> pageList = DbBaseClient
.Queryable<T>()
.WithNoLockOrNot(false)
.ToPageList(page.Page, page.PageSize, ref totalCount);
return new IPage<T>(totalCount, page, pageList);
}
/// <summary>
/// 查询表单所有数据(分页) 异步
/// </summary>
/// <param name="page"></param>
/// <returns></returns>
public async Task<IPage<T>> QueryIPageAsync(QueryPageModel page)
{
RefAsync<int> totalCount = 0;
List<T> pageList = await DbBaseClient
.Queryable<T>()
.WithNoLockOrNot(false)
.ToPageListAsync(page.Page, page.PageSize, totalCount);
return new IPage<T>(totalCount, page, pageList);
}
/// <summary>
/// 根据主值列表查询单条数据
/// </summary>
@ -186,6 +240,7 @@ public abstract class BaseRepository<T> where T : class, new()
.ToList();
}
/// <summary>
/// 根据条件查询数据
/// </summary>
@ -203,6 +258,66 @@ public abstract class BaseRepository<T> where T : class, new()
.WithNoLockOrNot(blUseNoLock)
.ToListAsync();
}
public async Task<List<TResult>> QueryListByClauseAsync<TResult>(
bool isWhere, Expression<Func<T, bool>> expression,
Expression<Func<T, object>> orderBy,
bool blUseNoLock = false)
{
return await DbBaseClient
.Queryable<T>()
.OrderBy(orderBy, OrderByType.Asc)
.WhereIF(isWhere, expression)
.WithNoLockOrNot(blUseNoLock)
.Select<TResult>()
.ToListAsync();
}
public async Task<List<TResult>> QueryListByClauseAsync<TResult>(
Expression<Func<T, bool>> expression, Expression<Func<T, TResult>> expression1
)
{
return await DbBaseClient
.Queryable<T>()
.Where(expression)
.ToListAsync(expression1);
}
public async Task<List<TResult>> QueryListBySelectClauseAsync<TResult>(Expression<Func<T, TResult>> selectExpression)
{
return await DbBaseClient
.Queryable<T>()
.Select(selectExpression)
.ToListAsync();
}
public async Task<List<T>> QueryListByOrderClauseAsync(Expression<Func<T, object>> expression)
{
return await DbBaseClient
.Queryable<T>()
.OrderBy(expression, OrderByType.Asc)
.ToListAsync();
}
public async Task<List<T>> QueryListByClauseAsync<TReturn1>(
Expression<Func<T, List<TReturn1>>> include1,
Expression<Func<T, object>> expression)
{
return await DbBaseClient
.Queryable<T>()
.Includes(include1)
.OrderBy(expression, OrderByType.Asc)
.ToListAsync();
}
public async Task<List<T>> QueryListByInludeClauseAsync<TReturn1>(
Expression<Func<T, TReturn1>> include1, Expression<Func<T, bool>> expression, Expression<Func<T, object>> expression2
)
{
return await DbBaseClient
.Queryable<T>()
.Includes(include1)
.Where(expression)
.OrderBy(expression2, OrderByType.Asc)
.ToListAsync();
}
/// <summary>
/// 根据条件查询数据
@ -239,6 +354,89 @@ public abstract class BaseRepository<T> where T : class, new()
.WithNoLockOrNot(blUseNoLock)
.ToListAsync();
}
public async Task<List<T>> QueryListByClauseAsync(
bool isWhere, Expression<Func<T, bool>> expression,
bool isWhere1, Expression<Func<T, bool>> expression1,
bool isWhere2, Expression<Func<T, bool>> expression2,
Expression<Func<T, object>> expression3,
bool blUseNoLock = false)
{
return await DbBaseClient
.Queryable<T>()
.OrderBy(expression3, OrderByType.Asc)
.WhereIF(isWhere, expression)
.WhereIF(isWhere1, expression1)
.WhereIF(isWhere2, expression2)
.WithNoLockOrNot(blUseNoLock)
.ToListAsync();
}
public async Task<List<T>> QueryListByClauseAsync(
Expression<Func<T, bool>> expression,
bool isWhere1, Expression<Func<T, bool>> expression1,
bool isWhere2, Expression<Func<T, bool>> expression2,
Expression<Func<T, object>> expression3,
int pageNumber, int pageSize, RefAsync<int> totalNumber,
bool blUseNoLock = false)
{
return await DbBaseClient
.Queryable<T>()
.OrderBy(expression3, OrderByType.Asc)
.Where(expression)
.WhereIF(isWhere1, expression1)
.WhereIF(isWhere2, expression2)
.WithNoLockOrNot(blUseNoLock)
.ToPageListAsync(pageNumber, pageSize, totalNumber);
}
public async Task<List<T>> QueryTreeByClauseAsync(
Expression<Func<T, object>> expression,
Expression<Func<T, IEnumerable<object>>> childListExpression, Expression<Func<T, object>> parentIdExpression, object rootValue)
{
return await DbBaseClient
.Queryable<T>()
.OrderBy(expression, OrderByType.Asc)
.ToTreeAsync(childListExpression, parentIdExpression, rootValue);
}
public async Task<List<T>> QueryTreeByClauseAsync(
Expression<Func<T, object>> expression,
Expression<Func<T, IEnumerable<object>>> childListExpression, Expression<Func<T, object>> parentIdExpression, object rootValue, object[] childIds)
{
return await DbBaseClient
.Queryable<T>()
.OrderBy(expression, OrderByType.Asc)
.ToTreeAsync(childListExpression, parentIdExpression, rootValue, childIds);
}
public async Task<List<T>> QueryTreeByClauseAsync(
Expression<Func<T, object>> parentIdExpression, object primaryKeyValue, bool isContainOneself = true)
{
return await DbBaseClient
.Queryable<T>()
.ToChildListAsync(parentIdExpression, primaryKeyValue, isContainOneself);
}
public async Task<List<T>> QueryTreeByClauseAsync(
Expression<Func<T, bool>> expression,
Expression<Func<T, object>> expression1,
Expression<Func<T, IEnumerable<object>>> childListExpression, Expression<Func<T, object>> parentIdExpression, object rootValue
)
{
return await DbBaseClient
.Queryable<T>()
.Where(expression)
.OrderBy(expression1, OrderByType.Asc)
.ToTreeAsync(childListExpression, parentIdExpression, rootValue);
}
public async Task<List<T>> QueryTreeByClauseAsync(
Expression<Func<T, bool>> expression,
Expression<Func<T, object>> expression1,
Expression<Func<T, IEnumerable<object>>> childListExpression, Expression<Func<T, object>> parentIdExpression, object rootValue, object[] childIds
)
{
return await DbBaseClient
.Queryable<T>()
.Where(expression)
.OrderBy(expression1, OrderByType.Asc)
.ToTreeAsync(childListExpression, parentIdExpression, rootValue, childIds);
}
/// <summary>
/// 根据条件查询数据
@ -277,6 +475,19 @@ public abstract class BaseRepository<T> where T : class, new()
.WithNoLockOrNot(blUseNoLock)
.ToListAsync();
}
public async Task<List<TResult>> QueryListByClauseAsync<TResult>(
Expression<Func<T, bool>> expression,
bool isWhere, Expression<Func<T, bool>> whereIfExpression,
Expression<Func<T, TResult>> selectExpression
)
{
return await DbBaseClient
.Queryable<T>()
.Where(expression)
.WhereIF(isWhere, whereIfExpression)
.Select(selectExpression)
.ToListAsync();
}
/// <summary>
/// 根据条件查询一定数量数据
@ -387,6 +598,47 @@ public abstract class BaseRepository<T> where T : class, new()
.WithNoLockOrNot(blUseNoLock)
.FirstAsync(predicate);
}
public async Task<List<TResult>> QueryByGroupByAsync<TResult>(
Expression<Func<T, object>> expression,
Expression<Func<T, TResult>> expression2
)
{
return await DbBaseClient
.Queryable<T>()
.GroupBy(expression)
.Select(expression2)
.ToListAsync();
}
public async Task<List<long>> QueryByClauseAsync(Expression<Func<T, bool>> predicate, Expression<Func<T, long>> selectExpression, bool blUseNoLock = false)
{
return await DbBaseClient
.Queryable<T>()
.Where(predicate)
.Select(selectExpression)
.WithNoLockOrNot(blUseNoLock)
.ToListAsync();
}
public async Task<int> UpdateColumnsAsync(
T updateObj,
Expression<Func<T, object>> columns
)
{
return await DbBaseClient
.Updateable(updateObj)
.UpdateColumns(columns)
.ExecuteCommandAsync();
}
public async Task<List<T>> QueryListByClauseAsync(
Expression<Func<T, bool>> expression)
{
return await DbBaseClient
.Queryable<T>()
.Where(expression)
.ToListAsync();
}
/// <summary>
/// 根据条件查询数据
@ -423,6 +675,99 @@ public abstract class BaseRepository<T> where T : class, new()
.WithNoLockOrNot(blUseNoLock)
.FirstAsync(predicate);
}
public async Task<List<T>> QueryByOrderByClauseAsync
(
Expression<Func<T, bool>> expression,
Expression<Func<T, object>> expression1,
bool blUseNoLock = false)
{
return await DbBaseClient
.Queryable<T>()
.Where(expression)
.OrderBy(expression1, OrderByType.Asc)
.WithNoLockOrNot(blUseNoLock)
.ToListAsync();
}
public List<T> QueryByClauseToList(
Expression<Func<T, bool>> expression, Expression<Func<T, bool>> expression2,
Expression<Func<T, object>> expression1, bool blUseNoLock = false)
{
return DbBaseClient
.Queryable<T>()
.Where(expression)
.Where(expression2)
.OrderBy(expression1, OrderByType.Asc)
.WithNoLockOrNot(blUseNoLock)
.ToList();
}
public List<T> QueryByClauseToList(Expression<Func<T, bool>> expression, Expression<Func<T, bool>> expression2, bool blUseNoLock = false)
{
return DbBaseClient
.Queryable<T>()
.Where(expression)
.Where(expression2)
.WithNoLockOrNot(blUseNoLock)
.ToList();
}
public List<T> QueryByClauseToList(Expression<Func<T, bool>> expression, Expression<Func<T, object>> expression1, bool blUseNoLock = false)
{
return DbBaseClient
.Queryable<T>()
.Where(expression)
.OrderBy(expression1, OrderByType.Asc)
.WithNoLockOrNot(blUseNoLock)
.ToList();
}
public List<T> QueryByClauseToList(Expression<Func<T, bool>> expression)
{
return DbBaseClient
.Queryable<T>()
.Where(expression)
.ToList();
}
/// <summary>
///
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="T2"></typeparam>
/// <typeparam name="TResult"></typeparam>
/// <param name="joinExpression"></param>
/// <param name="whereExpression"></param>
/// <param name="orderExpression"></param>
/// <param name="selectExpression"></param>
/// <returns></returns>
public async Task<List<TResult>> QueryByClauseAsync<T, T2, TResult>(
Expression<Func<T, T2, bool>> joinExpression,
Expression<Func<T, T2, bool>> whereExpression,
Expression<Func<T, T2, object>> orderExpression,
Expression<Func<T, T2, TResult>> selectExpression
)
{
return await DbBaseClient
.Queryable<T>()
.LeftJoin<T2>(joinExpression)
.Where(whereExpression)
.OrderBy(orderExpression, OrderByType.Asc)
.Select(selectExpression)
.ToListAsync();
}
public async Task<List<TResult>> QueryByClauseAsync<T, T2, TResult>(
Expression<Func<T, T2, bool>> joinExpression,
Expression<Func<T, T2, bool>> whereExpression,
bool isWhere, Expression<Func<T, T2, bool>> whereifExpression,
Expression<Func<T, T2, object>> orderExpression,
Expression<Func<T, T2, TResult>> selectExpression
)
{
return await DbBaseClient
.Queryable<T>()
.LeftJoin<T2>(joinExpression)
.Where(whereExpression)
.WhereIF(isWhere, whereifExpression)
.OrderBy(orderExpression, OrderByType.Asc)
.Select(selectExpression)
.ToListAsync();
}
/// <summary>
/// 写入实体数据
@ -435,6 +780,16 @@ public abstract class BaseRepository<T> where T : class, new()
.Insertable(entity)
.ExecuteReturnIdentity();
}
/// <summary>
/// 写入或者更新实体数据
/// </summary>
/// <param name="entity">实体数据</param>
/// <returns></returns>
public int InsertOrUpdate(T entity)
{
return DbBaseClient.Storageable(entity).ExecuteCommand();
}
/// <summary>
/// 写入实体数据
@ -447,7 +802,12 @@ public abstract class BaseRepository<T> where T : class, new()
.Insertable(entity)
.ExecuteReturnIdentityAsync();
}
public async Task<T> InsertReturnEntityAsync(T entity)
{
return await DbBaseClient
.Insertable(entity)
.ExecuteReturnEntityAsync();
}
/// <summary>
/// 写入实体数据
/// </summary>
@ -554,6 +914,64 @@ public abstract class BaseRepository<T> where T : class, new()
return await DbBaseClient.Updateable(entity).ExecuteCommandHasChangeAsync();
}
public async Task<bool> UpdateAsync(
Expression<Func<T, bool>> expression
)
{
return await DbBaseClient
.Queryable<T>()
.ClearFilter()
.AnyAsync(expression);
}
public int Update(Expression<Func<T, bool>> columns,
Expression<Func<T, bool>> expression)
{
return DbBaseClient.Updateable<T>().SetColumns(columns).Where(expression).ExecuteCommand();
}
public async Task<int> UpdateAsync(
Expression<Func<T, bool>> columns,
Expression<Func<T, bool>> expression
)
{
return await DbBaseClient
.Updateable<T>()
.SetColumns(columns)
.Where(expression)
.ExecuteCommandAsync();
}
public async Task<int> UpdateAsync(
Expression<Func<T, object>> columns
)
{
return await DbBaseClient
.Updateable<T>()
.IgnoreColumns(columns)
.ExecuteCommandAsync();
}
public async Task<int> UpdateAsync(
T updateObj,
bool ignoreAllNullColumns
)
{
return await DbBaseClient
.Updateable(updateObj)
.IgnoreColumns(ignoreAllNullColumns)
.ExecuteCommandAsync();
}
public async Task<int> UpdateAsync(
T updateObj, bool ignoreAllNullColumns, Expression<Func<T, object>> columns
)
{
return await DbBaseClient
.Updateable<T>(updateObj)
.IgnoreColumns(ignoreAllNullColumns)
.IgnoreColumns(columns)
.ExecuteCommandAsync();
}
/// <summary>
/// 更新实体数据
/// </summary>
@ -574,6 +992,7 @@ public abstract class BaseRepository<T> where T : class, new()
return await DbBaseClient.Updateable(entity).ExecuteCommandHasChangeAsync();
}
/// <summary>
/// 根据手写条件更新
/// </summary>
@ -718,7 +1137,23 @@ public abstract class BaseRepository<T> where T : class, new()
{
return await DbBaseClient.Deleteable<T>(entity).ExecuteCommandHasChangeAsync();
}
/// <summary>
/// 新增方法
/// 该方法用于根据角色Id删除用户角色
/// </summary>
/// <param name="predicate"></param>
/// <param name="selectExpression"></param>
/// <param name="action"></param>
/// <returns></returns>
public async Task DeleteUserRoleByRoleId(
Expression<Func<T, bool>> predicate,
Expression<Func<T, long>> selectExpression, Action<long> action)
{
await DbBaseClient.Queryable<T>()
.Where(predicate)
.Select(selectExpression)
.ForEachAsync(action);
}
/// <summary>
/// 删除数据
/// </summary>
@ -1043,99 +1478,100 @@ public abstract class BaseRepository<T> where T : class, new()
{
return await DbBaseClient.Queryable<T>().Where(predicate).WithNoLockOrNot(blUseNoLock).SumAsync(field);
}
/// <summary>
/// 根据条件查询表单数据(分页)
/// </summary>
/// <param name="page"> 页数</param>
/// <param name="pageSize">每页几条数据</param>
/// <param name="blUseNoLock">是否使用WITH(NOLOCK)</param>
/// <returns></returns>
public IPage<T> QueryIPageByCause(QueryPageModel page, Expression<Func<T, bool>> predicate)
{
if (null == predicate)
{
return this.QueryIPage(page);
}
int totalCount = 0;
List<T> pageList = DbBaseClient
.Queryable<T>()
.Where(predicate)
.WithNoLockOrNot(false)
.ToPageList(page.Page, page.PageSize, ref totalCount);
return new IPage<T>(totalCount, page, pageList);
}
/// <summary>
/// 根据条件查询表单数据(分页) 异步
/// </summary>
/// <param name="page"></param>
/// <param name="predicate"></param>
/// <returns></returns>
public async Task<IPage<T>> QueryIPageByCauseAsync(QueryPageModel page, Expression<Func<T, bool>> predicate)
public async Task<List<T>> QueryPageByIncludeAsync<TReturn1>(Expression<Func<T, TReturn1>> include1,
Expression<Func<T, bool>> whereExpression, bool isWhere, Expression<Func<T, bool>> expression,
bool isWhere1, Expression<Func<T, bool>> expression1,
Expression<Func<T, object>> orderExpression,
//TODO::
int pageIndex = 1, int pageSize = 20, RefAsync<int> totalNumber = null, bool blUseNoLock = false)
{
if (null == predicate)
{
return await this.QueryIPageAsync(page);
}
RefAsync<int> totalCount = 0;
var page = await DbBaseClient
.Queryable<T>()
.Includes(include1)
.Where(whereExpression)
.WhereIF(isWhere, expression)
.WhereIF(isWhere1, expression1)
.OrderBy(orderExpression, OrderByType.Asc)
.WithNoLockOrNot(blUseNoLock)
.ToPageListAsync(pageIndex, pageSize, totalNumber);
return page;
}
List<T> pageList = await DbBaseClient
.Queryable<T>()
.Where(predicate)
.WithNoLockOrNot(false)
.ToPageListAsync(page.Page, page.PageSize, totalCount);
return new IPage<T>(totalCount, page, pageList);
public async Task<List<T>> QueryPageAsync(
bool isWhere1, Expression<Func<T, bool>> expression1,
bool isWhere2, Expression<Func<T, bool>> expression2,
Expression<Func<T, object>> orderBy,
int pageNumber, int pageSize, RefAsync<int> totalNumber,
bool blUseNoLock = false)
{
var page = await DbBaseClient
.Queryable<T>()
.OrderBy(orderBy, OrderByType.Asc)
.WhereIF(isWhere1, expression1)
.WhereIF(isWhere2, expression2)
.WithNoLockOrNot(blUseNoLock)
.ToPageListAsync(pageNumber, pageSize, totalNumber);
return page;
}
/// <summary>
/// 查询表单所有数据(分页)
/// </summary>
/// <param name="page"> 页数</param>
/// <param name="pageSize">每页几条数据</param>
/// <param name="blUseNoLock">是否使用WITH(NOLOCK)</param>
/// <returns></returns>
public IPage<T> QueryIPage(QueryPageModel page)
public async Task<List<T>> QueryPageAsync(
bool isWhere1, Expression<Func<T, bool>> expression1,
bool isWhere2, Expression<Func<T, bool>> expression2,
int pageNumber, int pageSize, RefAsync<int> 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<T>()
.WhereIF(isWhere1, expression1)
.WhereIF(isWhere2, expression2)
.WithNoLockOrNot(blUseNoLock)
.ToPageListAsync(pageNumber, pageSize, totalNumber);
return page;
}
List<T> pageList = DbBaseClient
.Queryable<T>()
.WithNoLockOrNot(false)
.ToPageList(page.Page, page.PageSize, ref totalCount);
return new IPage<T>(totalCount, page, pageList);
public async Task<List<T>> QueryPageAsync(
bool isWhere1, Expression<Func<T, bool>> expression1,
bool isWhere2, Expression<Func<T, bool>> expression2,
bool isWhere3, Expression<Func<T, bool>> expression3,
Expression<Func<T, object>> orderBy,
int pageNumber, int pageSize, RefAsync<int> totalNumber,
bool blUseNoLock = false)
{
var page = await DbBaseClient
.Queryable<T>()
.OrderBy(orderBy, OrderByType.Asc)
.WhereIF(isWhere1, expression1)
.WhereIF(isWhere2, expression2)
.WhereIF(isWhere3, expression3)
.WithNoLockOrNot(blUseNoLock)
.ToPageListAsync(pageNumber, pageSize, totalNumber);
return page;
}
/// <summary>
/// 查询表单所有数据(分页) 异步
/// </summary>
/// <param name="page"></param>
/// <returns></returns>
public async Task<IPage<T>> QueryIPageAsync(QueryPageModel page)
public async Task<List<T>> QueryPageAsync(
bool isWhere1, Expression<Func<T, bool>> expression1,
bool isWhere2, Expression<Func<T, bool>> expression2,
bool isWhere3, Expression<Func<T, bool>> expression3,
int pageNumber, int pageSize, RefAsync<int> totalNumber,
PageConfigReq input, bool blUseNoLock = false)
{
RefAsync<int> totalCount = 0;
List<T> pageList = await DbBaseClient
var page = await DbBaseClient
.Queryable<T>()
.WithNoLockOrNot(false)
.ToPageListAsync(page.Page, page.PageSize, totalCount);
return new IPage<T>(totalCount, page, pageList);
.WhereIF(isWhere1, expression1)
.WhereIF(isWhere2, expression2)
.WhereIF(isWhere3, expression3)
.OrderBuilder(input)
.WithNoLockOrNot(blUseNoLock)
.ToPageListAsync(pageNumber, pageSize, totalNumber);
return page;
}
/// <summary>
/// 查询-2表查询
/// </summary>
@ -1337,4 +1773,7 @@ public abstract class BaseRepository<T> where T : class, new()
var list = await DbBaseClient.SqlQueryable<T>(sql).ToListAsync();
return list;
}
}

@ -0,0 +1,13 @@
using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac.Attribute;
using SqlSugar;
namespace Repository.Station;
[Scope("SingleInstance")]
public class BatteryOpModelDetailRepository : BaseRepository<BatteryOpModelDetail>
{
public BatteryOpModelDetailRepository(ISqlSugarClient sqlSugar) : base(sqlSugar)
{
}
}

@ -0,0 +1,13 @@
using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac.Attribute;
using SqlSugar;
namespace Repository.Station;
[Scope("SingleInstance")]
public class BatteryOpModelRepository : BaseRepository<BatteryOpModel>
{
public BatteryOpModelRepository(ISqlSugarClient sqlSugar) : base(sqlSugar)
{
}
}

@ -3,10 +3,21 @@ using HybirdFrameworkCore.Autofac.Attribute;
using SqlSugar;
namespace Repository.Station;
[Scope("SingleInstance")]
public class BinInfoRepository:BaseRepository<BinInfo>
public class BinInfoRepository : BaseRepository<BinInfo>
{
public BinInfoRepository(ISqlSugarClient sqlSugar) : base(sqlSugar)
{
}
/// <summary>
///
/// </summary>
/// <param name="binNo"></param>
/// <returns></returns>
public BinInfo? QueryByBinNo(string binNo)
{
return this.QueryByClause(it => it.No == binNo);
}
}

@ -0,0 +1,72 @@
using Entity.DbModel.Station;
using HybirdFrameworkCore.Autofac.Attribute;
using HybirdFrameworkCore.Entity;
using Repository.Station;
using Service.Charger.Client;
namespace Service.Charger;
/// <summary>
/// 充电机服务
/// </summary>
[Scope]
public class ChargerService
{
public BinInfoRepository BinInfoRepository { get; set; }
/// <summary>
/// 启动充电
/// </summary>
/// <param name="binNo"></param>
/// <returns></returns>
public Result<bool> StartChargeByBinNo(string binNo)
{
BinInfo? binInfo = BinInfoRepository.QueryByBinNo(binNo);
if (binInfo == null)
{
return Result<bool>.Fail(@"充电仓不存在");
}
if (string.IsNullOrWhiteSpace(binInfo.ChargerNo))
{
return Result<bool>.Fail(@"充电仓未配置充电机编号");
}
ChargerClient? chargerClient = ClientMgr.GetBySn(binInfo.ChargerNo);
if (chargerClient == null || !chargerClient.Connected)
{
return Result<bool>.Fail(@"充电机未连接");
}
return chargerClient.StartCharge();
}
/// <summary>
/// 停止充电
/// </summary>
/// <param name="binNo"></param>
/// <returns></returns>
public Result<bool> StopChargeByBinNo(string binNo)
{
BinInfo? binInfo = BinInfoRepository.QueryByBinNo(binNo);
if (binInfo == null)
{
return Result<bool>.Fail(@"充电仓不存在");
}
if (string.IsNullOrWhiteSpace(binInfo.ChargerNo))
{
return Result<bool>.Fail(@"充电仓未配置充电机编号");
}
ChargerClient? chargerClient = ClientMgr.GetBySn(binInfo.ChargerNo);
if (chargerClient == null || !chargerClient.Connected)
{
return Result<bool>.Fail(@"充电机未连接");
}
chargerClient.SendRemoteStopCharging();
return Result<bool>.Success("发送停止命令成功");
}
}

@ -27,7 +27,6 @@ namespace Service.Charger.Client;
[Scope("InstancePerDependency")]
public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
{
#region 属性
public ushort AuthTimes { get; set; } = 0;
@ -37,10 +36,12 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
/// 参考 Service.Charger.Common.ChargingStatus
/// </summary>
public UInt16 ChargingStatus { get; set; }
/// <summary>
/// 是否已经开始充电
/// </summary>
public bool IsCharged { get; set; } = false;
public bool IsStopped { get; set; } = false;
public bool IsCanSendStopCmd { get; set; } = true;
@ -51,44 +52,53 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
/// <summary>
/// 电池包实时数据
/// </summary>
public BatteryPackData? BatteryPackData { get; set; }
public BatteryPackData? BatteryPackData { get; set; }
/// <summary>
/// 电池包实时单体温度&单体电压数据
/// </summary>
public BatteryPackDataVoltage? BatteryPackDataVoltage { get; set; }
public BatteryPackDataVoltage? BatteryPackDataVoltage { get; set; }
/// <summary>
/// 电池包上报累计充放电电量
/// </summary>
public BatteryPackTotalElectricity? BatteryPackTotalElectricity { get; set; }
public BatteryPackTotalElectricity? BatteryPackTotalElectricity { get; set; }
/// <summary>
/// 电池包上报充放电口温度
/// </summary>
public BatteryPackPortTemperature? BatteryPackPortTemperature { get; set; }
public BatteryPackPortTemperature? BatteryPackPortTemperature { get; set; }
/// <summary>
/// 电池包内部接触器状态和故障上报
/// </summary>
public BatteryPackStateAndFault? BatteryPackStateAndFault { get; set; }
public BatteryPackStateAndFault? BatteryPackStateAndFault { get; set; }
/// <summary>
/// 充放电设备应答站功率调节指令
/// </summary>
public PowerRegulationRes PowerRegulationRes { get; set; }
/// <summary>
/// 电池包实时遥信上报(站内充电模式有电池包时周期性上传)
/// </summary>
public RemoteSignaling RemoteSignaling { get; set; }
/// <summary>
/// 充电机上报车辆 VIN
/// </summary>
public VehicleVIN VehicleVIN { get; set; }
/// <summary>
/// 充放电机应答辅助控制
/// </summary>
public AuxiliaryPowerRes AuxiliaryPowerRes { get; set; }
/// <summary>
/// 充放电上报交流电表数据(交流电表接到充电机上的情况)
/// </summary>
public AcMeter AcMeter { get; set; }
/// <summary>
///充电机遥信数据
/// </summary>
@ -98,14 +108,17 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
/// 充电机工作状态-从遥信数据包中得到。00H待机 01H工作 02H工作完成 03H充/放电暂停
/// </summary>
public byte Workstate { get; set; }
/// <summary>
/// 充电机故障-遥信数据包总故障 00H正常、01H故障
/// </summary>
public bool TotalError { get; set; }
/// <summary>
/// 充电机告警-遥信数据包总告警 00H正常、01H告警
/// </summary>
public bool TotalWarning { get; set; }
/// <summary>
/// 充电机遥测数据
/// </summary>
@ -115,35 +128,47 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
///充电机实时充电功率
/// </summary>
public float RealTimeChargePower { get; set; } = 0;
/// <summary>
/// 心跳-桩状态
/// </summary>
public byte PileState { get; set; }
/// <summary>
/// 电池编码
/// </summary>
public string? BatterNo { get; set; }
public string? BatteryNo { get; set; }
/// <summary>
/// 电池厂家
/// </summary>
public byte? BatteryFactory { get; set; }
/// <summary>
/// 电池仓编号
/// </summary>
public string? BinNo { get; set; }
/// <summary>
/// 远程升级-监控网关上送升级完成确认帧
/// </summary>
public UplinkUpgrade UplinkUpgrade { get; set; }
/// <summary>
/// 充电订单号
/// </summary>
public string? ChargeOrderNo { get; set; }
public string? ChargeOrderNo { get; set; }
/// <summary>
/// 当前指令
/// </summary>
public string? CurrentCmd { get; set; }
/// <summary>
/// 当前接收报文
/// </summary>
public string? CurrentMsg { get; set; }
#endregion
#region db
@ -158,14 +183,15 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
_chargeOrderRepository = chargeOrderRepository;
_binInfoRepository = binInfoRepository;
}
/// <summary>
///
/// </summary>
/// <param name="asdu"></param>
public void ReceiveMsgHandle(ASDU asdu)
{
this.CurrentMsg = CurrentCmd = JsonConvert.SerializeObject(asdu, Formatting.Indented)+ "\r\n" + BitUtls.BytesToHexStr(asdu.ToBytes());
this.CurrentMsg = CurrentCmd = JsonConvert.SerializeObject(asdu, Formatting.Indented) + "\r\n" +
BitUtls.BytesToHexStr(asdu.ToBytes());
}
#region 发送指令
@ -183,7 +209,7 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
return AuthTimes;
}
/// <summary>
/// 发送鉴权
@ -193,7 +219,8 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
byte authCodeKey = ChargerUtils.GetByteRandomNum(); //鉴码KEY[随机数]
byte[] authCodes = ChargerUtils.GetAuthCodesResult(ChargerConst.AuthCode, authCodeKey); //鉴权码
Auth auth = new Auth(IncreAuthTimes(), authCodes, authCodeKey);
CurrentCmd = JsonConvert.SerializeObject(auth, Formatting.Indented)+ "\r\n" + BitUtls.BytesToHexStr(auth.ToBytes());
CurrentCmd = JsonConvert.SerializeObject(auth, Formatting.Indented) + "\r\n" +
BitUtls.BytesToHexStr(auth.ToBytes());
this.Channel.WriteAndFlushAsync(auth);
}
@ -204,15 +231,17 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
/// <param name="changePowerCmdType">功率调节指令类型.默认1 绝对功率值</param>
/// <param name="changePower">0.1kw/位,默认3600</param>
/// <param name="chargeOrderNo">充电流水号</param>
public string SendRemoteStartCharging(byte socLimit, float changePower=3600, byte changePowerCmdType=1,
public string SendRemoteStartCharging(byte socLimit, float changePower = 3600, byte changePowerCmdType = 1,
string? chargeOrderNo = null)
{
if (string.IsNullOrWhiteSpace(chargeOrderNo))
{
chargeOrderNo = ChargerUtils.GenChargeOrderSn();
}
var remoteStartCharging = new RemoteStartCharging(socLimit, changePowerCmdType, changePower, chargeOrderNo);
CurrentCmd = JsonConvert.SerializeObject(remoteStartCharging, Formatting.Indented)+ "\r\n" + BitUtls.BytesToHexStr(remoteStartCharging.ToBytes());
CurrentCmd = JsonConvert.SerializeObject(remoteStartCharging, Formatting.Indented) + "\r\n" +
BitUtls.BytesToHexStr(remoteStartCharging.ToBytes());
this.Channel.WriteAndFlushAsync(remoteStartCharging);
return chargeOrderNo;
@ -222,10 +251,11 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
/// 监控平台发送远程停止充电指令
/// </summary>
/// <param name="reason">0 正常停机 1 服务器发现桩异常,强制停机</param>
public void SendRemoteStopCharging(byte reason)
public void SendRemoteStopCharging(byte reason = 0)
{
RemoteStopCharging remoteStopCharging = new RemoteStopCharging(reason);
CurrentCmd = JsonConvert.SerializeObject(remoteStopCharging, Formatting.Indented) + "\r\n" + BitUtls.BytesToHexStr(remoteStopCharging.ToBytes());
CurrentCmd = JsonConvert.SerializeObject(remoteStopCharging, Formatting.Indented) + "\r\n" +
BitUtls.BytesToHexStr(remoteStopCharging.ToBytes());
this.Channel.WriteAndFlushAsync(remoteStopCharging);
}
@ -256,7 +286,8 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
public void SendAuxiliaryPower(byte openFlag)
{
AuxiliaryPower auxiliaryPower = new AuxiliaryPower(openFlag);
CurrentCmd = JsonConvert.SerializeObject(auxiliaryPower, Formatting.Indented)+ "\r\n" + BitUtls.BytesToHexStr(auxiliaryPower.ToBytes());
CurrentCmd = JsonConvert.SerializeObject(auxiliaryPower, Formatting.Indented) + "\r\n" +
BitUtls.BytesToHexStr(auxiliaryPower.ToBytes());
this.Channel.WriteAndFlushAsync(auxiliaryPower);
}
@ -269,12 +300,12 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
public void SendBatteryHolderStatus(byte battery, byte connectionState, byte waterCondition)
{
BatteryHolderStatus batteryHolderStatus = new BatteryHolderStatus(battery, connectionState, waterCondition);
CurrentCmd = JsonConvert.SerializeObject(batteryHolderStatus, Formatting.Indented)+ "\r\n" + BitUtls.BytesToHexStr(batteryHolderStatus.ToBytes());
CurrentCmd = JsonConvert.SerializeObject(batteryHolderStatus, Formatting.Indented) + "\r\n" +
BitUtls.BytesToHexStr(batteryHolderStatus.ToBytes());
this.Channel.WriteAndFlushAsync(batteryHolderStatus);
}
/// <summary>
/// 站控下发 VIN 鉴权的结果
/// </summary>
@ -284,6 +315,7 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
AuthenticationVIN authenticationVIN = new AuthenticationVIN(vinresult);
this.Channel.WriteAndFlushAsync(authenticationVIN);
}
/// <summary>
/// 远程升级-站级监控升级请求下发
/// </summary>
@ -295,9 +327,10 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
/// <param name="mD5Verification">MD5校验值</param>
/// <param name="url">URL文件路径</param>
public void SendUpgradeRequest(byte executionControl, byte downloadTimeout, string versionNumber,
string fileName, uint fileSize, string mD5Verification, string url)
string fileName, uint fileSize, string mD5Verification, string url)
{
UpgradeRequest upgradeRequest=new UpgradeRequest(executionControl, downloadTimeout, versionNumber, fileName, fileSize, mD5Verification, url);
UpgradeRequest upgradeRequest = new UpgradeRequest(executionControl, downloadTimeout, versionNumber, fileName,
fileSize, mD5Verification, url);
this.Channel.WriteAndFlushAsync(upgradeRequest);
}
@ -307,7 +340,8 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
/// <param name="setPeakValleyTime"></param>
public void SendSetPeakValleyTime(SetPeakValleyTime setPeakValleyTime)
{
CurrentCmd = JsonConvert.SerializeObject(setPeakValleyTime, Formatting.Indented)+ "\r\n" + BitUtls.BytesToHexStr(setPeakValleyTime.ToBytes());
CurrentCmd = JsonConvert.SerializeObject(setPeakValleyTime, Formatting.Indented) + "\r\n" +
BitUtls.BytesToHexStr(setPeakValleyTime.ToBytes());
this.Channel.WriteAndFlushAsync(setPeakValleyTime);
}
@ -318,7 +352,8 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
public void SendOfflineStopCharging(byte enabled)
{
OfflineStopCharging offlineStopCharging = new OfflineStopCharging(enabled);
CurrentCmd = JsonConvert.SerializeObject(offlineStopCharging, Formatting.Indented)+ "\r\n" + BitUtls.BytesToHexStr(offlineStopCharging.ToBytes());
CurrentCmd = JsonConvert.SerializeObject(offlineStopCharging, Formatting.Indented) + "\r\n" +
BitUtls.BytesToHexStr(offlineStopCharging.ToBytes());
this.Channel.WriteAndFlushAsync(offlineStopCharging);
}
@ -338,7 +373,8 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
public void SendQueryBattery()
{
QueryBattery queryBattery = new QueryBattery(ChargerConst.BatteryNo);
CurrentCmd = JsonConvert.SerializeObject(queryBattery, Formatting.Indented)+ "\r\n" + BitUtls.BytesToHexStr(queryBattery.ToBytes());
CurrentCmd = JsonConvert.SerializeObject(queryBattery, Formatting.Indented) + "\r\n" +
BitUtls.BytesToHexStr(queryBattery.ToBytes());
this.Channel.WriteAndFlushAsync(queryBattery);
}
@ -356,6 +392,7 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
{
return Result<bool>.Fail("charger init error with no BinNo");
}
if (!Connected)
{
return Result<bool>.Fail($"charger-{BinNo} disconnect");
@ -366,12 +403,18 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
{
return Result<bool>.Fail($"charger-{BinNo} not exist");
}
BatterNo = binInfo.BatteryNo;
if (string.IsNullOrWhiteSpace(BatterNo))
BatteryNo = binInfo.BatteryNo;
if (string.IsNullOrWhiteSpace(BatteryNo))
{
return Result<bool>.Fail($"charger-{BinNo} battery not exist");
}
if (binInfo.Status == 0)
{
return Result<bool>.Fail($"仓-{BinNo} 被禁用");
}
RedisHelper redisHelper = AppInfo.Container.Resolve<RedisHelper>();
string? lockKey = redisHelper.GetStrValue($"chargeNo{BinNo}Start");
@ -388,18 +431,18 @@ public class ChargerClient : TcpClient<IBaseHandler, Decoder, Encoder>
_chargeOrderRepository.Insert(new ChargeOrder()
{
Sn = chargeOrderNo,
BatteryNo = BatterNo,
BatteryNo = BatteryNo,
CmdStatus = 0,
ChargerNo = BinNo,
ChargeMode = 1,
StartMode = 1
});
return Result<bool>.Success(true);
return Result<bool>.Success(true, "发送成功");
}
#endregion
/// <summary>
///
/// </summary>

@ -9,6 +9,7 @@ using log4net;
using Repository.Station;
using Service.Charger.Common;
using Service.Equipment;
using Service.Init;
namespace Service.Charger.Client;
@ -82,19 +83,49 @@ public static class ClientMgr
}
StartAutoChargeThread();
StartQueryBatteryInfoThread();
}
}
private static void StartQueryBatteryInfoThread()
{
Thread thread = new Thread(QueryBatteryInfo)
{
Name = @"QueryBatteryInfoThread"
};
thread.Start();
}
private static void QueryBatteryInfo()
{
while (true)
{
try
{
Thread.Sleep(1000);
foreach (var (key, client) in Dictionary)
{
client.SendQueryBattery();
}
}
catch (Exception e)
{
Log.Error("QueryBatteryInfo error", e);
}
}
}
/// <summary>
///
/// </summary>
public static void StartAutoChargeThread()
private static void StartAutoChargeThread()
{
if (!AutoChargeWorking)
{
Thread thread = new Thread(AutoChargeThread)
{
Name = @"auto-charge"
Name = @"AutoChargeThread"
};
thread.Start();
AutoChargeWorking = true;
@ -111,16 +142,42 @@ public static class ClientMgr
ElecPriceModelVersionDetailRepository elecPriceModelVersionDetailRepository =
AppInfo.Container.Resolve<ElecPriceModelVersionDetailRepository>();
BatteryOpModelRepository batteryOpModelRepository = AppInfo.Container.Resolve<BatteryOpModelRepository>();
BatteryOpModelDetailRepository batteryOpModelDetailRepository =
AppInfo.Container.Resolve<BatteryOpModelDetailRepository>();
BinInfoRepository binInfoRepository = AppInfo.Container.Resolve<BinInfoRepository>();
while (true)
{
Thread.Sleep(1000 * 30);
try
{
Thread.Sleep(1000 * 30);
DateTime now = DateTime.Now;
ElecPriceModelVersion elecPriceModelVersion = elecPriceModelVersionRepository.QueryByClause(i => i.StartTime >= now && i.EndTime < now);
List<BinInfo> binInfos = binInfoRepository.Query();
if (binInfos.Count < 0)
{
Log.Info("lack of binInfos");
continue;
}
var chargeSoc = StaticStationInfo.ChargeSoc;
List<BinInfo> socNeedChargeList = binInfos.Where(t => t.Soc < chargeSoc).ToList();
if (socNeedChargeList.Count < 0)
{
Log.Info($"lack of binInfos.soc < {chargeSoc}");
continue;
}
#region 电价模型
int ceid = StaticStationInfo.Ceid;
ElecPriceModelVersion elecPriceModelVersion = elecPriceModelVersionRepository.QueryByClause(i => i.Version == ceid);
if (elecPriceModelVersion == null)
{
Log.Info("lack of effective elec price model");
Log.Info("lack of effective elecPriceModelVersion");
continue;
}
@ -130,17 +187,57 @@ public static class ClientMgr
i.EndMinute > now.Minute).FirstOrDefault();
if (elecPriceModelVersionDetail == null)
{
Log.Info("lack of effective elec price model detail");
Log.Info("lack of effective elecPriceModelVersionDetail");
continue;
}
//int batteryCount = elecPriceModelVersionDetail.BatteryCount;
#endregion
#region 运营模型
int oid = int.Parse(StaticStationInfo.Oid);
BatteryOpModel batteryOpModel = batteryOpModelRepository.QueryByClause(d => d.ModelId == oid);
if (batteryOpModel == null)
{
Log.Info("lack of effective batteryOpModel");
continue;
}
List<BatteryOpModelDetail> batteryOpModelDetails = batteryOpModelDetailRepository.QueryListByClause(d => d.ModelId == oid);
List<BatteryOpModelDetail> opModelDetails = batteryOpModelDetails.Where(t =>
{
List<int> start = t.StartTime.Split(":").Select(int.Parse).ToList();
List<int> end = t.EndTime.Split(":").Select(int.Parse).ToList();
return now.Hour >= start[0] && now.Hour < end[0] && now.Minute >= start[1] && now.Minute < end[1] && now.Second >= start[2] && now.Second < end[2] ;
}).ToList();
if (opModelDetails.Count == 0)
{
Log.Info("lack of effective batteryOpModelDetails");
continue;
}
int needBatteryCount = opModelDetails[0].BatteryCount ?? 8;
if ((binInfos.Count - socNeedChargeList.Count) >= needBatteryCount)
{
Log.Info($"lack of needBatteryCount {needBatteryCount}");
continue;
}
#endregion
foreach (KeyValuePair<string, ChargerClient> pair in Dictionary)
foreach (BinInfo binInfo in socNeedChargeList)
{
Result<bool> result = pair.Value.StartCharge();
Log.Info($"start {pair.Key} charge {result.IsSuccess}:{result.Msg}");
if (Dictionary.TryGetValue(binInfo.ChargerNo, out var client))
{
Result<bool> result = client.StartCharge();
Log.Info($"start {binInfo.ChargerNo} charge {result.IsSuccess}:{result.Msg}");
}
else
{
Log.Info($"can not find {binInfo.ChargerNo} in dict");
}
}
}
catch (Exception e)

@ -2,9 +2,9 @@
using DotNetty.Transport.Channels;
using HybirdFrameworkCore.Autofac.Attribute;
using log4net;
using Repository.Station;
using Service.Charger.Client;
using Service.Charger.Msg.Charger.Req;
using Service.Charger.Msg.Charger.Resp;
namespace Service.Charger.Handler
{
@ -16,9 +16,16 @@ namespace Service.Charger.Handler
/// </summary>
[Order(8)]
[Scope("InstancePerDependency")]
public class QueryBatteryBasicInfo2ResHandler : SimpleChannelInboundHandler<QueryBatterySnRes>, IBaseHandler
public class QueryBatterySnResHandler : SimpleChannelInboundHandler<QueryBatterySnRes>, IBaseHandler
{
private static readonly ILog Log = LogManager.GetLogger(typeof(QueryBatteryBasicInfo2ResHandler));
private static readonly ILog Log = LogManager.GetLogger(typeof(QueryBatterySnResHandler));
private BinInfoRepository _binInfoRepository;
public QueryBatterySnResHandler(BinInfoRepository binInfoRepository)
{
_binInfoRepository = binInfoRepository;
}
protected override void ChannelRead0(IChannelHandlerContext ctx, QueryBatterySnRes msg)
{
@ -30,7 +37,17 @@ namespace Service.Charger.Handler
sb.Append(Convert.ToChar(b));
}
client.BatterNo = sb.ToString();
client.BatteryNo = sb.ToString();
client.BatteryFactory = msg.BatterFactory;
if (_binInfoRepository.Update(t => t.BatteryNo == client.BatteryNo, t => t.No == client.BinNo) > 0)
{
Log.Info($"succeed update battery no {client.BatteryNo} for {client.BinNo}");
}
else
{
Log.Info($"fail update battery no {client.BatteryNo} for {client.BinNo}");
}
Log.Info($"receive {msg} from {sn}");
}

@ -73,7 +73,7 @@ namespace Service.Charger.Handler
ChargeOrder chargeOrder = new ChargeOrder()
{
Sn = client.ChargeOrderNo,
BatteryNo = client.BatterNo,
BatteryNo = client.BatteryNo,
StartTime = new DateTime((msg.StartYear+1900) , msg.StartMonth ,msg.StartDay ,msg.StartHour, msg.StartMinute, msg.StartSecond),
EndTime = new DateTime(msg.EndYear + 1900, msg.EndMonth, msg.EndDay, msg.EndHour, msg.EndMinute, msg.EndSecond),
StartSoc = msg.SocBefore,

@ -3,7 +3,7 @@
namespace Service.Charger.Msg.Charger.Req;
/// <summary>
/// 3.6.2.3 充放电机回复电池基本参数 2PGN:0x00F802
/// 3.6.2.3 充放电机上传电池包编码PGN:0x00F881
/// </summary>
public class QueryBatterySnRes : ASDU
{

@ -10,43 +10,59 @@ namespace Service.Init;
/// </summary>
public class StaticStationInfo
{
public static string StationStatus
public static int StationStatus
{
get => Resolve(StationParamConst.StationStatus);
get => int.Parse(Resolve(StationParamConst.StationStatus));
set => Set(StationParamConst.StationStatus, value);
}
public static string OperationStartTime
{
get => Resolve(StationParamConst.OperationStartTime);
set => Set(StationParamConst.OperationStartTime, value);
}
public static string OperationEndTime
{
get => Resolve(StationParamConst.OperationEndTime);
set => Set(StationParamConst.OperationEndTime, value);
}
public static string StationWay
{
get => Resolve(StationParamConst.StationWay);
set => Set(StationParamConst.StationWay, value);
}
public static string StationModel
{
get => Resolve(StationParamConst.StationModel);
set => Set(StationParamConst.StationModel, value);
}
public static string StationName
{
get => Resolve(StationParamConst.StationName);
set => Set(StationParamConst.StationName, value);
}
public static string StationNo
{
get => Resolve(StationParamConst.StationNo);
set => Set(StationParamConst.StationNo, value);
}
public static string StationSn
{
get => Resolve(StationParamConst.StationSn);
set => Set(StationParamConst.StationSn, value);
}
public static string SwapFinishChargeTime
{
get => Resolve(StationParamConst.SwapFinishChargeTime);
set => Set(StationParamConst.SwapFinishChargeTime, value);
}
public static string SwapSoc
{
get => Resolve(StationParamConst.SwapSoc);
@ -55,6 +71,24 @@ public class StaticStationInfo
#region 充电相关
public static int Eid
{
get => int.Parse(Resolve(StationParamConst.Eid));
set => Set(StationParamConst.Eid, value);
}
public static string Oid
{
get => Resolve(StationParamConst.Oid);
set => Set(StationParamConst.Oid, value);
}
public static int Ceid
{
get => int.Parse(Resolve(StationParamConst.Ceid));
set => Set(StationParamConst.Ceid, value);
}
public static byte ChargeSoc
{
get => byte.Parse(Resolve(StationParamConst.ChargeSoc));
@ -70,14 +104,6 @@ public class StaticStationInfo
set => Set(StationParamConst.AutoChargeEnabled, value);
}
/// <summary>
/// 最低满电电池数量
/// </summary>
public static int BatteryNeedCount
{
get => int.Parse(Resolve(StationParamConst.BatteryNeedCount));
set => Set(StationParamConst.BatteryNeedCount, value);
}
#endregion
@ -100,7 +126,6 @@ public class StaticStationInfo
{
return 33000;
}
return int.Parse(port);
}
set => Set(StationParamConst.CloudServerPort, value);

@ -2,9 +2,185 @@
public class StationParamConst
{
#region 换电站基础信息
/// <summary>
/// 换电站编码
/// </summary>
public static readonly string StationNo = "Station.StationNo";
/// <summary>
/// 换电站名称
/// </summary>
public static readonly string StationName = "Station.StationName";
/// <summary>
/// 站类型
/// </summary>
public static readonly string StationType = "Station.StationType";
/// <summary>
/// 换电站识别号
/// </summary>
public static readonly string StationSn = "Station.StationSn";
/// <summary>
/// 地理位置
/// </summary>
public static readonly string StationLocation = "Station.StationLocation";
/// <summary>
/// 经度
/// </summary>
public static readonly string Longitude = "Station.Longitude";
/// <summary>
/// 纬度
/// </summary>
public static readonly string Latitude = "Station.Latitude";
/// <summary>
/// 区域编号
/// </summary>
public static readonly string AreaCode = "Station.AreaCode";
/// <summary>
/// 区域名称
/// </summary>
public static readonly string AreaName = "Station.AreaName";
/// <summary>
/// 营运开始时间
/// </summary>
public static readonly string OperationStartTime = "Station.OperationStartTime";
/// <summary>
/// 营运结束时间
/// </summary>
public static readonly string OperationEndTime = "Station.OperationEndTime";
/// <summary>
/// 服务状态
/// </summary>
public static readonly string Sevstatus = "Station.Sevstatus";
/// <summary>
/// 换电站状态: 1营运中 2歇业中 3设备维护状态 4暂停营业
/// </summary>
public static readonly string Status = "Station.Status";
/// <summary>
/// 投放时间
/// </summary>
public static readonly string? LaunchTime = "Station.LaunchTime";
/// <summary>
/// 联系方式
/// </summary>
public static readonly string ContactWay = "Station.ContactWay";
/// <summary>
/// 负责人
/// </summary>
public static readonly string Principal = "Station.Principal";
/// <summary>
/// 所属运营企业
/// </summary>
public static readonly string StationCompany = "Station.StationCompany";
/// <summary>
/// 所属运营企业统一社会信用代码
/// </summary>
public static readonly string SocialCreditCode = "Station.SocialCreditCode";
/// <summary>
/// 站控主机软件版本号
/// </summary>
public static readonly string StationSftVer = "Station.StationSftVer";
/// <summary>
/// 供应商代码
/// </summary>
public static readonly string SupplierCode = "Station.SupplierCode";
/// <summary>
/// 换电站基础信息版本号
/// </summary>
public static readonly string StationVersion = "Station.StationVersion";
/// <summary>
/// 换电站硬件版本
/// </summary>
public static readonly string? HardwareVersion = "Station.HardwareVersion";
/// <summary>
/// 封面图片文件
/// </summary>
public static readonly string Cover = "Station.Cover";
/// <summary>
/// 总体故障等级
/// </summary>
public static readonly string? Faultlevel = "Station.Faultlevel";
/// <summary>
/// 加解锁方式
/// </summary>
public static readonly string? LockType = "Station.LockType";
/// <summary>
/// 进入方式
/// </summary>
public static readonly string? AccessType = "Station.AccessType";
/// <summary>
/// 举升方式
/// </summary>
public static readonly string? RiseType = "Station.RiseType";
/// <summary>
/// 创建时间
/// </summary>
public static readonly string CreateTime = "Station.CreateTime";
/// <summary>
/// 修改时间
/// </summary>
public static readonly string? ModifyTime = "Station.ModifyTime";
/// <summary>
/// 配电容量kVA
/// </summary>
public static readonly string? DistributionCapacity = "Station.DistributionCapacity";
/// <summary>
/// 总功率kW
/// </summary>
public static readonly string? TotalPower = "Station.TotalPower";
/// <summary>
/// 省份
/// </summary>
public static readonly string StationProvince = "Station.StationProvince";
/// <summary>
/// 城市
/// </summary>
public static readonly string StationCity = "Station.StationCity";
/// <summary>
/// 组织机构ID
/// </summary>
public static readonly string? OrganizationId = "Station.OrganizationId";
/// <summary>
/// 站控电脑MAC地址
/// </summary>
public static readonly string StationMac = "Station.StationMac";
#endregion 换电站基础信息
//选包策略中最后结束充电时间需要>此值
public static readonly string SwapFinishChargeTime = "Station.SwapFinishChargeTime";
@ -14,8 +190,9 @@ public class StationParamConst
//充电soc
public static readonly string ChargeSoc = "Station.ChargeSoc";
public static readonly string AutoChargeEnabled = "Station.AutoChargeEnabled";
public static readonly string BatteryNeedCount = "Station.BatteryNeedCount";
public static readonly string Eid = "Station.Eid";
public static readonly string Oid = "Station.Oid";
public static readonly string Ceid = "Station.Ceid";
public static readonly string StationStatus = "Station.StationStatus";
public static readonly string StationWay = "Station.StationWay";

@ -0,0 +1,45 @@
using HybirdFrameworkCore.Entity;
using Microsoft.AspNetCore.Mvc;
using Service.Charger;
namespace WebStarter.Controllers;
/// <summary>
/// 充电机管理
/// </summary>
[Produces("application/json")]
[ApiController]
[Route("/api[controller]")]
public class ChargeController : ControllerBase
{
private ChargerService _chargerService;
public ChargeController(ChargerService chargerService)
{
_chargerService = chargerService;
}
/// <summary>
/// 通过仓号启动充电
/// </summary>
/// <param name="binNo">仓号</param>
/// <returns></returns>
[HttpGet]
[Route("/StartChargeByBinNo/{binNo}")]
public Result<bool> StartChargeByBinNo(string binNo)
{
return _chargerService.StartChargeByBinNo(binNo);
}
/// <summary>
/// 通过仓号停止充电
/// </summary>
/// <param name="binNo">仓号</param>
/// <returns></returns>
[HttpGet]
[Route("/StopChargeByBinNo/{binNo}")]
public Result<bool> StopChargeByBinNo(string binNo)
{
return _chargerService.StartChargeByBinNo(binNo);
}
}

@ -105,7 +105,7 @@ public partial class Form2 : Form
private void DisplayData()
{
this.SetText(this.rTxtData, JsonConvert.SerializeObject(_chargerClient, Formatting.Indented));
this.lblBatterNo.Text = _chargerClient?.BatterNo;
this.lblBatterNo.Text = _chargerClient?.BatteryNo;
}
private void btnConn_Click(object sender, EventArgs e)

Loading…
Cancel
Save