|
@@ -14,6 +14,10 @@ import (
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
+var (
|
|
|
+ ArrLock []sync.Mutex
|
|
|
+)
|
|
|
+
|
|
|
func init() {
|
|
|
config.Init("./common.toml")
|
|
|
InitLog()
|
|
@@ -26,6 +30,10 @@ func init() {
|
|
|
updateSp = make(chan bool, 5)
|
|
|
recordPool = make(chan []map[string]interface{}, 5000)
|
|
|
recordSp = make(chan bool, 5)
|
|
|
+
|
|
|
+ for i := 0; i < config.Conf.Serve.Thread; i++ {
|
|
|
+ ArrLock = append(ArrLock, sync.Mutex{})
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
func main() {
|
|
@@ -38,39 +46,47 @@ func main() {
|
|
|
ch := make(chan bool, config.Conf.Serve.Thread)
|
|
|
wg := &sync.WaitGroup{}
|
|
|
|
|
|
- q := map[string]interface{}{"_id": mongodb.StringTOBsonId("639751bb063a7b816e026aa1")}
|
|
|
- it := sess.DB(config.Conf.DB.Mongo.Dbname).C("bidding_fusion").Find(q).Select(nil).Iter()
|
|
|
+ //q := map[string]interface{}{"_id": mongodb.StringTOBsonId("635ff15d631ff1ac3d095c41")}
|
|
|
+ //f := map[string]interface{}{"contenthtml": 0}
|
|
|
+ it := sess.DB(config.Conf.DB.Mongo.Dbname).C("bidding_fusion").Find(nil).Select(nil).Iter()
|
|
|
count := 0
|
|
|
for tmp := make(map[string]interface{}); it.Next(tmp); count++ {
|
|
|
- if count%2000 == 0 {
|
|
|
+ if count%20000 == 0 {
|
|
|
log.Info("main", zap.Int("current:", count))
|
|
|
}
|
|
|
- if repeat := util.IntAll(tmp["repeat"]); repeat != 1 {
|
|
|
+ if repeat := util.IntAll(tmp["extracttype"]); repeat != -1 {
|
|
|
continue
|
|
|
}
|
|
|
ch <- true
|
|
|
wg.Add(1)
|
|
|
+
|
|
|
+ rid := util.ObjToString(tmp["repeat_id"])
|
|
|
+ ArrLock[util.HashCode(rid)%config.Conf.Serve.Thread].Lock()
|
|
|
+
|
|
|
go func(tmp map[string]interface{}) {
|
|
|
- defer func() {
|
|
|
+ defer func(rid string) {
|
|
|
<-ch
|
|
|
wg.Done()
|
|
|
- }()
|
|
|
+
|
|
|
+ ArrLock[util.HashCode(rid)%config.Conf.Serve.Thread].Unlock()
|
|
|
+ }(rid)
|
|
|
repeatId := util.ObjToString(tmp["repeat_id"])
|
|
|
if str := redis.GetStr("fusion_id", repeatId); str != "" {
|
|
|
mid := strings.Split(str, "-")[0]
|
|
|
- tmp1, _ := MgoB.FindById("bidding_fusion", mid, nil)
|
|
|
+ tmp1 := findData(mid)
|
|
|
w, s := getWeight(tmp)
|
|
|
- w1, s1 := getWeight(*tmp1)
|
|
|
- util.Debug(w, s, w1, s1)
|
|
|
+ w1, _ := getWeight(tmp1)
|
|
|
var update map[string]interface{}
|
|
|
+ var fs []string
|
|
|
if w > w1 {
|
|
|
- update = mergeTmp(tmp, *tmp1)
|
|
|
- //if len(update) > 0 {
|
|
|
- // updatePool <- []map[string]interface{}{
|
|
|
- // {"_id": tmp["_id"]},
|
|
|
- // {"$set": update},
|
|
|
- // }
|
|
|
- //}
|
|
|
+ update, fs = mergeTmp(tmp, tmp1)
|
|
|
+ if len(update) > 0 {
|
|
|
+ updatePool <- []map[string]interface{}{
|
|
|
+ {"_id": tmp["_id"]},
|
|
|
+ {"$set": update, "$addToSet": map[string]interface{}{"fusion_fields": map[string]interface{}{"$each": fs}}},
|
|
|
+ //{"$addToSet": map[string]interface{}{"fusion_fields": map[string]interface{}{"$each": fs}}},
|
|
|
+ }
|
|
|
+ }
|
|
|
record := make(map[string]interface{})
|
|
|
record["$set"] = map[string]interface{}{
|
|
|
"template_id": mongodb.BsonIdToSId(tmp["_id"]),
|
|
@@ -92,13 +108,14 @@ func main() {
|
|
|
}
|
|
|
redis.PutCKV("fusion_id", repeatId, fmt.Sprintf("%s-%s", mongodb.BsonIdToSId(tmp["_id"]), str))
|
|
|
} else {
|
|
|
- update = mergeTmp(*tmp1, tmp)
|
|
|
- //if len(update) > 0 {
|
|
|
- // updatePool <- []map[string]interface{}{
|
|
|
- // {"_id": (*tmp1)["_id"]},
|
|
|
- // {"$set": update},
|
|
|
- // }
|
|
|
- //}
|
|
|
+ update, fs = mergeTmp(tmp1, tmp)
|
|
|
+ if len(update) > 0 {
|
|
|
+ updatePool <- []map[string]interface{}{
|
|
|
+ {"_id": (tmp1)["_id"]},
|
|
|
+ {"$set": update, "$addToSet": map[string]interface{}{"fusion_fields": map[string]interface{}{"$each": fs}}},
|
|
|
+ //{"$addToSet": map[string]interface{}{"fusion_fields": map[string]interface{}{"$each": fs}}},
|
|
|
+ }
|
|
|
+ }
|
|
|
record := make(map[string]interface{})
|
|
|
record["$set"] = map[string]interface{}{
|
|
|
"template_weight": w1,
|
|
@@ -117,30 +134,35 @@ func main() {
|
|
|
{"_id": mongodb.StringTOBsonId(repeatId)},
|
|
|
record,
|
|
|
}
|
|
|
- redis.PutCKV("fusion_id", repeatId, fmt.Sprintf("%s-%s", str, mongodb.BsonIdToSId(tmp["_id"])))
|
|
|
+ redis.PutCKV("fusion_id", mid, fmt.Sprintf("%s-%s", str, mongodb.BsonIdToSId(tmp["_id"])))
|
|
|
}
|
|
|
} else {
|
|
|
- tmp1, _ := MgoB.FindById("bidding_fusion", repeatId, nil)
|
|
|
+ tmp1 := findData(repeatId)
|
|
|
w, s := getWeight(tmp)
|
|
|
- w1, s1 := getWeight(*tmp1)
|
|
|
+ w1, s1 := getWeight(tmp1)
|
|
|
var update map[string]interface{}
|
|
|
+ var fs []string
|
|
|
if w > w1 {
|
|
|
- update = mergeTmp(tmp, *tmp1)
|
|
|
- //if len(update) > 0 {
|
|
|
- // updatePool <- []map[string]interface{}{
|
|
|
- // {"_id": tmp["_id"]},
|
|
|
- // {"$set": update},
|
|
|
- // }
|
|
|
- //}
|
|
|
+ update, fs = mergeTmp(tmp, tmp1)
|
|
|
+ if len(update) > 0 {
|
|
|
+ set := util.DeepCopy(update).(map[string]interface{})
|
|
|
+ set["fusion_fields"] = fs
|
|
|
+ updatePool <- []map[string]interface{}{
|
|
|
+ {"_id": tmp["_id"]},
|
|
|
+ {"$set": set},
|
|
|
+ //{"$addToSet": map[string]interface{}{"fusion_fields": map[string]interface{}{"$each": fs}}},
|
|
|
+ //{"$set": map[string]interface{}{"fusion_fields": fs}},
|
|
|
+ }
|
|
|
+ }
|
|
|
record := make(map[string]interface{})
|
|
|
- record["_id"] = (*tmp1)["_id"]
|
|
|
+ record["_id"] = tmp1["_id"]
|
|
|
record["template_id"] = mongodb.BsonIdToSId(tmp["_id"])
|
|
|
record["template_weight"] = w
|
|
|
record["ids"] = []string{mongodb.BsonIdToSId(tmp["_id"]), mongodb.BsonIdToSId(repeatId)}
|
|
|
var recordlist []map[string]interface{}
|
|
|
recordlist = append(recordlist, map[string]interface{}{"infoid": mongodb.BsonIdToSId(tmp["_id"]), "weight": w})
|
|
|
update1 := util.DeepCopy(update).(map[string]interface{})
|
|
|
- update1["infoid"] = mongodb.BsonIdToSId((*tmp1)["_id"])
|
|
|
+ update1["infoid"] = mongodb.BsonIdToSId(tmp1["_id"])
|
|
|
update1["weight"] = w1
|
|
|
if w1 == 0 {
|
|
|
update1["remark"] = s1
|
|
@@ -148,25 +170,29 @@ func main() {
|
|
|
recordlist = append(recordlist, update1)
|
|
|
record["record"] = recordlist
|
|
|
recordPool <- []map[string]interface{}{
|
|
|
- {"_id": (*tmp1)["_id"]},
|
|
|
+ {"_id": tmp1["_id"]},
|
|
|
{"$set": record},
|
|
|
}
|
|
|
- redis.PutCKV("fusion_id", repeatId, fmt.Sprintf("%s-%s", mongodb.BsonIdToSId(tmp["_id"]), mongodb.BsonIdToSId((*tmp1)["_id"])))
|
|
|
+ redis.PutCKV("fusion_id", repeatId, fmt.Sprintf("%s-%s", mongodb.BsonIdToSId(tmp["_id"]), mongodb.BsonIdToSId(tmp1["_id"])))
|
|
|
} else {
|
|
|
- update = mergeTmp(*tmp1, tmp)
|
|
|
- //if len(update) > 0 {
|
|
|
- // updatePool <- []map[string]interface{}{
|
|
|
- // {"_id": (*tmp1)["_id"]},
|
|
|
- // {"$set": update},
|
|
|
- // }
|
|
|
- //}
|
|
|
+ update, fs = mergeTmp(tmp1, tmp)
|
|
|
+ if len(update) > 0 {
|
|
|
+ set := util.DeepCopy(update).(map[string]interface{})
|
|
|
+ set["fusion_fields"] = fs
|
|
|
+ updatePool <- []map[string]interface{}{
|
|
|
+ {"_id": tmp1["_id"]},
|
|
|
+ {"$set": set},
|
|
|
+ //{"$addToSet": map[string]interface{}{"fusion_fields": map[string]interface{}{"$each": fs}}},
|
|
|
+ //{"$set": map[string]interface{}{"fusion_fields": fs}},
|
|
|
+ }
|
|
|
+ }
|
|
|
record := make(map[string]interface{})
|
|
|
- record["_id"] = (*tmp1)["_id"]
|
|
|
- record["template_id"] = mongodb.BsonIdToSId((*tmp1)["_id"])
|
|
|
+ record["_id"] = tmp1["_id"]
|
|
|
+ record["template_id"] = mongodb.BsonIdToSId(tmp1["_id"])
|
|
|
record["template_weight"] = w1
|
|
|
- record["ids"] = []string{mongodb.BsonIdToSId(tmp["_id"]), mongodb.BsonIdToSId((*tmp1)["_id"])}
|
|
|
+ record["ids"] = []string{mongodb.BsonIdToSId(tmp["_id"]), mongodb.BsonIdToSId(tmp1["_id"])}
|
|
|
var recordlist []map[string]interface{}
|
|
|
- recordlist = append(recordlist, map[string]interface{}{"infoid": mongodb.BsonIdToSId((*tmp1)["_id"]), "weight": w1})
|
|
|
+ recordlist = append(recordlist, map[string]interface{}{"infoid": mongodb.BsonIdToSId(tmp1["_id"]), "weight": w1})
|
|
|
update1 := util.DeepCopy(update).(map[string]interface{})
|
|
|
update1["infoid"] = mongodb.BsonIdToSId(tmp["_id"])
|
|
|
update1["weight"] = w
|
|
@@ -176,21 +202,35 @@ func main() {
|
|
|
recordlist = append(recordlist, update1)
|
|
|
record["record"] = recordlist
|
|
|
recordPool <- []map[string]interface{}{
|
|
|
- {"_id": (*tmp1)["_id"]},
|
|
|
+ {"_id": tmp1["_id"]},
|
|
|
{"$set": record},
|
|
|
}
|
|
|
- redis.PutCKV("fusion_id", repeatId, fmt.Sprintf("%s-%s", mongodb.BsonIdToSId((*tmp1)["_id"]), mongodb.BsonIdToSId(tmp["_id"])))
|
|
|
+ redis.PutCKV("fusion_id", repeatId, fmt.Sprintf("%s-%s", mongodb.BsonIdToSId(tmp1["_id"]), mongodb.BsonIdToSId(tmp["_id"])))
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
}(tmp)
|
|
|
tmp = map[string]interface{}{}
|
|
|
}
|
|
|
+ wg.Wait()
|
|
|
|
|
|
+ log.Info("fusion over...", zap.Int("count:", count))
|
|
|
c := make(chan bool, 1)
|
|
|
<-c
|
|
|
}
|
|
|
|
|
|
+func findData(id string) map[string]interface{} {
|
|
|
+ tmp, _ := MgoB.FindById("bidding_fusion", id, nil)
|
|
|
+ if tmp != nil && len(*tmp) > 0 {
|
|
|
+ return *tmp
|
|
|
+ } else {
|
|
|
+ tmp, _ = MgoB.FindById("bidding", id, nil)
|
|
|
+ if tmp != nil && len(*tmp) > 0 {
|
|
|
+ return *tmp
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return nil
|
|
|
+}
|
|
|
+
|
|
|
func getWeight(tmp map[string]interface{}) (int, string) {
|
|
|
var w int
|
|
|
if util.IntAll(tmp["publishtime"]) <= 0 {
|
|
@@ -201,17 +241,30 @@ func getWeight(tmp map[string]interface{}) (int, string) {
|
|
|
}
|
|
|
for k, v := range config.Conf.Serve.Weight {
|
|
|
if tmp[k] != nil {
|
|
|
- util.Debug(k)
|
|
|
- if reflect.TypeOf(tmp[k]).String() == "string" {
|
|
|
- if util.ObjToString(tmp[k]) != "" {
|
|
|
- w += v
|
|
|
+ if k == "attachments" {
|
|
|
+ if pinfo, ok := tmp["projectinfo"].(map[string]interface{}); ok {
|
|
|
+ if atts, o2 := pinfo["attachments"].(map[string]interface{}); o2 {
|
|
|
+ if len(atts) > 0 {
|
|
|
+ w += v
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
- } else if reflect.TypeOf(tmp[k]).String() == "float64" {
|
|
|
- if util.Float64All(tmp[k]) > 0 {
|
|
|
+ } else {
|
|
|
+ if reflect.TypeOf(tmp[k]).String() == "string" {
|
|
|
+ if util.ObjToString(tmp[k]) != "" {
|
|
|
+ w += v
|
|
|
+ }
|
|
|
+ } else if reflect.TypeOf(tmp[k]).String() == "float64" {
|
|
|
+ if util.Float64All(tmp[k]) > 0 {
|
|
|
+ w += v
|
|
|
+ }
|
|
|
+ } else if reflect.TypeOf(tmp[k]).String() == "[]interface {}" {
|
|
|
+ if len(tmp[k].([]interface{})) > 0 {
|
|
|
+ w += v
|
|
|
+ }
|
|
|
+ } else {
|
|
|
w += v
|
|
|
}
|
|
|
- } else {
|
|
|
- w += v
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -220,20 +273,51 @@ func getWeight(tmp map[string]interface{}) (int, string) {
|
|
|
|
|
|
// @Description tmp模版数据, tmp1补充数据
|
|
|
// @Author J 2023/1/3 11:31
|
|
|
-func mergeTmp(tmp map[string]interface{}, tmp1 map[string]interface{}) map[string]interface{} {
|
|
|
+func mergeTmp(tmp map[string]interface{}, tmp1 map[string]interface{}) (map[string]interface{}, []string) {
|
|
|
update := make(map[string]interface{})
|
|
|
+ var fs []string
|
|
|
for _, v := range config.Conf.Serve.Fields {
|
|
|
- if tmp[v] == nil && tmp1[v] != nil {
|
|
|
- if reflect.TypeOf(tmp1[v]).String() == "string" && util.ObjToString(tmp1[v]) != "" {
|
|
|
- update[v] = util.ObjToString(tmp1[v])
|
|
|
- } else if reflect.TypeOf(tmp1[v]).String() == "[]interface {}" && len(tmp1[v].([]interface{})) > 0 {
|
|
|
- update[v] = tmp1[v]
|
|
|
- } else {
|
|
|
- update[v] = tmp1[v]
|
|
|
+ if v == "attachments" {
|
|
|
+ if pinfo1, ok1 := tmp1["projectinfo"].(map[string]interface{}); ok1 {
|
|
|
+ if ats, ok2 := pinfo1[v].(map[string]interface{}); ok2 {
|
|
|
+ if pinfo1[v] != nil && len(ats) > 0 {
|
|
|
+ if pinfo, ok := tmp["projectinfo"].(map[string]interface{}); ok {
|
|
|
+ if pinfo[v] == nil {
|
|
|
+ pinfo[v] = pinfo1[v]
|
|
|
+ update["projectinfo"] = pinfo
|
|
|
+ update["attach_text"] = tmp1["attach_text"] // 补充附件文本
|
|
|
+ fs = append(fs, v)
|
|
|
+ fs = append(fs, "attach_text")
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ update["projectinfo"] = map[string]interface{}{v: pinfo1[v]}
|
|
|
+ update["attach_text"] = tmp1["attach_text"]
|
|
|
+ fs = append(fs, v)
|
|
|
+ fs = append(fs, "attach_text")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if pinfo1[v] != nil {
|
|
|
+ log.Error("mergeTmp err...", zap.Any("id", mongodb.BsonIdToSId(tmp1["_id"])))
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if tmp[v] == nil && tmp1[v] != nil {
|
|
|
+ if reflect.TypeOf(tmp1[v]).String() == "string" && util.ObjToString(tmp1[v]) != "" {
|
|
|
+ update[v] = util.ObjToString(tmp1[v])
|
|
|
+ fs = append(fs, v)
|
|
|
+ } else if reflect.TypeOf(tmp1[v]).String() == "[]interface {}" && len(tmp1[v].([]interface{})) > 0 {
|
|
|
+ update[v] = tmp1[v]
|
|
|
+ fs = append(fs, v)
|
|
|
+ } else {
|
|
|
+ update[v] = tmp1[v]
|
|
|
+ fs = append(fs, v)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- return update
|
|
|
+ return update, fs
|
|
|
}
|
|
|
|
|
|
func updateMethod() {
|