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._04_BZ21_搬运整垛机器人_
|
{
|
public class DataProcess_BZ21
|
{
|
public static void Hander()
|
{
|
var alertMsg = "";
|
LogType logType = LogType.DataProcess_BZ21;
|
while (true)
|
{
|
Thread.Sleep(2000);//休眠2秒,将休眠写到前面,是为了下面的continue方法执行后不显示错误信息的提示!!!【EditBy shaocx,2022-05-24】
|
SystemWarningMsg._lbl_alert_DataProcess_BZ21 = string.Empty;
|
try
|
{
|
if (SystemValue.isStartedModel)
|
{
|
var rgvLocation = StationLocationEnum.BZ21.ToString();
|
/*
|
* 1、从数据库中判断是否齐套
|
* 2、根据齐套结果,推送给PLC
|
*/
|
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_RobotBuffer_FinishTask = $"{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_BZ21 = $"{rgvLocation.ToString()}-请求了解码,但是结果是空的,此次循环结束";
|
continue;
|
}
|
var upiCode = result.Replace("/r", ""); ;
|
short cartonwidth = 0;//是否末板
|
short cartonhigh = 0;//是否旋转
|
short placeX = 0;
|
short placeY = 0;
|
short placeZ = 0;
|
string place = "";
|
using (WmsDBModel wmsDB = new WmsDBModel())
|
{
|
//要是有已下发的任务,就不要执行
|
var isValidate = TaskHandler.ValidateIssueTaskForBZ21(wmsDB,result);
|
if (!isValidate)
|
{
|
SystemWarningMsg._lbl_alert_DataProcess_BZ21 = $"{rgvLocation.ToString()}-有‘已下发’的任务,不能处理,此次循环结束";
|
continue;
|
}
|
var upiObj = wmsDB.mes_batchOrderUPI_new.Where(x => x.UPI == upiCode).FirstOrDefault();
|
if (upiObj == null)
|
{
|
SystemWarningMsg._lbl_alert_DataProcess_BZ21 = $"{rgvLocation.ToString()},根据UPI:{upiCode}没有找到对象 ";
|
continue;
|
}
|
placeX = (short)upiObj.MachineXCenter;
|
placeY = (short)upiObj.MachineYCenter;
|
placeZ = (short)upiObj.MachineZCenter;
|
cartonhigh = (short)upiObj.Info1;
|
cartonwidth = (short)upiObj.Info2;
|
|
//记录任务
|
var _id = Yitter.IdGenerator.YitIdHelper.NextId();
|
var plcTaskNo = BusinessHelper.CreatePlcTaskIdForSrmTask();
|
var putpakegecode = new mes_push_packagecode()
|
{
|
Id = _id,
|
PackageCode=upiObj.PackageCode,
|
PushStatus=0,
|
PushNum=0,
|
CreateTime = DateTime.Now,
|
CreateUserName = "CC",
|
UpdateTime = DateTime.Now,
|
UpdateUserName = "CC",
|
};
|
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);
|
wmsDB.mes_push_packagecode.Add(putpakegecode);
|
using (StationServiceClient client = new StationServiceClient())
|
{
|
|
var res = client.WriteSurroundTaskInfo((int)EDevice.Station, rgvLocation, Convert.ToInt32(task.TaskNo),
|
(short)upiObj.Info1, (short)upiObj.Info2,cartonhigh,cartonwidth,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);
|
}
|
}
|
}
|
public static void PushPackageCode()
|
{
|
while (true)
|
{
|
Thread.Sleep(2000);
|
using (WmsDBModel edm = new WmsDBModel())
|
{
|
var value = edm.mes_push_packagecode.Where(x => x.PushStatus == 0 || x.PushStatus == 1).FirstOrDefault();
|
if (value != null)
|
{
|
PushPackageCodeInput input = new PushPackageCodeInput();
|
input.PackageCode = value.PackageCode;
|
var res = HttpHelper.GetHttpResponse<PushPackageCodeInput, Respone>(" ", input, 10000);
|
|
}
|
}
|
}
|
}
|
public class PushPackageCodeInput
|
{
|
public string PackageCode { get; set; }
|
}
|
public class Respone
|
{
|
/// <summary>
|
/// 返回码
|
/// </summary>
|
public string code { get; set; }
|
|
/// <summary>
|
/// 返回消息
|
/// </summary>
|
public string message { get; set; }
|
|
/// <summary>
|
/// 请求编号
|
/// </summary>
|
public string reqCode { get; set; }
|
|
/// <summary>
|
/// 自定义返回(返回任务单号)
|
/// </summary>
|
public string data { get; set; }
|
}
|
}
|
}
|