config.go 13 KB

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