dataMethod.go 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. package main
  2. import (
  3. "math"
  4. "regexp"
  5. "strings"
  6. qutil "qfw/util"
  7. )
  8. //完善判重数据检测-前置条件
  9. func convertArabicNumeralsAndLetters(data string) string {
  10. newData :=data
  11. res1, _ := regexp.Compile("[a-zA-Z]+");
  12. if res1.MatchString(data) {
  13. newData = res1.ReplaceAllStringFunc(data, strings.ToUpper);
  14. }
  15. res2, _ := regexp.Compile("[0-9]+");
  16. if res2.MatchString(newData) {
  17. arr1:=[]string {"0","1","2","3","4","5","6","7","8","9"}
  18. arr2:=[]string {"零","一","二","三","四","五","六","七","八","九"}
  19. for i:=0 ;i<len(arr1) ;i++ {
  20. resTemp ,_:=regexp.Compile(arr1[i])
  21. newData= resTemp.ReplaceAllString(newData, arr2[i]);
  22. }
  23. }
  24. return newData
  25. }
  26. func dealWithSpecialPhrases(str1 string,str2 string) (string,string) {
  27. newStr1:=str1
  28. newStr2:=str2
  29. res, _ := regexp.Compile("重新招标");
  30. if res.MatchString(newStr1) {
  31. newStr1 = res.ReplaceAllString(newStr1,"重招");
  32. }
  33. if res.MatchString(newStr2) {
  34. newStr2 = res.ReplaceAllString(newStr2,"重招");
  35. }
  36. return newStr1,newStr2
  37. }
  38. //关键词数量v
  39. func dealWithSpecialWordNumber(info*Info,v*Info) int {
  40. okNum:=0
  41. if info.titleSpecialWord || info.specialWord {
  42. okNum++
  43. }
  44. if v.titleSpecialWord || v.specialWord {
  45. okNum++
  46. }
  47. return okNum
  48. }
  49. //关键词再次判断
  50. func againRepeat(v *Info, info *Info) bool {
  51. if isBidopentimeInterval(info.bidopentime,v.bidopentime) {
  52. return true
  53. }
  54. if v.budget != info.budget && v.budget != 0 && info.budget != 0 {
  55. return true
  56. }
  57. if isBidWinningAmount(v.bidamount,info.bidamount) && v.bidamount != 0 && info.bidamount != 0{
  58. return true
  59. }
  60. if deleteExtraSpace(v.winner) != deleteExtraSpace(info.winner) && v.winner != "" && info.winner != "" {
  61. return true
  62. }
  63. if v.contractnumber != "" && info.contractnumber != "" && v.contractnumber != info.contractnumber {
  64. return true
  65. }
  66. if v.projectcode != "" && info.projectcode != "" && v.projectcode != info.projectcode {
  67. return true
  68. }
  69. return false
  70. }
  71. ////站点再次判断
  72. //func againSite(v *Info, info *Info) bool {
  73. //
  74. // if v.budget != info.budget && v.budget != 0 && info.budget != 0 {
  75. // return true
  76. // }
  77. // if isBidWinningAmount(v.bidamount,info.bidamount) && v.bidamount != 0 && info.bidamount != 0{
  78. // return true
  79. // }
  80. // if deleteExtraSpace(v.winner) != deleteExtraSpace(info.winner) && v.winner != "" && info.winner != "" {
  81. // return true
  82. // }
  83. // if v.contractnumber != "" && info.contractnumber != "" && v.contractnumber != info.contractnumber {
  84. // return true
  85. // }
  86. // if v.projectcode != "" && info.projectcode != "" && v.projectcode != info.projectcode {
  87. // return true
  88. // }
  89. //
  90. // return false
  91. //}
  92. //删除中标单位字符串中多余的空格(含tab)
  93. func deleteExtraSpace(s string) string {
  94. //删除字符串中的多余空格,有多个空格时,仅保留一个空格
  95. s1 := strings.Replace(s, " ", " ", -1) //替换tab为空格
  96. regstr := "\\s{2,}" //两个及两个以上空格的正则表达式
  97. reg, _ := regexp.Compile(regstr) //编译正则表达式
  98. s2 := make([]byte, len(s1)) //定义字符数组切片
  99. copy(s2, s1) //将字符串复制到切片
  100. spc_index := reg.FindStringIndex(string(s2)) //在字符串中搜索
  101. for len(spc_index) > 0 { //找到适配项
  102. s2 = append(s2[:spc_index[0]+1], s2[spc_index[1]:]...) //删除多余空格
  103. spc_index = reg.FindStringIndex(string(s2)) //继续在字符串中搜索
  104. }
  105. return string(s2)
  106. }
  107. //中标金额倍率:10000
  108. func isBidWinningAmount(f1 float64 ,f2 float64) bool {
  109. if f1==f2||f1*10000==f2||f2*10000==f1 {
  110. return false
  111. }
  112. return true
  113. }
  114. //开标时间区间为一天
  115. func isBidopentimeInterval(i1 int64 ,i2 int64) bool {
  116. if i1==0||i2==0 {
  117. return false
  118. }
  119. //不在同一天-或者同一天间隔超过六小时,属于不相等返回true
  120. timeOne,timeTwo:=i1,i2
  121. day1 := qutil.FormatDateByInt64(&timeOne, qutil.Date_yyyyMMdd)
  122. day2 := qutil.FormatDateByInt64(&timeTwo, qutil.Date_yyyyMMdd)
  123. if day1==day2 {
  124. //是否间隔超过十二小时
  125. if math.Abs(float64(i1-i2)) >43200.0 {
  126. return true
  127. }else {
  128. return false
  129. }
  130. }else {
  131. return true
  132. }
  133. }
  134. //开标时间区间为一天
  135. func isTheSameDay(i1 int64 ,i2 int64) bool {
  136. if i1==0||i2==0 {
  137. return false
  138. }
  139. timeOne,timeTwo:=i1,i2
  140. day1 := qutil.FormatDateByInt64(&timeOne, qutil.Date_yyyyMMdd)
  141. day2 := qutil.FormatDateByInt64(&timeTwo, qutil.Date_yyyyMMdd)
  142. if day1==day2 {
  143. return true
  144. }
  145. return false
  146. }
  147. //前置0 五要素均相等认为重复
  148. func leadingElementSame(v *Info, info *Info) bool {
  149. isok:= 0
  150. if info.projectname != "" && v.projectname == info.projectname {
  151. isok++
  152. }
  153. if info.buyer != "" && v.buyer == info.buyer {
  154. isok++
  155. }
  156. if info.subtype == "合同" || info.subtype == "验收" || info.subtype == "违规" {
  157. if info.contractnumber != "" && v.contractnumber == info.contractnumber {
  158. isok++
  159. }
  160. }else {
  161. if info.projectcode != "" && v.projectcode == info.projectcode {
  162. isok++
  163. }
  164. }
  165. if info.title != "" && v.title == info.title {
  166. isok++
  167. }
  168. if v.agency == info.agency &&info.agency != "" {
  169. isok++
  170. }
  171. if v.winner == info.winner&&info.winner != "" {
  172. isok++
  173. }
  174. if isok>=5 {
  175. return true
  176. }
  177. return false
  178. }
  179. //buyer的优先级
  180. func buyerIsContinue(v *Info, info *Info) bool {
  181. if !isTheSameDay(info.publishtime,v.publishtime) {
  182. return true
  183. }
  184. if v.title != info.title && v.title != "" && info.title != ""{
  185. return true
  186. }
  187. if v.projectname != info.projectname && v.projectname != "" && info.projectname != ""{
  188. return true
  189. }
  190. //if v.budget != info.budget && v.budget != 0 && info.budget != 0 {
  191. // return true
  192. //}
  193. //if isBidWinningAmount(v.bidamount,info.bidamount) && v.bidamount != 0 && info.bidamount != 0{
  194. // return true
  195. //}
  196. //if deleteExtraSpace(v.winner) != deleteExtraSpace(info.winner) && v.winner != "" && info.winner != "" {
  197. // return true
  198. //}
  199. if v.contractnumber != "" && info.contractnumber != "" && v.contractnumber != info.contractnumber {
  200. return true
  201. }
  202. if v.projectcode != "" && info.projectcode != "" && v.projectcode != info.projectcode {
  203. return true
  204. }
  205. return false
  206. }
  207. //无效数据
  208. func invalidData(d1 string, d2 string, d3 string, d4 string) bool {
  209. var n int
  210. if d1 != "" {
  211. n++
  212. }
  213. if d2 != "" {
  214. n++
  215. }
  216. if d3 != "" {
  217. n++
  218. }
  219. if d4 != "" {
  220. n++
  221. }
  222. if n == 0 {
  223. return true
  224. }
  225. return false
  226. }