Преглед изворни кода

Merge branch 'feature/eta1.4.3_yongyi_edb' into debug

xyxie пре 1 година
родитељ
комит
db62b081be
2 измењених фајлова са 31 додато и 8 уклоњено
  1. 26 6
      controllers/data_manage/yongyi_data.go
  2. 5 2
      models/data_manage/base_from_yongyi.go

+ 26 - 6
controllers/data_manage/yongyi_data.go

@@ -9,6 +9,7 @@ import (
 	"github.com/tealeg/xlsx"
 	"os"
 	"path/filepath"
+	"strings"
 	"time"
 )
 
@@ -152,15 +153,34 @@ func (this *EdbInfoController) YongyiSearchList() {
 		return
 	}
 
+	list := make([]*data_manage.BaseFromYongyiIndexSearchItem, 0)
+	var err error
 	//关键字
 	keyword := this.GetString("Keyword")
+	if keyword != "" {
+		keyWordArr := strings.Split(keyword, " ")
 
-	// todo es 模糊搜索
-	list, err := data_manage.GetYongyiItemList(keyword)
-	if err != nil {
-		br.ErrMsg = "获取失败,Err:" + err.Error()
-		br.Msg = "获取失败"
-		return
+		if len(keyWordArr) > 0 {
+			condition := ""
+			for _, v := range keyWordArr {
+				condition += ` AND CONCAT(index_name,index_code) LIKE '%` + v + `%'`
+			}
+			list, err = data_manage.GetYongyiItemList(condition)
+			if err != nil {
+				br.ErrMsg = "获取失败,Err:" + err.Error()
+				br.Msg = "获取失败"
+				return
+			}
+		}
+
+	} else {
+		// todo es 模糊搜索
+		list, err = data_manage.GetYongyiItemList("")
+		if err != nil {
+			br.ErrMsg = "获取失败,Err:" + err.Error()
+			br.Msg = "获取失败"
+			return
+		}
 	}
 
 	br.Ret = 200

+ 5 - 2
models/data_manage/base_from_yongyi.go

@@ -103,9 +103,12 @@ type BaseFromYongyiIndexSearchItem struct {
 }
 
 // GetYongyiItemList 模糊查询Yongyi数据库指标列表
-func GetYongyiItemList(keyword string) (items []*BaseFromYongyiIndexSearchItem, err error) {
+func GetYongyiItemList(condition string) (items []*BaseFromYongyiIndexSearchItem, err error) {
 	o := orm.NewOrmUsingDB("data")
-	sql := "SELECT * FROM base_from_yongyi_index WHERE CONCAT(index_name,index_code) LIKE '%" + keyword + "%'"
+	sql := "SELECT * FROM base_from_yongyi_index  WHERE 1=1"
+	if condition != "" {
+		sql += condition
+	}
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
 }