Browse Source

项目何必打分

zhangjinkun 6 years ago
parent
commit
3e7053c226

+ 1 - 3
udpprojectset/src/cleareids.go

@@ -84,15 +84,13 @@ func clearIdsKeys(pKey *KeyMap, nowtime int64) []string {
 			for _, id := range delids {
 				ids = deleteSliceId(*ids, id.(string))
 			}
-			log.Println(ids, *ma.Arr)
+			//log.Println(ids, *ma.Arr)
 			ma.Arr = ids
 			if len(*ma.Arr) < 1 {
 				redis.Del(REDISKEYS, k)
 				delkey = append(delkey, k)
 			} else {
 				//更新REDISKEYS
-				l := redis.Get(REDISKEYS, k)
-				log.Println(l, k, *ma.Arr)
 				redis.Put(REDISKEYS, k, *ma.Arr, 0)
 			}
 		}

+ 15 - 10
udpprojectset/src/compare.go

@@ -1,6 +1,7 @@
 package main
 
 import (
+	"log"
 	"qfw/util"
 	"qfw/util/redis"
 	"regexp"
@@ -58,6 +59,8 @@ type CompareOne struct {
 	Parent          *CompareInfo
 	Pinfo           *ProjectInfo
 	Pos             int
+
+	Cresult string //对比结果
 }
 
 type CompareInfo struct {
@@ -131,21 +134,20 @@ func Compare(tmp map[string]interface{} /*新信息*/, pici int64) (sflag string
 		}
 	}
 	IdLock.Unlock()
-
+	updateid := ""
 	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(thisinfo)
+				PNCB.ProcessInfo(new_pn, tmp, pici, thisinfo)
 				tmpArr = append(tmpArr, PNCB.Scores...)
 			}
 		}
 	}
 
 	//排序取出最大分值的对象,更新对象
-	updateid := ""
 	if len(tmpArr) > 0 {
 		sort.Slice(tmpArr, func(i, j int) bool {
 			return tmpArr[i].Score > tmpArr[j].Score
@@ -155,16 +157,13 @@ func Compare(tmp map[string]interface{} /*新信息*/, pici int64) (sflag string
 			//获取到对象
 			max.Parent.Bfind = true
 			updateid = updateinfo(thisinfo, tmp, max.Pinfo, pici)
+			sflag = "repeat"
 		}
-	}
-
-	if updateid == "" {
+	} else {
 		sflag = "normal"
-		updateid = InsertProject(new_pn, tmp, pici, thisinfo)
+		updateid = InsertProject(new_pn, tmp, nil, pici, thisinfo)
 		p1 := NewPinfo(updateid, thisinfo)
 		redis.PutCKV(REDISIDS, updateid, p1)
-	} else {
-		sflag = "repeat"
 	}
 	//更新redis中存入的三大map对象中的id
 	if updateid != "" {
@@ -174,6 +173,7 @@ func Compare(tmp map[string]interface{} /*新信息*/, pici int64) (sflag string
 				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)
 				}
 			}
 		}
@@ -185,7 +185,7 @@ func Compare(tmp map[string]interface{} /*新信息*/, pici int64) (sflag string
 }
 
 //没有在redis中查找到,新增项目
-func InsertProject(new_pn string, tmp map[string]interface{}, pici int64, thisinfo *Info) string {
+func InsertProject(new_pn string, tmp, mess map[string]interface{}, pici int64, thisinfo *Info) string {
 	e := InitEL("")
 	set := map[string]interface{}{
 		"pici": pici,
@@ -238,6 +238,11 @@ func InsertProject(new_pn string, tmp map[string]interface{}, pici int64, thisin
 	set["list"] = []bson.M{
 		push,
 	}
+	if mess != nil { //不参与对比项目标识
+		for k, v := range mess {
+			set[k] = v
+		}
+	}
 	return MQFW.Save(projectColl, set)
 }
 

+ 15 - 14
udpprojectset/src/scores.go

@@ -19,7 +19,7 @@ func init() {
 		"AAA": true,
 		"AAB": true,
 	}
-	twos := [][][]string{
+	tows := [][][]string{
 		[][]string{
 			[]string{"A", "B"},
 			[]string{"A", "B"},
@@ -41,10 +41,10 @@ func init() {
 			[]string{"A", "B"},
 		},
 	}
-	for _, two := range twos {
-		for _, v1 := range two[0] {
-			for _, v2 := range two[1] {
-				for _, v3 := range two[2] {
+	for _, tow := range tows {
+		for _, v1 := range tow[0] {
+			for _, v2 := range tow[1] {
+				for _, v3 := range tow[2] {
 					key := fmt.Sprintf("%s%s%s", v1, v2, v3)
 					ThreeToTow[key] = true
 				}
@@ -141,7 +141,7 @@ func (com *CompareInfo) ComputeOne(thisinfo *Info, ids []string) []*CompareOne {
 }
 
 //三选二打分
-func (com *CompareInfo) ComputeTwo(thisinfo *Info, ids []string, hasbyer bool) []*CompareOne {
+func (com *CompareInfo) ComputeTow(thisinfo *Info, ids []string, hasbyer bool) []*CompareOne {
 	defer util.Catch()
 	res := redis.Mget(REDISIDS, ids)
 	scores := []*CompareOne{}
@@ -157,20 +157,20 @@ func (com *CompareInfo) ComputeTwo(thisinfo *Info, ids []string, hasbyer bool) [
 					Parent: com,
 					Pinfo:  &info,
 				}
-				fieldPCBScore(thisinfo.Buyer, info.Buyer, cone.BuyerType, cone.Score)
+				cone.BuyerType, cone.Score = fieldPCBScore(thisinfo.Buyer, info.Buyer, cone.BuyerType, cone.Score)
 				if hasbyer {
-					fieldPCBScore(thisinfo.ProjectName, info.ProjectName, cone.ProjectNameType, cone.Score)
-					fieldPCBScore(thisinfo.ProjectCode, info.ProjectCode, cone.ProjectCodeType, cone.Score)
+					cone.ProjectNameType, cone.Score = fieldPCBScore(thisinfo.ProjectName, info.ProjectName, cone.ProjectNameType, cone.Score)
+					cone.ProjectCodeType, cone.Score = fieldPCBScore(thisinfo.ProjectCode, info.ProjectCode, cone.ProjectCodeType, cone.Score)
 				} else { //无采购单位,打分考虑长度
 					if len([]rune(thisinfo.ProjectName)) > 5 {
-						fieldPCBScore(thisinfo.ProjectName, info.ProjectName, cone.ProjectNameType, cone.Score)
+						cone.ProjectNameType, cone.Score = fieldPCBScore(thisinfo.ProjectName, info.ProjectName, cone.ProjectNameType, cone.Score)
 					} else {
 						cone.ProjectNameType = "D"
 					}
-					if len([]rune(thisinfo.ProjectName)) > 6 {
-						fieldPCBScore(thisinfo.ProjectCode, info.ProjectCode, cone.ProjectCodeType, cone.Score)
+					if len(thisinfo.ProjectCode) > 6 {
+						cone.ProjectCodeType, cone.Score = fieldPCBScore(thisinfo.ProjectCode, info.ProjectCode, cone.ProjectCodeType, cone.Score)
 					} else {
-						cone.ProjectNameType = "D"
+						cone.ProjectCodeType = "D"
 					}
 				}
 				//省市打分
@@ -207,7 +207,7 @@ func (com *CompareInfo) ComputeTwo(thisinfo *Info, ids []string, hasbyer bool) [
 }
 
 //项目名称、项目编号、采购单位打分
-func fieldPCBScore(this, info, ctype string, score int) {
+func fieldPCBScore(this, info, ctype string, score int) (string, int) {
 	if len(info) > 0 {
 		if this == info { //A
 			score += 5
@@ -227,4 +227,5 @@ func fieldPCBScore(this, info, ctype string, score int) {
 	} else { //D不计分
 		ctype = "D"
 	}
+	return ctype, score
 }

+ 65 - 6
udpprojectset/src/thisinfo.go

@@ -129,43 +129,62 @@ func PreThisInfo(tmp map[string]interface{} /*新信息*/) *Info {
 }
 
 //流程处理
-func (com *CompareInfo) ProcessInfo(info *Info) {
+func (com *CompareInfo) ProcessInfo(new_pn string, tmp map[string]interface{}, pici int64, info *Info) {
 	pcbv := PCBValue(info)
 	if info.SubType == "变更" {
 		if pcbv.Val > 1 {
-			com.Process(info, pcbv)
+			com.Process(new_pn, tmp, pici, info, pcbv)
 		} else {
 			//信息无效
+			MQFW.UpdateById(extractColl, info.Id,
+				map[string]interface{}{
+					"$set": map[string]interface{}{
+						"ext_mess": info.SubType + ",不满足三选二",
+					},
+				})
 		}
 	} else { //非变更
-		com.Process(info, pcbv)
+		com.Process(new_pn, tmp, pici, info, pcbv)
 	}
 }
 
 //流程
-func (com *CompareInfo) Process(info *Info, pcbv PCBV) {
+func (com *CompareInfo) Process(new_pn string, tmp map[string]interface{}, pici int64, info *Info, pcbv PCBV) {
 	if pcbv.Bname { //有采购单位
 		if pcbv.Pname || pcbv.Cname {
 			//三选二打分
-			scores := com.ComputeTwo(info, com.IdArr, true)
+			scores := com.ComputeTow(info, com.IdArr, true)
 			for _, v := range scores {
 				skey := fmt.Sprintf("%s%s%s", v.BuyerType, v.ProjectNameType, v.ProjectCodeType)
 				if ThreeToTow[skey] { //判断是否进入打分合并逻辑
+					v.Cresult = skey
 					com.Scores = append(com.Scores, v)
+				} else {
+					//新建项目,(Compare方法中创建)不在此创建,其他同理
 				}
 			}
 		} else {
 			//生成项目,不参与后续对比
+			InsertProject(new_pn, tmp,
+				map[string]interface{}{
+					"ext_mess": map[string]interface{}{
+						"type": "无采购单位,不满足三选二",
+						"mess": "省市不存在",
+					},
+				}, pici, info)
 		}
 	} else { //无采购单位
 		if pcbv.Pname {
 			if pcbv.Cname {
 				//三选二打分
-				scores := com.ComputeTwo(info, com.IdArr, false)
+				scores := com.ComputeTow(info, com.IdArr, false)
 				for _, v := range scores {
 					skey := fmt.Sprintf("%s%s%s", v.BuyerType, v.ProjectNameType, v.ProjectCodeType)
 					if ThreeToTow[skey] { //判断是否进入打分合并逻辑
+						v.Cresult = skey
 						com.Scores = append(com.Scores, v)
+					} else {
+						//新建项目
 					}
 				}
 			} else {
@@ -176,14 +195,31 @@ func (com *CompareInfo) Process(info *Info, pcbv PCBV) {
 						for _, v := range scores { // v.ProjectNameType, v.ProjectCodeType二者有其一
 							skey := fmt.Sprintf("%s%s%s%s", v.ProjectNameType, v.ProjectCodeType, v.AreaType, v.AgencyType)
 							if ThreeToOne[skey] { //判断是否进入打分合并逻辑
+								v.Cresult = skey
 								com.Scores = append(com.Scores, v)
+							} else {
+								//新建项目
 							}
 						}
 					} else {
 						//生成项目,不参与后续对比
+						InsertProject(new_pn, tmp,
+							map[string]interface{}{
+								"ext_mess": map[string]interface{}{
+									"type": "无采购单位,不满足三选一",
+									"mess": "省市不存在",
+								},
+							},
+							pici, info)
 					}
 				} else {
 					//生成项目,不参与后续对比
+					InsertProject(new_pn, tmp,
+						map[string]interface{}{"ext_mess": map[string]interface{}{
+							"type": "无采购单位,不满足三选一",
+							"mess": "项目名小于等于5",
+						},
+						}, pici, info)
 				}
 			}
 		} else {
@@ -195,17 +231,40 @@ func (com *CompareInfo) Process(info *Info, pcbv PCBV) {
 						for _, v := range scores { // v.ProjectNameType, v.ProjectCodeType二者有其一
 							skey := fmt.Sprintf("%s%s%s%s", v.ProjectNameType, v.ProjectCodeType, v.AreaType, v.AgencyType)
 							if ThreeToOne[skey] { //判断是否进入打分合并逻辑
+								v.Cresult = skey
 								com.Scores = append(com.Scores, v)
+							} else {
+								//新建项目
 							}
 						}
 					} else {
 						//生成项目,不参与后续对比
+						InsertProject(new_pn, tmp,
+							map[string]interface{}{
+								"ext_mess": map[string]interface{}{
+									"type": "无采购单位,不满足三选一",
+									"mess": "省市不存在",
+								},
+							}, pici, info)
 					}
 				} else {
 					//生成项目,不参与后续对比
+					InsertProject(new_pn, tmp,
+						map[string]interface{}{
+							"ext_mess": map[string]interface{}{
+								"type": "无采购单位,不满足三选一",
+								"mess": "项目编号长度小于等于8",
+							},
+						}, pici, info)
 				}
 			} else {
 				//信息无效
+				MQFW.UpdateById(extractColl, info.Id,
+					map[string]interface{}{
+						"$set": map[string]interface{}{
+							"ext_mess": info.SubType + ",不满足三选一",
+						},
+					})
 			}
 		}
 	}