Browse Source

fix:兼容mongo

Roc 11 months ago
parent
commit
69e4773d2a
1 changed files with 13 additions and 6 deletions
  1. 13 6
      models/data_manage/edb_data.go

+ 13 - 6
models/data_manage/edb_data.go

@@ -194,16 +194,16 @@ 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) {
 	// 自有数据需要额外处理(从mongo获取)
 	if source == utils.DATA_SOURCE_BUSINESS {
-		return m.getEdbDataListByMongo(source, subSource, edbCode, "", "", fieldArr, orderRule)
+		return m.getEdbDataListByMongo(source, subSource, edbCode, startDate, "", fieldArr, orderRule)
 	}
 
-	return m.getItemsBySourceAndCodeByMysql(source, subSource, edbCode, fieldArr, orderRule)
+	return m.getItemsBySourceAndCodeByMysql(source, subSource, edbCode, startDate, fieldArr, orderRule)
 }
 
-func (m *EdbData) getItemsBySourceAndCodeByMysql(source, subSource int, edbCode string, fieldArr []string, orderRule string) (items []*EdbData, err error) {
+func (m *EdbData) getItemsBySourceAndCodeByMysql(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")
@@ -219,8 +219,15 @@ func (m *EdbData) getItemsBySourceAndCodeByMysql(source, subSource int, edbCode
 	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
 }