config.go 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. package utils
  2. import (
  3. "fmt"
  4. beeLogger "github.com/beego/bee/v2/logger"
  5. "github.com/beego/beego/v2/server/web"
  6. "github.com/rdlucklib/rdluck_tools/cache"
  7. "strconv"
  8. )
  9. var (
  10. RunMode string //运行模式
  11. MYSQL_URL string //数据库连接
  12. MYSQL_URL_RDDP string //数据库连接
  13. MYSQL_URL_EDB string
  14. MYSQL_URL_DATA string
  15. MYSQL_URL_GL string
  16. MYSQL_LOG_URL string
  17. MYSQL_WEEKLY_URL string //用户主库
  18. MYSQL_AI_URL string //ETA-AI 数据库
  19. REDIS_CACHE string //缓存地址
  20. Rc *cache.Cache //redis缓存
  21. Re error //redis错误
  22. )
  23. // 基础配置
  24. var (
  25. STATIC_DIR string
  26. DesKey string // 接口返回加密KEY
  27. APPNAME string //项目中文名称
  28. EmailSendToUsers string // 邮件提醒人员
  29. JhGnAppKey string // 聚合短信,国内AppKey
  30. JhGjAppKey string // 聚合短信,国际AppKey
  31. )
  32. // ES配置
  33. var (
  34. ES_URL string // ES服务器地址
  35. ES_USERNAME string // ES账号
  36. ES_PASSWORD string // ES密码
  37. )
  38. // 公共api内部服务调用
  39. var (
  40. // EDB_LIB_URL 公共指标库
  41. EDB_LIB_URL string
  42. APP_EDB_LIB_NAME_EN string
  43. EDB_LIB_Md5_KEY string
  44. // PublicChartHost 公共图库的host
  45. PublicChartHost string
  46. // MySteelPostUrl 钢联化工的服务地址
  47. MySteelPostUrl string
  48. // SendWxTemplateMsgUrl 模板消息推送
  49. SendWxTemplateMsgUrl string
  50. // SendTemplateMsgAuthorization 模板推送秘钥
  51. SendTemplateMsgAuthorization string
  52. // HandleVideoDecibelUrl 处理音频分贝的url
  53. HandleVideoDecibelUrl string
  54. // Ppt2ImageUrl ppt转图片服务的地址
  55. Ppt2ImageUrl string
  56. // HongzeOpenApiHost 开放openapi的地址
  57. HongzeOpenApiHost string
  58. // EnglishShareUrl 英文研报群发邮件分享地址
  59. EnglishShareUrl string
  60. // EnPolicyReportUrl 英文策略报告
  61. EnPolicyReportUrl string
  62. // GoogleTranslateUrl 谷歌翻译服务
  63. GoogleTranslateUrl string
  64. // AlarmMsgUrl 报警服务地址
  65. AlarmMsgUrl string
  66. // ChatUrl chatGPT服务地址
  67. ChatUrl string
  68. EtaBridgeUrl string // 桥接服务地址
  69. EtaBridgeAppNameEn string // 桥接服务英文名称-鉴权用
  70. EtaBridgeMd5Key string // 桥接服务Md5密钥-鉴权用
  71. EtaBridgeDesKey string // 桥接服务Des密钥-解密数据用
  72. )
  73. // 微信配置信息
  74. var (
  75. WxId string //微信原始ID
  76. WxAppId string // 公众号appid
  77. WxAppSecret string // 公众号秘钥
  78. TemplateIdByProduct string //产品运行报告通知-模板ID
  79. WxYbAppId string // 研报小程序appid
  80. WxYbId string // 研报小程序微信原始ID
  81. WxYbAppSecret string // 研报小程序秘钥
  82. WxYbPlatform int //弘则研报来源
  83. )
  84. // ES索引配置
  85. var (
  86. DATA_INDEX_NAME string //数据指标库索引
  87. CHART_INDEX_NAME string //研究图库索引
  88. EsReportIndexName string //研报ES索引
  89. EsEnglishReportIndexName string //英文研报ES索引
  90. MY_CHART_INDEX_NAME string //研究图库(MY ETA)索引
  91. EsSemanticAnalysisDocIndexName string //ES语义分析文档索引名
  92. SmartReportIndexName string //智能研报ES索引
  93. )
  94. var (
  95. XfHostUrl string // 科大讯飞--语音合成
  96. )
  97. // 对象存储客户端
  98. var (
  99. ObjectStorageClient string // 目前有oss minio,默认oss
  100. )
  101. // 阿里云配置
  102. var (
  103. Bucketname string
  104. Endpoint string
  105. Imghost string
  106. UploadDir string
  107. Upload_Audio_Dir string
  108. AccessKeyId string
  109. AccessKeySecret string
  110. )
  111. // 阿里云oss前端上传用
  112. var (
  113. AliStsScheme string
  114. RegionId string
  115. RoleArn string
  116. RoleSessionName string
  117. RAMAccessKeyId string
  118. RAMAccessKeySecret string
  119. STSTokenCacheKey string
  120. )
  121. // 阿里云邮箱配置
  122. var (
  123. AliyunEmailAccountName string
  124. AliyunEmailAccessKeyId string
  125. AliyunEmailAccessKeySecret string
  126. AliyunEmailReplyAddress string
  127. AliyunEmailReplyAddressAlias string
  128. )
  129. // 腾讯云邮箱配置
  130. var (
  131. TencentSDKSecretId string // 腾讯云主账号SecretId
  132. TencentSDKSecretKey string // 腾讯云主账号SecretKey
  133. TencentEmailFromEmailAddress string // 腾讯云邮件发信地址
  134. TencentEmailTemplateID uint64 // 云邮件模板ID
  135. )
  136. // LibreOfficePath LibreOfficePath的地址
  137. var LibreOfficePath string
  138. // CrmEtaServerUrl CRM-ETA服务地址
  139. var (
  140. CrmEtaServerUrl string
  141. CrmEtaServerDes3Key string
  142. )
  143. // BusinessCode 商家编码
  144. var BusinessCode string
  145. // 日志配置
  146. var (
  147. LogPath string //调用过程中的日志存放地址
  148. LogFile string
  149. LogDataPath string //调用过程中图表相关的日志存放地址
  150. LogDataFile string
  151. BinLogPath string //数据库相关的日志存放地址
  152. BinLogFile string
  153. ApiLogPath string //接口请求地址和接口返回值日志存放地址
  154. ApiLogFile string
  155. LogMaxDays int //日志最大保留天数
  156. )
  157. // MinIo配置
  158. var (
  159. MinIoBucketname string
  160. MinIoEndpoint string
  161. MinIoImghost string
  162. MinIoUploadDir string
  163. MinIoUpload_Audio_Dir string
  164. MinIoAccessKeyId string
  165. MinIoAccessKeySecret string
  166. MinIoUseSSL string
  167. MinIoPort string
  168. MinIoRegion string
  169. )
  170. // PythonUrlReport2Img 生成长图服务地址
  171. var PythonUrlReport2Img string
  172. // ETA-AI服务
  173. var EtaAiUrl string
  174. var (
  175. EtaAppid string
  176. EtaSecret string
  177. )
  178. // S3配置
  179. var (
  180. S3Endpoint string
  181. S3BackEndpoint string
  182. S3BucketName string
  183. S3UploadDir string
  184. S3AccessKeyId string
  185. S3AccessKeySecret string
  186. S3Host string
  187. S3Region string
  188. S3ForceStyle string
  189. S3EndpointPort string
  190. S3Protocol string
  191. S3DisableSSL string
  192. S3OpenAcl string
  193. )
  194. func init() {
  195. tmpRunMode, err := web.AppConfig.String("run_mode")
  196. if err != nil {
  197. panic(any("配置文件读取run_mode错误 " + err.Error()))
  198. }
  199. RunMode = tmpRunMode
  200. fmt.Println("RunMode:", RunMode)
  201. if RunMode == "" {
  202. localIp, err := GetLocalIP()
  203. fmt.Println("localIp:", localIp)
  204. if localIp == "10.0.0.123" {
  205. RunMode = "debug"
  206. } else {
  207. RunMode = "release"
  208. }
  209. fmt.Println("RunMode:", RunMode)
  210. configPath := `/home/code/config/eta_api/conf/app.conf`
  211. fmt.Println("configPath:", configPath)
  212. err = web.LoadAppConfig("ini", configPath)
  213. if err != nil {
  214. fmt.Println("web.LoadAppConfig Err:" + err.Error())
  215. }
  216. }
  217. config, err := web.AppConfig.GetSection(RunMode)
  218. if err != nil {
  219. panic(any("配置文件读取错误 " + err.Error()))
  220. }
  221. beeLogger.Log.Info(RunMode + " 模式")
  222. MYSQL_URL = config["mysql_url"]
  223. MYSQL_URL_RDDP = config["mysql_url_rddp"]
  224. MYSQL_URL_EDB = config["mysql_url_edb"]
  225. MYSQL_URL_DATA = config["mysql_url_data"]
  226. MYSQL_URL_GL = config["mysql_url_gl"]
  227. MYSQL_LOG_URL = config["mysql_url_log"]
  228. // 用户主库
  229. MYSQL_WEEKLY_URL = config["mysql_url_weekly"]
  230. // 用户主库
  231. MYSQL_WEEKLY_URL = config["mysql_url_weekly"]
  232. //ETA-AI
  233. MYSQL_AI_URL = config["mysql_url_ai"]
  234. REDIS_CACHE = config["beego_cache"]
  235. if len(REDIS_CACHE) <= 0 {
  236. panic(any("redis链接参数没有配置"))
  237. }
  238. Rc, Re = cache.NewCache(REDIS_CACHE) //初始化缓存
  239. if Re != nil {
  240. fmt.Println("redis链接异常:", Re)
  241. panic(any(Re))
  242. }
  243. // 项目中文名称
  244. appNameCn, err := web.AppConfig.String("app_name_cn")
  245. if err != nil {
  246. panic(any("配置文件读取app_name_cn错误 " + err.Error()))
  247. }
  248. APPNAME = appNameCn
  249. // 初始化内部服务配置
  250. // 接口返回加密KEY
  251. DesKey = config["des_key"]
  252. // 邮件提醒人员
  253. EmailSendToUsers = config["email_send_to_users"]
  254. // 聚合短信,国内AppKey
  255. JhGnAppKey = config["jh_gn_app_key"]
  256. JhGjAppKey = config["jh_gj_app_key"]
  257. // ppt 转图片服务地址
  258. Ppt2ImageUrl = config["ppt2_image_url"]
  259. // 静态文件目录
  260. STATIC_DIR = config["static_dir"]
  261. // 系统内部服务地址
  262. {
  263. // 公共指标库相关
  264. EDB_LIB_URL = config["edb_lib_url"]
  265. APP_EDB_LIB_NAME_EN = config["app_edb_lib_name_en"]
  266. EDB_LIB_Md5_KEY = config["edb_lib_md5_key"]
  267. // 图表项目域名
  268. PublicChartHost = config["public_chart_host"]
  269. // 钢联化工服务地址
  270. MySteelPostUrl = config["mysteel_post_url"]
  271. // 发送微信模板消息地址
  272. SendWxTemplateMsgUrl = config["send_wx_template_msg_url"]
  273. // 发送微信模板消息地址
  274. SendTemplateMsgAuthorization = config["send_template_msg_authorization"]
  275. // 语音分贝处理的地址
  276. HandleVideoDecibelUrl = config["handle_video_decibel_url"]
  277. // 弘则open api的地址
  278. HongzeOpenApiHost = config["hongze_open_api_host"]
  279. // 英文研报分享的地址
  280. EnglishShareUrl = config["english_share_url"]
  281. // 策略报告地址
  282. EnPolicyReportUrl = config["en_policy_report_url"]
  283. // 谷歌翻译服务地址
  284. GoogleTranslateUrl = config["google_translate_url"]
  285. // 报警服务地址
  286. AlarmMsgUrl = config["alarm_msg_url"]
  287. // chatGPT服务地址
  288. ChatUrl = config["chat_url"]
  289. EtaBridgeUrl = config["eta_bridge_url"] // 桥接服务地址
  290. EtaBridgeAppNameEn = config["eta_bridge_app_name_en"] // 桥接服务英文名称-鉴权用
  291. EtaBridgeMd5Key = config["eta_bridge_md5_key"] // 桥接服务Md5密钥-鉴权用
  292. EtaBridgeDesKey = config["eta_bridge_des_key"] // 桥接服务Des密钥-解密数据用
  293. }
  294. //日志配置
  295. {
  296. LogPath = config["log_path"]
  297. LogFile = config["log_file"]
  298. LogDataPath = config["log_data_path"]
  299. LogDataFile = config["log_data_file"]
  300. BinLogPath = config["binlog_path"]
  301. BinLogFile = config["binlog_file"]
  302. ApiLogPath = config["apilog_path"]
  303. ApiLogFile = config["apilog_file"]
  304. logMaxDaysStr := config["log_max_day"]
  305. LogMaxDays, _ = strconv.Atoi(logMaxDaysStr)
  306. }
  307. // ES配置
  308. {
  309. ES_URL = config["es_url"]
  310. ES_USERNAME = config["es_username"]
  311. ES_PASSWORD = config["es_password"]
  312. }
  313. // 微信相关
  314. {
  315. WxAppId = config["wx_appid"]
  316. WxAppSecret = config["wx_app_secret"]
  317. WxId = config["wx_id"]
  318. //模板消息
  319. TemplateIdByProduct = config["template_id_by_product"]
  320. WxYbAppId = config["wx_yb_appid"] //弘则研报小程序
  321. WxYbId = config["wx_yb_id"] // 研报小程序微信原始ID
  322. WxYbAppSecret = config["wx_yb_app_secret"] // 研报小程序秘钥
  323. wxYbPlatformStr := config["wx_yb_platform"]
  324. if wxYbPlatformStr != `` {
  325. WxYbPlatform, err = strconv.Atoi(wxYbPlatformStr) //弘则研报来源
  326. if err != nil {
  327. panic(any("配置文件读取wx_yb_platform错误 " + err.Error()))
  328. }
  329. }
  330. }
  331. // 对象存储客户端
  332. ObjectStorageClient = config["object_storage_client"]
  333. // OSS相关
  334. {
  335. Endpoint = config["endpoint"]
  336. Bucketname = config["bucket_name"]
  337. Imghost = config["img_host"]
  338. UploadDir = config["upload_dir"]
  339. Upload_Audio_Dir = config["upload_audio_dir"]
  340. AccessKeyId = config["access_key_id"]
  341. AccessKeySecret = config["access_key_secret"]
  342. }
  343. // OSS相关(前端使用)
  344. {
  345. AliStsScheme = config["ali_sts_scheme"]
  346. RegionId = config["region_id"]
  347. RoleArn = config["role_arn"]
  348. RoleSessionName = config["role_session_name"]
  349. RAMAccessKeyId = config["ram_access_key_id"]
  350. RAMAccessKeySecret = config["ram_access_key_secret"]
  351. STSTokenCacheKey = config["sts_token_cache_key"]
  352. }
  353. // 阿里云邮箱配置
  354. {
  355. AliyunEmailAccountName = config["aliyun_email_account_name"]
  356. AliyunEmailAccessKeyId = config["aliyun_email_access_key_id"]
  357. AliyunEmailAccessKeySecret = config["aliyun_email_access_key_secret"]
  358. AliyunEmailReplyAddress = config["aliyun_email_reply_address"]
  359. AliyunEmailReplyAddressAlias = config["aliyun_email_reply_address_alias"]
  360. }
  361. // 腾讯云邮箱配置
  362. {
  363. TencentSDKSecretId = config["tencent_sdk_secret_id"] // 腾讯云主账号SecretId
  364. TencentSDKSecretKey = config["tencent_sdk_secret_key"] // 腾讯云主账号SecretKey
  365. TencentEmailFromEmailAddress = config["tencent_email_from_email_address"] // 腾讯云邮件发信地址
  366. tencentEmailTemplateIDtr := config["tencent_email_template_id"]
  367. if tencentEmailTemplateIDtr != `` {
  368. tmpTencentEmailTemplateID, err := strconv.Atoi(tencentEmailTemplateIDtr) //弘则研报来源
  369. if err != nil {
  370. panic(any("配置文件读取tencent_email_template_id错误 " + err.Error()))
  371. }
  372. TencentEmailTemplateID = uint64(tmpTencentEmailTemplateID)
  373. }
  374. }
  375. // 科大讯飞
  376. {
  377. //XfAPPID = config["xf_appid"]
  378. //XfAPIKey = config["xf_api_key"]
  379. //XfAPISecret = config["xf_api_secret"]
  380. XfHostUrl = config["xf_host_url"]
  381. //XfOrigin = config["xf_origin"]
  382. //XfVcn = config["xf_vcn"]
  383. }
  384. // ES 索引
  385. {
  386. DATA_INDEX_NAME = config["data_index_name"]
  387. CHART_INDEX_NAME = config["chart_index_name"]
  388. MY_CHART_INDEX_NAME = config["my_chart_index_name"]
  389. EsReportIndexName = config["es_report_index_name"]
  390. EsEnglishReportIndexName = config["es_english_report_index_name"]
  391. EsSemanticAnalysisDocIndexName = config["es_semantic_analysis_doc_index_name"]
  392. SmartReportIndexName = config["es_smart_report_index_name"]
  393. }
  394. CrmEtaServerUrl = config["crm_eta_server_url"]
  395. CrmEtaServerDes3Key = config["crm_eta_server_des3_key"]
  396. LibreOfficePath = config["libre_office_path"]
  397. // 商家编码
  398. BusinessCode = config["business_code"]
  399. // MinIo相关
  400. {
  401. MinIoEndpoint = config["minio_endpoint"]
  402. MinIoBucketname = config["minio_bucket_name"]
  403. MinIoImghost = config["minio_img_host"]
  404. MinIoUploadDir = config["minio_upload_dir"]
  405. MinIoUpload_Audio_Dir = config["minio_upload_audio_dir"]
  406. MinIoAccessKeyId = config["minio_access_key_id"]
  407. MinIoAccessKeySecret = config["minio_access_key_secret"]
  408. MinIoUseSSL = config["minio_use_ssl"]
  409. MinIoPort = config["minio_port"]
  410. MinIoRegion = config["minio_region"]
  411. }
  412. // S3-OSS相关
  413. {
  414. S3Endpoint = config["s3_endpoint"]
  415. S3BackEndpoint = config["s3_back_endpoint"]
  416. S3BucketName = config["s3_bucket_name"]
  417. S3Host = config["s3_host"]
  418. S3AccessKeyId = config["s3_access_key_id"]
  419. S3AccessKeySecret = config["s3_access_key_secret"]
  420. S3UploadDir = config["s3_upload_dir"]
  421. S3Region = config["s3_region"]
  422. S3ForceStyle = config["s3_force_style"]
  423. S3EndpointPort = config["s3_endpoint_port"]
  424. S3Protocol = config["s3_protocol"]
  425. S3DisableSSL = config["s3_disable_ssl"]
  426. S3OpenAcl = config["s3_open_acl"]
  427. }
  428. // 生成长图服务地址
  429. PythonUrlReport2Img = config["python_url_report2img"]
  430. EtaAiUrl = config["eta_ai_url"]
  431. EtaAppid = config["eta_appid"]
  432. EtaSecret = config["eta_secret"]
  433. // 初始化ES
  434. initEs()
  435. }