zhangjinkun 6 سال پیش
والد
کامیت
7a577adcc2
3فایلهای تغییر یافته به همراه57 افزوده شده و 38 حذف شده
  1. 14 14
      udpprojectset/src/main.go
  2. 33 24
      udpprojectset/src/projectmeger.go
  3. 10 0
      udpprojectset/src/thisinfo.go

+ 14 - 14
udpprojectset/src/main.go

@@ -214,23 +214,23 @@ func task(data []byte, mapInfo map[string]interface{}) {
 			log.Println("checkid err", err.Error())
 		}
 		if !b {
-			thisinfo := PreThisInfo(tmp)
-			if thisinfo != nil {
-				lockPNCBMap(thisinfo)
-				wg.Add(1)
-				idmap.Store(tmp["_id"], true) //增加判重逻辑,重复id不再生成
-				MultiThread <- true
-				go func(tmp map[string]interface{}, thisid string, info *Info) {
-					defer func() {
-						<-MultiThread
-						wg.Done()
-						idmap.Delete(tmp["_id"])
-					}()
+			wg.Add(1)
+			idmap.Store(tmp["_id"], true) //增加判重逻辑,重复id不再生成
+			MultiThread <- true
+			go func(tmp map[string]interface{}, thisid string) {
+				defer func() {
+					<-MultiThread
+					wg.Done()
+					idmap.Delete(tmp["_id"])
+				}()
+				info := PreThisInfo(tmp)
+				if info != nil {
+					lockPNCBMap(info)
 					startProjectMerge(info, tmp)
 					redis.Put(INFOID, thisid, 1, INFOTIMEOUT)
 					unlockPNCBMap(info)
-				}(tmp, thisid, thisinfo)
-			}
+				}
+			}(tmp, thisid)
 		}
 		if count%500 == 0 {
 			log.Println("count:", count)

+ 33 - 24
udpprojectset/src/projectmeger.go

@@ -73,6 +73,9 @@ func startProjectMerge(thisinfo *Info, tmp map[string]interface{}) {
 	}
 	//合并流程
 	if bNormalScore {
+		PNKeyMap.Store(thisinfo.PNKey, true)
+		PBKeyMap.Store(thisinfo.PBKey, true)
+		PCKeyMap.Store(thisinfo.PCKey, true)
 		if pcbv.Buyer { //有采购单位
 			hasBuyer(pcbv, thisinfo, tmp)
 		} else { //无采购单位
@@ -99,11 +102,15 @@ func checkInfoAlter(tmp map[string]interface{} /*新信息*/) bool {
 
 //有采购单位
 func hasBuyer(p PCBV, thisinfo *Info, tmp map[string]interface{}) {
+	var pncb []*CompareInfo
+	var res []interface{}
 	sflag := ""
 	pici := time.Now().Unix()
 	if p.Pname || p.Pcode { //有项目名称或项目编号
+		//获取对比项目数组
+		res, pncb = getComeperProjects(p, thisinfo)
 		//三选二打分
-		scores, pncb := score3Select2(p, thisinfo, tmp)
+		scores := score3Select2(p, thisinfo, tmp, res, pncb)
 		//项目合并
 		sflag = mergeProject(tmp, thisinfo, scores, pncb)
 	} else {
@@ -121,18 +128,22 @@ func hasBuyer(p PCBV, thisinfo *Info, tmp map[string]interface{}) {
 
 //无采购单位
 func noBuyer(p PCBV, thisinfo *Info, tmp map[string]interface{}) {
+	var pncb []*CompareInfo
+	var res []interface{}
 	sflag := ""
 	pici := time.Now().Unix()
 	if p.Pname { //有项目名称
+		//获取对比项目数组
+		res, pncb = getComeperProjects(p, thisinfo)
 		if p.Pcode { //有项目编号
 			//三选二打分
-			scores, pncb := score3Select2(p, thisinfo, tmp)
+			scores := score3Select2(p, thisinfo, tmp, res, pncb)
 			//项目合并
 			sflag = mergeProject(tmp, thisinfo, scores, pncb)
 		} else { //无项目编号
 			if p.PnameLen > MegerFieldsLen.ProjectNamelen {
 				//三选一打分
-				scores, pncb := score3Select1(p, thisinfo, tmp)
+				scores := score3Select1(p, thisinfo, tmp, res, pncb)
 				//项目合并
 				sflag = mergeProject(tmp, thisinfo, scores, pncb)
 			} else {
@@ -147,10 +158,12 @@ func noBuyer(p PCBV, thisinfo *Info, tmp map[string]interface{}) {
 		}
 	} else { //无项目名称
 		if p.Pcode {
+			//获取对比项目数组
+			res, pncb = getComeperProjects(p, thisinfo)
 			if p.PcodeLen > MegerFieldsLen.ProjectCodelen {
 				if p.Area && p.City && p.Agency { //有省市代理机构
 					//三选一打分
-					scores, pncb := score3Select1(p, thisinfo, tmp)
+					scores := score3Select1(p, thisinfo, tmp, res, pncb)
 					//项目合并
 					sflag = mergeProject(tmp, thisinfo, scores, pncb)
 				} else {
@@ -181,12 +194,10 @@ func noBuyer(p PCBV, thisinfo *Info, tmp map[string]interface{}) {
 }
 
 //3选2打分
-func score3Select2(p PCBV, thisinfo *Info, tmp map[string]interface{}) (scores []*CompareOne, pncb []*CompareInfo) {
+func score3Select2(p PCBV, thisinfo *Info, tmp map[string]interface{}, res []interface{}, pncb []*CompareInfo) (scores []*CompareOne) {
 	defer qu.Catch()
-	res := []interface{}{}
-	res, pncb = getComeperProjects(p, thisinfo) //获取对比项目数组
-	//对比打分
-	if len(res) > 0 { //找到项目名称、项目编号或采购单位相同时
+	if len(res) > 0 {
+		//对比打分
 		for k, tmps := range res { //遍历对象数组
 			if tmp, ok := tmps.([]interface{}); ok {
 				for _, b1 := range tmp {
@@ -256,10 +267,8 @@ func score3Select2(p PCBV, thisinfo *Info, tmp map[string]interface{}) (scores [
 }
 
 //3选1打分
-func score3Select1(p PCBV, thisinfo *Info, tmp map[string]interface{}) (scores []*CompareOne, pncb []*CompareInfo) {
+func score3Select1(p PCBV, thisinfo *Info, tmp map[string]interface{}, res []interface{}, pncb []*CompareInfo) (scores []*CompareOne) {
 	defer qu.Catch()
-	res := []interface{}{}
-	res, pncb = getComeperProjects(p, thisinfo) //获取对比项目数组
 	//对比打分
 	if len(res) > 0 { //找到项目名称、项目编号或采购单位相同时
 		for k, tmps := range res { //遍历对象数组
@@ -399,8 +408,12 @@ func getComeperProjects(p PCBV, thisinfo *Info) (res []interface{}, pncb []*Comp
 }
 
 //合并项目
-func mergeProject(tmp map[string]interface{}, thisinfo *Info, scores []*CompareOne, pncb []*CompareInfo) string {
-	id, sflag := "", ""
+func mergeProject(tmp map[string]interface{}, thisinfo *Info, scores []*CompareOne, pncb []*CompareInfo) (sflag string) {
+	var id = ""
+	//分值排序
+	sort.Slice(scores, func(i, j int) bool {
+		return scores[i].Score > scores[j].Score
+	})
 	if len(scores) > 0 {
 		//分值排序
 		sort.Slice(scores, func(i, j int) bool {
@@ -429,19 +442,18 @@ func mergeProject(tmp map[string]interface{}, thisinfo *Info, scores []*CompareO
 		}
 		id = newProject(tmp, mess, time.Now().Unix(), thisinfo)
 	}
-	if id != "" {
-		//更新REDISKEYS redis
-		PUT := []interface{}{}
+	if id != "" { //更新REDISKEYS redis
+		put := []interface{}{}
 		for _, pv := range pncb {
 			if pv != nil && !pv.Bfind {
 				if BinarySearch(*pv.K.Arr, id) == -1 {
 					*(pv.K.Arr) = append(*(pv.K.Arr), id)
-					PUT = append(PUT, []interface{}{pv.Key, *(pv.K.Arr)})
+					put = append(put, []interface{}{pv.Key, *(pv.K.Arr)})
 				}
 			}
 		}
-		if len(PUT) > 0 {
-			redis.BulkPut(REDISKEYS, 0, PUT...)
+		if len(put) > 0 {
+			redis.BulkPut(REDISKEYS, 0, put...)
 		}
 	}
 	return sflag
@@ -449,8 +461,7 @@ func mergeProject(tmp map[string]interface{}, thisinfo *Info, scores []*CompareO
 
 //新增项目
 func newProject(tmp, mess map[string]interface{}, pipc int64, thisinfo *Info) (id string) {
-	new_pn, _ := handleprojectname(thisinfo.ProjectName, thisinfo.Buyer, thisinfo.TopType)
-	id = InsertProject(new_pn, tmp, mess, pipc, thisinfo)
+	id = InsertProject(thisinfo.NewPNKey, tmp, mess, pipc, thisinfo)
 	sflag := qu.ObjToString(mess["meger_sflag"])
 	if sflag != "alone" {
 		p1 := NewPinfo(id, thisinfo)
@@ -550,7 +561,6 @@ func fieldPCBScore(this, info, ctype string, score int) (string, int) {
 
 //pncbMap加锁
 func lockPNCBMap(thisinfo *Info) {
-	PncbMayLock.Lock()
 	for { //等待其他任务完成
 		ok := true
 		if len(thisinfo.PNKey) > 3 {
@@ -572,7 +582,6 @@ func lockPNCBMap(thisinfo *Info) {
 			break
 		}
 	}
-	PncbMayLock.Unlock()
 }
 
 //pncbMap解锁

+ 10 - 0
udpprojectset/src/thisinfo.go

@@ -2,7 +2,10 @@
 package main
 
 import (
+	"crypto/sha1"
 	"encoding/json"
+	"fmt"
+	"io"
 	du "jy/util"
 	"qfw/util"
 	"strings"
@@ -138,3 +141,10 @@ func PreThisInfo(tmp map[string]interface{} /*新信息*/) *Info {
 	thisinfo.PBKey = "pb_" + thisinfo.Buyer
 	return thisinfo
 }
+
+//获取hascode
+func GetHas1(key string) string {
+	t := sha1.New()
+	io.WriteString(t, key)
+	return fmt.Sprintf("%x", t.Sum(nil))
+}