|
@@ -46,6 +46,9 @@ using Hotline.Users;
|
|
|
using MongoDB.Driver;
|
|
|
using System.Threading;
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
+using Hotline.Import;
|
|
|
+using MiniExcelLibs;
|
|
|
+using Hotline.Application.ExportExcel;
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
namespace Hotline.Api.Controllers;
|
|
@@ -102,6 +105,7 @@ public class OrderController : BaseController
|
|
|
private readonly ITypedCache<EnterpriseVo> _cacheResponse;
|
|
|
private readonly IRepository<OrderSendBackAudit> _orderSendBackAuditRepository;
|
|
|
private readonly IRepository<User> _userRepository;
|
|
|
+ private readonly IExportApplication _exportApplication;
|
|
|
|
|
|
public OrderController(
|
|
|
IOrderDomainService orderDomainService,
|
|
@@ -150,7 +154,8 @@ public class OrderController : BaseController
|
|
|
ILogger<OrderController> logger,
|
|
|
ITypedCache<EnterpriseVo> cacheResponse,
|
|
|
IRepository<OrderSendBackAudit> orderSendBackAuditRepository,
|
|
|
- IRepository<User> userRepository
|
|
|
+ IRepository<User> userRepository,
|
|
|
+ IExportApplication exportApplication
|
|
|
)
|
|
|
{
|
|
|
_orderDomainService = orderDomainService;
|
|
@@ -200,6 +205,7 @@ public class OrderController : BaseController
|
|
|
_cacheResponse = cacheResponse;
|
|
|
_orderSendBackAuditRepository = orderSendBackAuditRepository;
|
|
|
_userRepository = userRepository;
|
|
|
+ _exportApplication = exportApplication;
|
|
|
}
|
|
|
|
|
|
#region 工单发布
|
|
@@ -3710,5 +3716,81 @@ public class OrderController : BaseController
|
|
|
{
|
|
|
return await _enterpriseService.GetEnterpriseList(dto.Keyword!, dto.PageIndex, dto.PageSize, HttpContext.RequestAborted, _cacheResponse);
|
|
|
}
|
|
|
+ #endregion
|
|
|
+
|
|
|
+ #region 导入工单
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 下载工单导入模板
|
|
|
+ /// </summary>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpGet("download-order-template")]
|
|
|
+ public async Task<object> DownLoadOrderTemplate()
|
|
|
+ {
|
|
|
+ List<ExcelContent> list = new List<ExcelContent>();
|
|
|
+ ExcelContent excelContent = new ExcelContent() { No = "123123" };
|
|
|
+ list.Add(excelContent);
|
|
|
+ return _exportApplication.ExportData(list, "demo.xlsx");
|
|
|
+ }
|
|
|
+
|
|
|
+ /// <summary>
|
|
|
+ /// 导入工单
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="file"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ [HttpPost("import-order")]
|
|
|
+ public async Task ImportOrder(/*[FromForm]*/IFormFile file,/*[FromBody]*/ESource source)
|
|
|
+ {
|
|
|
+ if (source< ESource.MALASHEQU || source > ESource.WENZHENGSC)
|
|
|
+ {
|
|
|
+ throw UserFriendlyException.SameMessage("不支持导入该渠道");
|
|
|
+ }
|
|
|
+ using (var stream = new MemoryStream())
|
|
|
+ {
|
|
|
+ file.CopyTo(stream);
|
|
|
+ var list = MiniExcel.Query<ExcelContent>(stream).ToList();
|
|
|
+
|
|
|
+ if (list!=null && list.Count>0)
|
|
|
+ {
|
|
|
+ int count = list.Count;
|
|
|
+ int errorCount = 0;
|
|
|
+ int successCount = 0;
|
|
|
+ foreach (var item in list)
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var order =await _orderRepository.GetAsync(x => x.No == item.No, HttpContext.RequestAborted);
|
|
|
+ if (order is null)
|
|
|
+ {
|
|
|
+ order = _mapper.Map<Order>(item);
|
|
|
+ order.Source = source;
|
|
|
+ var id = await _orderRepository.AddAsync(order,HttpContext.RequestAborted);
|
|
|
+ if (!string.IsNullOrEmpty(id))
|
|
|
+ {
|
|
|
+ successCount++;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ errorCount++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ _mapper.Map(item, order);
|
|
|
+ await _orderRepository.UpdateAsync(order,HttpContext.RequestAborted);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ catch
|
|
|
+ {
|
|
|
+ errorCount++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
#endregion
|
|
|
}
|