98 lines
3.4 KiB
C#
98 lines
3.4 KiB
C#
using SJZY.Track.Domain;
|
|
using SJZY.Track.Domain.Aggregates.OrderAggregate;
|
|
using SJZY.Track.Domain.Dtos.Order;
|
|
|
|
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<int> PushWarnOrdersAsync()
|
|
{
|
|
return await Context.Ado.ExecuteCommandAsync(@"UPDATE `t_track_push_config` `a`
|
|
LEFT JOIN `t_order` `b` ON `a`.`SubSystemId` = `b`.`SubSystemId` AND `a`.`CustomId` = `b`.`CustomId`
|
|
SET `b`.`QuestionType` = CASE
|
|
WHEN `b`.`LatestPushTime` IS NULL THEN 2
|
|
WHEN `b`.`LatestPushTime` < DATE_SUB(NOW(), INTERVAL 12 HOUR) THEN 2
|
|
ELSE 0 END
|
|
WHERE `b`.`IsCompleted` = 0 AND `b`.`QuestionType` != 1 AND `b`.`CreateTime` < DATE_SUB(NOW(), INTERVAL 12 HOUR)
|
|
AND `a`.`IsDeleted` = 0 AND `b`.`IsDeleted` = 0;");
|
|
}
|
|
|
|
#region 订单关联
|
|
|
|
public async Task<List<LinkedOrderVO>> GetLinkedOrdersAsync(int[] orderIds)
|
|
{
|
|
return await Context.Queryable<OrderLinkEntity>()
|
|
.LeftJoin<OrderEntity>((a, b) => a.LinkOrderId == b.Id)
|
|
.Where(a => orderIds.Contains(a.OrderId))
|
|
.Select((a, b) => new LinkedOrderVO
|
|
{
|
|
OwnerOrderId = a.OrderId,
|
|
OrderId = b.Id,
|
|
OrderNo = b.OrderNo,
|
|
OrderType = b.OrderType,
|
|
SubSystemId = b.SubSystemId,
|
|
CustomId = b.CustomId
|
|
})
|
|
.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
|
|
} |