Browse Source

粮油商务网-excel导出

gmy 6 months ago
parent
commit
b7886afa13

+ 1 - 1
controllers/data_manage/base_from_ly_index_controller.go

@@ -402,7 +402,7 @@ func (this *BaseFromLyIndexController) LyIndexDataExport() {
 	}
 
 	fileName := `粮油商务网`
-	if classifyId >= 0 && indexCode == "" {
+	if classifyId > 0 && indexCode == "" {
 		lyClassify, err := data_manage.GetLyClassifyById(classifyId)
 		if err != nil {
 			return

+ 18 - 3
models/data_manage/base_from_ly_index.go

@@ -222,8 +222,23 @@ func GetLyIndexByCodeAndClassify(indexCode string, classifyId int, frequency *st
 
 // GetLyIndexFrequency 获取指标频度
 func GetLyIndexFrequency(classifyId int) (items []*string, err error) {
-	sql := `SELECT DISTINCT frequency FROM base_from_ly_index where base_from_ly_classify_id=? AND frequency IS NOT NULL ORDER BY FIELD(frequency,'日度','周度','月度','季度','半年度','年度') `
+	sql := `SELECT DISTINCT frequency 
+        FROM base_from_ly_index 
+        WHERE frequency IS NOT NULL`
+
+	// 如果 classifyId > 0,则添加该条件
+	if classifyId > 0 {
+		sql += ` AND base_from_ly_classify_id = ?`
+	}
+
+	sql += ` ORDER BY FIELD(frequency, '日度', '周度', '月度', '季度', '半年度', '年度')`
+
 	o := orm.NewOrmUsingDB("data")
-	_, err = o.Raw(sql, classifyId).QueryRows(&items)
-	return
+	if classifyId > 0 {
+		_, err = o.Raw(sql, classifyId).QueryRows(&items)
+	} else {
+		_, err = o.Raw(sql).QueryRows(&items)
+	}
+
+	return items, err
 }