Kaynağa Gözat

fixed: 导出excel支持可空日期格式

xf 1 ay önce
ebeveyn
işleme
cd6dfe1f7f

+ 32 - 25
src/Hotline.Api/Controllers/TestController.cs

@@ -1495,42 +1495,49 @@ public class TestController : BaseController
              */
             new ColumnInfo { Prop = "title", Name = "工单标题" },
             new ColumnInfo { Prop = "expiredTime", Name = "期满时间" },
-            new ColumnInfo { Prop = "reTransactNum", Name = "重办次数" },
+            new ColumnInfo { Prop = "allDurationHour", Name = "办理时长" },
+            new ColumnInfo { Prop = "creationTimeHandleDuration", Name = "办结时长" },
         };
-        dynamic? dynamicClass = DynamicClassHelper.CreateDynamicClass<MyClass>(columns);
+        dynamic? dynamicClass = DynamicClassHelper.CreateDynamicClass<OrderDto>(columns);
 
         //var order = await _orderRepository.GetAsync("08dd65e7-7a7c-43ce-8212-242435a18216", HttpContext.RequestAborted);
         //var dto = _mapper.Map<OrderDto>(order);
 
-        var dtos = new List<MyClass> {
-            new MyClass
-        {
-            Title = "测试标题",
-            ExpiredTime = DateTime.Now,
-            ReTransactNum = 12
-        },
-            new MyClass
-            {
-                Title = "测试标题1",
-                ExpiredTime = DateTime.Now.AddDays(1),
-                ReTransactNum = 13
-            },
-            new MyClass
-            {
-                Title = "测试标题2",
-                ExpiredTime = DateTime.Now.AddDays(2),
-                ReTransactNum = 14
-            }
-        };
+        //var dtos = new List<MyClass> {
+        //    new MyClass
+        //{
+        //    Title = "测试标题",
+        //    ExpiredTime = DateTime.Now,
+        //    ReTransactNum = 12
+        //},
+        //    new MyClass
+        //    {
+        //        Title = "测试标题1",
+        //        ExpiredTime = DateTime.Now.AddDays(1),
+        //        ReTransactNum = 13
+        //    },
+        //    new MyClass
+        //    {
+        //        Title = "测试标题2",
+        //        ExpiredTime = DateTime.Now.AddDays(2),
+        //        ReTransactNum = 14
+        //    }
+        //};
 
         //dynamic temp = _mapper.Map(dtos, typeof(List<MyClass>), dynamicClass);
+        var orders = await _orderRepository.Queryable()
+            .OrderByDescending(d => d.CreationTime)
+            .Take(10)
+            .ToListAsync(HttpContext.RequestAborted);
+
+        var orderDtos = _mapper.Map<List<OrderDto>>(orders);
 
-        dynamic temp = dtos
-            .Select(stu => _mapper.Map(stu, typeof(MyClass), dynamicClass))
+        var dtos = orderDtos
+            .Select(stu => _mapper.Map(stu, typeof(OrderDto), dynamicClass))
             .Cast<object>()
             .ToList();
 
-        var stream = ExcelHelper.CreateStream(temp);
+        var stream = ExcelHelper.CreateStream(dtos);
 
         return ExcelStreamResult(stream, "工单数据");
     }

+ 1 - 1
src/Hotline/Tools/DynamicClassHelper.cs

@@ -91,7 +91,7 @@ public class DynamicClassHelper
             var attributeBuilder = new CustomAttributeBuilder(columnNameCtorInfo, new object[] { property.Name, null });
             propertyBuilder.SetCustomAttribute(attributeBuilder);
 
-            if (propertyType == typeof(DateTime))
+            if (propertyType == typeof(DateTime) || propertyType == typeof(DateTime?))
             {
                 var columnExcelFormatCtorInfo = typeof(ExcelFormatAttribute).GetConstructor(new Type[] { typeof(string) });
                 var excelFormatAttributeBuilder = new CustomAttributeBuilder(columnExcelFormatCtorInfo, new object[] { "yyyy-MM-dd HH:mm:ss" });