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.
348 lines
13 KiB
348 lines
13 KiB
using Kean.Application.Command.ViewModels;
|
|
using Kean.Application.Query.ViewModels;
|
|
using Kean.Domain;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Extensions.Configuration;
|
|
using System;
|
|
using System.Linq;
|
|
using System.Text.Json;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Kean.Presentation.Rest.Controllers
|
|
{
|
|
/// <summary>
|
|
/// 订单服务
|
|
/// </summary>
|
|
[ApiController, Route("api/orders")]
|
|
public class OrdersController : ControllerBase
|
|
{
|
|
private readonly Application.Command.Interfaces.IOrderService _orderCommandService; // 订单信息命令服务
|
|
private readonly Application.Query.Interfaces.IOrderService _orderQueryService; // 订单信息查询服务
|
|
private readonly IConfiguration _configuration;
|
|
|
|
/// <summary>
|
|
/// 依赖注入
|
|
/// </summary>
|
|
public OrdersController(
|
|
Application.Command.Interfaces.IOrderService orderCommandService,
|
|
IConfiguration configuration,
|
|
Application.Query.Interfaces.IOrderService orderQueryService)
|
|
{
|
|
_orderCommandService = orderCommandService;
|
|
_orderQueryService = orderQueryService;
|
|
_configuration = configuration;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取系统行为列表
|
|
/// </summary>
|
|
/// <response code="200">成功</response>
|
|
[HttpGet("actions")]
|
|
[ProducesResponseType(200)]
|
|
public async Task<IActionResult> GetActionList()
|
|
{
|
|
var items = await _orderQueryService.GetActionList();
|
|
return StatusCode(200, new { items, total = items.Count() });
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取订单类型列表
|
|
/// </summary>
|
|
/// <response code="200">成功</response>
|
|
[HttpGet("types")]
|
|
[ProducesResponseType(200)]
|
|
public async Task<IActionResult> GetTypeList()
|
|
{
|
|
var items = await _orderQueryService.GetTypeList();
|
|
return StatusCode(200, new { items, total = items.Count() });
|
|
}
|
|
|
|
/// <summary>
|
|
/// 创建订单类型
|
|
/// </summary>
|
|
/// <response code="201">成功</response>
|
|
/// <response code="409">类型已存在</response>
|
|
/// <response code="422">请求内容错误</response>
|
|
[HttpPost("types")]
|
|
[ProducesResponseType(201)]
|
|
[ProducesResponseType(409)]
|
|
[ProducesResponseType(422)]
|
|
public async Task<IActionResult> CreateType(Application.Command.ViewModels.Ordtyp type)
|
|
{
|
|
if (type.Menu != null)
|
|
{
|
|
foreach (var key in type.Menu.Keys)
|
|
{
|
|
var jsonElement = (JsonElement)type.Menu[key];
|
|
type.Menu[key] = jsonElement.ValueKind switch
|
|
{
|
|
JsonValueKind.Number => jsonElement.GetInt32(),
|
|
JsonValueKind.String => jsonElement.GetString(),
|
|
_ => null
|
|
};
|
|
}
|
|
}
|
|
var result = await _orderCommandService.CreateType(type);
|
|
return result switch
|
|
{
|
|
{ Id: > 0 } => StatusCode(201, result.Id),
|
|
{ Failure.ErrorCode: nameof(ErrorCode.Conflict) } => StatusCode(409, result.Failure),
|
|
_ => StatusCode(422, result.Failure)
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// 修改订单类型
|
|
/// </summary>
|
|
/// <response code="200">成功</response>
|
|
/// <response code="409">类型已存在</response>
|
|
/// <response code="410">类型已删除</response>
|
|
/// <response code="422">请求内容错误</response>
|
|
/// <response code="423">类型被锁定</response>
|
|
[HttpPut("types/{id}")]
|
|
[ProducesResponseType(200)]
|
|
[ProducesResponseType(409)]
|
|
[ProducesResponseType(410)]
|
|
[ProducesResponseType(422)]
|
|
[ProducesResponseType(423)]
|
|
public async Task<IActionResult> ModifyType(int id, Application.Command.ViewModels.Ordtyp type)
|
|
{
|
|
type.Id = id;
|
|
if (type.Menu != null)
|
|
{
|
|
foreach (var key in type.Menu.Keys)
|
|
{
|
|
var jsonElement = (JsonElement)type.Menu[key];
|
|
type.Menu[key] = jsonElement.ValueKind switch
|
|
{
|
|
JsonValueKind.Number => jsonElement.GetInt32(),
|
|
JsonValueKind.String => jsonElement.GetString(),
|
|
_ => null
|
|
};
|
|
}
|
|
}
|
|
var result = await _orderCommandService.ModifyType(type);
|
|
return result switch
|
|
{
|
|
{ Success: true } => StatusCode(200),
|
|
{ Failure.ErrorCode: nameof(ErrorCode.Conflict) } => StatusCode(409, result.Failure),
|
|
{ Failure.ErrorCode: nameof(ErrorCode.Gone) } => StatusCode(410, result.Failure),
|
|
{ Failure.ErrorCode: nameof(ErrorCode.Locked) } => StatusCode(423, result.Failure),
|
|
_ => StatusCode(422, result.Failure)
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除订单类型
|
|
/// </summary>
|
|
/// <response code="204">成功</response>
|
|
/// <response code="422">请求内容错误</response>
|
|
/// <response code="423">类型被锁定</response>
|
|
[HttpDelete("types/{id}")]
|
|
[ProducesResponseType(204)]
|
|
[ProducesResponseType(422)]
|
|
[ProducesResponseType(423)]
|
|
public async Task<IActionResult> DeleteType(int id)
|
|
{
|
|
var result = await _orderCommandService.DeleteType(id);
|
|
return result switch
|
|
{
|
|
{ Success: true } => StatusCode(204),
|
|
{ Failure.ErrorCode: nameof(ErrorCode.Locked) } => StatusCode(423, result.Failure),
|
|
_ => StatusCode(422, result.Failure)
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取工作流列表
|
|
/// </summary>
|
|
/// <response code="200">成功</response>
|
|
[HttpGet("flows")]
|
|
[ProducesResponseType(200)]
|
|
public async Task<IActionResult> GetFlowList()
|
|
{
|
|
var items = await _orderQueryService.GetFlowList();
|
|
return StatusCode(200, new { items, total = items.Count() });
|
|
}
|
|
|
|
/// <summary>
|
|
/// 创建工作流
|
|
/// </summary>
|
|
/// <response code="201">成功</response>
|
|
/// <response code="409">工作流已存在</response>
|
|
/// <response code="422">请求内容错误</response>
|
|
[HttpPost("flows")]
|
|
[ProducesResponseType(201)]
|
|
[ProducesResponseType(409)]
|
|
[ProducesResponseType(422)]
|
|
public async Task<IActionResult> CreateFlow(Application.Command.ViewModels.Flow flow)
|
|
{
|
|
var result = await _orderCommandService.CreateFlow(flow);
|
|
return result switch
|
|
{
|
|
{ Id: > 0 } => StatusCode(201, result.Id),
|
|
{ Failure.ErrorCode: nameof(ErrorCode.Conflict) } => StatusCode(409, result.Failure),
|
|
_ => StatusCode(422, result.Failure)
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// 修改工作流
|
|
/// </summary>
|
|
/// <response code="200">成功</response>
|
|
/// <response code="409">工作流已存在</response>
|
|
/// <response code="410">工作流已删除</response>
|
|
/// <response code="422">请求内容错误</response>
|
|
/// <response code="423">工作流被锁定</response>
|
|
[HttpPut("flows/{id}")]
|
|
[ProducesResponseType(200)]
|
|
[ProducesResponseType(409)]
|
|
[ProducesResponseType(410)]
|
|
[ProducesResponseType(422)]
|
|
[ProducesResponseType(423)]
|
|
public async Task<IActionResult> ModifyFlow(int id, Application.Command.ViewModels.Flow flow)
|
|
{
|
|
flow.Id = id;
|
|
var result = await _orderCommandService.ModifyFlow(flow);
|
|
return result switch
|
|
{
|
|
{ Success: true } => StatusCode(200),
|
|
{ Failure.ErrorCode: nameof(ErrorCode.Conflict) } => StatusCode(409, result.Failure),
|
|
{ Failure.ErrorCode: nameof(ErrorCode.Gone) } => StatusCode(410, result.Failure),
|
|
{ Failure.ErrorCode: nameof(ErrorCode.Locked) } => StatusCode(423, result.Failure),
|
|
_ => StatusCode(422, result.Failure)
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除工作流
|
|
/// </summary>
|
|
/// <response code="204">成功</response>
|
|
/// <response code="422">请求内容错误</response>
|
|
/// <response code="423">类型被锁定</response>
|
|
[HttpDelete("flows/{id}")]
|
|
[ProducesResponseType(204)]
|
|
[ProducesResponseType(422)]
|
|
[ProducesResponseType(423)]
|
|
public async Task<IActionResult> DeleteFlow(int id)
|
|
{
|
|
var result = await _orderCommandService.DeleteFlow(id);
|
|
return result switch
|
|
{
|
|
{ Success: true } => StatusCode(204),
|
|
{ Failure.ErrorCode: nameof(ErrorCode.Locked) } => StatusCode(423, result.Failure),
|
|
_ => StatusCode(422, result.Failure)
|
|
};
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取实例列表
|
|
/// </summary>
|
|
/// <response code="200">成功</response>
|
|
[HttpGet]
|
|
[ProducesResponseType(200)]
|
|
public async Task<IActionResult> GetOrderList(
|
|
[FromQuery] int? type,
|
|
[FromQuery] int? flow,
|
|
[FromQuery] int? node,
|
|
[FromQuery] string no,
|
|
[FromQuery] string creater,
|
|
[FromQuery] DateTime? createTimeFrom,
|
|
[FromQuery] DateTime? createTimeTo,
|
|
[FromQuery] string sort,
|
|
[FromQuery] int? offset,
|
|
[FromQuery] int? limit)
|
|
{
|
|
var items = await _orderQueryService.GetOrderList(type, flow, node, no, creater, createTimeFrom, createTimeTo, sort, offset, limit);
|
|
if (offset.HasValue || limit.HasValue)
|
|
{
|
|
var total = await _orderQueryService.GetOrderCount(type, flow, node, no, creater, createTimeFrom, createTimeTo);
|
|
return StatusCode(200, new { items, total });
|
|
}
|
|
else
|
|
{
|
|
return StatusCode(200, new { items, total = items.Count() });
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取行列表
|
|
/// </summary>
|
|
/// <response code="200">成功</response>
|
|
[HttpGet("{id}/lines")]
|
|
[ProducesResponseType(200)]
|
|
public async Task<IActionResult> GetLineList(
|
|
[FromRoute] int? id,
|
|
[FromQuery] string sort,
|
|
[FromQuery] int? offset,
|
|
[FromQuery] int? limit)
|
|
{
|
|
var items = await _orderQueryService.GetLineList(id, sort, offset, limit);
|
|
if (offset.HasValue || limit.HasValue)
|
|
{
|
|
var total = await _orderQueryService.GetLineCount(id);
|
|
return StatusCode(200, new { items, total });
|
|
}
|
|
else
|
|
{
|
|
return StatusCode(200, new { items, total = items.Count() });
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 创建订单
|
|
/// </summary>
|
|
/// <response code="201">成功</response>
|
|
/// <response code="422">请求内容错误</response>
|
|
[HttpPost]
|
|
[ProducesResponseType(201)]
|
|
[ProducesResponseType(422)]
|
|
public async Task<IActionResult> CreateOrder(Application.Command.ViewModels.Order order)
|
|
{
|
|
var result = await _orderCommandService.CreateOrder(order);
|
|
if (result.Id > 0)
|
|
{
|
|
return StatusCode(201, result.Id);
|
|
}
|
|
else
|
|
{
|
|
return StatusCode(422, result.Failure);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 修改订单
|
|
/// </summary>
|
|
/// <response code="200">成功</response>
|
|
/// <response code="422">请求内容错误</response>
|
|
[HttpPut("{id}")]
|
|
[ProducesResponseType(200)]
|
|
[ProducesResponseType(422)]
|
|
public async Task<IActionResult> ModifyOrder(int id, Application.Command.ViewModels.Order order)
|
|
{
|
|
order.Id = id;
|
|
var result = await _orderCommandService.ModifyOrder(order);
|
|
if (result.Success)
|
|
{
|
|
return StatusCode(200);
|
|
}
|
|
else
|
|
{
|
|
return StatusCode(422, result.Failure);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 删除订单
|
|
/// </summary>
|
|
/// <response code="204">成功</response>
|
|
[HttpDelete("{id}")]
|
|
[ProducesResponseType(204)]
|
|
public async Task<IActionResult> DeleteOrder(int id)
|
|
{
|
|
await _orderCommandService.DeleteOrder(Math.Abs(id), id > 0);
|
|
return StatusCode(204);
|
|
}
|
|
|
|
}
|
|
}
|