diff --git a/.vs/WMS.Web/DesignTimeBuild/.dtbcache.v2 b/.vs/WMS.Web/DesignTimeBuild/.dtbcache.v2 index 3594c178..5c42c02b 100644 Binary files a/.vs/WMS.Web/DesignTimeBuild/.dtbcache.v2 and b/.vs/WMS.Web/DesignTimeBuild/.dtbcache.v2 differ diff --git a/src/WMS.Web.Domain/Infrastructure/IProductInventoryRepositories.cs b/src/WMS.Web.Domain/Infrastructure/IProductInventoryRepositories.cs index 99021660..fa0bcd53 100644 --- a/src/WMS.Web.Domain/Infrastructure/IProductInventoryRepositories.cs +++ b/src/WMS.Web.Domain/Infrastructure/IProductInventoryRepositories.cs @@ -29,6 +29,8 @@ namespace WMS.Web.Domain.Infrastructure /// /// Task Delete(ProductInventoryType type, bool isTransaction = true); + Task EditEntityList(List entitys, bool isTransaction = true); + Task> GetEntityList(ProductInventoryType type); /// /// 列表-分页 /// diff --git a/src/WMS.Web.Domain/Mappers/ProductInventoryMapper.cs b/src/WMS.Web.Domain/Mappers/ProductInventoryMapper.cs new file mode 100644 index 00000000..182a829a --- /dev/null +++ b/src/WMS.Web.Domain/Mappers/ProductInventoryMapper.cs @@ -0,0 +1,17 @@ +using AutoMapper; +using System; +using System.Collections.Generic; +using System.Text; +using WMS.Web.Core.Dto.Erp; +using WMS.Web.Domain.Entitys; + +namespace WMS.Web.Domain.Mappers +{ + public class ProductInventoryMapper : Profile + { + public ProductInventoryMapper() + { + CreateMap().ReverseMap(); + } + } +} diff --git a/src/WMS.Web.Domain/Services/ProductInventoryService.cs b/src/WMS.Web.Domain/Services/ProductInventoryService.cs index fce77817..94d6c0c0 100644 --- a/src/WMS.Web.Domain/Services/ProductInventoryService.cs +++ b/src/WMS.Web.Domain/Services/ProductInventoryService.cs @@ -130,6 +130,9 @@ namespace WMS.Web.Domain.Services .Select(s => s.WarehouseCodeOfJushuitan) .ToList(); if (listNames.Count() <= 0) return Result.ReSuccess(); + //获取原数据 + var yList = await _repositories.GetEntityList(ProductInventoryType.JushuiTan); + //获取领星仓库 var resStock = await _juShuiTanService.GetStock(); if (!resStock.IsSuccess) return resStock; @@ -139,6 +142,8 @@ namespace WMS.Web.Domain.Services var resInventory = await _juShuiTanService.GetInventory(ids); if (!resInventory.IsSuccess) return resStock; + + //物料 var materials_result = await _erpService.BillQueryForMaterial(); List materials = new List(); @@ -146,6 +151,7 @@ namespace WMS.Web.Domain.Services materials = materials_result.Data.ToList(); List inventoryList = new List(); + List update_List = new List(); foreach (var item in resInventory.Data) { //如果物料不匹配 过滤 @@ -167,7 +173,17 @@ namespace WMS.Web.Domain.Services Qty = item.ky_qty, BeforeQty = item.qty ?? 0 }; - inventoryList.Add(entity); + + var old_Entity = yList.FirstOrDefault(f => f.MaterialNumber.Equals(entity.MaterialNumber) && + f.OrgCode.Equals(entity.OrgCode) && f.StockCode.Equals(entity.StockCode)); + if (old_Entity != null) + { + old_Entity.Qty = entity.Qty; + old_Entity.BeforeQty = entity.BeforeQty; + update_List.Add(old_Entity); + } + else + inventoryList.Add(entity); } IDbContextTransaction _transaction = _transactionRepositories.GetTransaction(); Result res_Rollback = Result.ReSuccess(); @@ -176,7 +192,7 @@ namespace WMS.Web.Domain.Services //先删除之前的再添加 if (res_Rollback.IsSuccess) { - isSuccess = await _repositories.Delete(ProductInventoryType.LingXing, false); + isSuccess = await _repositories.EditEntityList(update_List, false); if (isSuccess == false) res_Rollback = Result.ReFailure(ResultCodes.DateWriteError); } if (res_Rollback.IsSuccess) @@ -283,7 +299,7 @@ namespace WMS.Web.Domain.Services _logger.LogInformation($"同步成品仓库存->开始 {DateTime.Now}"); var res = await this.Erp(); - if(!res.IsSuccess)return res; + if (!res.IsSuccess) return res; res = await this.JuShuiTan(); if (!res.IsSuccess) return res; diff --git a/src/WMS.Web.Repositories/ProductInventoryRepositories.cs b/src/WMS.Web.Repositories/ProductInventoryRepositories.cs index f97e08ec..ecea21f5 100644 --- a/src/WMS.Web.Repositories/ProductInventoryRepositories.cs +++ b/src/WMS.Web.Repositories/ProductInventoryRepositories.cs @@ -19,6 +19,8 @@ using WMS.Web.Core.Dto.OutStockTask; using WMS.Web.Domain.Values.Single; using WMS.Web.Core; using NPOI.SS.Formula.Functions; +using WMS.Web.Domain.Mappers; +using WMS.Web.Core.Help; namespace WMS.Web.Repositories { @@ -173,5 +175,50 @@ namespace WMS.Web.Repositories var (list, count, qty) = await GetListAsync(dto, companyId); return (list, count); } + /// + /// 批量修改 + /// + /// + /// + /// + public async Task EditEntityList(List entitys, bool isTransaction = true) + { + IDbContextTransaction _transaction = null; + if (isTransaction) + _transaction = _context.Database.BeginTransaction(); + try + { + List list = entitys.Select(s => s.Id).ToList(); + + var res = await _context.ProductInventory + .Where(f => list.Contains(f.Id)).ToListAsync(); + + _mapper.ToMapList(entitys, res); + await _context.SaveChangesAsync(); + if (_transaction != null) + _transaction.Commit(); + } + catch (Exception ex) + { + if (_transaction != null) + _transaction.Rollback(); + return false; + } + return true; + + } + /// + /// 获取数据 + /// + /// + /// + public async Task> GetEntityList(ProductInventoryType type) + { + var res = await _context.ProductInventory + .Where(f => f.Type==type) + .ToListAsync(); + + return res.Clone(); + } } }