using HslCommunication;
|
using System;
|
using System.Collections.Generic;
|
using System.Text;
|
using WIDESEA_Common;
|
using WIDESEA_Common.LogEnum;
|
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 WeighingLogic
|
{
|
|
/// <summary>
|
/// 获取重量,不管是空托还是实托,都需要有重量记录
|
/// </summary>
|
/// <param name="taskWCSinfoRepository"></param>
|
/// <param name="station"></param>
|
/// <param name="client"></param>
|
public static void DealWithWeighingLogic(Dt_TaskWCSinfoRepository taskWCSinfoRepository, Dt_StationManager station, PLCClient client)
|
{
|
OperateResult<Int16> weightingResult = (OperateResult<Int16>)client.ReadValue(CLineInfoDBName.R_Line_Weighting.ToString(), station.sm_stationNo);
|
OperateResult<UInt32> rfidResult = (OperateResult<UInt32>)client.ReadValue(CLineInfoDBName.R_Line_Barcode.ToString(), station.sm_stationNo);
|
OperateResult<UInt32> taskRes = (OperateResult<UInt32>)client.ReadValue(CLineInfoDBName.R_Line_TaskNumber.ToString(), station.sm_stationNo);
|
if (weightingResult.IsSuccess && rfidResult.IsSuccess && taskRes.IsSuccess)
|
{
|
UInt32 rfidValue = rfidResult.Content; //托盘码
|
int weighting = weightingResult.Content; //1 = 称重中 2= 称重完成
|
UInt32 taskNum = taskRes.Content;
|
|
//找到正在进行称重的任务
|
Dt_TaskWCSinfo wcsInfo = taskWCSinfoRepository.FindFirst(x =>
|
x.wcstask_barcode == rfidValue.ToString() &&
|
x.wcstask_taskNumber == taskNum &&
|
(x.wcstask_type == TaskType.TaskType_Box_Pallet_Inbound.ToString() ||
|
x.wcstask_type == TaskType.TaskType_Empty_Pallet_Inbound.ToString())&&
|
(x.wcstask_state == TaskState.TaskState_ConveyorLineExecuting.ToString() ||
|
x.wcstask_state == TaskState.TaskState_Weighing.ToString()));
|
if (wcsInfo != null)
|
{
|
//1 = 表示在称重中
|
if (weighting == 1)
|
{
|
LogRecord.WriteLog(LogEnum.InBound,$"任务号:【{taskNum}】,托盘号:【{rfidValue}】对应的任务达到【20201】站台,并且处于【称重中...】状态");
|
//在此更新任务状态、上报WMS任务状态
|
WebResponseContent content = WMSApi.PostTaskStateToWMS(rfidValue.ToString(), TaskState.TaskState_Weighing.ToString());
|
if (content.Status)
|
{
|
wcsInfo.wcstask_state = TaskState.TaskState_Weighing.ToString();
|
wcsInfo.wcstask_dispatcherTime = DateTime.Now;
|
taskWCSinfoRepository.Update(wcsInfo, true);
|
Console.WriteLine($"{DateTime.Now}=>Success=> 上报WMS更新任务状态成功【TaskState_Weighing】,任务号:【{wcsInfo.wcstask_taskNumber}】");
|
|
LogRecord.WriteLog(LogEnum.InBound, $"任务号:【{taskNum}】,托盘号:【{rfidValue}】上报WMS更新任务状态成功【TaskState_Weighing】");
|
}
|
else
|
{
|
Console.WriteLine($"{DateTime.Now}=>Failed=> 上报WMS更新任务状态出错【TaskState_Weighing】,任务号:【{wcsInfo.wcstask_taskNumber}】,原因:{content.Message}");
|
|
LogRecord.WriteLog(LogEnum.InBound, $"::Error::=> 任务号:【{taskNum}】,托盘号:【{rfidValue}】上报WMS更新任务状态失败【TaskState_Weighing】,原因:{content.Message}");
|
}
|
}
|
else if (weighting == 2)
|
{
|
OperateResult<UInt32> weightResult = (OperateResult<UInt32>)client.ReadValue(CLineInfoDBName.R_Line_Weight.ToString(), station.sm_stationNo);
|
if (weightResult.IsSuccess)
|
{
|
UInt32 weightValue = weightResult.Content;
|
|
LogRecord.WriteLog(LogEnum.InBound, $" 任务号:【{taskNum}】,托盘号:【{rfidValue}】读取到称重值:【{weightValue}】");
|
|
//向WMS上报读取到的重量值和对应的RFID值
|
WebResponseContent content = WMSApi.TellWmsWeightResult(rfidValue.ToString(), weightValue.ToString());
|
if (content.Status)
|
{
|
Console.WriteLine($"{DateTime.Now}=>上报WMS称重结果完成,托盘号:【{rfidValue}】,重量值:【{weightValue}】");
|
LogRecord.WriteLog(LogEnum.InBound, $" 任务号:【{taskNum}】,托盘号:【{rfidValue}】上报WMS称重值:【{weightValue}】成功");
|
//上报重量结果后,在此通知线体继续任务,该为了人工手动
|
bool goonTask = client.WriteValue(CLineInfoDBName.W_Line_Weight_OK.ToString(), true);
|
if (goonTask)
|
{
|
LogRecord.WriteLog(LogEnum.InBound, $" 任务号:【{taskNum}】,托盘号:【{rfidValue}】上报WMS称重值后,发送继续任务指令给线体");
|
Console.WriteLine($"{DateTime.Now}=>Success=> 称重完成后继续任务,任务号:【{wcsInfo.wcstask_taskNumber}】");
|
//称重完成后,在此更新任务状态、上报WMS任务状态
|
content = WMSApi.PostTaskStateToWMS(rfidValue.ToString(), TaskState.TaskState_ConveyorLineExecuting.ToString());
|
if (content.Status)
|
{
|
wcsInfo.wcstask_state = TaskState.TaskState_ConveyorLineExecuting.ToString();
|
wcsInfo.wcstask_dispatcherTime = DateTime.Now;
|
taskWCSinfoRepository.Update(wcsInfo, true);
|
Console.WriteLine($"{DateTime.Now}=>Success=> 上报WMS更新任务状态成功【TaskState_ConveyorLineExecuting】,任务号:【{wcsInfo.wcstask_taskNumber}】");
|
|
LogRecord.WriteLog(LogEnum.InBound, $"任务号:【{taskNum}】,托盘号:【{rfidValue}】上报WMS更新任务状态成功【TaskState_ConveyorLineExecuting】,称重后上报");
|
}
|
else
|
{
|
Console.WriteLine($"{DateTime.Now}=>Failed=> 上报WMS更新任务状态出错【TaskState_ConveyorLineExecuting】,任务号:【{wcsInfo.wcstask_taskNumber}】,原因:{content.Message}");
|
|
LogRecord.WriteLog(LogEnum.InBound, $"::Error::=> 任务号:【{taskNum}】,托盘号:【{rfidValue}】上报WMS更新任务状态失败【TaskState_ConveyorLineExecuting】,称重后上报,原因:{content.Message}");
|
}
|
}
|
else
|
{
|
Console.WriteLine($"{DateTime.Now}=>Failed=> 称重完成后写如继续任务失败,任务号:【{wcsInfo.wcstask_taskNumber}】");
|
}
|
}
|
else
|
{
|
Console.WriteLine($"::Error::=> 上报WMS称重结果失败,托盘号:【{rfidValue}】,重量值:【{weightValue}】");
|
|
LogRecord.WriteLog(LogEnum.InBound, $"::Error::=> 任务号:【{taskNum}】,托盘号:【{rfidValue}】上报WMS称重结果失败,原因:{content.Message}");
|
}
|
}
|
else
|
{
|
LogRecord.WriteLog(LogEnum.InBound, $"::Error::=> 任务号:【{taskNum}】,托盘号:【{rfidValue}】读取重量值失败");
|
}
|
}
|
|
}
|
else
|
{
|
//Console.WriteLine("当前没有需要进行的称重任务");
|
}
|
}
|
}
|
}
|
}
|