|
|
|
@ -1,9 +1,12 @@
|
|
|
|
|
using EntrustSettle.Common;
|
|
|
|
|
using EntrustSettle.Controllers;
|
|
|
|
|
using EntrustSettle.IServices;
|
|
|
|
|
using EntrustSettle.Model;
|
|
|
|
|
using EntrustSettle.Model.Dtos;
|
|
|
|
|
using EntrustSettle.Model.Models;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
|
|
|
|
namespace EntrustSettle.Api.Controllers
|
|
|
|
|
{
|
|
|
|
@ -13,8 +16,22 @@ namespace EntrustSettle.Api.Controllers
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
public class OpenController : BaseApiController
|
|
|
|
|
{
|
|
|
|
|
public OpenController()
|
|
|
|
|
private readonly IOrderService orderService;
|
|
|
|
|
private readonly ILogger<OpenController> logger;
|
|
|
|
|
private readonly IOrderHistoryService orderHistoryService;
|
|
|
|
|
private readonly IQueueService queueService;
|
|
|
|
|
private readonly IOrderFeeService orderFeeService;
|
|
|
|
|
public OpenController(IOrderService orderService,
|
|
|
|
|
ILogger<OpenController> logger,
|
|
|
|
|
IOrderHistoryService orderHistoryService,
|
|
|
|
|
IQueueService queueService,
|
|
|
|
|
IOrderFeeService orderFeeService)
|
|
|
|
|
{
|
|
|
|
|
this.orderService = orderService;
|
|
|
|
|
this.logger = logger;
|
|
|
|
|
this.orderHistoryService = orderHistoryService;
|
|
|
|
|
this.queueService = queueService;
|
|
|
|
|
this.orderFeeService = orderFeeService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -64,5 +81,96 @@ namespace EntrustSettle.Api.Controllers
|
|
|
|
|
var result = await App.GetService<AnnexController>().DownloadFile(annexId);
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 海运达状态回推接口
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ApiUser(ApiCode = "PushOrderStatus")]
|
|
|
|
|
public async Task<MessageModel> PushOrderStatus([FromBody] HydQueryResultDto item)
|
|
|
|
|
{
|
|
|
|
|
var orderList = await orderService.Query(x => x.Bsno == item.id);
|
|
|
|
|
if (orderList == null || orderList.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
string msg = $"订单Id[{item.id}]接收到回推后未查询到本地订单";
|
|
|
|
|
logger.LogInformation(msg);
|
|
|
|
|
return FailedMsg(msg);
|
|
|
|
|
}
|
|
|
|
|
if (orderList.Count > 1)
|
|
|
|
|
{
|
|
|
|
|
string msg = $"订单Id[{item.id}]接收到回推后根据Id查询到多个本地订单:{string.Join(',', orderList.Select(x => x.Mblno))}";
|
|
|
|
|
logger.LogInformation(msg);
|
|
|
|
|
return FailedMsg(msg);
|
|
|
|
|
}
|
|
|
|
|
var order = orderList[0];
|
|
|
|
|
if (order.Status == item.status)
|
|
|
|
|
{
|
|
|
|
|
string msg = $"订单Id[{item.id}],提单号[{order.Mblno}]状态不变";
|
|
|
|
|
logger.LogInformation(msg);
|
|
|
|
|
return SuccessMsg(msg);
|
|
|
|
|
}
|
|
|
|
|
order.Status = item.status;
|
|
|
|
|
var updateSuccess = await orderService.Update(order, x => new { x.Status });
|
|
|
|
|
logger.LogInformation($"订单Id[{item.id}],提单号[{order.Mblno}]状态更新{(updateSuccess ? "成功" : "失败")},status:{item.status}");
|
|
|
|
|
|
|
|
|
|
// 记录订单状态变更历史
|
|
|
|
|
await orderHistoryService.Add(new OrderHistory()
|
|
|
|
|
{
|
|
|
|
|
Pid = order.Id,
|
|
|
|
|
Status = item.status,
|
|
|
|
|
StatusTime = DateTime.Now,
|
|
|
|
|
CreateBy = "系统",
|
|
|
|
|
Remark = "(状态接收)"
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 将更新后的状态及费用推送到消息队列
|
|
|
|
|
if (AppSettings.app("RabbitMQ", "Enabled").ObjToBool())
|
|
|
|
|
{
|
|
|
|
|
_ = Task.Run(async () =>
|
|
|
|
|
{
|
|
|
|
|
string msg = $"Id:[{order.Id}],提单号[{order.Mblno}],自动更新状态后推送队列";
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
StatusPushDto pushDto = new()
|
|
|
|
|
{
|
|
|
|
|
OrderId = order.Id,
|
|
|
|
|
Mblno = order.Mblno,
|
|
|
|
|
MessageType = 1,
|
|
|
|
|
MessageDesc = "状态更新推送",
|
|
|
|
|
Remark = "",
|
|
|
|
|
Status = item.status,
|
|
|
|
|
StatusDesc = item.status switch
|
|
|
|
|
{
|
|
|
|
|
0 => "已下单",
|
|
|
|
|
1 => "已接单",
|
|
|
|
|
2 => "待缴费",
|
|
|
|
|
3 => "已缴费",
|
|
|
|
|
4 => "已完结",
|
|
|
|
|
_ => "未知状态",
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
var feeList = await orderFeeService.Query(x => x.OrderId == order.Id);
|
|
|
|
|
if (feeList.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
pushDto.FeeList = feeList.Select(x => new StatusPushDto.FeeDto()
|
|
|
|
|
{
|
|
|
|
|
FeeId = x.Id,
|
|
|
|
|
FeeName = x.Name,
|
|
|
|
|
FeeAmount = x.Amount
|
|
|
|
|
}).ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var json = JsonConvert.SerializeObject(pushDto, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore });
|
|
|
|
|
queueService.Push(msg, order.CompanyId, json);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logger.LogError(ex, $"订单Id[{item.id}],提单号[{order.Mblno}]接收到状态然后推送时发生未知异常:{msg}");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return SuccessMsg($"订单Id[{item.id}],提单号[{order.Mblno}]状态更新成功");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|