Browse Source

指标库-优化筛选项

hsun 11 months ago
parent
commit
c81a6d34ab
2 changed files with 27 additions and 11 deletions
  1. 17 8
      controllers/edb.go
  2. 10 3
      models/data_manage/edb_data.go

+ 17 - 8
controllers/edb.go

@@ -6,6 +6,7 @@ import (
 	"eta/eta_hub/services"
 	"eta/eta_hub/services/data"
 	"eta/eta_hub/utils"
+	"time"
 )
 
 // EdbController 指标
@@ -127,16 +128,15 @@ func (this *EdbController) List() {
 	}()
 
 	classifyId, _ := this.GetInt("ClassifyId")
-	if classifyId <= 0 {
-		br.Msg = "参数有误"
-		return
-	}
 
 	edbOb := new(data_manage.EdbInfo)
-	cond := ` AND classify_id = ?`
+	cond := ``
 	pars := make([]interface{}, 0)
-	pars = append(pars, classifyId)
-	edbList, e := edbOb.GetItemsByCondition(cond, pars, []string{}, "sort ASC")
+	if classifyId > 0 {
+		cond += ` AND classify_id = ?`
+		pars = append(pars, classifyId)
+	}
+	edbList, e := edbOb.GetItemsByCondition(cond, pars, []string{}, "sort ASC, create_time DESC")
 	if e != nil {
 		br.Msg = "获取失败"
 		br.ErrMsg = "EdbList GetItemsByCondition err: " + e.Error()
@@ -217,6 +217,15 @@ func (this *EdbController) EdbData() {
 		br.Msg = "参数有误"
 		return
 	}
+	startDate := this.GetString("StartDate")
+	if startDate != "" {
+		_, e := time.Parse(utils.FormatDate, startDate)
+		if e != nil {
+			br.Msg = "开始日期格式有误"
+			return
+		}
+	}
+
 	edbOb := new(data_manage.EdbInfo)
 	edb, e := edbOb.GetItemByUniCode(unicode)
 	if e != nil {
@@ -231,7 +240,7 @@ func (this *EdbController) EdbData() {
 
 	// 获取指标数据
 	dataOb := new(data_manage.EdbData)
-	dataList, e := dataOb.GetItemsBySourceAndCode(edb.Source, edb.SubSource, edb.EdbCode, []string{}, "")
+	dataList, e := dataOb.GetItemsBySourceAndCode(edb.Source, edb.SubSource, edb.EdbCode, startDate, []string{}, "")
 	if e != nil {
 		br.Msg = "获取失败"
 		br.ErrMsg = "EdbData GetItemsBySourceAndCode err: " + e.Error()

+ 10 - 3
models/data_manage/edb_data.go

@@ -192,7 +192,7 @@ type EdbDataItem struct {
 	UpdateTime string  `description:"更新时间"`
 }
 
-func (m *EdbData) GetItemsBySourceAndCode(source, subSource int, edbCode string, fieldArr []string, orderRule string) (items []*EdbData, err error) {
+func (m *EdbData) GetItemsBySourceAndCode(source, subSource int, edbCode, startDate string, fieldArr []string, orderRule string) (items []*EdbData, err error) {
 	tableName := GetEdbDataTableName(source, subSource)
 	if tableName == "" {
 		err = fmt.Errorf("table name empty")
@@ -208,8 +208,15 @@ func (m *EdbData) GetItemsBySourceAndCode(source, subSource int, edbCode string,
 	if orderRule != "" {
 		order = ` ORDER BY ` + orderRule
 	}
-	sql := fmt.Sprintf(`SELECT %s FROM %s WHERE edb_code = ? %s`, fields, tableName, order)
-	_, err = o.Raw(sql, edbCode).QueryRows(&items)
+	cond := ` edb_code = ?`
+	pars := make([]interface{}, 0)
+	pars = append(pars, edbCode)
+	if startDate != "" {
+		cond += ` AND data_time >= ?`
+		pars = append(pars, startDate)
+	}
+	sql := fmt.Sprintf(`SELECT %s FROM %s WHERE %s %s`, fields, tableName, cond, order)
+	_, err = o.Raw(sql, pars).QueryRows(&items)
 	return
 }