Explorar o código

Merge branch 'dev3.4' of http://192.168.3.207:10080/qmx/jy-data-extract into dev3.4

fengweiqiang %!s(int64=5) %!d(string=hai) anos
pai
achega
29f3053853

+ 4 - 2
fullproject/src_v1/init.go

@@ -294,14 +294,16 @@ type ProjectInfo struct {
 	Buyerclass  string                 `json:"buyerclass"`            //采购单位分类
 	Bidopentime int64                  `json:"bidopentime,omitempty"` //开标时间
 	//	Zbtime        int64                  `json:"zbtime"`        //招标时间
-	//	Jgtime        int64                  `json:"jgtime"`        //结果中标时间
+	Jgtime        int64              `json:"jgtime"`        //结果中标时间
 	Bidamount float64 `json:"bidamount,omitempty"` //中标金额
 	Budget    float64 `json:"budget,omitempty"`    //预算
 	//Winnerorder []string `json:"winnerorder"` //中标候选人
 	score         int
 	comStr        string
 	resVal, pjVal int
-	InfoFiled	map[string]InfoField	`json:"infofiled"`		//逻辑处理需要的info字段
+	InfoFiled	map[string]InfoField	`json:"infofiled"`			//逻辑处理需要的info字段
+	Budgettag		int					`json:"budgettag"`			//预算是否有效标记
+	Bidamounttag	int					`json:"bidamounttag"`		//中标金额是否有效标记
 }
 
 //存储部分招标信息字段,业务逻辑处理需要

+ 159 - 128
fullproject/src_v1/project.go

@@ -3,13 +3,13 @@ package main
 import (
 	"encoding/json"
 	"log"
+	"time"
+
 	//	"log"
 	"math"
 	qu "qfw/util"
 	"sort"
 	"strings"
-	"time"
-
 	//"gopkg.in/mgo.v2/bson"
 	"go.mongodb.org/mongo-driver/bson"
 	"go.mongodb.org/mongo-driver/bson/primitive"
@@ -456,37 +456,11 @@ func (p *ProjectTask) NewProject(tmp map[string]interface{}, thisinfo *Info) (st
 			set[f] = tmp[f]
 		}
 	}
-	if tmp["budget"] != nil {
-		set["budget"] = thisinfo.Budget
-	}
-	if tmp["bidamount"] != nil {
-		set["bidamount"] = thisinfo.Bidamount
-	}
 	bidopentime := qu.Int64All(tmp["bidopentime"])
 	if bidopentime > 0 {
 		set["bidopentime"] = bidopentime
 	}
-	if thisinfo.ProjectName != "" {
-		set["s_projectname"] = tmp["projectname"]
-	}
-	now := time.Now().Unix()
-	set["createtime"] = now
-	set["sourceinfoid"] = thisinfo.Id
-	set["sourceinfourl"] = tmp["href"]
-	set["firsttime"] = tmp["publishtime"]
-	set["lasttime"] = tmp["publishtime"]
-	set["pici"] = p.pici
-	set["ids"] = []string{thisinfo.Id}
-	if thisinfo.TopType == "招标" {
-		set["zbtime"] = tmp["publishtime"]
-	} else if thisinfo.TopType == "结果" || thisinfo.SubType == "合同" {
-		set["jgtime"] = tmp["publishtime"]
-	}
-	//废标、流标   处理时间
-	if thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
-		set["zbtime"] = int64(0)
-		set["bidopentime"] = int64(0)
-	}
+
 	//异常标记
 	if thisinfo.TopType != "招标" && thisinfo.TopType != "拟建" && thisinfo.TopType != "预告" {
 		set["exception"] = 1
@@ -508,12 +482,14 @@ func (p *ProjectTask) NewProject(tmp map[string]interface{}, thisinfo *Info) (st
 	set["bidtype"] = bidtype[bs]
 	if bt == "招标" {
 		set["projectscope"] = qu.ObjToString(tmp["projectscope"])
-		set["bidstatus"] = bs
+		set["bidstatus"] = bt
 	}else {
 		if bidstatus[bs] != "" {
 			set["bidstatus"] = thisinfo.SubType
 		} else if tmp["infoformat"] == 2 {
 			set["bidstatus"] = "拟建"
+		}else if bs == "" {
+			set["bidstatus"] =  ""
 		} else {
 			set["bidstatus"] = "其它"
 		}
@@ -522,10 +498,45 @@ func (p *ProjectTask) NewProject(tmp map[string]interface{}, thisinfo *Info) (st
 
 	pkg := PackageFormat(thisinfo, nil)
 	p1 := p.NewCachePinfo(pId, thisinfo, bt, pkg)
+
+	now := time.Now().Unix()
+	set["createtime"] = now
+	set["sourceinfoid"] = thisinfo.Id
+	set["sourceinfourl"] = tmp["href"]
+	set["firsttime"] = tmp["publishtime"]
+	set["lasttime"] = tmp["publishtime"]
+	set["pici"] = p.pici
+	set["ids"] = []string{thisinfo.Id}
+	if thisinfo.TopType == "招标" {
+		if thisinfo.SubType != "变更" && thisinfo.SubType != "其它" {
+			set["zbtime"] = tmp["publishtime"]
+		}
+	} else if thisinfo.TopType == "结果" || thisinfo.SubType == "合同" {
+		set["jgtime"] = tmp["publishtime"]
+		p1.Jgtime = thisinfo.Publishtime
+	}
+
 	if len(thisinfo.Subscopeclass) > 0 {
-		s_subscopeclass := strings.Join(thisinfo.Subscopeclass, ",")
-		set["s_subscopeclass"] = s_subscopeclass
+		set["s_subscopeclass"] = strings.Join(thisinfo.Subscopeclass, ",")
 	}
+
+	if tmp["budget"] != nil && tmp["budget"] != "" {
+		set["budget"] = thisinfo.Budget
+		p1.Budgettag = 0
+		set["budgettag"] = 0
+	}else {
+		p1.Budgettag = 1
+		set["budgettag"] = 1
+	}
+	if tmp["bidamount"] != nil && tmp["bidamount"] != "" {
+		set["bidamount"] = thisinfo.Bidamount
+		p1.Bidamounttag = 0
+		set["bidamounttag"] = 0
+	}else {
+		p1.Bidamounttag = 1
+		set["bidamounttag"] = 1
+	}
+
 	if len(thisinfo.Winners) > 0 {
 		set["s_winner"] = strings.Join(thisinfo.Winners, ",")
 		p1.Winners = thisinfo.Winners
@@ -537,6 +548,10 @@ func (p *ProjectTask) NewProject(tmp map[string]interface{}, thisinfo *Info) (st
 		set["multipackage"] = 0
 	}
 
+	if thisinfo.Buyer == "" {
+		set["buyerclass"] = ""
+	}
+
 	p1.InfoFiled = make(map[string]InfoField)
 	infofiled := InfoField{
 		Budget:       thisinfo.Budget,
@@ -596,6 +611,7 @@ var INFOFIELDS = []string{
 	"buyertel",
 	"area",
 	"city",
+	"district",
 	"spidercode",
 	"site",
 }
@@ -658,22 +674,35 @@ func (p *ProjectTask) UpdateProject(tmp map[string]interface{}, thisinfo *Info,
 	}
 	set := map[string]interface{}{}
 	pInfo.Ids = append(pInfo.Ids, thisinfo.Id)
-
-	//1--firsttime
-	if thisinfo.Publishtime < pInfo.FirstTime && thisinfo.Publishtime > 0 {
-		pInfo.FirstTime = thisinfo.Publishtime
-		set["firsttime"] = thisinfo.Publishtime
-		if thisinfo.TopType == "招标" {
-			set["zbtime"] = tmp["publishtime"]
-		}
+	if len(pInfo.Ids) > 30 {
+		//异常标记
+		set["listtag"] = 1
 	}
-	//2--lasttime
+
+	//zbtime、lasttime、jgtime
 	pInfo.LastTime = thisinfo.Publishtime
 	set["lasttime"] = thisinfo.Publishtime
 	if thisinfo.TopType == "招标" {
-		set["zbtime"] = tmp["publishtime"]
-	} else if thisinfo.TopType == "结果" || thisinfo.SubType == "合同" {
-		set["jgtime"] = tmp["publishtime"]
+		if thisinfo.SubType != "变更" && thisinfo.SubType != "其它" {
+			set["zbtime"] = tmp["publishtime"]
+		}
+		if pInfo.Jgtime > 0 {
+			pInfo.Jgtime = int64(0)
+			set["jgtime"] = int64(0)
+		}
+	}else if thisinfo.TopType == "结果" {
+		pInfo.Jgtime = thisinfo.Publishtime
+		set["jgtime"] = thisinfo.Publishtime
+	} else if thisinfo.SubType == "合同" {
+		if pInfo.Jgtime <= 0 {
+			set["jgtime"] = tmp["publishtime"]
+			pInfo.Jgtime = thisinfo.Publishtime
+		}
+	}
+
+	if thisinfo.Bidopentime > pInfo.Bidopentime {
+		pInfo.Bidopentime = thisinfo.Bidopentime
+		set["bidopentime"] = pInfo.Bidopentime
 	}
 
 	bt := qu.ObjToString(tmp["toptype"])
@@ -687,30 +716,25 @@ func (p *ProjectTask) UpdateProject(tmp map[string]interface{}, thisinfo *Info,
 		if tmp["projectscope"] != nil {
 			set["projectscope"] = qu.ObjToString(tmp["projectscope"])
 		}
-		set["bidstatus"] = bs
+		set["bidstatus"] = bt
+		pInfo.Bidstatus = bt
 	}else {
 		if bidstatus[bs] != "" {
 			set["bidstatus"] = thisinfo.SubType
+			pInfo.Bidstatus = thisinfo.SubType
 		} else if tmp["infoformat"] == 2 {
 			set["bidstatus"] = "拟建"
-		} else {
+			pInfo.Bidstatus = "拟建"
+		}else if bs == "" {
+			set["bidstatus"] =  ""
+			pInfo.Bidstatus = ""
+		}else {
 			set["bidstatus"] = "其它"
+			pInfo.Bidstatus =  "其它"
 		}
 	}
 	p.mapBidLock.Unlock()
 
-	//废标、流标   处理时间
-	if thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
-		pInfo.FirstTime = thisinfo.Publishtime
-		pInfo.Bidopentime = int64(0)
-		pInfo.LastTime = thisinfo.Publishtime
-
-		set["firsttime"] = thisinfo.Publishtime
-		set["zbtime"] = int64(0)
-		set["publishtime"] = thisinfo.Publishtime
-		set["bidopentime"] = int64(0)
-	}
-
 	//异常标记
 	if ex > 0 {
 		set["exception"] = ex
@@ -775,11 +799,6 @@ func (p *ProjectTask) UpdateProject(tmp map[string]interface{}, thisinfo *Info,
 		set["buyertel"] = pInfo.Buyertel
 	}
 
-	if thisinfo.Bidopentime > pInfo.Bidopentime {
-		pInfo.Bidopentime = thisinfo.Bidopentime
-		set["bidopentime"] = pInfo.Bidopentime
-	}
-
 	if len(thisinfo.Topscopeclass) > 0 {
 		sort.Strings(pInfo.Topscopeclass)
 		for _, k := range thisinfo.Topscopeclass {
@@ -805,7 +824,7 @@ func (p *ProjectTask) UpdateProject(tmp map[string]interface{}, thisinfo *Info,
 	//winner
 	if len(thisinfo.Winners) > 0 {
 		if len(pInfo.Winners) <= 0 {
-			set["winner"] = tmp["winner"].(string)
+			set["winner"] = qu.ObjToString(tmp["winner"])
 		}
 
 		sort.Strings(pInfo.Winners)
@@ -826,9 +845,20 @@ func (p *ProjectTask) UpdateProject(tmp map[string]interface{}, thisinfo *Info,
 		set["multipackage"] = 0
 	}
 	//处理多包后,计算预算金额、中标金额
-	CountAmount(pInfo, thisinfo)
-	set["budget"] = pInfo.Budget
-	set["bidamount"] = pInfo.Bidamount
+	CountAmount(pInfo, thisinfo, tmp)
+	if pInfo.Budget >= 0 && pInfo.Budgettag != 1 {
+		set["budget"] = pInfo.Budget
+		set["budgettag"] = 0
+	}else {
+		set["budgettag"] = 1
+	}
+	if pInfo.Bidamount >= 0 && pInfo.Bidamounttag != 1 {
+		set["bidamount"] = pInfo.Bidamount
+		set["bidamounttag"] = 0
+	}else {
+		set["bidamounttag"] = 1
+	}
+
 	infofiled := InfoField{
 		Budget:       thisinfo.Budget,
 		Bidamount:    thisinfo.Bidamount,
@@ -887,7 +917,9 @@ func (p *ProjectTask) CompareStatus(project *ProjectInfo, info *Info) (bool, int
 	if info.TopType == "拟建" || info.TopType == "预告" || info.TopType == "招标" {
 		if project.Bidstatus == "拟建" || project.Bidstatus == "预告" || project.Bidstatus == "招标" {
 			return false, 0
-		} else {
+		}else if project.Bidstatus == "废标" || project.Bidstatus == "流标" {
+			return false, 0
+		}else {
 			return true, 0
 		}
 	} else if info.TopType == "结果" {
@@ -926,10 +958,10 @@ func ComparePlace(project *ProjectInfo, info *Info) bool {
 		return false
 	}
 	if info.Area == project.Area {
-		if info.City == "" {
+		if info.City == "" || project.City == "" {
 			return false
 		} else if info.City == project.City {
-			if info.District == "" || info.District == project.District {
+			if project.District == "" || info.District == "" || info.District == project.District {
 				return false
 			} else {
 				return true
@@ -1013,28 +1045,34 @@ func PackageFormat(info *Info, project *ProjectInfo) map[string]interface{} {
 }
 
 //计算预算(budget)、中标金额(bidamount)
-func CountAmount(project *ProjectInfo, info *Info) {
+func CountAmount(project *ProjectInfo, info *Info, tmp map[string]interface{}) {
 	if info.HasPackage {
 		budget := 0.0
 		for _, v := range project.Package{
 			v1, _ := v.([]map[string]interface{})
 			for _, v2 := range v1{
-				b1 := qu.Float64All(v2["budget"])
-				if b1 > 0 {
-					budget = budget + b1
-					break
+				if v2["budget"] != nil {
+					b1 := qu.Float64All(v2["budget"])
+					if b1 > 0 {
+						budget = budget + b1
+						break
+					}
+				}else {
+					project.Budgettag = 1
 				}
+
 			}
 		}
-		if budget == 0 && info.Budget > 0 {
-			budget = info.Budget
-		}
 		if budget > 0 {
 			project.Budget = budget
+			project.Budgettag = 0
+		}else if budget == 0 && info.Budget > 0 {
+			project.Budget = info.Budget
+			project.Budgettag = 0
 		}
 	}else {
 		//招标没有多包
-		k := KeyPackage.FindStringSubmatch(project.ProjectName)
+		k := KeyPackage.FindStringSubmatch(info.ProjectName)
 		if len(k) > 0 {
 			//招标是单包
 			if len(project.Package) > 0 {
@@ -1048,32 +1086,26 @@ func CountAmount(project *ProjectInfo, info *Info) {
 				}
 				if !flag {
 					project.Budget = project.Budget + info.Budget
+					project.Budgettag = 0
 				}
 			}else {
 				//项目没有多包
 				if info.Budget > 0 {
 					project.Budget = project.Budget + info.Budget
+					project.Budgettag = 0
+				}else if info.Budget == 0 && tmp["budget"] != nil {
+					project.Budgettag = 0
+				}else {
+					project.Budgettag = 1
 				}
 			}
 		}else {
-			//招标不是单包
-			//flag := false
-			//if project.InfoFiled != nil && len(project.InfoFiled) > 0 {
-			//	for _, res := range project.InfoFiled {
-			//		if res.ProjectName == info.ProjectName {
-			//			if res.Budget < info.Budget {
-			//				project.Budget = project.Budget - res.Budget + info.Budget
-			//			}
-			//			flag = true
-			//			break
-			//		}
-			//	}
-			//	if !flag {
-			//		project.Budget = project.Budget + info.Budget
-			//	}
-			//}
 			if project.Budget < info.Budget {
 				project.Budget = info.Budget
+				project.Budgettag = 0
+			}
+			if tmp["budget"] == nil {
+				project.Budgettag = 1
 			}
 		}
 	}
@@ -1083,17 +1115,27 @@ func CountAmount(project *ProjectInfo, info *Info) {
 			for _, v := range project.Package{
 				v1, _ := v.([]map[string]interface{})
 				for _, v2 := range v1{
-					b1 := qu.Float64All(v2["bidamount"])
-					if b1 > 0 {
-						bidamount = bidamount + b1
-						break
+					if tmp["bidamount"] != nil {
+						b1 := qu.Float64All(v2["bidamount"])
+						if b1 > 0 {
+							bidamount = bidamount + b1
+							break
+						}
+					}else {
+						project.Bidamount = 1
 					}
 				}
 			}
-			project.Bidamount = bidamount
+			if bidamount > 0 {
+				project.Bidamount = bidamount
+				project.Bidamounttag = 0
+			}else if bidamount == 0 && info.Budget > 0 {
+				project.Bidamount = info.Bidamount
+				project.Bidamounttag = 0
+			}
 		}else {
 			//招标没有多包
-			k := KeyPackage.FindStringSubmatch(project.ProjectName)
+			k := KeyPackage.FindStringSubmatch(info.ProjectName)
 			if len(k) > 0 {
 				//招标是单包
 				if len(project.Package) > 0 {
@@ -1101,49 +1143,30 @@ func CountAmount(project *ProjectInfo, info *Info) {
 					flag := false
 					for _, v := range project.Package{
 						v1, _ := v.([]map[string]interface{})
-						if len(v1) > 0 {
+						if len(v1) > 0 && v1[0]["name"] == info.ProjectName {
 							flag = true
 						}
 					}
 					if !flag {
 						project.Bidamount = project.Bidamount + info.Bidamount
+						project.Bidamounttag = 0
 					}
 				}else {
 					//项目没有多包
 					if info.Bidamount > 0 {
 						project.Bidamount = project.Bidamount + info.Bidamount
+						project.Bidamounttag = 0
+					}else if info.Bidamount == 0 && tmp["bidamount"] != nil {
+						project.Bidamounttag = 0
+					}else {
+						project.Bidamounttag = 1
 					}
 				}
 			}else {
-				//招标不是单包
-				//flag := false
-				//if project.InfoFiled != nil && len(project.InfoFiled) > 0 {
-				//	for _, res := range project.InfoFiled {
-				//		if res.Bidstatus == "合同" && res.ContractCode != "" && info.SubType == "合同" && info.ContractCode != "" {
-				//			if res.ContractCode == info.ContractCode {
-				//				if res.Bidamount < info.Bidamount {
-				//					project.Bidamount = project.Bidamount - res.Bidamount + info.Bidamount
-				//				}
-				//				flag = true
-				//				break
-				//			}
-				//		}else {
-				//			if res.ProjectName == info.ProjectName {
-				//				if res.Bidamount < info.Bidamount {
-				//					project.Bidamount = project.Bidamount - res.Bidamount + info.Bidamount
-				//				}
-				//				flag = true
-				//				break
-				//			}
-				//		}
-				//	}
-				//	if !flag {
-				//		project.Bidamount = project.Bidamount + info.Bidamount
-				//	}
-				//}
 				if info.SubType == "中标" || info.SubType == "成交" {
 					if project.Bidamount < info.Bidamount {
 						project.Bidamount = info.Bidamount
+						project.Bidamounttag = 0
 					}else {
 						flag := false
 						if project.InfoFiled != nil && len(project.InfoFiled) > 0 {
@@ -1159,17 +1182,25 @@ func CountAmount(project *ProjectInfo, info *Info) {
 							}
 							if !flag {
 								project.Bidamount = project.Bidamount + info.Bidamount
+								project.Bidamounttag = 0
 							}else {
 								if project.Bidamount < info.Bidamount {
 									project.Bidamount = info.Bidamount
+									project.Bidamounttag = 0
 								}
 							}
 						}
 					}
 				}
+				if tmp["bidamount"] == nil {
+					project.Budgettag = 1
+				}
 			}
 		}
+	}else {
+		project.Bidamounttag = 1
 	}
+
 }
 
 //结构体转map

+ 2 - 0
fullproject/src_v1/task.go

@@ -718,6 +718,8 @@ func (p *ProjectTask) fillInPlace(tmp map[string]interface{}) {
 					tmp["city"] = site.City
 					tmp["district"] = site.District
 					return
+				}else if site.City == "" {
+					return
 				}
 			}
 		} else {

+ 28 - 29
fullproject/src_v1/update.go

@@ -63,7 +63,7 @@ func (p *ProjectTask) mergeAndModify(pInfoId string, index int, info *Info, tmp
 			//跟原项目list第0条信息作对比,可以合并
 			if pId == pInfoId {
 				//合并到当前项目
-				mergeProject(p, currentPro.P, info, tmpPro, index)
+				mergeProject(p, currentPro.P, info, tmpPro, tmp)
 				p.AllIdsMapLock.Lock()
 				p.AllIdsMap[currentPro.P.Id.Hex()].P = currentPro.P
 				p.AllIdsMapLock.Unlock()
@@ -263,13 +263,13 @@ func (p *ProjectTask) updateMerge(index int, info *Info, pInfoId string, tmp map
 //内部合并
 func (p *ProjectTask) innerMerge(pInfo *ProjectInfo, info *Info, tmp map[string]interface{}, tmpPro map[string]interface{}) {
 	infoList := []interface{}(tmpPro["list"].(primitive.A))
-	for index, info1 := range infoList{
+	for _, info1 := range infoList{
 		info2 := info1.(map[string]interface{})
 		if info2["infoid"] == info.Id {
 			deleteSlice1(infoList, info1)
 			continue
 		}
-		mergeProject(p, pInfo, info, tmpPro, index)
+		mergeProject(p, pInfo, info, tmpPro, tmp)
 	}
 	mapTmp, _ := tmpPro["infofiled"].(map[string]interface{})
 	delete(mapTmp, info.Id)
@@ -280,46 +280,43 @@ func (p *ProjectTask) innerMerge(pInfo *ProjectInfo, info *Info, tmp map[string]
 }
 
 //合并字段到project
-func mergeProject(p *ProjectTask, pInfo *ProjectInfo, thisinfo *Info, set map[string]interface{}, index int) map[string]interface{} {
-	//1--firsttime
-	if thisinfo.Publishtime < pInfo.FirstTime && thisinfo.Publishtime > 0 {
-		pInfo.FirstTime = thisinfo.Publishtime
-		set["firsttime"] = thisinfo.Publishtime
-		if thisinfo.TopType == "招标" {
-			set["zbtime"] = thisinfo.Publishtime
-		}
-	}
-	//2--lasttime
+func mergeProject(p *ProjectTask, pInfo *ProjectInfo, thisinfo *Info, set map[string]interface{}, tmp map[string]interface{}) map[string]interface{} {
 	pInfo.LastTime = thisinfo.Publishtime
 	set["lasttime"] = thisinfo.Publishtime
 	if thisinfo.TopType == "招标" {
-		set["zbtime"] = thisinfo.Publishtime
-	} else if thisinfo.TopType == "结果" || thisinfo.SubType == "合同" {
+		if thisinfo.SubType != "变更" && thisinfo.SubType != "其它" {
+			set["zbtime"] = thisinfo.Publishtime
+		}
+		if pInfo.Jgtime > 0 {
+			pInfo.Jgtime = int64(0)
+			set["jgtime"] = int64(0)
+		}
+	}else if thisinfo.TopType == "结果" {
+		pInfo.Jgtime = thisinfo.Publishtime
 		set["jgtime"] = thisinfo.Publishtime
+	} else if thisinfo.SubType == "合同" {
+		if pInfo.Jgtime <= 0 {
+			set["jgtime"] = thisinfo.Publishtime
+		}
 	}
-	//废标、流标   处理时间
-	if thisinfo.SubType == "流标" || thisinfo.SubType == "废标" {
-		pInfo.FirstTime = thisinfo.Publishtime
-		pInfo.Bidopentime = int64(0)
-		pInfo.LastTime = thisinfo.Publishtime
 
-		set["firsttime"] = thisinfo.Publishtime
-		set["zbtime"] = int64(0)
-		set["publishtime"] = thisinfo.Publishtime
-		set["bidopentime"] = int64(0)
+	if thisinfo.Bidopentime > pInfo.Bidopentime {
+		pInfo.Bidopentime = thisinfo.Bidopentime
+		set["bidopentime"] = pInfo.Bidopentime
 	}
 
+
 	bt := thisinfo.TopType
 	bs := thisinfo.SubType
 	p.mapBidLock.Lock()
+	set["bidtype"] = bidtype[bs]
 	if bt == "招标" {
 		//招标状态,更新projectscope
 		if thisinfo.ProjectScope != "" {
 			set["projectscope"] = thisinfo.ProjectScope
 		}
-		set["bidtype"] = bidtype[bs]
+		set["bidstatus"] = bt
 	}else {
-		set["bidtype"] = bt
 		if bidstatus[bs] != "" {
 			set["bidstatus"] = thisinfo.SubType
 		} else if thisinfo.Infoformat == 2 {
@@ -328,7 +325,6 @@ func mergeProject(p *ProjectTask, pInfo *ProjectInfo, thisinfo *Info, set map[st
 			set["bidstatus"] = "其它"
 		}
 	}
-
 	p.mapBidLock.Unlock()
 
 	//3\4\5--省、市、县
@@ -373,6 +369,10 @@ func mergeProject(p *ProjectTask, pInfo *ProjectInfo, thisinfo *Info, set map[st
 		set["buyerclass"] = ""
 	}
 
+	if thisinfo.ContractCode != "" {
+		set["contractcode"] = pInfo.ContractCode + ","+thisinfo.ContractCode
+	}
+
 	//8--代理机构
 	if (pInfo.Agency == "" && thisinfo.Agency != "") || (len([]rune(pInfo.Agency)) < 5 && len([]rune(thisinfo.Agency)) > 5) {
 		pInfo.Agency = thisinfo.Agency
@@ -437,7 +437,6 @@ func mergeProject(p *ProjectTask, pInfo *ProjectInfo, thisinfo *Info, set map[st
 				sort.Strings(pInfo.Winners)
 			}
 		}
-		//set["winners"] = pInfo.Winners
 		set["s_winner"] = strings.Join(pInfo.Winners, ",")
 	}
 
@@ -449,7 +448,7 @@ func mergeProject(p *ProjectTask, pInfo *ProjectInfo, thisinfo *Info, set map[st
 		set["multipackage"] = 0
 	}
 	//处理多包后,计算预算金额、中标金额
-	CountAmount(pInfo, thisinfo)
+	CountAmount(pInfo, thisinfo, tmp)
 	set["budget"] = pInfo.Budget
 	set["bidamount"] = pInfo.Bidamount
 

+ 315 - 0
udpfilterdup/src/mgo.go

@@ -0,0 +1,315 @@
+package main
+
+import (
+	"context"
+	"log"
+	"time"
+
+	"go.mongodb.org/mongo-driver/bson"
+	"go.mongodb.org/mongo-driver/bson/primitive"
+	"go.mongodb.org/mongo-driver/mongo"
+	"go.mongodb.org/mongo-driver/mongo/options"
+)
+
+type MgoSess struct {
+	Db     string
+	Coll   string
+	Query  interface{}
+	Sorts  []string
+	fields interface{}
+	limit  int64
+	skip   int64
+	M      *MongodbSim
+}
+
+type MgoIter struct {
+	Cursor *mongo.Cursor
+}
+
+func (mt *MgoIter) Next(result interface{}) bool {
+	if mt.Cursor != nil {
+		if mt.Cursor.Next(nil) {
+			err := mt.Cursor.Decode(result)
+			if err != nil {
+				log.Println("mgo cur err", err.Error())
+				mt.Cursor.Close(nil)
+				return false
+			}
+			return true
+		} else {
+			mt.Cursor.Close(nil)
+			return false
+		}
+	} else {
+		return false
+	}
+
+}
+
+func (ms *MgoSess) DB(name string) *MgoSess {
+	ms.Db = name
+	return ms
+}
+
+func (ms *MgoSess) C(name string) *MgoSess {
+	ms.Coll = name
+	return ms
+}
+
+func (ms *MgoSess) Find(q interface{}) *MgoSess {
+	ms.Query = q
+	return ms
+}
+
+func (ms *MgoSess) Select(fields interface{}) *MgoSess {
+	ms.fields = fields
+	return ms
+}
+
+func (ms *MgoSess) Limit(limit int64) *MgoSess {
+	ms.limit = limit
+	return ms
+}
+func (ms *MgoSess) Skip(skip int64) *MgoSess {
+	ms.skip = skip
+	return ms
+}
+
+func (ms *MgoSess) Sort(sorts ...string) *MgoSess {
+	ms.Sorts = sorts
+	return ms
+}
+
+func (ms *MgoSess) Iter() *MgoIter {
+	it := &MgoIter{}
+	find := options.Find()
+	if ms.skip > 0 {
+		find.SetSkip(ms.skip)
+	}
+	if ms.limit > 0 {
+		find.SetLimit(ms.limit)
+	}
+	find.SetBatchSize(100)
+	if len(ms.Sorts) > 0 {
+		sort := bson.M{}
+		for _, k := range ms.Sorts {
+			switch k[:1] {
+			case "-":
+				sort[k[1:]] = -1
+			case "+":
+				sort[k[1:]] = 1
+			default:
+				sort[k] = 1
+			}
+		}
+		find.SetSort(sort)
+	}
+	if ms.fields != nil {
+		find.SetProjection(ms.fields)
+	}
+	cur, err := ms.M.C.Database(ms.Db).Collection(ms.Coll).Find(ms.M.Ctx, ms.Query, find)
+	if err != nil {
+		log.Println("mgo find err", err.Error())
+	} else {
+		it.Cursor = cur
+	}
+	return it
+}
+
+type MongodbSim struct {
+	MongodbAddr string
+	Size        int
+	//	MinSize     int
+	DbName   string
+	C        *mongo.Client
+	Ctx      context.Context
+	ShortCtx context.Context
+	pool     chan bool
+}
+
+func (m *MongodbSim) GetMgoConn() *MgoSess {
+	//m.Open()
+	ms := &MgoSess{}
+	ms.M = m
+	return ms
+}
+
+func (m *MongodbSim) DestoryMongoConn(ms *MgoSess) {
+	//m.Close()
+	ms.M = nil
+	ms = nil
+}
+
+func (m *MongodbSim) InitPool() {
+	opts := options.Client()
+	opts.SetConnectTimeout(3 * time.Second)
+	opts.ApplyURI("mongodb://" + m.MongodbAddr)
+	opts.SetMaxPoolSize(uint64(m.Size))
+	m.pool = make(chan bool, m.Size)
+	opts.SetMaxConnIdleTime(2 * time.Hour)
+	m.Ctx, _ = context.WithTimeout(context.Background(), 99999*time.Hour)
+	m.ShortCtx, _ = context.WithTimeout(context.Background(), 1*time.Minute)
+	client, err := mongo.Connect(m.ShortCtx, opts)
+	if err != nil {
+		log.Println("mgo init error:", err.Error())
+	} else {
+		m.C = client
+		log.Println("init success")
+	}
+}
+
+func (m *MongodbSim) Open() {
+	m.pool <- true
+}
+func (m *MongodbSim) Close() {
+	<-m.pool
+}
+
+//批量插入
+func (m *MongodbSim) UpSertBulk(c string, doc ...[]map[string]interface{}) (map[int64]interface{}, bool) {
+	m.Open()
+	defer m.Close()
+	coll := m.C.Database(m.DbName).Collection(c)
+	var writes []mongo.WriteModel
+	for _, d := range doc {
+		write := mongo.NewUpdateOneModel()
+		write.SetFilter(d[0])
+		write.SetUpdate(d[1])
+		write.SetUpsert(true)
+		writes = append(writes, write)
+	}
+	r, e := coll.BulkWrite(m.Ctx, writes)
+	if e != nil {
+		log.Println("mgo upsert error:", e.Error())
+		return nil, false
+	}
+	//	else {
+	//		if r.UpsertedCount != int64(len(doc)) {
+	//			log.Println("mgo upsert uncomplete:uc/dc", r.UpsertedCount, len(doc))
+	//		}
+	//		return true
+	//	}
+	return r.UpsertedIDs, true
+}
+
+//批量插入
+func (m *MongodbSim) SaveBulk(c string, doc ...map[string]interface{}) bool {
+	m.Open()
+	defer m.Close()
+	coll := m.C.Database(m.DbName).Collection(c)
+	var writes []mongo.WriteModel
+	for _, d := range doc {
+		write := mongo.NewInsertOneModel()
+		write.SetDocument(d)
+		writes = append(writes, write)
+	}
+	_, e := coll.BulkWrite(m.Ctx, writes)
+	if e != nil {
+		log.Println("mgo savebulk error:", e.Error())
+		return false
+	}
+	return true
+}
+
+//保存
+func (m *MongodbSim) Save(c string, doc map[string]interface{}) interface{} {
+	m.Open()
+	defer m.Close()
+	coll := m.C.Database(m.DbName).Collection(c)
+	r, err := coll.InsertOne(m.Ctx, doc)
+	if err != nil {
+		return nil
+	}
+	return r.InsertedID
+}
+
+//更新by Id
+func (m *MongodbSim) UpdateById(c, id string, doc map[string]interface{}) bool {
+	m.Open()
+	defer m.Close()
+	coll := m.C.Database(m.DbName).Collection(c)
+	_, err := coll.UpdateOne(m.Ctx, map[string]interface{}{"_id": StringTOBsonId(id)}, doc)
+	if err != nil {
+		return false
+	}
+	return true
+}
+
+//删除by id
+func (m *MongodbSim) DeleteById(c, id string) int64 {
+	m.Open()
+	defer m.Close()
+	coll := m.C.Database(m.DbName).Collection(c)
+	r, err := coll.DeleteOne(m.Ctx, map[string]interface{}{"_id": StringTOBsonId(id)})
+	if err != nil {
+		return 0
+	}
+	return r.DeletedCount
+}
+
+//通过条件删除
+func (m *MongodbSim) Delete(c string, query map[string]interface{}) int64 {
+	m.Open()
+	defer m.Close()
+	coll := m.C.Database(m.DbName).Collection(c)
+	r, err := coll.DeleteMany(m.Ctx, query)
+	if err != nil {
+		return 0
+	}
+	return r.DeletedCount
+}
+
+//findbyid
+func (m *MongodbSim) FindById(c, id string) map[string]interface{} {
+	m.Open()
+	defer m.Close()
+	coll := m.C.Database(m.DbName).Collection(c)
+	r := coll.FindOne(m.Ctx, map[string]interface{}{"_id": StringTOBsonId(id)})
+	v := map[string]interface{}{}
+	r.Decode(&v)
+	return v
+}
+
+//findone
+func (m *MongodbSim) FindOne(c string, query map[string]interface{}) map[string]interface{} {
+	m.Open()
+	defer m.Close()
+	coll := m.C.Database(m.DbName).Collection(c)
+	r := coll.FindOne(m.Ctx, query)
+	v := map[string]interface{}{}
+	r.Decode(&v)
+	return v
+}
+
+//find
+func (m *MongodbSim) Find(c string, query map[string]interface{}, sort, fields interface{}) ([]map[string]interface{}, error) {
+	m.Open()
+	defer m.Close()
+	coll := m.C.Database(m.DbName).Collection(c)
+	op := options.Find()
+	r, err := coll.Find(m.Ctx, query, op.SetSort(sort), op.SetProjection(fields))
+	if err != nil {
+		log.Fatal(err)
+		return nil, err
+	}
+	var results []map[string]interface{}
+	if err = r.All(m.Ctx, &results); err != nil {
+		log.Fatal(err)
+		return nil, err
+	}
+	return results, nil
+}
+
+//创建_id
+func NewObjectId() primitive.ObjectID {
+	return primitive.NewObjectID()
+}
+
+func StringTOBsonId(id string) primitive.ObjectID {
+	objectId, _ := primitive.ObjectIDFromHex(id)
+	return objectId
+}
+
+func BsonTOStringId(id interface{}) string {
+	return id.(primitive.ObjectID).Hex()
+}