Browse Source

xlsx少数据问题

xuzhiheng 5 years ago
parent
commit
19ac351c00
4 changed files with 58 additions and 15 deletions
  1. 5 2
      src/history/historytask.go
  2. 10 7
      src/history/task.go
  3. 43 6
      src/history/util_history.go
  4. BIN
      src/web/res/fields.xlsx

+ 5 - 2
src/history/historytask.go

@@ -77,10 +77,13 @@ func (this *HistoryData) HistoryTask(history_id string) {
 		cus.GetData("history")                             //获取数据
 		cus.RemoveRepeatData()                             //数据去重
 		resultcount := cus.AssembelAndSaveData(history_id) //组装、保存数据
-		time.Sleep(2 * time.Second)
 		//发邮件
 		log.Println("xlsxArr", len(xlsxArr))
-		GetXlsxs(xlsxArr, customer_name, email, history_id)
+		if len(xlsxArr) == resultcount {
+			GetXlsxs(xlsxArr, customer_name, email, history_id)
+		} else {
+			log.Println("excel数据量错误")
+		}
 		xlsxArr = []map[string]interface{}{}
 		go UpdateHistoryState(2, history_id, resultcount)
 	} else {

+ 10 - 7
src/history/task.go

@@ -203,18 +203,18 @@ func (c *Customer) GetData(stype string) {
 								*/
 								//1.附加词匹配
 								IsMatch := false
-								qu.Debug("sr.AW---", len(sr.AW))
+								// qu.Debug("sr.AW---", len(sr.AW))
 								for i, aw := range sr.AW {
-									qu.Debug("-------------------------开始附加词匹配--------------------------")
+									// qu.Debug("-------------------------开始附加词匹配--------------------------")
 									IsMatchAddKey := RegMatch(fieldText, aw.MatchType, aw.KeyReg, nil, nil, false, true)
-									qu.Debug(IsMatchAddKey, "------------------------------------------------------------")
+									// qu.Debug(IsMatchAddKey, "------------------------------------------------------------")
 
 									//2.关键词匹配
 									if IsMatchAddKey {
 										kw := sr.KW[i]
-										qu.Debug("-------------------------开始关键词匹配--------------------------")
+										// qu.Debug("-------------------------开始关键词匹配--------------------------")
 										IsMatchKey := RegMatch(fieldText, kw.MatchType, kw.KeyReg, matchKey, matchKeyType, true, false)
-										qu.Debug(IsMatchKey, "------------------------------------------------------------")
+										// qu.Debug(IsMatchKey, "------------------------------------------------------------")
 										if IsMatchKey {
 											IsMatch = true
 										}
@@ -223,7 +223,7 @@ func (c *Customer) GetData(stype string) {
 								/*
 									到此已经匹配完数据
 								*/
-								qu.Debug("---------------------", id, IsMatch, matchKey)
+								// qu.Debug("---------------------", id, IsMatch, matchKey)
 								if IsMatch { //匹配成功,数据上新增规则id,matchKey,item并临时保存数据
 									tmpMatchKey := MapDataToArr(matchKey)
 									tmpMatchKeyType := MapDataToArr(matchKeyType)
@@ -300,7 +300,7 @@ func (c *Customer) GetData(stype string) {
 									dm.DepartmentData[sr.ID] = append(dm.DepartmentData[sr.ID], tmpMap)
 									dm.DataLock.Unlock()
 								} else {
-									qu.Debug("------------", id, IsMatch)
+									// qu.Debug("------------", id, IsMatch)
 								}
 							}
 						}(hit)
@@ -379,6 +379,7 @@ func (c *Customer) AssembelAndSaveData(historyId string) int {
 				}
 			}(tmp)
 			n++
+			xlsxArr = append(xlsxArr, tmp)
 			if n%500 == 0 {
 				log.Println("Current:", n)
 			}
@@ -401,6 +402,7 @@ func (c *Customer) AssembelAndSaveData(historyId string) int {
 						}
 					}(tmp)
 					n++
+					xlsxArr = append(xlsxArr, tmp)
 					if n%500 == 0 {
 						log.Println("Current:", n)
 					}
@@ -423,6 +425,7 @@ func (c *Customer) AssembelAndSaveData(historyId string) int {
 				}
 			}(tmp)
 			n++
+			xlsxArr = append(xlsxArr, tmp)
 			if n%500 == 0 {
 				log.Println("Current:", n)
 			}

+ 43 - 6
src/history/util_history.go

@@ -484,7 +484,6 @@ func AssembelSave(tmp map[string]interface{}, IsSearchHosp, IsSearchEnps bool, h
 			}
 		}
 	}
-	xlsxArr = append(xlsxArr, tmp)
 	MgoSaveCache <- tmp
 	return true
 }
@@ -882,7 +881,7 @@ func GetXlsxs(mMap []map[string]interface{}, fn, email, id string) {
 				for i, v := range mMap {
 					row := sh.AddRow()
 					row.AddCell().SetInt(i + 1)
-					row.AddCell().SetValue(v["s_matchkey"])
+					row.AddCell().SetValue(v["matchkey"])
 					row.AddCell().SetValue(v["area"])
 					row.AddCell().SetValue(v["city"])
 					row.AddCell().SetValue(v["title"])
@@ -903,13 +902,13 @@ func GetXlsxs(mMap []map[string]interface{}, fn, email, id string) {
 					row.AddCell().SetValue(v["detail"])
 					row.AddCell().SetValue(v["s_jyhref"])
 				}
-				xf.Sheets = xf.Sheets[:1]
+				xf.Sheets = xf.Sheets[0:1]
 			} else if dataType == 2 {
 				sh := xf.Sheets[1]
 				for i, v := range mMap {
 					row := sh.AddRow()
 					row.AddCell().SetInt(i + 1)
-					row.AddCell().SetValue(v["s_matchkey"])
+					row.AddCell().SetValue(v["matchkey"])
 					row.AddCell().SetValue(v["area"])
 					row.AddCell().SetValue(v["city"])
 					row.AddCell().SetValue(v["title"])
@@ -951,9 +950,47 @@ func GetXlsxs(mMap []map[string]interface{}, fn, email, id string) {
 					row.AddCell().SetValue(v["company_phone"])
 					row.AddCell().SetValue(v["company_email"])
 				}
-				xf.Sheets = xf.Sheets[1:]
+				xf.Sheets = xf.Sheets[1:2]
 			} else {
-
+				sh := xf.Sheets[2]
+				for i, v := range mMap {
+					row := sh.AddRow()
+					row.AddCell().SetInt(i + 1)
+					row.AddCell().SetValue(v["matchkey"])
+					row.AddCell().SetValue(v["area"])
+					row.AddCell().SetValue(v["city"])
+					row.AddCell().SetValue(v["district"])
+					row.AddCell().SetValue(v["title"])
+					row.AddCell().SetValue(v["detail"])
+					if v["publishtime"] != nil {
+						row.AddCell().SetValue(time.Unix(qu.Int64All(v["publishtime"]), 0).Format("2006-01-02"))
+					} else {
+						row.AddCell()
+					}
+					row.AddCell().SetValue(v["href"])
+					if v["bidamount"] != nil {
+						row.AddCell().SetFloat(qu.Float64All(v["bidamount"]) / 10000)
+					} else {
+						row.AddCell()
+					}
+					row.AddCell().SetValue(v["buyer"])
+					row.AddCell().SetValue(v["buyerperson"])
+					row.AddCell().SetValue(v["buyertel"])
+					row.AddCell().SetValue(v["s_winner"])
+					row.AddCell().SetValue(v["legal_person"])
+					row.AddCell().SetValue(v["company_phone"])
+					row.AddCell().SetValue(v["company_address"])
+					row.AddCell().SetValue(v["rank"])
+					row.AddCell().SetValue(v["purchasing"])
+					row.AddCell().SetValue(v["capital"])
+					row.AddCell().SetValue(v["establish_date"])
+					row.AddCell().SetValue(v["business_scope"])
+					row.AddCell().SetValue(v["stock_name"])
+					row.AddCell().SetValue(v["buyer_credit_no"])
+					row.AddCell().SetValue(v["winner_credit_no"])
+					row.AddCell().SetValue(v["id"])
+				}
+				xf.Sheets = xf.Sheets[2:3]
 			}
 			//生文件
 			t := strconv.FormatInt(time.Now().Unix(), 10)

BIN
src/web/res/fields.xlsx