浏览代码

修改图库取值

hongze 3 年之前
父节点
当前提交
470d08a783
共有 2 个文件被更改,包括 34 次插入11 次删除
  1. 18 9
      controllers/chart.go
  2. 16 2
      models/chart.go

+ 18 - 9
controllers/chart.go

@@ -82,31 +82,39 @@ func (this *ChartController) ChartInfoDetail() {
 	switch dateType {
 	case 1:
 		startDate = "2000-01-01"
-		endDate = time.Now().Format(utils.FormatDate)
+		//endDate = time.Now().Format(utils.FormatDate)
+		endDate=""
 	case 2:
 		startDate = "2010-01-01"
-		endDate = time.Now().Format(utils.FormatDate)
+		//endDate = time.Now().Format(utils.FormatDate)
+		endDate =""
 	case 3:
 		startDate = "2015-01-01"
-		endDate = time.Now().Format(utils.FormatDate)
+		//endDate = time.Now().Format(utils.FormatDate)
+		endDate =""
 	case 4:
 		startDate = strconv.Itoa(time.Now().Year()) + "-01-01"
-		endDate = time.Now().Format(utils.FormatDate)
+		//endDate = time.Now().Format(utils.FormatDate)
+		endDate =""
 	case 5:
 		startDate = startDate + "-01"
 		endDate = endDate + "-01"
 	case 6:
 		startDate = startDate + "-01"
-		endDate = time.Now().Format(utils.FormatDate)
+		//endDate = time.Now().Format(utils.FormatDate)
+		endDate =""
 	case 7:
 		startDate = "2018-01-01"
-		endDate = time.Now().Format(utils.FormatDate)
+		//endDate = time.Now().Format(utils.FormatDate)
+		endDate =""
 	case 8:
 		startDate = "2019-01-01"
-		endDate = time.Now().Format(utils.FormatDate)
+		//endDate = time.Now().Format(utils.FormatDate)
+		endDate =""
 	case 9:
 		startDate = "2020-01-01"
-		endDate = time.Now().Format(utils.FormatDate)
+		//endDate = time.Now().Format(utils.FormatDate)
+		endDate =""
 	}
 
 	if startDate == "" || endDate == "" {
@@ -125,7 +133,8 @@ func (this *ChartController) ChartInfoDetail() {
 		if seasonEndDate != "" {
 			endDate = seasonEndDate + "-12-31"
 		} else {
-			endDate = time.Now().Format(utils.FormatDate)
+			//endDate = time.Now().Format(utils.FormatDate)
+			endDate =""
 		}
 	}
 

+ 16 - 2
models/chart.go

@@ -93,11 +93,25 @@ func GetEdbDataList(source, endInfoId int, startDate, endDate string) (list []*E
 		list = make([]*EdbDataList, 0)
 		return list, err
 	}
-	sql := `SELECT edb_data_id,edb_info_id,data_time,TRUNCATE(value,2) AS value,data_timestamp FROM %s WHERE edb_info_id=? AND data_time>=? AND data_time<=? ORDER BY data_time ASC `
+	var pars []interface{}
+	var condition string
+	if startDate != "" {
+		condition += ` AND data_time>=? `
+		pars = append(pars, startDate)
+	}
+	if endDate != "" {
+		condition += ` AND data_time<=? `
+		pars = append(pars, endDate)
+	}
+	sql := `SELECT edb_data_id,edb_info_id,data_time,TRUNCATE(value,2) AS value,data_timestamp FROM %s WHERE edb_info_id=? `
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` ORDER BY data_time ASC  `
 	sql = fmt.Sprintf(sql, tableName)
 	o := orm.NewOrm()
 	o.Using("data")
-	_, err = o.Raw(sql, endInfoId, startDate, endDate).QueryRows(&list)
+	_, err = o.Raw(sql, endInfoId, pars).QueryRows(&list)
 	return
 }