package main import ( qu "qfw/util" "qfw/util/redis" "strings" "time" "gopkg.in/mgo.v2/bson" ) func NewProject(tmp map[string]interface{}, thisinfo *Info) string { set := map[string]interface{}{} for _, f := range FIELDS { if tmp[f] != nil { set[f] = tmp[f] } } set["s_projectname"] = thisinfo.ProjectName set["createtime"] = time.Now().Unix() set["sourceinfoid"] = qu.BsonIdToSId(tmp["_id"]) set["sourceinfourl"] = tmp["href"] set["topscopeclass"] = thisinfo.Topscopeclass set["subscopeclass"] = thisinfo.Subscopeclass if thisinfo.Buyerperson != "" { set["buyerperson"] = thisinfo.Buyerperson } if thisinfo.Buyertel != "" { set["buyertel"] = thisinfo.Buyertel } if thisinfo.Buyerclass != "" { set["buyertel"] = thisinfo.Buyerclass } if thisinfo.Bidopentime > 0 { set["bidopentime"] = thisinfo.Bidopentime } if len(thisinfo.Winnerorder) > 0 { set["winnerorder"] = thisinfo.Winnerorder } s_subscopeclass := strings.Join(thisinfo.Subscopeclass, ",") set["s_subscopeclass"] = s_subscopeclass s_winner := strings.Join(thisinfo.Winners, ",") set["s_winner"] = s_winner if tmp["package"] != nil { set["package"] = tmp["package"] //没定义优先级 } push := NewPushInfo(tmp) set["list"] = []bson.M{ push, } id := MongoTool.Save(ProjectColl, set) p1 := NewPinfo(id, thisinfo) redis.PutCKV(ProjectCache, id, p1) return id } func NewPushInfo(tmp map[string]interface{}) bson.M { res := bson.M{ "comeintime": tmp["comeintime"], "publishtime": tmp["publishtime"], "title": tmp["title"], "toptype": tmp["toptype"], "subtype": tmp["subtype"], "infoformat": tmp["infoformat"], "infoid": qu.BsonIdToSId(tmp["_id"]), "area": tmp["area"], "city": tmp["city"], "projectname": tmp["projectname"], "projectcode": tmp["projectcode"], "buyer": tmp["buyer"], "href": tmp["href"], } for _, k := range []string{"winner", "budget", "bidamount"} { if tmp[k] != nil { res[k] = tmp[k] } } return res } //生成存放在redis数组中的对象 func NewPinfo(id string, thisinfo *Info) ProjectInfo { p1 := ProjectInfo{ Id: bson.ObjectIdHex(id), Ids: []string{thisinfo.Id}, Topscopeclass: thisinfo.Topscopeclass, Subscopeclass: thisinfo.Subscopeclass, Winners: thisinfo.Winners, ProjectName: thisinfo.ProjectName, ProjectCode: thisinfo.ProjectCode, Buyer: thisinfo.Buyer, Agency: thisinfo.Agency, Area: thisinfo.Area, City: thisinfo.City, District: thisinfo.District, MPN: []string{}, MPC: []string{}, HasPackage: thisinfo.HasPackage, Package: map[string]interface{}{}, Buyerclass: thisinfo.Buyerclass, Bidopentime: thisinfo.Bidopentime, Winnerorder: thisinfo.Winnerorder, FirstTime: thisinfo.Publishtime, LastTime: thisinfo.Publishtime, } if thisinfo.LenPTC > 5 { p1.MPC = append(p1.MPC, thisinfo.PTC) } for k4, _ := range thisinfo.Package { p1.Package[k4] = "" } return p1 }