diff --git a/.vs/WMS.Web/DesignTimeBuild/.dtbcache.v2 b/.vs/WMS.Web/DesignTimeBuild/.dtbcache.v2 index 0def82f7..c6848a43 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/wwwroot/WMS.Web.Domain.xml b/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml index a0167415..c4ffb2ac 100644 --- a/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml +++ b/src/WMS.Web.Api/wwwroot/WMS.Web.Domain.xml @@ -1093,6 +1093,11 @@ + + + erp删单 作废处理 + + erp入库任务单的对应box箱信息表 @@ -1955,6 +1960,11 @@ + + + erp删单 作废处理 + + erp出库任务单明细 @@ -3133,6 +3143,9 @@ + + 查询实体集合 + 库存相关-仓储接口 @@ -3303,6 +3316,9 @@ 查询实体集合 + + 查询实体集合 + 查询实体集合(明细Id) @@ -3698,6 +3714,12 @@ + + + 金蝶删单后这边单据作废 + + + 作废 @@ -4014,84 +4036,84 @@ - + erp:单据查询-采购入库单 - + erp:单据查询-其他入库单 - + erp:单据查询-直接调拨入库单 - + erp:单据查询-分步式调入单 - + erp:单据查询-组装拆卸单-组装(成品入库) - + erp:单据查询-组装拆卸单-拆卸(子件入库) - + erp:单据查询-出库单 - + erp:单据查询-直接调拨出库 - + erp:单据查询-分布式调出 - + erp:单据查询-组装拆卸单(拆卸 主出) - + erp:单据查询-组装拆卸单(组装 子出) - + erp:单据查询-其他出库 - + erp:单据查询-销售出库单 @@ -4289,6 +4311,12 @@ + + + 金蝶删单后这边单据作废 + + + 查询出库任务单详情 @@ -5402,6 +5430,21 @@ + + + 金蝶删单后wms单据作废 + + + + + + + + 获取金蝶数据 + + + + 即时库存-服务 @@ -5597,6 +5640,20 @@ + + + 金蝶删单后wms单据作废 + + + + + + + 获取金蝶数据 + + + + 同步erp基础数据 @@ -5792,7 +5849,7 @@ - + erp:单据查询-采购入库单 @@ -5800,35 +5857,35 @@ 单据编号集合精确查找 - + erp:单据查询-其他入库单 - + erp:单据查询-直接调拨入库单 - + erp:单据查询-分步式调入单 - + erp:单据查询-组装拆卸单-组装(成品入库) - + erp:单据查询-组装拆卸单-拆卸(子件入库) @@ -5953,42 +6010,42 @@ - + 直接调拨出库 - + 分布式调出 - + 组装拆卸单 (拆卸 主出) - + 其他出库 - + 组装拆卸单 (组装 子出) - + 销售出库单 diff --git a/src/WMS.Web.Domain/Entitys/InstockTask.cs b/src/WMS.Web.Domain/Entitys/InstockTask.cs index 06409c78..e2d05671 100644 --- a/src/WMS.Web.Domain/Entitys/InstockTask.cs +++ b/src/WMS.Web.Domain/Entitys/InstockTask.cs @@ -12,7 +12,7 @@ namespace WMS.Web.Domain.Entitys /// erp入库任务表 /// [Serializable] - [Table("t_erp_instock_task")] + [Table("t_erp_instock_task")] public class InStockTask : EntityBase { /// @@ -91,7 +91,7 @@ namespace WMS.Web.Domain.Entitys /// /// 明细 /// - public List Details { get; set; } + public List Details { get; set; } /// /// 创建 @@ -99,7 +99,7 @@ namespace WMS.Web.Domain.Entitys /// /// /// - public void Create(InstockType type,string sourceBillNo, DateTime createTime,int supplierId,string orgCode) + public void Create(InstockType type, string sourceBillNo, DateTime createTime, int supplierId, string orgCode) { if (type == InstockType.Purchase) this.Status = InstockStatus.Wait; @@ -115,10 +115,10 @@ namespace WMS.Web.Domain.Entitys /// /// 作废 /// - public void Repeal(int repealerId,List detailsIds) + public void Repeal(int repealerId, List detailsIds) { this.RepealerId = repealerId; - this.RepealTime= DateTime.Now; + this.RepealTime = DateTime.Now; //明细行作废 this.Details.Where(x => detailsIds.Contains(x.Id)).ToList().ForEach(x => { x.IsRepeal = true; }); @@ -181,7 +181,7 @@ namespace WMS.Web.Domain.Entitys } //改变状态 - public void ChangeInstockStatus() + public void ChangeInstockStatus() { //明细中:所有的应入数量之和 var totalAccruedQty = this.Details.Where(x => x.IsRepeal != true).Sum(x => x.AccruedQty); @@ -194,9 +194,9 @@ namespace WMS.Web.Domain.Entitys if (totalAccruedQty <= totalRealityQty) this.Status = InstockStatus.Already; - else if(totalReceiveQty<= 0 && this.Type == InstockType.Purchase) + else if (totalReceiveQty <= 0 && this.Type == InstockType.Purchase) this.Status = InstockStatus.Wait; - else if(totalRealityQty<=0) + else if (totalRealityQty <= 0) this.Status = InstockStatus.WaitInStock; else this.Status = InstockStatus.Part; @@ -218,7 +218,7 @@ namespace WMS.Web.Domain.Entitys /// 非采购上架 /// /// - public void NoPurchaseShelf(int creatorId) + public void NoPurchaseShelf(int creatorId) { this.ChangeInstockStatus(); this.ReceiverId = creatorId; @@ -226,5 +226,17 @@ namespace WMS.Web.Domain.Entitys this.ShelferId = creatorId; this.ShelfTime = DateTime.Now; } + /// + /// erp删单 作废处理 + /// + public void ErpDel() + { + foreach (var d in this.Details) + { + d.AccruedQty = 0; + d.IsRepeal = true; + } + this.Status = InstockStatus.Repeal; + } } } diff --git a/src/WMS.Web.Domain/Entitys/OutStockTask.cs b/src/WMS.Web.Domain/Entitys/OutStockTask.cs index 71ac6713..e12214d9 100644 --- a/src/WMS.Web.Domain/Entitys/OutStockTask.cs +++ b/src/WMS.Web.Domain/Entitys/OutStockTask.cs @@ -1,4 +1,5 @@ -using System; +using Npoi.Mapper; +using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations.Schema; using System.Linq; @@ -292,5 +293,21 @@ namespace WMS.Web.Domain.Entitys return Result.ReSuccess(); } + /// + /// erp删单 作废处理 + /// + public void ErpDel(string sourceBillNo) + { + foreach (var d in this.Details) + { + d.ErpDetails.Where(w => w.SourceBillNo.Equals(sourceBillNo)).ForEach(f => f.AccruedQty = 0); + + d.AccruedQty = d.ErpDetails.Sum(s => s.AccruedQty); + if (d.AccruedQty <= 0) d.IsRepeal = true; + } + //明细都作废后 整个单据作废 + if (this.Details.Count() == this.Details.Where(w => w.IsRepeal == true).Count()) + this.Status = OutStockStatus.Repeal; + } } } diff --git a/src/WMS.Web.Domain/IService/IInStockTaskService.cs b/src/WMS.Web.Domain/IService/IInStockTaskService.cs index 4c2a8590..b46b9490 100644 --- a/src/WMS.Web.Domain/IService/IInStockTaskService.cs +++ b/src/WMS.Web.Domain/IService/IInStockTaskService.cs @@ -66,7 +66,11 @@ namespace WMS.Web.Domain.IService /// /// Task Sysn(List billNos = null); - + /// + /// 金蝶删单后这边单据作废 + /// + /// + Task ErpDel(DateTime begin); /// /// 作废 /// diff --git a/src/WMS.Web.Domain/IService/Public/IOutStockTaskService.cs b/src/WMS.Web.Domain/IService/Public/IOutStockTaskService.cs index 755f07e2..f83af859 100644 --- a/src/WMS.Web.Domain/IService/Public/IOutStockTaskService.cs +++ b/src/WMS.Web.Domain/IService/Public/IOutStockTaskService.cs @@ -61,6 +61,11 @@ namespace WMS.Web.Domain.IService.Public /// Task Sync(List billNos = null,DateTime? begin=null); /// + /// 金蝶删单后这边单据作废 + /// + /// + Task ErpDel(DateTime begin); + /// /// 查询出库任务单详情 /// /// diff --git a/src/WMS.Web.Domain/Infrastructure/IInStockTaskRepositories.cs b/src/WMS.Web.Domain/Infrastructure/IInStockTaskRepositories.cs index 8701be5f..5d6e4140 100644 --- a/src/WMS.Web.Domain/Infrastructure/IInStockTaskRepositories.cs +++ b/src/WMS.Web.Domain/Infrastructure/IInStockTaskRepositories.cs @@ -148,5 +148,7 @@ namespace WMS.Web.Domain.Infrastructure /// /// Task Update(InStockTask entity, bool isTransaction = true); + /// 查询实体集合 + Task> GetEntityList(DateTime begin); } } diff --git a/src/WMS.Web.Domain/Infrastructure/IOutStockTaskRepositories.cs b/src/WMS.Web.Domain/Infrastructure/IOutStockTaskRepositories.cs index 15a1ee6e..03a293c6 100644 --- a/src/WMS.Web.Domain/Infrastructure/IOutStockTaskRepositories.cs +++ b/src/WMS.Web.Domain/Infrastructure/IOutStockTaskRepositories.cs @@ -22,6 +22,8 @@ namespace WMS.Web.Domain.Infrastructure Task<(List list, int total)> GetListAsync(OutStockTaskQueryRequest dto, int companyId = 0); /// 查询实体集合 Task> GetEntityList(List ids); + /// 查询实体集合 + Task> GetEntityList(DateTime begin); /// 查询实体集合(明细Id) Task> GetEntityListByDetailIds(List ids); /// diff --git a/src/WMS.Web.Domain/QuartzJob/InStockOrderQuartzJob.cs b/src/WMS.Web.Domain/QuartzJob/InStockOrderQuartzJob.cs index 5c210423..513b0634 100644 --- a/src/WMS.Web.Domain/QuartzJob/InStockOrderQuartzJob.cs +++ b/src/WMS.Web.Domain/QuartzJob/InStockOrderQuartzJob.cs @@ -5,6 +5,7 @@ using Microsoft.Extensions.Options; using Quartz; using System; using System.Collections.Generic; +using System.Drawing; using System.Text; using System.Threading.Tasks; using WMS.Web.Core.Internal.Results; @@ -12,6 +13,7 @@ using WMS.Web.Domain.Infrastructure; using WMS.Web.Domain.IService; using WMS.Web.Domain.IService.Public; using WMS.Web.Domain.Options; +using WMS.Web.Domain.Services; namespace WMS.Web.Domain.QuartzJob { @@ -63,6 +65,9 @@ namespace WMS.Web.Domain.QuartzJob var enddatetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); _logger.LogInformation($"同步金蝶入库单数据:执行结束时间->{begindatetime}"); + DateTime begin = DateTime.Now.AddHours(-8);//默认拉去8个小时以内的 + //验证金蝶是否有删单 + await _inStockTaskService.ErpDel(begin); } catch (Exception ex) { @@ -71,6 +76,6 @@ namespace WMS.Web.Domain.QuartzJob } - + } } diff --git a/src/WMS.Web.Domain/QuartzJob/OutStockOrderQuartzJob.cs b/src/WMS.Web.Domain/QuartzJob/OutStockOrderQuartzJob.cs index 131d3ef7..49eabd36 100644 --- a/src/WMS.Web.Domain/QuartzJob/OutStockOrderQuartzJob.cs +++ b/src/WMS.Web.Domain/QuartzJob/OutStockOrderQuartzJob.cs @@ -54,6 +54,8 @@ namespace WMS.Web.Domain.QuartzJob //5.记录:结束时间 var enddatetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); _logger.LogInformation($"出库单-同步金蝶出库单数据:执行结束时间->{enddatetime}"); + //验证金蝶是否有删单 + await _outStockTaskService.ErpDel(begin); } catch (Exception ex) diff --git a/src/WMS.Web.Domain/Services/InStockTaskService.cs b/src/WMS.Web.Domain/Services/InStockTaskService.cs index 76b7a25b..3dfd7a1b 100644 --- a/src/WMS.Web.Domain/Services/InStockTaskService.cs +++ b/src/WMS.Web.Domain/Services/InStockTaskService.cs @@ -11,6 +11,7 @@ using System.Threading.Tasks; using WMS.Web.Core; using WMS.Web.Core.Dto; using WMS.Web.Core.Dto.Erp; +using WMS.Web.Core.Dto.Erp.OutStock; using WMS.Web.Core.Dto.InStockTask; using WMS.Web.Core.Dto.Login; using WMS.Web.Core.Internal.Results; @@ -699,5 +700,111 @@ namespace WMS.Web.Domain.Services return Result.ReSuccess(); } + /// + /// 金蝶删单后wms单据作废 + /// + /// + /// + /// + public async Task ErpDel(DateTime begin) + { + var list = await _inStockTaskRepositories.GetEntityList(begin); + var result = await GetData(list); + if (!result.IsSuccess) return Result.ReFailure(result.Message, result.Status); + var erp_list = result.Data; + List update_list = new List(); + //处理数据 因为入库任务单和出库任务单结构不一样 没有合并的单据 所以处理不同 + foreach (var entity in list) + { + //判断是否在erp数据池里 + int count = erp_list.Where(w => w.BillNo.Equals(entity.SourceBillNo)).Count(); + if (count > 0) continue; + //如果不在数据池里 被删除了 那么需要把订单作废 + entity.ErpDel(); + _logger.LogInformation($"入库任务单 金蝶未找到单据:{entity.SourceBillNo} wms订单号:{entity.BillNo} 作废来源单号:{entity.SourceBillNo}"); + if (update_list.FirstOrDefault(f => f.Id == entity.Id) == null) + update_list.Add(entity); + + } + if (update_list.Count() <= 0) return Result.ReSuccess(); + + var isSuccess = await _inStockTaskRepositories.UpdateRange(update_list, true); + if (!isSuccess) + return Result.ReFailure(ResultCodes.DateWriteError); + + return Result.ReSuccess(); + } + /// + /// 获取金蝶数据 + /// + /// + /// + public async Task>> GetData(List list) + { + List erp_list = new List(); + List Instock_sourceBillNos = new List(); + List Miscellaneous_sourceBillNos = new List(); + List TransferDirect_sourceBillNos = new List(); + List Transferin_sourceBillNos = new List(); + List AssembledApp_sourceBillNos = new List(); + + foreach (var entity in list) + { + if (entity.Type == InstockType.Purchase) + Instock_sourceBillNos.Add(entity.SourceBillNo); + else if (entity.Type == InstockType.Stkdirecttransfers) + TransferDirect_sourceBillNos.Add(entity.SourceBillNo); + else if (entity.Type == InstockType.StktransferInst) + Transferin_sourceBillNos.Add(entity.SourceBillNo); + else if (entity.Type == InstockType.Assembled) + AssembledApp_sourceBillNos.Add(entity.SourceBillNo); + else if (entity.Type == InstockType.Miscellaneous) + Miscellaneous_sourceBillNos.Add(entity.SourceBillNo); + } + + if (Instock_sourceBillNos.Count() > 0) + { + var erp_result = await _erpService.BillQueryForPurchaseInStock(Instock_sourceBillNos, null); + if (!erp_result.IsSuccess) + return Result>.ReFailure(erp_result.Message, erp_result.Status); + erp_list.AddRange(erp_result.Data); + } + if (Miscellaneous_sourceBillNos.Count() > 0) + { + var erp_result = await _erpService.BillQueryForMiscellaneous(Miscellaneous_sourceBillNos, null); + if (!erp_result.IsSuccess) + return Result>.ReFailure(erp_result.Message, erp_result.Status); + erp_list.AddRange(erp_result.Data); + } + if (TransferDirect_sourceBillNos.Count() > 0) + { + var erp_result = await _erpService.BillQueryForTransferDirect(TransferDirect_sourceBillNos, null); + if (!erp_result.IsSuccess) + return Result>.ReFailure(erp_result.Message, erp_result.Status); + erp_list.AddRange(erp_result.Data); + } + if (Transferin_sourceBillNos.Count() > 0) + { + var erp_result = await _erpService.BillQueryForTransferin(Transferin_sourceBillNos, null); + if (!erp_result.IsSuccess) + return Result>.ReFailure(erp_result.Message, erp_result.Status); + erp_list.AddRange(erp_result.Data); + } + if (AssembledApp_sourceBillNos.Count() > 0) + { + var erp_result_ass = await _erpService.BillQueryForAssembledApp_Assembly(AssembledApp_sourceBillNos, null); + if (!erp_result_ass.IsSuccess) + return Result>.ReFailure(erp_result_ass.Message, erp_result_ass.Status); + erp_list.AddRange(erp_result_ass.Data); + + //1.1.获取金蝶数据:拆卸子件入库订单数据 + var erp_result_disass = await _erpService.BillQueryForAssembledApp_Disassembly(AssembledApp_sourceBillNos, null); + if (!erp_result_disass.IsSuccess) + return Result>.ReFailure(erp_result_disass.Message, erp_result_disass.Status); + + erp_list.AddRange(erp_result_disass.Data); + } + return Result>.ReSuccess(erp_list); + } } } diff --git a/src/WMS.Web.Domain/Services/OutStockTaskService.cs b/src/WMS.Web.Domain/Services/OutStockTaskService.cs index 5ab4e865..a43bfbff 100644 --- a/src/WMS.Web.Domain/Services/OutStockTaskService.cs +++ b/src/WMS.Web.Domain/Services/OutStockTaskService.cs @@ -641,5 +641,113 @@ namespace WMS.Web.Domain.Services throw ex; } } + /// + /// 金蝶删单后wms单据作废 + /// + /// + /// + public async Task ErpDel(DateTime begin) + { + var list = await _outStockTaskRepositories.GetEntityList(begin); + var result = await GetData(list); + if (!result.IsSuccess) return Result.ReFailure(result.Message, result.Status); + var erp_list = result.Data; + List update_list = new List(); + //处理数据 + foreach (var entity in list) + { + //合并单有多个来源订单 + var nos = entity.Details.SelectMany(s => s.ErpDetails).Select(s => s.SourceBillNo).ToList(); + foreach (var no in nos) + { + //判断是否在erp数据池里 + int count = erp_list.Where(w => w.SourceBillNo.Equals(no)).Count(); + if (count > 0) continue; + //如果不在数据池里 被删除了 那么需要把订单作废 + entity.ErpDel(no); + _logger.LogInformation($"出库任务单 金蝶未找到单据:{no} wms订单号:{entity.BillNo} 作废来源单号:{no}"); + if (update_list.FirstOrDefault(f => f.Id == entity.Id) == null) + update_list.Add(entity); + } + } + if (update_list.Count() <= 0) return Result.ReSuccess(); + + var isSuccess = await _outStockTaskRepositories.EditEntityList(update_list, true); + if (!isSuccess) + return Result.ReFailure(ResultCodes.DateWriteError); + + return Result.ReSuccess(); + } + /// + /// 获取金蝶数据 + /// + /// + /// + public async Task>> GetData(List list) + { + List erp_list = new List(); + //根据指定单号更新 + List SalOutStock_Nos = new List(); + List TransferDirect_Nos = new List(); + List TransferOut_Nos = new List(); + List AssembledApp_Nos = new List(); + List MisDeliveryOut_Nos = new List(); + foreach (var entity in list) + { + if (entity.Type == OutStockType.Sal) + SalOutStock_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.ErpDetails).Select(s => s.SourceBillNo)); + else if (entity.Type == OutStockType.StktransferInst) + 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.ErpDetails).Select(s => s.SourceBillNo)); + else if (entity.Type == OutStockType.Miscellaneous) + MisDeliveryOut_Nos.AddRange(entity.Details.SelectMany(s => s.ErpDetails).Select(s => s.SourceBillNo)); + } + + if (SalOutStock_Nos.Count() > 0) + { + var erp_result = await _erpService.BillQueryForSalOutStock(SalOutStock_Nos, null); + if (!erp_result.IsSuccess) + return Result>.ReFailure(erp_result.Message, erp_result.Status); + erp_list.AddRange(erp_result.Data); + } + if (TransferDirect_Nos.Count() > 0) + { + var erp_result = await _erpService.BillQueryForTransferDirectOutStock(TransferDirect_Nos, null); + if (!erp_result.IsSuccess) + return Result>.ReFailure(erp_result.Message, erp_result.Status); + erp_list.AddRange(erp_result.Data); + } + if (TransferOut_Nos.Count() > 0) + { + var erp_result = await _erpService.BillQueryForTransferOutOutStock(TransferOut_Nos, null); + if (!erp_result.IsSuccess) + return Result>.ReFailure(erp_result.Message, erp_result.Status); + erp_list.AddRange(erp_result.Data); + } + if (AssembledApp_Nos.Count() > 0) + { + var erp_result = await _erpService.BillQueryForAssembledAppOutStock_Dassembly(AssembledApp_Nos, null); + if (!erp_result.IsSuccess) + return Result>.ReFailure(erp_result.Message, erp_result.Status); + erp_list.AddRange(erp_result.Data); + + var erp_result_a = await _erpService.BillQueryForAssembledAppOutStock_Assembly(AssembledApp_Nos, null); + if (!erp_result_a.IsSuccess) + return Result>.ReFailure(erp_result_a.Message, erp_result_a.Status); + erp_list.AddRange(erp_result_a.Data); + } + if (MisDeliveryOut_Nos.Count() > 0) + { + var erp_result = await _erpService.BillQueryForMisDeliveryOutStock(MisDeliveryOut_Nos, null); + if (!erp_result.IsSuccess) + return Result>.ReFailure(erp_result.Message, erp_result.Status); + erp_list.AddRange(erp_result.Data); + } + + return Result>.ReSuccess(erp_list); + } } } diff --git a/src/WMS.Web.Repositories/InStockTaskRepositories.cs b/src/WMS.Web.Repositories/InStockTaskRepositories.cs index 431f641d..ec07b711 100644 --- a/src/WMS.Web.Repositories/InStockTaskRepositories.cs +++ b/src/WMS.Web.Repositories/InStockTaskRepositories.cs @@ -828,5 +828,15 @@ namespace WMS.Web.Repositories return (list, total); } + + public async Task> GetEntityList(DateTime begin) + { + var res = await _context.InStockTask + .Include(s => s.Details) + .Where(f => f.WmsUpdateTime >= begin) + .ToListAsync(); + + return res.Clone(); + } } } diff --git a/src/WMS.Web.Repositories/OutStockTaskRepositories.cs b/src/WMS.Web.Repositories/OutStockTaskRepositories.cs index d0852250..fe56258f 100644 --- a/src/WMS.Web.Repositories/OutStockTaskRepositories.cs +++ b/src/WMS.Web.Repositories/OutStockTaskRepositories.cs @@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Storage; using Microsoft.Extensions.Logging; using Newtonsoft.Json; +using Org.BouncyCastle.Crypto; using System; using System.Collections.Generic; using System.Linq; @@ -566,5 +567,14 @@ namespace WMS.Web.Repositories return entitys.Clone(); } + public async Task> GetEntityList(DateTime begin) + { + var res = await _context.OutStockTask + .Include(s => s.Details).ThenInclude(s => s.ErpDetails) + .Where(f => f.WmsUpdateTime >= begin) + .ToListAsync(); + + return res.Clone(); + } } }