base_from_oilchem.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package data
  2. import (
  3. "eta/eta_api/models/data_manage"
  4. "eta/eta_api/utils"
  5. "fmt"
  6. )
  7. type OilchemIndexSource2EdbReq struct {
  8. EdbCode string
  9. EdbName string
  10. Frequency string
  11. Unit string
  12. ClassifyId int
  13. AdminId int
  14. AdminRealName string
  15. }
  16. // OilchemIndexSource2Edb 新增隆众资讯数据从数据源到指标库
  17. func OilchemIndexSource2Edb(req OilchemIndexSource2EdbReq, lang string) (edb *data_manage.EdbInfo, errMsg string, skip bool, err error) {
  18. if req.EdbCode == "" {
  19. err = fmt.Errorf("指标ID为空")
  20. return
  21. }
  22. defer func() {
  23. if err != nil {
  24. tips := fmt.Sprintf("OilchemIndexSource2Edb新增失败, Err: %s", err.Error())
  25. fmt.Println(tips)
  26. utils.FileLog.Info(tips)
  27. }
  28. }()
  29. source := utils.DATA_SOURCE_OILCHEM
  30. // 是否新增过指标
  31. exist, e := data_manage.GetEdbInfoByEdbCode(source, req.EdbCode)
  32. if e != nil && e.Error() != utils.ErrNoRow() {
  33. err = fmt.Errorf("获取指标是否存在失败, err: %s", e.Error())
  34. return
  35. }
  36. if exist != nil {
  37. skip = true
  38. return
  39. }
  40. // 开始结束时间
  41. var startDate, endDate string
  42. // 新增指标库
  43. edbInfo, e, msg, _ := EdbInfoAdd(source, utils.DATA_SUB_SOURCE_EDB, req.ClassifyId, req.EdbCode, req.EdbName, req.Frequency, req.Unit, startDate, endDate, req.AdminId, req.AdminRealName, lang)
  44. if e != nil {
  45. errMsg = msg
  46. err = fmt.Errorf("EdbInfo: 新增指标失败, err: %s", e.Error())
  47. return
  48. }
  49. edb = edbInfo
  50. return
  51. }