config.go 14 KB

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