M182轴承端盖外观缺陷AOI
kingno
2025-05-26 5a405c7dce20d8c79a733c9c786cc42eb59fe81c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
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}";
        }
    }
}