#region << 版 本 注 释 >>
|
/*----------------------------------------------------------------
|
* 命名空间:WIDESEAWCS_TaskInfoService
|
* 创建者:胡童庆
|
* 创建时间:2024/8/2 16:13:36
|
* 版本:V1.0.0
|
* 描述:
|
*
|
* ----------------------------------------------------------------
|
* 修改人:
|
* 修改时间:
|
* 版本:V1.0.1
|
* 修改说明:
|
*
|
*----------------------------------------------------------------*/
|
#endregion << 版 本 注 释 >>
|
|
using AutoMapper;
|
using Castle.Components.DictionaryAdapter.Xml;
|
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
using Microsoft.OpenApi.Any;
|
using NetTaste;
|
using Newtonsoft.Json;
|
using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
|
using OfficeOpenXml.FormulaParsing.Excel.Functions.Math;
|
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
|
using SqlSugar;
|
using StackExchange.Profiling.Internal;
|
using System;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.Data;
|
using System.Diagnostics;
|
using System.Diagnostics.CodeAnalysis;
|
using System.Linq;
|
using System.Linq.Expressions;
|
using System.Reflection;
|
using System.Reflection.Metadata;
|
using System.Security.Cryptography.Xml;
|
using System.Security.Policy;
|
using System.Text;
|
using System.Threading.Tasks;
|
using WIDESEA_Comm.Http;
|
using WIDESEA_Common.Log;
|
using WIDESEA_Core.Enums;
|
using WIDESEAWCS_Common.TaskEnum;
|
using WIDESEAWCS_Core;
|
using WIDESEAWCS_Core.BaseServices;
|
using WIDESEAWCS_Core.Enums;
|
using WIDESEAWCS_Core.Utilities;
|
using WIDESEAWCS_DTO.Enum;
|
using WIDESEAWCS_DTO.TaskInfo;
|
using WIDESEAWCS_ITaskInfoRepository;
|
using WIDESEAWCS_ITaskInfoService;
|
using WIDESEAWCS_Model.Models;
|
using WIDESEAWCS_QuartzJob;
|
using WIDESEAWCS_QuartzJob.DTO;
|
using WIDESEAWCS_QuartzJob.Models;
|
using WIDESEAWCS_QuartzJob.Service;
|
using WIDESEAWCS_TaskInfoRepository;
|
using static Microsoft.IO.RecyclableMemoryStreamManager;
|
|
namespace WIDESEAWCS_TaskInfoService
|
{
|
public partial class TaskService
|
{
|
|
//============================================以下是后续新增内容查找任务=============================================================
|
#region wms任务模块
|
//任务下发
|
public ApiResponse saveTask(TransferTask transfer)
|
{
|
WriteLog.Write_Log("WMS任务下发接口", "WMS任务下发接口信息", "调取参数", transfer);
|
|
ApiResponse apiResponse = new ApiResponse();
|
try
|
{
|
if (transfer == null) return apiResponse.ErrorResponse("接收的WMS任务下发参数为空");
|
// 进一步校验必要字段
|
if (string.IsNullOrEmpty(transfer.taskType)) return apiResponse.ErrorResponse("任务类型不能为空");
|
if (string.IsNullOrEmpty(transfer.barCode)) return apiResponse.ErrorResponse("条码不能为空");
|
if (transfer.from == null || string.IsNullOrEmpty(transfer.from.code)) return apiResponse.ErrorResponse("起始位置不能为空");
|
if (transfer.to == null || string.IsNullOrEmpty(transfer.to.code)) return apiResponse.ErrorResponse("目标位置不能为空");
|
if (transfer.device == null || string.IsNullOrEmpty(transfer.device.uuid)) return apiResponse.ErrorResponse("设备标识不能为空");
|
|
Dt_Task setask = BaseDal.QueryData(x => x.WMStaskid == transfer.barCode).FirstOrDefault();
|
if (setask != null) return apiResponse.ErrorResponse($"WCS已有当前任务,不可重复下发,托盘编号:{transfer.barCode}");
|
|
|
|
(int TaskType, int TaskState) = transfer.taskType switch
|
{
|
"in" => ((int)TaskTypeEnum.Inbound, (int)TaskInStatusEnum.InNew),
|
"out" => ((int)TaskTypeEnum.Outbound, (int)TaskOutStatusEnum.OutNew),
|
"check" => ((int)TaskTypeEnum.Inventorybound, (int)TaskinventoryStatusEnum.inventoryNew),
|
_ => (0, 0) // 保持原有的默认值
|
};
|
|
Dt_Task task = new Dt_Task();
|
task.TaskNum = BaseDal.GetTaskNum(nameof(SequenceEnum.SeqTaskNum)); //任务编号
|
task.PalletCode = transfer.original_barCode;
|
task.Roadway = transfer.from.code.Substring(0, 1);
|
task.TaskType = TaskType;
|
task.TaskState = TaskState;
|
task.SourceAddress = transfer.from.code;
|
task.TargetAddress = transfer.to.code;
|
task.CurrentAddress = transfer.from.code;
|
task.NextAddress = transfer.to.code;
|
task.Grade = 1;
|
task.Creater = "WMS";
|
task.CreateDate = DateTime.Now;
|
task.deviceuuid = transfer.device.uuid;
|
|
_unitOfWorkManage.BeginTran();
|
BaseDal.AddData(task);
|
_unitOfWorkManage.CommitTran();
|
return apiResponse.SuccessResponse();
|
}
|
catch (Exception ex)
|
{
|
_unitOfWorkManage.RollbackTran();
|
return apiResponse.ErrorResponse($"WCS任务添加错误,原因:{ex.Message}");
|
}
|
}
|
|
|
|
//通知库口上料完成
|
public ApiResponse scanData(TaskReportingData taskReporting)
|
{
|
WriteLog.Write_Log("通知库口上料完成接口", "通知库口上料完成信息", "调取参数", taskReporting);
|
|
ApiResponse apiResponse = new ApiResponse();
|
try
|
{
|
if (taskReporting == null) return apiResponse.ErrorResponse("接收的WMS任务下发参数为空");
|
if (taskReporting.baseInfo == null) return apiResponse.ErrorResponse("库口基础数据baseInfo不能为空");
|
if (string.IsNullOrWhiteSpace(taskReporting.baseInfo.code)) return apiResponse.ErrorResponse("任务类型不能为空");
|
if (taskReporting.details == null || !taskReporting.details.Any()) return apiResponse.ErrorResponse("库口详情集合details不能为空/无数据");
|
|
|
|
return apiResponse.SuccessResponse();
|
}
|
catch (Exception ex)
|
{
|
return apiResponse.ErrorResponse($"WCS任务添加错误,原因:{ex.Message}");
|
}
|
}
|
|
//获取库口状态
|
public ApiResponse getPortStatus(string[] datas)
|
{
|
WriteLog.Write_Log("获取库口状态接口", "获取库口状态信息", "调取参数", datas);
|
|
ApiResponse apiResponse = new ApiResponse();
|
try
|
{
|
//IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == "1002");
|
//if (device == null) return apiResponse.ErrorResponse("WCS未能获取到库口实例");
|
//CommonConveyorLine conveyorLine = (CommonConveyorLine)device;
|
|
Dictionary<string, int> portStatusDict = new Dictionary<string, int>();
|
|
foreach (string DeStateName in datas)
|
{
|
//暂时数据
|
portStatusDict[DeStateName] = 1;
|
|
/*DeviceProDTO? deviceProDTO = conveyorLine.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == DeStateName && x.DeviceProParamName == "StationFree");
|
if (deviceProDTO == null) return apiResponse.ErrorResponse($"WCS未找到库口:{DeStateName},对应的协议");
|
conveyorLine.Communicator.Read<bool>(deviceProDTO.DeviceProAddress);
|
bool portStatus = conveyorLine.Communicator.Read<bool>(deviceProDTO.DeviceProAddress);
|
int statusValue = portStatus ? 1 : 0;
|
portStatusDict[DeStateName] = statusValue;*/
|
}
|
|
return apiResponse.SuccessResponse(portStatusDict);
|
}
|
catch (Exception ex)
|
{
|
return apiResponse.ErrorResponse($"WCS任务添加错误,原因:{ex.Message}");
|
}
|
}
|
|
|
//获取光幕状态
|
public ApiResponse getSafeStatus(string[] datas)
|
{
|
WriteLog.Write_Log("获取光幕状态接口", "获取光幕状态信息", "调取参数", setCurtain);
|
ApiResponse apiResponse = new ApiResponse();
|
try
|
{
|
Dictionary<string, int> portStatusDict = new Dictionary<string, int>();
|
foreach (string DeStateName in datas)
|
{
|
portStatusDict[DeStateName] = 1;
|
}
|
|
return apiResponse.SuccessResponse(portStatusDict);
|
}
|
catch (Exception ex)
|
{
|
return apiResponse.ErrorResponse($"WCS任务添加错误,原因:{ex.Message}");
|
}
|
}
|
|
|
//设置光幕
|
public ApiResponse setCurtain(SetCurtainRequest setCurtain)
|
{
|
//获取WMS调取的参数
|
WriteLog.Write_Log("设置光幕接口", "设置光幕信息", "调取参数", setCurtain);
|
|
ApiResponse apiResponse = new ApiResponse();
|
try
|
{
|
return apiResponse.SuccessResponse();
|
}
|
catch (Exception ex)
|
{
|
return apiResponse.ErrorResponse($"WCS任务添加错误,原因:{ex.Message}");
|
}
|
}
|
|
|
//agv进出状态反馈
|
public ApiResponse getAGVStatus(AgvUpdateRequest agvUpdateRequest)
|
{
|
//获取WMS调取的参数
|
WriteLog.Write_Log("agv进出状态反馈接口", "agv进出状态信息", "调取参数", setCurtain);
|
|
ApiResponse apiResponse = new ApiResponse();
|
try
|
{
|
|
|
return apiResponse.SuccessResponse();
|
}
|
catch (Exception ex)
|
{
|
return apiResponse.ErrorResponse($"WCS任务添加错误,原因:{ex.Message}");
|
}
|
}
|
#endregion
|
|
|
|
#region 调取上游接口
|
public CommandResult taskreturn(int taskId, string taskType, string invType, string psd)
|
{
|
CommandResult commandResult = new CommandResult();
|
try
|
{
|
TaskInfo taskInfo1 = new TaskInfo();
|
taskInfo1.taskId = taskId;
|
taskInfo1.taskType = taskType;
|
taskInfo1.invType = invType;
|
taskInfo1.psd = psd;
|
commandResult = HttpHelper.Post<CommandResult>(urlWMStaskreturn, taskInfo1, "任务状态回调");
|
|
WriteLog.Write_Log("同步给上游反馈任务完成", "任务信息", $"任务号:{taskId}", $"调取参数:{taskInfo1.ToJson()},返回参数:{commandResult.ToJson()}");
|
return commandResult;
|
}
|
catch (Exception ex)
|
{
|
commandResult.status = "error";
|
commandResult.result = $"WCS接口错误,原因:{ex.Message}";
|
|
WriteLog.Write_Log("同步给上游反馈任务完成", "任务信息", $"任务号:{taskId}", $"WCS接口错误,原因:{ex.Message}");
|
return commandResult;
|
}
|
|
}
|
|
public CommandResult deverror(string devuuid, string id, string errorcode, string errorinfo, string erroraddress, string warehouse, string remark, string devname, string dealType, string psd)
|
{
|
CommandResult commandResult = new CommandResult();
|
try
|
{
|
DeviceErrorRequest deviceErrorRequest = new DeviceErrorRequest
|
{
|
devErrorJsons = new List<DeviceErrorInfo>
|
{
|
new DeviceErrorInfo
|
{
|
devuuid = devuuid,
|
id = id,
|
errorcode = errorcode,
|
errorinfo = errorinfo,
|
erroraddress = erroraddress,
|
warehouse = warehouse,
|
remark = remark,
|
devname = devname
|
}
|
},
|
dealType = dealType,
|
psd = psd
|
};
|
|
commandResult = HttpHelper.Post<CommandResult>(urlWMSdeverror, deviceErrorRequest, "设备故障回调");
|
WriteLog.Write_Log("同步给上游设备故障信息", "设备故障信息", $"设备id:{devuuid},成功", $"调取参数:{deviceErrorRequest.ToJson()},返回参数:{commandResult.ToJson()}");
|
return commandResult;
|
}
|
catch (Exception ex)
|
{
|
commandResult.status = "error";
|
commandResult.result = $"WCS接口错误,原因:{ex.Message}";
|
|
WriteLog.Write_Log("同步给上游设备故障信息", "设备故障信息", $"设备id:{devuuid},失败", $"WCS接口错误,原因:{ex.Message}");
|
return commandResult;
|
}
|
|
}
|
|
|
public CommandResult liftinposition(string invtype, string invcode, string kloccode)
|
{
|
CommandResult commandResult = new CommandResult();
|
try
|
{
|
ShelvesPosition deviceErrorRequest = new ShelvesPosition
|
{
|
invtype= invtype,
|
invcode = invcode,
|
kloccode = kloccode
|
};
|
commandResult = HttpHelper.Post<CommandResult>(urlWMSliftinposition, deviceErrorRequest, "设备故障回调");
|
|
WriteLog.Write_Log("同步给上游提升到位信息", "信息内容", $"库口编号:{kloccode},成功信息", $"调取参数:{deviceErrorRequest.ToJson()},返回参数:{commandResult.ToJson()}");
|
return commandResult;
|
}
|
catch (Exception ex)
|
{
|
commandResult.status = "error";
|
commandResult.result = $"WCS接口错误,原因:{ex.Message}";
|
WriteLog.Write_Log("同步给上游提升到位信息", "信息内容", $"错误信息", $"WCS接口错误,原因:{ex.Message}");
|
return commandResult;
|
}
|
|
}
|
#endregion
|
}
|
}
|