base_from_pcsg.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. package data
  2. import (
  3. "context"
  4. "encoding/json"
  5. "eta/eta_task/utils"
  6. "fmt"
  7. "io/ioutil"
  8. "time"
  9. )
  10. // RefreshPCSGBloomberg 中石油新加坡-定时刷新指标
  11. func RefreshPCSGBloomberg(cont context.Context) (err error) {
  12. defer func() {
  13. if err != nil {
  14. tips := "RefreshPCSGBloombergDaily-中石油新加坡-刷新彭博指标失败, ErrMsg:\n" + err.Error()
  15. utils.FileLog.Info(tips)
  16. }
  17. }()
  18. runTime := time.Now().Local().Format("15:04")
  19. tasks, e := LoadPCSGBloombergTask()
  20. if e != nil {
  21. err = fmt.Errorf("读取配置失败, %v", e)
  22. return
  23. }
  24. if len(tasks) == 0 {
  25. utils.FileLog.Info("任务未配置")
  26. return
  27. }
  28. // 根据分钟匹配任务
  29. uri := "bloomberg/pcsg/refresh_task"
  30. for _, v := range tasks {
  31. if runTime != v.TaskTime {
  32. continue
  33. }
  34. utils.FileLog.Info(fmt.Sprintf("执行%s", v.TaskKey))
  35. param := make(map[string]interface{})
  36. param["TaskKey"] = v.TaskKey
  37. res, e := postRefreshEdbData(param, uri)
  38. if e != nil {
  39. utils.FileLog.Info(fmt.Sprintf("postRefreshEdbData, %v", e))
  40. continue
  41. }
  42. if res != nil && res.Ret != 200 {
  43. utils.FileLog.Info("postRefreshEdbData, fail")
  44. continue
  45. }
  46. utils.FileLog.Info(fmt.Sprintf("执行结束%s", v.TaskKey))
  47. }
  48. return
  49. }
  50. type PCSGBloombergTask struct {
  51. TaskKey string `json:"TaskKey"`
  52. TaskTime string `json:"TaskTime"`
  53. }
  54. // LoadPCSGBloombergTask 加载配置
  55. func LoadPCSGBloombergTask() (tasks []*PCSGBloombergTask, err error) {
  56. filePath := "./static/pcsg_task.json"
  57. b, e := ioutil.ReadFile(filePath)
  58. if e != nil {
  59. err = fmt.Errorf("读取配置失败, err: %v", e)
  60. return
  61. }
  62. if e = json.Unmarshal(b, &tasks); e != nil {
  63. err = fmt.Errorf("解析配置失败, err: %v", e)
  64. return
  65. }
  66. return
  67. }