|
|
|
@ -9,8 +9,12 @@ using EntrustSettle.Model.Models;
|
|
|
|
|
using EntrustSettle.Model.Validator;
|
|
|
|
|
using EntrustSettle.Repository.UnitOfWorks;
|
|
|
|
|
using FluentValidation;
|
|
|
|
|
using Mapster;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using RabbitMQ.Client;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace EntrustSettle.Api.Controllers
|
|
|
|
|
{
|
|
|
|
@ -26,6 +30,8 @@ namespace EntrustSettle.Api.Controllers
|
|
|
|
|
private readonly IUnitOfWorkManage unitOfWorkManage;
|
|
|
|
|
private readonly IOrderHistoryService orderHistoryService;
|
|
|
|
|
private readonly IHYDService hydService;
|
|
|
|
|
private readonly IOrderFeeService orderFeeService;
|
|
|
|
|
private readonly IQueueService queueService;
|
|
|
|
|
|
|
|
|
|
public OrderController(IOrderService orderService,
|
|
|
|
|
IOrderAnnexService orderFileService,
|
|
|
|
@ -33,7 +39,9 @@ namespace EntrustSettle.Api.Controllers
|
|
|
|
|
IUnitOfWorkManage unitOfWorkManage,
|
|
|
|
|
IOrderHistoryService orderHistoryService,
|
|
|
|
|
IHYDService hydService,
|
|
|
|
|
IAnnexService annexService)
|
|
|
|
|
IAnnexService annexService,
|
|
|
|
|
IOrderFeeService orderFeeService,
|
|
|
|
|
IQueueService queueService)
|
|
|
|
|
{
|
|
|
|
|
this.orderService = orderService;
|
|
|
|
|
this.orderAnnexService = orderFileService;
|
|
|
|
@ -42,6 +50,8 @@ namespace EntrustSettle.Api.Controllers
|
|
|
|
|
this.orderHistoryService = orderHistoryService;
|
|
|
|
|
this.hydService = hydService;
|
|
|
|
|
this.annexService = annexService;
|
|
|
|
|
this.orderFeeService = orderFeeService;
|
|
|
|
|
this.queueService = queueService;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取订单列表
|
|
|
|
@ -96,8 +106,8 @@ namespace EntrustSettle.Api.Controllers
|
|
|
|
|
return SuccessPage(result);
|
|
|
|
|
}
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
[ApiUser(ApiCode = "OrderSubmit")]
|
|
|
|
|
//[AllowAnonymous]
|
|
|
|
|
//[ApiUser(ApiCode = "OrderSubmit")]
|
|
|
|
|
public async Task<dynamic> Test()
|
|
|
|
|
{
|
|
|
|
|
var a = App.User.Name;
|
|
|
|
@ -296,10 +306,27 @@ namespace EntrustSettle.Api.Controllers
|
|
|
|
|
throw new Exception("未找到该订单");
|
|
|
|
|
}
|
|
|
|
|
order.Status = (int)changeStatusDto.Status;
|
|
|
|
|
order.Amount = changeStatusDto.Amount;
|
|
|
|
|
|
|
|
|
|
unitOfWorkManage.BeginTran();
|
|
|
|
|
// test是否会更新UpdateTIme
|
|
|
|
|
|
|
|
|
|
// 清除原有费用信息
|
|
|
|
|
await orderFeeService.Delete(x => x.OrderId == changeStatusDto.Id);
|
|
|
|
|
order.Amount = order.Amount == null ? null : 0;
|
|
|
|
|
|
|
|
|
|
// 添加新的费用信息
|
|
|
|
|
if (changeStatusDto.FeeList != null && changeStatusDto.FeeList.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
var orderFeeModelList = changeStatusDto.FeeList.Select(x => new OrderFee()
|
|
|
|
|
{
|
|
|
|
|
Name = x.Name,
|
|
|
|
|
Amount = x.Amount,
|
|
|
|
|
OrderId = changeStatusDto.Id
|
|
|
|
|
}).ToList();
|
|
|
|
|
await orderFeeService.Add(orderFeeModelList);
|
|
|
|
|
|
|
|
|
|
order.Amount = changeStatusDto.FeeList.Select(x => x.Amount).Sum();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await orderService.Update(order, x => new { x.Status, x.Amount });
|
|
|
|
|
|
|
|
|
|
var orderHistory = new OrderHistory
|
|
|
|
@ -307,21 +334,56 @@ namespace EntrustSettle.Api.Controllers
|
|
|
|
|
Pid = order.Id,
|
|
|
|
|
Status = (int)changeStatusDto.Status,
|
|
|
|
|
Remark = changeStatusDto.Remark,
|
|
|
|
|
Amount = changeStatusDto.Amount,
|
|
|
|
|
Amount = order.Amount,
|
|
|
|
|
StatusTime = DateTime.Now,
|
|
|
|
|
};
|
|
|
|
|
await orderHistoryService.Add(orderHistory);
|
|
|
|
|
unitOfWorkManage.CommitTran();
|
|
|
|
|
|
|
|
|
|
// 将更新后的状态及费用推送到消息队列
|
|
|
|
|
if (AppSettings.app("RabbitMQ", "Enabled").ObjToBool())
|
|
|
|
|
{
|
|
|
|
|
_ = Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
string msg = $"Id:[{order.Id}],提单号:[{order.Mblno}],手动更新状态后推送队列";
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
StatusPushDto pushDto = new()
|
|
|
|
|
{
|
|
|
|
|
MessageType = 1,
|
|
|
|
|
MessageDesc = "状态更新推送",
|
|
|
|
|
Remark = changeStatusDto.Remark,
|
|
|
|
|
Status = (int)changeStatusDto.Status,
|
|
|
|
|
StatusDesc = changeStatusDto.Status.ToString()
|
|
|
|
|
};
|
|
|
|
|
if (changeStatusDto.FeeList != null && changeStatusDto.FeeList.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
pushDto.FeeList = changeStatusDto.FeeList.Select(x => new StatusPushDto.FeeDto()
|
|
|
|
|
{
|
|
|
|
|
FeeName = x.Name,
|
|
|
|
|
FeeAmount = x.Amount
|
|
|
|
|
}).ToList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var json = JsonConvert.SerializeObject(pushDto, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore });
|
|
|
|
|
queueService.Push(msg, json);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logger.LogError(ex, $"{msg},失败");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return SuccessMsg();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 为订单更新附件或信息
|
|
|
|
|
/// 为订单追加附件或信息
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public async Task<MessageModel> BindAnnexOrInfo([FromBody] BindAnnexOrInfoDto bindDto)
|
|
|
|
|
public async Task<MessageModel> BindAnnexOrInfo(BindAnnexOrInfoDto bindDto)
|
|
|
|
|
{
|
|
|
|
|
var order = await orderService.QueryById(bindDto.OrderId);
|
|
|
|
|
if (order == null)
|
|
|
|
@ -329,10 +391,9 @@ namespace EntrustSettle.Api.Controllers
|
|
|
|
|
throw new Exception("未找到该订单");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 反馈附件需要请求海运达接口,所以需要先判断订单状态
|
|
|
|
|
// 反馈附件需要请求海运达接口,所以需要先判断是否反馈成功,成功后再执行后续操作
|
|
|
|
|
if (bindDto.OperType == FileTypeEnum.反馈附件)
|
|
|
|
|
{
|
|
|
|
|
// todo: 待放开 || order.Bsno == null
|
|
|
|
|
if (order.Status == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("请等待具有已下单状态后再进行反馈");
|
|
|
|
@ -382,9 +443,9 @@ namespace EntrustSettle.Api.Controllers
|
|
|
|
|
logger.LogInformation($"提单号:{order.Mblno}向海运达反馈成功");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
unitOfWorkManage.BeginTran();
|
|
|
|
|
if (bindDto.AnnexIdList != null && bindDto.AnnexIdList.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
unitOfWorkManage.BeginTran();
|
|
|
|
|
|
|
|
|
|
if (bindDto.OperType == FileTypeEnum.账单 || bindDto.OperType == FileTypeEnum.发票)
|
|
|
|
|
{
|
|
|
|
@ -429,6 +490,41 @@ namespace EntrustSettle.Api.Controllers
|
|
|
|
|
await orderService.Db.Updateable(order).ExecuteCommandAsync();
|
|
|
|
|
unitOfWorkManage.CommitTran();
|
|
|
|
|
|
|
|
|
|
// 如果操作类型为发票或账单,将反馈推送到消息队列
|
|
|
|
|
if ((bindDto.OperType is FileTypeEnum.发票 or FileTypeEnum.账单)
|
|
|
|
|
&& AppSettings.app("RabbitMQ", "Enabled").ObjToBool())
|
|
|
|
|
{
|
|
|
|
|
_ = Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
string msg = $"Id:[{order.Id}],提单号:[{order.Mblno}],更新账单或发票后推送队列";
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
BillPushDto pushDto = new()
|
|
|
|
|
{
|
|
|
|
|
AnnexIdList = bindDto.AnnexIdList,
|
|
|
|
|
};
|
|
|
|
|
if (bindDto.OperType == FileTypeEnum.账单)
|
|
|
|
|
{
|
|
|
|
|
pushDto.MessageType = 2;
|
|
|
|
|
pushDto.MessageDesc = "账单附件信息推送";
|
|
|
|
|
}
|
|
|
|
|
else if (bindDto.OperType == FileTypeEnum.发票)
|
|
|
|
|
{
|
|
|
|
|
pushDto.MessageType = 3;
|
|
|
|
|
pushDto.MessageDesc = "发票附件信息推送";
|
|
|
|
|
pushDto.MailFlag = bindDto.MailFlag;
|
|
|
|
|
pushDto.MailBillNo = bindDto.MailBillNo;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var json = JsonConvert.SerializeObject(pushDto, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore });
|
|
|
|
|
queueService.Push(msg, json);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
logger.LogError(ex, $"{msg},失败");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return SuccessMsg();
|
|
|
|
|
}
|
|
|
|
@ -462,5 +558,18 @@ namespace EntrustSettle.Api.Controllers
|
|
|
|
|
|
|
|
|
|
return Success(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取订单费用列表
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public async Task<MessageModel<List<OrderFeeDto>>> FeeList(long id)
|
|
|
|
|
{
|
|
|
|
|
var result = await orderFeeService.AsQueryable()
|
|
|
|
|
.Where(x => x.OrderId == id)
|
|
|
|
|
.Select<OrderFeeDto>()
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
return Success(result);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|