Browse Source

项目合并优化

zhangjinkun 6 years ago
parent
commit
076de3bc60
4 changed files with 100 additions and 69 deletions
  1. 39 31
      udpprojectset/src/compare.go
  2. 3 0
      udpprojectset/src/main.go
  3. 1 1
      udpprojectset/src/scores.go
  4. 57 37
      udpprojectset/src/thisinfo.go

+ 39 - 31
udpprojectset/src/compare.go

@@ -38,6 +38,7 @@ type ProjectInfo struct {
 	Buyertel      string                 `json:"buyertel"`
 	Agency        string                 `json:"agency"`     //代理机构唯一
 	Area          string                 `json:"area"`       //地区唯一
+	City          string                 `json:"city"`       //地市
 	HasPackage    bool                   `json:"haspackage"` //是否有分包
 	Package       map[string]interface{} `json:"package"`    //分包的对比对象
 
@@ -134,52 +135,59 @@ func Compare(tmp map[string]interface{} /*新信息*/, pici int64) (sflag string
 		}
 	}
 	IdLock.Unlock()
-	updateid := ""
+	updateid, ncid := "", ""
 	tmpArr := []*CompareOne{}
 	//三个对比对象分别和thisinfo比较,打完分的对象放入scores,合并放入tempArr
 	for _, PNCB := range []*CompareInfo{PN, PC, PB} {
 		if PNCB != nil {
 			if len(PNCB.IdArr) > 0 {
 				//PNCB.compute(thisinfo, PNCB.IdArr)
-				PNCB.ProcessInfo(new_pn, tmp, pici, thisinfo)
+				ncid = PNCB.ProcessInfo(new_pn, tmp, pici, thisinfo)
 				tmpArr = append(tmpArr, PNCB.Scores...)
 			}
 		}
 	}
-
-	//排序取出最大分值的对象,更新对象
-	if len(tmpArr) > 0 {
-		sort.Slice(tmpArr, func(i, j int) bool {
-			return tmpArr[i].Score > tmpArr[j].Score
-		})
-		max := tmpArr[0]
-		if max.Score > 0 {
-			//获取到对象
-			max.Parent.Bfind = true
-			updateid = updateinfo(thisinfo, tmp, max.Pinfo, pici)
+	if ncid == "" {
+		//排序取出最大分值的对象,更新对象
+		if len(tmpArr) > 0 {
+			sort.Slice(tmpArr, func(i, j int) bool {
+				return tmpArr[i].Score > tmpArr[j].Score
+			})
+			max := tmpArr[0]
+			if max.Score > 0 {
+				//获取到对象
+				max.Parent.Bfind = true
+				tmp["cresult"] = max.Cresult
+				updateid = updateinfo(thisinfo, tmp, max.Pinfo, pici)
+				//log.Println("更新项目", updateid)
+			}
+		}
+		if updateid == "" {
+			sflag = "normal"
+			updateid = InsertProject(new_pn, tmp, nil, pici, thisinfo)
+			p1 := NewPinfo(updateid, thisinfo)
+			redis.PutCKV(REDISIDS, updateid, p1)
+			//log.Println("生成项目", updateid)
+		} else {
 			sflag = "repeat"
 		}
-	} else {
-		sflag = "normal"
-		updateid = InsertProject(new_pn, tmp, nil, pici, thisinfo)
-		p1 := NewPinfo(updateid, thisinfo)
-		redis.PutCKV(REDISIDS, updateid, p1)
-	}
-	//更新redis中存入的三大map对象中的id
-	if updateid != "" {
-		PUT := []interface{}{}
-		for _, PNCB := range []*CompareInfo{PN, PC, PB} {
-			if PNCB != nil && !PNCB.Bfind {
-				if BinarySearch(*PNCB.K.Arr, updateid) == -1 {
-					*(PNCB.K.Arr) = append(*(PNCB.K.Arr), updateid)
-					PUT = append(PUT, []interface{}{PNCB.Key, *(PNCB.K.Arr)})
-					log.Println(PUT)
+		//更新redis中存入的三大map对象中的id
+		if updateid != "" {
+			PUT := []interface{}{}
+			for _, PNCB := range []*CompareInfo{PN, PC, PB} {
+				if PNCB != nil && !PNCB.Bfind {
+					if BinarySearch(*PNCB.K.Arr, updateid) == -1 {
+						*(PNCB.K.Arr) = append(*(PNCB.K.Arr), updateid)
+						PUT = append(PUT, []interface{}{PNCB.Key, *(PNCB.K.Arr)})
+					}
 				}
 			}
+			if len(PUT) > 0 {
+				redis.BulkPut(REDISKEYS, 0, PUT...)
+			}
 		}
-		if len(PUT) > 0 {
-			redis.BulkPut(REDISKEYS, 0, PUT...)
-		}
+	} else {
+		log.Println("无效项目", ncid)
 	}
 	return
 }

+ 3 - 0
udpprojectset/src/main.go

@@ -280,5 +280,8 @@ func NewPushInfo(tmp map[string]interface{}) bson.M {
 		"infoformat":  tmp["infoformat"],
 		"infoid":      util.BsonIdToSId(tmp["_id"]),
 		"href":        tmp["href"],
+		"area":        tmp["area"],
+		"city":        tmp["city"],
+		"cresult":     tmp["cresult"],
 	}
 }

+ 1 - 1
udpprojectset/src/scores.go

@@ -175,7 +175,7 @@ func (com *CompareInfo) ComputeTow(thisinfo *Info, ids []string, hasbyer bool) [
 				}
 				//省市打分
 				if thisinfo.Area != "A" && thisinfo.Area != "全国" && info.Area != "A" && info.Area != "全国" {
-					if thisinfo.Area == info.Area && thisinfo.District == info.District {
+					if thisinfo.Area == info.Area && thisinfo.City == info.City {
 						cone.Score += 2
 					} else {
 						cone.Score -= 1

+ 57 - 37
udpprojectset/src/thisinfo.go

@@ -5,6 +5,7 @@ import (
 	"encoding/json"
 	"fmt"
 	du "jy/util"
+	"log"
 	"qfw/util"
 	"strings"
 
@@ -26,6 +27,7 @@ type Info struct {
 	Buyertel      string                 `json:"buyertel"`
 	Agency        string                 `json:"agency"`
 	Area          string                 `json:"area"`
+	City          string                 `json:"city"`
 	HasPackage    bool                   `json:"haspackage"`
 	Package       map[string]interface{} `json:"package"`
 	PNum          string                 `json:"pnum"`
@@ -42,13 +44,13 @@ type Info struct {
 
 //pcb三选值
 type PCBV struct {
-	Val      int  //1一项有效值,2二项有效值,3三项有效值
-	Pname    bool //有项目名称
-	Cname    bool //有项目编号
-	Bname    bool //有采购单位
-	Area     bool //区域
-	District bool //市县
-	Agency   bool //代理机构
+	Val    int  //1一项有效值,2二项有效值,3三项有效值
+	Pname  bool //有项目名称
+	Cname  bool //有项目编号
+	Bname  bool //有采购单位
+	Area   bool //区域
+	City   bool //市
+	Agency bool //代理机构
 
 	PnameLen int //值长度
 	CnameLen int //值长度
@@ -77,14 +79,14 @@ func PreThisInfo(tmp map[string]interface{} /*新信息*/) *Info {
 		//当信息类型是结果时,并且标题中包含分包字样,找到包号,用以后面比较打分
 		res := TitleReg.FindAllStringSubmatch(thisinfo.Title, -1)
 		pnum := du.PackageNumberConvert(res[0][0])
-		du.Debug(pnum, res)
+		//du.Debug(pnum, res)
 		thisinfo.PNum = pnum
 	}
 	if thisinfo.SubType == "变更" || strings.Index(thisinfo.Title, "变更公告") > -1 || strings.Index(thisinfo.Title, "更正公告") > -1 {
 		//当信息类型是变更或标题中含变更时
 		if thisinfo.TopType == "招标" {
 			//招标的变更公告过,不作处理
-			du.Debug(thisinfo.Id, thisinfo.Href, thisinfo.ProjectName, thisinfo.ProjectCode)
+			//du.Debug(thisinfo.Id, thisinfo.Href, thisinfo.ProjectName, thisinfo.ProjectCode)
 			return nil
 		} else if thisinfo.TopType == "结果" {
 			thisinfo.SubType = "变更"
@@ -129,11 +131,11 @@ func PreThisInfo(tmp map[string]interface{} /*新信息*/) *Info {
 }
 
 //流程处理
-func (com *CompareInfo) ProcessInfo(new_pn string, tmp map[string]interface{}, pici int64, info *Info) {
+func (com *CompareInfo) ProcessInfo(new_pn string, tmp map[string]interface{}, pici int64, info *Info) (id string) {
 	pcbv := PCBValue(info)
 	if info.SubType == "变更" {
 		if pcbv.Val > 1 {
-			com.Process(new_pn, tmp, pici, info, pcbv)
+			id = com.Process(new_pn, tmp, pici, info, pcbv)
 		} else {
 			//信息无效
 			MQFW.UpdateById(extractColl, info.Id,
@@ -142,14 +144,16 @@ func (com *CompareInfo) ProcessInfo(new_pn string, tmp map[string]interface{}, p
 						"ext_mess": info.SubType + ",不满足三选二",
 					},
 				})
+			du.Debug("信息无效", info.Id)
 		}
 	} else { //非变更
-		com.Process(new_pn, tmp, pici, info, pcbv)
+		id = com.Process(new_pn, tmp, pici, info, pcbv)
 	}
+	return id
 }
 
 //流程
-func (com *CompareInfo) Process(new_pn string, tmp map[string]interface{}, pici int64, info *Info, pcbv PCBV) {
+func (com *CompareInfo) Process(new_pn string, tmp map[string]interface{}, pici int64, info *Info, pcbv PCBV) (id string) {
 	if pcbv.Bname { //有采购单位
 		if pcbv.Pname || pcbv.Cname {
 			//三选二打分
@@ -157,21 +161,25 @@ func (com *CompareInfo) Process(new_pn string, tmp map[string]interface{}, pici
 			for _, v := range scores {
 				skey := fmt.Sprintf("%s%s%s", v.BuyerType, v.ProjectNameType, v.ProjectCodeType)
 				if ThreeToTow[skey] { //判断是否进入打分合并逻辑
+					log.Println(info.Id, skey)
 					v.Cresult = skey
 					com.Scores = append(com.Scores, v)
-				} else {
-					//新建项目,(Compare方法中创建)不在此创建,其他同理
 				}
 			}
+			if len(scores) < 1 {
+				//新建项目,(Compare方法中创建)不在此创建,其他同理
+				//du.Debug("有采购单位,新建项目")
+			}
 		} else {
 			//生成项目,不参与后续对比
-			InsertProject(new_pn, tmp,
+			id = InsertProject(new_pn, tmp,
 				map[string]interface{}{
 					"ext_mess": map[string]interface{}{
-						"type": "采购单位,不满足三选二",
-						"mess": "省市不存在",
+						"type": "采购单位,不满足三选二",
+						"mess": "项目名称或项目编号不满足",
 					},
 				}, pici, info)
+			//du.Debug("生成项目,不参与后续对比", id)
 		}
 	} else { //无采购单位
 		if pcbv.Pname {
@@ -183,13 +191,15 @@ func (com *CompareInfo) Process(new_pn string, tmp map[string]interface{}, pici
 					if ThreeToTow[skey] { //判断是否进入打分合并逻辑
 						v.Cresult = skey
 						com.Scores = append(com.Scores, v)
-					} else {
-						//新建项目
 					}
 				}
+				if len(scores) < 1 {
+					//新建项目
+					//du.Debug("无采购单位,新建项目")
+				}
 			} else {
 				if pcbv.PnameLen > 5 {
-					if pcbv.Area && pcbv.District {
+					if pcbv.Area && pcbv.City {
 						//三选一打分
 						scores := com.ComputeOne(info, com.IdArr)
 						for _, v := range scores { // v.ProjectNameType, v.ProjectCodeType二者有其一
@@ -197,35 +207,39 @@ func (com *CompareInfo) Process(new_pn string, tmp map[string]interface{}, pici
 							if ThreeToOne[skey] { //判断是否进入打分合并逻辑
 								v.Cresult = skey
 								com.Scores = append(com.Scores, v)
-							} else {
-								//新建项目
 							}
 						}
+						if len(scores) < 1 {
+							//新建项目
+							du.Debug("新建项目")
+						}
 					} else {
 						//生成项目,不参与后续对比
-						InsertProject(new_pn, tmp,
+						id = InsertProject(new_pn, tmp,
 							map[string]interface{}{
 								"ext_mess": map[string]interface{}{
 									"type": "无采购单位,不满足三选一",
-									"mess": "省市不存在",
+									"mess": "省市不满足",
 								},
 							},
 							pici, info)
+						//du.Debug("生成项目,不参与后续对比", id)
 					}
 				} else {
 					//生成项目,不参与后续对比
-					InsertProject(new_pn, tmp,
+					id = InsertProject(new_pn, tmp,
 						map[string]interface{}{"ext_mess": map[string]interface{}{
 							"type": "无采购单位,不满足三选一",
-							"mess": "项目名小于等于5",
+							"mess": "项目名称不满足",
 						},
 						}, pici, info)
+					//du.Debug("生成项目,不参与后续对比", id)
 				}
 			}
 		} else {
 			if pcbv.Cname {
 				if pcbv.CnameLen > 8 {
-					if pcbv.Area && pcbv.District {
+					if pcbv.Area && pcbv.City {
 						//三选一打分
 						scores := com.ComputeOne(info, com.IdArr)
 						for _, v := range scores { // v.ProjectNameType, v.ProjectCodeType二者有其一
@@ -233,29 +247,33 @@ func (com *CompareInfo) Process(new_pn string, tmp map[string]interface{}, pici
 							if ThreeToOne[skey] { //判断是否进入打分合并逻辑
 								v.Cresult = skey
 								com.Scores = append(com.Scores, v)
-							} else {
-								//新建项目
 							}
 						}
+						if len(scores) < 1 {
+							//新建项目
+							//du.Debug("无采购单位,新建项目")
+						}
 					} else {
 						//生成项目,不参与后续对比
-						InsertProject(new_pn, tmp,
+						id = InsertProject(new_pn, tmp,
 							map[string]interface{}{
 								"ext_mess": map[string]interface{}{
 									"type": "无采购单位,不满足三选一",
-									"mess": "省市不存在",
+									"mess": "省市不满足",
 								},
 							}, pici, info)
+						//du.Debug("生成项目,不参与后续对比", id)
 					}
 				} else {
 					//生成项目,不参与后续对比
-					InsertProject(new_pn, tmp,
+					id = InsertProject(new_pn, tmp,
 						map[string]interface{}{
 							"ext_mess": map[string]interface{}{
 								"type": "无采购单位,不满足三选一",
-								"mess": "项目编号长度小于等于8",
+								"mess": "项目编号不满足",
 							},
 						}, pici, info)
+					//du.Debug("生成项目,不参与后续对比", id)
 				}
 			} else {
 				//信息无效
@@ -265,9 +283,11 @@ func (com *CompareInfo) Process(new_pn string, tmp map[string]interface{}, pici
 							"ext_mess": info.SubType + ",不满足三选一",
 						},
 					})
+				//du.Debug("信息无效", info.Id)
 			}
 		}
 	}
+	return id
 }
 func PCBValue(info *Info) PCBV {
 	pcbv := PCBV{}
@@ -288,12 +308,12 @@ func PCBValue(info *Info) PCBV {
 		pcbv.Bname = true
 		pcbv.BnameLen = len([]rune(info.Buyer))
 	}
-	//省市/县代理机构
+	//省市代理机构
 	if info.Area != "" {
 		pcbv.Area = true
 	}
-	if info.District != "" {
-		pcbv.District = true
+	if info.City != "" {
+		pcbv.City = true
 	}
 	if info.Agency != "" {
 		pcbv.Agency = true