Files
shgx_tz_mes_backend_sync/ZR.Service/mes/wms/WmAGVService.cs

248 lines
8.2 KiB
C#
Raw Normal View History

2024-06-07 11:04:26 +08:00
using Infrastructure;
2024-03-29 10:24:20 +08:00
using Infrastructure.Attribute;
2024-06-07 11:04:26 +08:00
using Mapster;
using SqlSugar;
using System;
using System.Text.Json;
using ZR.Model.MES.pro;
2024-03-29 10:24:20 +08:00
using ZR.Model.MES.wms;
using ZR.Model.MES.wms.Dto;
using ZR.Service.mes.wms.IService;
namespace ZR.Service.Business
{
/// <summary>
/// 盘点记录Service业务层处理
/// </summary>
[AppService(ServiceType = typeof(IWmAGVService), ServiceLifetime = LifeTime.Transient)]
public class WmAGVService : BaseService<AgvTask>, IWmAGVService
{
2024-04-01 17:20:23 +08:00
2024-03-29 10:24:20 +08:00
/// <summary>
/// 1.获取工单列表
/// </summary>
/// <param name="parm"></param>
/// <returns></returns>
public List<AGVWorkorderDto> GetList(QueryAGVparam param)
{
2024-04-01 17:20:23 +08:00
List<AGVWorkorderDto> aGVWorkorderDtos = new List<AGVWorkorderDto>();
2024-03-29 10:24:20 +08:00
var predicate = Expressionable.Create<ProWorkorder_v2>()
.AndIF(param.year > 0, it => it.Year == param.year)
.AndIF(param.week > 0, it => it.Week == param.week)
.AndIF(param.day > 0, it => it.Date == param.day);
var response = Context.Queryable<ProWorkorder_v2>()
2024-04-01 17:20:23 +08:00
.Where(it => it.Remark3 == "是")
2024-03-29 10:24:20 +08:00
.Where(predicate.ToExpression()).ToList();
foreach (var item in response)
{
aGVWorkorderDtos.Add(item.Adapt<AGVWorkorderDto>());
}
return aGVWorkorderDtos;
}
/// <summary>
/// 2.获取当前工单下的所有AGV小车任务
/// </summary>
/// <param name="workorder_id"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public List<AgvTask> QueryAGVTask(string workorder_id)
{
2024-04-01 17:20:23 +08:00
return Context.Queryable<AgvTask>().Where(it => it.FkWorkorderId == workorder_id).OrderBy(it => it.Sort).ToList();
2024-03-29 10:24:20 +08:00
}
/// <summary>
/// 3.新增AGV小车任务
/// </summary>
/// <param name="task"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public int AddAGVTask(AgvTask task)
{
int result = 0;
//TODO 1 判断agv小车task是否可以新增
2024-04-01 17:20:23 +08:00
if (string.IsNullOrEmpty(task.FkWorkorderId))
2024-03-29 10:24:20 +08:00
{
return -1;
}
ProWorkorder_v2 workorder = Context.Queryable<ProWorkorder_v2>()
.Where(it => it.Id == task.FkWorkorderId)
.First();
2024-04-01 17:20:23 +08:00
int require_num = workorder.PreviousNumber;
int all_require_num = Context.Queryable<AgvTask>().Where(it => it.FkWorkorderId == workorder.Id).Sum(it => it.Number) ?? 0;
if (require_num > all_require_num)
2024-03-29 10:24:20 +08:00
{
task.Id = SnowFlakeSingle.Instance.NextId().ToString();
2024-04-01 17:20:23 +08:00
result = Context.Insertable(task).ExecuteCommand();
2024-03-29 10:24:20 +08:00
}
return result;
}
/// <summary>
/// 4.删除AGV小车任务
/// </summary>
/// <param name="taskId"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public int DeleteTask(string taskId)
{
2024-04-01 17:20:23 +08:00
return Context.Deleteable<AgvTask>().Where(it => it.Id == taskId).ExecuteCommand();
2024-03-29 10:24:20 +08:00
}
/// <summary>
/// 6 获取agv 起点和终点
/// </summary>
/// <param name="location"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public List<AgvLocation> GetAGV_position_list(AgvLocation location)
{
var predicate = Expressionable.Create<AgvLocation>()
2024-04-01 17:20:23 +08:00
.AndIF(location.AreaCode > -1, it => it.AreaCode == location.AreaCode)
2024-03-29 10:24:20 +08:00
.AndIF(location.Type > -1, it => it.Type == location.Type)
.AndIF(!string.IsNullOrEmpty(location.Coordinate), it => it.Coordinate == location.Coordinate);
2024-03-29 10:24:20 +08:00
2024-04-01 17:20:23 +08:00
return Context.Queryable<AgvLocation>().Where(predicate.ToExpression()).ToList();
}
/// <summary>
2024-04-23 16:52:04 +08:00
/// 7 生成agv任务,并执行
2024-04-01 17:20:23 +08:00
/// </summary>
/// <param name="taskid"></param>
/// <returns></returns>
2024-06-07 11:04:26 +08:00
public string GenerateAgvTask(string taskid, int flag)
2024-04-01 17:20:23 +08:00
{
2024-06-07 11:04:26 +08:00
AgvTask agvTask = Context.Queryable<AgvTask>().Where(it => it.Id == taskid).First();
2024-04-23 11:04:23 +08:00
// 保存当前控制台文本颜色
ConsoleColor originalColor = Console.ForegroundColor;
2024-06-07 11:04:26 +08:00
2024-04-23 11:04:23 +08:00
// 设置文本颜色为红色
Console.ForegroundColor = ConsoleColor.Red;
2024-06-07 11:04:26 +08:00
2024-04-23 16:52:04 +08:00
string url = "http://192.168.60.1:8182/rcms/services/rest/hikRpcService/genAgvSchedulingTask";
2024-04-23 11:04:23 +08:00
Console.WriteLine("=======》打印请求URL" + url);
2024-04-01 17:20:23 +08:00
string start_point = "";
string end_point = "";
2024-06-07 11:04:26 +08:00
if (flag == 1)
{
start_point = agvTask.GoStartPoint;
2024-04-01 17:20:23 +08:00
end_point = agvTask.GoEndPoint;
}
2024-06-07 11:04:26 +08:00
else if (flag == 2)
2024-04-01 17:20:23 +08:00
{
start_point = agvTask.BackStartPoint;
end_point = agvTask.BackEndPoint;
}
AGVtask_third task = new AGVtask_third();
2024-04-23 16:52:04 +08:00
task.reqCode = SnowFlakeSingle.Instance.NextId().ToString();
// "taskTyp":"F01",
task.taskTyp = "F01";
2024-04-01 17:20:23 +08:00
task.positionCodePath = new List<AGV_location_third>
{
new AGV_location_third()
{
positionCode=start_point,
type="00"
},
new AGV_location_third()
{
positionCode=end_point,
type="01"
}
};
string postData = JsonSerializer.Serialize(task);
2024-04-23 11:04:23 +08:00
Console.WriteLine("=======》打印请求数据:" + postData);
2024-06-07 11:04:26 +08:00
string response = HttpHelper.HttpPost(url, postData);
2024-04-23 09:35:11 +08:00
// 设置文本颜色为红色
Console.ForegroundColor = ConsoleColor.Red;
2024-06-07 11:04:26 +08:00
Console.WriteLine("=======》打印请求数据返回:" + response);
2024-04-23 09:35:11 +08:00
Console.ForegroundColor = originalColor;
2024-04-01 17:20:23 +08:00
2024-06-07 11:04:26 +08:00
AGV_task_third res_data = JsonSerializer.Deserialize<AGV_task_third>(response);
2024-04-23 11:04:23 +08:00
Console.WriteLine("=======》打印请求数据返回2" + res_data.ToString());
2024-06-07 11:04:26 +08:00
if (res_data != null && res_data.code == "0")
{
2024-04-01 17:20:23 +08:00
if (flag == 1)
{
Context.Updateable<AgvTask>().SetColumns(it => it.GoTaskId == res_data.reqCode)
.Where(it => it.Id == agvTask.Id).ExecuteCommand();
}
else if (flag == 2)
{
Context.Updateable<AgvTask>().SetColumns(it => it.BackTaskId == res_data.reqCode)
.Where(it => it.Id == agvTask.Id).ExecuteCommand();
}
}
return response;
}
/// <summary>
/// 8.取消agv任务
/// </summary>
/// <param name="taskId"></param>
/// <param name="flag"></param>
2024-06-07 11:04:26 +08:00
public string CancelAGVTask(string taskId, int flag)
2024-04-01 17:20:23 +08:00
{
2024-06-07 11:04:26 +08:00
if (flag != 1 || flag != 2)
2024-04-01 17:20:23 +08:00
{
return null;
}
AgvTask agvTask = Context.Queryable<AgvTask>().Where(it => it.Id == taskId).First();
2024-06-07 11:04:26 +08:00
if (agvTask != null)
2024-04-01 17:20:23 +08:00
{
string task_id = null;
if (flag == 1)
{
//
task_id = agvTask.GoTaskId;
2024-06-07 11:04:26 +08:00
}
else if (flag == 2)
2024-04-01 17:20:23 +08:00
{
task_id = agvTask.BackTaskId;
}
2024-06-07 11:04:26 +08:00
2024-04-23 16:52:04 +08:00
string url = "http://192.168.60.1:8182/rcms/services/rest/hikRpcService/cancelTask";
2024-04-01 17:20:23 +08:00
AGVtask_cancel_third req = new AGVtask_cancel_third();
2024-04-23 16:52:04 +08:00
req.reqCode = SnowFlakeSingle.Instance.NextId().ToString();
2024-04-01 17:20:23 +08:00
req.forceCancel = "1";
req.taskCode = task_id;
2024-06-07 11:04:26 +08:00
string postData = JsonSerializer.Serialize(req);
2024-04-01 17:20:23 +08:00
string response = HttpHelper.HttpPost(url, postData);
return response;
}
2024-06-07 11:04:26 +08:00
return null;
2024-04-01 17:20:23 +08:00
2024-03-29 10:24:20 +08:00
}
}
}