123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- 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
- }
|