diff --git a/src/WMS.Web.Core/Dto/Erp/OutStock/ErpDeliveryNoticeOutStockResultDto.cs b/src/WMS.Web.Core/Dto/Erp/OutStock/ErpDeliveryNoticeOutStockResultDto.cs index e5ab45bd..bbdcecd1 100644 --- a/src/WMS.Web.Core/Dto/Erp/OutStock/ErpDeliveryNoticeOutStockResultDto.cs +++ b/src/WMS.Web.Core/Dto/Erp/OutStock/ErpDeliveryNoticeOutStockResultDto.cs @@ -49,5 +49,9 @@ namespace WMS.Web.Core.Dto.Erp.OutStock /// 创建时间(erp那边的创建时间) /// public DateTime? CreateTime { get; set; } + /// + /// 用来自动构建单据类型 跟OutStockType 一致 + /// + public int Type { get; set; } } } diff --git a/src/WMS.Web.Domain/Entitys/OutStock.cs b/src/WMS.Web.Domain/Entitys/OutStock.cs index a7b84333..a97e9301 100644 --- a/src/WMS.Web.Domain/Entitys/OutStock.cs +++ b/src/WMS.Web.Domain/Entitys/OutStock.cs @@ -44,7 +44,7 @@ namespace WMS.Web.Domain.Entitys /// 单据类型 /// [Column("Type")] - public OrderType Type { get; set; } = OrderType.Sal_Out; + public OutStockType Type { get; set; } = OutStockType.Sal; /// /// 发货组织 /// @@ -78,7 +78,7 @@ namespace WMS.Web.Domain.Entitys /// 创建 /// /// - public void Create(int creatorId,int taskId, OrderType type) + public void Create(int creatorId,int taskId, OutStockType type) { this.TaskId = taskId; this.Type = type; diff --git a/src/WMS.Web.Domain/Entitys/OutStockTask.cs b/src/WMS.Web.Domain/Entitys/OutStockTask.cs index 7a59aebc..26451462 100644 --- a/src/WMS.Web.Domain/Entitys/OutStockTask.cs +++ b/src/WMS.Web.Domain/Entitys/OutStockTask.cs @@ -51,7 +51,7 @@ namespace WMS.Web.Domain.Entitys /// 单据类型 /// [Column("Type")] - public OrderType Type { get; set; } = OrderType.Sal_Out; + public OutStockType Type { get; set; } = OutStockType.Sal; /// /// 操作人(出库人) /// @@ -71,6 +71,14 @@ namespace WMS.Web.Domain.Entitys /// 明细 /// public List Details = new List(); + public void Create(OutStockType type, string sourceBillNo, int deliveryOrgId, int receiptCustomerId, DateTime createTime) + { + this.Type = type; + this.SourceBillNo = sourceBillNo; + this.DeliveryOrgId = deliveryOrgId; + this.ReceiptCustomerId = receiptCustomerId; + this.CreateTime = createTime; + } /// /// 生成单据号 /// @@ -114,7 +122,7 @@ namespace WMS.Web.Domain.Entitys { // 符合合并数据逻辑:出库状态为”待拣货”+出库类型为:销售出库+发货组织一致+收货客户一致+发货仓库一致 if (list.Where(w => w.Status != OutStockStatus.Wait).Any()) return Result.ReFailure(ResultCodes.MergeStatusError); - if (list.Where(w => w.Type != OrderType.Sal_Out).Any()) return Result.ReFailure(ResultCodes.MergeStatusError); + if (list.Where(w => w.Type != OutStockType.Sal).Any()) return Result.ReFailure(ResultCodes.MergeStatusError); if (list.GroupBy(g => g.DeliveryOrgId).Count() > 1) return Result.ReFailure(ResultCodes.MergeStatusError); if (list.GroupBy(g => g.ReceiptCustomerId).Count() > 1) return Result.ReFailure(ResultCodes.MergeStatusError); @@ -131,7 +139,7 @@ namespace WMS.Web.Domain.Entitys this.OperatorId = creatorId; this.OperateTime = DateTime.Now; this.Status = OutStockStatus.Wait; - this.Type = OrderType.Sal_Out; + this.Type = OutStockType.Sal; this.Details = details; return Result.ReSuccess(); diff --git a/src/WMS.Web.Domain/IService/Public/IOutStockTaskService.cs b/src/WMS.Web.Domain/IService/Public/IOutStockTaskService.cs index d595171d..2ef222e7 100644 --- a/src/WMS.Web.Domain/IService/Public/IOutStockTaskService.cs +++ b/src/WMS.Web.Domain/IService/Public/IOutStockTaskService.cs @@ -18,7 +18,7 @@ namespace WMS.Web.Domain.IService.Public /// /// /// - Task SsynDeliveryNoticeOutStock(bool isTransaction); + Task SsynDeliveryNoticeOutStock(bool isTransaction,List sourceBillNos = null); //出库任务作废 Task Repeal(OperateRequest dto, LoginInDto loginInfo); //出库任务作废 diff --git a/src/WMS.Web.Domain/Infrastructure/IOutStockTaskRepositories.cs b/src/WMS.Web.Domain/Infrastructure/IOutStockTaskRepositories.cs index e56baac5..811a8b26 100644 --- a/src/WMS.Web.Domain/Infrastructure/IOutStockTaskRepositories.cs +++ b/src/WMS.Web.Domain/Infrastructure/IOutStockTaskRepositories.cs @@ -11,10 +11,23 @@ namespace WMS.Web.Domain.Infrastructure { // 新增 Task Add(OutStockTask entity, bool isTransaction = true); + /// + /// 批量添加 + /// + /// + /// + /// + Task AddRange(List entitys, bool isTransaction = true); // 获取列表 Task<(List list, int total)> GetListAsync(OutStockTaskQueryRequest dto); /// 查询实体集合 Task> GetEntityList(List ids); + /// + /// 列表-根据明细中的来源单号 + /// + /// + /// + Task> GetListBySourceBillNo(List sourceBillNos); /// 修改实体集合 Task EditEntityList(List entitys, bool isTransaction = true); //编辑 diff --git a/src/WMS.Web.Domain/Mappers/OutStockMapper.cs b/src/WMS.Web.Domain/Mappers/OutStockMapper.cs index 042de07d..94d4b627 100644 --- a/src/WMS.Web.Domain/Mappers/OutStockMapper.cs +++ b/src/WMS.Web.Domain/Mappers/OutStockMapper.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Text; +using WMS.Web.Core.Dto.Erp.OutStock; using WMS.Web.Core.Dto.OutStock; using WMS.Web.Core.Dto.OutStockTask; using WMS.Web.Domain.Entitys; @@ -22,6 +23,8 @@ namespace WMS.Web.Domain.Mappers CreateMap(); CreateMap(); + + CreateMap(); } } } diff --git a/src/WMS.Web.Domain/Services/OutStockTaskService.cs b/src/WMS.Web.Domain/Services/OutStockTaskService.cs index edb11381..727b193b 100644 --- a/src/WMS.Web.Domain/Services/OutStockTaskService.cs +++ b/src/WMS.Web.Domain/Services/OutStockTaskService.cs @@ -6,6 +6,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using WMS.Web.Core.Dto; +using WMS.Web.Core.Dto.Erp.OutStock; using WMS.Web.Core.Dto.Erp.Purchase; using WMS.Web.Core.Dto.Login; using WMS.Web.Core.Internal.Results; @@ -20,7 +21,7 @@ namespace WMS.Web.Domain.Services /// /// 出库任务 /// - public class OutStockTaskService: IOutStockTaskService + public class OutStockTaskService : IOutStockTaskService { private readonly IMapper _mapper; private readonly IErpService _erpService; @@ -85,20 +86,86 @@ namespace WMS.Web.Domain.Services return Result.ReSuccess(); } + + /// + /// erp数据转化wms 执行数据库操作 + /// + /// + /// + /// + public async Task SsynDate(List erp_list, bool isTransaction) + { + //2.通过单据编号找到wms系统现有的任务单;并修改 + var erp_removeList = new List(); + var SourceBillNo_list = erp_list.GroupBy(x => x.SourceBillNo).Select(x => x.Key).ToList(); + var data_list = await _outStockTaskRepositories.GetListBySourceBillNo(SourceBillNo_list); + if (data_list.Count != 0) + { + //2.1提取出wms任务单明细信息 + foreach (var e in erp_list) + { + //代表单据已经存在 那么就对单据进行修改 + var data = data_list.FirstOrDefault(f => f.SourceBillNo == e.SourceBillNo); + var detail = data.Details.FirstOrDefault(w => w.MaterialId == e.MaterialId); + //存在就修改,没有就添加 + if (detail != null) + detail.AccruedQty = e.AccruedQty; + else + data.Details.Add(_mapper.Map(e)); + + erp_removeList.Add(e); + } + //2.2.提交修改 + var isSuccess = await _outStockTaskRepositories.EditEntityList(data_list, isTransaction); + if (!isSuccess) + return Result.ReFailure(ResultCodes.DateWriteError); + + //2.3剔除:已修改的单据 + foreach (var item in erp_removeList) + erp_list.Remove(item); + + //3.wms任务单的来源单据编号不存在于erp中,那么就新增 + if (erp_list.Count != 0) + { + var add_entitys = new List(); + var billNos = erp_list.GroupBy(x => x.SourceBillNo).Select(x => x.Key).ToList(); + foreach (var item in billNos) + { + var e = erp_list.FirstOrDefault(f => f.SourceBillNo == item); + var dto = new OutStockTask(); + dto.SourceBillNo = e.SourceBillNo; + dto.Create((OutStockType)e.Type, e.SourceBillNo, e.DeliveryOrgId, e.ReceiptCustomerId, (DateTime)e.CreateTime); + + //找到当前对应来源单据编号的集合数据 + var current_erp_details = erp_list.Where(x => x.SourceBillNo == item).ToList(); + //给到dto的实体明细中 + dto.Details = _mapper.Map>(current_erp_details); + add_entitys.Add(dto); + } + //3.1提交新增 + isSuccess = await _outStockTaskRepositories.AddRange(add_entitys, isTransaction); + if (!isSuccess) + return Result.ReFailure(ResultCodes.DateWriteError); + } + + } + + return Result.ReSuccess(); + } + /// /// 发货通知单同步数据 /// /// /// - public async Task SsynDeliveryNoticeOutStock(bool isTransaction) + public async Task SsynDeliveryNoticeOutStock(bool isTransaction, List sourceBillNos = null) { //1.获取金蝶数据:采购订单数据 - var erp_result = await _erpService.BillQueryForPurchaseInStock(); + var erp_result = await _erpService.BillQueryForDeliveryNoticeOutStock(sourceBillNos); if (!erp_result.IsSuccess) return Result.ReFailure(erp_result.Message, erp_result.Status); - var erp_list = erp_result.Data; - return Result.ReSuccess(); + return await this.SsynDate(erp_result.Data.ToList(), isTransaction); } } } diff --git a/src/WMS.Web.Domain/Services/Public/ErpService.cs b/src/WMS.Web.Domain/Services/Public/ErpService.cs index 4e789263..7efc9431 100644 --- a/src/WMS.Web.Domain/Services/Public/ErpService.cs +++ b/src/WMS.Web.Domain/Services/Public/ErpService.cs @@ -424,6 +424,7 @@ namespace WMS.Web.Domain.Services.Public lis.AccruedQty = Convert.ToDecimal(item[7]); lis.Remark = item[8]; lis.CreateTime = Convert.ToDateTime(item[9]); + lis.Type = (int)OutStockType.Sal; erp_list.Add(lis); } return ResultList.ReSuccess(erp_list); diff --git a/src/WMS.Web.Repositories/OutStockTaskRepositories.cs b/src/WMS.Web.Repositories/OutStockTaskRepositories.cs index d37eb6f3..1651f5e2 100644 --- a/src/WMS.Web.Repositories/OutStockTaskRepositories.cs +++ b/src/WMS.Web.Repositories/OutStockTaskRepositories.cs @@ -225,7 +225,7 @@ namespace WMS.Web.Repositories if (!string.IsNullOrEmpty(dto.SourceBillNo)) query = query.Where(w => EF.Functions.Like(w.order.SourceBillNo, "%" + dto.SourceBillNo + "%")); if (dto.Type != null) - query = query.Where(w => w.order.Type == (OrderType)dto.Type); + query = query.Where(w => w.order.Type == (OutStockType)dto.Type); if (dto.Status != null) query = query.Where(w => w.order.Status == (OutStockStatus)dto.Status); if (dto.DeliveryOrgId != null) @@ -273,5 +273,55 @@ namespace WMS.Web.Repositories var mIds = entity.Details.Select(s => s.MaterialId).ToList(); return response; } + /// + /// 根据来源单号搜索 + /// + /// + /// + public async Task> GetListBySourceBillNo(List sourceBillNos) + { + var entitys = await _context.OutStockTask + .Include(s => s.Details) + .Where(w => sourceBillNos.Contains(w.SourceBillNo)) + .ToListAsync(); + + return entitys.Clone(); + } + /// + /// 批量添加 + /// + /// + /// + /// + public async Task AddRange(List entitys, bool isTransaction = true) + { + IDbContextTransaction _transaction = null; + if (isTransaction) + _transaction = _context.Database.BeginTransaction(); + try + { + if (entitys != null && entitys.Count != 0) + { + await _context.OutStockTask.AddRangeAsync(entitys); + await _context.SaveChangesAsync(); + foreach (var item in entitys) + { + if (string.IsNullOrEmpty(item.BillNo)) + //自动生成单据编号 + item.GenerateNo(); + } + await _context.SaveChangesAsync(); + } + if (_transaction != null) + _transaction.Commit(); + return true; + } + catch + { + if (_transaction != null) + _transaction.Rollback(); + return false; + } + } } }