From 1e80d92f3ce3f831002d7f91089279dc4613f4e6 Mon Sep 17 00:00:00 2001 From: xiaochanghai Date: Wed, 24 Apr 2024 13:59:49 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E8=8F=9C=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/CommonController.cs | 37 + Tiobon.Core.Api/Tiobon.Core.xml | 19 + .../DB/Dapper/Utilities/DbAccess.cs | 6 +- Tiobon.Core.IServices/ICommonServices.cs | 22 + Tiobon.Core.Model/ViewModels/Menu.cs | 32 + Tiobon.Core.Services/BASE/BaseServices.cs | 1657 ++++++++--------- Tiobon.Core.Services/CommonServices.cs | 90 + 7 files changed, 1030 insertions(+), 833 deletions(-) create mode 100644 Tiobon.Core.Api/Controllers/CommonController.cs create mode 100644 Tiobon.Core.IServices/ICommonServices.cs create mode 100644 Tiobon.Core.Model/ViewModels/Menu.cs create mode 100644 Tiobon.Core.Services/CommonServices.cs diff --git a/Tiobon.Core.Api/Controllers/CommonController.cs b/Tiobon.Core.Api/Controllers/CommonController.cs new file mode 100644 index 00000000..c56302f1 --- /dev/null +++ b/Tiobon.Core.Api/Controllers/CommonController.cs @@ -0,0 +1,37 @@ +namespace Tiobon.Core.Controllers; + +/// +/// 公共服务 +/// +[Produces("application/json")] +[Route("api/Common")] +[ApiExplorerSettings(GroupName = Grouping.GroupName_System)] +public class CommonController : BaseApiController +{ + private readonly ILogger _logger; + private readonly ICommonServices _commonServices; + + /// + /// 构造函数 + /// + /// + /// + public CommonController(ILogger logger, ICommonServices commonServices) + { + _commonServices = commonServices; + _logger = logger; + } + + #region 获取菜单 + /// + /// 获取菜单 + /// + /// + /// + [HttpPost, Route("GetMenu")] + public async Task> GetMenuAsync([FromBody] MenuParam param) + { + return await _commonServices.GetMenuAsync(param); + } + #endregion +} \ No newline at end of file diff --git a/Tiobon.Core.Api/Tiobon.Core.xml b/Tiobon.Core.Api/Tiobon.Core.xml index 046bc4f4..fecd742b 100644 --- a/Tiobon.Core.Api/Tiobon.Core.xml +++ b/Tiobon.Core.Api/Tiobon.Core.xml @@ -211,6 +211,25 @@ + + + 公共服务 + + + + + 构造函数 + + + + + + + 获取菜单 + + + + 构造函数 diff --git a/Tiobon.Core.Common/DB/Dapper/Utilities/DbAccess.cs b/Tiobon.Core.Common/DB/Dapper/Utilities/DbAccess.cs index e5254a6b..5610ffb8 100644 --- a/Tiobon.Core.Common/DB/Dapper/Utilities/DbAccess.cs +++ b/Tiobon.Core.Common/DB/Dapper/Utilities/DbAccess.cs @@ -90,7 +90,7 @@ public class DbAccess public static DataTable GetDataTable(string sql, object param = null, CommandType? commandType = null, bool beginTransaction = false) => Instance.GetDataTable(sql, param, commandType, beginTransaction); public static async Task GetDataTableAsync(string cmd, object param = null, IDbTransaction transaction = null, CommandType? commandType = null, int? commandTimeout = null) => await Instance.GetDataTableAsync(cmd, param, transaction, commandType, commandTimeout); - public static List QueryList(string cmd, object param, CommandType? commandType = null, bool beginTransaction = false) where T : class => Instance.QueryList(cmd, param, commandType, beginTransaction); + public static List QueryList(string cmd, object param = null, CommandType? commandType = null, bool beginTransaction = false) where T : class => Instance.QueryList(cmd, param, commandType, beginTransaction); public static async Task> QueryListAsync(string cmd, object param = null, bool beginTransaction = false, CommandType? commandType = null, int? commandTimeout = null) where T : class => await Instance.QueryListAsync(cmd, param, commandType, beginTransaction, commandTimeout); @@ -101,9 +101,9 @@ public class DbAccess public static async Task ExecuteScalarAsync(string cmd, object param = null, CommandType? commandType = null, bool beginTransaction = false) => await Instance.ExecuteScalarAsync(cmd, param, commandType, beginTransaction); public static int ExcuteNonQuery(string cmd, object param, CommandType? commandType = null, bool beginTransaction = false) => Instance.ExcuteNonQuery(cmd, param, commandType, beginTransaction); - public static (List, List) QueryMultiple(string cmd, object param, CommandType? commandType = null, bool beginTransaction = false) => Instance.QueryMultiple(cmd, param, commandType, beginTransaction); + public static (List, List) QueryMultiple(string cmd, object param = null, CommandType? commandType = null, bool beginTransaction = false) => Instance.QueryMultiple(cmd, param, commandType, beginTransaction); - public static (List, List, List) QueryMultiple(string cmd, object param, CommandType? commandType = null, bool beginTransaction = false) => Instance.QueryMultiple(cmd, param, commandType, beginTransaction); + public static (List, List, List) QueryMultiple(string cmd, object param = null, CommandType? commandType = null, bool beginTransaction = false) => Instance.QueryMultiple(cmd, param, commandType, beginTransaction); public static int ExecuteDML(string cmd, object param, CommandType? commandType = null, IDbTransaction dbTransaction = null) => Instance.ExecuteDML(cmd, param, commandType, dbTransaction); diff --git a/Tiobon.Core.IServices/ICommonServices.cs b/Tiobon.Core.IServices/ICommonServices.cs new file mode 100644 index 00000000..57c760be --- /dev/null +++ b/Tiobon.Core.IServices/ICommonServices.cs @@ -0,0 +1,22 @@ +using Microsoft.AspNetCore.Mvc; +using Tiobon.Core.IServices.BASE; +using Tiobon.Core.Model; + +namespace Tiobon.Core.IServices; + +/// +/// IPayServices +/// +public interface ICommonServices : IBaseServices> +{ + + /// + /// 获取菜单 + /// + /// + /// + Task> GetMenuAsync([FromBody] MenuParam param); + + + +} diff --git a/Tiobon.Core.Model/ViewModels/Menu.cs b/Tiobon.Core.Model/ViewModels/Menu.cs new file mode 100644 index 00000000..574b16f2 --- /dev/null +++ b/Tiobon.Core.Model/ViewModels/Menu.cs @@ -0,0 +1,32 @@ +namespace Tiobon.Core.Model; + +public class MenuParam +{ + public int langId { get; set; } + public string menuName { get; set; } + public string timestamp { get; set; } + public string token { get; set; } + public dynamic jsonParam { get; set; } +} +public class MenuReturn +{ + public List DT_SubMenu { get; set; } + public List DT_MenuColType { get; set; } + +} +public class DT_SubMenu +{ + public string IconType { get; set; } + public string MenuGroupTitle { get; set; } + public string MenuName { get; set; } + public string MenuNo { get; set; } + public string MenuUrl { get; set; } + +} + +public class DT_MenuColType +{ + public string MenuColType { get; set; } + + +} \ No newline at end of file diff --git a/Tiobon.Core.Services/BASE/BaseServices.cs b/Tiobon.Core.Services/BASE/BaseServices.cs index 1dc10bba..490da9d7 100644 --- a/Tiobon.Core.Services/BASE/BaseServices.cs +++ b/Tiobon.Core.Services/BASE/BaseServices.cs @@ -3,7 +3,6 @@ using System.Linq.Expressions; using System.Reflection; using AgileObjects.AgileMapper; using Microsoft.AspNetCore.Http; -using OfficeOpenXml.FormulaParsing.Excel.Functions.Text; using SqlSugar; using Tiobon.Core.Common; using Tiobon.Core.Common.DB.Dapper; @@ -15,980 +14,978 @@ using Tiobon.Core.Common.UserManager; using Tiobon.Core.IRepository.Base; using Tiobon.Core.IServices.BASE; using Tiobon.Core.Model; -using Tiobon.Core.Repository.Base; -namespace Tiobon.Core.Services.BASE +namespace Tiobon.Core.Services.BASE; + +public class BaseServices : IBaseServices where TEntity : class, new() { - public class BaseServices : IBaseServices where TEntity : class, new() + public BaseServices(IBaseRepository BaseDal = null) { - public BaseServices(IBaseRepository BaseDal = null) - { - this.BaseDal = BaseDal; - } + this.BaseDal = BaseDal; + } - //public IBaseRepository baseDal = new BaseRepository(); - public IBaseRepository BaseDal { get; set; } //通过在子类的构造函数中注入,这里是基类,不用构造函数 + //public IBaseRepository baseDal = new BaseRepository(); + public IBaseRepository BaseDal { get; set; } //通过在子类的构造函数中注入,这里是基类,不用构造函数 - public ISqlSugarClient Db => BaseDal.Db; + public ISqlSugarClient Db => BaseDal.Db; - public async Task QueryById(object objId) - { - return await BaseDal.QueryById(objId); - } + public async Task QueryById(object objId) + { + return await BaseDal.QueryById(objId); + } - /// - /// 根据ID查询一条数据 - /// - /// id(必须指定主键特性 [SugarColumn(IsPrimaryKey=true)]),如果是联合主键,请使用Where条件 - /// 是否使用缓存 - /// 数据实体 - public async Task QueryById(object objId, bool blnUseCache = false) - { - return await BaseDal.QueryById(objId, blnUseCache); - } + /// + /// 根据ID查询一条数据 + /// + /// id(必须指定主键特性 [SugarColumn(IsPrimaryKey=true)]),如果是联合主键,请使用Where条件 + /// 是否使用缓存 + /// 数据实体 + public async Task QueryById(object objId, bool blnUseCache = false) + { + return await BaseDal.QueryById(objId, blnUseCache); + } - /// - /// 根据ID查询数据 - /// - /// id列表(必须指定主键特性 [SugarColumn(IsPrimaryKey=true)]),如果是联合主键,请使用Where条件 - /// 数据实体列表 - public async Task> QueryByIDs(object[] lstIds) - { - return await BaseDal.QueryByIDs(lstIds); - } + /// + /// 根据ID查询数据 + /// + /// id列表(必须指定主键特性 [SugarColumn(IsPrimaryKey=true)]),如果是联合主键,请使用Where条件 + /// 数据实体列表 + public async Task> QueryByIDs(object[] lstIds) + { + return await BaseDal.QueryByIDs(lstIds); + } - /// - /// 写入实体数据 - /// - /// 博文实体类 - /// - public async Task Add(TEntity entity) - { - return await BaseDal.Add(entity); - } + /// + /// 写入实体数据 + /// + /// 博文实体类 + /// + public async Task Add(TEntity entity) + { + return await BaseDal.Add(entity); + } - /// - /// 批量插入实体(速度快) - /// - /// 实体集合 - /// 影响行数 - public async Task> Add(List listEntity) - { - return await BaseDal.Add(listEntity); - } + /// + /// 批量插入实体(速度快) + /// + /// 实体集合 + /// 影响行数 + public async Task> Add(List listEntity) + { + return await BaseDal.Add(listEntity); + } - /// - /// 更新实体数据 - /// - /// 博文实体类 - /// - public async Task Update(TEntity entity) - { - return await BaseDal.Update(entity); - } - /// - /// 更新实体数据 - /// - /// 博文实体类 - /// - public async Task Update(List entity) - { - return await BaseDal.Update(entity); - } + /// + /// 更新实体数据 + /// + /// 博文实体类 + /// + public async Task Update(TEntity entity) + { + return await BaseDal.Update(entity); + } + /// + /// 更新实体数据 + /// + /// 博文实体类 + /// + public async Task Update(List entity) + { + return await BaseDal.Update(entity); + } - public async Task Update(TEntity entity, string where) - { - return await BaseDal.Update(entity, where); - } + public async Task Update(TEntity entity, string where) + { + return await BaseDal.Update(entity, where); + } - public async Task Update(object operateAnonymousObjects) - { - return await BaseDal.Update(operateAnonymousObjects); - } + public async Task Update(object operateAnonymousObjects) + { + return await BaseDal.Update(operateAnonymousObjects); + } - public async Task Update(TEntity entity, List lstColumns = null, List lstIgnoreColumns = null, string where = "") - { - return await BaseDal.Update(entity, lstColumns, lstIgnoreColumns, where); - } + public async Task Update(TEntity entity, List lstColumns = null, List lstIgnoreColumns = null, string where = "") + { + return await BaseDal.Update(entity, lstColumns, lstIgnoreColumns, where); + } - /// - /// 根据实体删除一条数据 - /// - /// 博文实体类 - /// - public async Task Delete(TEntity entity) - { - return await BaseDal.Delete(entity); - } + /// + /// 根据实体删除一条数据 + /// + /// 博文实体类 + /// + public async Task Delete(TEntity entity) + { + return await BaseDal.Delete(entity); + } - /// - /// 删除指定ID的数据 - /// - /// 主键ID - /// - public async Task DeleteById(object id) - { - return await BaseDal.DeleteById(id); - } + /// + /// 删除指定ID的数据 + /// + /// 主键ID + /// + public async Task DeleteById(object id) + { + return await BaseDal.DeleteById(id); + } - /// - /// 删除指定ID集合的数据(批量删除) - /// - /// 主键ID集合 - /// - public async Task DeleteByIds(object[] ids) - { - return await BaseDal.DeleteByIds(ids); - } + /// + /// 删除指定ID集合的数据(批量删除) + /// + /// 主键ID集合 + /// + public async Task DeleteByIds(object[] ids) + { + return await BaseDal.DeleteByIds(ids); + } - /// - /// 查询所有数据 - /// - /// 数据列表 - public async Task> Query() - { - return await BaseDal.Query(); - } + /// + /// 查询所有数据 + /// + /// 数据列表 + public async Task> Query() + { + return await BaseDal.Query(); + } - /// - /// 查询数据列表 - /// - /// 条件 - /// 数据列表 - public async Task> Query(string where) - { - return await BaseDal.Query(where); - } + /// + /// 查询数据列表 + /// + /// 条件 + /// 数据列表 + public async Task> Query(string where) + { + return await BaseDal.Query(where); + } - /// - /// 查询数据列表 - /// - /// whereExpression - /// 数据列表 - public async Task> Query(Expression> whereExpression) - { - return await BaseDal.Query(whereExpression); - } + /// + /// 查询数据列表 + /// + /// whereExpression + /// 数据列表 + public async Task> Query(Expression> whereExpression) + { + return await BaseDal.Query(whereExpression); + } - /// - /// 按照特定列查询数据列表 - /// - /// - /// - /// - public async Task> Query(Expression> expression) - { - return await BaseDal.Query(expression); - } + /// + /// 按照特定列查询数据列表 + /// + /// + /// + /// + public async Task> Query(Expression> expression) + { + return await BaseDal.Query(expression); + } - /// - /// 按照特定列查询数据列表带条件排序 - /// - /// - /// 过滤条件 - /// 查询实体条件 - /// 排序条件 - /// - public async Task> Query(Expression> expression, Expression> whereExpression, string orderByFileds) - { - return await BaseDal.Query(expression, whereExpression, orderByFileds); - } + /// + /// 按照特定列查询数据列表带条件排序 + /// + /// + /// 过滤条件 + /// 查询实体条件 + /// 排序条件 + /// + public async Task> Query(Expression> expression, Expression> whereExpression, string orderByFileds) + { + return await BaseDal.Query(expression, whereExpression, orderByFileds); + } - /// - /// 查询一个列表 - /// - /// 条件表达式 - /// 排序字段,如name asc,age desc - /// 数据列表 - public async Task> Query(Expression> whereExpression, Expression> orderByExpression, bool isAsc = true) - { - return await BaseDal.Query(whereExpression, orderByExpression, isAsc); - } + /// + /// 查询一个列表 + /// + /// 条件表达式 + /// 排序字段,如name asc,age desc + /// 数据列表 + public async Task> Query(Expression> whereExpression, Expression> orderByExpression, bool isAsc = true) + { + return await BaseDal.Query(whereExpression, orderByExpression, isAsc); + } - public async Task> Query(Expression> whereExpression, string orderByFileds) - { - return await BaseDal.Query(whereExpression, orderByFileds); - } + public async Task> Query(Expression> whereExpression, string orderByFileds) + { + return await BaseDal.Query(whereExpression, orderByFileds); + } - /// - /// 查询一个列表 - /// - /// 条件 - /// 排序字段,如name asc,age desc - /// 数据列表 - public async Task> Query(string where, string orderByFileds) - { - return await BaseDal.Query(where, orderByFileds); - } + /// + /// 查询一个列表 + /// + /// 条件 + /// 排序字段,如name asc,age desc + /// 数据列表 + public async Task> Query(string where, string orderByFileds) + { + return await BaseDal.Query(where, orderByFileds); + } - /// - /// 根据sql语句查询 - /// - /// 完整的sql语句 - /// 参数 - /// 泛型集合 - public async Task> QuerySql(string sql, SugarParameter[] parameters = null) - { - return await BaseDal.QuerySql(sql, parameters); - } + /// + /// 根据sql语句查询 + /// + /// 完整的sql语句 + /// 参数 + /// 泛型集合 + public async Task> QuerySql(string sql, SugarParameter[] parameters = null) + { + return await BaseDal.QuerySql(sql, parameters); + } - /// - /// 根据sql语句查询 - /// - /// 完整的sql语句 - /// 参数 - /// DataTable - public async Task QueryTable(string sql, SugarParameter[] parameters = null) - { - return await BaseDal.QueryTable(sql, parameters); - } + /// + /// 根据sql语句查询 + /// + /// 完整的sql语句 + /// 参数 + /// DataTable + public async Task QueryTable(string sql, SugarParameter[] parameters = null) + { + return await BaseDal.QueryTable(sql, parameters); + } - /// - /// 查询前N条数据 - /// - /// 条件表达式 - /// 前N条 - /// 排序字段,如name asc,age desc - /// 数据列表 - public async Task> Query(Expression> whereExpression, int top, string orderByFileds) - { - return await BaseDal.Query(whereExpression, top, orderByFileds); - } + /// + /// 查询前N条数据 + /// + /// 条件表达式 + /// 前N条 + /// 排序字段,如name asc,age desc + /// 数据列表 + public async Task> Query(Expression> whereExpression, int top, string orderByFileds) + { + return await BaseDal.Query(whereExpression, top, orderByFileds); + } - /// - /// 查询前N条数据 - /// - /// 条件 - /// 前N条 - /// 排序字段,如name asc,age desc - /// 数据列表 - public async Task> Query(string where, int top, string orderByFileds) - { - return await BaseDal.Query(where, top, orderByFileds); - } + /// + /// 查询前N条数据 + /// + /// 条件 + /// 前N条 + /// 排序字段,如name asc,age desc + /// 数据列表 + public async Task> Query(string where, int top, string orderByFileds) + { + return await BaseDal.Query(where, top, orderByFileds); + } - /// - /// 分页查询 - /// - /// 条件表达式 - /// 页码(下标0) - /// 页大小 - /// 排序字段,如name asc,age desc - /// 数据列表 - public async Task> Query(Expression> whereExpression, int pageIndex, int pageSize, string orderByFileds) - { - return await BaseDal.Query(whereExpression, pageIndex, pageSize, orderByFileds); - } + /// + /// 分页查询 + /// + /// 条件表达式 + /// 页码(下标0) + /// 页大小 + /// 排序字段,如name asc,age desc + /// 数据列表 + public async Task> Query(Expression> whereExpression, int pageIndex, int pageSize, string orderByFileds) + { + return await BaseDal.Query(whereExpression, pageIndex, pageSize, orderByFileds); + } - /// - /// 分页查询 - /// - /// 条件 - /// 页码(下标0) - /// 页大小 - /// 排序字段,如name asc,age desc - /// 数据列表 - public async Task> Query(string where, int pageIndex, int pageSize, string orderByFileds) - { - return await BaseDal.Query(where, pageIndex, pageSize, orderByFileds); - } + /// + /// 分页查询 + /// + /// 条件 + /// 页码(下标0) + /// 页大小 + /// 排序字段,如name asc,age desc + /// 数据列表 + public async Task> Query(string where, int pageIndex, int pageSize, string orderByFileds) + { + return await BaseDal.Query(where, pageIndex, pageSize, orderByFileds); + } - public async Task> QueryPage(Expression> whereExpression, int pageIndex = 1, int pageSize = 20, string orderByFileds = null) - { - return await BaseDal.QueryPage(whereExpression, pageIndex, pageSize, orderByFileds); - } - public async Task> QueryMuch(Expression> joinExpression, Expression> selectExpression, Expression> whereLambda = null) where T : class, new() - { - return await BaseDal.QueryMuch(joinExpression, selectExpression, whereLambda); - } + public async Task> QueryPage(Expression> whereExpression, int pageIndex = 1, int pageSize = 20, string orderByFileds = null) + { + return await BaseDal.QueryPage(whereExpression, pageIndex, pageSize, orderByFileds); + } + public async Task> QueryMuch(Expression> joinExpression, Expression> selectExpression, Expression> whereLambda = null) where T : class, new() + { + return await BaseDal.QueryMuch(joinExpression, selectExpression, whereLambda); + } - public async Task> QueryPage(PaginationModel pagination) - { - var express = DynamicLinqFactory.CreateLambda(pagination.Conditions); - return await QueryPage(express, pagination.PageIndex, pagination.PageSize, pagination.OrderByFileds); - } + public async Task> QueryPage(PaginationModel pagination) + { + var express = DynamicLinqFactory.CreateLambda(pagination.Conditions); + return await QueryPage(express, pagination.PageIndex, pagination.PageSize, pagination.OrderByFileds); + } - #region 分表 + #region 分表 - public async Task> AddSplit(TEntity entity) - { - return await BaseDal.AddSplit(entity); - } + public async Task> AddSplit(TEntity entity) + { + return await BaseDal.AddSplit(entity); + } - public async Task UpdateSplit(TEntity entity, DateTime dateTime) - { - return await BaseDal.UpdateSplit(entity, dateTime); - } + public async Task UpdateSplit(TEntity entity, DateTime dateTime) + { + return await BaseDal.UpdateSplit(entity, dateTime); + } - /// - /// 根据实体删除一条数据 - /// - /// 博文实体类 - /// - public async Task DeleteSplit(TEntity entity, DateTime dateTime) - { - return await BaseDal.DeleteSplit(entity, dateTime); - } + /// + /// 根据实体删除一条数据 + /// + /// 博文实体类 + /// + public async Task DeleteSplit(TEntity entity, DateTime dateTime) + { + return await BaseDal.DeleteSplit(entity, dateTime); + } - public async Task QueryByIdSplit(object objId) - { - return await BaseDal.QueryByIdSplit(objId); - } + public async Task QueryByIdSplit(object objId) + { + return await BaseDal.QueryByIdSplit(objId); + } - public async Task> QueryPageSplit(Expression> whereExpression, DateTime beginTime, DateTime endTime, int pageIndex = 1, int pageSize = 20, string orderByFields = null) - { - return await BaseDal.QueryPageSplit(whereExpression, beginTime, endTime, pageIndex, pageSize, orderByFields); - } + public async Task> QueryPageSplit(Expression> whereExpression, DateTime beginTime, DateTime endTime, int pageIndex = 1, int pageSize = 20, string orderByFields = null) + { + return await BaseDal.QueryPageSplit(whereExpression, beginTime, endTime, pageIndex, pageSize, orderByFields); + } - #endregion + #endregion +} + + +/// +/// 增删改查基础服务 +/// +/// +/// +/// +/// +public class BaseServices : IBaseServices where TEntity : class, new() +{ + public BaseServices(IBaseRepository BaseDal = null) + { + this.BaseDal = BaseDal; } + //public IBaseRepository baseDal = new BaseRepository(); + public IBaseRepository BaseDal { get; set; } //通过在子类的构造函数中注入,这里是基类,不用构造函数 + + public ISqlSugarClient Db => BaseDal.Db; /// - /// 增删改查基础服务 + /// 根据ID查询实体数据是否存在 /// - /// - /// - /// - /// - public class BaseServices : IBaseServices where TEntity : class, new() + /// + /// + public async Task AnyAsync(object objId) { - public BaseServices(IBaseRepository BaseDal = null) - { - this.BaseDal = BaseDal; - } + var data = await BaseDal.AnyAsync(objId); + return data; + } - //public IBaseRepository baseDal = new BaseRepository(); - public IBaseRepository BaseDal { get; set; } //通过在子类的构造函数中注入,这里是基类,不用构造函数 + public async Task QueryById(object objId) + { + var data = await BaseDal.QueryById(objId); + return Mapper.Map(data).ToANew(); + } - public ISqlSugarClient Db => BaseDal.Db; + /// + /// 根据ID查询一条数据 + /// + /// id(必须指定主键特性 [SugarColumn(IsPrimaryKey=true)]),如果是联合主键,请使用Where条件 + /// 是否使用缓存 + /// 数据实体 + public async Task QueryById(object objId, bool blnUseCache = false) + { + var data = await BaseDal.QueryById(objId, blnUseCache); + return Mapper.Map(data).ToANew(); + } - /// - /// 根据ID查询实体数据是否存在 - /// - /// - /// - public async Task AnyAsync(object objId) - { - var data = await BaseDal.AnyAsync(objId); - return data; - } + /// + /// 根据ID查询数据 + /// + /// id列表(必须指定主键特性 [SugarColumn(IsPrimaryKey=true)]),如果是联合主键,请使用Where条件 + /// 数据实体列表 + public async Task> QueryByIDs(object[] lstIds) + { + var data = await BaseDal.QueryByIDs(lstIds); + return Mapper.Map(data).ToANew>(); + } - public async Task QueryById(object objId) - { - var data = await BaseDal.QueryById(objId); - return Mapper.Map(data).ToANew(); - } + /// + /// 写入实体数据 + /// + /// 实体类 + /// + public async Task Add(TInsertDto entity) + { + HttpRequest request = UserContext.Context.Request; + var api = request.Path.ObjToString().TrimEnd('/').ToLower(); + var ip = GetUserIp(UserContext.Context); - /// - /// 根据ID查询一条数据 - /// - /// id(必须指定主键特性 [SugarColumn(IsPrimaryKey=true)]),如果是联合主键,请使用Where条件 - /// 是否使用缓存 - /// 数据实体 - public async Task QueryById(object objId, bool blnUseCache = false) - { - var data = await BaseDal.QueryById(objId, blnUseCache); - return Mapper.Map(data).ToANew(); - } + var entity1 = Mapper.Map(entity).ToANew(); + BasePoco ent = entity1 as BasePoco; - /// - /// 根据ID查询数据 - /// - /// id列表(必须指定主键特性 [SugarColumn(IsPrimaryKey=true)]),如果是联合主键,请使用Where条件 - /// 数据实体列表 - public async Task> QueryByIDs(object[] lstIds) - { - var data = await BaseDal.QueryByIDs(lstIds); - return Mapper.Map(data).ToANew>(); - } + ent.CreateIP = ip; + ent.CreateProg = api; - /// - /// 写入实体数据 - /// - /// 实体类 - /// - public async Task Add(TInsertDto entity) - { - HttpRequest request = UserContext.Context.Request; - var api = request.Path.ObjToString().TrimEnd('/').ToLower(); - var ip = GetUserIp(UserContext.Context); + #region 检查是否存在相同值 + CheckOnly(entity1); + #endregion - var entity1 = Mapper.Map(entity).ToANew(); - BasePoco ent = entity1 as BasePoco; + return await BaseDal.Add(entity1); + } + /// + /// 批量插入实体(速度快) + /// + /// 实体集合 + /// 影响行数 + public async Task> Add(List listEntity) + { + var userId = UserContext.Current.User_Id; + HttpRequest request = UserContext.Context.Request; + var api = request.Path.ObjToString().TrimEnd('/').ToLower(); + var ip = GetUserIp(UserContext.Context); + var list = Mapper.Map(listEntity).ToANew>(); + list.ForEach(entity => + { + BasePoco ent = entity as BasePoco; ent.CreateIP = ip; ent.CreateProg = api; + #region 检查是否存在相同值 - CheckOnly(entity1); + CheckOnly(entity); #endregion + }); + return await BaseDal.Add(list); + } - return await BaseDal.Add(entity1); - } + /// + /// 更新实体数据 + /// + /// 博文实体类 + /// + public async Task Update(long Id, TEditDto editModel) + { + HttpRequest request = UserContext.Context.Request; + var api = request.Path.ObjToString().TrimEnd('/').ToLower(); + var ip = GetUserIp(UserContext.Context); + + if (editModel == null || !await BaseDal.AnyAsync(Id)) + return false; + + var entity = await BaseDal.QueryById(Id); + ConvertTEditDto2TEntity(editModel, entity); + BasePoco ent = entity as BasePoco; + ent.UpdateIP = ip; + ent.UpdateProg = api; + CheckOnly(entity, Id); + return await BaseDal.Update(entity); + } + public async Task Update(Dictionary editModels) + { + HttpRequest request = UserContext.Context.Request; + var api = request.Path.ObjToString().TrimEnd('/').ToLower(); + var ip = GetUserIp(UserContext.Context); - /// - /// 批量插入实体(速度快) - /// - /// 实体集合 - /// 影响行数 - public async Task> Add(List listEntity) + List entities = new List(); + foreach (var keyValuePairs in editModels) { - var userId = UserContext.Current.User_Id; - HttpRequest request = UserContext.Context.Request; - var api = request.Path.ObjToString().TrimEnd('/').ToLower(); - var ip = GetUserIp(UserContext.Context); - var list = Mapper.Map(listEntity).ToANew>(); - list.ForEach(entity => - { - BasePoco ent = entity as BasePoco; - ent.CreateIP = ip; - ent.CreateProg = api; + if (keyValuePairs.Value == null || !BaseDal.Any(keyValuePairs.Key)) + continue; + var entity = await BaseDal.QueryById(keyValuePairs.Key); - #region 检查是否存在相同值 - CheckOnly(entity); - #endregion - }); - return await BaseDal.Add(list); + ConvertTEditDto2TEntity(keyValuePairs.Value, entity); + BasePoco ent = entity as BasePoco; + ent.UpdateIP = ip; + ent.UpdateProg = api; + CheckOnly(entity, keyValuePairs.Key); + entities.Add(entity); } - /// - /// 更新实体数据 - /// - /// 博文实体类 - /// - public async Task Update(long Id, TEditDto editModel) + return await BaseDal.Update(entities); + } + /// + /// 更新实体数据 + /// + /// 博文实体类 + /// + public async Task Update(List listEntity) + { + HttpRequest request = UserContext.Context.Request; + var api = request.Path.ObjToString().TrimEnd('/').ToLower(); + var ip = GetUserIp(UserContext.Context); + listEntity.ForEach(entity => { - HttpRequest request = UserContext.Context.Request; - var api = request.Path.ObjToString().TrimEnd('/').ToLower(); - var ip = GetUserIp(UserContext.Context); - - if (editModel == null || !await BaseDal.AnyAsync(Id)) - return false; - - var entity = await BaseDal.QueryById(Id); - ConvertTEditDto2TEntity(editModel, entity); BasePoco ent = entity as BasePoco; ent.UpdateIP = ip; ent.UpdateProg = api; - CheckOnly(entity, Id); - return await BaseDal.Update(entity); - } - public async Task Update(Dictionary editModels) - { - HttpRequest request = UserContext.Context.Request; - var api = request.Path.ObjToString().TrimEnd('/').ToLower(); - var ip = GetUserIp(UserContext.Context); - - List entities = new List(); - foreach (var keyValuePairs in editModels) - { - if (keyValuePairs.Value == null || !BaseDal.Any(keyValuePairs.Key)) - continue; + }); + return await BaseDal.Update(listEntity); + } - var entity = await BaseDal.QueryById(keyValuePairs.Key); + public async Task Update(TEntity entity, string where) + { + HttpRequest request = UserContext.Context.Request; + var api = request.Path.ObjToString().TrimEnd('/').ToLower(); + var ip = GetUserIp(UserContext.Context); + BasePoco ent = entity as BasePoco; + ent.UpdateIP = ip; + ent.UpdateProg = api; + return await BaseDal.Update(entity, where); + } - ConvertTEditDto2TEntity(keyValuePairs.Value, entity); - BasePoco ent = entity as BasePoco; - ent.UpdateIP = ip; - ent.UpdateProg = api; - CheckOnly(entity, keyValuePairs.Key); - entities.Add(entity); - } + public async Task Update(object operateAnonymousObjects) + { + return await BaseDal.Update(operateAnonymousObjects); + } - return await BaseDal.Update(entities); - } - /// - /// 更新实体数据 - /// - /// 博文实体类 - /// - public async Task Update(List listEntity) - { - HttpRequest request = UserContext.Context.Request; - var api = request.Path.ObjToString().TrimEnd('/').ToLower(); - var ip = GetUserIp(UserContext.Context); - listEntity.ForEach(entity => - { - BasePoco ent = entity as BasePoco; - ent.UpdateIP = ip; - ent.UpdateProg = api; - }); - return await BaseDal.Update(listEntity); - } + public async Task Update(TEntity entity, List lstColumns = null, List lstIgnoreColumns = null, string where = "") + { + return await BaseDal.Update(entity, lstColumns, lstIgnoreColumns, where); + } - public async Task Update(TEntity entity, string where) - { - HttpRequest request = UserContext.Context.Request; - var api = request.Path.ObjToString().TrimEnd('/').ToLower(); - var ip = GetUserIp(UserContext.Context); - BasePoco ent = entity as BasePoco; - ent.UpdateIP = ip; - ent.UpdateProg = api; - return await BaseDal.Update(entity, where); - } - public async Task Update(object operateAnonymousObjects) - { - return await BaseDal.Update(operateAnonymousObjects); - } + /// + /// 根据实体删除一条数据 + /// + /// 博文实体类 + /// + public async Task Delete(TEntity entity) + { + return await BaseDal.Delete(entity); + } - public async Task Update(TEntity entity, List lstColumns = null, List lstIgnoreColumns = null, string where = "") - { - return await BaseDal.Update(entity, lstColumns, lstIgnoreColumns, where); - } + /// + /// 删除指定ID的数据 + /// + /// 主键ID + /// + public async Task DeleteById(object id) + { + return await BaseDal.DeleteById(id); + } + /// + /// 删除指定ID的数据 + /// + /// 主键ID + /// + public async Task DeleteById1(object id) + { + var entity = await BaseDal.QueryById(id); + BasePoco ent = entity as BasePoco; + ent.IsEnable = 0; + return await BaseDal.Update(entity); + } - /// - /// 根据实体删除一条数据 - /// - /// 博文实体类 - /// - public async Task Delete(TEntity entity) - { - return await BaseDal.Delete(entity); - } + /// + /// 删除指定ID集合的数据(批量删除) + /// + /// 主键ID集合 + /// + public async Task DeleteByIds(object[] ids) + { + return await BaseDal.DeleteByIds(ids); + } + /// + /// 删除指定ID集合的数据(批量删除) + /// + /// 主键ID集合 + /// + public async Task DeleteByIds1(long[] ids) + { + HttpRequest request = UserContext.Context.Request; + var api = request.Path.ObjToString().TrimEnd('/').ToLower(); + var ip = GetUserIp(UserContext.Context); - /// - /// 删除指定ID的数据 - /// - /// 主键ID - /// - public async Task DeleteById(object id) + List entities = new List(); + foreach (var id in ids) { - return await BaseDal.DeleteById(id); - } + if (id == null || !BaseDal.Any(id)) + continue; - /// - /// 删除指定ID的数据 - /// - /// 主键ID - /// - public async Task DeleteById1(object id) - { var entity = await BaseDal.QueryById(id); + BasePoco ent = entity as BasePoco; + ent.UpdateIP = ip; + ent.UpdateProg = api; ent.IsEnable = 0; - return await BaseDal.Update(entity); + entities.Add(entity); } - /// - /// 删除指定ID集合的数据(批量删除) - /// - /// 主键ID集合 - /// - public async Task DeleteByIds(object[] ids) - { - return await BaseDal.DeleteByIds(ids); - } - /// - /// 删除指定ID集合的数据(批量删除) - /// - /// 主键ID集合 - /// - public async Task DeleteByIds1(long[] ids) - { - HttpRequest request = UserContext.Context.Request; - var api = request.Path.ObjToString().TrimEnd('/').ToLower(); - var ip = GetUserIp(UserContext.Context); - - List entities = new List(); - foreach (var id in ids) - { - if (id == null || !BaseDal.Any(id)) - continue; - - var entity = await BaseDal.QueryById(id); - - BasePoco ent = entity as BasePoco; - ent.UpdateIP = ip; - ent.UpdateProg = api; - ent.IsEnable = 0; - entities.Add(entity); - } - - return await BaseDal.Update(entities); - } + return await BaseDal.Update(entities); + } - /// - /// 查询所有数据 - /// - /// 数据列表 - public async Task> Query() - { - return await BaseDal.Query(); - } + /// + /// 查询所有数据 + /// + /// 数据列表 + public async Task> Query() + { + return await BaseDal.Query(); + } - /// - /// 查询数据列表 - /// - /// 条件 - /// 数据列表 - public async Task> Query(string where) - { - return await BaseDal.Query(where); - } + /// + /// 查询数据列表 + /// + /// 条件 + /// 数据列表 + public async Task> Query(string where) + { + return await BaseDal.Query(where); + } - /// - /// 查询数据列表 - /// - /// whereExpression - /// 数据列表 - public async Task> Query(Expression> whereExpression) - { - return await BaseDal.Query(whereExpression); - } + /// + /// 查询数据列表 + /// + /// whereExpression + /// 数据列表 + public async Task> Query(Expression> whereExpression) + { + return await BaseDal.Query(whereExpression); + } - /// - /// 按照特定列查询数据列表 - /// - /// - /// - /// - public async Task> Query(Expression> expression) - { - return await BaseDal.Query(expression); - } + /// + /// 按照特定列查询数据列表 + /// + /// + /// + /// + public async Task> Query(Expression> expression) + { + return await BaseDal.Query(expression); + } - /// - /// 按照特定列查询数据列表带条件排序 - /// - /// - /// 过滤条件 - /// 查询实体条件 - /// 排序条件 - /// - public async Task> Query(Expression> expression, Expression> whereExpression, string orderByFileds) - { - return await BaseDal.Query(expression, whereExpression, orderByFileds); - } + /// + /// 按照特定列查询数据列表带条件排序 + /// + /// + /// 过滤条件 + /// 查询实体条件 + /// 排序条件 + /// + public async Task> Query(Expression> expression, Expression> whereExpression, string orderByFileds) + { + return await BaseDal.Query(expression, whereExpression, orderByFileds); + } - /// - /// 查询一个列表 - /// - /// 条件表达式 - /// 排序字段,如name asc,age desc - /// 数据列表 - public async Task> Query(Expression> whereExpression, Expression> orderByExpression, bool isAsc = true) - { - return await BaseDal.Query(whereExpression, orderByExpression, isAsc); - } + /// + /// 查询一个列表 + /// + /// 条件表达式 + /// 排序字段,如name asc,age desc + /// 数据列表 + public async Task> Query(Expression> whereExpression, Expression> orderByExpression, bool isAsc = true) + { + return await BaseDal.Query(whereExpression, orderByExpression, isAsc); + } - public async Task> Query(Expression> whereExpression, string orderByFileds) - { - return await BaseDal.Query(whereExpression, orderByFileds); - } + public async Task> Query(Expression> whereExpression, string orderByFileds) + { + return await BaseDal.Query(whereExpression, orderByFileds); + } - /// - /// 查询一个列表 - /// - /// 条件 - /// 排序字段,如name asc,age desc - /// 数据列表 - public async Task> Query(string where, string orderByFileds) - { - return await BaseDal.Query(where, orderByFileds); - } + /// + /// 查询一个列表 + /// + /// 条件 + /// 排序字段,如name asc,age desc + /// 数据列表 + public async Task> Query(string where, string orderByFileds) + { + return await BaseDal.Query(where, orderByFileds); + } - /// - /// 根据sql语句查询 - /// - /// 完整的sql语句 - /// 参数 - /// 泛型集合 - public async Task> QuerySql(string sql, SugarParameter[] parameters = null) - { - return await BaseDal.QuerySql(sql, parameters); - } + /// + /// 根据sql语句查询 + /// + /// 完整的sql语句 + /// 参数 + /// 泛型集合 + public async Task> QuerySql(string sql, SugarParameter[] parameters = null) + { + return await BaseDal.QuerySql(sql, parameters); + } - /// - /// 根据sql语句查询 - /// - /// 完整的sql语句 - /// 参数 - /// DataTable - public async Task QueryTable(string sql, SugarParameter[] parameters = null) - { - return await BaseDal.QueryTable(sql, parameters); - } + /// + /// 根据sql语句查询 + /// + /// 完整的sql语句 + /// 参数 + /// DataTable + public async Task QueryTable(string sql, SugarParameter[] parameters = null) + { + return await BaseDal.QueryTable(sql, parameters); + } - /// - /// 查询前N条数据 - /// - /// 条件表达式 - /// 前N条 - /// 排序字段,如name asc,age desc - /// 数据列表 - public async Task> Query(Expression> whereExpression, int top, string orderByFileds) - { - return await BaseDal.Query(whereExpression, top, orderByFileds); - } + /// + /// 查询前N条数据 + /// + /// 条件表达式 + /// 前N条 + /// 排序字段,如name asc,age desc + /// 数据列表 + public async Task> Query(Expression> whereExpression, int top, string orderByFileds) + { + return await BaseDal.Query(whereExpression, top, orderByFileds); + } - /// - /// 查询前N条数据 - /// - /// 条件 - /// 前N条 - /// 排序字段,如name asc,age desc - /// 数据列表 - public async Task> Query(string where, int top, string orderByFileds) - { - return await BaseDal.Query(where, top, orderByFileds); - } + /// + /// 查询前N条数据 + /// + /// 条件 + /// 前N条 + /// 排序字段,如name asc,age desc + /// 数据列表 + public async Task> Query(string where, int top, string orderByFileds) + { + return await BaseDal.Query(where, top, orderByFileds); + } - /// - /// 分页查询 - /// - /// 条件表达式 - /// 页码(下标0) - /// 页大小 - /// 排序字段,如name asc,age desc - /// 数据列表 - public async Task> Query(Expression> whereExpression, int pageIndex, int pageSize, string orderByFileds) - { - return await BaseDal.Query(whereExpression, pageIndex, pageSize, orderByFileds); - } + /// + /// 分页查询 + /// + /// 条件表达式 + /// 页码(下标0) + /// 页大小 + /// 排序字段,如name asc,age desc + /// 数据列表 + public async Task> Query(Expression> whereExpression, int pageIndex, int pageSize, string orderByFileds) + { + return await BaseDal.Query(whereExpression, pageIndex, pageSize, orderByFileds); + } - /// - /// 分页查询 - /// - /// 条件 - /// 页码(下标0) - /// 页大小 - /// 排序字段,如name asc,age desc - /// 数据列表 - public async Task> Query(string where, int pageIndex, int pageSize, string orderByFileds) - { - return await BaseDal.Query(where, pageIndex, pageSize, orderByFileds); - } + /// + /// 分页查询 + /// + /// 条件 + /// 页码(下标0) + /// 页大小 + /// 排序字段,如name asc,age desc + /// 数据列表 + public async Task> Query(string where, int pageIndex, int pageSize, string orderByFileds) + { + return await BaseDal.Query(where, pageIndex, pageSize, orderByFileds); + } - public async Task> QueryPage(Expression> whereExpression, int pageIndex = 1, int pageSize = 20, string orderByFileds = null) - { - return await BaseDal.QueryPage(whereExpression, pageIndex, pageSize, orderByFileds); - } + public async Task> QueryPage(Expression> whereExpression, int pageIndex = 1, int pageSize = 20, string orderByFileds = null) + { + return await BaseDal.QueryPage(whereExpression, pageIndex, pageSize, orderByFileds); + } - public async Task> QueryFilterPage([FromFilter] QueryFilter filter) - { - var data = await BaseDal.QueryFilterPage(filter); + public async Task> QueryFilterPage([FromFilter] QueryFilter filter) + { + var data = await BaseDal.QueryFilterPage(filter); - return new ServicePageResult(filter.PageIndex, data.TotalCount, filter.PageSize, Mapper.Map(data.Data).ToANew>()); + return new ServicePageResult(filter.PageIndex, data.TotalCount, filter.PageSize, Mapper.Map(data.Data).ToANew>()); - } + } - public async Task> QueryMuch(Expression> joinExpression, Expression> selectExpression, Expression> whereLambda = null) where T : class, new() - { - return await BaseDal.QueryMuch(joinExpression, selectExpression, whereLambda); - } + public async Task> QueryMuch(Expression> joinExpression, Expression> selectExpression, Expression> whereLambda = null) where T : class, new() + { + return await BaseDal.QueryMuch(joinExpression, selectExpression, whereLambda); + } - public async Task> QueryPage(PaginationModel pagination) - { - var express = DynamicLinqFactory.CreateLambda(pagination.Conditions); - return await QueryPage(express, pagination.PageIndex, pagination.PageSize, pagination.OrderByFileds); - } + public async Task> QueryPage(PaginationModel pagination) + { + var express = DynamicLinqFactory.CreateLambda(pagination.Conditions); + return await QueryPage(express, pagination.PageIndex, pagination.PageSize, pagination.OrderByFileds); + } - #region 分表 + #region 分表 - public async Task> AddSplit(TEntity entity) - { - return await BaseDal.AddSplit(entity); - } + public async Task> AddSplit(TEntity entity) + { + return await BaseDal.AddSplit(entity); + } - public async Task UpdateSplit(TEntity entity, DateTime dateTime) - { - return await BaseDal.UpdateSplit(entity, dateTime); - } + public async Task UpdateSplit(TEntity entity, DateTime dateTime) + { + return await BaseDal.UpdateSplit(entity, dateTime); + } - /// - /// 根据实体删除一条数据 - /// - /// 博文实体类 - /// - public async Task DeleteSplit(TEntity entity, DateTime dateTime) - { - return await BaseDal.DeleteSplit(entity, dateTime); - } + /// + /// 根据实体删除一条数据 + /// + /// 博文实体类 + /// + public async Task DeleteSplit(TEntity entity, DateTime dateTime) + { + return await BaseDal.DeleteSplit(entity, dateTime); + } - public async Task QueryByIdSplit(object objId) - { - return await BaseDal.QueryByIdSplit(objId); - } + public async Task QueryByIdSplit(object objId) + { + return await BaseDal.QueryByIdSplit(objId); + } - public async Task> QueryPageSplit(Expression> whereExpression, DateTime beginTime, DateTime endTime, int pageIndex = 1, int pageSize = 20, string orderByFields = null) - { - return await BaseDal.QueryPageSplit(whereExpression, beginTime, endTime, pageIndex, pageSize, orderByFields); - } + public async Task> QueryPageSplit(Expression> whereExpression, DateTime beginTime, DateTime endTime, int pageIndex = 1, int pageSize = 20, string orderByFields = null) + { + return await BaseDal.QueryPageSplit(whereExpression, beginTime, endTime, pageIndex, pageSize, orderByFields); + } - #endregion + #endregion - public static string GetUserIp(HttpContext context) + public static string GetUserIp(HttpContext context) + { + string realIP = null; + string forwarded = null; + string remoteIpAddress = context.Connection.RemoteIpAddress.ToString(); + if (context.Request.Headers.ContainsKey("X-Real-IP")) { - string realIP = null; - string forwarded = null; - string remoteIpAddress = context.Connection.RemoteIpAddress.ToString(); - if (context.Request.Headers.ContainsKey("X-Real-IP")) + realIP = context.Request.Headers["X-Real-IP"].ToString(); + if (realIP != remoteIpAddress) { - realIP = context.Request.Headers["X-Real-IP"].ToString(); - if (realIP != remoteIpAddress) - { - remoteIpAddress = realIP; - } + remoteIpAddress = realIP; } - if (context.Request.Headers.ContainsKey("X-Forwarded-For")) - { - forwarded = context.Request.Headers["X-Forwarded-For"].ToString(); - if (forwarded != remoteIpAddress) - { - remoteIpAddress = forwarded; - } - } - remoteIpAddress = remoteIpAddress.Replace("::ffff:", null); - return remoteIpAddress; } - - - #region 辅助方法 - /// - /// 转换TEditDto2TEntity - /// - /// - /// - /// - protected void ConvertTEditDto2TEntity(TEditDto source, TEntity dest) + if (context.Request.Headers.ContainsKey("X-Forwarded-For")) { - foreach (PropertyInfo mItem in typeof(TEditDto).GetProperties()) + forwarded = context.Request.Headers["X-Forwarded-For"].ToString(); + if (forwarded != remoteIpAddress) { - if (dest.HasField(mItem.Name)) - dest.SetValueForField(mItem.Name, mItem.GetValue(source, null)); + remoteIpAddress = forwarded; } - //dest.SetValueForField(DbConsts.ColunmName_LastModificationTime, DateTimeHelper.Now()); - //if (_currentUserId != default) - //{ - // //dest.SetValueForField(DbConsts.ColunmName_LastModifierId, _currentUserId); - // dest.SetValueForField(DbConsts.ColunmName_LastModifier, _currentUserName); - //} - - //if (_currentTenantId != null) - //{ - // dest.SetValueForField(DbConsts.ColunmName_TenantId, _currentTenantId); - //} } + remoteIpAddress = remoteIpAddress.Replace("::ffff:", null); + return remoteIpAddress; + } + + + #region 辅助方法 + /// + /// 转换TEditDto2TEntity + /// + /// + /// + /// + protected void ConvertTEditDto2TEntity(TEditDto source, TEntity dest) + { + foreach (PropertyInfo mItem in typeof(TEditDto).GetProperties()) + { + if (dest.HasField(mItem.Name)) + dest.SetValueForField(mItem.Name, mItem.GetValue(source, null)); + } + //dest.SetValueForField(DbConsts.ColunmName_LastModificationTime, DateTimeHelper.Now()); + //if (_currentUserId != default) + //{ + // //dest.SetValueForField(DbConsts.ColunmName_LastModifierId, _currentUserId); + // dest.SetValueForField(DbConsts.ColunmName_LastModifier, _currentUserName); + //} + + //if (_currentTenantId != null) + //{ + // dest.SetValueForField(DbConsts.ColunmName_TenantId, _currentTenantId); + //} + } - /// - /// 获取根据ID查询的条件 - /// - /// - /// - protected QueryFilter QueryFilterById(Guid id) + /// + /// 获取根据ID查询的条件 + /// + /// + /// + protected QueryFilter QueryFilterById(Guid id) + { + return new QueryFilter { - return new QueryFilter - { - PageIndex = 1, - PageSize = 1, - Sorting = string.Empty, - Conditions = string.Empty - }; - } + PageIndex = 1, + PageSize = 1, + Sorting = string.Empty, + Conditions = string.Empty + }; + } + + public static void CheckOnly(TEntity entity, long? id = null) + { + Type entityType = typeof(TEntity); + var tableName = entityType.GetEntityTableName(); - public static void CheckOnly(TEntity entity, long? id = null) + var names = new List(); + var values = new List(); + var descriptions = new List(); + entity.GetOnlyList(out names, out values, out descriptions); + for (int i = 0; i < names.Count; i++) { - Type entityType = typeof(TEntity); - var tableName = entityType.GetEntityTableName(); - - var names = new List(); - var values = new List(); - var descriptions = new List(); - entity.GetOnlyList(out names, out values, out descriptions); - for (int i = 0; i < names.Count; i++) - { - CheckCodeExist(tableName, names[i], values[i], id != null ? ModifyType.Edit : ModifyType.Add, descriptions[i]); - } + CheckCodeExist(tableName, names[i], values[i], id != null ? ModifyType.Edit : ModifyType.Add, descriptions[i]); } - /// - /// 检查表中是否已经存在相同代码的数据 - /// - /// 表名 - /// 字段名 - /// 字段值 - /// ModifyType.Add,ModifyType.Edit - /// ModifyType.Edit时修改记录的ROW_ID值 - /// 判断栏位的提示名称 - public static void CheckCodeExist(string tableName, string fieldName, object fieldValue, ModifyType modifyType, string promptName, long? rowid = null) + } + /// + /// 检查表中是否已经存在相同代码的数据 + /// + /// 表名 + /// 字段名 + /// 字段值 + /// ModifyType.Add,ModifyType.Edit + /// ModifyType.Edit时修改记录的ROW_ID值 + /// 判断栏位的提示名称 + public static void CheckCodeExist(string tableName, string fieldName, object fieldValue, ModifyType modifyType, string promptName, long? rowid = null) + { + try { - try - { - CheckCodeExist(tableName, fieldName, fieldValue, modifyType, rowid, promptName, null); - } - catch (Exception) - { - throw; - } + CheckCodeExist(tableName, fieldName, fieldValue, modifyType, rowid, promptName, null); } + catch (Exception) + { + throw; + } + } - /// - /// 检查表中是否已经存在相同代码的数据 - /// - /// 表名 - /// 字段名 - /// 字段值 - /// 条件 - /// ModifyType.Add,ModifyType.Edit - /// ModifyType.Edit时修改记录的ROW_ID值 - /// 判断栏位的提示名称 - /// Where后的条件,如:IS_ALCON='Y' - public static bool CheckCodeExist(string tableName, string fieldName, object fieldValue, ModifyType modifyType, long? rowid, string promptName, string whereCondition) + /// + /// 检查表中是否已经存在相同代码的数据 + /// + /// 表名 + /// 字段名 + /// 字段值 + /// 条件 + /// ModifyType.Add,ModifyType.Edit + /// ModifyType.Edit时修改记录的ROW_ID值 + /// 判断栏位的提示名称 + /// Where后的条件,如:IS_ALCON='Y' + public static bool CheckCodeExist(string tableName, string fieldName, object fieldValue, ModifyType modifyType, long? rowid, string promptName, string whereCondition) + { + try { - try + bool result = false; + if (modifyType == ModifyType.Add) { - bool result = false; - if (modifyType == ModifyType.Add) - { - string sql = string.Empty; - sql = "SELECT COUNT(*) FROM " + tableName + " WHERE " + fieldName + "='" + fieldValue + "' AND IsEnable=1"; - - if (!string.IsNullOrEmpty(whereCondition)) - sql += " AND " + whereCondition; + string sql = string.Empty; + sql = "SELECT COUNT(*) FROM " + tableName + " WHERE " + fieldName + "='" + fieldValue + "' AND IsEnable=1"; - int count = Convert.ToInt32(DbAccess.ExecuteScalar(sql)); - if (count > 0) - { - result = true; - throw new Exception(string.Format("{0}【{1}】已经存在!", promptName, fieldValue)); - } - else - result = false; + if (!string.IsNullOrEmpty(whereCondition)) + sql += " AND " + whereCondition; - } - else if (modifyType == ModifyType.Edit) + int count = Convert.ToInt32(DbAccess.ExecuteScalar(sql)); + if (count > 0) { - string sql = string.Empty; - sql = "SELECT COUNT(*) FROM " + tableName + " WHERE " + fieldName + "='" + fieldValue + "' AND IsEnable=1 AND ID!='" + rowid.Value + "'"; - - if (!string.IsNullOrEmpty(whereCondition)) - sql += " AND " + whereCondition; - - int count = Convert.ToInt32(DbAccess.ExecuteScalar(sql)); - if (count > 0) - { - result = true; - throw new Exception(string.Format("{0}【{1}】已经存在!", promptName, fieldValue)); - } - else - result = false; + result = true; + throw new Exception(string.Format("{0}【{1}】已经存在!", promptName, fieldValue)); } - return result; + else + result = false; + } - catch (Exception) + else if (modifyType == ModifyType.Edit) { - throw; + string sql = string.Empty; + sql = "SELECT COUNT(*) FROM " + tableName + " WHERE " + fieldName + "='" + fieldValue + "' AND IsEnable=1 AND ID!='" + rowid.Value + "'"; + + if (!string.IsNullOrEmpty(whereCondition)) + sql += " AND " + whereCondition; + + int count = Convert.ToInt32(DbAccess.ExecuteScalar(sql)); + if (count > 0) + { + result = true; + throw new Exception(string.Format("{0}【{1}】已经存在!", promptName, fieldValue)); + } + else + result = false; } + return result; + } + catch (Exception) + { + throw; } - - #endregion } + + #endregion } \ No newline at end of file diff --git a/Tiobon.Core.Services/CommonServices.cs b/Tiobon.Core.Services/CommonServices.cs new file mode 100644 index 00000000..f630bb9a --- /dev/null +++ b/Tiobon.Core.Services/CommonServices.cs @@ -0,0 +1,90 @@ +using System.Data; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; +using Tiobon.Core.Common; +using Tiobon.Core.Common.DB.Dapper; +using Tiobon.Core.IServices; +using Tiobon.Core.Model; +using Tiobon.Core.Services.BASE; + +namespace Tiobon.Core.Services; + +public partial class CommonServices : BaseServices>, ICommonServices +{ + IHttpContextAccessor _httpContextAccessor; + ILogger _logger; + public CommonServices(ILogger logger, IHttpContextAccessor httpContextAccessor) + { + _logger = logger; + _httpContextAccessor = httpContextAccessor; + } + #region 获取菜单 + + /// + /// 获取菜单 + /// + /// + /// + public async Task> GetMenuAsync([FromBody] MenuParam param) + { + var result = new MenuReturn(); + string sql = "SELECT MenuID, MenuType FROM Ghrs_Menu WHERE IsEnable = 1 AND MenuNo = '{0}'"; + sql = string.Format(sql, param.menuName); + DataTable dt = await DbAccess.GetDataTableAsync(sql); + + int MenuID = 0; + string MenuType = string.Empty; + if (dt.Rows.Count > 0) + { + MenuID = int.Parse(dt.Rows[0]["MenuID"].ToString()); + MenuType = dt.Rows[0]["MenuType"].ToString(); + } + + switch (MenuType) + { + case "MenuForm": + { + sql = @"SELECT MenuNo, + [dbo].[FLangKeyToValue] (MKey, {0}, MenuName) MenuName, + IconType, + MenuUrl, + [dbo].[FParaDetailNoToName] ('GHRPara', + 'MenuGroupTitle', + MenuGroupTitle, + {0}, + 1) MenuGroupTitle + FROM Ghrs_Menu + WHERE ParentmenuID ='{1}' + AND IsEnable = 1 + AND (SELECT count (1) + FROM Ghrs_UserRole + WHERE UserID = '{2}' + AND IsEnable = 1 + AND dbo.Fs_GetMenuIsCheckByRole (RoleId, MenuID, '') > 0) > + 0 + ORDER BY SortNo"; + sql = string.Format(sql, param.langId, MenuID, App.User.ID); + result.DT_SubMenu = await Db.Ado.SqlQueryAsync(sql); + + sql = @"SELECT iif (MenuColDisplayType ! = 'Tile', 'Tab', 'Tile') MenuColType + FROM Ghrs_Menu + WHERE menuID = 120"; + sql = string.Format(sql, MenuID); + result.DT_MenuColType = await Db.Ado.SqlQueryAsync(sql); + break; + } + + default: + { + break; + + } + } + + return new ServiceResult() { Success = true, Message = "查询成功", Data = result, }; + + } + #endregion + +}