using HH.WCS.Mobox3.DoubleCoin.dispatch;
|
using HH.WCS.Mobox3.DoubleCoin.models;
|
using HH.WCS.Mobox3.DoubleCoin.util;
|
using System;
|
using System.Text;
|
using static HH.WCS.Mobox3.DoubleCoin.api.ApiModel;
|
|
namespace HH.WCS.Mobox3.DoubleCoin.wms
|
{
|
/// <summary>
|
/// wms管到作业
|
/// </summary>
|
internal class WMSHelper
|
{
|
/// <summary>
|
/// 人工手动PDA取消任务:1=发给AGV取消任务
|
/// </summary>
|
/// <param name="model"></param>
|
/// <returns></returns>
|
internal static SimpleResult PDACancleTask(CancleTaskInfo model)
|
{
|
SimpleResult simpleResult = new SimpleResult();
|
var db = new SqlHelper<object>().GetInstance();
|
try
|
{
|
if (model.taskNO.Length > 0)
|
{
|
var task = db.Queryable<TN_Task>().First(a => a.S_CODE == model.taskNO);
|
if (task != null && task.S_B_STATE != "完成")
|
{
|
if (NDCApi.CancelOrder(model.taskNO).err_code == 0)
|
{
|
task.S_B_STATE = "错误";
|
task.N_B_STATE = 4;
|
if (db.Updateable<TN_Task>(task).ExecuteCommand() > 0)
|
{
|
simpleResult.resultCode = 0;
|
simpleResult.resultMsg = $"通知AGV取消该任务号,成功,{model.taskNO}";
|
LogHelper.Info(simpleResult.resultMsg);
|
return simpleResult;
|
}
|
else
|
{
|
simpleResult.resultCode = 4;
|
simpleResult.resultMsg = $"更新任务状态信息失败{model.taskNO}";
|
LogHelper.Info(simpleResult.resultMsg);
|
return simpleResult;
|
}
|
}
|
else
|
{
|
simpleResult.resultCode = 1;
|
simpleResult.resultMsg = $"通知AGV取消该任务号,失败,{model.taskNO}";
|
LogHelper.Info(simpleResult.resultMsg);
|
return simpleResult;
|
}
|
|
}
|
else
|
{
|
simpleResult.resultCode = 2;
|
simpleResult.resultMsg = $"未找到该任务号或该任务号已完成,无需通知AGV取消";
|
LogHelper.Info(simpleResult.resultMsg);
|
return simpleResult;
|
}
|
|
}
|
else
|
{
|
simpleResult.resultCode = 3;
|
simpleResult.resultMsg = $"人工手动PDA取消任务:1=发给AGV取消任务,参数无效";
|
LogHelper.Info(simpleResult.resultMsg);
|
return simpleResult;
|
}
|
}
|
catch (Exception ex)
|
{
|
simpleResult.resultCode = -1;
|
simpleResult.resultMsg = $"发生了异常{ex.Message}";
|
LogHelper.Info(simpleResult.resultMsg);
|
return simpleResult;
|
}
|
}
|
|
/// <summary>
|
/// 插入操作员信息
|
/// </summary>
|
/// <param name="staff"></param>
|
/// <param name="type"></param>
|
/// <param name="cntrCode"></param>
|
/// <param name="qty"></param>
|
public static void InsertOpInfo(string staff, string type , string cntrCode ="",int qty = 0)
|
{
|
try
|
{
|
if(string.IsNullOrEmpty(staff))
|
{
|
LogHelper.Info($"操作员信息为空,{staff}");
|
return;
|
}
|
|
var db = new SqlHelper<object>().GetInstance();
|
var target = new TN_Operator_Info()
|
{
|
S_STAFF = staff,
|
S_SNTR_CODE = cntrCode,
|
F_QTY = qty,
|
S_TYPE = type
|
};
|
|
if(db.Insertable<TN_Operator_Info>(target).ExecuteCommand() > 0)
|
{
|
LogHelper.Info($"插入操作员信息成功,{staff}");
|
}
|
else
|
{
|
LogHelper.Info($"插入操作员信息失败,{staff}");
|
}
|
}
|
catch(Exception ex)
|
{
|
LogHelper.Error($"插入操作员信息,发生了异常,{ex.Message}",ex);
|
}
|
}
|
|
/// <summary>
|
/// 将16进制字符串转换为ASCII字符串
|
/// </summary>
|
/// <param name="hexString"></param>
|
/// <returns></returns>
|
public static string ConvertHexToAscii(string hexString)
|
{
|
LogHelper.Info($"将16进制字符串转换为ASCII字符串,转换前:{hexString}");
|
|
// 验证输入是否为16位16进制字符串
|
if (hexString.Length != 16 || !System.Text.RegularExpressions.Regex.IsMatch(hexString, @"^[0-9A-Fa-f]+$"))
|
{
|
throw new ArgumentException("输入必须是16位的16进制字符串");
|
}
|
|
// 每两位转换一个ASCII字符
|
StringBuilder asciiString = new StringBuilder();
|
for (int i = 0; i < 16; i += 2)
|
{
|
string hexPair = hexString.Substring(i, 2);
|
byte asciiChar = Convert.ToByte(hexPair, 16);
|
asciiString.Append((char)asciiChar);
|
}
|
|
LogHelper.Info($"将16进制字符串转换为ASCII字符串,转换后:{asciiString.ToString()}");
|
return asciiString.ToString();
|
}
|
}
|
}
|