Jianghan 2 жил өмнө
parent
commit
bfe29f61c7

+ 46 - 19
fullproject/src_v1/load_data.go

@@ -5,6 +5,8 @@ import (
 	"log"
 	"qfw/util"
 	"qfw/util/redis"
+	"strings"
+	"sync"
 	"time"
 )
 
@@ -13,17 +15,15 @@ func (p *ProjectTask) loadData(starttime int64) {
 	log.Println("load project start..", starttime)
 	p.findLock.Lock()
 	defer p.findLock.Unlock()
-	p.AllIdsMapLock.Lock()
-	defer p.AllIdsMapLock.Unlock()
 	sess := MongoTool.GetMgoConn()
 	defer MongoTool.DestoryMongoConn(sess)
 	loadOver := make(chan bool)
 	q := map[string]interface{}{
 		"lasttime": map[string]interface{}{"$gte": starttime},
 	}
-	//field := map[string]interface{}{"list": 0}
-	it := sess.DB(MongoTool.DbName).C(p.coll).Find(&q).Select(nil).Iter()
-	n := 0
+	field := map[string]interface{}{"list": 0}
+	it := sess.DB(MongoTool.DbName).C(p.coll).Find(&q).Select(field).Iter()
+	n, count := 0, 0
 	pool := make(chan *ProjectCache, 1000)
 	go func() {
 		for {
@@ -72,29 +72,40 @@ func (p *ProjectTask) loadData(starttime int64) {
 							k.Arr = append(k.Arr, id)
 						}
 					}
+
+					p.AllIdsMapLock.Lock()
 					p.AllIdsMap[id] = &ID{Id: id, P: tmp}
+					p.AllIdsMapLock.Unlock()
 				}
 			case <-loadOver:
 				return
 			}
 		}
 	}()
-	for {
-		result := make(map[string]interface{})
-		if it.Next(&result) {
-			go func(res map[string]interface{}) {
-				bys, _ := json.Marshal(result)
 
-				var tmp *ProjectCache
-				_ = json.Unmarshal(bys, &tmp)
-				saveFiled(p, result, tmp)
-				redis.PutCKV("project", tmp.Id.Hex(), result)
-				pool <- tmp
-			}(result)
-		} else {
-			break
-		}
+	ch := make(chan bool, 3)
+	wg := &sync.WaitGroup{}
+	for tmp := make(map[string]interface{}); it.Next(tmp); count++ {
+		//if count%20000 == 0 {
+		//	log.Println(fmt.Sprintf("iter --- %d", count))
+		//}
+		ch <- true
+		wg.Add(1)
+		go func(tmp map[string]interface{}) {
+			defer func() {
+				<-ch
+				wg.Done()
+			}()
+			bys, _ := json.Marshal(tmp)
+			var pc *ProjectCache
+			_ = json.Unmarshal(bys, &pc)
+			saveFiled(p, tmp, pc)
+			redis.PutCKV("project", pc.Id.Hex(), tmp)
+			pool <- pc
+		}(tmp)
+		tmp = make(map[string]interface{})
 	}
+	wg.Wait()
 	time.Sleep(2 * time.Second)
 	loadOver <- true
 	log.Println("load project over..", n)
@@ -153,6 +164,22 @@ func saveFiled(p *ProjectTask, res map[string]interface{}, tmp *ProjectCache) {
 		p.mapHref[proHref] = tmp.Id.Hex()
 		p.mapHrefLock.Unlock()
 	}
+	if res["entidlist"] != nil {
+		elist := util.ObjArrToStringArr(res["entidlist"].([]interface{}))
+		wlist := strings.Split(util.ObjToString(res["s_winner"]), ",")
+		buyer := util.ObjToString(res["buyer"])
+		if len(elist) == len(wlist) && buyer != "" {
+			for i, eid := range elist {
+				if eid != "-" {
+					text := buyer + "," + wlist[i]
+					ex, _ := redis.Exists(RedisCode, text)
+					if !ex {
+						redis.PutCKV(RedisCode, text, tmp.Id.Hex())
+					}
+				}
+			}
+		}
+	}
 
 	//tmpMap := make(map[string]InfoField)
 	//infoMap := res["infofield"].(map[string]interface{})

+ 36 - 12
fullproject/src_v1/project.go

@@ -616,9 +616,14 @@ func (p *ProjectTask) NewProject(tmp map[string]interface{}, thisinfo *Info) (st
 			set["sortprice"] = p1.Budget
 		}
 	}
+	if tmp["bid_field"] != nil {
+		set["bid_field"] = tmp["bid_field"]
+	}
 	redis.PutCKV("project", thisinfo.Id, set)
 	push := p.PushListInfo(tmp, thisinfo.Id)
-	push["s_winner"] = strings.Join(thisinfo.Winners, ",")
+	if len(thisinfo.Winners) > 0 {
+		push["s_winner"] = strings.Join(thisinfo.Winners, ",")
+	}
 	set["list"] = []bson.M{
 		push,
 	}
@@ -949,23 +954,38 @@ func (p *ProjectTask) UpdateProject(tmp map[string]interface{}, thisinfo *Info,
 	}
 
 	if len(thisinfo.Winners) > 0 {
-		if len(project.Winners) <= 0 {
+		var winners []string
+		if project.Winners == "" {
 			set["winner"] = qu.ObjToString(tmp["winner"])
-		}
-		winners := strings.Split(project.Winners, ",")
-		for _, k := range thisinfo.Winners {
-			if thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
-				if BinarySearch(winners, k) != -1 {
-					deleteSlice(winners, k, "")
+			for _, k := range thisinfo.Winners {
+				if k == "" {
+					continue
 				}
-			} else {
 				if BinarySearch(winners, k) == -1 {
 					winners = append(winners, k)
 				}
 			}
+		} else {
+			winners = strings.Split(project.Winners, ",")
+			for _, k := range thisinfo.Winners {
+				if k == "" {
+					continue
+				}
+				if thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
+					if BinarySearch(winners, k) != -1 {
+						deleteSlice(winners, k, "")
+					}
+				} else {
+					if BinarySearch(winners, k) == -1 {
+						winners = append(winners, k)
+					}
+				}
+			}
+		}
+		if len(winners) > 0 {
+			set["s_winner"] = strings.Join(qu.ObjArrToStringArr(Duplicate(winners)), ",")
 		}
 
-		set["s_winner"] = strings.Join(qu.ObjArrToStringArr(Duplicate(winners)), ",")
 	}
 
 	if len(thisinfo.EntIdList) > 0 {
@@ -1079,7 +1099,9 @@ func (p *ProjectTask) UpdateProject(tmp map[string]interface{}, thisinfo *Info,
 			set["sortprice"] = pInfo.Budget
 		}
 	}
-
+	if tmp["bid_field"] != nil {
+		set["bid_field"] = tmp["bid_field"]
+	}
 	infofield := InfoField{
 		Budget:       thisinfo.Budget,
 		Bidamount:    thisinfo.Bidamount,
@@ -1111,7 +1133,9 @@ func (p *ProjectTask) UpdateProject(tmp map[string]interface{}, thisinfo *Info,
 		update["$set"] = set
 	}
 	push := p.PushListInfo(tmp, thisinfo.Id)
-	push["s_winner"] = strings.Join(thisinfo.Winners, ",")
+	if len(thisinfo.Winners) > 0 {
+		push["s_winner"] = strings.Join(thisinfo.Winners, ",")
+	}
 	push["compareStr"] = comStr
 	push["resVal"] = pInfo.resVal
 	push["pjVal"] = pInfo.pjVal

+ 1 - 0
fullproject/src_v1/task.go

@@ -609,6 +609,7 @@ func ParseInfo(tmp map[string]interface{}) (info *Info) {
 			if tmp[d] != nil {
 				thisinfo.Publishtime = util.Int64All(tmp[d])
 				tmp["publishtime"] = tmp[d]
+				break
 			}
 		}
 	}

+ 6 - 6
fullproject/src_v1/update.go

@@ -49,7 +49,7 @@ func (p *ProjectTask) modifyUpdate(pid string, index, position int, tmpPro, modi
 }
 
 func (p *ProjectTask) mergeAndModify(pInfoId string, index, position int, tmp map[string]interface{}, tmpPro map[string]interface{}, modifyMap map[string]interface{}) {
-	proList := []interface{}(tmpPro["list"].(primitive.A))
+	proList := tmpPro["list"].([]interface{})
 	info := ParseInfo(tmp)
 	//项目中list大小等于1
 	if len(proList) == 1 {
@@ -199,12 +199,12 @@ func (p *ProjectTask) mergeAndModify(pInfoId string, index, position int, tmp ma
 // 删除
 func (p *ProjectTask) delJudge(infoid, pid string) {
 	tmpPro, _ := MongoTool.FindById(ProjectColl, pid, nil)
-	ids := []interface{}((*tmpPro)["ids"].(primitive.A))
-	proList := []interface{}((*tmpPro)["list"].(primitive.A))
+	ids := (*tmpPro)["ids"].([]interface{})
+	proList := (*tmpPro)["list"].([]interface{})
 	if len(ids) == 1 {
 		(*tmpPro)["reason"] = "删除项目信息"
 		backupPro(*tmpPro)
-		c := MongoTool.Delete(ProjectColl, pid)
+		c := MongoTool.Delete(ProjectColl, map[string]interface{}{"_id": mongodb.StringTOBsonId(pid)})
 		if c > 0 {
 			client := Es.GetEsConn()
 			defer Es.DestoryEsConn(client)
@@ -1168,7 +1168,7 @@ func deleteSlice1(arr []interface{}, v interface{}) []interface{} {
 //	修改字段值
 func UpdateValue(proMap map[string]interface{}, index, position int, modifyMap map[string]interface{}) map[string]interface{} {
 	updataSet := make(map[string]interface{})
-	infoList := []interface{}(proMap["list"].(primitive.A))
+	infoList := proMap["list"].([]interface{})
 	tempMap := infoList[position].(map[string]interface{})
 
 	for k := range modifyMap {
@@ -1221,7 +1221,7 @@ func backupPro(tmp map[string]interface{}) {
 
 // 删除原有项目数据
 func delOldPro(pid string) {
-	t := MongoTool.Delete(ProjectColl, pid)
+	t := MongoTool.Delete(ProjectColl, map[string]interface{}{"_id": mongodb.StringTOBsonId(pid)})
 	if t >= 0 {
 		client := Es.GetEsConn()
 		defer Es.DestoryEsConn(client)