Bladeren bron

项目Id判重appid配置为数组

xuzhiheng 5 jaren geleden
bovenliggende
commit
47d6d0e32e

+ 8 - 4
customerdata/src/config.json

@@ -20,9 +20,9 @@
 	"save": {
 		"addr": "192.168.3.207:27092",
 		"size": 15,
-		"db": "mxs",
-		"coll": "usermail_0806_03",
-		"coll_project": "usermail_projectid_0806_03"
+		"db": "xzh",
+		"coll": "usermail_0812_01",
+		"coll_project": "usermail_projectid_0812_01"
 	},
 	"es": {
 		"addr": "http://127.0.0.1:9800",
@@ -30,5 +30,9 @@
 		"itype": "bidding",
 		"pool": 15
 	},
-	"project_appid": "jyOh1XQgUJBQ5bTUlKCyZ1"
+	"project_appid": [
+		"111",
+		"222",
+		"jyPB1XQgsGBQNbQElICQNW"
+	]
 }

+ 9 - 0
customerdata/src/historytask.go

@@ -4,6 +4,7 @@ import (
 	"log"
 	qu "qfw/util"
 	"strings"
+	"time"
 	mgoutil "util/mgodb"
 )
 
@@ -36,6 +37,14 @@ func HistoryTask(name string) {
 			}
 		}
 
+		if projectAppidMap[appId] {
+			start := time.Now().Unix()
+			log.Println("加载projectId---开始")
+			InitProjectId()
+			end := time.Now().Unix()
+			log.Println("加载projectId---结束,耗时", end-start, "秒")
+		}
+
 		cus.GetTagRules()             //获取客户打标签规则
 		cus.GetDepartments("history") //获取客户信息
 		//PrintLog(cus)        //打印查看初始化的信息

+ 4 - 9
customerdata/src/main.go

@@ -6,7 +6,6 @@ import (
 	qu "qfw/util"
 	"qfw/util/elastic"
 	"sync"
-	"time"
 	"util/mgodb"
 
 	"github.com/donnie4w/go-logger/logger"
@@ -36,6 +35,7 @@ var (
 var MgoSaveCache = make(chan map[string]interface{}, 1000)
 var SP = make(chan bool, 5)
 var projectIdMap sync.Map
+var projectAppidMap = map[string]bool{}
 
 func init() {
 	qu.ReadConfig(&Sysconfig)
@@ -95,7 +95,9 @@ func init() {
 	// }
 	// AssembelSave(tmp, true, true)
 	// qu.Debug(tmp)
-
+	for _, v := range Sysconfig["project_appid"].([]interface{}) {
+		projectAppidMap[v.(string)] = true
+	}
 }
 func main() {
 	go SaveMgo()
@@ -105,13 +107,6 @@ func main() {
 	flag.Parse()
 	log.Println("customer", CustomerName)
 	if CustomerName != "" {
-		if CustomerName == "徐志恒的" {
-			start := time.Now().Unix()
-			log.Println("加载projectId---开始")
-			InitProjectId()
-			end := time.Now().Unix()
-			log.Println("加载projectId---结束,耗时", end-start, "秒")
-		}
 		go HistoryTask(CustomerName)
 	} else {
 		go TimeTask() //定时任务

+ 3 - 3
customerdata/src/task.go

@@ -68,7 +68,7 @@ func GetCustomerData() {
 			}
 		}
 		//
-		if appId == qu.ObjToString(Sysconfig["project_appid"]) {
+		if projectAppidMap[appId] {
 			start := time.Now().Unix()
 			log.Println("加载projectId---开始")
 			InitProjectId()
@@ -218,8 +218,8 @@ func (c *Customer) GetData(stype string) {
 											}
 											//从最新年报中获取 中标单位联系电话、中标单位邮箱
 											if annual_reports, ok := finddata["annual_reports"].(primitive.A); ok && len(annual_reports) > 0 {
-												anreport:=Sort_year_report(annual_reports)
-												if len(anreport)>0{
+												anreport := Sort_year_report(annual_reports)
+												if len(anreport) > 0 {
 													if email := qu.ObjToString(anreport["company_email"]); email != "" {
 														tmp["company_email"] = email
 													}

+ 1 - 2
customerdata/src/util.go

@@ -457,7 +457,7 @@ func AssembelSave(tmp map[string]interface{}, IsSearchHosp, IsSearchEnps bool, a
 		tmp["bidopentime"] = qu.Int64All(bidopentime)
 	}
 	//
-	if appid == qu.ObjToString(Sysconfig["project_appid"]) {
+	if projectAppidMap[appid] {
 		projectId := GetProjectId(id)
 		if projectId != "" {
 			projectIds := strings.Split(projectId, ",")
@@ -809,7 +809,6 @@ func InitProjectId() {
 		log.Printf("本次共取到%d个projectId\n", count)
 	}()
 	save := Sysconfig["save"].(map[string]interface{})
-	log.Println(Sysconfig["project_appid"])
 	query := map[string]interface{}{"appid": Sysconfig["project_appid"]}
 	field := map[string]interface{}{"projectId": 1}
 	iter := session.DB(qu.ObjToString(save["db"])).C(SaveColl).Find(query).Select(field).Sort("_id").Iter()

+ 8 - 2
src/config.json

@@ -46,7 +46,8 @@
 		"addr": "192.168.3.207:27092",
 		"size": 15,
 		"db": "datatag_ent",
-		"coll": "usermail_history"
+		"coll": "usermail_history",
+		"coll_project": "usermail_history_projectid"
 	},
 	"es": {
 		"addr": "http://192.168.3.128:9800",
@@ -61,5 +62,10 @@
             "pwd": "ue9Rg9Sf4CVtdm5a",
             "user": "public03@topnet.net.cn"
         }
-    ]
+    ],
+    "project_appid": [
+		"111",
+		"222",
+		"jyPB1XQgsGBQNbQElICQNW"
+	]
 }

+ 2 - 0
src/history/datamodel.go

@@ -70,6 +70,8 @@ var FielsArr = map[string]interface{}{
 	"company_address":  "中标单位注册地址(公示网站)",
 	"tagname":          "标签名称",
 }
+var ProjectAppidMap = map[string]bool{}
+var projectIdMap = sync.Map{}
 
 //客户模型
 type Customer struct {

+ 9 - 0
src/history/historytask.go

@@ -49,6 +49,15 @@ func (this *HistoryData) HistoryTask(history_id string) {
 				cus.IsSearchEnps = true
 			}
 		}
+		//
+		if ProjectAppidMap[appId] {
+			start := time.Now().Unix()
+			log.Println("加载projectId---开始")
+			InitProjectId()
+			end := time.Now().Unix()
+			log.Println("加载projectId---结束,耗时", end-start, "秒")
+		}
+		//
 		tag_rule, ok := c["tag_rules"].([]interface{})
 		if !ok {
 			tag_rule = []interface{}{}

+ 13 - 4
src/history/task.go

@@ -167,7 +167,7 @@ func (c *Customer) GetData(stype string) {
 											//从最新年报中获取 中标单位联系电话、中标单位邮箱
 											if annual_reports, ok := finddata["annual_reports"].(primitive.A); ok && len(annual_reports) > 0 {
 												anreport := Sort_year_report(annual_reports)
-												if len(anreport)>0{
+												if len(anreport) > 0 {
 													if email := qu.ObjToString(anreport["company_email"]); email != "" {
 														tmp["company_email"] = email
 													}
@@ -373,7 +373,10 @@ func (c *Customer) AssembelAndSaveData(historyId string) int {
 					<-ch
 					wg.Done()
 				}()
-				AssembelSave(data, c.IsSearchHosp, c.IsSearchEnps, historyId)
+				ok := AssembelSave(data, c.IsSearchHosp, c.IsSearchEnps, historyId, c.AppId)
+				if !ok {
+					n--
+				}
 			}(tmp)
 			n++
 			if n%500 == 0 {
@@ -392,7 +395,10 @@ func (c *Customer) AssembelAndSaveData(historyId string) int {
 							<-ch
 							wg.Done()
 						}()
-						AssembelSave(data, c.IsSearchHosp, c.IsSearchEnps, historyId)
+						ok := AssembelSave(data, c.IsSearchHosp, c.IsSearchEnps, historyId, c.AppId)
+						if !ok {
+							n--
+						}
 					}(tmp)
 					n++
 					if n%500 == 0 {
@@ -411,7 +417,10 @@ func (c *Customer) AssembelAndSaveData(historyId string) int {
 					<-ch
 					wg.Done()
 				}()
-				AssembelSave(data, c.IsSearchHosp, c.IsSearchEnps, historyId)
+				ok := AssembelSave(data, c.IsSearchHosp, c.IsSearchEnps, historyId, c.AppId)
+				if !ok {
+					n--
+				}
 			}(tmp)
 			n++
 			if n%500 == 0 {

+ 67 - 3
src/history/util_history.go

@@ -1,6 +1,7 @@
 package history
 
 import (
+	"fmt"
 	"log"
 	"os"
 	qu "qfw/util"
@@ -446,7 +447,7 @@ func MergeField(str1, str2 string) string {
 }
 
 //补充信息并保存
-func AssembelSave(tmp map[string]interface{}, IsSearchHosp, IsSearchEnps bool, historyId string) {
+func AssembelSave(tmp map[string]interface{}, IsSearchHosp, IsSearchEnps bool, historyId, appid string) bool {
 	if IsSearchHosp { //医院信息
 		SearchHospInfo(tmp)
 	}
@@ -463,7 +464,28 @@ func AssembelSave(tmp map[string]interface{}, IsSearchHosp, IsSearchEnps bool, h
 	if bidopentime, ok := tmp["bidopentime"].(float64); ok && bidopentime > 0 {
 		tmp["bidopentime"] = qu.Int64All(bidopentime)
 	}
+	//
+	if ProjectAppidMap[appid] {
+		projectId := GetProjectId(id)
+		if projectId != "" {
+			projectIds := strings.Split(projectId, ",")
+			tmp["projectId"] = projectId
+			isOk := true
+			for _, v := range projectIds {
+				if _, ok := projectIdMap.Load(v); ok {
+					isOk = false
+				} else {
+					projectIdMap.Store(v, true)
+				}
+			}
+			if !isOk {
+				MgoSave.Save(SaveCollProject, tmp)
+				return false
+			}
+		}
+	}
 	MgoSaveCache <- tmp
+	return true
 }
 
 //查询第三方医院等级信息和招标客户的社会征信代码
@@ -541,8 +563,8 @@ func SearchEnterpriseInfo(tmp map[string]interface{}) {
 			}
 			//从最新年报中获取 中标单位联系电话、中标单位邮箱
 			if annual_reports, ok := data["annual_reports"].(primitive.A); ok && len(annual_reports) > 0 {
-				anreport:=Sort_year_report(annual_reports)
-				if len(anreport)>0{
+				anreport := Sort_year_report(annual_reports)
+				if len(anreport) > 0 {
 					if email := qu.ObjToString(anreport["company_email"]); email != "" {
 						tmp["company_email"] = email
 					}
@@ -853,3 +875,45 @@ func PathExists(path string) (bool, error) {
 	}
 	return false, err
 }
+
+func GetProjectId(id string) string {
+	query := `{"query": {"bool": {"must": [{"term": {"projectset.ids": "%s"}}],"must_not": [],"should": []}}}`
+	querys := fmt.Sprintf(query, id)
+	projectId := ""
+	projectIdArr := []string{}
+	data := Es.Get("projectset", "projectset", querys)
+	if data != nil && *data != nil && len(*data) > 0 {
+		for _, v := range *data {
+			projectIdArr = append(projectIdArr, qu.ObjToString(v["_id"]))
+
+		}
+		projectId = strings.Join(projectIdArr, ",")
+		log.Println("projectId", projectId)
+	}
+	return projectId
+}
+
+func InitProjectId() {
+	session := MgoSave.GetMgoConn()
+	count := 0
+	defer func() {
+		MgoSave.DestoryMongoConn(session)
+		log.Printf("本次共取到%d个projectId\n", count)
+	}()
+	save := Sysconfig["save"].(map[string]interface{})
+	query := map[string]interface{}{"appid": Sysconfig["project_appid"]}
+	field := map[string]interface{}{"projectId": 1}
+	iter := session.DB(qu.ObjToString(save["db"])).C(SaveColl).Find(query).Select(field).Sort("_id").Iter()
+	thisData := map[string]interface{}{}
+	for {
+		if !iter.Next(&thisData) {
+			break
+		}
+		projectId := qu.ObjToString(thisData["projectId"])
+		if projectId != "" {
+			projectIdMap.Store(projectId, true)
+			count++
+		}
+		thisData = map[string]interface{}{}
+	}
+}

+ 3 - 0
src/main.go

@@ -53,6 +53,9 @@ func init() {
 			}
 		}
 	}
+	for _, v := range util.Sysconfig["project_appid"].([]interface{}) {
+		history.ProjectAppidMap[v.(string)] = true
+	}
 }
 
 func main() {

+ 3 - 1
src/service/customer_service.go

@@ -908,7 +908,7 @@ func (c *Customer) CustomerHistory() {
 			c.T["data"] = *hData
 		}
 	} else {
-		var user_name, user_customername, user_salesperson = "", "", ""
+		var user_name, user_customername, user_salesperson, appid = "", "", "", ""
 		var push_model, push_type, i_push = 0, 0, 0
 		userInfo, ok := Mgo.FindOne("euser", query)
 		if ok && userInfo != nil && *userInfo != nil {
@@ -918,6 +918,7 @@ func (c *Customer) CustomerHistory() {
 			push_model = qu.IntAll((*userInfo)["i_pushmodel"])
 			push_type = qu.IntAll((*userInfo)["i_pushtype"])
 			i_push = qu.IntAll((*userInfo)["i_push"])
+			appid = qu.ObjToString((*userInfo)["s_appid"])
 		}
 		history_id = Mgo.Save("historylog", map[string]interface{}{
 			"createtime":     time.Now().Unix(),
@@ -931,6 +932,7 @@ func (c *Customer) CustomerHistory() {
 			"i_pushmodel":    push_model,
 			"i_pushtype":     push_type,
 			"i_push":         i_push,
+			"s_appid":        appid,
 		})
 		c.Redirect("/service/customer/history?id=" + id + "&hid=" + history_id)
 		return

+ 5 - 3
src/util/config.go

@@ -31,9 +31,10 @@ var (
 	Itype           string
 	TaskTime        int64 //定时任务时间
 	//历史数据
-	SId           string
-	EId           string
-	CustomerName  string
+	SId             string
+	EId             string
+	CustomerName    string
+	SaveCollProject string
 )
 
 var (
@@ -185,6 +186,7 @@ func initdb() {
 	//mgo save
 	save := Sysconfig["save"].(map[string]interface{})
 	SaveColl = qu.ObjToString(save["coll"])
+	SaveCollProject = qu.ObjToString(save["coll"])
 	MgoSave = &mgo.MongodbSim{
 		MongodbAddr: qu.ObjToString(save["addr"]),
 		DbName:      qu.ObjToString(save["db"]),