scoreExpError.go 5.7 KB

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