diff --git a/.vs/WMS.Web/DesignTimeBuild/.dtbcache.v2 b/.vs/WMS.Web/DesignTimeBuild/.dtbcache.v2 index aa15dfb0..d5fefd82 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.Api/Controllers/OutStockTaskController.cs b/src/WMS.Web.Api/Controllers/OutStockTaskController.cs index 15e35a27..7963336c 100644 --- a/src/WMS.Web.Api/Controllers/OutStockTaskController.cs +++ b/src/WMS.Web.Api/Controllers/OutStockTaskController.cs @@ -131,7 +131,11 @@ namespace WMS.Web.Api.Controllers if (loginInfo == null || loginInfo.UserInfo == null) return ResultList.ReFailure(ResultCodes.Token_Invalid_Error); + List str = new List(); + str.Add(billNo); + var res2 = await _repositories.GetListBySourceBillNo(str); var res = await _repositories.GetOutStockTaskListByNo(billNo); + if (res == null || res.Count() == 0) return ResultList.ReFailure(ResultCodes.OutStockTaskNoData); return ResultList.ReSuccess(res); } diff --git a/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml b/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml index 5058c7ee..371ae633 100644 --- a/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml +++ b/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml @@ -964,6 +964,11 @@ 同步成功或者失败 null 就是未同步 + + + 同步失败的源订单号 + + 同步时间 @@ -985,7 +990,7 @@ - + 同步金蝶 @@ -1142,21 +1147,6 @@ 单据头Id - - - 对应金蝶单据明细id(销售出库同步金蝶下推使用) - - - - - 来源单号(合并后有多个) - - - - - 销售订单号 - - 物料Id @@ -1182,16 +1172,6 @@ 已出库数量 - - - 已出库数量(合并后不同物料 分别出库多少) - - - - - 应出库数量(合并后不同物料 分别应出多少) - - 订单明细备注 @@ -1207,6 +1187,51 @@ 出库结束时间 + + + 对应erp明细 同一个物料 存在于不同的来源单中(合并后出现多条) + + + + + 对应金蝶的明细 + + + + + 主键 订单编号 + + + + + 任务单明细Id + + + + + 对应金蝶单据明细id(销售出库同步金蝶下推使用) + + + + + 来源单号 + + + + + 销售订单号 + + + + + 应出库数量 + + + + + 已出库数量 + + 序列号操作记录表 @@ -1882,7 +1907,7 @@ - 列表-根据明细中的来源单号 + 列表-根据明细中的来源单号精确匹配 diff --git a/src/WMS.Web.Domain/Entitys/OutStockTask.cs b/src/WMS.Web.Domain/Entitys/OutStockTask.cs index 22e9d9b2..fc3a24e9 100644 --- a/src/WMS.Web.Domain/Entitys/OutStockTask.cs +++ b/src/WMS.Web.Domain/Entitys/OutStockTask.cs @@ -168,10 +168,13 @@ namespace WMS.Web.Domain.Entitys if (detail_new != null) { detail_new.AccruedQty += d.AccruedQty;//应出数量累加 - detail_new.SaleBillNos.AddRange(d.SaleBillNos); - detail_new.SourceBillNos.AddRange(d.SourceBillNos); - foreach (var dic in d.AccruedQty_Dic) - detail_new.AccruedQty_Dic.Add(dic.Key, dic.Value); + foreach (var erpd in d.ErpDetails) + { + var cd = erpd.Clone(); + cd.Id = 0;cd.DetailId = 0; + detail_new.ErpDetails.Add(cd); + } + } else details_new.Add(d); diff --git a/src/WMS.Web.Domain/Entitys/OutStockTaskDetails.cs b/src/WMS.Web.Domain/Entitys/OutStockTaskDetails.cs index 5ca32cd1..c03c628b 100644 --- a/src/WMS.Web.Domain/Entitys/OutStockTaskDetails.cs +++ b/src/WMS.Web.Domain/Entitys/OutStockTaskDetails.cs @@ -28,22 +28,6 @@ namespace WMS.Web.Domain.Entitys [Column("Fid")] public int Fid { get; set; } /// - /// 对应金蝶单据明细id(销售出库同步金蝶下推使用) - /// - [Column("Erp_DetailId")] - public int Erp_DetailId { get; set; } - /// - /// 来源单号(合并后有多个) - /// - [Column("SourceBillNo")] - public List SourceBillNos { get; set; } - - /// - /// 销售订单号 - /// - [Column("SaleBillNo")] - public List SaleBillNos { get; set; } - /// /// 物料Id /// [Column("MaterialId")] @@ -69,16 +53,6 @@ namespace WMS.Web.Domain.Entitys [Column("RealityQty")] public decimal RealityQty { get; set; } /// - /// 已出库数量(合并后不同物料 分别出库多少) - /// - [Column("RealityQty_Dic")] - public Dictionary RealityQty_Dic { get; set; } = new Dictionary(); - /// - /// 应出库数量(合并后不同物料 分别应出多少) - /// - [Column("AccruedQty_Dic")] - public Dictionary AccruedQty_Dic { get; set; } = new Dictionary(); - /// /// 订单明细备注 /// [Column("Remark")] @@ -93,7 +67,10 @@ namespace WMS.Web.Domain.Entitys /// [Column("OutStockEndTime")] public DateTime? OutStockEndTime { get; set; } - + /// + /// 对应erp明细 同一个物料 存在于不同的来源单中(合并后出现多条) + /// + public List ErpDetails { get; set; } = new List(); } } diff --git a/src/WMS.Web.Domain/Entitys/OutStockTaskErpDetails.cs b/src/WMS.Web.Domain/Entitys/OutStockTaskErpDetails.cs new file mode 100644 index 00000000..88f425cf --- /dev/null +++ b/src/WMS.Web.Domain/Entitys/OutStockTaskErpDetails.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.Text; +using WMS.Web.Core; + +namespace WMS.Web.Domain.Entitys +{ + /// + /// 对应金蝶的明细 + /// + [Serializable] + [Table("t_erp_outstock_task_erp_details")] + public class OutStockTaskErpDetails : EntityBase + { + public OutStockTaskErpDetails() { } + /// + /// 主键 订单编号 + /// + [Column("Id")] + public override int Id { get; set; } + /// + /// 任务单明细Id + /// + [Column("DetailId")] + public int DetailId { get; set; } + /// + /// 对应金蝶单据明细id(销售出库同步金蝶下推使用) + /// + [Column("Erp_DetailId")] + public int Erp_DetailId { get; set; } + /// + /// 来源单号 + /// + [Column("SourceBillNo")] + public string SourceBillNo { get; set; } + /// + /// 销售订单号 + /// + [Column("SaleBillNo")] + public string SaleBillNo { get; set; } + /// + /// 应出库数量 + /// + [Column("AccruedQty")] + public decimal AccruedQty { get; set; } + /// + /// 已出库数量 + /// + [Column("RealityQty")] + public decimal RealityQty { get; set; } + } +} diff --git a/src/WMS.Web.Domain/Infrastructure/IOutStockTaskRepositories.cs b/src/WMS.Web.Domain/Infrastructure/IOutStockTaskRepositories.cs index f5e57db1..0c29481b 100644 --- a/src/WMS.Web.Domain/Infrastructure/IOutStockTaskRepositories.cs +++ b/src/WMS.Web.Domain/Infrastructure/IOutStockTaskRepositories.cs @@ -23,7 +23,7 @@ namespace WMS.Web.Domain.Infrastructure /// 查询实体集合 Task> GetEntityList(List ids); /// - /// 列表-根据明细中的来源单号 + /// 列表-根据明细中的来源单号精确匹配 /// /// /// diff --git a/src/WMS.Web.Domain/Mappers/OutStockMapper.cs b/src/WMS.Web.Domain/Mappers/OutStockMapper.cs index 09e61d71..5690b5ee 100644 --- a/src/WMS.Web.Domain/Mappers/OutStockMapper.cs +++ b/src/WMS.Web.Domain/Mappers/OutStockMapper.cs @@ -24,9 +24,8 @@ namespace WMS.Web.Domain.Mappers CreateMap(); CreateMap(); - CreateMap() - .ForPath(x => x.SourceBillNos, ops => ops.MapFrom(x => new List() { x.SourceBillNo })) - .ForPath(x => x.SaleBillNos, ops => ops.MapFrom(x => new List() { x.SaleBillNo })); + CreateMap(); + CreateMap(); } } } diff --git a/src/WMS.Web.Domain/Services/BoxService.cs b/src/WMS.Web.Domain/Services/BoxService.cs index 53ffcc13..69febf42 100644 --- a/src/WMS.Web.Domain/Services/BoxService.cs +++ b/src/WMS.Web.Domain/Services/BoxService.cs @@ -76,6 +76,7 @@ namespace WMS.Web.Domain.Services foreach (var sn in ops_box.Details.SelectMany(s => s.SerialNumbers)) { var detail = ops_box.Details.FirstOrDefault(f => f.SerialNumbers.Select(s=>s.SerialNumber).Equals(sn.SerialNumber)); + if (detail == null) continue; var opsSerial = list.FirstOrDefault(f => f.OpsBoxId == b.OpsBoxId).Details .SelectMany(s => s.SerialNumbers) .FirstOrDefault(s => s.SerialNumber.Equals(sn.SerialNumber)); diff --git a/src/WMS.Web.Domain/Services/OutStockTaskService.cs b/src/WMS.Web.Domain/Services/OutStockTaskService.cs index b84b5345..57eb2c08 100644 --- a/src/WMS.Web.Domain/Services/OutStockTaskService.cs +++ b/src/WMS.Web.Domain/Services/OutStockTaskService.cs @@ -103,29 +103,41 @@ namespace WMS.Web.Domain.Services if (data_list.Count != 0) { //2.1提取出wms任务单明细信息 - foreach (var e in erp_list) + foreach (var outStockTask in data_list) { - //代表单据已经存在 那么就对单据进行修改 - var data = data_list.FirstOrDefault(f => f.Details.SelectMany(s => s.SourceBillNos).Contains(e.SourceBillNo)); - var detail = data.Details.FirstOrDefault(w => w.MaterialId == e.MaterialId); - //存在就修改,没有就添加 - if (detail != null) + var sourcNos = outStockTask.Details.SelectMany(s => s.ErpDetails).Select(s => s.SourceBillNo).ToList(); + var erps = erp_list.Where(w => sourcNos.Contains(w.SourceBillNo)).ToList(); + foreach (var erp in erps) { - if (detail.AccruedQty_Dic.ContainsKey(e.SourceBillNo)) - detail.AccruedQty_Dic[e.SourceBillNo] = e.AccruedQty; + var detail = outStockTask.Details.FirstOrDefault(w => w.MaterialId == erp.MaterialId); + if (detail == null) + { + //添加一条物料明细 + detail = _mapper.Map(erp); + var erpDetail = _mapper.Map(erp); + detail.ErpDetails.Add(erpDetail); + outStockTask.Details.Add(detail); + } else - detail.AccruedQty_Dic.Add(e.SourceBillNo, e.AccruedQty); - //对集合里的应发做出累加 - detail.AccruedQty = detail.AccruedQty_Dic.Sum(s => s.Value); - } - else - { - var de = _mapper.Map(e); - de.AccruedQty_Dic.Add(de.SourceBillNos.First(), de.AccruedQty); - data.Details.Add(de); + { + //找到物料明细下面对应的来源单明细 然后修改 + var erpDetail = detail.ErpDetails.FirstOrDefault(f => f.SourceBillNo.Equals(erp.SourceBillNo)); + if (erpDetail == null) + { + erpDetail = _mapper.Map(erp); + detail.ErpDetails.Add(erpDetail); + outStockTask.Details.Add(detail); + } + else + { + erpDetail.AccruedQty = erp.AccruedQty; + detail.AccruedQty = detail.ErpDetails.Sum(s => s.AccruedQty); + } + } + //操作完后剔除 + erp_removeList.Add(erp); } - erp_removeList.Add(e); } //2.2.提交修改 var isSuccess = await _outStockTaskRepositories.EditEntityList(data_list, isTransaction); @@ -150,9 +162,13 @@ namespace WMS.Web.Domain.Services //找到当前对应来源单据编号的集合数据 var current_erp_details = erp_list.Where(x => x.SourceBillNo == item).ToList(); //给到dto的实体明细中 - entity.Details = _mapper.Map>(current_erp_details); - foreach (var de in entity.Details) - de.AccruedQty_Dic.Add(de.SourceBillNos.First(), de.AccruedQty); + foreach (var erp in current_erp_details) + { + var detail = _mapper.Map(erp); + var erpDetail = _mapper.Map(erp); + detail.ErpDetails.Add(erpDetail); + entity.Details.Add(detail); + } add_entitys.Add(entity); } //3.1提交新增 @@ -294,15 +310,15 @@ namespace WMS.Web.Domain.Services foreach (var entity in taskList) { if (entity.Type == OutStockType.Sal) - DeliveryNotice_Nos.AddRange(entity.Details.SelectMany(s => s.SourceBillNos)); + DeliveryNotice_Nos.AddRange(entity.Details.SelectMany(s => s.ErpDetails).Select(s=>s.SourceBillNo)); else if (entity.Type == OutStockType.Stkdirecttransfers) - TransferDirect_Nos.AddRange(entity.Details.SelectMany(s => s.SourceBillNos)); + TransferDirect_Nos.AddRange(entity.Details.SelectMany(s => s.ErpDetails).Select(s => s.SourceBillNo)); else if (entity.Type == OutStockType.StktransferInst) - TransferOut_Nos.AddRange(entity.Details.SelectMany(s => s.SourceBillNos)); + TransferOut_Nos.AddRange(entity.Details.SelectMany(s => s.ErpDetails).Select(s => s.SourceBillNo)); else if (entity.Type == OutStockType.Assembled) - AssembledApp_Nos.AddRange(entity.Details.SelectMany(s => s.SourceBillNos)); + AssembledApp_Nos.AddRange(entity.Details.SelectMany(s => s.ErpDetails).Select(s => s.SourceBillNo)); else if (entity.Type == OutStockType.Miscellaneous) - MisDeliveryOut_Nos.AddRange(entity.Details.SelectMany(s => s.SourceBillNos)); + MisDeliveryOut_Nos.AddRange(entity.Details.SelectMany(s => s.ErpDetails).Select(s => s.SourceBillNo)); } if (DeliveryNotice_Nos.Count() > 0) diff --git a/src/WMS.Web.Repositories/Configuration/RepositoryDbContext.cs b/src/WMS.Web.Repositories/Configuration/RepositoryDbContext.cs index 4cb2ecdf..ddd8e34f 100644 --- a/src/WMS.Web.Repositories/Configuration/RepositoryDbContext.cs +++ b/src/WMS.Web.Repositories/Configuration/RepositoryDbContext.cs @@ -125,21 +125,16 @@ namespace WMS.Web.Repositories.Configuration ent.ToTable("t_erp_outstock_task_details"); ent.HasKey(x => x.Id); - ent.Property(f => f.SourceBillNos).HasConversion( - v => JsonConvert.SerializeObject(v), - v => JsonConvert.DeserializeObject>(v)); + ent.HasMany(p => p.ErpDetails) + .WithOne() + .HasForeignKey(p => p.DetailId) + .OnDelete(DeleteBehavior.Cascade); + }); - ent.Property(f => f.SaleBillNos).HasConversion( - v => JsonConvert.SerializeObject(v), - v => JsonConvert.DeserializeObject>(v)); - - ent.Property(f => f.AccruedQty_Dic).HasConversion( - v => JsonConvert.SerializeObject(v), - v => JsonConvert.DeserializeObject>(v)); - - ent.Property(f => f.RealityQty_Dic).HasConversion( - v => JsonConvert.SerializeObject(v), - v => JsonConvert.DeserializeObject>(v)); + builder.Entity(ent => + { + ent.ToTable("t_erp_outstock_task_erp_details"); + ent.HasKey(x => x.Id); }); #endregion @@ -298,6 +293,7 @@ namespace WMS.Web.Repositories.Configuration public DbSet TakeStock { get; set; } public DbSet OutStockDetails { get; set; } public DbSet OutStockTaskDetails { get; set; } + public DbSet OutStockTaskErpDetails { get; set; } public DbSet TakeStockDetails { get; set; } public DbSet Instock { get; set; } public DbSet InStockDetails { get; set; } diff --git a/src/WMS.Web.Repositories/OutStockTaskRepositories.cs b/src/WMS.Web.Repositories/OutStockTaskRepositories.cs index b852ceea..2e699e5f 100644 --- a/src/WMS.Web.Repositories/OutStockTaskRepositories.cs +++ b/src/WMS.Web.Repositories/OutStockTaskRepositories.cs @@ -188,12 +188,13 @@ namespace WMS.Web.Repositories try { var res = await _context.OutStockTask - .Include(s => s.Details) + .Include(s => s.Details).ThenInclude(s => s.ErpDetails) .FirstOrDefaultAsync(f => f.Id == entity.Id); if (res == null) return null; _mapper.Map(entity, res); _mapper.ToMapList(entity.Details, res.Details); + _mapper.ToMapList(entity.Details.SelectMany(s => s.ErpDetails).ToList(), res.Details.SelectMany(s => s.ErpDetails).ToList()); await _context.SaveChangesAsync(); if (_transaction != null) @@ -216,17 +217,13 @@ namespace WMS.Web.Repositories /// public async Task<(List list, int total)> GetListAsync(OutStockTaskQueryRequest dto) { - List ids = new List(); - if (!string.IsNullOrEmpty(dto.SourceBillNo)) - ids = await _context.OutStockTaskDetails.FromSqlRaw($"SELECT Id FROM t_erp_outstock_task_details WHERE SourceBillNo like '%{dto.SourceBillNo}%'").Select(s => s.Id).ToListAsync(); - - #region erp基础资料 List mIds = new List(); var materials_result = await _erpService.BillQueryForMaterial(); if (!materials_result.IsSuccess) return (new List(), 0); var materials = materials_result.Data.ToList(); + //var materials =new List(); //物料集合;模糊查询后的物料集合 if (!string.IsNullOrEmpty(dto.MaterialNumber)) { @@ -247,7 +244,7 @@ namespace WMS.Web.Repositories #endregion - var query = _context.OutStockTaskDetails + var query = _context.OutStockTaskDetails.Include(x => x.ErpDetails) .GroupJoin(_context.OutStockTask, detail => detail.Fid, order => order.Id, (detail, orders) => new { detail, orders }) .SelectMany(x => x.orders.DefaultIfEmpty(), (p, order) => new { p.detail, order }) .OrderByDescending(o => o.order.Id) @@ -267,8 +264,8 @@ namespace WMS.Web.Repositories query = query.Where(w => mIds.Contains(w.detail.MaterialId)); if (dto.Ids.Count() > 0) query = query.Where(w => dto.Ids.Contains(w.detail.Id)); - if (ids.Count() != 0) - query = query.Where(w => ids.Contains(w.detail.Id)); + if (!string.IsNullOrEmpty(dto.SourceBillNo)) + query = query.Where(w => w.detail.ErpDetails.Where(wd => EF.Functions.Like(wd.SourceBillNo, "%" + dto.SourceBillNo + "%")).Select(s => s.DetailId).Contains(w.detail.Id)); if (dto.Type != null) query = query.Where(w => w.order.Type == (OutStockType)dto.Type); if (dto.Status != null) @@ -295,8 +292,8 @@ namespace WMS.Web.Repositories OutStockBeginTime = s.detail.OutStockBeginTime.DateToStringSeconds(), OutStockEndTime = s.detail.OutStockEndTime.DateToStringSeconds(), Stock = _singleDataService.GetSingleData(SingleAction.Stocks, _loginRepositories.CompanyId, s.detail.StockCode), - SourceBillNo = string.Join(",", s.detail.SourceBillNos), - SaleBillNo = string.Join(",", s.detail.SaleBillNos), + SourceBillNo = string.Join(",", s.detail.ErpDetails.Select(s => s.SourceBillNo)), + SaleBillNo = string.Join(",", s.detail.ErpDetails.Select(s => s.SaleBillNo)), DeliveryOrg = _erpBasicDataExtendService.GetOrgName(orgs, s.order.DeliveryOrgId), ReceiptCustomer = s.order.Type == OutStockType.Sal ? _erpBasicDataExtendService.GetCustomerName(customers, s.order.ReceiptCustomerId) @@ -321,13 +318,12 @@ namespace WMS.Web.Repositories if (!materials_result.IsSuccess) return new List(); var materials = materials_result.Data.ToList(); - List ids = new List(); - ids = await _context.OutStockTaskDetails.FromSqlRaw($"SELECT Fid FROM t_erp_outstock_task_details WHERE SourceBillNo like '%{billNo}%'").Select(s => s.Id).ToListAsync(); - var list = await _context.OutStockTask.Include(x => x.Details) + + var list = await _context.OutStockTask.Include(x => x.Details).ThenInclude(s => s.ErpDetails) .Where(f => (EF.Functions.Like(f.BillNo, "%" + billNo + "%") || - ids.Contains(f.Id)) && + f.Details.SelectMany(s => s.ErpDetails).Where(w => EF.Functions.Like(w.SourceBillNo, "%" + billNo + "%")).Any()) && (f.Status == OutStockStatus.Part || f.Status == OutStockStatus.Wait)) .OrderByDescending(o => o.Id) .ToListAsync(); @@ -354,7 +350,7 @@ namespace WMS.Web.Repositories return new GetOutStockTaskByNoResponse(); var materials = materials_result.Data.ToList(); - var entity = await _context.OutStockTask.Include(x => x.Details) + var entity = await _context.OutStockTask.Include(x => x.Details).ThenInclude(s => s.ErpDetails) .FirstOrDefaultAsync(f => f.BillNo.Equals(billNo) && (f.Status == OutStockStatus.Part || f.Status == OutStockStatus.Wait)); @@ -372,26 +368,15 @@ namespace WMS.Web.Repositories } /// - /// 单号搜索 + /// 单号精确匹配 /// /// /// public async Task> GetListBySourceBillNo(List sourcebillNos) { - List ids = new List(); - string str=$"SELECT Fid FROM t_erp_outstock_task_details WHERE "; - for (int i=0;i s.Id).ToListAsync(); - var entitys = await _context.OutStockTask - .Include(s => s.Details) - .Where(w => ids.Contains(w.Id)) + .Include(s => s.Details).ThenInclude(s => s.ErpDetails) + .Where(w => w.Details.SelectMany(s => s.ErpDetails).Where(wd => sourcebillNos.Contains(wd.SourceBillNo)).Any()) .OrderByDescending(o => o.Id) .ToListAsync(); @@ -436,12 +421,9 @@ namespace WMS.Web.Repositories public async Task> GetOutStockTaskNosByNo(string billNo) { - List ids = new List(); - ids = await _context.OutStockTaskDetails.FromSqlRaw($"SELECT Fid FROM t_erp_outstock_task_details WHERE SourceBillNo like '%{billNo}%'").Select(s => s.Id).ToListAsync(); - - return await _context.OutStockTask.Include(x => x.Details) + return await _context.OutStockTask.Include(x => x.Details).ThenInclude(s => s.ErpDetails) .Where(f => (EF.Functions.Like(f.BillNo, "%" + billNo + "%") || - ids.Contains(f.Id)) && + f.Details.SelectMany(s => s.ErpDetails).Where(w => EF.Functions.Like(w.SourceBillNo, "%" + billNo + "%")).Any()) && (f.Status == OutStockStatus.Part || f.Status == OutStockStatus.Wait)) .OrderByDescending(o => o.Id) .Select(s => s.BillNo) @@ -458,11 +440,16 @@ namespace WMS.Web.Repositories { return await GetListAsync(dto); } - + /// + /// 根据订单号精确搜索 + /// + /// + /// public async Task> GetListByBillNo(List billNos) { var entitys = await _context.OutStockTask .Include(s => s.Details) + .ThenInclude(s => s.ErpDetails) .Where(w => billNos.Contains(w.BillNo)) .OrderByDescending(o => o.Id) .ToListAsync();