分档
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using JinYuan.MES.Models;
|
||||
using JinYuan.Models;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JinYuan.MES
|
||||
{
|
||||
@@ -228,5 +229,19 @@ namespace JinYuan.MES
|
||||
/// <param name="resJson"></param>
|
||||
/// <returns></returns>
|
||||
bool UploadDeviceCollectData(string url, string equipNum, List<string> antiDustAirSpeedNum, List<float> collectData, ref string msg);
|
||||
|
||||
/// <summary>
|
||||
/// MES分档接口
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="barCode"></param>
|
||||
/// <param name="siteCode"></param>
|
||||
/// <param name="lineCode"></param>
|
||||
/// <param name="userName"></param>
|
||||
/// <param name="equipCode"></param>
|
||||
/// <param name="materialCode"></param>
|
||||
/// <returns></returns>
|
||||
(bool Success, List<string> MesMessage, List<string> MesResType) MesGrading(
|
||||
string url, string barCode, string siteCode, string lineCode, string userName, string equipCode, string materialCode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace JinYuan.MES
|
||||
{
|
||||
@@ -1796,5 +1798,158 @@ namespace JinYuan.MES
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 17、单个电池分档
|
||||
/// <summary>
|
||||
/// 单个电池分档
|
||||
/// </summary>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="barCode"></param>
|
||||
/// <param name="siteCode"></param>
|
||||
/// <param name="lineCode"></param>
|
||||
/// <param name="userName"></param>
|
||||
/// <param name="equipCode"></param>
|
||||
/// <param name="materialCode"></param>
|
||||
/// <returns></returns>
|
||||
public (bool Success, List<string> MesMessage, List<string> MesResType) MesGrading(
|
||||
string url, string barCode, string siteCode, string lineCode, string userName, string equipCode, string materialCode)
|
||||
{
|
||||
bool res = false; // 操作结果
|
||||
string resJson = ""; // 日志信息
|
||||
|
||||
//string mesage = ""; // 消息
|
||||
//MesResType mesResType = MesResType.D; // 默认响应类型
|
||||
var lstbarCode = new List<string>();
|
||||
lstbarCode.Add(barCode);
|
||||
List<string> mesage = GetListString(lstbarCode.Count, "分档失败"); // 消息列表
|
||||
List<string> mesResType = GetListString(lstbarCode.Count, "NULL"); // 响应类型列表
|
||||
|
||||
try
|
||||
{
|
||||
// 直接构建电池信息列表(对应materiallotCodeList)
|
||||
JArray materiallotCodeList = new JArray(lstbarCode);
|
||||
JObject gradingParam = new JObject();
|
||||
gradingParam.Add("siteCode", siteCode);
|
||||
gradingParam.Add("lineCode", lineCode);
|
||||
gradingParam.Add("userName", userName);
|
||||
gradingParam.Add("equipCode", equipCode);
|
||||
gradingParam.Add("recordDate", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
|
||||
gradingParam.Add("qty", 1);
|
||||
gradingParam.Add("containerCode", "");
|
||||
gradingParam.Add("materialCode", materialCode);
|
||||
gradingParam.Add("materiallotCodeList", materiallotCodeList);
|
||||
|
||||
|
||||
// 序列化请求数据
|
||||
var nowDate = DateTime.Now;
|
||||
var postcontent = JsonConvert.SerializeObject(gradingParam);
|
||||
|
||||
// 记录请求开始时间
|
||||
var sw = Stopwatch.StartNew();
|
||||
|
||||
// 调用异步API
|
||||
string result = MESApiHelper.WepPostAPIAsync(url, postcontent);
|
||||
|
||||
// 记录请求结束时间
|
||||
sw.Stop();
|
||||
|
||||
// 如果请求耗时超过1秒,记录日志
|
||||
long outTime = sw.ElapsedMilliseconds;
|
||||
if (outTime > 1000)
|
||||
{
|
||||
LoggerHelp.WriteLog($"卷芯分档PC<=>MES上传耗时:{outTime}ms,卷芯码:{string.Join(",", lstbarCode)}", "MESTime");
|
||||
|
||||
}
|
||||
|
||||
// 如果返回结果为空,记录日志并返回
|
||||
if (string.IsNullOrEmpty(result))
|
||||
{
|
||||
string resData = result == "" ? "" : result;
|
||||
resJson = $"{nowDate.ToString("yyyy-MM-dd HH:mm:ss.fff")}:调用分档信息(包装)接口:{url},请求数据为:{postcontent},\n{nowDate.AddMilliseconds(sw.ElapsedMilliseconds).ToString("yyyy-MM-dd HH:mm:ss.fff")}:接口耗时:{sw.ElapsedMilliseconds}ms,返回结果:{resData}";
|
||||
TxtHelper.WriteTxt($@"D:\APILog\Logs\MesLogs\{nowDate.ToString("yyyyMMdd")}\产品出站信息\{nowDate.ToString("HH")}.txt", resJson);
|
||||
return (res, mesage, mesResType);
|
||||
}
|
||||
|
||||
// 解析返回结果 - 修改部分开始
|
||||
var res1 = ReturnMesMsg<MesGradingResponse>(result);
|
||||
|
||||
|
||||
|
||||
if (res1.success)
|
||||
{
|
||||
// 处理单个电池的结果(当只上传一个电池时)
|
||||
for (int i = 0; i < lstbarCode.Count; i++)
|
||||
{
|
||||
string MesGrading = "NULL";
|
||||
string Mesage = string.Empty;
|
||||
GetGradingMesResType(res1, barCode, ref Mesage, ref MesGrading);
|
||||
mesage[i] = Mesage ?? "分档成功";
|
||||
mesResType[i] = MesGrading;
|
||||
}
|
||||
res = true;
|
||||
resJson = $"{nowDate.ToString("yyyy-MM-dd HH:mm:ss.fff")}:调用分档信息(包装)接口:{url},请求数据为:{postcontent},\n{nowDate.AddMilliseconds(sw.ElapsedMilliseconds).ToString("yyyy-MM-dd HH:mm:ss.fff")}:接口耗时:{sw.ElapsedMilliseconds}ms,返回结果:{result}";
|
||||
TxtHelper.WriteTxt($@"D:\APILog\Logs\MesLogs\{nowDate.ToString("yyyyMMdd")}\调用分档信息\{nowDate.ToString("HH")}.txt", resJson);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 设置所有电池的错误消息
|
||||
for (int i = 0; i < lstbarCode.Count; i++)
|
||||
{
|
||||
mesage[i] = "分档失败";
|
||||
mesResType[i] = "NULL";
|
||||
}
|
||||
// 如果操作失败,记录日志
|
||||
resJson = $"{nowDate.ToString("yyyy-MM-dd HH:mm:ss.fff")}:调用分档信息(包装)接口:{url},请求数据为:{postcontent},\n{nowDate.AddMilliseconds(sw.ElapsedMilliseconds).ToString("yyyy-MM-dd HH:mm:ss.fff")}:接口耗时:{sw.ElapsedMilliseconds}ms,返回结果:{result}";
|
||||
TxtHelper.WriteTxt($@"D:\APILog\Logs\MesLogs\{nowDate.ToString("yyyyMMdd")}\调用分档信息\{nowDate.ToString("HH")}.txt", resJson);
|
||||
}
|
||||
|
||||
// 修改部分结束
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// 捕获异常并记录日志
|
||||
resJson = $"调用分档信息(包装)接口发生异常:{ex.Message}";
|
||||
LoggerHelp.WriteEX("调用分档信息(包装)接口", ex);
|
||||
|
||||
}
|
||||
|
||||
// 返回结果
|
||||
return (res, mesage, mesResType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 单电池分档
|
||||
/// </summary>
|
||||
/// <param name="res1"></param>
|
||||
/// <param name="BarCode"></param>
|
||||
/// <param name="MesMessage"></param>
|
||||
/// <param name="mesResType"></param>
|
||||
private void GetGradingMesResType(MesGradingResponse res1, string BarCode, ref string MesMessage, ref string MesGrading)
|
||||
{
|
||||
if (res1 != null && res1.rows != null)
|
||||
{
|
||||
rowsListItem row = null;
|
||||
foreach (var item in res1.rows)
|
||||
{
|
||||
if (item.identification == BarCode)
|
||||
{
|
||||
row = item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (row != null)
|
||||
{
|
||||
MesMessage = row.message.ToString();
|
||||
MesGrading = row.rank;
|
||||
}
|
||||
else
|
||||
{
|
||||
MesMessage = "返回为空!";
|
||||
MesGrading = "NULL";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,4 +167,41 @@ namespace JinYuan.MES.Models
|
||||
{
|
||||
public List<T> Result { get; set; }
|
||||
}
|
||||
|
||||
public class MesGradingResponse : MesResponse
|
||||
{
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 报错消息类型 A=停线,B=排出,C=忽略(需警示)
|
||||
/// </summary>
|
||||
public string category { get; set; }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 条码及档位结果信息
|
||||
/// </summary>
|
||||
public List<rowsListItem> rows { get; set; }
|
||||
|
||||
|
||||
|
||||
}
|
||||
public class rowsListItem
|
||||
{
|
||||
/// <summary>
|
||||
/// 电池条码
|
||||
/// </summary>
|
||||
public string identification { get; set; }
|
||||
/// <summary>
|
||||
/// 电池等级
|
||||
/// </summary>
|
||||
public string level { get; set; }
|
||||
/// <summary>
|
||||
/// 电池挡位
|
||||
/// </summary>
|
||||
public string rank { get; set; }
|
||||
|
||||
public object passage { get; set; }
|
||||
public object message { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user