You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

669 lines
34 KiB
C#

using AUCMA.STORE.Business.Implements;
using AUCMA.STORE.Business.Interface;
using AUCMA.STORE.Common;
using AUCMA.STORE.Entity.DAO;
using AUCMA.STORE.Entity.DTO;
using AUCMA.STORE.Entity.Enums;
using AUCMA.STORE.SqlSugar;
using AUCMA.STORE.SqlSugar.serviceImpl;
using AutoMapper;
using HslCommunication.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
#region << 版 本 注 释 >>
/*--------------------------------------------------------------------
* (c) 2024 WenJY
* CLR4.0.30319.42000
* T14-GEN3-7895
* AUCMA.STORE.Business
* ff279f65-fbfa-4688-8560-d0bf2051cd85
*
* WenJY
*
* 2024-12-22 14:41:08
* V1.0.0
*
*
*--------------------------------------------------------------------
*
*
*
*
* V1.0.0
*--------------------------------------------------------------------*/
#endregion << 版 本 注 释 >>
namespace AUCMA.STORE.Business
{
public class TaskHandleBusiness
{
private List<BaseDeviceInfo> m_DeviceInfoList = new List<BaseDeviceInfo>();
private PLCAddressTypeDTO[] ReadOnePilerPlcAddress = new PLCAddressTypeDTO[20];
private PLCAddressTypeDTO[] ReadRGVPlcAddress = new PLCAddressTypeDTO[8];
private PLCAddressTypeDTO[] WriteRGVPlcAddress = new PLCAddressTypeDTO[7];
private IBaseTaskQueueBusiness baseTaskQueueBusiness = new BaseTaskQueueBusiness();
private OutStoreBusinessImpl outStoreBusiness = new OutStoreBusinessImpl();
private IByteTransform byteTransform = new RegularByteTransform();
public delegate void TaskInfoInvoke(int TaskNo, TaskType taskType, LocationArea locationArea, string locationCode);
public event TaskInfoInvoke TaskInfoRefreshEvent;
private static TaskHandleBusiness _singleton;
private static readonly object _object = new object();
private TaskHandleBusiness()
{
}
public static TaskHandleBusiness GetInstance()
{
if (_singleton == null)
{
lock (_object)
{
if (_singleton == null)
{
_singleton = new TaskHandleBusiness();
}
}
}
return _singleton;
}
/// <summary>
/// 初始化
/// </summary>
/// <param name="deviceInfos"></param>
/// <param name="_ReadOnePilerPlcAddress"></param>
/// <param name="_ReadRGVPlcAddress"></param>
/// <param name="_WriteRGVPlcAddress"></param>
public void Init(List<BaseDeviceInfo> deviceInfos, PLCAddressTypeDTO[] _ReadOnePilerPlcAddress,
PLCAddressTypeDTO[] _ReadRGVPlcAddress, PLCAddressTypeDTO[] _WriteRGVPlcAddress)
{
m_DeviceInfoList = deviceInfos;
ReadOnePilerPlcAddress = _ReadOnePilerPlcAddress;
ReadRGVPlcAddress = _ReadRGVPlcAddress;
WriteRGVPlcAddress = _WriteRGVPlcAddress;
Task.Run(() =>
{
while (true)
{
LeftPilerTaskHandle();
Task.Delay(5000).Wait();
}
});
Task.Run(() =>
{
while (true)
{
RightPilerTaskHandle();
Task.Delay(5000).Wait();
}
});
}
/// <summary>
/// 左库出入库逻辑处理
/// </summary>
private void LeftPilerTaskHandle()
{
try
{
BaseDeviceInfo item = m_DeviceInfoList.Where(x => x.m_iDeviceId == 1002).FirstOrDefault();
BaseDeviceInfo rgvDeviceInfo = m_DeviceInfoList.Where(x => x.m_iDeviceId == 1001).FirstOrDefault();
int PilerState = item.m_IDeviceAdapter.ReadInt16ByAddress(ReadOnePilerPlcAddress[2].PLCAddress);
int iReadIsReadySignal = item.m_IDeviceAdapter.ReadInt16ByAddress(ReadOnePilerPlcAddress[8].PLCAddress);
if (PilerState == 0 && iReadIsReadySignal == 2)
{
LogHelper.LeftPilerlog($"左库==>{item.m_iDeviceId}堆垛机:{item.m_plcName};{ReadOnePilerPlcAddress[2].PLCAddress}:{PilerState};{ReadOnePilerPlcAddress[8].PLCAddress}:{iReadIsReadySignal};当前空闲并且准备就绪可以下发任务");
int iReadOutForkSignal = rgvDeviceInfo.m_IDeviceAdapter.ReadInt16ByAddress(ReadRGVPlcAddress[2].PLCAddress);
if (iReadOutForkSignal != 1)
{
LogHelper.LeftPilerlog($"左库==>出库口状态:{iReadOutForkSignal};出库皮带空闲可以出库");
//出库
byte[] outStoreBuffer = GetOutStoreTask(item.m_iDeviceId, out string outStoreTaskCode, out BaseTaskQueue baseTaskQueue,LocationArea.Location_Left);
if (outStoreBuffer != null)
{
SendBufferToLeftPiler(item, rgvDeviceInfo, outStoreBuffer, outStoreTaskCode, true);
UpdateLocationStatus("A", LocationArea.Location_Left, $"{baseTaskQueue.pilerClaimGoodsRows}-{baseTaskQueue.pilerClaimGoodsLine}-{baseTaskQueue.pilerClaimGoodsTier}", LocationStatus.UnUsed);
TaskInfoRefreshEvent?.Invoke(Convert.ToInt32(outStoreTaskCode), TaskType.OutStore, LocationArea.Location_Left, $"{baseTaskQueue.pilerClaimGoodsRows}-{baseTaskQueue.pilerClaimGoodsLine}-{baseTaskQueue.pilerClaimGoodsTier}");
return;
}
else
{
LogHelper.LeftPilerlog($"左库==>当前没有可执行的出库任务");
}
}
else
{
LogHelper.LeftPilerlog($"左库==>出库口状态:{iReadOutForkSignal};出库皮带占用不具备出库条件");
}
var inStoreBuffer = GetInStoreTaskInfo(item.m_iDeviceId, out string inStoreTaskCode,out BaseTaskQueue taskQueue);
if(inStoreBuffer != null)
{
LogHelper.LeftPilerlog($"左库==>存在入库任务,进行入库操作,任务号:{inStoreTaskCode}");
SendBufferToLeftPiler(item, rgvDeviceInfo, inStoreBuffer, inStoreTaskCode, false);
UpdateLocationStatus("A", LocationArea.Location_Left, $"{taskQueue.pilerUnloadRows}-{taskQueue.pilerUnloadLine}-{taskQueue.pilerUnloadTier}", LocationStatus.InUse);
TaskInfoRefreshEvent?.Invoke(Convert.ToInt32(inStoreTaskCode), TaskType.InStore, LocationArea.Location_Left, $"{taskQueue.pilerUnloadRows}-{taskQueue.pilerUnloadLine}-{taskQueue.pilerUnloadTier}");
}
}
else
{
LogHelper.LeftPilerlog($"左库==>{item.m_iDeviceId}堆垛机:{item.m_plcName};{ReadOnePilerPlcAddress[2].PLCAddress}:{PilerState};{ReadOnePilerPlcAddress[8].PLCAddress}:{iReadIsReadySignal};当前状态不满足无法下发任务");
}
}
catch (Exception ex)
{
LogHelper.LeftPilerlog($"左库出入库逻辑处理异常:{ex.Message}");
}
}
/// <summary>
/// 右库出入库逻辑处理
/// </summary>
private void RightPilerTaskHandle()
{
try
{
BaseDeviceInfo item = m_DeviceInfoList.Where(x => x.m_iDeviceId == 1003).FirstOrDefault();
BaseDeviceInfo rgvDeviceInfo = m_DeviceInfoList.Where(x => x.m_iDeviceId == 1001).FirstOrDefault();
int PilerState = item.m_IDeviceAdapter.ReadInt16ByAddress(ReadOnePilerPlcAddress[2].PLCAddress);
int iReadIsReadySignal = item.m_IDeviceAdapter.ReadInt16ByAddress(ReadOnePilerPlcAddress[8].PLCAddress);
if (PilerState == 0 && iReadIsReadySignal == 2)
{
LogHelper.RightPilerlog($"右库==>{item.m_iDeviceId}堆垛机:{item.m_plcName};{ReadOnePilerPlcAddress[2].PLCAddress}:{PilerState};{ReadOnePilerPlcAddress[8].PLCAddress}:{iReadIsReadySignal};当前空闲并且准备就绪可以下发任务");
int iReadOutForkSignal = rgvDeviceInfo.m_IDeviceAdapter.ReadInt16ByAddress(ReadRGVPlcAddress[3].PLCAddress);
if (iReadOutForkSignal != 1)
{
LogHelper.RightPilerlog($"右库==>出库口状态:{iReadOutForkSignal};出库皮带空闲可以出库");
byte[] outStoreBuffer = GetOutStoreTask(item.m_iDeviceId, out string outStoreTaskCode, out BaseTaskQueue baseTaskQueue, LocationArea.Location_Right);
if (outStoreBuffer != null)
{
SendBufferToRightPiler(item, rgvDeviceInfo, outStoreBuffer, outStoreTaskCode, true);
UpdateLocationStatus("A", LocationArea.Location_Right, $"{baseTaskQueue.pilerClaimGoodsRows}-{baseTaskQueue.pilerClaimGoodsLine}-{baseTaskQueue.pilerClaimGoodsTier}", LocationStatus.UnUsed);
TaskInfoRefreshEvent?.Invoke(Convert.ToInt32(outStoreTaskCode), TaskType.OutStore, LocationArea.Location_Right, $"{baseTaskQueue.pilerClaimGoodsRows}-{baseTaskQueue.pilerClaimGoodsLine}-{baseTaskQueue.pilerClaimGoodsTier}");
return;
}
else
{
LogHelper.RightPilerlog($"右库==>当前没有可执行的出库任务");
}
}
else
{
LogHelper.RightPilerlog($"右库==>出库口状态:{iReadOutForkSignal};出库皮带占用不具备出库条件");
}
var inStoreBuffer = GetInStoreTaskInfo(item.m_iDeviceId, out string inStoreTaskCode,out BaseTaskQueue taskQueue);
if(inStoreBuffer != null)
{
LogHelper.LeftPilerlog($"右库==>存在入库任务,进行入库操作,任务号:{inStoreTaskCode}");
SendBufferToRightPiler(item, rgvDeviceInfo, inStoreBuffer, inStoreTaskCode, false);
UpdateLocationStatus("A", LocationArea.Location_Right, $"{taskQueue.pilerUnloadRows}-{taskQueue.pilerUnloadLine}-{taskQueue.pilerUnloadTier}", LocationStatus.InUse);
TaskInfoRefreshEvent?.Invoke(Convert.ToInt32(inStoreTaskCode), TaskType.InStore, LocationArea.Location_Right, $"{taskQueue.pilerUnloadRows}-{taskQueue.pilerUnloadLine}-{taskQueue.pilerUnloadTier}");
}
}
else
{
LogHelper.RightPilerlog($"右库==>{item.m_iDeviceId}堆垛机:{item.m_plcName};{ReadOnePilerPlcAddress[2].PLCAddress}:{PilerState};{ReadOnePilerPlcAddress[8].PLCAddress}:{iReadIsReadySignal};当前状态不满足无法下发任务");
}
}
catch (Exception ex)
{
LogHelper.RightPilerlog($"右库出入库逻辑处理异常:{ex.Message}");
}
}
/// <summary>
/// 发送左库堆垛机任务
/// </summary>
/// <param name="item"></param>
/// <param name="rgvDeviceInfo"></param>
/// <param name="buffer"></param>
/// <param name="taskCode"></param>
/// <param name="isOut"></param>
private void SendBufferToLeftPiler(BaseDeviceInfo item, BaseDeviceInfo rgvDeviceInfo, byte[] buffer, string taskCode, bool isOut = true)
{
try
{
bool isSend = false;
do
{
if (item.m_IDeviceAdapter.WriteByteByAddress("DB11.0", buffer))
{
LogHelper.LeftPilerlog($"左库==>任务:{taskCode};写入PLC成功");
//读取堆垛机任务号
bool isSuc = true;
do
{
var pilerTaskCode = item.m_IDeviceAdapter.ReadInt32ByAddress(ReadOnePilerPlcAddress[0].PLCAddress).ToString();
LogHelper.LeftPilerlog($"左库==>堆垛机当前任务号:{pilerTaskCode};上位机下发任务号:{taskCode}");
if (pilerTaskCode == taskCode)
{
LogHelper.LeftPilerlog($"左库==>堆垛机当前任务号:{pilerTaskCode};与下发任务号:{taskCode};一致");
if (isOut)
{
bool isRgvSend = rgvDeviceInfo.m_IDeviceAdapter.WriteInt16ByAddress(WriteRGVPlcAddress[5].PLCAddress, "1");
if (isRgvSend)
{
LogHelper.LeftPilerlog($"左库==>RGV任务下发成功;{WriteRGVPlcAddress[5].PLCAddress}:1");
}
else
{
LogHelper.LeftPilerlog($"左库==>RGV任务下发失败;");
}
}
isSuc = false;
}
else
{
LogHelper.LeftPilerlog($"左库==>堆垛机当前任务号:{pilerTaskCode};与下发任务号:{taskCode};不一致");
Task.Delay(1000).Wait();
}
} while (isSuc);
isSend = true;
}
else
{
LogHelper.LeftPilerlog($"左库==>任务:{taskCode};写入PLC失败");
}
} while (!isSend);
}
catch (Exception ex)
{
LogHelper.LeftPilerlog($"左库==>任务下发至堆垛机逻辑处理异常:{ex.Message}");
}
}
/// <summary>
/// 发送右库堆垛机任务
/// </summary>
/// <param name="item"></param>
/// <param name="rgvDeviceInfo"></param>
/// <param name="buffer"></param>
/// <param name="taskCode"></param>
/// <param name="isOut"></param>
private void SendBufferToRightPiler(BaseDeviceInfo item,BaseDeviceInfo rgvDeviceInfo, byte[] buffer,string taskCode,bool isOut = true)
{
try
{
bool isSend = false;
do
{
if (item.m_IDeviceAdapter.WriteByteByAddress("DB11.0", buffer))
{
LogHelper.RightPilerlog($"右库==>任务:{taskCode};写入PLC成功");
//读取堆垛机任务号
bool isSuc = true;
do
{
var pilerTaskCode = item.m_IDeviceAdapter.ReadInt32ByAddress(ReadOnePilerPlcAddress[0].PLCAddress).ToString();
LogHelper.RightPilerlog($"右库==>堆垛机当前任务号:{pilerTaskCode};上位机下发任务号:{taskCode}");
if (pilerTaskCode == taskCode)
{
LogHelper.RightPilerlog($"右库==>堆垛机当前任务号:{pilerTaskCode};与下发任务号:{taskCode};一致");
if (isOut)
{
bool isRgvSend = rgvDeviceInfo.m_IDeviceAdapter.WriteInt16ByAddress(WriteRGVPlcAddress[5].PLCAddress, "2");
if (isRgvSend)
{
LogHelper.RightPilerlog($"右库==>RGV任务下发成功;{WriteRGVPlcAddress[5].PLCAddress}:2");
}
else
{
LogHelper.RightPilerlog($"右库==>RGV任务下发失败;");
}
}
isSuc = false;
}
else
{
LogHelper.RightPilerlog($"右库==>堆垛机当前任务号:{pilerTaskCode};与下发任务号:{taskCode};不一致");
Task.Delay(1000).Wait();
}
} while (isSuc);
isSend = true;
}
else
{
LogHelper.RightPilerlog($"右库==>任务:{taskCode};写入PLC失败");
}
} while (!isSend);
}catch(Exception ex)
{
LogHelper.RightPilerlog($"右库==>任务下发至堆垛机逻辑处理异常:{ex.Message}");
}
}
/// <summary>
/// 获取出库任务
/// </summary>
/// <param name="deviceId"></param>
/// <param name="taskCode"></param>
/// <returns></returns>
private byte[] GetOutStoreTask(int deviceId,out string taskCode,out BaseTaskQueue taskQueue,LocationArea locationArea)
{
lock (string.Empty)
{
taskCode = string.Empty;
taskQueue = null;
try
{
BaseTaskQueue baseTaskQueue = baseTaskQueueBusiness.GetTaskQueue(locationArea, TaskType.OutStore, OperationType.ManualOperation).Result;
if (baseTaskQueue == null)
{
baseTaskQueue = baseTaskQueueBusiness.GetTaskQueue(locationArea, TaskType.OutStore, OperationType.Automatic).Result;
}
if (baseTaskQueue == null)
{
LogHelper.Pilerlog($"当前不存在出库任务");
return null;
}
LogHelper.Pilerlog($"获取出库任务,获取到出库任务:{baseTaskQueue.pilerTaskCode};任务信息:{JsonChange.ModeToJson(baseTaskQueue)}");
//LocationArea locationArea = LocationArea.Location_Left;
//if (deviceId != 1)
//{
// locationArea = LocationArea.Location_Right;
//}
Expression<Func<BaseLocationInfo, bool>> exp = s1 => true;
if(baseTaskQueue.operationType == OperationType.Automatic)
{
exp = exp.And(s1 => s1.materialType == baseTaskQueue.materialCode
&& s1.locationStatus == LocationStatus.InUse
&& s1.deleteFlag == Entity.Enums.DeleteFlag.No
&& s1.locationArea == locationArea
&& s1.storeCode == ConfigHelper.GetConfig("storeCode"));
}
else
{
exp = exp.And(s1 => s1.locationArea == baseTaskQueue.locationArea
&& s1.storeCode == baseTaskQueue.storeCode
&& s1.locationLine == baseTaskQueue.pilerClaimGoodsLine
&& s1.locationRow == baseTaskQueue.pilerClaimGoodsRows
&& s1.locationTier == baseTaskQueue.pilerClaimGoodsTier);
}
List<BaseLocationInfo> locationInfos = new BaseServices<BaseLocationInfo>().Query(exp).Result;
var locationInfo = outStoreBusiness.FiltrateBestlocation(locationInfos);
if (locationInfo == null)
{
LogHelper.Pilerlog($"出库任务:{baseTaskQueue.pilerTaskCode}未匹配到库位");
return null;
}
_ = baseTaskQueueBusiness.DeleteTaskQueue(baseTaskQueue);
LogHelper.Pilerlog("移除出库任务队列信息:" + baseTaskQueue.pilerTaskCode);
TaskInfoRefreshEvent?.Invoke(Convert.ToInt32(baseTaskQueue.pilerTaskCode), TaskType.OutStore, locationArea, locationInfo.locationCode);
LogHelper.Pilerlog($"出库任务:{baseTaskQueue.pilerTaskCode}匹配的出库库位为:{JsonChange.ModeToJson(locationInfo)}");
Mapper.Initialize(cret => cret.CreateMap<BaseTaskQueue, TaskDTO>());
TaskDTO task = Mapper.Map<TaskDTO>(baseTaskQueue);
task.locationCode = locationInfo.locationCode;
task.row = locationInfo.locationRow;
task.line = locationInfo.locationLine;
task.tier = locationInfo.locationTier;
task.plcCode = deviceId;
task.pilerClaimGoodsRows = locationInfo.locationRow;
task.pilerClaimGoodsLine = locationInfo.locationLine;
task.pilerClaimGoodsTier = locationInfo.locationTier;
if (locationInfo.locationArea == LocationArea.Location_Left)
{
if (ConfigHelper.GetConfig("storeCode") == "A") task.pilerUnloadRows = 2;
if (ConfigHelper.GetConfig("storeCode") == "B") task.pilerUnloadRows = 1;
}
if (locationInfo.locationArea == LocationArea.Location_Right)
{
if (ConfigHelper.GetConfig("storeCode") == "A") task.pilerUnloadRows = 1;
if (ConfigHelper.GetConfig("storeCode") == "B") task.pilerUnloadRows = 2;
}
Mapper.Initialize(cret => cret.CreateMap<TaskDTO, BaseTaskQueue>());
baseTaskQueue = Mapper.Map<BaseTaskQueue>(task);
Mapper.Initialize(cret => cret.CreateMap<BaseTaskQueue, PlcDirectiveDTO>());
PlcDirectiveDTO taskDTO = Mapper.Map<PlcDirectiveDTO>(baseTaskQueue);
//读取到线体信号反馈
#region 将出库任务转换成字节发送
byte[] buffer = new byte[42];
taskDTO.inStorePlatformCode = 0;
taskDTO.claimGoods = 0;
taskDTO.unload = 0;
taskDTO.outStorePlatformCode = 0;
taskDTO.goodsSize = 0;
taskDTO.goodsHeight = 0;
taskDTO.goodsWeight = 0;
taskDTO.trayCode = 0;
taskDTO.takePutTheCar = 0;
taskDTO.verify = 0;
taskDTO.exitFork = 1;
byte[] taskNo = StringChange.intToBytesBig(taskDTO.pilerTaskCode);
taskNo.CopyTo(buffer, 0);
byteTransform.TransByte((short)taskDTO.pilerTaskType).CopyTo(buffer, 4);
Array.Reverse(buffer, 4, 2);
byteTransform.TransByte((short)taskDTO.inStorePlatformCode).CopyTo(buffer, 6);
Array.Reverse(buffer, 6, 2);
byteTransform.TransByte((short)taskDTO.claimGoods).CopyTo(buffer, 8);
Array.Reverse(buffer, 8, 2);
byteTransform.TransByte((short)taskDTO.unload).CopyTo(buffer, 10);
Array.Reverse(buffer, 10, 2);
byteTransform.TransByte((short)taskDTO.outStorePlatformCode).CopyTo(buffer, 12);
Array.Reverse(buffer, 12, 2);
byteTransform.TransByte((short)taskDTO.pilerClaimGoodsRows).CopyTo(buffer, 14);
Array.Reverse(buffer, 14, 2);
byteTransform.TransByte((short)taskDTO.pilerClaimGoodsLine).CopyTo(buffer, 16);
Array.Reverse(buffer, 16, 2);
byteTransform.TransByte((short)taskDTO.pilerClaimGoodsTier).CopyTo(buffer, 18);
Array.Reverse(buffer, 18, 2);
byteTransform.TransByte((short)taskDTO.pilerUnloadRows).CopyTo(buffer, 20);
Array.Reverse(buffer, 20, 2);
byteTransform.TransByte((short)taskDTO.pilerUnloadLine).CopyTo(buffer, 22);
Array.Reverse(buffer, 22, 2);
byteTransform.TransByte((short)taskDTO.pilerUnloadTier).CopyTo(buffer, 24);
Array.Reverse(buffer, 24, 2);
byteTransform.TransByte((short)taskDTO.goodsSize).CopyTo(buffer, 26);
Array.Reverse(buffer, 26, 2);
byteTransform.TransByte((short)taskDTO.goodsHeight).CopyTo(buffer, 28);
Array.Reverse(buffer, 28, 2);
byteTransform.TransByte((short)taskDTO.goodsWeight).CopyTo(buffer, 30);
Array.Reverse(buffer, 30, 2);
byteTransform.TransByte((int)taskDTO.trayCode).CopyTo(buffer, 32);
Array.Reverse(buffer, 32, 2);
byteTransform.TransByte((short)taskDTO.takePutTheCar).CopyTo(buffer, 36);
Array.Reverse(buffer, 36, 2);
byteTransform.TransByte((byte)taskDTO.verify).CopyTo(buffer, 38);
Array.Reverse(buffer, 38, 2);
byteTransform.TransByte((short)taskDTO.exitFork).CopyTo(buffer, 40);
Array.Reverse(buffer, 40, 2);
#endregion
taskCode = taskDTO.pilerTaskCode.ToString();
taskQueue = baseTaskQueue;
TaskInfoRefreshEvent?.Invoke(Convert.ToInt32(baseTaskQueue.pilerTaskCode), TaskType.OutStore, locationArea, locationInfo.locationCode);
UpdateLocationStatus("A", locationArea, locationInfo.locationCode, LocationStatus.Occupy);
return buffer;
}
catch (Exception ex)
{
LogHelper.Pilerlog($"获取出库任务逻辑执行异常:{ex.Message}");
return null;
}
}
}
private byte[] GetInStoreTaskInfo(int deviceId, out string taskCode, out BaseTaskQueue taskQueue)
{
lock (string.Empty)
{
taskCode = string.Empty;
taskQueue = null;
try
{
LocationArea locationArea = LocationArea.Location_Left;
if(deviceId != 1002)
{
locationArea = LocationArea.Location_Right;
}
BaseTaskQueue baseTaskQueue = baseTaskQueueBusiness.GetTaskQueue(locationArea, TaskType.InStore, OperationType.ManualOperation).Result;
if (baseTaskQueue == null)
{
baseTaskQueue = baseTaskQueueBusiness.GetTaskQueue(locationArea, TaskType.InStore, OperationType.Automatic).Result;
}
if (baseTaskQueue != null)
{
LogHelper.Pilerlog($"入库任务:{baseTaskQueue.pilerTaskCode};内容:{JsonChange.ModeToJson(baseTaskQueue)}");
Mapper.Initialize(cret => cret.CreateMap<BaseTaskQueue, PlcDirectiveDTO>());
PlcDirectiveDTO taskDTO = Mapper.Map<PlcDirectiveDTO>(baseTaskQueue);
LogHelper.Pilerlog($"入库任务:{baseTaskQueue.pilerTaskCode};映射为PlcDirectiveDTO");
#region 将入库任务转换成字节发送
byte[] buffer = new byte[42];
taskDTO.inStorePlatformCode = 0;
taskDTO.claimGoods = 0;
taskDTO.unload = 0;
taskDTO.outStorePlatformCode = 0;
taskDTO.goodsSize = 0;
taskDTO.goodsHeight = 0;
taskDTO.goodsWeight = 0;
taskDTO.trayCode = 0;
taskDTO.takePutTheCar = 0;
taskDTO.verify = 0;
taskDTO.exitFork = 1;
byte[] taskNo = StringChange.intToBytesBig(taskDTO.pilerTaskCode);
taskNo.CopyTo(buffer, 0);
byteTransform.TransByte((short)taskDTO.pilerTaskType).CopyTo(buffer, 4);
Array.Reverse(buffer, 4, 2);
byteTransform.TransByte((short)taskDTO.inStorePlatformCode).CopyTo(buffer, 6);
Array.Reverse(buffer, 6, 2);
byteTransform.TransByte((short)taskDTO.claimGoods).CopyTo(buffer, 8);
Array.Reverse(buffer, 8, 2);
byteTransform.TransByte((short)taskDTO.unload).CopyTo(buffer, 10);
Array.Reverse(buffer, 10, 2);
byteTransform.TransByte((short)taskDTO.outStorePlatformCode).CopyTo(buffer, 12);
Array.Reverse(buffer, 12, 2);
byteTransform.TransByte((short)taskDTO.pilerClaimGoodsRows).CopyTo(buffer, 14);
Array.Reverse(buffer, 14, 2);
byteTransform.TransByte((short)taskDTO.pilerClaimGoodsLine).CopyTo(buffer, 16);
Array.Reverse(buffer, 16, 2);
byteTransform.TransByte((short)taskDTO.pilerClaimGoodsTier).CopyTo(buffer, 18);
Array.Reverse(buffer, 18, 2);
byteTransform.TransByte((short)taskDTO.pilerUnloadRows).CopyTo(buffer, 20);
Array.Reverse(buffer, 20, 2);
byteTransform.TransByte((short)taskDTO.pilerUnloadLine).CopyTo(buffer, 22);
Array.Reverse(buffer, 22, 2);
byteTransform.TransByte((short)taskDTO.pilerUnloadTier).CopyTo(buffer, 24);
Array.Reverse(buffer, 24, 2);
byteTransform.TransByte((short)taskDTO.goodsSize).CopyTo(buffer, 26);
Array.Reverse(buffer, 26, 2);
byteTransform.TransByte((short)taskDTO.goodsHeight).CopyTo(buffer, 28);
Array.Reverse(buffer, 28, 2);
byteTransform.TransByte((short)taskDTO.goodsWeight).CopyTo(buffer, 30);
Array.Reverse(buffer, 30, 2);
byteTransform.TransByte((int)taskDTO.trayCode).CopyTo(buffer, 32);
Array.Reverse(buffer, 32, 2);
byteTransform.TransByte((short)taskDTO.takePutTheCar).CopyTo(buffer, 36);
Array.Reverse(buffer, 36, 2);
byteTransform.TransByte((byte)taskDTO.verify).CopyTo(buffer, 38);
Array.Reverse(buffer, 38, 2);
byteTransform.TransByte((short)taskDTO.exitFork).CopyTo(buffer, 40);
Array.Reverse(buffer, 40, 2);
#endregion
taskCode = taskDTO.pilerTaskCode.ToString();
taskQueue = baseTaskQueue;
TaskInfoRefreshEvent?.Invoke(Convert.ToInt32(baseTaskQueue.pilerTaskCode), TaskType.InStore, locationArea, $"{taskQueue.pilerUnloadRows} - {taskQueue.pilerUnloadLine} - {taskQueue.pilerUnloadTier}");
bool res = baseTaskQueueBusiness.DeleteTaskQueue(baseTaskQueue).Result;
LogHelper.Pilerlog($"入库任务:{baseTaskQueue.pilerTaskCode};移除");
UpdateLocationStatus("A", locationArea, $"{taskQueue.pilerUnloadRows}-{taskQueue.pilerUnloadLine}-{taskQueue.pilerUnloadTier}", LocationStatus.Occupy);
return buffer;
}
else
{
LogHelper.Pilerlog($"入库任务为空");
return null;
}
}
catch (Exception ex)
{
LogHelper.Pilerlog($"获取入库任务逻辑处理异常:{ex.Message}");
LogHelper.Error($"获取入库任务逻辑处理异常:{ex.Message}",ex);
return null;
}
}
}
private IBaseServices<BaseLocationInfo> locationInfoService = new BaseServices<BaseLocationInfo>();
private void UpdateLocationStatus(string StoreCode,LocationArea locationArea,string locationCode, LocationStatus locationStatus)
{
try
{
var locationInfos = locationInfoService.Query(x => x.storeCode == StoreCode && x.locationArea == locationArea && x.locationCode == locationCode).Result;
if (locationInfos != null)
{
BaseLocationInfo locationInfo = locationInfos.FirstOrDefault();
locationInfo.locationStatus = locationStatus;
var isRes = locationInfoService.Update(locationInfo).Result;
LogHelper.Pilerlog($"库位:{locationInfo.locationCode};状态:{locationStatus};更新{(isRes ? "" : "")}");
}
}
catch (Exception ex)
{
LogHelper.Pilerlog($"库位信息更新异常:{ex.Message}");
}
}
}
}