Seamus 8 ay önce
ebeveyn
işleme
ed170da329

+ 1 - 0
ERP.Application/Program.cs

@@ -1,4 +1,5 @@
 using ERP.Core;
+using ERP.Framework.Constants;
 
 namespace ERP
 {

+ 6 - 7
ERP.Core/Application.cs

@@ -8,7 +8,6 @@ using ERP.Framework.Config;
 using ERP.Framework.Constants;
 using ERP.Framework.Extensions;
 using ERP.Framework.Filter;
-using ERP.Framework.Orm;
 using Newtonsoft.Json;
 
 namespace ERP.Core
@@ -25,7 +24,7 @@ namespace ERP.Core
         {
             // 获取配置项
             var redisConfig = builder.Configuration.GetSection(FrameworkConstant.Redis).Get<RedisConfig>();
-            var dbConfig = builder.Configuration.GetSection(FrameworkConstant.DBConfig).Get<DBConfig>();
+            //var dbConfig = builder.Configuration.GetSection(FrameworkConstant.DBConfig).Get<DBConfig>();
 
             // 处理Id生成配置
             builder.Configuration.InitIdGenerater();
@@ -39,8 +38,8 @@ namespace ERP.Core
 
             // 缓存注册
             builder.Services.AddCache(redisConfig);
-            // SqlSugar
-            builder.Services.AddSqlSugar(dbConfig);
+            // EntityFrameworkCore
+            //builder.Services.AddSqlSugar(dbConfig);
             //  跨域
             builder.Services.AddCorsAccessor();
             // Todo 任务队列
@@ -49,7 +48,7 @@ namespace ERP.Core
             // Todo 添加MiniProfiler 性能分析
 
             // Swagger
-            builder.Services.AddSwagger();
+            //builder.Services.AddSwagger();
 
             // 校验异常拦截
             // 全局异常拦截
@@ -91,8 +90,8 @@ namespace ERP.Core
             app.UseHttpsRedirection();
             //app.UseI18N();
 
-            app.UseSwagger();
-            app.UseSwaggerUI();
+            //app.UseSwagger();
+            //app.UseSwaggerUI();
 
             app.UseRouting();
             app.UseEndpoints(endpoints =>

+ 2 - 2
ERP.Core/Controller/AuthController.cs

@@ -6,7 +6,7 @@ using ERP.Core.Emum;
 using ERP.Framework.Config;
 using ERP.Framework.Constants;
 using ERP.Framework.WebApi;
-using Swashbuckle.AspNetCore.Annotations;
+//using Swashbuckle.AspNetCore.Annotations;
 
 namespace ERP.Core.Controller
 {
@@ -23,7 +23,7 @@ namespace ERP.Core.Controller
         }
 
         [HttpPost("/login")]
-        [SwaggerOperation(Description = "登录接口", Summary = "Login")]
+        //[SwaggerOperation(Description = "登录接口", Summary = "Login")]
         public async Task<IActionResult> LoginAsync([FromBody] LoginBody form)
         {
             var securityConfig = _configuration.GetSection(FrameworkConstant.SecurityConfig).Get<SecurityConfig>() ?? new SecurityConfig();

+ 0 - 2
ERP.Core/Entity/SysRole.cs

@@ -1,12 +1,10 @@
 using ERP.Core.Enum;
 using ERP.Framework.WebApi;
-using SqlSugar;
 
 namespace ERP.Core.Entity
 {
     public class SysRole : BaseEntity
     {
-        [SugarColumn(ColumnName ="role_id")]
         public override long Id { get => base.Id; set => base.Id = value; }
 
         /// <summary>

+ 0 - 2
ERP.Core/Entity/SysUser.cs

@@ -1,12 +1,10 @@
 using ERP.Core.Enum;
 using ERP.Framework.WebApi;
-using SqlSugar;
 
 namespace ERP.Core.Entity
 {
     public class SysUser : BaseEntity
     {
-        [SugarColumn(ColumnName = "user_id")]
         public override long Id { get => base.Id; set => base.Id = value; }
 
         /// <summary>

+ 2 - 17
ERP.Core/Repository/SysUserRepository.cs

@@ -1,7 +1,6 @@
 using ERP.Core.Dto;
 using ERP.Core.Entity;
 using ERP.Framework.WebApi;
-using SqlSugar;
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -10,22 +9,8 @@ using System.Threading.Tasks;
 
 namespace ERP.Core.Repository
 {
-    public class SysUserRepository : BaseRepository<SysUser>
+    public class SysUserRepository 
     {
-        public SysUserRepository(ISqlSugarClient context) : base(context)
-        {
-        }
-
-        public Task<SysUser> SelectByUserName(string userName)
-        {
-            return GetFirstAsync(u => u.UserName == userName);
-        }
-
-        public Task<LoginUser> SelectLoginUserByUserName(string userName)
-        {
-            var q = AsQueryable()
-                .LeftJoin<SysUserRole>((u,ur)=>u.Id==ur.SysUserId)
-                .LeftJoin<SysRole>((u,ur,r)=>ur.SysRoleId==r.i);
-        }
+   
     }
 }

+ 7 - 7
ERP.Core/Service/AuthService.cs

@@ -36,16 +36,16 @@ namespace ERP.Core.Service
             , string loginName
             , string password)
         {
-            var user = await _sysUserRepository.SelectByUserName(loginName);
+            //var user = await _sysUserRepository.SelectByUserName(loginName);
 
-            if (user == null)
-            {
-                throw new Exception(string.Format(_localizer["User.NotExist"], loginName));
-            }
+            //if (user == null)
+            //{
+            //    throw new Exception(string.Format(_localizer["User.NotExist"], loginName));
+            //}
 
-            CheckUserStatus(user);
+            //CheckUserStatus(user);
 
-            CheckLogin(securityConfig, password, user);
+            //CheckLogin(securityConfig, password, user);
 
             return new LoginUser();
         }

+ 6 - 6
ERP.Core/Service/SysUserService.cs

@@ -18,14 +18,14 @@ namespace ERP.Core.Service
 
         public async Task<LoginUser> GetUserInfo(string loginName)
         {
-            var user = await SysUserRepository.SelectByUserName(loginName);
+            //var user = await SysUserRepository.SelectByUserName(loginName);
 
-            if (user == null)
-            {
-                //throw new Exception(new Status(StatusCode.Unknown, string.Format(_localizer["User.NotExist"], loginName)));
-            }
+            //if (user == null)
+            //{
+            //    //throw new Exception(new Status(StatusCode.Unknown, string.Format(_localizer["User.NotExist"], loginName)));
+            //}
 
-            CheckUserStatus(user);
+            //CheckUserStatus(user);
 
             //var roleList = SysRoleRepository.SelectRoleListByUserId(user.Id);
             //var roleKeyList = roleList.Select(t => t.RoleKey).ToList();

+ 0 - 14
ERP.Framework/Config/DBConfig.cs

@@ -1,14 +0,0 @@
-using SqlSugar;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace ERP.Framework.Config
-{
-    public class DBConfig
-    {
-        public List<ConnectionConfig> ConnectionConfigs { get; set; } = new();
-    }
-}

+ 1 - 0
ERP.Framework/ERP.Framework.csproj

@@ -24,6 +24,7 @@
     </PackageReference>
     <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
     <PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="7.0.0" />
+    <PackageReference Include="StackExchange.Redis" Version="2.8.0" />
     <PackageReference Include="Yitter.IdGenerator" Version="1.0.14" />
   </ItemGroup>
 

+ 0 - 78
ERP.Framework/Extensions/SwaggerExtension.cs

@@ -1,78 +0,0 @@
-using Microsoft.Extensions.DependencyInjection;
-using Microsoft.OpenApi.Models;
-using Swashbuckle.AspNetCore.Annotations;
-using Swashbuckle.AspNetCore.SwaggerGen;
-
-namespace ERP.Framework.Extensions
-{
-    public static class SwaggerExtension
-    {
-        /// <summary>
-        /// 注册swagger组件
-        /// </summary>
-        public static void AddSwagger(this IServiceCollection services)
-        {
-            services.AddSwaggerGen(option =>
-            {
-                option.SwaggerDoc("v1", new OpenApiInfo { Title = "ERP", Version = "v1" });
-                //option.DocumentFilter<PrefixDocumentFilter>("Seed");
-
-                //option.TagActionsBy(api => new[] { api.GroupName });
-                option.OperationFilter<SwaggerDescriptionFilter>();
-                option.OperationFilter<SwaggerSummaryFilter>();
-            });
-        }
-
-        private class PrefixDocumentFilter : IDocumentFilter
-        {
-            private readonly string _prefix;
-
-            public PrefixDocumentFilter(string prefix)
-            {
-                _prefix = prefix;
-            }
-
-            public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
-            {
-                var paths = new OpenApiPaths();
-
-                foreach (var path in swaggerDoc.Paths)
-                {
-                    paths.Add(_prefix + path.Key, path.Value);
-                }
-
-                swaggerDoc.Paths = paths;
-            }
-        }
-
-        private class SwaggerDescriptionFilter : IOperationFilter
-        {
-            public void Apply(OpenApiOperation operation, OperationFilterContext context)
-            {
-                var attribute = context.MethodInfo
-             .GetCustomAttributes(typeof(SwaggerOperationAttribute), false)
-             .FirstOrDefault() as SwaggerOperationAttribute;
-
-                if (attribute != null && !string.IsNullOrEmpty(attribute.Description))
-                {
-                    operation.Description = attribute.Description;
-                }
-            }
-        }
-
-        public class SwaggerSummaryFilter : IOperationFilter
-        {
-            public void Apply(OpenApiOperation operation, OperationFilterContext context)
-            {
-                var attribute = context.MethodInfo
-                    .GetCustomAttributes(typeof(SwaggerOperationAttribute), false)
-                    .FirstOrDefault() as SwaggerOperationAttribute;
-
-                if (attribute != null && !string.IsNullOrEmpty(attribute.Summary))
-                {
-                    operation.Summary = attribute.Summary;
-                }
-            }
-        }
-    }
-}

+ 0 - 62
ERP.Framework/Orm/SqlSugarCache.cs

@@ -1,62 +0,0 @@
-using Microsoft.Extensions.Caching.Memory;
-using SqlSugar;
-
-namespace ERP.Framework.Orm;
-
-/// <summary>
-/// SqlSugar二级缓存
-/// </summary>
-public class SqlSugarCache : ICacheService
-{
-    private readonly IMemoryCache _cache;
-    private readonly List<string> _keys;
-
-    public SqlSugarCache()
-    {
-        _cache = new MemoryCache(new MemoryCacheOptions());
-        _keys = new List<string>();
-    }
-
-    public void Add<V>(string key, V value)
-    {
-        _keys.Add(key);
-        _cache.Set(key, value);
-    }
-
-    public void Add<V>(string key, V value, int cacheDurationInSeconds)
-    {
-        _keys.Add(key);
-        _cache.Set(key, value, TimeSpan.FromSeconds(cacheDurationInSeconds));
-    }
-
-    public bool ContainsKey<V>(string key)
-    {
-        return _cache.TryGetValue<V>(key, out _);
-    }
-
-    public V Get<V>(string key)
-    {
-        return _cache.Get<V>(key);
-    }
-
-    public IEnumerable<string> GetAllKey<V>()
-    {
-        return _keys.ToList();
-    }
-
-    public V GetOrCreate<V>(string cacheKey, Func<V> create, int cacheDurationInSeconds = int.MaxValue)
-    {
-        if (!_cache.TryGetValue(cacheKey, out V value))
-        {
-            value = create();
-            _cache.Set(cacheKey, value, TimeSpan.FromSeconds(cacheDurationInSeconds));
-        }
-        return value;
-    }
-
-    public void Remove<V>(string key)
-    {
-        _keys.Remove(key);
-        _cache.Remove(key);
-    }
-}

+ 0 - 172
ERP.Framework/Orm/SqlSugarExtension.cs

@@ -1,172 +0,0 @@
-using Microsoft.AspNetCore.Http;
-using Microsoft.Extensions.DependencyInjection;
-using Microsoft.IdentityModel.Logging;
-using ERP.Framework.Config;
-using ERP.Framework.WebApi;
-using Newtonsoft.Json;
-using SqlSugar;
-using System.Reflection;
-
-namespace ERP.Framework.Orm
-{
-    public static class SqlSugarExtension
-    {
-        public static void AddSqlSugar(this IServiceCollection services, DBConfig dbConfig)
-        {
-            dbConfig.ConnectionConfigs.ForEach(SetDbConfig);
-
-            SqlSugarScope sqlSugar = new(dbConfig.ConnectionConfigs, db =>
-            {
-                dbConfig.ConnectionConfigs.ForEach(config =>
-                {
-                    var dbProvider = db.GetConnectionScope(config.ConfigId);
-                    SetDbAop(dbProvider);
-                    SetDbDiffLog(dbProvider, config);
-                });
-            });
-
-            // 单例注册
-            services.AddSingleton<ISqlSugarClient>(sqlSugar);
-        }
-
-        /// <summary>
-        /// 配置数据库连接
-        /// </summary>
-        /// <param name="config"></param>
-        private static void SetDbConfig(ConnectionConfig config)
-        {
-            var configureExternalServices = new ConfigureExternalServices
-            {
-                EntityNameService = (type, entity) =>
-                {
-                    entity.DbTableName = UtilMethods.ToUnderLine(entity.DbTableName); // 驼峰转下划线
-                },
-                EntityService = (type, column) =>
-                {
-                    if (new NullabilityInfoContext().Create(type).WriteState is NullabilityState.Nullable)
-                        column.IsNullable = true;
-
-                    if (column.DbColumnName == "ColumnName")
-                    {
-                        return;
-                    }
-
-                    column.DbColumnName = UtilMethods.ToUnderLine(column.DbColumnName); // 驼峰转下划线
-                },
-                DataInfoCacheService = new SqlSugarCache(),
-            };
-
-            config.ConfigureExternalServices = configureExternalServices;
-            config.InitKeyType = InitKeyType.Attribute;
-            config.IsAutoCloseConnection = true;
-            config.MoreSettings = new ConnMoreSettings
-            {
-                IsAutoRemoveDataCache = true,
-                IsAutoDeleteQueryFilter = true, // 启用删除查询过滤器
-                IsAutoUpdateQueryFilter = true, // 启用更新查询过滤器
-                SqlServerCodeFirstNvarchar = true // 采用Nvarchar
-            };
-        }
-
-        /// <summary>
-        /// 配置Aop
-        /// </summary>
-        /// <param name="db"></param>
-        public static void SetDbAop(SqlSugarScopeProvider db)
-        {
-            var config = db.CurrentConnectionConfig;
-
-            // 设置超时时间
-            db.Ado.CommandTimeOut = 30;
-
-            // Todo 打印SQL语句
-            db.Aop.OnLogExecuting = (sql, pars) =>
-            {
-                //NLogHelper.Info($"SQL {UtilMethods.GetSqlString(config.DbType, sql, pars)}");
-
-                // Todo 打印到MiniProfiler
-            };
-            db.Aop.OnError = ex =>
-            {
-                //NLogHelper.Error($"SQL {UtilMethods.GetSqlString(config.DbType, ex.Sql, (SugarParameter[])ex.Parametres)}");
-
-                // Todo 打印到MiniProfiler
-            };
-
-            // Todo 数据事务
-            db.Aop.DataExecuting = (oldValue, entityInfo) =>
-            {
-                if (entityInfo.OperationType == DataFilterType.InsertByObject)
-                {
-                    if (entityInfo.PropertyName == "CreateUser")
-                    {
-                        var createUser = ((dynamic)entityInfo.EntityValue).CreatedUser;
-                        if (createUser == "" || createUser == null)
-                            entityInfo.SetValue(GetUserName());
-                    }
-
-                    if (entityInfo.PropertyName == "TenantId")
-                    {
-                    }
-                }
-                if (entityInfo.OperationType == DataFilterType.UpdateByObject)
-                {
-                    if (entityInfo.PropertyName == "UpdateTime")
-                    {
-                        entityInfo.SetValue(DateTime.Now);
-                    }
-
-                    if (entityInfo.PropertyName == "UpdateUser")
-                    {
-                        entityInfo.SetValue(GetUserName());
-                    }
-                }
-            };
-
-            // Todo 配置实体假删除过滤器
-            // Todo 配置租户过滤器
-            // Todo 配置用户机构(数据范围)过滤器
-            // Todo 配置自定义过滤器
-        }
-
-        /// <summary>
-        /// Todo 开启库表差异化日志 ORM审计
-        /// </summary>
-        /// <param name="db"></param>
-        /// <param name="config"></param>
-        private static void SetDbDiffLog(SqlSugarScopeProvider db, ConnectionConfig config)
-        {
-            db.Aop.OnDiffLogEvent = async u =>
-            {
-                // 操作前记录(字段描述、列名、值、表名、表描述)
-                var b = u.BeforeData;
-                // 操作后记录(字段描述、列名、值、表名、表描述)
-                var a = u.AfterData;
-                // 传进来的对象
-                var c = u.BeforeData;
-                // insert、update、delete
-                var d = u.DiffType.ToString();
-                // sql 语句
-                var sql = UtilMethods.GetSqlString(config.DbType, u.Sql, u.Parameters);
-                // 用时
-                var elapsed = u.Time == null ? 0 : (long)u.Time.Value.TotalMilliseconds;
-
-                // todo await 插入mongDB/数据库
-            };
-        }
-
-        private static string GetUserName()
-        {
-            var httpContextAccessor = new HttpContextAccessor();
-            var httpContext = httpContextAccessor.HttpContext;
-            var userId = httpContext!.Items["UserName"] as string;
-
-            if (userId != null)
-            {
-                return userId;
-            }
-
-            return null;
-        }
-    }
-}

+ 1 - 3
ERP.Framework/WebApi/BaseEntity.cs

@@ -1,5 +1,4 @@
-using SqlSugar;
-using System;
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
@@ -19,7 +18,6 @@ namespace ERP.Framework.WebApi
         /// <summary>
         /// 主键Id
         /// </summary>
-        [SugarColumn(IsPrimaryKey = true)]
         public virtual long Id { get; set; }
 
         /// <summary>

+ 0 - 51
ERP.Framework/WebApi/BaseRepository.cs

@@ -1,51 +0,0 @@
-using SqlSugar;
-
-namespace ERP.Framework.WebApi
-{
-    public class BaseRepository<TEntity> : SimpleClient<TEntity>
-           where TEntity : class, new()
-    {
-        protected ITenant iTenant; // 多租户事务
-
-        public BaseRepository(ISqlSugarClient context) : base(context)
-        {
-            iTenant = context.AsTenant();
-
-            // todo 根据当前用户使用多租户,切库/Id隔离
-            // todo 根据多库/日志连接不同数据库
-        }
-
-        //protected List<TEntity> PaginationList(ISugarQueryable<TEntity> queryable, Pagination pagination)
-        //{
-        //    int pageTotal = 0;
-
-        //    if (!pagination.Sort.IsNullOrEmpty())
-        //    {
-        //        var orderType = OrderByType.Asc;
-
-        //        if (pagination.Order == "asc")
-        //        {
-        //            orderType = OrderByType.Asc;
-        //        }
-        //        else if (pagination.Order == "desc")
-        //        {
-        //            orderType = OrderByType.Desc;
-        //        }
-
-        //        List<OrderByModel> orderList = OrderByModel.Create(
-        //            new OrderByModel() { FieldName = UtilMethods.ToUnderLine(pagination.Sort), OrderByType = orderType }
-        //        );
-
-        //        queryable.OrderBy(orderList);
-        //    }
-
-        //    var result = queryable.ToPageList(pagination.PageNumber, pagination.PageSize, ref pageTotal);
-
-        //    pagination.Total = pageTotal;
-
-        //    return result.ToList();
-        //}
-
-        // todo 分表等操作
-    }
-}