using Admin.NET.Application;
|
using iWareCC.StationService;
|
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.Text;
|
using System.Threading;
|
using System.Threading.Tasks;
|
|
namespace iWareCC.ThreadService._03_BZ12_机器人码包工位_
|
{
|
public class DataProcess_BZ12
|
{
|
public static void Hander()
|
{
|
var alertMsg = "";
|
LogType logType = LogType.DataProcess_BZ12;
|
while (true)
|
{
|
Thread.Sleep(2000);//休眠2秒,将休眠写到前面,是为了下面的continue方法执行后不显示错误信息的提示!!!【EditBy shaocx,2022-05-24】
|
SystemWarningMsg._lbl_alert_DataProcess_BZ12 = string.Empty;
|
try
|
{
|
if ( SystemValue.isStartedModel)
|
{
|
var rgvLocation = StationLocationEnum.BZ12.ToString();
|
/*
|
* 1、从数据库中判断是否齐套
|
* 2、根据齐套结果,推送给PLC
|
*/
|
var obj = FormCC.stationView.R_StationForReadCommList.Where(x => x.StationCode == rgvLocation.ToString()).FirstOrDefault();
|
if (obj.R_ReqParseData)
|
{
|
var result = obj.R_ReadCodeResult;
|
if (string.IsNullOrEmpty(result))
|
{
|
SystemWarningMsg._lbl_alert_DataProcess_BZ39 = $"{rgvLocation.ToString()}-请求了解码,但是结果是空的,此次循环结束";
|
continue;
|
}
|
var upiCode = result;
|
bool islast = false;//是否末板
|
short isrotate = 0;//是否旋转
|
short placeX = 0;
|
short placeY = 0;
|
string place = "";
|
using (WmsDBModel wmsDB = new WmsDBModel())
|
{
|
//要是有已下发的任务,就不要执行
|
var isValidate = TaskHandler.ValidateIssueTaskForBZ12(wmsDB);
|
if (!isValidate)
|
{
|
SystemWarningMsg._lbl_alert_DataProcess_BZ12 = $"{rgvLocation.ToString()}-有‘已下发’的任务,不能处理,此次循环结束";
|
continue;
|
}
|
var upiObj = wmsDB.mes_batchOrderUPI_new.Where(x => x.UPI == upiCode).FirstOrDefault();
|
if (upiObj == null)
|
{
|
SystemWarningMsg._lbl_alert_DataProcess_BZ12 = $"{rgvLocation.ToString()},根据UPI:{upiCode}没有找到对象 ";
|
continue;
|
}
|
isrotate = 1;
|
placeX = (short)upiObj.MachineXCenter;
|
placeY = (short)upiObj.MachineYCenter;
|
//查处这包所有的数量
|
var upiList = wmsDB.mes_batchOrderUPI_new.Where(x => x.PackageCode == upiObj.PackageCode).ToList();
|
//查询是否末板并且判断有没有混批
|
var wms_rbline_runmode = wmsDB.wms_rbline_runmode.FirstOrDefault();
|
if (wms_rbline_runmode != null)
|
{
|
//查询是否混批
|
if (!string.IsNullOrEmpty(wms_rbline_runmode.PalletizingUPI))
|
{
|
if (upiObj.PackageCode != wms_rbline_runmode.PalletizingUPI)
|
{
|
SystemWarningMsg._lbl_alert_DataProcess_BZ12 = $"{rgvLocation.ToString()},UPI:{upiCode}码包部件混批 ";
|
continue;
|
}
|
}
|
//获取码垛目标位
|
if (wms_rbline_runmode.PalletizingStation != 0)
|
{
|
place = wms_rbline_runmode.PalletizingStation.ToString();
|
}
|
else
|
{
|
wms_rbline_runmode.PalletizingUPI=upiObj.PackageCode
|
if (obj.R_PalletizingStation1 == 1)
|
{
|
place = "1";
|
}
|
else if (obj.R_PalletizingStation2 == 1)
|
{
|
place = "2";
|
|
}
|
else
|
{
|
SystemWarningMsg._lbl_alert_DataProcess_BZ12 = $"{rgvLocation.ToString()},UPI:{upiCode}无可用码垛目标位 ";
|
continue;
|
}
|
}
|
//如果次序等于当钱包总数量,是否末板置为true
|
if (upiObj.Shelf == upiList.Count())
|
{
|
islast = true;
|
wms_rbline_runmode.PalletizingUPI = null;
|
wms_rbline_runmode.PalletizingStation = 0;
|
}
|
|
}
|
//查询有没有次序小于当前次序并且没有码垛的
|
var oldupi = upiList.Where(x => x.Shelf < upiObj.Shelf && x.UpiStatus != (int)UpiStatusEnum.已码垛).FirstOrDefault();
|
if (oldupi != null)
|
{
|
SystemWarningMsg._lbl_alert_DataProcess_BZ12 = $"{rgvLocation.ToString()},UPI:{upiCode}码包顺序错误 ";
|
continue;
|
}
|
|
//记录任务
|
var _id = Yitter.IdGenerator.YitIdHelper.NextId();
|
var plcTaskNo = BusinessHelper.CreatePlcTaskIdForSrmTask();
|
var task = new wms_rbline_task()
|
{
|
Id = _id,
|
TaskNo = plcTaskNo,
|
UPI = upiObj.UPI,
|
Length = upiObj.Length,
|
Width = upiObj.Width,
|
Thk = upiObj.Thk,
|
IssueTime = DateTime.Now,
|
PlanNo = upiObj.PlanNo,
|
OrderId = upiObj.OrderId,
|
PackageCode = upiObj.PackageCode,
|
RbTaskType = (int)RbTaskTypeEnum.码板任务,
|
RbTaskTypeEnumName = RbTaskTypeEnum.码板任务.ToString(),
|
TaskStatus = (int)TaskStatusEnum.已下发,
|
TaskStatusName = TaskStatusEnum.已下发.ToString(),
|
TaskMsg = "码板",
|
CreateTime = DateTime.Now,
|
CreateUserName = "CC",
|
UpdateTime = DateTime.Now,
|
UpdateUserName = "CC",
|
PlaceCode=place
|
};
|
|
wmsDB.wms_rbline_task.Add(task);
|
|
using (StationServiceClient client = new StationServiceClient())
|
{
|
|
var res = client.WritePalletizingTaskInfo((int)EDevice.Station, rgvLocation, Convert.ToInt32(task.TaskNo), islast,
|
(short)upiObj.Length, (short)upiObj.Width, (short)upiObj.Thk, isrotate, short.Parse(task.PlaceCode), placeX, placeY);
|
if (!res.result)
|
{
|
SystemWarningMsg._lbl_alert_DataProcess_BZ12 = $"{rgvLocation.ToString()}-下发入库任务 失败,WriteInStoreTaskInfoAsync 返回:{res.resMsg}";
|
continue;
|
}
|
else
|
{
|
Log4NetHelper.WriteInfoLog(logType, $"{rgvLocation.ToString()}-下发入库任务 成功,WriteInStoreTaskInfoAsync,参数: 站点{rgvLocation}");
|
}
|
}
|
|
wmsDB.SaveChanges();
|
}
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
SystemWarningMsg._lbl_alert_DataProcess_BZ39 += " 出现异常:" + ex.Message + SysGloble.SPLIT_STR;
|
Log4NetHelper.WriteErrorLog(logType, " 出现异常:" + ex.Message, ex);
|
}
|
}
|
}
|
}
|
}
|