From 6f1ce6c95406d03e3073925aaac1b6e1f0314ac4 Mon Sep 17 00:00:00 2001 From: tongfei <244188119@qq.com> Date: Wed, 1 Nov 2023 12:02:20 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=91=E8=9D=B6=E8=8E=B7=E5=8F=96=E9=87=87?= =?UTF-8?q?=E8=B4=AD=E5=85=A5=E5=BA=93=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/WMS.Web.Api/Controllers/TestController.cs | 35 ++++++++++++++++++- src/WMS.Web.Api/wwwroot/WMS.Web.Api.xml | 6 ++++ src/WMS.Web.Api/wwwroot/WMS.Web.Core.xml | 10 ------ .../Services/InStockTaskService.cs | 19 ++++++---- 4 files changed, 53 insertions(+), 17 deletions(-) diff --git a/src/WMS.Web.Api/Controllers/TestController.cs b/src/WMS.Web.Api/Controllers/TestController.cs index 7dd5fa5b..8a271e6b 100644 --- a/src/WMS.Web.Api/Controllers/TestController.cs +++ b/src/WMS.Web.Api/Controllers/TestController.cs @@ -2,12 +2,16 @@ using ERP; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore.Storage; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; using System.ServiceModel; using System.Threading.Tasks; +using WMS.Web.Core.Internal.Results; +using WMS.Web.Domain.Infrastructure; +using WMS.Web.Domain.IService; using WMS.Web.Domain.IService.Public; namespace WMS.Web.Api.Controllers @@ -17,9 +21,13 @@ namespace WMS.Web.Api.Controllers public class TestController : ControllerBase { private readonly IErpService _erpService; - public TestController(IErpService erpService) + private IInStockTaskService _inStockTaskService; + private ITransactionRepositories _transactionRepositories; + public TestController(IErpService erpService, IInStockTaskService inStockTaskService, ITransactionRepositories transactionRepositories) { this._erpService = erpService; + this._inStockTaskService = inStockTaskService; + this._transactionRepositories = transactionRepositories; } [HttpGet] @@ -32,5 +40,30 @@ namespace WMS.Web.Api.Controllers return ""; return JsonConvert.SerializeObject(result.Data); } + + /// + /// 测试:同步采购单的入库 + /// + /// + [HttpGet] + [Route("InStock")] + public async Task InStock() + { + //1.事务 + IDbContextTransaction _transaction = _transactionRepositories.GetTransaction(); + bool isRollback = false; + bool isTransaction = false; + + //3.同步数据 + var result = await _inStockTaskService.SsynPurchaseInStock(isTransaction); + if (!result.IsSuccess) isRollback = true; + + //4.提交事务 + var isSuccess = _transactionRepositories.CommitTransaction(isRollback, _transaction); + if (!isSuccess) + return Result.ReFailure(result.Message,result.Status); + return result; + + } } } diff --git a/src/WMS.Web.Api/wwwroot/WMS.Web.Api.xml b/src/WMS.Web.Api/wwwroot/WMS.Web.Api.xml index 966ca712..b25bce3d 100644 --- a/src/WMS.Web.Api/wwwroot/WMS.Web.Api.xml +++ b/src/WMS.Web.Api/wwwroot/WMS.Web.Api.xml @@ -282,5 +282,11 @@ + + + 测试:同步采购单的入库 + + + diff --git a/src/WMS.Web.Api/wwwroot/WMS.Web.Core.xml b/src/WMS.Web.Api/wwwroot/WMS.Web.Core.xml index 3e410cd2..82c73bc1 100644 --- a/src/WMS.Web.Api/wwwroot/WMS.Web.Core.xml +++ b/src/WMS.Web.Api/wwwroot/WMS.Web.Core.xml @@ -300,11 +300,6 @@ 目标箱子 - - - 仓库 - - 原仓位ID @@ -350,11 +345,6 @@ 物料规格型号 - - - 仓库 - - 序列号 diff --git a/src/WMS.Web.Domain/Services/InStockTaskService.cs b/src/WMS.Web.Domain/Services/InStockTaskService.cs index be692a8a..5881d71c 100644 --- a/src/WMS.Web.Domain/Services/InStockTaskService.cs +++ b/src/WMS.Web.Domain/Services/InStockTaskService.cs @@ -61,10 +61,12 @@ namespace WMS.Web.Domain.Services var data_list_details = data_list.SelectMany(x => x.Details).ToList(); foreach (var item in data_list_details) { + var data= data_list.Where(x => x.Id == item.Fid).FirstOrDefault(); + //2.1.1对比erp的物料信息 - var erp_data = erp_list.Where(x => x.FMaterialId == item.MaterialId).FirstOrDefault(); + var erp_data = erp_list.Where(x =>x.FBillNo==data.SourceBillNo && x.FMaterialId == item.MaterialId).FirstOrDefault(); if (erp_data != null) - { + { //2.1.2修改数量 item.AccruedQty = erp_data.FQty; erp_removeList.Add(erp_data); @@ -84,15 +86,20 @@ namespace WMS.Web.Domain.Services } //3.wms任务单的来源单据编号不存在于erp中,那么就新增 - if (SourceBillNo_list.Count != 0) + if (erp_list.Count != 0) { var add_entitys = new List(); - foreach (var sourceBillNo in SourceBillNo_list) + var billNos = erp_list.GroupBy(x => x.FBillNo).Select(x => x.Key).ToList(); + foreach (var item in billNos) { var dto = new InStockTask(); - dto.SourceBillNo = sourceBillNo; + dto.SourceBillNo = item; dto.Create(InstockType.Purchase); - dto.Details = _mapper.Map>(erp_list); + + //找到当前对应来源单据编号的集合数据 + var current_erp_details= erp_list.Where(x => x.FBillNo == item).ToList(); + //给到dto的实体明细中 + dto.Details = _mapper.Map>(current_erp_details); add_entitys.Add(dto); } //3.1提交新增