mes集成增加MesCallResult
This commit is contained in:
@@ -12,6 +12,7 @@ using JY.Inspection.Frm;
|
||||
using JY.Inspection.Mes;
|
||||
using JY.MES;
|
||||
using JY.MES.Entity;
|
||||
using JY.MES.Enum;
|
||||
using JY.MES.MES;
|
||||
using JY.Model;
|
||||
using JY.Model.Excel;
|
||||
@@ -2434,17 +2435,17 @@ namespace JY.Inspection
|
||||
if (m != null)
|
||||
{
|
||||
#region 3、产品结果加工参数
|
||||
MesResponse resMes = ToMesData.ProductResultParameters(m);
|
||||
if (!resMes.success)
|
||||
MesCallResult<RespProductResult> resMes = ToMesData.ProductResultParameters(m);
|
||||
if (!resMes.IsSuccess)
|
||||
{
|
||||
if (resMes.error == 99)
|
||||
if (resMes.ErrorType == MesErrorType.NetworkError || resMes.ErrorType == MesErrorType.NetworkTimeout)
|
||||
{
|
||||
omronPLCCom.lstMcUI[0].WriteDReg("W249", (short)1);//MES网络异常
|
||||
LogManagerControl.AddLog("结果数据上传MES超时或无法访问MES服务器", LogAddtype.local, Logtype.Error);
|
||||
}
|
||||
else
|
||||
{
|
||||
LogManagerControl.AddLog("结果数据上传MES失败NG" + resMes.message, LogAddtype.local, Logtype.Error);
|
||||
LogManagerControl.AddLog("结果数据上传MES失败NG" + resMes.OriResponse.Message, LogAddtype.local, Logtype.Error);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
@@ -2469,7 +2470,7 @@ namespace JY.Inspection
|
||||
}
|
||||
}
|
||||
};
|
||||
RespArrivalStation resp = ToMesData.PostProductExitStationData(req);
|
||||
RespExitStation resp = ToMesData.PostProductExitStationData(req);
|
||||
|
||||
if (resp == null || !resp.Success)
|
||||
{
|
||||
|
||||
@@ -487,6 +487,8 @@
|
||||
<None Include="Resources\设备报警.png" />
|
||||
<None Include="Resources\报警记录.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<ItemGroup>
|
||||
<Folder Include="Exceptions\" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -1,4 +1,7 @@
|
||||
using JY.MES;
|
||||
using JY.MES.Entity;
|
||||
using JY.MES.Enum;
|
||||
using JY.MES.Exceptions;
|
||||
using JY.MES.MES;
|
||||
using JY.Model;
|
||||
using JY.Utility;
|
||||
@@ -7,6 +10,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
|
||||
namespace JY.Inspection.Mes
|
||||
{
|
||||
@@ -25,7 +29,7 @@ namespace JY.Inspection.Mes
|
||||
/// </summary>
|
||||
/// <param name="m"></param>
|
||||
/// <returns></returns>
|
||||
MesResponse ProductResultParameters(BlankingData m);
|
||||
MesCallResult<RespProductResult> ProductResultParameters(BlankingData m);
|
||||
|
||||
/// <summary>
|
||||
/// 产品进站(包装)
|
||||
@@ -131,9 +135,9 @@ namespace JY.Inspection.Mes
|
||||
#endregion
|
||||
|
||||
#region 2、结果加工参数
|
||||
public MesResponse ProductResultParameters(BlankingData m)
|
||||
public MesCallResult<RespProductResult> ProductResultParameters(BlankingData m)
|
||||
{
|
||||
MesResponse mesResponse = new MesResponse();
|
||||
MesCallResult<RespProductResult> resp = new MesCallResult<RespProductResult>();
|
||||
DateTime nowTime = DateTime.Now;
|
||||
string josnTxtMsg = string.Empty;
|
||||
try
|
||||
@@ -184,7 +188,8 @@ namespace JY.Inspection.Mes
|
||||
}
|
||||
|
||||
// 生成TagDataVoListItem
|
||||
tdvls.Add(new TagDataVOListItem() {
|
||||
tdvls.Add(new TagDataVOListItem()
|
||||
{
|
||||
tagCode = cfgItem.MesItemCode,
|
||||
tagValue = item.Value,
|
||||
tagTime = m.OutTime,
|
||||
@@ -209,30 +214,25 @@ namespace JY.Inspection.Mes
|
||||
|
||||
var sw = new Stopwatch();
|
||||
sw.Start();
|
||||
string mesRes = MESApiHelper.HttpPostJsonAPI(Global.systemConfig.ResultProcessMesUrl, p, Global.systemConfig.MesRequestTime);
|
||||
var mesCallResult = MESApiHelper.HttpPostJsonAPI<RespProductResult>(Global.systemConfig.ResultProcessMesUrl, p, Global.systemConfig.MesRequestTime);
|
||||
sw.Stop();
|
||||
|
||||
var res = JsonConvert.DeserializeObject<dynamic>(mesRes);
|
||||
mesResponse.success = res.success.Value;
|
||||
if (!res.success.Value)
|
||||
if (mesCallResult?.OriResponse?.Success != true)
|
||||
{
|
||||
mesResponse.code = res.code.Value;
|
||||
mesResponse.message = res.message.Value;
|
||||
if (mesRes.Contains("category"))
|
||||
mesResponse.category = res.category.Value;
|
||||
if (res.error != null)
|
||||
mesResponse.error = (int)res.error.Value;
|
||||
resp.IsSuccess = false;
|
||||
resp.ErrorType = MesErrorType.BusinessError;
|
||||
resp.ErrorMessage = mesCallResult?.OriResponse.Message ?? "MES业务处理失败";
|
||||
}
|
||||
|
||||
new MesLog().LogProductResult(nowTime, p, mesRes, sw.ElapsedMilliseconds);
|
||||
new MesLog().LogProductResult(nowTime, p, mesCallResult.OriRespJsonStr, sw.ElapsedMilliseconds);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
mesResponse.success = false;
|
||||
mesResponse.error = 9;
|
||||
mesResponse.message = "结果加工参数上传异常:" + ex.Message;
|
||||
resp.IsSuccess = false;
|
||||
resp.ErrorType = MesErrorType.ClientError;
|
||||
resp.ErrorMessage = "结果加工参数上传异常:" + ex.Message;
|
||||
}
|
||||
return mesResponse;
|
||||
return resp;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
using JY.MES.Enum;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JY.MES.Entity
|
||||
{
|
||||
public class MesCallResult<T>
|
||||
{
|
||||
public bool IsSuccess { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 错误类型枚举
|
||||
/// </summary>
|
||||
public MesErrorType ErrorType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 错误描述
|
||||
/// </summary>
|
||||
public string ErrorMessage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// mes实际返回的响应
|
||||
/// </summary>
|
||||
public T OriResponse { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// mes实际返回的响应json字符串
|
||||
/// </summary>
|
||||
public string OriRespJsonStr { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JY.MES.Enum
|
||||
{
|
||||
public enum MesErrorType
|
||||
{
|
||||
None, // 无错误
|
||||
NetworkError, // 网络错误(DNS、连接拒绝等)
|
||||
NetworkTimeout, // 网络超时
|
||||
BusinessError, // 业务错误(200但业务失败)
|
||||
ParseError, // 响应解析失败
|
||||
ClientError, // 客户端错误(400)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JY.MES.Exceptions
|
||||
{
|
||||
public class MesNetworkException : Exception
|
||||
{
|
||||
public MesNetworkException(string message) : base(message)
|
||||
{ }
|
||||
|
||||
public MesNetworkException() : base("MES网络异常")
|
||||
{ }
|
||||
}
|
||||
}
|
||||
@@ -48,6 +48,7 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Entity\MesCallResult.cs" />
|
||||
<Compile Include="Entity\UploadAlarmParam.cs" />
|
||||
<Compile Include="Entity\UploadTestDataParam.cs" />
|
||||
<Compile Include="Entity\UploadAlarmResult.cs" />
|
||||
@@ -56,6 +57,8 @@
|
||||
<Compile Include="Entity\CheckBarcodeParam.cs" />
|
||||
<Compile Include="Entity\EqpStatusResult.cs" />
|
||||
<Compile Include="Entity\EqpStatusParam.cs" />
|
||||
<Compile Include="Enum\MesErrorType.cs" />
|
||||
<Compile Include="Exceptions\MesNetworkException.cs" />
|
||||
<Compile Include="FMS\FMS_Alarm.cs" />
|
||||
<Compile Include="FMS\FMS_Materialln.cs" />
|
||||
<Compile Include="FMS\FMS_Status.cs" />
|
||||
@@ -71,7 +74,9 @@
|
||||
<Compile Include="MES\ReqArrivalStation.cs" />
|
||||
<Compile Include="MES\ReqExitStation.cs" />
|
||||
<Compile Include="MES\RespArrivalStation.cs" />
|
||||
<Compile Include="MES\RespBase.cs" />
|
||||
<Compile Include="MES\RespExitStation.cs" />
|
||||
<Compile Include="MES\RespProductResult.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -9,26 +9,8 @@ namespace JY.MES.MES
|
||||
/// <summary>
|
||||
/// 产品进站响应信息
|
||||
/// </summary>
|
||||
public class RespArrivalStation
|
||||
public class RespArrivalStation : RespBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 错误代码,成功不返回
|
||||
/// </summary>
|
||||
public string Code { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 成功标识,false失败 true 成功
|
||||
/// </summary>
|
||||
public bool Success { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 数据处理消息,成功不返回
|
||||
/// </summary>
|
||||
public string Message { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 报错消息类型 A:停线、B:排出、C:忽略(需警示)
|
||||
/// </summary>
|
||||
public string Category { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JY.MES.MES
|
||||
{
|
||||
/// <summary>
|
||||
/// 1440项目对应MES响应消息基类
|
||||
/// </summary>
|
||||
public abstract class RespBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 错误代码,成功不返回
|
||||
/// </summary>
|
||||
public string Code { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 成功标识,false失败 true 成功
|
||||
/// </summary>
|
||||
public bool Success { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 数据处理消息,成功不返回
|
||||
/// </summary>
|
||||
public string Message { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 报错消息类型 A:停线、B:排出、C:忽略(需警示)
|
||||
/// </summary>
|
||||
public string Category { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ namespace JY.MES.MES
|
||||
/// <summary>
|
||||
/// 产品出站响应信息
|
||||
/// </summary>
|
||||
public sealed class RespExitStation : RespArrivalStation
|
||||
public sealed class RespExitStation : RespBase
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JY.MES.MES
|
||||
{
|
||||
/// <summary>
|
||||
/// 结果加工参数响应信息
|
||||
/// </summary>
|
||||
public class RespProductResult : RespBase
|
||||
{
|
||||
}
|
||||
}
|
||||
+45
-4
@@ -1,6 +1,10 @@
|
||||
using JY.MES.Entity;
|
||||
using JY.MES.Enum;
|
||||
using JY.MES.Exceptions;
|
||||
using JY.MES.MES;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.CodeDom;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@@ -31,11 +35,48 @@ namespace JY.MES
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
mesResponse.success = false;
|
||||
mesResponse.message = $"massage:[{ex.InnerException}],mes: [MES反馈超时或无法访间MES服务器]";
|
||||
mesResponse.error = 99;
|
||||
return JsonConvert.SerializeObject(mesResponse);
|
||||
throw new MesNetworkException($"massage:[{ex.InnerException}],mes: [MES反馈超时或无法访间MES服务器]");
|
||||
}
|
||||
}
|
||||
|
||||
public static MesCallResult<T> HttpPostJsonAPI<T>(string url, string strJosnData, double MesRequestTime)
|
||||
{
|
||||
var result = new MesCallResult<T>() { IsSuccess = false };
|
||||
|
||||
try
|
||||
{
|
||||
StringContent stringContent = new StringContent(strJosnData, Encoding.UTF8, "application/json");
|
||||
string respJsonStr = new HttpClient()
|
||||
{
|
||||
Timeout = TimeSpan.FromSeconds(MesRequestTime)
|
||||
}.PostAsync(url, (HttpContent)stringContent).Result.Content.ReadAsStringAsync().Result;
|
||||
|
||||
var mesResp = JsonConvert.DeserializeObject<T>(respJsonStr);
|
||||
|
||||
result.IsSuccess = true;
|
||||
result.OriResponse = mesResp;
|
||||
result.OriRespJsonStr = respJsonStr;
|
||||
}
|
||||
catch (TimeoutException ex)
|
||||
{
|
||||
result.ErrorType = MesErrorType.NetworkTimeout;
|
||||
result.ErrorMessage = $"MES请求超时: {ex.Message}";
|
||||
return result;
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
result.ErrorType = MesErrorType.NetworkError;
|
||||
result.ErrorMessage = $"MES网络请求失败: {ex.Message}";
|
||||
return result;
|
||||
}
|
||||
catch (JsonException ex)
|
||||
{
|
||||
result.ErrorType = MesErrorType.ParseError;
|
||||
result.ErrorMessage = $"MES响应解析失败: {ex.Message}";
|
||||
return result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user