xuzhiheng 2 anos atrás
pai
commit
cce61e0464

+ 23 - 21
sqlutil/src/sqlmodel/rules_es.go

@@ -1,10 +1,11 @@
 package sqlmodel
 
 type QueryObjecct struct {
-	Filtered struct {
-		Filter *Filter `json:"filter,omitempty"`
-		Query *Query   `json:"query,omitempty"`
-	} `json:"filtered,omitempty"`
+	Bool *BoolObject `json:"bool,omitempty"`
+	// Filtered struct {
+	// 	Filter *Filter `json:"filter,omitempty"`
+	// 	Query  *Query  `json:"query,omitempty"`
+	// } `json:"filtered,omitempty"`
 }
 
 type Query struct {
@@ -15,12 +16,12 @@ type Filter struct {
 	Bool *BoolObject `json:"bool,omitempty"`
 }
 
-//省市县
+// 省市县
 type AreaCityDistrictMust struct {
 	*AreaCityDistrict `json:"terms,omitempty"`
 }
 
-//省市县
+// 省市县
 type AreaCityDistrict struct {
 	Area     []string `json:"area,omitempty"`
 	City     []string `json:"city,omitempty"`
@@ -34,12 +35,12 @@ type DistrictObject struct {
 	} `json:"term,omitempty"`
 }
 
-//一级分类、二级分类
+// 一级分类、二级分类
 type ToptypeSubtypeMust struct {
 	*ToptypeSubtype `json:"terms,omitempty"`
 }
 
-//一级分类、二级分类
+// 一级分类、二级分类
 type ToptypeSubtype struct {
 	Toptype []string `json:"toptype,omitempty"`
 	Subtype []string `json:"subtype,omitempty"`
@@ -50,7 +51,7 @@ type ToptypeSubtype struct {
 //	*Scopeclass `json:"prefix,omitempty"`
 //}
 
-//公告类型
+// 公告类型
 type ScopeclassMust struct {
 	*Scopeclass `json:"terms,omitempty"`
 }
@@ -76,12 +77,12 @@ type BudgetOrBidamount struct {
 	Lt  float64 `json:"lt,omitempty"`
 }
 
-//时间范围
+// 时间范围
 type PublishtimeMust struct {
 	PublishtimeObject *PublishtimeObject `json:"range,omitempty"`
 }
 
-//时间范围
+// 时间范围
 type PublishtimeObject struct {
 	//查询时间
 	Publishtime  *Publishtime  `json:"publishtime,omitempty"`
@@ -89,7 +90,7 @@ type PublishtimeObject struct {
 	Publishtime2 *Publishtime2 `json:"publishtime2,omitempty"`
 }
 
-//查询时间
+// 查询时间
 type Publishtime struct {
 	Gte int `json:"gte"`
 	Lt  int `json:"lt"`
@@ -101,12 +102,12 @@ type Publishtime2 struct {
 	Lt int `json:"lt"`
 }
 
-//字段是或否存在
+// 字段是或否存在
 type ExistfieldsObjectMust struct {
 	ExistfieldsObject *ExistfieldsObject `json:"constant_score,omitempty"`
 }
 
-//字段存在 存在放MustNot,字符串为空忽略
+// 字段存在 存在放MustNot,字符串为空忽略
 type ExistfieldsObject struct {
 	Filter struct {
 		Missing struct {
@@ -120,7 +121,7 @@ type ShouldObj struct {
 	MultiMatch  *MultiMatch  `json:"multi_match,omitempty"`
 }
 
-//匹配方式
+// 匹配方式
 type MatchPhrase struct {
 	Title       string `json:"title,omitempty"`
 	Detail      string `json:"detail,omitempty"`
@@ -135,9 +136,9 @@ type MultiMatch struct {
 	Fields []string `json:"fields,omitempty"`
 }
 
-//匹配方式 采购单位、中标单位 正则匹配
+// 匹配方式 采购单位、中标单位 正则匹配
 type Regular struct {
-	Regexp1 *MultiMatch  `json:"regexp1,omitempty"`
+	Regexp1 *MultiMatch `json:"regexp1,omitempty"`
 	Regexp2 *MultiMatch `json:"regexp2,omitempty"`
 }
 type Regular_Buyer struct {
@@ -152,6 +153,7 @@ type Regular_winner struct {
 	Type   string   `json:"type,omitempty"`
 	Fields []string `json:"fields,omitempty"`
 }
+
 /********************************************/
 type BuyerMatch struct {
 	*Buyer `json:"terms,omitempty"`
@@ -169,13 +171,13 @@ type Winner struct {
 
 /********************************************/
 
-//排除词 must_not
+// 排除词 must_not
 type NotkeyObject struct {
 	MatchPhrase *MatchPhrase `json:"match_phrase,omitempty"`
 	MultiMatch  *MultiMatch  `json:"multi_match,omitempty"`
 }
 
-//采购单位行业 should
+// 采购单位行业 should
 type BuyerclassObject struct {
 	Terms struct {
 		Buyerclass []string `json:"buyerclass,omitempty"`
@@ -188,14 +190,14 @@ type TopscopeclassObject struct {
 	} `json:"terms,omitempty"`
 }
 
-//公告行业二级 should
+// 公告行业二级 should
 type SubscopeclassObject struct {
 	Terms struct {
 		Subscopeclass []string `json:"s_subscopeclass,omitempty"`
 	} `json:"terms,omitempty"`
 }
 
-//xf should
+// xf should
 type NewEsObject struct {
 	Bool struct {
 		Must    []interface{} `json:"must,omitempty"`

+ 11 - 12
src/client/customerRule.go

@@ -123,7 +123,7 @@ func filter(sql string) string {
 	return sql
 }
 
-//匹配包含detail的组
+// 匹配包含detail的组
 func checkDetail(sql string) (arrMap map[string]string) {
 	arrMap = map[string]string{}
 	res := reg_detail.FindAllStringSubmatch(sql, -1)
@@ -137,12 +137,12 @@ func checkDetail(sql string) (arrMap map[string]string) {
 	return
 }
 
-//校验是否有单字
+// 校验是否有单字
 func checkSingleWord(sql string) bool {
 	return len(reg_single.FindStringSubmatch(sql)) > 0
 }
 
-//计算每组字段的替换值
+// 计算每组字段的替换值
 func makeReplace(s_match string) (s_replace string) {
 	arr := []string{}
 	for _, v := range strings.Split(s_match, ",") {
@@ -153,7 +153,7 @@ func makeReplace(s_match string) (s_replace string) {
 	return strings.Join(arr, ",")
 }
 
-//导入关键词
+// 导入关键词
 func (r *CustomerRule) RuleImport() {
 	defer qu.Catch()
 	if r.Method() == "POST" {
@@ -180,7 +180,7 @@ func (r *CustomerRule) RuleImport() {
 	}
 }
 
-//生成预览数据
+// 生成预览数据
 func (c *CustomerRule) ProductData() {
 	defer qu.Catch()
 	if c.Method() == "POST" {
@@ -385,10 +385,10 @@ func FilterTimeSql(esquery string, startTime, endTime int64) (string, error) {
 	if json.Unmarshal([]byte(esquery), &query) == nil {
 		qb := query["query"]
 		for i := 0; i <= 2; i++ {
-			filter := qb.Filtered.Filter
-			if filter != nil && filter.Bool != nil { //有filter
+			filter := qb.Bool
+			if filter != nil { //有filter
 				index := -1 //记录range的位置
-				for i, m := range filter.Bool.Must {
+				for i, m := range filter.Must {
 					mMap := m.(map[string]interface{})
 					if esRange, ok := mMap["range"].(map[string]interface{}); ok && esRange != nil { //有range
 						if esRange["publishtime"] != nil {
@@ -407,9 +407,9 @@ func FilterTimeSql(esquery string, startTime, endTime int64) (string, error) {
 					},
 				}
 				if index > -1 {
-					filter.Bool.Must[index] = tmpRange_
+					filter.Must[index] = tmpRange_
 				} else {
-					filter.Bool.Must = append(filter.Bool.Must, tmpRange_)
+					filter.Must = append(filter.Must, tmpRange_)
 				}
 				tmpQuery := query
 				strQuery, err := json.Marshal(tmpQuery)
@@ -420,8 +420,7 @@ func FilterTimeSql(esquery string, startTime, endTime int64) (string, error) {
 					return esquery, err
 				}
 			} else {
-				qb.Filtered.Filter = &sql.Filter{}
-				qb.Filtered.Filter.Bool = &sql.BoolObject{}
+				qb.Bool = &sql.BoolObject{}
 				continue
 			}
 		}

+ 22 - 19
src/config.json

@@ -1,10 +1,10 @@
 {
   "port": "7001",
   "udpport": ":11117",
-  "mgodb": "192.168.3.207:27092",
+  "mgodb": "192.168.3.71:29099",
   "dbsize": 5,
   "dbname": "datatag_ent",
-  "mgodben": "192.168.3.207:27092",
+  "mgodben": "192.168.3.71:29099",
   "dbnameen": "enterprise",
   "mongoenc": "winner_enterprise",
   "subday": 15,
@@ -15,7 +15,7 @@
     "dbsize": 5
   },
   "preview_href": "http://192.168.3.204:8081/preview/data-preview.html",
-  "elasticsearch": "http://192.168.3.206:9800",
+  "elasticsearch": "http://192.168.3.241:9205",
   "elasticsearch_index": "bidding",
   "elasticsearch_type": "bidding",
   "elasticsearch_interim_index": "bidding",
@@ -32,24 +32,24 @@
     "memo": "生索引"
   },
   "buyerinfo": {
-    "addr": "192.168.3.207:27001,192.168.3.206:27002",
+    "addr": "192.168.3.71:29099",
     "size": 15,
     "db": "mixdata",
     "hospcoll": "buyer_rank",
     "buyerentcoll": "buyer_ent",
-    "username": "jyDevGroup",
-    "password": "jy@DevGroup"
+    "username": "",
+    "password": ""
   },
   "enterprise": {
-    "addr": "192.168.3.207:27001,192.168.3.206:27002",
+    "addr": "192.168.3.71:29099",
     "size": 15,
     "db": "mixdata",
     "coll": "qyxy_std",
-    "username": "jyDevGroup",
-    "password": "jy@DevGroup"
+    "username": "",
+    "password": ""
   },
   "save": {
-    "addr": "192.168.3.207:27092",
+    "addr": "192.168.3.71:29099",
     "size": 15,
     "db": "datatag_ent",
     "coll": "usermail_history",
@@ -58,16 +58,19 @@
     "coll_project": "usermail_history_projectid"
   },
   "extract": {
-    "addr": "192.168.3.128:27080",
+    "addr": "192.168.3.206:27080",
     "coll": "result_20200917",
     "db": "qfw",
     "size": 15
   },
   "es": {
-    "addr": "http://192.168.3.206:9800",
-    "index": "bidding_v1",
+    "addr": "http://192.168.3.241:9205",
+    "index": "bidding",
     "itype": "bidding",
-    "pool": 15
+    "pool": 15,
+    "version": "v7",
+    "userName": "",
+    "password": ""
   },
   "mail": [
     {
@@ -216,20 +219,20 @@
     "jyMDBXQQIDCQBeSUdBITNf",
     "jyFApXQQIEAw5TTUZOMBpD"
   ],
-  "redis_addrs": "datag=192.168.3.128:1712,export=192.168.3.128:1712",
+  "redis_addrs": "datag=192.168.3.11:1712,export=192.168.3.11:1712",
   "jyMysql": {
     "username": "root",
     "password": "Topnet123",
-    "address": "192.168.3.11:3366",
+    "address": "192.168.3.149:3306",
     "dbName": "jianyu"
   },
   "bidding_mgo": {
-    "addr": "192.168.3.207:27001,192.168.3.206:27002",
+    "addr": "192.168.3.71:29099",
     "coll": "bidding",
     "db": "qfw_data",
     "size": 15,
-    "username": "jyDevGroup",
-    "password": "jy@DevGroup",
+    "username": "",
+    "password": "",
     "replSet": "bidding"
   },
   "file_downloadurl": "http://jy-datafile.oss-cn-beijing.aliyuncs.com/",

+ 0 - 221
src/history/datamodel.go

@@ -1,221 +0,0 @@
-package history
-
-import (
-	"qfw/util"
-	"regexp"
-	"sync"
-
-	"gopkg.in/mgo.v2/bson"
-)
-
-// var FielsArr = map[string]interface{}{
-// 	"title":            "公告标题",
-// 	"content":          "公告内容",
-// 	"href":             "公告地址",
-// 	"jybxhref":         "剑鱼标讯地址",
-// 	"detail":           "公告正文",
-// 	"area":             "省份",
-// 	"city":             "城市",
-// 	"publishtime":      "发布时间",
-// 	"projectname":      "项目名称",
-// 	"projectcode":      "项目编号",
-// 	"buyer":            "采购单位",
-// 	"buyerperson":      "采购单位联系人",
-// 	"buyertel":         "采购单位联系电话",
-// 	"budget":           "预算(元)",
-// 	"bidopentime":      "开标日期",
-// 	"s_winner":         "中标单位",
-// 	"bidamount":        "中标价(元)",
-// 	"agency":           "招标机构",
-// 	"projectscope":     "项目范围",
-// 	"currency":         "币种",
-// 	"subtype":          "公告类别",
-// 	"toptype":          "公告类别大类",
-// 	"id":               "信息标识",
-// 	"industry":         "行业",
-// 	"matchkey":         "信息匹配词",
-// 	"matchtype":        "匹配字段",
-// 	"priority":         "信息重要程度",
-// 	"department":       "部门",
-// 	"excludetype":      "排除类型",
-// 	"winner_organcode": "中标单位代码",
-// 	"winner_phone":     "中标单位电话",
-// 	"subscopeclass":    "信息二级分类",
-// 	"winner":           "中标单位",
-// 	"winner_county":    "中标单位县区",
-// 	"winner_address":   "中标单位地址",
-// 	"winner_city":      "中标单位城市",
-// 	"winner_time":      "中标时间",
-// 	"bid2017":          "2017年中标数",
-// 	"bid2018":          "2018年中标数",
-// 	"bid2019":          "2019年中标数",
-// 	"bid2020":          "2020年中标数",
-// 	"winner_credit_no": "中标单位征信代码",
-// 	"buyer_credit_no":  "招标客户征信代码",
-// 	"stock_name":       "股东名单",
-// 	"business_scope":   "经营范围",
-// 	"establish_date":   "注册时间",
-// 	"capital":          "注册资金",
-// 	"winneraddr":       "中标单位的注册地址",
-// 	"purchasing":       "中标产品信息",
-// 	"rank":             "医院等级",
-// 	"winnertel":        "中标单位联系电话(公告)",
-// 	"winnerperson":     "中标单位联系人(公告)",
-// 	"district":         "区县",
-// 	"legal_person":     "中标单位联系人(公示网站)",
-// 	"company_phone":    "中标单位联系电话(公示网站)",
-// 	"company_email":    "中标单位电子邮箱(公示网站)",
-// 	"company_address":  "中标单位注册地址(公示网站)",
-// 	"tagname":          "标签名称",
-// }
-var (
-	MgoSaveCache           = make(chan map[string]interface{}, 1000)
-	MgoSaveUsermailCache   = make(chan map[string]interface{}, 1000)
-	xlsxArr                = []map[string]interface{}{}
-	SP                     = make(chan bool, 5)
-	xlsxCount              = 0
-	SE                     = util.SimpleEncrypt{Key: "topJYBX2019"}
-	ProjectAppidMap        = map[string]bool{}
-	projectIdMap           = sync.Map{}
-	FileTextAppidMap       = map[string]bool{}
-	CheckBidOpenAppidMap   = map[string]bool{}
-	CheckBidHrefRuleIdMap  = map[string]bool{}
-	DisPackageAppidMap     = map[string]bool{}
-	NeedProjectidAppidMap  = map[string]bool{}
-	FilterFilehrefAppidMap = map[string]bool{}
-	NeedFilehrefAppidMap      = map[string]bool{}
-)
-
-//客户模型
-type Customer struct {
-	ID           string                            //客户ID
-	Name         string                            //客户名称
-	AppId        string                            //appid
-	PushModel    int                               //推送模式 0:全局模式;1:部门模式;2:标签模式;3:部门+标签模式;4:规则模式
-	Departments  []*Department                     //所有部门
-	IsTagRule    bool                              //是否打标签
-	IsSearchHosp bool                              //是否查询第三方医院信息
-	IsSearchEnps bool                              //是否查询第三方企业信息
-	TagRules     []*TagRule                        //打标签规则集合
-	SaveDataMap  map[string]map[string]interface{} //最终入库数据(全局模式)
-	SaveDataArr  []map[string]interface{}          //最终入库数据(规则模式)
-	IdRange      bson.M                            //由当前时间生成是id查询区间
-}
-
-//部门模型
-type Department struct {
-	ID             string                              //部门ID
-	Name           string                              //部门名称
-	CustomerID     string                              //所属客户id
-	Rules          []*SearchRule                       //客户的多个规则
-	DepartmentData map[string][]map[string]interface{} //部门所有数据 key:ruleid value:[{k:dataid v:data},{k:dataid v:data}]
-	DataLock    *sync.Mutex                            //数据锁
-	SaveDataMap map[string]map[string]interface{}      //最终入库数据(部门内部去重)
-}
-
-//查询规则模型
-type SearchRule struct {
-	//一条查询规则
-	ID           string
-	Name         string
-	ExtFieldType int                    //规则1、标准字段包,2、高级字段包
-	CustomerID   string                 //所属客户id
-	DepartmentID string                 //所属部门id
-	EsQuery      string                 //客户所有标签的es语句
-	Fields       map[string]interface{} //存储所有字段(清理词、关键词、附加词匹配方式)
-	GCW          *ClearWord             //全局清理词
-	KW           []*KeyWord             //多组关键词(与附加词一一对应)
-	AW           []*AddWord             //多组附加词(与关键词一一对应)
-	Maths        []map[string]string
-}
-
-//打标签规则模型
-type TagRule struct {
-	//一条打标签规则
-	ID            string
-	Name          string
-	CustomerId    string
-	DepartRuleIds map[string]bool        //部门规则id组
-	Fields        map[string]interface{} //存储所有字段(排除词、关键词、附加词匹配方式)
-	//GNW           []*GlobalNotWord //全局排除词
-	//GAW           []*GlobalAddWord //全局附加词
-	NW       []*NotKeyWord //排除词
-	KW       []*KeyWord    //多组关键词(与附加词一一对应)
-	AW       []*AddWord    //多组附加词(与关键词一一对应)
-	TagNames []string      //一个关键词+一个附加词都有一个标签名称
-}
-
-//全局清理词类型
-type ClearWord struct {
-	KeyReg    []*regexp.Regexp
-	MatchType []string //清理词匹配方式
-}
-
-//关键词类型
-type KeyWord struct {
-	KeyReg    *Reg     //匹配规则(0:逗号分隔 1:&&分隔)      例如:[[智能,5G],[智慧交通,智慧城市]]
-	MatchType []string //关键词的匹配方式
-	//KeyWordMap []map[int]bool
-	//KeyWordMap []map[int]interface{} //记录KeyReg中字母规则(0:逗号分隔 1:&&分隔 interface{}实际为map[string]string k:大写 v:原值)
-	//KeyStr     [][]string            //记录关键词的原始值,与KeyReg一一对应 例如:[[智能,5G],[智慧交通&&智慧城市]]
-	//KeyWordMap []map[int]map[string]string //记录KeyReg中字母规则(0:逗号分隔 1:&&分隔)
-}
-
-//附加词类型
-type AddWord struct {
-	KeyReg    *Reg     //匹配规则(0:逗号分隔 1:&&分隔)
-	MatchType []string //附加词的匹配方式
-	//AddWordMap []map[int]bool
-	//AddWordMap []map[int]interface{} //记录KeyReg中字母规则(0:逗号分隔 1:&&分隔 interface{}实际为map[string]string k:大写 v:原值)
-	//KeyStr     [][]string
-	//AddWordMap []map[int]map[string]string //记录KeyReg中字母规则(0:逗号分隔 1:&&分隔)
-}
-
-//排除词
-type NotKeyWord struct {
-	KeyReg    *Reg     //例如:排除1&&排除2,排除3,KeyReg[0]存 排除3;KeyReg[1]存 排除1 排除2
-	MatchType []string //排除词的匹配方式
-	//NotWordMap []map[int]bool //记录KeyReg中字母规则
-}
-
-//匹配正则
-type Reg struct {
-	CReg []*CommonReg //逗号分隔
-	AReg []*AndRegPre //&&分隔
-	//KeyStr []string     //原始值(用于含字母时取原值)
-}
-
-//逗号分隔正则
-type CommonReg struct {
-	CrVal    *regexp.Regexp //正则类型
-	CsVal    string         //原始值
-	IsLetter bool           //是否含字母
-}
-
-//&&分隔正则
-type AndRegPre struct {
-	AndRegKid []*AndReg
-	CsVal     string //原始值
-}
-
-//&&分隔正则
-type AndReg struct {
-	CrVal    *regexp.Regexp
-	IsLetter bool //是否含字母
-}
-
-/*
-//全局排除词类型
-type GlobalNotWord struct {
-	KeyReg           [][]*regexp.Regexp //例如:排除1&&排除2,排除3,KeyReg[0]存 排除3;KeyReg[1]存 排除1 排除2
-	MatchType        []string           //排除词的匹配方式
-	GlobalNotWordMap []map[int]bool     //记录KeyReg中字母规则
-}
-
-//全局附加词类型
-type GlobalAddWord struct {
-	KeyReg           [][]*regexp.Regexp //例如:附加1&&附加2,附加3,KeyReg[0]存 附加3;KeyReg[1]存 附加1 附加2
-	MatchType        []string           //匹配方式
-	GlobalAddWordMap []map[int]bool     //记录KeyReg中字母规则
-}
-*/

+ 0 - 679
src/history/historytask.go

@@ -1,679 +0,0 @@
-package history
-
-import (
-	"encoding/json"
-	"fmt"
-	"regexp"
-	"sync"
-
-	"gopkg.in/mgo.v2/bson"
-
-	"log"
-	mongoutil "qfw/mongodb"
-	qu "qfw/util"
-	"strings"
-	"time"
-	. "util"
-
-	"github.com/go-xweb/xweb"
-)
-
-type HistoryData struct {
-	*xweb.Action
-	historyTask     xweb.Mapper `xweb:"/service/history/(.*)"`
-	historyList     xweb.Mapper `xweb:"/service/historylog/list"`
-	historyClone    xweb.Mapper `xweb:"/service/historyClone/(.*)"`
-	historyRuleEdit xweb.Mapper `xweb:"/service/historyRule/edit"`
-	productData     xweb.Mapper `xweb:"/service/history/produce"` //历史数据生成预览数据
-	dataTest        xweb.Mapper `xweb:"/service/dataTest/(.*)"`
-}
-
-func (this *HistoryData) HistoryTask(history_id string) {
-	log.Println("开始历史任务...")
-	go UpdateHistoryState(1, history_id, 0)
-	//加载一个客户
-	log.Println("history_id", history_id)
-	//是否根据项目id去重
-	/*isFilter, _ := this.GetInteger("isFilter")
-	noticeFilter, _ := this.GetInteger("noticeIsFilter")
-	dataTable, _ := this.GetInteger("dataTable")
-	log.Println(isFilter, noticeFilter, dataTable)*/
-	customer, _ := Mgo.Find("historylog", map[string]interface{}{"_id": mongoutil.StringTOBsonId(history_id)}, nil, nil, false, -1, -1)
-	if len(*customer) == 1 {
-		c := (*customer)[0]
-		customerId := mongoutil.BsonIdToSId(c["_id"])
-		customer_name := qu.ObjToString(c["s_name"]) //客户名称
-		appId := qu.ObjToString(c["s_appid"])        //appid
-		extends := qu.ObjToString(c["s_extends"])    //扩展信息
-		pushModel := qu.IntAll(c["i_pushmodel"])     //推送模式
-		email := qu.ObjToString(c["sendMail"])       //推送邮箱
-		noticeFilter := qu.IntAll(c["isDup"])        //公告是否去重
-		isFilter := qu.IntAll(c["i_projectdup"])     //是否根据项目id去重
-		dataTable := qu.IntAll(c["i_datatable"])     //数据存储位置
-		i_pushtype := qu.IntAll(c["i_pushtype"])     //邮箱或者存表
-
-		isfile := false
-		isHenanMobile := false
-		isfilehref := false
-		if FileTextAppidMap[appId] {
-			isfile = true
-		}
-		if DisPackageAppidMap[appId] {
-			isHenanMobile = true
-		}
-		if NeedFilehrefAppidMap[appId] {
-			isfilehref = true
-		}
-		cus := &Customer{}
-		cus.SaveDataMap = map[string]map[string]interface{}{}
-		cus.SaveDataArr = []map[string]interface{}{}
-		cus.ID = customerId
-		cus.Name = customer_name
-		cus.PushModel = pushModel
-		cus.AppId = appId
-		for _, v := range strings.Split(extends, ",") {
-			if v == "hospitalgrade" {
-				cus.IsSearchHosp = true
-			} else if v == "enterpise" {
-				cus.IsSearchEnps = true
-			}
-		}
-		//
-		//if ProjectAppidMap[appId] {
-		if isFilter == 1 {
-			log.Println("g根据项目id去重。。。")
-			start := time.Now().Unix()
-			log.Println("加载projectId---开始")
-			if dataTable == 0 {
-				InitProjectId(appId)
-			}
-			if dataTable == 1 {
-				InitUsermailProjectId(appId)
-			}
-			end := time.Now().Unix()
-			log.Println("加载projectId---结束,耗时", end-start, "秒")
-		} else {
-			projectIdMap = sync.Map{}
-		}
-		entId := 0
-		if dataTable == 2 { //存到mysql pushentniche表中
-			//根据APPID查询客户手机号,在去mysql查询客户企业id
-			cusdata, _ := MgoCus.FindOneByField("user", map[string]interface{}{"appid": appId}, `"phone":1`)
-			if cusdata != nil && len(*cusdata) > 0 {
-				phone := qu.ObjToString((*cusdata)["phone"])
-				entInfo := JyMysql.FindOne("entniche_info", map[string]interface{}{"phone": phone}, "id,phone", "")
-				if entInfo != nil && len(*entInfo) > 0 {
-					entId = qu.IntAll((*entInfo)["id"])
-				}
-			}
-		}
-		//
-		tag_rule, ok := c["tag_rules"].([]interface{})
-		if !ok {
-			tag_rule = []interface{}{}
-		}
-		dep_rule, ok := c["dep_rules"].([]interface{})
-		if !ok {
-			dep_rule = []interface{}{}
-		}
-		tag_rules := qu.ObjArrToMapArr(tag_rule)
-		dep_rules := qu.ObjArrToMapArr(dep_rule)
-		log.Println(tag_rules, "*********************")
-		cus.GetTagRules(tag_rules)               //获取客户打标签规则
-		cus.GetDepartments("history", dep_rules) //获取客户信息
-		qu.Debug("customer:", cus.ID, cus.Name, cus.PushModel, cus.AppId, cus.IsTagRule, cus.IsSearchHosp, cus.IsSearchEnps, len(cus.TagRules), len(cus.Departments))
-		cus.GetData("history")                                                        //获取数据
-		cus.RemoveRepeatData()                                                        //数据去重
-		cus.AssembelAndSaveData(history_id, isFilter, noticeFilter, dataTable, entId) //组装、保存数据
-		if dataTable == 2 {
-			//使用pc商机管理的企业,数据存入mysql表,扣除数据量
-			if xlsxCount > 0 {
-				go UpdateJyqyfwDatacount(appId, xlsxCount)
-			}
-		}
-		//发邮件
-		if i_pushtype == 0 {
-			go func() {
-				time.Sleep(3 * time.Second)
-				log.Println("xlsxArr", len(xlsxArr))
-				log.Println("xlsxCount", xlsxCount)
-				if len(xlsxArr) != xlsxCount {
-					log.Println("excel数据量错误")
-				}
-				GetXlsxs(xlsxArr, customer_name, email, history_id, isfile, isHenanMobile, isfilehref, appId)
-				go UpdateHistoryState(2, history_id, xlsxCount)
-				xlsxArr = []map[string]interface{}{}
-				xlsxCount = 0
-			}()
-			projectIdMap = sync.Map{}
-		} else {
-			go UpdateHistoryState(2, history_id, xlsxCount)
-			xlsxArr = []map[string]interface{}{}
-			xlsxCount = 0
-		}
-	} else {
-		log.Println("初始化客户信息失败")
-	}
-}
-
-func (this *HistoryData) HistoryList() {
-	id := this.GetString("id")
-	if this.Method() == "POST" {
-		data, _ := Mgo.Find("historylog", map[string]interface{}{"user_id": id}, `{"createtime":-1}`, nil, false, -1, -1)
-		this.ServeJson(map[string]interface{}{
-			"data": data,
-		})
-	} else {
-		this.T["id"] = id
-		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": mongoutil.StringTOBsonId(history_id)}, map[string]interface{}{
-			"$set": map[string]interface{}{
-				"state":        state,
-				"result_count": count,
-				"finishtime":   time.Now().Unix(),
-			},
-		}, false, false)
-		return
-	}
-
-	Mgo.Update("historylog", map[string]interface{}{"_id": mongoutil.StringTOBsonId(history_id)}, map[string]interface{}{
-		"$set": map[string]interface{}{
-			"state": state,
-		},
-	}, false, false)
-}
-
-func (this *HistoryData) HistoryClone(hid string) {
-	user := this.GetSession("user").(map[string]interface{})
-	data, ok := Mgo.FindOne("historylog", map[string]interface{}{"_id": mongoutil.StringTOBsonId(hid)})
-	if ok && data != nil && *data != nil {
-		(*data)["state"] = 0
-		(*data)["result_count"] = nil
-		(*data)["createtime"] = time.Now().Unix()
-		(*data)["updatetime"] = time.Now().Unix()
-		(*data)["create_user"] = user["name"]
-		Mgo.Save("historylog", *data)
-	}
-}
-
-func (c *HistoryData) HistoryRuleEdit() {
-	hid := c.GetString("hid")
-	rid := c.GetString("rid")
-	if c.Method() == "POST" {
-		data := GetPostForm(c.Request)
-		o_rules := []map[string]interface{}{}
-		o_rulesStr := data["o_rules"].(string)
-		json.Unmarshal([]byte(o_rulesStr), &o_rules)
-		data["o_rules"] = o_rules
-		data["_id"] = mongoutil.StringTOBsonId(rid)
-		if qu.IntAll(data["i_esquerytype"]) == 1 { //自动生成es
-			data["s_esquery"] = Utiltags(data)
-		}
-		datas, ok := Mgo.FindOne("historylog", map[string]interface{}{"_id": mongoutil.StringTOBsonId(hid)})
-		if ok && datas != nil && *datas != nil {
-			dep_rules := qu.ObjArrToMapArr((*datas)["dep_rules"].([]interface{}))
-			for k, v := range dep_rules {
-				if rid == mongoutil.BsonIdToSId(v["_id"]) {
-					dep_rules[k] = data
-				}
-			}
-			rep := Mgo.Update("historylog", map[string]interface{}{"_id": mongoutil.StringTOBsonId(hid)}, map[string]interface{}{"$set": map[string]interface{}{"dep_rules": dep_rules}}, false, false)
-			c.ServeJson(map[string]interface{}{
-				"rep":       rep,
-				"s_esquery": data["s_esquery"],
-			})
-		}
-	} else {
-		id := c.GetString("id")
-		data, ok := Mgo.FindOne("historylog", map[string]interface{}{"_id": mongoutil.StringTOBsonId(hid)})
-		if ok && data != nil && *data != nil {
-			dep_rules := qu.ObjArrToMapArr((*data)["dep_rules"].([]interface{}))
-			for _, v := range dep_rules {
-				if rid == mongoutil.BsonIdToSId(v["_id"]) {
-					c.T["data"] = v
-				}
-			}
-		}
-		c.T["did"] = id //部门id
-		c.T["cid"] = id //客户id
-		c.T["ids"] = id
-		c.T["history_id"] = hid
-		c.T["rid"] = rid
-		c.T["province"] = Province
-		c.T["city"] = ProvinceCitys
-		c.T["district"] = CityDistricts
-		c.T["topTypeArr"] = TopTypeArr
-		c.T["subTypeArr"] = SubTypeArr
-		c.T["matchTypeMap"] = MatchTypeMap
-		c.T["matchTypeMap2"] = MatchTypeMap2
-		c.T["existField"] = ExistFiled
-		c.T["buyerClass"] = BuyerClass
-		c.T["buyerClassMap"] = BuyerClassMap
-		c.T["scopeClass"] = ScopeClassMap
-		c.Render("private/history_rule_edit.html", &c.T)
-	}
-}
-
-func (this *HistoryData) ProductData() {
-	defer qu.Catch()
-	if this.Method() == "POST" {
-		rep := false
-		id := this.GetString("id")
-		hid := this.GetString("hid")
-		dep_rules, _ := Mgo.FindById("historylog", hid, `{"dep_rules:1"}`)
-		var tag = map[string]interface{}{}
-		if len(*dep_rules) != 0 && dep_rules != nil {
-			for _, v := range (*dep_rules)["dep_rules"].([]interface{}) {
-				dep_rule := qu.ObjToMap(v)
-				if (*dep_rule)["_id"] == mongoutil.StringTOBsonId(id) {
-					tag = *dep_rule
-				}
-			}
-		}
-
-		// 限制multi_match 个数小于1000个
-		s_esquery := qu.ObjToString((tag)["s_esquery"])
-		multi_match_count := strings.Count(s_esquery, "multi_match")
-		//fmt.Println("multi_match", multi_match_count, s_esquery)
-		if multi_match_count > 1000 {
-			this.ServeJson(map[string]interface{}{
-				"rep": false,
-				"msg": "关键词、附加词、排除词、全局附加词、全局排除词过多,请分多条规则查询",
-			})
-			return
-		}
-		//关键词总字节
-		keyTotal := 0
-		//附加词总字节
-		addKeyTotal := 0
-		for _, v_ := range (tag)["o_rules"].([]interface{}) {
-			v := v_.(map[string]interface{})
-			// 匹配方式6/7 时为 单位匹配和中标单位匹配 生成es时使用的是terms
-			// 关键词
-			if v["s_keymatch"] == "7" || v["s_keymatch"] == "6" {
-				s_matchkey := strings.Replace(v["s_matchkey"].(string), ",", "", -1)
-				if len(s_matchkey) > 4000 {
-					this.ServeJson(map[string]interface{}{
-						"rep": false,
-						"msg": "采购单位、中标单位过多,请分多条规则查询",
-					})
-					return
-				} else {
-					keyTotal += len(s_matchkey)
-				}
-			}
-			// 附加词
-			if v["s_addkeymatch"] == "7" || v["s_addkeymatch"] == "6" {
-				s_addkey := strings.Replace(v["s_addkey"].(string), ",", "", -1)
-				if len(s_addkey) > 4000 {
-					this.ServeJson(map[string]interface{}{
-						"rep": false,
-						"msg": "采购单位、中标单位过多,请分多条规则查询",
-					})
-					return
-				} else {
-					addKeyTotal += len(s_addkey)
-				}
-			}
-			// 判断总数是否大于4000
-			if keyTotal > 4000 || addKeyTotal > 4000 {
-				this.ServeJson(map[string]interface{}{
-					"rep": false,
-					"msg": "采购单位、中标单位过多,请分多条规则查询",
-				})
-				return
-			}
-
-		}
-
-		err, count := UtilEsFind1(tag)
-		if err == nil {
-			rep = true
-		}
-		this.ServeJson(map[string]interface{}{
-			"rep":   rep,
-			"count": count,
-		})
-	}
-}
-
-//func (this *HistoryData) DataTest(id string) {
-//	log.Println("测试数据是否匹配开始...")
-//	dataId := this.GetString("id")
-//	log.Println("id", id)
-//	log.Println("dataId", dataId)
-//	//加载一个客户
-//	customer, _ := Mgo.Find("cuserdepartrule", map[string]interface{}{"_id": mongoutil.StringTOBsonId(id)}, nil, nil, false, -1, -1)
-//	if len(*customer) == 1 {
-//		c := (*customer)[0]
-//		tmps := Es.GetByIdField(Index, Itype, dataId, "")
-//		tmp := map[string]interface{}{}
-//		if tmps != nil {
-//			tmp = *tmps
-//		}
-//		if len(tmp) == 0 {
-//			this.ServeJson(map[string]interface{}{
-//				"result": false,
-//				"info":   "没有查到此数据",
-//			})
-//			return
-//		}
-//		s_globaladdkey := qu.ObjToString(c["s_globaladdkey"])
-//		s_globaladdkeymatch := qu.ObjToString(c["s_globaladdkeymatch"])
-//		s_globalnotkey := qu.ObjToString(c["s_globalnotkey"])
-//		s_globalnotkeymatch := qu.ObjToString(c["s_globalnotkeymatch"])
-//		// s_globalclearkey := qu.ObjToString(c["s_globalclearkey"])
-//		// s_globalclearkeymatch := qu.ObjToString(c["s_globalclearkeymatch"])
-//		o_rule, ok := c["o_rules"].([]interface{})
-//		if !ok {
-//			o_rule = []interface{}{}
-//		}
-//		o_rules := qu.ObjArrToMapArr(o_rule)
-//		matchKey := ""
-//		//
-//		if s_globaladdkey != "" {
-//			gKey := TestMactchKeys(s_globaladdkeymatch, s_globaladdkey, tmp)
-//			if gKey == "" {
-//				this.ServeJson(map[string]interface{}{
-//					"result": false,
-//					"info":   "全局附加词没有匹配成功",
-//				})
-//				return
-//			} else {
-//				matchKey = gKey
-//			}
-//		}
-//		if s_globalnotkey != "" {
-//			gNKey := TestMactchKeys(s_globalnotkeymatch, s_globalnotkey, tmp)
-//			if gNKey != "" {
-//				this.ServeJson(map[string]interface{}{
-//					"result":        false,
-//					"allexcluedKey": gNKey,
-//				})
-//				return
-//			}
-//		}
-//		for _, v := range o_rules {
-//			key := qu.ObjToString(v["s_matchkey"])
-//			keymatch := qu.ObjToString(v["s_keymatch"])
-//			addkey := qu.ObjToString(v["s_addkey"])
-//			addkeymatch := qu.ObjToString(v["s_addkeymatch"])
-//			notkey := qu.ObjToString(v["s_notkey"])
-//			notkeymatch := qu.ObjToString(v["s_notkeymatch"])
-//			if notkey != "" {
-//				nKey := TestMactchKeys(notkeymatch, notkey, tmp)
-//				if nKey != "" {
-//					this.ServeJson(map[string]interface{}{
-//						"result":     false,
-//						"excluedKey": nKey,
-//					})
-//					return
-//				}
-//			}
-//			if key != "" {
-//				sKey := TestMactchKeys(keymatch, key, tmp)
-//				aKey := ""
-//				if addkey != "" {
-//					aKey = TestMactchKeys(addkeymatch, addkey, tmp)
-//					if aKey != "" && sKey != "" {
-//						if matchKey != "" {
-//							matchKey += ","
-//						}
-//						matchKey = aKey + "," + sKey
-//						break
-//					}
-//				} else {
-//					if sKey != "" {
-//						if matchKey != "" {
-//							matchKey += ","
-//						}
-//						matchKey = sKey
-//						break
-//					}
-//				}
-//			}
-//		}
-//		if matchKey == "" {
-//			this.ServeJson(map[string]interface{}{
-//				"result": false,
-//				"info":   "没有匹配成功",
-//			})
-//		} else {
-//			this.ServeJson(map[string]interface{}{
-//				"result":   true,
-//				"matchKey": matchKey,
-//			})
-//		}
-//		return
-//	} else {
-//		log.Println("初始化客户信息失败")
-//	}
-//	log.Println("测试数据是否匹配结束...")
-//}
-func (this *HistoryData) DataTest(id string) {
-	//获取数据
-	title := this.GetString("title")
-	detail := this.GetString("detail")
-	//fmt.Println(title, detail)
-	if title == "" && detail == "" {
-		this.ServeJson(map[string]interface{}{
-			"status":  false,
-			"data":    "",
-			"message": "标题和正文至少要有一个",
-		})
-		return
-	}
-	article := map[string]interface{}{
-		"title":  title,
-		"detail": detail,
-	}
-
-	log.Println("测试数据是否匹配开始...")
-
-	//
-	log.Println("id", id)
-	//加载一个客户
-	customer, _ := Mgo.Find("cuserdepartrule", map[string]interface{}{"_id": mongoutil.StringTOBsonId(id)}, nil, nil, false, -1, -1)
-	if len(*customer) == 1 {
-		c := (*customer)[0]
-
-		s_globaladdkey := qu.ObjToString(c["s_globaladdkey"])
-		s_globaladdkeymatch := qu.ObjToString(c["s_globaladdkeymatch"])
-		s_globalnotkey := qu.ObjToString(c["s_globalnotkey"])
-		s_globalnotkeymatch := qu.ObjToString(c["s_globalnotkeymatch"])
-		s_globalclearkey := qu.ObjToString(c["s_globalclearkey"])
-		s_globalclearkeymatch := qu.ObjToString(c["s_globalclearkeymatch"])
-
-		//清理词匹配方式
-		cwmArr := []string{}
-		for _, mv := range strings.Split(s_globalclearkeymatch, ",") {
-			if field := qu.ObjToString(MatchType[mv]); field != "" {
-				cwmArr = append(cwmArr, field)
-			}
-		}
-		//清理词正则
-		cwkArr := []*regexp.Regexp{}
-		for _, kv := range strings.Split(s_globalclearkey, ",") {
-			if LetterCase.MatchString(kv) { //字母转大写
-				kv = strings.ToUpper(kv)
-			}
-			reg := regexp.MustCompile(kv)
-			cwkArr = append(cwkArr, reg)
-		}
-		//清理清理词
-		for _, cwm := range cwmArr {
-			if text := qu.ObjToString(article[cwm]); text != "" {
-				for _, gcw_reg := range cwkArr {
-					text = gcw_reg.ReplaceAllString(text, "")
-				}
-				article[cwm] = text
-			}
-		}
-
-		o_rule, ok := c["o_rules"].([]interface{})
-		if !ok {
-			o_rule = []interface{}{}
-		}
-		o_rules := qu.ObjArrToMapArr(o_rule)
-		matchKey := ""
-
-		if s_globaladdkey != "" {
-			gKey := TestMactchKeys(s_globaladdkeymatch, s_globaladdkey, article)
-			if gKey == "" {
-				this.ServeJson(map[string]interface{}{
-					"status": true,
-					"data": map[string]interface{}{
-						"result": false,
-						"info":   "全局附加词没有匹配成功",
-						"data":   s_globaladdkey,
-					},
-					"message": "测试成功",
-				})
-				return
-			} else {
-				matchKey = gKey
-			}
-		}
-		if s_globalnotkey != "" {
-			gNKey := TestMactchKeys(s_globalnotkeymatch, s_globalnotkey, article)
-			if gNKey != "" {
-				this.ServeJson(map[string]interface{}{
-					"status": true,
-					"data": map[string]interface{}{
-						"result": false,
-						"info":   "被全局排除词排除",
-						"data":   gNKey,
-					},
-					"message": "测试成功",
-				})
-				return
-			}
-		}
-
-		var resultList []interface{}
-		for _, v := range o_rules {
-			matchKey = ""
-			key := qu.ObjToString(v["s_matchkey"])
-			keymatch := qu.ObjToString(v["s_keymatch"])
-			addkey := qu.ObjToString(v["s_addkey"])
-			addkeymatch := qu.ObjToString(v["s_addkeymatch"])
-			notkey := qu.ObjToString(v["s_notkey"])
-			notkeymatch := qu.ObjToString(v["s_notkeymatch"])
-			var tempData = map[string]interface{}{
-				"key":         key,
-				"keymatch":    keymatch,
-				"addkey":      addkey,
-				"addkeymatch": addkeymatch,
-				"notkey":      notkey,
-				"notkeymatch": notkeymatch,
-			}
-			if notkey != "" {
-				nKey := TestMactchKeys(notkeymatch, notkey, article)
-				if nKey != "" {
-					tempData["status"] = false
-					tempData["info"] = "排除词排除"
-					tempData["data"] = nKey
-					tempData["marknotkey"] = nKey
-					resultList = append(resultList, tempData)
-					if key != "" {
-						tempData["markkey"] = TestMactchKeys(keymatch, key, article)
-					}
-					if addkey != "" {
-						tempData["markaddkey"] = TestMactchKeys(addkeymatch, addkey, article)
-					}
-					continue
-				}
-			}
-			if key != "" {
-				sKey := TestMactchKeys(keymatch, key, article)
-				tempData["markkey"] = sKey
-				aKey := ""
-				if addkey != "" {
-					aKey = TestMactchKeys(addkeymatch, addkey, article)
-					tempData["markaddkey"] = aKey
-					if aKey != "" && sKey != "" {
-						matchKey = aKey + "," + sKey
-						tempData["status"] = true
-						tempData["info"] = "匹配成功"
-						tempData["data"] = matchKey
-						resultList = append(resultList, tempData)
-
-					} else if aKey == "" {
-						tempData["status"] = false
-						tempData["info"] = "附加词匹配失败"
-						tempData["data"] = ""
-						resultList = append(resultList, tempData)
-
-					} else if sKey == "" {
-						tempData["status"] = false
-						tempData["info"] = "关键词匹配失败"
-						tempData["data"] = ""
-						resultList = append(resultList, tempData)
-
-					}
-				} else {
-					if sKey != "" {
-						matchKey = sKey
-						tempData["status"] = true
-						tempData["info"] = "匹配成功"
-						tempData["data"] = matchKey
-						resultList = append(resultList, tempData)
-
-					} else {
-
-						matchKey = sKey
-						tempData["status"] = false
-						tempData["info"] = "关键词匹配失败"
-						tempData["data"] = matchKey
-						resultList = append(resultList, tempData)
-
-					}
-				}
-			}
-		}
-		if resultList == nil {
-			this.ServeJson(map[string]interface{}{
-				"status": true,
-				"data": map[string]interface{}{
-					"result": true,
-					"info":   "全局附加词匹配成功" + matchKey,
-					"data":   "",
-				},
-				"message": "测试成功",
-			})
-			return
-
-		} else {
-			this.ServeJson(map[string]interface{}{
-				"status":  true,
-				"data":    resultList,
-				"message": "测试成功",
-			})
-		}
-		return
-	} else {
-
-		log.Println("初始化客户信息失败")
-		this.ServeJson(map[string]interface{}{
-			"status":  true,
-			"data":    "",
-			"message": "初始化客户信息失败",
-		})
-		return
-	}
-	log.Println("测试数据是否匹配结束...")
-}
-
-func UpdateJyqyfwDatacount(appid string, newGetLen int) {
-	update_b := MgoCus.Update("user", bson.M{"appid": appid}, bson.M{"$inc": bson.M{"plan.current": -newGetLen}}, false, false)
-	if update_b {
-		log.Println("历史数据导入mysql表扣量成功 appid:" + appid + "扣除数据量:" + fmt.Sprintln(newGetLen))
-		return
-	}
-	log.Println("历史数据导入mysql表扣量失败 appid:" + appid + "应扣除数据量:" + fmt.Sprintln(newGetLen))
-}

+ 0 - 749
src/history/task.go

@@ -1,749 +0,0 @@
-package history
-
-import (
-	"encoding/json"
-	"log"
-	mongoutil "qfw/mongodb"
-	qu "qfw/util"
-	"regexp"
-	. "sqlmodel"
-	"strings"
-	"sync"
-	. "util"
-
-	"gopkg.in/mgo.v2/bson"
-
-	// "go.mongodb.org/mongo-driver/bson/primitive"
-	es "gopkg.in/olivere/elastic.v1"
-)
-
-//获取客户打标签规则
-func (c *Customer) GetTagRules(tagRules []map[string]interface{}) {
-	log.Println("开始加载标签规则...")
-	defer qu.Catch()
-	if len(tagRules) > 0 {
-		c.IsTagRule = true //查到打标签规则,表示打标签
-		for _, tr := range tagRules {
-			TR := &TagRule{}
-			TR.Fields = make(map[string]interface{})
-			TR.DepartRuleIds = make(map[string]bool)
-			id := mongoutil.BsonIdToSId(tr["_id"])
-			name := qu.ObjToString(tr["s_name"])
-			TR.ID = id
-			TR.Name = name
-			TR.CustomerId = c.ID
-			//部门规则id组
-			if departRuleIds := qu.ObjToString(tr["o_departruleids"]); departRuleIds != "" {
-				for _, drid := range strings.Split(departRuleIds, ",") {
-					TR.DepartRuleIds[drid] = true
-				}
-			}
-
-			o_list, ok := tr["o_list"].([]interface{})
-			if !ok {
-				o_list = []interface{}{}
-			}
-			o_lists := qu.ObjArrToMapArr(o_list)
-			//规则
-			if len(o_list) > 0 {
-				TR.GetKeyAddNotKeyWord(o_lists)
-			}
-			c.TagRules = append(c.TagRules, TR)
-		}
-	}
-}
-
-//获取部门信息
-func (c *Customer) GetDepartments(stype string, departments []map[string]interface{}) {
-	log.Println("开始获取部门信息...")
-	defer qu.Catch()
-	if len(departments) > 0 {
-		departMap := map[string]interface{}{}
-		for _, ds := range departments {
-			s_id := qu.ObjToString(ds["s_departid"])
-			if departMap[s_id] == nil {
-				departMap[s_id] = ds["s_depart_name"]
-			}
-		}
-		for k, v := range departMap {
-			DM := &Department{}
-			DM.DataLock = &sync.Mutex{}
-			DM.DepartmentData = map[string][]map[string]interface{}{}
-			DM.SaveDataMap = map[string]map[string]interface{}{}
-			id := k
-			name := qu.ObjToString(v)
-			DM.ID = id
-			DM.Name = name
-			DM.CustomerID = c.ID
-			dsArr := []map[string]interface{}{}
-			for _, ds := range departments {
-				s_id := qu.ObjToString(ds["s_departid"])
-				if s_id == k {
-					dsArr = append(dsArr, ds)
-				}
-			}
-			DM.GetSearchRules(c.ID, stype, c.IdRange, dsArr) //获取某个部门的所有规则
-			c.Departments = append(c.Departments, DM)
-			// qu.Debug("Departments---", DM.ID, DM.Name, DM.CustomerID, len(DM.Rules))
-		}
-	}
-}
-
-//获取数据
-func (c *Customer) GetData(stype string) {
-	log.Println("开始匹配数据...")
-	defer qu.Catch()
-	client := Es.GetEsConn()
-	defer Es.DestoryEsConn(client)
-	for _, dm := range c.Departments {
-		for _, sr := range dm.Rules {
-			//测试
-			// MgoDataTest(sr, dm, c)
-			// return
-
-			ch := make(chan bool, 10)
-			wg := &sync.WaitGroup{}
-			escount := Es.Count(Index, Itype, sr.EsQuery)
-			log.Println("index", Index, "type", Itype)
-			log.Println("查询总数:", escount, "规则ID:", sr.ID, "EsQuery:", sr.EsQuery)
-			if escount == 0 {
-				continue
-			}
-			//查询条件类型转换
-			var q es.Query
-			tmpQuery := es.BoolQuery{
-				QueryStrings: sr.EsQuery,
-			}
-			q = tmpQuery
-
-			//游标查询,index不支持别名,只能写索引库的名称
-			res, err := client.Scroll(Index).Query(q).Size(200).Do() //查询一条获取游标
-			if err == nil {
-				numDocs := 0
-				scrollId := res.ScrollId
-				for {
-					if scrollId == "" {
-						log.Println("ScrollId Is Error")
-						break
-					}
-					searchResult, err := client.Scroll(Index).Size(200).ScrollId(scrollId).Do() //查询
-					if err != nil {
-						if err.Error() == "EOS" { //迭代完毕
-							log.Println("Es Search Data Over:", err)
-						} else {
-							log.Println("Es Search Data Error:", err)
-						}
-						break
-					}
-					for _, hit := range searchResult.Hits.Hits {
-						//开始处理数据
-						wg.Add(1)
-						ch <- true
-						go func(tmpHit *es.SearchHit) {
-							defer func() {
-								<-ch
-								wg.Done()
-							}()
-							tmp := make(map[string]interface{})
-							if json.Unmarshal(*tmpHit.Source, &tmp) == nil {
-								if stype != "history" {
-									if !SkipData(tmp) {
-										qu.Debug("跳过该条数据,发布时间在入库时间7天之前,", qu.ObjToString(tmp["_id"]))
-										return
-									}
-								}
-								id := qu.ObjToString(tmp["_id"])
-								//亚信
-								if CheckBidOpenAppidMap[c.AppId] {
-									if tmp["bidopentime"] != nil {
-										bidopentime := qu.Int64All(tmp["bidopentime"])
-										comeintime := qu.Int64All(tmp["comeintime"])
-										if bidopentime-comeintime <= 7*24*60*60 {
-											qu.Debug("跳过该条数据,开标时间-入库时间<=7天,", id)
-											return
-										}
-									}
-								}
-								//河南移动,过滤掉中国移动采购网招标数据
-								if CheckBidHrefRuleIdMap[dm.ID] {
-									if strings.Contains(qu.ObjToString(tmp["href"]), "b2b.10086.cn") {
-										qu.Debug("跳过该条数据,公告原网址中包含 b2b.10086.cn,", id)
-										return
-									}
-								}
-								//
-								tmp["id"] = id //记录数据原有id
-								delete(tmp, "_id")
-								if sr.ExtFieldType == 2 {
-									findwinner := ""
-									s_winner := strings.Split(qu.ObjToString(tmp["s_winner"]), ",")
-									if len(s_winner) > 0 {
-										for i := 0; i < len(s_winner); i++ {
-											findwinners := strings.TrimSpace(s_winner[i])
-											if findwinners != "" {
-												for _, v := range Sysconfig["s_winner_filter"].([]interface{}) {
-													strings.ReplaceAll(findwinners, v.(string), "")
-												}
-												if findwinners != "" {
-													findwinner = findwinners
-													break
-												}
-											}
-										}
-									}
-									// findwinner := strings.TrimSpace(qu.ObjToString(tmp["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 != "" {
-												tmp["legal_person"] = legal_person
-											}
-											if email := qu.ObjToString(finddata["company_email"]); email != "" {
-												tmp["company_email"] = email
-											}
-											if phone := qu.ObjToString(finddata["company_phone"]); phone != "" {
-												tmp["company_phone"] = phone
-											}
-											//从最新年报中获取 中标单位联系电话、中标单位邮箱
-											// if annual_reports, ok := finddata["annual_reports"].(primitive.A); ok && len(annual_reports) > 0 {
-											// 	anreport := Sort_year_report(annual_reports)
-											// 	if len(anreport) > 0 {
-											// 		if email := qu.ObjToString(anreport["company_email"]); email != "" {
-											// 			tmp["company_email"] = email
-											// 		}
-											// 		if phone := qu.ObjToString(anreport["company_phone"]); phone != "" {
-											// 			tmp["company_phone"] = phone
-											// 		}
-											// 	}
-											// }
-										}
-									}
-								}
-								matchKey := map[string]bool{}     //记录所有匹配上的关键词
-								matchKeyType := map[string]bool{} //记录关键词对应的匹配方式
-								//先获取用到的所有字段值
-								fieldText := map[string]interface{}{}
-								for field, _ := range sr.Fields {
-									text := qu.ObjToString(tmp[field])
-									text = ProcessData(text) //处理文本(字母转大写,删除一些符号)
-									fieldText[field] = text
-								}
-								//清理词清理
-								for _, cwm := range sr.GCW.MatchType {
-									if text := qu.ObjToString(fieldText[cwm]); text != "" {
-										for _, gcw_reg := range sr.GCW.KeyReg {
-											text = gcw_reg.ReplaceAllString(text, "")
-										}
-										fieldText[cwm] = text
-									}
-								}
-								/*
-									因为要记录所有匹配上的关键词,所有优先匹配附加词,在匹配关键词
-								*/
-								//1.附加词匹配
-								IsMatch := false
-								// qu.Debug("sr.AW---", len(sr.AW))
-								for i, aw := range sr.AW {
-									// qu.Debug("-------------------------开始附加词匹配--------------------------")
-									IsMatchAddKey := RegMatch(fieldText, aw.MatchType, aw.KeyReg, nil, nil, false, true)
-									// qu.Debug(IsMatchAddKey, "------------------------------------------------------------")
-
-									//2.关键词匹配
-									if IsMatchAddKey {
-										kw := sr.KW[i]
-										// qu.Debug("-------------------------开始关键词匹配--------------------------")
-										IsMatchKey := RegMatch(fieldText, kw.MatchType, kw.KeyReg, matchKey, matchKeyType, true, false)
-										// qu.Debug(IsMatchKey, "------------------------------------------------------------")
-										if IsMatchKey {
-											IsMatch = true
-										}
-									}
-								}
-								if len(sr.AW) == 0 {
-									IsMatch = true
-								}
-								/*
-									到此已经匹配完数据
-								*/
-								qu.Debug("---------------------", id, IsMatch)
-								if IsMatch { //匹配成功,数据上新增规则id,matchKey,item并临时保存数据
-									// tmpMatchKey := MapDataToArr(matchKey)
-									tmpMatchKeyType := MapDataToArr(matchKeyType)
-									tmp["matchkey"] = GetMactchKeys(sr.Maths, tmp)
-									tmp["matchtype"] = strings.Join(tmpMatchKeyType, ",")
-									tmp["ruleid"] = sr.ID
-									tmp["rulename"] = sr.Name
-
-									//开始打标签
-									//qu.Debug("c.IsTagRule+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
-									if c.IsTagRule {
-										tagNameMap := map[string]bool{}
-										tagIdMap := map[string]bool{}
-										//qu.Debug("c.TagRules---", len(c.TagRules))
-										for _, tr := range c.TagRules {
-											if tr.DepartRuleIds[sr.ID] {
-												//先获取用到的所有字段值
-												for field, _ := range tr.Fields {
-													if fieldText[field] == nil { //补充fieldText
-														text := qu.ObjToString(tmp[field])
-														text = ProcessData(text) //处理文本(字母转大写,删除一些符号)
-														fieldText[field] = text
-													}
-												}
-												//qu.Debug("-------------------------开始排除词匹配--------------------------")
-												//qu.Debug("tr.NW---", len(tr.NW))
-												for j, tag_nw := range tr.NW { //排除词匹配
-													IsMatchNotKey := RegMatch(fieldText, tag_nw.MatchType, tag_nw.KeyReg, nil, nil, false, false)
-													//qu.Debug(IsMatchNotKey, "------------------------------------------------------------")
-													if !IsMatchNotKey { //排除词未匹配,匹配附加词关键词
-														if RegMatch(fieldText, tr.AW[j].MatchType, tr.AW[j].KeyReg, nil, nil, false, true) && RegMatch(fieldText, tr.KW[j].MatchType, tr.KW[j].KeyReg, nil, nil, false, false) {
-															tagname := tr.TagNames[j]
-															//qu.Debug("tagname-----", tagname)
-															tagNameMap[tagname] = true
-															tagIdMap[tr.ID] = true
-														}
-													}
-												}
-											}
-										}
-										//tagname
-										tagNameArr := MapDataToArr(tagNameMap)
-										tagIdArr := MapDataToArr(tagIdMap)
-										if len(tagNameArr) > 0 {
-											tmp["tagname"] = strings.Join(tagNameArr, ",")
-											if DisPackageAppidMap[c.AppId] {
-												tmp["buyer_type"] = strings.Join(tagNameArr, ",")
-											}
-											if c.PushModel == 2 {
-												tmp["item"] = strings.Join(tagNameArr, ",")
-											}
-											tmp["tagid"] = strings.Join(tagIdArr, ",")
-										}
-									}
-									//item
-									switch c.PushModel {
-									case 0:
-										tmp["item"] = "数据"
-									case 1:
-										tmp["item"] = dm.Name
-									case 2:
-										//tmp["item"] = sr.Name
-									case 3:
-										tmp["item"] = dm.Name + "_" + sr.Name
-									case 4:
-										tmp["item"] = sr.Name
-									}
-									//appid
-									tmp["appid"] = c.AppId
-									//部门名称
-									tmp["departname"] = dm.Name
-									tmp["departid"] = dm.ID
-									//存储数据
-									dm.DataLock.Lock()
-									//qu.Debug("tmp---", tmp)
-									tmpMap := map[string]interface{}{id: tmp}
-									dm.DepartmentData[sr.ID] = append(dm.DepartmentData[sr.ID], tmpMap)
-									dm.DataLock.Unlock()
-								} else {
-									// qu.Debug("------------", id, IsMatch)
-								}
-							}
-						}(hit)
-						numDocs += 1
-						if numDocs%500 == 0 {
-							log.Println("Current:", numDocs)
-						}
-					}
-					scrollId = searchResult.ScrollId
-				}
-				wg.Wait()
-				client.ClearScroll().ScrollId(scrollId).Do() //清理游标
-				log.Println("SearchRule ID", sr.ID, "Result Data Count:", numDocs)
-			} else {
-				log.Println("Customer:", c.Name, "Departmnet", dm.Name, "TagName", sr.Name, "Es Search Data Error,Tag ID:", sr.ID)
-			}
-		}
-	}
-}
-
-//数据去重
-func (c *Customer) RemoveRepeatData() {
-	log.Println("开始数据去重...")
-	defer qu.Catch()
-	for _, dm := range c.Departments {
-		for _, dataMapArr := range dm.DepartmentData { //一个部门的所有数据
-			for _, dataMap := range dataMapArr {
-				for dataId, data := range dataMap {
-					tmp := data.(map[string]interface{})
-					if c.PushModel == 0 { //全局模式所有数据去重
-						if c.SaveDataMap[dataId] == nil {
-							c.SaveDataMap[dataId] = tmp
-						} else { //数据重复
-							cus_history := c.SaveDataMap[dataId]
-							MergeData(cus_history, tmp, c.IsTagRule, true, c.PushModel) //合并字段
-							//c.SaveDataMap[dataId] = cus_history
-						}
-					} else if c.PushModel == 2 || c.PushModel == 3 { //部门内部去重
-						if dm.SaveDataMap[dataId] == nil {
-							dm.SaveDataMap[dataId] = tmp
-						} else { //数据重复
-							dm_history := dm.SaveDataMap[dataId]
-							MergeData(dm_history, tmp, c.IsTagRule, false, c.PushModel) //合并字段
-							//dm.SaveDataMap[dataId] = dm_history
-						}
-					} else if c.PushModel == 4 { //规则模式数据合并
-						//c.SaveDataArr = append(c.SaveDataArr, tmp)
-						if c.SaveDataMap[dataId] == nil {
-							tmp["itemdist"] = map[string]interface{}{qu.ObjToString(tmp["item"]): qu.ObjToString(tmp["matchkey"])}
-							c.SaveDataMap[dataId] = tmp
-						} else { //数据重复
-							dm_history := c.SaveDataMap[dataId]
-							MergeDatas(dm_history, tmp, c.IsTagRule, false) //合并字段
-							//dm.SaveDataMap[dataId] = dm_history
-						}
-					} else if c.PushModel == 1 { // 部门模式数据合并
-						if c.SaveDataMap[dataId] == nil {
-							tmp["itemdist"] = map[string]interface{}{qu.ObjToString(tmp["item"]): qu.ObjToString(tmp["matchkey"])}
-							c.SaveDataMap[dataId] = tmp
-						} else { //数据重复
-							dm_history := c.SaveDataMap[dataId]
-							MergeData(dm_history, tmp, c.IsTagRule, true, c.PushModel) //合并字段
-						}
-					}
-				}
-			}
-		}
-		//将部门数据清空
-		dm.DepartmentData = map[string][]map[string]interface{}{}
-	}
-}
-
-//组装保存数据
-func (c *Customer) AssembelAndSaveData(historyId string, isFilter, noticeFilter, dataTable, entId int) {
-	log.Println("开始组装保存数据...")
-	defer qu.Catch()
-	ch := make(chan bool, 10)
-	wg := &sync.WaitGroup{}
-	var datalock = sync.RWMutex{}
-	n := 0
-	if (c.PushModel == 0 || c.PushModel == 1 || c.PushModel == 4) && len(c.SaveDataMap) > 0 {
-		for _, tmp := range c.SaveDataMap {
-			wg.Add(1)
-			ch <- true
-			go func(data map[string]interface{}) {
-				datalock.Lock()
-				defer func() {
-					<-ch
-					datalock.Unlock()
-					wg.Done()
-				}()
-				AssembelSave(data, c.IsSearchHosp, c.IsSearchEnps, historyId, c.AppId, isFilter, noticeFilter, dataTable, entId)
-			}(tmp)
-			n++
-			if n%500 == 0 {
-				log.Println("Current:", n)
-			}
-		}
-		wg.Wait()
-	} else if c.PushModel == 2 || c.PushModel == 3 {
-		for _, dm := range c.Departments {
-			if len(dm.SaveDataMap) > 0 {
-				for _, tmp := range dm.SaveDataMap {
-					wg.Add(1)
-					ch <- true
-					go func(data map[string]interface{}) {
-						datalock.Lock()
-						defer func() {
-							<-ch
-							datalock.Unlock()
-							wg.Done()
-						}()
-						AssembelSave(data, c.IsSearchHosp, c.IsSearchEnps, historyId, c.AppId, isFilter, noticeFilter, dataTable, entId)
-					}(tmp)
-					n++
-					if n%500 == 0 {
-						log.Println("Current:", n)
-					}
-				}
-			}
-		}
-		wg.Wait()
-	} /*else if c.PushModel == 4 && len(c.SaveDataMap) > 0 {
-		for _, tmp := range c.SaveDataMap {
-			wg.Add(1)
-			ch <- true
-			go func(data map[string]interface{}) {
-				datalock.Lock()
-				defer func() {
-					<-ch
-					datalock.Unlock()
-					wg.Done()
-				}()
-				AssembelSave(data, c.IsSearchHosp, c.IsSearchEnps, historyId, c.AppId, isFilter, noticeFilter, dataTable, entId)
-			}(tmp)
-			n++
-			if n%500 == 0 {
-				log.Println("Current:", n)
-			}
-		}
-		wg.Wait()
-	}*/
-	log.Println("数据保存完毕...		Save Number:", n)
-}
-
-//获取用户所有规则
-func (d *Department) GetSearchRules(cid, stype string, idRange bson.M, searchRules []map[string]interface{}) {
-	defer qu.Catch()
-	if len(searchRules) > 0 {
-		for _, sr := range searchRules {
-			SR := &SearchRule{}
-			SR.Fields = make(map[string]interface{})
-			id := mongoutil.BsonIdToSId(sr["_id"])
-			name := qu.ObjToString(sr["s_name"])
-			SR.ID = id
-			SR.Name = name
-			SR.CustomerID = cid
-			SR.DepartmentID = d.ID
-			SR.ExtFieldType = qu.IntAll(sr["i_extfieldstype"])
-			//SR.RuleData = &sync.Map{}
-			esquery := qu.ObjToString(sr["s_esquery"])
-			clearKey := qu.ObjToString(sr["s_globalclearkey"])
-			clearKeyMatch := qu.ObjToString(sr["s_globalclearkeymatch"])
-
-			//获取es
-			if stype == "history" {
-				SR.EsQuery = esquery
-			} else {
-				SR.GetEs(d.Name, esquery, idRange)
-			}
-			//获取关键词和附加词
-			o_rule, ok := sr["o_rules"].([]interface{})
-			if !ok {
-				o_rule = []interface{}{}
-			}
-			o_rules := qu.ObjArrToMapArr(o_rule)
-			if len(o_rules) > 0 {
-				SR.GetKeyAddWord(o_rules)
-			}
-			//获取全局清理词
-			SR.GetClearWord(clearKey, clearKeyMatch)
-			d.Rules = append(d.Rules, SR)
-			//
-			if orules1, ok := sr["o_rules"].([]interface{}); ok {
-				for _, v := range orules1 {
-					orule, _ := v.(map[string]interface{})
-					SR.Maths = append(SR.Maths, map[string]string{
-						"s_matchkey": qu.ObjToString(orule["s_matchkey"]),
-						"s_keymatch": qu.ObjToString(orule["s_keymatch"]),
-					})
-				}
-			} else if orules2, ok := sr["o_rules"].([]map[string]interface{}); ok {
-				for _, v := range orules2 {
-					SR.Maths = append(SR.Maths, map[string]string{
-						"s_matchkey": qu.ObjToString(v["s_matchkey"]),
-						"s_keymatch": qu.ObjToString(v["s_keymatch"]),
-					})
-				}
-			}
-		}
-	}
-}
-
-//获取转换后的es语句
-func (sr *SearchRule) GetEs(department, esquery string, tmpRange bson.M) {
-	defer qu.Catch()
-	query := map[string]*QueryObjecct{}
-	if json.Unmarshal([]byte(esquery), &query) == nil {
-		qb := query["query"]
-		filter := qb.Filtered.Filter
-		if filter != nil && filter.Bool != nil { //有filter
-			index := -1 //记录range的位置
-			for i, m := range filter.Bool.Must {
-				mMap := m.(map[string]interface{})
-				if esRange, ok := mMap["range"].(map[string]interface{}); ok && esRange != nil { //有range
-					if esRange["publishtime"] != nil {
-						index = i
-						break
-					}
-				}
-			}
-			if index > -1 {
-				filter.Bool.Must[index] = tmpRange
-			} else {
-				filter.Bool.Must = append(filter.Bool.Must, tmpRange)
-			}
-		} else { //无filter则添加
-			bo := &BoolObject{}
-			bo.Must = append(bo.Must, tmpRange)
-			tmpFilter := &Filter{
-				Bool: bo,
-			}
-			qb.Filtered.Filter = tmpFilter
-		}
-		strquery, err := json.Marshal(query)
-		if err == nil {
-			sr.EsQuery = string(strquery)
-		} else {
-			log.Println("Department:", department, "Es Error,Tag ID:", sr.ID)
-		}
-	} else {
-		log.Println("Department:", department, "Es Error,Tag ID:", sr.ID)
-	}
-}
-
-//全局清理词处理
-func (sr *SearchRule) GetClearWord(key, match string) {
-	defer qu.Catch()
-	//匹配方式
-	cwmArr := []string{}
-	for _, mv := range strings.Split(match, ",") {
-		if field := qu.ObjToString(MatchType[mv]); field != "" {
-			cwmArr = append(cwmArr, field)
-			sr.Fields[field] = true
-		}
-	}
-	//清理词正则
-	cwkArr := []*regexp.Regexp{}
-	for _, kv := range strings.Split(key, ",") {
-		if LetterCase.MatchString(kv) { //字母转大写
-			kv = strings.ToUpper(kv)
-		}
-		reg := regexp.MustCompile(kv)
-		cwkArr = append(cwkArr, reg)
-	}
-	cw := &ClearWord{
-		KeyReg:    cwkArr,
-		MatchType: cwmArr,
-	}
-	sr.GCW = cw
-}
-
-//关键词、附加词处理
-func (sr *SearchRule) GetKeyAddWord(o_rules []map[string]interface{}) {
-	defer qu.Catch()
-	kw, aw, _, _ := GetNotkeyAndKeyAddWord(o_rules, sr.Fields, false)
-	sr.KW = kw
-	sr.AW = aw
-	//sr.Fields = fields
-}
-
-//排除词、关键词、附加词处理
-func (tr *TagRule) GetKeyAddNotKeyWord(o_list []map[string]interface{}) {
-	defer qu.Catch()
-	kw, aw, nkw, tagnames := GetNotkeyAndKeyAddWord(o_list, tr.Fields, true)
-	tr.NW = nkw
-	tr.KW = kw
-	tr.AW = aw
-	//tr.Fields = fields
-	tr.TagNames = tagnames
-}
-
-func GetMactchKeys(match []map[string]string, data map[string]interface{}) string {
-	keyWord := []string{}
-	for _, keys := range match {
-		types := keys["s_keymatch"]
-		key := keys["s_matchkey"]
-		if strings.Contains(types, "1") {
-			title := qu.ObjToString(data["title"])
-			keyWord = KeyWordToDatas(types, title, key, keyWord)
-		}
-		if strings.Contains(types, "2") {
-			detail := qu.ObjToString(data["detail"])
-			keyWord = KeyWordToDatas(types, detail, key, keyWord)
-		}
-		if strings.Contains(types, "3") {
-			purchasing := qu.ObjToString(data["purchasing"])
-			keyWord = KeyWordToDatas(types, purchasing, key, keyWord)
-		}
-		if strings.Contains(types, "4") {
-			filetext := qu.ObjToString(data["filetext"])
-			keyWord = KeyWordToDatas(types, filetext, key, keyWord)
-		}
-		if strings.Contains(types, "5") {
-			projectname := qu.ObjToString(data["projectname"])
-			keyWord = KeyWordToDatas(types, projectname, key, keyWord)
-		}
-		if strings.Contains(types, "6") || strings.Contains(types, "8") {
-			buyer := qu.ObjToString(data["buyer"])
-			keyWord = KeyWordToDatas(types, buyer, key, keyWord)
-		}
-		if strings.Contains(types, "7") || strings.Contains(types, "9") {
-			winner := qu.ObjToString(data["s_winner"])
-			keyWord = KeyWordToDatas(types, winner, key, keyWord)
-		}
-	}
-	keyMap := map[string]bool{}
-	keyArr := []string{}
-	for _, key := range keyWord {
-		keyMap[key] = true
-	}
-	for k, _ := range keyMap {
-		keyArr = append(keyArr, k)
-	}
-	return strings.Join(keyArr, ",")
-}
-
-func KeyWordToDatas(types, item, key string, keyWord []string) []string {
-	for _, mk := range strings.Split(key, ",") {
-		if strings.Contains(mk, "&&") {
-			arr := strings.Split(mk, "&&")
-			isok := true
-			for _, s := range arr {
-				if s != "" {
-					if !strings.Contains(strings.ToUpper(item), strings.ToUpper(s)) {
-						isok = false
-					}
-				}
-			}
-			if isok {
-				keyWord = append(keyWord, mk)
-			}
-		} else {
-			if strings.Contains(strings.ToUpper(item), strings.ToUpper(mk)) {
-				keyWord = append(keyWord, mk)
-			}
-		}
-	}
-	return keyWord
-}
-
-func TestMactchKeys(types, key string, data map[string]interface{}) string {
-	keyWord := []string{}
-	if strings.Contains(types, "1") {
-		title := qu.ObjToString(data["title"])
-		keyWord = KeyWordToDatas(types, title, key, keyWord)
-	}
-	if strings.Contains(types, "2") {
-		detail := qu.ObjToString(data["detail"])
-		keyWord = KeyWordToDatas(types, detail, key, keyWord)
-	}
-	if strings.Contains(types, "3") {
-		purchasing := qu.ObjToString(data["purchasing"])
-		keyWord = KeyWordToDatas(types, purchasing, key, keyWord)
-	}
-	if strings.Contains(types, "4") {
-		filetext := qu.ObjToString(data["filetext"])
-		keyWord = KeyWordToDatas(types, filetext, key, keyWord)
-	}
-	if strings.Contains(types, "5") {
-		projectname := qu.ObjToString(data["projectname"])
-		keyWord = KeyWordToDatas(types, projectname, key, keyWord)
-	}
-	if strings.Contains(types, "6") || strings.Contains(types, "8") {
-		buyer := qu.ObjToString(data["buyer"])
-		keyWord = KeyWordToDatas(types, buyer, key, keyWord)
-	}
-	if strings.Contains(types, "7") || strings.Contains(types, "9") {
-		winner := qu.ObjToString(data["s_winner"])
-		keyWord = KeyWordToDatas(types, winner, key, keyWord)
-	}
-	keyMap := map[string]bool{}
-	keyArr := []string{}
-	for _, key := range keyWord {
-		keyMap[key] = true
-	}
-	for k, _ := range keyMap {
-		keyArr = append(keyArr, k)
-	}
-	return strings.Join(keyArr, ",")
-}

+ 0 - 1699
src/history/util_history.go

@@ -1,1699 +0,0 @@
-package history
-
-import (
-	"fmt"
-	"log"
-	"os"
-	qu "qfw/util"
-	"qfw/util/mail"
-	"qfw/util/redis"
-	"regexp"
-	"strings"
-	"time"
-
-	. "util"
-	"util/mgodb"
-
-	"github.com/tealeg/xlsx"
-
-	"github.com/donnie4w/go-logger/logger"
-	// "go.mongodb.org/mongo-driver/bson/primitive"
-	"gopkg.in/mgo.v2/bson"
-)
-
-var LetterCase = regexp.MustCompile("[A-Za-z]")
-var LetterCase2 = regexp.MustCompile("[A-Za-z0-9]")
-
-// var FilteReg = regexp.MustCompile("[()(){}]*")
-var FilteReg = regexp.MustCompile("[{}]*")
-var Gmails []*mail.GmailAuth
-
-//匹配方式map
-var MatchType = map[string]interface{}{
-	"1": "title",
-	"2": "detail",
-	"3": "purchasing",
-	"4": "filetext",
-	"5": "projectname.name",
-	"6": "buyer",
-	"7": "s_winner",
-	"8": "buyer",
-	"9": "s_winner",
-}
-
-//加载排除词、附加词、关键词
-func GetNotkeyAndKeyAddWord(list []map[string]interface{}, fieldMap map[string]interface{}, hasNotKey bool) (kws []*KeyWord, aws []*AddWord, nkws []*NotKeyWord, tagnames []string) {
-	defer qu.Catch()
-	for _, rules := range list {
-		ruleMap := rules
-		if hasNotKey { //是否处理排除词
-			//排除词匹配方式
-			nkm := qu.ObjToString(ruleMap["s_notkeymatch"])
-			nkmArr := []string{}
-			for _, nv := range strings.Split(nkm, ",") {
-				if field := qu.ObjToString(MatchType[nv]); field != "" {
-					nkmArr = append(nkmArr, field)
-					fieldMap[field] = true
-				}
-			}
-			//排除词
-			nkw := &NotKeyWord{}
-			nkw.MatchType = nkmArr
-			notkeyword := qu.ObjToString(ruleMap["s_notkey"])
-			nkw_commaArr := strings.Split(notkeyword, ",")
-			nkw_reg := &Reg{}
-			for _, comma := range nkw_commaArr {
-				nkw_addArr := strings.Split(comma, "&&")
-				if len(nkw_addArr) == 1 { //,
-					tmp_nkw := nkw_addArr[0]
-					if tmp_nkw != "" {
-						cr := &CommonReg{}
-						cr.CsVal = tmp_nkw                   //记录原值
-						if LetterCase.MatchString(tmp_nkw) { //判断附加词中是否有英文
-							tmp_nkw = strings.ToUpper(tmp_nkw) //附加词中有英文全部转为大写
-							cr.IsLetter = true                 //含字母
-						}
-						tmp_nkw = strings.ReplaceAll(tmp_nkw, "(", `\(`)
-						tmp_nkw = strings.ReplaceAll(tmp_nkw, ")", `\)`)
-						cr.CrVal = regexp.MustCompile(tmp_nkw) //记录reg值
-						nkw_reg.CReg = append(nkw_reg.CReg, cr)
-					}
-				} else { //&&
-					arp := &AndRegPre{}
-					arp.CsVal = comma //记录原值
-					for _, and := range nkw_addArr {
-						if and != "" {
-							ar := &AndReg{}
-							if LetterCase.MatchString(and) { //判断附加词中是否有英文
-								and = strings.ToUpper(and) //附加词中有英文全部转为大写
-								ar.IsLetter = true         //含字母
-							}
-							and = strings.ReplaceAll(and, "(", `\(`)
-							and = strings.ReplaceAll(and, ")", `\)`)
-							ar.CrVal = regexp.MustCompile(and)
-							arp.AndRegKid = append(arp.AndRegKid, ar)
-						}
-					}
-					nkw_reg.AReg = append(nkw_reg.AReg, arp)
-				}
-			}
-			nkw.KeyReg = nkw_reg
-			nkws = append(nkws, nkw)
-			//获取每组关键词的标签名称
-			tagname := qu.ObjToString(ruleMap["s_name"])
-			tagnames = append(tagnames, tagname)
-		}
-		//附加词匹配方式
-		awm := qu.ObjToString(ruleMap["s_addkeymatch"])
-		awmArr := []string{}
-		for _, av := range strings.Split(awm, ",") {
-			if field := qu.ObjToString(MatchType[av]); field != "" {
-				awmArr = append(awmArr, field)
-				fieldMap[field] = true
-			}
-		}
-		//附加词
-		aw := &AddWord{}
-		aw.MatchType = awmArr
-		aw_reg := &Reg{}
-		addword := qu.ObjToString(ruleMap["s_addkey"])
-		aw_commaArr := strings.Split(addword, ",")
-		for _, comma := range aw_commaArr {
-			aw_addArr := strings.Split(comma, "&&")
-			if len(aw_addArr) == 1 { //,
-				tmp_aw := aw_addArr[0]
-				if tmp_aw != "" {
-					cr := &CommonReg{}
-					cr.CsVal = tmp_aw                   //记录原值
-					if LetterCase.MatchString(tmp_aw) { //判断附加词中是否有英文
-						tmp_aw = strings.ToUpper(tmp_aw) //附加词中有英文全部转为大写
-						cr.IsLetter = true               //含字母
-					}
-					tmp_aw = strings.ReplaceAll(tmp_aw, "(", `\(`)
-					tmp_aw = strings.ReplaceAll(tmp_aw, ")", `\)`)
-					cr.CrVal = regexp.MustCompile(tmp_aw) //记录reg值
-					aw_reg.CReg = append(aw_reg.CReg, cr)
-				}
-			} else { //&&
-				arp := &AndRegPre{}
-				arp.CsVal = comma //记录原值
-				for _, and := range aw_addArr {
-					if and != "" {
-						ar := &AndReg{}
-						if LetterCase.MatchString(and) { //判断附加词中是否有英文
-							and = strings.ToUpper(and) //附加词中有英文全部转为大写
-							ar.IsLetter = true         //含字母
-						}
-						and = strings.ReplaceAll(and, "(", `\(`)
-						and = strings.ReplaceAll(and, ")", `\)`)
-						ar.CrVal = regexp.MustCompile(and)
-						arp.AndRegKid = append(arp.AndRegKid, ar)
-					}
-				}
-				aw_reg.AReg = append(aw_reg.AReg, arp)
-			}
-		}
-		aw.KeyReg = aw_reg
-		aws = append(aws, aw)
-		//关键词匹配方式
-		kwm := qu.ObjToString(ruleMap["s_keymatch"])
-		kwmArr := []string{}
-		for _, kv := range strings.Split(kwm, ",") {
-			if field := qu.ObjToString(MatchType[kv]); field != "" {
-				kwmArr = append(kwmArr, field)
-				fieldMap[field] = true
-			}
-		}
-		//关键词
-		kw := &KeyWord{}
-		kw.MatchType = kwmArr
-		kw_reg := &Reg{}
-		keyword := qu.ObjToString(ruleMap["s_matchkey"])
-		kw_commaArr := strings.Split(keyword, ",")
-		for _, comma := range kw_commaArr {
-			kw_addArr := strings.Split(comma, "&&")
-			if len(kw_addArr) == 1 { //,
-				tmp_kw := kw_addArr[0]
-				if tmp_kw != "" {
-					cr := &CommonReg{}
-					cr.CsVal = tmp_kw //记录原值
-					if LetterCase.MatchString(tmp_kw) {
-						tmp_kw = strings.ToUpper(tmp_kw)
-						cr.IsLetter = true //含字母
-					}
-					tmp_kw = strings.ReplaceAll(tmp_kw, "(", `\(`)
-					tmp_kw = strings.ReplaceAll(tmp_kw, ")", `\)`)
-					cr.CrVal = regexp.MustCompile(tmp_kw) //记录reg值
-					kw_reg.CReg = append(kw_reg.CReg, cr)
-				}
-			} else { //&&
-				arp := &AndRegPre{}
-				arp.CsVal = comma //记录原值
-				for _, and := range kw_addArr {
-					if and != "" {
-						ar := &AndReg{}
-						if LetterCase.MatchString(and) {
-							and = strings.ToUpper(and) //附加词中有英文全部转为大写
-							ar.IsLetter = true         //含字母
-						}
-						and = strings.ReplaceAll(and, "(", `\(`)
-						and = strings.ReplaceAll(and, ")", `\)`)
-						ar.CrVal = regexp.MustCompile(and)
-						arp.AndRegKid = append(arp.AndRegKid, ar)
-					}
-				}
-				kw_reg.AReg = append(kw_reg.AReg, arp)
-			}
-		}
-		kw.KeyReg = kw_reg
-		kws = append(kws, kw)
-	}
-	return
-}
-
-//根据时间获取起始和终止ID范围
-func GetIdRange() (bson.M, bool) {
-	defer qu.Catch()
-	now := time.Now().Unix()
-	for { //当前时间一直向前推半小时,直到取到数据
-		now = now - 600 //10分钟前
-		endTime := time.Unix(now, 0)
-		endId := bson.NewObjectIdWithTime(endTime).Hex()
-		if endId > LatestId {
-			esquery := `{"query": {"bool": {"must": [{"range": {"id": {"gt": "` + LatestId + `" , "lte": "` + endId + `"}}}]}}, "sort": [{"comeintime": "desc"}]}`
-			if Es.Count(Index, Itype, esquery) > 0 { //有数据返回id区间
-				list := Es.Get(Index, Itype, esquery)
-				tmpRange := bson.M{
-					"range": bson.M{
-						"id": bson.M{
-							"lte": endId,
-							"gt":  LatestId,
-						},
-					},
-				}
-				LatestId = qu.ObjToString((*list)[0]["_id"])
-				return tmpRange, true
-			}
-		} else { //结束id不大于起始id 退出
-			logger.Debug("Search End ID Range Error. Sid:", LatestId, "Eid:", endId)
-			break
-		}
-	}
-	return bson.M{}, false
-	// now := time.Now()
-	// end := now.Unix() - int64(60*now.Minute()) - int64(now.Second())
-	// start := end - TaskTime*3600
-	// endTime := time.Unix(end, 0)
-	// startTime := time.Unix(start, 0)
-	// eid := bson.NewObjectIdWithTime(endTime).Hex()
-	// sid := bson.NewObjectIdWithTime(startTime).Hex()
-
-	// query := bson.M{
-	// 	"_id": bson.M{
-	// 		"$gt": mongodb.StringTOBsonId(LatestId),
-	// 	},
-	// }
-	// sort := bson.M{
-	// 	"_id": -1,
-	// }
-	// fields := bson.M{
-	// 	"_id": 1,
-	// }
-	// //查抽取表最后一个id
-	// extData, err := MgoExt.FindByLimit(ExtColl, query, sort, fields, 0, 1)
-	// if len(extData) == 1 && err == nil {
-	// 	endId := mongodb.BsonTOStringId(extData[0]["_id"])
-	// 	if endId > LatestId {
-	// 		tmpRange := bson.M{
-	// 			"range": bson.M{
-	// 				"id": bson.M{
-	// 					"lte": endId,
-	// 					"gt":  LatestId,
-	// 				},
-	// 			},
-	// 		}
-	// 		LatestId = endId
-	// 		return tmpRange, true
-	// 	} else {
-	// 		logger.Debug("ID Range Error,Start ID:", LatestId, "End ID:", endId)
-	// 		return bson.M{}, false
-	// 	}
-	// }
-	// logger.Debug("Search End ID No Data", query, "Error:", err)
-
-}
-
-//处理文本
-func ProcessData(text string) string {
-	defer qu.Catch()
-	text = strings.ToUpper(text)               //文本中的英文全转为大写
-	text = FilteReg.ReplaceAllString(text, "") //去除一些特殊符号
-	return text
-}
-
-//校验字母
-func CheckLetter(text string, reg *regexp.Regexp, indexArr [][]int) (flag bool) {
-	defer qu.Catch()
-	for _, tmpArr := range indexArr {
-		sIndex := tmpArr[0]
-		eIndex := tmpArr[1]
-		sbyte := ""
-		ebyte := ""
-		//log.Println("---", sIndex, eIndex)
-		if sIndex != 0 {
-			sbyte = text[sIndex-1 : sIndex]
-			if eIndex != len(text) { //BAIB
-				ebyte = text[eIndex : eIndex+1]
-			} /*else { //BAI
-
-			}*/
-		} else {
-			if eIndex != len(text) { //AIB
-				ebyte = text[eIndex : eIndex+1]
-			} /*else { //AI
-
-			}*/
-		}
-		//log.Println("sssss", "s:", sbyte, "e:", ebyte, LetterCase2.Match([]byte(sbyte)), LetterCase2.Match([]byte(ebyte)))
-		if !LetterCase2.Match([]byte(sbyte)) && !LetterCase2.Match([]byte(ebyte)) {
-			flag = true
-			break
-		}
-	}
-	return
-}
-
-//匹配
-func RegMatch(fieldText map[string]interface{}, matchType []string, matchReg *Reg, matchKey map[string]bool, matchKeyType map[string]bool, goon, isAddWord bool) (match bool) {
-	defer qu.Catch()
-	if len(matchType) == 0 && isAddWord { //特殊处理附加词为空的情况
-		match = true
-		return
-	}
-	for _, mt := range matchType {
-		if text := qu.ObjToString(fieldText[mt]); text != "" {
-			for _, cr := range matchReg.CReg { //逗号分隔,任意一个匹配表示匹配成功
-				if goon && matchKey[cr.CsVal] { //matchkey已存在不在匹配
-					continue
-				}
-				if indexArr := cr.CrVal.FindAllStringIndex(text, -1); len(indexArr) > 0 { //匹配成功
-					if !cr.IsLetter { //reg无字母
-						if goon {
-							matchKey[cr.CsVal] = true
-							matchKeyType[mt] = true
-							match = true
-						} else {
-							match = true
-							return
-						}
-					} else if cr.IsLetter && CheckLetter(text, cr.CrVal, indexArr) { //reg有字母,判断是否是包含关系(AAAIBBB or AI){//
-						if goon {
-							matchKey[cr.CsVal] = true
-							matchKeyType[mt] = true
-							match = true
-						} else {
-							match = true
-							return
-						}
-					}
-				}
-			}
-			for _, ar := range matchReg.AReg { //&&分割,所有匹配表示匹配成功
-				if goon && matchKey[ar.CsVal] {
-					continue
-				}
-				IsAregMatch := false
-				for n, arc := range ar.AndRegKid { //ar.AndRegKid若有值必不小于2
-					if indexArr := arc.CrVal.FindAllStringIndex(text, -1); len(indexArr) < 1 { //匹配失败(ar.AndRegKid中任意一个未匹配则失败)
-						break
-					} else { //匹配成功,判断字母
-						if arc.IsLetter && !CheckLetter(text, arc.CrVal, indexArr) { //reg有字母,判断是否是包含关系(AAAIBBB or AI)
-							break
-						}
-					}
-					if n == len(ar.AndRegKid)-1 {
-						IsAregMatch = true
-					}
-				}
-				if IsAregMatch {
-					if goon {
-						matchKey[ar.CsVal] = true
-						matchKeyType[mt] = true
-						match = true
-					} else {
-						match = true
-						return
-					}
-				}
-			}
-		}
-	}
-	return
-}
-
-//map数据转数组
-func MapDataToArr(tmpMap map[string]bool) (tmpArr []string) {
-	for tm, _ := range tmpMap {
-		tmpArr = append(tmpArr, tm)
-	}
-	return
-}
-
-//合并数据
-func MergeData(history, tmp map[string]interface{}, isTagRule, isDepartRmvRep bool, pushModel int) {
-	//matchkey、matchtype、ruleid均非空
-	matchkey1 := qu.ObjToString(history["matchkey"])
-	matchkey2 := qu.ObjToString(tmp["matchkey"])
-	history["matchkey"] = MergeField(matchkey1, matchkey2)
-
-	matchkeytype1 := qu.ObjToString(history["matchtype"])
-	matchkeytype2 := qu.ObjToString(tmp["matchtype"])
-	history["matchtype"] = MergeField(matchkeytype1, matchkeytype2)
-
-	ruleid1 := qu.ObjToString(history["ruleid"])
-	ruleid2 := qu.ObjToString(tmp["ruleid"])
-	history["ruleid"] = MergeField(ruleid1, ruleid2)
-
-	rulename1 := qu.ObjToString(history["rulename"])
-	rulename2 := qu.ObjToString(tmp["rulename"])
-	history["rulename"] = MergeField(rulename1, rulename2)
-
-	if isTagRule { //标签模式 tagname、tagid合并
-		tagname1 := qu.ObjToString(history["tagname"])
-		tagname2 := qu.ObjToString(tmp["tagname"])
-		if tagNameResult := MergeField(tagname1, tagname2); tagNameResult != "" {
-			history["tagname"] = tagNameResult
-		}
-
-		tagid1 := qu.ObjToString(history["tagid"])
-		tagid2 := qu.ObjToString(tmp["tagid"])
-		if tagIdResult := MergeField(tagid1, tagid2); tagIdResult != "" {
-			history["tagid"] = tagIdResult
-		}
-	}
-	if isDepartRmvRep { //全局模式 部门合并
-		departname1 := qu.ObjToString(history["departname"])
-		departname2 := qu.ObjToString(tmp["departname"])
-		history["departname"] = MergeField(departname1, departname2)
-		departid1 := qu.ObjToString(history["departid"])
-		departid2 := qu.ObjToString(tmp["departid"])
-		history["departid"] = MergeField(departid1, departid2)
-		if pushModel == 1 {
-			item1 := qu.ObjToString(history["item"])
-			item2 := qu.ObjToString(tmp["item"])
-			history["item"] = MergeField(item1, item2)
-			history["itemdist"].(map[string]interface{})[departname2] = matchkey2
-		}
-	}
-}
-
-func MergeDatas(history, tmp map[string]interface{}, isTagRule, isDepartRmvRep bool) {
-	//matchkey、matchtype、ruleid均非空
-	matchkey1 := qu.ObjToString(history["matchkey"])
-	matchkey2 := qu.ObjToString(tmp["matchkey"])
-	history["matchkey"] = MergeField(matchkey1, matchkey2)
-
-	matchkeytype1 := qu.ObjToString(history["matchtype"])
-	matchkeytype2 := qu.ObjToString(tmp["matchtype"])
-	history["matchtype"] = MergeField(matchkeytype1, matchkeytype2)
-
-	ruleid1 := qu.ObjToString(history["ruleid"])
-	ruleid2 := qu.ObjToString(tmp["ruleid"])
-	history["ruleid"] = MergeField(ruleid1, ruleid2)
-
-	rulename1 := qu.ObjToString(history["rulename"])
-	rulename2 := qu.ObjToString(tmp["rulename"])
-	history["rulename"] = MergeField(rulename1, rulename2)
-
-	item1 := qu.ObjToString(history["item"])
-	item2 := qu.ObjToString(tmp["item"])
-	history["item"] = MergeField(item1, item2)
-	history["itemdist"].(map[string]interface{})[item2] = matchkey2
-	qu.Debug("组装后的item:", history["item"], history["itemdist"])
-
-	if isTagRule { //标签模式 tagname、tagid合并
-		tagname1 := qu.ObjToString(history["tagname"])
-		tagname2 := qu.ObjToString(tmp["tagname"])
-		if tagNameResult := MergeField(tagname1, tagname2); tagNameResult != "" {
-			history["tagname"] = tagNameResult
-		}
-
-		tagid1 := qu.ObjToString(history["tagid"])
-		tagid2 := qu.ObjToString(tmp["tagid"])
-		if tagIdResult := MergeField(tagid1, tagid2); tagIdResult != "" {
-			history["tagid"] = tagIdResult
-		}
-	}
-	//if isDepartRmvRep { //全局模式 部门合并
-	departname1 := qu.ObjToString(history["departname"])
-	departname2 := qu.ObjToString(tmp["departname"])
-	history["departname"] = MergeField(departname1, departname2)
-	departid1 := qu.ObjToString(history["departid"])
-	departid2 := qu.ObjToString(tmp["departid"])
-	history["departid"] = MergeField(departid1, departid2)
-	//}
-}
-
-//合并字段
-func MergeField(str1, str2 string) string {
-	if str1 == "" {
-		return str2
-	} else if str2 == "" {
-		return str1
-	}
-	slice1 := strings.Split(str1, ",")
-	slice2 := strings.Split(str2, ",")
-	m := make(map[string]int)
-	for _, v := range slice1 {
-		m[v]++
-	}
-
-	for _, v := range slice2 {
-		times, _ := m[v]
-		if times == 0 {
-			slice1 = append(slice1, v)
-		}
-	}
-	return strings.Join(slice1, ",")
-}
-
-//补充信息并保存
-func AssembelSave(tmp map[string]interface{}, IsSearchHosp, IsSearchEnps bool, historyId, appid string, isFilter, noticeFilter, dataTable, entId int) {
-	if IsSearchHosp { //医院信息
-		SearchHospInfo(tmp)
-	}
-	if IsSearchEnps { //企业信息
-		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`
-	tmp["jybxhref"] = `https://www.jianyu360.cn/article/entservice/` + qu.SE3.EncodeString(id) + `.html?appid`
-	if publishtime, ok := tmp["publishtime"].(float64); ok && publishtime > 0 {
-		tmp["publishtime"] = qu.Int64All(publishtime)
-	}
-	if bidopentime, ok := tmp["bidopentime"].(float64); ok && bidopentime > 0 {
-		tmp["bidopentime"] = qu.Int64All(bidopentime)
-	}
-	//数据存到usermail,并且根据公告id去重
-	/*if dataTable == 1 && noticeFilter == 1 {
-		log.Println("datag", appid+"_"+qu.ObjToString(tmp["id"]))
-		isExists, err := redis.Exists("datag", appid+"_"+qu.ObjToString(tmp["id"]))
-		if err != nil {
-			log.Println("redis信息id判重出错 ", err)
-		} else if isExists {
-			log.Println("信息id重复 ", qu.ObjToString(tmp["id"]))
-			return
-		}
-	}*/
-	//存到mysql pushentniche表中,根据公告id去重
-	if dataTable == 2 {
-		isExist, err := redis.Exists("other", "entexportdata_"+qu.ObjToString(tmp["id"])+"_"+fmt.Sprintln(entId))
-		if err != nil {
-			log.Println("企业订阅数据导出redis判重失败")
-		} else if isExist {
-			log.Println("数据重复,id ", qu.ObjToString(tmp["id"]), "entid ", entId)
-			return
-		}
-	}
-	isOk := true
-	//if ProjectAppidMap[appid] {
-	//log.Println("补充信息中根据项目id去重。。。。")
-	//所有的数据都匹配项目id,是否去重根据isFilter
-	projectId := getProjectId(id)
-	if projectId != "" {
-		projectIds := strings.Split(projectId, ",")
-		tmp["projectId"] = projectId
-		if isFilter == 1 {
-			for _, v := range projectIds {
-				if _, ok := projectIdMap.Load(v); ok {
-					isOk = false
-				} else {
-					projectIdMap.Store(v, true)
-				}
-			}
-			if !isOk {
-				MgoSave.Save(SaveCollProject, tmp)
-			}
-			log.Println("项目id去重,项目id:", projectId, isOk)
-		}
-	} else {
-		tmp["projectId"] = ""
-	}
-
-	//河南移动/盈峰科技
-	/*if NeedProjectidAppidMap[appid] {
-		projectId := GetProjectId(id)
-		if projectId != "" {
-			//projectIds := strings.Split(projectId, ",")
-			//tmp["projectId"] = SE.EncodeString(projectId)
-			tmp["projectId"] = projectId
-		} else {
-			tmp["projectId"] = ""
-		}
-	}*/
-
-	// 标识第一条数据是否拆过包
-	var isDis bool = false
-	if DisPackageAppidMap[appid] {
-		querys := map[string]interface{}{
-			"_id": mongodb.StringTOBsonId(id),
-		}
-		s_winner := qu.ObjToString(tmp["s_winner"])
-		if s_winner != "" && len(strings.Split(s_winner, ",")) > 1 {
-			datas := MgoExtract.FindOne(ExtractColl, querys)
-			indexdata := []map[string]interface{}{}
-			index := 1
-			if datas != nil && len(datas) > 0 {
-				if (datas)["package"] != nil {
-					packages := (datas)["package"].(map[string]interface{})
-					for _, vv := range packages {
-						vs := vv.(map[string]interface{})
-						if qu.ObjToString(tmp["toptype"]) == "结果" || qu.ObjToString(tmp["toptype"]) == "其它" || qu.ObjToString(tmp["subtype"]) == "单一" {
-							if vs["winner"] != nil && qu.ObjToString(vs["winner"]) != "" {
-								winner := strings.Split(qu.ObjToString(vs["winner"]), ",")
-								for _, w := range winner {
-									// if MactchWinner(w) {
-									if index > 1 {
-										s_data := map[string]interface{}{}
-										for ks, vks := range tmp {
-											s_data[ks] = vks
-										}
-										delete(s_data, "legal_person")
-										delete(s_data, "company_address")
-										delete(s_data, "winner_credit_no")
-										delete(s_data, "company_email")
-										delete(s_data, "company_phone")
-										s_data["s_winner"] = w
-										SearchEnterpriseInfos(s_data, w)
-										GetWinnerType(w, s_data)
-										if s_data["winner_type"] == "集成商" {
-											continue
-										}
-										if vs["bidamount"] != nil {
-											s_data["bidamount"] = vs["bidamount"]
-										}
-										if vs["budget"] != nil {
-											s_data["budget"] = vs["budget"]
-										}
-										indexdata = append(indexdata, s_data)
-										log.Println("index", index, " ", id, " ", w)
-									} else {
-										tmp["s_winner"] = w
-										delete(tmp, "legal_person")
-										delete(tmp, "company_address")
-										delete(tmp, "winner_credit_no")
-										delete(tmp, "company_email")
-										delete(tmp, "company_phone")
-										SearchEnterpriseInfos(tmp, w)
-										GetWinnerType(w, tmp)
-										if vs["bidamount"] != nil {
-											tmp["bidamount"] = vs["bidamount"]
-										}
-										if vs["budget"] != nil {
-											tmp["budget"] = vs["budget"]
-										}
-										log.Println("index", index, " ", id, " ", w)
-										isDis = true
-									}
-									index++
-									// }
-								}
-							}
-						} else {
-							if vs["budget"] != nil {
-								s_data := map[string]interface{}{}
-								for ks, vks := range tmp {
-									s_data[ks] = vks
-								}
-								s_data["budget"] = vs["budget"]
-								indexdata = append(indexdata, s_data)
-							}
-						}
-					}
-				}
-			}
-			if index == 1 {
-				GetWinnerType(qu.ObjToString(tmp["s_winner"]), tmp)
-			}
-			if len(indexdata) > 0 {
-				for _, v := range indexdata {
-					MgoSaveCache <- v
-					xlsxArr = append(xlsxArr, v)
-					xlsxCount++
-				}
-			}
-		} else {
-			GetWinnerType(qu.ObjToString(tmp["s_winner"]), tmp)
-		}
-	}
-	if isDis && tmp["winner_type"] == "集成商" {
-		return
-	}
-	if noticeFilter == 1 && (dataTable == 0 || dataTable == 1) && isOk {
-		ok := checkBidId(appid, id, dataTable)
-		if !ok {
-			isOk = false
-			tmp["chongfu"] = id
-			MgoSave.Save(SaveCollbid, tmp)
-		}
-	}
-	//匹配公告附件
-	info := MgoBidding.FindOne(BiddingColl, map[string]interface{}{"_id": mongodb.StringTOBsonId(id)})
-	if info != nil && len(info) > 0 {
-		if info["projectinfo"] != nil {
-			projectInfo := qu.ObjToMap(info["projectinfo"])
-			if projectInfo != nil && len(*projectInfo) > 0 {
-				if (*projectInfo)["attachments"] != nil {
-					filesArr := []map[string]interface{}{}
-					fileUrl := qu.ObjToString(Sysconfig["file_downloadurl"])
-					if attachments, oks := (*projectInfo)["attachments"].(map[string]interface{}); oks {
-						for _, v := range attachments {
-							if atta, ok := v.(map[string]interface{}); ok {
-								if atta["fid"] != nil && qu.ObjToString(atta["fid"]) != "" {
-									fileMap := map[string]interface{}{
-										"filename": atta["filename"],
-										"url":      fileUrl + qu.ObjToString(atta["fid"]),
-									}
-									filesArr = append(filesArr, fileMap)
-								} else {
-									if atta["org_url"] != nil {
-										fileMap := map[string]interface{}{
-											"filename": atta["filename"],
-											"url":      qu.ObjToString(atta["org_url"]),
-										}
-										filesArr = append(filesArr, fileMap)
-									}
-								}
-							}
-						}
-					}
-					log.Println("查询附件结果:", id, "附件数量:", len(filesArr))
-					if len(filesArr) > 0 {
-						tmp["filehref"] = filesArr
-					}
-				}
-			}
-		}
-	}
-	if isOk {
-		if dataTable == 0 { //存到usermail_history
-			MgoSaveCache <- tmp
-		} else if dataTable == 1 { //存到usermail
-			//redis.Put("datag", appid+"_"+id, 1, -1)
-			MgoSaveUsermailCache <- tmp
-		} else if dataTable == 2 {
-			//存入mysql,并存到redis
-			b := saveMysqlPush(tmp, entId)
-			if !b {
-				return
-			}
-		}
-		//MgoSaveCache <- tmp
-		xlsxArr = append(xlsxArr, tmp)
-		xlsxCount++
-	}
-}
-
-//查询第三方医院等级信息和招标客户的社会征信代码
-func SearchHospInfo(tmp map[string]interface{}) {
-	if buyer := qu.ObjToString(tmp["buyer"]); buyer != "" { //buyer存在
-		//医院等级
-		hospData := MgoBuyer.FindOne(HospColl, bson.M{"name": buyer})
-		if hospData != nil && len(hospData) > 0 {
-			if rank := qu.ObjToString(hospData["rank"]); rank != "" {
-				tmp["rank"] = hospData["rank"]
-			}
-		}
-		//招标客户的社会征信代码
-		buyerEntData := MgoBuyer.FindOne(BuyerEntColl, bson.M{"company_name": buyer})
-		if buyerEntData != nil && len(buyerEntData) > 0 {
-			if credit_no := qu.ObjToString(buyerEntData["credit_no"]); credit_no != "" {
-				tmp["buyer_credit_no"] = credit_no
-			}
-		}
-	}
-}
-
-//查询第三方中标企业信息
-func SearchEnterpriseInfo(tmp map[string]interface{}) {
-	if s_winner := qu.ObjToString(tmp["s_winner"]); s_winner != "" { //buyer存在
-		winner := strings.Split(s_winner, ",")[0] //取第一个中标单位
-		data := MgoEnps.FindOne(EnpsColl, bson.M{"company_name": winner})
-		if data != nil && len(data) > 0 {
-			//中标单位联系人
-			if legal_person := qu.ObjToString(data["legal_person"]); legal_person != "" {
-				tmp["legal_person"] = legal_person
-			}
-			//中标单位的注册地址
-			if company_address := qu.ObjToString(data["company_address"]); company_address != "" {
-				tmp["company_address"] = company_address
-			}
-			//注册资金"capital" : "324 万","capital" : 124.8,
-			if data["capital"] != nil {
-				tmp["capital"] = qu.Float64All(data["capital"])
-			}
-			// if capital := qu.Float64All(data["capital"]); capital != "" {
-			// 	tmp["capital"] = capital
-			// if capitalStr, ok := data["capital"].(string); ok && capitalStr != "" {
-			// 	if capital := ObjToMoney(capitalStr); capital != 0 { //金额转换
-			// 		tmp["capital"] = capital
-			// 	}
-			// } else if capitalFloat, ok := data["capital"].(float64); ok && capitalFloat != 0 {
-			// 	tmp["capital"] = capitalFloat
-			// }
-			// }
-			//注册时间"establish_date" : ISODate("1949-10-01T00:00:00.000+0000")
-			if establish_date := qu.ObjToString(data["establish_date"]); establish_date != "" {
-				tmp["establish_date"] = establish_date
-			}
-			// if data["establish_date"] != nil {
-			// 	if establish_date, ok := data["establish_date"].(primitive.DateTime); ok {
-			// 		t := establish_date.Time()
-			// 		tmp["establish_date"] = qu.FormatDate(&t, qu.Date_Short_Layout)
-			// 	}
-			// }
-			//经营范围
-			if business_scope := qu.ObjToString(data["business_scope"]); business_scope != "" {
-				tmp["business_scope"] = business_scope
-			}
-			//中标单位的社会征信代码
-			if credit_no := qu.ObjToString(data["credit_no"]); credit_no != "" {
-				tmp["winner_credit_no"] = credit_no
-			}
-			//股东名单
-			if stock_name := qu.ObjToString(data["stock_name"]); stock_name != "" {
-				tmp["stock_name"] = stock_name
-			}
-			// if partners, ok := data["partners"].(primitive.A); ok && len(partners) > 0 {
-			// 	stock_name_arr := []string{}
-			// 	for _, partner := range partners {
-			// 		p := partner.(map[string]interface{})
-			// 		if stock_name := qu.ObjToString(p["stock_name"]); stock_name != "" {
-			// 			stock_name_arr = append(stock_name_arr, stock_name)
-			// 		}
-			// 	}
-			// 	if len(stock_name_arr) > 0 {
-			// 		tmp["stock_name"] = strings.Join(stock_name_arr, ",")
-			// 	}
-			// }
-			if email := qu.ObjToString(data["company_email"]); email != "" {
-				tmp["company_email"] = email
-			}
-			if phone := qu.ObjToString(data["company_phone"]); phone != "" {
-				tmp["company_phone"] = phone
-			}
-			//从最新年报中获取 中标单位联系电话、中标单位邮箱
-			// if annual_reports, ok := data["annual_reports"].(primitive.A); ok && len(annual_reports) > 0 {
-			// 	anreport := Sort_year_report(annual_reports)
-			// 	if len(anreport) > 0 {
-			// 		if email := qu.ObjToString(anreport["company_email"]); email != "" {
-			// 			tmp["company_email"] = email
-			// 		}
-			// 		if phone := qu.ObjToString(anreport["company_phone"]); phone != "" {
-			// 			tmp["company_phone"] = phone
-			// 		}
-			// 	}
-			// }
-		}
-	}
-}
-
-func SearchEnterpriseInfos(tmp map[string]interface{}, s_winner string) {
-	winner := strings.Split(s_winner, ",")[0] //取第一个中标单位
-	data := MgoEnps.FindOne(EnpsColl, bson.M{"company_name": winner})
-	if data != nil && len(data) > 0 {
-		//中标单位联系人
-		if legal_person := qu.ObjToString(data["legal_person"]); legal_person != "" {
-			tmp["legal_person"] = legal_person
-		}
-		//中标单位的注册地址
-		if company_address := qu.ObjToString(data["company_address"]); company_address != "" {
-			tmp["company_address"] = company_address
-		}
-		//注册资金"capital" : "324 万","capital" : 124.8,
-		if data["capital"] != nil {
-			tmp["capital"] = qu.Float64All(data["capital"])
-		}
-		//注册时间"establish_date" : ISODate("1949-10-01T00:00:00.000+0000")
-		if establish_date := qu.ObjToString(data["establish_date"]); establish_date != "" {
-			tmp["establish_date"] = establish_date
-		}
-		//经营范围
-		if business_scope := qu.ObjToString(data["business_scope"]); business_scope != "" {
-			tmp["business_scope"] = business_scope
-		}
-		//中标单位的社会征信代码
-		if credit_no := qu.ObjToString(data["credit_no"]); credit_no != "" {
-			tmp["winner_credit_no"] = credit_no
-		}
-		//股东名单
-		if stock_name := qu.ObjToString(data["stock_name"]); stock_name != "" {
-			tmp["stock_name"] = stock_name
-		}
-		if email := qu.ObjToString(data["company_email"]); email != "" {
-			tmp["company_email"] = email
-		}
-		if phone := qu.ObjToString(data["company_phone"]); phone != "" {
-			tmp["company_phone"] = phone
-		}
-	}
-}
-
-//数据存库
-func SaveMgo() {
-	log.Println("Mgo Save...")
-	arru := make([]map[string]interface{}, 500)
-	indexu := 0
-	counts := 0
-	for {
-		select {
-		case v := <-MgoSaveCache:
-			arru[indexu] = v
-			indexu++
-			counts++
-			if indexu == 500 {
-				SP <- true
-				go func(arru []map[string]interface{}) {
-					defer func() {
-						<-SP
-					}()
-					MgoSave.SaveBulk(SaveColl, arru...)
-				}(arru)
-				arru = make([]map[string]interface{}, 500)
-				indexu = 0
-			}
-		case <-time.After(1000 * time.Millisecond):
-			if indexu > 0 {
-				SP <- true
-				go func(arru []map[string]interface{}) {
-					defer func() {
-						<-SP
-					}()
-					MgoSave.SaveBulk(SaveColl, arru...)
-				}(arru[:indexu])
-				arru = make([]map[string]interface{}, 500)
-				indexu = 0
-			}
-		}
-	}
-}
-
-//数据存库
-func SaveUsermailMgo() {
-	log.Println("Mgo Save Usermail...")
-	arru := make([]map[string]interface{}, 500)
-	indexu := 0
-	counts := 0
-	for {
-		select {
-		case v := <-MgoSaveUsermailCache:
-			arru[indexu] = v
-			indexu++
-			counts++
-			if indexu == 500 {
-				SP <- true
-				go func(arru []map[string]interface{}) {
-					defer func() {
-						<-SP
-					}()
-					MgoSave.SaveBulk(SaveUserMail, arru...)
-				}(arru)
-				arru = make([]map[string]interface{}, 500)
-				indexu = 0
-			}
-		case <-time.After(1000 * time.Millisecond):
-			if indexu > 0 {
-				SP <- true
-				go func(arru []map[string]interface{}) {
-					defer func() {
-						<-SP
-					}()
-					MgoSave.SaveBulk(SaveUserMail, arru...)
-				}(arru[:indexu])
-				arru = make([]map[string]interface{}, 500)
-				indexu = 0
-			}
-		}
-	}
-}
-
-//打印初始化信息
-func PrintLog(cus *Customer) {
-	qu.Debug("----------------------打标签规则----------------------------")
-	for i, tr := range cus.TagRules {
-		qu.Debug("tagrules:", i, tr.ID, tr.Name, tr.CustomerId, tr.DepartRuleIds, tr.Fields)
-		for j, kw := range tr.KW {
-			qu.Debug("kw_matchkey---", kw.MatchType, len(kw.MatchType))
-			qu.Debug("------------CReg--------------")
-			for ck1, cr := range kw.KeyReg.CReg {
-				qu.Debug("CR---", ck1, cr.CrVal, cr.CsVal, cr.IsLetter)
-			}
-			qu.Debug("------------AReg--------------")
-			for ck1, ar := range kw.KeyReg.AReg {
-				qu.Debug("AR---", ck1, ar.CsVal)
-				for _, arc := range ar.AndRegKid {
-					qu.Debug("ARC---", arc.CrVal, arc.IsLetter)
-				}
-			}
-			qu.Debug("+++++++++++++++++++++AW++++++++++++++++++++++")
-			qu.Debug("aw_matchkey---", tr.AW[j].MatchType, len(tr.AW[j].MatchType))
-			qu.Debug("------------CReg--------------")
-			for ck2, cr := range tr.AW[j].KeyReg.CReg {
-				qu.Debug("CR---", ck2, cr.CrVal, cr.CsVal, cr.IsLetter)
-			}
-			qu.Debug("------------AReg--------------")
-			for ck2, ar := range tr.AW[j].KeyReg.AReg {
-				qu.Debug("AR---", ck2, ar.CsVal)
-				for _, arc := range ar.AndRegKid {
-					qu.Debug("ARC---", arc.CrVal, arc.IsLetter)
-				}
-			}
-			qu.Debug("++++++++++++++++++++NW+++++++++++++++++++++++")
-			qu.Debug("nw_matchkey---", tr.NW[j].MatchType, len(tr.NW[j].MatchType))
-			qu.Debug("------------CReg--------------")
-			for ck1, cr := range tr.NW[j].KeyReg.CReg {
-				qu.Debug("CR---", ck1, cr.CrVal, cr.CsVal, cr.IsLetter)
-			}
-			qu.Debug("------------AReg--------------")
-			for ck1, ar := range tr.NW[j].KeyReg.AReg {
-				qu.Debug("AR---", ck1, ar.CsVal)
-				for _, arc := range ar.AndRegKid {
-					qu.Debug("ARC---", arc.CrVal, arc.IsLetter)
-				}
-			}
-			qu.Debug("tagname-------------", tr.TagNames[j])
-			qu.Debug("-------------------------------------------------")
-		}
-	}
-	qu.Debug("----------------------查询规则----------------------------")
-	for i, dm := range cus.Departments {
-		qu.Debug("deparment:", i, dm.ID, dm.Name, dm.CustomerID)
-		for j, sr := range dm.Rules {
-			qu.Debug("ck---", j, sr.ID, sr.Name, sr.CustomerID, sr.DepartmentID, sr.GCW.KeyReg, len(sr.GCW.KeyReg), sr.GCW.MatchType, len(sr.GCW.MatchType), sr.Fields, len(sr.Fields), sr.EsQuery)
-			for j, kw := range sr.KW {
-				qu.Debug("kw_matchkey---", kw.MatchType, len(kw.MatchType))
-				qu.Debug("------------CReg--------------")
-				for ck1, cr := range kw.KeyReg.CReg {
-					qu.Debug("CR---", ck1, cr.CrVal, cr.CsVal, cr.IsLetter)
-				}
-				qu.Debug("------------AReg--------------")
-				for ck1, ar := range kw.KeyReg.AReg {
-					qu.Debug("AR---", ck1, ar.CsVal)
-					for _, arc := range ar.AndRegKid {
-						qu.Debug("ARC---", arc.CrVal, arc.IsLetter)
-					}
-				}
-				qu.Debug("+++++++++++++++++++++AW++++++++++++++++++++++")
-				qu.Debug("aw_matchkey---", sr.AW[j].MatchType, len(sr.AW[j].MatchType))
-				qu.Debug("------------CReg--------------")
-				for ck2, cr := range sr.AW[j].KeyReg.CReg {
-					qu.Debug("CR---", ck2, cr.CrVal, cr.CsVal, cr.IsLetter)
-				}
-				qu.Debug("------------AReg--------------")
-				for ck2, ar := range sr.AW[j].KeyReg.AReg {
-					qu.Debug("AR---", ck2, ar.CsVal)
-					for _, arc := range ar.AndRegKid {
-						qu.Debug("ARC---", arc.CrVal, arc.IsLetter)
-					}
-				}
-				qu.Debug("--------------------------------------------------------------------------------------")
-			}
-		}
-	}
-}
-
-//匹配
-func RegMatchTest(fieldText map[string]interface{}, matchType []string, matchReg *Reg, matchKey map[string]bool, matchKeyType map[string]bool, goon, isAddWord bool) (match bool) {
-	defer qu.Catch()
-	qu.Debug("matchType---", matchType)
-	if len(matchType) == 0 && isAddWord { //特殊处理附加词为空的情况
-		match = true
-		return
-	}
-	for _, mt := range matchType {
-		if text := qu.ObjToString(fieldText[mt]); text != "" {
-			qu.Debug("匹配方式---", mt, "text---", text)
-			qu.Debug("--------------开始查找逗号分隔----------------", len(matchReg.CReg))
-			for i, cr := range matchReg.CReg { //逗号分隔,任意一个匹配表示匹配成功
-				qu.Debug("iiii---", i, cr.CrVal, goon, matchKey)
-				if goon && matchKey[cr.CsVal] { //matchkey已存在不在匹配
-					continue
-				}
-				if indexArr := cr.CrVal.FindAllStringIndex(text, -1); len(indexArr) > 0 { //匹配成功
-					if !cr.IsLetter { //reg无字母
-						qu.Debug("goon---", goon)
-						if goon {
-							qu.Debug("key++++++++++ ++++++++++", cr.CsVal)
-							matchKey[cr.CsVal] = true
-							matchKeyType[mt] = true
-							match = true
-						} else {
-							match = true
-							return
-						}
-					} else if cr.IsLetter && CheckLetter(text, cr.CrVal, indexArr) { //reg有字母,判断是否是包含关系(AAAIBBB or AI){//
-						qu.Debug("goon---", goon)
-						if goon {
-							qu.Debug("key++++++++++++++++++++", cr.CsVal)
-							matchKey[cr.CsVal] = true
-							matchKeyType[mt] = true
-							match = true
-						} else {
-							match = true
-							return
-						}
-					}
-				}
-			}
-			qu.Debug("--------------开始查找&&分隔----------------", len(matchReg.AReg))
-			for j, ar := range matchReg.AReg { //&&分割,所有匹配表示匹配成功
-				qu.Debug("jjjj---", j, ar.CsVal, goon, matchKey)
-				if goon && matchKey[ar.CsVal] {
-					continue
-				}
-				IsAregMatch := false
-				qu.Debug("ar.AndRegKid---", j, ar.AndRegKid, len(ar.AndRegKid))
-				for n, arc := range ar.AndRegKid { //ar.AndRegKid若有值必不小于2
-					qu.Debug("nnnn---", n, arc.CrVal, arc.IsLetter)
-					if indexArr := arc.CrVal.FindAllStringIndex(text, -1); len(indexArr) < 1 { //匹配失败(ar.AndRegKid中任意一个未匹配则失败)
-						break
-					} else { //匹配成功,判断字母
-						if arc.IsLetter && !CheckLetter(text, arc.CrVal, indexArr) { //reg有字母,判断是否是包含关系(AAAIBBB or AI)
-							break
-						}
-					}
-					if n == len(ar.AndRegKid)-1 {
-						IsAregMatch = true
-					}
-				}
-				qu.Debug("IsAregMatch---", IsAregMatch)
-				if IsAregMatch {
-					qu.Debug("goon---", goon)
-					if goon {
-						qu.Debug("key++++++++++++++++++++", ar.CsVal)
-						matchKey[ar.CsVal] = true
-						matchKeyType[mt] = true
-						match = true
-					} else {
-						match = true
-						return
-					}
-				}
-			}
-		}
-	}
-	return
-}
-
-//发布时间不在范围内(7天)不要这条数据
-func SkipData(tmp map[string]interface{}) bool {
-	comeIn := qu.Int64All(tmp["comeintime"])
-	if qu.Int64All(tmp["publishtime"]) > (comeIn - 7*24*60*60) {
-		return true
-	}
-	return false
-}
-
-func GetXlsxs(mMap []map[string]interface{}, fn, email, id string, isfile, isHenanMobile, isfilehref bool, appid string) {
-	if id != "" {
-		query := bson.M{
-			"_id": bson.ObjectIdHex(id),
-		}
-		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())
-			}
-			style := xlsx.NewStyle()
-			style.Font.Size = 12
-			style.Font.Bold = true
-			style.Alignment.Vertical = "center"
-			style.Alignment.Horizontal = "center"
-			if dataType == 1 {
-				sh := xf.Sheets[0]
-				if isfile {
-					cell := sh.Rows[0].AddCell()
-					cell.SetValue("附件")
-					cell.SetStyle(style)
-				}
-				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["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"]))
-					} else {
-						row.AddCell()
-					}
-					row.AddCell().SetValue(v["projectname"])
-					row.AddCell().SetValue(v["detail"])
-					row.AddCell().SetValue(v["jybxhref"])
-					ids := SE.EncodeString(qu.ObjToString(v["id"]))
-					row.AddCell().SetValue(ids)
-					if isfile {
-						row.AddCell().SetValue(v["filetext"])
-					}
-				}
-				xf.Sheets = xf.Sheets[0:1]
-			} else if dataType == 2 {
-
-				sh := xf.Sheets[1]
-				if isfile {
-					cell := sh.Rows[0].AddCell()
-					cell.SetValue("附件")
-					cell.SetStyle(style)
-				}
-				if isfilehref {
-					cell := sh.Rows[0].AddCell()
-					cell.SetValue("附件链接")
-					cell.SetStyle(style)
-				}
-				for _, 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["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["jybxhref"])
-					row.AddCell().SetValue(v["projectname"])
-					row.AddCell().SetValue(v["projectcode"])
-					row.AddCell().SetValue(v["projectscope"])
-					if v["budget"] != nil {
-						row.AddCell().SetFloat(qu.Float64All(v["budget"]))
-					} else {
-						row.AddCell()
-					}
-					if v["bidamount"] != nil {
-						row.AddCell().SetFloat(qu.Float64All(v["bidamount"]))
-					} 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["s_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"])
-					ids := SE.EncodeString(qu.ObjToString(v["id"]))
-					row.AddCell().SetValue(ids)
-					if isfile {
-						row.AddCell().SetValue(v["filetext"])
-					}
-					if isfilehref {
-						if v["filehref"] != nil {
-							if filelist, ok := v["filehref"].([]map[string]interface{}); ok {
-								index := 0
-								for _, url := range filelist {
-									//if urlMap, ok := url.(map[string]interface{}); ok {
-									if url["url"] != nil {
-										style1 := xlsx.NewStyle()
-										style1.Font.Name = "宋体"
-										style1.Font.Size = 12
-										style1.Font.Bold = false
-										if FilterFilehrefAppidMap[appid] {
-											if strings.Contains(url["url"].(string), "jy-datafile.oss-cn-beijing.aliyuncs.com") {
-												cell := row.AddCell()
-												cell.SetStyle(style1)
-												cell.SetValue(url["url"])
-												index++
-											}
-										} else {
-											cell := row.AddCell()
-											cell.SetStyle(style1)
-											cell.SetValue(url["url"])
-											index++
-										}
-									}
-									//}
-								}
-							}
-						}
-					}
-				}
-				xf.Sheets = xf.Sheets[1:2]
-			} else if dataType == 3 {
-				sh := xf.Sheets[2]
-				if isfile {
-					cell := sh.Rows[0].AddCell()
-					cell.SetValue("附件")
-					cell.SetStyle(style)
-				}
-				for _, v := range mMap {
-					row := sh.AddRow()
-					// row.AddCell().SetInt(i + 1)
-					row.AddCell().SetValue(v["departname"])
-					row.AddCell().SetValue(v["rulename"])
-					row.AddCell().SetValue(v["matchkey"])
-					row.AddCell().SetValue(v["toptype"])
-					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"]))
-					} else {
-						row.AddCell()
-					}
-					row.AddCell().SetValue(v["purchasing"])
-					row.AddCell().SetValue(v["buyer"])
-					row.AddCell().SetValue(v["buyerclass"])
-					row.AddCell().SetValue(v["buyerperson"])
-					row.AddCell().SetValue(v["buyertel"])
-					row.AddCell().SetValue(v["buyer_credit_no"])
-					row.AddCell().SetValue(v["rank"])
-					row.AddCell().SetValue(v["s_winner"])
-					row.AddCell().SetValue(v["legal_person"])
-					row.AddCell().SetValue(v["company_phone"])
-					row.AddCell().SetValue(v["winner_credit_no"])
-					row.AddCell().SetValue(v["company_address"])
-					row.AddCell().SetValue(v["capital"])
-					row.AddCell().SetValue(v["establish_date"])
-					row.AddCell().SetValue(v["business_scope"])
-					row.AddCell().SetValue(v["stock_name"])
-					ids := SE.EncodeString(qu.ObjToString(v["id"]))
-					row.AddCell().SetValue(ids)
-					if isfile {
-						row.AddCell().SetValue(v["filetext"])
-					}
-				}
-				xf.Sheets = xf.Sheets[2:3]
-			} else if dataType == 4 {
-				sh := xf.Sheets[3]
-				for _, v := range mMap {
-					row := sh.AddRow()
-					row.AddCell().SetValue(v["departname"])
-					row.AddCell().SetValue(v["rulename"])
-					row.AddCell().SetValue(v["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["jybxhref"])
-					row.AddCell().SetValue(v["projectname"])
-					row.AddCell().SetValue(v["projectcode"])
-					row.AddCell().SetValue(v["projectscope"])
-					if v["budget"] != nil {
-						row.AddCell().SetFloat(qu.Float64All(v["budget"]))
-					} else {
-						row.AddCell()
-					}
-					if v["bidamount"] != nil {
-						row.AddCell().SetFloat(qu.Float64All(v["bidamount"]))
-					} 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"])
-					ids := SE.EncodeString(qu.ObjToString(v["id"]))
-					row.AddCell().SetValue(ids)
-				}
-				xf.Sheets = xf.Sheets[3:4]
-			} else if dataType == 5 {
-				sh := xf.Sheets[4]
-				//if isfile {
-				//	cell := sh.Rows[0].AddCell()
-				//	cell.SetValue("附件")
-				//	cell.SetStyle(style)
-				//}
-				for _, v := range mMap {
-					row := sh.AddRow()
-					// row.AddCell().SetInt(i + 1)
-					row.AddCell().SetValue(v["matchkey"])    //信息匹配词
-					row.AddCell().SetValue(v["city"])        //城市
-					row.AddCell().SetValue(v["district"])    //县区
-					row.AddCell().SetValue(v["projectname"]) //项目名称
-					row.AddCell().SetValue(v["buyer"])       //采购单位
-					row.AddCell().SetValue(v["buyer_type"])  //采购单位类别---私有标签tagname
-					if v["bidamount"] != nil {               //中标金额
-						row.AddCell().SetFloat(qu.Float64All(v["bidamount"]))
-					} else {
-						row.AddCell()
-					}
-					if v["budget"] != nil { //预算
-						row.AddCell().SetFloat(qu.Float64All(v["budget"]))
-					} else {
-						row.AddCell()
-					}
-					if v["publishtime"] != nil { //公告发布时间
-						row.AddCell().SetValue(time.Unix(qu.Int64All(v["publishtime"]), 0).Format("2006-01-02"))
-					} 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["s_winner"])           //中标单位
-					row.AddCell().SetValue(v["winner_type"])        //中标模式--移动、电信、联通
-					row.AddCell().SetValue(v["title"])              //公告标题
-					row.AddCell().SetValue(v["subtype"])            //公告类别
-					row.AddCell().SetValue(v["area"])               //省份
-					row.AddCell().SetValue(v["projectcode"])        //项目编号
-					row.AddCell().SetValue(v["projectscope"])       //项目范围
-					row.AddCell().SetValue(v["agency"])             //招标代理机构
-					row.AddCell().SetValue(v["detail"])             //公告内容
-					row.AddCell().SetValue(v["href"])               //公告地址
-					row.AddCell().SetValue(v["buyerperson"])        //采购单位联系人
-					row.AddCell().SetValue(v["buyertel"])           //采购单位联系电话
-					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"])      //中标企业邮箱
-					ids := SE.EncodeString(qu.ObjToString(v["id"])) //唯一标识
-					row.AddCell().SetValue(ids)
-					row.AddCell().SetValue(SE.EncodeString(qu.ObjToString(v["projectId"]))) //项目标识
-					row.AddCell().SetValue(v["jybxhref"])                                   //剑鱼标讯地址
-
-					//row.AddCell().SetValue(v["projectcode"])
-				}
-				xf.Sheets = xf.Sheets[4:5]
-			}
-			xf.Sheets[0].Name = "详细数据"
-			//生文件
-			//t := strconv.FormatInt(time.Now().Unix(), 10)
-			t := time.Now().Format("20060102")
-			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"
-			fname := fmt.Sprintf("%s_%s_%s.xlsx", fn, t, qu.GetRandom(4))
-			log.Println("fname", fname)
-			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
-					}
-				}
-			}
-		}
-	}
-}
-
-func PathExists(path string) (bool, error) {
-	_, err := os.Stat(path)
-	if err == nil {
-		return true, nil
-	}
-	if os.IsNotExist(err) {
-		return false, nil
-	}
-	return false, err
-}
-
-func getProjectId(id string) string {
-	query := `{"query": {"bool": {"must": [{"term": {"projectset.ids": "%s"}}],"must_not": [],"should": []}}}`
-	querys := fmt.Sprintf(query, id)
-	projectId := ""
-	projectIdArr := []string{}
-	data := Es.Get("projectset", "projectset", querys)
-	if data != nil && *data != nil && len(*data) > 0 {
-		for _, v := range *data {
-			projectIdArr = append(projectIdArr, qu.ObjToString(v["_id"]))
-		}
-		projectId = strings.Join(projectIdArr, ",")
-		log.Println("projectId", projectId)
-	}
-	return projectId
-}
-
-func InitProjectId(appid string) {
-	session := MgoSave.GetMgoConn()
-	count := 0
-	defer func() {
-		MgoSave.DestoryMongoConn(session)
-		log.Printf("本次共取到%d个projectId\n", count)
-	}()
-	save := Sysconfig["save"].(map[string]interface{})
-	query := map[string]interface{}{"appid": appid}
-	field := map[string]interface{}{"projectId": 1}
-	iter := session.DB(qu.ObjToString(save["db"])).C(SaveColl).Find(query).Select(field).Sort("_id").Iter()
-	thisData := map[string]interface{}{}
-	for {
-		if !iter.Next(&thisData) {
-			break
-		}
-		projectId := qu.ObjToString(thisData["projectId"])
-		if projectId != "" {
-			projectIdMap.Store(projectId, true)
-			count++
-		}
-		thisData = map[string]interface{}{}
-	}
-}
-
-func InitUsermailProjectId(appid string) {
-	session := MgoCus.GetMgoConn()
-	count := 0
-	defer func() {
-		MgoCus.DestoryMongoConn(session)
-		log.Printf("本次共取到%d个projectId\n", count)
-	}()
-	customer := Sysconfig["customer"].(map[string]interface{})
-	query := map[string]interface{}{"appid": appid}
-	field := map[string]interface{}{"projectId": 1}
-	iter := session.DB(qu.ObjToString(customer["dbname"])).C(SaveUserMail).Find(query).Select(field).Sort("_id").Iter()
-	thisData := map[string]interface{}{}
-	for {
-		if !iter.Next(&thisData) {
-			break
-		}
-		projectId := qu.ObjToString(thisData["projectId"])
-		if projectId != "" {
-			projectIdMap.Store(projectId, true)
-			count++
-		}
-		thisData = map[string]interface{}{}
-	}
-}
-
-func checkBidId(appid, id string, dataTable int) bool {
-	isOk := true
-	if dataTable == 1 {
-		count := MgoCus.Count(SaveUserMail, bson.M{"appid": appid, "id": id})
-		if count > 0 {
-			log.Println("用户 ", appid, " 在 ", SaveUserMail, " 中找到重复公告id ", id)
-			isOk = false
-		}
-	}
-	if dataTable == 0 {
-		count := Mgo.Count(SaveColl, bson.M{"appid": appid, "id": id})
-		if count > 0 {
-			log.Println("用户 ", appid, " 在 ", SaveColl, " 中找到重复公告id ", id)
-			isOk = false
-		}
-	}
-	return isOk
-}
-
-func GetWinnerType(s_winner string, v map[string]interface{}) {
-	if s_winner != "" {
-		winnerModel := []string{}
-		for _, vw := range strings.Split(s_winner, ",") {
-			j := 1
-			for _, vs := range Sysconfig["dis_package_config"].(map[string]interface{}) {
-				vvs := vs.(map[string]interface{})
-				keyWord := qu.ObjToString(vvs["keyWord"])
-				exclued := qu.ObjToString(vvs["exclued"])
-				name := qu.ObjToString(vvs["name"])
-				isMatch := false
-				for _, key := range strings.Split(keyWord, ",") {
-					if strings.Contains(vw, key) {
-						isMatch = true
-						if exclued != "" {
-							for _, keys := range strings.Split(exclued, ",") {
-								if strings.Contains(vw, keys) {
-									isMatch = false
-								}
-							}
-						}
-					}
-				}
-				if isMatch {
-					winnerModel = append(winnerModel, name)
-					//v["winner_type"] = name
-					break
-				} else {
-					if j == len(Sysconfig["dis_package_config"].(map[string]interface{})) {
-						winnerModel = append(winnerModel, "集成商")
-					}
-				}
-				j++
-			}
-		}
-		wname := ""
-		for key, val := range winnerModel {
-			if key < len(winnerModel)-1 {
-				wname += val + ","
-			} else {
-				wname += val
-			}
-		}
-		v["winner_type"] = wname
-	} else {
-		v["winner_type"] = ""
-	}
-}
-
-//历史数据存到mysql pushentniche推送表中
-func saveMysqlPush(tmp map[string]interface{}, entId int) bool {
-	saveMap := map[string]interface{}{}
-	saveMap["entid"] = entId
-	infoid := qu.ObjToString(tmp["id"])
-	saveMap["infoid"] = infoid
-	matchkeys := qu.ObjToString(tmp["matchkey"])
-	if matchkeys != "" {
-		matchkeysStr := ""
-		matchkeysArr := strings.Split(matchkeys, ",")
-		for i, val := range matchkeysArr {
-			if i < len(matchkeysArr)-1 {
-				matchkeysStr += val + " "
-			} else {
-				matchkeysStr += val
-			}
-		}
-		saveMap["matchkeys"] = matchkeysStr
-	}
-	area := qu.ObjToString(tmp["area"])
-	city := qu.ObjToString(tmp["city"])
-	buyerClass := qu.ObjToString(tmp["buyerclass"])
-	toptype := qu.ObjToString(tmp["toptype"])
-	subtype := qu.ObjToString(tmp["subtype"])
-	saveMap["deptid"] = 0
-	saveMap["userid"] = 0
-	saveMap["date"] = time.Now().Unix()
-	if area != "" {
-		saveMap["area"] = qu.IntAll(ProvinceMap[area])
-	}
-	if city != "" {
-		saveMap["city"] = qu.IntAll(ProvinceMap[city])
-	}
-	if buyerClass != "" {
-		saveMap["buyerclass"] = qu.IntAll(BuryClassType[buyerClass])
-	}
-	if toptype != "" {
-		saveMap["toptype"] = qu.IntAll(BuryClassType[toptype])
-	}
-	if subtype != "" {
-		saveMap["subtype"] = qu.IntAll(BuryClassType[subtype])
-	}
-	b := JyMysql.Insert("pushentniche", saveMap)
-	if b <= 0 {
-		log.Println("数据插入pushentniche表失败,id ", qu.ObjToString(tmp["id"]), "entid ", entId)
-		return false
-	} else {
-		redis.Put("other", "entexportdata_"+infoid+"_"+fmt.Sprintln(entId), 1, -1)
-	}
-	return true
-}

+ 2 - 45
src/main.go

@@ -4,11 +4,11 @@ import (
 	"client"
 	_ "filter"
 	"front"
-	"history"
+
+	// "history"
 
 	"log"
 	qu "qfw/util"
-	"qfw/util/mail"
 	"recharge"
 	"service"
 	"time"
@@ -38,55 +38,12 @@ func init() {
 	xweb.AddAction(&service.Private{})
 	xweb.AddAction(&service.Customer{})
 	xweb.AddAction(&service.SecondPush{})
-
-	xweb.AddAction(&history.HistoryData{})
 	xweb.AddAction(&client.Client{})
 	xweb.AddAction(&client.OwnTag{})
 	xweb.AddAction(&client.CustomerRule{})
 	xweb.AddAction(&recharge.EntRecharge{})
 	xweb.RootApp().AppConfig.SessionTimeout = 7 * 24 * time.Hour
 	xweb.RootApp().Logger.SetOutputLevel(1)
-	go history.SaveMgo()
-	go history.SaveUsermailMgo()
-	mails, _ := util.Sysconfig["mail"].([]interface{})
-	if len(mails) > 0 {
-		history.Gmails = make([]*mail.GmailAuth, len(mails))
-		for k, v1 := range mails {
-			v, _ := v1.(map[string]interface{})
-			history.Gmails[k] = &mail.GmailAuth{
-				SmtpHost: qu.ObjToString(v["addr"]),
-				SmtpPort: qu.IntAll(v["port"]),
-				User:     qu.ObjToString(v["user"]),
-				Pwd:      qu.ObjToString(v["pwd"]),
-				//PoolSize: v.MailPollSize,
-				//ReTry:    v.MailReTry,
-			}
-		}
-	}
-	for _, v := range util.Sysconfig["project_appid"].([]interface{}) {
-		history.ProjectAppidMap[v.(string)] = true
-	}
-	for _, s := range util.Sysconfig["filetext_appid"].([]interface{}) {
-		history.FileTextAppidMap[s.(string)] = true
-	}
-	for _, s := range util.Sysconfig["checkbidopen_appid"].([]interface{}) {
-		history.CheckBidOpenAppidMap[s.(string)] = true
-	}
-	for _, v := range util.Sysconfig["checkbidhref_ruleid"].([]interface{}) {
-		history.CheckBidHrefRuleIdMap[v.(string)] = true
-	}
-	for _, v := range util.Sysconfig["dis_package_appid"].([]interface{}) {
-		history.DisPackageAppidMap[v.(string)] = true
-	}
-	for _, v := range util.Sysconfig["need_projectid_appid"].([]interface{}) {
-		history.NeedProjectidAppidMap[v.(string)] = true
-	}
-	for _, v := range util.Sysconfig["filter_filehref_appid"].([]interface{}) {
-		history.FilterFilehrefAppidMap[v.(string)] = true
-	}
-	for _, v := range util.Sysconfig["need_filehref_appid"].([]interface{}) {
-		history.NeedFilehrefAppidMap[v.(string)] = true
-	}
 }
 
 func main() {

+ 413 - 418
src/service/second_push.go

@@ -3,19 +3,14 @@ package service
 import (
 	"encoding/json"
 	"fmt"
-	"history"
 	"log"
-	"os"
 	mongoutil "qfw/mongodb"
 	qu "qfw/util"
-	"qfw/util/mail"
 	"strconv"
 	"strings"
 	"time"
 	. "util"
 
-	"github.com/tealeg/xlsx"
-
 	"github.com/go-xweb/xweb"
 
 	"gopkg.in/mgo.v2/bson"
@@ -119,7 +114,7 @@ func (s *SecondPush) GetUserRule() {
 	}
 }
 
-//保存二次推送规则
+// 保存二次推送规则
 func (s *SecondPush) SaveSpushRule() {
 	rules_id := s.GetString("rulesid")
 	s_pushid := s.GetString("s_pushid")
@@ -445,419 +440,419 @@ func (s *SecondPush) HistoryRuleEdit() {
 }
 
 func GetXlsxs(mMap []map[string]interface{}, fn, email, id, appid string) {
-	if id != "" {
-		isfile := false
-		isfilehref := false
-		if history.FileTextAppidMap[appid] {
-			isfile = true
-		}
-		if history.NeedFilehrefAppidMap[appid] {
-			isfilehref = true
-		}
-		query := bson.M{
-			"_id": bson.ObjectIdHex(id),
-		}
-		data, ok := Mgo.FindOne("second_push", 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())
-			}
-			newFile := xlsx.NewFile()
-			style := xlsx.NewStyle()
-			style.Font.Size = 12
-			style.Font.Bold = true
-			style.Alignment.Vertical = "center"
-			style.Alignment.Horizontal = "center"
-			if dataType == 1 {
-				sh := xf.Sheets[0]
-				sheetIndex := map[string]int{}
-				for _, v := range mMap {
-					// 拿到所选字段包的sheet页  如果item存在则追加 不存在则创建新sheet页
-					var sheet *xlsx.Sheet
-					if v["item"].(string) == "" {
-						v["item"] = "其他方式"
-					}
-					items := strings.Split(v["item"].(string), ",")
-					for _, i := range items {
-						if len(items) > 1 && v["itemdist"] != nil {
-							v["matchkey"] = v["itemdist"].(map[string]interface{})[i]
-							v["item"] = i
-						}
-						if _, ok := newFile.Sheet[v["item"].(string)]; ok {
-							sheet = newFile.Sheet[v["item"].(string)]
-							sheetIndex[v["item"].(string)] += 1
-						} else {
-							sheet, err = newFile.AppendSheet(*sh, v["item"].(string))
-							sheetIndex[v["item"].(string)] = 1
-						}
-						row := sheet.AddRow()
-						row.AddCell().SetInt(sheetIndex[v["item"].(string)])
-						row.AddCell().SetValue(v["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["s_winner"])
-						if v["bidamount"] != nil {
-							row.AddCell().SetFloat(qu.Float64All(v["bidamount"]))
-						} else {
-							row.AddCell()
-						}
-						row.AddCell().SetValue(v["projectname"])
-						row.AddCell().SetValue(v["detail"])
-						row.AddCell().SetValue(v["jybxhref"])
-						ids := SE.EncodeString(qu.ObjToString(v["id"]))
-						row.AddCell().SetValue(ids)
-					}
+	// if id != "" {
+	// 	isfile := false
+	// 	isfilehref := false
+	// 	if history.FileTextAppidMap[appid] {
+	// 		isfile = true
+	// 	}
+	// 	if history.NeedFilehrefAppidMap[appid] {
+	// 		isfilehref = true
+	// 	}
+	// 	query := bson.M{
+	// 		"_id": bson.ObjectIdHex(id),
+	// 	}
+	// 	data, ok := Mgo.FindOne("second_push", 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())
+	// 		}
+	// 		newFile := xlsx.NewFile()
+	// 		style := xlsx.NewStyle()
+	// 		style.Font.Size = 12
+	// 		style.Font.Bold = true
+	// 		style.Alignment.Vertical = "center"
+	// 		style.Alignment.Horizontal = "center"
+	// 		if dataType == 1 {
+	// 			sh := xf.Sheets[0]
+	// 			sheetIndex := map[string]int{}
+	// 			for _, v := range mMap {
+	// 				// 拿到所选字段包的sheet页  如果item存在则追加 不存在则创建新sheet页
+	// 				var sheet *xlsx.Sheet
+	// 				if v["item"].(string) == "" {
+	// 					v["item"] = "其他方式"
+	// 				}
+	// 				items := strings.Split(v["item"].(string), ",")
+	// 				for _, i := range items {
+	// 					if len(items) > 1 && v["itemdist"] != nil {
+	// 						v["matchkey"] = v["itemdist"].(map[string]interface{})[i]
+	// 						v["item"] = i
+	// 					}
+	// 					if _, ok := newFile.Sheet[v["item"].(string)]; ok {
+	// 						sheet = newFile.Sheet[v["item"].(string)]
+	// 						sheetIndex[v["item"].(string)] += 1
+	// 					} else {
+	// 						sheet, err = newFile.AppendSheet(*sh, v["item"].(string))
+	// 						sheetIndex[v["item"].(string)] = 1
+	// 					}
+	// 					row := sheet.AddRow()
+	// 					row.AddCell().SetInt(sheetIndex[v["item"].(string)])
+	// 					row.AddCell().SetValue(v["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["s_winner"])
+	// 					if v["bidamount"] != nil {
+	// 						row.AddCell().SetFloat(qu.Float64All(v["bidamount"]))
+	// 					} else {
+	// 						row.AddCell()
+	// 					}
+	// 					row.AddCell().SetValue(v["projectname"])
+	// 					row.AddCell().SetValue(v["detail"])
+	// 					row.AddCell().SetValue(v["jybxhref"])
+	// 					ids := SE.EncodeString(qu.ObjToString(v["id"]))
+	// 					row.AddCell().SetValue(ids)
+	// 				}
 
-				}
-				//xf.Sheets = xf.Sheets[0:1]
-			} else if dataType == 2 {
-				sh := xf.Sheets[1]
-				if isfile {
-					cell := sh.Rows[0].AddCell()
-					cell.SetValue("附件")
-					cell.SetStyle(style)
-				}
-				if isfilehref {
-					cell := sh.Rows[0].AddCell()
-					cell.SetValue("附件链接")
-					cell.SetStyle(style)
-				}
-				for _, v := range mMap {
-					if v["item"].(string) == "" {
-						v["item"] = "其他方式"
-					}
-					items := strings.Split(v["item"].(string), ",")
-					for _, i := range items {
-						if len(items) > 1 && v["itemdist"] != nil {
-							v["matchkey"] = v["itemdist"].(map[string]interface{})[i]
-							v["item"] = i
-						}
-						var sheet *xlsx.Sheet
-						if _, ok := newFile.Sheet[v["item"].(string)]; ok {
-							sheet = newFile.Sheet[v["item"].(string)]
-						} else {
-							sheet, err = newFile.AppendSheet(*sh, v["item"].(string))
-						}
-						row := sheet.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["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["jybxhref"])
-						row.AddCell().SetValue(v["projectname"])
-						row.AddCell().SetValue(v["projectcode"])
-						row.AddCell().SetValue(v["projectscope"])
-						if v["budget"] != nil {
-							row.AddCell().SetFloat(qu.Float64All(v["budget"]))
-						} else {
-							row.AddCell()
-						}
-						if v["bidamount"] != nil {
-							row.AddCell().SetFloat(qu.Float64All(v["bidamount"]))
-						} 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["s_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"])
-						ids := SE.EncodeString(qu.ObjToString(v["id"]))
-						row.AddCell().SetValue(ids)
-						if isfile {
-							row.AddCell().SetValue(v["filetext"])
-						}
-						if isfilehref {
-							if v["filehref"] != nil {
-								if filelist, ok := v["filehref"].([]interface{}); ok {
-									index := 0
-									for _, url := range filelist {
-										if urlMap, ok := url.(map[string]interface{}); ok {
-											if urlMap["url"] != nil {
-												style1 := xlsx.NewStyle()
-												style1.Font.Name = "宋体"
-												style1.Font.Size = 12
-												style1.Font.Bold = false
-												if history.FilterFilehrefAppidMap[appid] {
-													if strings.Contains(urlMap["url"].(string), "jy-datafile.oss-cn-beijing.aliyuncs.com") {
-														cell := row.AddCell()
-														cell.SetStyle(style1)
-														cell.SetValue(urlMap["url"])
-														index++
-													}
-												} else {
-													cell := row.AddCell()
-													cell.SetStyle(style1)
-													cell.SetValue(urlMap["url"])
-													index++
-												}
-											}
-										}
-									}
-								}
-							}
-						}
-					}
-				}
-				//xf.Sheets = xf.Sheets[1:2]
-			} else if dataType == 3 {
-				sh := xf.Sheets[2]
-				for _, v := range mMap {
-					if v["item"].(string) == "" {
-						v["item"] = "其他方式"
-					}
-					items := strings.Split(v["item"].(string), ",")
-					for _, i := range items {
-						if len(items) > 1 && v["itemdist"] != nil {
-							v["matchkey"] = v["itemdist"].(map[string]interface{})[i]
-							v["item"] = i
-						}
-						var sheet *xlsx.Sheet
-						if _, ok := newFile.Sheet[v["item"].(string)]; ok {
-							sheet = newFile.Sheet[v["item"].(string)]
-						} else {
-							sheet, err = newFile.AppendSheet(*sh, v["item"].(string))
-						}
-						row := sheet.AddRow()
-						// row.AddCell().SetInt(i + 1)
-						row.AddCell().SetValue(v["departname"])
-						row.AddCell().SetValue(v["rulename"])
-						row.AddCell().SetValue(v["matchkey"])
-						row.AddCell().SetValue(v["toptype"])
-						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"]))
-						} else {
-							row.AddCell()
-						}
-						row.AddCell().SetValue(v["buyer"])
-						row.AddCell().SetValue(v["buyerclass"])
-						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"])
-						ids := SE.EncodeString(qu.ObjToString(v["id"]))
-						row.AddCell().SetValue(ids)
-					}
-				}
-				//xf.Sheets = xf.Sheets[2:3]
-			} else if dataType == 4 {
-				sh := xf.Sheets[3]
-				for _, v := range mMap {
-					if v["item"].(string) == "" {
-						v["item"] = "其他方式"
-					}
-					items := strings.Split(v["item"].(string), ",")
-					for _, i := range items {
-						if len(items) > 1 && v["itemdist"] != nil {
-							v["matchkey"] = v["itemdist"].(map[string]interface{})[i]
-							v["item"] = i
-						}
-						var sheet *xlsx.Sheet
-						if _, ok := newFile.Sheet[v["item"].(string)]; ok {
-							sheet = newFile.Sheet[v["item"].(string)]
-						} else {
-							sheet, err = newFile.AppendSheet(*sh, v["item"].(string))
-						}
-						row := sheet.AddRow()
-						// row.AddCell().SetInt(i + 1)
-						row.AddCell().SetValue(v["departname"])
-						row.AddCell().SetValue(v["rulename"])
-						row.AddCell().SetValue(v["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["jybxhref"])
-						row.AddCell().SetValue(v["projectname"])
-						row.AddCell().SetValue(v["projectcode"])
-						row.AddCell().SetValue(v["projectscope"])
-						if v["budget"] != nil {
-							row.AddCell().SetFloat(qu.Float64All(v["budget"]))
-						} else {
-							row.AddCell()
-						}
-						if v["bidamount"] != nil {
-							row.AddCell().SetFloat(qu.Float64All(v["bidamount"]))
-						} 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["s_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"])
-						ids := SE.EncodeString(qu.ObjToString(v["id"]))
-						row.AddCell().SetValue(ids)
-					}
-				}
-				//xf.Sheets = xf.Sheets[3:4]
-			} else if dataType == 5 {
-				sh := xf.Sheets[4]
-				for _, v := range mMap {
-					if v["item"].(string) == "" {
-						v["item"] = "其他方式"
-					}
-					items := strings.Split(v["item"].(string), ",")
-					for _, i := range items {
-						if len(items) > 1 && v["itemdist"] != nil {
-							v["matchkey"] = v["itemdist"].(map[string]interface{})[i]
-							v["item"] = i
-						}
-						var sheet *xlsx.Sheet
-						if _, ok := newFile.Sheet[v["item"].(string)]; ok {
-							sheet = newFile.Sheet[v["item"].(string)]
-						} else {
-							sheet, err = newFile.AppendSheet(*sh, v["item"].(string))
-						}
-						row := sheet.AddRow()
-						// row.AddCell().SetInt(i + 1)
-						row.AddCell().SetValue(v["matchkey"])    //信息匹配词
-						row.AddCell().SetValue(v["city"])        //城市
-						row.AddCell().SetValue(v["district"])    //县区
-						row.AddCell().SetValue(v["projectname"]) //项目名称
-						row.AddCell().SetValue(v["buyer"])       //采购单位
-						row.AddCell().SetValue(v["buyer_type"])  //采购单位类别---私有标签tagname
-						if v["bidamount"] != nil {               //中标金额
-							row.AddCell().SetFloat(qu.Float64All(v["bidamount"]))
-						} else {
-							row.AddCell()
-						}
-						if v["budget"] != nil { //预算
-							row.AddCell().SetFloat(qu.Float64All(v["budget"]))
-						} else {
-							row.AddCell()
-						}
-						if v["publishtime"] != nil { //公告发布时间
-							row.AddCell().SetValue(time.Unix(qu.Int64All(v["publishtime"]), 0).Format("2006-01-02"))
-						} 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["s_winner"])           //中标单位
-						row.AddCell().SetValue(v["winner_type"])        //中标模式--移动、电信、联通
-						row.AddCell().SetValue(v["title"])              //公告标题
-						row.AddCell().SetValue(v["subtype"])            //公告类别
-						row.AddCell().SetValue(v["area"])               //省份
-						row.AddCell().SetValue(v["projectcode"])        //项目编号
-						row.AddCell().SetValue(v["projectscope"])       //项目范围
-						row.AddCell().SetValue(v["agency"])             //招标代理机构
-						row.AddCell().SetValue(v["detail"])             //公告内容
-						row.AddCell().SetValue(v["href"])               //公告地址
-						row.AddCell().SetValue(v["buyerperson"])        //采购单位联系人
-						row.AddCell().SetValue(v["buyertel"])           //采购单位联系电话
-						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"])      //中标企业邮箱
-						ids := SE.EncodeString(qu.ObjToString(v["id"])) //唯一标识
-						row.AddCell().SetValue(ids)
-						row.AddCell().SetValue(SE.EncodeString(qu.ObjToString(v["projectId"]))) //项目标识
-						row.AddCell().SetValue(v["jybxhref"])
-						//row.AddCell().SetValue(v["projectcode"])
-					}
-				}
-				//xf.Sheets = xf.Sheets[4:5]
-			}
-			//xf.Sheets[0].Name = "详细数据"
-			//生文件
-			//t := strconv.FormatInt(time.Now().Unix(), 10)
-			t := time.Now().Format("20060102")
-			dir := "./web/res/xlsx/" + t + "/"
-			if b, _ := history.PathExists(dir); !b {
-				err1 := os.MkdirAll(dir, os.ModePerm)
-				if err1 != nil {
-					log.Println("mkdir err", dir)
-				}
-			}
-			fname := fmt.Sprintf("%s_%s_%s.xlsx", fn, t, qu.GetRandom(4))
-			log.Println("fname", fname)
-			err = newFile.Save(dir + fname)
-			if err != nil {
-				log.Println("xls error", err, fname)
-			} else {
-				for i := 0; i < len(history.Gmails); i++ {
-					gmail := history.Gmails[i]
-					status := mail.GSendMail_q("剑鱼标讯", email, "", "", fn, "", dir+fname, fname, gmail)
-					if status {
-						log.Println("send mail success", fname, email)
-						break
-					}
-				}
-			}
-		}
-	}
+	// 			}
+	// 			//xf.Sheets = xf.Sheets[0:1]
+	// 		} else if dataType == 2 {
+	// 			sh := xf.Sheets[1]
+	// 			if isfile {
+	// 				cell := sh.Rows[0].AddCell()
+	// 				cell.SetValue("附件")
+	// 				cell.SetStyle(style)
+	// 			}
+	// 			if isfilehref {
+	// 				cell := sh.Rows[0].AddCell()
+	// 				cell.SetValue("附件链接")
+	// 				cell.SetStyle(style)
+	// 			}
+	// 			for _, v := range mMap {
+	// 				if v["item"].(string) == "" {
+	// 					v["item"] = "其他方式"
+	// 				}
+	// 				items := strings.Split(v["item"].(string), ",")
+	// 				for _, i := range items {
+	// 					if len(items) > 1 && v["itemdist"] != nil {
+	// 						v["matchkey"] = v["itemdist"].(map[string]interface{})[i]
+	// 						v["item"] = i
+	// 					}
+	// 					var sheet *xlsx.Sheet
+	// 					if _, ok := newFile.Sheet[v["item"].(string)]; ok {
+	// 						sheet = newFile.Sheet[v["item"].(string)]
+	// 					} else {
+	// 						sheet, err = newFile.AppendSheet(*sh, v["item"].(string))
+	// 					}
+	// 					row := sheet.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["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["jybxhref"])
+	// 					row.AddCell().SetValue(v["projectname"])
+	// 					row.AddCell().SetValue(v["projectcode"])
+	// 					row.AddCell().SetValue(v["projectscope"])
+	// 					if v["budget"] != nil {
+	// 						row.AddCell().SetFloat(qu.Float64All(v["budget"]))
+	// 					} else {
+	// 						row.AddCell()
+	// 					}
+	// 					if v["bidamount"] != nil {
+	// 						row.AddCell().SetFloat(qu.Float64All(v["bidamount"]))
+	// 					} 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["s_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"])
+	// 					ids := SE.EncodeString(qu.ObjToString(v["id"]))
+	// 					row.AddCell().SetValue(ids)
+	// 					if isfile {
+	// 						row.AddCell().SetValue(v["filetext"])
+	// 					}
+	// 					if isfilehref {
+	// 						if v["filehref"] != nil {
+	// 							if filelist, ok := v["filehref"].([]interface{}); ok {
+	// 								index := 0
+	// 								for _, url := range filelist {
+	// 									if urlMap, ok := url.(map[string]interface{}); ok {
+	// 										if urlMap["url"] != nil {
+	// 											style1 := xlsx.NewStyle()
+	// 											style1.Font.Name = "宋体"
+	// 											style1.Font.Size = 12
+	// 											style1.Font.Bold = false
+	// 											if history.FilterFilehrefAppidMap[appid] {
+	// 												if strings.Contains(urlMap["url"].(string), "jy-datafile.oss-cn-beijing.aliyuncs.com") {
+	// 													cell := row.AddCell()
+	// 													cell.SetStyle(style1)
+	// 													cell.SetValue(urlMap["url"])
+	// 													index++
+	// 												}
+	// 											} else {
+	// 												cell := row.AddCell()
+	// 												cell.SetStyle(style1)
+	// 												cell.SetValue(urlMap["url"])
+	// 												index++
+	// 											}
+	// 										}
+	// 									}
+	// 								}
+	// 							}
+	// 						}
+	// 					}
+	// 				}
+	// 			}
+	// 			//xf.Sheets = xf.Sheets[1:2]
+	// 		} else if dataType == 3 {
+	// 			sh := xf.Sheets[2]
+	// 			for _, v := range mMap {
+	// 				if v["item"].(string) == "" {
+	// 					v["item"] = "其他方式"
+	// 				}
+	// 				items := strings.Split(v["item"].(string), ",")
+	// 				for _, i := range items {
+	// 					if len(items) > 1 && v["itemdist"] != nil {
+	// 						v["matchkey"] = v["itemdist"].(map[string]interface{})[i]
+	// 						v["item"] = i
+	// 					}
+	// 					var sheet *xlsx.Sheet
+	// 					if _, ok := newFile.Sheet[v["item"].(string)]; ok {
+	// 						sheet = newFile.Sheet[v["item"].(string)]
+	// 					} else {
+	// 						sheet, err = newFile.AppendSheet(*sh, v["item"].(string))
+	// 					}
+	// 					row := sheet.AddRow()
+	// 					// row.AddCell().SetInt(i + 1)
+	// 					row.AddCell().SetValue(v["departname"])
+	// 					row.AddCell().SetValue(v["rulename"])
+	// 					row.AddCell().SetValue(v["matchkey"])
+	// 					row.AddCell().SetValue(v["toptype"])
+	// 					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"]))
+	// 					} else {
+	// 						row.AddCell()
+	// 					}
+	// 					row.AddCell().SetValue(v["buyer"])
+	// 					row.AddCell().SetValue(v["buyerclass"])
+	// 					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"])
+	// 					ids := SE.EncodeString(qu.ObjToString(v["id"]))
+	// 					row.AddCell().SetValue(ids)
+	// 				}
+	// 			}
+	// 			//xf.Sheets = xf.Sheets[2:3]
+	// 		} else if dataType == 4 {
+	// 			sh := xf.Sheets[3]
+	// 			for _, v := range mMap {
+	// 				if v["item"].(string) == "" {
+	// 					v["item"] = "其他方式"
+	// 				}
+	// 				items := strings.Split(v["item"].(string), ",")
+	// 				for _, i := range items {
+	// 					if len(items) > 1 && v["itemdist"] != nil {
+	// 						v["matchkey"] = v["itemdist"].(map[string]interface{})[i]
+	// 						v["item"] = i
+	// 					}
+	// 					var sheet *xlsx.Sheet
+	// 					if _, ok := newFile.Sheet[v["item"].(string)]; ok {
+	// 						sheet = newFile.Sheet[v["item"].(string)]
+	// 					} else {
+	// 						sheet, err = newFile.AppendSheet(*sh, v["item"].(string))
+	// 					}
+	// 					row := sheet.AddRow()
+	// 					// row.AddCell().SetInt(i + 1)
+	// 					row.AddCell().SetValue(v["departname"])
+	// 					row.AddCell().SetValue(v["rulename"])
+	// 					row.AddCell().SetValue(v["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["jybxhref"])
+	// 					row.AddCell().SetValue(v["projectname"])
+	// 					row.AddCell().SetValue(v["projectcode"])
+	// 					row.AddCell().SetValue(v["projectscope"])
+	// 					if v["budget"] != nil {
+	// 						row.AddCell().SetFloat(qu.Float64All(v["budget"]))
+	// 					} else {
+	// 						row.AddCell()
+	// 					}
+	// 					if v["bidamount"] != nil {
+	// 						row.AddCell().SetFloat(qu.Float64All(v["bidamount"]))
+	// 					} 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["s_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"])
+	// 					ids := SE.EncodeString(qu.ObjToString(v["id"]))
+	// 					row.AddCell().SetValue(ids)
+	// 				}
+	// 			}
+	// 			//xf.Sheets = xf.Sheets[3:4]
+	// 		} else if dataType == 5 {
+	// 			sh := xf.Sheets[4]
+	// 			for _, v := range mMap {
+	// 				if v["item"].(string) == "" {
+	// 					v["item"] = "其他方式"
+	// 				}
+	// 				items := strings.Split(v["item"].(string), ",")
+	// 				for _, i := range items {
+	// 					if len(items) > 1 && v["itemdist"] != nil {
+	// 						v["matchkey"] = v["itemdist"].(map[string]interface{})[i]
+	// 						v["item"] = i
+	// 					}
+	// 					var sheet *xlsx.Sheet
+	// 					if _, ok := newFile.Sheet[v["item"].(string)]; ok {
+	// 						sheet = newFile.Sheet[v["item"].(string)]
+	// 					} else {
+	// 						sheet, err = newFile.AppendSheet(*sh, v["item"].(string))
+	// 					}
+	// 					row := sheet.AddRow()
+	// 					// row.AddCell().SetInt(i + 1)
+	// 					row.AddCell().SetValue(v["matchkey"])    //信息匹配词
+	// 					row.AddCell().SetValue(v["city"])        //城市
+	// 					row.AddCell().SetValue(v["district"])    //县区
+	// 					row.AddCell().SetValue(v["projectname"]) //项目名称
+	// 					row.AddCell().SetValue(v["buyer"])       //采购单位
+	// 					row.AddCell().SetValue(v["buyer_type"])  //采购单位类别---私有标签tagname
+	// 					if v["bidamount"] != nil {               //中标金额
+	// 						row.AddCell().SetFloat(qu.Float64All(v["bidamount"]))
+	// 					} else {
+	// 						row.AddCell()
+	// 					}
+	// 					if v["budget"] != nil { //预算
+	// 						row.AddCell().SetFloat(qu.Float64All(v["budget"]))
+	// 					} else {
+	// 						row.AddCell()
+	// 					}
+	// 					if v["publishtime"] != nil { //公告发布时间
+	// 						row.AddCell().SetValue(time.Unix(qu.Int64All(v["publishtime"]), 0).Format("2006-01-02"))
+	// 					} 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["s_winner"])           //中标单位
+	// 					row.AddCell().SetValue(v["winner_type"])        //中标模式--移动、电信、联通
+	// 					row.AddCell().SetValue(v["title"])              //公告标题
+	// 					row.AddCell().SetValue(v["subtype"])            //公告类别
+	// 					row.AddCell().SetValue(v["area"])               //省份
+	// 					row.AddCell().SetValue(v["projectcode"])        //项目编号
+	// 					row.AddCell().SetValue(v["projectscope"])       //项目范围
+	// 					row.AddCell().SetValue(v["agency"])             //招标代理机构
+	// 					row.AddCell().SetValue(v["detail"])             //公告内容
+	// 					row.AddCell().SetValue(v["href"])               //公告地址
+	// 					row.AddCell().SetValue(v["buyerperson"])        //采购单位联系人
+	// 					row.AddCell().SetValue(v["buyertel"])           //采购单位联系电话
+	// 					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"])      //中标企业邮箱
+	// 					ids := SE.EncodeString(qu.ObjToString(v["id"])) //唯一标识
+	// 					row.AddCell().SetValue(ids)
+	// 					row.AddCell().SetValue(SE.EncodeString(qu.ObjToString(v["projectId"]))) //项目标识
+	// 					row.AddCell().SetValue(v["jybxhref"])
+	// 					//row.AddCell().SetValue(v["projectcode"])
+	// 				}
+	// 			}
+	// 			//xf.Sheets = xf.Sheets[4:5]
+	// 		}
+	// 		//xf.Sheets[0].Name = "详细数据"
+	// 		//生文件
+	// 		//t := strconv.FormatInt(time.Now().Unix(), 10)
+	// 		t := time.Now().Format("20060102")
+	// 		dir := "./web/res/xlsx/" + t + "/"
+	// 		if b, _ := history.PathExists(dir); !b {
+	// 			err1 := os.MkdirAll(dir, os.ModePerm)
+	// 			if err1 != nil {
+	// 				log.Println("mkdir err", dir)
+	// 			}
+	// 		}
+	// 		fname := fmt.Sprintf("%s_%s_%s.xlsx", fn, t, qu.GetRandom(4))
+	// 		log.Println("fname", fname)
+	// 		err = newFile.Save(dir + fname)
+	// 		if err != nil {
+	// 			log.Println("xls error", err, fname)
+	// 		} else {
+	// 			for i := 0; i < len(history.Gmails); i++ {
+	// 				gmail := history.Gmails[i]
+	// 				status := mail.GSendMail_q("剑鱼标讯", email, "", "", fn, "", dir+fname, fname, gmail)
+	// 				if status {
+	// 					log.Println("send mail success", fname, email)
+	// 					break
+	// 				}
+	// 			}
+	// 		}
+	// 	}
+	// }
 }
 
 func (s *SecondPush) AddSecondPushRule() {

+ 22 - 15
src/util/config.go

@@ -5,7 +5,9 @@ import (
 	"io/ioutil"
 	"qfw/mongodb"
 	qu "qfw/util"
-	"qfw/util/elastic"
+
+	// "qfw/util/elastic"
+	elastic "es"
 	"qfw/util/mysql"
 	"qfw/util/redis"
 	"sort"
@@ -40,10 +42,11 @@ var (
 	HospColl        string
 	BuyerEntColl    string
 	EnpsColl        string
-	Es              *elastic.Elastic //es
-	Index           string
-	Itype           string
-	TaskTime        int64 //定时任务时间
+	// Es              *elastic.Elastic //es
+	Es       elastic.Es
+	Index    string
+	Itype    string
+	TaskTime int64 //定时任务时间
 	//历史数据
 	SId             string
 	EId             string
@@ -241,7 +244,11 @@ 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))
+	// elastic.InitElasticSize(qu.ObjToString(Sysconfig["elasticsearch"]), qu.IntAllDef(qu.Int64All(Sysconfig["elasticPoolSize"]), 30))
+	es := Sysconfig["es"].(map[string]interface{})
+	Es = elastic.NewEs(qu.ObjToString(es["version"]), qu.ObjToString(es["addr"]), qu.IntAllDef(es["pool"], 15), qu.ObjToString(es["userName"]), qu.ObjToString(es["password"]))
+	Index = qu.ObjToString(es["index"])
+	Itype = qu.ObjToString(es["itype"])
 }
 
 func initTagField() {
@@ -326,15 +333,15 @@ func initdb() {
 	MgoExtract.InitPool()
 
 	//es
-	es := Sysconfig["es"].(map[string]interface{})
-	Es = &elastic.Elastic{
-		S_esurl: qu.ObjToString(es["addr"]),
-		I_size:  qu.IntAllDef(es["pool"], 15),
-	}
-	Es.InitElasticSize()
+	// es := Sysconfig["es"].(map[string]interface{})
+	// Es = &elastic.Elastic{
+	// 	S_esurl: qu.ObjToString(es["addr"]),
+	// 	I_size:  qu.IntAllDef(es["pool"], 15),
+	// }
+	// Es.InitElasticSize()
 	redis.InitRedisBySize(qu.ObjToString(Sysconfig["redis_addrs"]), 100, 30, 300)
-	Index = qu.ObjToString(es["index"])
-	Itype = qu.ObjToString(es["itype"])
+	// Index = qu.ObjToString(es["index"])
+	// Itype = qu.ObjToString(es["itype"])
 	jyMysql := qu.ObjToMap(Sysconfig["jyMysql"])
 	JyMysql = &mysql.Mysql{
 		Address:  (*jyMysql)["address"].(string),
@@ -364,7 +371,7 @@ func (s ByPinyin) Less(i, j int) bool {
 	return true
 }
 
-//UTF82GBK : transform UTF8 rune into GBK byte array
+// UTF82GBK : transform UTF8 rune into GBK byte array
 func UTF82GBK(src string) ([]byte, error) {
 	GB18030 := simplifiedchinese.All[0]
 	return ioutil.ReadAll(transform.NewReader(bytes.NewReader([]byte(src)), GB18030.NewEncoder()))

+ 33 - 28
src/util/utiltag.go

@@ -1,6 +1,7 @@
 package util
 
 import (
+	"context"
 	"encoding/json"
 	"errors"
 	"fmt"
@@ -8,14 +9,16 @@ import (
 	"models"
 	"mongodb"
 	"qfw/util"
-	"qfw/util/elastic"
+
+	// "qfw/util/elastic"
+	esv "es"
 	sql "sqlmodel"
 	"strings"
 	"sync"
 	"time"
 
+	es "github.com/olivere/elastic"
 	"gopkg.in/mgo.v2/bson"
-	es "gopkg.in/olivere/elastic.v1"
 )
 
 const (
@@ -68,7 +71,7 @@ func UtilEsSaveData(sdataid string, datas *[]map[string]interface{}) error {
 	return nil
 }
 
-//客户规则
+// 客户规则
 func UtilEsFind1(tags map[string]interface{}) (error, int64) {
 	defer util.Catch()
 	ch := make(chan bool, 20)
@@ -108,10 +111,12 @@ func UtilEsFind1(tags map[string]interface{}) (error, int64) {
 	} else {
 		return errors.New("o_rules no found"), 0
 	}
-	client := elastic.GetEsConn()
-	defer elastic.DestoryEsConn(client)
+	ctx, _ := context.WithTimeout(context.Background(), 30*time.Second)
+	esCon := esv.VarEs.(*esv.EsV7)
+	client := esCon.GetEsConn()
+	defer esCon.DestoryEsConn(client)
 	esquery = esquery[:len(esquery)-1] + `,"size":` + fmt.Sprintf("%d", i_maxnum) + `}`
-	searchResult, err := client.Search(EsIndex).Source(esquery).Do()
+	searchResult, err := client.Search(EsIndex).Source(esquery).Do(ctx)
 	if err == nil && searchResult.Hits != nil {
 		datas := make([]map[string]interface{}, 0)
 		util.Debug("es查询到的数量:", searchResult.Hits.TotalHits)
@@ -127,10 +132,10 @@ func UtilEsFind1(tags map[string]interface{}) (error, int64) {
 				}()
 				arrsync.Lock()
 				item := make(map[string]interface{})
-				if json.Unmarshal(*tmpHit.Source, &item) == nil {
+				if json.Unmarshal(tmpHit.Source, &item) == nil {
 					item["appid"] = tags["appid"]
 					item["rulename"] = tags["s_name"]
-					info_id := util.ObjToString(item["_id"])
+					info_id := util.ObjToString(item["id"])
 					item["info_id"] = info_id
 					item["s_dataid"] = sdataid
 					// item["s_jyhref"] = fmt.Sprintf(Url, util.CommonEncodeArticle("content", info_id))
@@ -261,9 +266,9 @@ func UtilEsFind1(tags map[string]interface{}) (error, int64) {
 		wg.Wait()
 		Mgo.Update("entniche_rule", bson.M{"_id": tags["_id"]}, bson.M{
 			"$set": bson.M{
-				"i_estotal": searchResult.Hits.TotalHits,
+				"i_estotal": searchResult.Hits.TotalHits.Value,
 			}}, false, false)
-		count := searchResult.Hits.TotalHits
+		count := searchResult.Hits.TotalHits.Value
 		return UtilEsSaveData(sdataid, &datas), count
 	} else {
 		util.Debug(err)
@@ -509,7 +514,7 @@ func Utiltags(tag map[string]interface{}) string {
 			bidamountSql.Bool.Should = append(bidamountSql.Bool.Should, sql.BidamountMust{BidamountObj: &sql.BidamountObj{Bidamount: limit}})
 		}
 		if tab.SbidamountFieldExist == 1 {
-			bidamountSql.Bool.Should = append(bidamountSql.Bool.Should, sql.ExistfieldsObjectMust{
+			fqBoolObject.MustNot = append(fqBoolObject.MustNot, sql.ExistfieldsObjectMust{
 				ExistfieldsObject: &sql.ExistfieldsObject{Filter: struct {
 					Missing struct {
 						Field string `json:"field,omitempty"`
@@ -545,7 +550,7 @@ func Utiltags(tag map[string]interface{}) string {
 			budgetSql.Bool.Should = append(budgetSql.Bool.Should, sql.BudgetMust{BudgetObj: &sql.BudgetObj{Budget: limit}})
 		}
 		if tab.SbudgetFieldExist == 1 {
-			budgetSql.Bool.Should = append(budgetSql.Bool.Should, sql.ExistfieldsObjectMust{
+			fqBoolObject.MustNot = append(fqBoolObject.MustNot, sql.ExistfieldsObjectMust{
 				ExistfieldsObject: &sql.ExistfieldsObject{Filter: struct {
 					Missing struct {
 						Field string `json:"field,omitempty"`
@@ -561,43 +566,43 @@ func Utiltags(tag map[string]interface{}) string {
 	}
 
 	if len(ffBoolObject.Must) > 0 || len(ffBoolObject.MustNot) > 0 || len(ffBoolObject.Should) > 0 {
-		QueryObjecct.Filtered.Filter = &sql.Filter{}
-		QueryObjecct.Filtered.Filter.Bool = &ffBoolObject
+		QueryObjecct.Bool = &ffBoolObject
 	}
 	if len(fqBoolObject.Must) > 0 || len(fqBoolObject.MustNot) > 0 || len(fqBoolObject.Should) > 0 {
-		QueryObjecct.Filtered.Query = &sql.Query{}
-		QueryObjecct.Filtered.Query.Bool = &fqBoolObject
+		QueryObjecct.Bool.Must = append(QueryObjecct.Bool.Must, &fqBoolObject)
 		if len(torules.Should) > 0 {
-			QueryObjecct.Filtered.Query.Bool.Must = append(QueryObjecct.Filtered.Query.Bool.Must, map[string]interface{}{
+			QueryObjecct.Bool.Must = append(QueryObjecct.Bool.Must, map[string]interface{}{
 				"bool": torules,
 			})
 		}
 	} else if len(torules.Should) > 0 {
-		if QueryObjecct.Filtered.Query == nil {
-			QueryObjecct.Filtered.Query = &sql.Query{}
-			QueryObjecct.Filtered.Query.Bool = &fqBoolObject
+		if QueryObjecct.Bool == nil {
+			QueryObjecct.Bool = &sql.BoolObject{}
 		}
-		QueryObjecct.Filtered.Query.Bool.Must = append(QueryObjecct.Filtered.Query.Bool.Must, map[string]interface{}{
+		QueryObjecct.Bool.Must = append(QueryObjecct.Bool.Must, map[string]interface{}{
 			"bool": torules,
 		})
 	}
 	if (len(budgetSql.Bool.Should) > 0 || len(bidamountSql.Bool.Should) > 0) && (len(fqBoolObject.Must) > 0 || len(fqBoolObject.MustNot) > 0 || len(fqBoolObject.Should) > 0) {
+		if QueryObjecct.Bool == nil {
+			QueryObjecct.Bool = &sql.BoolObject{}
+		}
 		if len(budgetSql.Bool.Should) > 0 {
-			QueryObjecct.Filtered.Query.Bool.Must = append(QueryObjecct.Filtered.Query.Bool.Must, budgetSql)
+			QueryObjecct.Bool.Must = append(QueryObjecct.Bool.Must, budgetSql)
 		}
 		if len(bidamountSql.Bool.Should) > 0 {
-			QueryObjecct.Filtered.Query.Bool.Must = append(QueryObjecct.Filtered.Query.Bool.Must, bidamountSql)
+			QueryObjecct.Bool.Must = append(QueryObjecct.Bool.Must, bidamountSql)
 		}
 	} else {
-		QueryObjecct.Filtered.Query = &sql.Query{}
-		QueryObjecct.Filtered.Query.Bool = &fqBoolObject
+		if QueryObjecct.Bool == nil {
+			QueryObjecct.Bool = &sql.BoolObject{}
+		}
 		if len(budgetSql.Bool.Should) > 0 {
-			QueryObjecct.Filtered.Query.Bool.Must = append(QueryObjecct.Filtered.Query.Bool.Must, budgetSql)
+			QueryObjecct.Bool.Must = append(QueryObjecct.Bool.Must, budgetSql)
 		}
 		if len(bidamountSql.Bool.Should) > 0 {
-			QueryObjecct.Filtered.Query.Bool.Must = append(QueryObjecct.Filtered.Query.Bool.Must, bidamountSql)
+			QueryObjecct.Bool.Must = append(QueryObjecct.Bool.Must, bidamountSql)
 		}
-		//QueryObjecct.Filtered.Query.Bool.Must = append(QueryObjecct.Filtered.Query.Bool.Must, budgetSql)
 	}
 	rdata := make(map[string]interface{})
 	rdata["query"] = QueryObjecct