Browse Source

Merge branch 'master' of http://110.188.24.182:10023/Fengwo/hotline

xf 1 năm trước cách đây
mục cha
commit
9dfc68c17a

+ 2 - 0
src/Hotline.Api/Controllers/BaseController.cs

@@ -1,5 +1,6 @@
 using Hotline.Api.Filter;
 using Microsoft.AspNetCore.Mvc;
+using MiniExcelLibs;
 
 namespace Hotline.Api.Controllers;
 
@@ -9,6 +10,7 @@ namespace Hotline.Api.Controllers;
 [LogFilterAttribute]
 public class BaseController : ControllerBase
 {
+    
 }
 
 [ApiController]

+ 83 - 1
src/Hotline.Api/Controllers/OrderController.cs

@@ -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
 }

+ 41 - 3
src/Hotline.Api/Controllers/TestController.cs

@@ -1,7 +1,10 @@
 using System.Collections.Concurrent;
 using System.Data;
+using System.IO;
 using DotNetCore.CAP;
 using Fw.Utility.Client;
+using Google.Protobuf.WellKnownTypes;
+using Hotline.Application.ExportExcel;
 using Hotline.CallCenter.BlackLists;
 using Hotline.CallCenter.Devices;
 using Hotline.CallCenter.Ivrs;
@@ -13,13 +16,16 @@ using Hotline.Realtimes;
 using Hotline.Repository.SqlSugar;
 using Hotline.Repository.SqlSugar.Ts;
 using Hotline.Settings.TimeLimits;
+using Hotline.Share.Dtos.FlowEngine;
 using Hotline.Share.Dtos.Realtime;
 using Hotline.Share.Enums.Settings;
 using Hotline.Share.Mq;
 using Hotline.Users;
 using MediatR;
 using Microsoft.AspNetCore.Authorization;
+using Microsoft.AspNetCore.Http;
 using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Routing.Template;
 using Microsoft.Extensions.Options;
 using MiniExcelLibs;
 using NewRock.Sdk;
@@ -68,6 +74,7 @@ public class TestController : BaseController
     private readonly ITrClient _trClient;
     private readonly ICapPublisher _capPublisher;
     private readonly IQueue _queue;
+    private readonly IExportApplication _exportApplication;
 
 
     //private readonly ITypedCache<List<User>> _cache;
@@ -98,7 +105,8 @@ public class TestController : BaseController
         IDaySettingRepository daySettingRepository,
         ITrClient trClient,
         ICapPublisher capPublisher,
-        IQueue queue
+        IQueue queue,
+        IExportApplication exportApplication
     )
     {
         _logger = logger;
@@ -122,6 +130,7 @@ public class TestController : BaseController
         _trClient = trClient;
         _capPublisher = capPublisher;
         _queue = queue;
+        _exportApplication = exportApplication;
     }
 
     [HttpGet("testo")]
@@ -135,8 +144,37 @@ public class TestController : BaseController
     [AllowAnonymous]
     public async Task<List<ExcelContent>> Import(IFormFile file)
     {
-        List<ExcelContent> openExcelFile = MiniExcel.Query<ExcelContent>(file.FileName).ToList();
-        return openExcelFile;
+        //var FileName = file.FileName;
+        //var fileExtension = Path.GetExtension(FileName);
+        ////新文件名
+        //var newFileName = DateTime.Now.ToString("yyyyMMddhhmmss");
+        ////文件保存路径
+        //var filePath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "Upload", newFileName);
+        ////判断路径是否存在
+        //if (!Directory.Exists(filePath))
+        //{
+        //    //创建路径
+        //    Directory.CreateDirectory(filePath);
+        //}
+        //filePath = Path.Combine(filePath, newFileName+ fileExtension);
+        using (var stream = new MemoryStream())
+        {
+            file.CopyTo(stream);
+            var list = MiniExcel.Query<ExcelContent>(stream).ToList();
+            //Directory.Delete(filePath, true);
+            return list;
+        }
+
+    }
+
+    [AllowAnonymous]
+    [HttpGet("export")]
+    public async Task<object> Export()
+    {
+        List<ExcelContent> list = new List<ExcelContent>();
+        ExcelContent excelContent = new ExcelContent() { No = "123123" };
+        list.Add(excelContent);
+        return _exportApplication.ExportData<ExcelContent>(list, "demo.xlsx");
     }
 
 

BIN
src/Hotline.Api/wwwroot/Upload/20240313110019/20240313110019.xlsx


+ 0 - 0
src/Hotline.Api/模板.xlsx


+ 28 - 0
src/Hotline.Application/ExportExcel/ExportApplication.cs

@@ -0,0 +1,28 @@
+
+using Microsoft.AspNetCore.Mvc;
+using MiniExcelLibs;
+using XF.Domain.Dependency;
+
+namespace Hotline.Application.ExportExcel
+{
+    public class ExportApplication : IExportApplication, IScopeDependency
+    {
+        /// <summary>
+        /// 导出数据
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="list">数据集</param>
+        /// <param name="name">导出文件名(不传则生成yyyyMMddhhmmss)</param>
+        /// <returns></returns>
+        public FileStreamResult ExportData<T>(List<T> list, string? name)
+        {
+            var stream = new MemoryStream();
+            stream.SaveAs(list);
+            stream.Seek(0, SeekOrigin.Begin);
+            return new FileStreamResult(stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
+            {
+                FileDownloadName = !string.IsNullOrEmpty(name) ? DateTime.Now.ToString("yyyyMMddhhmmss") + ".xlsx" : name
+            };
+        }
+    }
+}

+ 21 - 0
src/Hotline.Application/ExportExcel/IExportApplication.cs

@@ -0,0 +1,21 @@
+using Microsoft.AspNetCore.Mvc;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Hotline.Application.ExportExcel
+{
+    public interface IExportApplication
+    {
+        /// <summary>
+        /// 导出数据
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="list">数据集List<T></param>
+        /// <param name="name">导出文件名(不传则生成yyyyMMddhhmmss)</param>
+        /// <returns></returns>
+        FileStreamResult ExportData<T>(List<T> list, string? name);
+    }
+}

+ 20 - 1
src/Hotline.Share/Enums/Order/ESource.cs

@@ -1,4 +1,6 @@
-namespace Hotline.Share.Enums.Order;
+using System.ComponentModel;
+
+namespace Hotline.Share.Enums.Order;
 
 public enum ESource
 {
@@ -41,4 +43,21 @@ public enum ESource
     /// i宜宾
     /// </summary>
     IYIBIN = 401,
+
+    #region 导入类型(>=500  <530为导入来源)
+    /// <summary>
+    /// 麻辣社区导入
+    /// </summary>
+    [Description("麻辣社区")]
+    MALASHEQU = 500,
+
+    [Description("人民网")]
+    RENMINWANG = 501,
+
+    [Description("省长信箱")]
+    SHENGZHANGXINXIANG = 502,
+
+    [Description("问政四川")]
+    WENZHENGSC = 529,
+    #endregion
 }

+ 9 - 6
src/Hotline/Import/ExcelContent.cs

@@ -25,28 +25,28 @@ namespace Hotline.Import
         public string AcceptType { get; set; }
 
         [ExcelColumnName("热点全称")]
-        public string HotspotFullName { get; set; }
+        public string HotspotSpliceName { get; set; }
 
         [ExcelColumnName("热点名称")]
         public string HotspotName { get; set; }
 
         [ExcelColumnName("热点编码")]
-        public string HotspotCode { get; set; }
+        public string HotspotId { get; set; }
 
         [ExcelColumnName("事件全称")]
-        public string EventFullName { get; set; }
+        public string EventCategorySpliceName { get; set; }
 
         [ExcelColumnName("事件名称")]
-        public string EventName { get; set; }
+        public string EventCategoryName { get; set; }
 
         [ExcelColumnName("事件编码")]
-        public string EventCode { get; set; }
+        public string EventCategoryId { get; set; }
 
         [ExcelColumnName("地址编码")]
         public string AreaCode { get; set; }
 
         [ExcelColumnName("市")]
-        public string CityName { get; set; }
+        public string City { get; set; }
 
         [ExcelColumnName("区")]
         public string County { get; set; }
@@ -68,5 +68,8 @@ namespace Hotline.Import
 
         [ExcelColumnName("来电人身份")]
         public EIdentityType IdentityType { get; set; }
+
+        [ExcelColumnName("工单状态")]
+        public EOrderStatus OrderStatus { get; set; }
     }
 }