Kaynağa Gözat

fix:excel导出,修复选择一级分类的时候,数据导出为空的bug

Roc 6 ay önce
ebeveyn
işleme
e9abe1d94d
2 değiştirilmiş dosya ile 24 ekleme ve 13 silme
  1. 22 11
      controllers/target.go
  2. 2 2
      models/target.go

+ 22 - 11
controllers/target.go

@@ -1041,21 +1041,32 @@ func (this *TargetController) ExportDataList() {
 		br.ErrMsg = "生成文件失败"
 		return
 	}
-	var frequencies []*string
-	if keyWord == "" {
+	var frequencies []string
+	if len(childClassifyIdList) > 0 {
 		frequencies, err = models.GetEdbDataFrequencyByClassifyIdList(childClassifyIdList)
 		if err != nil {
 			br.Msg = "查询频度失败"
 			br.ErrMsg = "查询频度失败"
 			return
 		}
-	} else {
+	} else if tradeCode != `` {
+		manualEdb, err := models.GetEdbinfoByTradeCode(tradeCode)
+		if err != nil {
+			br.Msg = "查询指标信息失败"
+			br.ErrMsg = "查询指标信息失败,err:" + err.Error()
+			return
+		}
+		frequencies = append(frequencies, manualEdb.Frequency)
+	} else if keyWord != `` {
 		frequencies, err = models.GetEdbDataFrequencyByKeyord(keyWord)
 		if err != nil {
 			br.Msg = "查询频度失败"
 			br.ErrMsg = "查询频度失败"
 			return
 		}
+	} else {
+		// 啥也没选的情况下
+		frequencies = append(frequencies, `日度`, `周度`, `月度`, `季度`, `半年度`, `年度`)
 	}
 
 	fileName := `手工数据`
@@ -1087,7 +1098,7 @@ func (this *TargetController) ExportDataList() {
 		}
 		var sheet *xlsx.Sheet
 		if len(secNameList) > 0 {
-			sheet, err = xlsxFile.AddSheet(*frequency)
+			sheet, err = xlsxFile.AddSheet(frequency)
 			if err != nil {
 				br.Msg = "新增Sheet失败"
 				br.ErrMsg = "新增Sheet失败,Err:" + err.Error()
@@ -1189,7 +1200,7 @@ func (this *TargetController) ExportDataList() {
 
 	fileName += time.Now().Format("06.01.02") + `.xlsx` //文件名称
 	this.Ctx.Output.Download(downloadFilePath, fileName)
-	
+
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "success"
@@ -2057,13 +2068,13 @@ func (this *TargetController) TargetFrequencyList() {
 
 func sortEdbFrequency(frequencyList []string) (newFrequencyList []string) {
 	var frequencyMap1 = map[string]int{
-		"日度":   1,
-		"周度":   2,
-		"旬度":   3,
-		"月度":   4,
-		"季度":   5,
+		"日度":  1,
+		"周度":  2,
+		"旬度":  3,
+		"月度":  4,
+		"季度":  5,
 		"半年度": 6,
-		"年度":   7,
+		"年度":  7,
 	}
 
 	var frequencyMap2 = map[int]string{

+ 2 - 2
models/target.go

@@ -1064,7 +1064,7 @@ func GetEdbDataFrequency(classifyId int) (items []*string, err error) {
 // @param classifyIdList []int
 // @return items []*string
 // @return err error
-func GetEdbDataFrequencyByClassifyIdList(classifyIdList []int) (items []*string, err error) {
+func GetEdbDataFrequencyByClassifyIdList(classifyIdList []int) (items []string, err error) {
 	num := len(classifyIdList)
 	if num <= 0 {
 		return
@@ -1075,7 +1075,7 @@ func GetEdbDataFrequencyByClassifyIdList(classifyIdList []int) (items []*string,
 	return
 }
 
-func GetEdbDataFrequencyByKeyord(keyword string) (items []*string, err error) {
+func GetEdbDataFrequencyByKeyord(keyword string) (items []string, err error) {
 	sql := `SELECT DISTINCT frequency FROM edbinfo where SEC_NAME=? ORDER BY FIELD(frequency,'日度','周度','月度','季度','半年度','年度') `
 	o := orm.NewOrmUsingDB("edb")
 	_, err = o.Raw(sql, keyword).QueryRows(&items)