Kaynağa Gözat

修改随手拍开关, 根据配置联动.

qinchaoyue 2 hafta önce
ebeveyn
işleme
d978411c54

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

@@ -4271,10 +4271,7 @@ public class OrderController : BaseController
             .WhereIF(!string.IsNullOrEmpty(dto.Keyword), d => d.Title.Contains(dto.Keyword!) || d.No.Contains(dto.Keyword!));
 
         //随手拍
-        bool.TryParse(
-            _systemSettingCacheManager.GetSetting(SettingConstants.Snapshot)?.SettingValue[0],
-            out bool isSnapshotEnable);
-        if (isSnapshotEnable && !string.IsNullOrEmpty(dto.IndustryId))
+        if (_systemSettingCacheManager.Snapshot && !string.IsNullOrEmpty(dto.IndustryId))
         {
             query.Where(d => d.OrderSnapshot.IndustryId == dto.IndustryId);
         }

+ 1 - 4
src/Hotline.Application/Handlers/FlowEngine/WorkflowNextHandler.cs

@@ -241,10 +241,7 @@ public class WorkflowNextHandler : INotificationHandler<NextStepNotify>
                         await _qualityApplication.AddQualityAsync(EQualitySource.Send, order.Id, cancellationToken);
 
                     //随手拍推送网格员
-                    bool.TryParse(
-                        _systemSettingCacheManager.GetSetting(SettingConstants.Snapshot)?.SettingValue[0],
-                        out bool isSnapshotEnable);
-                    if (isSnapshotEnable)
+                    if (_systemSettingCacheManager.Snapshot)
                     {
                         if (string.Compare(TagDefaults.Wanggeyuan, notification.NextStepDefine.Tag,
                                 StringComparison.OrdinalIgnoreCase) == 0)

+ 2 - 4
src/Hotline.Application/OrderApp/OrderApplication.cs

@@ -5105,10 +5105,8 @@ public class OrderApplication : IOrderApplication, IScopeDependency
         //);
 
         //随手拍
-        bool.TryParse(
-            _systemSettingCacheManager.GetSetting(SettingConstants.Snapshot)?.SettingValue[0],
-            out bool isSnapshotEnable);
-        if (isSnapshotEnable && !string.IsNullOrEmpty(dto.IndustryId))
+
+        if (_systemSettingCacheManager.Snapshot && !string.IsNullOrEmpty(dto.IndustryId))
         {
             query.Where(d => d.OrderSnapshot.IndustryId == dto.IndustryId);
         }

+ 4 - 3
src/Hotline.WeChat/ServiceCollectionExtensions.cs

@@ -15,16 +15,17 @@ using Microsoft.Extensions.Options;
 using Senparc.CO2NET;
 using Senparc.Weixin;
 using Senparc.Weixin.Entities;
+using XF.Domain.Options;
 
 namespace Hotline.WeChat;
 public static class ServiceCollectionExtensions
 {
-    private readonly static string Name = "SenparcWeixinSetting";
     private readonly static string KeyName = "WxOpenAppId";
     public static IServiceCollection AddWeChatService(this IServiceCollection services, ConfigurationManager configuration)
     {
-        var config = configuration.GetSection(Name);
+        var config = configuration.GetSection(nameof(SenparcWeixinSetting));
         if (config.GetSection(KeyName).Value == null) return services;
+        services.Configure<Configurations.SenparcWeixinSetting>(d => configuration.GetSection(nameof(SenparcWeixinSetting)).Bind(d));
         services.AddMemoryCache();
         services.AddSenparcWeixin(configuration);
         return services;
@@ -32,7 +33,7 @@ public static class ServiceCollectionExtensions
 
     public static void UseWeChat(this WebApplication app)
     {
-        if (app.Configuration.GetSection(Name).GetSection(KeyName).Value == null) return;
+        if (app.Configuration.GetSection(nameof(SenparcWeixinSetting)).GetSection(KeyName).Value == null) return;
         //var c = app.Configuration.GetSection("Cache");
         //var redisConfigurationStr = $"{c.GetSection("Host").Value}:{c.GetSection("Port").Value},password={c.GetSection("Password").Value},connectTimeout=1000,connectRetry=2,syncTimeout=10000,defaultDatabase={c.GetSection("Database").Value}";
         //app.UseSenparcGlobal(app.Environment, null, globalRegister =>

+ 7 - 4
src/Hotline/Caching/Services/SystemSettingCacheManager.cs

@@ -1,9 +1,12 @@
 using Hotline.Caching.Interfaces;
+using Hotline.Configurations;
 using Hotline.Settings;
 using Hotline.Share.Tools;
 using Hotline.ThirdAccountDomainServices.Interfaces;
+using Microsoft.Extensions.Configuration;
 using Microsoft.Extensions.DependencyInjection;
 using Microsoft.Extensions.Logging;
+using Microsoft.Extensions.Options;
 using Newtonsoft.Json.Linq;
 using System.Reflection.Metadata.Ecma335;
 using XF.Domain.Cache;
@@ -19,14 +22,14 @@ namespace Hotline.Caching.Services
         private readonly ILogger<SystemSettingCacheManager> _logger;
         private readonly ITypedCache<SystemSetting> _cacheSystemSetting;
         private readonly IRepository<SystemSetting> _systemSettingRepository;
-        private readonly IServiceProvider _serviceProvider;
+        private readonly IOptionsSnapshot<SenparcWeixinSetting> _senparcWeixin;
 
-        public SystemSettingCacheManager(ITypedCache<SystemSetting> cacheSystemSetting, IRepository<SystemSetting> systemSettingRepository, ILogger<SystemSettingCacheManager> logger, IServiceProvider serviceProvider)
+        public SystemSettingCacheManager(ITypedCache<SystemSetting> cacheSystemSetting, IRepository<SystemSetting> systemSettingRepository, ILogger<SystemSettingCacheManager> logger, IOptionsSnapshot<SenparcWeixinSetting> senparcWeixin)
         {
             _cacheSystemSetting = cacheSystemSetting;
             _systemSettingRepository = systemSettingRepository;
             _logger = logger;
-            _serviceProvider = serviceProvider;
+            _senparcWeixin = senparcWeixin;
         }
 
         public SystemSetting? GetSetting(string code)
@@ -213,7 +216,7 @@ namespace Hotline.Caching.Services
             get
             {
                 var switchBtn = GetOrDefault("08dd0eca-66b8-4c98-8dec-0c76c29d77e3", SettingConstants.Snapshot, "随手拍功能开关", false, "随手拍功能开关");
-                if (_serviceProvider.GetService<IThirdIdentiyService>() == null) return false;
+                if (_senparcWeixin.Value.WxOpenAppId == null) return false;
                 return switchBtn;
             }
         }

+ 12 - 0
src/Hotline/Configurations/SenparcWeixinSetting.cs

@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Hotline.Configurations;
+
+public class SenparcWeixinSetting
+{
+    public string WxOpenAppId { get; set; }
+}