base_from_hisugar.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. package data
  2. import (
  3. "eta/eta_api/models/data_manage"
  4. "eta/eta_api/utils"
  5. "fmt"
  6. "github.com/rdlucklib/rdluck_tools/paging"
  7. )
  8. type HisugarIndexSource2EdbReq struct {
  9. EdbCode string
  10. EdbName string
  11. Frequency string
  12. Unit string
  13. ClassifyId int
  14. AdminId int
  15. AdminRealName string
  16. }
  17. // HisugarIndexSource2Edb 新增泛糖科技数据从数据源到指标库
  18. func HisugarIndexSource2Edb(req HisugarIndexSource2EdbReq, lang string) (edb *data_manage.EdbInfo, errMsg string, skip bool, err error) {
  19. if req.EdbCode == "" {
  20. err = fmt.Errorf("指标ID为空")
  21. return
  22. }
  23. defer func() {
  24. if err != nil {
  25. tips := fmt.Sprintf("HisugarIndexSource2Edb新增失败, Err: %s", err.Error())
  26. fmt.Println(tips)
  27. utils.FileLog.Info(tips)
  28. }
  29. }()
  30. source := utils.DATA_SOURCE_HISUGAR
  31. // 是否新增过指标
  32. exist, e := data_manage.GetEdbInfoByEdbCode(source, req.EdbCode)
  33. if e != nil && e.Error() != utils.ErrNoRow() {
  34. err = fmt.Errorf("获取指标是否存在失败, err: %s", e.Error())
  35. return
  36. }
  37. if exist != nil {
  38. skip = true
  39. return
  40. }
  41. // 开始结束时间
  42. var startDate, endDate string
  43. // 新增指标库
  44. 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)
  45. if e != nil {
  46. errMsg = msg
  47. err = fmt.Errorf("EdbInfo: 新增指标失败, err: %s", e.Error())
  48. return
  49. }
  50. edb = edbInfo
  51. return
  52. }
  53. // GethisugarIndexInfo 获取指标信息-分页
  54. func GethisugarIndexInfo(keyWord string, classifyIdList []string, frequencyList []string, currentIndex int, pageSize int) (baseFromHisugarIndexPage *data_manage.BaseFromHisugarIndexPage, err error) {
  55. // 获取指标
  56. var condition string
  57. var pars []interface{}
  58. if keyWord != "" {
  59. condition += ` AND CONCAT(index_name,index_code) LIKE '%` + keyWord + `%'`
  60. }
  61. if len(classifyIdList) > 0 {
  62. condition += ` AND classify_id IN (`
  63. for _, v := range classifyIdList {
  64. condition += `?,`
  65. pars = append(pars, v)
  66. }
  67. condition = condition[:len(condition)-1] + `)`
  68. }
  69. if len(frequencyList) > 0 {
  70. condition += ` AND frequency IN (`
  71. for _, v := range frequencyList {
  72. condition += `?,`
  73. pars = append(pars, v)
  74. }
  75. condition = condition[:len(condition)-1] + `)`
  76. }
  77. count, err := data_manage.GetHisugarIndexInfoCount(condition, pars)
  78. if err != nil {
  79. return
  80. }
  81. page := paging.GetPaging(currentIndex, pageSize, count)
  82. if count <= 0 {
  83. baseFromHisugarIndexPage = &data_manage.BaseFromHisugarIndexPage{
  84. List: []*data_manage.BaseFromHisugarIndex{},
  85. Paging: page,
  86. }
  87. return
  88. }
  89. startSize := utils.StartIndex(currentIndex, pageSize)
  90. fenWeiIndexInfoList, err := data_manage.GetHisugarIndexInfoPage(condition, pars, startSize, pageSize)
  91. if err != nil {
  92. return
  93. }
  94. baseFromHisugarIndexPage = &data_manage.BaseFromHisugarIndexPage{
  95. List: fenWeiIndexInfoList,
  96. Paging: page,
  97. }
  98. return
  99. }