base_from_oilchem.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package data
  2. import (
  3. "eta_gn/eta_api/models/data_manage"
  4. "eta_gn/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. }