131 lines
3.8 KiB
C#
131 lines
3.8 KiB
C#
using System.Diagnostics;
|
|
using Dlhis.Canteen.Dishes.Request;
|
|
using Dlhis.Canteen.Order.Request;
|
|
using Dlhis.Canteen.Order.Response;
|
|
using Dlhis.Canteen.Order.Services;
|
|
using Kurisu.AspNetCore.DataAccess.Dto;
|
|
using Kurisu.AspNetCore.DataAccess.SqlSugar.Aop;
|
|
using Kurisu.AspNetCore.UnifyResultAndValidation;
|
|
using Kurisu.AspNetCore.Utils.Extensions;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace Dlhis.Canteen.Order.Controllers;
|
|
|
|
/// <summary>
|
|
/// 订单
|
|
/// </summary>
|
|
[Authorize]
|
|
[Route("api/[controller]")]
|
|
[ApiController]
|
|
public class OrdersController : ControllerBase
|
|
{
|
|
private readonly IOrderService _orderService;
|
|
private readonly IBookingOrderService _bookingOrderService;
|
|
private readonly ILogger<OrdersController> _logger;
|
|
|
|
public OrdersController(IOrderService orderService, IBookingOrderService bookingOrderService, ILogger<OrdersController> logger)
|
|
{
|
|
_orderService = orderService;
|
|
_bookingOrderService = bookingOrderService;
|
|
_logger = logger;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 消费
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <returns></returns>
|
|
[Authorize(Policy = "consumer")]
|
|
[HttpPost]
|
|
[IgnoreTenant]
|
|
public async Task<DefaultApiResult<OrderResultResponse>> AddAsync(OrderAddRequest request)
|
|
{
|
|
var sw = Stopwatch.StartNew();
|
|
try
|
|
{
|
|
return await _orderService.AddAsync(request);
|
|
}
|
|
finally
|
|
{
|
|
_logger.LogInformation("消费请求:{json}. 耗时:{time}", request.ToJson(), sw.ElapsedMilliseconds);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 设备发起订单
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <returns></returns>
|
|
[Authorize(Policy = "consumer")]
|
|
[HttpPost("device")]
|
|
[IgnoreTenant]
|
|
public async Task<DefaultApiResult<OrderResultResponse>> DeviceConsume(OrderAddRequest request)
|
|
{
|
|
return await _orderService.AddAsync(request);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 订单聚合数据
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
[HttpGet("aggregation")]
|
|
[IgnoreTenant]
|
|
public async Task<Pagination<OrderAggregationResponse>> GetOrdersAggregationAsync([FromQuery] PageDto page)
|
|
{
|
|
return await _orderService.GetOrdersAggregationAsync(page);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 取消订单
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <returns></returns>
|
|
[HttpPut("user-cancel")]
|
|
[Transactional]
|
|
[IgnoreTenant]
|
|
public async Task CancelOrderAsync(OrderCancelRequest request)
|
|
{
|
|
await _bookingOrderService.UserCancelOrderAsync(request);
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// 取消订单
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <returns></returns>
|
|
[HttpPut("manager-cancel")]
|
|
[Transactional]
|
|
[IgnoreTenant]
|
|
public async Task ManagerCancelOrderAsync(OrderCancelRequest request)
|
|
{
|
|
await _bookingOrderService.ManagerCancelOrderAsync(request);
|
|
}
|
|
|
|
//************************************************************** 订餐功能 **********************************************************************************
|
|
|
|
/// <summary>
|
|
/// 取消订单
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <returns></returns>
|
|
[HttpPost("booking")]
|
|
[Transactional]
|
|
[IgnoreTenant]
|
|
public async Task<BookingResponse> Booking(BookingMealRequest request)
|
|
{
|
|
return await _bookingOrderService.BookingAsync(request);
|
|
}
|
|
|
|
/// <summary>
|
|
/// 订单分页
|
|
/// </summary>
|
|
/// <param name="request"></param>
|
|
/// <returns></returns>
|
|
[HttpGet("booking/page")]
|
|
public async Task<Pagination<OrderBookingResponse>> GetBookingPageAsync([FromQuery] OrderBookingPageRequest request)
|
|
{
|
|
return await _bookingOrderService.GetBookingPageAsync(request);
|
|
}
|
|
} |