From 1fc87ae94b445ad5c0b5cca70bddb2217089e7e4 Mon Sep 17 00:00:00 2001 From: admin Date: Wed, 13 Jan 2021 12:37:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=87=87=E8=B4=AD=E5=85=A5?= =?UTF-8?q?=E5=BA=93=E5=8D=95=E6=8E=A5=E5=8F=A3=20=E7=BB=9F=E4=B8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +- NX.ERP.Model/Store/PuStoreIn.cs | 2 +- NX.ERP.U8.App/FrmMain.cs | 13 ++-- NX.ERP.U8/NX.ERP.U8.csproj | 1 - NX.ERP.U8/Store/MaterielStoreOutDAL.cs | 4 +- NX.ERP.U8/Store/OtherStoreInDAL.cs | 4 +- NX.ERP.U8/Store/OtherStoreOutDAL.cs | 4 +- NX.ERP.U8/Store/PuStoreInDAL.cs | 8 +-- NX.ERP.U8/Store/VoucherBase.cs | 40 ++++++++---- NX.ERP.U8/U8LoginContext.cs | 14 ++--- NX.ERP.WebAPi/App_Start/WebApiConfig.cs | 61 ++++++++++++++++++- .../Controllers/Store/PuStoreInController.cs | 18 ++++++ NX.ERP.WebAPi/NX.ERP.WebAPi.csproj | 25 +++++--- NX.ERP.WebAPi/ResultModel.cs | 14 +++++ 14 files changed, 161 insertions(+), 50 deletions(-) create mode 100644 NX.ERP.WebAPi/Controllers/Store/PuStoreInController.cs create mode 100644 NX.ERP.WebAPi/ResultModel.cs diff --git a/.gitignore b/.gitignore index 4ce6fdd..2d2c6be 100644 --- a/.gitignore +++ b/.gitignore @@ -337,4 +337,5 @@ ASALocalRun/ .localhistory/ # BeatPulse healthcheck temp database -healthchecksdb \ No newline at end of file +healthchecksdb +/NX.ERP.WebAPi/binXMLDOM diff --git a/NX.ERP.Model/Store/PuStoreIn.cs b/NX.ERP.Model/Store/PuStoreIn.cs index 1c17dc6..80f139f 100644 --- a/NX.ERP.Model/Store/PuStoreIn.cs +++ b/NX.ERP.Model/Store/PuStoreIn.cs @@ -20,7 +20,7 @@ namespace NX.ERP.Model.Store private string _puCode; private string maker; private string personCode; - public IList PuStoreInDetails { get => puStoreInDetails; set => puStoreInDetails = value; } + public IList Details { get => puStoreInDetails; set => puStoreInDetails = value; } public int Id { get => id; set => id = value; } public string Code { get => code; set => code = value; } public DateTime Date { get => date; set => date = value; } diff --git a/NX.ERP.U8.App/FrmMain.cs b/NX.ERP.U8.App/FrmMain.cs index c5b0349..4e18771 100644 --- a/NX.ERP.U8.App/FrmMain.cs +++ b/NX.ERP.U8.App/FrmMain.cs @@ -301,25 +301,20 @@ namespace U8AppMain var id = a.AddVocher(new NX.ERP.Model.Store.PuStoreIn() { Code = "0001", - //PersonCode = "wx065", - //PuCode = "0002", Date = DateTime.Today, - //Id = 1000021, RdCode = "101", Depcode = "24", - Source = "采购到货单", Whcode = "1", + Source = "采购到货单", SourceCode = "CGDH210100187", - PuStoreInDetails = new List() { + Details = new List() { new NX.ERP.Model.Store.PuStoreInDetail(){ - //Batch="001", + Quantity=1, - //Id=1, + Invcode="201763", - //PuStoreInId=1002001, SorceDetailId=1000023624, } - } }); diff --git a/NX.ERP.U8/NX.ERP.U8.csproj b/NX.ERP.U8/NX.ERP.U8.csproj index fc55431..671e2f9 100644 --- a/NX.ERP.U8/NX.ERP.U8.csproj +++ b/NX.ERP.U8/NX.ERP.U8.csproj @@ -36,7 +36,6 @@ true - diff --git a/NX.ERP.U8/Store/MaterielStoreOutDAL.cs b/NX.ERP.U8/Store/MaterielStoreOutDAL.cs index 539863d..0dd74c1 100644 --- a/NX.ERP.U8/Store/MaterielStoreOutDAL.cs +++ b/NX.ERP.U8/Store/MaterielStoreOutDAL.cs @@ -14,7 +14,7 @@ namespace NX.ERP.U8.Store public class MaterielStoreOutDAL : VoucherBase { - public MaterielStoreOutDAL() : base("11") + public MaterielStoreOutDAL() : base("11", "U8API/MaterialOut") { } @@ -118,7 +118,7 @@ namespace NX.ERP.U8.Store try { - return U8LoginContext.Instance.AddRdVoucher("U8API/MaterialOut/Add", voucherParameter); + return U8LoginContext.Instance.AddRdVoucher(AddUrl, voucherParameter); } catch (Exception err) { diff --git a/NX.ERP.U8/Store/OtherStoreInDAL.cs b/NX.ERP.U8/Store/OtherStoreInDAL.cs index 588aa6f..0dadc17 100644 --- a/NX.ERP.U8/Store/OtherStoreInDAL.cs +++ b/NX.ERP.U8/Store/OtherStoreInDAL.cs @@ -8,7 +8,7 @@ namespace NX.ERP.U8.Store { public class OtherStoreInDAL : VoucherBase { - public OtherStoreInDAL() : base("08") + public OtherStoreInDAL() : base("08", "U8API/otherin") { } @@ -86,7 +86,7 @@ namespace NX.ERP.U8.Store Console.WriteLine(str); try { - return U8LoginContext.Instance.AddRdVoucher("U8API/PuStoreIn/Add", voucherParameter); + return U8LoginContext.Instance.AddRdVoucher(AddUrl, voucherParameter); } catch (Exception err) { diff --git a/NX.ERP.U8/Store/OtherStoreOutDAL.cs b/NX.ERP.U8/Store/OtherStoreOutDAL.cs index 9e8734e..9401e17 100644 --- a/NX.ERP.U8/Store/OtherStoreOutDAL.cs +++ b/NX.ERP.U8/Store/OtherStoreOutDAL.cs @@ -8,7 +8,7 @@ namespace NX.ERP.U8.Store { public class OtherStoreOutDAL : VoucherBase { - public OtherStoreOutDAL() : base("09") + public OtherStoreOutDAL() : base("09", "U8API/otherout") { @@ -85,7 +85,7 @@ namespace NX.ERP.U8.Store Console.WriteLine(str); try { - return U8LoginContext.Instance.AddRdVoucher("U8API/PuStoreIn/Add", voucherParameter); + return U8LoginContext.Instance.AddRdVoucher(AddUrl, voucherParameter); } catch (Exception err) { diff --git a/NX.ERP.U8/Store/PuStoreInDAL.cs b/NX.ERP.U8/Store/PuStoreInDAL.cs index a632625..ef73317 100644 --- a/NX.ERP.U8/Store/PuStoreInDAL.cs +++ b/NX.ERP.U8/Store/PuStoreInDAL.cs @@ -12,7 +12,7 @@ namespace NX.ERP.U8.Store { public class PuStoreInDAL : VoucherBase { - public PuStoreInDAL() : base("01") + public PuStoreInDAL() : base("01", "U8API/PuStoreIn") { } /// @@ -65,9 +65,9 @@ namespace NX.ERP.U8.Store headXml.setAttribute("cptcode", Arrival.PTCode); IXMLDOMElement bodyXml; - for (var n = 0; n < puStoreIn.PuStoreInDetails.Count; n++) + for (var n = 0; n < puStoreIn.Details.Count; n++) { - var detail = puStoreIn.PuStoreInDetails[n]; + var detail = puStoreIn.Details[n]; var arrivalDetail = Arrival.ArrivalDetails.First(m => { return m.Id == detail.SorceDetailId; }); headXml.setAttribute("cordercode", arrivalDetail.OrderCode); // headXml.setAttribute("ipurorderid", arrivalDetail.PoId); @@ -110,7 +110,7 @@ namespace NX.ERP.U8.Store Console.WriteLine(str); try { - return U8LoginContext.Instance.AddRdVoucher("U8API/PuStoreIn/Add", voucherParameter); + return U8LoginContext.Instance.AddRdVoucher(AddUrl, voucherParameter); } catch (Exception err) { diff --git a/NX.ERP.U8/Store/VoucherBase.cs b/NX.ERP.U8/Store/VoucherBase.cs index 6f0a97a..5e99cfc 100644 --- a/NX.ERP.U8/Store/VoucherBase.cs +++ b/NX.ERP.U8/Store/VoucherBase.cs @@ -10,6 +10,23 @@ namespace NX.ERP.U8.Store { private string voucherID; + private string Url; + + public string LoadUrl + { + get + { + return $"{Url}/Load"; + } + } + + public string AddUrl + { + get + { + return $"{Url}/Add"; + } + } protected string VoucherID { @@ -18,14 +35,15 @@ namespace NX.ERP.U8.Store return this.voucherID; } } - public VoucherBase(string voucherID) + public VoucherBase(string voucherID, string Url) { this.voucherID = voucherID; + this.Url = Url; } protected string HeadTemplate - { - get + { + get { return this.GetHeadTemplate(); } @@ -42,7 +60,7 @@ namespace NX.ERP.U8.Store private string GetHeadTemplate() { - var strTemlate = FileHelp.ReadFile(AppDomain.CurrentDomain.BaseDirectory + $"XMLDOM\\XMLDomHead{this.voucherID}.xml"); + var strTemlate = FileHelp.ReadFile(AppDomain.CurrentDomain.RelativeSearchPath + $"XMLDOM\\XMLDomHead{this.voucherID}.xml"); if (strTemlate == string.Empty) { this.LoadTemplate(); @@ -53,7 +71,7 @@ namespace NX.ERP.U8.Store private string GetBodyTemplate() { - var strTemlate = FileHelp.ReadFile(AppDomain.CurrentDomain.BaseDirectory + $"XMLDOM\\XMLDomBody{this.voucherID}.xml"); + var strTemlate = FileHelp.ReadFile(AppDomain.CurrentDomain.RelativeSearchPath + $"XMLDOM\\XMLDomBody{this.voucherID}.xml"); if (strTemlate == string.Empty) { this.LoadTemplate(); @@ -68,18 +86,18 @@ namespace NX.ERP.U8.Store VoucherParameter rdVoucherParameter = null; try { - if (!Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "XMLDOM")) + if (!Directory.Exists(AppDomain.CurrentDomain.RelativeSearchPath + "XMLDOM")) { - Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "XMLDOM"); + Directory.CreateDirectory(AppDomain.CurrentDomain.RelativeSearchPath + "XMLDOM"); } rdVoucherParameter = new VoucherParameter(); - rdVoucherParameter.VoucherType =this.VoucherID; + rdVoucherParameter.VoucherType = this.VoucherID; rdVoucherParameter.IsGetBlank = true; - U8LoginContext.Instance.LoadRdVoucher(rdVoucherParameter); + U8LoginContext.Instance.LoadRdVoucher(this.LoadUrl, rdVoucherParameter); if (rdVoucherParameter.ReturnValue) { - FileHelp.WriteFile(rdVoucherParameter.DomHead.xml, AppDomain.CurrentDomain.BaseDirectory + $"XMLDOM\\XMLDomHead{this.voucherID}.xml"); - FileHelp.WriteFile(rdVoucherParameter.DomBody.xml, AppDomain.CurrentDomain.BaseDirectory + $"XMLDOM\\XMLDomBody{this.voucherID}.xml"); + FileHelp.WriteFile(rdVoucherParameter.DomHead.xml, AppDomain.CurrentDomain.RelativeSearchPath + $"XMLDOM\\XMLDomHead{this.voucherID}.xml"); + FileHelp.WriteFile(rdVoucherParameter.DomBody.xml, AppDomain.CurrentDomain.RelativeSearchPath + $"XMLDOM\\XMLDomBody{this.voucherID}.xml"); } } diff --git a/NX.ERP.U8/U8LoginContext.cs b/NX.ERP.U8/U8LoginContext.cs index 21bad90..16c2370 100644 --- a/NX.ERP.U8/U8LoginContext.cs +++ b/NX.ERP.U8/U8LoginContext.cs @@ -231,7 +231,7 @@ namespace NX.ERP.U8 para.ReturnValue = false; u8ApiBroker.Release(); - + } para.ReturnValue = Convert.ToBoolean(u8ApiBroker.GetReturnValue()); para.DOMMsg = u8ApiBroker.GetResult("domMsg") as DOMDocument; @@ -241,7 +241,7 @@ namespace NX.ERP.U8 { para.VoucherId = u8ApiBroker.GetResult("VouchId") as string; VoucherId = para.VoucherId; - + } else { @@ -256,19 +256,19 @@ namespace NX.ERP.U8 throw ex3; } finally - { - + { + } } - public void LoadRdVoucher(VoucherParameter para) + public void LoadRdVoucher(string Url, VoucherParameter para) { try { U8EnvContext u8EnvContext = new U8EnvContext(); u8EnvContext.U8Login = this.ClsLogin; - U8ApiAddress apiAddress = new U8ApiAddress("U8API/PuStoreIn/Load"); + U8ApiAddress apiAddress = new U8ApiAddress(Url); U8ApiBroker u8ApiBroker = new U8ApiBroker(apiAddress, u8EnvContext); u8ApiBroker.AssignNormalValue("sVouchType", para.VoucherType); u8ApiBroker.AssignNormalValue("sWhere", para.StrWhere); @@ -325,8 +325,8 @@ namespace NX.ERP.U8 } catch (Exception ex3) { + throw ex3; - throw new Exception("装载供应链库存单据失败!"); } } diff --git a/NX.ERP.WebAPi/App_Start/WebApiConfig.cs b/NX.ERP.WebAPi/App_Start/WebApiConfig.cs index fcc1ce9..264d327 100644 --- a/NX.ERP.WebAPi/App_Start/WebApiConfig.cs +++ b/NX.ERP.WebAPi/App_Start/WebApiConfig.cs @@ -6,12 +6,62 @@ using System.Linq; using System.Net.Http; using System.Net.Http.Formatting; using System.Net.Http.Headers; +using System.Threading; +using System.Threading.Tasks; using System.Web.Http; +using System.Web.Http.Controllers; +using System.Web.Http.Filters; namespace NX.ERP.WebAPi { + + public class ExceptionFilter : System.Web.Http.Filters.IExceptionFilter + { + public bool AllowMultiple => throw new NotImplementedException(); + + public Task ExecuteExceptionFilterAsync(HttpActionExecutedContext actionExecutedContext, CancellationToken cancellationToken) + { + var ex = actionExecutedContext.Exception; + actionExecutedContext.Response = new System.Net.Http.HttpResponseMessage(); + + actionExecutedContext.Response.Content = new System.Net.Http.ObjectContent(typeof(ResultModel), + new ResultModel { ErrCode = 500, ErrMsg = ex.Message, Data = null }, + new JsonMediaTypeFormatter()); + + return Task.FromResult(0); + } + } + + public class ApiResultAttribute : System.Web.Http.Filters.ActionFilterAttribute + { + public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext) + { + base.OnActionExecuted(actionExecutedContext); + if (actionExecutedContext.Exception == null) + { + ResultModel result = new ResultModel(); + // 取得由 API 返回的状态代码 + result.ErrCode = 0; + // 取得由 API 返回的资料 + result.Data = actionExecutedContext.ActionContext.Response.Content.ReadAsAsync().Result; + + //请求是否成功 + // result.IsSuccess = actionExecutedContext.ActionContext.Response.IsSuccessStatusCode; + //结果转为自定义消息格式 + HttpResponseMessage httpResponseMessage = new HttpResponseMessage() { Content = new StringContent(JsonConvert.SerializeObject(result, GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings)) }; + // 重新封装回传格式 + actionExecutedContext.Response = httpResponseMessage; + } + } + } + + + + + public class JsonContentNegotiator : IContentNegotiator { + private readonly JsonMediaTypeFormatter _jsonFormatter; public JsonContentNegotiator(JsonMediaTypeFormatter formatter) @@ -29,6 +79,10 @@ namespace NX.ERP.WebAPi { public static void Register(HttpConfiguration config) { + //System.Web.Http.Filters.IExceptionFilter + config.Filters.Add(new ExceptionFilter()); + config.Filters.Add(new ApiResultAttribute()); + Console.WriteLine(config.Filters.Count); // Web API 配置和服务 GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings = new JsonSerializerSettings { @@ -36,12 +90,13 @@ namespace NX.ERP.WebAPi ReferenceLoopHandling = ReferenceLoopHandling.Ignore, Formatting = Newtonsoft.Json.Formatting.Indented, //小驼峰命名法 - ContractResolver = new DefaultContractResolver() { + ContractResolver = new DefaultContractResolver() + { NamingStrategy = new SnakeCaseNamingStrategy() } //格式化日期时间 - + //空值处理 //NullValueHandling = NullValueHandling.Ignore @@ -50,7 +105,7 @@ namespace NX.ERP.WebAPi // Web API 路由 config.MapHttpAttributeRoutes(); - + config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{action}/{code}", diff --git a/NX.ERP.WebAPi/Controllers/Store/PuStoreInController.cs b/NX.ERP.WebAPi/Controllers/Store/PuStoreInController.cs new file mode 100644 index 0000000..f58ffc3 --- /dev/null +++ b/NX.ERP.WebAPi/Controllers/Store/PuStoreInController.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.Http; + +namespace NX.ERP.WebAPi.Controllers.Store +{ + public class PuStoreInController : ApiController + { + [HttpPost] + public string AddVoucher([FromBody] Model.Store.PuStoreIn storeIn) + { + var dal = new NX.ERP.U8.Store.PuStoreInDAL(); + return dal.AddVocher(storeIn); + } + } +} \ No newline at end of file diff --git a/NX.ERP.WebAPi/NX.ERP.WebAPi.csproj b/NX.ERP.WebAPi/NX.ERP.WebAPi.csproj index 66c8545..7093ebe 100644 --- a/NX.ERP.WebAPi/NX.ERP.WebAPi.csproj +++ b/NX.ERP.WebAPi/NX.ERP.WebAPi.csproj @@ -25,6 +25,7 @@ + true @@ -34,6 +35,8 @@ DEBUG;TRACE prompt 4 + x86 + false true @@ -43,20 +46,26 @@ TRACE prompt 4 + false + + E:\U8SOFT\Interop\ADODB.dll + False + True + - - - - - - + + + + + + @@ -108,6 +117,7 @@ True ..\packages\Microsoft.AspNet.WebPages.3.2.7\lib\net45\System.Web.WebPages.Razor.dll + True ..\packages\WebGrease.1.6.0\lib\WebGrease.dll @@ -137,10 +147,12 @@ + Global.asax + @@ -155,7 +167,6 @@ - diff --git a/NX.ERP.WebAPi/ResultModel.cs b/NX.ERP.WebAPi/ResultModel.cs new file mode 100644 index 0000000..20596e7 --- /dev/null +++ b/NX.ERP.WebAPi/ResultModel.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace NX.ERP.WebAPi +{ + public class ResultModel + { + public int ErrCode { get; set; } + public string ErrMsg { get; set; } = ""; + public T Data { get; set; } + } +} \ No newline at end of file