xuzhiheng 5 years ago
parent
commit
4156df4aa3
3 changed files with 27 additions and 6 deletions
  1. 20 1
      src/history/historytask.go
  2. 5 4
      src/history/task.go
  3. 2 1
      src/history/util_history.go

+ 20 - 1
src/history/historytask.go

@@ -17,6 +17,7 @@ type HistoryData struct {
 
 func (this *HistoryData) HistoryTask(history_id string) {
 	log.Println("开始历史任务...")
+	go UpdateHistoryState(1, history_id, 0)
 	//加载一个客户
 	log.Println("history_id", history_id)
 	customer, _ := Mgo.Find("historylog", map[string]interface{}{"_id": qu.StringTOBsonId(history_id)}, nil, nil, false, -1, -1)
@@ -61,7 +62,8 @@ func (this *HistoryData) HistoryTask(history_id string) {
 		// log.Println("c.SaveDataMap111", cus.SaveDataMap)
 		cus.RemoveRepeatData() //数据去重
 		// log.Println("c.SaveDataMap222", cus.SaveDataMap)
-		cus.AssembelAndSaveData() //组装、保存数据
+		resultcount := cus.AssembelAndSaveData(history_id) //组装、保存数据
+		go UpdateHistoryState(2, history_id, resultcount)
 	} else {
 		log.Println("初始化客户信息失败")
 	}
@@ -79,3 +81,20 @@ func (this *HistoryData) HistoryList() {
 		this.Render("private/historylog_list.html", &this.T)
 	}
 }
+
+func UpdateHistoryState(state int, history_id string, count int) {
+	if state == 2 {
+		Mgo.Update("historylog", map[string]interface{}{"_id": qu.StringTOBsonId(history_id)}, map[string]interface{}{
+			"$set": map[string]interface{}{
+				"state":        state,
+				"result_count": count,
+			},
+		}, false, false)
+		return
+	}
+	Mgo.Update("historylog", map[string]interface{}{"_id": qu.StringTOBsonId(history_id)}, map[string]interface{}{
+		"$set": map[string]interface{}{
+			"state": state,
+		},
+	}, false, false)
+}

+ 5 - 4
src/history/task.go

@@ -357,7 +357,7 @@ func (c *Customer) RemoveRepeatData() {
 }
 
 //组装保存数据
-func (c *Customer) AssembelAndSaveData() {
+func (c *Customer) AssembelAndSaveData(historyId string) int {
 	log.Println("开始组装保存数据...")
 	defer qu.Catch()
 	ch := make(chan bool, 10)
@@ -372,7 +372,7 @@ func (c *Customer) AssembelAndSaveData() {
 					<-ch
 					wg.Done()
 				}()
-				AssembelSave(data, c.IsSearchHosp, c.IsSearchEnps)
+				AssembelSave(data, c.IsSearchHosp, c.IsSearchEnps, historyId)
 			}(tmp)
 			n++
 			if n%500 == 0 {
@@ -391,7 +391,7 @@ func (c *Customer) AssembelAndSaveData() {
 							<-ch
 							wg.Done()
 						}()
-						AssembelSave(data, c.IsSearchHosp, c.IsSearchEnps)
+						AssembelSave(data, c.IsSearchHosp, c.IsSearchEnps, historyId)
 					}(tmp)
 					n++
 					if n%500 == 0 {
@@ -410,7 +410,7 @@ func (c *Customer) AssembelAndSaveData() {
 					<-ch
 					wg.Done()
 				}()
-				AssembelSave(data, c.IsSearchHosp, c.IsSearchEnps)
+				AssembelSave(data, c.IsSearchHosp, c.IsSearchEnps, historyId)
 			}(tmp)
 			n++
 			if n%500 == 0 {
@@ -420,6 +420,7 @@ func (c *Customer) AssembelAndSaveData() {
 		wg.Wait()
 	}
 	log.Println("数据保存完毕...		Save Number:", n)
+	return n
 }
 
 //获取用户所有规则

+ 2 - 1
src/history/util_history.go

@@ -440,7 +440,7 @@ func MergeField(str1, str2 string) string {
 }
 
 //补充信息并保存
-func AssembelSave(tmp map[string]interface{}, IsSearchHosp, IsSearchEnps bool) {
+func AssembelSave(tmp map[string]interface{}, IsSearchHosp, IsSearchEnps bool, historyId string) {
 	if IsSearchHosp { //医院信息
 		SearchHospInfo(tmp)
 	}
@@ -448,6 +448,7 @@ func AssembelSave(tmp map[string]interface{}, IsSearchHosp, IsSearchEnps bool) {
 		SearchEnterpriseInfo(tmp)
 	}
 	tmp["createtime"] = time.Now().Unix()
+	tmp["historyId"] = historyId
 	id := qu.ObjToString(tmp["id"])
 	tmp["jybxhref"] = `https://www.jianyu360.com/article/content/` + qu.CommonEncodeArticle("content", id) + `.html`
 	if publishtime, ok := tmp["publishtime"].(float64); ok && publishtime > 0 {