config.go 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. package utils
  2. import (
  3. "fmt"
  4. "strconv"
  5. "time"
  6. beeLogger "github.com/beego/bee/v2/logger"
  7. "github.com/beego/beego/v2/server/web"
  8. "github.com/patrickmn/go-cache"
  9. )
  10. var (
  11. RunMode string //运行模式
  12. )
  13. // 公共api内部服务调用
  14. var (
  15. // EDB_LIB_URL 公共指标库
  16. EDB_LIB_URL string
  17. APP_EDB_LIB_NAME_EN string
  18. EDB_LIB_Md5_KEY string
  19. OpUserId int // 操作人id
  20. OpUserRealName string // 操作人真实名称
  21. )
  22. // 弘则
  23. const (
  24. APPID = "SJCrpOPvagscPxEv"
  25. SECRET = "gLLjT72uFHQZEFtaFCuoZegD1z2ezfyX"
  26. )
  27. // 日志配置
  28. var (
  29. LogPath string //调用过程中的日志存放地址
  30. LogFile string
  31. BinLogPath string //数据库相关的日志存放地址
  32. BinLogFile string
  33. LogMaxDays int //日志最大保留天数
  34. )
  35. // 涌益生猪
  36. var (
  37. YongyiFilePath string //excel文件地址
  38. YongyiReadFilePath string //已读的excel文件地址
  39. YongyiOpen string //是否配置涌益生猪数据源,1已配置
  40. YongyiDownloadHost string
  41. )
  42. // 中国煤炭网
  43. var (
  44. CoalMineFilePath string //excel文件地址
  45. CoalMineOpen string //是否配置中国煤炭网数据源,1已配置
  46. CoalMailAttachmentScriptPath string // 获取邮件附件的脚本目录
  47. CoalMailAttachmentOpen string // 获取邮件附件功能,1已配置
  48. CoalMailAttachmentTime string // 获取邮件附件功能时间
  49. CoalMailAttachmentPythonVersion string // 获取邮件附件功能python版本
  50. )
  51. // 汾渭煤炭
  52. var (
  53. FenweiFileDir string // excel文件目录
  54. FenweiOldFileDir string // 已读取过的excel文件目录
  55. FenweiOpen string // 是否配置汾渭数据源
  56. FenweiNetOpen string // 是否配置汾渭网页数据源
  57. FenweiNetUseName string // 汾渭登录账号
  58. FenweiNetPassword string // 汾渭登录密码
  59. FenweiNetJsonPath string // 汾渭json文件地址
  60. )
  61. // 煤炭江湖
  62. var (
  63. MtjhFilePath string //excel文件地址
  64. MtjhOpen string //是否配置煤炭江湖数据源,1已配置
  65. )
  66. // 粮油商务网
  67. var (
  68. LY_USERNAME string
  69. LY_PASSWORD string
  70. LY_JSON_PATH string
  71. LY_OPEN string
  72. )
  73. // 睿姿得数据
  74. var (
  75. RZD_TASK_TIME string
  76. RZD_USERNAME string
  77. RZD_PASSWORD string
  78. RZD_EXCEL_PATH string
  79. RZD_OPEN string
  80. RZD_DOWNLOAD_PATH string
  81. RZD_LOGIN_PATH string
  82. )
  83. // CCF化纤信息
  84. var (
  85. CCFOpen string // 是否配置CCF
  86. CCFCookieFile string // CCF登录Cookie
  87. CCFDataRuleFile string // CCF数据爬取规则
  88. CCFDailyTaskTime string // CCF数据日度任务时间
  89. CCFWeeklyTaskTime string // CCF数据周度任务时间
  90. CCFStockTaskTime string // CCF数据装置任务时间
  91. CCFUseName string // CCF登录账号
  92. CCFPassword string // CCF登录密码
  93. CCFDailyFetchNum int // CCF数据日度每次获取报告数量
  94. CCFWeeklyFetchNum int // CCF数据周度每次获取报告数量
  95. CCFStockFetchNum int // CCF数据装置每次获取报告数量
  96. CCFChartRuleFile string // CCF图表爬取规则
  97. CCFChartAdditionRuleFile string // CCF图表爬取附加规则
  98. CCFChartTaskTime string
  99. )
  100. var (
  101. OilchemAccount string
  102. OilchemPassword string
  103. OilchemCookieFile string
  104. OilchemOpen string
  105. OilchemDataInit string
  106. )
  107. var (
  108. HisugarAccount string
  109. HisugarPassword string
  110. HisugarOpen string
  111. )
  112. var TerminalCode string
  113. // 克拉克森
  114. var (
  115. ClarkSonsFilePath string //excel文件地址
  116. ClarkSonsOpen string //是否配置克拉克森数据源,1已配置
  117. )
  118. // minio配置
  119. var (
  120. MinIoAccessKeyId string
  121. MinIoAccessKeySecret string
  122. MinIoEndpoint string
  123. MinIoUseSSL string
  124. MinIoBucketName string
  125. MinIoUploadDir string
  126. MinIoViewHost string
  127. ChromePath string
  128. CommandPython string
  129. OssType string
  130. )
  131. // S3配置
  132. var (
  133. S3Endpoint string
  134. S3BackEndpoint string
  135. S3BucketName string
  136. S3UploadDir string
  137. S3AccessKeyId string
  138. S3AccessKeySecret string
  139. S3Host string
  140. S3Region string
  141. S3ForceStyle string
  142. S3EndpointPort string
  143. S3Protocol string
  144. S3DisableSSL string
  145. S3OpenAcl string
  146. )
  147. // 阿里云配置
  148. var (
  149. Bucketname string
  150. Endpoint string
  151. Imghost string
  152. UploadDir string
  153. Upload_Audio_Dir string
  154. AccessKeyId string
  155. AccessKeySecret string
  156. )
  157. // Kpler
  158. var (
  159. KplerExcelFilePath string //excel文件地址
  160. KplerExcelOpen string //是否配置Kpler数据源,1已配置
  161. KplerRefreshUrl string //Kpler刷新url
  162. KplerApiAccount string //Kpler API调用方式的账号
  163. KplerApiPassword string //Kpler API调用方式的密码
  164. )
  165. var (
  166. CacheClient *cache.Cache
  167. )
  168. func init() {
  169. tmpRunMode, err := web.AppConfig.String("run_mode")
  170. if err != nil {
  171. panic("配置文件读取run_mode错误 " + err.Error())
  172. }
  173. RunMode = tmpRunMode
  174. fmt.Println("RunMode:", RunMode)
  175. config, err := web.AppConfig.GetSection(RunMode)
  176. if err != nil {
  177. panic("配置文件读取错误 " + err.Error())
  178. }
  179. beeLogger.Log.Info(RunMode + " 模式")
  180. // 公共api内部服务调用
  181. {
  182. // 公共指标库相关
  183. EDB_LIB_URL = config["edb_lib_url"]
  184. APP_EDB_LIB_NAME_EN = config["app_edb_lib_name_en"]
  185. EDB_LIB_Md5_KEY = config["edb_lib_md5_key"]
  186. opUserIdStr := config["op_user_id"]
  187. if opUserIdStr != `` {
  188. OpUserId, err = strconv.Atoi(opUserIdStr)
  189. if err != nil {
  190. panic("配置文件中操作人配置错误 " + err.Error())
  191. }
  192. }
  193. OpUserRealName = config["op_user_real_name"]
  194. }
  195. //日志配置
  196. {
  197. LogPath = config["log_path"]
  198. LogFile = config["log_file"]
  199. BinLogPath = config["binlog_path"]
  200. BinLogFile = config["binlog_file"]
  201. logMaxDaysStr := config["log_max_day"]
  202. LogMaxDays, _ = strconv.Atoi(logMaxDaysStr)
  203. }
  204. //涌益咨询文件夹配置
  205. {
  206. YongyiFilePath = config["yongyi_file_path"]
  207. YongyiReadFilePath = config["yongyi_read_file_path"]
  208. YongyiOpen = config["yongyi_open"]
  209. YongyiDownloadHost = config["yongyi_download_host"]
  210. if YongyiDownloadHost == "" {
  211. YongyiDownloadHost = "http://127.0.0.1:7010/"
  212. }
  213. }
  214. //中国煤炭网文件夹配置
  215. {
  216. CoalMineFilePath = config["coal_mine_file_path"]
  217. CoalMineOpen = config["coal_mine_open"]
  218. CoalMailAttachmentScriptPath = config["coal_mail_attachment_script_path"]
  219. CoalMailAttachmentOpen = config["coal_mail_attachment_open"]
  220. CoalMailAttachmentTime = config["coal_mail_attachment_time"]
  221. CoalMailAttachmentPythonVersion = config["coal_mail_attachment_python_version"]
  222. }
  223. // 汾渭配置
  224. {
  225. FenweiOpen = config["fenwei_open"]
  226. FenweiFileDir = config["fenwei_file_dir"]
  227. FenweiOldFileDir = config["fenwei_old_file_dir"]
  228. FenweiNetOpen = config["fenwei_net_open"]
  229. FenweiNetUseName = config["fenwei_net_username"]
  230. FenweiNetPassword = config["fenwei_net_password"]
  231. FenweiNetJsonPath = config["fenwei_net_json_path"]
  232. }
  233. //煤炭江湖文件夹配置
  234. {
  235. MtjhFilePath = config["mtjh_file_path"]
  236. MtjhOpen = config["mtjh_open"]
  237. }
  238. TerminalCode = config["terminal_code"]
  239. // CCF化纤信息
  240. {
  241. CCFOpen = config["ccf_open"]
  242. CCFCookieFile = config["ccf_cookie_file"]
  243. CCFDataRuleFile = config["ccf_data_rule_file"]
  244. CCFDailyTaskTime = config["ccf_daily_task_time"]
  245. CCFWeeklyTaskTime = config["ccf_weekly_task_time"]
  246. CCFStockTaskTime = config["ccf_stock_task_time"]
  247. CCFUseName = config["ccf_username"]
  248. CCFPassword = config["ccf_password"]
  249. CCFDailyFetchNum, _ = strconv.Atoi(config["ccf_daily_fetch_num"])
  250. if CCFDailyFetchNum <= 0 {
  251. CCFDailyFetchNum = 7
  252. }
  253. CCFWeeklyFetchNum, _ = strconv.Atoi(config["ccf_weekly_fetch_num"])
  254. if CCFWeeklyFetchNum <= 0 {
  255. CCFWeeklyFetchNum = 3
  256. }
  257. CCFStockFetchNum, _ = strconv.Atoi(config["ccf_stock_fetch_num"])
  258. if CCFStockFetchNum <= 0 {
  259. CCFStockFetchNum = 3
  260. }
  261. CCFChartRuleFile = config["ccf_chart_rule_file"]
  262. if CCFChartRuleFile == "" {
  263. CCFChartRuleFile = "static/ccf_chart_rule.json"
  264. }
  265. if CCFChartAdditionRuleFile == "" {
  266. CCFChartAdditionRuleFile = "static/ccf_chart_addition_rule.json"
  267. }
  268. CCFChartTaskTime = config["ccf_chart_task_time"]
  269. }
  270. {
  271. LY_USERNAME = config["ly_username"]
  272. LY_PASSWORD = config["ly_password"]
  273. LY_JSON_PATH = config["ly_json_path"]
  274. LY_OPEN = config["ly_open"]
  275. }
  276. {
  277. RZD_TASK_TIME = config["rzd_task_time"]
  278. RZD_USERNAME = config["rzd_username"]
  279. RZD_PASSWORD = config["rzd_password"]
  280. RZD_EXCEL_PATH = config["rzd_excel_path"]
  281. RZD_OPEN = config["rzd_open"]
  282. RZD_DOWNLOAD_PATH = config["rzd_download_path"]
  283. RZD_LOGIN_PATH = config["rzd_login_path"]
  284. }
  285. // 隆众数据
  286. {
  287. OilchemAccount = config["oilchem_account"]
  288. OilchemPassword = config["oilchem_password"]
  289. OilchemCookieFile = config["oilchem_cookie_file"]
  290. OilchemOpen = config["oilchem_open"]
  291. OilchemDataInit = config["oilchem_data_init"]
  292. }
  293. // 泛糖科技
  294. {
  295. HisugarAccount = config["hisugar_account"]
  296. HisugarPassword = config["hisugar_password"]
  297. HisugarOpen = config["hisugar_open"]
  298. }
  299. //克拉克森文件夹配置
  300. {
  301. ClarkSonsFilePath = config["clarksons_file_path"]
  302. ClarkSonsOpen = config["clarksons_open"]
  303. }
  304. //PDF生成配置
  305. {
  306. MinIoAccessKeyId = config["minio_access_key_id"]
  307. MinIoAccessKeySecret = config["minio_access_key_secret"]
  308. MinIoEndpoint = config["minio_endpoint"]
  309. MinIoUseSSL = config["minio_use_ssl"]
  310. MinIoBucketName = config["minio_bucket_name"]
  311. MinIoUploadDir = config["minio_upload_dir"]
  312. MinIoViewHost = config["minio_view_host"]
  313. ChromePath = config["chrome_path"]
  314. CommandPython = config["command_python"]
  315. if CommandPython == "" {
  316. CommandPython = "python3"
  317. }
  318. OssType = config["oss_type"]
  319. if OssType == "" {
  320. OssType = MINIO
  321. }
  322. // S3-OSS相关
  323. S3Endpoint = config["s3_endpoint"]
  324. S3BackEndpoint = config["s3_back_endpoint"]
  325. S3BucketName = config["s3_bucket_name"]
  326. S3Host = config["s3_host"]
  327. S3AccessKeyId = config["s3_access_key_id"]
  328. S3AccessKeySecret = config["s3_access_key_secret"]
  329. S3UploadDir = config["s3_upload_dir"]
  330. S3Region = config["s3_region"]
  331. S3ForceStyle = config["s3_force_style"]
  332. S3EndpointPort = config["s3_endpoint_port"]
  333. S3Protocol = config["s3_protocol"]
  334. S3DisableSSL = config["s3_disable_ssl"]
  335. S3OpenAcl = config["s3_open_acl"]
  336. //aliyun oss
  337. Endpoint = config["endpoint"]
  338. Bucketname = config["bucket_name"]
  339. Imghost = config["img_host"]
  340. UploadDir = config["upload_dir"]
  341. Upload_Audio_Dir = config["upload_audio_dir"]
  342. AccessKeyId = config["access_key_id"]
  343. AccessKeySecret = config["access_key_secret"]
  344. }
  345. KplerExcelOpen = config["kpler_excel_open"]
  346. KplerExcelFilePath = config["kpler_excel_file_path"]
  347. KplerRefreshUrl = config["kpler_refresh_url"]
  348. KplerApiAccount = config["kpler_api_account"]
  349. KplerApiPassword = config["kpler_api_password"]
  350. CacheClient = cache.New(365*24*time.Hour, 365*24*time.Hour)
  351. }
  352. //修改接口文档
  353. //http://8.136.199.33:8300/swagger/