using Admin.NET.Application;
using iWareCommon.Common.Globle;
using iWareCommon.Utils;
using iWareModel;
using iWareSql.DataAccess;
using iWareSql.WmsDBModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace iWareCC.ThreadService
{
///
/// 机器人缓存岛 人工强制出库 处理
///
public static class CC_DataProcess_RobotBuffer_ForceOutbound
{
public static bool Handler(string packageCode, ref string alertMsg)
{
alertMsg = "";
LogType logType = LogType.DataProcess_RobotBuffer_AutoQiTaoOutbound;
try
{
var rgvLocation = StationLocationEnum.BZ39.ToString();
var obj = FormCC.stationView.R_StationForReadCommList.Where(x => x.StationCode == rgvLocation.ToString()).FirstOrDefault();
if (obj.R_ForceOutboundMode == false)
{
alertMsg = "PLC不是强制出库模式";
return false;
}
using (WmsDBModel wmsDB = new WmsDBModel())
{
List qunList = wmsDB.wms_stock_quan.Where(x => x.StockStatus == (int)StockStatusEnum.在库
&& x.PackageCode == packageCode
).ToList();
foreach (var x in qunList)
{
x.StockStatus = (int)StockStatusEnum.人工强制待出库;
//生成出库任务
//记录任务
var _id = Yitter.IdGenerator.YitIdHelper.NextId();
var plcTaskNo = BusinessHelper.CreatePlcTaskIdForSrmTask();
var new_task = new wms_rbline_task()
{
Id = _id,
TaskNo = plcTaskNo,
Upi = x.Upi,
Length = x.Length,
Width = x.Width,
Thk = x.Thk,
PlanNo = x.PlanNo,
OrderId = x.OrderId,
PackageCode = x.PackageCode,
PlaceCode = x.PlaceCode,
RbTaskType = (int)RbTaskTypeEnum.强制出库任务,
TaskStatus = (int)TaskStatusEnum.新建,
TaskMsg = "人工强制待出库",
CreateTime = DateTime.Now,
CreateUserName = SysGloble.WCSSystem,
UpdateTime = DateTime.Now,
UpdateUserName = SysGloble.WCSSystem,
};
wmsDB.wms_rbline_task.Add(new_task);
var place = StationHandler.GetPlaceByPlaceCode(x.PlaceCode, wmsDB);
place.PlaceStatus = (int)PlaceStatusEnum.锁定;
Thread.Sleep(100);
}
wmsDB.SaveChanges();
}
return true;
}
catch (Exception ex)
{
alertMsg = " 出现异常:" + ex.Message;
SystemWarningMsg._lbl_Alert_DataProcess_RobotBuffer_AutoQiTaoOutbound += " 出现异常:" + ex.Message + SysGloble.SPLIT_STR;
Log4NetHelper.WriteErrorLog(logType, " 出现异常:" + ex.Message, ex);
return false;
}
}
}
}