diff --git a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application.Contracts/PurchaseOrders/CreatePurchaseOrderDetailValidator.cs b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application.Contracts/PurchaseOrders/CreatePurchaseOrderDetailValidator.cs index 920c788..6dbf65f 100644 --- a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application.Contracts/PurchaseOrders/CreatePurchaseOrderDetailValidator.cs +++ b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application.Contracts/PurchaseOrders/CreatePurchaseOrderDetailValidator.cs @@ -2,7 +2,7 @@ using FluentValidation; namespace Win_in.Sfs.Scp.WebApi; -public class CreatePurchaseOrderDetailValidator : AbstractValidator +public class CreatePurchaseOrderDetailValidator : AbstractValidator { public CreatePurchaseOrderDetailValidator() { diff --git a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application.Contracts/WebApiApplicationContractsModule.cs b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application.Contracts/WebApiApplicationContractsModule.cs index 26f9fb5..ec44907 100644 --- a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application.Contracts/WebApiApplicationContractsModule.cs +++ b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Application.Contracts/WebApiApplicationContractsModule.cs @@ -1,5 +1,6 @@ using Volo.Abp.Account; using Volo.Abp.FeatureManagement; +using Volo.Abp.FluentValidation; using Volo.Abp.Identity; using Volo.Abp.Modularity; using Volo.Abp.ObjectExtending; @@ -17,7 +18,8 @@ namespace Win_in.Sfs.Scp.WebApi typeof(AbpPermissionManagementApplicationContractsModule), typeof(AbpSettingManagementApplicationContractsModule), typeof(AbpTenantManagementApplicationContractsModule), - typeof(AbpObjectExtendingModule) + typeof(AbpObjectExtendingModule), + typeof(AbpFluentValidationModule) )] public class WebApiApplicationContractsModule : AbpModule { diff --git a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Controllers/PartController.cs b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Controllers/PartController.cs index e2e8a78..2461139 100644 --- a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Controllers/PartController.cs +++ b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Controllers/PartController.cs @@ -1,7 +1,11 @@ -using System.Net.Mime; +using System; +using System.Net.Mime; using System.Threading.Tasks; +using System.Xml.Serialization; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.ModelBinding; +using Volo.Abp; namespace Win_in.Sfs.Scp.WebApi.XmlHost.Controllers { @@ -27,10 +31,15 @@ namespace Win_in.Sfs.Scp.WebApi.XmlHost.Controllers public virtual async Task> CreateAsync([FromBody]PartCreateDto input) { - - var dto = await _httpClientInvoker.InvokePostAsync(input, RouteConsts.Part); - - return Ok(dto); + try + { + var dto = await _httpClientInvoker.InvokePostAsync(input, RouteConsts.Part); + return Ok(dto); + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } } } } \ No newline at end of file diff --git a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Controllers/PurchaseOrderController.cs b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Controllers/PurchaseOrderController.cs index 15fd50c..736b329 100644 --- a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Controllers/PurchaseOrderController.cs +++ b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Controllers/PurchaseOrderController.cs @@ -1,4 +1,5 @@ -using System.Net.Mime; +using System; +using System.Net.Mime; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; @@ -24,10 +25,18 @@ namespace Win_in.Sfs.Scp.WebApi.XmlHost.Controllers [Produces(MediaTypeNames.Application.Xml)] public virtual async Task> CreateAsync([FromBody] PurchaseOrderCreateDTO input) { + try + { + var dto = await _httpClientInvoker.InvokePostAsync(input, RouteConsts.PurchaseOrder); - var dto = await _httpClientInvoker.InvokePostAsync(input, RouteConsts.PurchaseOrder); + return Ok(dto); + + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } - return Ok(dto); } } } \ No newline at end of file diff --git a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Controllers/ReceiptController.cs b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Controllers/ReceiptController.cs index 727a0a4..d4ed07b 100644 --- a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Controllers/ReceiptController.cs +++ b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Controllers/ReceiptController.cs @@ -1,4 +1,5 @@ -using System.Net.Mime; +using System; +using System.Net.Mime; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; @@ -24,10 +25,18 @@ namespace Win_in.Sfs.Scp.WebApi.XmlHost.Controllers [Produces(MediaTypeNames.Application.Xml)] public virtual async Task> CreateAsync([FromBody] ReceiptCreateDTO input) { + try + { + var dto = await _httpClientInvoker.InvokePostAsync(input, RouteConsts.Receipt); - var dto = await _httpClientInvoker.InvokePostAsync(input, RouteConsts.Receipt); + return Ok(dto); + + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } - return Ok(dto); } } } \ No newline at end of file diff --git a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Controllers/SupplierController.cs b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Controllers/SupplierController.cs index 6941538..9d3e85e 100644 --- a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Controllers/SupplierController.cs +++ b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Controllers/SupplierController.cs @@ -1,4 +1,5 @@ -using System.Net.Mime; +using System; +using System.Net.Mime; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; @@ -24,10 +25,18 @@ namespace Win_in.Sfs.Scp.WebApi.XmlHost.Controllers [Produces(MediaTypeNames.Application.Xml)] public virtual async Task> CreateAsync([FromBody] SupplierCreateDTO input) { + try + { + var dto = await _httpClientInvoker.InvokePostAsync(input, RouteConsts.Supplier); - var dto = await _httpClientInvoker.InvokePostAsync(input, RouteConsts.Supplier); + return Ok(dto); + + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } - return Ok(dto); } } } \ No newline at end of file diff --git a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Controllers/UnplannedReceiptController.cs b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Controllers/UnplannedReceiptController.cs index bcad7cf..e43ff6d 100644 --- a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Controllers/UnplannedReceiptController.cs +++ b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/Controllers/UnplannedReceiptController.cs @@ -1,4 +1,5 @@ -using System.Net.Mime; +using System; +using System.Net.Mime; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; @@ -23,10 +24,18 @@ namespace Win_in.Sfs.Scp.WebApi.XmlHost.Controllers [Produces(MediaTypeNames.Application.Xml)] public virtual async Task> CreateAsync([FromBody] UnplannedReceiptCreateDTO input) { + try + { + var dto = await _httpClientInvoker.InvokePostAsync(input, RouteConsts.UnplannedReceipt); - var dto = await _httpClientInvoker.InvokePostAsync(input, RouteConsts.UnplannedReceipt); + return Ok(dto); + + } + catch (Exception ex) + { + return BadRequest(ex.Message); + } - return Ok(dto); } } } \ No newline at end of file diff --git a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/HttpClientInvokers/HttpClientInvoker.cs b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/HttpClientInvokers/HttpClientInvoker.cs index cbdb7a6..9ae5098 100644 --- a/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/HttpClientInvokers/HttpClientInvoker.cs +++ b/WebApiService/src/Win_in.Sfs.Scp.WebApi.Xml.Host/HttpClientInvokers/HttpClientInvoker.cs @@ -7,6 +7,7 @@ using System.Runtime.Serialization; using System.Threading.Tasks; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Options; +using Volo.Abp; namespace Win_in.Sfs.Scp.WebApi.XmlHost { @@ -37,11 +38,16 @@ namespace Win_in.Sfs.Scp.WebApi.XmlHost { var client = CreateClient(); var response = await client.PostAsJsonAsync(routeString, input); - response.EnsureSuccessStatusCode(); - var str =await response.Content.ReadAsStringAsync(); - - var dto = await response.Content.ReadFromJsonAsync(); - return dto; + if (response.IsSuccessStatusCode) + { + var dto = await response.Content.ReadFromJsonAsync(); + return dto; + } + else + { + var str = await response.Content.ReadAsStringAsync(); + throw new AbpException(str); + } } private HttpClient CreateClient() @@ -50,7 +56,7 @@ namespace Win_in.Sfs.Scp.WebApi.XmlHost client.BaseAddress = new Uri(_baseUrl); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); - + //XmlHost也使用Jwt认证,并连到同一个IDS4 server,不需要再手工添加鉴权信息了 if (_httpAuthorizationHandler.IsLoggedIn()) {