config.go 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  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. // Kpler
  119. var (
  120. KplerExcelFilePath string //excel文件地址
  121. KplerExcelOpen string //是否配置Kpler数据源,1已配置
  122. )
  123. var (
  124. CacheClient *cache.Cache
  125. )
  126. func init() {
  127. tmpRunMode, err := web.AppConfig.String("run_mode")
  128. if err != nil {
  129. panic("配置文件读取run_mode错误 " + err.Error())
  130. }
  131. RunMode = tmpRunMode
  132. fmt.Println("RunMode:", RunMode)
  133. config, err := web.AppConfig.GetSection(RunMode)
  134. if err != nil {
  135. panic("配置文件读取错误 " + err.Error())
  136. }
  137. beeLogger.Log.Info(RunMode + " 模式")
  138. // 公共api内部服务调用
  139. {
  140. // 公共指标库相关
  141. EDB_LIB_URL = config["edb_lib_url"]
  142. APP_EDB_LIB_NAME_EN = config["app_edb_lib_name_en"]
  143. EDB_LIB_Md5_KEY = config["edb_lib_md5_key"]
  144. opUserIdStr := config["op_user_id"]
  145. if opUserIdStr != `` {
  146. OpUserId, err = strconv.Atoi(opUserIdStr)
  147. if err != nil {
  148. panic("配置文件中操作人配置错误 " + err.Error())
  149. }
  150. }
  151. OpUserRealName = config["op_user_real_name"]
  152. }
  153. //日志配置
  154. {
  155. LogPath = config["log_path"]
  156. LogFile = config["log_file"]
  157. BinLogPath = config["binlog_path"]
  158. BinLogFile = config["binlog_file"]
  159. logMaxDaysStr := config["log_max_day"]
  160. LogMaxDays, _ = strconv.Atoi(logMaxDaysStr)
  161. }
  162. //涌益咨询文件夹配置
  163. {
  164. YongyiFilePath = config["yongyi_file_path"]
  165. YongyiReadFilePath = config["yongyi_read_file_path"]
  166. YongyiOpen = config["yongyi_open"]
  167. YongyiDownloadHost = config["yongyi_download_host"]
  168. if YongyiDownloadHost == "" {
  169. YongyiDownloadHost = "http://127.0.0.1:7010/"
  170. }
  171. }
  172. //中国煤炭网文件夹配置
  173. {
  174. CoalMineFilePath = config["coal_mine_file_path"]
  175. CoalMineOpen = config["coal_mine_open"]
  176. CoalMailAttachmentScriptPath = config["coal_mail_attachment_script_path"]
  177. CoalMailAttachmentOpen = config["coal_mail_attachment_open"]
  178. CoalMailAttachmentTime = config["coal_mail_attachment_time"]
  179. CoalMailAttachmentPythonVersion = config["coal_mail_attachment_python_version"]
  180. }
  181. // 汾渭配置
  182. {
  183. FenweiOpen = config["fenwei_open"]
  184. FenweiFileDir = config["fenwei_file_dir"]
  185. FenweiOldFileDir = config["fenwei_old_file_dir"]
  186. FenweiNetOpen = config["fenwei_net_open"]
  187. FenweiNetUseName = config["fenwei_net_username"]
  188. FenweiNetPassword = config["fenwei_net_password"]
  189. FenweiNetJsonPath = config["fenwei_net_json_path"]
  190. }
  191. //煤炭江湖文件夹配置
  192. {
  193. MtjhFilePath = config["mtjh_file_path"]
  194. MtjhOpen = config["mtjh_open"]
  195. }
  196. TerminalCode = config["terminal_code"]
  197. // CCF化纤信息
  198. {
  199. CCFOpen = config["ccf_open"]
  200. CCFCookieFile = config["ccf_cookie_file"]
  201. CCFDataRuleFile = config["ccf_data_rule_file"]
  202. CCFDailyTaskTime = config["ccf_daily_task_time"]
  203. CCFWeeklyTaskTime = config["ccf_weekly_task_time"]
  204. CCFStockTaskTime = config["ccf_stock_task_time"]
  205. CCFUseName = config["ccf_username"]
  206. CCFPassword = config["ccf_password"]
  207. CCFDailyFetchNum, _ = strconv.Atoi(config["ccf_daily_fetch_num"])
  208. if CCFDailyFetchNum <= 0 {
  209. CCFDailyFetchNum = 7
  210. }
  211. CCFWeeklyFetchNum, _ = strconv.Atoi(config["ccf_weekly_fetch_num"])
  212. if CCFWeeklyFetchNum <= 0 {
  213. CCFWeeklyFetchNum = 3
  214. }
  215. CCFStockFetchNum, _ = strconv.Atoi(config["ccf_stock_fetch_num"])
  216. if CCFStockFetchNum <= 0 {
  217. CCFStockFetchNum = 3
  218. }
  219. CCFChartRuleFile = config["ccf_chart_rule_file"]
  220. if CCFChartRuleFile == "" {
  221. CCFChartRuleFile = "static/ccf_chart_rule.json"
  222. }
  223. if CCFChartAdditionRuleFile == "" {
  224. CCFChartAdditionRuleFile = "static/ccf_chart_addition_rule.json"
  225. }
  226. CCFChartTaskTime = config["ccf_chart_task_time"]
  227. }
  228. {
  229. LY_USERNAME = config["ly_username"]
  230. LY_PASSWORD = config["ly_password"]
  231. LY_JSON_PATH = config["ly_json_path"]
  232. LY_OPEN = config["ly_open"]
  233. }
  234. {
  235. RZD_TASK_TIME = config["rzd_task_time"]
  236. RZD_USERNAME = config["rzd_username"]
  237. RZD_PASSWORD = config["rzd_password"]
  238. RZD_EXCEL_PATH = config["rzd_excel_path"]
  239. RZD_OPEN = config["rzd_open"]
  240. RZD_DOWNLOAD_PATH = config["rzd_download_path"]
  241. RZD_LOGIN_PATH = config["rzd_login_path"]
  242. }
  243. // 隆众数据
  244. {
  245. OilchemAccount = config["oilchem_account"]
  246. OilchemPassword = config["oilchem_password"]
  247. OilchemCookieFile = config["oilchem_cookie_file"]
  248. OilchemOpen = config["oilchem_open"]
  249. OilchemDataInit = config["oilchem_data_init"]
  250. }
  251. // 泛糖科技
  252. {
  253. HisugarAccount = config["hisugar_account"]
  254. HisugarPassword = config["hisugar_password"]
  255. HisugarOpen = config["hisugar_open"]
  256. }
  257. //克拉克森文件夹配置
  258. {
  259. ClarkSonsFilePath = config["clarksons_file_path"]
  260. ClarkSonsOpen = config["clarksons_open"]
  261. }
  262. KplerExcelOpen = config["kpler_excel_open"]
  263. KplerExcelFilePath = config["kpler_excel_file_path"]
  264. CacheClient = cache.New(365*24*time.Hour, 365*24*time.Hour)
  265. }
  266. //修改接口文档
  267. //http://8.136.199.33:8300/swagger/