using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using OfficeOpenXml.FormulaParsing.Excel.Functions.Information;
using WIDESEAWCS_Core;
using WIDESEAWCS_Core.Caches;
using WIDESEAWCS_QuartzJob;
using WIDESEAWCS_QuartzJob.Repository;
using WIDESEAWCS_QuartzJob.Service;
using WIDESEAWCS_Tasks.ConveyorLineJob;
using WIDESEAWCS_Tasks.ShuttleCarJob;
using WIDESEAWCS_Tasks.StackerCraneJob;
namespace WIDESEAWCS_Server.Controllers
{
[Route("api/LargeScreen")]
[ApiController, AllowAnonymous]
public class LargeScreenController : Controller
{
private readonly IDeviceInfoRepository _deviceInfoRepository;
private readonly IRouterService _routerService;
private readonly ICacheService _cacheService;
public LargeScreenController(ICacheService cacheService, IRouterService routerService, IDeviceInfoRepository deviceInfoRepository)
{
_deviceInfoRepository = deviceInfoRepository;
_routerService = routerService;
_cacheService = cacheService;
}
///
/// 获取穿梭车电量
///
///
[HttpPost, Route("GetShuttleCarInfos")]
public WebResponseContent GetShuttleCarInfos()
{
WebResponseContent webResponseContent = new WebResponseContent();
int ElectricQuantity1 = 0;
int ElectricQuantity2 = 0;
try
{
var Device = _cacheService.Get(typeof(ShuttleCarTaskCommandR), "RGV01");
if (Device != null)
{
ShuttleCarTaskCommandR? shuttleCar = Device as ShuttleCarTaskCommandR;
if (shuttleCar != null) ElectricQuantity1 = shuttleCar.ElectricQuantity;
}
Device = _cacheService.Get(typeof(ShuttleCarTaskCommandR), "RGV02");
if (Device != null)
{
ShuttleCarTaskCommandR? shuttleCar = Device as ShuttleCarTaskCommandR;
if (shuttleCar != null) ElectricQuantity2 = shuttleCar.ElectricQuantity;
}
}
catch (Exception ex)
{
webResponseContent.Error(ex.Message);
}
return webResponseContent.OK(data: new
{
ElectricQuantity1,
ElectricQuantity2
});
}
///
/// 获取设备信息
///
///
[HttpPost, Route("GetDeviceInfos")]
public WebResponseContent GetDeviceInfos()
{
WebResponseContent webResponseContent = new WebResponseContent();
try
{
List devices = new List();
var DeviceInfos = _deviceInfoRepository.QueryData(x => x.DeviceStatus == "1").ToList();
foreach (var item in DeviceInfos)
{
switch (item.DeviceType)
{
case "SpeStackerCrane"://堆垛机
{
var Device = _cacheService.Get(typeof(StackerCraneTaskCommandR), item.DeviceCode);
if (Device != null)
{
DeviceInfo deviceInfo = new DeviceInfo()
{
DeviceName = item.DeviceName,
Deviceinfo = Device
};
devices.Add(deviceInfo);
}
}
break;
case "CommonConveyorLine"://输送线
{
List childDeviceCodes = _routerService.QueryAllPositions(item.DeviceCode);
foreach (var childDeviceCode in childDeviceCodes)
{
var Device = _cacheService.Get(typeof(ConveyorLineTaskCommandR), childDeviceCode);
if (Device != null)
{
DeviceInfo deviceInfo = new DeviceInfo()
{
DeviceName = childDeviceCode,
Deviceinfo = Device
};
devices.Add(deviceInfo);
}
}
}
break;
case "ShuttleCar"://穿梭车
{
var Device = _cacheService.Get(typeof(ShuttleCarTaskCommandR), item.DeviceCode);
if (Device != null)
{
DeviceInfo deviceInfo = new DeviceInfo()
{
DeviceName = item.DeviceName,
Deviceinfo = Device
};
devices.Add(deviceInfo);
}
}
break;
default:
break;
}
}
webResponseContent.OK(data: new
{
devices
});
}
catch (Exception ex)
{
return WebResponseContent.Instance.Error(ex.Message);
}
return webResponseContent;
}
public class DeviceInfo
{
//public string DeviceCode { get; set; }
public string DeviceName { get; set; }
public object Deviceinfo { get; set; }
}
}
}