using Microsoft.AspNetCore.Mvc;
using System.Linq;
using System.Threading.Tasks;
namespace Kean.Presentation.Rest.Controllers
{
///
/// 货位服务
///
[ApiController, Route("api/cells")]
public class CellsController : ControllerBase
{
private readonly Application.Query.Interfaces.IWarehouseService _warehouseQueryService; // 库房信息查询服务
///
/// 依赖注入
///
public CellsController(
Application.Query.Interfaces.IWarehouseService warehouseQueryService)
{
_warehouseQueryService = warehouseQueryService;
}
///
/// 获取货位列表
///
/// 成功
[HttpGet]
[ProducesResponseType(200)]
public async Task GetList(
[FromQuery] int[] area,
[FromQuery] string type,
[FromQuery] bool? @in,
[FromQuery] bool? @out,
[FromQuery] string name,
[FromQuery] string sort,
[FromQuery] int? offset,
[FromQuery] int? limit,
[FromQuery] string laneway,
[FromQuery] string cellTag)
{
if (area.Length == 0)
{
area = null;
}
var items = await _warehouseQueryService.GetCellList(area, type, @in, @out, name, null, sort, offset, limit, laneway, cellTag);
if (offset.HasValue || limit.HasValue)
{
var total = await _warehouseQueryService.GetCellCount(area, type, @in, @out, name, null, laneway, cellTag);
return StatusCode(200, new { items, total });
}
else
{
return StatusCode(200, new { items, total = items.Count() });
}
}
}
}