1.任务状态等信息同步回wcs 2.货架绑定解绑接入rcs

This commit is contained in:
hehaibing-1996
2025-02-22 18:52:46 +08:00
parent cc8e2029b4
commit ddfbe18624
7 changed files with 320 additions and 125 deletions

View File

@ -1,4 +1,5 @@
using System;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
@ -25,7 +26,7 @@ namespace WCS.BLL.Manager
while (true)
{
//每5秒同步一次
Thread.Sleep(5000);
Thread.Sleep(3000);
try
{
var url = @"http://192.168.18.150:8181/rcms/services/rest/hikRpcService/queryTaskStatus";
@ -61,6 +62,23 @@ namespace WCS.BLL.Manager
Enum.TryParse<TaskStatusEnum>(responseData.taskStatus, out TaskStatusEnum status);
isUpdate = true;
tasks[i].TaskStatus = status;
//取消任务时 货架数据需要更新
if (status == TaskStatusEnum.)
{
var shelf = DbHelp.db.Queryable<ShelfInfo>()
.Where(t => t.ShelfCode == tasks[i].ShelfCode)
.Where(t => t.CurrentLocationId == tasks[i].StratLocationId && t.DestinationLocationId == tasks[i].EndLocationId)
.First();
if (shelf != null)
{
shelf.DestinationLocationId = 0;
shelf.DestinationLocaiotnCode = string.Empty;
shelf.TransStatus = TransStatusEnum.;
DbHelp.db.Updateable(shelf).ExecuteCommand();
}
}
}
if (isUpdate)
{
@ -136,6 +154,11 @@ namespace WCS.BLL.Manager
}
}
/// <summary>
/// RCS取消任务
/// </summary>
/// <param name="agvTask"></param>
/// <returns></returns>
public static AGVResponseModel CancelTask(AgvTask agvTask)
{
try
@ -153,8 +176,10 @@ namespace WCS.BLL.Manager
var response = ApiHelp.GetDataFromHttp<AGVResponseModel>(url, body, "POST", true);
if (response.code == "0" && response.message == "成功")
{
agvTask.TaskStatus = Model.ApiModel.AGV.TaskStatusEnum.;
DbHelp.db.Updateable(agvTask).ExecuteCommand();
//取消会统一在后台线程更新
//agvTask.TaskStatus = Model.ApiModel.AGV.TaskStatusEnum.取消完成;
//DbHelp.db.Updateable(agvTask).ExecuteCommand();
}
return response;
}
@ -168,5 +193,55 @@ namespace WCS.BLL.Manager
};
}
}
/// <summary>
/// RCS货架绑定 解绑
/// </summary>
/// <param name="agvTask"></param>
/// <returns></returns>
public static AGVResponseModel BindPodAndBerth(string shelfCode,string locationCode , BindPodAndBerthMethod bindPodAndBerthMethod)
{
try
{
//货架绑定解绑地址
var url = @"http://192.168.18.150:8181/rcms/services/rest/hikRpcService/bindPodAndBerth";
//任务只允许一个一个发送
lock (lockFlag)
{
var body = new AGVBindPodAndBerthRequest()
{
podCode = shelfCode,
positionCode = locationCode,
pointCode = locationCode,
indBind = ((int)bindPodAndBerthMethod).ToString(),
};
var response = ApiHelp.GetDataFromHttp<AGVResponseModel>(url, body, "POST", true);
//if (response.code == "0" && response.message == "成功")
//{
//}
return response;
}
}
catch (Exception ex)
{
return new AGVResponseModel()
{
code = "-1",
message = $"发生异常:{ex.Message}"
};
}
}
}
/// <summary>
/// 解绑或者绑定
/// </summary>
public enum BindPodAndBerthMethod
{
= 0,
= 1,
}
}

View File

@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WCS.Model;
using WCS.Model.ApiModel.PDAMatBind;
using WCS.Model.WebSocketModel;
namespace WCS.BLL.Services.IService
{
/// <summary>
/// Pda物料绑定
/// </summary>
public interface IPDAMatBindService
{
public Task<ResponseCommon> callEmptyShelf(BindMatDetailRequest request);
}
}

View File

@ -0,0 +1,125 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WCS.BLL.Manager;
using WCS.BLL.Services.IService;
using WCS.DAL.Db;
using WCS.DAL.DbModels;
using WCS.Model;
using WCS.Model.ApiModel.PDAMatBind;
namespace WCS.BLL.Services.Service
{
public class PDAMatBindService : IPDAMatBindService
{
public async Task<ResponseCommon> callEmptyShelf(BindMatDetailRequest request)
{
try
{
#region
//判断参数
if (request.LocationId == 0 || string.IsNullOrEmpty(request.LocationCode))
{
return new ResponseCommon()
{
Code = 201,
Message = "工位或工位编码为空!\r\n请重新扫工位码",
Data = null,
};
}
#endregion
#region
//获取是否存在当前工位
var endLocation = await DbHelp.db.Queryable<LocationInfo>()
.Where(t => t.Id == request.LocationId)
.Where(t => t.IsEnable == true)
.FirstAsync();
if (endLocation == null)
{
return new ResponseCommon()
{
Code = 201,
Message = $"工位[{request.LocationCode}]不存在或已被禁用!\r\n请联系系统管理人员维护工位信息",
Data = null,
};
}
//获取当前工位的货架
var shelf = await DbHelp.db.Queryable<ShelfInfo>()
.Where(t => t.CurrentLocationId == endLocation.Id && t.TransStatus == TransStatusEnum.
|| t.DestinationLocationId == endLocation.Id && t.TransStatus == TransStatusEnum.)//解决产线人员 呼叫后货架未到的时候绑定的问题
.Where(t => t.IsEnable == true)
.FirstAsync();
if (shelf != null)
{
return new ResponseCommon()
{
Code = 205,
Message = $"货架【{shelf.ShelfCode}】在工位上或即将在工位上,请勿重复呼叫!",
Data = null,
};
}
#endregion
//获取空货架进行呼叫
shelf = await DbHelp.db.Queryable<ShelfInfo>()
.Where(t => t.TransStatus == TransStatusEnum. && t.CurrentLocationId != 0)
.Where(t => t.IsEnable == true)
.FirstAsync();
if (shelf == null)
{
return new ResponseCommon()
{
Code = 201,
Message = $"不存在空货架!",
Data = null,
};
}
var startLocation = await DbHelp.db.Queryable<LocationInfo>()
.Where(t => t.Id == shelf.CurrentLocationId)
.Where(t => t.IsEnable == true)
.FirstAsync();
var response = AGVManager.GenAgvSchedulingTask(startLocation, endLocation, shelf.ShelfCode, request.UserName);
if (response.code == "0" && response.message == "成功")
{
//更新货架位置信息
shelf.TransStatus = TransStatusEnum.;
shelf.DestinationLocationId = endLocation.Id;
shelf.DestinationLocaiotnCode = endLocation.LocationCode;
DbHelp.db.Updateable(shelf).ExecuteCommand();
return new ResponseCommon()
{
Code = 200,
Message = "success",
Data = null,
};
}
else
{
return new ResponseCommon()
{
Code = 201,
Message = $"海康RCS返回{response.message}",
Data = null,
};
}
}
catch (Exception ex)
{
return new ResponseCommon()
{
Code = 201,
Message = ex.Message,
Data = null,
};
}
}
}
}

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WCS.BLL.Manager;
using WCS.BLL.Services.IService;
using WCS.DAL.Db;
using WCS.DAL.DbModels;
@ -146,19 +147,35 @@ namespace WCS.BLL.Services.Service
};
}
//开始绑定
shelfInfo.CurrentLocaiotnCode = locationInfo.LocationCode;
shelfInfo.CurrentLocationId = locationInfo.Id;
shelfInfo.TransStatus = TransStatusEnum.;
DbHelp.db.Updateable(shelfInfo).ExecuteCommand();
//返回成功
return new ResponseCommon()
//调用RCS绑定
var rcsResponse = AGVManager.BindPodAndBerth(shelfInfo.ShelfCode, locationInfo.LocationCode, BindPodAndBerthMethod.);
if (rcsResponse.code == "0")
{
Code = 200,
Message = "success",
Data = null,
};
//开始绑定
shelfInfo.CurrentLocaiotnCode = locationInfo.LocationCode;
shelfInfo.CurrentLocationId = locationInfo.Id;
shelfInfo.DestinationLocationId = 0;
shelfInfo.DestinationLocaiotnCode = string.Empty;
shelfInfo.TransStatus = TransStatusEnum.;
DbHelp.db.Updateable(shelfInfo).ExecuteCommand();
//返回成功
return new ResponseCommon()
{
Code = 200,
Message = "success",
Data = null,
};
}
else
{
return new ResponseCommon()
{
Code = 201,
Message = $"RCS返回{rcsResponse.message}",
Data = null,
};
}
}
catch (Exception ex)
{
@ -198,21 +215,35 @@ namespace WCS.BLL.Services.Service
};
}
//开始解绑
shelfInfo.CurrentLocationId = 0;
shelfInfo.CurrentLocaiotnCode = string.Empty;
shelfInfo.DestinationLocationId = 0;
shelfInfo.DestinationLocaiotnCode = string.Empty;
shelfInfo.TransStatus = TransStatusEnum.;
DbHelp.db.Updateable(shelfInfo).ExecuteCommand();
//返回成功
return new ResponseCommon()
//调用RCS解绑
var rcsResponse = AGVManager.BindPodAndBerth(shelfInfo.ShelfCode, shelfInfo.CurrentLocaiotnCode, BindPodAndBerthMethod.);
if (rcsResponse.code == "0")
{
Code = 200,
Message = "success",
Data = null,
};
//开始解绑
shelfInfo.CurrentLocationId = 0;
shelfInfo.CurrentLocaiotnCode = string.Empty;
shelfInfo.DestinationLocationId = 0;
shelfInfo.DestinationLocaiotnCode = string.Empty;
shelfInfo.TransStatus = TransStatusEnum.;
DbHelp.db.Updateable(shelfInfo).ExecuteCommand();
//返回成功
return new ResponseCommon()
{
Code = 200,
Message = "success",
Data = null,
};
}
else
{
return new ResponseCommon()
{
Code = 201,
Message = $"RCS返回{rcsResponse.message}",
Data = null,
};
}
}
catch (Exception ex)
{

View File

@ -0,0 +1,34 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace WCS.Model.ApiModel.AGV
{
public class AGVBindPodAndBerthRequest
{
/// <summary>
/// 请求码 每一次请求唯一
/// </summary>
public string reqCode { get; set; } = Guid.NewGuid().ToString().Replace("-", "");
/// <summary>
/// 货架编号
/// </summary>
public string podCode { get; set; }
/// <summary>
/// 点位码
/// </summary>
public string pointCode { get; set; }
/// <summary>
/// 解绑或者绑定 "1":绑定, "0":解绑
/// </summary>
public string indBind { get; set; }
/// <summary>
/// 位置编号
/// </summary>
public string positionCode { get; set; }
}
}

View File

@ -19,11 +19,11 @@ namespace WCS.WebApi.Controllers
[Route("[controller]")]
public class PDAMatBindController : ControllerBase
{
public IWarningService _warningService { get; set; }
public IPDAMatBindService _PDAMatBindService { get; set; }
public PDAMatBindController(IWarningService warningService)
public PDAMatBindController(IPDAMatBindService PDAMatBindService)
{
_warningService = warningService;
_PDAMatBindService = PDAMatBindService;
}
[Route("getShelfInfoByLocationCode")]
@ -275,98 +275,7 @@ namespace WCS.WebApi.Controllers
{
try
{
#region
//判断参数
if (request.LocationId == 0 || string.IsNullOrEmpty(request.LocationCode))
{
return new ResponseCommon()
{
Code = 201,
Message = "工位或工位编码为空!\r\n请重新扫工位码",
Data = null,
};
}
#endregion
#region
//获取是否存在当前工位
var endLocation = await DbHelp.db.Queryable<LocationInfo>()
.Where(t => t.Id == request.LocationId)
.Where(t => t.IsEnable == true)
.FirstAsync();
if (endLocation == null)
{
return new ResponseCommon()
{
Code = 201,
Message = $"工位[{request.LocationCode}]不存在或已被禁用!\r\n请联系系统管理人员维护工位信息",
Data = null,
};
}
//获取当前工位的货架
var shelf = await DbHelp.db.Queryable<ShelfInfo>()
.Where(t => t.CurrentLocationId == endLocation.Id && t.TransStatus == TransStatusEnum.
|| t.DestinationLocationId == endLocation.Id && t.TransStatus == TransStatusEnum.)//解决产线人员 呼叫后货架未到的时候绑定的问题
.Where(t => t.IsEnable == true)
.FirstAsync();
if (shelf != null)
{
return new ResponseCommon()
{
Code = 205,
Message = $"货架【{shelf.ShelfCode}】在工位上或即将在工位上,请勿重复呼叫!",
Data = null,
};
}
#endregion
//获取空货架进行呼叫
shelf = await DbHelp.db.Queryable<ShelfInfo>()
.Where(t => t.TransStatus == TransStatusEnum. && t.CurrentLocationId != 0)
.Where(t => t.IsEnable == true)
.FirstAsync();
if (shelf == null)
{
return new ResponseCommon()
{
Code = 201,
Message = $"不存在空货架!",
Data = null,
};
}
var startLocation = await DbHelp.db.Queryable<LocationInfo>()
.Where(t => t.Id == shelf.CurrentLocationId)
.Where(t => t.IsEnable == true)
.FirstAsync();
var response = AGVManager.GenAgvSchedulingTask(startLocation, endLocation,shelf.ShelfCode,request.UserName);
if (response.code == "0" && response.message == "成功")
{
//更新货架位置信息
shelf.TransStatus = TransStatusEnum.;
shelf.DestinationLocationId = endLocation.Id;
shelf.DestinationLocaiotnCode = endLocation.LocationCode;
DbHelp.db.Updateable(shelf).ExecuteCommand();
return new ResponseCommon()
{
Code = 200,
Message = "success",
Data = null,
};
}
else
{
return new ResponseCommon()
{
Code = 201,
Message = $"海康RCS返回{response.message}",
Data = null,
};
}
return await _PDAMatBindService.callEmptyShelf(request);
}
catch (Exception ex)
{

View File

@ -92,6 +92,8 @@ namespace WebApi
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EBA1A2><EFBFBD>ɵ<EFBFBD><C9B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><C3B5><EFBFBD>ģʽ
builder.Services.AddSingleton<IGenerateService, GenerateService>();
builder.Services.AddSingleton<IPDAMatBindService, PDAMatBindService>();
var app = builder.Build();
app.UseMiddleware<RequestResponseLoggingMiddleware>();