dataMethod.go 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. package main
  2. import (
  3. "math"
  4. qutil "qfw/util"
  5. "regexp"
  6. "strings"
  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. if v.projectname != info.projectname && v.projectname != "" && info.projectname != ""{
  70. return true
  71. }
  72. return false
  73. }
  74. //均含有关键词再次判断
  75. func againContainSpecialWord (v *Info, info *Info) bool {
  76. if isBidopentimeInterval(info.bidopentime,v.bidopentime) {
  77. return true
  78. }
  79. if v.budget != info.budget && v.budget != 0 && info.budget != 0 {
  80. return true
  81. }
  82. if isBidWinningAmount(v.bidamount,info.bidamount) && v.bidamount != 0 && info.bidamount != 0{
  83. return true
  84. }
  85. if deleteExtraSpace(v.winner) != deleteExtraSpace(info.winner) && v.winner != "" && info.winner != "" {
  86. return true
  87. }
  88. if v.contractnumber != "" && info.contractnumber != "" && v.contractnumber != info.contractnumber {
  89. return true
  90. }
  91. if v.projectcode != "" && info.projectcode != "" && v.projectcode != info.projectcode {
  92. return true
  93. }
  94. //提取标题-标段号处理
  95. if dealTitleSpecial(v.title,info.title) {
  96. return true
  97. }
  98. return false
  99. }
  100. //提取标题-标段号处理
  101. func dealTitleSpecial(title1 string,title2 string) bool{
  102. regular1 := "(包|标段|标包)[((]?[0-9a-zA-Z一二三四五六七八九十零123456789][))]?"
  103. regular2 := "[0-9a-zA-Z一二三四五六七八九十零123456789](包|标段|标包)"
  104. regx1_1,_ := regexp.Compile(regular1)
  105. str1:=regx1_1.FindString(title1)
  106. if str1!="" {
  107. //log.Println("标题1,规则一提取:",str1)
  108. }else {
  109. regx1_2,_ := regexp.Compile(regular2)
  110. str1=regx1_2.FindString(title1)
  111. if str1!="" {
  112. //log.Println("标题1,规则二提取:",str1)
  113. }
  114. }
  115. regx2_1,_ := regexp.Compile(regular1)
  116. str2:=regx2_1.FindString(title2)
  117. if str2!="" {
  118. //log.Println("标题2,规则一提取:",str2)
  119. }else {
  120. regx2_2,_ := regexp.Compile(regular2)
  121. str2=regx2_2.FindString(title2)
  122. if str2!="" {
  123. //log.Println("标题2,规则二提取:",str2)
  124. }
  125. }
  126. //根据提取的结果,在进行清洗
  127. if str1!="" {
  128. str1 = deleteExtraSpace(str1)
  129. str1= strings.Replace(str1, "(", "", -1)
  130. str1= strings.Replace(str1, "(", "", -1)
  131. str1= strings.Replace(str1, ")", "", -1)
  132. str1= strings.Replace(str1, ")", "", -1)
  133. str1 = convertArabicNumeralsAndLetters(str1)
  134. }
  135. if str2!="" {
  136. str2 = deleteExtraSpace(str2)
  137. str2= strings.Replace(str2, "(", "", -1)
  138. str2= strings.Replace(str2, "(", "", -1)
  139. str2= strings.Replace(str2, ")", "", -1)
  140. str2= strings.Replace(str2, ")", "", -1)
  141. str2 = convertArabicNumeralsAndLetters(str2)
  142. }
  143. //log.Println("最终:",str1,str2)
  144. if str1!=str2 {
  145. //log.Println("不一致")
  146. return true
  147. }else {
  148. //log.Println("一致")
  149. return false
  150. }
  151. }
  152. //删除中标单位字符串中多余的空格(含tab)
  153. func deleteExtraSpace(s string) string {
  154. //删除字符串中的多余空格,有多个空格时,仅保留一个空格
  155. s1 := strings.Replace(s, " ", " ", -1) //替换tab为空格
  156. regstr := "\\s{2,}" //两个及两个以上空格的正则表达式
  157. reg, _ := regexp.Compile(regstr) //编译正则表达式
  158. s2 := make([]byte, len(s1)) //定义字符数组切片
  159. copy(s2, s1) //将字符串复制到切片
  160. spc_index := reg.FindStringIndex(string(s2)) //在字符串中搜索
  161. for len(spc_index) > 0 { //找到适配项
  162. s2 = append(s2[:spc_index[0]+1], s2[spc_index[1]:]...) //删除多余空格
  163. spc_index = reg.FindStringIndex(string(s2)) //继续在字符串中搜索
  164. }
  165. return string(s2)
  166. }
  167. //中标金额倍率:10000
  168. func isBidWinningAmount(f1 float64 ,f2 float64) bool {
  169. if f1==f2||f1*10000==f2||f2*10000==f1 {
  170. return false
  171. }
  172. return true
  173. }
  174. //时间间隔周期
  175. func isTimeIntervalPeriod(i1 int64 ,i2 int64) bool {
  176. if math.Abs(float64(i1-i2)) < 172800.0 {
  177. return true
  178. }else {
  179. return false //大于48小时
  180. }
  181. }
  182. //开标时间区间为一天
  183. func isBidopentimeInterval(i1 int64 ,i2 int64) bool {
  184. if i1==0||i2==0 {
  185. return false
  186. }
  187. //不在同一天-或者同一天间隔超过六小时,属于不相等返回true
  188. timeOne,timeTwo:=i1,i2
  189. day1 := qutil.FormatDateByInt64(&timeOne, qutil.Date_yyyyMMdd)
  190. day2 := qutil.FormatDateByInt64(&timeTwo, qutil.Date_yyyyMMdd)
  191. if day1==day2 {
  192. //是否间隔超过十二小时
  193. if math.Abs(float64(i1-i2)) >43200.0 {
  194. return true
  195. }else {
  196. return false
  197. }
  198. }else {
  199. return true
  200. }
  201. }
  202. //开标时间区间为一天
  203. func isTheSameDay(i1 int64 ,i2 int64) bool {
  204. if i1==0||i2==0 {
  205. return false
  206. }
  207. timeOne,timeTwo:=i1,i2
  208. day1 := qutil.FormatDateByInt64(&timeOne, qutil.Date_yyyyMMdd)
  209. day2 := qutil.FormatDateByInt64(&timeTwo, qutil.Date_yyyyMMdd)
  210. if day1==day2 {
  211. return true
  212. }
  213. return false
  214. }
  215. //前置0 五要素均相等认为重复
  216. func leadingElementSame(v *Info, info *Info) bool {
  217. isok:= 0
  218. if info.projectname != "" && v.projectname == info.projectname {
  219. isok++
  220. }
  221. if info.buyer != "" && v.buyer == info.buyer {
  222. isok++
  223. }
  224. if info.subtype == "合同" || info.subtype == "验收" || info.subtype == "违规" {
  225. if info.contractnumber != "" && v.contractnumber == info.contractnumber {
  226. isok++
  227. }
  228. }else {
  229. if info.projectcode != "" && v.projectcode == info.projectcode {
  230. isok++
  231. }
  232. }
  233. if info.title != "" && v.title == info.title {
  234. isok++
  235. }
  236. if v.agency == info.agency &&info.agency != "" {
  237. isok++
  238. }
  239. if v.winner == info.winner&&info.winner != "" {
  240. isok++
  241. }
  242. if isok>=5 {
  243. return true
  244. }
  245. return false
  246. }
  247. //buyer的优先级
  248. func buyerIsContinue(v *Info, info *Info) bool {
  249. if !isTheSameDay(info.publishtime,v.publishtime) {
  250. return true
  251. }
  252. if v.title != info.title && v.title != "" && info.title != ""{
  253. return true
  254. }
  255. if v.projectname != info.projectname && v.projectname != "" && info.projectname != ""{
  256. return true
  257. }
  258. //if v.budget != info.budget && v.budget != 0 && info.budget != 0 {
  259. // return true
  260. //}
  261. //if isBidWinningAmount(v.bidamount,info.bidamount) && v.bidamount != 0 && info.bidamount != 0{
  262. // return true
  263. //}
  264. //if deleteExtraSpace(v.winner) != deleteExtraSpace(info.winner) && v.winner != "" && info.winner != "" {
  265. // return true
  266. //}
  267. if v.contractnumber != "" && info.contractnumber != "" && v.contractnumber != info.contractnumber {
  268. return true
  269. }
  270. if v.projectcode != "" && info.projectcode != "" && v.projectcode != info.projectcode {
  271. return true
  272. }
  273. return false
  274. }
  275. //无效数据
  276. func invalidData(d1 string, d2 string, d3 string, d4 string) bool {
  277. var n int
  278. if d1 != "" {
  279. n++
  280. }
  281. if d2 != "" {
  282. n++
  283. }
  284. if d3 != "" {
  285. n++
  286. }
  287. if d4 != "" {
  288. n++
  289. }
  290. if n == 0 {
  291. return true
  292. }
  293. return false
  294. }