feat: 增加LG-AGV接口并完善物料校验与报工逻辑
This commit is contained in:
@@ -212,8 +212,12 @@
|
||||
<Compile Include="WebAPI\Other\DewPointData.cs" />
|
||||
<Compile Include="WebAPI\WEB\WEB_BusinessLogic.cs" />
|
||||
<Compile Include="WebAPI\WEB\WEB_Models.cs" />
|
||||
<Compile Include="WebAPI\WEB\LGWEB_BusinessLogic.cs" />
|
||||
<Compile Include="WebAPI\WEB\LGWEB_Models.cs" />
|
||||
<Compile Include="WebAPI\AGV\AGV_BusinessLogic.cs" />
|
||||
<Compile Include="WebAPI\AGV\AGV_Models.cs" />
|
||||
<Compile Include="WebAPI\AGV\LGAGV_BusinessLogic.cs" />
|
||||
<Compile Include="WebAPI\AGV\LGAGV_Models.cs" />
|
||||
<Compile Include="WebAPI\Controller\WEBController.cs" />
|
||||
<Compile Include="WebAPI\FactoryMES\Analysis508Msg.cs" />
|
||||
<Compile Include="WebAPI\FactoryMES\CALL_Inerface_DataHandle.cs" />
|
||||
@@ -519,4 +523,4 @@
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\..\packages\WinSCP.6.5.3\build\WinSCP.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\..\packages\WinSCP.6.5.3\build\WinSCP.targets'))" />
|
||||
</Target>
|
||||
</Project>
|
||||
</Project>
|
||||
|
||||
@@ -0,0 +1,364 @@
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Web.Http;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using MisDataSaveDate.Helper;
|
||||
using static MisDataSaveDate.Helper.ApiLogHelper;
|
||||
using WebApi;
|
||||
|
||||
namespace MisDataSaveDate
|
||||
{
|
||||
/// <summary>
|
||||
/// 临工AGV接口业务处理。
|
||||
/// </summary>
|
||||
public class LGAGV_BusinessLogic
|
||||
{
|
||||
private const string DirectionMesToAgv = "MES_TO_AGV";
|
||||
private const string DirectionAgvToMes = "AGV_TO_MES";
|
||||
|
||||
/// <summary>
|
||||
/// MES调用临工AGV两点任务接口。
|
||||
/// </summary>
|
||||
public static LGAGV_CallResult CallAddTask(LGAGV_AddTaskRequest request)
|
||||
{
|
||||
if (request == null)
|
||||
{
|
||||
throw new Exception("AGV任务参数不能为空");
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(request.requestTaskId))
|
||||
{
|
||||
throw new Exception("任务ID(requestTaskId)不能为空");
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(request.startPosition))
|
||||
{
|
||||
throw new Exception("起点位置(startPosition)不能为空");
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(request.endPosition))
|
||||
{
|
||||
throw new Exception("终点位置(endPosition)不能为空");
|
||||
}
|
||||
|
||||
return PostToAgv("AddTaskFromMes", "/api/mes/AddTaskFromMes", request,
|
||||
request.requestTaskId, null, request.endPosition, null, request.materialCode, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// MES调用临工AGV三点任务接口。
|
||||
/// </summary>
|
||||
public static LGAGV_CallResult CallAddTask2(LGAGV_AddTask2Request request)
|
||||
{
|
||||
if (request == null)
|
||||
{
|
||||
throw new Exception("AGV任务参数不能为空");
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(request.requestTaskId))
|
||||
{
|
||||
throw new Exception("任务ID(requestTaskId)不能为空");
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(request.startPosition))
|
||||
{
|
||||
throw new Exception("起点位置(startPosition)不能为空");
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(request.midPosition))
|
||||
{
|
||||
throw new Exception("中间位置(midPosition)不能为空");
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(request.endPosition))
|
||||
{
|
||||
throw new Exception("终点位置(endPosition)不能为空");
|
||||
}
|
||||
|
||||
return PostToAgv("AddTaskFromMes2", "/api/mes/AddTaskFromMes2", request,
|
||||
request.requestTaskId, null, request.endPosition, null, request.materialCode, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// MES调用临工AGV放行接口。
|
||||
/// </summary>
|
||||
public static LGAGV_CallResult CallAllowLeave(LGAGV_AllowLeaveRequest request)
|
||||
{
|
||||
if (request == null)
|
||||
{
|
||||
throw new Exception("放行参数不能为空");
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(request.requestId))
|
||||
{
|
||||
throw new Exception("请求ID(requestId)不能为空");
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(request.position))
|
||||
{
|
||||
throw new Exception("位置(position)不能为空");
|
||||
}
|
||||
|
||||
request.allowLeave = 1;
|
||||
return PostToAgv("AllowLeave", "/api/mes/AllowLeave", request,
|
||||
null, request.requestId, request.position, null, null, request.agvNo);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 处理临工AGV到达/离开回调。
|
||||
/// </summary>
|
||||
public static string ProcessStatusUpdate(string url, [FromBody] JObject jobj)
|
||||
{
|
||||
var result = LGAGV_Response.Success();
|
||||
string requestText = jobj?.ToString() ?? "";
|
||||
SaveLog_Interface_Request(url, 2, requestText, out int aid);
|
||||
|
||||
LGAGV_StatusUpdateRequest request = null;
|
||||
try
|
||||
{
|
||||
if (jobj == null)
|
||||
{
|
||||
throw new Exception("请求参数不能为空");
|
||||
}
|
||||
|
||||
request = JsonConvert.DeserializeObject<LGAGV_StatusUpdateRequest>(requestText);
|
||||
if (request == null)
|
||||
{
|
||||
throw new Exception("请求参数格式不正确");
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(request.requestId))
|
||||
{
|
||||
throw new Exception("请求ID(requestId)不能为空");
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(request.position))
|
||||
{
|
||||
throw new Exception("位置(position)不能为空");
|
||||
}
|
||||
if (request.type != 1 && request.type != 2)
|
||||
{
|
||||
throw new Exception("类型(type)只支持1到达、2离开");
|
||||
}
|
||||
|
||||
string procedureName = request.type == 1 ? "LG_AGV_库位Moby_AGV到达" : "LG_AGV_库位Moby_AGV离开";
|
||||
var param = new SqlParameter[]
|
||||
{
|
||||
new SqlParameter("@requestId", request.requestId ?? ""),
|
||||
new SqlParameter("@position", request.position ?? ""),
|
||||
new SqlParameter("@materialCode", request.materialCode ?? ""),
|
||||
new SqlParameter("@agvNo", request.agvNo ?? "")
|
||||
};
|
||||
ExecuteResultProcedure(procedureName, ref param);
|
||||
|
||||
SaveInterfaceRecord("StatusUpdate", DirectionAgvToMes, request.position, request.position,
|
||||
null, request.requestId, request.position, request.type, request.materialCode, request.agvNo,
|
||||
"", requestText, "", 1, "");
|
||||
|
||||
string typeDesc = request.type == 1 ? "到达" : "离开";
|
||||
SaveMesLog("LGAGV_StatusUpdate", $"临工AGV{typeDesc}:位置={request.position}, requestId={request.requestId}, AGV={request.agvNo}", MesLogType.INFO);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
result = LGAGV_Response.Fail(ex.Message);
|
||||
SaveInterfaceRecord("StatusUpdate", DirectionAgvToMes, request?.position, request?.position,
|
||||
null, request?.requestId, request?.position, request?.type, request?.materialCode, request?.agvNo,
|
||||
"", requestText, "", 2, ex.Message);
|
||||
SaveMesLog("LGAGV_StatusUpdate", ex.Message, MesLogType.ERROR);
|
||||
}
|
||||
|
||||
string responseText = JsonConvert.SerializeObject(result);
|
||||
SaveLog_Interface_Response(responseText, aid);
|
||||
return responseText;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 处理临工AGV任务结果回调。
|
||||
/// </summary>
|
||||
public static string ProcessTaskResult(string url, [FromBody] JObject jobj)
|
||||
{
|
||||
var result = LGAGV_Response.Success();
|
||||
string requestText = jobj?.ToString() ?? "";
|
||||
SaveLog_Interface_Request(url, 2, requestText, out int aid);
|
||||
|
||||
LGAGV_TaskResultRequest request = null;
|
||||
try
|
||||
{
|
||||
if (jobj == null)
|
||||
{
|
||||
throw new Exception("请求参数不能为空");
|
||||
}
|
||||
|
||||
request = JsonConvert.DeserializeObject<LGAGV_TaskResultRequest>(requestText);
|
||||
if (request == null)
|
||||
{
|
||||
throw new Exception("请求参数格式不正确");
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(request.requestTaskId))
|
||||
{
|
||||
throw new Exception("任务ID(requestTaskId)不能为空");
|
||||
}
|
||||
|
||||
bool isSuccess = IsAgvSuccess(request.status);
|
||||
var param = new SqlParameter[]
|
||||
{
|
||||
new SqlParameter("@requestTaskId", request.requestTaskId ?? ""),
|
||||
new SqlParameter("@status", request.status ?? ""),
|
||||
new SqlParameter("@agvNo", request.agvNo ?? ""),
|
||||
new SqlParameter("@message", request.message ?? ""),
|
||||
new SqlParameter("@materialCode", request.materialCode ?? "")
|
||||
};
|
||||
ExecuteResultProcedure("LG_AGV_库位Moby_任务结果", ref param);
|
||||
|
||||
SaveInterfaceRecord("TaskResult", DirectionAgvToMes, null, null,
|
||||
request.requestTaskId, null, null, null, request.materialCode, request.agvNo, request.status,
|
||||
requestText, "", isSuccess ? 1 : 2, request.message ?? "");
|
||||
|
||||
SaveMesLog("LGAGV_TaskResult", $"临工AGV任务结果:requestTaskId={request.requestTaskId}, status={request.status}, AGV={request.agvNo}, message={request.message}", MesLogType.INFO);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
result = LGAGV_Response.Fail(ex.Message);
|
||||
SaveInterfaceRecord("TaskResult", DirectionAgvToMes, null, null,
|
||||
request?.requestTaskId, null, null, null, request?.materialCode, request?.agvNo, request?.status,
|
||||
requestText, "", 2, ex.Message);
|
||||
SaveMesLog("LGAGV_TaskResult", ex.Message, MesLogType.ERROR);
|
||||
}
|
||||
|
||||
string responseText = JsonConvert.SerializeObject(result);
|
||||
SaveLog_Interface_Response(responseText, aid);
|
||||
return responseText;
|
||||
}
|
||||
|
||||
public static void SaveInterfaceRecord(string interfaceName, string direction, string positionCode, string workStation,
|
||||
string requestTaskId, string requestId, string position, int? type, string materialCode, string agvNo, string status,
|
||||
string requestText, string responseText, int isSuccess, string errorMessage)
|
||||
{
|
||||
var param = new SqlParameter[]
|
||||
{
|
||||
new SqlParameter("@库位号", positionCode ?? ""),
|
||||
new SqlParameter("@工位号", workStation ?? ""),
|
||||
new SqlParameter("@接口名称", interfaceName ?? ""),
|
||||
new SqlParameter("@接口方向", direction ?? ""),
|
||||
new SqlParameter("@requestTaskId", requestTaskId ?? ""),
|
||||
new SqlParameter("@requestId", requestId ?? ""),
|
||||
new SqlParameter("@position", position ?? ""),
|
||||
new SqlParameter("@type", type.HasValue ? (object)type.Value : DBNull.Value),
|
||||
new SqlParameter("@materialCode", materialCode ?? ""),
|
||||
new SqlParameter("@agvNo", agvNo ?? ""),
|
||||
new SqlParameter("@status", status ?? ""),
|
||||
new SqlParameter("@message", errorMessage ?? ""),
|
||||
new SqlParameter("@请求报文", requestText ?? ""),
|
||||
new SqlParameter("@响应报文", responseText ?? ""),
|
||||
new SqlParameter("@是否成功", isSuccess),
|
||||
new SqlParameter("@错误信息", errorMessage ?? "")
|
||||
};
|
||||
DataLinkMesWork2.DataAccess2.ExecuteStoredProcedure("LG_AGV_接口记录_增加", ref param, out string errMessage);
|
||||
if (!string.IsNullOrEmpty(errMessage))
|
||||
{
|
||||
SaveMesLog("LGAGV_InterfaceRecord", errMessage, MesLogType.ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
public static bool IsAgvSuccess(string codeOrStatus)
|
||||
{
|
||||
string value = (codeOrStatus ?? "").Trim().ToLower();
|
||||
return value == "0" || value == "200" || value == "true" || value == "success" || value == "成功";
|
||||
}
|
||||
|
||||
private static LGAGV_CallResult PostToAgv(string interfaceName, string path, object request,
|
||||
string requestTaskId, string requestId, string position, int? type, string materialCode, string agvNo)
|
||||
{
|
||||
string baseUrl = ConfigurationManager.AppSettings["LGAGV_BaseUrl"];
|
||||
if (string.IsNullOrWhiteSpace(baseUrl))
|
||||
{
|
||||
throw new Exception("未配置 LGAGV_BaseUrl");
|
||||
}
|
||||
|
||||
string interfaceUrl = baseUrl.TrimEnd('/') + path;
|
||||
string requestText = JsonConvert.SerializeObject(request);
|
||||
SaveLog_Interface_Request("LGAGV_" + interfaceName, 1, requestText, out int aid);
|
||||
|
||||
string responseText = Post.Post_Auto(interfaceUrl, requestText);
|
||||
SaveLog_Interface_Response(responseText, aid);
|
||||
|
||||
JObject response = ParseResponse(responseText);
|
||||
string codeText = response["code"]?.ToString() ?? response["result"]?.ToString() ?? "";
|
||||
string message = response["desc"]?.ToString() ?? response["message"]?.ToString() ?? response["msg"]?.ToString() ?? "";
|
||||
bool success = IsAgvSuccess(codeText);
|
||||
if (response["success"] != null)
|
||||
{
|
||||
if (bool.TryParse(response["success"].ToString(), out bool successValue))
|
||||
{
|
||||
success = successValue;
|
||||
}
|
||||
}
|
||||
|
||||
SaveInterfaceRecord(interfaceName, DirectionMesToAgv, position, position, requestTaskId, requestId, position,
|
||||
type, materialCode, agvNo, codeText, requestText, responseText, success ? 1 : 2, success ? "" : message);
|
||||
|
||||
if (success)
|
||||
{
|
||||
SaveMesLog("LGAGV_" + interfaceName, $"临工AGV接口调用成功:{interfaceName}, position={position}, requestTaskId={requestTaskId}", MesLogType.INFO);
|
||||
}
|
||||
else
|
||||
{
|
||||
SaveMesLog("LGAGV_" + interfaceName, $"临工AGV接口调用失败:{interfaceName}, code={codeText}, message={message}", MesLogType.ERROR);
|
||||
}
|
||||
|
||||
return new LGAGV_CallResult
|
||||
{
|
||||
Success = success,
|
||||
Code = ToInt(codeText, success ? 0 : 500),
|
||||
Message = message,
|
||||
InterfaceUrl = interfaceUrl,
|
||||
RequestText = requestText,
|
||||
ResponseText = responseText,
|
||||
Response = response
|
||||
};
|
||||
}
|
||||
|
||||
private static JObject ParseResponse(string responseText)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(responseText))
|
||||
{
|
||||
return new JObject
|
||||
{
|
||||
{ "code", 500 },
|
||||
{ "message", "AGV返回空响应" },
|
||||
{ "success", false }
|
||||
};
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
return JObject.Parse(responseText);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new JObject
|
||||
{
|
||||
{ "code", 500 },
|
||||
{ "message", "AGV返回非JSON响应:" + ex.Message },
|
||||
{ "raw", responseText },
|
||||
{ "success", false }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private static int ToInt(string value, int defaultValue)
|
||||
{
|
||||
if (int.TryParse(value, out int intValue))
|
||||
{
|
||||
return intValue;
|
||||
}
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
private static void ExecuteResultProcedure(string procedureName, ref SqlParameter[] param)
|
||||
{
|
||||
DataLinkMesWork2.DataAccess2.ExecuteStoredProcedure(procedureName, ref param, out DataTable dt, out string errMessage);
|
||||
if (!string.IsNullOrEmpty(errMessage))
|
||||
{
|
||||
throw new Exception(errMessage);
|
||||
}
|
||||
if (dt != null && dt.Rows.Count > 0 && dt.Columns.Contains("result") && dt.Rows[0]["result"].ToString() != "1")
|
||||
{
|
||||
string msg = dt.Columns.Contains("msg") ? dt.Rows[0]["msg"].ToString() : "存储过程执行失败";
|
||||
throw new Exception(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
106
Interface_WebAPI/SlMesDbIterface/WebAPI/AGV/LGAGV_Models.cs
Normal file
106
Interface_WebAPI/SlMesDbIterface/WebAPI/AGV/LGAGV_Models.cs
Normal file
@@ -0,0 +1,106 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace MisDataSaveDate
|
||||
{
|
||||
/// <summary>
|
||||
/// 临工AGV两点任务请求。
|
||||
/// </summary>
|
||||
public class LGAGV_AddTaskRequest
|
||||
{
|
||||
public string requestTaskId { get; set; }
|
||||
public string startPosition { get; set; }
|
||||
public string endPosition { get; set; }
|
||||
public string materialCode { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 临工AGV三点任务请求。
|
||||
/// </summary>
|
||||
public class LGAGV_AddTask2Request
|
||||
{
|
||||
public string requestTaskId { get; set; }
|
||||
public string startPosition { get; set; }
|
||||
public string midPosition { get; set; }
|
||||
public string endPosition { get; set; }
|
||||
public string materialCode { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 临工AGV放行请求。
|
||||
/// </summary>
|
||||
public class LGAGV_AllowLeaveRequest
|
||||
{
|
||||
public string requestId { get; set; }
|
||||
public string position { get; set; }
|
||||
public string agvNo { get; set; }
|
||||
public int allowLeave { get; set; } = 1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 临工AGV到达/离开回调。
|
||||
/// </summary>
|
||||
public class LGAGV_StatusUpdateRequest
|
||||
{
|
||||
public string requestId { get; set; }
|
||||
public string position { get; set; }
|
||||
public int type { get; set; }
|
||||
public string materialCode { get; set; }
|
||||
public string agvNo { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 临工AGV任务执行结果回调。
|
||||
/// </summary>
|
||||
public class LGAGV_TaskResultRequest
|
||||
{
|
||||
public string requestTaskId { get; set; }
|
||||
public string status { get; set; }
|
||||
public string agvNo { get; set; }
|
||||
public string message { get; set; }
|
||||
public string materialCode { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 返回给临工AGV的通用响应。
|
||||
/// </summary>
|
||||
public class LGAGV_Response
|
||||
{
|
||||
public int code { get; set; }
|
||||
public string desc { get; set; }
|
||||
public bool success { get; set; }
|
||||
|
||||
public static LGAGV_Response Success(string desc = "成功")
|
||||
{
|
||||
return new LGAGV_Response
|
||||
{
|
||||
code = 0,
|
||||
desc = desc,
|
||||
success = true
|
||||
};
|
||||
}
|
||||
|
||||
public static LGAGV_Response Fail(string desc)
|
||||
{
|
||||
return new LGAGV_Response
|
||||
{
|
||||
code = 1,
|
||||
desc = desc,
|
||||
success = false
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// MES调用临工AGV接口后的内部结果。
|
||||
/// </summary>
|
||||
public class LGAGV_CallResult
|
||||
{
|
||||
public bool Success { get; set; }
|
||||
public int Code { get; set; }
|
||||
public string Message { get; set; }
|
||||
public string InterfaceUrl { get; set; }
|
||||
public string RequestText { get; set; }
|
||||
public string ResponseText { get; set; }
|
||||
public JObject Response { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -40,5 +40,35 @@ namespace MisDataSaveDate
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 临工AGV到达/离开状态回调接口。
|
||||
/// </summary>
|
||||
/// <param name="jobj">临工AGV状态回调数据</param>
|
||||
/// <returns>处理结果</returns>
|
||||
[HttpPost]
|
||||
[Route("agv/lgagv/statusUpdate")]
|
||||
public HttpResponseMessage LGAGV_StatusUpdate([FromBody] JObject jobj)
|
||||
{
|
||||
return new HttpResponseMessage
|
||||
{
|
||||
Content = new StringContent(LGAGV_BusinessLogic.ProcessStatusUpdate(headUrl + System.Reflection.MethodBase.GetCurrentMethod().Name, jobj), Encoding.GetEncoding("UTF-8"), "application/json")
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 临工AGV任务结果回调接口。
|
||||
/// </summary>
|
||||
/// <param name="jobj">临工AGV任务结果数据</param>
|
||||
/// <returns>处理结果</returns>
|
||||
[HttpPost]
|
||||
[Route("agv/lgagv/taskResult")]
|
||||
public HttpResponseMessage LGAGV_TaskResult([FromBody] JObject jobj)
|
||||
{
|
||||
return new HttpResponseMessage
|
||||
{
|
||||
Content = new StringContent(LGAGV_BusinessLogic.ProcessTaskResult(headUrl + System.Reflection.MethodBase.GetCurrentMethod().Name, jobj), Encoding.GetEncoding("UTF-8"), "application/json")
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,6 +99,36 @@ namespace MisDataSaveDate
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 临工AGV网页按钮调度接口。
|
||||
/// </summary>
|
||||
/// <param name="jobj">调度请求数据</param>
|
||||
/// <returns>处理结果</returns>
|
||||
[HttpPost]
|
||||
[Route("web/LGAGV_Dispatch")]
|
||||
public HttpResponseMessage LGAGV_Dispatch([FromBody] JObject jobj)
|
||||
{
|
||||
return new HttpResponseMessage
|
||||
{
|
||||
Content = new StringContent(LGWEB_BusinessLogic.WEB_DispatchAGV(headUrl + System.Reflection.MethodBase.GetCurrentMethod().Name, jobj), Encoding.GetEncoding("UTF-8"), "application/json")
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 临工AGV网页按钮放行接口。
|
||||
/// </summary>
|
||||
/// <param name="jobj">放行请求数据</param>
|
||||
/// <returns>处理结果</returns>
|
||||
[HttpPost]
|
||||
[Route("web/LGAGV_AllowLeave")]
|
||||
public HttpResponseMessage LGAGV_AllowLeave([FromBody] JObject jobj)
|
||||
{
|
||||
return new HttpResponseMessage
|
||||
{
|
||||
Content = new StringContent(LGWEB_BusinessLogic.WEB_AllowLeave(headUrl + System.Reflection.MethodBase.GetCurrentMethod().Name, jobj), Encoding.GetEncoding("UTF-8"), "application/json")
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量读取PLC点位值接口
|
||||
/// 前端传递TagTypeCodeID数组和工位号,返回对应点位的值
|
||||
@@ -131,4 +161,4 @@ namespace MisDataSaveDate
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,17 @@ namespace WebApi
|
||||
{
|
||||
public class CALL_Inerface_DataHandle
|
||||
{
|
||||
private static bool TryCheckProcessReportAllowed(string opName, string engineID, string orderForm, string reqType)
|
||||
{
|
||||
DataTable isSendDT = MisDataFun.IOT_ReqData_UpLoad_IsSend(opName, orderForm, reqType, engineID);
|
||||
if (isSendDT.Rows[0]["result"].ToString() != "1")
|
||||
{
|
||||
SaveMesLog($"工序{reqType}", isSendDT.Rows[0]["msg"].ToString(), MesLogType.ERROR);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 开工(工序)
|
||||
/// </summary>
|
||||
@@ -32,10 +43,8 @@ namespace WebApi
|
||||
/// <param name="OrderForm"></param>
|
||||
public static void CALL_Inerface_JobStart(string OpName, string EngineID, string OrderForm)
|
||||
{
|
||||
DataTable IsSendDT = MisDataFun.IOT_ReqData_UpLoad_IsSend(OpName, OrderForm, "完工");
|
||||
if (IsSendDT.Rows[0]["result"].ToString() != "1")
|
||||
if (!TryCheckProcessReportAllowed(OpName, EngineID, OrderForm, "开工"))
|
||||
{
|
||||
SaveMesLog("工序完工", IsSendDT.Rows[0]["msg"].ToString(), MesLogType.ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -101,10 +110,8 @@ namespace WebApi
|
||||
/// <param name="OrderForm"></param>
|
||||
public static void CALL_Inerface_JobFinished(string OpName, string EngineID, string OrderForm)
|
||||
{
|
||||
DataTable IsSendDT = MisDataFun.IOT_ReqData_UpLoad_IsSend(OpName, OrderForm, "完工");
|
||||
if (IsSendDT.Rows[0]["result"].ToString() != "1")
|
||||
if (!TryCheckProcessReportAllowed(OpName, EngineID, OrderForm, "完工"))
|
||||
{
|
||||
SaveMesLog("工序完工", IsSendDT.Rows[0]["msg"].ToString(), MesLogType.ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,319 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Web.Http;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using MisDataSaveDate.Helper;
|
||||
using static MisDataSaveDate.Helper.ApiLogHelper;
|
||||
|
||||
namespace MisDataSaveDate
|
||||
{
|
||||
/// <summary>
|
||||
/// 临工AGV网页按钮业务处理。
|
||||
/// </summary>
|
||||
public class LGWEB_BusinessLogic
|
||||
{
|
||||
/// <summary>
|
||||
/// 网页按钮下发临工AGV搬运任务。
|
||||
/// </summary>
|
||||
public static string WEB_DispatchAGV(string url, [FromBody] JObject jobj)
|
||||
{
|
||||
var result = new MsgResHeader<object>
|
||||
{
|
||||
code = 200,
|
||||
message = "",
|
||||
Data = null
|
||||
};
|
||||
|
||||
if (jobj == null)
|
||||
{
|
||||
result.code = 500;
|
||||
result.message = "参数格式不正确!";
|
||||
return JsonConvert.SerializeObject(result);
|
||||
}
|
||||
|
||||
string requestText = jobj.ToString();
|
||||
SaveLog_Interface_Request(url, 2, requestText, out int aid);
|
||||
|
||||
try
|
||||
{
|
||||
LGWEB_DispatchRequest request = JsonConvert.DeserializeObject<LGWEB_DispatchRequest>(requestText);
|
||||
if (request == null)
|
||||
{
|
||||
throw new Exception("请求参数格式不正确");
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(request.routeCode))
|
||||
{
|
||||
throw new Exception("路线编码(routeCode)不能为空");
|
||||
}
|
||||
|
||||
LGWEB_RouteInfo route = GetRouteInfo(request.routeCode);
|
||||
string startPosition = string.IsNullOrWhiteSpace(request.startPosition) ? route.StartPosition : request.startPosition;
|
||||
string midPosition = string.IsNullOrWhiteSpace(request.midPosition) ? route.MidPosition : request.midPosition;
|
||||
string endPosition = route.ActualEndPosition;
|
||||
string requestTaskId = string.IsNullOrWhiteSpace(request.requestTaskId) ? Guid.NewGuid().ToString() : request.requestTaskId;
|
||||
string materialCode = FirstText(request.materialCode, request.productCode, request.containerNo);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(startPosition))
|
||||
{
|
||||
throw new Exception("起点位置不能为空,请检查路线配置或请求参数");
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(endPosition))
|
||||
{
|
||||
throw new Exception("终点位置不能为空,请检查路线配置");
|
||||
}
|
||||
|
||||
LGAGV_CallResult agvResult;
|
||||
if (string.Equals(route.InterfaceName, "AddTaskFromMes2", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
agvResult = LGAGV_BusinessLogic.CallAddTask2(new LGAGV_AddTask2Request
|
||||
{
|
||||
requestTaskId = requestTaskId,
|
||||
startPosition = startPosition,
|
||||
midPosition = midPosition,
|
||||
endPosition = endPosition,
|
||||
materialCode = materialCode
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
agvResult = LGAGV_BusinessLogic.CallAddTask(new LGAGV_AddTaskRequest
|
||||
{
|
||||
requestTaskId = requestTaskId,
|
||||
startPosition = startPosition,
|
||||
endPosition = endPosition,
|
||||
materialCode = materialCode
|
||||
});
|
||||
}
|
||||
|
||||
SaveDispatchResult(request, route, requestTaskId, startPosition, midPosition, endPosition, materialCode, agvResult);
|
||||
|
||||
result.code = agvResult.Success ? 200 : 500;
|
||||
result.message = agvResult.Success ? "AGV调度成功" : $"AGV调度失败:{agvResult.Message}";
|
||||
result.Data = new
|
||||
{
|
||||
requestTaskId = requestTaskId,
|
||||
routeCode = request.routeCode,
|
||||
startPosition = startPosition,
|
||||
midPosition = midPosition,
|
||||
endPosition = endPosition,
|
||||
originalEndPosition = route.OriginalEndPosition,
|
||||
routeMessage = route.RouteMessage,
|
||||
agvResponse = agvResult.Response
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
result.code = 500;
|
||||
result.message = ex.Message;
|
||||
SaveMesLog("LGWEB_DispatchAGV", ex.Message, MesLogType.ERROR);
|
||||
}
|
||||
|
||||
string responseText = JsonConvert.SerializeObject(result);
|
||||
SaveLog_Interface_Response(responseText, aid);
|
||||
return responseText;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 网页按钮放行临工AGV离开。
|
||||
/// </summary>
|
||||
public static string WEB_AllowLeave(string url, [FromBody] JObject jobj)
|
||||
{
|
||||
var result = new MsgResHeader<object>
|
||||
{
|
||||
code = 200,
|
||||
message = "",
|
||||
Data = null
|
||||
};
|
||||
|
||||
if (jobj == null)
|
||||
{
|
||||
result.code = 500;
|
||||
result.message = "参数格式不正确!";
|
||||
return JsonConvert.SerializeObject(result);
|
||||
}
|
||||
|
||||
string requestText = jobj.ToString();
|
||||
SaveLog_Interface_Request(url, 2, requestText, out int aid);
|
||||
|
||||
try
|
||||
{
|
||||
LGWEB_AllowLeaveRequest request = JsonConvert.DeserializeObject<LGWEB_AllowLeaveRequest>(requestText);
|
||||
if (request == null)
|
||||
{
|
||||
throw new Exception("请求参数格式不正确");
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(request.requestId))
|
||||
{
|
||||
throw new Exception("请求ID(requestId)不能为空");
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(request.position))
|
||||
{
|
||||
throw new Exception("位置(position)不能为空");
|
||||
}
|
||||
|
||||
LGAGV_CallResult agvResult = LGAGV_BusinessLogic.CallAllowLeave(new LGAGV_AllowLeaveRequest
|
||||
{
|
||||
requestId = request.requestId,
|
||||
position = request.position,
|
||||
agvNo = request.agvNo,
|
||||
allowLeave = 1
|
||||
});
|
||||
|
||||
var param = new SqlParameter[]
|
||||
{
|
||||
new SqlParameter("@requestId", request.requestId ?? ""),
|
||||
new SqlParameter("@position", request.position ?? ""),
|
||||
new SqlParameter("@agvNo", request.agvNo ?? ""),
|
||||
new SqlParameter("@操作人工号", request.operatorCode ?? ""),
|
||||
new SqlParameter("@操作人姓名", request.operatorName ?? ""),
|
||||
new SqlParameter("@备注", request.remark ?? ""),
|
||||
new SqlParameter("@是否成功", agvResult.Success ? 1 : 2),
|
||||
new SqlParameter("@错误信息", agvResult.Success ? "" : (agvResult.Message ?? ""))
|
||||
};
|
||||
ExecuteResultProcedure("LG_AGV_库位Moby_允许离开", ref param);
|
||||
|
||||
result.code = agvResult.Success ? 200 : 500;
|
||||
result.message = agvResult.Success ? "AGV放行成功" : $"AGV放行失败:{agvResult.Message}";
|
||||
result.Data = new
|
||||
{
|
||||
requestId = request.requestId,
|
||||
position = request.position,
|
||||
agvResponse = agvResult.Response
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
result.code = 500;
|
||||
result.message = ex.Message;
|
||||
SaveMesLog("LGWEB_AllowLeave", ex.Message, MesLogType.ERROR);
|
||||
}
|
||||
|
||||
string responseText = JsonConvert.SerializeObject(result);
|
||||
SaveLog_Interface_Response(responseText, aid);
|
||||
return responseText;
|
||||
}
|
||||
|
||||
private static LGWEB_RouteInfo GetRouteInfo(string routeCode)
|
||||
{
|
||||
var param = new SqlParameter[]
|
||||
{
|
||||
new SqlParameter("@路线编码", routeCode ?? "")
|
||||
};
|
||||
DataLinkMesWork2.DataAccess2.ExecuteStoredProcedure("LG_AGV_路线_实际终点解析", ref param, out DataTable dt, out string errMessage);
|
||||
if (!string.IsNullOrEmpty(errMessage))
|
||||
{
|
||||
throw new Exception(errMessage);
|
||||
}
|
||||
if (dt == null || dt.Rows.Count == 0)
|
||||
{
|
||||
throw new Exception("路线解析无返回结果");
|
||||
}
|
||||
|
||||
DataRow row = dt.Rows[0];
|
||||
string resultText = row.Table.Columns.Contains("result") ? row["result"].ToString() : "2";
|
||||
if (resultText != "1")
|
||||
{
|
||||
string msg = ReadColumn(row, "msg", "message");
|
||||
throw new Exception(string.IsNullOrWhiteSpace(msg) ? "路线不可用" : msg);
|
||||
}
|
||||
|
||||
return new LGWEB_RouteInfo
|
||||
{
|
||||
RouteCode = ReadColumn(row, "路线编码"),
|
||||
StartPosition = ReadColumn(row, "起点位置"),
|
||||
MidPosition = ReadColumn(row, "中间位置"),
|
||||
OriginalEndPosition = ReadColumn(row, "原终点位置", "终点位置"),
|
||||
ActualEndPosition = ReadColumn(row, "实际终点位置"),
|
||||
InterfaceName = FirstText(ReadColumn(row, "调用接口"), "AddTaskFromMes"),
|
||||
BusinessType = ReadColumn(row, "业务类型"),
|
||||
TriggerMode = ReadColumn(row, "触发方式"),
|
||||
SourceWorkStation = ReadColumn(row, "源工位号"),
|
||||
TargetWorkStation = ReadColumn(row, "目标工位号"),
|
||||
RouteMessage = ReadColumn(row, "msg", "message")
|
||||
};
|
||||
}
|
||||
|
||||
private static void SaveDispatchResult(LGWEB_DispatchRequest request, LGWEB_RouteInfo route, string requestTaskId,
|
||||
string startPosition, string midPosition, string endPosition, string materialCode, LGAGV_CallResult agvResult)
|
||||
{
|
||||
var param = new SqlParameter[]
|
||||
{
|
||||
new SqlParameter("@路线编码", request.routeCode ?? ""),
|
||||
new SqlParameter("@业务类型", route.BusinessType ?? ""),
|
||||
new SqlParameter("@触发方式", string.IsNullOrWhiteSpace(route.TriggerMode) ? "WEB" : route.TriggerMode),
|
||||
new SqlParameter("@订单号", request.orderNo ?? ""),
|
||||
new SqlParameter("@产品编码", FirstText(request.productCode, request.materialCode)),
|
||||
new SqlParameter("@产品型号", request.productModel ?? ""),
|
||||
new SqlParameter("@器具号", request.containerNo ?? ""),
|
||||
new SqlParameter("@requestTaskId", requestTaskId ?? ""),
|
||||
new SqlParameter("@起点位置", startPosition ?? ""),
|
||||
new SqlParameter("@中间位置", midPosition ?? ""),
|
||||
new SqlParameter("@终点位置", endPosition ?? ""),
|
||||
new SqlParameter("@原终点位置", route.OriginalEndPosition ?? ""),
|
||||
new SqlParameter("@materialCode", materialCode ?? ""),
|
||||
new SqlParameter("@调用接口", route.InterfaceName ?? ""),
|
||||
new SqlParameter("@操作人工号", request.operatorCode ?? ""),
|
||||
new SqlParameter("@操作人姓名", request.operatorName ?? ""),
|
||||
new SqlParameter("@备注", request.remark ?? ""),
|
||||
new SqlParameter("@是否成功", agvResult.Success ? 1 : 2),
|
||||
new SqlParameter("@错误信息", agvResult.Success ? "" : (agvResult.Message ?? ""))
|
||||
};
|
||||
ExecuteResultProcedure("LG_AGV_库位Moby_下发任务", ref param);
|
||||
}
|
||||
|
||||
private static string ReadColumn(DataRow row, params string[] columnNames)
|
||||
{
|
||||
foreach (string columnName in columnNames)
|
||||
{
|
||||
if (row.Table.Columns.Contains(columnName))
|
||||
{
|
||||
return row[columnName]?.ToString() ?? "";
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private static string FirstText(params string[] values)
|
||||
{
|
||||
foreach (string value in values)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(value))
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private static void ExecuteResultProcedure(string procedureName, ref SqlParameter[] param)
|
||||
{
|
||||
DataLinkMesWork2.DataAccess2.ExecuteStoredProcedure(procedureName, ref param, out DataTable dt, out string errMessage);
|
||||
if (!string.IsNullOrEmpty(errMessage))
|
||||
{
|
||||
throw new Exception(errMessage);
|
||||
}
|
||||
if (dt != null && dt.Rows.Count > 0 && dt.Columns.Contains("result") && dt.Rows[0]["result"].ToString() != "1")
|
||||
{
|
||||
string msg = dt.Columns.Contains("msg") ? dt.Rows[0]["msg"].ToString() : "存储过程执行失败";
|
||||
throw new Exception(msg);
|
||||
}
|
||||
}
|
||||
|
||||
private class LGWEB_RouteInfo
|
||||
{
|
||||
public string RouteCode { get; set; }
|
||||
public string StartPosition { get; set; }
|
||||
public string MidPosition { get; set; }
|
||||
public string OriginalEndPosition { get; set; }
|
||||
public string ActualEndPosition { get; set; }
|
||||
public string InterfaceName { get; set; }
|
||||
public string BusinessType { get; set; }
|
||||
public string TriggerMode { get; set; }
|
||||
public string SourceWorkStation { get; set; }
|
||||
public string TargetWorkStation { get; set; }
|
||||
public string RouteMessage { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
34
Interface_WebAPI/SlMesDbIterface/WebAPI/WEB/LGWEB_Models.cs
Normal file
34
Interface_WebAPI/SlMesDbIterface/WebAPI/WEB/LGWEB_Models.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
namespace MisDataSaveDate
|
||||
{
|
||||
/// <summary>
|
||||
/// 临工AGV网页按钮调度请求。
|
||||
/// </summary>
|
||||
public class LGWEB_DispatchRequest
|
||||
{
|
||||
public string routeCode { get; set; }
|
||||
public string requestTaskId { get; set; }
|
||||
public string startPosition { get; set; }
|
||||
public string midPosition { get; set; }
|
||||
public string materialCode { get; set; }
|
||||
public string productCode { get; set; }
|
||||
public string productModel { get; set; }
|
||||
public string containerNo { get; set; }
|
||||
public string orderNo { get; set; }
|
||||
public string operatorCode { get; set; }
|
||||
public string operatorName { get; set; }
|
||||
public string remark { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 临工AGV网页按钮放行请求。
|
||||
/// </summary>
|
||||
public class LGWEB_AllowLeaveRequest
|
||||
{
|
||||
public string requestId { get; set; }
|
||||
public string position { get; set; }
|
||||
public string agvNo { get; set; }
|
||||
public string operatorCode { get; set; }
|
||||
public string operatorName { get; set; }
|
||||
public string remark { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -80,7 +80,7 @@ namespace MisDataSaveDate
|
||||
throw new Exception("OperAtion_JobStart 缺少必要参数:工位号、订单号或工件编号");
|
||||
}
|
||||
|
||||
CALL_Inerface_DataHandle.CALL_Inerface_JobStart(workStation1, orderNo1, workpieceNo1);
|
||||
CALL_Inerface_DataHandle.CALL_Inerface_JobStart(workStation1, workpieceNo1, orderNo1);
|
||||
break;
|
||||
|
||||
case "OperAtion_JobFinished":
|
||||
@@ -98,7 +98,7 @@ namespace MisDataSaveDate
|
||||
throw new Exception("OperAtion_JobFinished 缺少必要参数:工位号、订单号或工件编号");
|
||||
}
|
||||
|
||||
CALL_Inerface_DataHandle.CALL_Inerface_JobFinished(workStation2, orderNo2, workpieceNo2);
|
||||
CALL_Inerface_DataHandle.CALL_Inerface_JobFinished(workStation2, workpieceNo2, orderNo2);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -408,4 +408,4 @@ namespace MisDataSaveDate
|
||||
return retString;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user