base_from_gpr_risk.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package data
  2. import (
  3. "eta/eta_api/models/data_manage"
  4. "eta/eta_api/utils"
  5. "fmt"
  6. )
  7. // GprRiskIndexSource2Edb 新增涌益咨询数据源到指标库
  8. func GprRiskIndexSource2Edb(req data_manage.GprRiskIndexSource2EdbReq, lang string) (edb *data_manage.EdbInfo, err error, errMsg string, skip bool) {
  9. if req.EdbCode == "" {
  10. err = fmt.Errorf("指标ID为空")
  11. return
  12. }
  13. defer func() {
  14. if err != nil {
  15. tips := fmt.Sprintf("GprRiskIndexSource2Edb新增失败, Err: %s", err.Error())
  16. fmt.Println(tips)
  17. utils.FileLog.Info(tips)
  18. }
  19. }()
  20. source := utils.DATA_SOURCE_USDA_FAS
  21. // 是否新增过指标
  22. exist, e := data_manage.GetEdbInfoByEdbCode(source, req.EdbCode)
  23. if e != nil && e.Error() != utils.ErrNoRow() {
  24. err = fmt.Errorf("获取指标是否存在失败, err: %s", e.Error())
  25. return
  26. }
  27. if exist != nil {
  28. skip = true
  29. return
  30. }
  31. // 开始结束时间
  32. var startDate, endDate string
  33. // 新增指标库
  34. 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)
  35. if e != nil {
  36. errMsg = msg
  37. err = fmt.Errorf("EdbInfo: 新增指标失败, err: %s", e.Error())
  38. return
  39. }
  40. edb = edbInfo
  41. return
  42. }