248 lines
8.2 KiB
C#
248 lines
8.2 KiB
C#
using Infrastructure;
|
||
using Infrastructure.Attribute;
|
||
using Mapster;
|
||
using SqlSugar;
|
||
using System;
|
||
using System.Text.Json;
|
||
using ZR.Model.MES.pro;
|
||
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
|
||
{
|
||
|
||
|
||
/// <summary>
|
||
/// 1.获取工单列表
|
||
/// </summary>
|
||
/// <param name="parm"></param>
|
||
/// <returns></returns>
|
||
public List<AGVWorkorderDto> GetList(QueryAGVparam param)
|
||
{
|
||
List<AGVWorkorderDto> aGVWorkorderDtos = new List<AGVWorkorderDto>();
|
||
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>()
|
||
.Where(it => it.Remark3 == "是")
|
||
.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)
|
||
{
|
||
return Context.Queryable<AgvTask>().Where(it => it.FkWorkorderId == workorder_id).OrderBy(it => it.Sort).ToList();
|
||
}
|
||
|
||
|
||
|
||
/// <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是否可以新增
|
||
if (string.IsNullOrEmpty(task.FkWorkorderId))
|
||
{
|
||
return -1;
|
||
}
|
||
ProWorkorder_v2 workorder = Context.Queryable<ProWorkorder_v2>()
|
||
.Where(it => it.Id == task.FkWorkorderId)
|
||
.First();
|
||
|
||
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)
|
||
{
|
||
task.Id = SnowFlakeSingle.Instance.NextId().ToString();
|
||
result = Context.Insertable(task).ExecuteCommand();
|
||
}
|
||
|
||
|
||
return result;
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 4.删除AGV小车任务
|
||
/// </summary>
|
||
/// <param name="taskId"></param>
|
||
/// <returns></returns>
|
||
/// <exception cref="NotImplementedException"></exception>
|
||
public int DeleteTask(string taskId)
|
||
{
|
||
return Context.Deleteable<AgvTask>().Where(it => it.Id == taskId).ExecuteCommand();
|
||
|
||
}
|
||
|
||
/// <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>()
|
||
.AndIF(location.AreaCode > -1, it => it.AreaCode == location.AreaCode)
|
||
.AndIF(location.Type > -1, it => it.Type == location.Type)
|
||
.AndIF(!string.IsNullOrEmpty(location.Coordinate), it => it.Coordinate == location.Coordinate);
|
||
|
||
|
||
return Context.Queryable<AgvLocation>().Where(predicate.ToExpression()).ToList();
|
||
}
|
||
/// <summary>
|
||
/// 7 生成agv任务,并执行
|
||
/// </summary>
|
||
/// <param name="taskid"></param>
|
||
/// <returns></returns>
|
||
public string GenerateAgvTask(string taskid, int flag)
|
||
{
|
||
AgvTask agvTask = Context.Queryable<AgvTask>().Where(it => it.Id == taskid).First();
|
||
// 保存当前控制台文本颜色
|
||
ConsoleColor originalColor = Console.ForegroundColor;
|
||
|
||
|
||
// 设置文本颜色为红色
|
||
Console.ForegroundColor = ConsoleColor.Red;
|
||
|
||
|
||
|
||
string url = "http://192.168.60.1:8182/rcms/services/rest/hikRpcService/genAgvSchedulingTask";
|
||
Console.WriteLine("=======》打印请求URL:" + url);
|
||
string start_point = "";
|
||
string end_point = "";
|
||
|
||
if (flag == 1)
|
||
{
|
||
start_point = agvTask.GoStartPoint;
|
||
end_point = agvTask.GoEndPoint;
|
||
}
|
||
else if (flag == 2)
|
||
{
|
||
start_point = agvTask.BackStartPoint;
|
||
end_point = agvTask.BackEndPoint;
|
||
|
||
}
|
||
AGVtask_third task = new AGVtask_third();
|
||
task.reqCode = SnowFlakeSingle.Instance.NextId().ToString();
|
||
// "taskTyp":"F01",
|
||
task.taskTyp = "F01";
|
||
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);
|
||
|
||
|
||
Console.WriteLine("=======》打印请求数据:" + postData);
|
||
string response = HttpHelper.HttpPost(url, postData);
|
||
|
||
|
||
// 设置文本颜色为红色
|
||
Console.ForegroundColor = ConsoleColor.Red;
|
||
Console.WriteLine("=======》打印请求数据返回:" + response);
|
||
Console.ForegroundColor = originalColor;
|
||
|
||
|
||
AGV_task_third res_data = JsonSerializer.Deserialize<AGV_task_third>(response);
|
||
Console.WriteLine("=======》打印请求数据返回2:" + res_data.ToString());
|
||
if (res_data != null && res_data.code == "0")
|
||
{
|
||
|
||
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>
|
||
public string CancelAGVTask(string taskId, int flag)
|
||
{
|
||
if (flag != 1 || flag != 2)
|
||
{
|
||
return null;
|
||
}
|
||
AgvTask agvTask = Context.Queryable<AgvTask>().Where(it => it.Id == taskId).First();
|
||
if (agvTask != null)
|
||
{
|
||
string task_id = null;
|
||
if (flag == 1)
|
||
{
|
||
//
|
||
task_id = agvTask.GoTaskId;
|
||
}
|
||
else if (flag == 2)
|
||
{
|
||
task_id = agvTask.BackTaskId;
|
||
}
|
||
|
||
string url = "http://192.168.60.1:8182/rcms/services/rest/hikRpcService/cancelTask";
|
||
AGVtask_cancel_third req = new AGVtask_cancel_third();
|
||
req.reqCode = SnowFlakeSingle.Instance.NextId().ToString();
|
||
req.forceCancel = "1";
|
||
req.taskCode = task_id;
|
||
string postData = JsonSerializer.Serialize(req);
|
||
|
||
|
||
|
||
|
||
string response = HttpHelper.HttpPost(url, postData);
|
||
|
||
return response;
|
||
}
|
||
return null;
|
||
|
||
}
|
||
}
|
||
}
|