480 lines
20 KiB
C#
480 lines
20 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using JSON = Newtonsoft.Json.JsonConvert;
|
|||
|
|
using Newtonsoft.Json;
|
|||
|
|
using Unity;
|
|||
|
|
using System.Collections.Concurrent;
|
|||
|
|
using Cowain.Bake.BLL;
|
|||
|
|
using Cowain.Bake.Common.Enums;
|
|||
|
|
using Cowain.Bake.Model;
|
|||
|
|
using static Cowain.Bake.Common.Models.MESModel;
|
|||
|
|
using Cowain.Bake.Model.Models;
|
|||
|
|
using Cowain.Bake.Common.Core;
|
|||
|
|
using System.Linq;
|
|||
|
|
|
|||
|
|
namespace Cowain.Bake.Communication.MOM
|
|||
|
|
{
|
|||
|
|
public class MESProcess
|
|||
|
|
{
|
|||
|
|
readonly ConcurrentDictionary<int, float> dicMaxTemp = null; //表示该变量的引用(指针)不可变
|
|||
|
|
string url = null;
|
|||
|
|
public string URL
|
|||
|
|
{
|
|||
|
|
get
|
|||
|
|
{
|
|||
|
|
if (url != null)
|
|||
|
|
{
|
|||
|
|
return url;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
TDeviceConfig dev = _unityContainer.Resolve<DeviceConfigService>().GetConfig(EDeviceType.MOM)[0];
|
|||
|
|
GetJsonParam(dev.Json);
|
|||
|
|
return url;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
readonly IUnityContainer _unityContainer;
|
|||
|
|
public MESProcess(IUnityContainer unityContainer)
|
|||
|
|
{
|
|||
|
|
_unityContainer = unityContainer;
|
|||
|
|
dicMaxTemp = new ConcurrentDictionary<int, float>();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void GetJsonParam(string param)
|
|||
|
|
{
|
|||
|
|
dynamic d = JsonConvert.DeserializeObject<dynamic>(param);
|
|||
|
|
this.url = d.URL;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 心跳
|
|||
|
|
/// </summary>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public MESReturnCmdModel Alive()
|
|||
|
|
{
|
|||
|
|
EqptAlive eqptAlive = new EqptAlive();
|
|||
|
|
DateTime currentTime = DateTime.Now;
|
|||
|
|
DateTime oneMinuteAgo = currentTime.AddMinutes(-1);
|
|||
|
|
eqptAlive.Info.EquipmentCode = _unityContainer.Resolve<SysSetupService>().GetValueByParaID(ESysSetup.DeviceNum.ToString()); ;
|
|||
|
|
eqptAlive.Info.PPM = _unityContainer.Resolve<BatteryInfoService>().GetPPM(oneMinuteAgo, currentTime).ToString();
|
|||
|
|
|
|||
|
|
var resultModel = SendData(JSON.SerializeObject(eqptAlive), (int)EMesLogClass.EqptAlive, true);
|
|||
|
|
//string result = HttpClientHelper.HttpPost(URL, JSON.SerializeObject(eqptAlive));
|
|||
|
|
//var resultModel = JSON.DeserializeObject<MESReturnCmdModel>(result);
|
|||
|
|
return resultModel;
|
|||
|
|
}
|
|||
|
|
//2.设备状态 报警要把报警信息传过去,(与PLC确认)
|
|||
|
|
public MESReturnCmdModel MESEqptStatus(UInt16 status, List<TAlarm> models)
|
|||
|
|
{
|
|||
|
|
string urlCmd = URL;
|
|||
|
|
EqptStatus eqptStatu = new EqptStatus();
|
|||
|
|
eqptStatu.Info.EquipmentCode = _unityContainer.Resolve<SysSetupService>().GetValueByParaID(ESysSetup.DeviceNum.ToString());// "EC001";
|
|||
|
|
eqptStatu.Info.StatusCode = status.ToString();
|
|||
|
|
if (null != models)
|
|||
|
|
{
|
|||
|
|
foreach(var item in models)
|
|||
|
|
{
|
|||
|
|
eqptStatu.Info.AlertInfo.Add(
|
|||
|
|
new AlerInfoModel()
|
|||
|
|
{
|
|||
|
|
AlertMessage = item.Desc,
|
|||
|
|
AlertCode = item.Id.ToString()
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return SendData(JSON.SerializeObject(eqptStatu), (int)EMesLogClass.Status);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 3.设备报警
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="arrayAlert"></param>
|
|||
|
|
public void MESEqptAlert(List<AlertInfoModel> arrayAlert)
|
|||
|
|
{
|
|||
|
|
if (0 == arrayAlert.Count) return;
|
|||
|
|
|
|||
|
|
EqptAlertModel eqptAlertModel = new EqptAlertModel();
|
|||
|
|
EqptAlert eqptAlert = new EqptAlert();
|
|||
|
|
eqptAlertModel.AlertInfo = arrayAlert;
|
|||
|
|
eqptAlert.Info = eqptAlertModel;
|
|||
|
|
eqptAlert.Info.EquipmentCode = _unityContainer.Resolve<SysSetupService>().GetValueByParaID(ESysSetup.DeviceNum.ToString());
|
|||
|
|
SendData(JSON.SerializeObject(eqptAlert), (int)EMesLogClass.Alarm, false);
|
|||
|
|
}
|
|||
|
|
//4.工艺参数请求:心跳为2时请求
|
|||
|
|
public EqptParameterReturnCmd GetProcessParam()
|
|||
|
|
{
|
|||
|
|
EqptParameter process = new EqptParameter();
|
|||
|
|
process.Info.EquipmentCode = _unityContainer.Resolve<SysSetupService>().GetValueByParaID(ESysSetup.DeviceNum.ToString());
|
|||
|
|
var result = SendData<EqptParameterReturnCmd>(JSON.SerializeObject(process), (int)EMesLogClass.ParameterRequest);
|
|||
|
|
if (result == default(EqptParameterReturnCmd))
|
|||
|
|
{
|
|||
|
|
LogHelper.Instance.Error($"获取工艺参数失败!请求内容:{JSON.SerializeObject(process)}");
|
|||
|
|
return null;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return result;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
///5 参数变更
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="userId"></param>
|
|||
|
|
/// <param name="paramInfo"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public MESReturnCmdModel ChangeParam(string userId, List<EqptParameterModel> paramInfo)
|
|||
|
|
{
|
|||
|
|
ParameterChangeCmd param = new ParameterChangeCmd();
|
|||
|
|
//param.Info = new ParameterChange();
|
|||
|
|
param.Info.EquipmentCode = _unityContainer.Resolve<SysSetupService>().GetValueByParaID(ESysSetup.DeviceNum.ToString());
|
|||
|
|
param.Info.EmployeeNo = userId;
|
|||
|
|
param.Info.ParameterInfo = paramInfo;
|
|||
|
|
return SendData(JSON.SerializeObject(param), (int)EMesLogClass.ParameterChange);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//6.联机请求
|
|||
|
|
public MESReturnCmdModel EqptRun(string user, string pwd, string equipmentModel)
|
|||
|
|
{
|
|||
|
|
EqptRunCmd eqptRunCmd = new EqptRunCmd();
|
|||
|
|
EqptRun eqptRun = new EqptRun();
|
|||
|
|
eqptRun.EmployeeNo = user;
|
|||
|
|
eqptRun.Password = pwd;
|
|||
|
|
eqptRun.EquipmentModel = equipmentModel;
|
|||
|
|
eqptRun.EquipmentCode = _unityContainer.Resolve<SysSetupService>().GetValueByParaID(ESysSetup.DeviceNum.ToString());
|
|||
|
|
eqptRunCmd.Info = eqptRun;
|
|||
|
|
return SendData(JSON.SerializeObject(eqptRunCmd), (int)EMesLogClass.EqptRun);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
///7 电芯状态获取(进站电芯)
|
|||
|
|
/// </summary>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public MESReturnCmdModel GetBatteryStatus(string batteryCode)
|
|||
|
|
{
|
|||
|
|
CellStateCmd cellStateCmd = new CellStateCmd();
|
|||
|
|
//cellStateCmd.Info = new CellState();
|
|||
|
|
cellStateCmd.Info.CellNo = batteryCode;
|
|||
|
|
cellStateCmd.Info.EquipmentCode = _unityContainer.Resolve<SysSetupService>().GetValueByParaID(ESysSetup.DeviceNum.ToString());
|
|||
|
|
return SendData(JSON.SerializeObject(cellStateCmd), (int)EMesLogClass.GetCellState);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
///8 烘烤进站
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="LocationID"></param>
|
|||
|
|
/// <param name="palletCode"></param>
|
|||
|
|
/// <param name="batteryCodes"></param>
|
|||
|
|
public void MESBakingInput(string LocationID, string palletCode, List<string> batteryCodes, string recipeName)
|
|||
|
|
{
|
|||
|
|
BakingInputCmd bakingInputCmd = new BakingInputCmd();
|
|||
|
|
//bakingInputCmd.Info = new BakingInput();
|
|||
|
|
bakingInputCmd.Info.EquipmentCode = _unityContainer.Resolve<SysSetupService>().GetValueByParaID(ESysSetup.DeviceNum.ToString());// "EC001";
|
|||
|
|
bakingInputCmd.Info.TrayNo = palletCode;
|
|||
|
|
bakingInputCmd.Info.LocationID = LocationID;
|
|||
|
|
bakingInputCmd.Info.RecipeName = recipeName;
|
|||
|
|
List<CellModel> cellModels = new List<CellModel>();
|
|||
|
|
batteryCodes.ForEach((x) =>
|
|||
|
|
{
|
|||
|
|
cellModels.Add(new CellModel() { CellNo = x });
|
|||
|
|
});
|
|||
|
|
bakingInputCmd.Info.Cells = cellModels;
|
|||
|
|
SendData(JSON.SerializeObject(bakingInputCmd), (int)EMesLogClass.EnterStation, true);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 9.烘烤过程参数采集
|
|||
|
|
/// </summary>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public void MESBakingParameter(float vacuum, float[] temps, string LocationID)
|
|||
|
|
{
|
|||
|
|
int index = 0;
|
|||
|
|
BakingParameterCmd param = new BakingParameterCmd();
|
|||
|
|
//param.Info = new BakingParameter();
|
|||
|
|
List<ProcessData> processDatas = new List<ProcessData>();
|
|||
|
|
param.Info.LocationID = LocationID;
|
|||
|
|
param.Info.LocalTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); ;
|
|||
|
|
param.Info.EquipmentCode = _unityContainer.Resolve<SysSetupService>().GetValueByParaID(ESysSetup.DeviceNum.ToString());
|
|||
|
|
|
|||
|
|
//真空
|
|||
|
|
ProcessData parameterInfo = new ProcessData();
|
|||
|
|
parameterInfo.ParameterCode = "HK-0017";
|
|||
|
|
parameterInfo.ParameterType = "float";
|
|||
|
|
parameterInfo.Value = vacuum.ToString();
|
|||
|
|
processDatas.Add(parameterInfo);
|
|||
|
|
|
|||
|
|
//温度
|
|||
|
|
int i = 0;
|
|||
|
|
foreach (var temp in temps)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
if (i % 2 != 0)
|
|||
|
|
{
|
|||
|
|
index++;
|
|||
|
|
parameterInfo = new ProcessData();
|
|||
|
|
parameterInfo.ParameterCode = "HK-00" + $"{12 + index}";
|
|||
|
|
parameterInfo.ParameterType = "float";
|
|||
|
|
parameterInfo.Value = temp.ToString();
|
|||
|
|
parameterInfo.Description = $"巡检-温度{index}";
|
|||
|
|
processDatas.Add(parameterInfo);
|
|||
|
|
}
|
|||
|
|
i++;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
param.Info.ParameterInfo = processDatas;
|
|||
|
|
SendData(JSON.SerializeObject(param), (int)EMesLogClass.BakingParameter, false);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
///10. 烘烤出站
|
|||
|
|
/// </summary>
|
|||
|
|
|
|||
|
|
public MESReturnCmdModel MESBakingOutput(string LocationID, TPalletInfo palletInfo, List<TBatteryInfo> batterys, bool outFlag, bool realTimeSend)
|
|||
|
|
{
|
|||
|
|
BakingOutputCmd outputParams = new BakingOutputCmd();
|
|||
|
|
|
|||
|
|
outputParams.Info.EquipmentCode = _unityContainer.Resolve<SysSetupService>().GetValueByParaID(ESysSetup.DeviceNum.ToString());
|
|||
|
|
outputParams.Info.TrayNo = palletInfo.PalletCode;
|
|||
|
|
outputParams.Info.LocationID = LocationID;
|
|||
|
|
outputParams.Info.OutFlag = outFlag ? "Y" : "N";
|
|||
|
|
List<CellModel> cellModels = new List<CellModel>();
|
|||
|
|
WaterModel waterModel = new WaterModel();
|
|||
|
|
|
|||
|
|
if (!string.IsNullOrEmpty(palletInfo.WaterValue))
|
|||
|
|
{
|
|||
|
|
var waterModelList = JsonConvert.DeserializeObject<List<WaterModel>>(palletInfo.WaterValue); //输入水含量异常,导致
|
|||
|
|
waterModel = waterModelList.OrderByDescending(x => x.Id).First(); //最ID最大的
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
var batteryCodes = batterys.Select(x => x.BatteryCode).ToList();
|
|||
|
|
batteryCodes.ForEach((x) =>
|
|||
|
|
{
|
|||
|
|
cellModels.Add(new CellModel() { CellNo = x });
|
|||
|
|
});
|
|||
|
|
outputParams.Info.Cells = cellModels;
|
|||
|
|
string RowAndColumn = "";
|
|||
|
|
foreach (var item in batterys)
|
|||
|
|
{
|
|||
|
|
RowAndColumn += $"{item.PositionX}行,{item.PositionY}列,";
|
|||
|
|
}
|
|||
|
|
List<ParametersModel> bakingOutputDatas = new List<ParametersModel>();
|
|||
|
|
|
|||
|
|
ParametersModel bakingOutputData = new ParametersModel();
|
|||
|
|
bakingOutputData = new ParametersModel();
|
|||
|
|
bakingOutputData.ParameterCode = "HK-0001";
|
|||
|
|
bakingOutputData.ParameterDesc = "烘烤号";
|
|||
|
|
var cavity = _unityContainer.Resolve<MemoryDataProvider>().CavityInfo.Where(x => x.Id == (palletInfo.BakingPosition ?? 0)).FirstOrDefault();
|
|||
|
|
bakingOutputData.Value = (cavity == null) ? "" : cavity.Name;
|
|||
|
|
bakingOutputDatas.Add(bakingOutputData);
|
|||
|
|
|
|||
|
|
bakingOutputData = new ParametersModel();
|
|||
|
|
bakingOutputData.ParameterCode = "HK-0002";
|
|||
|
|
bakingOutputData.ParameterDesc = "托盘号";
|
|||
|
|
bakingOutputData.Value = palletInfo.PalletCode;
|
|||
|
|
bakingOutputDatas.Add(bakingOutputData);
|
|||
|
|
|
|||
|
|
bakingOutputData = new ParametersModel();
|
|||
|
|
bakingOutputData.ParameterCode = "HK-0003";
|
|||
|
|
bakingOutputData.ParameterDesc = "行列";
|
|||
|
|
bakingOutputData.Value = $"{RowAndColumn}";
|
|||
|
|
bakingOutputDatas.Add(bakingOutputData);
|
|||
|
|
|
|||
|
|
bakingOutputData = new ParametersModel();
|
|||
|
|
bakingOutputData.ParameterCode = "HK-0004";
|
|||
|
|
bakingOutputData.ParameterDesc = "进站时间";
|
|||
|
|
bakingOutputData.Value = null == palletInfo.LoadingBegingTime ? DateTime.Now.ToString() : palletInfo.LoadingBegingTime.Value.ToString();
|
|||
|
|
bakingOutputDatas.Add(bakingOutputData);
|
|||
|
|
|
|||
|
|
bakingOutputData = new ParametersModel();
|
|||
|
|
bakingOutputData.ParameterCode = "HK-0005";
|
|||
|
|
bakingOutputData.ParameterDesc = "出站时间";
|
|||
|
|
bakingOutputData.Value = DateTime.Now.ToString();
|
|||
|
|
bakingOutputDatas.Add(bakingOutputData);
|
|||
|
|
|
|||
|
|
bakingOutputData = new ParametersModel();
|
|||
|
|
bakingOutputData.ParameterCode = "HK-0006";
|
|||
|
|
bakingOutputData.ParameterDesc = "烘烤开始时间";
|
|||
|
|
bakingOutputData.Value = null == palletInfo.BakingBeginTime ? DateTime.Now.ToString() : palletInfo.BakingBeginTime.Value.ToString();
|
|||
|
|
bakingOutputDatas.Add(bakingOutputData);
|
|||
|
|
|
|||
|
|
bakingOutputData = new ParametersModel();
|
|||
|
|
bakingOutputData.ParameterCode = "HK-0007";
|
|||
|
|
bakingOutputData.ParameterDesc = "烘烤结束时间";
|
|||
|
|
bakingOutputData.Value = null == palletInfo.BakingOverTime ? DateTime.Now.ToString() : palletInfo.BakingOverTime.Value.ToString();
|
|||
|
|
bakingOutputDatas.Add(bakingOutputData);
|
|||
|
|
|
|||
|
|
bakingOutputData = new ParametersModel();
|
|||
|
|
bakingOutputData.ParameterCode = "HK-0008";
|
|||
|
|
bakingOutputData.ParameterDesc = "电芯冷却温度";
|
|||
|
|
var temps = batterys.Select(x => x.CoolTemp).ToList();
|
|||
|
|
bakingOutputData.Value = string.Join(", ", temps);
|
|||
|
|
bakingOutputDatas.Add(bakingOutputData);
|
|||
|
|
|
|||
|
|
|
|||
|
|
bakingOutputData = new ParametersModel();
|
|||
|
|
bakingOutputData.ParameterCode = "HK-0011";
|
|||
|
|
bakingOutputData.ParameterDesc = "冷却开始时间";
|
|||
|
|
bakingOutputData.Value = DateTime.Now.ToString();
|
|||
|
|
bakingOutputDatas.Add(bakingOutputData);
|
|||
|
|
|
|||
|
|
|
|||
|
|
bakingOutputData = new ParametersModel();
|
|||
|
|
bakingOutputData.ParameterCode = "HK-0012";
|
|||
|
|
bakingOutputData.ParameterDesc = "冷却结束时间";
|
|||
|
|
bakingOutputData.Value = DateTime.Now.ToString();
|
|||
|
|
bakingOutputDatas.Add(bakingOutputData);
|
|||
|
|
|
|||
|
|
bakingOutputData = new ParametersModel();
|
|||
|
|
bakingOutputData.ParameterCode = "HK-0013";
|
|||
|
|
bakingOutputData.ParameterDesc = "正极水含量";
|
|||
|
|
bakingOutputData.Value = waterModel.AnodeWaterValue;
|
|||
|
|
bakingOutputDatas.Add(bakingOutputData);
|
|||
|
|
|
|||
|
|
bakingOutputData = new ParametersModel();
|
|||
|
|
bakingOutputData.ParameterCode = "HK-0014";
|
|||
|
|
bakingOutputData.ParameterDesc = "隔膜水含量";
|
|||
|
|
bakingOutputData.Value = waterModel.SeptumWaterValue;
|
|||
|
|
bakingOutputDatas.Add(bakingOutputData);
|
|||
|
|
|
|||
|
|
bakingOutputData = new ParametersModel();
|
|||
|
|
bakingOutputData.ParameterCode = "HK-0015";
|
|||
|
|
bakingOutputData.ParameterDesc = "负极水含量";
|
|||
|
|
bakingOutputData.Value = waterModel.CathodeWaterValue;
|
|||
|
|
bakingOutputDatas.Add(bakingOutputData);
|
|||
|
|
|
|||
|
|
//bakingOutputData = new ParametersModel();
|
|||
|
|
//bakingOutputData.ParameterCode = "HK-0019";
|
|||
|
|
//bakingOutputData.ParameterDesc = "是否出站";
|
|||
|
|
//bakingOutputData.Value = outFlag ? "Y" : "N";
|
|||
|
|
//bakingOutputDatas.Add(bakingOutputData);
|
|||
|
|
|
|||
|
|
bakingOutputData = new ParametersModel();
|
|||
|
|
bakingOutputData.ParameterCode = "HK-0020";
|
|||
|
|
bakingOutputData.ParameterDesc = "最高温度";
|
|||
|
|
bakingOutputData.Value = GetMaxTemperature(palletInfo.VirtualId).ToString();
|
|||
|
|
bakingOutputDatas.Add(bakingOutputData);
|
|||
|
|
|
|||
|
|
outputParams.Info.Parameters = bakingOutputDatas;
|
|||
|
|
//return outputParams;
|
|||
|
|
return SendData(JSON.SerializeObject(outputParams), (int)EMesLogClass.ExitStation, realTimeSend);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public float GetMaxTemperature(int virtualId)
|
|||
|
|
{
|
|||
|
|
float value = 0;
|
|||
|
|
if (!dicMaxTemp.TryGetValue(virtualId, out value)) //可以不删除dicMaxTemp,因为量不大,
|
|||
|
|
{
|
|||
|
|
LogHelper.Instance.Warn("开始获取最高温度");
|
|||
|
|
value = _unityContainer.Resolve<StoveSctualPatrolService>().GetStoveMaxTemp(virtualId);
|
|||
|
|
LogHelper.Instance.Warn("结束获取最高温度");
|
|||
|
|
|
|||
|
|
dicMaxTemp.TryAdd(virtualId, value);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return value;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public MESReturnCmdModel SendData(string info, sbyte msgType = (int)EMesLogClass.ExitStation, bool isEanble = true)
|
|||
|
|
{
|
|||
|
|
var result = GetRecvData(info, msgType, isEanble);
|
|||
|
|
if (string.IsNullOrEmpty(result))
|
|||
|
|
{
|
|||
|
|
return null;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return JSON.DeserializeObject<MESReturnCmdModel>(result);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public T SendData<T>(string info, sbyte msgType, bool isEanble = true)
|
|||
|
|
{
|
|||
|
|
var result = GetRecvData(info, msgType, isEanble);
|
|||
|
|
if (string.IsNullOrEmpty(result))
|
|||
|
|
{
|
|||
|
|
return default(T); //default(T)
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return JSON.DeserializeObject<T>(result);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public string GetRecvData(string info, sbyte msgType, bool isEanble = true)
|
|||
|
|
{
|
|||
|
|
CCommandType ct = new CCommandType();
|
|||
|
|
ct.UrlCmd = URL;
|
|||
|
|
TMesData mesModel = new TMesData();
|
|||
|
|
mesModel.CreateTime = DateTime.Now;
|
|||
|
|
mesModel.CommandType = JSON.SerializeObject(ct);
|
|||
|
|
mesModel.Content = info; //JSON.SerializeObject(obj);
|
|||
|
|
mesModel.MsgType = msgType;
|
|||
|
|
if (int.Parse(_unityContainer.Resolve<SysSetupService>().GetValueByParaID(ESysSetup.MOMEnable.ToString())) == (int)EMOMEnable.Enable
|
|||
|
|
&& isEanble) //又发又存
|
|||
|
|
{
|
|||
|
|
mesModel.SendTime = DateTime.Now;
|
|||
|
|
string result = HttpClientHelper.HttpPost(URL, info);
|
|||
|
|
mesModel.RecvTime = DateTime.Now;
|
|||
|
|
mesModel.RecvContent = result;
|
|||
|
|
mesModel.SendFlag = string.IsNullOrEmpty(result) ? (sbyte)EMesUpLoadStatus.Fail : (sbyte)EMesUpLoadStatus.Success;
|
|||
|
|
|
|||
|
|
if(msgType != (int)EMesLogClass.EqptAlive)
|
|||
|
|
{
|
|||
|
|
_unityContainer.Resolve<MesDataService>().Insert(mesModel); //保存数据
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (string.IsNullOrEmpty(result))
|
|||
|
|
{
|
|||
|
|
return null;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
WriteRequestLog(info);
|
|||
|
|
WriteResponseLog(result);
|
|||
|
|
//var resultModel = JSON.DeserializeObject<MESReturnCmdModel>(result);
|
|||
|
|
return result;
|
|||
|
|
}
|
|||
|
|
else if (int.Parse(_unityContainer.Resolve<SysSetupService>().GetValueByParaID(ESysSetup.MOMEnable.ToString())) == (int)EMOMEnable.Disable
|
|||
|
|
|| !isEanble) //只存不发
|
|||
|
|
{
|
|||
|
|
mesModel.SendFlag = (sbyte)EMesUpLoadStatus.Wait;
|
|||
|
|
_unityContainer.Resolve<MesDataService>().Insert(mesModel); //保存数据
|
|||
|
|
return null;
|
|||
|
|
}
|
|||
|
|
else //不发,也不存
|
|||
|
|
{
|
|||
|
|
return null;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
///发送
|
|||
|
|
public void WriteRequestLog(string info)
|
|||
|
|
{
|
|||
|
|
dynamic d = JsonConvert.DeserializeObject<dynamic>(info);
|
|||
|
|
string cmd = d.Cmd;
|
|||
|
|
string dateTime = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
|
|||
|
|
string uuid = d.Info.Key;
|
|||
|
|
LogHelper.Instance.Trace($"[Request][{cmd}][{dateTime}][{uuid}][{info}]");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 接收
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="info"></param>
|
|||
|
|
public void WriteResponseLog(string info)
|
|||
|
|
{
|
|||
|
|
dynamic d = JsonConvert.DeserializeObject<dynamic>(info);
|
|||
|
|
string cmd = d.Cmd;
|
|||
|
|
string dateTime = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
|
|||
|
|
string uuid = d.Info.Key;
|
|||
|
|
LogHelper.Instance.Trace($"[Response][{cmd}][{dateTime}][{uuid}][{info}]");
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public string GetEquipmentCode(int MachineID)
|
|||
|
|
{
|
|||
|
|
string equipmentCode = _unityContainer.Resolve<SysSetupService>().GetValueByParaID(ESysSetup.DeviceNum.ToString());
|
|||
|
|
string LineCode = equipmentCode.Substring(equipmentCode.Length - 2);
|
|||
|
|
MachineID = int.Parse(LineCode) + MachineID - 1;
|
|||
|
|
string formattedNumber = MachineID.ToString().PadLeft(2, '0');
|
|||
|
|
equipmentCode = equipmentCode.Replace(LineCode, formattedNumber);
|
|||
|
|
return equipmentCode;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|