change:订单增删改返回id

This commit is contained in:
xiaolipro 2024-09-05 14:28:20 +08:00
parent 85b05dfa5d
commit 7206bc64cd
4 changed files with 21 additions and 19 deletions

View File

@ -10,14 +10,14 @@ public interface IOrderService : IRemoteService
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
Task<UnifyResultDto> UpsertAsync(UpsertOrderInput input);
Task<UnifyResultDto<IdBaseDto>> UpsertAsync(UpsertOrderInput input);
/// <summary>
/// 删除订单
/// </summary>
/// <param name="input"></param>
/// <returns></returns>
Task<UnifyResultDto> DeleteOrderAsync(DeleteOrderInput input);
Task<UnifyResultDto<IdBaseDto>> DeleteOrderAsync(DeleteOrderInput input);
/// <summary>
/// 关联订单

View File

@ -32,7 +32,7 @@ public partial class OrderService : ApplicationService, IOrderService
/// <param name="input"></param>
/// <returns></returns>
[HttpPost("Order/Upsert")]
public async Task<UnifyResultDto> UpsertAsync(UpsertOrderInput input)
public async Task<UnifyResultDto<IdBaseDto>> UpsertAsync(UpsertOrderInput input)
{
var subSystemId = CurrentUserRequest.SubSystemId;
@ -44,25 +44,21 @@ public partial class OrderService : ApplicationService, IOrderService
// 订单已存在则视为更新
await UpdateOrderAsync(input, order);
return new UnifyResultDto()
return new UnifyResultDto<IdBaseDto>(true, new IdBaseDto
{
Code = "200",
Msg = "操作成功",
Data = "创建成功"
};
Id = order.Id
});
}
order = ObjectMapper.Map<UpsertOrderInput, OrderEntity>(input);
order.SubSystemId = subSystemId;
order.OrderFlights = ObjectMapper.Map<List<OrderFlightInfo>, List<OrderFlightEntity>>(input.FlightInfos);
await _orderRepository.CreateOrderAsync(order);
return new UnifyResultDto()
var orderId = await _orderRepository.CreateOrderAsync(order);
return new UnifyResultDto<IdBaseDto>(true, new IdBaseDto
{
Code = "200",
Msg = "操作成功",
Data = "新增成功"
};
Id = orderId
});
}
/// <summary>
@ -72,10 +68,11 @@ public partial class OrderService : ApplicationService, IOrderService
/// <returns></returns>
/// <exception cref="BusinessException"></exception>
[HttpPost("Order/Delete")]
public async Task<UnifyResultDto> DeleteOrderAsync(DeleteOrderInput input)
public async Task<UnifyResultDto<IdBaseDto>> DeleteOrderAsync(DeleteOrderInput input)
{
var susSystemId = CurrentUserRequest.SubSystemId;
var orderId = await _orderRepository.GetFirstAsync(x =>
x.OrderType == input.OrderType && x.OrderNo == input.OrderNo, x => x.Id);
x.SubSystemId == susSystemId && x.OrderType == input.OrderType && x.OrderNo == input.OrderNo, x => x.Id);
if (orderId == default)
{
throw new BusinessException(message: $"订单:{input.OrderNo}不存在");
@ -83,7 +80,10 @@ public partial class OrderService : ApplicationService, IOrderService
await _orderRepository.DeleteOrderAsync(orderId);
return new UnifyResultDto(true, true);
return new UnifyResultDto<IdBaseDto>(true, new IdBaseDto
{
Id = orderId
});
}
private async Task UpdateOrderAsync(UpdateOrderInput input, OrderEntity order)

View File

@ -9,7 +9,7 @@ public interface IOrderRepository : IBasicRepository<OrderEntity>
/// </summary>
/// <param name="order"></param>
/// <returns></returns>
Task CreateOrderAsync(OrderEntity order);
Task<int> CreateOrderAsync(OrderEntity order);
/// <summary>
/// 更新订单

View File

@ -6,7 +6,7 @@ namespace SJZY.Track.Repository.Repositories;
public class OrderRepository : BasicRepository<OrderEntity>, IOrderRepository, ITransientDependency
{
public async Task CreateOrderAsync(OrderEntity order)
public async Task<int> CreateOrderAsync(OrderEntity order)
{
using var tran = TransactionHelper.GetReadCommitted();
@ -15,6 +15,8 @@ public class OrderRepository : BasicRepository<OrderEntity>, IOrderRepository, I
await Context.Insertable(order.OrderFlights).ExecuteCommandAsync();
tran.Complete();
return orderId;
}
public Task<int> UpdateBatchIdsAsync(List<int> ids, int newValue)