fix 代码优化
This commit is contained in:
@@ -1,8 +0,0 @@
|
||||
namespace Dlhis.Basic.BusinessPlace.Response
|
||||
{
|
||||
public class BusinessPlaceDto
|
||||
{
|
||||
public Guid Code { get; set; }
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
namespace Dlhis.Basic.BusinessPlace.Response
|
||||
{
|
||||
public class GetMyResponse
|
||||
{
|
||||
public List<BusinessPlaceDto> dtos { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using Dlhis.Basic.Places.Request;
|
||||
using Dlhis.Basic.BusinessPlace.Response;
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
using Dlhis.Basic.Places.Dtos;
|
||||
|
||||
namespace Dlhis.Basic.BusinessPlace.Services;
|
||||
|
||||
@@ -10,5 +11,5 @@ public interface IBusinessPlacePermissionsService : IScopeDependency
|
||||
|
||||
Task SaveBusinessPlacePermissionAsync(BusinessPlacePermissionSaveRequest request);
|
||||
|
||||
Task<GetMyResponse> GetMyAsync();
|
||||
Task<List<BusinessPlaceDto>> GetMyAsync();
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ using Kurisu.Core.DataAccess.Dto;
|
||||
using Kurisu.Core.User.Abstractions;
|
||||
using Kurisu.SqlSugar.Services;
|
||||
using Mapster;
|
||||
using Dlhis.Basic.Places.Dtos;
|
||||
|
||||
namespace Dlhis.Basic.BusinessPlace.Services.Implements;
|
||||
|
||||
@@ -24,7 +25,7 @@ public class BusinessPlacePermissionsService : IBusinessPlacePermissionsService
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public async Task<GetMyResponse> GetMyAsync()
|
||||
public async Task<List<BusinessPlaceDto>> GetMyAsync()
|
||||
{
|
||||
var userId = _currentUser.GetIntSubjectId();
|
||||
|
||||
@@ -34,15 +35,10 @@ public class BusinessPlacePermissionsService : IBusinessPlacePermissionsService
|
||||
.Distinct()
|
||||
.ToListAsync();
|
||||
|
||||
var dtos = await _dbContext.Queryable<BusinessPlaceEntity>()
|
||||
return await _dbContext.Queryable<BusinessPlaceEntity>()
|
||||
.Where(x => guids.Contains(x.Code))
|
||||
.Select<BusinessPlaceDto>()
|
||||
.ToListAsync();
|
||||
var myResponse = new GetMyResponse
|
||||
{
|
||||
dtos = dtos
|
||||
};
|
||||
return myResponse;
|
||||
.ToListAsync();
|
||||
}
|
||||
|
||||
public async Task SaveBusinessPlacePermissionAsync(BusinessPlacePermissionSaveRequest request)
|
||||
|
||||
@@ -6,7 +6,6 @@ using Kurisu.AspNetCore.DataAccess.SqlSugar.Aop;
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Org.BouncyCastle.Asn1.Ocsp;
|
||||
|
||||
namespace Dlhis.Canteen.Dishes.Controllers;
|
||||
|
||||
@@ -93,7 +92,7 @@ public class OrdersController : ControllerBase
|
||||
//************************************************************** 订餐功能 **********************************************************************************
|
||||
|
||||
/// <summary>
|
||||
/// 订餐
|
||||
/// 订单聚合数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost("booking")]
|
||||
@@ -104,16 +103,7 @@ public class OrdersController : ControllerBase
|
||||
return await _bookingOrderService.BookingAsync(request);
|
||||
}
|
||||
|
||||
///// <summary>
|
||||
///// 获取详情
|
||||
///// </summary>
|
||||
///// <param name="no"></param>
|
||||
///// <returns></returns>
|
||||
//[HttpGet("details")]
|
||||
//public async Task<List<OrderDetailResponse>> GetDetailsAsync(string no)
|
||||
//{
|
||||
// return await _orderService.GetDetailsAsync(no);
|
||||
//}
|
||||
//************************************************************** 订餐功能 **********************************************************************************
|
||||
|
||||
/// <summary>
|
||||
/// 订单分页
|
||||
@@ -127,12 +117,13 @@ public class OrdersController : ControllerBase
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 订单聚合数据
|
||||
/// 订单分页
|
||||
/// </summary>
|
||||
/// <param name="request"></param>
|
||||
/// <returns></returns>
|
||||
[HttpGet("aggregation")]
|
||||
public async Task<Pagination<OrderAggregationResponse>> GetOrdersAggregationAsync([FromQuery] PageDto page)
|
||||
[HttpGet("booking/page")]
|
||||
public async Task<Pagination<OrderBookingResponse>> GetBookingPageAsync([FromQuery] OrderBookingPageRequest request)
|
||||
{
|
||||
return await _orderService.GetOrdersAggregationAsync(page);
|
||||
return await _bookingOrderService.GetBookingPageAsync(request);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,8 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Dlhis.Entity.Canteen.Enums;
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
using Kurisu.Core.DataAccess.Dto;
|
||||
|
||||
namespace Dlhis.Canteen.Order.Request;
|
||||
|
||||
public class OrderBookingPageRequest : PageDto
|
||||
{
|
||||
/// <summary>
|
||||
/// 订单状态 CanteenOrderStatusEnumType
|
||||
/// </summary>
|
||||
[EnumDataType(typeof(CanteenOrderStatusEnumType))]
|
||||
public CanteenOrderStatusEnumType? OrderStatus { get; set; }
|
||||
|
||||
}
|
||||
|
||||
@@ -33,6 +33,10 @@ public abstract class BaseOrderService
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
protected BaseOrderService(ICanteenSettingService canteenSettingService)
|
||||
{
|
||||
_canteenSettingService = canteenSettingService;
|
||||
}
|
||||
|
||||
protected IDbContext DbContext => _dbContext;
|
||||
|
||||
|
||||
@@ -19,6 +19,8 @@ namespace Dlhis.Canteen.Order.Services.Implements;
|
||||
|
||||
public class BookingOrderService : BaseOrderService, IBookingOrderService
|
||||
{
|
||||
private readonly IDbContext _dbContext;
|
||||
private readonly ICurrentUser _currentUser;
|
||||
private readonly IDisheMenuApi _disheMenuApi;
|
||||
private readonly IBusinessPlacePermissionsApi _businessPlacePermissionsApi;
|
||||
|
||||
@@ -101,45 +103,45 @@ public class BookingOrderService : BaseOrderService, IBookingOrderService
|
||||
{
|
||||
|
||||
var mealInfo = await DbContext.Queryable<GainfoMealEntity>().Where(x => x.UserNo == order.UserNo).FirstAsync();
|
||||
if (mealInfo == null)
|
||||
{
|
||||
if (mealInfo == null)
|
||||
{
|
||||
await DbContext.InsertAsync(new GainfoMealEntity
|
||||
{
|
||||
Balance = 0,
|
||||
BalanceOfRecharge = 0,
|
||||
BalanceOfSubsidies = 0,
|
||||
UserCode = gainfo.Code,
|
||||
UserNo = gainfo.No,
|
||||
Version = 0,
|
||||
});
|
||||
{
|
||||
Balance = 0,
|
||||
BalanceOfRecharge = 0,
|
||||
BalanceOfSubsidies = 0,
|
||||
UserCode = gainfo.Code,
|
||||
UserNo = gainfo.No,
|
||||
Version = 0,
|
||||
});
|
||||
|
||||
(mealInfo == null).ThrowIfTrue("余额不足,无法消费");
|
||||
}
|
||||
//金额+-
|
||||
mealInfo.Balance += order.Amount;
|
||||
(mealInfo.Balance < 0).ThrowIfTrue("余额不足,无法消费");
|
||||
(mealInfo == null).ThrowIfTrue("余额不足,无法消费");
|
||||
}
|
||||
//金额+-
|
||||
mealInfo.Balance += order.Amount;
|
||||
(mealInfo.Balance < 0).ThrowIfTrue("余额不足,无法消费");
|
||||
|
||||
var effectMeal = await DbContext.Updateable<GainfoMealEntity>()
|
||||
.SetColumns(x => x.Balance == mealInfo.Balance)
|
||||
.SetColumns(x => x.Version == x.Version + 1)
|
||||
.Where(x => x.UserNo == order.UserNo && x.Version == mealInfo.Version)//必须与查询时的version一致
|
||||
.ExecuteCommandAsync();
|
||||
.SetColumns(x => x.Balance == mealInfo.Balance)
|
||||
.SetColumns(x => x.Version == x.Version + 1)
|
||||
.Where(x => x.UserNo == order.UserNo && x.Version == mealInfo.Version)//必须与查询时的version一致
|
||||
.ExecuteCommandAsync();
|
||||
|
||||
if (effectMeal <= 0) throw new VersionExceptions("更新版本冲突");
|
||||
}
|
||||
|
||||
|
||||
var effectMenu = await DbContext.Updateable<DishesMenuEntity>()
|
||||
.SetColumns(x => x.Number == menuDetail.Number)
|
||||
.SetColumns(x => x.Version == x.Version + 1)
|
||||
.SetColumns(x => x.ModifiedTime == now)
|
||||
.SetColumns(x => x.Number == menuDetail.Number)
|
||||
.SetColumns(x => x.Version == x.Version + 1)
|
||||
.SetColumns(x => x.ModifiedTime == now)
|
||||
.Where(x => x.StartDate <= menuDetail.Date && menuDetail.Date <= x.EndDate
|
||||
&& x.ShiftType == request.ShiftType
|
||||
&& x.BusinessPlaceCode == request.BusinessPlaceCode
|
||||
&& x.DishesCode == request.DishesCode
|
||||
&& x.Version == menuDetail.Version
|
||||
)
|
||||
.ExecuteCommandAsync();
|
||||
&& x.ShiftType == request.ShiftType
|
||||
&& x.BusinessPlaceCode == request.BusinessPlaceCode
|
||||
&& x.DishesCode == request.DishesCode
|
||||
&& x.Version == menuDetail.Version
|
||||
)
|
||||
.ExecuteCommandAsync();
|
||||
|
||||
if (effectMenu <= 0) throw new VersionExceptions("更新版本冲突");
|
||||
|
||||
@@ -176,7 +178,7 @@ public class BookingOrderService : BaseOrderService, IBookingOrderService
|
||||
var myCodes = (await _businessPlacePermissionsApi.GetMyAsync()).Data.Select(x => (Guid?)x.Code).ToList();
|
||||
|
||||
var page = await DbContext.Queryable<CanteenOrderEntity>()
|
||||
.LeftJoin<GainfoEntity>((x, ga) => x.UserNo == ga.No)
|
||||
.LeftJoin<GainfoEntity>((x, ga) => x.UserNo == ga.No)
|
||||
.Where(x => myCodes.Contains(x.BusinessPlaceCode))
|
||||
.WhereIF(request.OrderStatus.HasValue, x => x.OrderStatus == request.OrderStatus)
|
||||
.WhereIF(request.Search.IsPresent(), (x, ga) => x.UserCode == request.Search || ga.Name.Contains(request.Search))
|
||||
@@ -242,9 +244,9 @@ public class BookingOrderService : BaseOrderService, IBookingOrderService
|
||||
.ExecuteCommandAsync();
|
||||
|
||||
if (effect <= 0)
|
||||
{
|
||||
{
|
||||
throw new VersionExceptions("取消订单失败!");
|
||||
}
|
||||
}
|
||||
|
||||
}, 5);
|
||||
}
|
||||
|
||||
@@ -18,8 +18,6 @@ using SqlSugar;
|
||||
using Dlhis.Canteen.Order.Response;
|
||||
using Dlhis.Canteen.Dishes;
|
||||
using Dlhis.Canteen.Order.Request;
|
||||
using System.Numerics;
|
||||
using MySqlX.XDevAPI.Relational;
|
||||
|
||||
namespace Dlhis.Canteen.Order.Services.Implements;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user