using Dapper; using JiaZhiQuan.Common.ClassEnum; using MathNet.Numerics.Statistics.Mcmc; using Microsoft.Extensions.Logging; using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Linq; using Wicture.DbRESTFul.Infrastructure.Repository; namespace JiaZhiQuan.Common.Config { public class ConfigFromDb { private readonly IConnectionManager _connectionManager; private readonly ILogger _logger; /// /// 主分类 /// public static List> PrimaryTypes { get; set; } = new List>(); /// /// 在App展示的主分类 /// public static List> PrimaryTypesVisibleInApp { get; set; } = new List>(); /// /// 在App展示的主分类(仅用于审核) /// public static List> PrimaryTypesVisibleInAppPreview { get; set; } = new List>(); /// /// APP 版本Preview配置,配置之后,接口会返回用于审核的测试数据。数据格式为“channel,os_version” /// public static List AppPreviewTypeList { get; set; } = new List(); /// /// 资源所属的市场 /// public static List> ResourceMarkets { get; set; } = new List>() { new KeyValuePair(1, "A股"), new KeyValuePair(2, "港股"), new KeyValuePair(4, "美股") }; /// /// 社区 /// public static List AppIndexCusTabList = new List(); /// /// 商城 /// public static List MallAppIndexCusTabList = new List(); /// /// 不同天数的随机概率,2~15天 /// public static List> RandomProbabilities = new List> { new List{67, 33 }, new List{50, 33, 17 }, new List{40, 30, 20, 10 }, new List{35, 26, 20, 13, 6 }, new List{31, 23, 19, 14, 9, 4 }, new List{28, 21, 17, 14, 10, 7, 3 }, new List{26, 19, 16, 13, 11, 8, 5, 2 }, new List{24, 17, 15, 13, 11, 8, 6, 4, 2 }, new List{23, 16, 14, 12, 10, 9, 7, 5, 3, 1 }, new List{20, 15, 13, 12, 10, 9, 7, 6, 4, 3, 1 }, new List{21, 14, 12, 11, 10, 8, 7, 6, 5, 3, 2, 1 }, new List{20, 13, 12, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 }, new List{21, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 1 }, new List{18, 11, 10, 10, 9, 8, 7, 6, 5, 5, 4, 3, 2, 1, 1 }, }; public ConfigFromDb(IConnectionManager manager, ILoggerFactory loggerFactory) { _connectionManager = manager; _logger = loggerFactory.CreateLogger("DbRESTFul"); try { Resolve(); } catch (Exception ex) { _logger.LogError(ex, "ConfigFromDb 读取失败"); } } public ConfigFromDb Resolve() { using (var conn = _connectionManager.GetConnection()) { conn.Open(); InitModel(SqlMapper.Query(conn, "select * from s_config")); // 初始化主分类 var types = SqlMapper.Query(conn, "select id, name, hiddenInApp, previewable from s_types_main where state<>-1 order by displayOrder desc"); PrimaryTypes = types.Select(e => new KeyValuePair(e.id, e.name)).ToList(); PrimaryTypesVisibleInApp = types.Where(e => e.hiddenInApp == 0).Select(e => new KeyValuePair(e.id, e.name)).ToList(); PrimaryTypesVisibleInAppPreview = types.Where(e => e.hiddenInApp == 0 && e.previewable > 0).Select(e => new KeyValuePair(e.id, e.name)).ToList(); AppPreviewTypeList = SqlMapper.Query(conn, "select channel, version from s_app_preview").Select(e => (e.channel + "," + e.version) as string).ToList(); var custab= SqlMapper.Query(conn, "select category,type, label, activeImg, deactiveImg, data from n_app_index_custab where state=0") .ToList(); //社区 AppIndexCusTabList = custab.Where(x => x.category == AppIndexTabEnum.COMMUNITY.category).ToList(); //商品 MallAppIndexCusTabList = custab.Where(x => x.category == AppIndexTabEnum.MALL.category).ToList(); } return this; } public string SMSignName { get; set; } public string SMRsetMobileTemplateCode { get; set; } public string SMNormalValidationTemplateCode { get; set; } public string SMLoginTemplateCode { get; set; } public string WXGZAppID { get; set; } public string WXGZAppSecret { get; set; } public string WXAppID { get; set; } public string WXAppSecret { get; set; } public string QQAppID { get; set; } public string QQAppKey { get; set; } public string WeiboAppID { get; set; } public string WeiboAppSecret { get; set; } public string AliVisionAccessKeyId { get; set; } public string AliVisionAccessSecret { get; set; } public string AliOssAccessKeyId { get; set; } public string AliOssAccessSecret { get; set; } public string AliSMAccessKeyId { get; set; } public string AliSMAccessSecret { get; set; } public string AliDytnsAccessKeyId { get; set; } public string AliDytnsAccessSecret { get; set; } public string AliVodAccessKeyId { get; set; } public string AliVodAccessSecret { get; set; } public string AliVodCallbackUrl { get; set; } public string AliVodCallbackKey { get; set; } public string AliFaceVerifyAccessKeyId { get; set; } public string AliFaceVerifyAccessSecret { get; set; } public string AliPhoneNumberAuthCode { get; set; } public string AliPhoneNumberAccessKeyId { get; set; } public string AliPhoneNumberAccessSecret { get; set; } public string AliCaptchaAccessKeyId { get; set; } public string AliCaptchaAccessKeySecret { get; set; } public int PostPublishFirst { get; set; } public string UmengAppKeyAndroid { get; set; } public string UmengAppMasterSecretAndroid { get; set; } public string UmengAppKeyIOS { get; set; } public string UmengAppMasterSecretIOS { get; set; } public string SystemAdministratorPassword { get; set; } public string PointsName { get; set; } /// /// 用户签到赠送价值币数量列表,里面包含的即为一个周期 /// public string UserSignInPointsCountList { get; set; } /// /// 用户发送请求时,参数MD5加密时的混淆串 /// public string UserRequestParameterMD5Salt { get; set; } /// /// 用户默认头像地址,逗号分隔,路径为 olscdn.olssglobal.com/common/images/member/hdi/xxxxxx /// public string DefaultUserHeadImages { get; set; } /// /// 用户个人中心默认背景地址,逗号分隔,路径为 olscdn.olssglobal.com/common/images/member/hdi/xxxxxx /// public string DefaultUserHeadBackgroundImages { get; set; } /// /// Apple第三方登录私钥 /// public string AppleSignInPrivateKey { get; set; } public string AppleTeamID { get; set; } public string AppleBundleID { get; set; } /// /// 短链地址 /// public string ShorLinkPrefix { get; set; } /// /// H5 URL地址,无Http和/。如m.olssglobal.com /// public string H5UrlAddress { get; set; } /// /// 邀请好友注册短信模板 /// public string ShareShortMessageTemplate { get; set; } /// /// 用户发动态任务获取的金币 /// public int UserPointsPublishPost { get; set; } /// /// 发动态任务能够获取金币一天最多发放的数量 /// public int UserPointsPublishPostMaxCount { get; set; } /// /// 用户评论任务获取的金币 /// public int UserPointsComment { get; set; } /// /// 评论任务能够获取金币一天最多发放的数量 /// public int UserPointsCommentMaxCount { get; set; } /// /// 用户点赞任务获取的金币 /// public int UserPointsThumbsup { get; set; } /// /// 点赞任务能够获取金币需要达到的数量 /// public int UserPointsThumbsupCount { get; set; } /// /// 用户分享任务获取的金币 /// public int UserPointsShare { get; set; } /// /// 分享任务能够获取金币需要达到的数量 /// public int UserPointsShareCount { get; set; } /// /// 用户被评论任务获取的金币 /// public int UserPointsPassiveComment { get; set; } /// /// 被评论任务能够获取金币需要达到的数量 /// public int UserPointsPassiveCommentCount { get; set; } /// /// 用户被点赞任务获取的金币 /// public int UserPointsPassiveThumbsup { get; set; } /// /// 被点赞任务能够获取金币需要达到的数量 /// public int UserPointsPassiveThumbsupCount { get; set; } /// /// 用户被分享任务获取的金币 /// public int UserPointsPassiveShare { get; set; } /// /// 被分享任务能够获取金币需要达到的数量 /// public int UserPointsPassiveShareCount { get; set; } /// /// 用户评级时,动态质量最小要达到的值,1-5 /// public int UserLevelPostMinQuality { get; set; } /// /// 客服电话 /// public string ConfigCSPhone { get; set; } /// /// 客服邮箱 /// public string ConfigCSEmail { get; set; } /// /// QQ邮件发送邮件账户 /// public string MailAccount { get; set; } /// /// QQ邮件发送邮件的授权码 /// public string MailAuthCode { get; set; } /// /// 模拟文章用户列表 /// public string MockPostUser { get; set; } /// /// 模拟评论用户列表 /// public string MockCommentUser { get; set; } /// /// 是否禁用模拟评论文本AI审核,默认未禁用 /// public int MockCommentDisableTextAiAuth { get; set; } /// /// 是否关闭文章自动点赞 /// public int MockPostAutoThumbsupDisabled { get; set; } /// /// 是否关闭用户的自动关注 /// public int MockUserAutoFocusDisabled { get; set; } /// /// 文章是否启用文本AI审核,大于0表示true, 等于0表示false /// public int EnablePostTextAiAuth { get; set; } /// /// 文章阅读统计同一用户每天最大有效阅读数量(有效阅读) /// public int PostReadStatisticMaxCountPerDayPerUser { get; set; } /// /// 文章阅读最小有效秒数 /// public int PostReadStatisticMinSecs { get; set; } /// /// 文章阅读统计同一IP针对同一笔记(未登录),最多可统计的有效次数(有效阅读) /// public int PostReadStatisticMaxCountPerDayPerIP { get; set; } /// /// 文章阅读统计同一IP针对同一笔记(未登录),最多可统计的有效次数(非有效阅读) /// public int PostReadStatisticMaxCountPerDayPerIP_Normal { get; set; } /// /// 文章分享统计同一用户每天最大有效分享数量(有效分享) /// public int PostShareStatisticMaxCountPerDayPerUser { get; set; } /// /// 文章分享统计同一用户每天最大有效分享数量(非有效分享) /// public int PostShareStatisticMaxCountPerDayPerUser_Normal { get; set; } /// /// 同一用户同一文章最大有效分享数量(有效分享) /// public int PostShareStatisticMaxCountPerDayPerUserPerPost { get; set; } /// /// 同一用户同一文章最大有效分享数量(非有效分享) /// public int PostShareStatisticMaxCountPerDayPerUserPerPost_Normal { get; set; } /// /// 每天同一用户同一作者主页访问次数(非有效次数) /// public int PersonalPageVisitMaxCountPerDayPerUser2User_Normal { get; set; } /// /// 研报百次有效阅读单价(分为单位) /// public int PostStandpointSettlementPrice { get; set; } /// /// 价格变动提醒 /// public string PostStandpointPriceChangeTip { get; set; } /// /// 视频笔记百次有效阅读单价(分为单位) /// public int PostDiaryHasVideoSettlementPrice { get; set; } /// /// 图文笔记百次有效阅读单价(分为单位) /// public int PostDiaryNoVideoSettlementPrice { get; set; } /// /// 价格变动提醒 /// public string PostDiaryPriceChangeTip { get; set; } /// /// 创作者平台统计预警发送邮箱,多个用逗号分隔 /// public string MPPostStatWarningMailTo { get; set; } /// /// 创作者平台统计预警配置,如{ diary: { read: { hours: 1, max: 5 }, thumbsup: { hours: 1, max: 5 }, share: { hours: 1, max: 5 }, totalRead: { hours: 1, max: 5 } }, standpoint: { ... } } /// public MPStatisticWarningConfig MPStatisticWarningConfig { get; set; } /// /// 文章最大推荐的天数,超过后,热度置0 /// public int PostMaxRecommendDays { get; set; } /// /// 如果配置了此日期值,文章推荐则优先使用此值,而非PostMaxRecommendDays /// public string PostStartRecommendDate { get; set; } /// /// 文章距离当前时间多少小时内忽略热度值 /// public int PostIgnoreHotRecentHours { get; set; } /// /// 文章冷却小时数,即在文章发布多久内计算冷却系数 /// public int PostCoolingPeriodHours { get; set; } /// /// 文章在冷却周期内,小于等于此值时,冷却系数为1 /// public int PostIgnoreCoolingMaxCountPerPeriod { get; set; } /// /// 用户主页默认背景图片地址 /// public string UserPersonalPageBGImage { get; set; } /// /// 提现最小金额(含),单位为分 /// public int CashoutMinAmount { get; set; } /// /// 提现最大金额(含),单位为分 /// public int CashoutMaxAmount { get; set; } /// /// 提现每个自然月提现最大次数(含) /// public int CashoutMaxTimesPerMonth { get; set; } /// /// 用户邀请海报版本 /// public int LastestInvitationPosterVersion { get; set; } /// /// 用户邀请海报生成参数 /// public InvitationPosterParams InvitationPosterParams { get; set; } /// /// 邀请激活报警参数 /// public InvitationAlarm InvitationAlarm { get; set; } /// /// 活动任务奖励兑换过期天数 /// public int ActivityRewardExchangeExpireDays { get; set; } /// /// 价值币图标URL /// public string PointsIconUrl { get; set; } /// /// 平台微信客服二维码URL /// public string WXCSQRCodeUrl { get; set; } /// /// App社区Tab顺序及默认显示配置, 如:FOCUS,RECOMMEND,IMGPOST,VIDEOPOST|RECOMMEND /// public string AppIndexPageTabConfig { get; set; } /// /// App商城Tab顺序及默认显示配置, 如:FOCUS,RECOMMEND,IMGPOST,VIDEOPOST|RECOMMEND /// public string MallAppIndexPageTabConfig { get; set; } = "FOCUS,RECOMMEND,VIDEOPOST|RECOMMEND"; /// /// App活动板块的火图标是否显示 /// public int ActivityHotIconInAppVisible { get; set; } /// /// 内容推荐中每页包含的研报数量 /// public int StandPointCountPerPageInRecommendation { get; set; } /// /// App中置顶资讯编号 /// public long AppTopNewsId { get; set; } /// /// App中热门讨论出现的位置 /// public int AppHotDiscussPosition { get; set; } /// /// App中推荐列表热门活动出现的位置,如果配置为-1表示不显示 /// public int AppHotActivityPosition { get; set; } /// /// App活跃Tick接口调用间隔(秒) /// public int AppAliveTickInterval { get; set; } = 5; /// /// App同步行为数据时间间隔(秒) /// public int AppSyncActionDataInterval { get; set; } = 30; /// /// App一次同步行为数据量最大值 /// public int AppSyncActionDataMaxSize { get; set; } = 100; /// /// VIVO商业开放平台AccessToken /// public string AdVivoAccessToken { get; set; } /// /// VIVO商业开放平台AccessToken过期时间 /// public DateTime? AdVivoAccessTokenExpireAt { get; set; } /// /// VIVO商业开放平台refreshToken /// public string AdVivoRefreshToken { get; set; } /// /// 模拟评论时间随机因子1 /// public int MockCommentRandomTimeFactor01 { get; set; } = 45; /// /// 模拟评论时间随机因子2 /// public int MockCommentRandomTimeFactor02 { get; set; } = 120; /// /// 是否显示活动历史的按钮, 0 显示, 1 不显示 /// public int AppActivityHistoryRecordsBtnVisible { get; set; } /// /// 商务邮箱 /// public string CompanyEmail { get; set; } /// /// 无效评论关键词配置,正则表达式 /// public string InvalidCommentReg { get; set; } /// /// Api中Sign检查是否禁用 /// public int ApiSignCheckingDisabled { get; set; } /// /// Api中Sign每分钟最大验证错误次数,超过此次数,则禁止访问1个小时,如果配置0,则无最大错误次数 /// public int ApiSignCheckingFailedMaxCountPerMin { get; set; } /// /// Api验签URL忽略正规 /// public string ApiSignCheckingUrlIgnoreReg { get; set; } /// /// Api验签密钥 /// public string ApiSignKey { get; set; } /// /// api加密白名单ip /// public string EncryptWhiteIPList { get; set; } /// /// 第元人民币相当于多少价值币 /// public int PointsCountPerYuan { get; set; } = 500; /// /// 支付超时时间(分钟) /// public int PaymentTimeoutMinutes { get; set; } = 10; /// /// 卖家发货超时时间(小时) /// public int MallDeliveryTimeoutHours { get; set; } = 72; /// /// 买卖双方订单评论超时时间(小时) /// public int MallOrderRatingTimeoutHours { get; set; } = 15 * 24; /// /// 买家确认收货超时间(小时) /// public int MallReceiptTimeoutHours { get; set; } = 24 * 10; /// /// 买家操作延长确认收货时间的天数 /// public int MallOrderConfirmReceiptExtendDays { get; set; } = 3; /// /// 快递鸟用户id /// public string KDNiaoEBusinessID { get; set; } /// /// 快递鸟用户apikey /// public string KDNiaoApiKey { get; set; } /// /// 于初科技代理商id /// public string YCTechAgentId { get; set; } /// /// 于初科技代理商key /// public string YCTechSignKey { get; set; } /// /// 于初科技接口host /// public string YCTechHost { get; set; } /// /// 于初科技订单结果回调接口url /// public string YCTechOrderCallBackUrl { get; set; } /// /// 于初科技平台id /// public int YCTechSupplierId { get; set; } /// /// 商品免责声明 /// public string MallGoodsDisclaimer { get; set; } public double UEActivityDisplayOrder { get; set; } /// /// 卖家超过多少天未上架,超时上架天数 /// public int UEShelveTimeout { get; set; } /// /// 平台退货,卖家自动确认收货超时时间 /// public int UESellerReceiveTimeout { get; set; } public PlatformShopConfig PlatformShopConfig { get; set; } public HuiFuCommonConfig HuiFuConfig { get; set; } public string HuiFuJspayCallbackUrl { get; set; } public string HuiFuChashCallbackUrl { get; set; } public string HuiFuOpenCallbackUrl { get; set; } public string HuiFuRefundCallbackUrl { get; set; } public string HuiFuYuEPayCallbackUrl { get; set; } public string RongYunIMAppKey { get; set; } public string RongYunIMAppSecret { get; set; } /// /// 融云IM分配的客服编号列表,逗号分隔 /// public string RongCloudIMCSIdList { get; set; } /// /// config 为从数据库查询出来的数据集合 /// /// public void InitModel(dynamic configs) { var props = GetType().GetProperties(); foreach (var config in configs) { if (string.IsNullOrEmpty(config.value)) continue; var prop = props.FirstOrDefault(e => e.Name.Equals(config.key)); if (prop != null) { if (prop.PropertyType == typeof(int)) { prop.SetValue(this, int.Parse(config.value)); } if (prop.PropertyType == typeof(long)) { prop.SetValue(this, long.Parse(config.value)); } else if (prop.PropertyType == typeof(string)) { prop.SetValue(this, config.value); } else if (prop.PropertyType == typeof(float)) { prop.SetValue(this, float.Parse(config.value)); } else if (prop.PropertyType == typeof(double)) { prop.SetValue(this, double.Parse(config.value)); } else if (prop.PropertyType == typeof(DateTime) || prop.PropertyType == typeof(DateTime?)) { prop.SetValue(this, DateTime.Parse(config.value)); } else if (typeof(IConfigFromDbJsonModel).IsAssignableFrom(prop.PropertyType)) { var value = (string)config.value; if (!string.IsNullOrEmpty(value)) { prop.SetValue(this, JsonConvert.DeserializeObject(value, prop.PropertyType)); } } } } } } }