定时同步rcs货架绑定关系
This commit is contained in:
@ -85,7 +85,7 @@ namespace WCS.BLL.Manager
|
|||||||
if (isUpdate)
|
if (isUpdate)
|
||||||
{
|
{
|
||||||
tasks[i].ModifyTime = DateTime.Now;
|
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 = "-";
|
tasks[i].AgvStatus = "-";
|
||||||
}
|
}
|
||||||
@ -108,6 +108,101 @@ namespace WCS.BLL.Manager
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
#endregion
|
#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();
|
public static object lockFlag = new object();
|
||||||
@ -386,8 +481,8 @@ namespace WCS.BLL.Manager
|
|||||||
}
|
}
|
||||||
var dataItem = response?.data.Where(t => t.robotCode == agvCode).FirstOrDefault();
|
var dataItem = response?.data.Where(t => t.robotCode == agvCode).FirstOrDefault();
|
||||||
if (dataItem == null)
|
if (dataItem == null)
|
||||||
{
|
{
|
||||||
continue ;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
var str = string.Empty;
|
var str = string.Empty;
|
||||||
|
31
WCS.Model/ApiModel/AGV/AGVSyncMapDatasRequest.cs
Normal file
31
WCS.Model/ApiModel/AGV/AGVSyncMapDatasRequest.cs
Normal 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";
|
||||||
|
}
|
||||||
|
}
|
66
WCS.Model/ApiModel/AGV/AGVSyncMapDatasResponse.cs
Normal file
66
WCS.Model/ApiModel/AGV/AGVSyncMapDatasResponse.cs
Normal 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; }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue
Block a user