xuzhiheng 4 сар өмнө
parent
commit
3b4252ac21

+ 12 - 8
customerdata/src/datamodel.go

@@ -9,19 +9,23 @@ import (
 
 // 客户模型
 type Customer struct {
-	ID           string                            //客户ID
-	Name         string                            //客户名称
-	AppId        string                            //appid
-	PushModel    int                               //推送模式 0:全局模式;1:部门模式;2:标签模式;3:部门+标签模式;4:规则模式
-	Departments  []*Department                     //所有部门
-	IsTagRule    bool                              //是否打标签
-	IsTagRule2   bool                              //是否打标签
-	IsTagRule3   bool                              //是否打标签
+	ID           string        //客户ID
+	Name         string        //客户名称
+	AppId        string        //appid
+	PushModel    int           //推送模式 0:全局模式;1:部门模式;2:标签模式;3:部门+标签模式;4:规则模式
+	Departments  []*Department //所有部门
+	IsTagRule    bool          //是否打标签
+	IsTagRule2   bool          //是否打标签
+	IsTagRule3   bool          //是否打标签
+	IsTagRule4   bool
+	IsTagRule5   bool
 	IsSearchHosp bool                              //是否查询第三方医院信息
 	IsSearchEnps bool                              //是否查询第三方企业信息
 	TagRules     []*TagRule                        //打标签规则集合
 	TagRules2    []*TagRule                        //打标签规则集合
 	TagRules3    []*TagRule                        //打标签规则集合
+	TagRules4    []*TagRule                        //打标签规则集合
+	TagRules5    []*TagRule                        //打标签规则集合
 	SaveDataMap  map[string]map[string]interface{} //最终入库数据(全局模式)
 	SaveDataArr  map[string]map[string]interface{} //最终入库数据(规则模式)
 	IdRange      bson.M                            //由当前时间生成是id查询区间

+ 1 - 1
customerdata/src/jylog.go

@@ -30,7 +30,7 @@ var LogPath = "./jylog"
 func init() {
 	os.Mkdir(LogPath, os.ModePerm)
 	//默认保留15天内的日志,-1为永久保留
-	initLog(15)
+	initLog(60)
 }
 
 func initLog(saveDay int) {

+ 209 - 4
customerdata/src/task.go

@@ -256,6 +256,56 @@ func (c *Customer) GetTagRules() {
 			c.TagRules3 = append(c.TagRules3, TR)
 		}
 	}
+	tagRules4, _ := MgoTag.Find("eusertagrule", map[string]interface{}{"s_userid": c.ID, "i_isuse": 1, "b_delete": false, "tagType": "4"}, nil, nil)
+	if len(tagRules4) > 0 {
+		c.IsTagRule4 = true //查到打标签规则,表示打标签
+		for _, tr := range tagRules4 {
+			TR := &TagRule{}
+			TR.Fields = make(map[string]interface{})
+			TR.DepartRuleIds = make(map[string]bool)
+			id := mgoutil.BsonTOStringId(tr["_id"])
+			name := qu.ObjToString(tr["s_name"])
+			TR.ID = id
+			TR.Name = name
+			TR.CustomerId = c.ID
+			//部门规则id组
+			if departRuleIds := qu.ObjToString(tr["o_departruleids"]); departRuleIds != "" {
+				for _, drid := range strings.Split(departRuleIds, ",") {
+					TR.DepartRuleIds[drid] = true
+				}
+			}
+			//规则
+			if o_list, ok := tr["o_list"].(primitive.A); ok && len(o_list) > 0 {
+				TR.GetKeyAddNotKeyWord(o_list)
+			}
+			c.TagRules4 = append(c.TagRules4, TR)
+		}
+	}
+	tagRules5, _ := MgoTag.Find("eusertagrule", map[string]interface{}{"s_userid": c.ID, "i_isuse": 1, "b_delete": false, "tagType": "5"}, nil, nil)
+	if len(tagRules5) > 0 {
+		c.IsTagRule5 = true //查到打标签规则,表示打标签
+		for _, tr := range tagRules5 {
+			TR := &TagRule{}
+			TR.Fields = make(map[string]interface{})
+			TR.DepartRuleIds = make(map[string]bool)
+			id := mgoutil.BsonTOStringId(tr["_id"])
+			name := qu.ObjToString(tr["s_name"])
+			TR.ID = id
+			TR.Name = name
+			TR.CustomerId = c.ID
+			//部门规则id组
+			if departRuleIds := qu.ObjToString(tr["o_departruleids"]); departRuleIds != "" {
+				for _, drid := range strings.Split(departRuleIds, ",") {
+					TR.DepartRuleIds[drid] = true
+				}
+			}
+			//规则
+			if o_list, ok := tr["o_list"].(primitive.A); ok && len(o_list) > 0 {
+				TR.GetKeyAddNotKeyWord(o_list)
+			}
+			c.TagRules5 = append(c.TagRules5, TR)
+		}
+	}
 }
 
 // 获取部门信息
@@ -290,7 +340,7 @@ func (c *Customer) GetData(stype string) {
 	if esversion == "v1" {
 	} else {
 		if stype == "high" {
-			esCon := Es2.(*esv.EsV7)
+			esCon := Es.(*esv.EsV7)
 			c.EsConGetDataV7(stype, esCon)
 		} else {
 			esCon := Es.(*esv.EsV7)
@@ -335,8 +385,8 @@ func (c *Customer) EsConGetDataV7(stype string, esCon *esv.EsV7) {
 			esindex := Index
 			escount := int64(0)
 			if stype == "high" {
-				esindex = "bidding_ai"
-				escount = Es2.Count(esindex, Itype, sr.EsQuery)
+				// esindex = "bidding"
+				escount = Es.Count(esindex, Itype, sr.EsQuery)
 			} else {
 				escount = Es.Count(esindex, Itype, sr.EsQuery)
 			}
@@ -473,7 +523,9 @@ func (c *Customer) EsConGetDataV7(stype string, esCon *esv.EsV7) {
 								fieldText[field] = text
 							}
 							//清理词清理
+							isClear := false
 							for _, cwm := range sr.GCW.MatchType {
+								isClear = true
 								if text := qu.ObjToString(fieldText[cwm]); text != "" {
 									for _, gcw_reg := range sr.GCW.KeyReg {
 										text = gcw_reg.ReplaceAllString(text, "")
@@ -496,7 +548,12 @@ func (c *Customer) EsConGetDataV7(stype string, esCon *esv.EsV7) {
 									continue
 								}
 							}
-							tmp["matchkey"], tmp["matchtype"] = GetMactchKeys(sr.Maths, tmp)
+							matchkey, matchtype := GetMactchKeys(sr.Maths, fieldText)
+							if matchkey == "" && isClear {
+								qu.Debug("-------------------二次匹配失败", id)
+								continue
+							}
+							tmp["matchkey"], tmp["matchtype"] = matchkey, matchtype
 							tmp["ruleid"] = sr.ID
 							tmp["rulename"] = sr.Name
 							tmpBuyerClass := qu.ObjToString(tmp["buyerclass"])
@@ -723,6 +780,154 @@ func (c *Customer) EsConGetDataV7(stype string, esCon *esv.EsV7) {
 									tmp["tagid3"] = strings.Join(tagIdArr, ",")
 								}
 							}
+							if c.IsTagRule4 {
+								tagNameMap := map[string]bool{}
+								tagIdMap := map[string]bool{}
+								//qu.Debug("c.TagRules---", len(c.TagRules))
+								//log.Println(c.TagRules,"=========",)
+								for _, tr := range c.TagRules4 {
+									if tr.DepartRuleIds[sr.ID] {
+										// log.Println(tr.TagNames, "===========打标签")
+										//先获取用到的所有字段值
+										for field, _ := range tr.Fields {
+											if fieldText[field] == nil { //补充fieldText
+												text := qu.ObjToString(tmp[field])
+												text = ProcessData(text) //处理文本(字母转大写,删除一些符号)
+												fieldText[field] = text
+											}
+										}
+										//qu.Debug("-------------------------开始排除词匹配--------------------------")
+										//qu.Debug("tr.NW---", len(tr.NW))
+										matchKeyTag := map[string]bool{}     //记录所有标签里的匹配上的关键词
+										matchKeyTypeTag := map[string]bool{} //记录标签里的关键词对应的匹配方式
+										for j, tag_nw := range tr.NW {       //排除词匹配
+											IsMatchNotKey := RegMatch(fieldText, tag_nw.MatchType, tag_nw.KeyReg, nil, nil, false, false)
+											//qu.Debug(IsMatchNotKey, "------------------------------------------------------------")
+											if !IsMatchNotKey { //排除词未匹配,匹配附加词关键词
+												// log.Println(j, tr.TagNames[j])
+												if RegMatch(fieldText, tr.AW[j].MatchType, tr.AW[j].KeyReg, nil, nil, false, true) && RegMatch(fieldText, tr.KW[j].MatchType, tr.KW[j].KeyReg, matchKeyTag, matchKeyTypeTag, true, false) {
+													tagname := tr.TagNames[j]
+													tagBuyerClass := tr.BuyerClass[j]
+													if tagBuyerClass != "" {
+														if strings.Contains(tagBuyerClass, tmpBuyerClass) {
+															tempList := []string{}
+															for k, _ := range matchKeyTag {
+																tempList = append(tempList, k)
+															}
+															if tagname == "" {
+																tagname = strings.Join(tempList, ",")
+																log.Println("=====tagname为空取匹配词为标签名称", tagname)
+															}
+															tmp["tagkey4"] = strings.Join(tempList, ",")
+															tagNameMap[tagname] = true
+															tagIdMap[tr.ID] = true
+														}
+													} else {
+														tempList := []string{}
+														for k, _ := range matchKeyTag {
+															tempList = append(tempList, k)
+														}
+														if tagname == "" {
+															tagname = strings.Join(tempList, ",")
+															log.Println("=====tagname为空取匹配词为标签名称", tagname)
+														}
+														tmp["tagkey4"] = strings.Join(tempList, ",")
+														tagNameMap[tagname] = true
+														tagIdMap[tr.ID] = true
+													}
+												}
+											}
+										}
+									}
+								}
+								//tagname
+								tagNameArr := MapDataToArr(tagNameMap)
+								tagIdArr := MapDataToArr(tagIdMap)
+								if len(tagNameArr) > 0 {
+									tmp["tagname4"] = strings.Join(tagNameArr, ",")
+									if DisPackageAppidMap[c.AppId] {
+										tmp["buyer_type4"] = strings.Join(tagNameArr, ",")
+									}
+									if c.PushModel == 2 {
+										tmp["item4"] = strings.Join(tagNameArr, ",")
+									}
+									tmp["tagid4"] = strings.Join(tagIdArr, ",")
+								}
+							}
+							if c.IsTagRule5 {
+								tagNameMap := map[string]bool{}
+								tagIdMap := map[string]bool{}
+								//qu.Debug("c.TagRules---", len(c.TagRules))
+								//log.Println(c.TagRules,"=========",)
+								for _, tr := range c.TagRules5 {
+									if tr.DepartRuleIds[sr.ID] {
+										// log.Println(tr.TagNames, "===========打标签")
+										//先获取用到的所有字段值
+										for field, _ := range tr.Fields {
+											if fieldText[field] == nil { //补充fieldText
+												text := qu.ObjToString(tmp[field])
+												text = ProcessData(text) //处理文本(字母转大写,删除一些符号)
+												fieldText[field] = text
+											}
+										}
+										//qu.Debug("-------------------------开始排除词匹配--------------------------")
+										//qu.Debug("tr.NW---", len(tr.NW))
+										matchKeyTag := map[string]bool{}     //记录所有标签里的匹配上的关键词
+										matchKeyTypeTag := map[string]bool{} //记录标签里的关键词对应的匹配方式
+										for j, tag_nw := range tr.NW {       //排除词匹配
+											IsMatchNotKey := RegMatch(fieldText, tag_nw.MatchType, tag_nw.KeyReg, nil, nil, false, false)
+											//qu.Debug(IsMatchNotKey, "------------------------------------------------------------")
+											if !IsMatchNotKey { //排除词未匹配,匹配附加词关键词
+												// log.Println(j, tr.TagNames[j])
+												if RegMatch(fieldText, tr.AW[j].MatchType, tr.AW[j].KeyReg, nil, nil, false, true) && RegMatch(fieldText, tr.KW[j].MatchType, tr.KW[j].KeyReg, matchKeyTag, matchKeyTypeTag, true, false) {
+													tagname := tr.TagNames[j]
+													tagBuyerClass := tr.BuyerClass[j]
+													if tagBuyerClass != "" {
+														if strings.Contains(tagBuyerClass, tmpBuyerClass) {
+															tempList := []string{}
+															for k, _ := range matchKeyTag {
+																tempList = append(tempList, k)
+															}
+															if tagname == "" {
+																tagname = strings.Join(tempList, ",")
+																log.Println("=====tagname为空取匹配词为标签名称", tagname)
+															}
+															tmp["tagkey5"] = strings.Join(tempList, ",")
+															tagNameMap[tagname] = true
+															tagIdMap[tr.ID] = true
+														}
+													} else {
+														tempList := []string{}
+														for k, _ := range matchKeyTag {
+															tempList = append(tempList, k)
+														}
+														if tagname == "" {
+															tagname = strings.Join(tempList, ",")
+															log.Println("=====tagname为空取匹配词为标签名称", tagname)
+														}
+														tmp["tagkey5"] = strings.Join(tempList, ",")
+														tagNameMap[tagname] = true
+														tagIdMap[tr.ID] = true
+													}
+												}
+											}
+										}
+									}
+								}
+								//tagname
+								tagNameArr := MapDataToArr(tagNameMap)
+								tagIdArr := MapDataToArr(tagIdMap)
+								if len(tagNameArr) > 0 {
+									tmp["tagname5"] = strings.Join(tagNameArr, ",")
+									if DisPackageAppidMap[c.AppId] {
+										tmp["buyer_type5"] = strings.Join(tagNameArr, ",")
+									}
+									if c.PushModel == 2 {
+										tmp["item5"] = strings.Join(tagNameArr, ",")
+									}
+									tmp["tagid5"] = strings.Join(tagIdArr, ",")
+								}
+							}
 							//item
 							switch c.PushModel {
 							case 0:

+ 6 - 57
customerdata/src/util.go

@@ -298,7 +298,7 @@ func GetIdRanges() (bson.M, bson.M, bool, int64) {
 		esquerys := `{"query":{"bool":{"must":{"range":{"id":{"gt":"%s"}}}}},"_source":["id","pici"],"sort":{"pici":"desc"},"from":0,"size":1}`
 		idQuery = fmt.Sprintf(esquerys, LatestId)
 	}
-	resId := Es2.Get("bidding_ai", "", idQuery)
+	resId := Es.Get(Index, Itype, idQuery)
 	if resId != nil && *resId != nil && len(*resId) == 1 {
 		endTime = qu.Int64All((*resId)[0]["pici"]) - 600
 	} else {
@@ -797,63 +797,12 @@ func AssembelSave(tmp map[string]interface{}, IsSearchHosp, IsSearchEnps bool, a
 		tmp["approvetime"] = qu.Int64All(info["approvetime"])
 		tmp["project_completedate"] = qu.Int64All(info["project_completedate"])
 		tmp["competehref"] = qu.ObjToString(info["competehref"])
-	} else {
-		infos := MgoBidding.FindOne("bidding_back", map[string]interface{}{"_id": mongodb.StringTOBsonId(id)})
-		if infos != nil && len(infos) > 0 {
-			if infos["projectinfo"] != nil {
-				projectInfo := qu.ObjToMap(infos["projectinfo"])
-				if projectInfo != nil && len(*projectInfo) > 0 {
-					if (*projectInfo)["attachments"] != nil {
-						filesArr := []map[string]interface{}{}
-						fileUrl := Sysconfig.FileUrl
-						if attachments, oks := (*projectInfo)["attachments"].(map[string]interface{}); oks {
-							for _, v := range attachments {
-								if atta, ok := v.(map[string]interface{}); ok {
-									if atta["fid"] != nil && qu.ObjToString(atta["fid"]) != "" {
-										fileMap := map[string]interface{}{
-											"filename": atta["filename"],
-											"url":      fileUrl + qu.ObjToString(atta["fid"]),
-										}
-										filesArr = append(filesArr, fileMap)
-									} else {
-										if atta["org_url"] != nil {
-											fileMap := map[string]interface{}{
-												"filename": atta["filename"],
-												"url":      qu.ObjToString(atta["org_url"]),
-											}
-											filesArr = append(filesArr, fileMap)
-										}
-									}
-								}
-							}
-						}
-						log.Println("查询附件结果:", id, "附件数量:", len(filesArr))
-						if len(filesArr) > 0 {
-							if FilterFilehrefAppidMap[appid] {
-								filesArrs := []map[string]interface{}{}
-								for _, v := range filesArr {
-									url := qu.ObjToString(v["url"])
-									if strings.Contains(url, "jy-datafile.oss-cn-beijing.aliyuncs.com") {
-										filesArrs = append(filesArrs, v)
-									}
-								}
-								if len(filesArrs) > 0 {
-									tmp["filehref"] = filesArrs
-								}
-							} else {
-								tmp["filehref"] = filesArr
-							}
-						}
-					}
-				}
+		siteStr := "中国招标与采购网,元博网,马克数据网,标800,优质采,山西省政府采购电子卖场,陕西省政府采购电子卖场,中国电子科技集团有限公司电子采购平台"
+		site := qu.ObjToString(tmp["site"])
+		for _, s := range strings.Split(siteStr, ",") {
+			if s == site {
+				tmp["href"] = tmp["competehref"]
 			}
-			tmp["details"] = qu.ObjToString(info["detail"])
-			tmp["bidtype"] = qu.ObjToString(info["bidtype"])
-			tmp["owner"] = qu.ObjToString(info["owner"])
-			tmp["total_investment"] = qu.ObjToString(info["total_investment"])
-			tmp["approvestatus"] = qu.ObjToString(info["approvestatus"])
-			tmp["approvetime"] = qu.ObjToString(info["approvetime"])
-			tmp["project_completedate"] = qu.Int64All(info["project_completedate"])
 		}
 	}
 	if FilterOwnerMap[appid] {