#region << 版 本 注 释 >>
|
/*----------------------------------------------------------------
|
* 命名空间:WIDESEAWCS_TaskInfoService
|
* 创建者:胡童庆
|
* 创建时间:2024/8/2 16:13:36
|
* 版本:V1.0.0
|
* 描述:
|
*
|
* ----------------------------------------------------------------
|
* 修改人:
|
* 修改时间:
|
* 版本:V1.0.1
|
* 修改说明:
|
*
|
*----------------------------------------------------------------*/
|
#endregion << 版 本 注 释 >>
|
|
using AutoMapper;
|
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
using NetTaste;
|
using Newtonsoft.Json;
|
using OfficeOpenXml.FormulaParsing.Excel.Functions.DateTime;
|
using OfficeOpenXml.FormulaParsing.Excel.Functions.Text;
|
using SqlSugar;
|
using System;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.Diagnostics;
|
using System.Diagnostics.CodeAnalysis;
|
using System.Linq;
|
using System.Linq.Expressions;
|
using System.Reflection;
|
using System.Reflection.Metadata;
|
using System.Text;
|
using System.Threading.Tasks;
|
using WIDESEA_Comm.Http;
|
using WIDESEAWCS_Core;
|
using WIDESEAWCS_Core.BaseServices;
|
using WIDESEAWCS_Core.Enums;
|
using WIDESEAWCS_DTO.Enum;
|
using WIDESEAWCS_DTO.TaskInfo;
|
using WIDESEAWCS_ITaskInfoRepository;
|
using WIDESEAWCS_ITaskInfoService;
|
using WIDESEAWCS_Model.Models;
|
using WIDESEAWCS_QuartzJob.DTO;
|
using WIDESEAWCS_QuartzJob;
|
using WIDESEAWCS_QuartzJob.Service;
|
using System.Net;
|
using WIDESEAWCS_ISystemServices;
|
using System.Security.Claims;
|
using WIDESEAWCS_Common.TaskEnum;
|
|
namespace WIDESEAWCS_TaskInfoService
|
{
|
public class RgvOperationService : ServiceBase<Dt_Task_hty, ITask_HtyRepository>, IRgvOperationService
|
{
|
private readonly IAgvStationService _gvStationService;
|
private readonly ITaskRepository _taskRepository;
|
public RgvOperationService(ITask_HtyRepository BaseDal, IAgvStationService agvStationService, ITaskRepository taskRepository) : base(BaseDal)
|
{
|
_gvStationService = agvStationService;
|
_taskRepository = taskRepository;
|
}
|
|
|
public WebResponseContent WriteInitialization(SaveModel saveModel)
|
{
|
WebResponseContent webResponse = new WebResponseContent();
|
|
string DeviceName = saveModel.DelKeys[0].ToString(); //设备名称
|
IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceName);
|
SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
|
|
//获取实例
|
DeviceProDTO? RGV_RGVtasktypet = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_RGVtasktypet", "DeviceCommand"); //任务类型
|
//第一步写入任务
|
RgvSetLine(Commonstacker, RGV_RGVtasktypet.DeviceProAddress, (short)3);
|
|
//复位报警
|
DeviceProDTO? RGV_Resetoperation = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_Resetoperation", "DeviceCommand"); //复位报警信息
|
RgvSetLine(Commonstacker, RGV_Resetoperation.DeviceProAddress, (short)1);
|
|
//写入自动
|
DeviceProDTO? RGV_DWorkingmode = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_DWorkingmode", "DeviceCommand"); //任务id
|
RgvSetLine(Commonstacker, RGV_DWorkingmode.DeviceProAddress, (short)1);
|
|
//写入清除任务
|
RgvSetLine(Commonstacker, RGV_RGVtasktypet.DeviceProAddress, (short)4);
|
|
//反馈确认任务
|
DeviceProDTO? RGV_taskcomplete = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_taskcomplete", "RGV_taskcomplete"); //任务id
|
RgvSetLine(Commonstacker, RGV_taskcomplete.DeviceProAddress, (short)1);
|
|
return webResponse.OK();
|
}
|
|
public WebResponseContent WriteRGVmokuai(SaveModel saveModel)
|
{
|
WebResponseContent webResponse = new WebResponseContent();
|
string DeviceName = saveModel.DelKeys[0].ToString(); //工作类型
|
string DBType = saveModel.DelKeys[1].ToString(); //设备名称
|
short WriteRGVvalue = short.Parse(saveModel.DelKeys[2].ToString()); //写入值
|
IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceName);
|
SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
|
switch (DBType)
|
{
|
case "1": // 工作模式(0手动、1自动)
|
//获取实例
|
DeviceProDTO? RGV_DWorkingmode = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_DWorkingmode", "DeviceCommand"); //任务类型
|
//第一步写入任务
|
RgvSetLine(Commonstacker, RGV_DWorkingmode.DeviceProAddress, WriteRGVvalue);
|
break;
|
case "2": //复位操作(0不复位、1复位)
|
DeviceProDTO? RGV_Resetoperation = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_Resetoperation", "DeviceCommand"); //任务类型
|
//第一步写入任务
|
RgvSetLine(Commonstacker, RGV_Resetoperation.DeviceProAddress, WriteRGVvalue);
|
break;
|
case "3": //任务确认完成(0不确定,1确定)
|
DeviceProDTO? RGV_taskcomplete = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_taskcomplete", "RGV_taskcomplete"); //任务类型
|
//第一步写入任务
|
RgvSetLine(Commonstacker, RGV_taskcomplete.DeviceProAddress, WriteRGVvalue);
|
break;
|
case "4": //任务类型(4清除)
|
DeviceProDTO? RGV_RGVtasktypet = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_RGVtasktypet", "DeviceCommand"); //任务类型
|
//第一步写入任务
|
RgvSetLine(Commonstacker, RGV_RGVtasktypet.DeviceProAddress, WriteRGVvalue);
|
break;
|
}
|
return webResponse.OK();
|
}
|
|
/// <summary>
|
/// 手动移动RGV
|
/// </summary>
|
/// <param name="saveModel"></param>
|
/// <returns></returns>
|
public WebResponseContent ManualmovementRGV(SaveModel saveModel)
|
{
|
WebResponseContent webResponse = new WebResponseContent();
|
|
string DeviceName = saveModel.DelKeys[0].ToString(); //设备名称
|
short Nextaddres = short.Parse(saveModel.DelKeys[1].ToString());
|
IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceName);
|
SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
|
|
//获取实例
|
DeviceProDTO? RGV_RGVtasktypet = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_RGVtasktypet", "DeviceCommand"); //任务类型
|
//第一步写入任务
|
RgvSetLine(Commonstacker, RGV_RGVtasktypet.DeviceProAddress, (short)3);
|
|
//目标位置
|
DeviceProDTO? RGV_Resetoperation = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_RGVTasklocationt", "DeviceCommand"); //复位报警信息
|
RgvSetLine(Commonstacker, RGV_Resetoperation.DeviceProAddress, (short)Nextaddres);
|
|
//写入自动
|
DeviceProDTO? RGV_DWorkingmode = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_Rgvtaskidt", "DeviceCommand"); //任务id
|
//任务id
|
RgvSetLine(Commonstacker, RGV_DWorkingmode.DeviceProAddress, (short)30001);
|
|
//任务id
|
DeviceProDTO? RGV_taskcomplete = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_Lanjiantaskidt", "DeviceCommand"); //任务id
|
RgvSetLine(Commonstacker, RGV_taskcomplete.DeviceProAddress, (short)30001);
|
|
|
return webResponse.OK();
|
}
|
|
/// <summary>
|
/// 一键启动入库子母车
|
/// </summary>
|
public WebResponseContent WriteInReset(SaveModel saveModel)
|
{
|
WebResponseContent webResponse = new WebResponseContent();
|
|
List<AGVStation> rgvdata = _gvStationService.GetInStroller();
|
foreach (AGVStation rgvstation in rgvdata)
|
{
|
string DeviceName = rgvstation.ChildPosiDeviceCode; //设备名称
|
IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceName);
|
if (device == null) continue;
|
SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
|
|
//获取需要复位的设备
|
DeviceProDTO? RGV_Resetoperation = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_Resetoperation", "DeviceCommand"); //复位报警信息
|
RgvSetLine(Commonstacker, RGV_Resetoperation.DeviceProAddress, (short)1);
|
}
|
return webResponse.OK();
|
}
|
|
/// <summary>
|
/// 写入复位(出库端)
|
/// </summary>
|
public WebResponseContent WriteOutReset(SaveModel saveModel)
|
{
|
WebResponseContent webResponse = new WebResponseContent();
|
List<AGVStation> rgvdata = _gvStationService.GetOutStroller();
|
foreach (AGVStation rgvstation in rgvdata)
|
{
|
string DeviceName = rgvstation.ChildPosiDeviceCode; //设备名称
|
IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceName);
|
if (device == null) continue;
|
SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
|
|
//获取需要复位的设备
|
DeviceProDTO? RGV_Resetoperation = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_Resetoperation", "DeviceCommand"); //复位报警信息
|
RgvSetLine(Commonstacker, RGV_Resetoperation.DeviceProAddress, (short)0);
|
}
|
return webResponse.OK();
|
}
|
|
/// <summary>
|
/// 一键暂停
|
/// </summary>
|
/// <param name="saveModel"></param>
|
/// <returns></returns>
|
public WebResponseContent WriteOutbuttonpause(SaveModel saveModel)
|
{
|
WebResponseContent webResponse = new WebResponseContent();
|
List<AGVStation> rgvdata = _gvStationService.GetOutStroller();
|
foreach (AGVStation rgvstation in rgvdata)
|
{
|
string DeviceName = rgvstation.ChildPosiDeviceCode; //设备名称
|
IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceName);
|
if (device == null) continue;
|
SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
|
|
//获取需要复位的设备
|
DeviceProDTO? RGV_Resetoperation = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_DWorkingmode", "DeviceCommand");
|
RgvSetLine(Commonstacker, RGV_Resetoperation.DeviceProAddress, (short)0);
|
}
|
return webResponse.OK();
|
}
|
|
public WebResponseContent InWriteOutbuttonpause(SaveModel saveModel)
|
{
|
WebResponseContent webResponse = new WebResponseContent();
|
List<AGVStation> rgvdata = _gvStationService.InGetOutStroller();
|
foreach (AGVStation rgvstation in rgvdata)
|
{
|
string DeviceName = rgvstation.ChildPosiDeviceCode; //设备名称
|
IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceName);
|
if (device == null) continue;
|
SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
|
|
//获取需要复位的设备
|
DeviceProDTO? RGV_Resetoperation = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_DWorkingmode", "DeviceCommand");
|
RgvSetLine(Commonstacker, RGV_Resetoperation.DeviceProAddress, (short)0);
|
}
|
return webResponse.OK();
|
}
|
|
/// <summary>
|
/// 一键启动
|
/// </summary>
|
/// <param name="saveModel"></param>
|
/// <returns></returns>
|
public WebResponseContent WriteOuttouchstart(SaveModel saveModel)
|
{
|
WebResponseContent webResponse = new WebResponseContent();
|
List<AGVStation> rgvdata = _gvStationService.GetOutStroller();
|
foreach (AGVStation rgvstation in rgvdata)
|
{
|
string DeviceName = rgvstation.ChildPosiDeviceCode; //设备名称
|
IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceName);
|
if (device == null) continue;
|
SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
|
|
//获取需要复位的设备
|
DeviceProDTO? RGV_Resetoperation = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_DWorkingmode", "DeviceCommand");
|
RgvSetLine(Commonstacker, RGV_Resetoperation.DeviceProAddress, (short)1);
|
}
|
return webResponse.OK();
|
}
|
|
|
|
/// <summary>
|
/// 查询RGV设备
|
/// </summary>
|
/// <param name="Commonstacker"></param>
|
/// <param name="SCAddress"></param>
|
/// <param name="Interactivet"></param>
|
/// <returns></returns>
|
public static DeviceProDTO? GetRGVDeviceProDTO(SpeStackerCrane Commonstacker, string SCAddress, string DeviceProParamName, string DeviceProParamType)
|
{
|
return Commonstacker.DeviceProDTOs.FirstOrDefault(x => x.DeviceChildCode == SCAddress && x.DeviceProParamName == DeviceProParamName && x.DeviceProParamType == DeviceProParamType);
|
}
|
/// <summary>
|
/// 读取设备信息
|
/// </summary>
|
/// <param name="conveyorLine"></param>
|
/// <param name="DeviceProDataBlock"></param>
|
/// <returns></returns>
|
public static int GetLine(SpeStackerCrane Commonstacker, string DeviceProDataBlock)
|
{
|
return Commonstacker.Communicator.Read<short>(DeviceProDataBlock);
|
}
|
|
/// <summary>
|
/// 写入设备信息
|
/// </summary>
|
/// <param name="conveyorLine"></param>
|
/// <param name="DeviceProDataBlock"></param>
|
/// <returns></returns>
|
public static bool RgvSetLine(SpeStackerCrane Commonstacker, string DeviceProDataBlock, short rgvvalues)
|
{
|
return Commonstacker.Communicator.Write<short>(DeviceProDataBlock, rgvvalues);
|
}
|
|
/// <summary>
|
/// 正常入库
|
/// </summary>
|
public WebResponseContent WriteInNormal(SaveModel saveModel)
|
{
|
WebResponseContent content = new WebResponseContent();
|
Dt_Task dt_Task = _taskRepository.QueryFirst(x => x.TaskState == (int)TaskInStatusEnum.InAbnormalFinish);
|
dt_Task.TaskState = (int)TaskInStatusEnum.RGV_InPickupFinish;
|
dt_Task.RGVTaskType = (int)RGVTaskTypeEnum.Placing;
|
dt_Task.NextAddress = "1021";
|
_taskRepository.UpdateData(dt_Task);
|
return content;
|
}
|
/// <summary>
|
/// 入库异常排出
|
/// </summary>
|
public WebResponseContent WriteInAbnormal(SaveModel saveModel)
|
{
|
WebResponseContent content = new WebResponseContent();
|
Dt_Task dt_Task = _taskRepository.QueryFirst(x => x.TaskState == (int)TaskInStatusEnum.InAbnormalFinish);
|
dt_Task.TaskState = (int)TaskInStatusEnum.InexceptionalSelection;
|
dt_Task.RGVTaskType = (int)RGVTaskTypeEnum.Placing;
|
_taskRepository.UpdateData(dt_Task);
|
return content;
|
}
|
|
|
|
public static List<string> OutStationareaList = new List<string>() { "RGV111", "RGV116", "RGV110", "RGV112", "RGV114", "RGV115", "RGV118" };
|
public static List<string> InStationareaList = new List<string>() { "RGV111", "RGV116", "RGV110", "RGV112", "RGV114", "RGV115", "RGV118" };
|
/// <summary>
|
/// 查看报警
|
/// </summary>
|
public bool AQMReadAlarminform(int tasktype)
|
{
|
var deviceList = tasktype == 1 ? InStationareaList : OutStationareaList;
|
|
foreach (string deviceName in deviceList)
|
{
|
IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == deviceName);
|
if (device == null) return false;
|
|
SpeStackerCrane stacker = (SpeStackerCrane)device;
|
DeviceProDTO? faultInfo = GetRGVDeviceProDTO(stacker, deviceName, "RGV_Faultcode", "ReadDeviceCommand");
|
int alarmCode = GetLine(stacker, faultInfo.DeviceProAddress);
|
|
if (alarmCode != 0)
|
{
|
return true;
|
}
|
}
|
|
return true;
|
}
|
|
|
/// <summary>
|
/// 查看报警
|
/// </summary>
|
public WebResponseContent ReadAlarminformation(SaveModel saveModel)
|
{
|
WebResponseContent webResponse = new WebResponseContent();
|
string DeviceName = saveModel.DelKeys[0].ToString(); //设备名称
|
IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == DeviceName);
|
if (device == null) return webResponse.Error();
|
SpeStackerCrane Commonstacker = (SpeStackerCrane)device;
|
DeviceProDTO? RGV_Resetoperation = GetRGVDeviceProDTO(Commonstacker, DeviceName, "RGV_Faultcode", "ReadDeviceCommand");
|
int baoj = GetLine(Commonstacker, RGV_Resetoperation.DeviceProAddress);
|
string alarmMessage = "";
|
if (DeviceName == "RGV118")
|
{
|
alarmMessage = GetAlarmMessage(baoj);
|
}
|
else if (DeviceName == "RGV111" || DeviceName == "RGV116")
|
{
|
alarmMessage = GetAlarmMessage2(baoj);
|
}
|
else if (DeviceName == "RGV110" || DeviceName == "RGV112" || DeviceName == "RGV114" || DeviceName == "RGV115")
|
{
|
alarmMessage = GetAlarmMessage3(baoj);
|
}
|
|
|
return webResponse.OK(data: alarmMessage);
|
}
|
|
// 报警代码映射方法
|
private string GetAlarmMessage(int alarmCode)
|
{
|
var alarmMessages = new Dictionary<int, string>
|
{
|
{0, "无报警"},
|
{1, "RGV小车急停被按下"},
|
{2, "正转雷达报警"},
|
{3, "反转雷达报警"},
|
{4, "前进限位报警"},
|
{5, "后退限位报警"},
|
{6, ""},
|
{7, "PLC摸块故障"},
|
{8, "PLC扩展模块故障"},
|
{9, "称重模块故障"},
|
{10, "扫码定位故障"},
|
{11, "RGV长时间空转故障"},
|
{12, "目的地不等于实际位置故障"},
|
{13, "与总控通讯故障"},
|
{14, "前雷达屏蔽警告"},
|
{15, "后雷达屏蔽警告"},
|
{16, "行走变频器故障"},
|
{17, "伸缩叉变频器故障"},
|
{18, "液压单元过载保护故障"},
|
{19, "液压上升超时报警"},
|
{20, "液压下降超时报警"},
|
{21, "伸缩叉伸出超时报警"},
|
{22, "伸缩叉缩回超时报警"},
|
{23, "外形检测报警"},
|
{24, "称重超重报警"},
|
{25, "货叉伸出极限限位报警"},
|
{26, "货叉缩回极限限位报警"},
|
{27, "取货时自身有货物报警"},
|
{28, "放货时自身无货物报警"},
|
{29, "货叉未回到初始位报警"},
|
{30, "触发仅移动命令时货叉不在初始位报警"},
|
{31, "货叉到达初始位但中位传感器未检测到报警"}
|
};
|
|
return alarmMessages.ContainsKey(alarmCode) ? alarmMessages[alarmCode] : "未知报警代码";
|
}
|
|
|
private string GetAlarmMessage2(int alarmCode)
|
{
|
var alarmMessages = new Dictionary<int, string>
|
{
|
{0, "无报警"},
|
{1, "RGV小车急停被按下"},
|
{2, "前进限位报警"},
|
{3, "后退限位报警"},
|
{4, "PLC摸块故障"},
|
{5, "PLC扩展模块故障"},
|
{6, "扫码定位故障"},
|
{7, "RGV长时间空转故障"},
|
{8, "目的地不等于实际位置故障"},
|
{9, "与总控通讯故障"},
|
{10, "行走变频器故障"},
|
{11, "液压单元过载保护故障"},
|
{12, "液压上升超时报警"},
|
{13, "液压下降超时报警"},
|
{14, "取货时自身有货物报警"},
|
{15, "放货时自身无货物报警"},
|
{16, "取货检测不到货物报警"}
|
};
|
|
return alarmMessages.ContainsKey(alarmCode) ? alarmMessages[alarmCode] : "未知报警代码";
|
}
|
|
private string GetAlarmMessage3(int alarmCode)
|
{
|
var alarmMessages = new Dictionary<int, string>
|
{
|
{0, "无报警"},
|
{1, "RGV小车急停被按下"},
|
{2, "前进限位报警"},
|
{3, "后退限位报警"},
|
{4, "PLC摸块故障"},
|
{5, "PLC扩展模块故障"},
|
{6, "RGV长时间空转故障"},
|
{7, "目的地不等于实际位置故障"},
|
{8, "与总控通讯故障"},
|
{9, "行走变频器故障"},
|
{10, "取货时自身有货物报警"},
|
{11, "放货时自身无货物报警"},
|
{12, "停止时位置过冲报警"}
|
};
|
|
return alarmMessages.ContainsKey(alarmCode) ? alarmMessages[alarmCode] : "未知报警代码";
|
}
|
}
|
}
|