From 22428c74e4b57c87a979a8f2f199e0e8e34dbb86 Mon Sep 17 00:00:00 2001 From: wxw <Administrator@DESKTOP-5BIMHQ3> Date: 星期六, 28 六月 2025 16:48:09 +0800 Subject: [PATCH] 编写接收SAP下发入库单接口 --- Wms/Wms/Controllers/UpApiController.cs | 74 +++++++++++++++++++++++++++++++----- 1 files changed, 63 insertions(+), 11 deletions(-) diff --git a/Wms/Wms/Controllers/UpApiController.cs b/Wms/Wms/Controllers/UpApiController.cs index ffa1384..ba15e9e 100644 --- a/Wms/Wms/Controllers/UpApiController.cs +++ b/Wms/Wms/Controllers/UpApiController.cs @@ -28,6 +28,8 @@ using WMS.IBLL; using ZXing.QrCode.Internal; using System.Xml.Linq; +using WMS.IBLL.ISysServer; +using ZXing; namespace Wms.Controllers { @@ -45,11 +47,14 @@ private readonly IStockCheckServer _stockCheckSvc;//鐩樼偣鍗昐vc private readonly IProcurePlanServer _procurePlanSvc;//閲囪喘鍗昐vs private readonly IPdaAsnServer _pdaAsnServer;// PDA + private readonly IMaterialsServer _materialSvc;//鐗╂枡Svc + private readonly ICustomerServer _customerSvc;//瀹㈡埛Svc private readonly IHttpServer _http; + private string logStr = $@".\log\SAP璧嬬爜\Sap涓嬪彂鎶ユ枃" + DateTime.Now.ToString("yyyyMMdd") + ".txt"; - public UpApiController(IOptions<ApiUrlConfig> setting, IExportNoticeServer exNoticeSvc, IArrivalNoticeServer arrivalNoticeServer, IStockCheckServer stockCheckSvc, IProcurePlanServer procurePlanSvc, IPdaAsnServer pdaAsnServer, IHttpServer http) + public UpApiController(IOptions<ApiUrlConfig> setting, IExportNoticeServer exNoticeSvc, IArrivalNoticeServer arrivalNoticeServer, IStockCheckServer stockCheckSvc, IProcurePlanServer procurePlanSvc, IPdaAsnServer pdaAsnServer, IMaterialsServer materialSvc, ICustomerServer customerSvc, IHttpServer http) { _config = setting.Value; _exNoticeSvc = exNoticeSvc; @@ -57,6 +62,8 @@ _stockCheckSvc = stockCheckSvc; _procurePlanSvc = procurePlanSvc; _pdaAsnServer = pdaAsnServer; + _materialSvc = materialSvc; + _customerSvc = customerSvc; _http = http; } #endregion @@ -69,11 +76,23 @@ /// <returns></returns> [AllowAnonymous] [HttpPost] - public IActionResult CreateSku(object model) + public async Task<IActionResult> CreateSku(SapSkuInfoVm model) { + var logStr = $@".\log\SAP\鐗╂枡涓绘暟鎹笅鍙�" + DateTime.Now.ToString("yyyyMMdd") + ".txt"; try { - LogFile.SaveLogToFile($"Sap鐗╂枡涓绘暟鎹細( {model} ),", logStr); + var jsonData = JsonConvert.SerializeObject(model); + LogFile.SaveLogToFile($"Sap鐗╂枡涓绘暟鎹細( {jsonData} ),", logStr);; + + var str = await _materialSvc.AddSkuSap(model.data); + + var list = new { Success = 0, Message = "涓嬪彂鎴愬姛" }; + if (!str.Contains("0")) + { + list = new { Success = -1, Message = str }; + } + + LogFile.SaveLogToFile($"SAP鐗╂枡涓绘暟鎹笅鍙戯細( {JsonConvert.SerializeObject(list)} ),", logStr); return Ok(new { result = true, code = "1" ,message = "success" }); } catch (Exception e) @@ -90,13 +109,30 @@ /// <returns></returns> [AllowAnonymous] [HttpPost] - public IActionResult CreateCustomer(object model) + public async Task<IActionResult> CreateCustomer(SapCustomerVm model) { - + var logStr = $@".\log\SAP\瀹㈡埛渚涘簲鍟嗕富鏁版嵁鍚屾" + DateTime.Now.ToString("yyyyMMdd") + ".txt"; try { - LogFile.SaveLogToFile($"Sap瀹㈡埛淇℃伅涓绘暟鎹細( {model} ),", logStr); - return Ok(new { result = true, code = "1", message = "success" }); + var jsonData = JsonConvert.SerializeObject(model); + LogFile.SaveLogToFile($"Sap瀹㈡埛淇℃伅涓绘暟鎹細( {jsonData} ),", logStr); + + var str = await _customerSvc.AddCustomerSap(model.data); + + var list = new { Success = 0, Message = "涓嬪彂鎴愬姛" }; + if (!str.Contains("0")) + { + list = new { Success = -1, Message = str }; + + LogFile.SaveLogToFile($"瀹㈡埛渚涘簲鍟嗕富鏁版嵁鍚屾锛�( {JsonConvert.SerializeObject(list)} ),", logStr); + return Ok(new { result = false, code = "400", message = str }); + } + else + { + LogFile.SaveLogToFile($"瀹㈡埛渚涘簲鍟嗕富鏁版嵁鍚屾锛�( {JsonConvert.SerializeObject(list)} ),", logStr); + + return Ok(new { result = true, code = "1", message = "success" }); + } } catch (Exception e) { @@ -112,13 +148,29 @@ /// <returns></returns> [AllowAnonymous] [HttpPost] - public IActionResult CreateAsn(object model) + public IActionResult CreateAsn(SapAsnVm model) { - + var logStr = $@".\log\SAP\鍏ュ簱鍗曚笅鍙�" + DateTime.Now.ToString("yyyyMMdd") + ".txt"; try { - LogFile.SaveLogToFile($"Sap鍏ュ簱鍗曚笅鍙戯細( {model} ),", logStr); - return Ok(new { result = true, code = "1", message = "success" }); + var jsonData = JsonConvert.SerializeObject(model); + LogFile.SaveLogToFile($"Sap鍏ュ簱鍗曚笅鍙戯細( {jsonData} ),", logStr); + + var _result = _arrivalNoticeSvc.CreateAsn(model.data, model.@operator); + + var list = new { Success = 0, Message = "涓嬪彂鎴愬姛" }; + if (_result.Success == 0) + { + LogFile.SaveLogToFile($"瀹㈡埛渚涘簲鍟嗕富鏁版嵁鍚屾锛�( {JsonConvert.SerializeObject(list)} ),", logStr); + return Ok(new { result = true, code = "1", message = "success" }); + } + else + { + list = new { Success = -1, Message = _result.Message }; + + LogFile.SaveLogToFile($"瀹㈡埛渚涘簲鍟嗕富鏁版嵁鍚屾锛�( {JsonConvert.SerializeObject(list)} ),", logStr); + return Ok(new { result = false, code = "400", message = _result.Message }); + } } catch (Exception e) { -- Gitblit v1.8.0