2595 lines
126 KiB
C#
2595 lines
126 KiB
C#
using JinYuan.Helper;
|
||
using JinYuan.MES.Enums;
|
||
using JinYuan.MES.Models;
|
||
using JinYuan.Models;
|
||
using Newtonsoft.Json;
|
||
using Newtonsoft.Json.Linq;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Diagnostics;
|
||
using System.IO;
|
||
using System.Linq;
|
||
using System.Net.Http;
|
||
using System.Reflection.Emit;
|
||
using System.Runtime.Remoting.Messaging;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
|
||
namespace JinYuan.MES
|
||
{
|
||
public class MesDataProcess : IMes
|
||
{
|
||
|
||
|
||
#region 1、登录验证 √
|
||
|
||
/// 账号密码登录(异步方法)
|
||
/// </summary>
|
||
/// <param name="url">API地址</param>
|
||
/// <param name="siteCode">站点代码</param>
|
||
/// <param name="lineCode">线体代码</param>
|
||
/// <param name="equipNum">设备编号</param>
|
||
/// <param name="userName">用户名</param>
|
||
/// <param name="passWord">密码</param>
|
||
/// <param name="UserCardID">用户卡ID</param>
|
||
/// <returns>返回结果(是否成功、消息)</returns> userCardID = UserCardID
|
||
public async Task<(bool Success, string Message, string MesUserLevel)> LoginEnyityAsync(string url, string siteCode, string lineCode, string equipNum, string userName, string passWord)
|
||
{
|
||
bool res = false; // 操作结果
|
||
string resJson = ""; // 日志信息
|
||
string message = ""; // 消息
|
||
string mesUserName = "";//mes返回登陆权限
|
||
|
||
try
|
||
{
|
||
// 创建请求模型
|
||
var model = new LoginEnyity
|
||
{
|
||
siteCode = siteCode,
|
||
lineCode = lineCode,
|
||
equipNum = equipNum,
|
||
userName = userName,
|
||
passWord = passWord,
|
||
|
||
};
|
||
|
||
// 序列化请求数据
|
||
var nowDate = DateTime.Now;
|
||
var postData = JsonConvert.SerializeObject(model);
|
||
|
||
// 记录请求开始时间
|
||
var sw = Stopwatch.StartNew();
|
||
|
||
// 调用异步API
|
||
string result = await MESApiHelper.SendRequestStringAsync(url, HttpMethod.Post, postData, false);
|
||
|
||
// 记录请求结束时间
|
||
sw.Stop();
|
||
|
||
// 如果返回结果为空,记录日志并返回
|
||
if (string.IsNullOrEmpty(result))
|
||
{
|
||
string resData = result == "" ? "" : result;
|
||
resJson = $"{nowDate.ToString("yyyy-MM-dd HH:mm:ss.fff")}:调用员工权限校验接口:{url},请求数据为:{postData},\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, message, mesUserName);
|
||
}
|
||
|
||
// 解析返回结果
|
||
var res1 = JsonConvert.DeserializeObject<MesResponseLogin>(result);
|
||
|
||
// 如果操作成功
|
||
if (res1 != null && res1.success && string.IsNullOrEmpty(res1.code) && string.IsNullOrEmpty(res1.message))
|
||
{
|
||
//mes登陆权限赋值
|
||
if (res1.rows[0].username == userName) { mesUserName = res1.rows[0].permissionLevel; }
|
||
|
||
res = true;
|
||
message = res1.message;
|
||
resJson = $"{nowDate.ToString("yyyy-MM-dd HH:mm:ss.fff")}:调用员工权限校验接口:{url},请求数据为:{postData}\n{nowDate.AddMilliseconds(sw.ElapsedMilliseconds).ToString("yyyy-MM-dd HH:mm:ss.fff")}:接口耗时:{sw.ElapsedMilliseconds}ms,返回结果:{JsonConvert.SerializeObject(result)}";
|
||
TxtHelper.WriteTxt($@"D:\APILog\Logs\MesLogs\{nowDate.ToString("yyyyMMdd")}\员工权限校验\{nowDate.ToString("HH")}.txt", resJson);
|
||
}
|
||
else
|
||
{
|
||
// 如果操作失败,记录日志
|
||
var resData = res1 == null ? "" : JsonConvert.SerializeObject(res1);
|
||
message = res1?.message ?? "未知错误";
|
||
resJson = $"{nowDate.ToString("yyyy-MM-dd HH:mm:ss.fff")}:调用员工权限校验接口:{url},请求数据为:{postData}\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);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
// 捕获异常并记录日志
|
||
message = "调用员工权限校验接口发生异常";
|
||
resJson = $"调用员工权限校验接口发生异常:{ex.Message}";
|
||
LogHelper.Instance.WriteEX("调用员工权限校验接口", ex);
|
||
}
|
||
|
||
// 返回结果
|
||
return (res, message, mesUserName);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 刷卡登录
|
||
/// </summary>
|
||
/// <param name="url"></param>
|
||
/// <param name="siteCode"></param>
|
||
/// <param name="lineCode"></param>
|
||
/// <param name="equipNum"></param>
|
||
/// <param name="UserCardID"></param>
|
||
/// <returns></returns>
|
||
|
||
public async Task<(bool Success, string Message)> LoginEnyityAsync(string url, string siteCode, string lineCode, string equipNum, string UserCardID)
|
||
{
|
||
bool res = false; // 操作结果
|
||
string resJson = ""; // 日志信息
|
||
string message = ""; // 消息
|
||
|
||
try
|
||
{
|
||
// 创建请求模型
|
||
var model = new LoginEnyity
|
||
{
|
||
siteCode = siteCode,
|
||
lineCode = lineCode,
|
||
equipNum = equipNum,
|
||
userCardID = UserCardID,
|
||
|
||
};
|
||
|
||
// 序列化请求数据
|
||
var nowDate = DateTime.Now;
|
||
var postData = JsonConvert.SerializeObject(model);
|
||
|
||
// 记录请求开始时间
|
||
var sw = Stopwatch.StartNew();
|
||
|
||
// 调用异步API
|
||
string result = await MESApiHelper.SendRequestStringAsync(url, HttpMethod.Post, postData, false);
|
||
|
||
// 记录请求结束时间
|
||
sw.Stop();
|
||
|
||
// 如果返回结果为空,记录日志并返回
|
||
if (string.IsNullOrEmpty(result))
|
||
{
|
||
string resData = result == "" ? "" : result;
|
||
resJson = $"{nowDate.ToString("yyyy-MM-dd HH:mm:ss.fff")}:调用员工权限校验接口:{url},请求数据为:{postData},\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, message);
|
||
}
|
||
|
||
// 解析返回结果
|
||
var res1 = JsonConvert.DeserializeObject<MesResponse>(result);
|
||
|
||
// 如果操作成功
|
||
if (res1 != null && res1.success && string.IsNullOrEmpty(res1.code) && string.IsNullOrEmpty(res1.message))
|
||
{
|
||
res = true;
|
||
message = res1.message;
|
||
resJson = $"{nowDate.ToString("yyyy-MM-dd HH:mm:ss.fff")}:调用员工权限校验接口:{url},请求数据为:{postData}\n{nowDate.AddMilliseconds(sw.ElapsedMilliseconds).ToString("yyyy-MM-dd HH:mm:ss.fff")}:接口耗时:{sw.ElapsedMilliseconds}ms,返回结果:{JsonConvert.SerializeObject(result)}";
|
||
TxtHelper.WriteTxt($@"D:\APILog\Logs\MesLogs\{nowDate.ToString("yyyyMMdd")}\员工权限校验\{nowDate.ToString("HH")}.txt", resJson);
|
||
}
|
||
else
|
||
{
|
||
// 如果操作失败,记录日志
|
||
var resData = res1 == null ? "" : JsonConvert.SerializeObject(res1);
|
||
message = res1?.message ?? "未知错误";
|
||
resJson = $"{nowDate.ToString("yyyy-MM-dd HH:mm:ss.fff")}:调用员工权限校验接口:{url},请求数据为:{postData}\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);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
// 捕获异常并记录日志
|
||
message = "调用员工权限校验接口发生异常";
|
||
resJson = $"调用员工权限校验接口发生异常:{ex.Message}";
|
||
LogHelper.Instance.WriteEX("调用员工权限校验接口", ex);
|
||
}
|
||
|
||
// 返回结果
|
||
return (res, message);
|
||
}
|
||
#endregion
|
||
|
||
#region 2、获取MES参数请求
|
||
/// <summary>
|
||
/// 获取MES参数请求
|
||
/// </summary>
|
||
/// <param name="url"></param>
|
||
/// <param name="equipNum"></param>
|
||
/// <param name="siteCode"></param>
|
||
/// <param name="lineCode"></param>
|
||
/// <param name="materialCode"></param>
|
||
/// <param name="userName"></param>
|
||
/// <param name="resJson"></param>
|
||
/// <returns></returns>
|
||
public async Task<(ParamReturnData Data, string Mesage)> GetParamSetRequestAsync(string url, string siteCode, string lineCode, string equipNum, string materialCode, string userName)
|
||
{
|
||
string resJson = "";
|
||
string mesage = ""; // 用于存储消息
|
||
|
||
try
|
||
{
|
||
var model = new
|
||
{
|
||
siteCode = siteCode,
|
||
lineCode = lineCode,
|
||
equipNum = equipNum,
|
||
materialCode = materialCode,
|
||
userName = userName
|
||
};
|
||
|
||
var nowDate = DateTime.Now;
|
||
var postcontent = JsonConvert.SerializeObject(model);
|
||
|
||
var sw = new Stopwatch();
|
||
sw.Start();
|
||
string result = await MESApiHelper.SendRequestStringAsync(url, HttpMethod.Post, postcontent, false);
|
||
|
||
|
||
sw.Stop();
|
||
|
||
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 (null, mesage);
|
||
}
|
||
|
||
var res1 = ReturnMesMsg<ParamReturnData>(result);
|
||
if (res1.success)
|
||
{
|
||
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
|
||
{
|
||
var resData = res1 == null ? "" : result;
|
||
mesage = "MES返回结果为空";
|
||
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 (res1, mesage);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
mesage = $"设备参数设定值请求接口发生异常:{ex.Message}";
|
||
LogHelper.Instance.WriteEX("设备参数设定值请求接口", ex);
|
||
return (null, mesage);
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
#region 3、参数变更请求
|
||
/// <summary>
|
||
/// 参数变更请求
|
||
/// </summary>
|
||
/// <param name="url"></param>
|
||
/// <param name="siteCode"></param>
|
||
/// <param name="lineCode"></param>
|
||
/// <param name="equipNum"></param>
|
||
/// <param name="materialCode"></param>
|
||
/// <param name="userName"></param>
|
||
/// <param name="paramChangeItems"></param>
|
||
/// <param name="Mesage"></param>
|
||
/// <returns></returns>
|
||
public async Task<bool> ParamChange(string url, string siteCode, string lineCode, string equipNum, string materialCode, string userName, List<TagListItem> paramChangeItems)
|
||
{
|
||
bool res = false;
|
||
string resJson = "";
|
||
try
|
||
{
|
||
var model = new ParamChange
|
||
{
|
||
siteCode = siteCode,
|
||
lineCode = lineCode,
|
||
equipNum = equipNum,
|
||
materialCode = materialCode,
|
||
userName = userName,
|
||
//changeTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
|
||
//tagGroupCode = "",
|
||
//tagGroupDescription = "",
|
||
};
|
||
|
||
//model.tagList = new List<TagListItem>();
|
||
//model.tagList.Add(new TagListItem
|
||
//{
|
||
// tagCode = "",
|
||
// unitBefore = "",
|
||
//});
|
||
|
||
var nowDate = DateTime.Now;
|
||
var postcontent = JsonConvert.SerializeObject(model);
|
||
|
||
var sw = new Stopwatch();
|
||
sw.Start();
|
||
string result = await MESApiHelper.SendRequestStringAsync(url, HttpMethod.Post, postcontent, false);
|
||
sw.Stop();
|
||
|
||
|
||
var 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\MesLogs\{nowDate.ToString("yyyyMMdd")}\参数设定值变更\{nowDate.ToString("HH")}.txt", resJson);
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
resJson = $"参数设定值变更接口发生异常:{ex.Message}";
|
||
LogHelper.Instance.WriteEX("参数设定值变更接口", ex);
|
||
}
|
||
|
||
return res;
|
||
|
||
}
|
||
#endregion
|
||
|
||
#region 4、单个上传(只上传卷芯码,不上传托杯码)
|
||
/// <summary>
|
||
/// 单个上传(只上传卷芯码,不上传托杯码)
|
||
/// </summary>
|
||
/// <param name="url"></param>
|
||
/// <param name="siteCode"></param>
|
||
/// <param name="lineCode"></param>
|
||
/// <param name="equipNum"></param>
|
||
/// <param name="materialCode"></param>
|
||
/// <param name="userName"></param>
|
||
/// <param name="BarCode"></param>
|
||
/// <returns>{"rows":[{"code":null,"success":true,"message":null,"identification":"InsertAt20231218095755934","containerCode":null,"category":null}],"success":true,"total":1}
|
||
/// </returns>
|
||
public async Task<(bool Success, string Mesage, MesResType MesResType)> SingleCellInStationAsync(string url, string siteCode, string lineCode, string equipNum, string materialCode, string userName, string BarCode)
|
||
{
|
||
bool res = false;
|
||
string resJson = "";
|
||
string mesage = ""; // 用于存储消息
|
||
MesResType mesResType = MesResType.D; // 默认为 OK
|
||
|
||
try
|
||
{
|
||
var model = new SingleCellInStation
|
||
{
|
||
siteCode = siteCode,
|
||
lineCode = lineCode,
|
||
equipNum = equipNum,
|
||
materialCode = materialCode,
|
||
userName = userName,
|
||
identification = BarCode,
|
||
productType = "OK"
|
||
};
|
||
|
||
var nowDate = DateTime.Now;
|
||
var postcontent = JsonConvert.SerializeObject(model);
|
||
|
||
var sw = new Stopwatch();
|
||
sw.Start();
|
||
string result = await MESApiHelper.SendRequestStringAsync(url, HttpMethod.Post, postcontent, false);
|
||
sw.Stop();
|
||
|
||
long outTime = sw.ElapsedMilliseconds;
|
||
if (outTime > 1000)
|
||
{
|
||
LogHelper.Instance.WriteLog($"钢壳进站PC<=>MES上传耗时:{outTime}ms,钢壳码:{BarCode}", "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<MesResponseSingle>(result);
|
||
if (res1.success)
|
||
{
|
||
res = true;
|
||
GetInMesResType(res1, BarCode, ref mesage, ref mesResType);
|
||
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
|
||
{
|
||
var resData = res1 == null ? "" : result;
|
||
mesage = res1.message;
|
||
|
||
if (res1.category != "")
|
||
{
|
||
switch (res1.category)
|
||
{
|
||
case "A":
|
||
mesResType = MesResType.A;
|
||
break;
|
||
case "B":
|
||
mesResType = MesResType.B;
|
||
break;
|
||
case "C":
|
||
mesResType = MesResType.C;
|
||
break;
|
||
case "D":
|
||
mesResType = MesResType.D;
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
|
||
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);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
mesage = "调用进站接口超时或MES无返回信息!";
|
||
mesResType = MesResType.B;
|
||
resJson = $"产品进站信息(组装)接口发生异常:{ex.Message}";
|
||
LogHelper.Instance.WriteEX("产品进站信息(组装)接口", ex);
|
||
}
|
||
|
||
return (res, mesage, mesResType);
|
||
}
|
||
#endregion
|
||
|
||
#region 5、复投单个上传(只上传条码,不上传卷芯码)
|
||
|
||
/// 复投单个上传(异步方法)
|
||
/// </summary>
|
||
/// <param name="url">API地址</param>
|
||
/// <param name="siteCode">站点代码</param>
|
||
/// <param name="lineCode">线体代码</param>
|
||
/// <param name="equipNum">设备编号</param>
|
||
/// <param name="materialCode">物料代码</param>
|
||
/// <param name="userName">用户名</param>
|
||
/// <param name="BarCode">条码</param>
|
||
/// <returns>返回结果(是否成功、日志信息、响应类型)</returns>
|
||
public async Task<(bool, string, MesResType)> SingleFTCellInStationAsync(string url, string siteCode, string lineCode, string equipNum, string materialCode, string userName, string BarCode)
|
||
{
|
||
bool res = false; // 操作结果
|
||
string resJson = ""; // 日志信息
|
||
MesResType mesResType = new MesResType(); // 响应类型
|
||
|
||
try
|
||
{
|
||
// 创建请求模型
|
||
var model = new ManyCellInStation
|
||
{
|
||
siteCode = siteCode,
|
||
lineCode = lineCode,
|
||
equipNum = equipNum,
|
||
materialCode = materialCode,
|
||
userName = userName,
|
||
identificationList = new List<string> { BarCode }, // 电芯条码
|
||
containerCodeList = new List<string>() // 电芯托杯码(为空)
|
||
};
|
||
|
||
// 序列化请求数据
|
||
var nowDate = DateTime.Now;
|
||
var postcontent = JsonConvert.SerializeObject(model);
|
||
|
||
// 记录请求开始时间
|
||
var sw = Stopwatch.StartNew();
|
||
|
||
// 调用异步API
|
||
string result = await MESApiHelper.SendRequestStringAsync(url, HttpMethod.Post, postcontent, false);
|
||
|
||
// 记录请求结束时间
|
||
sw.Stop();
|
||
|
||
// 如果请求耗时超过1秒,记录日志
|
||
long outTime = sw.ElapsedMilliseconds;
|
||
if (outTime > 1000)
|
||
{
|
||
LogHelper.Instance.WriteLog($"钢壳进站PC<=>MES上传耗时:{outTime}ms,钢壳码:{BarCode}", "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, resJson, mesResType);
|
||
}
|
||
|
||
// 解析返回结果
|
||
var res1 = JsonConvert.DeserializeObject<MesResponseSingle>(result);
|
||
|
||
// 如果操作成功
|
||
if (res1.success)
|
||
{
|
||
res = true;
|
||
GetInMesResType(res1, BarCode, ref resJson, ref mesResType); // 处理返回结果
|
||
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
|
||
{
|
||
// 如果操作失败,记录日志
|
||
var resData = res1 == null ? "" : 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);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
// 捕获异常并记录日志
|
||
resJson = $"产品进站信息(组装)接口发生异常:{ex.Message}";
|
||
LogHelper.Instance.WriteEX("产品进站信息(组装)接口", ex);
|
||
}
|
||
|
||
// 返回结果
|
||
return (res, resJson, mesResType);
|
||
}
|
||
#endregion
|
||
|
||
#region 原材料上传
|
||
/// <summary>
|
||
/// 原材料上传
|
||
/// </summary>
|
||
/// <param name="url"></param>
|
||
/// <param name="MaterialCode"></param>
|
||
/// <param name="equipNum"></param>
|
||
/// <param name="BarCode"></param>
|
||
/// <param name="Mesage"></param>
|
||
/// <param name="mesResType"></param>
|
||
/// <returns></returns>
|
||
public async Task<(bool Success, string MesMessage, MesResType MesResType)> RawMaterialStationAsync(string url, string MaterialCode, string equipNum, string BarCode)
|
||
{
|
||
bool res = false;
|
||
string resJson = "";
|
||
string mesMessage = "失败"; // 消息列表
|
||
MesResType mesResType = MesResType.B; // 响应类型列表
|
||
try
|
||
{
|
||
JObject jo4 = new JObject();
|
||
jo4.Add("materialCode", MaterialCode);//物料编码
|
||
jo4.Add("workOrderNum", "");//工单编号
|
||
jo4.Add("mesEquipNum", equipNum);//设备编号
|
||
|
||
JArray jo5 = new JArray();
|
||
jo5.Add(BarCode);//原材料条码
|
||
jo4.Add("materialLotCodeList", jo5);
|
||
|
||
var nowDate = DateTime.Now;
|
||
var sw = new Stopwatch();
|
||
sw.Start();
|
||
string result = await MESApiHelper.SendRequestStringAsync(url, HttpMethod.Post, jo4, false);
|
||
sw.Stop();
|
||
|
||
if (string.IsNullOrEmpty(result))
|
||
{
|
||
mesMessage = "原材料接口失败,MES服务器或网络异常,请联系MES维护人员处理!";
|
||
string resData = result == "" ? "" : result;
|
||
resJson = $"{nowDate.ToString("yyyy-MM-dd HH:mm:ss.fff")}:调用原材料接口:{url},请求数据为:{jo4.ToString()},\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, mesMessage, mesResType);
|
||
}
|
||
|
||
var res1 = ReturnMesMsg<MaterialMesRespons>(result);
|
||
|
||
if (!res1.success)
|
||
{
|
||
var resData = res1 == null ? "" : JsonConvert.SerializeObject(res1);
|
||
resJson = $"{nowDate.ToString("yyyy-MM-dd HH:mm:ss.fff")}:调用原材料接口:{url},请求数据为:{jo4.ToString()},\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);
|
||
}
|
||
else
|
||
{
|
||
res = true;
|
||
resJson = $"{nowDate.ToString("yyyy-MM-dd HH:mm:ss.fff")}:调用原材料接口:{url},请求数据为:{jo4.ToString()},\n{nowDate.AddMilliseconds(sw.ElapsedMilliseconds).ToString("yyyy-MM-dd HH:mm:ss.fff")}:接口耗时:{sw.ElapsedMilliseconds}ms,返回结果:{JsonConvert.SerializeObject(result)}";
|
||
TxtHelper.WriteTxt($@"D:\APILog\Logs\MesLogs\{nowDate.ToString("yyyyMMdd")}\原材料\{nowDate.ToString("HH")}.txt", resJson);
|
||
}
|
||
|
||
if (res1 != null)
|
||
{
|
||
if (res1.success)
|
||
{
|
||
mesResType = MesResType.D;
|
||
mesMessage = "原材料上传成功";
|
||
}
|
||
else
|
||
{
|
||
mesResType = MesResType.B;
|
||
mesMessage = res1.message;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
mesResType = MesResType.UnKnow;
|
||
mesMessage = "原材料接口调用失败,请联系MES维护人员!";
|
||
}
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
resJson = $"原材料接口发生异常:{ex.Message}";
|
||
LogHelper.Instance.WriteEX("原材料接口", ex);
|
||
}
|
||
|
||
// 返回结果
|
||
return (res, mesMessage, mesResType);
|
||
}
|
||
#endregion
|
||
|
||
#region 多个电池进站(异步方法)(进站)√
|
||
/// <summary>
|
||
/// 多个电池进站(异步方法)
|
||
/// </summary>
|
||
/// <param name="url">API地址</param>
|
||
/// <param name="siteCode">站点代码</param>
|
||
/// <param name="lineCode">线体代码</param>
|
||
/// <param name="equipNum">设备编号</param>
|
||
/// <param name="materialCode">物料代码</param>
|
||
/// <param name="userName">用户名</param>
|
||
/// <param name="listBar">条码列表</param>
|
||
/// <returns>返回结果(是否成功、消息列表、响应类型列表)</returns>
|
||
public async Task<(bool Success, List<string> MesMessage, List<MesResType> MesResType)> ManyCellInStationAsync(string url, string siteCode, string lineCode, string equipNum, string materialCode, string userName, List<string> listBar)
|
||
{
|
||
bool res = false; // 操作结果
|
||
string resJson = ""; // 日志信息
|
||
List<string> mesMessage = GetListString(listBar.Count, "进站失败"); // 消息列表
|
||
List<MesResType> mesResType = GetMesType(listBar.Count); // 响应类型列表
|
||
|
||
try
|
||
{
|
||
// 创建请求模型
|
||
var model = new ManyCellInStation
|
||
{
|
||
siteCode = siteCode,
|
||
lineCode = lineCode,
|
||
equipNum = equipNum,
|
||
//materialCode = materialCode,//取消
|
||
userName = userName,
|
||
productType = "G11",//待定
|
||
identificationList = new List<string>(listBar) // 电芯条码
|
||
};
|
||
|
||
// 序列化请求数据
|
||
var nowDate = DateTime.Now;
|
||
var postcontent = JsonConvert.SerializeObject(model);
|
||
|
||
// 记录请求开始时间
|
||
var sw = Stopwatch.StartNew();
|
||
|
||
// 调用异步API
|
||
string result = await MESApiHelper.SendRequestStringAsync(url, HttpMethod.Post, postcontent, false);
|
||
|
||
// 记录请求结束时间
|
||
sw.Stop();
|
||
|
||
// 如果请求耗时超过1秒,记录日志
|
||
long outTime = sw.ElapsedMilliseconds;
|
||
if (outTime > 1000)
|
||
{
|
||
//LogHelper.Instance.WriteLog($"进站PC<=>MES上传耗时:{outTime}ms,电芯码:{listBar[0]},{listBar[1]},{listBar[2]},{listBar[3]}", "MESTime");
|
||
LogHelper.Instance.WriteLog($"进站PC<=>MES上传耗时:{outTime}ms,电芯码:{string.Join(",", listBar)}", "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, mesMessage, mesResType);
|
||
}
|
||
|
||
// 修改解析部分 - 适应单个电池响应
|
||
var response = JObject.Parse(result);
|
||
bool overallSuccess = response["success"]?.Value<bool>() ?? false;
|
||
|
||
if (overallSuccess)
|
||
{
|
||
res = true;
|
||
// 单个电池的结果处理
|
||
for (int i = 0; i < listBar.Count; i++)
|
||
{
|
||
// 对于单个电池,直接使用整体结果
|
||
mesMessage[i] = response["message"]?.Value<string>() ?? "进站成功";
|
||
mesResType[i] = MesResType.D;
|
||
}
|
||
|
||
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
|
||
{
|
||
// 如果操作失败
|
||
string errorMessage = response["message"]?.Value<string>() ?? "进站失败";
|
||
|
||
List<RowsItemIn> rows = null;
|
||
if (errorMessage.Contains("详情看rows"))
|
||
{
|
||
rows = response["rows"].ToObject<List<RowsItemIn>>();
|
||
|
||
}
|
||
for (int i = 0; i < listBar.Count; i++)
|
||
{
|
||
var detail = GetDetail(rows, listBar[i]);
|
||
mesMessage[i] = detail??errorMessage;
|
||
}
|
||
|
||
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}";
|
||
LogHelper.Instance.WriteEX("产品进站信息(组装)接口", ex);
|
||
}
|
||
|
||
// 返回结果
|
||
return (res, mesMessage, mesResType);
|
||
}
|
||
|
||
private string GetDetail(List<RowsItemIn> rows, string barcode)
|
||
{
|
||
var item = rows.FirstOrDefault(r => r.identification == barcode);
|
||
return item?.moveInErrorInfo??"";
|
||
}
|
||
#endregion
|
||
|
||
#region 多个电池进站1(异步方法)(进站)√
|
||
/// <summary>
|
||
/// 多个电池进站(异步方法)
|
||
/// </summary>
|
||
/// <param name="url">API地址</param>
|
||
/// <param name="siteCode">站点代码</param>
|
||
/// <param name="lineCode">线体代码</param>
|
||
/// <param name="equipNum">设备编号</param>
|
||
/// <param name="materialCode">物料代码</param>
|
||
/// <param name="userName">用户名</param>
|
||
/// <param name="listBar">条码列表</param>
|
||
/// <returns>返回结果(是否成功、消息列表、响应类型列表)</returns>
|
||
public async Task<(bool Success, List<string> MesMessage, List<MesResType> MesResType, List<string> CellCode)> ManyCellInStationAsync1(string url, string siteCode, string lineCode, string equipNum, string materialCode, string userName, List<string> listBar)
|
||
{
|
||
bool res = false; // 操作结果
|
||
string resJson = ""; // 日志信息
|
||
List<string> mesMessage = GetListString(listBar.Count, "进站失败"); // 消息列表
|
||
List<MesResType> mesResType = GetMesType(listBar.Count); // 响应类型列表
|
||
List<string> cellCode = GetListString(listBar.Count, "");
|
||
|
||
try
|
||
{
|
||
// 创建请求模型
|
||
var model = new ManyCellInStation
|
||
{
|
||
siteCode = siteCode,
|
||
lineCode = lineCode,
|
||
equipNum = equipNum,
|
||
materialCode = materialCode,//取消
|
||
userName = userName,
|
||
productType = "OK",//待定
|
||
identificationList = new List<string>(listBar) // 电芯条码
|
||
};
|
||
|
||
// 序列化请求数据
|
||
var nowDate = DateTime.Now;
|
||
var postcontent = JsonConvert.SerializeObject(model);
|
||
|
||
// 记录请求开始时间
|
||
var sw = Stopwatch.StartNew();
|
||
|
||
// 调用异步API
|
||
string result = await MESApiHelper.SendRequestStringAsync(url, HttpMethod.Post, postcontent, false);
|
||
|
||
// 记录请求结束时间
|
||
sw.Stop();
|
||
|
||
// 如果请求耗时超过1秒,记录日志
|
||
long outTime = sw.ElapsedMilliseconds;
|
||
if (outTime > 1000)
|
||
{
|
||
//LogHelper.Instance.WriteLog($"进站PC<=>MES上传耗时:{outTime}ms,电芯码:{listBar[0]},{listBar[1]},{listBar[2]},{listBar[3]}", "MESTime");
|
||
LogHelper.Instance.WriteLog($"进站PC<=>MES上传耗时:{outTime}ms,电芯码:{string.Join(",", listBar)}", "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, mesMessage, mesResType, cellCode);
|
||
}
|
||
|
||
// 解析返回结果
|
||
var res1 = JsonConvert.DeserializeObject<MesResponseIn>(result);
|
||
|
||
// 如果操作成功
|
||
if (res1 != null && res1.success)
|
||
{
|
||
res = true;
|
||
GetInMesResType1(res1, listBar, ref mesMessage, ref mesResType, ref cellCode); // 处理返回结果
|
||
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
|
||
{
|
||
// 如果操作失败,记录日志
|
||
var resData = res1 == null ? "" : 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);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
// 捕获异常并记录日志
|
||
resJson = $"产品进站信息(组装)接口发生异常:{ex.Message}";
|
||
LogHelper.Instance.WriteEX("产品进站信息(组装)接口", ex);
|
||
}
|
||
|
||
// 返回结果
|
||
return (res, mesMessage, mesResType, cellCode);
|
||
}
|
||
#endregion
|
||
|
||
#region 7、单个电池出站 √
|
||
/// <summary>
|
||
/// 单个电池出站(异步方法)
|
||
/// </summary>
|
||
/// <param name="url">API地址</param>
|
||
/// <param name="siteCode">站点代码</param>
|
||
/// <param name="lineCode">线体代码</param>
|
||
/// <param name="equipNum">设备编号</param>
|
||
/// <param name="materialCode">物料代码</param>
|
||
/// <param name="userName">用户名</param>
|
||
/// <param name="m">电池实体</param>
|
||
/// <param name="type">类型</param>
|
||
/// <param name="materialLotCodeLocator">物料批次代码定位器</param>
|
||
/// <returns>返回结果(是否成功、消息、响应类型)</returns>
|
||
public async Task<(bool Success, string Mesage, MesResType MesResType)> SingleCellOutStationAsync(
|
||
string url, string siteCode, string lineCode, string equipNum, string modelName, string materialCode, string userName, BGearEntity m, int type, string materialLotCodeLocator)
|
||
{
|
||
bool res = false; // 操作结果
|
||
string resJson = ""; // 日志信息
|
||
string mesage = ""; // 消息
|
||
MesResType mesResType = MesResType.D; // 默认响应类型
|
||
|
||
try
|
||
{
|
||
// 创建请求数据
|
||
JArray jaIdentiftyList = new JArray(); // identiftyList
|
||
JObject joIdentifty = new JObject();
|
||
joIdentifty.Add("identification", m.BarCode); // 卷心码
|
||
joIdentifty.Add("qualityStatus", m.Result); // 质量状态
|
||
joIdentifty.Add("qrCode", ""); // 二维码
|
||
joIdentifty.Add("ngMessage", ""); // NG信息
|
||
joIdentifty.Add("ngCode", new JArray { "" }); // NG代码
|
||
|
||
// 创建 materialLotList
|
||
JArray jaMaterialLotList = new JArray();
|
||
JObject joMaterialLot = new JObject();
|
||
joMaterialLot.Add("materialLotCode", ""); // 物料批次码
|
||
joMaterialLot.Add("materialLotCodeLocator", ""); // 物料批次码定位
|
||
jaMaterialLotList.Add(joMaterialLot);
|
||
|
||
joIdentifty.Add("materialLotList", jaMaterialLotList); // 将 materialLotList 添加到 identiftyList
|
||
jaIdentiftyList.Add(joIdentifty); // 将 identiftyList 添加到主列表
|
||
|
||
JArray containerCodeAndIdentificationList = new JArray();
|
||
JObject joContainerCodeAndIdentification = new JObject();
|
||
joContainerCodeAndIdentification.Add("containerCode", "");
|
||
joContainerCodeAndIdentification.Add("identiftyList", jaIdentiftyList);
|
||
containerCodeAndIdentificationList.Add(joContainerCodeAndIdentification);
|
||
|
||
// 创建主 JSON 对象
|
||
JObject joRequest = new JObject();
|
||
joRequest.Add("siteCode", siteCode); // 站点代码
|
||
joRequest.Add("lineCode", lineCode); // 线代码
|
||
joRequest.Add("equipNum", equipNum); // 设备编号
|
||
joRequest.Add("userName", userName); // 用户名
|
||
joRequest.Add("materialCode", materialCode); // 物料代码
|
||
joRequest.Add("productType", modelName); // 产品类型
|
||
joRequest.Add("completeQty", "1"); // 完成数量
|
||
joRequest.Add("type", "1"); // 类型
|
||
//joRequest.Add("identiftyList", jaIdentiftyList); // 添加 identiftyList
|
||
joRequest.Add("containerCodeAndIdentificationList", containerCodeAndIdentificationList);
|
||
|
||
// 序列化请求数据
|
||
var nowDate = DateTime.Now;
|
||
var postcontent = JsonConvert.SerializeObject(joRequest);
|
||
|
||
// 记录请求开始时间
|
||
var sw = Stopwatch.StartNew();
|
||
|
||
// 调用异步API
|
||
string result = await MESApiHelper.SendRequestStringAsync(url, HttpMethod.Post, postcontent, false);
|
||
|
||
// 记录请求结束时间
|
||
sw.Stop();
|
||
|
||
// 如果请求耗时超过1秒,记录日志
|
||
long outTime = sw.ElapsedMilliseconds;
|
||
if (outTime > 1000)
|
||
{
|
||
LogHelper.Instance.WriteLog($"卷芯出站PC<=>MES上传耗时:{outTime}ms,卷芯码:{m.BarCode}", "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 = JsonConvert.DeserializeObject<MesResponseOut>(result);
|
||
|
||
// 如果操作成功
|
||
if (res1.success)
|
||
{
|
||
res = true;
|
||
GetOutMesResType(res1, m.BarCode, ref mesage, ref mesResType); // 处理返回结果
|
||
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
|
||
{
|
||
// 如果操作失败,记录日志
|
||
var resData = res1 == null ? "" : result;
|
||
mesage = res1.rows[0].message;
|
||
mesResType = MesResType.B;
|
||
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);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
// 捕获异常并记录日志
|
||
mesage = "产品出站信息(组装)接口发生异常";
|
||
mesResType = MesResType.B;
|
||
resJson = $"产品出站信息(组装)接口发生异常:{ex.Message}";
|
||
LogHelper.Instance.WriteEX("产品出站信息(组装)接口", ex);
|
||
}
|
||
|
||
// 返回结果
|
||
return (res, mesage, mesResType);
|
||
}
|
||
#endregion
|
||
|
||
#region 7.5、多个电池出站 √
|
||
|
||
/// <summary>
|
||
/// 多个电池出站(异步方法)
|
||
/// </summary>
|
||
/// <param name="url">API地址</param >
|
||
/// <param name="siteCode">站点代码</param>
|
||
/// <param name="lineCode">线体代码</param>
|
||
/// <param name="equipNum">设备编号</param>
|
||
/// <param name="materialCode">物料代码</param>
|
||
/// <param name="userName">用户名</param>
|
||
/// <param name="m">电池实体</param>
|
||
/// <param name="type">类型</param>
|
||
/// <param name="materialLotCodeLocator">物料批次代码定位器</param>
|
||
/// <returns>返回结果(是否成功、消息、响应类型)</returns>
|
||
public async Task<(bool Success, List<string> MesMessage, List<MesResType> MesResType)> ManyCellOutStationAsync(
|
||
string url, string siteCode, string lineCode, string equipNum, string modelName, string materialCode, string userName, List<BGearEntity> m, int type, string materialLotCodeLocator)
|
||
{
|
||
bool res = false; // 操作结果
|
||
string resJson = ""; // 日志信息
|
||
//string mesage = ""; // 消息
|
||
//MesResType mesResType = MesResType.D; // 默认响应类型
|
||
List<string> mesage = GetListString(m.Count, "出站失败"); // 消息列表
|
||
List<MesResType> mesResType = GetMesType(m.Count); // 响应类型列表
|
||
|
||
try
|
||
{
|
||
// 直接构建电池信息列表(对应assembleLineList)
|
||
JArray assembleLineList = new JArray();
|
||
|
||
for (int i = 0; i < m.Count; i++)
|
||
{
|
||
JObject batteryInfo = new JObject();
|
||
batteryInfo.Add("identification", m[i].BarCode);
|
||
// batteryInfo.Add("qualityStatus", "OK");
|
||
|
||
batteryInfo.Add("qualityStatus", m[i].Result);
|
||
batteryInfo.Add("qrCode", "");
|
||
//batteryInfo.Add("ngMessage", "");
|
||
//batteryInfo.Add("ngCode", new JArray()); // 目标格式中是空数组
|
||
var ngcode = new List<string>();
|
||
var ngmessage = "";
|
||
if (m[i].BarCode == "NG" || m[i].BarCode.IndexOf("-") >= 0)
|
||
{
|
||
ngcode.Add("UI00404");
|
||
ngmessage += ",扫码NG";
|
||
}
|
||
|
||
batteryInfo.Add("ngMessage", ngmessage);
|
||
batteryInfo.Add("ngCode", new JArray(ngcode.ToArray())); // 目标格式中是空数组
|
||
assembleLineList.Add(batteryInfo);
|
||
}
|
||
|
||
// 构建主请求对象(按目标格式)
|
||
JObject joRequest = new JObject();
|
||
joRequest.Add("siteCode", siteCode);
|
||
joRequest.Add("lineCode", lineCode);
|
||
joRequest.Add("equipNum", equipNum);
|
||
joRequest.Add("userName", userName);
|
||
joRequest.Add("containerCode", ""); // 空字符串
|
||
joRequest.Add("productType", modelName); // 对应目标中的productType
|
||
joRequest.Add("assembleLineList", assembleLineList); // 关键字段名变更
|
||
|
||
// 序列化请求数据
|
||
var nowDate = DateTime.Now;
|
||
var postcontent = JsonConvert.SerializeObject(joRequest);
|
||
|
||
// 记录请求开始时间
|
||
var sw = Stopwatch.StartNew();
|
||
|
||
// 调用异步API
|
||
string result = await MESApiHelper.SendRequestStringAsync(url, HttpMethod.Post, postcontent, false);
|
||
|
||
// 记录请求结束时间
|
||
sw.Stop();
|
||
|
||
// 如果请求耗时超过1秒,记录日志
|
||
long outTime = sw.ElapsedMilliseconds;
|
||
if (outTime > 1000)
|
||
{
|
||
//LogHelper.Instance.WriteLog($"卷芯出站PC<=>MES上传耗时:{outTime}ms,卷芯码:{m.BarCode}", "MESTime");
|
||
List<string> listCode = GetListString(m.Count, "");
|
||
for (int i = 0; i < m.Count; i++)
|
||
{
|
||
listCode.Add(m[i].BarCode);
|
||
}
|
||
LogHelper.Instance.WriteLog($"卷芯出站PC<=>MES上传耗时:{outTime}ms,卷芯码:{string.Join(",", listCode)}", "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 = JsonConvert.DeserializeObject<MesResponseOut>(result);
|
||
|
||
//// 如果操作成功
|
||
//if (res1.success)
|
||
//{
|
||
// res = true;
|
||
// GetManyOutMesResType(res1, m, ref mesage, ref mesResType); // 处理返回结果
|
||
// 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
|
||
//{
|
||
// // 如果操作失败,记录日志
|
||
// var resData = res1 == null ? "" : 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);
|
||
//}
|
||
// 解析返回结果 - 修改部分开始
|
||
var responseObj = JObject.Parse(result);
|
||
bool overallSuccess = responseObj["success"]?.Value<bool>() ?? false;
|
||
|
||
if (responseObj["message"] != null)
|
||
{
|
||
// 处理单个电池的结果(当只上传一个电池时)
|
||
string successMessage = responseObj["message"]?.Value<string>() ?? "出站失败";
|
||
for (int i = 0; i < m.Count; i++)
|
||
{
|
||
//{{
|
||
//"code": "EVEDL_0127",
|
||
// "message": "当前未进站,请检查!【传参电池条码: ZZCE11431A00SF8F0004456】",
|
||
// "success": false,
|
||
// "category": "C"
|
||
//}}
|
||
mesage[i] = successMessage;
|
||
//if (responseObj["category"].ToString() == "C") { mesResType[i] = MesResType.C; }
|
||
//else if (responseObj["category"].ToString() == "D") { mesResType[i] = MesResType.D; }
|
||
//else
|
||
{
|
||
mesResType[i] = MesResType.B;
|
||
}
|
||
}
|
||
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
|
||
{
|
||
|
||
string errorMessage = responseObj["message"]?.Value<string>() ?? "出站成功";
|
||
|
||
// 设置所有电池的错误消息
|
||
for (int i = 0; i < m.Count; i++)
|
||
{
|
||
mesage[i] = errorMessage;
|
||
mesResType[i] = MesResType.D;
|
||
}
|
||
// 如果操作失败,记录日志
|
||
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}";
|
||
LogHelper.Instance.WriteEX("产品出站信息(组装)接口", ex);
|
||
}
|
||
|
||
// 返回结果
|
||
return (res, mesage, mesResType);
|
||
}
|
||
#endregion
|
||
|
||
#region 8、单电池进出站(异步方法)(出站)√
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <param name="url"></param>
|
||
/// <param name="siteCode">工厂代码</param>
|
||
/// <param name="lineCode">产线编号</param>
|
||
/// <param name="equipNum">设备编号</param>
|
||
/// <param name="materialCode">物料编码</param>
|
||
/// <param name="userName">员工账号</param>
|
||
/// <param name="m">BGearEntity</param>
|
||
/// <param name="type">类型</param>
|
||
/// <param name="materialLotCodeLocator">原材料上料位置</param>
|
||
/// <returns></returns>
|
||
public async Task<(bool Success, string Mesage, MesResType MesResType)> SingleCellInAndOutStationAsync(
|
||
string url, string siteCode, string lineCode, string equipNum, string materialCode, string userName, BGearEntity m, int type, string materialLotCodeLocator)
|
||
{
|
||
bool res = false; // 操作结果
|
||
string resJson = ""; // 日志信息
|
||
string mesage = ""; // 消息
|
||
MesResType mesResType = MesResType.D; // 默认响应类型
|
||
|
||
try
|
||
{
|
||
// 创建请求数据
|
||
JArray jaContainerCode = new JArray(); // containerCodeAndIdentificationList
|
||
|
||
JArray jaMaterialLotCodeList = new JArray(); // materialLotCodeList
|
||
JObject jo4 = new JObject();
|
||
jo4.Add("materialLotCode", "");
|
||
jo4.Add("materialLotCodeLocator", materialLotCodeLocator);
|
||
jaMaterialLotCodeList.Add(jo4);
|
||
|
||
JArray jaIdentiftyList = new JArray(); // identiftyList
|
||
JObject jo3 = new JObject();
|
||
jo3.Add("identification", m.BarCode); // 卷心码
|
||
jo3.Add("qualityStatus", m.Result);
|
||
jo3.Add("qrCode", "");
|
||
jo3.Add("ngMessage", m.Remark);
|
||
jo3.Add("ngCode", "");//补
|
||
jo3.Add("materialLotList", jaMaterialLotCodeList);
|
||
jaIdentiftyList.Add(jo3);
|
||
|
||
JObject jo2 = new JObject();
|
||
jo2.Add("containerCode", ""); // 托杯码
|
||
jo2.Add("identiftyList", jaIdentiftyList);
|
||
jaContainerCode.Add(jo2);
|
||
|
||
JObject jo1 = new JObject();
|
||
jo1.Add("siteCode", siteCode);
|
||
jo1.Add("lineCode", lineCode);
|
||
jo1.Add("equipNum", equipNum);
|
||
jo1.Add("materialCode", materialCode);
|
||
jo1.Add("userName", userName);
|
||
jo1.Add("productType", "");
|
||
jo1.Add("completeQty", "");
|
||
jo1.Add("type", 1); // 追溯标识替换
|
||
jo1.Add("containerCodeAndIdentificationList", jaContainerCode);
|
||
|
||
// 序列化请求数据
|
||
var nowDate = DateTime.Now;
|
||
var postcontent = JsonConvert.SerializeObject(jo1);
|
||
|
||
// 记录请求开始时间
|
||
var sw = Stopwatch.StartNew();
|
||
|
||
// 调用异步API
|
||
string result = await MESApiHelper.SendRequestStringAsync(url, HttpMethod.Post, postcontent, false);
|
||
|
||
// 记录请求结束时间
|
||
sw.Stop();
|
||
|
||
// 如果请求耗时超过1秒,记录日志
|
||
long outTime = sw.ElapsedMilliseconds;
|
||
if (outTime > 1000)
|
||
{
|
||
LogHelper.Instance.WriteLog($"钢壳进出站PC<=>MES上传耗时:{outTime}ms,钢壳码:{m.BarCode}", "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 = JsonConvert.DeserializeObject<MesResponseOut>(result);
|
||
|
||
// 如果操作成功
|
||
if (res1.success)
|
||
{
|
||
res = true;
|
||
GetOutMesResType(res1, m.BarCode, ref mesage, ref mesResType); // 处理返回结果
|
||
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
|
||
{
|
||
// 如果操作失败,记录日志
|
||
var resData = res1 == null ? "" : 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);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
// 捕获异常并记录日志
|
||
mesage = "产品进出站一体信息(组装)接口发生异常";
|
||
mesResType = MesResType.B;
|
||
resJson = $"产品进出站一体信息(组装)接口发生异常:{ex.Message}";
|
||
LogHelper.Instance.WriteEX("产品进出站一体信息(组装)接口", ex);
|
||
}
|
||
|
||
// 返回结果
|
||
return (res, mesage, mesResType);
|
||
}
|
||
#endregion
|
||
|
||
#region 多个电芯上传 ×
|
||
/// <summary>
|
||
/// 多个电芯上传
|
||
/// </summary>
|
||
/// <param name="m"></param>
|
||
/// <returns></returns>
|
||
public async Task<(bool Success, List<string> MesMessage, List<MesResType> MesResType)> OutboundInformationsAsync(string url, string siteCode, string lineCode, string equipNum, string materialCode, string userName, List<BGearEntity> listBar)
|
||
{
|
||
bool res = false; // 操作结果
|
||
string resJson = ""; // 日志信息
|
||
List<string> mesMessage = GetListString(listBar.Count, "出站失败"); // 消息列表
|
||
List<MesResType> mesResType = GetMesType(listBar.Count); // 响应类型列表
|
||
|
||
try
|
||
{
|
||
// 创建请求模型
|
||
var model = new ManyCellOutStation
|
||
{
|
||
siteCode = siteCode,
|
||
lineCode = lineCode,
|
||
equipNum = equipNum,
|
||
materialCode = materialCode,
|
||
userName = userName,
|
||
productType = "OK",
|
||
completeQty = listBar.Count.ToString(),
|
||
containerCode = "",
|
||
type = 1
|
||
};
|
||
|
||
// 填充电芯条码信息
|
||
model.identiftyList = new List<identiftyList>();
|
||
for (int i = 0; i < listBar.Count; i++)
|
||
{
|
||
model.identiftyList.Add(new identiftyList
|
||
{
|
||
identification = listBar[i].BarCode,
|
||
materialLotList = new List<string>(),
|
||
materialLotCode = "",
|
||
qualityStatus = listBar[i].Result.ToString(),
|
||
qrCode = "",
|
||
ngCode = new List<string>(),
|
||
ngMessage = ""
|
||
});
|
||
}
|
||
|
||
// 序列化请求数据
|
||
var nowDate = DateTime.Now;
|
||
var postcontent = JsonConvert.SerializeObject(model);
|
||
|
||
// 记录请求开始时间
|
||
var sw = Stopwatch.StartNew();
|
||
|
||
// 调用异步API
|
||
string result = await MESApiHelper.SendRequestStringAsync(url, HttpMethod.Post, postcontent, false);
|
||
|
||
// 记录请求结束时间
|
||
sw.Stop();
|
||
|
||
// 如果请求耗时超过1秒,记录日志
|
||
long outTime = sw.ElapsedMilliseconds;
|
||
if (outTime > 1000)
|
||
{
|
||
LogHelper.Instance.WriteLog($"预焊出站PC<=>MES上传耗时:{outTime}ms,电芯码:{listBar[0].BarCode},{listBar[1].BarCode}", "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, mesMessage, mesResType);
|
||
}
|
||
|
||
// 解析返回结果
|
||
var res1 = JsonConvert.DeserializeObject<MesResponseOut>(result);
|
||
|
||
// 如果操作成功
|
||
if (res1 != null && res1.success)
|
||
{
|
||
res = true;
|
||
GetOutMesResType(res1, listBar, ref mesMessage, ref mesResType); // 处理返回结果
|
||
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
|
||
{
|
||
// 如果操作失败,记录日志
|
||
var resData = res1 == null ? "" : 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);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
// 捕获异常并记录日志
|
||
resJson = $"产品出站信息(组装)接口发生异常:{ex.Message}";
|
||
LogHelper.Instance.WriteEX("产品出站信息(组装)接口", ex);
|
||
}
|
||
|
||
// 返回结果
|
||
return (res, mesMessage, mesResType);
|
||
}
|
||
#endregion
|
||
|
||
|
||
#region 10、 过程数据上传
|
||
/// <summary>
|
||
/// 过程数据上传
|
||
/// </summary>
|
||
/// <param name="url"></param>
|
||
/// <param name="siteCode"></param>
|
||
/// <param name="userName"></param>
|
||
/// <param name="equipNum"></param>
|
||
/// <param name="lineCode"></param>
|
||
/// <param name="materialCode"></param>
|
||
/// <param name="unloadType"></param>
|
||
/// <param name="productProcessParam"></param>
|
||
/// <param name="resJson"></param>
|
||
/// <returns></returns>
|
||
/// <exception cref="NotImplementedException"></exception>
|
||
public bool ProductProcessParam(string url, string siteCode, string userName, string equipNum, string lineCode, string materialCode, MesUploadType unloadType, List<ProductProcessParam> productProcessParam, ref string resJson)
|
||
{
|
||
throw new NotImplementedException();
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region 11、结果参数上传(产品结果数据)√
|
||
/// <summary>
|
||
/// 结果参数上传
|
||
/// </summary>
|
||
/// <param name="url"></param>
|
||
/// <param name="siteCode"></param>
|
||
/// <param name="lineCode"></param>
|
||
/// <param name="equipNum"></param>
|
||
/// <param name="materialCode"></param>
|
||
/// <param name="userName"></param>
|
||
/// <param name="m"></param>
|
||
/// <param name="unloadType"></param>
|
||
/// <param name="Mesage"></param>
|
||
/// <returns></returns>
|
||
public async Task<(bool Success, string ResJson)> ProducResultParamAsync(string url, string siteCode, string lineCode, string equipNum, string materialCode, string userName, BGearEntity m, MesUploadType unloadType, string insertTime)
|
||
{
|
||
bool res = false;
|
||
string resJson = "";
|
||
|
||
try
|
||
{
|
||
var nowDate = DateTime.Now;
|
||
string sNowDate = nowDate.ToString("yyyy-MM-dd HH:mm:ss.fff");
|
||
|
||
var model = new ProductResultParameters
|
||
{
|
||
equipNum = equipNum,
|
||
type = unloadType.ToString(),
|
||
payload = ""
|
||
};
|
||
|
||
var sw = Stopwatch.StartNew();
|
||
switch (unloadType)
|
||
{
|
||
case MesUploadType.DD:
|
||
var payload1 = new Payload1
|
||
{
|
||
siteCode = siteCode,
|
||
lineCode = lineCode,
|
||
userName = userName,
|
||
materialCode = materialCode,
|
||
carCode = "",
|
||
collection = "JS",
|
||
recordDate = sNowDate,
|
||
qty = 1,
|
||
containerCode = "",
|
||
};
|
||
payload1.identification = new IdentificationListItem
|
||
{
|
||
identification = m.BarCode,
|
||
qualityStatus = "Y"
|
||
};
|
||
|
||
payload1.tagDataVOList = GetTagDataVOList(m, insertTime);
|
||
model.payload = JsonConvert.SerializeObject(payload1);
|
||
break;
|
||
}
|
||
|
||
sw.Stop();
|
||
LogHelper.Instance.WriteLog($"GetTagDataVOList 耗时{sw.ElapsedMilliseconds}ms");
|
||
|
||
var postcontent = JsonConvert.SerializeObject(model);
|
||
postcontent = postcontent.TrimEnd(',');
|
||
//var sw = Stopwatch.StartNew();
|
||
sw.Restart();
|
||
// 异步调用
|
||
string result = await MESApiHelper.SendRequestStringAsync(url, HttpMethod.Post, postcontent, false);
|
||
|
||
sw.Stop();
|
||
|
||
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, resJson);
|
||
}
|
||
|
||
var res1 = ReturnMesMsg<MesResponse>(result);
|
||
if (!res1.success)
|
||
{
|
||
var resData = res1 == null ? "" : JsonConvert.SerializeObject(res1);
|
||
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);
|
||
}
|
||
else
|
||
{
|
||
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,返回结果:{JsonConvert.SerializeObject(result)}";
|
||
TxtHelper.WriteTxt($@"D:\APILog\Logs\MesLogs\{nowDate.ToString("yyyyMMdd")}\产品结果加工参数\{nowDate.ToString("HH")}.txt", resJson);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
resJson = $"产品结果加工参数接口发生异常:{ex.Message}";
|
||
LogHelper.Instance.WriteEX("产品结果加工参数接口", ex);
|
||
}
|
||
|
||
return (res, resJson);
|
||
}
|
||
|
||
|
||
private List<TagDataVOListItem> GetTagDataVOList(BGearEntity m, string insertTime)
|
||
{
|
||
|
||
List<TagDataVOListItem> datavolist = new List<TagDataVOListItem>();
|
||
|
||
string strFileName = System.Environment.CurrentDirectory + "\\采集项目表.csv";
|
||
|
||
FileStream fileStream = new FileStream(strFileName, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||
StreamReader streamReader = new StreamReader(fileStream,Encoding.Default);
|
||
_ = streamReader.ReadLine();
|
||
while (!streamReader.EndOfStream)
|
||
{
|
||
string line = streamReader.ReadLine();
|
||
string[] keys = line.Split(new string[] { ","},StringSplitOptions.RemoveEmptyEntries);
|
||
if (keys.Length == 3)
|
||
{
|
||
var temp = m.GetType().GetProperty(keys[1]).GetValue(m, null);
|
||
|
||
datavolist.Add(new TagDataVOListItem()
|
||
{
|
||
tagCode = keys[0],
|
||
tagValue = temp == null ? "0" : temp.ToString(),//m
|
||
tagTime = DateTime.Now.ToString(),
|
||
tagCalculateResult = "Y",
|
||
tagRemark = keys[2]
|
||
});
|
||
}
|
||
}
|
||
#region 本地字段没有,手动赋值
|
||
string tagValueFV051 = m.CCDBottomFillet25DInspectionResult;
|
||
string tagValueFV052 = Judge(m.CCDNegativeTerminalWeldingZone2DInspectionNGReasons, "UI21301");
|
||
string tagValueFV053 = Judge(m.CCDTerminalPost2DInspectionNGReasons, "UI21301");
|
||
string tagValueFV054 = Judge(m.CCDPositiveTerminaJYQ2DInspectionNGReasons, "UI15301");
|
||
string tagValueFV055 = Judge(m.CCDNegativeTerminaJYQ2DInspectionNGReasons,"UI15302");
|
||
string tagValueFV056 = Judge(m.CCDCoverPlate2DInspectionNGReasons, "UI298");
|
||
string tagValueFV058 = "NG";
|
||
|
||
if (tagValueFV051 == "OK" && tagValueFV052 == "OK" && tagValueFV053 == "OK" && tagValueFV054 == "OK" &&
|
||
tagValueFV055 == "OK" && tagValueFV056 == "OK")
|
||
{
|
||
tagValueFV058 = "OK";
|
||
}
|
||
// 进站时间
|
||
if (string.IsNullOrEmpty(insertTime))
|
||
{
|
||
datavolist.Add(new TagDataVOListItem()
|
||
{
|
||
tagCode = "FV_F020_RES_006",
|
||
tagValue = DateTime.Now.ToString(),//m
|
||
tagTime = DateTime.Now.ToString(),
|
||
tagCalculateResult = "Y",
|
||
tagRemark = "采集时间"
|
||
});
|
||
}
|
||
else
|
||
{
|
||
datavolist.Add(new TagDataVOListItem()
|
||
{
|
||
tagCode = "FV_F020_RES_006",
|
||
tagValue = insertTime,//m
|
||
tagTime = DateTime.Now.ToString(),
|
||
tagCalculateResult = "Y",
|
||
tagRemark = "采集时间"
|
||
});
|
||
}
|
||
//// 设备名称
|
||
//datavolist.Add(new TagDataVOListItem()
|
||
//{
|
||
// tagCode = "FV_F060_RES_004",
|
||
// tagValue = "",//m
|
||
// tagTime = DateTime.Now.ToString(),
|
||
// tagCalculateResult = "Y",
|
||
// tagRemark = "设备名称"
|
||
//});
|
||
//// 操作员
|
||
//datavolist.Add(new TagDataVOListItem()
|
||
//{
|
||
// tagCode = "FV_F060_RES_005",
|
||
// tagValue = "",//m
|
||
// tagTime = DateTime.Now.ToString(),
|
||
// tagCalculateResult = "Y",
|
||
// tagRemark = "操作员"
|
||
//});
|
||
////备注手动赋值,避免长度超过100,上传报错
|
||
var temp1 = m.GetType().GetProperty("Remark").GetValue(m, null);
|
||
string strTemp = string.Empty;
|
||
if (temp1 != null)
|
||
{
|
||
strTemp = temp1.ToString();
|
||
strTemp = (strTemp.Length > 100) ? strTemp.Substring(0, 99) : strTemp;
|
||
}
|
||
datavolist.Add(new TagDataVOListItem()
|
||
{
|
||
//FV_F060_RES_034,Remark,备注
|
||
tagCode = "FV_F020_RES_033",
|
||
tagValue = "",//m
|
||
tagTime = DateTime.Now.ToString(),
|
||
tagCalculateResult = "Y",
|
||
tagRemark = "备注"
|
||
});
|
||
if (m.Futou > 0)
|
||
{
|
||
datavolist.Add(new TagDataVOListItem()
|
||
{
|
||
//FV_F060_RES_034,Remark,备注
|
||
tagCode = "FV_F020_RES_007",
|
||
tagValue = m.Result,
|
||
tagTime = DateTime.Now.ToString(),
|
||
tagCalculateResult = "Y",
|
||
tagRemark = "复测结果"
|
||
});
|
||
datavolist.Add(new TagDataVOListItem()
|
||
{
|
||
//FV_F060_RES_034,Remark,备注
|
||
tagCode = "FV_F020_RES_008",
|
||
tagValue = "",
|
||
tagTime = DateTime.Now.ToString(),
|
||
tagCalculateResult = "Y",
|
||
tagRemark = "复测NG原因"
|
||
});
|
||
|
||
}
|
||
datavolist.Add(new TagDataVOListItem()
|
||
{
|
||
//FV_F060_RES_034,Remark,备注
|
||
tagCode = "FV_F020_RES_003",
|
||
tagValue = "",
|
||
tagTime = DateTime.Now.ToString(),
|
||
tagCalculateResult = "Y",
|
||
tagRemark = "离子风清洁设备号"
|
||
});
|
||
datavolist.Add(new TagDataVOListItem()
|
||
{
|
||
//FV_F060_RES_034,Remark,备注
|
||
tagCode = "FV_F020_RES_002",
|
||
tagValue = "",
|
||
tagTime = DateTime.Now.ToString(),
|
||
tagCalculateResult = "Y",
|
||
tagRemark = "结果类型"
|
||
});
|
||
datavolist.Add(new TagDataVOListItem()
|
||
{
|
||
tagCode = "FV_F020_RES_052",
|
||
tagValue = tagValueFV052,
|
||
tagTime = DateTime.Now.ToString(),
|
||
tagCalculateResult = "Y",
|
||
tagRemark = "负极焊接区划伤"
|
||
});
|
||
datavolist.Add(new TagDataVOListItem()
|
||
{
|
||
tagCode = "FV_F020_RES_053",
|
||
tagValue = tagValueFV053,
|
||
tagTime = DateTime.Now.ToString(),
|
||
tagCalculateResult = "Y",
|
||
tagRemark = "极柱划伤"
|
||
});
|
||
datavolist.Add(new TagDataVOListItem()
|
||
{
|
||
tagCode = "FV_F020_RES_054",
|
||
tagValue = tagValueFV054,
|
||
tagTime = DateTime.Now.ToString(),
|
||
tagCalculateResult = "Y",
|
||
tagRemark = "正极端子绝缘圈残缺"
|
||
});
|
||
datavolist.Add(new TagDataVOListItem()
|
||
{
|
||
tagCode = "FV_F020_RES_055",
|
||
tagValue = tagValueFV055,
|
||
tagTime = DateTime.Now.ToString(),
|
||
tagCalculateResult = "Y",
|
||
tagRemark = "负极绝缘圈变形"
|
||
});
|
||
datavolist.Add(new TagDataVOListItem()
|
||
{
|
||
tagCode = "FV_F020_RES_056",
|
||
tagValue = tagValueFV056,
|
||
tagTime = DateTime.Now.ToString(),
|
||
tagCalculateResult = "Y",
|
||
tagRemark = "盖板生锈"
|
||
});
|
||
datavolist.Add(new TagDataVOListItem()
|
||
{
|
||
tagCode = "FV_F020_RES_057",
|
||
tagValue = Judge(m.CCDCylindricalSurface25DInspectionResult, "UI127"),
|
||
tagTime = DateTime.Now.ToString(),
|
||
tagCalculateResult = "Y",
|
||
tagRemark = "壳体凹坑"
|
||
});
|
||
datavolist.Add(new TagDataVOListItem()
|
||
{
|
||
tagCode = "FV_F020_RES_058",
|
||
tagValue = tagValueFV058,
|
||
tagTime = DateTime.Now.ToString(),
|
||
tagCalculateResult = "Y",
|
||
tagRemark = "6项汇总结果"
|
||
});
|
||
#endregion
|
||
|
||
return datavolist;
|
||
}
|
||
|
||
|
||
private string Judge(string reason, string code) => reason?.Contains(code) == true ? "OK" : "NG";
|
||
|
||
/// <summary>
|
||
/// 多个电池上传
|
||
/// </summary>
|
||
/// <param name="url"></param>
|
||
/// <param name="siteCode"></param>
|
||
/// <param name="lineCode"></param>
|
||
/// <param name="equipNum"></param>
|
||
/// <param name="materialCode"></param>
|
||
/// <param name="userName"></param>
|
||
/// <param name="m"></param>
|
||
/// <param name="unloadType"></param>
|
||
/// <returns></returns>
|
||
public async Task<(bool Success, string ResJson)> ProducResultParamAsync(string url, string siteCode, string lineCode, string equipNum, string materialCode, string userName, List<BGearEntity> m, MesUploadType unloadType)
|
||
{
|
||
bool res = false;
|
||
string resJson = "";
|
||
|
||
try
|
||
{
|
||
var nowDate = DateTime.Now;
|
||
string sNowDate = nowDate.ToString("yyyy-MM-dd HH:mm:ss.fff");
|
||
|
||
var model = new ProductResultParameters
|
||
{
|
||
equipNum = equipNum,
|
||
type = unloadType.ToString(),
|
||
payload = ""
|
||
};
|
||
|
||
switch (unloadType)
|
||
{
|
||
case MesUploadType.DD:
|
||
var payload1 = new Payload1
|
||
{
|
||
siteCode = siteCode,
|
||
lineCode = lineCode,
|
||
userName = userName,
|
||
materialCode = materialCode,
|
||
carCode = "",
|
||
collection = "JS",
|
||
recordDate = sNowDate,
|
||
qty = m.Count, // 数量改为传入的 BGearEntity 列表的数量
|
||
containerCode = "",
|
||
};
|
||
|
||
payload1.identification = new IdentificationListItem
|
||
{
|
||
identification = m[0].BarCode, // 使用第一个 BGearEntity 的条码
|
||
qualityStatus = "Y"
|
||
};
|
||
|
||
// 初始化 tagDataVOList
|
||
payload1.tagDataVOList = new List<TagDataVOListItem>();
|
||
|
||
// 遍历多个 BGearEntity,添加到 tagDataVOList
|
||
foreach (var entity in m)
|
||
{
|
||
var tagData = new TagDataVOListItem
|
||
{
|
||
// 根据 BGearEntity 的属性初始化 TagDataVOListItem
|
||
tagCode = "CSBYH_CODE_A",
|
||
tagValue = entity.BarCode[0].ToString(),
|
||
tagTime = entity.TestTime,
|
||
tagCalculateResult = "Y",
|
||
tagRemark = "A芯包条码"
|
||
};
|
||
payload1.tagDataVOList.Add(tagData);
|
||
|
||
// 可以根据需要添加更多 TagDataVOListItem
|
||
}
|
||
|
||
model.payload = JsonConvert.SerializeObject(payload1);
|
||
break;
|
||
}
|
||
|
||
var postcontent = JsonConvert.SerializeObject(model);
|
||
var sw = Stopwatch.StartNew();
|
||
|
||
// 异步调用
|
||
string result = await MESApiHelper.SendRequestStringAsync(url, HttpMethod.Post, postcontent, false);
|
||
|
||
sw.Stop();
|
||
|
||
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, resJson);
|
||
}
|
||
|
||
var res1 = ReturnMesMsg<MesResponse>(result);
|
||
if (!res1.success)
|
||
{
|
||
var resData = res1 == null ? "" : JsonConvert.SerializeObject(res1);
|
||
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);
|
||
}
|
||
else
|
||
{
|
||
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,返回结果:{JsonConvert.SerializeObject(result)}";
|
||
TxtHelper.WriteTxt($@"D:\APILog\Logs\MesLogs\{nowDate.ToString("yyyyMMdd")}\产品结果加工参数\{nowDate.ToString("HH")}.txt", resJson);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
resJson = $"产品结果加工参数接口发生异常:{ex.Message}";
|
||
LogHelper.Instance.WriteEX("产品结果加工参数接口", ex);
|
||
}
|
||
|
||
return (res, resJson);
|
||
}
|
||
|
||
|
||
#endregion
|
||
|
||
#region 12、设备状态
|
||
/// <summary>
|
||
/// 设备状态
|
||
/// </summary>
|
||
/// <param name="url">API URL</param>
|
||
/// <param name="siteCode">站点代码</param>
|
||
/// <param name="lineCode">生产线代码</param>
|
||
/// <param name="equipNum">设备编号</param>
|
||
/// <param name="materialCode">物料代码</param>
|
||
/// <param name="userName">用户名</param>
|
||
/// <param name="guid">唯一标识</param>
|
||
/// <param name="statusCode">状态代码</param>
|
||
/// <param name="faultCodes">故障代码列表</param>
|
||
/// <returns>返回操作结果和消息</returns>
|
||
public async Task<(bool Success, string ResJson)> UploadEquStatusAsync(string url, string siteCode, string lineCode, string equipNum, string materialCode, string userName, string guid, string statusCode, List<FaultCodeList> faultCodes)
|
||
{
|
||
bool res = false;
|
||
string resJson = "";
|
||
|
||
try
|
||
{
|
||
DateTime nowDate = DateTime.Now;
|
||
string sNowDate = nowDate.ToString("yyyy-MM-dd HH:mm:ss");
|
||
|
||
var parameters = new EqpStatusParam
|
||
{
|
||
siteCode = siteCode,
|
||
lineCode = lineCode,
|
||
equipNum = equipNum,
|
||
materialCode = materialCode,
|
||
userName = userName,
|
||
seatId = "",
|
||
recordDate = sNowDate,
|
||
statusCode = statusCode.ToString(),
|
||
uploadTime = sNowDate,
|
||
guid = guid
|
||
};
|
||
|
||
// 设置故障代码列表
|
||
parameters.faultCodeList = faultCodes;
|
||
|
||
var postcontent = JsonConvert.SerializeObject(parameters);
|
||
var sw = Stopwatch.StartNew();
|
||
|
||
// 异步调用
|
||
string result = await MESApiHelper.SendRequestStringAsync(url, HttpMethod.Post, postcontent, false);
|
||
|
||
sw.Stop();
|
||
|
||
if (string.IsNullOrEmpty(result))
|
||
{
|
||
string resData = result == "" ? "" : result;
|
||
resJson = $"{sNowDate}:调用设备运行状态接口:{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, resJson);
|
||
}
|
||
|
||
var res1 = ReturnMesMsg<MesResponse>(result);
|
||
if (!res1.success)
|
||
{
|
||
var resData = res1 == null ? "" : JsonConvert.SerializeObject(res1);
|
||
resJson = $"{sNowDate}:调用设备运行状态接口:{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);
|
||
}
|
||
else
|
||
{
|
||
res = true;
|
||
resJson = $"{sNowDate}:调用设备运行状态接口:{url},请求数据为:{postcontent},\n{nowDate.AddMilliseconds(sw.ElapsedMilliseconds).ToString("yyyy-MM-dd HH:mm:ss.fff")}:接口耗时:{sw.ElapsedMilliseconds}ms,返回结果:{JsonConvert.SerializeObject(result)}";
|
||
TxtHelper.WriteTxt($@"D:\APILog\Logs\MesLogs\{nowDate.ToString("yyyyMMdd")}\设备运行状态\{nowDate.ToString("HH")}.txt", resJson);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
resJson = $"设备运行状态接口发生异常:{ex.Message}";
|
||
LogHelper.Instance.WriteEX("设备运行状态接口", ex);
|
||
}
|
||
|
||
return (res, resJson);
|
||
}
|
||
#endregion
|
||
|
||
#region 13、设备报警上传接口
|
||
/// <summary>
|
||
/// 设备报警上传接口
|
||
/// </summary>
|
||
/// <param name="url">API URL</param>
|
||
/// <param name="siteCode">站点代码</param>
|
||
/// <param name="lineCode">生产线代码</param>
|
||
/// <param name="equipNum">设备编号</param>
|
||
/// <param name="materialCode">物料代码</param>
|
||
/// <param name="userName">用户名</param>
|
||
/// <param name="alarmObj">报警数据列表</param>
|
||
/// <param name="guid">唯一标识</param>
|
||
/// <returns>返回操作结果和消息</returns>
|
||
public async Task<(bool Success, string Mesage)> UploadEquAlarmAsync(string url, string siteCode, string lineCode, string equipNum, string materialCode, string userName, List<AlarmData> alarmObj, string guid)
|
||
{
|
||
bool res = false;
|
||
string resJson = "";
|
||
string mesage = ""; // 用于存储消息
|
||
|
||
try
|
||
{
|
||
var nowDate = DateTime.Now;
|
||
|
||
if (alarmObj.Count > 0)
|
||
{
|
||
Console.WriteLine($"{nowDate}: 开始处理报警数据,数量:{alarmObj.Count}");
|
||
|
||
var model = new UploadAlarmParam
|
||
{
|
||
siteCode = siteCode,
|
||
lineCode = lineCode,
|
||
equipNum = equipNum,
|
||
materialCode = materialCode,
|
||
userName = userName,
|
||
recordDate = nowDate.ToString("yyyy-MM-dd HH:mm:ss"),
|
||
guid = guid,
|
||
seatId = ""
|
||
};
|
||
|
||
model.alarmLineList = new List<AlarmLineListItem>();
|
||
for (int j = 0; j < alarmObj.Count; j++)
|
||
{
|
||
AlarmLineListItem alarmList = new AlarmLineListItem
|
||
{
|
||
alarmEndTime = System.Convert.ToString(alarmObj[j].EndTime),
|
||
alarmType = alarmObj[j].AlarmType,
|
||
alarmName = alarmObj[j].AlarmContent,
|
||
alarmStartTime = System.Convert.ToString(alarmObj[j].StartTime),
|
||
faultCode = alarmObj[j].AlarmCode
|
||
};
|
||
model.alarmLineList.Add(alarmList);
|
||
|
||
Console.WriteLine($"{nowDate}: 添加报警数据 - 报警类型:{alarmObj[j].AlarmType}, 报警内容:{alarmObj[j].AlarmContent}");
|
||
}
|
||
|
||
var postcontent = JsonConvert.SerializeObject(model);
|
||
Console.WriteLine($"{nowDate}: 请求数据已序列化:{postcontent}");
|
||
|
||
var sw = Stopwatch.StartNew();
|
||
Console.WriteLine($"{nowDate}: 开始调用设备报警信息接口");
|
||
|
||
// 异步调用
|
||
string result = await MESApiHelper.SendRequestStringAsync(url, HttpMethod.Post, postcontent, false);
|
||
|
||
sw.Stop();
|
||
Console.WriteLine($"{nowDate}: 接口调用完成,耗时:{sw.ElapsedMilliseconds}ms");
|
||
|
||
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);
|
||
Console.WriteLine($"{nowDate}: 接口返回结果为空");
|
||
return (res, mesage);
|
||
}
|
||
|
||
var res1 = ReturnMesMsg<MesResponse>(result);
|
||
if (!res1.success)
|
||
{
|
||
var resData = res1 == null ? "" : JsonConvert.SerializeObject(res1);
|
||
mesage = res1.message;
|
||
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);
|
||
Console.WriteLine($"{nowDate}: 接口调用失败,消息:{mesage}");
|
||
}
|
||
else
|
||
{
|
||
res = true;
|
||
mesage = res1.message;
|
||
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,返回结果:{JsonConvert.SerializeObject(result)}";
|
||
TxtHelper.WriteTxt($@"D:\APILog\Logs\MesLogs\{nowDate.ToString("yyyyMMdd")}\报警信息\{nowDate.ToString("HH")}.txt", resJson);
|
||
Console.WriteLine($"{nowDate}: 接口调用成功,消息:{mesage}");
|
||
}
|
||
}
|
||
else
|
||
{
|
||
Console.WriteLine($"{nowDate}: 报警数据为空,无需处理");
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
resJson = $"调用设备报警信息接口发生异常:{ex.Message}";
|
||
LogHelper.Instance.WriteEX("调用设备报警信息接口", ex);
|
||
Console.WriteLine($"{DateTime.Now}: 发生异常:{ex.Message}");
|
||
}
|
||
|
||
return (res, mesage);
|
||
}
|
||
#endregion
|
||
|
||
#region 14、上传设备能耗数据
|
||
/// <summary>
|
||
/// 上传设备能耗数据
|
||
/// </summary>
|
||
/// <param name="url">API URL</param>
|
||
/// <param name="siteCode">站点代码</param>
|
||
/// <param name="lineCode">生产线代码</param>
|
||
/// <param name="equipNum">设备编号</param>
|
||
/// <param name="userName">用户名</param>
|
||
/// <param name="electricMeterNum">电表编号列表</param>
|
||
/// <param name="wattrs">能耗数据列表</param>
|
||
/// <returns>返回操作结果和日志信息</returns>
|
||
public async Task<(bool Success, string Mesage)> UploadEquEnergyAsync(string url, string siteCode, string lineCode, string equipNum, string userName, List<string> electricMeterNum, List<WattrMeter> wattrs)
|
||
{
|
||
bool res = false;
|
||
string mesage = "";
|
||
|
||
try
|
||
{
|
||
var nowDate = DateTime.Now;
|
||
Console.WriteLine($"{nowDate}: 开始处理设备能耗数据");
|
||
|
||
// 序列化请求数据
|
||
var postcontent = JsonConvert.SerializeObject(wattrs);
|
||
Console.WriteLine($"{nowDate}: 请求数据已序列化:{postcontent}");
|
||
|
||
var sw = Stopwatch.StartNew();
|
||
Console.WriteLine($"{nowDate}: 开始调用设备能耗信息接口");
|
||
|
||
// 异步调用
|
||
string result = await MESApiHelper.SendRequestStringAsync(url, HttpMethod.Post, postcontent, false);
|
||
|
||
sw.Stop();
|
||
Console.WriteLine($"{nowDate}: 接口调用完成,耗时:{sw.ElapsedMilliseconds}ms");
|
||
|
||
if (string.IsNullOrEmpty(result))
|
||
{
|
||
string resData = result == "" ? "" : result;
|
||
mesage = $"{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", mesage);
|
||
Console.WriteLine($"{nowDate}: 接口返回结果为空");
|
||
return (res, mesage);
|
||
}
|
||
|
||
var res1 = ReturnMesMsg<MesResponse>(result);
|
||
if (!res1.success)
|
||
{
|
||
var resData = res1 == null ? "" : JsonConvert.SerializeObject(res1);
|
||
mesage = $"{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", mesage);
|
||
Console.WriteLine($"{nowDate}: 接口调用失败,返回结果:{resData}");
|
||
}
|
||
else
|
||
{
|
||
res = true;
|
||
mesage = $"{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,返回结果:{JsonConvert.SerializeObject(result)}";
|
||
TxtHelper.WriteTxt($@"D:\APILog\Logs\MesLogs\{nowDate.ToString("yyyyMMdd")}\设备能耗信息\{nowDate.ToString("HH")}.txt", mesage);
|
||
Console.WriteLine($"{nowDate}: 接口调用成功,返回结果:{result}");
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
mesage = $"调用设备能耗信息接口发生异常:{ex.Message}";
|
||
LogHelper.Instance.WriteEX("调用设备能耗信息接口", ex);
|
||
Console.WriteLine($"{DateTime.Now}: 发生异常:{ex.Message}");
|
||
}
|
||
|
||
return (res, mesage);
|
||
}
|
||
#endregion
|
||
|
||
#region 15、风速仪数据上传至MES
|
||
/// <summary>
|
||
/// 风速仪数据上传至MES
|
||
/// </summary>
|
||
/// <param name="url">API URL</param>
|
||
/// <param name="equipNum">设备编号</param>
|
||
/// <param name="antiDustAirSpeedNum">风速仪编号列表</param>
|
||
/// <param name="collectData">采集数据列表</param>
|
||
/// <returns>返回操作结果和消息</returns>
|
||
public async Task<(bool Success, string Mesage)> UploadDeviceCollectDataAsync(string url, string equipNum, List<string> antiDustAirSpeedNum, List<float> collectData)
|
||
{
|
||
bool res = false;
|
||
string resJson = "";
|
||
string mesage = ""; // 用于存储消息
|
||
|
||
try
|
||
{
|
||
if (collectData == null || collectData.Count == 0)
|
||
{
|
||
mesage = "采集数据为空,无需处理";
|
||
Console.WriteLine($"{DateTime.Now}: {mesage}");
|
||
return (res, mesage);
|
||
}
|
||
|
||
var nowDate = DateTime.Now;
|
||
Console.WriteLine($"{nowDate}: 开始处理风速仪数据");
|
||
|
||
// 创建请求模型
|
||
UploadDeviceCollectData uploadDevice = new UploadDeviceCollectData
|
||
{
|
||
appid = "e1012966a936170c6fcab98e24042d10",
|
||
device_code = equipNum,
|
||
collect_time = GetUnixTimestamp()
|
||
};
|
||
|
||
// 填充采集数据
|
||
List<Collect_code_value_list> list = new List<Collect_code_value_list>();
|
||
for (int i = 0; i < collectData.Count; i++)
|
||
{
|
||
Collect_code_value_list _Value_List = new Collect_code_value_list
|
||
{
|
||
target_code = 5,
|
||
target_value = collectData[i].ToString(),
|
||
target_value_tag = antiDustAirSpeedNum[i]
|
||
};
|
||
list.Add(_Value_List);
|
||
|
||
Console.WriteLine($"{nowDate}: 添加采集数据 - 风速仪编号:{antiDustAirSpeedNum[i]}, 采集值:{collectData[i]}");
|
||
}
|
||
uploadDevice.collect_code_value_list = list;
|
||
|
||
// 序列化请求数据
|
||
string postcontent = JsonConvert.SerializeObject(uploadDevice);
|
||
Console.WriteLine($"{nowDate}: 请求数据已序列化:{postcontent}");
|
||
|
||
var sw = Stopwatch.StartNew();
|
||
Console.WriteLine($"{nowDate}: 开始调用风速接口");
|
||
|
||
// 异步调用
|
||
string result = await MESApiHelper.SendRequestStringAsync(url, HttpMethod.Post, postcontent, false);
|
||
|
||
sw.Stop();
|
||
Console.WriteLine($"{nowDate}: 接口调用完成,耗时:{sw.ElapsedMilliseconds}ms");
|
||
|
||
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);
|
||
mesage = "接口返回结果为空";
|
||
Console.WriteLine($"{nowDate}: {mesage}");
|
||
return (res, mesage);
|
||
}
|
||
|
||
var res1 = ReturnMesMsg<MesResponse>(result);
|
||
if (!res1.success)
|
||
{
|
||
var resData = res1 == null ? "" : JsonConvert.SerializeObject(res1);
|
||
mesage = res1.message;
|
||
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);
|
||
Console.WriteLine($"{nowDate}: 接口调用失败,消息:{mesage}");
|
||
}
|
||
else
|
||
{
|
||
res = true;
|
||
mesage = res1.message;
|
||
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,返回结果:{JsonConvert.SerializeObject(result)}";
|
||
TxtHelper.WriteTxt($@"D:\APILog\Logs\MesLogs\{nowDate.ToString("yyyyMMdd")}\风速信息\{nowDate.ToString("HH")}.txt", resJson);
|
||
Console.WriteLine($"{nowDate}: 接口调用成功,消息:{mesage}");
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
resJson = $"调用风速接口发生异常:{ex.Message}";
|
||
LogHelper.Instance.WriteEX("调用风速接口", ex);
|
||
Console.WriteLine($"{DateTime.Now}: 发生异常:{ex.Message}");
|
||
}
|
||
|
||
return (res, mesage);
|
||
}
|
||
#endregion
|
||
|
||
#region 16、数据处理逻辑
|
||
/// <summary>
|
||
/// 单电池进站分类
|
||
/// </summary>
|
||
/// <param name="res1"></param>
|
||
/// <param name="BarCode"></param>
|
||
/// <param name="MesMessage"></param>
|
||
/// <param name="mesResType"></param>
|
||
private void GetInMesResType(MesResponseSingle res1, string BarCode, ref string MesMessage, ref MesResType mesResType)
|
||
{
|
||
if (res1 != null)
|
||
{
|
||
if (res1.success)
|
||
{
|
||
mesResType = MesResType.D;
|
||
MesMessage = "MES进站成功 ";
|
||
|
||
}
|
||
else
|
||
{
|
||
if (res1.category == null)
|
||
{
|
||
mesResType = MesResType.B;
|
||
MesMessage = res1.message;
|
||
}
|
||
else
|
||
{
|
||
switch (res1.category)
|
||
{
|
||
case "A":
|
||
mesResType = MesResType.A;
|
||
MesMessage = res1.message;
|
||
break;
|
||
case "B":
|
||
mesResType = MesResType.B;
|
||
MesMessage = res1.message;
|
||
break;
|
||
case "C":
|
||
mesResType = MesResType.C;
|
||
MesMessage = res1.message;
|
||
break;
|
||
default:
|
||
mesResType = MesResType.UnKnow;
|
||
MesMessage = "MES进站失败 ";
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 多电池进站分类
|
||
/// </summary>
|
||
/// <param name="res1"></param>
|
||
/// <param name="listBar"></param>
|
||
/// <param name="MesMessage"></param>
|
||
/// <param name="mesResType"></param>
|
||
private void GetInMesResType(MesResponseIn res1, List<string> listBar, ref List<string> MesMessage, ref List<MesResType> mesResType)
|
||
{
|
||
if (res1 != null)
|
||
{
|
||
for (int i = 0; i < res1.total; i++)
|
||
{
|
||
for (int j = 0; j < res1.total; j++)
|
||
{
|
||
if (res1.rows[j].identification == listBar[i])
|
||
{
|
||
if (res1.rows[j].success)
|
||
{
|
||
mesResType[i] = MesResType.D;
|
||
MesMessage[i] = "MES进站成功 ";
|
||
}
|
||
else
|
||
{
|
||
if (res1.rows[j].category == null)
|
||
{
|
||
mesResType[i] = MesResType.B;
|
||
MesMessage[i] = res1.rows[j].message;
|
||
}
|
||
else
|
||
{
|
||
switch (res1.rows[j].category)
|
||
{
|
||
case "A":
|
||
mesResType[i] = MesResType.A;
|
||
MesMessage[i] = res1.rows[j].message;
|
||
break;
|
||
case "B":
|
||
mesResType[i] = MesResType.B;
|
||
MesMessage[i] = res1.rows[j].message;
|
||
break;
|
||
case "C":
|
||
mesResType[i] = MesResType.C;
|
||
MesMessage[i] = res1.rows[j].message;
|
||
break;
|
||
default:
|
||
mesResType[i] = MesResType.UnKnow;
|
||
MesMessage[i] = "MES进站失败 ";
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 多电池进站分类
|
||
/// </summary>
|
||
/// <param name="res1"></param>
|
||
/// <param name="listBar"></param>
|
||
/// <param name="MesMessage"></param>
|
||
/// <param name="mesResType"></param>
|
||
private void GetInMesResType1(MesResponseIn res1, List<string> listBar, ref List<string> MesMessage, ref List<MesResType> mesResType, ref List<string> cellCode)
|
||
{
|
||
if (res1 != null)
|
||
{
|
||
for (int i = 0; i < res1.total; i++)
|
||
{
|
||
for (int j = 0; j < res1.total; j++)
|
||
{
|
||
if (res1.rows[j].identification == listBar[i])
|
||
{
|
||
cellCode[i] = res1.rows[j].identification;
|
||
if (res1.rows[j].success)
|
||
{
|
||
mesResType[i] = MesResType.D;
|
||
MesMessage[i] = "MES进站成功 ";
|
||
}
|
||
else
|
||
{
|
||
if (res1.rows[j].category == null)
|
||
{
|
||
mesResType[i] = MesResType.B;
|
||
MesMessage[i] = res1.rows[j].message;
|
||
}
|
||
else
|
||
{
|
||
switch (res1.rows[j].category)
|
||
{
|
||
case "A":
|
||
mesResType[i] = MesResType.A;
|
||
MesMessage[i] = res1.rows[j].message;
|
||
break;
|
||
case "B":
|
||
mesResType[i] = MesResType.B;
|
||
MesMessage[i] = res1.rows[j].message;
|
||
break;
|
||
case "C":
|
||
mesResType[i] = MesResType.C;
|
||
MesMessage[i] = res1.rows[j].message;
|
||
break;
|
||
default:
|
||
mesResType[i] = MesResType.UnKnow;
|
||
MesMessage[i] = "MES进站失败 ";
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 单电池出站分类
|
||
/// </summary>
|
||
/// <param name="res1"></param>
|
||
/// <param name="BarCode"></param>
|
||
/// <param name="MesMessage"></param>
|
||
/// <param name="mesResType"></param>
|
||
private void GetOutMesResType(MesResponseOut res1, string BarCode, ref string MesMessage, ref MesResType mesResType)
|
||
{
|
||
if (res1 != null && res1.rows != null)
|
||
{
|
||
if (res1.rows[0].success)
|
||
{
|
||
mesResType = MesResType.D;
|
||
MesMessage = "MES出站成功 ";
|
||
|
||
}
|
||
else
|
||
{
|
||
if (res1.rows[0].category == null)
|
||
{
|
||
mesResType = MesResType.B;
|
||
MesMessage = res1.rows[0].message;
|
||
}
|
||
else
|
||
{
|
||
switch (res1.rows[0].category)
|
||
{
|
||
case "A":
|
||
mesResType = MesResType.A;
|
||
MesMessage = res1.rows[0].message;
|
||
break;
|
||
case "B":
|
||
mesResType = MesResType.B;
|
||
MesMessage = res1.rows[0].message;
|
||
break;
|
||
case "C":
|
||
mesResType = MesResType.C;
|
||
MesMessage = res1.rows[0].message;
|
||
break;
|
||
default:
|
||
mesResType = MesResType.UnKnow;
|
||
MesMessage = "MES出站失败 ";
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 多电池出站分类
|
||
/// </summary>
|
||
/// <param name="res1"></param>
|
||
/// <param name="BarCode"></param>
|
||
/// <param name="MesMessage"></param>
|
||
/// <param name="mesResType"></param>
|
||
private void GetManyOutMesResType(MesResponseOut res1, List<BGearEntity> m, ref List<string> MesMessage, ref List<MesResType> mesResType)
|
||
{
|
||
if (res1 != null)
|
||
{
|
||
for (int i = 0; i < res1.total; i++)
|
||
{
|
||
for (int j = 0; j < res1.total; j++)
|
||
{
|
||
if (res1.rows[j].identification == m[i].BarCode)
|
||
{
|
||
if (res1.rows[j].success)
|
||
{
|
||
mesResType[i] = MesResType.D;
|
||
MesMessage[i] = "MES出站成功 ";
|
||
}
|
||
else
|
||
{
|
||
if (res1.rows[j].category == null)
|
||
{
|
||
mesResType[i] = MesResType.B;
|
||
MesMessage[i] = res1.rows[j].message;
|
||
}
|
||
else
|
||
{
|
||
switch (res1.rows[j].category)
|
||
{
|
||
case "A":
|
||
mesResType[i] = MesResType.A;
|
||
MesMessage[i] = res1.rows[j].message;
|
||
break;
|
||
case "B":
|
||
mesResType[i] = MesResType.B;
|
||
MesMessage[i] = res1.rows[j].message;
|
||
break;
|
||
case "C":
|
||
mesResType[i] = MesResType.C;
|
||
MesMessage[i] = res1.rows[j].message;
|
||
break;
|
||
default:
|
||
mesResType[i] = MesResType.UnKnow;
|
||
MesMessage[i] = "MES出站失败 ";
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
private void GetOutMesResType(MesResponse res1, string BarCode, ref string MesMessage, ref MesResType mesResType)
|
||
{
|
||
if (res1 != null)
|
||
{
|
||
if (res1.success)
|
||
{
|
||
mesResType = MesResType.D;
|
||
MesMessage = "MES出站成功 ";
|
||
|
||
}
|
||
else
|
||
{
|
||
mesResType = MesResType.B;
|
||
MesMessage = res1.message;
|
||
}
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 多电池出站结果分类
|
||
/// </summary>
|
||
/// <param name="res1"></param>
|
||
/// <param name="list"></param>
|
||
/// <param name="MesMessage"></param>
|
||
/// <param name="mesResType"></param>
|
||
private void GetOutMesResType(MesResponseOut res1, List<BGearEntity> list, ref List<string> MesMessage, ref List<MesResType> mesResType)
|
||
{
|
||
if (res1 != null)
|
||
{
|
||
for (int i = 0; i < list.Count; i++)
|
||
{
|
||
for (int j = 0; j < res1.total; j++)
|
||
{
|
||
if (res1.rows[j].identification == list[i].BarCode)
|
||
{
|
||
if (res1.rows[j].success)
|
||
{
|
||
mesResType[i] = MesResType.D;
|
||
MesMessage[i] = "MES出站成功 ";
|
||
|
||
}
|
||
else
|
||
{
|
||
if (res1.rows[j].category == null)
|
||
{
|
||
mesResType[i] = MesResType.B;
|
||
MesMessage[i] = res1.rows[j].message;
|
||
}
|
||
else
|
||
{
|
||
switch (res1.rows[i].category)
|
||
{
|
||
case "A":
|
||
mesResType[i] = MesResType.A;
|
||
MesMessage[i] = res1.rows[j].message;
|
||
break;
|
||
case "B":
|
||
mesResType[i] = MesResType.B;
|
||
MesMessage[i] = res1.rows[j].message;
|
||
break;
|
||
case "C":
|
||
mesResType[i] = MesResType.C;
|
||
MesMessage[i] = res1.rows[j].message;
|
||
break;
|
||
default:
|
||
mesResType[i] = MesResType.UnKnow;
|
||
MesMessage[i] = "MES出站失败 ";
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
|
||
/// <summary>
|
||
/// 序列化各类返回
|
||
/// </summary>
|
||
/// <typeparam name="T"></typeparam>
|
||
/// <param name="ret"></param>
|
||
/// <returns></returns>
|
||
private T ReturnMesMsg<T>(string ret)
|
||
{
|
||
|
||
try
|
||
{
|
||
return JsonConvert.DeserializeObject<T>(ret);
|
||
}
|
||
catch (System.Exception ex)
|
||
{
|
||
return default(T);
|
||
}
|
||
}
|
||
|
||
public List<MesResType> GetMesType(int Num)
|
||
{
|
||
List<MesResType> mesResTypes = new List<MesResType>();
|
||
for (int i = 0; i < Num; i++)
|
||
{
|
||
mesResTypes.Add(MesResType.B);
|
||
}
|
||
return mesResTypes;
|
||
}
|
||
|
||
|
||
public List<string> GetListString(int Num, string str)
|
||
{
|
||
List<string> mesResTypes = new List<string>();
|
||
for (int i = 0; i < Num; i++)
|
||
{
|
||
mesResTypes.Add(str);
|
||
}
|
||
return mesResTypes;
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
///本地时间为Unix时间戳
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public static long GetUnixTimestamp()
|
||
{
|
||
return (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000;
|
||
}
|
||
|
||
public Task<(bool Success, string ResJson)> ParamChangeAsync(string url, string siteCode, string lineCode, string equipNum, string materialCode, string userName, List<TagListItem> paramChangeItems)
|
||
{
|
||
throw new NotImplementedException();
|
||
}
|
||
|
||
|
||
public Task<(bool Success, string ResJson)> ProductProcessParamAsync(string url, string siteCode, string userName, string equipNum, string lineCode, string materialCode, MesUploadType unloadType, List<ProductProcessParam> productProcessParam)
|
||
{
|
||
throw new NotImplementedException();
|
||
}
|
||
|
||
|
||
|
||
|
||
#endregion
|
||
}
|
||
}
|