|
|
@@ -1,4 +1,5 @@
|
|
|
-using LocalhostMES.DataBase;
|
|
|
+using LocalhostMES.Core;
|
|
|
+using LocalhostMES.DataBase;
|
|
|
using LocalhostMES.Models;
|
|
|
using Newtonsoft.Json;
|
|
|
using Newtonsoft.Json.Linq;
|
|
|
@@ -53,7 +54,7 @@ namespace LocalhostMES.Controller
|
|
|
// 2.2.2 Headers - 需要token
|
|
|
var requestJson = JsonConvert.SerializeObject(request);
|
|
|
var content = new StringContent(requestJson, Encoding.UTF8, "application/json");
|
|
|
- var requestMessage = new HttpRequestMessage(HttpMethod.Post, $"https://uat-mom-jh-handle-api.leapmotor.com:443/app-mom-mes/api/battery/sn/print")
|
|
|
+ var requestMessage = new HttpRequestMessage(HttpMethod.Post, $"https://mom-jh-annex-api.leapmotor.com/app-mom-mes/api/battery/sn/print \r\n")
|
|
|
{
|
|
|
Content = content
|
|
|
};
|
|
|
@@ -63,16 +64,19 @@ namespace LocalhostMES.Controller
|
|
|
ApiResponse<SnPrintResponseData> res = await ParseResponseAsync<ApiResponse<SnPrintResponseData>>(response);
|
|
|
|
|
|
List<SnInfo> inSn = new List<SnInfo>();
|
|
|
- for (int i = 0; i < res.data.Sn.Count; i++)
|
|
|
+ if (res.data != null)
|
|
|
{
|
|
|
- inSn.Add(new SnInfo()
|
|
|
+ for (int i = 0; i < res.data.Sn.Count; i++)
|
|
|
{
|
|
|
- WorkOrderNo=res.data.WorkOrderNo,
|
|
|
- Sn = res.data.Sn[i].Sn,
|
|
|
- GenerateTime=DateTime.Now,
|
|
|
- IsUsed=false,
|
|
|
- PrintType="0"
|
|
|
- });
|
|
|
+ inSn.Add(new SnInfo()
|
|
|
+ {
|
|
|
+ WorkOrderNo = res.data.WorkOrderNo,
|
|
|
+ Sn = res.data.Sn[i].Sn,
|
|
|
+ GenerateTime = DateTime.Now,
|
|
|
+ IsUsed = false,
|
|
|
+ PrintType = "0"
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
if (inSn.Count != 0)
|
|
|
{
|
|
|
@@ -104,7 +108,7 @@ namespace LocalhostMES.Controller
|
|
|
{
|
|
|
var requestJson = JsonConvert.SerializeObject(request);
|
|
|
var content = new StringContent(requestJson, Encoding.UTF8, "application/json");
|
|
|
- var requestMessage = new HttpRequestMessage(HttpMethod.Post, $"https://uat-mom-jh-handle-api.leapmotor.com/app-mom-mes/api/task/receive/sn/keyComponent" )
|
|
|
+ var requestMessage = new HttpRequestMessage(HttpMethod.Post, $"https://mom-jh-annex-api.leapmotor.com/app-mom-mes/api/task/receive/sn/keyComponent " )
|
|
|
{
|
|
|
Content = content
|
|
|
};
|
|
|
@@ -132,7 +136,7 @@ namespace LocalhostMES.Controller
|
|
|
var requestJson = JsonConvert.SerializeObject(request);
|
|
|
var content = new StringContent(requestJson, Encoding.UTF8, "application/json");
|
|
|
|
|
|
- var requestMessage = new HttpRequestMessage(HttpMethod.Post, $"https://uat-mom-jh-handle-api.leapmotor.com/app-mom-mes/api/task/receive/manualSave")
|
|
|
+ var requestMessage = new HttpRequestMessage(HttpMethod.Post, $"https://mom-jh-annex-api.leapmotor.com/app-mom-mes/api/task/receive/manualSave ")
|
|
|
{
|
|
|
Content = content
|
|
|
};
|
|
|
@@ -141,6 +145,8 @@ namespace LocalhostMES.Controller
|
|
|
requestMessage.Headers.Add("token", _token);
|
|
|
|
|
|
var response = await _httpClient.SendAsync(requestMessage);
|
|
|
+ LogHelper.WriteLogInfo(requestMessage.ToString());
|
|
|
+
|
|
|
return await ParseResponseAsync<ApiResponse<bool?>>(response);
|
|
|
}
|
|
|
|
|
|
@@ -158,13 +164,24 @@ namespace LocalhostMES.Controller
|
|
|
#region 辅助方法
|
|
|
private async Task<T> ParseResponseAsync<T>(HttpResponseMessage response) where T : class
|
|
|
{
|
|
|
- if ( response.IsSuccessStatusCode )
|
|
|
+ LogHelper.WriteLogInfo(response.ToString());
|
|
|
+ if ( response.IsSuccessStatusCode)
|
|
|
{
|
|
|
var json = await response.Content.ReadAsStringAsync();
|
|
|
var jObject = JObject.Parse(json);
|
|
|
+ if (jObject.ContainsKey("data"))
|
|
|
+ {
|
|
|
+ string str = jObject["data"].ToString();
|
|
|
+ if (jObject["data"].ToString() == "null"|| jObject["data"].ToString().Length==0)
|
|
|
+ {
|
|
|
+ // 添加新属性
|
|
|
+ jObject["data"] = "true";
|
|
|
+ }
|
|
|
+ }
|
|
|
// 将JObject转换回字符串
|
|
|
string newJsonString = jObject.ToString();
|
|
|
- return JsonConvert.DeserializeObject<T>(json);
|
|
|
+
|
|
|
+ return JsonConvert.DeserializeObject<T>(newJsonString);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
@@ -174,13 +191,15 @@ namespace LocalhostMES.Controller
|
|
|
var jObject = JObject.Parse(errorJson);
|
|
|
if (jObject.ContainsKey("data"))
|
|
|
{
|
|
|
- if (jObject["data"].ToString() == "null")
|
|
|
+ if (jObject["data"].ToString() == "null" || jObject["data"].ToString().Length == 0)
|
|
|
{
|
|
|
// 添加新属性
|
|
|
jObject["data"] = "false";
|
|
|
}
|
|
|
}
|
|
|
- return JsonConvert.DeserializeObject<T>(errorJson);
|
|
|
+ // 将JObject转换回字符串
|
|
|
+ string newJsonString = jObject.ToString();
|
|
|
+ return JsonConvert.DeserializeObject<T>(newJsonString);
|
|
|
}
|
|
|
catch
|
|
|
{
|