|
@@ -8,7 +8,6 @@ import (
|
|
mu "mfw/util"
|
|
mu "mfw/util"
|
|
"qfw/util"
|
|
"qfw/util"
|
|
"regexp"
|
|
"regexp"
|
|
- "strconv"
|
|
|
|
"strings"
|
|
"strings"
|
|
"sync"
|
|
"sync"
|
|
"time"
|
|
"time"
|
|
@@ -103,12 +102,10 @@ var sp = make(chan bool, 5)
|
|
|
|
|
|
//初始化全量合并对象
|
|
//初始化全量合并对象
|
|
func init() {
|
|
func init() {
|
|
- util.Debug("task init...")
|
|
|
|
P_QL = NewPT()
|
|
P_QL = NewPT()
|
|
log.Println(len(P_QL.updatePool))
|
|
log.Println(len(P_QL.updatePool))
|
|
go P_QL.updateAllQueue()
|
|
go P_QL.updateAllQueue()
|
|
go P_QL.clearMem()
|
|
go P_QL.clearMem()
|
|
- util.Debug("task init end")
|
|
|
|
}
|
|
}
|
|
|
|
|
|
func (p *ProjectTask) updateAllQueue() {
|
|
func (p *ProjectTask) updateAllQueue() {
|
|
@@ -341,110 +338,118 @@ func (p *ProjectTask) taskUpdateInfo(udpInfo map[string]interface{}) {
|
|
p.enter(db, coll, q)
|
|
p.enter(db, coll, q)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func (p *ProjectTask) taskQuery() {
|
|
|
|
+ defer util.Catch()
|
|
|
|
+ count := 0
|
|
|
|
+ sess := MongoTool.GetMgoConn()
|
|
|
|
+ defer MongoTool.DestoryMongoConn(sess)
|
|
|
|
+ fields := map[string]interface{} {"budget": 1, "bidamount": 1, "package": 1}
|
|
|
|
+ ms := sess.DB(MongoTool.DbName).C(UpdateColl).Find(map[string]interface{}{}).Select(fields)
|
|
|
|
+ query := ms.Iter()
|
|
|
|
+L:
|
|
|
|
+ for {
|
|
|
|
+ tmp := make(map[string]interface{})
|
|
|
|
+ if query.Next(&tmp) {
|
|
|
|
+ lastid := tmp["_id"]
|
|
|
|
+ tmp["id"] = tmp["_id"].(primitive.ObjectID).Hex();
|
|
|
|
+ if count%1000 == 0 {
|
|
|
|
+ log.Println("current modify", count, lastid)
|
|
|
|
+ }
|
|
|
|
+ p.taskUpdateMoney(tmp)
|
|
|
|
+ count++
|
|
|
|
+ } else {
|
|
|
|
+ break L
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
//修改公告信息的预算/中标金额
|
|
//修改公告信息的预算/中标金额
|
|
func (p *ProjectTask) taskUpdateMoney(udpInfo map[string]interface{}) {
|
|
func (p *ProjectTask) taskUpdateMoney(udpInfo map[string]interface{}) {
|
|
defer util.Catch()
|
|
defer util.Catch()
|
|
id := udpInfo["id"].(string)
|
|
id := udpInfo["id"].(string)
|
|
- budget := util.ObjToString(udpInfo["budget"])
|
|
|
|
- bidamount := util.ObjToString(udpInfo["bidamount"])
|
|
|
|
- if budget == "" && bidamount == "" {
|
|
|
|
- util.Debug("")
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
|
|
+ budget := util.Float64All(udpInfo["budget"])
|
|
|
|
+ bidamount := util.Float64All(udpInfo["bidamount"])
|
|
|
|
|
|
client := Es.GetEsConn()
|
|
client := Es.GetEsConn()
|
|
defer Es.DestoryEsConn(client)
|
|
defer Es.DestoryEsConn(client)
|
|
esquery := `{"query": {"bool": {"must": [{"term": {"list.infoid": "`+id+`"}}]}}}`
|
|
esquery := `{"query": {"bool": {"must": [{"term": {"list.infoid": "`+id+`"}}]}}}`
|
|
data := Es.Get(Index, Itype, esquery)
|
|
data := Es.Get(Index, Itype, esquery)
|
|
- util.Debug(*data)
|
|
|
|
- if data != nil {
|
|
|
|
|
|
+ if len(*data) > 0 {
|
|
pid := util.ObjToString((*data)[0]["_id"])
|
|
pid := util.ObjToString((*data)[0]["_id"])
|
|
pro := MongoTool.FindById(ProjectColl, pid)
|
|
pro := MongoTool.FindById(ProjectColl, pid)
|
|
|
|
+ if len(pro) == 0 {
|
|
|
|
+ util.Debug("未找到项目, pid=", pid)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
var info *map[string]interface{}
|
|
var info *map[string]interface{}
|
|
for _, v := range []interface{}(pro["list"].(primitive.A)){
|
|
for _, v := range []interface{}(pro["list"].(primitive.A)){
|
|
v1 := v.(map[string]interface{})
|
|
v1 := v.(map[string]interface{})
|
|
if util.ObjToString(v1["infoid"]) == id {
|
|
if util.ObjToString(v1["infoid"]) == id {
|
|
info = util.ObjToMap(v)
|
|
info = util.ObjToMap(v)
|
|
infoField := util.ObjToMap(pro["infofield"])
|
|
infoField := util.ObjToMap(pro["infofield"])
|
|
- if budget != "" {
|
|
|
|
- if budget != "del" {
|
|
|
|
- newBudget, _ := strconv.ParseFloat(budget, 64)
|
|
|
|
- if pro["budget"] == (*info)["budget"] {
|
|
|
|
- pro["budget"] = newBudget
|
|
|
|
- }
|
|
|
|
- if util.IntAll(pro["multipackage"]) == 1 {
|
|
|
|
- if packages, ok := pro["package"].(map[string]interface{}); ok {
|
|
|
|
- M :
|
|
|
|
- for _, v := range packages{
|
|
|
|
- v1 := []interface{}(v.(primitive.A))
|
|
|
|
- for _, v2 := range v1{
|
|
|
|
- v3 := v2.(map[string]interface{})
|
|
|
|
- if util.ObjToString(v3["infoid"]) == id {
|
|
|
|
- if v3["budget"] != nil {
|
|
|
|
- v3["budget"] = newBudget
|
|
|
|
- }
|
|
|
|
- }else {
|
|
|
|
- break M
|
|
|
|
- }
|
|
|
|
|
|
+ if udpInfo["budget"] != nil{
|
|
|
|
+ util.Debug("update-------", (*info)["infoid"])
|
|
|
|
+ //if pro["budget"] == (*info)["budget"] {
|
|
|
|
+ // pro["budget"] = budget
|
|
|
|
+ //}
|
|
|
|
+ //多包中的金额
|
|
|
|
+ if util.IntAll(pro["multipackage"]) == 1 {
|
|
|
|
+ if packages, ok := pro["package"].(map[string]interface{}); ok {
|
|
|
|
+ M :
|
|
|
|
+ for k, v := range packages{
|
|
|
|
+ v1 := []interface{}(v.(primitive.A))
|
|
|
|
+ for _, v2 := range v1{
|
|
|
|
+ v3 := v2.(map[string]interface{})
|
|
|
|
+ if util.ObjToString(v3["infoid"]) == id {
|
|
|
|
+ if v3["budget"] != nil {
|
|
|
|
+ pkg := udpInfo["package"].(map[string]interface{})
|
|
|
|
+ tmp := pkg[k].(map[string]interface{})
|
|
|
|
+ v3["budget"] = tmp["budget"]
|
|
}
|
|
}
|
|
|
|
+ }else {
|
|
|
|
+ break M
|
|
}
|
|
}
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if pro["sortprice"] == (*info)["budget"] {
|
|
|
|
- pro["sortprice"] = newBudget
|
|
|
|
- }
|
|
|
|
- (*info)["budget"] = newBudget
|
|
|
|
- (*util.ObjToMap((*infoField)[id]))["budget"] = newBudget
|
|
|
|
- }else {
|
|
|
|
- delete(*info, "budget")
|
|
|
|
- delete(*util.ObjToMap((*infoField)[id]), "budget")
|
|
|
|
- if pro["budget"] == (*info)["budget"] {
|
|
|
|
- money := FindMoney("budget", pro)
|
|
|
|
- if money >= 0 {
|
|
|
|
- pro["budget"] = money
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
|
|
+ (*info)["budget"] = budget
|
|
|
|
+ (*util.ObjToMap((*infoField)[id]))["budget"] = budget
|
|
|
|
+ if pro["sortprice"] == (*info)["budget"] {
|
|
|
|
+ pro["sortprice"] = budget
|
|
|
|
+ }
|
|
|
|
+ }else {
|
|
|
|
+ delete(*info, "budget")
|
|
}
|
|
}
|
|
- if bidamount != "" {
|
|
|
|
- if bidamount != "del" {
|
|
|
|
- newBidamount, _ := strconv.ParseFloat(bidamount, 64)
|
|
|
|
- if pro["bidamount"] == (*info)["bidamount"] {
|
|
|
|
- pro["bidamount"] = newBidamount
|
|
|
|
- }
|
|
|
|
- if util.IntAll(pro["multipackage"]) == 1 {
|
|
|
|
- if packages, ok := pro["package"].(map[string]interface{}); ok {
|
|
|
|
- N :
|
|
|
|
- for _, v := range packages{
|
|
|
|
- v1 := []interface{}(v.(primitive.A))
|
|
|
|
- for _, v2 := range v1{
|
|
|
|
- v3 := v2.(map[string]interface{})
|
|
|
|
- if util.ObjToString(v3["infoid"]) == id {
|
|
|
|
- if v3["bidamount"] != nil {
|
|
|
|
- v3["bidamount"] = newBidamount
|
|
|
|
- }
|
|
|
|
- }else {
|
|
|
|
- break N
|
|
|
|
|
|
+ if udpInfo["bidamount"] != nil{
|
|
|
|
+ //if pro["bidamount"] == (*info)["bidamount"] {
|
|
|
|
+ // pro["bidamount"] = bidamount
|
|
|
|
+ //}
|
|
|
|
+ v1["bidamount"] = bidamount
|
|
|
|
+ if util.IntAll(pro["multipackage"]) == 1 {
|
|
|
|
+ if packages, ok := pro["package"].(map[string]interface{}); ok {
|
|
|
|
+ for k, v := range packages{
|
|
|
|
+ v1 := []interface{}(v.(primitive.A))
|
|
|
|
+ for _, v2 := range v1{
|
|
|
|
+ v3 := v2.(map[string]interface{})
|
|
|
|
+ if util.ObjToString(v3["infoid"]) == id {
|
|
|
|
+ if v3["bidamount"] != nil {
|
|
|
|
+ pkg := udpInfo["package"].(map[string]interface{})
|
|
|
|
+ tmp := pkg[k].(map[string]interface{})
|
|
|
|
+ v3["bidamount"] = tmp["bidamount"]
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if pro["sortprice"] == (*info)["bidamount"] {
|
|
|
|
- pro["sortprice"] = newBidamount
|
|
|
|
- }
|
|
|
|
- (*info)["bidamount"] = newBidamount
|
|
|
|
- (*util.ObjToMap((*infoField)[id]))["bidamount"] = newBidamount
|
|
|
|
- }else {
|
|
|
|
- delete((*info), "bidamount")
|
|
|
|
- delete((*util.ObjToMap((*infoField)[id])), "bidamount")
|
|
|
|
- if pro["bidamount"] == (*info)["bidamount"] {
|
|
|
|
- money := FindMoney("bidamount", pro)
|
|
|
|
- if money >= 0 {
|
|
|
|
- pro["bidamount"] = money
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
|
|
+ (*info)["bidamount"] = bidamount
|
|
|
|
+ (*util.ObjToMap((*infoField)[id]))["bidamount"] = bidamount
|
|
|
|
+ if pro["sortprice"] == (*info)["bidamount"] {
|
|
|
|
+ pro["sortprice"] = bidamount
|
|
|
|
+ }
|
|
|
|
+ }else {
|
|
|
|
+ delete(*info, "bidamount")
|
|
}
|
|
}
|
|
break
|
|
break
|
|
}
|
|
}
|
|
@@ -455,17 +460,22 @@ func (p *ProjectTask) taskUpdateMoney(udpInfo map[string]interface{}) {
|
|
_ = json.Unmarshal(bys, &project)
|
|
_ = json.Unmarshal(bys, &project)
|
|
bys1, _ := json.Marshal(info)
|
|
bys1, _ := json.Marshal(info)
|
|
_ = json.Unmarshal(bys1, &pInfo)
|
|
_ = json.Unmarshal(bys1, &pInfo)
|
|
- CountAmount(project, pInfo, *info)
|
|
|
|
-
|
|
|
|
- if project.Budget > 0 {
|
|
|
|
- util.Debug(project.Budget)
|
|
|
|
- pro["budget"] = project.Budget
|
|
|
|
- pro["budgettag"] = 0
|
|
|
|
- }
|
|
|
|
- if project.Bidamount > 0 {
|
|
|
|
- util.Debug(project.Bidamount)
|
|
|
|
- pro["bidamount"] = project.Bidamount
|
|
|
|
- pro["bidamounttag"] = 0
|
|
|
|
|
|
+ if len(project.Ids) > 1 {
|
|
|
|
+ CountAmount(project, pInfo, *info)
|
|
|
|
+ if project.Budget > 0 {
|
|
|
|
+ pro["budget"] = project.Budget
|
|
|
|
+ }
|
|
|
|
+ if project.Bidamount > 0 {
|
|
|
|
+ pro["bidamount"] = project.Bidamount
|
|
|
|
+ }
|
|
|
|
+ }else {
|
|
|
|
+ pro["budget"] = budget
|
|
|
|
+ pro["bidamount"] = bidamount
|
|
|
|
+ if budget > bidamount {
|
|
|
|
+ pro["sortprice"] = budget
|
|
|
|
+ }else {
|
|
|
|
+ pro["sortprice"] = bidamount
|
|
|
|
+ }
|
|
}
|
|
}
|
|
set := map[string]interface{}{
|
|
set := map[string]interface{}{
|
|
"$set": pro,
|
|
"$set": pro,
|
|
@@ -492,6 +502,7 @@ func (p *ProjectTask) taskUpdateMoney(udpInfo map[string]interface{}) {
|
|
}},
|
|
}},
|
|
"stype": "project",
|
|
"stype": "project",
|
|
})
|
|
})
|
|
|
|
+ util.Debug(string(by))
|
|
_ = udpclient.WriteUdp(by, mu.OP_TYPE_DATA, toaddr[1])
|
|
_ = udpclient.WriteUdp(by, mu.OP_TYPE_DATA, toaddr[1])
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -525,14 +536,12 @@ func nextNode(mapInfo map[string]interface{}, pici int64) {
|
|
mapInfo["query"] = map[string]interface{}{
|
|
mapInfo["query"] = map[string]interface{}{
|
|
"pici": pici,
|
|
"pici": pici,
|
|
}
|
|
}
|
|
- for n, to := range toaddr {
|
|
|
|
- key := fmt.Sprintf("%d-%s-%d", pici, "project", n)
|
|
|
|
- mapInfo["key"] = key
|
|
|
|
- datas, _ := json.Marshal(mapInfo)
|
|
|
|
- node := &udpNode{datas, to, time.Now().Unix(), 0}
|
|
|
|
- udptaskmap.Store(key, node)
|
|
|
|
- _ = udpclient.WriteUdp(datas, mu.OP_TYPE_DATA, to)
|
|
|
|
- }
|
|
|
|
|
|
+ key := fmt.Sprintf("%d-%s-%d", pici, "project", 0)
|
|
|
|
+ mapInfo["key"] = key
|
|
|
|
+ datas, _ := json.Marshal(mapInfo)
|
|
|
|
+ node := &udpNode{datas, toaddr[0], time.Now().Unix(), 0}
|
|
|
|
+ udptaskmap.Store(key, node)
|
|
|
|
+ _ = udpclient.WriteUdp(datas, mu.OP_TYPE_DATA, toaddr[0])
|
|
}
|
|
}
|
|
|
|
|
|
func (p *ProjectTask) enter(db, coll string, q map[string]interface{}) {
|
|
func (p *ProjectTask) enter(db, coll string, q map[string]interface{}) {
|
|
@@ -583,7 +592,6 @@ func (p *ProjectTask) enter(db, coll string, q map[string]interface{}) {
|
|
break L
|
|
break L
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
}()
|
|
}()
|
|
fields := map[string]interface{} {"area": 1, "city": 1, "district": 1, "comeintime": 1, "publishtime": 1, "bidopentime": 1, "title": 1, "projectname": 1, "href": 1,
|
|
fields := map[string]interface{} {"area": 1, "city": 1, "district": 1, "comeintime": 1, "publishtime": 1, "bidopentime": 1, "title": 1, "projectname": 1, "href": 1,
|
|
"projectcode": 1, "buyerclass": 1, "winner": 1, "s_winner": 1, "buyer": 1, "buyerperson": 1, "buyertel": 1, "infoformat": 1, "toptype": 1, "subtype": 1, "spidercode": 1,
|
|
"projectcode": 1, "buyerclass": 1, "winner": 1, "s_winner": 1, "buyer": 1, "buyerperson": 1, "buyertel": 1, "infoformat": 1, "toptype": 1, "subtype": 1, "spidercode": 1,
|