using HslCommunication; using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using WIDESEA_Common; using WIDESEA_Common.Tools; using WIDESEA_Core.Utilities; using WIDESEA_Entity.DomainModels; using WIDESEA_Services; using WIDESEA_Services.IRepositories; using WIDESEA_Services.Repositories; using WIDESEA_Services.Services; using WIDESEA_WCS.WCSClient; namespace WIDESEA_WCS.Jobs.ConveyorLine.InboundArea { public partial class InboundAreaDispatch { private static string InboundWeighStationNo = "20201"; public static void InboundWeighAction(IDt_TaskWCSinfoRepository taskWCSinfoRepository, PLCClient client) { //读取设备正常 try { int weightingResult = int.Parse(client.ReadValue(CLineInfoDBName.R_Line_Weighting.ToString(), InboundWeighStationNo).ToString()); int barcode = int.Parse(client.ReadValue(CLineInfoDBName.R_Line_Barcode.ToString(), InboundWeighStationNo).ToString()); int taskNumber = int.Parse(client.ReadValue(CLineInfoDBName.R_Line_TaskNumber.ToString(), InboundWeighStationNo).ToString()); Dt_TaskWCSinfo wcsInfo = taskWCSinfoRepository.FindFirst(x => x.wcstask_barcode == barcode.ToString() && x.wcstask_taskNumber == taskNumber); if (null != wcsInfo) { var currentdt_taskinfo = taskWCSinfoRepository.DbContext.ChangeTracker.Entries().FirstOrDefault(); if (currentdt_taskinfo != null) currentdt_taskinfo.State = EntityState.Detached; //避免应急模式称重有问题 if (wcsInfo.wcstask_type != TaskType.TaskType_Box_Pallet_Inbound.ToString() && wcsInfo.wcstask_type != TaskType.TaskType_Empty_Pallet_Inbound.ToString()) { if (weightingResult == 1) return; else if (weightingResult == 2) client.WriteValue(CLineInfoDBName.W_Line_Weight_OK.ToString(), true); return; } string str = string.Empty; //称重中 if (weightingResult == 1) { WebResponseContent content = WMSApi.PostTaskStateToWMS(barcode.ToString(), TaskState.TaskState_Weighing.ToString()); if (content.Status) { wcsInfo.wcstask_state = TaskState.TaskState_Weighing.ToString(); wcsInfo.wcstask_dispatcherTime = DateTime.Now; taskWCSinfoRepository.Update(wcsInfo, true); str = $"{DateTime.Now}开始称重上报WMS成功,托盘号:{wcsInfo.wcstask_barcode},任务号:【{wcsInfo.wcstask_taskNumber}】"; } else str = $"{DateTime.Now}开始称重上报WMS失败,托盘号:{wcsInfo.wcstask_barcode},任务号:【{wcsInfo.wcstask_taskNumber}】,错误信息:{content.Message}"; WriteLog.Info(InboundWeighStationNo).Write(str, InboundWeighStationNo); }//称重完成 else if (weightingResult == 2) { int weightResult = int.Parse(client.ReadValue(CLineInfoDBName.R_Line_Weight.ToString(), InboundWeighStationNo).ToString()); WebResponseContent content = WMSApi.TellWmsWeightResult(wcsInfo.wcstask_barcode, weightResult.ToString()); if (content.Status) { str = $"{DateTime.Now}称重完成上报WMS成功,托盘号:{wcsInfo.wcstask_barcode},任务号:{wcsInfo.wcstask_taskNumber}"; WriteLog.Info(InboundWeighStationNo).Write(str, InboundWeighStationNo); //上报重量结果后,在此通知线体继续任务,该为了人工手动 client.WriteValue(CLineInfoDBName.W_Line_Weight_OK.ToString(), true); //称重完成后,在此更新任务状态、上报WMS任务状态 content = WMSApi.PostTaskStateToWMS(wcsInfo.wcstask_barcode, TaskState.TaskState_ConveyorLineExecuting.ToString()); if (content.Status) { wcsInfo.wcstask_state = TaskState.TaskState_ConveyorLineExecuting.ToString(); wcsInfo.wcstask_dispatcherTime = DateTime.Now; taskWCSinfoRepository.Update(wcsInfo, true); } } else { str = $"{DateTime.Now}称重完成上报WMS失败,托盘号:{wcsInfo.wcstask_barcode},任务号:{wcsInfo.wcstask_taskNumber},错误:{content.Message}"; WriteLog.Info(InboundWeighStationNo).Write(str, InboundWeighStationNo); } } } } catch (Exception ex) { WriteLog.Info(InboundWeighStationNo).Write($"称重站台调度失败:{ex.Message}", InboundWeighStationNo); } } } }