#region << 版 本 注 释 >>
|
/*----------------------------------------------------------------
|
* 命名空间:WIDESEAWCS_TaskInfoService
|
* 创建者:胡童庆
|
* 创建时间:2024/8/2 16:13:36
|
* 版本:V1.0.0
|
* 描述:
|
*
|
* ----------------------------------------------------------------
|
* 修改人:
|
* 修改时间:
|
* 版本:V1.0.1
|
* 修改说明:
|
*
|
*----------------------------------------------------------------*/
|
#endregion << 版 本 注 释 >>
|
|
using AutoMapper;
|
using Newtonsoft.Json;
|
using SixLabors.ImageSharp.ColorSpaces;
|
using SqlSugar;
|
using System.Collections.Generic;
|
using System.Diagnostics.CodeAnalysis;
|
using System.Threading.Tasks;
|
using WIDESEAWCS_BasicInfoService;
|
using WIDESEAWCS_Common;
|
using WIDESEAWCS_Common.LocationEnum;
|
using WIDESEAWCS_Common.TaskEnum;
|
using WIDESEAWCS_Core;
|
using WIDESEAWCS_Core.BaseRepository;
|
using WIDESEAWCS_Core.BaseServices;
|
using WIDESEAWCS_Core.Enums;
|
using WIDESEAWCS_Core.Helper;
|
using WIDESEAWCS_DTO;
|
using WIDESEAWCS_DTO.AGV.HIKROBOT;
|
using WIDESEAWCS_DTO.RGV.FOURBOT;
|
using WIDESEAWCS_DTO.TaskInfo;
|
using WIDESEAWCS_DTO.WMS;
|
using WIDESEAWCS_IBasicInfoService;
|
using WIDESEAWCS_ITaskInfoService;
|
using WIDESEAWCS_Model.Models;
|
using WIDESEAWCS_QuartzJob;
|
using WIDESEAWCS_QuartzJob.Models;
|
using WIDESEAWCS_QuartzJob.Service;
|
|
namespace WIDESEAWCS_TaskInfoService
|
{
|
public partial class TaskService : ServiceBase<Dt_Task, IRepository<Dt_Task>>, ITaskService
|
{
|
private readonly ITrackloginfoService _trackloginfoService;
|
private readonly IRouterService _routerService;
|
private readonly ITaskExecuteDetailService _taskExecuteDetailService;
|
private readonly IHKLocationInfoService _hKLocationInfoService;
|
private readonly IKLSLocationInfoService _kLSLocationInfoService;
|
private readonly IRGVLocationInfoService _rGVLocationInfoService;
|
private readonly IRepository<Dt_TaskExecuteDetail> _taskExecuteDetailRepository;
|
private readonly IApiInfoService _apiInfoService;
|
private readonly IStationMangerService _stationMangerService;
|
private readonly IStationInfoService _stationInfo;
|
private readonly ITaskErrorMessageService _taskErrorMessageService;
|
private readonly IMapper _mapper;
|
|
private Dictionary<string, OrderByType> _taskOrderBy = new()
|
{
|
{nameof(Dt_Task.Grade),OrderByType.Desc },
|
{nameof(Dt_Task.CreateDate),OrderByType.Asc},
|
};
|
|
public Dictionary<string, OrderByType> TaskOrderBy { get { return _taskOrderBy; } set { _taskOrderBy = value; } }
|
|
public List<int> TaskInboundTypes => typeof(TaskInboundTypeEnum).GetEnumIndexList();
|
|
public List<int> TaskOutboundTypes => typeof(TaskOutboundTypeEnum).GetEnumIndexList();
|
|
/// <summary>
|
/// 仓储层(数据库访问)
|
/// </summary>
|
public IRepository<Dt_Task> Repository => BaseDal;
|
|
public TaskService(IRepository<Dt_Task> BaseDal, IRouterService routerService, ITaskExecuteDetailService taskExecuteDetailService, IRepository<Dt_TaskExecuteDetail> taskExecuteDetailRepository, IMapper mapper, IKLSLocationInfoService kLSLocationInfoService, IRGVLocationInfoService rGVLocationInfoService, IHKLocationInfoService hKLocationInfoService, IApiInfoService apiInfoService, ITrackloginfoService trackloginfoService, IStationMangerService stationMangerService, IStationInfoService stationInfo, ITaskErrorMessageService taskErrorMessageService) : base(BaseDal)
|
{
|
_routerService = routerService;
|
_taskExecuteDetailService = taskExecuteDetailService;
|
_taskExecuteDetailRepository = taskExecuteDetailRepository;
|
_mapper = mapper;
|
_kLSLocationInfoService = kLSLocationInfoService;
|
_rGVLocationInfoService = rGVLocationInfoService;
|
_hKLocationInfoService = hKLocationInfoService;
|
_apiInfoService = apiInfoService;
|
_trackloginfoService = trackloginfoService;
|
_stationMangerService = stationMangerService;
|
_stationInfo = stationInfo;
|
_taskErrorMessageService = taskErrorMessageService;
|
}
|
public WebResponseContent ReceiveWMSTask([NotNull] List<WMSTasksDTO> taskDTOs)
|
{
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
List<object> objects = new List<object>();
|
foreach (var item in taskDTOs)
|
{
|
foreach (var task in item.tasks)
|
{
|
#region 判断
|
var contentStatus = TaskHelpMethods.isOkTaskInfo(task, true, true);
|
if (!contentStatus.Status)
|
{
|
objects.Add(new
|
{
|
taskCode = task.taskCode,
|
Message = $"任务号【{task.taskCode}】{content.Message}"
|
});
|
continue;
|
}
|
if (BaseDal.QueryFirst(x => x.WMSTaskNum == task.taskCode && x.TaskType == item.taskType) != null)
|
{
|
objects.Add(new
|
{
|
taskCode = task.taskCode,
|
Message = $"任务号【{task.taskCode}】已存在任务"
|
});
|
continue;
|
//throw new Exception($"任务号【{task.taskCode}】已存在任务");
|
}
|
if (BaseDal.QueryFirst(x => x.PalletCode == task.containerCode /*&& x.TaskType == item.taskType*/) != null)
|
{
|
objects.Add(new
|
{
|
taskCode = task.taskCode,
|
Message = $"托盘号【{task.containerCode}】已存在任务"
|
});
|
continue;
|
//throw new Exception($"托盘号【{task.containerCode}】已存在任务");
|
}
|
if (BaseDal.QueryFirst(x => x.SourceAddress == task.fromLocationCode && x.TaskType == item.taskType && x.TaskState < TaskStatusEnum.TakeFinish.ObjToInt()) != null)
|
{
|
objects.Add(new
|
{
|
taskCode = task.taskCode,
|
Message = $"起点位置【{task.fromLocationCode}】已存在任务"
|
});
|
continue;
|
//throw new Exception($"起点位置【{task.containerCode}】已存在任务");
|
}
|
#endregion
|
switch (item.taskType)
|
{
|
#region 凯乐士AGV面料库
|
case (int)TaskTypeEnum.MLInbound:
|
content = CreateKLSNewInTask(task, item.taskType);
|
objects.Add(content.Data);
|
break;
|
case (int)TaskTypeEnum.MLOutbound:
|
content = CreateKLSNewOutTask(task, item.taskType);
|
objects.Add(content.Data);
|
break;
|
#endregion
|
#region 旷视四向车成品库
|
case (int)TaskTypeEnum.CPInbound:
|
content = CreateRGVNewInTask(task, item.taskType);
|
objects.Add(content.Data);
|
break;
|
case (int)TaskTypeEnum.CPOutbound:
|
content = CreateRGVNewOutTask(task, item.taskType);
|
objects.Add(content.Data);
|
break;
|
case (int)TaskTypeEnum.CPMoveInventory:
|
content = CreateRGVNewMoveTask(task, item.taskType);
|
objects.Add(content.Data);
|
break;
|
#endregion
|
#region 海康AGV
|
case (int)TaskTypeEnum.STURR:
|
case (int)TaskTypeEnum.Q1TSJ4:
|
content = CreateHKNewInTask(task, item.taskType);
|
objects.Add(content.Data);
|
break;
|
case (int)TaskTypeEnum.STU0003:
|
case (int)TaskTypeEnum.CHUKU1:
|
content = CreateHKNewOutTask(task, item.taskType);
|
objects.Add(content.Data);
|
break;
|
|
case (int)TaskTypeEnum.Q3RK:
|
case (int)TaskTypeEnum.Q3CK:
|
content = CarryTask(task, item.taskType);
|
objects.Add(content.Data);
|
break;
|
case (int)TaskTypeEnum.F01:
|
content = HKF01Transport(task, item.taskType);
|
break;
|
case (int)TaskTypeEnum.F04:
|
case (int)TaskTypeEnum.RK3F:
|
case (int)TaskTypeEnum.F02:
|
case (int)TaskTypeEnum.F03:
|
case (int)TaskTypeEnum.CK3F:
|
content = CJCarryTaske(task, item.taskType);
|
objects.Add(content.Data);
|
break;
|
#endregion
|
default:
|
objects.Add(new
|
{
|
taskCode = task.taskCode,
|
Message = $"未定义的任务类型"
|
});
|
break;
|
}
|
}
|
}
|
content.Data = objects;
|
}
|
catch (Exception ex)
|
{
|
content.Error(ex.Message);
|
}
|
finally
|
{
|
_trackloginfoService.AddTrackLog(taskDTOs, content, $"WMS下发任务,", "", "");
|
}
|
return content;
|
}
|
|
/// <summary>
|
/// 取消任务
|
/// </summary>
|
/// <param name="taskCode">任务号</param>
|
/// <param name="containerCode">料箱条码</param>
|
/// <returns></returns>
|
public WebResponseContent CancelWMSTask(WMSCancelTask wMSCancelTask)
|
{
|
WebResponseContent content = new WebResponseContent();
|
var KLS = new CancelGALAXISTask();
|
CancelHIKROBOTTask cancelHIKROBOTTask = new CancelHIKROBOTTask();
|
CancelSXCTake cancelSXCTake = new CancelSXCTake();
|
var deviceName = "";
|
try
|
{
|
Dt_Task dt_Task = BaseDal.QueryFirst(x => x.WMSTaskNum == wMSCancelTask.TaskCode && x.TaskType != TaskTypeEnum.CPMoveInventory.ObjToInt());
|
if (dt_Task == null) throw new Exception("未查询到任务号相关任务");
|
|
// 判断当前任务是否为凯乐士任务
|
bool isGALAXISTask = dt_Task.TaskType == (int)TaskTypeEnum.MLInbound ||
|
dt_Task.TaskType == (int)TaskTypeEnum.MLOutbound;
|
//四向车
|
bool isAGV = dt_Task.TaskType == (int)TaskTypeEnum.CPInbound || dt_Task.TaskType == (int)TaskTypeEnum.CPOutbound;
|
//海康
|
bool isHK = dt_Task.TaskType == (int)TaskTypeEnum.F01 || dt_Task.TaskType == (int)TaskTypeEnum.RK3F || dt_Task.TaskType == (int)TaskTypeEnum.CK3F || dt_Task.TaskType == (int)TaskTypeEnum.Q1TSJ4 || dt_Task.TaskType == (int)TaskTypeEnum.STU0003 || dt_Task.TaskType == (int)TaskTypeEnum.F02 || dt_Task.TaskType == (int)TaskTypeEnum.CHUKU1 || dt_Task.TaskType == (int)TaskTypeEnum.Q3RK || dt_Task.TaskType == (int)TaskTypeEnum.Q3CK || dt_Task.TaskType == (int)TaskTypeEnum.STURR;
|
//这里将状态改变了198取消任务
|
dt_Task.TaskType = TaskStatusEnum.WMSCancel.ObjToInt();
|
#region 凯乐士
|
if (isGALAXISTask)
|
{
|
deviceName = "凯乐士AGV";
|
KLS = new CancelGALAXISTask
|
{
|
taskId = dt_Task.WMSTaskNum,
|
reportTime = DateTime.Now.ToString()
|
};
|
Dt_ApiInfo? apiInfo = _apiInfoService.Repository.QueryFirst(x => x.ApiCode == nameof(CancelGALAXISTask));
|
if (apiInfo == null) throw new Exception("未找到凯乐士AGV任务下发接口配置信息!请检查接口配置");
|
string response = HttpHelper.Post(apiInfo.ApiAddress, KLS.Serialize());
|
GALAXISReturn agvContent = response.DeserializeObject<GALAXISReturn>();
|
content.OK(data: agvContent);
|
if (agvContent.success == true && agvContent.code == 0)
|
{
|
//直接移入历史
|
BaseDal.DeleteAndMoveIntoHty(dt_Task, OperateTypeEnum.自动完成);
|
content.OK($"取消{dt_Task.WMSTaskNum}任务成功", dt_Task);
|
}
|
else
|
{
|
content.Error($"任务{dt_Task.WMSTaskNum}失败{agvContent.data.returnInfo}");
|
|
}
|
}
|
#endregion
|
|
#region 四向车
|
if (isAGV)
|
{
|
deviceName = "四向车";
|
if (dt_Task.RGVTaskId == 0)
|
{
|
if (dt_Task.TaskType == TaskTypeEnum.CPOutbound.ObjToInt() && dt_Task.TaskState == TaskStatusEnum.RGV_WaitSend.ObjToInt())
|
{
|
//修改库位状态
|
var rgvlocaiion = _rGVLocationInfoService.Repository.QueryFirst(x => x.LocationCode == dt_Task.SourceAddress);
|
rgvlocaiion.LocationStatus = LocationStatusEnum.InStock.ObjToInt(); //将库位状态改为有货
|
}
|
BaseDal.DeleteAndMoveIntoHty(dt_Task, OperateTypeEnum.自动删除);
|
content.OK($"取消{dt_Task.WMSTaskNum}任务成功", dt_Task);
|
}
|
else
|
{
|
cancelSXCTake = new CancelSXCTake
|
{
|
taskID = dt_Task.RGVTaskId,
|
withoutRunning = 1
|
};
|
Dt_ApiInfo? apiInfo = _apiInfoService.Repository.QueryFirst(x => x.ApiCode == nameof(CancelSXCTake));
|
if (apiInfo == null) throw new Exception("未找到四向车AGV任务下发接口配置信息!请检查接口配置");
|
string response = HttpHelper.Post(apiInfo.ApiAddress, cancelSXCTake.Serialize());
|
FOURBOTReturn fOURBOTReturn = response.DeserializeObject<FOURBOTReturn>();
|
content.OK(data: fOURBOTReturn);
|
if (fOURBOTReturn.returnCode == 0 && fOURBOTReturn.returnUserMsg == "成功")
|
{
|
//直接移入历史
|
BaseDal.DeleteAndMoveIntoHty(dt_Task, OperateTypeEnum.自动完成);
|
content.OK($"取消{dt_Task.WMSTaskNum}任务成功", dt_Task);
|
}
|
else
|
{
|
content.Error($"任务{dt_Task.WMSTaskNum}失败{fOURBOTReturn.data}");
|
}
|
}
|
}
|
#endregion
|
|
#region 海康
|
if (isHK)
|
{
|
deviceName = "海康机器人";
|
cancelHIKROBOTTask = new CancelHIKROBOTTask
|
{
|
robotTaskCode = dt_Task.WMSTaskNum,
|
cancelType = "DROP"//原软取消,DROP人工介入(原硬取消)
|
};
|
var headers = new Dictionary<string, string>
|
{
|
{ "X-lr-request-id", DateTimeOffset.Now.ToUnixTimeSeconds().ToString() + wMSCancelTask.TaskCode }
|
};
|
|
Dt_ApiInfo? apiInfo = _apiInfoService.Repository.QueryFirst(x => x.ApiCode == nameof(CancelHIKROBOTTask));
|
if (apiInfo == null) throw new Exception("未找到四向车AGV任务下发接口配置信息!请检查接口配置");
|
string response = HttpHelper.Post(apiInfo.ApiAddress, cancelHIKROBOTTask.Serialize(), headers: headers);
|
HIKROBOTReturn hIKROBOTReturn = response.DeserializeObject<HIKROBOTReturn>();
|
content.OK(data: hIKROBOTReturn);
|
if (hIKROBOTReturn.code == "SUCCESS" && hIKROBOTReturn.message == "成功")
|
{
|
//直接移入历史
|
BaseDal.DeleteAndMoveIntoHty(dt_Task, OperateTypeEnum.自动完成);
|
content.OK("取消{dt_Task.WMSTaskNum}任务成功", dt_Task);
|
}
|
else
|
{
|
content.Error($"任务{dt_Task.WMSTaskNum}失败,错误信息:{hIKROBOTReturn.data}");
|
}
|
|
}
|
|
#endregion
|
}
|
catch (Exception ex)
|
{
|
content.Error(ex.Message);
|
}
|
finally
|
{
|
_trackloginfoService.AddTrackLog(wMSCancelTask, content, $"取消{deviceName}任务,", "", "");
|
}
|
return content;
|
}
|
|
|
/// <summary>
|
/// 修改任务优先级
|
/// </summary>
|
/// <param name="updateTaskPriority"></param>
|
/// <returns></returns>
|
public WebResponseContent UpdateWMSTaskPriority(WMSUpdateTaskPriority updateTaskPriority)
|
{
|
WebResponseContent content = new WebResponseContent();
|
var updateGALAXISTaskGrade = new UpdateGALAXISTaskGrade();
|
var request = new UpdateAgvSXCTake();
|
var Hkrequest = new HIKROBOTTaskGrade();
|
try
|
{
|
Dt_Task dt_Task = BaseDal.QueryFirst(x => x.WMSTaskNum == updateTaskPriority.taskCode);
|
if (dt_Task == null) throw new Exception("未查询到任务号相关任务");
|
|
// 判断当前任务是否为凯乐士任务
|
bool isGALAXISTask = dt_Task.TaskType == (int)TaskTypeEnum.MLInbound ||
|
dt_Task.TaskType == (int)TaskTypeEnum.MLOutbound;
|
|
//四向车
|
bool isAGV = dt_Task.TaskType == (int)TaskTypeEnum.CPInbound || dt_Task.TaskType == (int)TaskTypeEnum.CPOutbound;
|
|
//海康
|
bool isHK = dt_Task.TaskType == (int)TaskTypeEnum.F01 || dt_Task.TaskType == (int)TaskTypeEnum.RK3F || dt_Task.TaskType == (int)TaskTypeEnum.CK3F || dt_Task.TaskType == (int)TaskTypeEnum.Q1TSJ4 || dt_Task.TaskType == (int)TaskTypeEnum.STU0003 || dt_Task.TaskType == (int)TaskTypeEnum.F02 || dt_Task.TaskType == (int)TaskTypeEnum.CHUKU1 || dt_Task.TaskType == (int)TaskTypeEnum.Q3RK || dt_Task.TaskType == (int)TaskTypeEnum.Q3CK;
|
//修改原本任务优先级
|
dt_Task.Grade = updateTaskPriority.taskPriority;
|
#region 凯乐士
|
if (isGALAXISTask)
|
{
|
updateGALAXISTaskGrade = new UpdateGALAXISTaskGrade
|
{
|
taskId = dt_Task.WMSTaskNum,
|
reportTime = DateTime.Now.ToString(),
|
priorityCode = updateTaskPriority.taskPriority,
|
};
|
Dt_ApiInfo? apiInfo = _apiInfoService.Repository.QueryFirst(x => x.ApiCode == nameof(UpdateGALAXISTaskGrade));
|
if (apiInfo == null) throw new Exception("未找到凯乐士AGV任务下发接口配置信息!请检查接口配置");
|
string response = HttpHelper.Post(apiInfo.ApiAddress, updateGALAXISTaskGrade.Serialize());
|
GALAXISReturn agvContent = response.DeserializeObject<GALAXISReturn>();
|
content.OK(data: agvContent);
|
if (agvContent.success == true && agvContent.code == 0)
|
{
|
|
BaseDal.UpdateData(dt_Task);
|
content.OK($"修改{dt_Task.WMSTaskNum}任务优先级成功", dt_Task);
|
}
|
else
|
{
|
content.Error($"{dt_Task.WMSTaskNum}任务失败,错误信息:{agvContent.data.returnInfo}");
|
}
|
}
|
#endregion
|
|
#region 四向车
|
if (isAGV)
|
{
|
request = new UpdateAgvSXCTake
|
{
|
taskID = dt_Task.RGVTaskId,
|
priority = updateTaskPriority.taskPriority
|
};
|
Dt_ApiInfo? apiInfo = _apiInfoService.Repository.QueryFirst(x => x.ApiCode == nameof(UpdateAgvSXCTake));
|
if (apiInfo == null) throw new Exception("未找到更新四向车任务优先级接口配置信息!请检查接口配置");
|
string response = HttpHelper.Post(apiInfo.ApiAddress, request.Serialize());
|
FOURBOTReturn fOURBOTReturn = response.DeserializeObject<FOURBOTReturn>();
|
content.OK(data: fOURBOTReturn);
|
if (fOURBOTReturn.returnCode == 0 && fOURBOTReturn.returnUserMsg == "成功")
|
{
|
BaseDal.UpdateData(dt_Task);
|
content.OK("修改{dt_Task.WMSTaskNum}任务优先级成功", dt_Task);
|
}
|
else
|
{
|
content.Error($"任务{dt_Task.WMSTaskNum}失败,错误信息:{fOURBOTReturn.data}");
|
}
|
}
|
|
#endregion
|
#region 海康
|
if (isHK)
|
{
|
Hkrequest = new HIKROBOTTaskGrade
|
{
|
robotTaskCode = dt_Task.WMSTaskNum,//任务号
|
initPriority = updateTaskPriority.taskPriority//优先级
|
};
|
Dt_ApiInfo? apiInfo = _apiInfoService.Repository.QueryFirst(x => x.ApiCode == nameof(HIKROBOTTaskGrade));
|
if (apiInfo == null) throw new Exception("未找到四向车AGV任务下发接口配置信息!请检查接口配置");
|
string response = HttpHelper.Post(apiInfo.ApiAddress, Hkrequest.Serialize());
|
HIKROBOTReturn hIKROBOTReturn = response.DeserializeObject<HIKROBOTReturn>();
|
content.OK(data: hIKROBOTReturn);
|
if (hIKROBOTReturn.code == "SUCCESS0" && hIKROBOTReturn.message == "成功")
|
{
|
BaseDal.UpdateData(dt_Task);
|
content.OK("修改{dt_Task.WMSTaskNum}任务优先级成功", dt_Task);
|
}
|
else
|
{
|
content.Error($"任务{dt_Task.WMSTaskNum}失败,错误信息{hIKROBOTReturn.data}");
|
}
|
}
|
#endregion
|
}
|
catch (Exception ex)
|
{
|
content.Error(ex.Message);
|
}
|
finally
|
{
|
// 在 finally 中判断哪个对象被赋值了
|
object logObject = null;
|
string deviceName = "";
|
|
if (updateGALAXISTaskGrade != null)
|
{
|
logObject = updateGALAXISTaskGrade;
|
deviceName = "凯乐士AGV";
|
}
|
else if (Hkrequest != null)
|
{
|
logObject = Hkrequest;
|
deviceName = "海康机器人";
|
}
|
else if (request != null)
|
{
|
logObject = request;
|
deviceName = "四向车";
|
}
|
|
if (logObject != null)
|
{
|
_trackloginfoService.AddTrackLog(logObject, content, $"修改{deviceName}任务优先级", "", "");
|
}
|
}
|
return content;
|
}
|
|
/// <summary>
|
/// 修改库位分区
|
/// </summary>
|
/// <returns></returns>
|
public WebResponseContent ModifyWMSLayoutZone(WMSUpdateLocationArea wMSUpdateLocationArea)
|
{
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
var rgv = new List<Dt_RGVLocationInfo>();
|
var kls = new List<Dt_KLSLocationInfo>();
|
var hk = new List<Dt_HKLocationInfo>();
|
if (wMSUpdateLocationArea.WarehouseId == 1)
|
{
|
var rgvList = _rGVLocationInfoService.Repository.QueryData(x => wMSUpdateLocationArea.LocationCodes.Contains(x.LocationCode)).ToList();
|
foreach (var item in rgvList)
|
{
|
item.WarehouseId = wMSUpdateLocationArea.UpdateAreaCode.ObjToInt();
|
}
|
rgv.AddRange(rgvList);
|
}
|
if (wMSUpdateLocationArea.WarehouseId == 2)
|
{
|
|
var KLSLocationInfoList = _kLSLocationInfoService.Repository.QueryData(x => wMSUpdateLocationArea.LocationCodes.Contains(x.LocationCode)).ToList();
|
foreach (var item in KLSLocationInfoList)
|
{
|
item.WarehouseId = wMSUpdateLocationArea.UpdateAreaCode.ObjToInt();
|
}
|
kls.AddRange(KLSLocationInfoList);
|
}
|
if (wMSUpdateLocationArea.WarehouseId == 3)
|
{
|
var hkList = _hKLocationInfoService.Repository.QueryData(x => wMSUpdateLocationArea.LocationCodes.Contains(x.LocationCode)).ToList();
|
foreach (var item in hkList)
|
{
|
item.WarehouseId = wMSUpdateLocationArea.UpdateAreaCode.ObjToInt();
|
}
|
hk.AddRange(hkList);
|
}
|
Db.Ado.BeginTran();
|
_rGVLocationInfoService.UpdateData(rgv);
|
_kLSLocationInfoService.UpdateData(kls);
|
_hKLocationInfoService.UpdateData(hk);
|
Db.Ado.CommitTran();
|
content.OK();
|
}
|
catch (Exception ex)
|
{
|
content.Error(ex.Message);
|
}
|
return content;
|
}
|
|
private void UpdateLocationCode(object LocationInfo, string updateAreaCode)
|
{
|
|
}
|
|
|
/// <summary>
|
/// 接收WMS任务信息
|
/// </summary>
|
/// <param name="taskDTOs">WMS任务对象集合</param>
|
/// <returns>返回处理结果</returns>
|
public WebResponseContent ReceiveWMSTask([NotNull] List<WMSTaskDTO> taskDTOs)
|
{
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
List<Dt_Task> tasks = new List<Dt_Task>();
|
foreach (var item in taskDTOs)
|
{
|
if (BaseDal.QueryFirst(x => x.TaskNum == item.TaskNum || x.PalletCode == item.PalletCode) != null)
|
{
|
continue;
|
}
|
Dt_Task task = _mapper.Map<Dt_Task>(item);
|
task.Creater = "WMS";
|
if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
|
{
|
List<Dt_Router> routers = _routerService.QueryNextRoutes(item.RoadWay, item.TargetAddress);
|
//暂不考虑多路径
|
if (routers.Count > 0)
|
{
|
task.TaskState = (int)TaskOutStatusEnum.OutNew;
|
task.CurrentAddress = item.SourceAddress;
|
task.NextAddress = routers.FirstOrDefault().ChildPosi;
|
}
|
}
|
else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)
|
{
|
List<Dt_Router> routers = _routerService.QueryNextRoutes(item.SourceAddress, item.TargetAddress);
|
//暂不考虑多路径
|
if (routers.Count > 0)
|
{
|
task.TaskState = (int)TaskInStatusEnum.InNew;
|
task.CurrentAddress = item.SourceAddress;
|
task.NextAddress = routers.FirstOrDefault().ChildPosi;
|
}
|
}
|
tasks.Add(task);
|
}
|
BaseDal.AddData(tasks);
|
|
_taskExecuteDetailService.AddTaskExecuteDetail(tasks.Select(x => x.TaskNum).ToList(), "接收WMS任务");
|
|
content = WebResponseContent.Instance.OK("成功");
|
}
|
catch (Exception ex)
|
{
|
content = WebResponseContent.Instance.Error($"任务接收错误,错误信息:{ex.Message}");
|
}
|
return content;
|
}
|
|
/// <summary>
|
/// 根据托盘号、起始地址向WMS请求任务
|
/// </summary>
|
/// <param name="palletCode">托盘号</param>
|
/// <param name="sourceAddress">起始地址</param>
|
/// <returns></returns>
|
public WebResponseContent RequestWMSTask(string palletCode, string sourceAddress)
|
{
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
WMSTaskDTO taskDTO = new WMSTaskDTO()
|
{
|
TaskNum = Convert.ToInt32(DateTime.Now.ToString("HHmmss")),
|
Grade = 1,
|
PalletCode = palletCode,
|
RoadWay = "SC01",
|
SourceAddress = sourceAddress,
|
TargetAddress = "SC01",
|
TaskState = (int)TaskInStatusEnum.InNew,
|
Id = 0,
|
TaskType = (int)TaskInboundTypeEnum.Inbound
|
};
|
|
content = ReceiveWMSTask(new List<WMSTaskDTO> { taskDTO });
|
}
|
catch (Exception ex)
|
{
|
content = WebResponseContent.Instance.Error(ex.Message);
|
}
|
return content;
|
}
|
|
/// <summary>
|
/// 根据设备编号、当前地址查询输送线未执行的任务
|
/// </summary>
|
/// <param name="deviceNo">设备编号</param>
|
/// <param name="currentAddress">当前地址</param>
|
/// <returns></returns>
|
public Dt_Task QueryConveyorLineTask(string deviceNo, string currentAddress)
|
{
|
return BaseDal.QueryFirst(x => (TaskInboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskInStatusEnum.InNew || TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.SC_OutFinish) && x.CurrentAddress == currentAddress, TaskOrderBy);
|
}
|
|
/// <summary>
|
/// 根据任务号、下一地址查询输送线执行中的任务
|
/// </summary>
|
/// <param name="taskNum">任务号</param>
|
/// <param name="nextAddress">下一地址</param>
|
/// <returns></returns>
|
public Dt_Task QueryExecutingConveyorLineTask(int taskNum, string nextAddress)
|
{
|
return BaseDal.QueryFirst(x => x.TaskNum == taskNum && x.NextAddress == nextAddress && (x.TaskState == (int)TaskInStatusEnum.Line_InExecuting || x.TaskState == (int)TaskOutStatusEnum.Line_OutExecuting), TaskOrderBy);
|
}
|
|
/// <summary>
|
/// 根据任务号、当前地址查询输送线完成的任务
|
/// </summary>
|
/// <param name="taskNum">任务号</param>
|
/// <param name="currentAddress">当前地址</param>
|
/// <returns></returns>
|
public Dt_Task QueryCompletedConveyorLineTask(int taskNum, string currentAddress)
|
{
|
return BaseDal.QueryFirst(x => x.TaskNum == taskNum && x.CurrentAddress == currentAddress && (x.TaskState == (int)TaskInStatusEnum.Line_InFinish || x.TaskState == (int)TaskOutStatusEnum.Line_OutFinish), TaskOrderBy);
|
}
|
|
/// <summary>
|
/// 根据设备编号、任务类型分组(可选)按照优先级以及创建时间排序查询任务池新增的任务
|
/// </summary>
|
/// <param name="deviceNo">设备编号</param>
|
/// <param name="taskTypeGroup">任务类型分组(可选)</param>
|
/// <returns></returns>
|
public Dt_Task? QuertStackerCraneTask(string deviceNo, TaskTypeGroup? taskTypeGroup = null)
|
{
|
if (taskTypeGroup == null)
|
return BaseDal.QueryFirst(x => x.Roadway == deviceNo && (TaskInboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskInStatusEnum.Line_InFinish || TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.OutNew), TaskOrderBy);
|
if (taskTypeGroup.Value == TaskTypeGroup.InboundGroup)
|
return BaseDal.QueryFirst(x => x.Roadway == deviceNo && TaskInboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskInStatusEnum.Line_InFinish, TaskOrderBy);
|
if (taskTypeGroup.Value == TaskTypeGroup.OutbondGroup)
|
return BaseDal.QueryFirst(x => x.Roadway == deviceNo && TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.OutNew, TaskOrderBy);
|
return null;
|
}
|
|
/// <summary>
|
/// 根据设备编号、当前地址按照优先级以及创建时间排序查询任务池新增的任务
|
/// </summary>
|
/// <param name="deviceNo">设备编号</param>
|
/// <param name="currentAddress">当前地址</param>
|
/// <returns>返回任务实体对象,可能为null</returns>
|
public Dt_Task QueryStackerCraneTask(string deviceNo, string currentAddress = "")
|
{
|
if (string.IsNullOrEmpty(currentAddress))
|
return BaseDal.QueryFirst(x => x.Roadway == deviceNo && (TaskInboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskInStatusEnum.Line_InFinish || TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.OutNew), TaskOrderBy);
|
else
|
return BaseDal.QueryFirst(x => x.Roadway == deviceNo && x.CurrentAddress == currentAddress && (TaskInboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskInStatusEnum.Line_InFinish || TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.OutNew), TaskOrderBy);
|
}
|
|
/// <summary>
|
/// 根据设备编号、当前地址按照优先级以及创建时间排序查询任务池入库类型的新增的任务
|
/// </summary>
|
/// <param name="deviceNo">设备编号</param>
|
/// <param name="currentAddress">当前地址</param>
|
/// <returns>返回任务实体对象,可能为null</returns>
|
public Dt_Task QueryStackerCraneInTask(string deviceNo, string currentAddress = "")
|
{
|
if (string.IsNullOrEmpty(currentAddress))
|
return BaseDal.QueryFirst(x => x.Roadway == deviceNo && TaskInboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskInStatusEnum.Line_InFinish, TaskOrderBy);
|
else
|
return BaseDal.QueryFirst(x => x.Roadway == deviceNo && TaskInboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskInStatusEnum.Line_InFinish && x.CurrentAddress == currentAddress, TaskOrderBy);
|
}
|
|
/// <summary>
|
/// 根据设备编号、当前地址按照优先级以及创建时间排序查询任务池出库类型的新增的任务
|
/// </summary>
|
/// <param name="deviceNo">设备编号</param>
|
/// <param name="currentAddress">当前地址</param>
|
/// <returns>返回任务实体对象,可能为null</returns>
|
public Dt_Task QueryStackerCraneOutTask(string deviceNo, string currentAddress = "")
|
{
|
if (string.IsNullOrEmpty(currentAddress))
|
return BaseDal.QueryFirst(x => x.Roadway == deviceNo && TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.OutNew, TaskOrderBy);
|
else
|
return BaseDal.QueryFirst(x => x.Roadway == deviceNo && TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.OutNew && x.CurrentAddress == currentAddress, TaskOrderBy);
|
}
|
|
/// <summary>
|
/// 根据设备编号、当前地址按照优先级以及创建时间排序查询任务池出库类型的新增的任务
|
/// </summary>
|
/// <param name="deviceNo">设备编号</param>
|
/// <param name="currentAddress">当前地址</param>
|
/// <returns>返回任务实体对象集合,可能为null</returns>
|
public List<Dt_Task> QueryStackerCraneOutTasks(string deviceNo, List<string> outStationCodes)
|
{
|
return BaseDal.QueryData(x => x.Roadway == deviceNo && TaskOutboundTypes.Contains(x.TaskType) && x.TaskState == (int)TaskOutStatusEnum.OutNew && outStationCodes.Contains(x.CurrentAddress), TaskOrderBy);
|
}
|
|
/// <summary>
|
/// 更新任务异常信息显示
|
/// </summary>
|
/// <param name="taskNum">任务号</param>
|
/// <param name="message">异常信息</param>
|
public WebResponseContent UpdateTaskExceptionMessage(int taskNum, string message)
|
{
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
|
if (task == null) return WebResponseContent.Instance.Error($"未找到该任务信息,任务号:【{taskNum}】");
|
if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
|
{
|
task.TaskState = (int)TaskOutStatusEnum.OutPending;
|
}
|
else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)
|
{
|
task.TaskState = (int)TaskInStatusEnum.InPending;
|
}
|
task.ExceptionMessage = message;
|
task.ModifyDate = DateTime.Now;
|
BaseDal.UpdateData(task);
|
|
_taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, task.ExceptionMessage);
|
|
content = WebResponseContent.Instance.OK();
|
}
|
catch (Exception ex)
|
{
|
content = WebResponseContent.Instance.Error(ex.Message);
|
}
|
return content;
|
}
|
|
/// <summary>
|
/// 更新任务状态信息,并同步至WMS
|
/// </summary>
|
/// <param name="taskNum">任务号</param>
|
/// <param name="status">任务状态</param>
|
public void UpdateTaskStatus(int taskNum, int status)
|
{
|
Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
|
if (task == null) return;
|
task.TaskState = status;
|
task.ModifyDate = DateTime.Now;
|
BaseDal.UpdateData(task);
|
}
|
|
/// <summary>
|
/// 将任务状态修改为下一个状态
|
/// </summary>
|
/// <param name="taskNum">任务号</param>
|
public WebResponseContent UpdateTaskStatusToNext(int taskNum)
|
{
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
|
if (task == null) return WebResponseContent.Instance.Error($"未找到该任务信息,任务号:【{taskNum}】");
|
return UpdateTaskStatusToNext(task);
|
}
|
catch (Exception ex)
|
{
|
content = WebResponseContent.Instance.Error(ex.Message);
|
}
|
return content;
|
}
|
|
/// <summary>
|
/// 将任务状态修改为下一个状态
|
/// </summary>
|
/// <param name="task">任务实体对象</param>
|
/// <returns></returns>
|
public WebResponseContent UpdateTaskStatusToNext([NotNull] Dt_Task task)
|
{
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
int oldState = task.TaskState;
|
if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
|
{
|
if (task.TaskState >= (int)TaskOutStatusEnum.OutFinish)
|
{
|
return content = WebResponseContent.Instance.Error($"该任务状态不可跳转到下一步,任务号:【{task.TaskNum}】,任务状态:【{task.TaskState}】");
|
}
|
|
int nextStatus = task.TaskState.GetNextNotCompletedStatus<TaskOutStatusEnum>();
|
|
task.TaskState = nextStatus;
|
}
|
else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)
|
{
|
if (task.TaskState >= (int)TaskInStatusEnum.InFinish)
|
{
|
return content = WebResponseContent.Instance.Error($"该任务状态不可跳转到下一步,任务号:【{task.TaskNum}】,任务状态:【{task.TaskState}】");
|
}
|
|
int nextStatus = task.TaskState.GetNextNotCompletedStatus<TaskInStatusEnum>();
|
task.TaskState = nextStatus;
|
|
if (task.TaskState == (int)TaskInStatusEnum.Line_InFinish)
|
{
|
Random random = new Random();
|
task.CurrentAddress = task.NextAddress;
|
task.NextAddress = $"{random.Next(1, 100).ToString().PadLeft(3, '0')}-{random.Next(1, 100).ToString().PadLeft(3, '0')}-{random.Next(1, 100).ToString().PadLeft(3, '0')}";
|
task.TargetAddress = task.NextAddress;
|
}
|
}
|
else
|
{
|
throw new Exception($"任务类型错误,未找到该任务类型,任务号:【{task.TaskNum}】,任务类型:【{task.TaskType}】");
|
}
|
|
if (task.TaskState <= 0)
|
{
|
return content = WebResponseContent.Instance.Error($"该任务状态不可跳转到下一步,任务号:【{task.TaskNum}】,任务状态:【{task.TaskState}】");
|
}
|
|
task.ModifyDate = DateTime.Now;
|
task.Modifier = "System";
|
BaseDal.UpdateData(task);
|
|
_taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, App.User.UserId > 0 ? $"人工手动将任务状态从【{oldState}】跳转到【{task.TaskState}】" : $"系统自动流程,任务状态从【{oldState}】转到【{task.TaskState}】");
|
|
content = WebResponseContent.Instance.OK();
|
}
|
catch (Exception ex)
|
{
|
content = WebResponseContent.Instance.Error(ex.Message);
|
}
|
return content;
|
}
|
|
/// <summary>
|
/// 根据任务号、当前地址更新任务位置信息
|
/// </summary>
|
/// <param name="taskNum">任务号</param>
|
/// <param name="currentAddress">当前地址</param>
|
/// <returns></returns>
|
public Dt_Task? UpdatePosition(int taskNum, string currentAddress)
|
{
|
try
|
{
|
Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum && x.CurrentAddress == currentAddress);
|
if (task == null) throw new Exception($"未找到该任务信息,任务号:【{taskNum}】");
|
|
string oldCurrentPos = task.CurrentAddress;
|
string oldNextPos = task.NextAddress;
|
|
List<Dt_Router> routers = _routerService.QueryNextRoutes(task.NextAddress, task.TargetAddress);
|
if (!routers.Any()) throw new Exception($"未找到设备路由信息");
|
|
task.CurrentAddress = task.NextAddress;
|
task.NextAddress = routers.FirstOrDefault().ChildPosi;
|
|
task.ModifyDate = DateTime.Now;
|
task.Modifier = "System";
|
BaseDal.UpdateData(task);
|
|
_taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, $"系统自动流程,更新当前位置【{oldCurrentPos} ----> {task.CurrentAddress}】和下一位置【{oldNextPos} ----> {task.NextAddress}】");
|
return task;
|
}
|
catch (Exception ex)
|
{
|
}
|
return null;
|
}
|
|
/// <summary>
|
/// 任务完成
|
/// </summary>
|
/// <param name="taskNum">任务编号</param>
|
/// <returns>返回处理结果</returns>
|
public WebResponseContent StackCraneTaskCompleted(int taskNum)
|
{
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
|
if (task == null) return WebResponseContent.Instance.Error($"未找到该任务信息,任务号:【{taskNum}】");
|
|
if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup && task.TaskState == (int)TaskOutStatusEnum.SC_OutExecuting)
|
{
|
List<Dt_Router> routers = _routerService.QueryNextRoutes(task.NextAddress, task.TargetAddress);
|
if (!routers.Any()) return WebResponseContent.Instance.Error($"未找到设备路由信息");
|
|
int nextStatus = task.TaskState.GetNextNotCompletedStatus<TaskOutStatusEnum>();
|
task.TaskState = nextStatus;
|
task.CurrentAddress = task.NextAddress;
|
task.NextAddress = routers.FirstOrDefault().ChildPosi;
|
task.ModifyDate = DateTime.Now;
|
task.Modifier = "System";
|
BaseDal.UpdateData(task);
|
|
_taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, $"堆垛机出库完成");
|
//todo 同步到WMS
|
|
//暂不考虑多个出库口
|
}
|
else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup && task.TaskState == (int)TaskInStatusEnum.SC_InExecuting)
|
{
|
//todo
|
int nextStatus = task.TaskState.GetNextNotCompletedStatus<TaskInStatusEnum>();
|
task.TaskState = nextStatus;
|
task.ModifyDate = DateTime.Now;
|
task.Modifier = "System";
|
BaseDal.UpdateData(task);
|
_taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, $"堆垛机入库完成");
|
|
WMSTaskDTO taskDTO = new WMSTaskDTO()
|
{
|
TaskNum = Convert.ToInt32(DateTime.Now.ToString("HHmmss")),
|
Grade = 1,
|
PalletCode = task.PalletCode + "S",
|
RoadWay = "SC01",
|
SourceAddress = task.TargetAddress,
|
TargetAddress = "CLOutAreaA",
|
TaskState = (int)TaskOutStatusEnum.OutNew,
|
Id = 0,
|
TaskType = (int)TaskOutboundTypeEnum.Outbound
|
};
|
|
content = ReceiveWMSTask(new List<WMSTaskDTO> { taskDTO });
|
}
|
else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.RelocationGroup)
|
{
|
//todo 调用WMS移库完成
|
}
|
else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OtherGroup)
|
{
|
|
}
|
else
|
{
|
throw new Exception($"任务类型错误,未找到该任务类型,任务号:【{taskNum}】,任务类型:【{task.TaskType}】");
|
}
|
content = WebResponseContent.Instance.OK();
|
}
|
catch (Exception ex)
|
{
|
content = WebResponseContent.Instance.Error($"任务完成异常,任务号:【{taskNum}】");
|
}
|
return content;
|
}
|
|
/// <summary>
|
/// 恢复挂起任务
|
/// </summary>
|
/// <param name="taskNum">任务号</param>
|
/// <returns>返回处理结果</returns>
|
public WebResponseContent TaskStatusRecovery(int taskNum)
|
{
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
|
if (task == null) return WebResponseContent.Instance.Error($"未找到该任务信息,任务号:【{taskNum}】");
|
if (task.TaskState != (int)TaskInStatusEnum.InPending && task.TaskState != (int)TaskOutStatusEnum.OutPending)
|
{
|
return content = WebResponseContent.Instance.Error($"该任务状态不可恢复,任务号:【{taskNum}】,任务状态:【{task.TaskState}】");
|
}
|
|
Dt_TaskExecuteDetail taskExecuteDetail = _taskExecuteDetailRepository.QueryFirst(x => x.TaskId == task.TaskId && x.IsNormal, new Dictionary<string, OrderByType> { { nameof(Dt_TaskExecuteDetail.TaskDetailId), OrderByType.Desc } });
|
if (taskExecuteDetail != null)
|
{
|
task.TaskState = taskExecuteDetail.TaskState;
|
}
|
else
|
{
|
if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.OutbondGroup)
|
{
|
task.TaskState = (int)TaskOutStatusEnum.OutNew;
|
}
|
else if (task.TaskType.GetTaskTypeGroup() == TaskTypeGroup.InboundGroup)
|
{
|
task.TaskState = (int)TaskInStatusEnum.InNew;
|
}
|
//todo
|
}
|
|
task.ExceptionMessage = string.Empty;
|
|
BaseDal.UpdateData(task);
|
|
_taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, $"人工恢复挂起任务,恢复挂起时任务状态【{task.TaskState}】");
|
|
content = WebResponseContent.Instance.OK();
|
}
|
catch (Exception ex)
|
{
|
content = WebResponseContent.Instance.Error(ex.Message);
|
}
|
return content;
|
}
|
|
/// <summary>
|
/// 回滚任务状态
|
/// </summary>
|
/// <param name="taskNum">任务号</param>
|
/// <returns>返回处理结果</returns>
|
public WebResponseContent RollbackTaskStatusToLast(int taskNum)
|
{
|
WebResponseContent content = new();
|
try
|
{
|
Dt_Task task = BaseDal.QueryFirst(x => x.TaskNum == taskNum);
|
if (task == null) return WebResponseContent.Instance.Error($"未找到该任务信息,任务号:【{taskNum}】");
|
|
int oldState = task.TaskState;
|
Dt_TaskExecuteDetail taskExecuteDetail = _taskExecuteDetailRepository.QueryFirst(x => x.TaskId == task.TaskId && x.TaskState < task.TaskState && x.TaskState > 0, new Dictionary<string, OrderByType> { { nameof(Dt_TaskExecuteDetail.TaskDetailId), OrderByType.Desc } });
|
if (taskExecuteDetail != null)
|
{
|
task.TaskState = taskExecuteDetail.TaskState;
|
task.CurrentAddress = taskExecuteDetail.CurrentAddress;
|
task.NextAddress = taskExecuteDetail.NextAddress;
|
}
|
else
|
{
|
return content = WebResponseContent.Instance.Error($"未找到任务明细信息,该任务状态不可回滚到上一步,任务号:【{taskNum}】,任务状态:【{task.TaskState}】");
|
}
|
|
task.ExceptionMessage = string.Empty;
|
|
BaseDal.UpdateData(task);
|
|
_taskExecuteDetailService.AddTaskExecuteDetail(task.TaskId, $"人工将任务状态从【{oldState}】回滚到【{task.TaskState}】");
|
|
content = WebResponseContent.Instance.OK();
|
}
|
catch (Exception ex)
|
{
|
content = WebResponseContent.Instance.Error(ex.Message);
|
}
|
return content;
|
}
|
|
static object lock_taskNum = new object();
|
public int GetTaskNum(string sequenceName)
|
{
|
lock (lock_taskNum)
|
{
|
return Db.Ado.GetScalar($"SELECT NEXT VALUE FOR {sequenceName}").ObjToInt();
|
}
|
}
|
|
/// <summary>
|
/// 区域库位信息查询
|
/// </summary>
|
/// <param name="AreaCode"></param>
|
/// <returns></returns>
|
/// <exception cref="NotImplementedException">区域号</exception>
|
public WebResponseContent LocationInquiry(WMSGetLocationInfo getLocationInfo)
|
{
|
WebResponseContent content = new WebResponseContent();
|
List<object> list = new List<object>();
|
try
|
{
|
if (getLocationInfo == null) throw new Exception("请求参数不能为空!");
|
//if (getLocationInfo.AreaCode == null) throw new Exception("库区编号不能为空!");
|
if (getLocationInfo.WarehouseId == 0) throw new Exception("仓库ID不能为空!");
|
if (getLocationInfo.WarehouseId == 1)
|
{
|
List<Dt_RGVLocationInfo> rGVLocationInfos = new List<Dt_RGVLocationInfo>();
|
if (!string.IsNullOrEmpty(getLocationInfo.AreaCode))
|
rGVLocationInfos = _rGVLocationInfoService.Repository.QueryData(x => x.WarehouseId == getLocationInfo.AreaCode.ObjToInt());
|
else
|
rGVLocationInfos = _rGVLocationInfoService.Repository.QueryData();
|
foreach (var item in rGVLocationInfos)
|
{
|
list.Add(new
|
{
|
LoctionCode = item.LocationCode,
|
LocationStatus = item.LocationStatus,
|
EnableStatus = item.EnableStatus,
|
PalletCode = item.PalletCode
|
|
});
|
}
|
content.OK(data: list);
|
}
|
else if (getLocationInfo.WarehouseId == 2)
|
{
|
List<Dt_KLSLocationInfo> rGVLocationInfos = new List<Dt_KLSLocationInfo>();
|
if (!string.IsNullOrEmpty(getLocationInfo.AreaCode))
|
rGVLocationInfos = _kLSLocationInfoService.Repository.QueryData(x => x.WarehouseId == getLocationInfo.AreaCode.ObjToInt());
|
else
|
rGVLocationInfos = _kLSLocationInfoService.Repository.QueryData();
|
foreach (var item in rGVLocationInfos)
|
{
|
list.Add(new
|
{
|
LoctionCode = item.LocationCode,
|
LocationStatus = item.LocationStatus,
|
EnableStatus = item.EnableStatus,
|
PalletCode = item.PalletCode
|
});
|
}
|
content.OK(data: list);
|
}
|
else if (getLocationInfo.WarehouseId == 3)
|
{
|
//这里是提升机的
|
var device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "TSJ") as OtherDevice;
|
if (device == null) throw new Exception("未找到提升机设备信息");
|
if (!device.IsConnected) throw new Exception("PLC1提升机设备连接失败");
|
var value = device.GetValue<HoistEnum, short>(HoistEnum.Outboundmaterialbox, "TSJC3F");
|
list.Add(new
|
{
|
LoctionCode = value,
|
LocationStatus = value != 0 ? 100 : 0,
|
EnableStatus = 0,
|
});
|
content.OK(data: list);
|
}
|
else if (getLocationInfo.WarehouseId == 4)
|
{
|
List<Dt_HKLocationInfo> rGVLocationInfos = new List<Dt_HKLocationInfo>();
|
if (!string.IsNullOrEmpty(getLocationInfo.AreaCode))
|
rGVLocationInfos = _hKLocationInfoService.Repository.QueryData(x => x.WarehouseId == getLocationInfo.AreaCode.ObjToInt());
|
else
|
rGVLocationInfos = _hKLocationInfoService.Repository.QueryData();
|
foreach (var item in rGVLocationInfos)
|
{
|
list.Add(new
|
{
|
LoctionCode = item.LocationCode,
|
LocationStatus = item.LocationStatus,
|
EnableStatus = item.EnableStatus,
|
PalletCode = item.PalletCode
|
});
|
}
|
content.OK(data: list);
|
}
|
else if (getLocationInfo.WarehouseId == 5)
|
{
|
//读取光电信号
|
var device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "F1") as OtherDevice;
|
if (device == null) throw new Exception("未找到1楼质检门设备信息");
|
if (!device.IsConnected) throw new Exception("PLC1楼质检门设备连接失败");
|
var sta = _stationMangerService.Repository.QueryData(x => x.StationName.Contains("成品仓"));
|
foreach (var item in sta)
|
{
|
bool value = device.GetValue<QualityInspectionCommandEnum, bool>(QualityInspectionCommandEnum.R_StockAvailableSymbol, item.StationCode);
|
list.Add(new
|
{
|
LoctionCode = item.StationCode,
|
LocationStatus = value ? 100 : 0,
|
EnableStatus = 0,
|
});
|
}
|
content.OK(data: list);
|
}
|
}
|
catch (Exception ex)
|
{
|
content.Error(ex.Message);
|
}
|
return content;
|
}
|
|
|
/// <summary>
|
/// 地图同步
|
/// </summary>
|
/// <param name="mapSynchronizationDto"></param>
|
/// <returns></returns>
|
public WebResponseContent MapSynchronize(MapSynchronizationDto mapSynchronizationDto)
|
{
|
return WebResponseContent.Instance;
|
}
|
|
/// <summary>
|
/// 出入库完成
|
/// </summary>
|
/// <param name=""></param>
|
/// <returns></returns>
|
/// <exception cref="NotImplementedException"></exception>
|
public WebResponseContent InandoutCompleted(WMSInOutBoundCompleteFeedback wMSInOutBoundCompleteFeedback)
|
{
|
throw new NotImplementedException();
|
}
|
public WebResponseContent InboundElevatorExit(string LocationCode, string containerCode)
|
{
|
WebResponseContent content = new WebResponseContent();
|
inboundElevatorExitDTO inboundElevator=new inboundElevatorExitDTO();
|
try
|
{
|
Dt_ApiInfo? apiInfo = _apiInfoService.Repository.QueryFirst(x => x.ApiCode == nameof(inboundElevatorExitDTO)) ?? throw new Exception("未找到4F提升机出口托盘号上报WMS接口配置信息!请检查接口配置");
|
inboundElevator.containerCode= containerCode;
|
inboundElevator.toLocationCode = LocationCode;
|
string response = HttpHelper.Post(apiInfo.ApiAddress, inboundElevator.Serialize());
|
content.OK(data: response);
|
return WebResponseContent.Instance.OK();
|
}
|
catch (Exception ex)
|
{
|
return WebResponseContent.Instance.Error(ex.Message);
|
}
|
finally
|
{
|
_trackloginfoService.AddTrackLog(inboundElevator, content, "4F提升机出口托盘号上报WMS", "", "");
|
}
|
}
|
/// <summary>
|
/// 料箱验证
|
/// </summary>
|
/// <param name="taskCode">任务号</param>
|
/// <param name="containerCode">容器编码</param>
|
/// <returns></returns>
|
public WebResponseContent MaterialBoxInspection(string taskCode, string containerCode)
|
{
|
WebResponseContent content = new WebResponseContent();
|
inboundTransportCheckDTO checkDTO = new inboundTransportCheckDTO();
|
try
|
{
|
checkDTO.containerCode = containerCode;
|
Dt_ApiInfo? apiInfo = _apiInfoService.Repository.QueryFirst(x => x.ApiCode == nameof(inboundTransportCheckDTO)) ?? throw new Exception("未找到裁片入库3F到4F运输箱号校验接口配置信息!请检查接口配置");
|
string response = HttpHelper.Post(apiInfo.ApiAddress, checkDTO.Serialize());
|
content.OK(data: response);
|
WMSReturn wMSReturn = response.DeserializeObject<WMSReturn>();
|
if (wMSReturn == null) throw new Exception("WMS返回结果转换失败!");
|
if (!wMSReturn.success) throw new Exception(wMSReturn.message);
|
string dataJson = wMSReturn.result.ToString();
|
Exists? exists = JsonConvert.DeserializeObject<Exists>(dataJson);
|
if (exists == null) throw new Exception($"WMS返回结果的result转换失败");
|
return WebResponseContent.Instance.OK(exists.errorAreaCode);
|
}
|
catch (Exception ex)
|
{
|
return WebResponseContent.Instance.Error(ex.Message);
|
}
|
finally
|
{
|
_trackloginfoService.AddTrackLog(checkDTO, content, "裁片入库3F到4F运输箱号校验", "", "");
|
}
|
}
|
|
/// <summary>
|
/// wcs移库数据回传
|
/// </summary>
|
/// <param name="wMSMoveLocationFeedback"></param>
|
public WebResponseContent WcsMovingDataBack(WMSMoveLocationFeedback wMSMoveLocationFeedback)
|
{
|
throw new NotImplementedException();
|
}
|
/// <summary>
|
/// 容器流动请求
|
/// </summary>
|
/// <param name="wMSContainerFlow"></param>
|
/// <returns></returns>
|
/// <exception cref="NotImplementedException"></exception>
|
public WebResponseContent ContainerRequest(WMSContainerFlow wMSContainerFlow)
|
{
|
try
|
{
|
Dt_StationManger stationManger = _stationMangerService.Repository.QueryFirst(x => x.StationCode == wMSContainerFlow.slotCode) ?? throw new Exception($"未找到站台【{wMSContainerFlow.slotCode}】信息");
|
Dt_ApiInfo? apiInfo = _apiInfoService.Repository.QueryFirst(x => x.ApiCode == "releaseStation") ?? throw new Exception("未找到站点容器释放接口配置信息!请检查接口配置");
|
if (wMSContainerFlow.direction == "200")
|
{
|
stationManger.IsOccupied = LocationStatusEnum.Free.ObjToInt();
|
FOURBOToccupyStation fOURBOToccupyStation = new FOURBOToccupyStation()
|
{
|
stationCode = wMSContainerFlow.slotCode,
|
};
|
string response = HttpHelper.Post(apiInfo.ApiAddress, fOURBOToccupyStation.Serialize());
|
FOURBOTReturn fOURBOTReturn = response.DeserializeObject<FOURBOTReturn>();
|
if (fOURBOTReturn.returnCode != 0) throw new Exception(fOURBOTReturn.returnUserMsg);
|
_stationMangerService.UpdateData(stationManger);
|
}
|
return WebResponseContent.Instance.OK();
|
}
|
catch (Exception ex)
|
{
|
return WebResponseContent.Instance.Error(ex.Message);
|
}
|
}
|
/// <summary>
|
/// 质检结果反馈
|
/// </summary>
|
/// <param name="iQC"></param>
|
/// <returns></returns>
|
/// <exception cref="NotImplementedException"></exception>
|
public WebResponseContent IQCResult(IQCResultDTO iQC)
|
{
|
WebResponseContent content = new WebResponseContent();
|
try
|
{
|
#region 容器上架
|
Dt_StationManger stationManger = _stationMangerService.Repository.QueryFirst(x => x.StationCode == iQC.StationCode) ?? throw new Exception($"未找到站台【{iQC.StationCode}】信息");
|
Dt_ApiInfo? apiInfo = _apiInfoService.Repository.QueryFirst(x => x.ApiCode == nameof(FOURBOToccupyStation)) ?? throw new Exception("未找到站点容器上架接口配置信息!请检查接口配置");
|
FOURBOToccupyStation fOURBOToccupyStation = new FOURBOToccupyStation()
|
{
|
stationCode = iQC.StationCode,
|
podID = iQC.ContainerCode,
|
};
|
string response = HttpHelper.Post(apiInfo.ApiAddress, fOURBOToccupyStation.Serialize());
|
FOURBOTReturn fOURBOTReturn = response.DeserializeObject<FOURBOTReturn>();
|
content.OK(data: fOURBOTReturn);
|
if (fOURBOTReturn.returnCode != 0 /*&& fOURBOTReturn.returnUserMsg != $"站点已被占用,(podID={iQC.ContainerCode})"*/)
|
throw new Exception(fOURBOTReturn.returnUserMsg);
|
#endregion
|
|
#region 创建四向车任务
|
//var task = BaseDal.QueryFirst(x => x.PalletCode == iQC.ContainerCode && x.SourceAddress == iQC.StationCode && x.TaskState == (int)TaskStatusEnum.New);
|
#endregion
|
#region 呼叫四向车
|
//apiInfo = _apiInfoService.Repository.QueryFirst(x => x.ApiCode == nameof(FOURBOTnewMovePodTask)) ?? throw new Exception("未找到四向车任务下发接口配置信息!请检查接口配置");
|
//FOURBOTnewMovePodTask fOURBOTnewMovePodTask = new()
|
//{
|
// priority = task.Grade,
|
// podID = task.PalletCode,
|
// //desNodeID = task.SourceAddress,
|
// desExt = new
|
// {
|
// unload = 0//是否放下容器,0否1是
|
// },
|
// desStationCodes = task.SourceAddress,
|
// desType = 5
|
//};
|
//response = HttpHelper.Post(apiInfo.ApiAddress, fOURBOTnewMovePodTask.Serialize());
|
//fOURBOTReturn = response.DeserializeObject<FOURBOTReturn>();
|
//content.Data = fOURBOTReturn;
|
//if (fOURBOTReturn.returnCode != 0) throw new Exception(fOURBOTReturn.returnUserMsg);
|
//task.TaskState = (int)TaskStatusEnum.Execut;
|
//BaseDal.UpdateData(task);
|
#endregion
|
return WebResponseContent.Instance.OK();
|
}
|
catch (Exception ex)
|
{
|
return WebResponseContent.Instance.Error(ex.Message);
|
}
|
}
|
|
/// <summary>
|
/// 批量更新储位状态
|
/// </summary>
|
/// <param name="fOURBOTStorageStatusNotify"></param>
|
/// <returns></returns>
|
/// <exception cref="NotImplementedException"></exception>
|
public WebResponseContent multiSetNodeStatus(FOURBOTStorageStatusNotify fOURBOTStorageStatusNotify)
|
{
|
try
|
{
|
var Agvlocation = _rGVLocationInfoService.Repository.QueryData(x => fOURBOTStorageStatusNotify.storageCode.Contains(x.LocationCode));
|
foreach (var item in Agvlocation)
|
{
|
item.EnableStatus = (int)(fOURBOTStorageStatusNotify.disable == 0 ? EnableStatusEnum.Normal : EnableStatusEnum.Disable);
|
}
|
_rGVLocationInfoService.UpdateData(Agvlocation);
|
return WebResponseContent.Instance.OK();
|
}
|
catch (Exception ex)
|
{
|
|
return WebResponseContent.Instance.Error(ex.Message);
|
}
|
}
|
|
|
public override WebResponseContent DeleteData(object[] keys)
|
{
|
try
|
{
|
// 查找所有任务中包含这个id的
|
var take = BaseDal.QueryData(x => keys.Contains(x.TaskId));
|
|
// 执行移入历史操作,并检查结果
|
bool moveResult = BaseDal.DeleteAndMoveIntoHty(take, OperateTypeEnum.人工删除);
|
|
if (!moveResult)
|
{
|
// 移入历史失败,返回错误信息
|
return WebResponseContent.Instance.Error("移入历史记录失败");
|
}
|
return WebResponseContent.Instance.OK("删除成功,数据已移入历史");
|
}
|
catch (Exception ex)
|
{
|
// 记录异常日志
|
// Logger.Error(ex.Message);
|
return WebResponseContent.Instance.Error("删除失败:" + ex.Message);
|
}
|
}
|
|
|
|
}
|
}
|