123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- // scores
- package main
- import (
- "encoding/json"
- "fmt"
- "log"
- "qfw/util"
- "qfw/util/redis"
- "strings"
- )
- //有效值三选一、三选二
- var ThreeToTow, ThreeToOne map[string]bool
- func init() {
- ThreeToTow = map[string]bool{}
- ThreeToOne = map[string]bool{
- "AAA": true,
- "AAB": true,
- }
- tows := [][][]string{
- [][]string{
- []string{"A", "B"},
- []string{"A", "B"},
- []string{"A", "B"},
- },
- [][]string{
- []string{"A", "B"},
- []string{"D", "E"},
- []string{"A", "B"},
- },
- [][]string{
- []string{"A", "B"},
- []string{"A", "B"},
- []string{"D", "E"},
- },
- [][]string{
- []string{"D", "E"},
- []string{"A", "B"},
- []string{"A", "B"},
- },
- }
- for _, tow := range tows {
- for _, v1 := range tow[0] {
- for _, v2 := range tow[1] {
- for _, v3 := range tow[2] {
- key := fmt.Sprintf("%s%s%s", v1, v2, v3)
- ThreeToTow[key] = true
- }
- }
- }
- }
- }
- //三选一打分
- func (com *CompareInfo) ComputeOne(thisinfo *Info, ids []string) []*CompareOne {
- defer util.Catch()
- res := redis.Mget(REDISIDS, ids)
- scores := []*CompareOne{}
- if len(res) > 0 { //找到项目名称、项目编号或采购单位相同时
- for _, b1 := range res { //遍历对象数组
- if b1 != nil {
- var info ProjectInfo
- err := json.Unmarshal(b1.([]byte), &info)
- if err != nil {
- log.Println(err)
- }
- cone := &CompareOne{
- Parent: com,
- Pinfo: &info,
- }
- if com.Field == "pn" { //比较字段项目名称
- if len(info.ProjectName) > 0 {
- if thisinfo.ProjectName == info.ProjectName { //A
- cone.Score += 2
- cone.ProjectNameType = "A"
- } else if strings.Index(info.ProjectName, thisinfo.ProjectName) > -1 || strings.Index(thisinfo.ProjectName, info.ProjectName) > -1 { //B
- cone.Score += 1
- cone.ProjectNameType = "B"
- } else { //C
- cone.Score -= 2
- cone.ProjectNameType = "C"
- }
- } else { //D不计分
- cone.ProjectNameType = "D"
- }
- }
- if com.Field == "pc" { //比较字段项目编号
- if len(info.ProjectCode) > 0 {
- if thisinfo.ProjectCode == info.ProjectCode { //A
- cone.Score += 2
- cone.ProjectCodeType = "A"
- } else if strings.Index(info.ProjectCode, thisinfo.ProjectCode) > -1 || strings.Index(thisinfo.ProjectCode, info.ProjectCode) > -1 { //B
- cone.Score += 1
- cone.ProjectCodeType = "B"
- } else { //C
- cone.Score -= 2
- cone.ProjectCodeType = "C"
- }
- } else { //D不计分
- cone.ProjectCodeType = "D"
- }
- }
- if thisinfo.Area != "A" && thisinfo.Area != "全国" && info.Area != "A" && info.Area != "全国" {
- if thisinfo.Area == info.Area && thisinfo.District == info.District {
- cone.Score += 2
- cone.AreaType = "A"
- } else {
- cone.Score -= 1
- cone.AreaType = "C"
- }
- } else {
- cone.Score += 1
- cone.AreaType = "B"
- }
- if len([]rune(info.Agency)) > 0 {
- if thisinfo.Agency == info.Agency { //A
- cone.Score += 2
- cone.AgencyType = "A"
- } else if strings.Index(info.Agency, thisinfo.Agency) > -1 || strings.Index(thisinfo.Agency, info.Agency) > -1 { //B
- cone.Score += 1
- cone.AgencyType = "B"
- } else {
- if len(thisinfo.Agency) < 1 { //E
- cone.Score -= 1
- cone.AgencyType = "E"
- } else { //C
- cone.Score -= 2
- cone.AgencyType = "C"
- }
- }
- } else { //D不计分
- cone.AgencyType = "D"
- }
- scores = append(scores, cone)
- }
- }
- }
- return scores
- }
- //三选二打分
- func (com *CompareInfo) ComputeTow(thisinfo *Info, ids []string, hasbyer bool) []*CompareOne {
- defer util.Catch()
- res := redis.Mget(REDISIDS, ids)
- scores := []*CompareOne{}
- if len(res) > 0 { //找到项目名称、项目编号或采购单位相同时
- for _, b1 := range res { //遍历对象数组
- if b1 != nil {
- var info ProjectInfo
- err := json.Unmarshal(b1.([]byte), &info)
- if err != nil {
- log.Println(err)
- }
- cone := &CompareOne{
- Parent: com,
- Pinfo: &info,
- }
- cone.BuyerType, cone.Score = fieldPCBScore(thisinfo.Buyer, info.Buyer, cone.BuyerType, cone.Score)
- if hasbyer {
- cone.ProjectNameType, cone.Score = fieldPCBScore(thisinfo.ProjectName, info.ProjectName, cone.ProjectNameType, cone.Score)
- cone.ProjectCodeType, cone.Score = fieldPCBScore(thisinfo.ProjectCode, info.ProjectCode, cone.ProjectCodeType, cone.Score)
- } else { //无采购单位,打分考虑长度
- if len([]rune(thisinfo.ProjectName)) > 5 {
- cone.ProjectNameType, cone.Score = fieldPCBScore(thisinfo.ProjectName, info.ProjectName, cone.ProjectNameType, cone.Score)
- } else {
- cone.ProjectNameType = "D"
- }
- if len(thisinfo.ProjectCode) > 6 {
- cone.ProjectCodeType, cone.Score = fieldPCBScore(thisinfo.ProjectCode, info.ProjectCode, cone.ProjectCodeType, cone.Score)
- } else {
- cone.ProjectCodeType = "D"
- }
- }
- //省市打分
- if thisinfo.Area != "A" && thisinfo.Area != "全国" && info.Area != "A" && info.Area != "全国" {
- if thisinfo.Area == info.Area && thisinfo.City == info.City {
- cone.Score += 2
- } else {
- cone.Score -= 1
- }
- } else {
- cone.Score += 1
- }
- //代理机构打分
- if len([]rune(info.Agency)) > 0 {
- if thisinfo.Agency == info.Agency { //A
- cone.Score += 2
- } else if strings.Index(info.Agency, thisinfo.Agency) > -1 || strings.Index(thisinfo.Agency, info.Agency) > -1 { //B
- cone.Score += 1
- } else {
- if len(thisinfo.Agency) < 1 { //E
- cone.Score -= 1
- } else { //C
- cone.Score -= 2
- }
- }
- } else { //D不计分
- //
- }
- scores = append(scores, cone)
- }
- }
- }
- return scores
- }
- //项目名称、项目编号、采购单位打分
- func fieldPCBScore(this, info, ctype string, score int) (string, int) {
- if len(info) > 0 {
- if this == info { //A
- score += 5
- ctype = "A"
- } else if strings.Index(info, this) > -1 || strings.Index(this, info) > -1 { //B
- score += 2
- ctype = "B"
- } else {
- if len(this) < 1 { //E
- score -= 1
- ctype = "E"
- } else { //C
- score -= 2
- ctype = "C"
- }
- }
- } else { //D不计分
- ctype = "D"
- }
- return ctype, score
- }
|