base_from_eia_steo.go 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. package data
  2. import (
  3. "eta/eta_api/models/data_manage"
  4. "eta/eta_api/utils"
  5. "fmt"
  6. )
  7. func GetClassifyALLById(classifyId int) (items []*data_manage.BaseFromEiaSteoClassify, err error) {
  8. classify, err := data_manage.GetEiaSteoClassifyById(classifyId)
  9. if err != nil {
  10. return
  11. }
  12. if classify.Level == 1 {
  13. childClassify, er := data_manage.GetChildEiaSteoClassifyById(classifyId)
  14. if er != nil {
  15. err = er
  16. return
  17. }
  18. items = append(items, childClassify...)
  19. }
  20. // 兼容之前部分指标在一级分类下的情况
  21. if len(items) == 0 {
  22. items = append(items, classify)
  23. }
  24. return
  25. }
  26. type EiaSteoIndexSource2EdbReq struct {
  27. EdbCode string
  28. EdbName string
  29. Frequency string
  30. Unit string
  31. ClassifyId int
  32. AdminId int
  33. AdminRealName string
  34. }
  35. // EiaSteoIndexSource2Edb 新增eiaSteo数据源到指标库
  36. func EiaSteoIndexSource2Edb(req EiaSteoIndexSource2EdbReq, lang string) (edb *data_manage.EdbInfo, err error, errMsg string, skip bool) {
  37. if req.EdbCode == "" {
  38. err = fmt.Errorf("指标ID为空")
  39. return
  40. }
  41. defer func() {
  42. if err != nil {
  43. tips := fmt.Sprintf("EiaSteoIndexSource2Edb新增失败, Err: %s", err.Error())
  44. fmt.Println(tips)
  45. utils.FileLog.Info(tips)
  46. }
  47. }()
  48. source := utils.DATA_SOURCE_EIA_STEO
  49. // 是否新增过指标
  50. exist, e := data_manage.GetEdbInfoByEdbCode(source, req.EdbCode)
  51. if e != nil && e.Error() != utils.ErrNoRow() {
  52. err = fmt.Errorf("获取指标是否存在失败, err: %s", e.Error())
  53. return
  54. }
  55. if exist != nil {
  56. skip = true
  57. return
  58. }
  59. // 开始结束时间
  60. var startDate, endDate string
  61. // 新增指标库
  62. 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)
  63. if e != nil {
  64. errMsg = msg
  65. err = fmt.Errorf("EdbInfo: 新增指标失败, err: %s", e.Error())
  66. return
  67. }
  68. edb = edbInfo
  69. return
  70. }