base_edb_info.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package logic
  2. import (
  3. "errors"
  4. "eta/eta_index_lib/models"
  5. "eta/eta_index_lib/utils"
  6. "strconv"
  7. "time"
  8. )
  9. // RefreshBaseEdbInfo 刷新基础指标
  10. func RefreshBaseEdbInfo(edbInfo *models.EdbInfo, startDate string) (isHandling bool, errMsg string, err error) {
  11. cacheKey := utils.CACHE_EDB_DATA_REFRESH + strconv.Itoa(edbInfo.Source) + "_" + edbInfo.EdbCode
  12. if utils.Rc.IsExist(cacheKey) {
  13. isHandling = true
  14. return
  15. }
  16. utils.Rc.SetNX(cacheKey, 1, 1*time.Minute)
  17. defer func() {
  18. utils.Rc.Delete(cacheKey)
  19. }()
  20. switch edbInfo.Source {
  21. case utils.DATA_SOURCE_SCI:
  22. err = models.RefreshEdbDataFromSci(edbInfo.EdbInfoId, edbInfo.EdbCode, startDate)
  23. case utils.DATA_SOURCE_BAIINFO:
  24. err = models.RefreshEdbDataFromBaiinfo(edbInfo.EdbInfoId, edbInfo.EdbCode, startDate)
  25. case utils.DATA_SOURCE_MYSTEEL_CHEMICAL:
  26. err = models.RefreshEdbDataFromMysteelChemical(edbInfo.EdbInfoId, edbInfo.EdbCode, startDate)
  27. case utils.DATA_SOURCE_YS:
  28. err = models.RefreshEdbDataFromSmm(edbInfo.EdbInfoId, edbInfo.EdbCode, startDate)
  29. case utils.DATA_SOURCE_BLOOMBERG:
  30. err = models.RefreshEdbDataFromBloomberg(edbInfo.EdbInfoId, edbInfo.EdbCode, startDate)
  31. case utils.DATA_SOURCE_CCF:
  32. ccfOb := new(models.BaseFromCCF)
  33. err = ccfOb.Refresh(edbInfo.EdbInfoId, edbInfo.EdbCode, startDate)
  34. case utils.DATA_SOURCE_SCI_HQ:
  35. err = models.RefreshEdbDataFromSciHq(edbInfo.EdbInfoId, edbInfo.EdbCode, startDate)
  36. default:
  37. return
  38. }
  39. if err != nil && err.Error() != utils.ErrNoRow() {
  40. errMsg = "刷新指标信息失败!"
  41. err = errors.New("刷新指标信息失败 RefreshEdbDataFromSci,Err:" + err.Error())
  42. return
  43. }
  44. // 更新指标最大最小值
  45. if edbInfo.Source == utils.DATA_SOURCE_MYSTEEL_CHEMICAL {
  46. dataUpdateTime := time.Now().Format(utils.FormatDateTime)
  47. _, err, errMsg = models.UnifiedModifyEdbInfoMaxAndMinInfoDataUpdate(edbInfo, dataUpdateTime)
  48. if err != nil {
  49. return
  50. }
  51. } else {
  52. err, errMsg = models.UnifiedModifyEdbInfoMaxAndMinInfo(edbInfo)
  53. if err != nil {
  54. return
  55. }
  56. }
  57. // 更新ES
  58. go UpdateEs(edbInfo.EdbInfoId)
  59. return
  60. }