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.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 async 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
|
*/
|
if (FormCC.stationView == null)
|
{
|
SystemWarningMsg._lbl_alert_DataProcess_BZ12 = $"{rgvLocation.ToString()}-获取PLC对象为null";
|
continue;
|
}
|
var obj = FormCC.stationView.R_StationForReadCommList.Where(x => x.StationCode == rgvLocation.ToString()).FirstOrDefault();
|
if (obj.R_PalletizingAck)
|
{
|
//给PLC推送任务完接收完成复位信号
|
using (StationServiceClient client = new StationServiceClient())
|
{
|
var res = client.WriteStation_ACK((int)EDevice.Station, false, rgvLocation);
|
if (!res.result)
|
{
|
SystemWarningMsg._lbl_alert_DataProcess_BZ12 = $"{rgvLocation.ToString()}-下发码板任务 失败,SetPalletizingTaskFinishAck 返回:{res.resMsg}";
|
continue;
|
}
|
else
|
{
|
Log4NetHelper.WriteInfoLog(logType, $"{rgvLocation.ToString()}-下发入库任务 成功,SetPalletizingTaskFinishAck,参数: 站点{rgvLocation}");
|
}
|
}
|
|
|
}
|
if (obj.R_ReqParseData)
|
{
|
var result = obj.R_ReadCodeResult;
|
if (string.IsNullOrEmpty(result))
|
{
|
SystemWarningMsg._lbl_alert_DataProcess_BZ39 = $"{rgvLocation.ToString()}-请求了解码,但是结果是空的,此次循环结束";
|
continue;
|
}
|
var upiCode = result.Replace("/r", ""); ;
|
short lastnum = 0;//是否末板
|
//short isrotate = 0;//是否旋转
|
//short placeX = 0;
|
//short placeY = 0;
|
//short placeZ = 0;
|
string place = "";
|
using (WmsDBModel wmsDB = new WmsDBModel())
|
{
|
//要是有已下发的任务,就不要执行
|
var isValidate = TaskHandler.ValidateIssueTaskForNoFinishTaskByUpi(wmsDB, result);
|
if (!isValidate)
|
{
|
SystemWarningMsg._lbl_alert_DataProcess_BZ12 = $"{rgvLocation.ToString()}-upi:{result}有‘已下发’的任务,不能处理,此次循环结束";
|
continue;
|
}
|
|
isValidate = TaskHandler.ValidateNoFinishOutTaskFor码板任务(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)
|
{
|
//写入报警信息
|
await MyExtendHelper.WriteBoolPlcDataForWarning(PlcWarningAddressGloble.Num_BZ12_1);
|
|
SystemWarningMsg._lbl_alert_DataProcess_BZ12 = $"{rgvLocation.ToString()},根据UPI:{upiCode}没有找到对象 ";
|
continue;
|
}
|
//isrotate = short.Parse(upiObj.Info17);
|
//placeX = (short)upiObj.MachineXCenter;
|
//placeY = (short)upiObj.MachineYCenter;
|
//placeZ = (short)upiObj.MachineZCenter;
|
if (upiObj.UpiStatus == (int)UpiStatusEnum.已码垛 || upiObj.UpiStatus == (int)UpiStatusEnum.码垛中)
|
{
|
//写入报警信息
|
await MyExtendHelper.WriteBoolPlcDataForWarning(PlcWarningAddressGloble.Num_BZ12_3);
|
|
SystemWarningMsg._lbl_alert_DataProcess_BZ12 = $"{rgvLocation.ToString()},根据UPI:{upiCode}状态已是'已码垛'或'码垛中' ";
|
continue;
|
}
|
upiObj.UpiStatus = (int)UpiStatusEnum.码垛中;
|
upiObj.AreaCode = (int)AreaCodeEnum.码垛区域;
|
//查处这包所有的数量
|
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)
|
{
|
//写入报警信息
|
await MyExtendHelper.WriteBoolPlcDataForWarning(PlcWarningAddressGloble.Num_BZ12_4);
|
|
SystemWarningMsg._lbl_alert_DataProcess_BZ12 = $"{rgvLocation.ToString()},UPI:{upiCode}码包部件混批 ";
|
continue;
|
}
|
}
|
//获取码垛目标位
|
if (wms_rbline_runmode.PalletizingStation != 0)
|
{
|
place = wms_rbline_runmode.PalletizingStation.ToString();
|
}
|
else
|
{//表示这是 包的第一块板
|
lastnum = 1;
|
wms_rbline_runmode.PalletizingUPI = upiObj.PackageCode;
|
if (obj.R_PalletizingStation1 == 1)
|
{
|
place = "1";
|
}
|
else if (obj.R_PalletizingStation2 == 1)
|
{
|
place = "2";
|
|
}
|
else
|
{
|
//写入报警信息
|
await MyExtendHelper.WriteBoolPlcDataForWarning(PlcWarningAddressGloble.Num_BZ12_6);
|
|
SystemWarningMsg._lbl_alert_DataProcess_BZ12 = $"{rgvLocation.ToString()},UPI:{upiCode}无可用码垛目标位 ";
|
continue;
|
}
|
|
wms_rbline_runmode.PalletizingStation = int.Parse(place);
|
}
|
//如果次序等于当钱包总数量,是否末板置为true
|
if (upiObj.Shelf == upiList.Count())
|
{
|
lastnum = 2;
|
wms_rbline_runmode.PalletizingUPI = null;
|
wms_rbline_runmode.PalletizingStation = 0;
|
}
|
|
}
|
else
|
{
|
SystemWarningMsg._lbl_alert_DataProcess_BZ12 = $"{rgvLocation.ToString()},表wms_rbline_runmode无数据 ";
|
continue;
|
}
|
//查询有没有次序小于当前次序并且没有码垛的
|
var oldupi = upiList.Where(x => x.Shelf < upiObj.Shelf && (x.UpiStatus != (int)UpiStatusEnum.已码垛 && x.UpiStatus != (int)UpiStatusEnum.码垛中)).FirstOrDefault();
|
if (oldupi != null)
|
{
|
//写入报警信息
|
await MyExtendHelper.WriteBoolPlcDataForWarning(PlcWarningAddressGloble.Num_BZ12_5);
|
|
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,
|
|
PlanNo = upiObj.PlanNo,
|
OrderId = upiObj.OrderId,
|
PackageCode = upiObj.PackageCode,
|
RbTaskType = (int)RbTaskTypeEnum.码板任务,
|
TaskStatus = (int)TaskStatusEnum.新建,
|
TaskMsg = "码板",
|
CreateTime = DateTime.Now,
|
CreateUserName = "CC",
|
UpdateTime = DateTime.Now,
|
UpdateUserName = "CC",
|
PlaceCode = place,
|
LastNum = lastnum,
|
|
Info17 = upiObj.Info17,
|
MachineXCenter = upiObj.MachineXCenter,
|
MachineYCenter = upiObj.MachineYCenter,
|
MachineZCenter = upiObj.MachineZCenter,
|
Sequence = upiObj.Sequence,
|
};
|
|
wmsDB.wms_rbline_task.Add(task);
|
|
|
|
|
WmsRecordUpiProcessHandler.SaveWmsRecordUpiProcess(wmsDB, upiObj, "BZ12站点", "码包");
|
|
wmsDB.SaveChanges();
|
}
|
}
|
else
|
{
|
SystemWarningMsg._lbl_alert_DataProcess_BZ12 = $"{rgvLocation.ToString()}-没有要处理的数据";
|
}
|
}
|
}
|
catch (Exception ex)
|
{
|
SystemWarningMsg._lbl_alert_DataProcess_BZ12 += " 出现异常:" + ex.Message + SysGloble.SPLIT_STR;
|
Log4NetHelper.WriteErrorLog(logType, " 出现异常:" + ex.Message, ex);
|
}
|
}
|
}
|
}
|
}
|