采购订单添加物料功能

This commit is contained in:
陈淳
2023-01-05 19:21:48 +08:00
parent 7d578ce363
commit efbf799218
49 changed files with 518 additions and 191 deletions

View File

@@ -11,11 +11,13 @@ using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Yi.Framework.Common.Abstract;
using Yi.Framework.Interface;
using Yi.Framework.Job;
using Yi.Framework.Repository;
using Yi.Framework.Service;
using Yi.Framework.WebCore.AutoFacExtend;
using Yi.Framework.WebCore.Impl;
using Module = Autofac.Module;
namespace Yi.Framework.WebCore.AutoFacExtend
@@ -31,7 +33,7 @@ namespace Yi.Framework.WebCore.AutoFacExtend
var msg = "service.dll 丢失,请编译后重新生成。";
throw new Exception(msg);
}
return Assembly.LoadFrom(servicesDllFile); ;
return Assembly.LoadFrom(servicesDllFile); ;
}
protected override void Load(ContainerBuilder containerBuilder)
@@ -39,18 +41,18 @@ namespace Yi.Framework.WebCore.AutoFacExtend
//containerBuilder.RegisterType<DbContextFactory>().As<IDbContextFactory>().InstancePerDependency().EnableInterfaceInterceptors();
containerBuilder.RegisterType< HttpContextAccessor>().As<IHttpContextAccessor>().SingleInstance();
containerBuilder.RegisterType<HttpContextAccessor>().As<IHttpContextAccessor>().SingleInstance();
//containerBuilder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>)).InstancePerLifetimeScope();
//containerBuilder.RegisterGeneric(typeof(BaseService<>)).As(typeof(IBaseService<>)).InstancePerLifetimeScope();
///反射注入服务层及接口层
var assemblysServices = GetDll( "Yi.Framework.Service.dll");
containerBuilder.RegisterAssemblyTypes(assemblysServices)
var assemblysServices = GetDll("Yi.Framework.Service.dll");
containerBuilder.RegisterAssemblyTypes(assemblysServices).PropertiesAutowired(new AutowiredPropertySelector())
.AsImplementedInterfaces()
.InstancePerLifetimeScope()
.EnableInterfaceInterceptors();
//开启工作单元拦截
//.InterceptedBy(typeof(UnitOfWorkInterceptor));
//开启工作单元拦截
//.InterceptedBy(typeof(UnitOfWorkInterceptor));
///反射注册任务调度层
var assemblysJob = GetDll("Yi.Framework.Job.dll");
@@ -61,10 +63,6 @@ namespace Yi.Framework.WebCore.AutoFacExtend
containerBuilder.Register(c => new CustomAutofacAop());//AOP注册
//containerBuilder.RegisterType<A>().As<IA>().EnableInterfaceInterceptors();开启Aop
//将数据库对象注入
@@ -73,7 +71,6 @@ namespace Yi.Framework.WebCore.AutoFacExtend
//containerBuilder.RegisterGeneric(typeof(BaseService<>)).As(typeof(IBaseService<>)).InstancePerDependency().EnableInterfaceInterceptors();
}
}

View File

@@ -14,9 +14,11 @@ using System.Reflection;
using System.Threading.Tasks;
using Yi.Framework.Common.Attribute;
using Yi.Framework.Interface;
using Yi.Framework.Interface.Base.Crud;
using Yi.Framework.Job;
using Yi.Framework.Repository;
using Yi.Framework.Service;
using Yi.Framework.Service.Base.Crud;
using Module = Autofac.Module;
namespace Yi.Framework.WebCore.AutoFacExtend

View File

@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yi.Framework.Common.Abstract;
namespace Yi.Framework.WebCore.Impl
{
public class CurrentUser : ICurrentUser
{
public bool IsAuthenticated { get; set; }
public long Id { get; set; }
public string UserName { get; set; } = string.Empty;
public Guid? TenantId { get; set; }
public string Email { get; set; }=string.Empty;
public bool EmailVerified { get; set; }
public string PhoneNumber { get; set; } = string.Empty;
public bool PhoneNumberVerified { get; set; }
public string[]? Roles { get; set; }
public string[]? Permission { get; set; }
}
}

View File

@@ -0,0 +1,80 @@
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.IdentityModel.Tokens.Jwt;
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using Yi.Framework.Common.Abstract;
using Yi.Framework.Common.Const;
using Yi.Framework.WebCore.Impl;
namespace Yi.Framework.WebCore.MiddlewareExtend
{
public static class CurrentUserExrension
{
public static IServiceCollection AddCurrentUserServer(this IServiceCollection services)
{
return services.AddScoped<ICurrentUser, CurrentUser>();
}
public static IApplicationBuilder UseCurrentUserServer(this IApplicationBuilder app)
{
return app.UseMiddleware<CurrentUserMiddleware>();
}
}
public class CurrentUserMiddleware
{
private readonly RequestDelegate _next;
private ILogger<CurrentUserMiddleware> _logger;
public CurrentUserMiddleware(RequestDelegate next, ILogger<CurrentUserMiddleware> logger)
{
_next = next;
_logger = logger;
}
public async Task Invoke(HttpContext context, ICurrentUser _currentUser)
{
var authenticateContext = await context.AuthenticateAsync();
if (authenticateContext.Principal is null)
{
_currentUser.IsAuthenticated = false;
await _next(context);
return;
}
var claims = authenticateContext.Principal.Claims;
//通过鉴权之后,开始赋值
_currentUser.IsAuthenticated = true;
_currentUser.Id = claims.GetClaim(JwtRegisteredClaimNames.Sid) is null ? 0 : Convert.ToInt64(claims.GetClaim(JwtRegisteredClaimNames.Sid));
_currentUser.UserName = claims.GetClaim(SystemConst.UserName);
_currentUser.Permission = claims.GetClaims(SystemConst.PermissionClaim);
_currentUser.TenantId = claims.GetClaim(SystemConst.TenantId) is null ? null : Guid.Parse(claims.GetClaim(SystemConst.TenantId)!);
await _next(context);
}
}
public static class ClaimExtension
{
public static string? GetClaim(this IEnumerable<Claim> claims, string type)
{
return claims.Where(c => c.Type == type).Select(c => c.Value).FirstOrDefault();
}
public static string[]? GetClaims(this IEnumerable<Claim> claims, string type)
{
return claims.Where(c => c.Type == type).Select(c => c.Value).ToArray();
}
}
}