123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306 |
- package main
- import (
- qu "qfw/util"
- "regexp"
- "sync"
- "time"
- "unicode/utf8"
- )
- var sitelock sync.Mutex //锁
- var error_reason map[string]interface{}
- var abnormal_reason map[string]interface{}
- func dealWithErrorRate(tmp map[string]interface{}) (int , int, map[string]interface{}, map[string]interface{}) {
- error_reason = map[string]interface{}{}
- abnormal_reason = map[string]interface{}{}
- //错误 , 异常error_score abnormal_score,
- err_num,ab_num:=0,0
- //金额类
- budget:=qu.Float64All(tmp["budget"])
- bidamount:=qu.Float64All(tmp["bidamount"])
- if tmp["budget"]==nil&&tmp["bidamount"]==nil {
- //均不存在
- ab_num++
- abnormal_reason["money"] = "budget-bidamount均不存在"
- }else if tmp["budget"]!=nil&&tmp["bidamount"]!=nil&&budget!=0&&bidamount!=0 {
- //均存在
- err,ab:=amountAnalysis(budget,bidamount)
- err_num = err_num+err
- ab_num = err_num+ab
- }else {
- //二者存在一个
- if budget==0 && qu.ObjToString(tmp["toptype"])=="招标"{
- ab_num++
- abnormal_reason["money"] = "招标:budget空"
- }
- if bidamount==0 && qu.ObjToString(tmp["toptype"])=="结果"{
- ab_num++
- abnormal_reason["money"] = "结果:bidamount空"
- }
- }
- //采购单位
- buyer:=qu.ObjToString(tmp["buyer"])
- if buyer=="" {
- ab_num++
- abnormal_reason["buyer"] = "buyer空"
- }else {
- if utf8.RuneCountInString(buyer)<4 {
- err_num++
- error_reason["buyer"] = "buyer长度"
- }else {
- if !buyerAnalysis(buyer) {
- ab_num++
- abnormal_reason["buyer"] = "buyer-企业无"
- }
- }
- }
- //中标单位
- if qu.ObjToString(tmp["toptype"])=="结果" {
- winner:=qu.ObjToString(tmp["winner"])
- if winner=="" {
- ab_num++
- abnormal_reason["winner"] = "winner空"
- }else {
- if utf8.RuneCountInString(winner)<4 {
- err_num++
- error_reason["winner"] = "winner长度"
- }else {
- if !winnerAnalysis(winner) {
- ab_num++
- abnormal_reason["winner"] = "winner-企业无"
- }
- }
- }
- }
- //标题,名称
- title:=qu.ObjToString(tmp["title"])
- if title=="" {
- err_num++
- error_reason["title"] = "空"
- }else {
- if utf8.RuneCountInString(title)<4 {
- ab_num++
- abnormal_reason["title"] = "title长度"
- }else {
- }
- }
- projectname:=qu.ObjToString(tmp["projectname"])
- if projectname=="" {
- err_num++
- error_reason["projectname"] = "空"
- }else {
- if utf8.RuneCountInString(projectname)<4 {
- ab_num++
- abnormal_reason["projectname"] = "projectname长度"
- }else {
- }
- }
- //编号组
- projectcode:=qu.ObjToString(tmp["projectcode"])
- contractnumber:=qu.ObjToString(tmp["contractnumber"])
- if projectcode==""&&contractnumber=="" {
- ab_num++
- abnormal_reason["code"] = "code-空"
- }else {
- if !codesAnalysis(projectcode,contractnumber) {
- ab_num++
- abnormal_reason["code"] = "code-不符"
- }
- }
- //发布时间
- publishtime:=qu.Int64All(tmp["publishtime"])
- now:=time.Now().Unix()
- if publishtime<=0||publishtime-now>0 {
- err_num++
- error_reason["publishtime"] = "publishtime-(超前)(0)"
- }
- //省份,城市
- area := qu.ObjToString(tmp["area"])
- if area == "A" {
- area = "全国"
- }
- city := qu.ObjToString(tmp["city"])
- site := qu.ObjToString(tmp["site"])
- if !citysAnalysis(area,city,site) {
- ab_num++
- abnormal_reason["city"] = "area-站点不一致"
- }
- //招标时间-地点
- if qu.Int64All(tmp["bidopentime"])==0 && qu.ObjToString(tmp["bidopenaddress"])=="" &&
- qu.ObjToString(tmp["toptype"])=="招标" {
- ab_num++
- abnormal_reason["bidopen"] = "bidopen-时间-地点-空"
- }
- //类别问题
- if qu.ObjToString(tmp["toptype"]) == ""{
- err_num++
- error_reason["toptype"] = "toptype:空"
- }else {
- if !categoryAnalysis(tmp) {
- ab_num++
- abnormal_reason["toptype"] = "toptype:内容>>"
- }
- }
- return err_num,ab_num,error_reason,abnormal_reason
- }
- //分析-金额
- func amountAnalysis(budget float64,bidamount float64) (int ,int) {
- err_num,ab_num:=0,0
- proportion := bidamount/budget
- if proportion>=0.1&&proportion<=10 {
- }else if (proportion>=0.01&&proportion<0.1)||(proportion>10&&proportion<=100){
- ab_num++
- abnormal_reason["money"] = "bidamount/budget间隔异常"
- }else {
- err_num++
- error_reason["money"] = "bidamount/budget-比例错误"
- }
- return err_num,ab_num
- }
- //分析-采购单位
- func buyerAnalysis(buyer string) bool{
- q := map[string]interface{}{
- "company_name": buyer,
- }
- data :=qy_mgo.FindOne(qy_coll_name,q)
- //data,_:=qy_mgo.Find(qy_coll_name,q,nil,map[string]interface{}{"company_name":1})
- if data==nil {
- return false
- }
- return true
- }
- //分析-中标单位
- func winnerAnalysis(winner string) bool {
- q := map[string]interface{}{
- "company_name": winner,
- }
- data :=qy_mgo.FindOne(qy_coll_name,q)
- //data,_:=qy_mgo.Find(qy_coll_name,q,nil,map[string]interface{}{"company_name":1})
- if data==nil {
- return false
- }
- return true
- }
- //分析-编号组
- func codesAnalysis(projectcode string,contractnumber string) bool {
- if projectcode!="" {
- if utf8.RuneCountInString(projectcode)<4 {
- return false
- }
- //符合-8长度-日期格式 yyyyMMdd
- if !regAnalysis(projectcode) &&utf8.RuneCountInString(projectcode)==8 {
- return false
- }
- }
- if contractnumber!="" {
- if utf8.RuneCountInString(contractnumber)<4 {
- return false
- }
- if !regAnalysis(contractnumber) && utf8.RuneCountInString(projectcode)==8 {
- return false
- }
- }
- return true
- }
- //分析-省份,城市
- func citysAnalysis(area string,city string,site string) bool {
- if site != "" {//站点对比
- sitelock.Lock()
- dict := siteMap[site]
- sitelock.Unlock()
- if dict != nil {
- if (area == "全国" && dict["area"] != "") ||
- (city == "" && dict["city"] != "") {
- return false
- }
- }
- }
- return true
- }
- //分析-类别
- func categoryAnalysis(tmp map[string]interface{}) bool {
- toptype:=qu.ObjToString(tmp["toptype"])
- if toptype=="招标" {
- winner:=qu.ObjToString(tmp["winner"])
- bidamount:=qu.Float64All(tmp["bidamount"])
- if winner!=""||bidamount!=0 {
- //结果超前
- return false
- }
- }
- return true
- }
- func regAnalysis(str string) bool {
- reg:=`\d{8}`
- regx,_ := regexp.Compile(reg)
- if regx.FindString(str)!="" {
- return false
- }
- return true
- }
|