Seamus Gu 4 months ago
parent
commit
6d3fdf8846

+ 3 - 2
ERP.Core/Application.cs

@@ -23,7 +23,7 @@ namespace ERP.Core
         public static WebApplicationBuilder InitApplication(this WebApplicationBuilder builder)
         {
             // 获取配置项
-            var redisConfig = builder.Configuration.GetSection(FrameworkConstant.Redis).Get<RedisConfig>();
+            var redisConfig = builder.Configuration.GetSection(FrameworkConstant.REDIS).Get<RedisConfig>();
             //var dbConfig = builder.Configuration.GetSection(FrameworkConstant.DBConfig).Get<DBConfig>();
 
             // 处理Id生成配置
@@ -35,7 +35,8 @@ namespace ERP.Core
             {
                 builder.InitAutofac();
             });
-
+            // 注入HttpContext 
+            builder.Services.AddHttpContextAccessor();
             // 缓存注册
             builder.Services.AddCache(redisConfig);
             // EntityFrameworkCore

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

@@ -27,7 +27,7 @@ namespace ERP.Core.Controller
         //[SwaggerOperation(Description = "登录接口", Summary = "Login")]
         public IActionResult LoginAsync([FromBody] LoginBody form)
         {
-            var securityConfig = _configuration.GetSection(FrameworkConstant.SecurityConfig).Get<SecurityConfig>() ?? new SecurityConfig();
+            var securityConfig = _configuration.GetSection(FrameworkConstant.SECURITY_CONFIG).Get<SecurityConfig>() ?? new SecurityConfig();
 
             var loginUser = _authService.GetLoginUser(securityConfig, form.LoginName, form.Password);
 

+ 2 - 1
ERP.Core/Controller/SysUserController.cs

@@ -18,12 +18,13 @@ namespace ERP.Core.Controller
         }
 
         [HttpGet]
-        public void Test()
+        public IActionResult Test()
         {
             var m = GetType().Name;
 
             var c = "";
 
+            return Success();
         }
     }
 }

+ 9 - 7
ERP.Core/CoreDbContext.cs

@@ -3,14 +3,8 @@ using ERP.Framework.WebApi;
 using Microsoft.EntityFrameworkCore;
 using Microsoft.Extensions.Configuration;
 using Microsoft.Extensions.Logging;
-using Microsoft.Extensions.Options;
 using Serilog;
-using System;
-using System.Collections.Generic;
-using System.Linq;
 using System.Reflection;
-using System.Text;
-using System.Threading.Tasks;
 
 namespace ERP.Core
 {
@@ -63,10 +57,18 @@ namespace ERP.Core
         /// <param name="modelBuilder"></param>
         protected override void OnModelCreating(ModelBuilder modelBuilder)
         {
+            modelBuilder.Entity<SysUserRole>().HasNoKey();
+            modelBuilder.Entity<SysRoleMenu>().HasNoKey();
+
             var assembly = Assembly.GetExecutingAssembly();
             // 处理配置项
             modelBuilder.ApplyConfigurationsFromAssembly(assembly);
 
+            foreach (Type type in assembly.ExportedTypes
+                .Where(t => t.IsClass && (t.BaseType == typeof(BaseEntity) || t.BaseType == typeof(TreeEntity))))
+            {
+                modelBuilder.Model.AddEntityType(type);
+            }
         }
 
         private void UseLog(DbContextOptionsBuilder optionsBuilder)
@@ -78,4 +80,4 @@ namespace ERP.Core
             }));
         }
     }
-}
+}

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

@@ -1,8 +1,10 @@
 using ERP.Core.Enum;
 using ERP.Framework.WebApi;
+using System.ComponentModel.DataAnnotations.Schema;
 
 namespace ERP.Core.Entity
 {
+    [Table("sys_role")]
     public class SysRole : BaseEntity
     {
         /// <summary>

+ 3 - 2
ERP.Core/Entity/SysRoleMenu.cs

@@ -7,16 +7,17 @@ using System.Threading.Tasks;
 
 namespace ERP.Core.Entity
 {
+    [Table("sys_role_menu")]
     public class SysRoleMenu
     {
         /// <summary>
         /// 
         /// </summary>
-        public virtual long SysRoleId { get; set; }
+        public virtual long RoleId { get; set; }
 
         /// <summary>
         /// 
         /// </summary>
-        public virtual long SysMenuId { set; get; }
+        public virtual long MenuId { set; get; }
     }
 }

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

@@ -4,6 +4,7 @@ using System.ComponentModel.DataAnnotations.Schema;
 
 namespace ERP.Core.Entity
 {
+    [Table("sys_user")]
     public class SysUser : BaseEntity
     {
         public override long Id { get => base.Id; set => base.Id = value; }

+ 2 - 4
ERP.Core/Entity/SysUserRole.cs

@@ -13,13 +13,11 @@ namespace ERP.Core.Entity
         /// <summary>
         /// 用户Id
         /// </summary>
-        [Column("user_id")]
-        public long SysUserId { get; set; }
+        public long UserId { get; set; }
 
         /// <summary>
         /// 角色Id
         /// </summary>
-        [Column("role_id")]
-        public long SysRoleId { get; set; }
+        public long RoleId { get; set; }
     }
 }

+ 2 - 2
ERP.Core/Repository/SysMenuRepository.cs

@@ -20,8 +20,8 @@ namespace ERP.Core.Repository
         public List<string> SelectPermissionsByRoleIds(List<long> roleIds)
         {
             var q = from rm in Context.Set<SysRoleMenu>()
-                    join m in Context.Set<SysMenu>() on rm.SysMenuId equals m.Id
-                    where roleIds.Contains(rm.SysRoleId)
+                    join m in Context.Set<SysMenu>() on rm.MenuId equals m.Id
+                    where roleIds.Contains(rm.RoleId)
                     select m.Permission;
 
             return q.ToList();

+ 3 - 3
ERP.Core/Repository/SysRoleRepository.cs

@@ -20,9 +20,9 @@ namespace ERP.Core.Repository
         public List<SysRole> SelectRoleListByUserId(long userId)
         {
             var q = from ur in Context.Set<SysUserRole>()
-                    join r in Context.Set<SysUser>() on ur.SysRoleId equals r.Id
-                    where ur.SysUserId.Equals(userId)
-                    select new SysRole();
+                    join r in Context.Set<SysRole>() on ur.RoleId equals r.Id
+                    where ur.UserId.Equals(userId)
+                    select r;
 
             return q.ToList();
         }

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

@@ -56,9 +56,9 @@ namespace ERP.Core.Service
             var roleKeyList = roleList.Select(t => t.RoleKey).ToList();
             var permissions = new List<string>();
 
-            if (roleList.Any(t => t.RoleKey == FrameworkConstant.Admin))
+            if (roleList.Any(t => t.RoleKey == FrameworkConstant.ADMIN))
             {
-                permissions.Add(FrameworkConstant.AdminPermission);
+                permissions.Add(FrameworkConstant.ADMIN_PERMISSION);
             }
             else
             {

+ 17 - 17
ERP.Framework/Constants/FrameworkConstant.cs

@@ -8,24 +8,24 @@ namespace ERP.Framework.Constants
 {
     public static class FrameworkConstant
     {
-        public const string Redis = "Redis";
+        public const string REDIS = "Redis";
+        public const string ADMIN = "admin";
+        public const string ADMIN_PERMISSION = "*:*:*";
+        public const string SECURITY_CONFIG = "Security";
 
 
-        public const string AppSetting = "appsettings.json";
-        public const string ServerConfig = "Server";
-        public const string Consul = "Consul";
-        public const string CommonConfigKey = "IPL.HRMS.Common";
-        public const string SqlServer_ConnectionString = "SqlServer:ConnectionString";
-        public const string DBConfig = "DBConfig";
-        public const string Admin = "admin";
-        public const string AdminPermission = "*:*:*";
-        public const string ThreadPoolSettings = "ThreadPoolSettings";
-        public const string RabbitMq = "RabbitMq";
-        public const string JWT = "JWT";
-        public const string Logging = "Logging";
-        public const string SecurityConfig = "Security";
-        public const string Whites = "Whites";
-        public const string Logger = "Logger";
-        public const string TokenPrefix = "Bearer";
+        //public const string AppSetting = "appsettings.json";
+        //public const string ServerConfig = "Server";
+        //public const string Consul = "Consul";
+        //public const string CommonConfigKey = "IPL.HRMS.Common";
+        //public const string SqlServer_ConnectionString = "SqlServer:ConnectionString";
+        //public const string DBConfig = "DBConfig";
+        //public const string ThreadPoolSettings = "ThreadPoolSettings";
+        //public const string RabbitMq = "RabbitMq";
+        //public const string JWT = "JWT";
+        //public const string Logging = "Logging";
+        //public const string Whites = "Whites";
+        //public const string Logger = "Logger";
+        //public const string TokenPrefix = "Bearer";
     }
 }