wangshan 5 жил өмнө
parent
commit
1ab33a6557

+ 2 - 2
src/jfw/front/dataExport.go

@@ -638,14 +638,14 @@ func (d *DataExport) PreviewData(source, _id string) error {
 	_id = util.SE.Decode4Hex(_id)
 	dataType := d.GetString("dataType")
 	//从500条数据中筛选字段最全五条
-	res := public.GetDataExportSearchResultUseId(_id, dataType, -1)
+	res, kws := public.GetDataExportSearchResultUseId(_id, dataType, -1)
 	if res == nil {
 		d.Render("/pc/dataExport_noDataErr.html", &d.T)
 		log.Println("PreviewData查询出错")
 		return nil
 	}
 	//格式化字段
-	res_screen := public.ScreenData(res, dataType, 20)
+	res_screen := public.ScreenData(res, dataType, 20, kws)
 	list := public.FormatExportData(&res_screen, config.Sysconfig["webdomain"].(string), dataType, true)
 	d.T["data"] = subUrl(list, dataType)
 	d.T["dataType"] = dataType

+ 2 - 2
src/jfw/front/ws_dataExport.go

@@ -61,14 +61,14 @@ func (w *WsDataExport) GetPreview() error {
 	_id := util.SE.Decode4Hex(w.GetString("_id"))
 	dataType := w.GetString("dataType")
 	//从500条数据中筛选字段最全五条
-	res := public.GetDataExportSearchResultUseId(_id, dataType, -1)
+	res, _ := public.GetDataExportSearchResultUseId(_id, dataType, -1)
 	if res == nil {
 		w.Render("/pc/dataExport_noDataErr.html", &w.T)
 		log.Println("PreviewData查询出错")
 		return nil
 	}
 	//格式化字段
-	res_screen := public.ScreenData(res, dataType, 20)
+	res_screen := public.ScreenData(res, dataType, 20, nil)
 	list := public.FormatExportData(&res_screen, config.Sysconfig["webdomain"].(string), dataType, true)
 	_res["data"] = subUrl(list, dataType)
 	_res["dataType"] = dataType

+ 1 - 1
src/jfw/public/dataexport.go

@@ -479,7 +479,7 @@ func SendMailToPayUser(order *map[string]interface{}, order_money float64, pay_t
 		Border:    border,
 		Alignment: alignment,
 	}
-	list := GetDataExportSearchResultUseId(filter_id, dataType, data_count)
+	list, _ := GetDataExportSearchResultUseId(filter_id, dataType, data_count)
 	if list != nil {
 		for _, v := range *list {
 			row = sheet.AddRow()

+ 47 - 5
src/jfw/public/search.go

@@ -329,13 +329,15 @@ func isNullSearch(scd *SieveCondition) (isNull bool) {
  * webdomain 三级页域名
  * count 返回数量 (-1:预览数据查询)
  */
-func GetDataExportSearchResultUseId(_id, dataType string, count int) *[]map[string]interface{} {
+func GetDataExportSearchResultUseId(_id, dataType string, count int) (*[]map[string]interface{}, []KeyWord) {
 	defer util.Catch()
 	var res []map[string]interface{}
+	var kws []KeyWord
 	scd := getSqlObjFromId(_id)
 	//获取查询语句
 	qstr := getDataExportSql(scd)
 
+	kws = scd.Keyword
 	if count == -1 {
 		//数据预览数据查询
 		if scd.Comeinfrom == "supersearchPage" && len(scd.Keyword) == 0 && len(scd.Industry) == 0 {
@@ -349,7 +351,7 @@ func GetDataExportSearchResultUseId(_id, dataType string, count int) *[]map[stri
 					redis.Put("other", "export_news", res, 7200)
 				}
 			}
-			return &res
+			return &res, kws
 		} else if scd.Comeinfrom == "supersearchPage" || scd.Comeinfrom == "exportPage" {
 			//超级搜索非空查询
 			count = int(elastic.Count(INDEX, TYPE, qstr))
@@ -366,7 +368,7 @@ func GetDataExportSearchResultUseId(_id, dataType string, count int) *[]map[stri
 				scd.Keyword[0].Keyword = secondKWS
 				qstr = getDataExportSql(scd)
 				res2 := doSearch(qstr, 0, 100-count, "")
-				return delRepeatMapArr(res, res2)
+				return delRepeatMapArr(res, res2), kws
 			}
 		}
 		//非空查询
@@ -419,7 +421,7 @@ func GetDataExportSearchResultUseId(_id, dataType string, count int) *[]map[stri
 		}
 		res = *FormatExportData(&res, config.Sysconfig["webdomain"].(string), dataType, false)
 	}
-	return &res
+	return &res, kws
 }
 
 func FormatExportData(data *[]map[string]interface{}, webdomain string, dataType string, isBreviary bool) *[]map[string]interface{} {
@@ -547,13 +549,33 @@ func getStringArrFromDbResult(c interface{}) (arr []string) {
 }
 
 //获取结果,空字段最少的数据
-func ScreenData(arr *[]map[string]interface{}, dataType string, resultNum int) (res []map[string]interface{}) {
+func ScreenData(arr *[]map[string]interface{}, dataType string, resultNum int, kws []KeyWord) (res []map[string]interface{}) {
 	AllMap := map[int][]map[string]interface{}{}
+
+	NoKwsMap := map[int][]map[string]interface{}{}
+	lastNum := resultNum
 	for _, v := range *arr {
 		emptyNum := countOfTheEmpty(v, dataType)
 		if emptyNum == -1 {
 			continue
 		}
+		if len(kws) > 0 && kws[0].Keyword != "" {
+			var kwsFlag = true
+			for _, vk := range kws {
+				if strings.Contains(util.ObjToString(v["title"]), vk.Keyword) {
+					kwsFlag = false
+					continue
+				}
+			}
+			if kwsFlag {
+				if NoKwsMap[emptyNum] == nil {
+					NoKwsMap[emptyNum] = []map[string]interface{}{v}
+				} else {
+					NoKwsMap[emptyNum] = append(NoKwsMap[emptyNum], v)
+				}
+				continue
+			}
+		}
 		if AllMap[emptyNum] == nil {
 			AllMap[emptyNum] = []map[string]interface{}{v}
 			continue
@@ -577,6 +599,26 @@ func ScreenData(arr *[]map[string]interface{}, dataType string, resultNum int) (
 			res = tmp
 		}
 	}
+	if len(res) < lastNum {
+		resultNum = lastNum - len(res)
+		//获取key
+		Nokeys := []int{}
+		for k, _ := range NoKwsMap {
+			Nokeys = append(Nokeys, k)
+		}
+		sort.Ints(Nokeys)
+		log.Println("没关键词的空字段数量", Nokeys)
+		//选取结果
+		for _, v := range Nokeys {
+			if len(AllMap[v]) >= resultNum {
+				return append(res, NoKwsMap[v][:resultNum]...)
+			} else {
+				resultNum = resultNum - len(NoKwsMap[v])
+				tmp := append(res, NoKwsMap[v][:len(AllMap[v])]...)
+				res = tmp
+			}
+		}
+	}
 	return res
 }
 func countOfTheEmpty(m map[string]interface{}, dataType string) int {