using Bro.Common.Helper;
|
using Bro.Common.Model;
|
using Newtonsoft.Json;
|
using System;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.Drawing.Design;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace Bro.M141.Process
|
{
|
public partial class M141Process
|
{
|
private void OEEDataUpload(string stationCode, string sn, List<DetectResult> defectList)
|
{
|
try
|
{
|
WebApiHelper apiHelper = new WebApiHelper();
|
string data = GetDefectDataStrForOEEDataUpload(stationCode, sn, defectList);
|
LogAsync(DateTime.Now, EnumHelper.LogLevel.Assist, $"OEE上传信息{data}");
|
|
apiHelper.dooPostAsync(M141Config.OEEDataUploadURL, data).ContinueWith(t =>
|
{
|
try
|
{
|
string replyData = t.Result;
|
LogAsync(DateTime.Now, EnumHelper.LogLevel.Action, $"OEE上传信息完成,反馈{replyData}");
|
}
|
catch (Exception ex)
|
{
|
LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"OEE上传信息反馈异常,{ex.GetExceptionMessage()}");
|
}
|
});
|
}
|
catch (Exception ex)
|
{
|
LogAsync(DateTime.Now, EnumHelper.LogLevel.Exception, $"工位{stationCode}上传OEE信息异常,{ex.GetExceptionMessage()}");
|
}
|
}
|
|
const string MES_OK = "Passed";
|
const string MES_NG = "Failed";
|
private string GetDefectDataStrForOEEDataUpload(string stationCode, string sn, List<DetectResult> defectList)
|
{
|
MESDataFrame dataFrame = new MESDataFrame();
|
dataFrame.workPlace = stationCode;
|
|
snData data = new snData();
|
data.sn = sn;
|
data.dateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
data.result = defectList.All(u => u.ResultState == EnumHelper.ResultState.OK) ? MES_OK : MES_NG;
|
|
var specList = defectList.SelectMany(u => u.Specs).ToList();
|
specList.ForEach(s =>
|
{
|
measurement mm = new measurement();
|
mm.reference = s.Code;
|
mm.type = "1";
|
mm.status = s.MeasureResult == true ? MES_OK : MES_NG;
|
mm.value = s.GetMeasureValueStr(4);
|
mm.ucl = (s.StandardValue + s.Tolrenance_Positive).ToString("f4");
|
mm.lcl = (s.StandardValue - s.Tolrenance_Negative).ToString("f4");
|
data.measurements.Add(mm);
|
});
|
|
var allDefects = defectList.GetDefectDescList();
|
var assignedDefects = new List<string>();
|
|
//_allDefectList.ForEach(s =>
|
//{
|
// measurement mm = new measurement();
|
// mm.reference = s;
|
// mm.type = "2";
|
// mm.status = allDefects.Contains(s) ? MES_NG : MES_OK;
|
// data.measurements.Add(mm);
|
//});
|
|
var allDemands = Config.GetDefectSwitch().Where(u => u.IsEnable).Select(u => u.DefectName).Distinct().ToList();
|
|
allDemands.ForEach(s =>
|
{
|
if (specList.Any(u => u.Code == s))
|
{
|
return;
|
}
|
else
|
{
|
measurement mm = new measurement();
|
mm.reference = s;
|
mm.type = "2";
|
mm.status = allDefects.Contains(s) ? MES_NG : MES_OK;
|
data.measurements.Add(mm);
|
}
|
});
|
|
allDefects.ForEach(s =>
|
{
|
if (!data.measurements.Any(u => u.reference == s))
|
{
|
measurement mm = new measurement();
|
mm.reference = s;
|
mm.type = "2";
|
mm.status = MES_NG;
|
data.measurements.Add(mm);
|
}
|
});
|
|
dataFrame.snData.Add(data);
|
|
return JsonConvert.SerializeObject(dataFrame);
|
}
|
}
|
|
public class MESDataFrame
|
{
|
public string workPlace { get; set; } = "";
|
|
[TypeConverter(typeof(CollectionCountConvert))]
|
[Editor(typeof(ComplexCollectionEditor<snData>), typeof(UITypeEditor))]
|
public List<snData> snData { get; set; } = new List<snData>();
|
}
|
|
public class snData : IComplexDisplay
|
{
|
public string sn { get; set; } = "";
|
public string dateTime { get; set; } = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
public string result { get; set; } = "";
|
|
[TypeConverter(typeof(CollectionCountConvert))]
|
[Editor(typeof(ComplexCollectionEditor<measurement>), typeof(UITypeEditor))]
|
public List<measurement> measurements { get; set; } = new List<measurement>();
|
|
public string GetDisplayText()
|
{
|
return $"{sn} {result}";
|
}
|
}
|
|
public class measurement : IComplexDisplay
|
{
|
public string reference { get; set; } = "";
|
public string type { get; set; } = "1";
|
public string status { get; set; } = "";
|
public string value { get; set; } = "";
|
public string ucl { get; set; } = "";
|
public string lcl { get; set; } = "";
|
|
public string GetDisplayText()
|
{
|
return $"{reference} {status} {value}";
|
}
|
}
|
}
|