diff --git a/WinIn.FasterZ.Wms.Be/WinIn.FasterZ.Wms/WinIn.FasterZ.Wms/src/WinIn.FasterZ.Wms.Application/AppBase/ZbxBase.cs b/WinIn.FasterZ.Wms.Be/WinIn.FasterZ.Wms/WinIn.FasterZ.Wms/src/WinIn.FasterZ.Wms.Application/AppBase/ZbxBase.cs index 667d25c55..0aa17e62d 100644 --- a/WinIn.FasterZ.Wms.Be/WinIn.FasterZ.Wms/WinIn.FasterZ.Wms/src/WinIn.FasterZ.Wms.Application/AppBase/ZbxBase.cs +++ b/WinIn.FasterZ.Wms.Be/WinIn.FasterZ.Wms/WinIn.FasterZ.Wms/src/WinIn.FasterZ.Wms.Application/AppBase/ZbxBase.cs @@ -11,12 +11,11 @@ using AutoMapper; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; using Microsoft.Extensions.Caching.Distributed; using Microsoft.Extensions.Localization; using NPOI.SS.UserModel; using NPOI.XSSF.UserModel; -using Omu.ValueInjecter; +using Volo.Abp; using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Services; using Volo.Abp.Caching; @@ -29,7 +28,6 @@ using WinIn.FasterZ.Store.Enums; using WinIn.FasterZ.Wms.AppBase.Extensions; using WinIn.FasterZ.Wms.AppBaseBusiness.ExportCustomUserSetting; using WinIn.FasterZ.Wms.Localization; -using Mapper = AutoMapper.Mapper; namespace WinIn.FasterZ.Wms.AppBase; @@ -43,12 +41,14 @@ public class ZbxBase - /// redis缓存时间 分钟 + /// redis缓存时间 分钟 /// private const int CacheMinute = 30; private readonly IRepository _repository; + private IMapper _mapper; + private IStringLocalizer Localizer => LazyServiceProvider.LazyGetRequiredService>(); @@ -57,7 +57,6 @@ public class ZbxBase Cache => LazyServiceProvider.LazyGetRequiredService>(); - private IMapper _mapper; #endregion @@ -129,8 +128,8 @@ public class ZbxBase)) + && propertyInfo.PropertyType.IsGenericType + && propertyInfo.PropertyType.GetGenericTypeDefinition() == typeof(List<>)) { var listProperty = typeof(TEntity).GetProperty("Details"); @@ -211,101 +210,74 @@ public class ZbxBase(); + Type inputDetailDtoType = null; + Type entityDetailType = null; + bool inputDetailDtoTypeFlag = false; + bool entityDetailTypeFlag = false; - Type t1 = null; - Type t2 = null; - Type t3 = typeof(TUpdateInput); + var t3 = typeof(TUpdateInput); - #region 给所有字表的 Id和MasterId赋值 否则默认的会是000000-000-....的id 插入时会报错 + var entityProperties = entity.GetType().GetProperties(); + var inputProperties = input.GetType().GetProperties(); - var propertyInfos = entity.GetType().GetProperties(); - var dtolist = input.GetType().GetProperties(); - foreach (var propertyInfo in dtolist) + //InputDto的 + foreach (var propertyInfo in inputProperties) { if (propertyInfo.Name == "Details" - && propertyInfo.PropertyType.IsGenericType - && propertyInfo.PropertyType.GetGenericTypeDefinition() == typeof(List<>)) + && propertyInfo.PropertyType.IsGenericType + && propertyInfo.PropertyType.GetGenericTypeDefinition() == typeof(List<>)) { var listProperty = typeof(TUpdateInput).GetProperty("Details"); if (listProperty != null) { - t1 = listProperty.PropertyType.GetGenericArguments()[0]; + inputDetailDtoType = listProperty.PropertyType.GetGenericArguments()[0]; + inputDetailDtoTypeFlag = true; } } } - foreach (var propertyInfo in propertyInfos) + if (inputDetailDtoTypeFlag == true) { - //判断是否是List集合 - if (propertyInfo.Name == "Details" - && propertyInfo.PropertyType.IsGenericType - && propertyInfo.PropertyType.GetGenericTypeDefinition() == typeof(List<>)) + //实体的 + foreach (var propertyInfo in entityProperties) { - var listProperty = typeof(TEntity).GetProperty("Details"); - // 获取 List 的元素类型 - if (listProperty != null) + //判断是否是List集合 + if (propertyInfo.Name == "Details" + && propertyInfo.PropertyType.IsGenericType + && propertyInfo.PropertyType.GetGenericTypeDefinition() == typeof(List<>)) { - var listItemType = listProperty.PropertyType.GetGenericArguments()[0]; - t2 = listProperty.PropertyType.GetGenericArguments()[0]; - - // 获取元素类型的 ID 属性 - //var detailIdProperty = listItemType.GetProperty("Id"); - var masterIdProperty = listItemType.GetProperty("MasterId"); - - //if (detailIdProperty != null) - //{ - // // 获取 List 属性的值 - // var list = (IList)listProperty.GetValue(entity); - - // // 遍历 List 集合中的每个元素,给 ID 属性赋值 - // if (list != null) - // { - // foreach (var item in list) - // { - // if ((Guid)detailIdProperty.GetValue(item)! == Guid.Empty) - // { - // detailIdProperty.SetValue(item, Guid.NewGuid()); - // } - // } - // } - //} - - //if (masterIdProperty != null) - //{ - // // 获取 List 属性的值 - // var list = (IList)listProperty.GetValue(entity); - - // // 遍历 List 集合中的每个元素,给 ID 属性赋值 - // if (list != null) - // { - // foreach (var item in list) - // { - // masterIdProperty.SetValue(item, id); - // } - // } - //} + var listProperty = typeof(TEntity).GetProperty("Details"); + // 获取 List 的元素类型 + if (listProperty != null) + { + entityDetailType = listProperty.PropertyType.GetGenericArguments()[0]; + entityDetailTypeFlag = true; + } } } } - var config = new MapperConfiguration(cfg => + if (inputDetailDtoTypeFlag == true && entityDetailTypeFlag==true) { - // 动态创建映射关系 - cfg.CreateMap(typeof(TEntityDto), typeof(TEntity)); - cfg.CreateMap(t1, t2); - cfg.CreateMap(typeof(TUpdateInput), typeof(TEntity)); - }); - _mapper = new Mapper(config); - var tt = _mapper.Map(input, entity); - - #endregion - - //await Repository.UpdateAsync(entity, true); - //await Repository.UpdateAsync(tt, true); + var config = new MapperConfiguration(cfg => + { + // 动态创建映射关系 + cfg.CreateMap(typeof(TEntityDto), typeof(TEntity)); + cfg.CreateMap(typeof(TUpdateInput), typeof(TEntity)); + cfg.CreateMap(inputDetailDtoType, entityDetailType); + }); + _mapper = new Mapper(config); + } - //await Cache.SetAsync(entity.Id.ToString(), entity, GetCacheTime()); + await ReMoveCaCheAsync(id).ConfigureAwait(false); await Repository.UpdateAsync(entity, true); return await MapToGetOutputDtoAsync(entity); } @@ -579,6 +551,16 @@ public class ZbxBase + /// 清楚缓存 + /// + /// + /// + private async Task ReMoveCaCheAsync(TKey id) + { + await Cache.RemoveAsync(id?.ToString()); + } + /// /// 按表达式条件获取分页列表 /// @@ -713,15 +695,15 @@ public class ZbxBase - /// 获取缓存redis时间 + /// 获取缓存redis时间 /// /// private static DistributedCacheEntryOptions GetCacheTime() { - Random random = new Random(); + var random = new Random(); //解决雪崩 添加随机缓存时间 var time = CacheMinute + random.Next(10, 30); - return new DistributedCacheEntryOptions() + return new DistributedCacheEntryOptions { AbsoluteExpiration = DateTimeOffset.Now.AddMinutes(time) }; diff --git a/WinIn.FasterZ.Wms.Be/WinIn.FasterZ.Wms/WinIn.FasterZ.Wms/src/WinIn.FasterZ.Wms.Application/Z_Business/StoreSaleOrder/StoreSaleOrderAppService.cs b/WinIn.FasterZ.Wms.Be/WinIn.FasterZ.Wms/WinIn.FasterZ.Wms/src/WinIn.FasterZ.Wms.Application/Z_Business/StoreSaleOrder/StoreSaleOrderAppService.cs index 7b66cd446..9f843cfa1 100644 --- a/WinIn.FasterZ.Wms.Be/WinIn.FasterZ.Wms/WinIn.FasterZ.Wms/src/WinIn.FasterZ.Wms.Application/Z_Business/StoreSaleOrder/StoreSaleOrderAppService.cs +++ b/WinIn.FasterZ.Wms.Be/WinIn.FasterZ.Wms/WinIn.FasterZ.Wms/src/WinIn.FasterZ.Wms.Application/Z_Business/StoreSaleOrder/StoreSaleOrderAppService.cs @@ -1,13 +1,17 @@ using System; using System.Linq; using System.Threading.Tasks; +using AutoMapper; using Microsoft.AspNetCore.Mvc; +using Volo.Abp; using WinIn.FasterZ.Wms.Permissions; using WinIn.FasterZ.Wms.Z_Business.StoreSaleOrder.Dtos; using Volo.Abp.Application.Services; using WinIn.FasterZ.Wms.AppBase; using WinIn.FasterZ.Wms.Z_Business.StoreWorkOrder; using WinIn.FasterZ.Wms.Z_Business.StoreWorkOrder.Dtos; +using Omu.ValueInjecter; +using WinIn.FasterZ.Wms.Z_Business.StoreWorkOrderDetail.Dtos; namespace WinIn.FasterZ.Wms.Z_Business.StoreSaleOrder; @@ -25,18 +29,36 @@ public class StoreSaleOrderAppService : ZbxBase + /// Զ޸ Ѿ޸Ĵ + /// + /// + /// [HttpPost("xcvxcv")] public async Task test(CreateUpdateStoreWorkOrderDto dto) { - dto.Qty = 1; await _workOrderAppService.UpdateAsync(dto.Id, dto); - dto.Qty = 4; - await _workOrderAppService.UpdateAsync(dto.Id, dto); - } + var tttt =await _workOrderAppService.GetAsync(dto.Id); + tttt.Qty += 5; + + var config = new MapperConfiguration(cfg => + { + // ̬ӳϵ + cfg.CreateMap(typeof(StoreWorkOrderDto), typeof(CreateUpdateStoreWorkOrderDto)); + cfg.CreateMap(typeof(StoreWorkOrderDetailDto), typeof(CreateUpdateStoreWorkOrderDetailDto)); + }); + _mapperssssss = new AutoMapper.Mapper(config); + var ffff = _mapperssssss.Map(tttt); + + await _workOrderAppService.UpdateAsync(ffff.Id, ffff); + //throw new UserFriendlyException("xzcvxcv"); + } } diff --git a/WinIn.FasterZ.Wms.Be/WinIn.FasterZ.Wms/WinIn.FasterZ.Wms/src/WinIn.FasterZ.Wms.EntityFrameworkCore/EntityFrameworkCore/WmsDbContext.cs b/WinIn.FasterZ.Wms.Be/WinIn.FasterZ.Wms/WinIn.FasterZ.Wms/src/WinIn.FasterZ.Wms.EntityFrameworkCore/EntityFrameworkCore/WmsDbContext.cs index 7e1c0d745..9617fcb39 100644 --- a/WinIn.FasterZ.Wms.Be/WinIn.FasterZ.Wms/WinIn.FasterZ.Wms/src/WinIn.FasterZ.Wms.EntityFrameworkCore/EntityFrameworkCore/WmsDbContext.cs +++ b/WinIn.FasterZ.Wms.Be/WinIn.FasterZ.Wms/WinIn.FasterZ.Wms/src/WinIn.FasterZ.Wms.EntityFrameworkCore/EntityFrameworkCore/WmsDbContext.cs @@ -1036,6 +1036,7 @@ namespace WinIn.FasterZ.Wms.EntityFrameworkCore { b.ToTable(WmsConsts.DbTablePrefix + "Store_WorkOrder", WmsConsts.DbSchema); b.ConfigureByConvention(); + b.Property(e => e.ConcurrencyStamp).IsConcurrencyToken(false); b.HasMany(q => q.Details).WithOne().HasForeignKey(d => d.MasterId).IsRequired(); /* Configure more properties here */ @@ -3220,8 +3221,7 @@ namespace WinIn.FasterZ.Wms.EntityFrameworkCore //{ // item?.GetType().GetProperty("ConcurrencyStamp")?.SetValue(item, Guid.NewGuid().ToString()); //} - //return base.SaveChanges(); - return 1; + return base.SaveChanges(); } public override Task SaveChangesAsync(bool acceptAllChangesOnSuccess, CancellationToken cancellationToken = new CancellationToken()) @@ -3232,8 +3232,7 @@ namespace WinIn.FasterZ.Wms.EntityFrameworkCore //{ // item?.GetType().GetProperty("ConcurrencyStamp")?.SetValue(item, Guid.NewGuid().ToString()); //} - //return base.SaveChangesAsync(acceptAllChangesOnSuccess, cancellationToken); - return Task.FromResult(1); + return base.SaveChangesAsync(acceptAllChangesOnSuccess, cancellationToken); } public override Task SaveChangesOnDbContextAsync(bool acceptAllChangesOnSuccess, @@ -3245,8 +3244,7 @@ namespace WinIn.FasterZ.Wms.EntityFrameworkCore //{ // item?.GetType().GetProperty("ConcurrencyStamp")?.SetValue(item, Guid.NewGuid().ToString()); //} - //return base.SaveChangesOnDbContextAsync(acceptAllChangesOnSuccess, cancellationToken); - return Task.FromResult(1); + return base.SaveChangesOnDbContextAsync(acceptAllChangesOnSuccess, cancellationToken); } } }