using Kean.Application.Command.ViewModels; using Kean.Application.Query.ViewModels; using Microsoft.AspNetCore.Mvc; using System.Linq; using System.Threading.Tasks; namespace Kean.Presentation.Rest.Controllers { /// /// 仓库服务 /// [ApiController, Route("api/warehouses")] public class WarehousesController : ControllerBase { private readonly Application.Query.Interfaces.IWarehouseService _warehouseQueryService; // 仓库信息查询服务 private readonly Application.Command.Interfaces.ITaskService _taskCommandService; // 任务命令服务 /// /// 依赖注入 /// public WarehousesController( Application.Query.Interfaces.IWarehouseService warehouseQueryService, Application.Command.Interfaces.ITaskService taskCommandService) { _warehouseQueryService = warehouseQueryService; _taskCommandService = taskCommandService; } /// /// 获取仓库列表 /// /// 成功 [HttpGet] [ProducesResponseType(200)] public async Task GetList( [FromQuery] string sort, [FromQuery] int? offset, [FromQuery] int? limit) { var items = await _warehouseQueryService.GetWarehouseList(sort, offset, limit); if (offset.HasValue || limit.HasValue) { var total = await _warehouseQueryService.GetWarehouseCount(); return StatusCode(200, new { items, total }); } else { return StatusCode(200, new { items, total = items.Count() }); } } /// /// 获取应急站台列表 /// /// 成功 [HttpGet("emergency")] [ProducesResponseType(200)] public async Task GetEmergencyList( [FromQuery] string stationCode, [FromQuery] string stationModel, [FromQuery] string inout) { var total = await _warehouseQueryService.GetEmergencyCount(stationCode, stationModel, inout); var items = await _warehouseQueryService.GetEmergencyList(stationCode, stationModel, inout); return StatusCode(200, new { items, total = total }); } /// /// 修改应急站台 /// /// 成功 /// 信息已存在 /// 信息已删除 /// 请求内容错误 [HttpPut("emergency/{id}")] [ProducesResponseType(200)] [ProducesResponseType(409)] [ProducesResponseType(410)] [ProducesResponseType(422)] public async Task ModifyEmergency(string id, EmergencyStation emergencyStation, [FromMiddleware] int session) { Failure failure = await _taskCommandService.Emergency(id, emergencyStation.StationModel, session); if (failure == null) { return StatusCode(201); } else { return StatusCode(422, failure); } } } }