Explorar o código

Merge branch 'feature/snapshot' into test

qinchaoyue hai 3 meses
pai
achega
dd79f6c7bf

+ 7 - 39
src/Hotline.Api/Controllers/ExportData/ExportDataController.cs

@@ -1,15 +1,10 @@
 using Hotline.Application.ExportExcel;
 using Hotline.Share.Dtos.Order;
-using Hotline.Share.Dtos.Snapshot;
 using Hotline.Share.Tools;
 using Microsoft.AspNetCore.Mvc;
-using Microsoft.AspNetCore.Routing;
-using MongoDB.Bson.IO;
 using SqlSugar;
 using System.ComponentModel;
 using System.Reflection;
-using System.Text.Json;
-using XF.Domain.Dependency;
 using XF.Domain.Exceptions;
 
 namespace Hotline.Api.Controllers.ExportData;
@@ -40,28 +35,25 @@ public class ExportDataController : BaseController
         var fullPath = HttpContext.Request.Path.Value;
         var originalPath = fullPath?.Substring(0, fullPath.LastIndexOf("/export_excel")).TrimStart('/');
         if (string.IsNullOrEmpty(originalPath))
-            throw UserFriendlyException.SameMessage("Invalid export path.");
+            throw UserFriendlyException.SameMessage("无效的URL地址" + fullPath);
 
         var matchingEndpoint = _endpointDataSource.Endpoints
             .OfType<RouteEndpoint>()
-            .FirstOrDefault(endpoint => endpoint.RoutePattern.RawText == originalPath);
-
-        if (matchingEndpoint == null)
-            throw UserFriendlyException.SameMessage($"No route matches '{originalPath}'.");
+            .FirstOrDefault(endpoint => endpoint.RoutePattern.RawText == originalPath) 
+            ?? throw UserFriendlyException.SameMessage($"根据URL查询路由失败: {originalPath}");
 
         var controllerName = matchingEndpoint.RoutePattern.RequiredValues["controller"]?.ToString();
         var actionName = matchingEndpoint.RoutePattern.RequiredValues["action"]?.ToString();
 
-        var applicationServiceType = GetApplicationServiceType(controllerName);
-        if (applicationServiceType == null)
-            throw UserFriendlyException.SameMessage($"Application service for '{controllerName}' not found.");
+        var applicationServiceType = GetApplicationServiceType(controllerName) 
+            ?? throw UserFriendlyException.SameMessage($"根据名称查找方法失败. '{controllerName}'");
 
         var method = applicationServiceType.GetMethod(actionName);
         if (method == null)
         {
             method = applicationServiceType.GetMethod(actionName + "Async");
             if (method == null)
-                throw UserFriendlyException.SameMessage($"Action '{actionName}' not found in Application service.");
+                throw UserFriendlyException.SameMessage($"根据方法名查找方法失败. '{actionName}'");
         }
 
         var serviceInstance = _serviceProvider.GetService(applicationServiceType);
@@ -69,7 +61,7 @@ public class ExportDataController : BaseController
         {
             serviceInstance = _serviceProvider.GetService(applicationServiceType.GetInterfaces()[0]);
             if (serviceInstance == null)
-                throw UserFriendlyException.SameMessage($"Unable to create instance of Application service '{applicationServiceType.Name}'.");
+                throw UserFriendlyException.SameMessage($"获取注入失败. '{applicationServiceType.Name}'.");
         }
 
         try
@@ -137,35 +129,11 @@ public class ExportDataController : BaseController
 
     private Type GetApplicationServiceType(string controllerName)
     {
-        // 根据约定规则,将 Controller 映射到 Application 服务类
-        // 假设 Application 服务类命名规则为 "{ControllerName}Application"
-        var applicationServiceName = $"Hotline.Application.Snapshot.{controllerName}Application";
         var name = controllerName + "Application";
-
         var type = AppDomain.CurrentDomain.GetAssemblies().ToList()
         .SelectMany(d => d.GetTypes())
            .Where(d => d.Name == name)
            .First();
         return type;
     }
-
-    private async Task<object[]> BindMethodParameters(System.Reflection.MethodInfo method)
-    {
-        // 动态解析方法的参数绑定
-        var parameters = method.GetParameters();
-        var result = new List<object>();
-
-        foreach (var param in parameters)
-        {
-            using var reader = new StreamReader(HttpContext.Request.Body);
-            var body = await reader.ReadToEndAsync();
-            var genericType = typeof(ExportExcelDto<>).MakeGenericType(param.ParameterType);
-            var deserializedObject = body.FromJson(genericType);
-            var queryDto = genericType.GetProperty("QueryDto")?.GetValue(deserializedObject);
-            result.Add(queryDto);
-        }
-
-        return result.ToArray();
-    }
-
 }

+ 2 - 2
src/Hotline.Application/Snapshot/OrderSnapshotApplication.cs → src/Hotline.Application/Snapshot/SnapshotOrderApplication.cs

@@ -30,7 +30,7 @@ using XF.Domain.Exceptions;
 using XF.Utility.EnumExtensions;
 
 namespace Hotline.Application.Snapshot;
-public class OrderSnapshotApplication : IOrderSnapshotApplication, IScopeDependency
+public class SnapshotOrderApplication : IOrderSnapshotApplication, IScopeDependency
 {
     private readonly IOrderSnapshotRepository _orderSnapshotRepository;
     private readonly IOrderRepository _orderRepository;
@@ -44,7 +44,7 @@ public class OrderSnapshotApplication : IOrderSnapshotApplication, IScopeDepende
     private readonly ISnapshotLabelLogRepository _snapshotLabelLogRepository;
     private readonly IRedPackAuditRepository _redPackAuditRepository;
 
-    public OrderSnapshotApplication(IOrderSnapshotRepository orderSnapshotRepository, IOrderRepository orderRepository, ISnapshotOrderPublishRepository snapshotOrderPublishRepository, ISessionContext sessionContext, ISystemSettingCacheManager systemSettingCacheManager, IIndustryCaseRepository industryCaseRepository, ISystemDicDataCacheManager systemDicDataCacheManager, IIndustryRepository industryRepository, IFileRepository fileRepository, ISnapshotLabelLogRepository snapshotLabelLogRepository, IRedPackAuditRepository redPackAuditRepository)
+    public SnapshotOrderApplication(IOrderSnapshotRepository orderSnapshotRepository, IOrderRepository orderRepository, ISnapshotOrderPublishRepository snapshotOrderPublishRepository, ISessionContext sessionContext, ISystemSettingCacheManager systemSettingCacheManager, IIndustryCaseRepository industryCaseRepository, ISystemDicDataCacheManager systemDicDataCacheManager, IIndustryRepository industryRepository, IFileRepository fileRepository, ISnapshotLabelLogRepository snapshotLabelLogRepository, IRedPackAuditRepository redPackAuditRepository)
     {
         _orderSnapshotRepository = orderSnapshotRepository;
         _orderRepository = orderRepository;

+ 5 - 0
src/Hotline.Share/Dtos/Snapshot/IndustryDto.cs

@@ -121,6 +121,11 @@ public class IndustryItemsOutDto : IndustryOutDto
     /// </summary>
     public bool IsEnable { get; set; }
 
+    /// <summary>
+    /// 是否启用
+    /// </summary>
+    public string IsEnableTxt => IsEnable ? "启用" : "禁用";
+
     /// <summary>
     /// 排序
     /// </summary>