using HslCommunication;
using System;
using System.Collections.Generic;
using System.Text;
using WIDESEA_Common;
using WIDESEA_Core.Utilities;
using WIDESEA_Entity.DomainModels;
using WIDESEA_Services;
using WIDESEA_Services.Repositories;
using WIDESEA_WCS.WCSClient;
namespace WIDESEA_WCS.Jobs.ConveyorLine
{
public class CheckBarcodeLogic
{
///
/// 校验托盘码是否一直
///
///
///
///
public static void DealWithCheckBarcodeLogic(Dt_TaskWCSinfoRepository taskWCSinfoRepository, Dt_StationManager station, PLCClient client)
{
//读取任务号,找到对应的任务,在进行托盘码的比对
OperateResult taskRes = (OperateResult)client.ReadValue(CLineInfoDBName.R_Line_TaskNumber.ToString(), station.sm_stationNo);
if (taskRes.IsSuccess)
{
UInt32 taskNum = taskRes.Content;
Dt_TaskWCSinfo wcsInfo = null;
if (station.sm_stationNo == "30301")
{
wcsInfo = taskWCSinfoRepository.FindFirst(x =>
(x.wcstask_type == TaskType.TaskType_Empty_Pallet_Inbound.ToString() ||
x.wcstask_type == TaskType.TaskType_Box_Pallet_Inbound.ToString()) &&
x.wcstask_state == TaskState.TaskState_ConveyorLineExecuting.ToString() &&
x.wcstask_taskNumber == taskNum);
if(wcsInfo == null)
{
//继续看下是不是测量回库的任务
wcsInfo = taskWCSinfoRepository.FindFirst(x =>
x.wcstask_type == TaskType.TaskType_Box_Pallet_Measure_Back.ToString() &&
x.wcstask_state == TaskState.TaskState_Measure_Back_Line_Executing.ToString() &&
x.wcstask_taskNumber == taskNum);
}
}
else
{
wcsInfo = taskWCSinfoRepository.FindFirst(x =>
x.wcstask_type == TaskType.TaskType_Box_Pallet_Measure_Out.ToString() &&
x.wcstask_state == TaskState.TaskState_Measure_Out_Line_Executing.ToString() &&
x.wcstask_taskNumber == taskNum);
}
if (wcsInfo != null)
{
//读取RFID值
OperateResult rfidResult1 = (OperateResult)client.ReadValue(CLineInfoDBName.R_Line_RFID_OK.ToString(), station.sm_stationNo);
if (rfidResult1.IsSuccess)
{
if (wcsInfo.wcstask_barcode != rfidResult1.Content.ToString())
{
//说明托盘不一致,需要在前端进行提示
//Console.WriteLine($"::Wanring::检测入库任务在托盘检验站台,入库托盘号:【{wcsInfo.wcstask_barcode}】,与RFID读取到的【{rfidResult1.Content}】,不一致!!");
//把情报告诉WMS
WebResponseContent content = WMSApi.PostRFIDNoMatch(
wcsInfo.wcstask_barcode,
rfidResult1.Content.ToString(),
wcsInfo.wcstask_taskNumber.ToString(),
station.sm_stationNo);
if (content.Status)
{
//Console.WriteLine($"已将托盘码不一致的情况上报给你WMS");
bool goOn = client.WriteValue(CLineInfoDBName.W_Line_RFID_Done.ToString(), station.sm_stationNo, 1);
if (goOn)
{
wcsInfo.wcstask_backUp_1 = "checked";
taskWCSinfoRepository.Update(wcsInfo, true);
//Console.WriteLine($"已上报,继续任务!");
}
}
}
else
{
//说明一致,通知线体继续往前走
bool goOn = client.WriteValue(CLineInfoDBName.W_Line_RFID_Done.ToString(), station.sm_stationNo, 1);
if (goOn)
{
wcsInfo.wcstask_backUp_1 = "checked";
taskWCSinfoRepository.Update(wcsInfo, true);
//Console.WriteLine($"任务号:【{wcsInfo.wcstask_taskNumber}】,托盘码:【rfidResult1.Content】对应的任务,与线体检测一至,继续任务");
}
}
}
}
}
}
}
}