using Microsoft.EntityFrameworkCore.Storage.ValueConversion.Internal; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.IdentityModel.Tokens.Jwt; using System.Linq; using System.Runtime; using System.Text; using System.Threading.Tasks; using WIDESEA_Common; using WIDESEA_Common.MES; using WIDESEA_Common.MES.Request; using WIDESEA_Core; using WIDESEA_Core.Const; using WIDESEA_Core.Helper; using WIDESEA_DTO; using WIDESEA_Model.Models; namespace WIDESEA_StoragIntegrationServices { /// /// BDC向MES请求车辆特征信息 /// 接口描述: BDC在PBS01前一个工位通过(PVI+白车身后4位)向MES请求VIN+车辆特征信息写入tag /// public partial class MESService { /// /// BDC请求车辆特征信息 /// /// RFID /// 站台请求点位 /// public WebResponseContent getCharacteristic(RequestTaskDto json) { WebResponseContent content = new WebResponseContent(); try { var carBodyInfo = _carBodyRepository.QueryFirst(x => x.RFID == json.PVI); //if (carBodyInfo == null) throw new Exception($"未找到PVI{rfid}的车身数据"); CarCharacteristicInfo characterInfo = new CarCharacteristicInfo() { plantCode = "1052", pvi = carBodyInfo.PVI, //vin = "", messageTime = DateTime.Now.ToString(), unionKey = Guid.NewGuid().ToString(), }; var configs = _configService.GetConfigsByCategory(CateGoryConst.CONFIG_SYS_MESIPAddress); var wmsBase = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.MESIPAddress)?.ConfigValue; var ipAddress = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.getCharacteristic)?.ConfigValue; if (wmsBase == null || ipAddress == null) { throw new InvalidOperationException("WMS IP 未配置"); } var wmsIpAddress = wmsBase + ipAddress; var MESrespon = HttpHelper.PostAsync(wmsIpAddress, characterInfo.ToJson(), contentType, headers).Result; GetCarCharacteristicInfo characterRespon = JsonConvert.DeserializeObject(MESrespon.ToString()); if (characterRespon.code != 200) { throw new Exception($"{characterRespon.msg}"); } if (string.IsNullOrEmpty(characterRespon.data)) throw new Exception("请求成功,但无VIN信息"); carBodyInfo.VIN = characterRespon.data.ToString().Substring(35, 17); _carBodyRepository.UpdateData(carBodyInfo); LogFactory.GetLog("BDC请求车辆特征信息").Info(true, $"\r\r--------------------------------------"); LogFactory.GetLog("BDC请求车辆特征信息").Info(true, $"工位号:{json.Position},RFID:{json.PVI},响应信息:{characterRespon.ToJson()}"); return content.OK(data: characterRespon.data); } catch (Exception ex) { LogFactory.GetLog("BDC请求车辆特征信息").Info(true, $"\r\r--------------------------------------"); LogFactory.GetLog("BDC请求车辆特征信息").Info(true, $"工位号:{json.Position},RFID:{json.PVI},错误信息:{ex.Message}"); return content.Error($"BDC请求车辆特征信息::{ex.Message}"); } } } }