84 lines
3.3 KiB
C#
84 lines
3.3 KiB
C#
using CirculateTool.Attribute;
|
||
using WcsMain.ApiClient.DataEntity.WmsEntity;
|
||
using WcsMain.Common;
|
||
using WcsMain.DataBase.Dao;
|
||
using WcsMain.DataBase.TableEntity;
|
||
using WcsMain.Enum.Convey;
|
||
using WcsMain.EquipOperation.Convey;
|
||
using WcsMain.ExtendMethod;
|
||
using WcsMain.Plugins;
|
||
|
||
namespace WcsMain.Business.CirculationTask.Convey;
|
||
|
||
/// <summary>
|
||
/// 拣选站台按钮
|
||
/// </summary>
|
||
[Circulation]
|
||
public class PickStandButton(AppConveyStandDao conveyStandDao, ConveyOperation conveyOperation, WmsWebApiPost wmsWebApiPost)
|
||
{
|
||
|
||
private static List<AppConveyStand>? _pickStands; // 拣选站台
|
||
|
||
/// <summary>
|
||
/// 当拣选站站台按钮按下时上传 wms
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
[Circulation("拣选站按钮按下上报", 300)]
|
||
public bool UploadInfo()
|
||
{
|
||
if (_pickStands == default)
|
||
{
|
||
_pickStands = conveyStandDao.Query(new AppConveyStand() { StandStatus = 1, StandType = (int)ConveyStandTypeEnum.pick });
|
||
return true;
|
||
}
|
||
if (_pickStands.Count < 1)
|
||
{
|
||
ConsoleLog.Warning($"【提示】无卡特拣选站台信息,监控已经停止");
|
||
return false;
|
||
}
|
||
List<Task> tasks = [];
|
||
foreach (var pickStand in _pickStands)
|
||
{
|
||
Thread.Sleep(20);
|
||
Task task = new(() =>
|
||
{
|
||
int pickButtonStatus = conveyOperation.GetAllowPickStandGo(pickStand.StandId!);
|
||
if (pickButtonStatus != 1) return;
|
||
//ConsoleLog.Info($"【提示】拣选站:{pickStand.StandId} 按钮已经按下");
|
||
//conveyOperation.AllowPickStandGo(pickStand.StandId!, 2);
|
||
//ConsoleLog.Success($"{pickStand.StandId}按钮按下,调试阶段直接放行");
|
||
//return;
|
||
// 发送wms按钮按下
|
||
ConceyButtonClickRequest request = new()
|
||
{
|
||
Location = pickStand.StandId,
|
||
VehicleNo = "",
|
||
Remark = "按钮按下上报"
|
||
};
|
||
var responseEntity = wmsWebApiPost.HttpPost<ConceyButtonClickRequest, WmsResponse>(request, CommonData.AppApiBaseInfos.GetAddress("UploadPickStandButtonMethod") ?? "", 2000);
|
||
if (!responseEntity.IsSend) return; // 发送失败不处理,下一次循环在发送
|
||
// 只要发送成功则不再发送
|
||
ConsoleLog.Info( $"拣选站:{pickStand.StandId} 按钮已经按下上报成功,WMS返回:{responseEntity.ResponseMsg}");
|
||
var result = responseEntity.ResponseEntity;
|
||
if (result is { Code: 0 })
|
||
{
|
||
conveyOperation.AllowPickStandGo(pickStand.StandId!, 2);
|
||
ConsoleLog.Success($"{pickStand.StandId}按钮按下,放行成功");
|
||
}
|
||
else
|
||
{
|
||
conveyOperation.AllowPickStandGo(pickStand.StandId!, 0);
|
||
ConsoleLog.Error($"【异常】{pickStand.StandId}按钮按下,wms返回异常:{result?.Message}");
|
||
}
|
||
});
|
||
task.Start();
|
||
tasks.Add(task);
|
||
}
|
||
Task.WaitAll([.. tasks]);
|
||
|
||
return true;
|
||
}
|
||
|
||
|
||
}
|