config.go 14 KB

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