|
@@ -1,10 +1,6 @@
|
|
|
package main
|
|
|
|
|
|
import (
|
|
|
- "encoding/json"
|
|
|
- du "jy/util"
|
|
|
- "log"
|
|
|
- "math"
|
|
|
"qfw/util"
|
|
|
"qfw/util/redis"
|
|
|
"regexp"
|
|
@@ -50,43 +46,14 @@ type ProjectInfo struct {
|
|
|
Winnerorder []string //中标候选人
|
|
|
}
|
|
|
|
|
|
-//抽取信息映射实体类
|
|
|
-type Info struct {
|
|
|
- Id string `json:"_id"`
|
|
|
- Href string `json:"href"`
|
|
|
- Publishtime int64 `json:"publishtime"`
|
|
|
- Title string `json:"title"`
|
|
|
- TopType string `json:"toptype"`
|
|
|
- SubType string `json:"subtype"`
|
|
|
- ProjectName string `json:"projectname"`
|
|
|
- ProjectCode string `json:"projectcode"`
|
|
|
- Buyer string `json:"buyer"`
|
|
|
- Buyerperson string `json:"buyerperson"`
|
|
|
- Buyertel string `json:"buyertel"`
|
|
|
- Agency string `json:"agency"`
|
|
|
- Area string `json:"area"`
|
|
|
- HasPackage bool `json:"haspackage"`
|
|
|
- Package map[string]interface{} `json:"package"`
|
|
|
- PNum string `json:"pnum"`
|
|
|
- Topscopeclass []string `json:"topscopeclass"`
|
|
|
- Subscopeclass []string `json:"subscopeclass"`
|
|
|
- Winners []string
|
|
|
- dealtype int
|
|
|
-
|
|
|
- Buyerclass string `json:"buyerclass"`
|
|
|
- Bidopentime int64 `json:"bidopentime"`
|
|
|
- District string `json:"district"`
|
|
|
- Winnerorder []string
|
|
|
-}
|
|
|
-
|
|
|
type CompareOne struct {
|
|
|
- ProjectNameType int //项目名称对比结果分类 0未比较 1相等 2包含 3不相等
|
|
|
- ProjectCodeType int //0未比较 1相等 2包含 3不相等
|
|
|
- AreaType int //0未比较 1相等 2不相等
|
|
|
- PublistimeType int //1在时间范围 2不在
|
|
|
- BuyerType int //0未比较 1相等 2包含 3不相等
|
|
|
- AgencyType int //0未比较 1相等 2包含 3不相等
|
|
|
- PackageType int //1都是多包 2都不是多包 3招标 4新信息是结果
|
|
|
+ ProjectNameType string //项目名称对比结果分类 A相等 B包含 C不相等 Dthis存在对比不存在 Ethis不存在
|
|
|
+ ProjectCodeType string //同上
|
|
|
+ BuyerType string //同上
|
|
|
+ AreaType string //同上
|
|
|
+ AgencyType string //同上
|
|
|
+ PublistimeType int //1在时间范围 2不在
|
|
|
+ PackageType int //1都是多包 2都不是多包 3招标 4新信息是结果
|
|
|
Score int
|
|
|
Parent *CompareInfo
|
|
|
Pinfo *ProjectInfo
|
|
@@ -120,104 +87,24 @@ var TitleReg = regexp.MustCompile("([一二三四五六七八九十0-9A-Za-zⅠ
|
|
|
//对比打分程序
|
|
|
func Compare(tmp map[string]interface{} /*新信息*/, pici int64) (sflag string) {
|
|
|
defer util.Catch()
|
|
|
- /***********信息预处理开始***********/
|
|
|
- //信息由map转换成Info对象
|
|
|
- bys, _ := json.Marshal(tmp)
|
|
|
- var thisinfo *Info
|
|
|
- json.Unmarshal(bys, &thisinfo)
|
|
|
+ thisinfo := PreThisInfo(tmp) //信息预处理
|
|
|
if thisinfo == nil {
|
|
|
return
|
|
|
}
|
|
|
- if len(thisinfo.Topscopeclass) == 0 {
|
|
|
- thisinfo.Topscopeclass = []string{}
|
|
|
- }
|
|
|
- if len(thisinfo.Subscopeclass) == 0 {
|
|
|
- thisinfo.Subscopeclass = []string{}
|
|
|
- }
|
|
|
- //去重
|
|
|
- thisinfo.Subscopeclass = RemoveDup(thisinfo.Subscopeclass)
|
|
|
-
|
|
|
- if len(thisinfo.Package) > 0 { //信息是否分包
|
|
|
- thisinfo.HasPackage = true
|
|
|
- } else if thisinfo.TopType == "结果" && TitleReg.MatchString(thisinfo.Title) {
|
|
|
- //当信息类型是结果时,并且标题中包含分包字样,找到包号,用以后面比较打分
|
|
|
- res := TitleReg.FindAllStringSubmatch(thisinfo.Title, -1)
|
|
|
- pnum := du.PackageNumberConvert(res[0][0])
|
|
|
- du.Debug(pnum, res)
|
|
|
- thisinfo.PNum = pnum
|
|
|
- }
|
|
|
- if thisinfo.SubType == "变更" || strings.Index(thisinfo.Title, "变更公告") > -1 || strings.Index(thisinfo.Title, "更正公告") > -1 {
|
|
|
- //当信息类型是变更或标题中含变更时
|
|
|
- if thisinfo.TopType == "招标" {
|
|
|
- //招标的变更公告过,不作处理
|
|
|
- du.Debug(thisinfo.Id, thisinfo.Href, thisinfo.ProjectName, thisinfo.ProjectCode)
|
|
|
- return
|
|
|
- } else if thisinfo.TopType == "结果" {
|
|
|
- thisinfo.SubType = "变更"
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //计算中标人
|
|
|
- winner, _ := tmp["winner"].(string)
|
|
|
- m1 := map[string]bool{}
|
|
|
- winners := []string{}
|
|
|
- if winner != "" {
|
|
|
- m1[winner] = true
|
|
|
- winners = append(winners, winner)
|
|
|
- }
|
|
|
- if thisinfo.HasPackage {
|
|
|
- packageM, _ := tmp["package"].(bson.M)
|
|
|
- for _, p := range packageM {
|
|
|
- pm, _ := p.(map[string]interface{})
|
|
|
- pw, _ := pm["winner"].(string)
|
|
|
- if pw != "" {
|
|
|
- m1[pw] = true
|
|
|
- winners = append(winners, pw)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- thisinfo.Winners = winners
|
|
|
- m1 = nil
|
|
|
- //中标候选人
|
|
|
- winnerorder := []string{}
|
|
|
- if winorders, ok := tmp["winnerorder"].([]interface{}); ok {
|
|
|
- for _, wins := range winorders {
|
|
|
- if win, ok := wins.(map[string]interface{}); ok {
|
|
|
- entname := util.ObjToString(win["entname"])
|
|
|
- if entname != "" && len([]rune(entname)) > 6 {
|
|
|
- winnerorder = append(winnerorder, entname)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- thisinfo.Winnerorder = winnerorder
|
|
|
- /***********信息预处理**结束***********/
|
|
|
- updateid := ""
|
|
|
-
|
|
|
var PN, PC, PB *CompareInfo
|
|
|
-
|
|
|
new_pn, _ := handleprojectname(thisinfo.ProjectName, thisinfo.Buyer, thisinfo.TopType) //作为判断依据
|
|
|
- /***********根据项目名称比对**开始***********/
|
|
|
if thisinfo.ProjectName != "" {
|
|
|
KEY := "pn_" + new_pn
|
|
|
PN = NewCompareInfo("pn", KEY, PNKey)
|
|
|
}
|
|
|
- /***********根据项目名称比对**结束***********/
|
|
|
-
|
|
|
- /***********根据项目编号比对**开始***********/
|
|
|
if len(thisinfo.ProjectCode) > 5 && !numreg.MatchString(thisinfo.ProjectCode) { //大于5且不是纯数字bfind
|
|
|
KEY := "pc_" + thisinfo.ProjectCode
|
|
|
PC = NewCompareInfo("pc", KEY, PCKey)
|
|
|
}
|
|
|
- /***********根据项目编号比对**结束***********/
|
|
|
-
|
|
|
- /***********根据采购单位比对**开始***********/
|
|
|
if len([]rune(thisinfo.Buyer)) > 4 {
|
|
|
KEY := "pb_" + thisinfo.Buyer
|
|
|
PB = NewCompareInfo("pb", KEY, PBKey)
|
|
|
}
|
|
|
- //分值排序
|
|
|
- tmpArr := []*CompareOne{}
|
|
|
repeatId := map[string]bool{}
|
|
|
IdLock.Lock()
|
|
|
//此处加id锁,会引进多线程的死锁,对比三个大map数组,找到key相同的项目id数组,并去重
|
|
@@ -238,13 +125,6 @@ func Compare(tmp map[string]interface{} /*新信息*/, pici int64) (sflag string
|
|
|
if !repeatId[id] {
|
|
|
newarr = append(newarr, id)
|
|
|
repeatId[id] = true
|
|
|
- idlk := IdLockMap[id]
|
|
|
- if idlk == nil {
|
|
|
- idlk = &sync.Mutex{}
|
|
|
- IdLockMap[id] = idlk
|
|
|
- }
|
|
|
- idlk.Lock()
|
|
|
- defer idlk.Unlock()
|
|
|
}
|
|
|
}
|
|
|
PNCB.IdArr = newarr
|
|
@@ -252,16 +132,20 @@ func Compare(tmp map[string]interface{} /*新信息*/, pici int64) (sflag string
|
|
|
}
|
|
|
IdLock.Unlock()
|
|
|
|
|
|
+ tmpArr := []*CompareOne{}
|
|
|
//三个对比对象分别和thisinfo比较,打完分的对象放入scores,合并放入tempArr
|
|
|
for _, PNCB := range []*CompareInfo{PN, PC, PB} {
|
|
|
if PNCB != nil {
|
|
|
if len(PNCB.IdArr) > 0 {
|
|
|
- PNCB.compute(thisinfo, PNCB.IdArr)
|
|
|
+ //PNCB.compute(thisinfo, PNCB.IdArr)
|
|
|
+ PNCB.ProcessInfo(thisinfo)
|
|
|
tmpArr = append(tmpArr, PNCB.Scores...)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
//排序取出最大分值的对象,更新对象
|
|
|
+ updateid := ""
|
|
|
if len(tmpArr) > 0 {
|
|
|
sort.Slice(tmpArr, func(i, j int) bool {
|
|
|
return tmpArr[i].Score > tmpArr[j].Score
|
|
@@ -273,16 +157,12 @@ func Compare(tmp map[string]interface{} /*新信息*/, pici int64) (sflag string
|
|
|
updateid = updateinfo(thisinfo, tmp, max.Pinfo, pici)
|
|
|
}
|
|
|
}
|
|
|
- /***********根据采购单位比对**结束***********/
|
|
|
+
|
|
|
if updateid == "" {
|
|
|
sflag = "normal"
|
|
|
updateid = InsertProject(new_pn, tmp, pici, thisinfo)
|
|
|
p1 := NewPinfo(updateid, thisinfo)
|
|
|
- //PUT = append(PUT, []interface{}{updateid, p1})
|
|
|
redis.PutCKV(REDISIDS, updateid, p1)
|
|
|
- //IdLock.Lock()
|
|
|
- //IdLockMap[updateid] = &sync.Mutex{}
|
|
|
- //IdLock.Unlock()
|
|
|
} else {
|
|
|
sflag = "repeat"
|
|
|
}
|
|
@@ -378,10 +258,10 @@ func NewPinfo(id string, thisinfo *Info) ProjectInfo {
|
|
|
Area: thisinfo.Area,
|
|
|
HasPackage: thisinfo.HasPackage,
|
|
|
Package: map[string]interface{}{},
|
|
|
- // Buyerclass: thisinfo.Buyerclass,
|
|
|
- // Bidopentime: thisinfo.Bidopentime,
|
|
|
- // District: thisinfo.District,
|
|
|
- Winnerorder: thisinfo.Winnerorder,
|
|
|
+ Buyerclass: thisinfo.Buyerclass,
|
|
|
+ Bidopentime: thisinfo.Bidopentime,
|
|
|
+ District: thisinfo.District,
|
|
|
+ Winnerorder: thisinfo.Winnerorder,
|
|
|
}
|
|
|
for k4, _ := range thisinfo.Package {
|
|
|
p1.Package[k4] = ""
|
|
@@ -616,7 +496,8 @@ func EqInfoUpdate(thisinfo *Info, pInfo *ProjectInfo) {
|
|
|
//return pInfo
|
|
|
}
|
|
|
|
|
|
-func (com *CompareInfo /*对比对象,分别含有项目名称、项目编号、采购单位*/) compute(thisinfo *Info /*新信息*/, ids []string) {
|
|
|
+/**
|
|
|
+func (com *CompareInfo) compute(thisinfo *Info, ids []string) {
|
|
|
//根据 com的key到redis中查找对应的值(如:项目名称的key为"pn_某某项目",值为一维对象数组 即:[]ProjectInfo)
|
|
|
//这些信息id上面已经加过锁
|
|
|
defer util.Catch()
|
|
@@ -752,7 +633,7 @@ func (com *CompareInfo /*对比对象,分别含有项目名称、项目编号
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+**/
|
|
|
//二分字符串查找
|
|
|
func BinarySearch(s []string, k string) int {
|
|
|
sort.Strings(s)
|