|
|
|
@ -1,4 +1,6 @@
|
|
|
|
|
using EntrustSettle.Common;
|
|
|
|
|
using Amazon.Runtime;
|
|
|
|
|
using EntrustSettle.Common;
|
|
|
|
|
using EntrustSettle.Common.Const;
|
|
|
|
|
using EntrustSettle.Common.Extensions;
|
|
|
|
|
using EntrustSettle.Controllers;
|
|
|
|
|
using EntrustSettle.IServices;
|
|
|
|
@ -9,7 +11,9 @@ using EntrustSettle.Model.Validator;
|
|
|
|
|
using EntrustSettle.Repository.UnitOfWorks;
|
|
|
|
|
using FluentValidation;
|
|
|
|
|
using Mapster;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using System.ComponentModel.DataAnnotations;
|
|
|
|
|
|
|
|
|
|
namespace EntrustSettle.Api.Controllers
|
|
|
|
|
{
|
|
|
|
@ -23,18 +27,21 @@ namespace EntrustSettle.Api.Controllers
|
|
|
|
|
private readonly ILogger<OrderController> logger;
|
|
|
|
|
private readonly IUnitOfWorkManage unitOfWorkManage;
|
|
|
|
|
private readonly IOrderHistoryService orderHistoryService;
|
|
|
|
|
private readonly IHttpClientFactory httpClientFactory;
|
|
|
|
|
|
|
|
|
|
public OrderController(IOrderService orderService,
|
|
|
|
|
IOrderAnnexService orderFileService,
|
|
|
|
|
ILogger<OrderController> logger,
|
|
|
|
|
IUnitOfWorkManage unitOfWorkManage,
|
|
|
|
|
IOrderHistoryService orderHistoryService)
|
|
|
|
|
IOrderHistoryService orderHistoryService,
|
|
|
|
|
IHttpClientFactory httpClientFactory)
|
|
|
|
|
{
|
|
|
|
|
this.orderService = orderService;
|
|
|
|
|
this.orderAnnexService = orderFileService;
|
|
|
|
|
this.logger = logger;
|
|
|
|
|
this.unitOfWorkManage = unitOfWorkManage;
|
|
|
|
|
this.orderHistoryService = orderHistoryService;
|
|
|
|
|
this.httpClientFactory = httpClientFactory;
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 获取订单列表
|
|
|
|
@ -63,17 +70,25 @@ namespace EntrustSettle.Api.Controllers
|
|
|
|
|
|
|
|
|
|
return SuccessPage(result);
|
|
|
|
|
}
|
|
|
|
|
[HttpGet]
|
|
|
|
|
[AllowAnonymous]
|
|
|
|
|
public async Task<MessageModel> Test()
|
|
|
|
|
{
|
|
|
|
|
await Task.CompletedTask;
|
|
|
|
|
return SuccessMsg();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 下单
|
|
|
|
|
/// </summary>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
// test:[UseTran]
|
|
|
|
|
//[UseTran]
|
|
|
|
|
public async Task<MessageModel> Submit(OrderSubmitDto inputDto)
|
|
|
|
|
{
|
|
|
|
|
var validator = new OrderSubmitDtoValidator();
|
|
|
|
|
validator.ValidateAndThrow(inputDto);
|
|
|
|
|
|
|
|
|
|
// 订单信息保存
|
|
|
|
|
var orderList = new List<Order>();
|
|
|
|
|
foreach (var item in inputDto.MblnoList)
|
|
|
|
|
{
|
|
|
|
@ -94,7 +109,8 @@ namespace EntrustSettle.Api.Controllers
|
|
|
|
|
unitOfWorkManage.BeginTran();
|
|
|
|
|
var orderIdList = await orderService.Add(orderList);
|
|
|
|
|
|
|
|
|
|
if (inputDto.AnnexIdList.Length > 0)
|
|
|
|
|
// 附件关联信息保存
|
|
|
|
|
if (inputDto.AnnexIdList?.Count > 0)
|
|
|
|
|
{
|
|
|
|
|
var orderFileModelList = new List<OrderAnnex>();
|
|
|
|
|
|
|
|
|
@ -111,9 +127,23 @@ namespace EntrustSettle.Api.Controllers
|
|
|
|
|
};
|
|
|
|
|
await orderAnnexService.Add(orderFileModelList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 状态历史保存
|
|
|
|
|
var historyModelList = new List<OrderHistory>();
|
|
|
|
|
foreach (var item in orderIdList)
|
|
|
|
|
{
|
|
|
|
|
historyModelList.Add(new OrderHistory
|
|
|
|
|
{
|
|
|
|
|
Pid = item,
|
|
|
|
|
Status = (int)OrderStatusEnum.已下单,
|
|
|
|
|
StatusTime = DateTime.Now
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
await orderHistoryService.Add(historyModelList);
|
|
|
|
|
|
|
|
|
|
unitOfWorkManage.CommitTran();
|
|
|
|
|
|
|
|
|
|
// todo:测试是否不需要rollback
|
|
|
|
|
return SuccessMsg();
|
|
|
|
|
}
|
|
|
|
|
/// <summary>
|
|
|
|
@ -125,8 +155,13 @@ namespace EntrustSettle.Api.Controllers
|
|
|
|
|
public async Task<MessageModel<List<AnnexDto>>> GetAnnexInfoList(long id, FileTypeEnum fileType)
|
|
|
|
|
{
|
|
|
|
|
var result = await orderAnnexService.Db.Queryable<OrderAnnex, Annex>((o, a) => o.AnnexId == a.Id)
|
|
|
|
|
.Where((o, a) => o.OrderId == id && a.Type == (byte)fileType)
|
|
|
|
|
.Select<AnnexDto>()
|
|
|
|
|
.Where((o, a) => o.OrderId == id && a.Type == (int)fileType)
|
|
|
|
|
.Select((o, a) => new AnnexDto()
|
|
|
|
|
{
|
|
|
|
|
Name = a.Name,
|
|
|
|
|
Type = a.Type,
|
|
|
|
|
Id = a.Id
|
|
|
|
|
})
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
|
|
|
|
|
return Success(result);
|
|
|
|
@ -178,7 +213,7 @@ namespace EntrustSettle.Api.Controllers
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("未找到该订单");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unitOfWorkManage.BeginTran();
|
|
|
|
|
// 添加要新增绑定的附件信息
|
|
|
|
|
var orderAnnexModelList = bindDto.NewAnnexIdList.Select(x => new OrderAnnex()
|
|
|
|
|
{
|
|
|
|
@ -195,14 +230,15 @@ namespace EntrustSettle.Api.Controllers
|
|
|
|
|
await orderAnnexService.Delete(x => bindDto.DelAnnexIdList.Contains(x.AnnexId));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var updateable = orderService.AsUpdateable(order);
|
|
|
|
|
|
|
|
|
|
orderService.Db.Tracking(order);
|
|
|
|
|
if (bindDto.OperType == FileTypeEnum.反馈附件)
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(bindDto.Remark))
|
|
|
|
|
{
|
|
|
|
|
order.Remark += (Environment.NewLine + bindDto.Remark);
|
|
|
|
|
updateable.UpdateColumns(x => x.Remark);
|
|
|
|
|
string remark = string.IsNullOrEmpty(order.Remark) ?
|
|
|
|
|
bindDto.Remark :
|
|
|
|
|
order.Remark += (Environment.NewLine + bindDto.Remark);
|
|
|
|
|
order.Remark = remark;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else if (bindDto.OperType == FileTypeEnum.发票)
|
|
|
|
@ -210,15 +246,12 @@ namespace EntrustSettle.Api.Controllers
|
|
|
|
|
if (bindDto.MailFlag != null)
|
|
|
|
|
{
|
|
|
|
|
order.MailFlag = bindDto.MailFlag;
|
|
|
|
|
updateable.UpdateColumns(x => x.MailFlag);
|
|
|
|
|
}
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(bindDto.MailBillNo))
|
|
|
|
|
{
|
|
|
|
|
order.MailBillNo = bindDto.MailBillNo;
|
|
|
|
|
updateable.UpdateColumns(x => x.MailBillNo);
|
|
|
|
|
}
|
|
|
|
|
order.MailBillNo = bindDto.MailBillNo;
|
|
|
|
|
}
|
|
|
|
|
await updateable.Where(x => x.Id == bindDto.OrderId).ExecuteCommandHasChangeAsync();
|
|
|
|
|
await orderService.Db.Updateable(order).ExecuteCommandAsync();
|
|
|
|
|
unitOfWorkManage.CommitTran();
|
|
|
|
|
|
|
|
|
|
return SuccessMsg();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -233,13 +266,13 @@ namespace EntrustSettle.Api.Controllers
|
|
|
|
|
.Select<OrderDetailDto>()
|
|
|
|
|
.FirstAsync();
|
|
|
|
|
|
|
|
|
|
if (result != null)
|
|
|
|
|
if (result == null)
|
|
|
|
|
{
|
|
|
|
|
throw new Exception("为找到该订单,请刷新后重试");
|
|
|
|
|
}
|
|
|
|
|
var annexList = await orderAnnexService.Db.Queryable<OrderAnnex, Annex>((o, a) => o.AnnexId == a.Id)
|
|
|
|
|
.Where((o, a) => o.OrderId == id)
|
|
|
|
|
.Where((o, a) => a.Type == (byte)FileTypeEnum.原始附件 || a.Type == (byte)FileTypeEnum.反馈附件)
|
|
|
|
|
.Where((o, a) => a.Type == (int)FileTypeEnum.原始附件 || a.Type == (int)FileTypeEnum.反馈附件)
|
|
|
|
|
.Select<AnnexDto>()
|
|
|
|
|
.ToListAsync();
|
|
|
|
|
result.AnnexList = annexList;
|
|
|
|
|