diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml
index d8e11c85..6c6c0a3b 100644
--- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml
+++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Config/SwaggerDoc.xml
@@ -953,5 +953,11 @@
+
+
+ 获取当前用户信息测试
+
+
+
diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/ERP/PurchaseController.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/ERP/PurchaseController.cs
index 5118f9f2..985c356e 100644
--- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/ERP/PurchaseController.cs
+++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/ERP/PurchaseController.cs
@@ -1,4 +1,6 @@
using Microsoft.AspNetCore.Mvc;
+using Yi.Framework.Common.Abstract;
+using Yi.Framework.Common.Attribute;
using Yi.Framework.Common.Models;
using Yi.Framework.DtoModel.ERP.Purchase;
using Yi.Framework.Interface.ERP;
diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/TestController.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/TestController.cs
index 878c3057..33e47ccd 100644
--- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/TestController.cs
+++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Controllers/TestController.cs
@@ -9,6 +9,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
+using Yi.Framework.Common.Abstract;
using Yi.Framework.Common.Attribute;
using Yi.Framework.Common.Const;
using Yi.Framework.Common.Models;
@@ -45,6 +46,9 @@ namespace Yi.Framework.ApiMicroservice.Controllers
private CacheInvoker _cacheDb;
private ILogger _logger;
ISugarUnitOfWork _unitOfWork;
+ [Autowired]
+ private ICurrentUser _currentUser { get; set; }
+
[Autowired]
public CacheInvoker CacheInvoker { get; set; }
//你可以依赖注入服务层各各接口,也可以注入其他仓储层,怎么爽怎么来!
@@ -403,5 +407,17 @@ namespace Yi.Framework.ApiMicroservice.Controllers
{
return Result.Success().SetStatus(CacheInvoker is not null);
}
+
+ ///
+ /// 获取当前用户信息测试
+ ///
+ ///
+ [HttpGet]
+ [Authorize]
+ public Result CurrentUserTest()
+ {
+ var per = _currentUser.Permission;
+ return Result.Success().SetData(per);
+ }
}
}
diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Program.cs b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Program.cs
index 52cea547..1c3c5501 100644
--- a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Program.cs
+++ b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/Program.cs
@@ -159,6 +159,10 @@ builder.Services.AddHttpContextAccessor();
#endregion
builder.Services.AddSingleton();
+#region
+//ӵǰûϢʹ
+#endregion
+builder.Services.AddCurrentUserServer();
#region
//ȫóʼֵ
@@ -222,6 +226,10 @@ app.UseAuthentication();
#endregion
app.UseAuthorization();
#region
+//ӵǰûϢʹ
+#endregion
+app.UseCurrentUserServer();
+#region
//Consulע
#endregion
app.UseConsulService();
diff --git a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db
index 6e7a4260..22b2f850 100644
Binary files a/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db and b/Yi.Framework.Net6/Yi.Framework.ApiMicroservice/yi-sqlsugar-dev.db differ
diff --git a/Yi.Framework.Net6/Yi.Framework.Common/Abstract/ICurrentUser.cs b/Yi.Framework.Net6/Yi.Framework.Common/Abstract/ICurrentUser.cs
new file mode 100644
index 00000000..582a97a1
--- /dev/null
+++ b/Yi.Framework.Net6/Yi.Framework.Common/Abstract/ICurrentUser.cs
@@ -0,0 +1,31 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Yi.Framework.Common.Abstract
+{
+ public interface ICurrentUser
+ {
+ public bool IsAuthenticated { get; set; }
+ public long Id { get; set; }
+
+ public string UserName { get; set; }
+
+ public Guid? TenantId { get; set; }
+
+ public string Email { get; set; }
+
+ public bool EmailVerified { get; set; }
+
+ public string PhoneNumber { get; set; }
+
+ public bool PhoneNumberVerified { get; set; }
+
+ public string[] Roles { get; set; }
+
+ public string[] Permission { get; set; }
+
+ }
+}
diff --git a/Yi.Framework.Net6/Yi.Framework.Common/Const/SystemConst.cs b/Yi.Framework.Net6/Yi.Framework.Common/Const/SystemConst.cs
index 1d6f695f..1cc4c6d1 100644
--- a/Yi.Framework.Net6/Yi.Framework.Common/Const/SystemConst.cs
+++ b/Yi.Framework.Net6/Yi.Framework.Common/Const/SystemConst.cs
@@ -12,5 +12,8 @@ namespace Yi.Framework.Common.Const
public const string AdminRolesCode = "admin";
public const string AdminPermissionCode = "*:*:*";
public const string PermissionClaim = "permission";
+ public const string UserName = "userName";
+ public const string DeptId = "deptId";
+ public const string TenantId = "tenantId";
}
}
diff --git a/Yi.Framework.Net6/Yi.Framework.Common/IOCOptions/AuthorizationOptions.cs b/Yi.Framework.Net6/Yi.Framework.Common/Options/AuthorizationOptions.cs
similarity index 100%
rename from Yi.Framework.Net6/Yi.Framework.Common/IOCOptions/AuthorizationOptions.cs
rename to Yi.Framework.Net6/Yi.Framework.Common/Options/AuthorizationOptions.cs
diff --git a/Yi.Framework.Net6/Yi.Framework.Common/IOCOptions/ConsulClientOption.cs b/Yi.Framework.Net6/Yi.Framework.Common/Options/ConsulClientOption.cs
similarity index 100%
rename from Yi.Framework.Net6/Yi.Framework.Common/IOCOptions/ConsulClientOption.cs
rename to Yi.Framework.Net6/Yi.Framework.Common/Options/ConsulClientOption.cs
diff --git a/Yi.Framework.Net6/Yi.Framework.Common/IOCOptions/ConsulRegisterOption.cs b/Yi.Framework.Net6/Yi.Framework.Common/Options/ConsulRegisterOption.cs
similarity index 100%
rename from Yi.Framework.Net6/Yi.Framework.Common/IOCOptions/ConsulRegisterOption.cs
rename to Yi.Framework.Net6/Yi.Framework.Common/Options/ConsulRegisterOption.cs
diff --git a/Yi.Framework.Net6/Yi.Framework.Common/IOCOptions/ElasticSearchOptions.cs b/Yi.Framework.Net6/Yi.Framework.Common/Options/ElasticSearchOptions.cs
similarity index 100%
rename from Yi.Framework.Net6/Yi.Framework.Common/IOCOptions/ElasticSearchOptions.cs
rename to Yi.Framework.Net6/Yi.Framework.Common/Options/ElasticSearchOptions.cs
diff --git a/Yi.Framework.Net6/Yi.Framework.Common/IOCOptions/JWTTokenOptions.cs b/Yi.Framework.Net6/Yi.Framework.Common/Options/JWTTokenOptions.cs
similarity index 100%
rename from Yi.Framework.Net6/Yi.Framework.Common/IOCOptions/JWTTokenOptions.cs
rename to Yi.Framework.Net6/Yi.Framework.Common/Options/JWTTokenOptions.cs
diff --git a/Yi.Framework.Net6/Yi.Framework.Common/IOCOptions/KafkaOptions.cs b/Yi.Framework.Net6/Yi.Framework.Common/Options/KafkaOptions.cs
similarity index 100%
rename from Yi.Framework.Net6/Yi.Framework.Common/IOCOptions/KafkaOptions.cs
rename to Yi.Framework.Net6/Yi.Framework.Common/Options/KafkaOptions.cs
diff --git a/Yi.Framework.Net6/Yi.Framework.Common/IOCOptions/RabbitMQOptions.cs b/Yi.Framework.Net6/Yi.Framework.Common/Options/RabbitMQOptions.cs
similarity index 100%
rename from Yi.Framework.Net6/Yi.Framework.Common/IOCOptions/RabbitMQOptions.cs
rename to Yi.Framework.Net6/Yi.Framework.Common/Options/RabbitMQOptions.cs
diff --git a/Yi.Framework.Net6/Yi.Framework.Common/IOCOptions/RedisConnOptions.cs b/Yi.Framework.Net6/Yi.Framework.Common/Options/RedisConnOptions.cs
similarity index 100%
rename from Yi.Framework.Net6/Yi.Framework.Common/IOCOptions/RedisConnOptions.cs
rename to Yi.Framework.Net6/Yi.Framework.Common/Options/RedisConnOptions.cs
diff --git a/Yi.Framework.Net6/Yi.Framework.Common/IOCOptions/SMSOptions.cs b/Yi.Framework.Net6/Yi.Framework.Common/Options/SMSOptions.cs
similarity index 100%
rename from Yi.Framework.Net6/Yi.Framework.Common/IOCOptions/SMSOptions.cs
rename to Yi.Framework.Net6/Yi.Framework.Common/Options/SMSOptions.cs
diff --git a/Yi.Framework.Net6/Yi.Framework.Common/IOCOptions/SqlConnOptions.cs b/Yi.Framework.Net6/Yi.Framework.Common/Options/SqlConnOptions.cs
similarity index 100%
rename from Yi.Framework.Net6/Yi.Framework.Common/IOCOptions/SqlConnOptions.cs
rename to Yi.Framework.Net6/Yi.Framework.Common/Options/SqlConnOptions.cs
diff --git a/Yi.Framework.Net6/Yi.Framework.Core/JwtInvoker.cs b/Yi.Framework.Net6/Yi.Framework.Core/JwtInvoker.cs
index 1f444409..58540dc0 100644
--- a/Yi.Framework.Net6/Yi.Framework.Core/JwtInvoker.cs
+++ b/Yi.Framework.Net6/Yi.Framework.Core/JwtInvoker.cs
@@ -43,8 +43,8 @@ namespace Yi.Framework.Core
claims.Add(new Claim(JwtRegisteredClaimNames.Nbf, $"{new DateTimeOffset(DateTime.Now).ToUnixTimeSeconds()}"));
claims.Add(new Claim(JwtRegisteredClaimNames.Exp, $"{new DateTimeOffset(DateTime.Now.AddMinutes(minutes)).ToUnixTimeSeconds()}"));
claims.Add(new Claim(JwtRegisteredClaimNames.Sid, user.Id.ToString()));
- claims.Add(new Claim("userName", user.UserName));
- claims.Add(new Claim("deptId", user.DeptId.ToString()));
+ claims.Add(new Claim(SystemConst.UserName, user.UserName));
+ claims.Add(new Claim(SystemConst.DeptId, user.DeptId.ToString()));
//-----------------------------以下从user的权限表中添加权限-----------------------例如:
foreach (var m in menus)
diff --git a/Yi.Framework.Net6/Yi.Framework.DTOModel/ERP/Material/MaterialCreateUpdateInput.cs b/Yi.Framework.Net6/Yi.Framework.DTOModel/ERP/Material/MaterialCreateUpdateInput.cs
index 372447b1..3ac90f21 100644
--- a/Yi.Framework.Net6/Yi.Framework.DTOModel/ERP/Material/MaterialCreateUpdateInput.cs
+++ b/Yi.Framework.Net6/Yi.Framework.DTOModel/ERP/Material/MaterialCreateUpdateInput.cs
@@ -10,9 +10,9 @@ namespace Yi.Framework.DtoModel.ERP.Material
{
public class MaterialCreateUpdateInput : EntityDto
{
- public string Code { get; set; }
- public string Name { get; set; }
- public string UnitName { get; set; }
- public string Remarks { get; set; }
+ public string? Code { get; set; }
+ public string? Name { get; set; }
+ public string? UnitName { get; set; }
+ public string? Remarks { get; set; }
}
}
diff --git a/Yi.Framework.Net6/Yi.Framework.DTOModel/ERP/PurchaseDetails/PurchaseDetailsCreateUpdateInput.cs b/Yi.Framework.Net6/Yi.Framework.DTOModel/ERP/PurchaseDetails/PurchaseDetailsCreateUpdateInput.cs
index b6782ce9..c371f87f 100644
--- a/Yi.Framework.Net6/Yi.Framework.DTOModel/ERP/PurchaseDetails/PurchaseDetailsCreateUpdateInput.cs
+++ b/Yi.Framework.Net6/Yi.Framework.DTOModel/ERP/PurchaseDetails/PurchaseDetailsCreateUpdateInput.cs
@@ -10,10 +10,12 @@ namespace Yi.Framework.DtoModel.ERP.PurchaseDetails
{
public class PurchaseDetailsCreateUpdateInput : EntityDto
{
- public string MaterialUnit { get; set; }
+ public string? MaterialUnit { get; set; }
+
+ public string? MaterialName { get; set; }
public float UnitPrice { get; set; }
public long TotalNumber { get; set; }
- public long CompleteNumber { get; set; }
- public string Remarks { get; set; }
+ public long? CompleteNumber { get; set; }
+ public string? Remarks { get; set; }
}
}
diff --git a/Yi.Framework.Net6/Yi.Framework.DTOModel/ERP/PurchaseDetails/PurchaseDetailsGetListOutput.cs b/Yi.Framework.Net6/Yi.Framework.DTOModel/ERP/PurchaseDetails/PurchaseDetailsGetListOutput.cs
index f8c1bd8a..962cbe69 100644
--- a/Yi.Framework.Net6/Yi.Framework.DTOModel/ERP/PurchaseDetails/PurchaseDetailsGetListOutput.cs
+++ b/Yi.Framework.Net6/Yi.Framework.DTOModel/ERP/PurchaseDetails/PurchaseDetailsGetListOutput.cs
@@ -9,6 +9,7 @@ namespace Yi.Framework.DtoModel.ERP.PurchaseDetails
{
public class PurchaseDetailsGetListOutput: EntityDto
{
+ public string MaterialName { get; set; }
public string MaterialUnit { get; set; }
public float UnitPrice { get; set; }
public long TotalNumber { get; set; }
diff --git a/Yi.Framework.Net6/Yi.Framework.DTOModel/ERP/Unit/UnitCreateUpdateInput.cs b/Yi.Framework.Net6/Yi.Framework.DTOModel/ERP/Unit/UnitCreateUpdateInput.cs
index c6f3452f..693925b3 100644
--- a/Yi.Framework.Net6/Yi.Framework.DTOModel/ERP/Unit/UnitCreateUpdateInput.cs
+++ b/Yi.Framework.Net6/Yi.Framework.DTOModel/ERP/Unit/UnitCreateUpdateInput.cs
@@ -10,8 +10,8 @@ namespace Yi.Framework.DtoModel.ERP.Unit
{
public class UnitCreateUpdateInput : EntityDto
{
- public string Code { get; set; }
- public string Name { get; set; }
- public string Remarks { get; set; }
+ public string? Code { get; set; }
+ public string? Name { get; set; }
+ public string? Remarks { get; set; }
}
}
diff --git a/Yi.Framework.Net6/Yi.Framework.DTOModel/ERP/Warehouse/WarehouseCreateUpdateInput.cs b/Yi.Framework.Net6/Yi.Framework.DTOModel/ERP/Warehouse/WarehouseCreateUpdateInput.cs
index 05bd02ea..07f3f49b 100644
--- a/Yi.Framework.Net6/Yi.Framework.DTOModel/ERP/Warehouse/WarehouseCreateUpdateInput.cs
+++ b/Yi.Framework.Net6/Yi.Framework.DTOModel/ERP/Warehouse/WarehouseCreateUpdateInput.cs
@@ -11,9 +11,9 @@ namespace Yi.Framework.DtoModel.ERP.Warehouse
{
public class WarehouseCreateUpdateInput : EntityDto
{
- public string Code { get; set; }
- public string Name { get; set; }
- public string Remarks { get; set; }
- public StateEnum State { get; set; }
+ public string? Code { get; set; }
+ public string? Name { get; set; }
+ public string? Remarks { get; set; }
+ public StateEnum? State { get; set; }
}
}
diff --git a/Yi.Framework.Net6/Yi.Framework.DtoModel/ERP/Supplier/SupplierCreateUpdateInput.cs b/Yi.Framework.Net6/Yi.Framework.DtoModel/ERP/Supplier/SupplierCreateUpdateInput.cs
index abbac95e..482804ad 100644
--- a/Yi.Framework.Net6/Yi.Framework.DtoModel/ERP/Supplier/SupplierCreateUpdateInput.cs
+++ b/Yi.Framework.Net6/Yi.Framework.DtoModel/ERP/Supplier/SupplierCreateUpdateInput.cs
@@ -13,29 +13,29 @@ namespace Yi.Framework.DtoModel.ERP.Supplier
///
/// 供应商编码
///
- public string Code { get; set; }
+ public string? Code { get; set; }
///
/// 供应商名称
///
- public string Name { get; set; }
+ public string? Name { get; set; }
///
/// 供应商地址
///
- public string Address { get; set; }
+ public string? Address { get; set; }
///
/// 电话
///
- public long Phone { get; set; }
+ public long? Phone { get; set; }
///
/// 传真
///
- public string Fax { get; set; }
+ public string? Fax { get; set; }
///
/// 邮箱
///
- public string Email { get; set; }
+ public string? Email { get; set; }
}
}
diff --git a/Yi.Framework.Net6/Yi.Framework.Interface/Base/Crud/ICreateAppService.cs b/Yi.Framework.Net6/Yi.Framework.Interface/Base/Crud/ICreateAppService.cs
index 88f10f0a..3f1c80dc 100644
--- a/Yi.Framework.Net6/Yi.Framework.Interface/Base/Crud/ICreateAppService.cs
+++ b/Yi.Framework.Net6/Yi.Framework.Interface/Base/Crud/ICreateAppService.cs
@@ -6,15 +6,13 @@ using System.Threading.Tasks;
namespace Yi.Framework.Interface.Base.Crud
{
- public interface ICreateAppService
- : ICreateAppService
+ public interface ICreateAppService: ICreateAppService
{
}
- public interface ICreateAppService : IApplicationService
+ public interface ICreateAppService : IApplicationService
{
Task CreateAsync(TCreateInputDto dto);
diff --git a/Yi.Framework.Net6/Yi.Framework.Interface/Base/Crud/ICrudAppService.cs b/Yi.Framework.Net6/Yi.Framework.Interface/Base/Crud/ICrudAppService.cs
index 78634aca..a32fb218 100644
--- a/Yi.Framework.Net6/Yi.Framework.Interface/Base/Crud/ICrudAppService.cs
+++ b/Yi.Framework.Net6/Yi.Framework.Interface/Base/Crud/ICrudAppService.cs
@@ -12,21 +12,21 @@ namespace Yi.Framework.Interface.Base.Crud
}
- public interface ICrudAppService
- : ICrudAppService
+ public interface ICrudAppService
+ : ICrudAppService
{
}
- public interface ICrudAppService
- : ICrudAppService
+ public interface ICrudAppService
+ : ICrudAppService
{
}
- public interface ICrudAppService
- : IReadOnlyAppService,
- ICreateUpdateAppService,
+ public interface ICrudAppService
+ : IReadOnlyAppService,
+ ICreateUpdateAppService,
IDeleteAppService
{
diff --git a/Yi.Framework.Net6/Yi.Framework.Model/ERP/Entitys/PurchaseDetailsEntity.cs b/Yi.Framework.Net6/Yi.Framework.Model/ERP/Entitys/PurchaseDetailsEntity.cs
index d893a431..537cc4e3 100644
--- a/Yi.Framework.Net6/Yi.Framework.Model/ERP/Entitys/PurchaseDetailsEntity.cs
+++ b/Yi.Framework.Net6/Yi.Framework.Model/ERP/Entitys/PurchaseDetailsEntity.cs
@@ -37,6 +37,12 @@ namespace Yi.Framework.Model.ERP.Entitys
///
public long MaterialId { get; set; }
+
+ ///
+ /// 物料名称
+ ///
+ public string MaterialName { get; set; }
+
///
/// 物料单位
///
diff --git a/Yi.Framework.Net6/Yi.Framework.Service/Base/Crud/AbstractKeyCrudAppService.cs b/Yi.Framework.Net6/Yi.Framework.Service/Base/Crud/AbstractKeyCrudAppService.cs
index 61c376a4..754218ac 100644
--- a/Yi.Framework.Net6/Yi.Framework.Service/Base/Crud/AbstractKeyCrudAppService.cs
+++ b/Yi.Framework.Net6/Yi.Framework.Service/Base/Crud/AbstractKeyCrudAppService.cs
@@ -14,28 +14,18 @@ namespace Yi.Framework.Service.Base.Crud
: AbstractKeyCrudAppService
where TEntity : class, IEntity, new()
{
- protected AbstractKeyCrudAppService(IRepository repository, IMapper mapper) : base(repository, mapper)
- {
- }
}
public abstract class AbstractKeyCrudAppService
: AbstractKeyCrudAppService
where TEntity : class, IEntity, new()
{
- protected AbstractKeyCrudAppService(IRepository repository, IMapper mapper) : base(repository, mapper)
- {
- }
}
- public abstract class AbstractKeyCrudAppService
- : AbstractKeyCrudAppService
+ public abstract class AbstractKeyCrudAppService
+ : AbstractKeyCrudAppService
where TEntity : class, IEntity, new()
{
- protected AbstractKeyCrudAppService(IRepository repository, IMapper mapper) : base(repository, mapper)
- {
- }
-
protected override Task MapToGetListOutputDtoAsync(TEntity entity)
{
return MapToGetOutputDtoAsync(entity);
@@ -47,23 +37,20 @@ namespace Yi.Framework.Service.Base.Crud
}
}
- public abstract class AbstractKeyCrudAppService
- : AbstractKeyReadOnlyAppService,
- ICrudAppService
+ public abstract class AbstractKeyCrudAppService
+ : AbstractKeyReadOnlyAppService,
+ ICrudAppService
where TEntity : class, IEntity, new()
{
- protected AbstractKeyCrudAppService(IRepository repository, IMapper mapper) : base(repository, mapper)
- {
- }
///
/// 创建
///
///
///
- public virtual async Task CreateAsync(TCreateInput input)
+ public virtual async Task CreateAsync(TCreateInputDto input)
{
-
+
var entity = await MapToEntityAsync(input);
TryToSetTenantId(entity);
@@ -76,7 +63,7 @@ namespace Yi.Framework.Service.Base.Crud
}
- public async virtual Task CreateAsync(IEnumerable dtos)
+ public async virtual Task CreateAsync(IEnumerable dtos)
{
var entity = await MapToEntitysAsync(dtos);
@@ -105,7 +92,7 @@ namespace Yi.Framework.Service.Base.Crud
///
///
///
- public virtual async Task UpdateAsync(TKey id, TUpdateInput input)
+ public virtual async Task UpdateAsync(TKey id, TUpdateInputDto input)
{
var entity = await GetEntityByIdAsync(id);
@@ -123,31 +110,30 @@ namespace Yi.Framework.Service.Base.Crud
///
///
///
- protected virtual Task UpdateValidAsync(TEntity idEntity, TUpdateInput dto)
+ protected virtual Task UpdateValidAsync(TEntity idEntity, TUpdateInputDto dto)
{
return Task.CompletedTask;
}
///
- /// 将 更新输入dto转化为实体的异步
+ /// 将 批量更新输入dto转化为实体的同步方法
///
///
- ///
- protected virtual Task MapToEntityAsync(TUpdateInput updateInput, TEntity entity)
+ ///
+ protected virtual List MapToEntity(IEnumerable updateInput)
{
- MapToEntity(updateInput, entity);
- return Task.CompletedTask;
+ return ObjectMapper.Map>(updateInput);
}
+
///
/// 将 批量更新输入dto转化为实体的异步
///
///
///
- protected virtual async Task> MapToEntitysAsync(IEnumerable updateInput)
+ protected virtual async Task> MapToEntitysAsync(IEnumerable updateInput)
{
- List entitys = MapToEntitys(updateInput);
-
+ List entitys = MapToEntity(updateInput);
return await Task.FromResult(entitys);
}
@@ -156,28 +142,28 @@ namespace Yi.Framework.Service.Base.Crud
///
///
///
- protected virtual void MapToEntity(TUpdateInput updateInput, TEntity entity)
+ protected virtual void MapToEntity(TUpdateInputDto updateInput, TEntity entity)
{
ObjectMapper.Map(updateInput, entity);
}
+
///
- /// 将 批量更新输入dto转化为实体的同步方法
+ /// 将 更新输入dto转化为实体的异步
///
///
- ///
- protected virtual List MapToEntitys(IEnumerable updateInput)
+ ///
+ protected virtual Task MapToEntityAsync(TUpdateInputDto updateInput, TEntity entity)
{
- return ObjectMapper.Map>(updateInput);
+ MapToEntity(updateInput, entity);
+ return Task.CompletedTask;
}
-
-
///
/// 创建dto 给 实体的转换的异步方法
///
///
///
- protected virtual Task MapToEntityAsync(TCreateInput createInput)
+ protected virtual Task MapToEntityAsync(TCreateInputDto createInput)
{
return Task.FromResult(MapToEntity(createInput));
}
@@ -187,9 +173,9 @@ namespace Yi.Framework.Service.Base.Crud
///
///
///
- protected virtual TEntity MapToEntity(TCreateInput createInput)
+ protected virtual TEntity MapToEntity(TCreateInputDto createInput)
{
- var entity = ObjectMapper.Map(createInput);
+ var entity = ObjectMapper.Map(createInput);
SetIdForGuids(entity);
return entity;
}
diff --git a/Yi.Framework.Net6/Yi.Framework.Service/Base/Crud/AbstractKeyReadOnlyAppService.cs b/Yi.Framework.Net6/Yi.Framework.Service/Base/Crud/AbstractKeyReadOnlyAppService.cs
index b97b0cfb..852eec53 100644
--- a/Yi.Framework.Net6/Yi.Framework.Service/Base/Crud/AbstractKeyReadOnlyAppService.cs
+++ b/Yi.Framework.Net6/Yi.Framework.Service/Base/Crud/AbstractKeyReadOnlyAppService.cs
@@ -7,6 +7,9 @@ using System.Linq.Expressions;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;
+using Yi.Framework.Common.Attribute;
+using Yi.Framework.Common.Enum;
+using Yi.Framework.Common.Exceptions;
using Yi.Framework.Interface.Base.Crud;
using Yi.Framework.Model.Base;
using Yi.Framework.Repository;
@@ -17,9 +20,6 @@ namespace Yi.Framework.Service.Base.Crud
: AbstractKeyReadOnlyAppService
where TEntity : class, IEntity, new()
{
- protected AbstractKeyReadOnlyAppService(IRepository repository, IMapper mapper) : base(repository, mapper)
- {
- }
}
@@ -27,13 +27,8 @@ namespace Yi.Framework.Service.Base.Crud
IReadOnlyAppService
where TEntity : class, IEntity, new()
{
-
- public AbstractKeyReadOnlyAppService(IRepository repository, IMapper mapper) : base(mapper)
- {
- Repository = repository;
-
- }
- protected IRepository Repository { get; set; }
+ [Autowired]
+ public IRepository Repository { get; set; }
public async Task> GetListAsync()
@@ -46,6 +41,10 @@ namespace Yi.Framework.Service.Base.Crud
public async Task GetByIdAsync(TKey id)
{
var entity = await GetEntityByIdAsync(id);
+ if (entity is null)
+ {
+ throw new UserFriendlyException($"主键:{id} 数据不存在",ResultCodeEnum.NotSuccess);
+ }
var entityDto = await MapToGetOutputDtoAsync(entity);
return entityDto;
@@ -92,6 +91,24 @@ namespace Yi.Framework.Service.Base.Crud
return dtos;
}
+
+ ///
+ /// 多个实体列表映射GetList输出dto列表的同步方法
+ ///
+ ///
+ ///
+ protected virtual async Task> MapToGetListOutputDtos(IEnumerable entities)
+ {
+ var dtos = new List();
+
+ foreach (var entity in entities)
+ {
+ dtos.Add(await MapToGetListOutputDtoAsync(entity));
+ }
+
+ return dtos;
+ }
+
///
/// 实体列表映射GetList输出dto的异步方法
///
diff --git a/Yi.Framework.Net6/Yi.Framework.Service/Base/Crud/ApplicationService.cs b/Yi.Framework.Net6/Yi.Framework.Service/Base/Crud/ApplicationService.cs
index 1c5618e9..d4f63d2c 100644
--- a/Yi.Framework.Net6/Yi.Framework.Service/Base/Crud/ApplicationService.cs
+++ b/Yi.Framework.Net6/Yi.Framework.Service/Base/Crud/ApplicationService.cs
@@ -1,16 +1,16 @@
using AutoMapper;
using AutoMapper.Internal.Mappers;
using Microsoft.Extensions.DependencyInjection;
+using System;
+using Yi.Framework.Common.Attribute;
using Yi.Framework.Interface.Base.Crud;
namespace Yi.Framework.Service.Base.Crud
{
public class ApplicationService : IApplicationService
{
- public ApplicationService(IMapper mapper)
- {
- ObjectMapper = mapper;
- }
- protected IMapper ObjectMapper { get; set; }
+ [Autowired]
+ public IServiceProvider ServiceProvider { get; set; }
+ protected IMapper ObjectMapper => ServiceProvider.GetRequiredService();
}
}
\ No newline at end of file
diff --git a/Yi.Framework.Net6/Yi.Framework.Service/Base/Crud/CrudAppService.cs b/Yi.Framework.Net6/Yi.Framework.Service/Base/Crud/CrudAppService.cs
index 4ebc7c02..5af6b50f 100644
--- a/Yi.Framework.Net6/Yi.Framework.Service/Base/Crud/CrudAppService.cs
+++ b/Yi.Framework.Net6/Yi.Framework.Service/Base/Crud/CrudAppService.cs
@@ -14,28 +14,17 @@ namespace Yi.Framework.Service.Base.Crud
: CrudAppService
where TEntity : class, IEntity, new()
{
- protected CrudAppService(IRepository repository, IMapper mapper) : base(repository, mapper)
- {
- }
}
- public abstract class CrudAppService
- : CrudAppService
+ public abstract class CrudAppService
+ : CrudAppService
where TEntity : class, IEntity, new()
{
- protected CrudAppService(IRepository repository, IMapper mapper) : base(repository, mapper)
- {
- }
}
- public abstract class CrudAppService
- : CrudAppService
+ public abstract class CrudAppService: CrudAppService
where TEntity : class, IEntity, new()
{
- protected CrudAppService(IRepository repository, IMapper mapper) : base(repository, mapper)
- {
- }
-
protected override Task MapToGetListOutputDtoAsync(TEntity entity)
{
return MapToGetOutputDtoAsync(entity);
@@ -47,14 +36,10 @@ namespace Yi.Framework.Service.Base.Crud
}
}
- public abstract class CrudAppService
- : AbstractKeyCrudAppService
+ public abstract class CrudAppService
+ : AbstractKeyCrudAppService
where TEntity : class, IEntity, new()
{
- protected CrudAppService(IRepository repository, IMapper mapper) : base(repository, mapper)
- {
- }
-
protected override async Task DeleteByIdAsync(TKey id)
{
await DeleteAsync(new List { id });
@@ -65,7 +50,7 @@ namespace Yi.Framework.Service.Base.Crud
return await Repository.GetByIdAsync(id);
}
- protected override void MapToEntity(TUpdateInput updateInput, TEntity entity)
+ protected override void MapToEntity(TUpdateInputDto updateInput, TEntity entity)
{
if (updateInput is IEntityDto entityDto)
{
diff --git a/Yi.Framework.Net6/Yi.Framework.Service/Base/Crud/ReadOnlyAppService.cs b/Yi.Framework.Net6/Yi.Framework.Service/Base/Crud/ReadOnlyAppService.cs
index cf2c6782..abc74e93 100644
--- a/Yi.Framework.Net6/Yi.Framework.Service/Base/Crud/ReadOnlyAppService.cs
+++ b/Yi.Framework.Net6/Yi.Framework.Service/Base/Crud/ReadOnlyAppService.cs
@@ -14,10 +14,6 @@ namespace Yi.Framework.Service.Base.Crud
: AbstractKeyReadOnlyAppService
where TEntity : class, IEntity, new()
{
- protected ReadOnlyAppService(IRepository repository, IMapper mapper) : base(repository, mapper)
- {
- }
-
protected override async Task GetEntityByIdAsync(TKey id)
{
return await Repository.GetByIdAsync(id);
diff --git a/Yi.Framework.Net6/Yi.Framework.Service/ERP/MaterialService.cs b/Yi.Framework.Net6/Yi.Framework.Service/ERP/MaterialService.cs
index a677be40..b98b8dad 100644
--- a/Yi.Framework.Net6/Yi.Framework.Service/ERP/MaterialService.cs
+++ b/Yi.Framework.Net6/Yi.Framework.Service/ERP/MaterialService.cs
@@ -16,9 +16,6 @@ namespace Yi.Framework.Service.ERP
{
public class MaterialService : CrudAppService, IMaterialService
{
- public MaterialService(IRepository repository, IMapper mapper) : base(repository, mapper)
- {
- }
public async Task>> PageListAsync(MaterialCreateUpdateInput input, PageParModel page)
{
RefAsync totalNumber = 0;
diff --git a/Yi.Framework.Net6/Yi.Framework.Service/ERP/PurchaseDetailsService.cs b/Yi.Framework.Net6/Yi.Framework.Service/ERP/PurchaseDetailsService.cs
index 2bbe84f7..ee51382b 100644
--- a/Yi.Framework.Net6/Yi.Framework.Service/ERP/PurchaseDetailsService.cs
+++ b/Yi.Framework.Net6/Yi.Framework.Service/ERP/PurchaseDetailsService.cs
@@ -16,9 +16,6 @@ namespace Yi.Framework.Service.ERP
{
public class PurchaseDetailsService : CrudAppService, IPurchaseDetailsService
{
- public PurchaseDetailsService(IRepository repository, IMapper mapper) : base(repository, mapper)
- {
- }
public async Task>> PageListAsync(PurchaseDetailsCreateUpdateInput input, PageParModel page)
{
RefAsync totalNumber = 0;
diff --git a/Yi.Framework.Net6/Yi.Framework.Service/ERP/PurchaseService.cs b/Yi.Framework.Net6/Yi.Framework.Service/ERP/PurchaseService.cs
index d976746a..be10575f 100644
--- a/Yi.Framework.Net6/Yi.Framework.Service/ERP/PurchaseService.cs
+++ b/Yi.Framework.Net6/Yi.Framework.Service/ERP/PurchaseService.cs
@@ -5,9 +5,11 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
+using Yi.Framework.Common.Attribute;
using Yi.Framework.Common.Models;
using Yi.Framework.DtoModel.ERP.Purchase;
using Yi.Framework.Interface.ERP;
+using Yi.Framework.Model.Base;
using Yi.Framework.Model.ERP.Entitys;
using Yi.Framework.Repository;
using Yi.Framework.Service.Base.Crud;
@@ -16,10 +18,10 @@ namespace Yi.Framework.Service.ERP
{
public class PurchaseService : CrudAppService, IPurchaseService
{
- private readonly ISugarUnitOfWork _unitOfWork;
+ private ISugarUnitOfWork _unitOfWork;
private readonly IPurchaseDetailsService _purchaseDetailsService;
- public PurchaseService(IRepository repository, IMapper mapper, ISugarUnitOfWork unitOfWork,
- IPurchaseDetailsService purchaseDetailsService) : base(repository, mapper)
+ public PurchaseService(ISugarUnitOfWork unitOfWork,
+ IPurchaseDetailsService purchaseDetailsService)
{
_unitOfWork = unitOfWork;
_purchaseDetailsService = purchaseDetailsService;
@@ -36,20 +38,20 @@ namespace Yi.Framework.Service.ERP
public override async Task CreateAsync(PurchaseCreateInput input)
{
-
+ PurchaseEntity entity = null;
using (var uow = _unitOfWork.CreateContext())
{
- var entity = await MapToEntityAsync(input);
+ entity = await MapToEntityAsync(input);
entity.PaidMoney = 0;
entity.TotalMoney = input.PurchaseDetails.Sum(u => u.UnitPrice * u.TotalNumber);
entity.PurchaseState = PurchaseStateEnum.Build;
TryToSetTenantId(entity);
var purchaseId = await Repository.InsertReturnSnowflakeIdAsync(entity);
-
+ entity.Id = purchaseId;
await _purchaseDetailsService.CreateAsync(input.PurchaseDetails);
+ uow.Commit();
}
-
- return null;
+ return await MapToGetListOutputDtoAsync(entity); ;
}
}
}
diff --git a/Yi.Framework.Net6/Yi.Framework.Service/ERP/SupplierService.cs b/Yi.Framework.Net6/Yi.Framework.Service/ERP/SupplierService.cs
index 1f9cd40e..d39a73cc 100644
--- a/Yi.Framework.Net6/Yi.Framework.Service/ERP/SupplierService.cs
+++ b/Yi.Framework.Net6/Yi.Framework.Service/ERP/SupplierService.cs
@@ -16,9 +16,6 @@ namespace Yi.Framework.Service.ERP
{
public class SupplierService : CrudAppService, ISupplierService
{
- public SupplierService(IRepository repository, IMapper mapper) : base(repository, mapper)
- {
- }
public async Task>> PageListAsync(SupplierCreateUpdateInput input, PageParModel page)
{
RefAsync totalNumber = 0;
diff --git a/Yi.Framework.Net6/Yi.Framework.Service/ERP/UnitService.cs b/Yi.Framework.Net6/Yi.Framework.Service/ERP/UnitService.cs
index bb850287..188d0e9d 100644
--- a/Yi.Framework.Net6/Yi.Framework.Service/ERP/UnitService.cs
+++ b/Yi.Framework.Net6/Yi.Framework.Service/ERP/UnitService.cs
@@ -16,9 +16,6 @@ namespace Yi.Framework.Service.ERP
{
public class UnitService : CrudAppService, IUnitService
{
- public UnitService(IRepository repository, IMapper mapper) : base(repository, mapper)
- {
- }
public async Task>> PageListAsync(UnitCreateUpdateInput input, PageParModel page)
{
RefAsync totalNumber = 0;
diff --git a/Yi.Framework.Net6/Yi.Framework.Service/ERP/WarehouseService.cs b/Yi.Framework.Net6/Yi.Framework.Service/ERP/WarehouseService.cs
index 7159a201..75486731 100644
--- a/Yi.Framework.Net6/Yi.Framework.Service/ERP/WarehouseService.cs
+++ b/Yi.Framework.Net6/Yi.Framework.Service/ERP/WarehouseService.cs
@@ -16,9 +16,6 @@ namespace Yi.Framework.Service.ERP
{
public class WarehouseService : CrudAppService, IWarehouseService
{
- public WarehouseService(IRepository repository, IMapper mapper) : base(repository, mapper)
- {
- }
public async Task>> PageListAsync(WarehouseCreateUpdateInput input, PageParModel page)
{
RefAsync totalNumber = 0;
diff --git a/Yi.Framework.Net6/Yi.Framework.Service/RABC/StudentService.cs b/Yi.Framework.Net6/Yi.Framework.Service/RABC/StudentService.cs
index 009ea0d3..a441f5e6 100644
--- a/Yi.Framework.Net6/Yi.Framework.Service/RABC/StudentService.cs
+++ b/Yi.Framework.Net6/Yi.Framework.Service/RABC/StudentService.cs
@@ -14,10 +14,6 @@ namespace Yi.Framework.Service.RABC
{
public class StudentService : CrudAppService, IStudentService
{
- public StudentService(IRepository repository, IMapper mapper) : base(repository, mapper)
- {
- }
-
public async Task> GetListAsync()
{
return await MapToGetListOutputDtosAsync(await Repository.GetListAsync());
diff --git a/Yi.Framework.Net6/Yi.Framework.Template/Program.cs b/Yi.Framework.Net6/Yi.Framework.Template/Program.cs
index f4580ffc..156ae451 100644
--- a/Yi.Framework.Net6/Yi.Framework.Template/Program.cs
+++ b/Yi.Framework.Net6/Yi.Framework.Template/Program.cs
@@ -17,6 +17,7 @@ foreach (var entityName in entityNames)
option.Add(new IServceTemplateProvider(modelName, entityName));
option.Add(new CreateUpdateInputTemplateProvider(modelName, entityName));
option.Add(new GetListOutputTemplateProvider(modelName, entityName));
+ option.Add(new GetListInputTemplateProvider(modelName, entityName));
option.Add(new ConstTemplateProvider(modelName, entityName));
option.Add(new ProfileTemplateProvider(modelName, entityName));
option.Add(new ControllerTemplateProvider(modelName, entityName));
diff --git a/Yi.Framework.Net6/Yi.Framework.Template/Provider/Server/GetListInputTemplateProvider.cs b/Yi.Framework.Net6/Yi.Framework.Template/Provider/Server/GetListInputTemplateProvider.cs
new file mode 100644
index 00000000..7217bc2e
--- /dev/null
+++ b/Yi.Framework.Net6/Yi.Framework.Template/Provider/Server/GetListInputTemplateProvider.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Yi.Framework.Template.Abstract;
+using Yi.Framework.Template.Const;
+
+namespace Yi.Framework.Template.Provider.Server
+{
+ public class GetListInputTemplateProvider : ModelTemplateProvider
+ {
+ public GetListInputTemplateProvider(string modelName, string entityName) : base(modelName, entityName)
+ {
+ BuildPath = $@"..\..\..\..\Yi.Framework.DtoModel\{TemplateConst.ModelName}\{TemplateConst.EntityName}\{TemplateConst.EntityName}GetListInput.cs";
+ TemplatePath = $@"..\..\..\Template\Server\GetListInputTemplate.txt";
+ EntityPath = $@"..\..\..\..\Yi.Framework.Model\{TemplateConst.ModelName}\Entitys\{TemplateConst.EntityName}Entity.cs";
+ }
+ }
+}
diff --git a/Yi.Framework.Net6/Yi.Framework.Template/Template/Server/GetListInputTemplate.txt b/Yi.Framework.Net6/Yi.Framework.Template/Template/Server/GetListInputTemplate.txt
new file mode 100644
index 00000000..d55956e8
--- /dev/null
+++ b/Yi.Framework.Net6/Yi.Framework.Template/Template/Server/GetListInputTemplate.txt
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Yi.Framework.Model.Base;
+
+namespace Yi.Framework.DtoModel.#ModelName#.#EntityName#
+{
+ public class #EntityName#GetListInput
+ {
+#EntityField#
+ }
+}
diff --git a/Yi.Framework.Net6/Yi.Framework.Template/Template/Server/ServiceTemplate.txt b/Yi.Framework.Net6/Yi.Framework.Template/Template/Server/ServiceTemplate.txt
index fec61106..1a669210 100644
--- a/Yi.Framework.Net6/Yi.Framework.Template/Template/Server/ServiceTemplate.txt
+++ b/Yi.Framework.Net6/Yi.Framework.Template/Template/Server/ServiceTemplate.txt
@@ -16,9 +16,6 @@ namespace Yi.Framework.Service.#ModelName#
{
public class #EntityName#Service : CrudAppService<#EntityName#Entity, #EntityName#GetListOutput, long, #EntityName#CreateUpdateInput>, I#EntityName#Service
{
- public #EntityName#Service(IRepository<#EntityName#Entity> repository, IMapper mapper) : base(repository, mapper)
- {
- }
public async Task>> PageListAsync(#EntityName#CreateUpdateInput input, PageParModel page)
{
RefAsync totalNumber = 0;
diff --git a/Yi.Framework.Net6/Yi.Framework.Template/Yi.Framework.Template.csproj b/Yi.Framework.Net6/Yi.Framework.Template/Yi.Framework.Template.csproj
index 49318819..dd49c63b 100644
--- a/Yi.Framework.Net6/Yi.Framework.Template/Yi.Framework.Template.csproj
+++ b/Yi.Framework.Net6/Yi.Framework.Template/Yi.Framework.Template.csproj
@@ -20,6 +20,9 @@
Always
+
+ Always
+
Always
diff --git a/Yi.Framework.Net6/Yi.Framework.WebCore/AutoFacExtend/CustomAutofacModule.cs b/Yi.Framework.Net6/Yi.Framework.WebCore/AutoFacExtend/CustomAutofacModule.cs
index 5eb7028e..0cc89fa6 100644
--- a/Yi.Framework.Net6/Yi.Framework.WebCore/AutoFacExtend/CustomAutofacModule.cs
+++ b/Yi.Framework.Net6/Yi.Framework.WebCore/AutoFacExtend/CustomAutofacModule.cs
@@ -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().As().InstancePerDependency().EnableInterfaceInterceptors();
- containerBuilder.RegisterType< HttpContextAccessor>().As().SingleInstance();
+ containerBuilder.RegisterType().As().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().As().EnableInterfaceInterceptors();开启Aop
//将数据库对象注入
@@ -73,7 +71,6 @@ namespace Yi.Framework.WebCore.AutoFacExtend
//containerBuilder.RegisterGeneric(typeof(BaseService<>)).As(typeof(IBaseService<>)).InstancePerDependency().EnableInterfaceInterceptors();
-
}
}
diff --git a/Yi.Framework.Net6/Yi.Framework.WebCore/AutoFacExtend/PropertiesAutowiredModule.cs b/Yi.Framework.Net6/Yi.Framework.WebCore/AutoFacExtend/PropertiesAutowiredModule.cs
index 03ac301b..d600a42e 100644
--- a/Yi.Framework.Net6/Yi.Framework.WebCore/AutoFacExtend/PropertiesAutowiredModule.cs
+++ b/Yi.Framework.Net6/Yi.Framework.WebCore/AutoFacExtend/PropertiesAutowiredModule.cs
@@ -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
diff --git a/Yi.Framework.Net6/Yi.Framework.WebCore/Impl/CurrentUser.cs b/Yi.Framework.Net6/Yi.Framework.WebCore/Impl/CurrentUser.cs
new file mode 100644
index 00000000..139a6c26
--- /dev/null
+++ b/Yi.Framework.Net6/Yi.Framework.WebCore/Impl/CurrentUser.cs
@@ -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; }
+ }
+}
diff --git a/Yi.Framework.Net6/Yi.Framework.WebCore/MiddlewareExtend/CurrentUserExrension.cs b/Yi.Framework.Net6/Yi.Framework.WebCore/MiddlewareExtend/CurrentUserExrension.cs
new file mode 100644
index 00000000..09f8e8fe
--- /dev/null
+++ b/Yi.Framework.Net6/Yi.Framework.WebCore/MiddlewareExtend/CurrentUserExrension.cs
@@ -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();
+ }
+
+
+ public static IApplicationBuilder UseCurrentUserServer(this IApplicationBuilder app)
+ {
+ return app.UseMiddleware();
+ }
+ }
+
+ public class CurrentUserMiddleware
+ {
+
+ private readonly RequestDelegate _next;
+ private ILogger _logger;
+ public CurrentUserMiddleware(RequestDelegate next, ILogger 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 claims, string type)
+ {
+ return claims.Where(c => c.Type == type).Select(c => c.Value).FirstOrDefault();
+ }
+
+ public static string[]? GetClaims(this IEnumerable claims, string type)
+ {
+ return claims.Where(c => c.Type == type).Select(c => c.Value).ToArray();
+ }
+ }
+
+}
diff --git a/Yi.Vue3.x.RuoYi/src/views/ERP/purchase/index.vue b/Yi.Vue3.x.RuoYi/src/views/ERP/purchase/index.vue
index 54ab4b7b..41697b5c 100644
--- a/Yi.Vue3.x.RuoYi/src/views/ERP/purchase/index.vue
+++ b/Yi.Vue3.x.RuoYi/src/views/ERP/purchase/index.vue
@@ -142,14 +142,19 @@
-
-
+
+
-
- 999{{ form.name }}
+
+ {{showTotalMoney}}
@@ -158,7 +163,7 @@
-
+
@@ -166,11 +171,30 @@
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 添加物料
@@ -185,6 +209,44 @@
+
+
+
+
+
+
+
+
+
+
+
+ 搜索
+ 重置
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -196,33 +258,21 @@ import {
addData,
updateData,
} from "@/api/erp/purchaseApi";
-import { ref } from "@vue/reactivity";
+import {
+ listData as materialListData
+} from "@/api/erp/materialApi";
+import { ref } from "@vue/reactivity";
+import { computed } from "@vue/runtime-core";
const { proxy } = getCurrentInstance();
const { sys_normal_disable } = proxy.useDict("sys_normal_disable");
-const tableData = [
- {
- date: '2016-05-03',
- name: 'Tom',
- address: 'No. 189, Grove St, Los Angeles',
- },
- {
- date: '2016-05-02',
- name: 'Tom',
- address: 'No. 189, Grove St, Los Angeles',
- },
- {
- date: '2016-05-04',
- name: 'Tom',
- address: 'No. 189, Grove St, Los Angeles',
- },
- {
- date: '2016-05-01',
- name: 'Tom',
- address: 'No. 189, Grove St, Los Angeles',
- },
-]
+//添加物料对话框
+const openMaterial=ref(false);
+const materialList= ref([]);
+const materialTotal = ref(0);
+const materialMultipleSelection=ref([]);
+
const dataList = ref([]);
@@ -236,7 +286,10 @@ const total = ref(0);
const title = ref("");
const dateRange = ref([]);
const data = reactive({
- form: {},
+ form: {
+ totalMoney:0,
+ purchaseDetails:[]
+ },
queryParams: {
pageNum: 1,
pageSize: 10,
@@ -244,14 +297,19 @@ const data = reactive({
code: undefined,
buyer: undefined,
},
+ queryMaterialParams:{
+ pageNum: 1,
+ pageSize: 10,
+ name: undefined,
+ code: undefined,
+ },
rules: {
code: [{ required: true, message: "采购单编号不能为空", trigger: "blur" }],
name: [{ required: true, message: "采购单名称不能为空", trigger: "blur" }],
},
});
-const { queryParams, form, rules } = toRefs(data);
-
+const { queryParams, form, queryMaterialParams,rules } = toRefs(data);
/** 查询列表 */
function getList() {
loading.value = true;
@@ -263,6 +321,7 @@ function getList() {
}
);
}
+
/** 取消按钮 */
function cancel() {
open.value = false;
@@ -343,5 +402,87 @@ function handleDelete(row) {
/** 导出按钮操作 */
function handleExport() { }
+
+
+//-------------这里开始是物料对话框的数据-----------
+/** 物料查询列表 */
+function getMaterialList() {
+ materialListData(proxy.addDateRange(queryMaterialParams.value, dateRange.value)).then(
+ (response) => {
+ materialList.value = response.data.data;
+ materialTotal.value = response.data.total;
+ }
+ );
+}
+/** 表单改变选择 */
+function materialHandleSelectionChange(select)
+{
+ materialMultipleSelection.value=select
+}
+/** 打开对话框 */
+function materialHandleAdd()
+{
+ getMaterialList();
+ openMaterial.value=true;
+}
+/** 搜索 */
+function handleMaterialQuery()
+{
+ getMaterialList();
+}
+/**重置表单 */
+function resetMaterialQuery()
+{
+ proxy.resetForm("queryMaterialRef");
+ handleMaterialQuery();
+}
+/** 提交物料表单 */
+function submitMaterialForm()
+{
+if(materialMultipleSelection.value.length>0)
+{
+ const purchaseDetailsList= materialMultipleSelection.value.map(u=>{
+ return {materialName:u.name,materialUnit:u.unitName}
+ })
+
+ form.value.purchaseDetails.push(...purchaseDetailsList)
+ materialCancel()
+
+}
+else
+{
+
+ proxy.$modal.msgError("请选择至少一个物料");
+}
+
+
+}
+/** 取消对话框 */
+function materialCancel()
+{
+ openMaterial.value=false
+}
+
+// watch(data.form, (newValue, oldValue) => {
+// console.log(newValue.purchaseDetails,999)
+// }
+// , { immdiate: true })
+/** 计算属性:实时计算展示的价格 */
+const showTotalMoney =computed(()=>{
+ let res=0;
+ form.value.purchaseDetails.forEach(details => {
+ if(details.unitPrice!=undefined && details.totalNumber!=undefined)
+ {res+= details.unitPrice*details.totalNumber}
+ });
+ return res;
+})
+
getList();
-
\ No newline at end of file
+
+
\ No newline at end of file