客户端重新发送功能

This commit is contained in:
hehaibing-1996
2025-02-23 15:59:26 +08:00
parent 60e996ebd2
commit dbdeaeaea7
8 changed files with 356 additions and 24 deletions

View File

@ -82,6 +82,7 @@ namespace WCS.BLL.Manager
}
if (isUpdate)
{
tasks[i].ModifyTime = DateTime.Now;
DbHelp.db.Updateable(tasks[i]).ExecuteCommand();
}
}
@ -126,11 +127,42 @@ namespace WCS.BLL.Manager
//任务只允许一个一个发送
lock (lockFlag)
{
//正在执行中的任务
var tasks = DbHelp.db.Queryable<AgvTask>()
.Where(t => t.TaskStatus == TaskStatusEnum. || t.TaskStatus == TaskStatusEnum.)
.ToList();
//校验货架
if (tasks.Where(t => t.ShelfCode == shelfCode).Any())
{
return new AGVResponseModel()
{
code = "-999",
message = $"货架[{shelfCode}]已有执行中的任务!",
};
}
//校验起点
if (tasks.Where(t => t.StratLocationId == startLocation.Id).Any())
{
return new AGVResponseModel()
{
code = "-999",
message = $"工位[{startLocation.LocationCode}]作为起点已有执行中的任务!",
};
}
//校验终点
if (tasks.Where(t => t.EndLocationId == endLocation.Id).Any())
{
return new AGVResponseModel()
{
code = "-999",
message = $"工位[{endLocation.LocationCode}]作为终点已有执行中的任务!",
};
}
var body = new GenAgvSchedulingTaskRequest()
{
positionCodePath = positionCodePathItems,
};
var response = ApiHelp.GetDataFromHttp<AGVResponseModel>(url, body, "POST", true);
if (response.code == "0" && response.message == "成功")
{
@ -154,6 +186,89 @@ namespace WCS.BLL.Manager
}
}
public static AGVResponseModel GenAgvSchedulingTaskForResend(LocationInfo startLocation, LocationInfo endLocation, AgvTask agvTask,string shelfCode, string createUser)
{
var url = @"http://192.168.18.150:8181/rcms/services/rest/hikRpcService/genAgvSchedulingTask";
var startPositionCodePathItem = new PositionCodePathItem()
{
positionCode = startLocation.RcsStoreCode,
};
var endPositionCodePathItem = new PositionCodePathItem()
{
positionCode = endLocation.RcsStoreCode,
};
List<PositionCodePathItem> positionCodePathItems = new List<PositionCodePathItem>();
positionCodePathItems.Add(startPositionCodePathItem);
positionCodePathItems.Add((endPositionCodePathItem));
//任务只允许一个一个发送
lock (lockFlag)
{
//正在执行中的任务
var tasks = DbHelp.db.Queryable<AgvTask>()
.Where(t => t.TaskStatus == TaskStatusEnum. || t.TaskStatus == TaskStatusEnum.)
.ToList();
//校验货架
if (tasks.Where(t => t.ShelfCode == shelfCode).Any())
{
return new AGVResponseModel()
{
code = "-999",
message = $"货架[{shelfCode}]已有执行中的任务!",
};
}
//校验起点
if (tasks.Where(t => t.StratLocationId == startLocation.Id).Any())
{
return new AGVResponseModel()
{
code = "-999",
message = $"工位[{startLocation.LocationCode}]作为起点已有执行中的任务!",
};
}
//校验终点
if (tasks.Where(t => t.EndLocationId == endLocation.Id).Any())
{
return new AGVResponseModel()
{
code = "-999",
message = $"工位[{endLocation.LocationCode}]作为终点已有执行中的任务!",
};
}
agvTask.TaskCode = agvTask.TaskCode + "_resend";
agvTask.CreateTime = DateTime.Now;
agvTask.CreateUser = createUser;
var body = new GenAgvSchedulingTaskRequest()
{
taskCode = agvTask.TaskCode,
positionCodePath = positionCodePathItems,
};
var response = ApiHelp.GetDataFromHttp<AGVResponseModel>(url, body, "POST", true);
if (response.code == "0" && response.message == "成功")
{
//DbHelp.db.Updateable(agvTask).ExecuteCommand();
//生成任务数据
var task = new AgvTask()
{
ShelfCode = shelfCode,
RequestCode = body.reqCode,
TaskCode = agvTask.TaskCode,
TaskType = "GenAgvSchedulingTask",
StratLocationId = startLocation.Id,
StartLocationCode = startLocation.LocationCode,
EndLocationId = endLocation.Id,
EndLocationCode = endLocation.LocationCode,
CreateUser = createUser
};
DbHelp.db.Insertable(task).ExecuteCommand();
}
return response;
}
}
/// <summary>
/// RCS取消任务
/// </summary>

View File

@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WCS.Model;
using WCS.Model.ApiModel.AGV;
using WCS.Model.ApiModel.PDAMatBind;
using WCS.Model.WebSocketModel;
@ -15,5 +16,7 @@ namespace WCS.BLL.Services.IService
public interface IPDAMatBindService
{
public Task<ResponseCommon> callEmptyShelf(BindMatDetailRequest request);
public Task<ResponseBase> resendAGVTask(ResendAGVTasksRequest request);
}
}

View File

@ -3,11 +3,13 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WCS.BLL.DbModels;
using WCS.BLL.Manager;
using WCS.BLL.Services.IService;
using WCS.DAL.Db;
using WCS.DAL.DbModels;
using WCS.Model;
using WCS.Model.ApiModel.AGV;
using WCS.Model.ApiModel.PDAMatBind;
namespace WCS.BLL.Services.Service
@ -113,6 +115,15 @@ namespace WCS.BLL.Services.Service
Data = null,
};
}
else if(response.code == "-999")
{
return new ResponseCommon()
{
Code = 201,
Message = $"{response.message}\r\n请重试或等待上一个任务完成",
Data = null,
};
}
else
{
return new ResponseCommon()
@ -134,5 +145,161 @@ namespace WCS.BLL.Services.Service
};
}
}
public async Task<ResponseBase> resendAGVTask(ResendAGVTasksRequest request)
{
try
{
#region
if (request.TaskId == 0 || string.IsNullOrEmpty(request.TaskCode))
{
return new ResponseCommon()
{
Code = 201,
Message = $"传入参数错误!",
};
}
var agvTask = await DbHelp.db.Queryable<AgvTask>()
.Where(t => t.Id == request.TaskId)
.Where(t => t.TaskCode == request.TaskCode)
.FirstAsync();
if (agvTask == null)
{
return new ResponseCommon()
{
Code = 201,
Message = $"任务[{agvTask.TaskCode}]不存在!",
};
}
if (agvTask.TaskStatus != TaskStatusEnum.)
{
return new ResponseCommon()
{
Code = 201,
Message = $"任务[{agvTask.TaskCode}]状态为【{agvTask.TaskStatus}】,无法重新发送!",
};
}
if (agvTask.ModifyTime < DateTime.Now.AddMinutes(-10))
{
return new ResponseCommon()
{
Code = 201,
Message = $"任务取消已超过10分钟,无法重新发送!",
};
}
#endregion
#region
var startLocation = await DbHelp.db.Queryable<LocationInfo>()
.Where(t => t.Id == agvTask.StratLocationId)
.Where(t => t.IsEnable == true)
.FirstAsync();
if (startLocation == null)
{
return new ResponseBase()
{
Code = 201,
Message = "任务重新发送失败:起点位置不存在或已被禁用!",
};
}
var endLocation = await DbHelp.db.Queryable<LocationInfo>()
.Where(t => t.Id == agvTask.EndLocationId)
.Where(t => t.IsEnable == true)
.FirstAsync();
if (endLocation == null)
{
return new ResponseBase()
{
Code = 201,
Message = "任务重新发送失败:终点位置不存在或已被禁用!",
};
}
//货架
var shelf = await DbHelp.db.Queryable<ShelfInfo>()
.Where(t => t.ShelfCode == agvTask.ShelfCode)
.Where (t => t.IsEnable == true)
.FirstAsync();
if (shelf == null)
{
return new ResponseBase()
{
Code = 201,
Message = $"任务重新发送失败:货架{agvTask.ShelfCode}不存在或已被禁用!",
};
}
if (shelf.TransStatus != TransStatusEnum. || shelf.CurrentLocationId != agvTask.StratLocationId)
{
return new ResponseBase()
{
Code = 201,
Message = $"任务重新发送失败:货架{agvTask.ShelfCode}已不在起点位置{startLocation.LocationCode}",
};
}
//查询终点位置是否有货架占用
var otherShelf = 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 (otherShelf != null)
{
return new ResponseBase()
{
Code = 201,
Message = $"任务重新发送失败:终点位置已被其他货架占用!",
};
}
#endregion
#region RCS进行重新发送任务
var response = AGVManager.GenAgvSchedulingTaskForResend(startLocation, endLocation, agvTask, 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 if (response.code == "-999")
{
return new ResponseCommon()
{
Code = 201,
Message = $"任务重新发送失败:{response.message}\r\n请重试或等待上一个任务完成",
Data = null,
};
}
else
{
return new ResponseCommon()
{
Code = 201,
Message = $"任务重新发送失败海康RCS返回{response.message}",
Data = null,
};
}
#endregion
}
catch (Exception ex)
{
return new ResponseCommon()
{
Code = 300,
Message = $"任务重新发送失败:{ex.Message}",
};
}
}
}
}

View File

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace WCS.Model.ApiModel.AGV
{
/// <summary>
/// 取消任务
/// </summary>
public class ResendAGVTasksRequest : RequestBase
{
public int TaskId { get; set; } = 0;
public string TaskCode { get; set; }
}
}

View File

@ -25,10 +25,10 @@ namespace WCS.WebApi.Controllers
[Route("[controller]")]
public class AgvTaskController : ControllerBase
{
public AgvTaskController()
public IPDAMatBindService _PDAMatBindService { get; set; }
public AgvTaskController(IPDAMatBindService PDAMatBindService)
{
_PDAMatBindService = PDAMatBindService;
}
/// <summary>
@ -155,5 +155,28 @@ namespace WCS.WebApi.Controllers
};
}
}
/// <summary>
/// 重新发送任务
/// </summary>
/// <param name="request"></param>
/// <returns></returns>
[Route("resendAGVTask")]
[HttpPost(Name = "resendAGVTask")]
public async Task<ResponseBase> resendAGVTask(ResendAGVTasksRequest request)
{
try
{
return await _PDAMatBindService.resendAGVTask(request);
}
catch (Exception ex)
{
return new ResponseCommon()
{
Code = 300,
Message = $"任务重新发送失败:{ex.Message}",
};
}
}
}
}

View File

@ -91,7 +91,6 @@ 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();

View File

@ -195,11 +195,13 @@ namespace 智慧物流软件系统.ViewModel
#endregion
}
public ICommand BtnCommitCommand { get => new DelegateCommand(BtnCommit); }
public async void BtnCommit()
/// <summary>
/// 任务取消
/// </summary>
public ICommand BtnCancelCommand { get => new DelegateCommand(BtnCancel); }
public async void BtnCancel()
{
Growl.Ask($"是否提交所有勾选的数据?", isConfirmed =>
Growl.Ask($"是否取消所有勾选的任务?", isConfirmed =>
{
if (isConfirmed)
{
@ -207,23 +209,28 @@ namespace 智慧物流软件系统.ViewModel
var needDeleteIds = DataGridItemSource?.Where(t => t.IsSelected == true)
.Select(t => t.Id)
.ToList();
if (needDeleteIds == null)
if (needDeleteIds == null || needDeleteIds.Count == 0)
{
Growl.Warning("请选择需要提交的数据");
Growl.Warning("请选择需要取消的任务");
return true;
}
else
{
var body = new DeleteInfosRequest()
var task = DataGridItemSource?.Where(t => t.IsSelected == true).First();
var body = new CancelAGVTasksRequest()
{
TaskId = task == null ? 0 : task.Id,
TaskCode = task?.TaskCode,
UserName = LocalStatic.CurrentUser,
DeviceType = LocalFile.Config.DeviceType,
needDeleteIds = needDeleteIds,
};
var Result = ApiHelp.GetDataFromHttp<ResponseBase<UserModel>>(LocalFile.Config.ApiIpHost + "PDAStocktaking/commitStocktakingInfos", body, "POST");
var Result = ApiHelp.GetDataFromHttp<ResponseBase<UserModel>>(LocalFile.Config.ApiIpHost + "agvTask/cancelAGVTask", body, "POST");
if (Result != null && Result.Code == 200)
{
CurrentPage = 1;
Growl.Success("提交成功!" + Result?.Message);
Growl.Success("取消成功!" + Result?.Message);
}
else
{
@ -237,12 +244,12 @@ namespace 智慧物流软件系统.ViewModel
/// <summary>
/// 物料删除操作
/// 任务重新发送
/// </summary>
public ICommand BtnCancelCommand { get => new DelegateCommand(BtnCancel); }
public async void BtnCancel()
public ICommand BtnResendCommand { get => new DelegateCommand(BtnResend); }
public async void BtnResend()
{
Growl.Ask($"是否取消所有勾选的任务?", isConfirmed =>
Growl.Ask($"是否重新发送所勾选的任务?", isConfirmed =>
{
if (isConfirmed)
{
@ -250,26 +257,28 @@ namespace 智慧物流软件系统.ViewModel
var needDeleteIds = DataGridItemSource?.Where(t => t.IsSelected == true)
.Select(t => t.Id)
.ToList();
var task = DataGridItemSource?.Where(t => t.IsSelected == true).First();
if (needDeleteIds == null || needDeleteIds.Count == 0)
{
Growl.Warning("请选择需要取消的任务!");
return true;
}
else
{
var body = new CancelAGVTasksRequest()
var task = DataGridItemSource?.Where(t => t.IsSelected == true).First();
var body = new ResendAGVTasksRequest()
{
TaskId = task == null ? 0 : task.Id,
TaskCode = task?.TaskCode,
UserName = LocalStatic.CurrentUser,
DeviceType = LocalFile.Config.DeviceType,
};
var Result = ApiHelp.GetDataFromHttp<ResponseBase<UserModel>>(LocalFile.Config.ApiIpHost + "agvTask/cancelAGVTask", body, "POST");
var Result = ApiHelp.GetDataFromHttp<ResponseBase<UserModel>>(LocalFile.Config.ApiIpHost + "agvTask/resendAGVTask", body, "POST");
if (Result != null && Result.Code == 200)
{
CurrentPage = 1;
Growl.Success("取消成功!" + Result?.Message);
Growl.Success("任务重新发送成功!" + Result?.Message);
}
else
{

View File

@ -146,7 +146,7 @@
FontFamily="{StaticResource IconFont}"
Foreground="WhiteSmoke"
Background="Green"
Command="{Binding BtnCommitCommand}"></Button>
Command="{Binding BtnResendCommand}"></Button>
<Button MinHeight="40"
FontSize="18"