|
|
|
@ -7,6 +7,7 @@ using EntrustSettle.Model.Models;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using RestSharp;
|
|
|
|
|
|
|
|
|
|
namespace EntrustSettle.Api.Controllers
|
|
|
|
|
{
|
|
|
|
@ -17,6 +18,8 @@ namespace EntrustSettle.Api.Controllers
|
|
|
|
|
public class OpenController : BaseApiController
|
|
|
|
|
{
|
|
|
|
|
private readonly IOrderService orderService;
|
|
|
|
|
private readonly IAnnexService annexService;
|
|
|
|
|
private readonly IOrderAnnexService orderAnnexService;
|
|
|
|
|
private readonly ILogger<OpenController> logger;
|
|
|
|
|
private readonly IOrderHistoryService orderHistoryService;
|
|
|
|
|
private readonly IQueueService queueService;
|
|
|
|
@ -25,13 +28,17 @@ namespace EntrustSettle.Api.Controllers
|
|
|
|
|
ILogger<OpenController> logger,
|
|
|
|
|
IOrderHistoryService orderHistoryService,
|
|
|
|
|
IQueueService queueService,
|
|
|
|
|
IOrderFeeService orderFeeService)
|
|
|
|
|
IOrderFeeService orderFeeService,
|
|
|
|
|
IAnnexService annexService,
|
|
|
|
|
IOrderAnnexService orderAnnexService)
|
|
|
|
|
{
|
|
|
|
|
this.orderService = orderService;
|
|
|
|
|
this.logger = logger;
|
|
|
|
|
this.orderHistoryService = orderHistoryService;
|
|
|
|
|
this.queueService = queueService;
|
|
|
|
|
this.orderFeeService = orderFeeService;
|
|
|
|
|
this.annexService = annexService;
|
|
|
|
|
this.orderAnnexService = orderAnnexService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -87,41 +94,90 @@ namespace EntrustSettle.Api.Controllers
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
[ApiUser(ApiCode = "PushOrderStatus")]
|
|
|
|
|
public async Task<MessageModel> PushOrderStatus([FromBody] HydQueryResultDto item)
|
|
|
|
|
public async Task<MessageModel> PushOrderStatus([FromBody] HydQueryResultDto input)
|
|
|
|
|
{
|
|
|
|
|
var orderList = await orderService.Query(x => x.Bsno == item.id);
|
|
|
|
|
var orderList = await orderService.Query(x => x.Bsno == input.id);
|
|
|
|
|
if (orderList == null || orderList.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
string msg = $"订单Id[{item.id}]接收到回推后未查询到本地订单";
|
|
|
|
|
string msg = $"订单Id[{input.id}]接收到回推后未查询到本地订单";
|
|
|
|
|
logger.LogInformation(msg);
|
|
|
|
|
return FailedMsg(msg);
|
|
|
|
|
}
|
|
|
|
|
if (orderList.Count > 1)
|
|
|
|
|
{
|
|
|
|
|
string msg = $"订单Id[{item.id}]接收到回推后根据Id查询到多个本地订单:{string.Join(',', orderList.Select(x => x.Mblno))}";
|
|
|
|
|
string msg = $"订单Id[{input.id}]接收到回推后根据Id查询到多个本地订单:{string.Join(',', orderList.Select(x => x.Mblno))}";
|
|
|
|
|
logger.LogInformation(msg);
|
|
|
|
|
return FailedMsg(msg);
|
|
|
|
|
}
|
|
|
|
|
var order = orderList[0];
|
|
|
|
|
if (order.Status == item.status)
|
|
|
|
|
|
|
|
|
|
// 保存往来单据
|
|
|
|
|
if (input.feedback != null && input.feedback.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
string msg = $"订单Id[{item.id}],提单号[{order.Mblno}]状态不变";
|
|
|
|
|
logger.LogInformation(msg);
|
|
|
|
|
return SuccessMsg(msg);
|
|
|
|
|
var outerFileIdList = input.feedback.Select(x => x.id).ToList();
|
|
|
|
|
|
|
|
|
|
var existsOuterFileIdList = await orderAnnexService.AsQueryable()
|
|
|
|
|
.LeftJoin<Annex>((o, a) => o.AnnexId == a.Id)
|
|
|
|
|
.Where((o, a) => o.OrderId == order.Id && outerFileIdList.Contains((long)a.OuterFileId))
|
|
|
|
|
.Select((o, a) => a.OuterFileId)
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
foreach (var item in input.feedback)
|
|
|
|
|
{
|
|
|
|
|
// 如果文件不是外部推送的,不处理
|
|
|
|
|
if (item.sendType != 1)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
// 如果文件信息已经存在,不处理
|
|
|
|
|
if (existsOuterFileIdList.Contains(item.id))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(item.fileUrl))
|
|
|
|
|
{
|
|
|
|
|
// 检查文件保存目录
|
|
|
|
|
var dir = Path.Combine(App.WebHostEnvironment.WebRootPath, "files");
|
|
|
|
|
if (!Directory.Exists(dir))
|
|
|
|
|
{
|
|
|
|
|
Directory.CreateDirectory(dir);
|
|
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
|
// 文件名
|
|
|
|
|
var newFileName = Guid.NewGuid().ToString("N") + Path.GetExtension(item.fileName);
|
|
|
|
|
|
|
|
|
|
// 相对路径
|
|
|
|
|
var relativePath = Path.Combine("files", newFileName);
|
|
|
|
|
|
|
|
|
|
// 完整路径
|
|
|
|
|
var fullPath = Path.Combine(dir, newFileName);
|
|
|
|
|
|
|
|
|
|
// 保存附件信息
|
|
|
|
|
var annex = new Annex()
|
|
|
|
|
{
|
|
|
|
|
Pid = order.Id,
|
|
|
|
|
Status = item.status,
|
|
|
|
|
StatusTime = DateTime.Now,
|
|
|
|
|
CreateBy = "系统",
|
|
|
|
|
Remark = "(状态接收)"
|
|
|
|
|
});
|
|
|
|
|
Type = 5,
|
|
|
|
|
|
|
|
|
|
OuterFileId = item.id,
|
|
|
|
|
Name = item.fileName,
|
|
|
|
|
Remark = item.remark,
|
|
|
|
|
BusinessTime = item.createTime,
|
|
|
|
|
|
|
|
|
|
Path = relativePath
|
|
|
|
|
};
|
|
|
|
|
await annexService.Add(annex);
|
|
|
|
|
|
|
|
|
|
var orderAnnex = new OrderAnnex()
|
|
|
|
|
{
|
|
|
|
|
OrderId = order.Id,
|
|
|
|
|
AnnexId = annex.Id
|
|
|
|
|
};
|
|
|
|
|
await orderAnnexService.Add(orderAnnex);
|
|
|
|
|
|
|
|
|
|
var restClient = new RestClient(item.fileUrl);
|
|
|
|
|
var request = new RestRequest();
|
|
|
|
|
using var stream = await restClient.DownloadStreamAsync(request);
|
|
|
|
|
using FileStream fileStream = new FileStream(fullPath, FileMode.Create);
|
|
|
|
|
await stream.CopyToAsync(fileStream);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 将更新后的状态及费用推送到消息队列
|
|
|
|
|
if (AppSettings.app("RabbitMQ", "Enabled").ObjToBool())
|
|
|
|
@ -138,8 +194,8 @@ namespace EntrustSettle.Api.Controllers
|
|
|
|
|
MessageType = 1,
|
|
|
|
|
MessageDesc = "状态更新推送",
|
|
|
|
|
Remark = "",
|
|
|
|
|
Status = item.status,
|
|
|
|
|
StatusDesc = item.status switch
|
|
|
|
|
Status = input.status,
|
|
|
|
|
StatusDesc = input.status switch
|
|
|
|
|
{
|
|
|
|
|
0 => "已下单",
|
|
|
|
|
1 => "已接单",
|
|
|
|
@ -159,18 +215,55 @@ namespace EntrustSettle.Api.Controllers
|
|
|
|
|
FeeAmount = x.Amount
|
|
|
|
|
}).ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var annexList = await orderAnnexService.AsQueryable()
|
|
|
|
|
.LeftJoin<Annex>((o, a) => o.AnnexId == a.Id)
|
|
|
|
|
.Where((o, a) => o.OrderId == order.Id && a.Type == 5)
|
|
|
|
|
.Select((o, a) => a)
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
if (annexList.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
pushDto.FeebackAnnexList = annexList.Select(x => new StatusPushDto.FeebackAnnex()
|
|
|
|
|
{
|
|
|
|
|
Id = x.Id,
|
|
|
|
|
BusinessTime = x.BusinessTime,
|
|
|
|
|
FileName = x.Name,
|
|
|
|
|
Remark = x.Remark
|
|
|
|
|
}).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}");
|
|
|
|
|
logger.LogError(ex, $"订单Id[{input.id}],提单号[{order.Mblno}]接收到状态然后推送时发生未知异常:{msg}");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return SuccessMsg($"订单Id[{item.id}],提单号[{order.Mblno}]状态更新成功");
|
|
|
|
|
if (order.Status != input.status)
|
|
|
|
|
{
|
|
|
|
|
order.Status = input.status;
|
|
|
|
|
var updateSuccess = await orderService.Update(order, x => new { x.Status });
|
|
|
|
|
logger.LogInformation($"订单Id[{input.id}],提单号[{order.Mblno}]状态更新{(updateSuccess ? "成功" : "失败")},status:{input.status}");
|
|
|
|
|
|
|
|
|
|
// 记录订单状态变更历史
|
|
|
|
|
await orderHistoryService.Add(new OrderHistory()
|
|
|
|
|
{
|
|
|
|
|
Pid = order.Id,
|
|
|
|
|
Status = input.status,
|
|
|
|
|
StatusTime = DateTime.Now,
|
|
|
|
|
CreateBy = "系统",
|
|
|
|
|
Remark = "(状态接收)"
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return SuccessMsg($"订单Id[{input.id}],提单号[{order.Mblno}]状态更新成功");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
string msg = $"订单Id[{input.id}],提单号[{order.Mblno}]状态不变";
|
|
|
|
|
logger.LogInformation(msg);
|
|
|
|
|
return SuccessMsg(msg);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|