You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
100 lines
3.6 KiB
100 lines
3.6 KiB
3 months ago
|
using Kean.Application.Command.ViewModels;
|
||
|
using Microsoft.AspNetCore.Mvc;
|
||
|
using System.Collections.Generic;
|
||
|
using System.Linq;
|
||
|
using System.Threading.Tasks;
|
||
|
|
||
|
namespace Kean.Presentation.Rest.Controllers
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// 禁用点服务
|
||
|
/// </summary>
|
||
|
[ApiController, Route("api/disablements")]
|
||
|
public class DisablementsController : ControllerBase
|
||
|
{
|
||
|
private readonly Application.Command.Interfaces.ITaskService _taskCommandService; // 任务命令服务
|
||
|
private readonly Application.Query.Interfaces.IWarehouseService _warehouseQueryService; // 库房查询服务
|
||
|
|
||
|
/// <summary>
|
||
|
/// 依赖注入
|
||
|
/// </summary>
|
||
|
public DisablementsController(
|
||
|
Application.Command.Interfaces.ITaskService taskCommandService,
|
||
|
Application.Query.Interfaces.IWarehouseService warehouseQueryService)
|
||
|
{
|
||
|
_taskCommandService = taskCommandService;
|
||
|
_warehouseQueryService = warehouseQueryService;
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 获取禁用点列表
|
||
|
/// </summary>
|
||
|
/// <response code="200">成功</response>
|
||
|
[HttpGet()]
|
||
|
[ProducesResponseType(200)]
|
||
|
public async Task<IActionResult> GetList(
|
||
|
[FromQuery] int[] area,
|
||
|
[FromQuery] string type,
|
||
|
[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, nameof(Domain.Task.Models.Cell), null, null, name, nameof(Domain.Task.Enums.CellState.Disabled), sort, offset, limit, laneway, cellTag);
|
||
|
if (offset.HasValue || limit.HasValue)
|
||
|
{
|
||
|
var total = await _warehouseQueryService.GetCellCount(area, nameof(Domain.Task.Models.Cell), null, null, name, nameof(Domain.Task.Enums.CellState.Disabled), laneway, cellTag);
|
||
|
return StatusCode(200, new { items, total });
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return StatusCode(200, new { items, total = items.Count() });
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 批量处理禁用点
|
||
|
/// </summary>
|
||
|
/// <response code="200">成功</response>
|
||
|
/// <response code="405">非法操作</response>
|
||
|
/// <response code="422">请求内容错误</response>
|
||
|
[HttpPost("batch")]
|
||
|
[ProducesResponseType(200)]
|
||
|
[ProducesResponseType(405)]
|
||
|
[ProducesResponseType(422)]
|
||
|
public async Task<IActionResult> Batch(
|
||
|
[FromMember] int warehouse,
|
||
|
[FromMember] string celltag,
|
||
|
[FromBody] Batch<string> batch)
|
||
|
|
||
|
{
|
||
|
(IEnumerable<bool?> States, Failure Failure) result;
|
||
|
switch (batch.Method)
|
||
|
{
|
||
|
case BatchMethod.Create:
|
||
|
result = await _taskCommandService.Disable(warehouse, batch.Data, celltag);
|
||
|
break;
|
||
|
case BatchMethod.Delete:
|
||
|
result = await _taskCommandService.Enable(warehouse, batch.Data);
|
||
|
break;
|
||
|
default:
|
||
|
return StatusCode(405);
|
||
|
}
|
||
|
if (result.Failure == null)
|
||
|
{
|
||
|
return StatusCode(200, result.States);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
return StatusCode(422, result.Failure);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|