12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- package services
- import (
- "eta/eta_forum_admin/models"
- "eta/eta_forum_admin/models/mgodb"
- "eta/eta_forum_admin/utils"
- "fmt"
- "time"
- )
- // GetEdbDataList 获取指标的数据(日期正序返回)
- func GetEdbDataList(endInfoId, edbType int, startDate, endDate string) (list []*models.EdbDataList, err error) {
- dataList := make([]*mgodb.EdbDataBase, 0)
- var startDateT, endDateT time.Time
- if startDate != "" {
- startDateT, err = time.Parse(utils.FormatDate, startDate)
- if err != nil {
- err = fmt.Errorf("日期格式错误 error, %v", err)
- return
- }
- }
- if endDate != "" {
- endDateT, err = time.Parse(utils.FormatDate, endDate)
- if err != nil {
- err = fmt.Errorf("日期格式错误 error, %v", err)
- return
- }
- }
- if edbType == 1 {
- dataList, err = mgodb.GetEdbDataList(endInfoId, startDateT, endDateT)
- if err != nil {
- err = fmt.Errorf("查询指标数据出错 error, %v", err)
- return
- }
- } else {
- dataList, err = mgodb.GetEdbCalculateDataList(endInfoId, startDateT, endDateT)
- if err != nil {
- err = fmt.Errorf("查询指标数据出错 error, %v", err)
- return
- }
- }
- list = make([]*models.EdbDataList, 0)
- for _, v := range dataList {
- // 字符串转成浮点数
- list = append(list, &models.EdbDataList{
- EdbInfoId: v.EdbInfoId,
- DataTime: v.DataTime.Format(utils.FormatDate),
- DataTimestamp: v.DataTimestamp,
- Value: v.Value,
- },
- )
- }
- return
- }
|