scoreExpError.go 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. package main
  2. import (
  3. qu "qfw/util"
  4. "regexp"
  5. "sync"
  6. "time"
  7. "unicode/utf8"
  8. )
  9. var sitelock sync.Mutex //锁
  10. var error_reason map[string]interface{}
  11. var abnormal_reason map[string]interface{}
  12. func dealWithErrorRate(tmp map[string]interface{}) (int , int, map[string]interface{}, map[string]interface{}) {
  13. error_reason = map[string]interface{}{}
  14. abnormal_reason = map[string]interface{}{}
  15. //错误 , 异常error_score abnormal_score,
  16. err_num,ab_num:=0,0
  17. //金额类
  18. budget:=qu.Float64All(tmp["budget"])
  19. bidamount:=qu.Float64All(tmp["bidamount"])
  20. if tmp["budget"]==nil&&tmp["bidamount"]==nil {
  21. //均不存在
  22. ab_num++
  23. abnormal_reason["money"] = "budget-bidamount均不存在"
  24. }else if tmp["budget"]!=nil&&tmp["bidamount"]!=nil&&budget!=0&&bidamount!=0 {
  25. //均存在
  26. err,ab:=amountAnalysis(budget,bidamount)
  27. err_num = err_num+err
  28. ab_num = err_num+ab
  29. }else {
  30. //二者存在一个
  31. if budget==0 && qu.ObjToString(tmp["toptype"])=="招标"{
  32. ab_num++
  33. abnormal_reason["money"] = "招标:budget空"
  34. }
  35. if bidamount==0 && qu.ObjToString(tmp["toptype"])=="结果"{
  36. ab_num++
  37. abnormal_reason["money"] = "结果:bidamount空"
  38. }
  39. }
  40. //采购单位
  41. buyer:=qu.ObjToString(tmp["buyer"])
  42. if buyer=="" {
  43. ab_num++
  44. abnormal_reason["buyer"] = "buyer空"
  45. }else {
  46. if utf8.RuneCountInString(buyer)<4 {
  47. err_num++
  48. error_reason["buyer"] = "buyer长度"
  49. }else {
  50. if !buyerAnalysis(buyer) {
  51. ab_num++
  52. abnormal_reason["buyer"] = "buyer-企业无"
  53. }
  54. }
  55. }
  56. //中标单位
  57. if qu.ObjToString(tmp["toptype"])=="结果" {
  58. winner:=qu.ObjToString(tmp["winner"])
  59. if winner=="" {
  60. ab_num++
  61. abnormal_reason["winner"] = "winner空"
  62. }else {
  63. if utf8.RuneCountInString(winner)<4 {
  64. err_num++
  65. error_reason["winner"] = "winner长度"
  66. }else {
  67. if !winnerAnalysis(winner) {
  68. ab_num++
  69. abnormal_reason["winner"] = "winner-企业无"
  70. }
  71. }
  72. }
  73. }
  74. //标题,名称
  75. title:=qu.ObjToString(tmp["title"])
  76. if title=="" {
  77. err_num++
  78. error_reason["title"] = "空"
  79. }else {
  80. if utf8.RuneCountInString(title)<4 {
  81. ab_num++
  82. abnormal_reason["title"] = "title长度"
  83. }else {
  84. }
  85. }
  86. projectname:=qu.ObjToString(tmp["projectname"])
  87. if projectname=="" {
  88. err_num++
  89. error_reason["projectname"] = "空"
  90. }else {
  91. if utf8.RuneCountInString(projectname)<4 {
  92. ab_num++
  93. abnormal_reason["projectname"] = "projectname长度"
  94. }else {
  95. }
  96. }
  97. //编号组
  98. projectcode:=qu.ObjToString(tmp["projectcode"])
  99. contractnumber:=qu.ObjToString(tmp["contractnumber"])
  100. if projectcode==""&&contractnumber=="" {
  101. ab_num++
  102. abnormal_reason["code"] = "code-空"
  103. }else {
  104. if !codesAnalysis(projectcode,contractnumber) {
  105. ab_num++
  106. abnormal_reason["code"] = "code-不符"
  107. }
  108. }
  109. //发布时间
  110. publishtime:=qu.Int64All(tmp["publishtime"])
  111. now:=time.Now().Unix()
  112. if publishtime<=0||publishtime-now>0 {
  113. err_num++
  114. error_reason["publishtime"] = "publishtime-(超前)(0)"
  115. }
  116. //省份,城市
  117. area := qu.ObjToString(tmp["area"])
  118. if area == "A" {
  119. area = "全国"
  120. }
  121. city := qu.ObjToString(tmp["city"])
  122. site := qu.ObjToString(tmp["site"])
  123. if !citysAnalysis(area,city,site) {
  124. ab_num++
  125. abnormal_reason["city"] = "area-站点不一致"
  126. }
  127. //招标时间-地点
  128. if qu.Int64All(tmp["bidopentime"])==0 && qu.ObjToString(tmp["bidopenaddress"])=="" &&
  129. qu.ObjToString(tmp["toptype"])=="招标" {
  130. ab_num++
  131. abnormal_reason["bidopen"] = "bidopen-时间-地点-空"
  132. }
  133. //类别问题
  134. if qu.ObjToString(tmp["toptype"]) == ""{
  135. err_num++
  136. error_reason["toptype"] = "toptype:空"
  137. }else {
  138. if !categoryAnalysis(tmp) {
  139. ab_num++
  140. abnormal_reason["toptype"] = "toptype:内容>>"
  141. }
  142. }
  143. return err_num,ab_num,error_reason,abnormal_reason
  144. }
  145. //分析-金额
  146. func amountAnalysis(budget float64,bidamount float64) (int ,int) {
  147. err_num,ab_num:=0,0
  148. proportion := bidamount/budget
  149. if proportion>=0.1&&proportion<=10 {
  150. }else if (proportion>=0.01&&proportion<0.1)||(proportion>10&&proportion<=100){
  151. ab_num++
  152. abnormal_reason["money"] = "bidamount/budget间隔异常"
  153. }else {
  154. err_num++
  155. error_reason["money"] = "bidamount/budget-比例错误"
  156. }
  157. return err_num,ab_num
  158. }
  159. //分析-采购单位
  160. func buyerAnalysis(buyer string) bool{
  161. q := map[string]interface{}{
  162. "company_name": buyer,
  163. }
  164. data :=qy_mgo.FindOne(qy_coll_name,q)
  165. //data,_:=qy_mgo.Find(qy_coll_name,q,nil,map[string]interface{}{"company_name":1})
  166. if data==nil {
  167. return false
  168. }
  169. return true
  170. }
  171. //分析-中标单位
  172. func winnerAnalysis(winner string) bool {
  173. q := map[string]interface{}{
  174. "company_name": winner,
  175. }
  176. data :=qy_mgo.FindOne(qy_coll_name,q)
  177. //data,_:=qy_mgo.Find(qy_coll_name,q,nil,map[string]interface{}{"company_name":1})
  178. if data==nil {
  179. return false
  180. }
  181. return true
  182. }
  183. //分析-编号组
  184. func codesAnalysis(projectcode string,contractnumber string) bool {
  185. if projectcode!="" {
  186. if utf8.RuneCountInString(projectcode)<4 {
  187. return false
  188. }
  189. //符合-8长度-日期格式 yyyyMMdd
  190. if !regAnalysis(projectcode) &&utf8.RuneCountInString(projectcode)==8 {
  191. return false
  192. }
  193. }
  194. if contractnumber!="" {
  195. if utf8.RuneCountInString(contractnumber)<4 {
  196. return false
  197. }
  198. if !regAnalysis(contractnumber) && utf8.RuneCountInString(projectcode)==8 {
  199. return false
  200. }
  201. }
  202. return true
  203. }
  204. //分析-省份,城市
  205. func citysAnalysis(area string,city string,site string) bool {
  206. if site != "" {//站点对比
  207. sitelock.Lock()
  208. dict := siteMap[site]
  209. sitelock.Unlock()
  210. if dict != nil {
  211. if (area == "全国" && dict["area"] != "") ||
  212. (city == "" && dict["city"] != "") {
  213. return false
  214. }
  215. }
  216. }
  217. return true
  218. }
  219. //分析-类别
  220. func categoryAnalysis(tmp map[string]interface{}) bool {
  221. toptype:=qu.ObjToString(tmp["toptype"])
  222. if toptype=="招标" {
  223. winner:=qu.ObjToString(tmp["winner"])
  224. bidamount:=qu.Float64All(tmp["bidamount"])
  225. if winner!=""||bidamount!=0 {
  226. //结果超前
  227. return false
  228. }
  229. }
  230. return true
  231. }
  232. func regAnalysis(str string) bool {
  233. reg:=`\d{8}`
  234. regx,_ := regexp.Compile(reg)
  235. if regx.FindString(str)!="" {
  236. return false
  237. }
  238. return true
  239. }