Admin
5 天以前 bd6818fc9d40f343547bafca0743658f3c0379dc
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using WIDESEA.Common;
using WIDESEA.Core.ManageUser;
using WIDESEA.Core.Utilities;
using WIDESEA.Entity.DomainModels;
using WIDESEA.Services.IServices;
using WIDESEA.Services.Repositories;
using WIDESEA_Common.LogEnum;
 
namespace WIDESEA.Services.Services.ToMes
{
    public class ToMesService
    {
        //http://172.21.1.117/barcode/Webservice/WebService_ZY/WebServiceZY.asmx;
        public static string POSTURL = "http://172.21.1.117/barcode/Webservice/WebService_ZY/Service_EQP.asmx";
        /// <summary>
        /// 获取轴承信息接口
        /// </summary>
        /// <param name="saveModel">轴承条码</param>
        /// <returns></returns>
        public static WebResponseContent Mes_GetBearingInfo(SaveModel saveModel)
        {
            getInfoByBearingXMLEntity xmlEntity = null;
            string resultString = string.Empty;
            WebResponseContent content = new WebResponseContent();
            Idt_rulerService rulerService = dt_rulerService.Instance;
            //WebResponseContent result = new WebResponseContent();
            try
            {
                string barcode = saveModel.MainData["barcode"].ToString();
                 //2695-2022-05-1815
                 EndpointAddress address = new EndpointAddress(POSTURL);
                 ErpWebService.Service_EQPSoapClient client = new ErpWebService.Service_EQPSoapClient(new BasicHttpBinding(), address);
                 Task<ErpWebService.getInfoByBearingResponse> res = client.getInfoByBearingAsync(barcode);
                 resultString = res.Result.Body.getInfoByBearingResult;
                 //result.OK(data: resultString);
                 // resultString = File.ReadAllText(@"D://xml.txt");
                 if (string.IsNullOrEmpty(resultString))
                     throw new Exception("获取轴承信息失败.");
 
 
                xmlEntity = XMLSerializationTool.DeserializeXmlToObject<getInfoByBearingXMLEntity>(resultString);
                WebResponseContent responseContent = rulerService.GetDateTimeByRule(xmlEntity.TRAINTYPE, xmlEntity.MANUFACTOR, xmlEntity.MAINFREQ, barcode);
                if(responseContent.Status)
                {
                    xmlEntity.ProductDate = responseContent.Data.ToString();
                }
               
                content.OK(data: xmlEntity);
            }
            catch (Exception ex)
            {
                content.Error("获取轴承信息失败.异常:" + ex.Message);
            }
            finally
            {
                LogRecord.WriteLog((int)LogEnum.Mes, $"组盘查询轴承信息结果:{resultString}");
            }
            return content;
        }
 
 
        /// <summary>
        /// 获取轴颈尺寸接口(扫描轮对条码,获取轴颈数据)
        /// </summary>
        /// <param name="saveModel">轮对条码</param>
        /// <returns></returns>
        public static WebResponseContent Mes_GetBearingNeckSizeInfo(SaveModel saveModel)
        {
            WebResponseContent content = new WebResponseContent();
            //WebResponseContent result = new WebResponseContent();
            string resultString = string.Empty;
            getInfoByJournalXMLEntity xmlEntity = null;
            string barcode = string.Empty;
            QueryZCInfo queryZCInfo = new QueryZCInfo();
            try
            {
                barcode = saveModel.MainData["barcode"].ToString();
                EndpointAddress address = new EndpointAddress(POSTURL);
                ErpWebService.Service_EQPSoapClient client = new ErpWebService.Service_EQPSoapClient(new BasicHttpBinding(), address);
                Task<ErpWebService.getInfoByJournalResponse> res = client.getInfoByJournalAsync(barcode);
                resultString = res.Result.Body.getInfoByJournalResult;
                // result.OK(data: resultString);
                // resultString = File.ReadAllText(@"D://xml.txt");
                xmlEntity = XMLSerializationTool.DeserializeXmlToObject<getInfoByJournalXMLEntity>(resultString);
                if (xmlEntity.FLAG == "S")
                {
                    Data zzjAVG = xmlEntity.Datas.Data.Where(r => r.name == "左轴颈平均值").OrderByDescending(r => r.time).FirstOrDefault();
                    if (null != zzjAVG) queryZCInfo.zzjAVG = decimal.Parse(zzjAVG.value).ToString("N3");
 
                    Data yzjAVG = xmlEntity.Datas.Data.Where(r => r.name == "右轴颈平均值").OrderByDescending(r => r.time).FirstOrDefault();
                    if (null != yzjAVG) queryZCInfo.yzjAVG = decimal.Parse(yzjAVG.value).ToString("N3");
 
                    Data zfcbAVG = xmlEntity.Datas.Data.Where(r => r.name == "左防尘板座平均值").OrderByDescending(r => r.time).FirstOrDefault();
                    if (null != zfcbAVG) queryZCInfo.zfcbAVG = decimal.Parse(zfcbAVG.value).ToString("N3");
 
                    Data yfcbAVG = xmlEntity.Datas.Data.Where(r => r.name == "右防尘板座平均值").OrderByDescending(r => r.time).FirstOrDefault();
                    if (null != yfcbAVG) queryZCInfo.yfcbAVG = decimal.Parse(yfcbAVG.value).ToString("N3");
 
                    Data zydAVG = xmlEntity.Datas.Data.Where(r => r.name == "左油档平均值").OrderByDescending(r => r.time).FirstOrDefault();
                    if (null != zydAVG) queryZCInfo.zydAVG = decimal.Parse(zydAVG.value).ToString("N3");
 
                    Data yydAVG = xmlEntity.Datas.Data.Where(r => r.name == "右油档平均值").OrderByDescending(r => r.time).FirstOrDefault();
                    if (null != yydAVG) queryZCInfo.yydAVG = decimal.Parse(yydAVG.value).ToString("N3");
 
                    Data materiel = xmlEntity.Datas.Data.Where(r => r.name == "车型").OrderByDescending(r => r.time).FirstOrDefault();
                    if (null != materiel) queryZCInfo.materiel = materiel.value;
 
                    Data ldcode = xmlEntity.Datas.Data.Where(r => r.name == "轮对号").OrderByDescending(r => r.time).FirstOrDefault();
                    if (null != ldcode) queryZCInfo.ldCode = ldcode.value;
 
                    queryZCInfo.ortherData = "";
                    List<Dt_materielinfo> materielinfo = Dt_materielinfoRepository.Instance.Find(r => r.materiel_suitMateriel.Contains(queryZCInfo.materiel));
                    if (null != materielinfo && materielinfo.Count > 0)
                    {
                        string[] listMaterielId = materielinfo.Select(r => r.materiel_id).ToArray();
                        List<Dt_selection_standards> standards = Dt_selection_standardsRepository.Instance.Find(r => listMaterielId.Contains(r.selection_carId));
                        if (null != standards && standards.Count > 0)
                        {
                            queryZCInfo.manufacturerArray = standards.Select(r => r.selection_zc_manufacturer).ToArray().Distinct().ToArray();
                            queryZCInfo.neworold = standards.Select(r => r.selection_zc_type).ToArray().Distinct().ToArray();
                        }
                    }
                }
                content.OK(data: queryZCInfo);
            }
            catch (Exception ex)
            {
                content.Error(ex.Message);
            }
            finally
            {
                LogRecord.WriteLog((int)LogEnum.Mes, $"{barcode},轴承出库查询轴承选配结果:{resultString},返回App信息:{JsonConvert.SerializeObject(queryZCInfo)}");
                // Services.CommonFunction.AddInterfaceLogAction(saveModel, result, "Mes_GetBearingNeckSizeInfo");
            }
            return content;
        }
 
 
 
        /// <summary>
        /// 轴承扫码选配接口
        /// </summary>
        /// <param name="saveModel"></param>
        /// <returns></returns>
        public WebResponseContent Mes_WheelsetMatch(SaveModel saveModel)
        {
            //WebResponseContent content = new WebResponseContent();
            //try
            //{
            //    //轮对条码
            //    string barcode = saveModel.MainData["barcode"].ToString();
            //    //轴承条码
            //    string barcodePart = saveModel.MainData["barcodePart"].ToString();
            //    //部件类型
            //    string barcodeType = saveModel.MainData["barcodeType"].ToString();
            //}
            //catch (Exception ex)
            //{
            //    content.Error(ex.Message);
            //}
 
            WebResponseContent content = new WebResponseContent();
            try
            {
                EndpointAddress address = new EndpointAddress("http://172.21.1.117/barcode/Webservice/WebService_ZY/Service_EQP.asmx");
                //EndpointAddress address = new EndpointAddress(" http://172.21.1.117/barcode/Webservice/WebService_ZY/WebServiceZY.asmx");
                ErpWebService.Service_EQPSoapClient client = new ErpWebService.Service_EQPSoapClient(new BasicHttpBinding(), address);
                Task<ErpWebService.WheelsetMatchResponse> res = client.WheelsetMatchAsync("", "", "");
                string resultString = res.Result.Body.WheelsetMatchResult;
                Console.WriteLine(resultString);
            }
            catch (Exception ex)
            {
                content.Error(ex.Message);
            }
            finally
            {
                //Services.CommonFunction.AddInterfaceLogAction("", content, "Mes_WheelsetMatch");
            }
            return content;
        }
        /// <summary>
        /// 查询测量数据结果
        /// </summary>
        /// <param name="materielNumber"></param>
        /// <returns></returns>
        public string Mes_QueryMeasureInfo(object materielNumber)
        {
            MeasureInfo result = new MeasureInfo();
            try
            {
                Dt_container_size_info info = Dt_container_size_infoRepository.Instance.FindFirst(x => x.csize_barcode == materielNumber.ToString());
                if (null != info)
                {
                    if (string.IsNullOrEmpty(info.csize_in_1))
                        throw new Exception("暂无测量值");
                    object obj = new
                    {
                        BearingInnerDiameter11 = info.csize_in_1,
                        BearingInnerDiameter12 = info.csize_in_2,
                        BearingInnerDiameter13 = info.csize_in_3,
                        BearingInnerDiameter14 = info.csize_in_4.Split('_')[0],
                        BearingInnerDiameter1Avg = info.csize_in_4.Split('_')[1],
 
                        BearingInnerDiameter21 = info.csize_in_5,
                        BearingInnerDiameter22 = info.csize_in_6,
                        BearingInnerDiameter23 = info.csize_in_7,
                        BearingInnerDiameter24 = info.csize_in_8.Split('_')[0],
                        BearingInnerDiameter2Avg = info.csize_in_8.Split('_')[1],
 
 
                        BearingInnerDiameter31 = info.csize_in_9,
                        BearingInnerDiameter32 = info.csize_in_10,
                        BearingInnerDiameter33 = info.csize_in_11,
                        BearingInnerDiameter34 = info.csize_in_12.Split('_')[0],
                        BearingInnerDiameter3Avg = info.csize_in_12.Split('_')[1],
 
                        BearingInnerDiameter41 = info.csize_in_13,
                        BearingInnerDiameter42 = info.csize_in_14,
                        BearingInnerDiameter43 = info.csize_in_15,
                        BearingInnerDiameter44 = info.csize_in_16.Split('_')[0],
                        BearingInnerDiameter4Avg = info.csize_in_16.Split('_')[1],
 
 
                        BearingInnerDiameterAvg = info.csize_in_value,
                        BearingInnerDiameterQualified = info.csize_in_result,
 
 
                        BearingOuterDiameter11 = info.csize_out_1,
                        BearingOuterDiameter12 = info.csize_out_2,
                        BearingOuterDiameter13 = info.csize_out_3,
                        BearingOuterDiameter14 = info.csize_out_4.Split('_')[0],
                        BearingOuterDiameter1Avg = info.csize_out_4.Split('_')[1],
 
 
                        BearingOuterDiameter21 = info.csize_out_5,
                        BearingOuterDiameter22 = info.csize_out_6,
                        BearingOuterDiameter23 = info.csize_out_7,
                        BearingOuterDiameter24 = info.csize_out_8.Split('_')[0],
                        BearingOuterDiameter2Avg = info.csize_out_8.Split('_')[1],
 
                        BearingOuterDiameter31 = info.csize_out_9,
                        BearingOuterDiameter32 = info.csize_out_10,
                        BearingOuterDiameter33 = info.csize_out_11,
                        BearingOuterDiameter34 = info.csize_out_12.Split('_')[0],
                        BearingOuterDiameter3Avg = info.csize_out_12.Split('_')[1],
 
                        BearingOuterDiameter41 = info.csize_out_13,
                        BearingOuterDiameter42 = info.csize_out_14,
                        BearingOuterDiameter43 = info.csize_out_15,
                        BearingOuterDiameter44 = info.csize_out_16.Split('_')[0],
                        BearingOuterDiameter4Avg = info.csize_out_16.Split('_')[1],
 
 
                        BearingOuterDiameterAvg = info.csize_out_value,
                        BearingOuterDiameterQualified = info.csize_out_result,
 
                        BearingOilGearDiameter1 = info.csize_three_1,
                        BearingOilGearDiameter2 = info.csize_three_2,
                        BearingOilGearDiameterAvg = info.csize_three_3,
                        BearingOilGearDiameterQualified = info.csize_three_result,
 
 
                        BearingTailgateDiameter1 = info.csize_four_1,
                        BearingTailgateDiameter2 = info.csize_four_2,
                        BearingTailgateDiameterAvg = info.csize_four_3,
                        BearingTailgateDiameterQualified = info.csize_four_result,
                    };
                    result.code = 1;
                    result.data = obj;
                }
                else
                {
                    result.code = 0;
                    result.message = "未找到轴承信息.";
                }
            }
            catch (Exception ex)
            {
                result.code = 0;
                result.message = ex.Message;
            }
            return JsonConvert.SerializeObject(result);
        }
 
        public WebResponseContent UploadMES(SaveModel saveModel)
        {
            WebResponseContent content = new WebResponseContent();
            try
            {
                foreach (var item in saveModel.DelKeys)
                {
                    string resultString = string.Empty;
                    string recordData = string.Empty;
                    try
                    {
                        dt_measureRecord record = dt_measureRecordRepository.Instance.FindFirst(r => r.measure_id == Guid.Parse(item.ToString()));
                        if (null == record)
                            return content.Error("未找到测量记录.");
                        if (!record.measure_result.Equals("合格"))
                            return content.Error("只能上传测量合格的数据.");
                        if (string.IsNullOrEmpty(record.measure_uploadData))
                            return content.Error("当前没有上传的数据,请重新测量.");
                        recordData = record.measure_uploadData;
                        EndpointAddress address = new EndpointAddress(ToMesService.POSTURL);
                        ErpWebService.Service_EQPSoapClient client = new ErpWebService.Service_EQPSoapClient(new BasicHttpBinding(), address);
                        Task<ErpWebService.ReportToSCEResponse> res = client.ReportToSCEAsync(record.measure_materielNumber, record.measure_uploadData);
                        resultString = res.Result.Body.ReportToSCEResult;
 
 
                        record.measure_uploadResult = "已上传";
                        record.measure_uploadTime = DateTime.Now;
                        record.measure_uploadUser = UserContext.Current.UserTrueName;
                        dt_measureRecordRepository.Instance.Update(record, x => new { x.measure_uploadResult, x.measure_uploadTime, x.measure_uploadUser }, true);
                    }
                    catch
                    {
 
                    }
                    finally
                    {
                        LogRecord.WriteLog((int)LogEnum.Mes, $"{UserContext.Current.UserTrueName}上传MES参数:{recordData},结果:{resultString}");
                    }
                }
                content.OK();
            }
            catch (Exception ex)
            {
                content.Error("上传失败:" + ex.Message);
            }
            finally
            {
 
            }
            return content;
        }
    }
    public class MeasureInfo
    {
        public int code { get; set; }
        public object data { get; set; }
 
        public string message { get; set; }
    }
}