|  |  |  | 
|---|
|  |  |  | using LogLibrary.Log; | 
|---|
|  |  |  | using AngleSharp.Io; | 
|---|
|  |  |  | using LogLibrary.Log; | 
|---|
|  |  |  | using Masuit.Tools; | 
|---|
|  |  |  | using Newtonsoft.Json; | 
|---|
|  |  |  | using WIDESEA_Common; | 
|---|
|  |  |  | using WIDESEA_Core; | 
|---|
|  |  |  | using WIDESEA_Core.Const; | 
|---|
|  |  |  | using WIDESEA_Core.Helper; | 
|---|
|  |  |  | using WIDESEA_DTO; | 
|---|
|  |  |  | using WIDESEA_DTO.MOM; | 
|---|
|  |  |  | using WIDESEA_IRepository; | 
|---|
|  |  |  | using WIDESEA_IServices; | 
|---|
|  |  |  | using WIDESEA_IStorageBasicService; | 
|---|
|  |  |  | using WIDESEA_IStoragIntegrationServices; | 
|---|
|  |  |  | using WIDESEA_Model.Models; | 
|---|
|  |  |  | using static Org.BouncyCastle.Math.EC.ECCurve; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | namespace WIDESEA_StoragIntegrationServices; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | 
|---|
|  |  |  | private readonly LogFactory LogFactory = new LogFactory(); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | private readonly IBoxingInfoService _boxingInfoService; | 
|---|
|  |  |  | private readonly ISys_ConfigService _configService; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | public CellStateService(IBoxingInfoService boxingInfoService) | 
|---|
|  |  |  | public CellStateService(IBoxingInfoService boxingInfoService, ISys_ConfigService configRepository) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | _boxingInfoService = boxingInfoService; | 
|---|
|  |  |  | _configService = configRepository; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /// <summary> | 
|---|
|  |  |  | 
|---|
|  |  |  | try | 
|---|
|  |  |  | { | 
|---|
|  |  |  | input.SessionId = Guid.NewGuid().ToString(); | 
|---|
|  |  |  | input.Software = "陈化机"; | 
|---|
|  |  |  | input.EquipmentCode = "P1K10040"; | 
|---|
|  |  |  | input.EmployeeNo = "T00001"; | 
|---|
|  |  |  | input.EmployeeNo = "MITest"; | 
|---|
|  |  |  | input.RequestTime = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now).ToString("yyyy-MM-ddTHH:mm:ss.fffZ"); | 
|---|
|  |  |  | var inputJson = input.ToDictionary(); | 
|---|
|  |  |  | var x = await HttpsClient.PostAsync("http://ts-momapp01:12020/api/MachineIntegration/CellState", inputJson); | 
|---|
|  |  |  | if (x != null) | 
|---|
|  |  |  | var configs = _configService.GetConfigsByCategory(CateGoryConst.SYS_MOMIPAddress); | 
|---|
|  |  |  | var wmsBase = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.MOMBaseIP)?.ConfigValue; | 
|---|
|  |  |  | var ipAddress = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.CellState)?.ConfigValue; | 
|---|
|  |  |  | if (wmsBase == null || ipAddress == null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | ResultCellState result = JsonConvert.DeserializeObject<ResultCellState>(x); | 
|---|
|  |  |  | DtBoxingInfo boxingInfo = new DtBoxingInfo() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | IsFull = true, | 
|---|
|  |  |  | PalletCode = "", | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | var details = new List<DtBoxingInfoDetail>(); | 
|---|
|  |  |  | foreach (var item in result.SerialNos) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | DtBoxingInfoDetail detail = new DtBoxingInfoDetail() | 
|---|
|  |  |  | { | 
|---|
|  |  |  | SerialNumber = item.SerialNo, | 
|---|
|  |  |  | OrderNo = item.BindCode, | 
|---|
|  |  |  | Status = item.SerialNoStatus, | 
|---|
|  |  |  | }; | 
|---|
|  |  |  | details.Add(detail); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | boxingInfo.BoxingInfoDetails = details; | 
|---|
|  |  |  | var abc = await _boxingInfoService.AddBoxingInfoAsync(boxingInfo); | 
|---|
|  |  |  | if (abc.Status) | 
|---|
|  |  |  | return content.OK("组盘成功"); | 
|---|
|  |  |  | else | 
|---|
|  |  |  | return content.Error("组盘失败"); | 
|---|
|  |  |  | throw new InvalidOperationException("WMS IP 未配置"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | var wmsIpAddress = wmsBase + ipAddress; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | var result = HttpsClient.PostAsync(wmsIpAddress, inputJson).Result; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | LogFactory.GetLog("单电芯属性获取").Info(true, $"\r\r--------------------------------------"); | 
|---|
|  |  |  | LogFactory.GetLog("单电芯属性获取").Info(true, x); | 
|---|
|  |  |  | LogFactory.GetLog("单电芯属性获取").Info(true, result); | 
|---|
|  |  |  | return result; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | catch (Exception err) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | Console.WriteLine(err.Message.ToString()); | 
|---|
|  |  |  | LogFactory.GetLog("单电芯属性获取").Error(true, $"\r\r--------------------------------------"); | 
|---|
|  |  |  | LogFactory.GetLog("单电芯属性获取").Error(true, $"请求参数: {JsonConvert.SerializeObject(input)}"); | 
|---|
|  |  |  | LogFactory.GetLog("单电芯属性获取").Error(true, err.Message); | 
|---|
|  |  |  | LogFactory.GetLog("单电芯属性获取").Error(true, err.StackTrace); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return Task.FromResult<dynamic>(null); | 
|---|
|  |  |  | 
|---|
|  |  |  | try | 
|---|
|  |  |  | { | 
|---|
|  |  |  | input.SessionId = Guid.NewGuid().ToString(); | 
|---|
|  |  |  | input.Software = "陈化机"; | 
|---|
|  |  |  | input.EquipmentCode = "P1K10040"; | 
|---|
|  |  |  | input.EmployeeNo = "T00001"; | 
|---|
|  |  |  | input.EmployeeNo = "MITest"; | 
|---|
|  |  |  | input.RequestTime = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now).ToString("yyyy-MM-ddTHH:mm:ss.fffZ"); | 
|---|
|  |  |  | var inputJson = input.ToDictionary(); | 
|---|
|  |  |  | var x = await HttpsClient.PostAsync("http://ts-momapp01:12020/api/MachineIntegration/TrayCellsStatus", inputJson); | 
|---|
|  |  |  | //if (x != null) | 
|---|
|  |  |  | //{ | 
|---|
|  |  |  | //    // 反序列化ResultTrayCellsStatus对象 | 
|---|
|  |  |  | //    ResultTrayCellsStatus result = JsonConvert.DeserializeObject<ResultTrayCellsStatus>(x); | 
|---|
|  |  |  | var configs = _configService.GetConfigsByCategory(CateGoryConst.SYS_MOMIPAddress); | 
|---|
|  |  |  | var wmsBase = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.MOMBaseIP)?.ConfigValue; | 
|---|
|  |  |  | var ipAddress = configs.FirstOrDefault(x => x.ConfigKey == SysConfigConst.TrayCellsStatus)?.ConfigValue; | 
|---|
|  |  |  | if (wmsBase == null || ipAddress == null) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | throw new InvalidOperationException("WMS IP 未配置"); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | var wmsIpAddress = wmsBase + ipAddress; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //    // 创建DtBoxingInfo对象 | 
|---|
|  |  |  | //    DtBoxingInfo boxingInfo = new DtBoxingInfo | 
|---|
|  |  |  | //    { | 
|---|
|  |  |  | //        IsFull = true, | 
|---|
|  |  |  | //        PalletCode = result.TrayBarcode, | 
|---|
|  |  |  | //    }; | 
|---|
|  |  |  | var result = HttpsClient.PostAsync(wmsIpAddress, inputJson).Result; | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //    // 使用LINQ创建DtBoxingInfoDetail对象列表 | 
|---|
|  |  |  | //    var details = result.SerialNos.Select(item => new DtBoxingInfoDetail | 
|---|
|  |  |  | //    { | 
|---|
|  |  |  | //        SerialNumber = item.SerialNo, | 
|---|
|  |  |  | //        OrderNo = item.PositionNo.ToString(), | 
|---|
|  |  |  | //        Status = item.SerialNoStatus, | 
|---|
|  |  |  | //        Remark = result.TrayBarcodePropertys.ToJsonString(), | 
|---|
|  |  |  | //        MaterielCode = result.BindCode, | 
|---|
|  |  |  | //    }).ToList(); | 
|---|
|  |  |  | var respone = JsonConvert.DeserializeObject<ResultTrayCellsStatus>(result.ToString()); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | //    // 赋值DtBoxingInfoDetails | 
|---|
|  |  |  | //    boxingInfo.BoxingInfoDetails = details; | 
|---|
|  |  |  | //    var abc = await _boxingInfoService.AddBoxingInfoAsync(boxingInfo); | 
|---|
|  |  |  | //    if (abc.Status) | 
|---|
|  |  |  | //        content.OK("组盘成功", result); | 
|---|
|  |  |  | //    else | 
|---|
|  |  |  | //        content.Error("组盘失败"); | 
|---|
|  |  |  | //} | 
|---|
|  |  |  | if (!respone.Success) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | MoMErrorMsg.AddMoMErrorMsg(0, input.TrayBarcode, respone.MOMMessage, SysConfigConst.TrayCellsStatus); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | else | 
|---|
|  |  |  | { | 
|---|
|  |  |  | MoMErrorMsg.DeleteMoMErrorMsg(0, input.TrayBarcode); | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | LogFactory.GetLog("整盘电芯属性获取").Info(true, $"\r\r--------------------------------------"); | 
|---|
|  |  |  | LogFactory.GetLog("整盘电芯属性获取").Info(true, x); | 
|---|
|  |  |  | LogFactory.GetLog("整盘电芯属性获取").Info(true, result); | 
|---|
|  |  |  | content.OK(data: result); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | catch (Exception err) | 
|---|
|  |  |  | { | 
|---|
|  |  |  | MoMErrorMsg.AddMoMErrorMsg(0, input.TrayBarcode, err.Message, SysConfigConst.TrayCellsStatus); | 
|---|
|  |  |  |  | 
|---|
|  |  |  | Console.WriteLine(err.Message.ToString()); | 
|---|
|  |  |  | LogFactory.GetLog("整盘电芯属性获取").Error(true, $"\r\r--------------------------------------"); | 
|---|
|  |  |  | LogFactory.GetLog("整盘电芯属性获取").Error(true, $"请求参数: {JsonConvert.SerializeObject(input)}"); | 
|---|
|  |  |  | LogFactory.GetLog("整盘电芯属性获取").Error(true, err.Message); | 
|---|
|  |  |  | LogFactory.GetLog("整盘电芯属性获取").Error(true, err.StackTrace); | 
|---|
|  |  |  | } | 
|---|
|  |  |  | return content; | 
|---|