config.go 17 KB

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