123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- package main
- import (
- qu "qfw/util"
- "sort"
- "strings"
- )
- func UpdateProject(tmp map[string]interface{}, thisinfo *Info, pInfo *ProjectInfo, weight int, comStr string, resVal, pjVal int) {
- //log.Println(thisinfo.ProjectName, pInfo.ProjectName, comStr)
- // updateid := pInfo.Id
- // if BinarySearch(pInfo.Ids, thisinfo.Id) > -1 {
- // return //updateid
- // }
- set := map[string]interface{}{}
- //res, bres := MongoTool.FindById(ProjectColl, pInfo.Id.Hex(), `{"list":0}`)
- EqInfoUpdate(thisinfo, pInfo)
- //if bres && res != nil && *res != nil {
- set["topscopeclass"] = pInfo.Topscopeclass
- set["subscopeclass"] = pInfo.Subscopeclass
- s_subscopeclass := strings.Join(pInfo.Subscopeclass, ",")
- if len(s_subscopeclass) > 0 {
- s_subscopeclass = "," + s_subscopeclass + ","
- }
- set["s_subscopeclass"] = s_subscopeclass
- s_winner := strings.Join(pInfo.Winners, ",")
- if len(s_winner) > 0 {
- s_winner = "," + s_winner + ","
- }
- set["s_winner"] = s_winner
- if pInfo.Buyerperson != "" && pInfo.Buyertel != "" {
- set["buyerperson"] = pInfo.Buyerperson
- set["buyertel"] = pInfo.Buyertel
- }
- if pInfo.Buyerclass != "" {
- set["buyerclass"] = pInfo.Buyerclass
- }
- if pInfo.District != "" {
- set["district"] = pInfo.District
- }
- if pInfo.Bidopentime > 0 {
- set["bidopentime"] = pInfo.Bidopentime
- }
- if len(pInfo.Winnerorder) > 0 {
- set["winnerorder"] = pInfo.Winnerorder
- }
- if thisinfo.HasPackage {
- set["multipackage"] = 1
- } else {
- set["multipackage"] = 0
- }
- if pInfo.ProjectName != "" {
- set["projectname"] = pInfo.ProjectName
- }
- if pInfo.ProjectCode != "" {
- set["projectcode"] = pInfo.ProjectCode
- }
- if pInfo.Buyer != "" {
- set["buyer"] = pInfo.Buyer
- }
- //预算、中标价
- if qu.Float64All(tmp["bidamount"]) > 0 && pInfo.Bidamount == 0 {
- set["bidamount"] = tmp["bidamount"]
- }
- if qu.Float64All(tmp["budget"]) > 0 && pInfo.Budget == 0 {
- set["budget"] = tmp["budget"]
- }
- set["mpn"] = pInfo.MPN
- set["mpc"] = pInfo.MPC
- set["area"] = pInfo.Area
- set["city"] = pInfo.City
- //e := InitEL(util.ObjToString((*res)["extractpos"]))
- if thisinfo.dealtype == 1 {
- var sonpackage map[string]interface{}
- for _, obj := range tmp["package"].(map[string]interface{}) {
- sonpackage, _ = obj.(map[string]interface{})
- }
- for _, v2 := range []string{"budget", "budget_w", "winner", "winner_w", "bidstatus", "bidstatus_w"} {
- if sonpackage[v2] != nil {
- tmp[v2] = sonpackage[v2]
- }
- }
- }
- //e.fieldpriority(&tmp, res, &set)
- //set["extractpos"] = e.GetVal()
- // if thisinfo.HasPackage { //多包处理
- // p1, _ := (*res)["package"].(map[string]interface{})
- // p2, _ := tmp["package"].(map[string]interface{})
- // if p2 != nil {
- // if p1 != nil {
- // for pk2, pv2 := range p2 {
- // if p1[pk2] != nil { //合并
- // item1, _ := p1[pk2].(map[string]interface{})
- // item2, _ := pv2.(map[string]interface{})
- // if item1 != nil && item2 != nil { //原始项
- // for ik1, iv1 := range item2 {
- // if item1[ik1] == nil {
- // item1[ik1] = iv1
- // }
- // }
- // }
- // } else {
- // p1[pk2] = pv2
- // }
- // }
- // } else {
- // p1 = p2
- // }
- // }
- // set["package"] = p1
- // }
- //中标候选人合并
- update := map[string]interface{}{}
- if len(set) > 0 {
- update["$set"] = set
- }
- //保留原数据吧
- push := NewPushInfo(tmp)
- push["compareStr"] = comStr
- push["resVal"] = resVal
- push["pjVal"] = pjVal
- update["$push"] = map[string]interface{}{
- "list": push,
- }
- if len(update) > 0 {
- updateInfo := []map[string]interface{}{
- map[string]interface{}{
- "_id": pInfo.Id,
- },
- update,
- }
- //批量更新,这块可能需要再做判重处理
- updatePool <- updateInfo
- // MongoTool.Update(ProjectColl, map[string]interface{}{
- // "_id": qu.StringTOBsonId(pInfo.Id.Hex()),
- // }, &update, false, false)
- }
- //}
- //再往redis中放 index
- //往队列中增加时间 -------------->start
- }
- func EqInfoUpdate(thisinfo *Info, pInfo *ProjectInfo) {
- if thisinfo.Publishtime > pInfo.LastTime {
- pInfo.LastTime = thisinfo.Publishtime
- }
- if pInfo.FirstTime == 0 || (thisinfo.Publishtime < pInfo.FirstTime && thisinfo.Publishtime > 0) {
- pInfo.FirstTime = thisinfo.Publishtime
- }
- pInfo.Ids = append(pInfo.Ids, thisinfo.Id)
- //增加发布时间结束----------------->end
- if (pInfo.Buyer == "" && thisinfo.Buyer != "") || (len([]rune(pInfo.Buyer)) < 5 && len([]rune(thisinfo.Buyer)) > 5) {
- pInfo.Buyer = thisinfo.Buyer
- }
- if (pInfo.Agency == "" && thisinfo.Agency != "") || (len([]rune(pInfo.Agency)) < 5 && len([]rune(thisinfo.Agency)) > 5) {
- pInfo.Agency = thisinfo.Agency
- }
- if (pInfo.ProjectCode == "" && thisinfo.ProjectCode != "") || (len([]rune(pInfo.ProjectCode)) < 6 && len([]rune(thisinfo.ProjectCode)) > 6) {
- pInfo.ProjectCode = thisinfo.ProjectCode
- }
- if pInfo.Area == "全国" && thisinfo.Area != "全国" {
- pInfo.Area = thisinfo.Area
- pInfo.City = thisinfo.City
- }
- if thisinfo.District != "" {
- pInfo.District = thisinfo.District
- }
- if thisinfo.Buyerperson != "" && thisinfo.Buyertel != "" {
- pInfo.Buyerperson = thisinfo.Buyerperson
- pInfo.Buyertel = thisinfo.Buyertel
- }
- if thisinfo.Buyerclass != "" {
- pInfo.Buyerclass = thisinfo.Buyerclass
- }
- if thisinfo.Bidopentime > 0 {
- pInfo.Bidopentime = thisinfo.Bidopentime
- }
- if thisinfo.Bidamount > 0 && pInfo.Bidamount < 1 {
- pInfo.Bidamount = thisinfo.Bidamount
- }
- if thisinfo.Budget > 0 && pInfo.Budget < 1 {
- pInfo.Budget = thisinfo.Budget
- }
- if len(thisinfo.Topscopeclass) > 0 {
- sort.Strings(pInfo.Topscopeclass)
- for _, k := range thisinfo.Topscopeclass {
- if BinarySearch(pInfo.Topscopeclass, k) == -1 {
- pInfo.Topscopeclass = append(pInfo.Topscopeclass, k)
- sort.Strings(pInfo.Topscopeclass)
- }
- }
- }
- if len(thisinfo.Subscopeclass) > 0 {
- sort.Strings(pInfo.Subscopeclass)
- for _, k := range thisinfo.Subscopeclass {
- if BinarySearch(pInfo.Subscopeclass, k) == -1 {
- pInfo.Subscopeclass = append(pInfo.Subscopeclass, k)
- sort.Strings(pInfo.Subscopeclass)
- }
- }
- }
- //winner
- if len(thisinfo.Winners) > 0 {
- sort.Strings(pInfo.Winners)
- for _, k := range thisinfo.Winners {
- if BinarySearch(pInfo.Winners, k) == -1 {
- pInfo.Winners = append(pInfo.Winners, k)
- sort.Strings(pInfo.Winners)
- }
- }
- }
- //winnerorder
- // if len(thisinfo.Winnerorder) > 0 {
- // sort.Strings(pInfo.Winnerorder)
- // for _, k := range thisinfo.Winnerorder {
- // //if BinarySearch(pInfo.Winnerorder, k) == -1 {
- // pInfo.Winnerorder = append(pInfo.Winnerorder, k)
- // sort.Strings(pInfo.Winnerorder)
- // //}
- // }
- // }
- }
|