1
This commit is contained in:
@@ -71,6 +71,6 @@ namespace Tnb.WarehouseMgr.Interfaces
|
|||||||
/// /// <param name="input"></param>
|
/// /// <param name="input"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
Task TaskExecuteAfter(TaskExecuteAfterUpInput input);
|
Task TaskExecuteAfter(TaskExecuteAfterUpInput input);
|
||||||
|
Func<string,Task> AddUnExecuteTask { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,6 +55,8 @@ namespace Tnb.WarehouseMgr
|
|||||||
public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc();
|
public OverideVisualDevFunc OverideFuncs { get; } = new OverideVisualDevFunc();
|
||||||
private readonly ChannelWriter<NotifyMessage> _channelWriter;
|
private readonly ChannelWriter<NotifyMessage> _channelWriter;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public BaseWareHouseService(ChannelWriter<NotifyMessage>? channelWriter = default)
|
public BaseWareHouseService(ChannelWriter<NotifyMessage>? channelWriter = default)
|
||||||
{
|
{
|
||||||
_channelWriter = channelWriter;
|
_channelWriter = channelWriter;
|
||||||
|
|||||||
@@ -254,6 +254,11 @@ namespace Tnb.WarehouseMgr
|
|||||||
{
|
{
|
||||||
await _elevatorControlService.SendOpenCloseCmd(elevatorQueueItem.elevator_code, 4); //向电梯发送前门关门指令
|
await _elevatorControlService.SendOpenCloseCmd(elevatorQueueItem.elevator_code, 4); //向电梯发送前门关门指令
|
||||||
await _db.Deleteable(elevatorQueueItem).ExecuteCommandAsync();
|
await _db.Deleteable(elevatorQueueItem).ExecuteCommandAsync();
|
||||||
|
elevatorQueueItem = await _db.Queryable<WmsElevatorUnexecute>().FirstAsync(it => disTasks.Select(x => x.id).Contains(it.distask_id) && it.task_status == "待执行");
|
||||||
|
if (!elevatorQueueItem?.elevator_code.IsNullOrEmpty() ?? false)
|
||||||
|
{
|
||||||
|
await (_wareHouseService.AddUnExecuteTask?.Invoke(elevatorQueueItem?.elevator_code!) ?? Task.CompletedTask);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -284,8 +289,9 @@ namespace Tnb.WarehouseMgr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
Log.Error("任务状态上报出现错误", ex);
|
||||||
return await ToApiResult(HttpStatusCode.InternalServerError, "请重试!");
|
return await ToApiResult(HttpStatusCode.InternalServerError, "请重试!");
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,45 +4,25 @@ using System.Diagnostics;
|
|||||||
using System.Dynamic;
|
using System.Dynamic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Linq.Expressions;
|
using System.Linq.Expressions;
|
||||||
using System.Reflection;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using System.Text;
|
|
||||||
using System.Text.Encodings.Web;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Aliyun.Credentials.Http;
|
|
||||||
using Aop.Api.Domain;
|
|
||||||
using Aspose.Cells.Drawing;
|
|
||||||
using JNPF;
|
using JNPF;
|
||||||
using JNPF.Common.Const;
|
|
||||||
using JNPF.Common.Contracts;
|
using JNPF.Common.Contracts;
|
||||||
using JNPF.Common.Core.Manager;
|
using JNPF.Common.Core.Manager;
|
||||||
using JNPF.Common.Enums;
|
using JNPF.Common.Enums;
|
||||||
using JNPF.Common.Extension;
|
using JNPF.Common.Extension;
|
||||||
using JNPF.Common.Manager;
|
using JNPF.Common.Manager;
|
||||||
using JNPF.Common.Security;
|
using JNPF.Common.Security;
|
||||||
using JNPF.DependencyInjection;
|
|
||||||
using JNPF.DynamicApiController;
|
|
||||||
using JNPF.Extras.CollectiveOAuth.Config;
|
|
||||||
using JNPF.FriendlyException;
|
using JNPF.FriendlyException;
|
||||||
using JNPF.Logging;
|
using JNPF.Logging;
|
||||||
using JNPF.Systems.Entitys.Dto.Module;
|
|
||||||
using JNPF.Systems.Interfaces.System;
|
using JNPF.Systems.Interfaces.System;
|
||||||
using Mapster;
|
using Mapster;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.CodeAnalysis;
|
using Microsoft.CodeAnalysis;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Polly.Timeout;
|
//using NPOI.SS.Formula.Functions;
|
||||||
using Senparc.NeuChar.Helpers;
|
|
||||||
using Senparc.Weixin.Work.AdvancedAPIs.OaDataOpen;
|
|
||||||
using Spire.Pdf.Widget;
|
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
|
||||||
using Tnb.BasicData.Entities;
|
using Tnb.BasicData.Entities;
|
||||||
using Tnb.BasicData.Entities.Enums;
|
|
||||||
using Tnb.Common.Extension;
|
using Tnb.Common.Extension;
|
||||||
using Tnb.Common.Utils;
|
using Tnb.Common.Utils;
|
||||||
using Tnb.ProductionMgr.Entities.Dto.PrdManage;
|
|
||||||
using Tnb.WarehouseMgr.Entities;
|
using Tnb.WarehouseMgr.Entities;
|
||||||
using Tnb.WarehouseMgr.Entities.Attributes;
|
using Tnb.WarehouseMgr.Entities.Attributes;
|
||||||
using Tnb.WarehouseMgr.Entities.Configs;
|
using Tnb.WarehouseMgr.Entities.Configs;
|
||||||
@@ -51,7 +31,6 @@ using Tnb.WarehouseMgr.Entities.Dto;
|
|||||||
using Tnb.WarehouseMgr.Entities.Dto.Inputs;
|
using Tnb.WarehouseMgr.Entities.Dto.Inputs;
|
||||||
using Tnb.WarehouseMgr.Entities.Entity;
|
using Tnb.WarehouseMgr.Entities.Entity;
|
||||||
using Tnb.WarehouseMgr.Entities.Enums;
|
using Tnb.WarehouseMgr.Entities.Enums;
|
||||||
using Tnb.WarehouseMgr.Entities.Exceptions;
|
|
||||||
using Tnb.WarehouseMgr.Interfaces;
|
using Tnb.WarehouseMgr.Interfaces;
|
||||||
|
|
||||||
namespace Tnb.WarehouseMgr
|
namespace Tnb.WarehouseMgr
|
||||||
@@ -68,7 +47,7 @@ namespace Tnb.WarehouseMgr
|
|||||||
private readonly ICacheManager _cacheManager;
|
private readonly ICacheManager _cacheManager;
|
||||||
private readonly IElevatorControlService _elevatorControlService;
|
private readonly IElevatorControlService _elevatorControlService;
|
||||||
private static Dictionary<string, object> _elevatorMap = new Dictionary<string, object>();
|
private static Dictionary<string, object> _elevatorMap = new Dictionary<string, object>();
|
||||||
|
public Func<string, Task> AddUnExecuteTask { get; set; }
|
||||||
|
|
||||||
public WareHouseService(ISqlSugarRepository<WmsInstockH> repository, IDictionaryDataService dictionaryDataService,
|
public WareHouseService(ISqlSugarRepository<WmsInstockH> repository, IDictionaryDataService dictionaryDataService,
|
||||||
IBillRullService billRullService, IUserManager userManager, ICacheManager cacheManager, IElevatorControlService elevatorControlService)
|
IBillRullService billRullService, IUserManager userManager, ICacheManager cacheManager, IElevatorControlService elevatorControlService)
|
||||||
@@ -79,6 +58,14 @@ namespace Tnb.WarehouseMgr
|
|||||||
_userManager = userManager;
|
_userManager = userManager;
|
||||||
_cacheManager = cacheManager;
|
_cacheManager = cacheManager;
|
||||||
_elevatorControlService = elevatorControlService;
|
_elevatorControlService = elevatorControlService;
|
||||||
|
AddUnExecuteTask = async code =>
|
||||||
|
{
|
||||||
|
(int sysStatus, int runStatus, int floorNo, int doorStatus, int agvStatus) = await _elevatorControlService.GetElevatorStatus(code, CancellationToken.None);
|
||||||
|
if (sysStatus.ToEnum<EnumSysStatus>() == EnumSysStatus.正常状态 && runStatus.ToEnum<EnumRunStatus>() == EnumRunStatus.停梯)
|
||||||
|
{
|
||||||
|
await _elevatorControlService.CallLift(code, 5, CancellationToken.None);
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -359,6 +346,37 @@ namespace Tnb.WarehouseMgr
|
|||||||
|
|
||||||
var endLocCodes = disTasks.Select(it => (it.endlocation_code, it.device_id, it.id)).Where(it => it.endlocation_code.StartsWith("DT", StringComparison.OrdinalIgnoreCase)).ToList();
|
var endLocCodes = disTasks.Select(it => (it.endlocation_code, it.device_id, it.id)).Where(it => it.endlocation_code.StartsWith("DT", StringComparison.OrdinalIgnoreCase)).ToList();
|
||||||
if (endLocCodes?.Count > 0)
|
if (endLocCodes?.Count > 0)
|
||||||
|
{
|
||||||
|
await CallingLanding(endLocCodes);
|
||||||
|
}
|
||||||
|
//调用AGV创建任务链接口
|
||||||
|
await AgvDispatch(disTasks, agvCts.Token);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex) when (ex is HttpRequestException hReqEx)
|
||||||
|
{
|
||||||
|
agvCts.Cancel();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Log.Error("生成预任务执行时出现错误", ex);
|
||||||
|
await db.Ado.RollbackTranAsync();
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
agvCts.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// 呼梯操作
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="endLocCodes"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private async Task CallingLanding(List<(string endlocation_code, string device_id, string id)> endLocCodes)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
var item = endLocCodes.FirstOrDefault();
|
var item = endLocCodes.FirstOrDefault();
|
||||||
if (_elevatorMap.ContainsKey(item.device_id))
|
if (_elevatorMap.ContainsKey(item.device_id))
|
||||||
@@ -371,6 +389,7 @@ namespace Tnb.WarehouseMgr
|
|||||||
await _elevatorControlService.WriteTagAsync(devName, ElevatorConsts.AGVControl, 1);
|
await _elevatorControlService.WriteTagAsync(devName, ElevatorConsts.AGVControl, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
{
|
||||||
foreach (var (_, devId, disTaskId) in endLocCodes)
|
foreach (var (_, devId, disTaskId) in endLocCodes)
|
||||||
{
|
{
|
||||||
WmsElevatorUnexecute elevatorQueueItem = new()
|
WmsElevatorUnexecute elevatorQueueItem = new()
|
||||||
@@ -388,14 +407,36 @@ namespace Tnb.WarehouseMgr
|
|||||||
{
|
{
|
||||||
var devName = _elevatorMap[devId].ToString();
|
var devName = _elevatorMap[devId].ToString();
|
||||||
elevatorQueueItem.task_status = "执行中";
|
elevatorQueueItem.task_status = "执行中";
|
||||||
|
(int sysStatus, int runStatus, int floorNo, int doorStatus, int agvStatus) = await _elevatorControlService.GetElevatorStatus(devName, CancellationToken.None);
|
||||||
|
if (sysStatus.ToEnum<EnumSysStatus>() == EnumSysStatus.正常状态 && runStatus.ToEnum<EnumRunStatus>() == EnumRunStatus.停梯)
|
||||||
|
{
|
||||||
await _elevatorControlService.CallLift(devName, 5, CancellationToken.None);
|
await _elevatorControlService.CallLift(devName, 5, CancellationToken.None);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//如果当前电梯有任务在做,将当前呼梯任务放入待执行队列
|
//如果当前电梯有任务在做,将当前呼梯任务放入待执行队列
|
||||||
await _db.Insertable(elevatorQueueItem).ExecuteCommandAsync();
|
await _db.Insertable(elevatorQueueItem).ExecuteCommandAsync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Log.Error("呼梯操作错误", ex);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// <summary>
|
||||||
|
/// Agv调度
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disTasks"></param>
|
||||||
|
/// <param name="token"></param>
|
||||||
|
/// <returns></returns>
|
||||||
|
private async Task AgvDispatch(List<WmsDistaskH> disTasks, CancellationToken token)
|
||||||
|
{
|
||||||
//调用AGV创建任务链接口
|
//调用AGV创建任务链接口
|
||||||
|
try
|
||||||
|
{
|
||||||
var requestCfg = App.Configuration.Build<AgvRequestConfig>();
|
var requestCfg = App.Configuration.Build<AgvRequestConfig>();
|
||||||
var url = requestCfg.AgvRequestUrls.CreateTaskChainUrl;
|
var url = requestCfg.AgvRequestUrls.CreateTaskChainUrl;
|
||||||
var taskChainCodeDic = disTasks.Where(t => !t.groups.IsNullOrWhiteSpace()).GroupBy(g => g.groups!)
|
var taskChainCodeDic = disTasks.Where(t => !t.groups.IsNullOrWhiteSpace()).GroupBy(g => g.groups!)
|
||||||
@@ -416,58 +457,15 @@ namespace Tnb.WarehouseMgr
|
|||||||
reqBody.taskChainPriority = 0;
|
reqBody.taskChainPriority = 0;
|
||||||
reqBody.taskList = v;
|
reqBody.taskList = v;
|
||||||
Log.Information($"请求参数:{JsonConvert.SerializeObject(reqBody)}");
|
Log.Information($"请求参数:{JsonConvert.SerializeObject(reqBody)}");
|
||||||
var respBody = await HttpClientHelper.PostStreamAsync(url, reqBody, agvCts.Token);
|
var respBody = await HttpClientHelper.PostStreamAsync(url, reqBody, token);
|
||||||
Log.Information($"调用Agv接口响应结果:{respBody}");
|
Log.Information($"调用Agv接口响应结果:{respBody}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (Exception ex) when (ex is HttpRequestException hReqEx)
|
|
||||||
{
|
|
||||||
agvCts.Cancel();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Log.Error("生成预任务执行时出现错误", ex);
|
Log.Error("agv调度失败异常", ex);
|
||||||
await db.Ado.RollbackTranAsync();
|
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
finally
|
|
||||||
{
|
|
||||||
agvCts.Dispose();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/// <summary>
|
|
||||||
/// Agv调度
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="disTasks"></param>
|
|
||||||
/// <param name="token"></param>
|
|
||||||
/// <returns></returns>
|
|
||||||
private async Task AgvDispatch(Dictionary<string, List<dynamic>> taskChainCodeDic, CancellationToken token)
|
|
||||||
{
|
|
||||||
//调用AGV创建任务链接口
|
|
||||||
var requestCfg = App.Configuration.Build<AgvRequestConfig>();
|
|
||||||
var url = requestCfg.AgvRequestUrls.CreateTaskChainUrl;
|
|
||||||
//var taskChainCodeDic = disTasks.Where(t => !t.groups.IsNullOrWhiteSpace()).GroupBy(g => g.groups!)
|
|
||||||
// .ToDictionary(x => x.Key, x => x.Select(it => new
|
|
||||||
// {
|
|
||||||
// taskCode = it.bill_code,
|
|
||||||
// sourceName = it.startpoint_code,
|
|
||||||
// targetName = it.endpoint_code,
|
|
||||||
// containerCode = it.carry_code,
|
|
||||||
// }));
|
|
||||||
Log.Information($"请求地址:{url}");
|
|
||||||
foreach (var (k, v) in taskChainCodeDic)
|
|
||||||
{
|
|
||||||
dynamic reqBody = new ExpandoObject();
|
|
||||||
reqBody.taskChainCode = k;
|
|
||||||
reqBody.type = (int)EnumTaskChainType.AGV;
|
|
||||||
reqBody.sequential = false;
|
|
||||||
reqBody.taskChainPriority = 0;
|
|
||||||
reqBody.taskList = v;
|
|
||||||
Log.Information($"请求参数:{JsonConvert.SerializeObject(reqBody)}");
|
|
||||||
var respBody = await HttpClientHelper.PostStreamAsync(url, reqBody, token);
|
|
||||||
Log.Information($"调用Agv接口响应结果:{respBody}");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,9 @@
|
|||||||
"DBType": "PostgreSQL", //MySql;SqlServer;Oracle;PostgreSQL;Dm;Kdbndp;Sqlite;
|
"DBType": "PostgreSQL", //MySql;SqlServer;Oracle;PostgreSQL;Dm;Kdbndp;Sqlite;
|
||||||
"Host": "localhost",
|
"Host": "localhost",
|
||||||
"Port": "5432",
|
"Port": "5432",
|
||||||
|
//"DBName": "tianyi_db",
|
||||||
|
//"UserName": "postgres",
|
||||||
|
//"Password": "pass@word123",
|
||||||
"DBName": "tianyi_bas",
|
"DBName": "tianyi_bas",
|
||||||
"UserName": "totong",
|
"UserName": "totong",
|
||||||
"Password": "IPANyxGSKxIXg0dBM",
|
"Password": "IPANyxGSKxIXg0dBM",
|
||||||
|
|||||||
@@ -63,4 +63,10 @@
|
|||||||
</Content>
|
</Content>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Update="_install.bat">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
Reference in New Issue
Block a user