105 lines
3.6 KiB
C#
105 lines
3.6 KiB
C#
using SJZY.Track.Domain;
|
|
using SJZY.Track.Domain.Aggregates.OrderAggregate;
|
|
using SJZY.Track.Domain.Aggregates.TrackPushAggregate;
|
|
using SJZY.Track.Domain.Dtos.Order;
|
|
using SJZY.Track.Domain.Enums;
|
|
|
|
namespace SJZY.Track.Repository.Repositories;
|
|
|
|
public class OrderRepository : BasicRepository<OrderEntity>, IOrderRepository, ITransientDependency
|
|
{
|
|
public async Task CreateOrderAsync(OrderEntity order)
|
|
{
|
|
using var tran = TransactionHelper.GetReadCommitted();
|
|
|
|
var orderId = await InsertReturnIdentityAsync(order);
|
|
order.OrderTemplates.ForEach(x => x.OrderId = orderId);
|
|
await Context.Insertable(order.OrderTemplates).ExecuteCommandAsync();
|
|
order.OrderFlights.ForEach(x => x.OrderId = orderId);
|
|
await Context.Insertable(order.OrderFlights).ExecuteCommandAsync();
|
|
|
|
tran.Complete();
|
|
}
|
|
|
|
public async Task UpdateOrderAsync(OrderEntity order)
|
|
{
|
|
using var tran = TransactionHelper.GetReadCommitted();
|
|
|
|
// 更新订单主表
|
|
await UpdateAsync(order, x => new { x.CustomId, x.SubSystemId });
|
|
|
|
// 更新订单模板
|
|
await Context.Deleteable<OrderTemplateEntity>().Where(x => x.OrderId == order.Id).ExecuteCommandAsync();
|
|
order.OrderTemplates.ForEach(x => x.OrderId = order.Id);
|
|
await Context.Insertable(order.OrderTemplates).ExecuteCommandAsync();
|
|
|
|
// 更新订单航班
|
|
await Context.Deleteable<OrderFlightEntity>().Where(x => x.OrderId == order.Id).ExecuteCommandAsync();
|
|
order.OrderFlights.ForEach(x => x.OrderId = order.Id);
|
|
await Context.Insertable(order.OrderFlights).ExecuteCommandAsync();
|
|
|
|
tran.Complete();
|
|
}
|
|
|
|
public async Task DeleteOrderAsync(int orderId)
|
|
{
|
|
using var tran = TransactionHelper.GetReadCommitted();
|
|
|
|
// 软删订单主表
|
|
await SoftDeleteAsync(x => x.Id == orderId);
|
|
|
|
// 软删订单模板
|
|
// 软删订单航班
|
|
// 软删订单关联关系
|
|
|
|
tran.Complete();
|
|
}
|
|
|
|
public async Task<List<OrderEntity>> GetPushWarnOrdersAsync()
|
|
{
|
|
var errorType = (int)TrackProblemType.Error;
|
|
|
|
return await Context.Queryable<TrackPushConfigEntity>()
|
|
.LeftJoin<OrderEntity>((a, b) => a.SubSystemId == b.SubSystemId && a.CustomId == b.CustomId)
|
|
.Where((a, b) => !b.IsCompleted && b.QuestionType != errorType)
|
|
.Select((a, b) => new OrderEntity
|
|
{
|
|
Id = b.Id,
|
|
QuestionType = b.QuestionType,
|
|
LatestPushTime = b.LatestPushTime
|
|
})
|
|
.ToListAsync();
|
|
}
|
|
|
|
#region 订单关联
|
|
|
|
public async Task<List<LinkedOrderVO>> GetLinkedOrdersAsync(int orderId)
|
|
{
|
|
return await Context.Queryable<OrderLinkEntity>()
|
|
.LeftJoin<OrderEntity>((a, b) => a.LinkOrderId == b.Id)
|
|
.Where(a => a.OrderId == orderId)
|
|
.Select((a, b) => new LinkedOrderVO
|
|
{
|
|
OrderId = b.Id,
|
|
OrderType = b.OrderType,
|
|
OrderNo = b.OrderNo,
|
|
SubSystemId = b.SubSystemId,
|
|
LatestPushTrackContentId = b.LatestPushTrackContentId,
|
|
CustomId = b.CustomId,
|
|
IsCompleted = b.IsCompleted
|
|
})
|
|
.ToListAsync();
|
|
}
|
|
|
|
public async Task LinkOrderAsync(List<OrderLinkEntity> orderLinkEntities)
|
|
{
|
|
await Context.Insertable(orderLinkEntities).ExecuteCommandAsync();
|
|
}
|
|
|
|
public async Task UnLinkByIdsAsync(List<int> linkIds)
|
|
{
|
|
await Context.Deleteable(linkIds).ExecuteCommandAsync();
|
|
}
|
|
|
|
#endregion
|
|
} |