|
@@ -1,9 +1,11 @@
|
|
|
package main
|
|
|
|
|
|
import (
|
|
|
+ "fmt"
|
|
|
"log"
|
|
|
mgoutil "mongodb"
|
|
|
qu "qfw/util"
|
|
|
+ "strings"
|
|
|
"sync"
|
|
|
"time"
|
|
|
|
|
@@ -13,6 +15,56 @@ import (
|
|
|
//"go.mongodb.org/mongo-driver/bson/primitive"
|
|
|
)
|
|
|
|
|
|
+const ESMODEL = `
|
|
|
+{
|
|
|
+ "query": {
|
|
|
+ "filtered": {
|
|
|
+ "filter": {
|
|
|
+ "bool": {
|
|
|
+ "must": [
|
|
|
+ {
|
|
|
+ "term": {
|
|
|
+ "buyer": "%s"
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ },
|
|
|
+ "query": {
|
|
|
+ "bool": {
|
|
|
+ "should": [
|
|
|
+ {
|
|
|
+ "multi_match": {
|
|
|
+ "query": "%s",
|
|
|
+ "type": "phrase",
|
|
|
+ "fields": [
|
|
|
+ "purchasing",
|
|
|
+ "s_projectname",
|
|
|
+ "title"
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ "from": 0,
|
|
|
+ "size": 100,
|
|
|
+ "sort": [
|
|
|
+ {
|
|
|
+ "publishtime": "desc"
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ "_source": [
|
|
|
+ "buyerperson",
|
|
|
+ "buyertel",
|
|
|
+ "projectname",
|
|
|
+ "_id"
|
|
|
+ ]
|
|
|
+}
|
|
|
+`
|
|
|
+
|
|
|
func SaveMgo() {
|
|
|
log.Println("Mgo Save...")
|
|
|
arru := make([]map[string]interface{}, 200)
|
|
@@ -213,14 +265,12 @@ func GetProjectData(sid, eid string) {
|
|
|
ForecastFlag++
|
|
|
}
|
|
|
for _, t := range *result {
|
|
|
- // r := make(map[string]interface{})
|
|
|
- // r["stage"] = t["stage"]
|
|
|
- // r["purchase_classify"] = t["purchase_classify"]
|
|
|
- // r["purchasing"] = t["purchasing"]
|
|
|
- // r["top_category"] = t["top_category"]
|
|
|
- // r["sub_category"] = t["sub_category"]
|
|
|
t["p_rate"] = Rate
|
|
|
t["time"] = ""
|
|
|
+ projects := GetProjects(qu.ObjToString(t["purchasing"]), buyer)
|
|
|
+ if len(projects) > 0 {
|
|
|
+ t["p_projects"] = projects
|
|
|
+ }
|
|
|
maps = append(maps, t)
|
|
|
}
|
|
|
//qu.Debug("ForecastFlag---", ForecastFlag)
|
|
@@ -239,6 +289,49 @@ func GetProjectData(sid, eid string) {
|
|
|
log.Println("Run Over...Count:", sum)
|
|
|
}
|
|
|
|
|
|
+func GetProjects(purchasing, buyer string) (projects []map[string]interface{}) {
|
|
|
+ if purchasing != "" {
|
|
|
+ for _, text := range strings.Split(purchasing, ",") {
|
|
|
+ latest_project := map[string]interface{}{} //存储最后一条数据信息
|
|
|
+ result_project := map[string]interface{}{} //存储每个purchasing所查询的招标信息
|
|
|
+ esquery := fmt.Sprintf(ESMODEL, buyer, text)
|
|
|
+ list := Es.Get(Index, Itype, esquery)
|
|
|
+ if list != nil && len(*list) > 0 {
|
|
|
+ for i, l := range *list {
|
|
|
+ p_phone := qu.ObjToString(l["buyertel"])
|
|
|
+ if p_phone != "" { //记录有联系电话的最新信息
|
|
|
+ result_project["p_purchasing"] = text
|
|
|
+ result_project["p_phone"] = p_phone
|
|
|
+ if p_person := qu.ObjToString(l["buyerperson"]); p_person != "" {
|
|
|
+ result_project["p_person"] = p_person
|
|
|
+ }
|
|
|
+ result_project["p_id"] = qu.ObjToString(l["_id"])
|
|
|
+ result_project["p_orther"] = qu.ObjToString(l["projectname"])
|
|
|
+ break
|
|
|
+ }
|
|
|
+ if i == 0 { //记录第一条数据信息
|
|
|
+ latest_project["p_purchasing"] = text
|
|
|
+ // if p_phone != "" {
|
|
|
+ // latest_project["p_phone"] = p_phone
|
|
|
+ // }
|
|
|
+ if p_person := qu.ObjToString(l["buyerperson"]); p_person != "" {
|
|
|
+ latest_project["p_person"] = p_person
|
|
|
+ }
|
|
|
+ latest_project["p_id"] = qu.ObjToString(l["_id"])
|
|
|
+ latest_project["p_orther"] = qu.ObjToString(l["projectname"])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if len(result_project) > 0 {
|
|
|
+ projects = append(projects, result_project)
|
|
|
+ } else if len(latest_project) > 0 {
|
|
|
+ projects = append(projects, latest_project)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
/*
|
|
|
func GetProjectData_back(t string) {
|
|
|
defer qu.Catch()
|