package main import ( "go.mongodb.org/mongo-driver/bson" "mongodb" "qfw/util" "regexp" "sort" "strings" "time" ) var numReg = regexp.MustCompile("[0-9]+") func taskinfo1(tmp map[string]interface{}) { info := tmp["v_baseinfo"].(map[string]interface{}) delete(info, "field_source") delete(info, "v_fieldscore") id := util.ObjToString(tmp["id"]) info["_id"] = mongodb.StringTOBsonId(id) Mgo.SaveByOriID(collSave, info) } func taskinfo(info map[string]interface{}) { id := mongodb.BsonIdToSId(info["_id"]) //info, ok := tmp["v_baseinfo"].(map[string]interface{}) //if !ok { // util.Debug("data err ---", id) // return //} // 数据标签 //var mtkey []string var tag []string for key, v := range TagMatchRule { M: for _, matching := range v { if matching.excludeKey != "" { // 匹配排除词 for _, way := range matching.excludeKeyWay { field := MatchWayMap[way] if val := util.ObjToString(info[field]); val != "" { for _, e1 := range matching.excludeKeyReg { if e1.regs.MatchString(val) { continue } } } } } if matching.matchKey != "" { // 匹配关键词 for _, way := range matching.matchKeyWay { field := MatchWayMap[way] if val := util.ObjToString(info[field]); val != "" { for _, r1 := range matching.matchKeyReg { if r1.regs.MatchString(val) { if matching.addKey != "" { // 匹配附加词 for _, w1 := range matching.addKeyWay { field = MatchWayMap[w1] if v1 := util.ObjToString(info[field]); v1 != "" { for _, r2 := range matching.addKeyReg { if r2.regs != nil && r2.regs.MatchString(v1) { //mtkey = append(mtkey, matching.matchKey) tag = append(tag, key) // 标签 break M } else { // && 特殊处理 if strings.Contains(r2.keyStr, "&&") { flag := true for _, s := range strings.Split(r2.keyStr, "&&") { if !strings.Contains(v1, s) { flag = false break } } if flag { //mtkey = append(mtkey, matching.matchKey) tag = append(tag, key) // 标签 break M } } } } } } } else { //mtkey = append(mtkey, matching.matchKey) tag = append(tag, key) // 标签 break M } } } } } } } } //info["mtkey"] = strings.Join(mtkey, "-") if len(tag) > 0 { info["tag_rule"] = strings.Join(tag, ",") } else { info["tag_rule"] = "IT" } /** 项目结束日期 project_completedate(中标、成交、合同) 1、优先采用project_completedate 2、通过项目周期(projectperiod)、工期时长(project_duration)、工期单位(project_timeunit)、项目开始时间(project_startdate/signaturedate)(发布时间/合同签订时间) */ completeData := util.Int64All(info["project_completedate"]) subtype := util.ObjToString(info["subtype"]) if completeData == 0 { if subtype == "中标" || subtype == "成交" || subtype == "合同" { var dur int if util.IntAll(info["project_duration"]) != 0 { dur = util.IntAll(info["project_duration"]) } else { period := periodMethod(info["projectperiod"]) if period > 0 { dur = period } } if dur > 0 { timeunit := util.ObjToString(info["project_timeunit"]) startdate := util.Int64All(info["project_startdate"]) if startdate > 0 { completeData = YcEndTime(startdate, dur, timeunit) } else if startdate = util.Int64All(info["signaturedate"]); startdate > 0 { completeData = YcEndTime(startdate, dur, timeunit) } else { startdate = util.Int64All(info["publishtime"]) completeData = YcEndTime(startdate, dur, timeunit) } } if completeData != 0 { info["project_completedate"] = completeData } } } // 企业标签(采购单位 1 /中标单位 2 ) if info["buyer"] != nil { qyxy, _ := Mgo.FindOne(qyxyColl, map[string]interface{}{"company_name": util.ObjToString(info["buyer"])}) if len(*qyxy) > 0 { if (*qyxy)["bid_type"] == nil { Mgo.UpdateById(qyxyColl, (*qyxy)["_id"], bson.M{"$set": bson.M{"bid_type": "1"}}) } else { stype := strings.Split(util.ObjToString((*qyxy)["bid_type"]), ",") if !strings.Contains(util.ObjToString((*qyxy)["bid_type"]), "1") { stype = append(stype, "1") sort.Strings(stype) Mgo.UpdateById(qyxyColl, (*qyxy)["_id"], bson.M{"$set": bson.M{"bid_type": strings.Join(stype, ",")}}) } } } } if info["s_winner"] != nil { winner := util.ObjToString(info["s_winner"]) for _, s := range strings.Split(winner, ",") { qyxy, _ := Mgo.FindOne(qyxyColl, map[string]interface{}{"company_name": s}) if len(*qyxy) > 0 { if (*qyxy)["bid_type"] == nil { Mgo.UpdateById(qyxyColl, (*qyxy)["_id"], bson.M{"$set": bson.M{"bid_type": "2"}}) } else { stype := strings.Split(util.ObjToString((*qyxy)["bid_type"]), ",") if !strings.Contains(util.ObjToString((*qyxy)["bid_type"]), "2") { stype = append(stype, "2") Mgo.UpdateById(qyxyColl, (*qyxy)["_id"], bson.M{"$set": bson.M{"bid_type": strings.Join(stype, ",")}}) } } } } //for _, op := range operators { // if strings.Contains(winner, op) { // info["isOperators"] = true // break // } //} } //info["_id"] = mongodb.StringTOBsonId(id) delete(info, "_id") info["updatetime"] = time.Now().Unix() //savePool <- info update := []map[string]interface{}{{ "_id": mongodb.StringTOBsonId(id), }, {"$set": info}, } updatePool <- update } func periodMethod(str interface{}) int { if util.ObjToString(str) != "" { arr := numReg.FindStringSubmatch(util.ObjToString(str)) if len(arr) > 0 { return util.IntAll(arr[0]) } } return 0 } func YcEndTime(starttime int64, num int, unit string) int64 { yuceendtime := int64(0) if unit == "日历天" || unit == "天" || unit == "日" { yuceendtime = starttime + int64(num*86400) } else if unit == "周" { yuceendtime = time.Unix(starttime, 0).AddDate(0, 0, num*7).Unix() } else if unit == "月" { yuceendtime = time.Unix(starttime, 0).AddDate(0, num, 0).Unix() } else if unit == "年" { yuceendtime = time.Unix(starttime, 0).AddDate(num, 0, 0).Unix() } else if unit == "工作日" { n := num / 7 * 2 yuceendtime = time.Unix(starttime, 0).AddDate(0, 0, num+n).Unix() } return yuceendtime }