浏览代码

xlsx格式

xuzhiheng 5 年之前
父节点
当前提交
edb13101b2

+ 3 - 4
src/history/historytask.go

@@ -77,9 +77,10 @@ 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))
-		GetXlsx(xlsxArr, customer_name, email)
+		GetXlsxs(xlsxArr, customer_name, email, history_id)
 		xlsxArr = []map[string]interface{}{}
 		go UpdateHistoryState(2, history_id, resultcount)
 	} else {
@@ -90,7 +91,7 @@ func (this *HistoryData) HistoryTask(history_id string) {
 func (this *HistoryData) HistoryList() {
 	id := this.GetString("id")
 	if this.Method() == "POST" {
-		data, _ := Mgo.Find("historylog", `{"user_id":"`+id+`"}`, `{updatetime: desc}`, nil, false, -1, -1)
+		data, _ := Mgo.Find("historylog", map[string]interface{}{"user_id": id}, `{"updatetime":-1}`, nil, false, -1, -1)
 		this.ServeJson(map[string]interface{}{
 			"data": data,
 		})
@@ -102,7 +103,6 @@ func (this *HistoryData) HistoryList() {
 
 func UpdateHistoryState(state int, history_id string, count int) {
 	if state == 2 {
-
 		Mgo.Update("historylog", map[string]interface{}{"_id": mongoutil.StringTOBsonId(history_id)}, map[string]interface{}{
 			"$set": map[string]interface{}{
 				"state":        state,
@@ -113,7 +113,6 @@ func UpdateHistoryState(state int, history_id string, count int) {
 	}
 
 	Mgo.Update("historylog", map[string]interface{}{"_id": mongoutil.StringTOBsonId(history_id)}, map[string]interface{}{
-
 		"$set": map[string]interface{}{
 			"state": state,
 		},

+ 181 - 64
src/history/util_history.go

@@ -484,6 +484,7 @@ func AssembelSave(tmp map[string]interface{}, IsSearchHosp, IsSearchEnps bool, h
 			}
 		}
 	}
+	xlsxArr = append(xlsxArr, tmp)
 	MgoSaveCache <- tmp
 	return true
 }
@@ -586,7 +587,6 @@ func SaveMgo() {
 		select {
 		case v := <-MgoSaveCache:
 			arru[indexu] = v
-			xlsxArr = append(xlsxArr, v)
 			indexu++
 			if indexu == 500 {
 				SP <- true
@@ -793,73 +793,190 @@ func SkipData(tmp map[string]interface{}) bool {
 }
 
 //生成xlsx
-func GetXlsx(mMap []map[string]interface{}, fn, email string) {
-	//信息
-	var err error
-	//样式
-	fx := xlsx.NewFile()
-	style := xlsx.NewStyle()
-	border := *xlsx.NewBorder("thin", "thin", "thin", "thin")
-	style.Border = border
-	style.Font.Size = 14
-	style.Alignment.Vertical = "center"
-	style.ApplyBorder = true
-	//
-	styleHead := xlsx.NewStyle()
-	styleHead.Font.Bold = true
-	styleHead.Font.Size = 18
-	styleHead.Border = border
-	styleHead.ApplyBorder = true
-
-	sheet1, err := fx.AddSheet("Sheet")
-	if err != nil {
-		log.Println("Err", err.Error())
-	}
-	head := sheet1.AddRow()
-	fields := []string{}
-	for r, _ := range FielsArr {
-		fields = append(fields, r)
-	}
+// func GetXlsxs(mMap []map[string]interface{}, fn, email string) {
+// 	//信息
+// 	var err error
+// 	//样式
+// 	fx := xlsx.NewFile()
+// 	style := xlsx.NewStyle()
+// 	border := *xlsx.NewBorder("thin", "thin", "thin", "thin")
+// 	style.Border = border
+// 	style.Font.Size = 14
+// 	style.Alignment.Vertical = "center"
+// 	style.ApplyBorder = true
+// 	//
+// 	styleHead := xlsx.NewStyle()
+// 	styleHead.Font.Bold = true
+// 	styleHead.Font.Size = 18
+// 	styleHead.Border = border
+// 	styleHead.ApplyBorder = true
 
-	for _, t := range fields {
-		if FielsArr[t] != nil {
-			cell := head.AddCell()
-			cell.SetValue(FielsArr[t])
-			cell.SetStyle(styleHead)
-		}
-	}
+// 	sheet1, err := fx.AddSheet("Sheet")
+// 	if err != nil {
+// 		log.Println("Err", err.Error())
+// 	}
+// 	head := sheet1.AddRow()
+// 	fields := []string{"title", "href", "detail", "publishtime", "matchkey", "area", "city", "district", "buyer", "buyerperson", "buyertel", "s_winner", "legal_person", "company_phone", "bidamount", "rank", "purchasing", "company_address", "capital", "establish_date", "business_scope", "stock_name", "buyer_credit_no", "winner_credit_no", "id"}
+// 	// for r, _ := range FielsArr {
+// 	// 	fields = append(fields, r)
+// 	// }
 
-	for _, v := range mMap {
-		row := sheet1.AddRow()
-		for _, t := range fields {
-			cell := row.AddCell()
-			cell.SetStyle(style)
-			if v[t] != nil {
-				cell.SetValue(v[t])
-			}
-		}
-	}
+// 	for _, t := range fields {
+// 		if FielsArr[t] != nil {
+// 			cell := head.AddCell()
+// 			cell.SetValue(FielsArr[t])
+// 			cell.SetStyle(styleHead)
+// 		}
+// 	}
+
+// 	for _, v := range mMap {
+// 		row := sheet1.AddRow()
+// 		for _, t := range fields {
+// 			cell := row.AddCell()
+// 			cell.SetStyle(style)
+// 			if v[t] != nil {
+// 				cell.SetValue(v[t])
+// 			}
+// 		}
+// 	}
 
-	//生文件
-	t := strconv.FormatInt(time.Now().Unix(), 10)
-	dir := "./web/res/xlsx/" + t + "/"
-	if b, _ := PathExists(dir); !b {
-		err1 := os.MkdirAll(dir, os.ModePerm)
-		if err1 != nil {
-			log.Println("mkdir err", dir)
+// 	//生文件
+// 	t := strconv.FormatInt(time.Now().Unix(), 10)
+// 	dir := "./web/res/xlsx/" + t + "/"
+// 	if b, _ := PathExists(dir); !b {
+// 		err1 := os.MkdirAll(dir, os.ModePerm)
+// 		if err1 != nil {
+// 			log.Println("mkdir err", dir)
+// 		}
+// 	}
+// 	fname := t + ".xlsx"
+// 	err = fx.Save(dir + fname)
+// 	if err != nil {
+// 		log.Println("xls error", fname)
+// 	} else {
+// 		for i := 0; i < len(Gmails); i++ {
+// 			gmail := Gmails[i]
+// 			status := mail.GSendMail_q("剑鱼标讯", email, "", "", fn, "", dir+fname, fname, gmail)
+// 			if status {
+// 				log.Println("send mail success", fname, email)
+// 				break
+// 			}
+// 		}
+// 	}
+// }
+
+func GetXlsxs(mMap []map[string]interface{}, fn, email, id string) {
+	if id != "" {
+		query := bson.M{
+			"_id": bson.ObjectIdHex(id),
 		}
-	}
-	fname := t + ".xlsx"
-	err = fx.Save(dir + fname)
-	if err != nil {
-		log.Println("xls error", fname)
-	} else {
-		for i := 0; i < len(Gmails); i++ {
-			gmail := Gmails[i]
-			status := mail.GSendMail_q("剑鱼标讯", email, "", "", fn, "", dir+fname, fname, gmail)
-			if status {
-				log.Println("send mail success", fname, email)
-				break
+		data, ok := Mgo.FindOne("historylog", query)
+		if ok && (*data) != nil && len(*data) > 0 {
+			dataType := qu.IntAll((*data)["i_extfieldstype"])
+			xf, err := xlsx.OpenFile("web/res/fields.xlsx")
+			if err != nil {
+				log.Println("fields file not foud", err.Error())
+			}
+			if dataType == 1 {
+				sh := xf.Sheets[0]
+				for i, v := range mMap {
+					row := sh.AddRow()
+					row.AddCell().SetInt(i + 1)
+					row.AddCell().SetValue(v["s_matchkey"])
+					row.AddCell().SetValue(v["area"])
+					row.AddCell().SetValue(v["city"])
+					row.AddCell().SetValue(v["title"])
+					row.AddCell().SetValue(v["subtype"])
+					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["buyer"])
+					row.AddCell().SetValue(v["winner"])
+					if v["bidamount"] != nil {
+						row.AddCell().SetFloat(qu.Float64All(v["bidamount"]) / 10000)
+					} else {
+						row.AddCell()
+					}
+					row.AddCell().SetValue(v["projectname"])
+					row.AddCell().SetValue(v["detail"])
+					row.AddCell().SetValue(v["s_jyhref"])
+				}
+				xf.Sheets = xf.Sheets[: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["area"])
+					row.AddCell().SetValue(v["city"])
+					row.AddCell().SetValue(v["title"])
+					row.AddCell().SetValue(v["subtype"])
+					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"])
+					row.AddCell().SetValue(v["s_jyhref"])
+					row.AddCell().SetValue(v["projectcode"])
+					row.AddCell().SetValue(v["projectname"])
+					row.AddCell().SetValue(v["projectscope"])
+					if v["budget"] != nil {
+						row.AddCell().SetFloat(qu.Float64All(v["budget"]) / 10000)
+					} else {
+						row.AddCell()
+					}
+					if v["bidamount"] != nil {
+						row.AddCell().SetFloat(qu.Float64All(v["bidamount"]) / 10000)
+					} else {
+						row.AddCell()
+					}
+					if v["bidopentime"] != nil {
+						row.AddCell().SetValue(time.Unix(qu.Int64All(v["bidopentime"]), 0).Format("2006-01-02"))
+					} else {
+						row.AddCell()
+					}
+					row.AddCell().SetValue(v["buyer"])
+					row.AddCell().SetValue(v["buyerperson"])
+					row.AddCell().SetValue(v["buyertel"])
+					row.AddCell().SetValue(v["agency"])
+					row.AddCell().SetValue(v["winner"])
+					row.AddCell().SetValue(v["winnerperson"])
+					row.AddCell().SetValue(v["winnertel"])
+					row.AddCell().SetValue(v["legal_person"])
+					row.AddCell().SetValue(v["company_phone"])
+					row.AddCell().SetValue(v["company_email"])
+				}
+				xf.Sheets = xf.Sheets[1:]
+			} else {
+
+			}
+			//生文件
+			t := strconv.FormatInt(time.Now().Unix(), 10)
+			dir := "./web/res/xlsx/" + t + "/"
+			if b, _ := PathExists(dir); !b {
+				err1 := os.MkdirAll(dir, os.ModePerm)
+				if err1 != nil {
+					log.Println("mkdir err", dir)
+				}
+			}
+			fname := t + ".xlsx"
+			err = xf.Save(dir + fname)
+			if err != nil {
+				log.Println("xls error", fname)
+			} else {
+				for i := 0; i < len(Gmails); i++ {
+					gmail := Gmails[i]
+					status := mail.GSendMail_q("剑鱼标讯", email, "", "", fn, "", dir+fname, fname, gmail)
+					if status {
+						log.Println("send mail success", fname, email)
+						break
+					}
+				}
 			}
 		}
 	}

+ 11 - 9
src/service/customer_service.go

@@ -1382,17 +1382,19 @@ func (c *Customer) Addhistoryrule() {
 			push_type, _ := strconv.Atoi(c.GetString("push_type"))
 			isDup, _ := strconv.Atoi(c.GetString("isDup"))
 			i_updatetime, _ := strconv.ParseInt(c.GetString("i_updatetime"), 10, 64)
+			i_extfieldstype, _ := strconv.Atoi(c.GetString("i_extfieldstype"))
 			set := bson.M{
 				"$set": bson.M{
-					"i_pushmodel":    push_model,
-					"s_customername": c.GetString("s_customername"),
-					"s_salesperson":  c.GetString("salename"),
-					"s_name":         c.GetString("s_name"),
-					"i_pushtype":     push_type,
-					"s_extends":      c.GetString("s_extends"),
-					"i_updatetime":   i_updatetime,
-					"sendMail":       c.GetString("sendMail"),
-					"isDup":          isDup,
+					"i_pushmodel":     push_model,
+					"s_customername":  c.GetString("s_customername"),
+					"s_salesperson":   c.GetString("salename"),
+					"s_name":          c.GetString("s_name"),
+					"i_pushtype":      push_type,
+					"s_extends":       c.GetString("s_extends"),
+					"i_updatetime":    i_updatetime,
+					"sendMail":        c.GetString("sendMail"),
+					"isDup":           isDup,
+					"i_extfieldstype": i_extfieldstype,
 				},
 			}
 			isupdata := Mgo.UpdateById("historylog", mongoutil.StringTOBsonId(his_id), set)

二进制
src/web/res/fields.xlsx


+ 3 - 3
src/web/templates/private/cuser_rule_history_edit.html

@@ -37,7 +37,7 @@
                 <ul class="nav nav-tabs edit-step">
                     <li class="active" data-mode="guide"><a href="#tab_1" data-toggle="tab" aria-expanded="true">通用规则</a></li>
                     <li data-mode="guide" class=""><a href="#tab_2" data-toggle="tab" aria-expanded="false">关键词规则</a></li>
-                    <button class="btn btn-primary btn-sm" style="float: right;margin-top: 7px;margin-right: 10px" onclick="saveTag()"><i class="fa fa-fw fa-file-text fa-lg"></i>保存标签</button>
+                    <button class="btn btn-primary btn-sm" style="float: right;margin-top: 7px;margin-right: 10px" onclick="saveTag()"><i class="fa fa-fw fa-file-text fa-lg"></i>保存规则</button>
                 </ul>
                 <div class="tab-content">
                     <div class="tab-pane active" id="tab_1">
@@ -49,9 +49,9 @@
                                 </div>
                                 <div class="box-body">
                                     <div class="form-group">
-                                        <label class="col-sm-2 control-label"><span style="color:red;">* </span>标签名称</label>
+                                        <label class="col-sm-2 control-label"><span style="color:red;">* </span>规则名称</label>
                                         <div class="col-sm-3">
-                                            <input type="text" class="form-control" id="tagname" placeholder="标签名称"
+                                            <input type="text" class="form-control" id="tagname" placeholder="规则名称"
                                                    value="" required>
                                         </div>
                                         <label class="col-sm-2 control-label"><span style="color:red;">* </span>部门名称</label>

+ 12 - 0
src/web/templates/private/customer_history.html

@@ -109,6 +109,18 @@
                                                         <option value=0>否</option>
                                                         <option value=1>是</option>
                                                     </select>
+                                                </div><label class="col-sm-2 control-label ">字段包</label>
+                                                <div class="col-sm-2">
+                                                    <select class="form-control selectpicker" id="extfiledselect">
+                                                        <option value="2">高级字段包</option>
+                                                        <option value="1">初级字段包</option>
+                                                        <option value="3">特殊字段包</option>
+                                                    </select>
+                                                    <script>
+                                                        $('#extfiledselect').on("change", function () {
+                                                            dataMap["i_extfieldstype"] = $('#extfiledselect option:selected').val();
+                                                        })
+                                                    </script>
                                                 </div>
                                             </div>
                                         </div>

+ 6 - 0
src/web/templates/private/historylog_list.html

@@ -144,6 +144,12 @@
                               '<a style="margin-left:10px" class="btn btn-sm btn-success" disabled>完成</a>' +
                               '<a style="margin-left:10px" class="btn btn-sm btn-info" eid="'+val+'" onclick="cloneWork(this)">克隆</a>' +
                               '</div>';
+                        }else if(row.state === 1){
+                            tmp = '<div>' +
+                              '<a class="btn btn-sm btn-primary" href="/service/customer/history?id='+ row.user_id +'&hid='+ val +'">编辑</a>' +
+                              '<a style="margin-left:10px" class="btn btn-sm btn-info">进行</a>' +
+                              '<a style="margin-left:10px" class="btn btn-sm btn-info" eid="'+val+'" onclick="cloneWork(this)">克隆</a>' +
+                              '</div>';
                         }else{
                             tmp = '<div>' +
                               '<a class="btn btn-sm btn-primary" href="/service/customer/history?id='+ row.user_id +'&hid='+ val +'">编辑</a>' +