Jelajahi Sumber

fix:数据导出限制关键词&采购单位&中标单位数

duxin 1 tahun lalu
induk
melakukan
a9142c41df

+ 2 - 0
src/jfw/config/config.go

@@ -21,6 +21,7 @@ var (
 	//seo.josn 配置文件中的版本号,可以动态更新
 	Seoconfig_Version    string
 	Sysconfig            map[string]interface{}
+	ExportConfig         map[string]interface{}
 	Seoconfig            map[string]interface{}
 	WeixinConfig         map[string]interface{}
 	PhoneFilterConfig    map[string]interface{}
@@ -49,6 +50,7 @@ type entnichePcConf struct {
 func init() {
 	g.Cfg().GetAdapter().(*gcfg.AdapterFile).SetFileName("config.yaml")
 	util.ReadConfig(&Sysconfig)
+	util.ReadConfig("./export.json", &ExportConfig)
 	IpInit()
 	//ClickhouseInit()
 	//log.Println("sysconfig:", Sysconfig)

+ 8 - 0
src/jfw/export.json

@@ -0,0 +1,8 @@
+{
+  "exportLimit": {
+    "wordsLimit": 100,
+    "countLimit": 300,
+    "buyerLimit": 100,
+    "winnerLimit": 100
+  }
+}

+ 47 - 7
src/jfw/front/dataExport.go

@@ -145,7 +145,6 @@ func (d *DataExport) SieveData() {
 		subTypeArr = strings.Split(subType, ",")
 		log.Println("subTypeArr", subTypeArr)
 	}
-	log.Println("keywordParam", keyword)
 	if keyword != "" {
 		err := json.Unmarshal([]byte(keyword), &keywordList)
 		if err != nil {
@@ -190,14 +189,52 @@ func (d *DataExport) SieveData() {
 			selectType = strings.Replace(strings.Join(detail, ","), "detail", "title,detail", -1)
 		}
 	}
-	if len(keywordList) > util.IntAllDef(config.Sysconfig["keywordRestrict"], 100) {
-		keywordList = keywordList[:util.IntAllDef(config.Sysconfig["keywordRestrict"], 100)]
+
+	exportLimit := util.StructToMapMore(config.ExportConfig["exportLimit"])
+	wordsLimit := util.IntAllDef(exportLimit["wordsLimit"], 100)
+	countLimit := util.IntAllDef(exportLimit["countLimit"], 300)
+	buyerLimit := util.IntAllDef(exportLimit["buyerLimit"], 100)
+	winnerLimit := util.IntAllDef(exportLimit["winnerLimit"], 100)
+
+	var count int
+	for k, kw := range keywordList {
+		if kw.Keyword != "" {
+			count++
+		}
+		count += len(kw.Appended)
+		count += len(kw.Exclude)
+		if len([]rune(kw.Keyword)) > wordsLimit {
+			keywordList[k].Keyword = util.SubString(kw.Keyword, 0, wordsLimit)
+		}
+
+		for k1, ad := range kw.Appended {
+			if len([]rune(ad)) > wordsLimit {
+				keywordList[k].Appended[k1] = util.SubString(ad, 0, wordsLimit)
+			}
+		}
+		for k1, el := range kw.Exclude {
+			if len([]rune(el)) > wordsLimit {
+				keywordList[k].Exclude[k1] = util.SubString(el, 0, wordsLimit)
+			}
+		}
 	}
-	if len(buyerArr) > util.IntAllDef(config.Sysconfig["buyerRestrict"], 100) {
-		buyerArr = buyerArr[:util.IntAllDef(config.Sysconfig["buyerRestrict"], 100)]
+	if count > countLimit {
+		d.ServeJson(map[string]interface{}{
+			"error_code": -1,
+			"error_msg":  fmt.Sprintf("关键词信息超过上限%d", countLimit),
+		})
 	}
-	if len(winnerArr) > util.IntAllDef(config.Sysconfig["winnerRestrict"], 100) {
-		winnerArr = winnerArr[:util.IntAllDef(config.Sysconfig["winnerRestrict"], 100)]
+	if len(buyerArr) > buyerLimit {
+		d.ServeJson(map[string]interface{}{
+			"error_code": -1,
+			"error_msg":  fmt.Sprintf("采购单位超过上限%d", buyerLimit),
+		})
+	}
+	if len(winnerArr) > winnerLimit {
+		d.ServeJson(map[string]interface{}{
+			"error_code": -1,
+			"error_msg":  fmt.Sprintf("中标单位超过上限%d", winnerLimit),
+		})
 	}
 	sieveCondition := map[string]interface{}{
 		"publishtime": publishtime,
@@ -244,12 +281,14 @@ func (d *DataExport) SieveData() {
 		var EntArr = []string{}
 		if dataType == "2" {
 			for _, v := range res_screen {
+				log.Println("res_screen====", v["buyer"], v["buyerclass"])
 				//高级字段查询且winner不为空
 				if v["s_winner"] != nil && v["s_winner"] != "" {
 					EntArr = append(EntArr, v["s_winner"].(string))
 				}
 			}
 		}
+
 		list := dataexport.FormatExportData(public.Mgo_Ent, &res_screen, config.Sysconfig["webdomain"].(string), dataType, true)
 		/*if msgCount > 20000 {
 			msgCount = 20000
@@ -626,6 +665,7 @@ func (d *DataExport) FontSet(version string) {
 
 func subUrl(list *[]map[string]interface{}, dataType string) *[]map[string]interface{} {
 	for _, v := range *list {
+		log.Println("res_screen1111111", v["title"], v["buyer"], v["buyerclass"])
 		//加密截取url
 		href := util.ObjToString(v["href"])
 		url := util.ObjToString(v["url"])

+ 45 - 7
src/jfw/front/wx_dataExport.go

@@ -3,6 +3,7 @@ package front
 import (
 	"encoding/json"
 	"errors"
+	"fmt"
 	"jy/src/jfw/config"
 	"jy/src/jfw/wx"
 	"log"
@@ -171,15 +172,45 @@ func (w *WxDataExport) SaveData() error {
 	if winner != "" {
 		winnerArr = strings.Split(winner, ",")
 	}
+	exportLimit := util.StructToMapMore(config.ExportConfig["exportLimit"])
 	if keyWord != "" {
+		countLimit := util.IntAllDef(exportLimit["countLimit"], 300)
+		var count int
+		wordsLimit := util.IntAllDef(exportLimit["wordsLimit"], 100)
 		if json.Unmarshal([]byte(keyWord), &keyWordArr) == nil {
 			for k, v := range keyWordArr {
+				if v.Keyword != "" {
+					count++
+				}
+				if len([]rune(v.Keyword)) > wordsLimit {
+					keyWordArr[k].Keyword = util.SubString(v.Keyword, 0, wordsLimit)
+				}
 				if v.Appended == nil {
 					keyWordArr[k].Appended = []string{}
+				} else {
+					for k1, ad := range v.Appended {
+						if len([]rune(ad)) > wordsLimit {
+							keyWordArr[k].Appended[k1] = util.SubString(ad, 0, wordsLimit)
+						}
+					}
 				}
 				if v.Exclude == nil {
 					keyWordArr[k].Exclude = []string{}
+				} else {
+					for k1, el := range v.Exclude {
+						if len([]rune(el)) > wordsLimit {
+							keyWordArr[k].Exclude[k1] = util.SubString(el, 0, wordsLimit)
+						}
+					}
 				}
+				count += len(v.Appended)
+				count += len(v.Exclude)
+			}
+			if count > countLimit {
+				w.ServeJson(map[string]interface{}{
+					"error_code": -1,
+					"error_msg":  fmt.Sprintf("关键词信息超过上限%d", countLimit),
+				})
 			}
 		} else {
 			log.Println("keyWord param 反序列化异常,查看前后台字段是否对应")
@@ -207,14 +238,21 @@ func (w *WxDataExport) SaveData() error {
 			selectType = strings.Replace(strings.Join(detail, ","), "detail", "title,detail", -1)
 		}
 	}
-	if len(keyWordArr) > util.IntAllDef(config.Sysconfig["keywordRestrict"], 100) {
-		keyWordArr = keyWordArr[:util.IntAllDef(config.Sysconfig["keywordRestrict"], 100)]
-	}
-	if len(buyerArr) > util.IntAllDef(config.Sysconfig["buyerRestrict"], 100) {
-		buyerArr = buyerArr[:util.IntAllDef(config.Sysconfig["buyerRestrict"], 100)]
+
+	buyerLimit := util.IntAllDef(exportLimit["buyerLimit"], 100)
+	winnerLimit := util.IntAllDef(exportLimit["winnerLimit"], 100)
+
+	if len(buyerArr) > buyerLimit {
+		w.ServeJson(map[string]interface{}{
+			"error_code": -1,
+			"error_msg":  fmt.Sprintf("采购单位超过上限%d", buyerLimit),
+		})
 	}
-	if len(winnerArr) > util.IntAllDef(config.Sysconfig["winnerRestrict"], 100) {
-		winnerArr = winnerArr[:util.IntAllDef(config.Sysconfig["winnerRestrict"], 100)]
+	if len(winnerArr) > winnerLimit {
+		w.ServeJson(map[string]interface{}{
+			"error_code": -1,
+			"error_msg":  fmt.Sprintf("中标单位超过上限%d", winnerLimit),
+		})
 	}
 	saveData := map[string]interface{}{
 		"publishtime": publishtime,

+ 45 - 7
src/jfw/modules/app/src/app/front/dataExport.go

@@ -3,6 +3,7 @@ package front
 import (
 	"encoding/json"
 	"errors"
+	"fmt"
 	"jy/src/jfw/modules/app/src/jfw/config"
 	"log"
 	"strings"
@@ -174,19 +175,49 @@ func (w *WxDataExport) SaveData() error {
 	if winner != "" {
 		winnerArr = strings.Split(winner, ",")
 	}
+	exportLimit := util.StructToMapMore(config.ExportConfig["exportLimit"])
 	if keyWord != "" {
+		countLimit := util.IntAllDef(exportLimit["countLimit"], 300)
+		var count int
+		wordsLimit := util.IntAllDef(exportLimit["wordsLimit"], 100)
 		err := json.Unmarshal([]byte(keyWord), &keyWordArr)
 		if err != nil {
 			log.Println("keyWord param 反序列化异常,查看前后台字段是否对应")
 		} else {
 			log.Println("keyWordArr", len(keyWordArr), keyWordArr)
 			for k, v := range keyWordArr {
+				if v.Keyword != "" {
+					count++
+				}
+				if len([]rune(v.Keyword)) > wordsLimit {
+					keyWordArr[k].Keyword = util.SubString(v.Keyword, 0, wordsLimit)
+				}
 				if v.Appended == nil {
 					keyWordArr[k].Appended = []string{}
+				} else {
+					for k1, ad := range v.Appended {
+						if len([]rune(ad)) > wordsLimit {
+							keyWordArr[k].Appended[k1] = util.SubString(ad, 0, wordsLimit)
+						}
+					}
 				}
 				if v.Exclude == nil {
 					keyWordArr[k].Exclude = []string{}
+				} else {
+					for k1, el := range v.Exclude {
+						if len([]rune(el)) > wordsLimit {
+							keyWordArr[k].Exclude[k1] = util.SubString(el, 0, wordsLimit)
+						}
+					}
 				}
+				count += len(v.Appended)
+				count += len(v.Exclude)
+			}
+			if count > countLimit {
+				w.ServeJson(map[string]interface{}{
+					"error_code": -1,
+					"error_msg":  fmt.Sprintf("关键词信息超过上限%d", countLimit),
+				})
 			}
 		}
 	}
@@ -212,14 +243,21 @@ func (w *WxDataExport) SaveData() error {
 			selectType = strings.Replace(strings.Join(detail, ","), "detail", "title,detail", -1)
 		}
 	}
-	if len(keyWordArr) > util.IntAllDef(config.Seoconfig["keywordRestrict"], 100) {
-		keyWordArr = keyWordArr[:util.IntAllDef(config.Sysconfig["keywordRestrict"], 100)]
-	}
-	if len(buyerArr) > util.IntAllDef(config.Sysconfig["buyerRestrict"], 100) {
-		buyerArr = buyerArr[:util.IntAllDef(config.Sysconfig["buyerRestrict"], 100)]
+
+	buyerLimit := util.IntAllDef(exportLimit["buyerLimit"], 100)
+	winnerLimit := util.IntAllDef(exportLimit["winnerLimit"], 100)
+
+	if len(buyerArr) > buyerLimit {
+		w.ServeJson(map[string]interface{}{
+			"error_code": -1,
+			"error_msg":  fmt.Sprintf("采购单位超过上限%d", buyerLimit),
+		})
 	}
-	if len(winnerArr) > util.IntAllDef(config.Sysconfig["winnerRestrict"], 100) {
-		winnerArr = winnerArr[:util.IntAllDef(config.Sysconfig["winnerRestrict"], 100)]
+	if len(winnerArr) > winnerLimit {
+		w.ServeJson(map[string]interface{}{
+			"error_code": -1,
+			"error_msg":  fmt.Sprintf("中标单位超过上限%d", winnerLimit),
+		})
 	}
 	saveData := map[string]interface{}{
 		"publishtime": publishtime,

+ 5 - 0
src/jfw/modules/app/src/app/tag/msg.go

@@ -15,6 +15,11 @@ func Msg(mtype, key string) string {
 	return readproperty(mtype, key)
 }
 
+// 从json配置文件中读取值
+func Export() map[string]interface{} {
+	return config.ExportConfig
+}
+
 func Cdns(host, mtype, key string) string {
 	if host == "" {
 		return readproperty(mtype, key)

+ 8 - 0
src/jfw/modules/app/src/export.json

@@ -0,0 +1,8 @@
+{
+  "exportLimit": {
+    "wordsLimit": 100,
+    "countLimit": 300,
+    "buyerLimit": 100,
+    "winnerLimit": 100
+  }
+}

+ 2 - 0
src/jfw/modules/app/src/jfw/config/config.go

@@ -15,6 +15,7 @@ import (
 var (
 	// Seoconfig_Version seo.josn 配置文件中的版本号,可以动态更新
 	Seoconfig_Version string
+	ExportConfig      map[string]interface{}
 	// Seoconfig_Mod_Version Seoconfig_Version 作为固定版本号 除非大版本更新需要改动,其他都更改Seoconfig_Mod_Version  王山  2020/06/11
 	Seoconfig_Mod_Version string
 	Seoconfig_Cdns        map[string]interface{}
@@ -30,6 +31,7 @@ var (
 func init() {
 	g.Cfg().GetAdapter().(*gcfg.AdapterFile).SetFileName("config.yaml")
 	util.ReadConfig(&Sysconfig)
+	util.ReadConfig("./export.json", &ExportConfig)
 	IpInit()
 	mails, _ := Sysconfig["mail"].([]interface{})
 	mailConfigArrMap := util.ObjArrToMapArr(mails)

+ 1 - 1
src/jfw/modules/app/src/main.go

@@ -68,7 +68,7 @@ func initXweb() {
 	xweb.RootApp().AppConfig.CacheTemplates = Sysconfig["cacheflag"].(bool)
 	xweb.RootApp().AddTmplVar("Msg", tag.Msg)
 	xweb.RootApp().AddTmplVar("Cdns", tag.Cdns)
-
+	xweb.RootApp().AddTmplVar("Export", tag.Export)
 	xweb.RootApp().AddTmplVar("Ad", tag.Ad)
 	xweb.RootApp().AddTmplVar("SafeUrl", tag.SafeUrl)
 	xweb.RootApp().Logger.SetOutputLevel(1) //输出日志,改为4则不输出任何日志

+ 1 - 0
src/jfw/tag/a_init.go

@@ -15,4 +15,5 @@ func init() {
 	xweb.RootApp().AddTmplVar("ParseHtml", ParseHtml)
 	xweb.RootApp().AddTmplVar("ParseHtmlCss", ParseHtmlCss)
 	xweb.RootApp().AddTmplVar("ParseHtmlAttr", ParseHtmlAttr)
+	xweb.RootApp().AddTmplVar("Export", Export)
 }

+ 6 - 3
src/jfw/tag/msg.go

@@ -10,12 +10,16 @@ import (
 	util "app.yhyue.com/moapp/jybase/common"
 )
 
-//从json配置文件中读取值
+// 从json配置文件中读取值
+func Export() map[string]interface{} {
+	return config.ExportConfig
+}
+
+// 从json配置文件中读取值
 func Msg(mtype, key string) string {
 	return readproperty(mtype, key)
 }
 
-//
 func DateTip(date2 int64) (timedate string) {
 	timedate = "30秒前"
 	date1 := time.Now().Unix()
@@ -50,7 +54,6 @@ func DateTip(date2 int64) (timedate string) {
 	return
 }
 
-//
 func readproperty(mtype, key string) string {
 	switch mtype {
 	case "seo":