From 756242b5a1ca2263bcdff8b72f9f9e95836ded97 Mon Sep 17 00:00:00 2001 From: wxw <Administrator@DESKTOP-5BIMHQ3> Date: 星期五, 27 六月 2025 16:39:47 +0800 Subject: [PATCH] 增加接收物料下发接口和客户信息接收接口 --- Wms/Wms/Controllers/UpApiController.cs | 42 +++++++- Wms/WMS.BLL/SysServer/CustomerServer.cs | 41 ++++++++ Wms/WMS.IBLL/ISysServer/ICustomerServer.cs | 11 ++ Wms/WMS.BLL/SysServer/MaterialsServer.cs | 90 +++++++++++++++++ Wms/Model/InterFaceModel/HttpModel.cs | 104 ++++++++++++++++++++ Wms/WMS.IBLL/ISysServer/IMaterialsServer.cs | 12 ++ 6 files changed, 291 insertions(+), 9 deletions(-) diff --git a/Wms/Model/InterFaceModel/HttpModel.cs b/Wms/Model/InterFaceModel/HttpModel.cs index 3be3a1a..b40bde9 100644 --- a/Wms/Model/InterFaceModel/HttpModel.cs +++ b/Wms/Model/InterFaceModel/HttpModel.cs @@ -483,4 +483,108 @@ } #endregion + + #region#SAP瀹炰綋绫� + public class SapSkuInfoVm + { + public SendSkuInfoVm data { get; set; } + } + public class SendSkuInfoVm + { + /// <summary> + /// 鐗╂枡鍙� + /// </summary> + public long skuNo { get; set; } + + /// <summary> + /// 鐗╂枡鍚嶇О + /// </summary> + public string skuName { get; set; } + + /// <summary> + /// 鐗╂枡绫荤洰 + /// </summary> + public string categoryNo { get; set; } + + /// <summary> + /// 鐗╂枡绫荤洰鍚嶇О + /// </summary> + public string categoryName { get; set; } + + /// <summary> + /// 鐗╂枡瀛樻斁鍖哄煙 + /// </summary> + public string regionNo { get; set; } + + /// <summary> + /// 鏄惁鍏嶆 + /// </summary> + public int consume { get; set; } + + /// <summary> + /// 鍩烘湰鍗曚綅 + /// </summary> + public string unit { get; set; } + + /// <summary> + /// 鍖呰鏁伴噺 + /// </summary> + public decimal packageQty { get; set; } + + /// <summary> + /// 绠卞崟浣� + /// </summary> + public string packageName { get; set; } + + /// <summary> + /// 瑙勬牸 + /// </summary> + public string specification { get; set; } + + /// <summary> + /// 淇濊川鏈� + /// </summary> + public string? shelfLife { get; set; } + + /// <summary> + /// 鍑哄簱涓存湡澶╂暟 + /// </summary> + public string? remainingDays { get; set; } + } + + public class SapCustomerVm + { + public SendCustomerVm data { get; set; } + } + /// <summary> + /// 涓嬪彂鍚屾瀹㈡埛渚涘簲鍟嗘暟鎹� + /// </summary> + public class SendCustomerVm + { + /// <summary> + /// 缂栧彿 + /// </summary> + public long customerNo { get; set; } + /// <summary> + /// 鍚嶇О + /// </summary> + public string customerName { get; set; } + /// <summary> + /// 绫诲瀷 0锛氬鎴枫��1锛氫緵搴斿晢銆� + /// </summary> + public string CustomerType { get; set; } + /// <summary> + /// 鍦板潃 + /// </summary> + public string streetAddress { get; set; } + /// <summary> + /// 鑱旂郴浜� + /// </summary> + public string contact { get; set; } + /// <summary> + /// 鑱旂郴浜虹數璇� + /// </summary> + public string contactMobile { get; set; } + } + #endregion } diff --git a/Wms/WMS.BLL/SysServer/CustomerServer.cs b/Wms/WMS.BLL/SysServer/CustomerServer.cs index 0d8783c..3ffd2fb 100644 --- a/Wms/WMS.BLL/SysServer/CustomerServer.cs +++ b/Wms/WMS.BLL/SysServer/CustomerServer.cs @@ -4,8 +4,10 @@ using System.Linq.Expressions; using System.Text; using System.Threading.Tasks; +using Model.InterFaceModel; using Model.ModelDto.SysDto; using SqlSugar; +using WMS.Entity.Context; using WMS.Entity.LogEntity; using WMS.Entity.SysEntity; using WMS.IBLL.ILogServer; @@ -16,6 +18,7 @@ { public class CustomerServer : ICustomerServer { + private static readonly SqlSugarScope Db = DataContext.Db; public ICustomerRepository CustomerRst { get; set; } private readonly IOperationSysServer _operation; //鎿嶄綔鏃ュ織 public CustomerServer(ICustomerRepository customerRst, IOperationSysServer operation) @@ -23,7 +26,7 @@ CustomerRst = customerRst; _operation = operation; } - + public async Task<List<CustomerDto>> GetCustomerList(string no, string name, int? type, string linkMan, string phone, int page, int limit, RefAsync<int> count) { @@ -172,5 +175,41 @@ var num = await CustomerRst.RemoveAllAsync(list, userId); return num > 0; } + + /// <summary> + /// SAP鏂板瀹㈡埛渚涘簲鍟嗘暟鎹� + /// </summary> + /// <param name="model"></param> + /// <returns></returns> + /// <exception cref="Exception"></exception> + public async Task<string> AddCustomerSap(SendCustomerVm model) + { + try + { + //鍒ゆ柇鏄惁閲嶅 + var customer = Db.Queryable<SysCustomer>().First(m => m.IsDel == "0" && m.CustomerNo == model.customerNo.ToString()); + if (customer != null) + { + throw new Exception("鐩稿悓缂栫爜鐨勫鎴峰凡瀛樺湪锛岃鍕块噸澶嶆坊鍔�"); + } + var addCustomer = new SysCustomer() + { + CustomerNo = model.customerNo.ToString(), + CustomerName = model.customerName, + Type = int.Parse(model.CustomerType), + Address = model.streetAddress, + LinkMan = model.contact, + Phone = model.contactMobile, + + CreateUser = 0, + }; + await Db.Insertable(addCustomer).ExecuteCommandAsync(); + return "0"; + } + catch (Exception e) + { + throw new Exception(e.Message); + } + } } } diff --git a/Wms/WMS.BLL/SysServer/MaterialsServer.cs b/Wms/WMS.BLL/SysServer/MaterialsServer.cs index 9ba5182..d23f17a 100644 --- a/Wms/WMS.BLL/SysServer/MaterialsServer.cs +++ b/Wms/WMS.BLL/SysServer/MaterialsServer.cs @@ -7,6 +7,7 @@ using System.Text; using System.Threading.Tasks; using AutoMapper; +using Model.InterFaceModel; using Model.ModelDto.SysDto; using SqlSugar; using Utility; @@ -202,7 +203,7 @@ #endregion #region erp - + /// <summary> /// 鑾峰彇erp鏁版嵁 /// </summary> @@ -297,5 +298,92 @@ #endregion + #region sap + + /// <summary> + /// SAP鏂板鐗╂枡涓绘暟鎹暟鎹� + /// </summary> + /// <param name="model">erp瀹炰綋</param> + /// <returns></returns> + /// <exception cref="Exception">鎹曡幏寮傚父</exception> + public async Task<string> AddSkuSap(SendSkuInfoVm model) + { + //鎹曡幏寮傚父 + try + { + if (string.IsNullOrWhiteSpace(model.skuNo.ToString()) || string.IsNullOrWhiteSpace(model.skuName) || string.IsNullOrWhiteSpace(model.categoryNo)) + { + throw new Exception("鍙傛暟閿欒"); + } + //鍒ゆ柇鏄惁鍞竴 + var sku = Db.Queryable<SysMaterials>().First(m => m.IsDel == "0" && m.SkuNo == model.skuNo.ToString()); + if (sku != null) + { + throw new Exception("褰撳墠鐗╂枡宸插瓨鍦�"); + } + //寮�鍚簨鍔� + Db.BeginTran(); + + var category = Db.Queryable<SysMaterialCategory>().First(w => w.IsDel == "0" && w.CategoryNo == model.categoryNo); + if (category == null) + { + category = new SysMaterialCategory() + { + CategoryNo = model.categoryNo, + CategoryName = model.categoryName, + CreateUser = 1 + }; + //娣诲姞鐗╂枡绫诲埆淇℃伅 + Db.Insertable(category).ExecuteCommand(); + } + var pack = new SysPackag() + { + PackagNo = model.skuNo.ToString(), + PackagName = model.skuName, + L1Num = 1, + L1Name = model.unit, + L2Num = Convert.ToInt32(model.packageQty), + L2Name = model.packageName + }; + //娣诲姞鍖呰淇℃伅 + Db.Insertable(pack).ExecuteCommand(); + + var addSku = new SysMaterials() + { + SkuNo = model.skuNo.ToString(), + SkuName = model.skuName, + Standard = model.specification, + CategoryNo = category.CategoryNo, + AuditStatusNo = "9", //model.AuditStatusNo + Type = "0", + IsControlled = "0",//鏄惁璇烽獙锛�0锛氭槸 1锛氬惁 + IsInspect = model.consume.ToString() == "0" ? "1" : "0", + IsPasteCode = "1", + Origin = "SAP", + UnitNo = model.unit, + PackagNo = pack.PackagNo, + Environment = null, + Weight = null, + Warranty = Convert.ToInt32(model.shelfLife.Trim()), + UnpackWarranty = null, + Price = null, + AdventTime = Convert.ToInt32(model.remainingDays) + }; + await Db.Insertable(addSku).ExecuteCommandAsync(); + + //鎻愪氦浜嬪姟 + Db.CommitTran(); + + return "0"; + } + catch (Exception ex) + { + //鍥炴粴浜嬪姟 + Db.RollbackTran(); + //鎶涘嚭寮傚父 + throw new Exception("鏂板erp鏁版嵁寮傚父", ex); + } + } + #endregion } } diff --git a/Wms/WMS.IBLL/ISysServer/ICustomerServer.cs b/Wms/WMS.IBLL/ISysServer/ICustomerServer.cs index 1c818ba..aafdcf8 100644 --- a/Wms/WMS.IBLL/ISysServer/ICustomerServer.cs +++ b/Wms/WMS.IBLL/ISysServer/ICustomerServer.cs @@ -1,4 +1,5 @@ -锘縰sing Model.ModelDto.SysDto; +锘縰sing Model.InterFaceModel; +using Model.ModelDto.SysDto; using SqlSugar; using System; using System.Collections.Generic; @@ -79,5 +80,13 @@ /// <param name="userId"></param> /// <returns></returns> Task<bool> DelsCustomer(List<int> ids, int userId); + + /// <summary> + /// SAP鏂板瀹㈡埛渚涘簲鍟嗘暟鎹� + /// </summary> + /// <param name="model"></param> + /// <returns></returns> + /// <exception cref="Exception"></exception> + Task<string> AddCustomerSap(SendCustomerVm model); } } diff --git a/Wms/WMS.IBLL/ISysServer/IMaterialsServer.cs b/Wms/WMS.IBLL/ISysServer/IMaterialsServer.cs index cbd5996..ee56bcb 100644 --- a/Wms/WMS.IBLL/ISysServer/IMaterialsServer.cs +++ b/Wms/WMS.IBLL/ISysServer/IMaterialsServer.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Text; using System.Threading.Tasks; +using Model.InterFaceModel; using Model.ModelDto.SysDto; using WMS.Entity.SysEntity; @@ -123,5 +124,16 @@ Task<int> EditERP(ERPTestDto erpdto); #endregion + + #region sap + + /// <summary> + /// SAP鏂板鐗╂枡涓绘暟鎹暟鎹� + /// </summary> + /// <param name="model">erp瀹炰綋</param> + /// <returns></returns> + /// <exception cref="Exception">鎹曡幏寮傚父</exception> + Task<string> AddSkuSap(SendSkuInfoVm model); + #endregion } } diff --git a/Wms/Wms/Controllers/UpApiController.cs b/Wms/Wms/Controllers/UpApiController.cs index ffa1384..3f77a43 100644 --- a/Wms/Wms/Controllers/UpApiController.cs +++ b/Wms/Wms/Controllers/UpApiController.cs @@ -28,6 +28,7 @@ using WMS.IBLL; using ZXing.QrCode.Internal; using System.Xml.Linq; +using WMS.IBLL.ISysServer; namespace Wms.Controllers { @@ -45,11 +46,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 +61,8 @@ _stockCheckSvc = stockCheckSvc; _procurePlanSvc = procurePlanSvc; _pdaAsnServer = pdaAsnServer; + _materialSvc = materialSvc; + _customerSvc = customerSvc; _http = http; } #endregion @@ -69,11 +75,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,12 +108,24 @@ /// <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); + 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 = true, code = "1", message = "success" }); } catch (Exception e) -- Gitblit v1.8.0