定时同步rcs货架绑定关系

This commit is contained in:
hehaibing-1996
2025-03-06 11:21:21 +08:00
parent fb573cdb5b
commit 66f700c560
3 changed files with 195 additions and 3 deletions

View File

@ -85,7 +85,7 @@ namespace WCS.BLL.Manager
if (isUpdate)
{
tasks[i].ModifyTime = DateTime.Now;
if (tasks[i].TaskStatus != TaskStatusEnum. && tasks[i].TaskStatus != TaskStatusEnum. )
if (tasks[i].TaskStatus != TaskStatusEnum. && tasks[i].TaskStatus != TaskStatusEnum.)
{
tasks[i].AgvStatus = "-";
}
@ -108,6 +108,101 @@ namespace WCS.BLL.Manager
}
});
#endregion
#region :
Task.Run(() =>
{
while (true)
{
try
{
var url = @"http://192.168.18.150:8181/rcms/services/rest/hikRpcService/syncMapDatas";
var data = new AGVSyncMapDatasRequest();
var result = ApiHelp.GetDataFromHttp<AGVSyncMapDatasResponse>(url, data, "POST", true);
if (result != null && result.data != null && result.data.Count > 0)
{
//获取RCS地图上所有的货架
var rcsDatas = result.data.Where(t => !string.IsNullOrEmpty(t.podCode))
.Select(t => new
{
ShelfCode = t.podCode,
LocationCode = t.positionCode,
})
.Distinct()
.ToList();
var shelfCodesInRcs = rcsDatas.Select(t => t.ShelfCode).Distinct().ToList();
var locationCodeInRcs = rcsDatas.Select(t => t.LocationCode).Distinct().ToList();
//获取位置
var Locations = DbHelp.db.Queryable<LocationInfo>()
.Where(t => locationCodeInRcs.Contains(t.LocationCode))
.ToList();
//更新货架的信息
var shelfs = DbHelp.db.Queryable<ShelfInfo>()
.Where(t => t.TransStatus == TransStatusEnum.)
.ToList();
foreach (var shelf in shelfs)
{
var currentLocationId = shelf.CurrentLocationId;
//RCS中有货架储位信息
if (shelfCodesInRcs.Contains(shelf.ShelfCode))
{
var rcsData = rcsDatas.Where(t => t.ShelfCode == shelf.ShelfCode).FirstOrDefault();
if (rcsData == null)
{
//此情况先按兵不动
continue;
}
var location = Locations.Where(t => t.LocationCode == rcsData.LocationCode).FirstOrDefault();
//货架绑定在我系统中未配置的点位上
if (location == null)
{
shelf.CurrentLocationId = 0;
shelf.CurrentLocaiotnCode = string.Empty;
}
//货架绑定在系统中已配置的点位上
else
{
shelf.CurrentLocationId = location.Id;
shelf.CurrentLocaiotnCode = location.LocationCode;
}
}
//RCS中没有货架储位的信息
else
{
shelf.CurrentLocationId = 0;
shelf.CurrentLocaiotnCode = string.Empty;
}
//只更新产生变化的 缩小更新范围
if (currentLocationId != shelf.CurrentLocationId)
{
shelf.IsSelected = true;
}
}
shelfs = shelfs.Where(t => t.IsSelected).ToList();
if (shelfs != null && shelfs.Count > 0)
{
DbHelp.db.Updateable(shelfs)
.UpdateColumns(t => new { t.CurrentLocationId, t.CurrentLocaiotnCode })
//.Where(t => t.TransStatus == TransStatusEnum.静止)
.ExecuteCommand();
}
}
}
catch (Exception ex)
{
Logs.Write("【定时任务】定时同步货架绑定情况异常:" + ex.Message);
}
//每60秒同步一次
Thread.Sleep(30000);
}
});
#endregion
}
public static object lockFlag = new object();
@ -386,8 +481,8 @@ namespace WCS.BLL.Manager
}
var dataItem = response?.data.Where(t => t.robotCode == agvCode).FirstOrDefault();
if (dataItem == null)
{
continue ;
{
continue;
}
var str = string.Empty;

View File

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace WCS.Model.ApiModel.AGV
{
//AGV同步地图数据
public class AGVSyncMapDatasRequest
{
/// <summary>
/// 请求码 每一次请求唯一
/// </summary>
public string reqCode { get; set; } = Guid.NewGuid().ToString().Replace("-", "");
/// <summary>
/// 请求时间
/// </summary>
public string reqTime { get; set; } = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
/// <summary>
/// 地图简称 RCS系统地图中有
/// </summary>
public string mapShortName = "STZL";
public string dataTyp = "";
public string tokenCode = "";
public string clientCode = "wcs";
}
}

View File

@ -0,0 +1,66 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace WCS.Model.ApiModel.AGV
{
//AGV同步地图数据
//如果好用,请收藏地址,帮忙分享。
public class AGVSyncMapDatasResponseDataItem
{
public string cooX { get; set; }
/// <summary>
///
/// </summary>
public string cooY { get; set; }
/// <summary>
///
/// </summary>
public string dataTyp { get; set; }
public string direction { get; set; }
public string mapCode { get; set; }
/// <summary>
///
/// </summary>
public string mapDataCode { get; set; }
/// <summary>
///
/// </summary>
public string podCode { get; set; }
/// <summary>
///
/// </summary>
public string positionCode { get; set; }
}
public class AGVSyncMapDatasResponse
{
/// <summary>
///
/// </summary>
public string code { get; set; }
/// <summary>
///
/// </summary>
public List<AGVSyncMapDatasResponseDataItem> data { get; set; }
/// <summary>
///
/// </summary>
public string interrupt { get; set; }
/// <summary>
/// 成功
/// </summary>
public string message { get; set; }
/// <summary>
///
/// </summary>
public string msgErrCode { get; set; }
/// <summary>
///
/// </summary>
public string reqCode { get; set; }
}
}