From c47361142d98e7cf854974b5a2d809403d0b5f2a Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 14 Dec 2022 08:21:31 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E8=A3=9CGetPLMEcn=E8=B3=87=E6=96=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/QASRV/GetPLMDataController.cs | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 AMESCoreStudio.WebApi/Controllers/QASRV/GetPLMDataController.cs diff --git a/AMESCoreStudio.WebApi/Controllers/QASRV/GetPLMDataController.cs b/AMESCoreStudio.WebApi/Controllers/QASRV/GetPLMDataController.cs new file mode 100644 index 00000000..a2f28bb0 --- /dev/null +++ b/AMESCoreStudio.WebApi/Controllers/QASRV/GetPLMDataController.cs @@ -0,0 +1,54 @@ +using Microsoft.AspNetCore.Mvc; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Net.Http; +using System.Net.Http.Headers; +using AMESCoreStudio.CommonTools.Result; + +namespace AMESCoreStudio.WebApi.Controllers.QASRV +{ + [Route("api/[controller]")] + [ApiController] + public class GetPLMDataController : ControllerBase + { + /// + /// GetPLM ECN + /// + /// 料號 + /// + [HttpGet("Get_PLM_ECN")] + public IResultModel GetPlmEcn(string ItemNo) + { + ResultModel resultModel = new ResultModel { Success = false }; + var client = new HttpClient(); + client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/xml")); + // + client.Timeout = TimeSpan.FromHours(1);//1小時 + try + { + var apiUrl = $"http://plm935fs01:50786/RMA_GetLocation/QueryLastReleaseECN?item={ItemNo}"; + HttpResponseMessage response = client.GetAsync(apiUrl).Result; + + if (response.IsSuccessStatusCode) + { + var jsonString = response.Content.ReadAsStringAsync(); + jsonString.Wait(); + System.Xml.XmlDocument xdoc = new System.Xml.XmlDocument(); + xdoc.LoadXml(jsonString.Result); + resultModel.Msg = xdoc.DocumentElement.LastChild.Value; + resultModel.Success = true; + return resultModel; + } + resultModel.Msg = "error"; + } + catch (Exception ex) + { + resultModel.Msg = ex.Message; + } + + return resultModel; + } + } +}