Sfoglia il codice sorgente

Merge branch 'master' of http://192.168.3.207:10080/qmx/datatag

# Conflicts:
#	src/util/utiltag.go
Jianghan 5 anni fa
parent
commit
83170f82b2
3 ha cambiato i file con 104 aggiunte e 116 eliminazioni
  1. 17 5
      src/util/parsxlsx.go
  2. 87 111
      src/util/utiltag.go
  3. BIN
      src/web/res/fields.xlsx

+ 17 - 5
src/util/parsxlsx.go

@@ -177,7 +177,7 @@ func ResponseXlsx(id string) string {
 				sh := xf.Sheets[0]
 				for i, v := range *data {
 					row := sh.AddRow()
-					row.AddCell().SetInt(i)
+					row.AddCell().SetInt(i+1)
 					row.AddCell().SetValue(v["s_matchkey"])
 					row.AddCell().SetValue(v["area"])
 					row.AddCell().SetValue(v["city"])
@@ -190,7 +190,11 @@ func ResponseXlsx(id string) string {
 					}
 					row.AddCell().SetValue(v["buyer"])
 					row.AddCell().SetValue(v["winner"])
-					row.AddCell().SetFloat(util.Float64All(v["bidamount"]) / 10000)
+					if v["bidamount"]!= nil{
+						row.AddCell().SetFloat(util.Float64All(v["bidamount"]) / 10000)
+					}else {
+						row.AddCell()
+					}
 					row.AddCell().SetValue(v["projectname"])
 					row.AddCell().SetValue(v["detail"])
 					row.AddCell().SetValue(v["s_jyhref"])
@@ -209,7 +213,7 @@ func ResponseXlsx(id string) string {
 				sh := xf.Sheets[1]
 				for i, v := range *data {
 					row := sh.AddRow()
-					row.AddCell().SetInt(i)
+					row.AddCell().SetInt(i+1)
 					row.AddCell().SetValue(v["s_matchkey"])
 					row.AddCell().SetValue(v["area"])
 					row.AddCell().SetValue(v["city"])
@@ -225,8 +229,16 @@ func ResponseXlsx(id string) string {
 					row.AddCell().SetValue(v["s_jyhref"])
 					row.AddCell().SetValue(v["projectname"])
 					row.AddCell().SetValue(v["projectscope"])
-					row.AddCell().SetFloat(util.Float64All(v["budget"]) / 10000)
-					row.AddCell().SetFloat(util.Float64All(v["bidamount"]) / 10000)
+					if v["budget"]!= nil{
+						row.AddCell().SetFloat(util.Float64All(v["budget"]) / 10000)
+					}else{
+						row.AddCell()
+					}
+					if v["bidamount"]!= nil{
+						row.AddCell().SetFloat(util.Float64All(v["bidamount"]) / 10000)
+					}else {
+						row.AddCell()
+					}
 					if v["bidopentime"] != nil {
 						row.AddCell().SetValue(time.Unix(util.Int64All(v["bidopentime"]), 0).Format("2006-01-02"))
 					}else {

+ 87 - 111
src/util/utiltag.go

@@ -44,7 +44,6 @@ const (
 	Url                       = "https://www.jianyu360.com/article/content/%s.html"
 )
 
-var StandardFields, AdvancedFields map[string]bool
 
 func UtilEsSaveData(sdataid string, datas *[]map[string]interface{}) error {
 	defer util.Catch()
@@ -65,19 +64,9 @@ func UtilEsFind(tags map[string]interface{}) (error, int64) {
 		return errors.New("s_esquery or s_dataid no found"), 0
 	}
 	i_maxnum := util.Int64All(tags["i_maxnum"])
-	if i_maxnum > 100 || i_maxnum <= 0 {
+	if i_maxnum <= 0 {
 		i_maxnum = 100
 	}
-	var isStandardFields bool
-	switch util.Int64All(tags["i_extfieldstype"]) {
-	case Standard:
-		isStandardFields = true
-	case Advanced:
-		isStandardFields = false
-	default:
-		log.Println("字段定义错误")
-		return errors.New("i_extfieldstype no found"), 0
-	}
 	maths := make([]map[string]string, 0)
 	if orules, ok := tags["o_rules"].([]interface{}); ok {
 		for _, v := range orules {
@@ -100,7 +89,6 @@ func UtilEsFind(tags map[string]interface{}) (error, int64) {
 	client := elastic.GetEsConn()
 	defer elastic.DestoryEsConn(client)
 	esquery = esquery[:len(esquery)-1] + `,"size":` + fmt.Sprintf("%d", i_maxnum) + `}`
-	//log.Println(esquery)
 	searchResult, err := client.Search(EsIndex).Source(esquery).Do()
 	if err == nil && searchResult.Hits != nil {
 		datas := make([]map[string]interface{}, 0)
@@ -108,31 +96,18 @@ func UtilEsFind(tags map[string]interface{}) (error, int64) {
 			item := make(map[string]interface{})
 			if json.Unmarshal(*v.Source, &item) == nil {
 				//log.Println(item)
-				save := make(map[string]interface{})
-				save["info_id"] = v.Id
-				save["s_dataid"] = sdataid
-				save["s_jyhref"] = fmt.Sprintf(Url, util.CommonEncodeArticle("content", v.Id))
-				save["i_createtime"] = time.Now().Unix()
-				if isStandardFields {
-					for k := range StandardFields {
-						if item[k] != nil {
-							save[k] = item[k]
-						}
-					}
-				} else {
-					for k := range AdvancedFields {
-						if item[k] != nil {
-							save[k] = item[k]
-						}
-					}
-				}
+				item["info_id"] = v.Id
+				item["s_dataid"] = sdataid
+				item["s_jyhref"] = fmt.Sprintf(Url, util.CommonEncodeArticle("content", v.Id))
+				item["i_createtime"] = time.Now().Unix()
 				var d *DFA = &DFA{}
 				for _, math := range maths {
 					fileds := strsToArr(math["s_keymatch"], "field")
 					d.AddWord(strings.Split(math["s_matchkey"], ",")...)
 					analyKeys := []string{}
 					for _, filed := range fileds {
-						analyKeys = append(analyKeys, d.Analy(util.ObjToString(item[filed]))...)
+						ddds := d.Analy(util.ObjToString(item[filed]))
+						analyKeys = append(analyKeys, ddds...)
 					}
 					if len(analyKeys) > 0 {
 						ssavekey := make(map[string]bool)
@@ -143,24 +118,23 @@ func UtilEsFind(tags map[string]interface{}) (error, int64) {
 						for k := range ssavekey {
 							ssavekeys = append(ssavekeys, k)
 						}
-						save["s_matchkey"] = strings.Join(ssavekeys, ",")
-						save["s_matchtype"] = strings.Join(fileds, ",")
+						item["s_matchkey"] = strings.Join(ssavekeys, ",")
+						item["s_matchtype"] = strings.Join(fileds, ",")
 						break
 					}
 				}
 				d.Clear()
-				if !isStandardFields {
-					findwinner := strings.TrimSpace(util.ObjToString(save["winner"]))
-					if findwinner != "" {
-						finddata, _ := MgoEn.FindOneByField(MgoEnC, bson.M{"company_name": findwinner}, bson.M{"legal_person": 1, "company_email": "1", "company_phone": 1})
-						if finddata != nil && (*finddata) != nil {
-							save["legal_person"] = util.ObjToString((*finddata)["legal_person"])
-							save["company_email"] = util.ObjToString((*finddata)["company_email"])
-							save["company_phone"] = util.ObjToString((*finddata)["company_phone"])
-						}
+				findwinner := strings.TrimSpace(util.ObjToString(item["winner"]))
+				if findwinner != "" {
+					finddata, _ := MgoEn.FindOne(MgoEnC, bson.M{"company_name": findwinner})
+					if finddata != nil && (*finddata) != nil {
+						item["legal_person"] = util.ObjToString((*finddata)["legal_person"])
+						item["company_email"] = util.ObjToString((*finddata)["company_email"])
+						item["company_phone"] = util.ObjToString((*finddata)["company_phone"])
+						item["qyk"] = finddata
 					}
 				}
-				datas = append(datas, save)
+				datas = append(datas, item)
 			}
 		}
 		Mgo.Update("tags", bson.M{"_id": tags["_id"]}, bson.M{
@@ -259,35 +233,78 @@ func Utiltags(tag map[string]interface{}) string {
 	if tab.Sglobaladdkey != "" && tab.Sglobaladdkeymatch != "" {
 		if tmps := strsToArr(tab.Sglobaladdkeymatch, "str"); tmps != nil {
 			for _, vv := range strings.Split(tab.Sglobaladdkey, ",") {
-				newEsObject.Bool.Should = append(newEsObject.Bool.Should, models.GlobaladdkeyObject{
-					MultiMatch: &models.MultiMatch{
-						Query:  vv,
-						Type:   MultiMatchType,
-						Fields: tmps,
-					},
-				})
+				addkeylines := strings.Split(vv, "&&")
+				if len(addkeylines) > 1 {
+					addkeyline := models.NewEsObject{}
+					for _, vvv := range addkeylines {
+						if vvv == "" {
+							continue
+						}
+						addkeyline.Bool.Must = append(addkeyline.Bool.Must, models.AddkeyObject{
+							MultiMatch: &models.MultiMatch{
+								Query:  vvv,
+								Type:   MultiMatchType,
+								Fields: tmps,
+							},
+						})
+					}
+					if len(addkeyline.Bool.Must) > 0 {
+						newEsObject.Bool.Should = append(newEsObject.Bool.Should, addkeyline)
+					}
+				} else {
+					newEsObject.Bool.Should = append(newEsObject.Bool.Should, models.GlobaladdkeyObject{
+						MultiMatch: &models.MultiMatch{
+							Query:  vv,
+							Type:   MultiMatchType,
+							Fields: tmps,
+						},
+					})
+				}
 			}
 		}
 	}
+	if len(newEsObject.Bool.Should) > 0 || len(newEsObject.Bool.MustNot) > 0 || len(newEsObject.Bool.Must) > 0 {
+		fqBoolObject.Must = append(fqBoolObject.Must, newEsObject)
+	}
 
+	nots := models.NewEsObject{}
 	if tab.Sglobalnotkey != "" && tab.Sglobalnotkeymatch != "" {
 		if tmps := strsToArr(tab.Sglobalnotkeymatch, "str"); tmps != nil {
 			for _, vv := range strings.Split(tab.Sglobalnotkey, ",") {
-				fqBoolObject.MustNot = append(fqBoolObject.MustNot, models.GlobalnotkeyObject{
-					MultiMatch: &models.MultiMatch{
-						Query:  vv,
-						Type:   MultiMatchType,
-						Fields: tmps,
-					},
-				})
+				addkeylines := strings.Split(vv, "&&")
+				if len(addkeylines) > 1 {
+					addkeyline := models.NewEsObject{}
+					for _, vvv := range addkeylines {
+						if vvv == "" {
+							continue
+						}
+						addkeyline.Bool.Must = append(addkeyline.Bool.Must, models.AddkeyObject{
+							MultiMatch: &models.MultiMatch{
+								Query:  vvv,
+								Type:   MultiMatchType,
+								Fields: tmps,
+							},
+						})
+					}
+					if len(addkeyline.Bool.Must) > 0 {
+						nots.Bool.Should = append(nots.Bool.Should, addkeyline)
+					}
+				} else {
+					nots.Bool.Should = append(nots.Bool.Should, models.GlobalnotkeyObject{
+						MultiMatch: &models.MultiMatch{
+							Query:  vv,
+							Type:   MultiMatchType,
+							Fields: tmps,
+						},
+					})
+				}
 			}
 		}
 	}
-
-	if len(newEsObject.Bool.Should) > 0 || len(newEsObject.Bool.MustNot) > 0 || len(newEsObject.Bool.Must) > 0 {
-		fqBoolObject.Must = append(fqBoolObject.Must, newEsObject)
+	if len(nots.Bool.Should) > 0 {
+		fqBoolObject.MustNot = append(fqBoolObject.MustNot, nots)
 	}
-
+	torules := models.BoolObject{}
 	for _, v := range tab.Orules {
 		tmpses := models.NewEsObject{}
 		tmpnewEsObject := models.NewEsObject{}
@@ -373,18 +390,24 @@ func Utiltags(tag map[string]interface{}) string {
 				},
 			})
 		}
-		fqBoolObject.Should = append(fqBoolObject.Should, tmpses)
+		torules.Should = append(torules.Should, tmpses)
 	}
 	if len(ffBoolObject.Must) > 0 || len(ffBoolObject.MustNot) > 0 || len(ffBoolObject.Should) > 0 {
 		QueryObjecct.Filtered.Filter.Bool = &ffBoolObject
 	}
 	if len(fqBoolObject.Must) > 0 || len(fqBoolObject.MustNot) > 0 || len(fqBoolObject.Should) > 0 {
+		QueryObjecct.Filtered.Query = &models.Query{}
 		QueryObjecct.Filtered.Query.Bool = &fqBoolObject
+		if len(torules.Should) > 0 {
+			QueryObjecct.Filtered.Query.Bool.Must = append(QueryObjecct.Filtered.Query.Bool.Must, map[string]interface{}{
+				"bool": torules,
+			})
+		}
 	}
 	rdata := make(map[string]interface{})
 	rdata["query"] = QueryObjecct
 	esbytes, _ := json.Marshal(rdata)
-	return strings.ReplaceAll(string(esbytes),"\\u0026","&")
+	return strings.ReplaceAll(string(esbytes), "\\u0026", "&")
 }
 
 func strsToArr(strs string, typestr string) []string {
@@ -438,51 +461,4 @@ func strsToArr(strs string, typestr string) []string {
 func init() {
 	EsIndex = util.ObjToString(Sysconfig["elasticsearch_index"])
 	EsType = util.ObjToString(Sysconfig["elasticsearch_type"])
-	StandardFields = map[string]bool{
-		"title":        true,
-		"s_jyhref":     true,
-		"subtype":      true,
-		"area":         true,
-		"city":         true,
-		"publishtime":  true,
-		"buyer":        true,
-		"winner":       true,
-		"bidamount":    true,
-		"projectname":  true,
-		"detail":       true,
-		//"budget":       true,
-		//"bidopentime":  true,
-		//"projectscope": true,
-		//"buyerperson":  true,
-		//"buyertel":     true,
-		//"agency":       true,
-	}
-	AdvancedFields = map[string]bool{
-		"title":        true,
-		"s_jyhref":     true,
-		"subtype":      true,
-		"area":         true,
-		"city":         true,
-		"publishtime":  true,
-		"buyer":        true,
-		"winner":       true,
-		"budget":       true,
-		"bidamount":    true,
-		"bidopentime":  true,
-		"projectname":  true,
-		"projectscope": true,
-		"detail":       true,
-		"buyerperson":  true,
-		"buyertel":     true,
-		"agency":       true,
-		"href":         true,
-		"winnerperson": true,
-		"winnertel":    true,
-		//"agencyperson": true,
-		//"agencytel":    true,
-		//"agencyemail":  true,
-		"legal_person":  true,
-		"company_phone": true,
-		"company_email": true,
-	}
 }

BIN
src/web/res/fields.xlsx