xuzhiheng 4 jaren geleden
bovenliggende
commit
801df89a77

+ 80 - 85
src/service/private_service.go

@@ -39,104 +39,99 @@ func (f *Private) Keydatademo(world string) {
 	tmp := make(map[string]interface{})
 	destr := qu.SE.DecodeString(world)
 	typeStr := f.GetString("type")
-
 	qu.Debug(destr)
 	if len(destr) > 10 {
-		ctime := destr[:10]
-		ctimeint := qu.Int64All(ctime)
-		if time.Now().Sub(time.Unix(ctimeint, 0)).Hours()/24 < Subday {
-			var tagfield *map[string]interface{}
-			if typeStr == "private" {
-				tagfield, _ = Mgo.FindOne("entniche_rule", bson.M{"s_dataid": world})
-				customer := JyMysql.FindOne("entniche_info", map[string]interface{}{"id": qu.IntAll((*tagfield)["entId"])}, "name", "")
-				(*tagfield)["s_customer"] = (*customer)["name"]
+		var tagfield *map[string]interface{}
+		if typeStr == "private" {
+			tagfield, _ = Mgo.FindOne("entniche_rule", bson.M{"s_dataid": world})
+			customer := JyMysql.FindOne("entniche_info", map[string]interface{}{"id": qu.IntAll((*tagfield)["entId"])}, "name", "")
+			(*tagfield)["s_customer"] = (*customer)["name"]
+			log.Println("customer", customer)
+		}
+
+		log.Println("tagfield", tagfield)
+		if (*tagfield) != nil && len(*tagfield) > 0 {
+			if qu.IntAll((*tagfield)["i_extfieldstype"]) == Standard {
+				tmp["fieldtype"] = Standardstr
+			} else if qu.IntAll((*tagfield)["i_extfieldstype"]) == Advanced {
+				tmp["fieldtype"] = Advancedstr
+			} else {
+				f.ServeJson(map[string]string{
+					"err": "参数失效",
+				})
+				return
 			}
-			if (*tagfield) != nil && len(*tagfield) > 0 {
-				if qu.IntAll((*tagfield)["i_extfieldstype"]) == Standard {
-					tmp["fieldtype"] = Standardstr
-				} else if qu.IntAll((*tagfield)["i_extfieldstype"]) == Advanced {
-					tmp["fieldtype"] = Advancedstr
-				} else {
-					f.ServeJson(map[string]string{
-						"err": "参数失效",
-					})
-					return
-				}
-				tmp["total"] = qu.Int64All((*tagfield)["i_estotal"])
-				tmp["customername"] = qu.ObjToString((*tagfield)["s_customer"])
-				datas, _ := Mgo.Find("tagsdata", bson.M{"s_dataid": world}, `{"publishtime":-1}`, nil, false, -1, -1)
-				if (*datas) != nil && len(*datas) > 0 {
-					matchskey := make(map[string]bool)
-					rdata := make([]map[string]interface{}, 0)
-					for _, v := range *datas {
-						for _, mv := range strings.Split(qu.ObjToString(v["s_matchkey"]), ",") {
-							matchskey[mv] = true
-						}
-						delete(v, "_id")
-						delete(v, "s_dataid")
-						delete(v, "i_createtime")
+			tmp["total"] = qu.Int64All((*tagfield)["i_estotal"])
+			tmp["customername"] = qu.ObjToString((*tagfield)["s_customer"])
+			datas, _ := Mgo.Find("tagsdata", bson.M{"s_dataid": world}, `{"publishtime":-1}`, nil, false, -1, -1)
+			if (*datas) != nil && len(*datas) > 0 {
+				log.Println("len", len(*datas))
+				matchskey := make(map[string]bool)
+				rdata := make([]map[string]interface{}, 0)
+				for _, v := range *datas {
+					for _, mv := range strings.Split(qu.ObjToString(v["s_matchkey"]), ",") {
+						matchskey[mv] = true
+					}
+					delete(v, "_id")
+					delete(v, "s_dataid")
+					delete(v, "i_createtime")
 
-						if v["bidamount"] != nil {
-							v["bidamount"] = qu.Float64All(fmt.Sprintf("%f", qu.Float64All(v["bidamount"])/10000))
-						}
-						if v["budget"] != nil {
-							v["budget"] = qu.Float64All(fmt.Sprintf("%f", qu.Float64All(v["budget"])/10000))
-						}
-						if v["publishtime"] != nil {
-							v["publishtime"] = time.Unix(qu.Int64All(v["publishtime"]), 0).Format("2006-01-02")
-						}
-						if v["bidopentime"] != nil {
-							v["bidopentime"] = time.Unix(qu.Int64All(v["bidopentime"]), 0).Format("2006-01-02")
-						}
-						if utf8.RuneCountInString(qu.ObjToString(v["title"])) > 60 {
-							title := string([]rune(qu.ObjToString(v["title"]))[:60])
-							v["title"] = title + "..."
-						}
-						if utf8.RuneCountInString(qu.ObjToString(v["detail"])) > 150 {
-							detail := string([]rune(qu.ObjToString(v["detail"]))[:150])
-							v["detail"] = detail + "..."
+					if v["bidamount"] != nil {
+						v["bidamount"] = qu.Float64All(fmt.Sprintf("%f", qu.Float64All(v["bidamount"])/10000))
+					}
+					if v["budget"] != nil {
+						v["budget"] = qu.Float64All(fmt.Sprintf("%f", qu.Float64All(v["budget"])/10000))
+					}
+					if v["publishtime"] != nil {
+						v["publishtime"] = time.Unix(qu.Int64All(v["publishtime"]), 0).Format("2006-01-02")
+					}
+					if v["bidopentime"] != nil {
+						v["bidopentime"] = time.Unix(qu.Int64All(v["bidopentime"]), 0).Format("2006-01-02")
+					}
+					if utf8.RuneCountInString(qu.ObjToString(v["title"])) > 60 {
+						title := string([]rune(qu.ObjToString(v["title"]))[:60])
+						v["title"] = title + "..."
+					}
+					if utf8.RuneCountInString(qu.ObjToString(v["detail"])) > 150 {
+						detail := string([]rune(qu.ObjToString(v["detail"]))[:150])
+						v["detail"] = detail + "..."
+					}
+					if qu.Int64All((*tagfield)["i_extfieldstype"]) == Advanced {
+						legal_person := strings.TrimSpace(qu.ObjToString(v["legal_person"]))
+						if utf8.RuneCountInString(legal_person) > 1 {
+							legal_person := []rune(legal_person)
+							v["legal_person"] = string(legal_person[:1]) + "**"
 						}
-						if qu.Int64All((*tagfield)["i_extfieldstype"]) == Advanced {
-							legal_person := strings.TrimSpace(qu.ObjToString(v["legal_person"]))
-							if utf8.RuneCountInString(legal_person) > 1 {
-								legal_person := []rune(legal_person)
-								v["legal_person"] = string(legal_person[:1]) + "**"
-							}
 
-							cemail := strings.TrimSpace(qu.ObjToString(v["company_email"]))
-							if emailreg.MatchString(cemail) {
-								v["company_email"] = "********" + cemail[strings.Index(cemail, "@"):]
-							} else {
-								v["company_email"] = ""
-							}
-							company_phone := strings.TrimSpace(qu.ObjToString(v["company_phone"]))
-							if telreg.MatchString(company_phone) || phonereg.MatchString(company_phone) {
-								company_phone = company_phone[:len(company_phone)-5] + "****"
-								v["company_phone"] = company_phone
-							} else {
-								v["company_phone"] = ""
-							}
+						cemail := strings.TrimSpace(qu.ObjToString(v["company_email"]))
+						if emailreg.MatchString(cemail) {
+							v["company_email"] = "********" + cemail[strings.Index(cemail, "@"):]
+						} else {
+							v["company_email"] = ""
 						}
-						deletefields(qu.IntAll((*tagfield)["i_extfieldstype"]), &v)
-						rdata = append(rdata, v)
-					}
-					tmp["keylist"] = []string{}
-					for k := range matchskey {
-						if k == "" {
-							continue
+						company_phone := strings.TrimSpace(qu.ObjToString(v["company_phone"]))
+						if telreg.MatchString(company_phone) || phonereg.MatchString(company_phone) {
+							company_phone = company_phone[:len(company_phone)-5] + "****"
+							v["company_phone"] = company_phone
+						} else {
+							v["company_phone"] = ""
 						}
-						tmp["keylist"] = append(tmp["keylist"].([]string), k)
 					}
-					tmp["data"] = rdata
-					f.ServeJson(tmp)
-					return
+					deletefields(qu.IntAll((*tagfield)["i_extfieldstype"]), &v)
+					rdata = append(rdata, v)
+				}
+				tmp["keylist"] = []string{}
+				for k := range matchskey {
+					if k == "" {
+						continue
+					}
+					tmp["keylist"] = append(tmp["keylist"].([]string), k)
 				}
+				tmp["data"] = rdata
 			}
 		}
 	}
-	f.ServeJson(map[string]string{
-		"err": "参数失效",
-	})
+	f.ServeJson(tmp)
 }
 
 func (f *Private) Keydataoption(world string) {

+ 92 - 130
src/util/utiltag.go

@@ -4,17 +4,19 @@ import (
 	"encoding/json"
 	"errors"
 	"fmt"
+	"log"
 	"models"
 	"qfw/util"
 	"qfw/util/elastic"
 	"regexp"
 	sql "sqlmodel"
 	"strings"
+	"sync"
 	"time"
 
 	// "go.mongodb.org/mongo-driver/bson/primitive"
-
 	"gopkg.in/mgo.v2/bson"
+	es "gopkg.in/olivere/elastic.v1"
 )
 
 const (
@@ -70,6 +72,8 @@ func UtilEsSaveData(sdataid string, datas *[]map[string]interface{}) error {
 //客户规则
 func UtilEsFind1(tags map[string]interface{}) (error, int64) {
 	defer util.Catch()
+	ch := make(chan bool, 20)
+	wg := &sync.WaitGroup{}
 	sdataid := util.ObjToString(tags["s_dataid"])
 	esquery := util.ObjToString(tags["s_esquery"])
 	if len(esquery) < 1 || len(sdataid) < 1 {
@@ -106,108 +110,106 @@ func UtilEsFind1(tags map[string]interface{}) (error, int64) {
 		datas := make([]map[string]interface{}, 0)
 		util.Debug("es查询到的数量:", searchResult.Hits.TotalHits)
 		for _, v := range searchResult.Hits.Hits {
-			item := make(map[string]interface{})
-			if json.Unmarshal(*v.Source, &item) == nil {
-				delete(item, "_id")
-				item["appid"] = tags["appid"]
-				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{}
-				var analyKeys []string //找到的关键词
-				var matchType []string //匹配方式
-				for _, math := range maths {
-					fileds := strsToArr(math["s_keymatch"], "field")
-					d.AddWord(strings.Split(math["s_matchkey"], ",")...)
-					mkMap := make(map[string]interface{})
-					tmpMap := make(map[string]interface{})
-					for _, mk := range strings.Split(math["s_matchkey"], ",") {
-						if strings.Contains(mk, "&&") {
-							arr := strings.Split(mk, "&&")
-							for _, s := range arr {
-								if s != "" {
-									tmpMap[s] = mk
-									if b, _ := regexp.MatchString("[A-Z]", s); b {
-										mkMap[strings.ToLower(s)] = s
-										d.AddWord(strings.ToLower(s))
-									} else {
-										d.AddWord(s)
+			wg.Add(1)
+			ch <- true
+			go func(tmpHit *es.SearchHit) {
+				defer func() {
+					<-ch
+					wg.Done()
+				}()
+				item := make(map[string]interface{})
+				if json.Unmarshal(*tmpHit.Source, &item) == nil {
+					delete(item, "_id")
+					item["appid"] = tags["appid"]
+					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{}
+					var analyKeys []string //找到的关键词
+					var matchType []string //匹配方式
+					for _, math := range maths {
+						fileds := strsToArr(math["s_keymatch"], "field")
+						d.AddWord(strings.Split(math["s_matchkey"], ",")...)
+						mkMap := make(map[string]interface{})
+						tmpMap := make(map[string]interface{})
+						for _, mk := range strings.Split(math["s_matchkey"], ",") {
+							if strings.Contains(mk, "&&") {
+								arr := strings.Split(mk, "&&")
+								for _, s := range arr {
+									if s != "" {
+										tmpMap[s] = mk
+										if b, _ := regexp.MatchString("[A-Z]", s); b {
+											mkMap[strings.ToLower(s)] = s
+											d.AddWord(strings.ToLower(s))
+										} else {
+											d.AddWord(s)
+										}
 									}
 								}
-							}
-						} else {
-							if b, _ := regexp.MatchString("[A-Z]", mk); b {
-								mkMap[strings.ToLower(mk)] = mk
-								d.AddWord(strings.ToLower(mk))
 							} else {
-								d.AddWord(mk)
+								if b, _ := regexp.MatchString("[A-Z]", mk); b {
+									mkMap[strings.ToLower(mk)] = mk
+									d.AddWord(strings.ToLower(mk))
+								} else {
+									d.AddWord(mk)
+								}
 							}
 						}
-					}
-					for _, filed := range fileds {
-						filed1 := strings.ToLower(util.ObjToString(item[filed]))
-						ddds := d.Analy(filed1)
-						analyKeys = append(analyKeys, ddds...)
-					}
-					if len(analyKeys) > 0 {
-						matchType = append(matchType, strings.Join(fileds, ","))
-						for k, v := range analyKeys {
-							if tmpMap[v] != "" && tmpMap[v] != nil {
-								analyKeys[k] = util.ObjToString(tmpMap[v])
-							}
+						for _, filed := range fileds {
+							filed1 := strings.ToLower(util.ObjToString(item[filed]))
+							ddds := d.Analy(filed1)
+							analyKeys = append(analyKeys, ddds...)
 						}
-						for _, v1 := range analyKeys {
-							if mkMap[v1] != "" && mkMap[v1] != nil {
-								analyKeys = deleteSlice(analyKeys, v1)
-								analyKeys = append(analyKeys, util.ObjToString(mkMap[v1]))
+						if len(analyKeys) > 0 {
+							matchType = append(matchType, strings.Join(fileds, ","))
+							for k, v := range analyKeys {
+								if tmpMap[v] != "" && tmpMap[v] != nil {
+									analyKeys[k] = util.ObjToString(tmpMap[v])
+								}
+							}
+							for _, v1 := range analyKeys {
+								if mkMap[v1] != "" && mkMap[v1] != nil {
+									analyKeys = deleteSlice(analyKeys, v1)
+									analyKeys = append(analyKeys, util.ObjToString(mkMap[v1]))
+								}
 							}
 						}
+						d.Clear()
 					}
-					d.Clear()
-				}
-				//去重
-				ssavekey := make(map[string]bool)
-				for _, v := range analyKeys {
-					ssavekey[v] = true
-				}
-				ssavekeys := []string{}
-				for k := range ssavekey {
-					ssavekeys = append(ssavekeys, k)
-				}
-				item["s_matchkey"] = GetMactchKey(maths, item)
-				item["s_matchtype"] = strings.Join(matchType, ",")
-				findwinner := strings.TrimSpace(util.ObjToString(item["winner"]))
-				if findwinner != "" {
-					finddata := MgoEnps.FindOne(EnpsColl, bson.M{"company_name": findwinner})
-					if finddata != nil {
-						if legal_person := util.ObjToString(finddata["legal_person"]); legal_person != "" {
-							item["legal_person"] = legal_person
-						}
-						if email := util.ObjToString(finddata["company_email"]); email != "" {
-							item["company_email"] = email
-						}
-						if phone := util.ObjToString(finddata["company_phone"]); phone != "" {
-							item["company_phone"] = phone
+					//去重
+					ssavekey := make(map[string]bool)
+					for _, v := range analyKeys {
+						ssavekey[v] = true
+					}
+					ssavekeys := []string{}
+					for k := range ssavekey {
+						ssavekeys = append(ssavekeys, k)
+					}
+					item["s_matchkey"] = GetMactchKey(maths, item)
+					item["s_matchtype"] = strings.Join(matchType, ",")
+					findwinner := strings.TrimSpace(util.ObjToString(item["winner"]))
+					if findwinner != "" {
+						finddata := MgoEnps.FindOne(EnpsColl, bson.M{"company_name": findwinner})
+						if finddata != nil {
+							if legal_person := util.ObjToString(finddata["legal_person"]); legal_person != "" {
+								item["legal_person"] = legal_person
+							}
+							if email := util.ObjToString(finddata["company_email"]); email != "" {
+								item["company_email"] = email
+							}
+							if phone := util.ObjToString(finddata["company_phone"]); phone != "" {
+								item["company_phone"] = phone
+							}
+							item["qyk"] = finddata
 						}
-						//从最新年报中获取 中标单位联系电话、中标单位邮箱
-						// if annual_reports, ok := finddata["annual_reports"].(primitive.A); ok && len(annual_reports) > 0 {
-						// 	report_year := Sort_year_report(annual_reports) //最新年报
-						// 	if len(report_year) > 0 {
-						// 		if email := util.ObjToString(report_year["company_email"]); email != "" {
-						// 			item["company_email"] = email
-						// 		}
-						// 		if phone := util.ObjToString(report_year["company_phone"]); phone != "" {
-						// 			item["company_phone"] = phone
-						// 		}
-						// 	}
-						// }
-						item["qyk"] = finddata
 					}
+					datas = append(datas, item)
+					log.Println("id", item["info_id"])
 				}
-				datas = append(datas, item)
-			}
+			}(v)
 		}
+		wg.Wait()
 		Mgo.Update("entniche_rule", bson.M{"_id": tags["_id"]}, bson.M{
 			"$set": bson.M{
 				"i_estotal": searchResult.Hits.TotalHits,
@@ -276,46 +278,6 @@ func Utiltags(tag map[string]interface{}) string {
 			Lt: tab.Iendtime,
 		}}})
 	}
-	/*if tab.Sbudget != "" {
-		if strings.Contains(tab.Sbudget, "大于") && strings.Contains(tab.Sbudget, "小于") {
-			arr := strings.Split(tab.Sbudget, ",")
-			limit := &sql.BudgetOrBidamount{
-				Gte: util.Float64All(strings.Replace(arr[0], "大于", "", -1)),
-				Lt:  util.Float64All(strings.Replace(arr[1], "小于", "", -1)),
-			}
-			ffBoolObject.Must = append(ffBoolObject.Must, sql.BudgetMust{BudgetObj: &sql.BudgetObj{Budget: limit}})
-		} else if strings.Contains(tab.Sbudget, "大于") {
-			limit := &sql.BudgetOrBidamount{
-				Gte: util.Float64All(strings.Replace(tab.Sbudget, "大于", "", -1)),
-			}
-			ffBoolObject.Must = append(ffBoolObject.Must, sql.BudgetMust{BudgetObj: &sql.BudgetObj{Budget: limit}})
-		} else if strings.Contains(tab.Sbudget, "小于") {
-			limit := &sql.BudgetOrBidamount{
-				Lt: util.Float64All(strings.Replace(tab.Sbudget, "小于", "", -1)),
-			}
-			ffBoolObject.Must = append(ffBoolObject.Must, sql.BudgetMust{BudgetObj: &sql.BudgetObj{Budget: limit}})
-		}
-	}*/
-	/*if tab.Sbidamount != "" {
-		if strings.Contains(tab.Sbidamount, "大于") && strings.Contains(tab.Sbidamount, "小于") {
-			arr := strings.Split(tab.Sbidamount, ",")
-			limit := &sql.BudgetOrBidamount{
-				Gte: util.Float64All(strings.Replace(arr[0], "大于", "", -1)),
-				Lt:  util.Float64All(strings.Replace(arr[1], "小于", "", -1)),
-			}
-			ffBoolObject.Must = append(ffBoolObject.Must, sql.BidamountMust{BidamountObj: &sql.BidamountObj{Bidamount: limit}})
-		} else if strings.Contains(tab.Sbidamount, "大于") {
-			limit := &sql.BudgetOrBidamount{
-				Gte: util.Float64All(strings.Replace(tab.Sbidamount, "大于", "", -1)),
-			}
-			ffBoolObject.Must = append(ffBoolObject.Must, sql.BidamountMust{BidamountObj: &sql.BidamountObj{Bidamount: limit}})
-		} else if strings.Contains(tab.Sbidamount, "小于") {
-			limit := &sql.BudgetOrBidamount{
-				Lt: util.Float64All(strings.Replace(tab.Sbidamount, "小于", "", -1)),
-			}
-			ffBoolObject.Must = append(ffBoolObject.Must, sql.BidamountMust{BidamountObj: &sql.BidamountObj{Bidamount: limit}})
-		}
-	}*/
 	if tab.Sglobalbuyerclass != "" {
 		if len(tab.Sglobalbuyerclass) > 0 {
 			buyerclass := sql.BuyerclassObject{

+ 4 - 1
src/web/templates/client/cuser_rule_create.html

@@ -443,7 +443,7 @@
         "s_globaladdkeymatch": "",
         "s_globalnotkey": "",
         "s_globalnotkeymatch": "",
-        "i_maxnum": 5000,
+        "i_maxnum": 1000,
         "i_starttime": 0,
         "i_endtime": 0,
         "i_extfieldstype": 2,
@@ -1497,6 +1497,9 @@
         }
         if ($('#maxnum').val() !== "") {
             dataMap["i_maxnum"] = $('#maxnum').val();
+            if ($('#maxnum').val() > 5000) {
+                dataMap["i_maxnum"] = 5000;
+            }
         }
         if (dataMap.s_globaladdkeymatch.indexOf("1") > -1 || dataMap.s_globaladdkeymatch.indexOf("2") > -1 || dataMap.s_globaladdkeymatch.indexOf("3") > -1 ||
             dataMap.s_globaladdkeymatch.indexOf("4") > -1 || dataMap.s_globaladdkeymatch.indexOf("5") > -1) {

+ 5 - 3
src/web/templates/client/cuser_rule_edit.html

@@ -366,13 +366,12 @@
                                     <div class="form-group">
                                         <label class="col-sm-2 control-label">预览数据量</label>
                                         <div class="col-sm-3">
-                                            <input type="text" class="form-control" readonly disabled id="maxnum"
+                                            <input type="text" class="form-control" id="maxnum"
                                                    value="{{.T.data.i_maxnum}}">
                                         </div>
                                         <label class="col-sm-2 control-label ">高级字段包</label>
                                         <div class="col-sm-3">
-                                            <select class="form-control" id="extfiledselect" style="border-radius:3px"
-                                                    readonly>
+                                            <select class="form-control" id="extfiledselect" style="border-radius:3px">
                                                 <option value="1">否</option>
                                                 <option value="2">是</option>
                                             </select>
@@ -1660,6 +1659,9 @@
         }
         if ($('#maxnum').val() !== "") {
             dataMap["i_maxnum"] = $('#maxnum').val();
+            if ($('#maxnum').val() > 5000) {
+                dataMap["i_maxnum"] = 5000
+            }
         }
         if (dataMap.s_globaladdkeymatch.indexOf("1") > -1 || dataMap.s_globaladdkeymatch.indexOf("2") > -1 || dataMap.s_globaladdkeymatch.indexOf("3") > -1 ||
             dataMap.s_globaladdkeymatch.indexOf("4") > -1 || dataMap.s_globaladdkeymatch.indexOf("5") > -1) {