Selaa lähdekoodia

feat:自助导出优化

xuzhiheng 3 vuotta sitten
vanhempi
commit
83c63bccd9

+ 97 - 40
src/client/customerRule.go

@@ -140,7 +140,7 @@ func (c *CustomerRule) ProductData() {
 	defer qu.Catch()
 	if c.Method() == "POST" {
 		log.Println("正在生成预览数据。。。")
-		rep := false
+		// rep := false
 		id := c.GetString("id")
 		tag, ok := Mgo.FindById("entniche_rule", id, `{}`)
 		if !ok {
@@ -157,13 +157,13 @@ func (c *CustomerRule) ProductData() {
 		if escount > 5000 {
 			c.ServeJson(map[string]interface{}{
 				"rep": false,
-				"msg": "本次匹配数据量:" + fmt.Sprint(escount) + "条,数据量大于5000,无法预览自助导出,请调整查询时间后重新点击生成数据",
+				"msg": "本次匹配数据量:" + fmt.Sprint(escount) + "条,数据量大于5000,无法预览自助导出,请调整规则条件后重新预览",
 			})
 			return
 		}
 		//
-		s_startTime := qu.IntAll((*tag)["i_starttime"])
-		s_endTime := qu.IntAll((*tag)["i_endtime"])
+		// s_startTime := qu.IntAll((*tag)["i_starttime"])
+		// s_endTime := qu.IntAll((*tag)["i_endtime"])
 		totalCount := 0
 		//
 		multiMatchcount := strings.Count(s_esquery, "multi_match")
@@ -186,13 +186,13 @@ func (c *CustomerRule) ProductData() {
 		if rangeCount != -1 {
 			totalCount += rangeCount
 		}
-		if totalCount > 1000 && (s_startTime == 0 || s_endTime == 0) {
-			c.ServeJson(map[string]interface{}{
-				"rep": false,
-				"msg": "查询过多,请限制开始时间及结束时间",
-			})
-			return
-		}
+		// if totalCount > 1000 && (s_startTime == 0 || s_endTime == 0) {
+		// 	c.ServeJson(map[string]interface{}{
+		// 		"rep": false,
+		// 		"msg": "查询过多,请限制开始时间及结束时间",
+		// 	})
+		// 	return
+		// }
 		if totalCount > 8000 {
 			c.ServeJson(map[string]interface{}{
 				"rep": false,
@@ -204,12 +204,13 @@ func (c *CustomerRule) ProductData() {
 		// 其他的分隔
 		// 1000<=总个数<4000,将时间(publishtime)按照每3个月进行分割,然后查询到的数据量进行求和。
 		// 4000<=总个数<8000,将时间(publishtime)按照每1个月进行分割,然后查询到的数据量进行求和
-		var err error
-		var count int64
+		// var err error
+		// var count int64
 		// var n int
 		// 小于1000的直接查
 		// if totalCount < 1000 {
-		err, count = UtilEsFind1(*tag)
+		// err, count = UtilEsFind1(*tag)
+		go UtilEsFind1(*tag)
 		// } else {
 		// 	if totalCount >= 1000 && totalCount < 4000 {
 		// 		n = 3
@@ -219,44 +220,100 @@ func (c *CustomerRule) ProductData() {
 		// 	}
 		// 	err, count = UtilEsFind2(*tag, n)
 		// }
-		var msg string
-		if err == nil {
-			rep = true
-			msg = "数据生成成功"
-		} else {
-			rep = false
-			msg = "数据生成失败"
-		}
-		c.ServeJson(map[string]interface{}{
-			"rep":   rep,
-			"count": count,
-			"msg":   msg,
-		})
+		// var msg string
+		// if err == nil {
+		// 	rep = true
+		// 	msg = "数据生成成功"
+		// } else {
+		// 	rep = false
+		// 	msg = "数据生成失败"
+		// }
+		// c.ServeJson(map[string]interface{}{
+		// "rep": rep,
+		// "count": count,
+		// "msg":   msg,
+		// })
 	}
 }
 
 func (r *CustomerRule) DemoData() {
 	defer qu.Catch()
 	if r.Method() == "POST" {
-		sDataid := r.GetString("s_dataid")
-		start, _ := r.GetInteger("start")
-		limit, _ := r.GetInteger("length")
+		esquery := r.GetString("esquery")
+		id := r.GetString("id")
 		draw, _ := r.GetInteger("draw")
-		query := bson.M{
-			"s_dataid": sDataid,
-		}
-		data, _ := Mgo.Find("tagsdata", query, `{"publishtime":-1}`, nil, false, start, limit)
-		count := Mgo.Count("tagsdata", query)
-		for _, v := range *data {
-			if v["budget"] != nil {
-				v["budget"] = qu.Float64All(fmt.Sprintf("%f", qu.Float64All(v["budget"])/10000))
+		tag, _ := Mgo.FindById("entniche_rule", id, `{}`)
+		tags := *tag
+		maths := make([]map[string]string, 0)
+		if orules, ok := tags["o_rules"].([]interface{}); ok {
+			for _, v := range orules {
+				orule, _ := v.(map[string]interface{})
+				maths = append(maths, map[string]string{
+					"s_matchkey": qu.ObjToString(orule["s_matchkey"]),
+					"s_keymatch": qu.ObjToString(orule["s_keymatch"]),
+				})
 			}
-			if v["bidamount"] != nil {
-				v["bidamount"] = qu.Float64All(fmt.Sprintf("%f", qu.Float64All(v["bidamount"])/10000))
+		} else if orules, ok := tags["o_rules"].([]map[string]interface{}); ok {
+			for _, v := range orules {
+				maths = append(maths, map[string]string{
+					"s_matchkey": qu.ObjToString(v["s_matchkey"]),
+					"s_keymatch": qu.ObjToString(v["s_keymatch"]),
+				})
+			}
+		}
+		esquery = esquery[:len(esquery)-1] + `,"size":` + fmt.Sprintf("%d", 100) + `}`
+		data := Es.Get(InterimIndex, Itype, esquery)
+		count := 0
+		if data != nil && len(*data) > 0 {
+			count = len(*data)
+			for _, item := range *data {
+				if item["budget"] != nil {
+					item["budget"] = qu.Float64All(fmt.Sprintf("%f", qu.Float64All(item["budget"])/10000))
+				}
+				if item["bidamount"] != nil {
+					item["bidamount"] = qu.Float64All(fmt.Sprintf("%f", qu.Float64All(item["bidamount"])/10000))
+				}
+				info_id := qu.ObjToString(item["_id"])
+				item["info_id"] = info_id
+				//
+				subType := qu.ObjToString(item["subtype"])
+				subTypeStr := "拟建,采购意向,预告,预审,预审结果,论证意见,需求公示"
+				if strings.Contains(subTypeStr, subType) {
+					item["s_jyhref"] = `https://www.jianyu360.cn/article/bdprivate/` + qu.CommonEncodeArticle("bdprivate", info_id) + `.html`
+				} else {
+					item["s_jyhref"] = `https://www.jianyu360.cn/article/content/` + qu.CommonEncodeArticle("content", info_id) + `.html`
+				}
+				//
+				item["i_createtime"] = time.Now().Unix()
+				delete(item, "_id")
+				//二次匹配关键词
+				matchKeys := GetMactchKey(maths, item)
+				if len(maths) > 0 {
+					if matchKeys != "" {
+						item["s_matchkey"] = matchKeys
+					}
+				}
+				findwinner := strings.TrimSpace(qu.ObjToString(item["winner"]))
+				if findwinner != "" {
+					finddata := MgoEnps.FindOne(EnpsColl, bson.M{"company_name": findwinner})
+					if finddata != nil {
+						if legal_person := qu.ObjToString(finddata["legal_person"]); legal_person != "" {
+							item["legal_person"] = legal_person
+						}
+						if email := qu.ObjToString(finddata["company_email"]); email != "" {
+							item["company_email"] = email
+						}
+						if phone := qu.ObjToString(finddata["company_phone"]); phone != "" {
+							item["company_phone"] = phone
+						}
+						item["qyk"] = finddata
+					}
+				}
 			}
 		}
 		r.ServeJson(map[string]interface{}{
 			"data":            data,
+			"count":           count,
 			"draw":            draw,
 			"recordsFiltered": count,
 			"recordsTotal":    count,

+ 4 - 4
src/config.json

@@ -18,6 +18,8 @@
   "elasticsearch": "http://192.168.3.206:9800",
   "elasticsearch_index": "bidding",
   "elasticsearch_type": "bidding",
+  "elasticsearch_interim_index": "bidding",
+  "elasticsearch_total_index": "bidding",
   "elasticPoolSize": 10,
   "jkmail": {
     "to": "wangjianghan@topnet.net.cn",
@@ -36,8 +38,7 @@
     "hospcoll": "buyer_rank",
     "buyerentcoll": "buyer_ent",
     "username": "jyDevGroup",
-    "password": "jy@DevGroup",
-    "replSet": "mixdata"
+    "password": "jy@DevGroup"
   },
   "enterprise": {
     "addr": "192.168.3.207:27001,192.168.3.206:27002",
@@ -45,8 +46,7 @@
     "db": "mixdata",
     "coll": "qyxy_std",
     "username": "jyDevGroup",
-    "password": "jy@DevGroup",
-    "replSet": "mixdata"
+    "password": "jy@DevGroup"
   },
   "save": {
     "addr": "192.168.3.207:27092",

+ 19 - 6
src/util/config.go

@@ -22,6 +22,8 @@ var (
 	MgoCus          *mongodb.MongodbSim //企业服务库
 	MgoEn           *mongodb.MongodbSim
 	EsIndex, EsType string
+	InterimIndex    string
+	TotalIndex      string
 	MgoEnC          string
 	Subday          float64
 	PreviewHref     string //数据预览地址
@@ -126,7 +128,10 @@ func initCitys() {
 	if CityDistricts == nil {
 		CityDistricts = make(map[string][]string)
 	}
-	datas, _ := Mgo.Find("code_city", `{}`, `{"_id":1}`, `{}`, false, -1, -1)
+	datas, ok := Mgo.Find("code_city", `{}`, `{"_id":1}`, `{}`, false, -1, -1)
+	if !ok || datas == nil || len(*datas) == 0 {
+		return
+	}
 	for k, data := range *datas {
 		brief := data["brief"].(string)
 		if k != 0 {
@@ -151,7 +156,10 @@ func initCitys() {
 }
 
 func initInfoType() {
-	datas, _ := Mgo.Find("code_infotype", `{}`, `{"_id":1}`, `{}`, false, -1, -1)
+	datas, ok := Mgo.Find("code_infotype", `{}`, `{"_id":1}`, `{}`, false, -1, -1)
+	if !ok || datas == nil || len(*datas) == 0 {
+		return
+	}
 	for _, data := range *datas {
 		name := data["name"].(string)
 		TopTypeArr = append(TopTypeArr, name)
@@ -165,7 +173,10 @@ func initBuyerClass() {
 	if BuyerClassMap == nil {
 		BuyerClassMap = make(map[string][]string)
 	}
-	datas, _ := Mgo.Find("code_buyerclass", `{}`, `{"name":1}`, `{}`, false, -1, -1)
+	datas, ok := Mgo.Find("code_buyerclass", `{}`, `{"name":1}`, `{}`, false, -1, -1)
+	if !ok || datas == nil || len(*datas) == 0 {
+		return
+	}
 	for _, data := range *datas {
 		name := data["name"].(string)
 		BuyerClass = append(BuyerClass, name)
@@ -226,6 +237,8 @@ func initTaskType() {
 
 func initEs() {
 	EsIndex, EsType = qu.ObjToString(Sysconfig["elasticsearch_index"]), qu.ObjToString(Sysconfig["elasticsearch_type"])
+	TotalIndex = qu.ObjToString(Sysconfig["elasticsearch_total_index"])
+	InterimIndex = qu.ObjToString(Sysconfig["elasticsearch_interim_index"])
 	elastic.InitElasticSize(qu.ObjToString(Sysconfig["elasticsearch"]), qu.IntAllDef(qu.Int64All(Sysconfig["elasticPoolSize"]), 30))
 }
 
@@ -284,9 +297,9 @@ func initdb() {
 		MongodbAddr: qu.ObjToString(enterprise["addr"]),
 		DbName:      qu.ObjToString(enterprise["db"]),
 		Size:        qu.IntAllDef(enterprise["size"], 15),
-		UserName:    qu.ObjToString(buyerinfo["username"]),
-		Password:    qu.ObjToString(buyerinfo["password"]),
-		ReplSet:     qu.ObjToString(buyerinfo["replSet"]),
+		UserName:    qu.ObjToString(enterprise["username"]),
+		Password:    qu.ObjToString(enterprise["password"]),
+		ReplSet:     qu.ObjToString(enterprise["replSet"]),
 	}
 	MgoEnps.InitPool()
 	//bidding库

+ 2 - 2
src/web/templates/client/cuser_rule_create.html

@@ -22,8 +22,8 @@
                 <button class="btn btn-primary btn-sm" onclick="importRule()"><i
                             class="fa fa-fw fa-cloud-upload fa-lg"></i>导入关键词
                 </button>
-                <a class="btn btn-sm btn-instagram" onclick="produceData()"><i class="fa fa-fw fa-database fa-lg"></i>生成数据</a>
-                <button id="previewDatas" class="btn btn-warning btn-sm" onclick="previewData()"><i class="fa fa-fw fa-eye fa-lg"></i>数据预览</button>
+                <!-- <a class="btn btn-sm btn-instagram" onclick="produceData()"><i class="fa fa-fw fa-database fa-lg"></i>快速预览</a> -->
+                <!-- <button id="previewDatas" class="btn btn-warning btn-sm" onclick="previewData()"><i class="fa fa-fw fa-eye fa-lg"></i>数据导出</button> -->
                 <form style="display:none" id='uploadform' method='post'>
                     <input type='file' name='xlsx' id='file'/>
                 </form>

+ 314 - 15
src/web/templates/client/cuser_rule_edit.html

@@ -48,8 +48,8 @@
                 <form style="display:none" id='uploadform' method='post'>
                     <input type='file' name='xlsx' id='file'/>
                 </form>
-                <a class="btn btn-sm btn-instagram" onclick="produceData()"><i class="fa fa-fw fa-database fa-lg"></i>生成数据</a>
-                <button id="previewData" class="btn btn-warning btn-sm" onclick="previewData()"><i class="fa fa-fw fa-eye fa-lg"></i>数据预览</button>
+                <a class="btn btn-sm btn-instagram" onclick="previewData1()"><i class="fa fa-fw fa-database fa-lg"></i>快速预览</a>
+                <button id="previewData" class="btn btn-warning btn-sm" onclick="previewData()"><i class="fa fa-fw fa-eye fa-lg"></i>数据导出</button>
             </small>
             <a class="btn btn-primary btn-sm" id="back" style="float: right"> 返回</a>
 
@@ -1698,27 +1698,321 @@
     //生成数据
     function produceData() {
         com.maskShow("正在生成数据...");
+        var isOk = true
+        
         $.ajax({
             url: "/customerRule/cuser/produce",
             type: "post",
             data: {"id": dataMap.id},
             success: function (r) {
-                com.maskHide();
-                if (r.rep===true) {
-                    dataMap.i_estotal = r.count;
-                    showTip("数据生成成功", 1000);
-                } else if (r.rep===false){
+                if (r.rep===false){
+                    com.maskHide();
+                    isOk = false
                     showTip(r.msg, 30000);
-                }else {
-                    showTip("数据生成失败", 12000);
                 }
-
             },
-            error: function (r) {
-                com.maskHide();
-            }
+            // error: function (r) {
+            //     com.maskHide();
+            // }
         })
+        setTimeout(function(){
+            if (isOk) {
+                com.maskShow("倒计时3s");
+                setTimeout(function(){
+                    com.maskShow("倒计时2s");
+                    setTimeout(function(){
+                        com.maskShow("倒计时1s");
+                        setTimeout(function(){
+                            com.maskShow("倒计时0s");
+                            var href = previewHref+"?type=private" + "&key=" + dataMap.s_dataid;
+                            window.open(href);
+                            com.maskHide();
+                        },1000)
+                    },1000)
+                },1000)
+            }
+        },3000)
     }
+    
+    //预览数据
+        function previewData1() {
+            com.maskShow("正在生成数据...");
+            $.ajax({
+                url: "/customerRule/rule/preview",
+                type: "post",
+                data: {"id": dataMap.id,"esquery": dataMap.s_esquery},
+                async: false,
+                success: function (r) {
+                    dataMap.i_estotal = r.count;
+                    dataMap.datas = r.data;
+                },
+            })
+            myDataTable = $('#previewData').DataTable({
+                "destroy": false,
+                "paging": true,
+                "lengthChange": false,
+                "searching": false,
+                "ordering": false,
+                "info": true,
+                "autoWidth": true,
+                "serverSide": false,
+                "data": dataMap.datas,
+                "language": {
+                    "url": "/dist/js/dataTables.chinese.lang"
+                },
+                "fnDrawCallback": function () {
+                    $("ul.pagination").prepend("&nbsp;&nbsp;&nbsp;转到第 <input type='text' id='changePage'   style='width:20px;'> 页    <a type='text' href='javascript:void(0);' id='dataTable-btn' style='text-align:center'>GO</a>");
+                    $('#dataTable-btn').click(function (e) {
+                        var redirectpage = 0
+                        if ($("#changePage").val() && $("#changePage").val() > 0) {
+                            var redirectpage = $("#changePage").val() - 1;
+                        }
+                        myDataTable.page(redirectpage).draw(false);
+                    });
+                    this.api().column(0).nodes().each(function (cell, i) {
+                        cell.innerHTML = i + 1;
+                    });
+                },
+                "columns": [
+                    {"data": null, width: "2%"},
+                    {
+                        "data": function (row) {
+                            if (row.s_matchkey) {
+                                return row.s_matchkey
+                            } else {
+                                return ""
+                            }
+                        }, width: "8%"
+                    },
+                    {
+                        "data": function (row) {
+                            if (row.area) {
+                                return row.area
+                            } else {
+                                return ""
+                            }
+                        }, width: "4%"
+                    },
+                    {
+                        "data": function (row) {
+                            if (row.city) {
+                                return row.city
+                            } else {
+                                return ""
+                            }
+                        }, width: "4%"
+                    },
+                    {
+                        "data": function (row) {
+                            if (row.s_jyhref) {
+                                if (row.title.length > 36) {
+                                    var str = row.title.substring(0, 36) + "..."
+                                } else {
+                                    var str = row.title
+                                }
+                                tmp = '<a class="" target="_blank" href=' + row.s_jyhref + '>' + str + '</a>';
+                                return tmp
+                            } else {
+                                return row.title
+                            }
+                        }, width: "5%"
+                    },
+                    {
+                        "data": function (row) {
+                            if (row.subtype) {
+                                return row.subtype
+                            } else {
+                                return ""
+                            }
+                        }, width: "4%"
+                    },
+                    {
+                        "data": function (row) {
+                            if (row.detail !== "" && row.detail !== undefined) {
+                                var str = com.trimStr(row.detail);
+                                if (str.length > 14) {
+                                    return str.substring(0, 14) + "..."
+                                } else {
+                                    return str
+                                }
+                            } else {
+                                row.detail = ""
+                            }
+                        }, width: "5%"
+                    },
+                    {
+                        "data": function (row) {
+                            var dt = new Date();
+                            dt.setTime(parseInt(row.publishtime) * 1000);
+                            return dt.format("yyyy-MM-dd")
+                        }, width: "4%"
+                    },
+                    {
+                        "data": function (row) {
+                            if (row.href) {
+                                var shref = row.href;
+                                tmp = '<a class="" target="_blank" href=' + shref + '>公告地址</a>';
+                                return tmp
+                            } else {
+                                return ""
+                            }
+                        }, width: "5%"
+                    },
+                    {
+                        "data": function (row) {
+                            if (row.projectcode) {
+                                return row.projectcode
+                            } else {
+                                return ""
+                            }
+                        }, width: "5%"
+                    },
+                    {
+                        "data": "projectname", width: "5%", render: function (val) {
+                            if (val === undefined) {
+                                return ""
+                            } else {
+                                return val
+                            }
+                        }
+                    },
+                    {
+                        "data": function (row) {
+                            if (row.projectscope) {
+                                if (row.projectscope.length > 14) {
+                                    return row.projectscope.substring(0, 14) + "..."
+                                } else {
+                                    return row.projectscope
+                                }
+                            }
+                            return ""
+                        }, width: "3%"
+                    },
+                    {
+                        "data": function (row) {
+                            if (row.budget == undefined) {
+                                return ""
+                            } else {
+                                return row.budget
+                            }
+                        }, width: "3%"
+                    },
+                    {
+                        "data": function (row) {
+                            if (row.bidamount == undefined) {
+                                return ""
+                            } else {
+                                return row.bidamount
+                            }
+                        }, width: "3%"
+                    },
+                    {
+                        "data": "bidopentime", width: "3%", render: function (val) {
+                            if (val) {
+                                var dt = new Date();
+                                dt.setTime(parseInt(val) * 1000);
+                                return dt.format("yyyy-MM-dd")
+                            } else {
+                                return ""
+                            }
+                        }
+                    },
+                    {
+                        "data": "buyer", width: "3%", render: function (val) {
+                            if (val == undefined) {
+                                val = ""
+                            }
+                            return val
+                        }
+                    },
+                    {
+                        "data": function (row) {
+                            if (row.buyerperson) {
+                                return row.buyerperson
+                            } else {
+                                return ""
+                            }
+                        }, width: "4%"
+                    },
+                    {
+                        "data": function (row) {
+                            if (row.buyertel) {
+                                return row.buyertel
+                            } else {
+                                return ""
+                            }
+                        }, width: "4%"
+                    },
+                    {
+                        "data": "agency", width: "5%", render: function (val) {
+                            if (val == undefined) {
+                                val = ""
+                            }
+                            return val
+                        }
+                    },
+                    {
+                        "data": "s_winner", width: "3%", render: function (val) {
+                            if (val == undefined) {
+                                val = ""
+                            }
+                            return val
+                        }
+                    },
+                    {
+                        "data": function (row) {
+                            if (row.winnerperson) {
+                                return row.winnerperson
+                            } else {
+                                return ""
+                            }
+                        }, width: "4%"
+                    },
+                    {
+                        "data": function (row) {
+                            if (row.winnertel) {
+                                return row.winnertel
+                            } else {
+                                return ""
+                            }
+                        }, width: "4%"
+                    },
+                    {
+                        "data": function (row) {
+                            if (row.legal_person) {
+                                return row.legal_person
+                            } else {
+                                return ""
+                            }
+                        }, width: "4%"
+                    },
+                    {
+                        "data": function (row) {
+                            if (row.company_phone) {
+                                return row.company_phone
+                            } else {
+                                return ""
+                            }
+                        }, width: "4%"
+                    },
+                    {
+                        "data": function (row) {
+                            if (row.company_email) {
+                                return row.company_email
+                            } else {
+                                return ""
+                            }
+                        }, width: "4%"
+                    },
+                ]
+            });
+            setTimeout(function(){
+                com.maskHide();
+                var str = "预览时间范围:近两个月,数据量:" + dataMap.i_estotal;
+                $('#dataCount').html(str);
+                $('#modal-preview').modal("show");
+            },3000)
+        }
 
     //导入标签
     function importRule() {
@@ -1928,8 +2222,13 @@
     }
     
     function previewData(){
-        var href = previewHref+"?type=private" + "&key=" + dataMap.s_dataid;
-        window.open(href);
+        showConfirm("建议您在数据导出前先使用快速预览功能完成规则优化,数据导出需要提交预生成数据请求。", function () {
+            showConfirm("预生成数据后方可导出,确认加入生成数据队列?", function () {
+                produceData();
+            });
+        });
+        // var href = previewHref+"?type=private" + "&key=" + dataMap.s_dataid;
+        // window.open(href);
     }
 
 </script>