|
@@ -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
|
|
|
|
-}
|
|
|