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";
///
/// 获取轴承信息接口
///
/// 轴承条码
///
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 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(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;
}
///
/// 获取轴颈尺寸接口(扫描轮对条码,获取轴颈数据)
///
/// 轮对条码
///
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 res = client.getInfoByJournalAsync(barcode);
resultString = res.Result.Body.getInfoByJournalResult;
// result.OK(data: resultString);
// resultString = File.ReadAllText(@"D://xml.txt");
xmlEntity = XMLSerializationTool.DeserializeXmlToObject(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 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 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;
}
///
/// 轴承扫码选配接口
///
///
///
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 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;
}
///
/// 查询测量数据结果
///
///
///
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 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; }
}
}