using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; using WIDESEAWCS_Core; using WIDESEAWCS_IBasicInfoRepository; using WIDESEAWCS_Model.Models; using WIDESEAWCS_QuartzJob; using WIDESEAWCS_Tasks; namespace WIDESEAWCS_Server.Controllers { [Route("api/[controller]")] [ApiController] public class AGVController : ControllerBase { private readonly IStationMangerRepository _stationMangerRepository; public AGVController(IStationMangerRepository stationMangerRepository) { _stationMangerRepository = stationMangerRepository; } [HttpPost, HttpGet, Route("PutRequest"), AllowAnonymous] public WebResponseContent PutRequest(string code, int palletType) { try { Dt_StationManger stationManger = _stationMangerRepository.QueryFirst(x => x.AGVStationCode == code); if (stationManger == null) { return WebResponseContent.Instance.Error($"未找到站台配置"); } IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManger.StationDeviceCode); if (device == null) { return WebResponseContent.Instance.Error($"未找到对应设备"); } OtherDevice otherDevice = (OtherDevice)device; bool canPut = otherDevice.GetValue(GroundStationDBName.R_IsCanPut, stationManger.StationCode); if (canPut) { return WebResponseContent.Instance.OK(); } else { otherDevice.SetValue(GroundStationDBName.W_PutRequest, true, stationManger.StationCode); otherDevice.SetValue(GroundStationDBName.W_PutPalletType, (short)palletType, stationManger.StationCode); Thread.Sleep(1000); canPut = otherDevice.GetValue(GroundStationDBName.R_IsCanPut, stationManger.StationCode); if (canPut) { return WebResponseContent.Instance.OK(); } else { return WebResponseContent.Instance.Error($"放货申请中"); } } } catch (Exception ex) { return WebResponseContent.Instance.Error(ex.Message); } } [HttpPost, HttpGet, Route("PutFinish"), AllowAnonymous] public WebResponseContent PutFinish(string code) { try { Dt_StationManger stationManger = _stationMangerRepository.QueryFirst(x => x.AGVStationCode == code); if (stationManger == null) { return WebResponseContent.Instance.Error($"未找到站台配置"); } IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManger.StationDeviceCode); if (device == null) { return WebResponseContent.Instance.Error($"未找到对应设备"); } OtherDevice otherDevice = (OtherDevice)device; otherDevice.SetValue(GroundStationDBName.W_PutFinish, true, stationManger.StationCode); return WebResponseContent.Instance.OK(); } catch (Exception ex) { return WebResponseContent.Instance.Error(ex.Message); } } [HttpPost, HttpGet, Route("TakeRequest"), AllowAnonymous] public WebResponseContent TakeRequest(string code) { try { Dt_StationManger stationManger = _stationMangerRepository.QueryFirst(x => x.AGVStationCode == code); if (stationManger == null) { return WebResponseContent.Instance.Error($"未找到站台配置"); } IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManger.StationDeviceCode); if (device == null) { return WebResponseContent.Instance.Error($"未找到对应设备"); } OtherDevice otherDevice = (OtherDevice)device; bool canPut = otherDevice.GetValue(GroundStationDBName.R_IsCanTake, stationManger.StationCode); if (canPut) { return WebResponseContent.Instance.OK(); } else { otherDevice.SetValue(GroundStationDBName.W_TakeRequest, true, stationManger.StationCode); Thread.Sleep(1000); canPut = otherDevice.GetValue(GroundStationDBName.R_IsCanTake, stationManger.StationCode); if (canPut) { return WebResponseContent.Instance.OK(); } else { return WebResponseContent.Instance.Error($"取货申请中"); } } } catch (Exception ex) { return WebResponseContent.Instance.Error(ex.Message); } } [HttpPost, HttpGet, Route("TakeFinish"), AllowAnonymous] public WebResponseContent TakeFinish(string code) { try { Dt_StationManger stationManger = _stationMangerRepository.QueryFirst(x => x.AGVStationCode == code); if (stationManger == null) { return WebResponseContent.Instance.Error($"未找到站台配置"); } IDevice? device = Storage.Devices.FirstOrDefault(x => x.DeviceCode == stationManger.StationDeviceCode); if (device == null) { return WebResponseContent.Instance.Error($"未找到对应设备"); } OtherDevice otherDevice = (OtherDevice)device; otherDevice.SetValue(GroundStationDBName.W_TakeFinish, true, stationManger.StationCode); return WebResponseContent.Instance.OK(); } catch (Exception ex) { return WebResponseContent.Instance.Error(ex.Message); } } } }