using Admin.NET.Application;
|
using iWareCC.Common.Helper;
|
using iWareCC.StationService;
|
using iWareCommon.Common.Globle;
|
using iWareCommon.Utils;
|
using iWareModel;
|
using iWareSql.DataAccess;
|
using iWareSql.DBModel;
|
using iWareSql.WmsDBModel;
|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.ServiceModel.Configuration;
|
using System.Text;
|
using System.Threading;
|
using System.Threading.Tasks;
|
using WZ.Useful.Commons;
|
using XiGang.Core.Model;
|
|
namespace iWareCC.ThreadService
|
{
|
/// <summary>
|
/// 机器人缓存岛入库任务完成处理
|
/// </summary>
|
public static class DataProcess_RobotBuffer_FinishTask
|
{
|
public static async void Handler()
|
{
|
var alertMsg = "";
|
LogType logType = LogType.DataProcess_RobotBuffer_FinishTask;
|
while (true)
|
{
|
Thread.Sleep(500);//休眠2秒,将休眠写到前面,是为了下面的continue方法执行后不显示错误信息的提示!!!【EditBy shaocx,2022-05-24】
|
SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTask = string.Empty;
|
try
|
{
|
if ( SystemValue.isStartedModel)//SystemValue.isAllowRuning_DataProcess_RobotBuffer_FinishTask &&
|
{
|
var rgvLocation = StationLocationEnum.BZ39.ToString();
|
var obj = FormCC.stationView.R_StationForReadCommList.Where(x => x.StationCode == rgvLocation.ToString()).FirstOrDefault();
|
if (obj.R_InboundFinish)
|
//if (true)//模拟
|
{
|
//var result = obj.R_InboundNumber;
|
//if (string.IsNullOrEmpty(result))
|
//{
|
// SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTask = $"{rgvLocation.ToString()}- 入库库位号是空的,此次循环结束";
|
// continue;
|
//}
|
//obj.R_Inbound_TaskID = 17797;//模拟
|
var result2 = obj.R_Inbound_TaskID;
|
if (result2 == 0)
|
{
|
SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTask = $"{rgvLocation.ToString()}- 入库任务号是空的,此次循环结束";
|
continue;
|
}
|
|
|
var qitaoReault = false;
|
using (WmsDBModel wmsDB = new WmsDBModel())
|
{
|
var task = wmsDB.wms_rbline_task.Where(x =>
|
x.TaskNo == obj.R_Inbound_TaskID.ToString()
|
&& x.RbTaskType == (int)RbTaskTypeEnum.入库任务
|
).OrderByDescending(x=>x.Id).FirstOrDefault();
|
if (task == null)
|
{
|
SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTask = $"{rgvLocation.ToString()},根据 R_InboundNumber:{obj.R_InboundNumber}没有找到已下发的任务 ";
|
continue;
|
}
|
else
|
{
|
if (task.TaskStatus == (int)TaskStatusEnum.已完成)
|
{
|
using (StationServiceClient client = new StationServiceClient())
|
{
|
var res = await client.InboundFinishConfirmAsync((int)EDevice.Station, true, rgvLocation);
|
|
}
|
continue;
|
}
|
}
|
|
var upiCode = task.UPI;
|
var upiObj = wmsDB.mes_batchOrderUPI_new.Where(x => x.UPI == upiCode).FirstOrDefault();
|
if (upiObj == null)
|
{
|
SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTask = $"{rgvLocation.ToString()},根据UPI:{upiCode}没有找到对象 ";
|
continue;
|
}
|
//增加库存
|
wms_stock_quan qun = new wms_stock_quan()
|
{
|
Id = Yitter.IdGenerator.YitIdHelper.NextId(),
|
Upi = upiCode,
|
PlanNo = task.PlanNo,
|
DetailName = upiObj.DetailName,
|
OrderId = task.OrderId,
|
CreateTime = DateTime.Now,
|
CreateUserName = "CC",
|
InTime = DateTime.Now,
|
OperReason = "入库",
|
PackageCode = task.PackageCode,
|
Length = task.Length,
|
Width = task.Width,
|
Thk = task.Thk,
|
PlaceCode = task.PlaceCode,
|
StockStatus = (int)StockStatusEnum.在库,
|
StockStatusName = StockStatusEnum.在库.ToString(),
|
|
};
|
wmsDB.wms_stock_quan.Add(qun);
|
|
task.TaskStatus = (int)TaskStatusEnum.已完成;
|
task.TaskStatusName = TaskStatusEnum.已完成.ToString();
|
task.FinishedTime = DateTime.Now;
|
|
|
var place = StationHandler.GetPlaceByPlaceCode(task.PlaceCode, wmsDB);
|
place.PlaceStatus = (int)PlaceStatusEnum.正常;
|
|
//给PLC推送任务完成确认信号
|
using (StationServiceClient client = new StationServiceClient())
|
{
|
var res = await client.InboundFinishConfirmAsync((int)EDevice.Station, true, rgvLocation);
|
if (!res.result)
|
{
|
SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTask = $"{rgvLocation.ToString()}-下发入库任务 失败,InboundFinishConfirmAsync 返回:{res.resMsg}";
|
continue;
|
}
|
else
|
{
|
Log4NetHelper.WriteInfoLog(logType, $"{rgvLocation.ToString()}-下发入库任务 成功,InboundFinishConfirmAsync,参数: 站点{rgvLocation}");
|
}
|
}
|
|
WmsRecordUpiProcessHandler.SaveWmsRecordUpiProcess(wmsDB, upiObj, task.PlaceCode, "缓存入库完成:"+ task.PlaceCode);
|
|
wmsDB.SaveChanges();
|
}
|
}
|
else
|
{
|
//不再拦截
|
|
//首先先清理
|
using (StationServiceClient client = new StationServiceClient())
|
{
|
var res = await client.InboundFinishConfirmAsync((int)EDevice.Station, false, rgvLocation);
|
|
}
|
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_FinishTask += " 出现异常:" + ex.Message + SysGloble.SPLIT_STR;
|
Log4NetHelper.WriteErrorLog(logType, " 出现异常:" + ex.Message, ex);
|
}
|
}
|
}
|
|
}
|
}
|