dataMethod.go 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. package src1
  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. //删除中标单位字符串中多余的空格(含tab)
  72. func deleteExtraSpace(s string) string {
  73. //删除字符串中的多余空格,有多个空格时,仅保留一个空格
  74. s1 := strings.Replace(s, " ", " ", -1) //替换tab为空格
  75. regstr := "\\s{2,}" //两个及两个以上空格的正则表达式
  76. reg, _ := regexp.Compile(regstr) //编译正则表达式
  77. s2 := make([]byte, len(s1)) //定义字符数组切片
  78. copy(s2, s1) //将字符串复制到切片
  79. spc_index := reg.FindStringIndex(string(s2)) //在字符串中搜索
  80. for len(spc_index) > 0 { //找到适配项
  81. s2 = append(s2[:spc_index[0]+1], s2[spc_index[1]:]...) //删除多余空格
  82. spc_index = reg.FindStringIndex(string(s2)) //继续在字符串中搜索
  83. }
  84. return string(s2)
  85. }
  86. //中标金额倍率:10000
  87. func isBidWinningAmount(f1 float64 ,f2 float64) bool {
  88. if f1==f2||f1*10000==f2||f2*10000==f1 {
  89. return false
  90. }
  91. return true
  92. }
  93. //开标时间区间为一天
  94. func isBidopentimeInterval(i1 int64 ,i2 int64) bool {
  95. if i1==0||i2==0 {
  96. return false
  97. }
  98. //不在同一天-或者同一天间隔超过六小时,属于不相等返回true
  99. timeOne,timeTwo:=i1,i2
  100. day1 := qutil.FormatDateByInt64(&timeOne, qutil.Date_yyyyMMdd)
  101. day2 := qutil.FormatDateByInt64(&timeTwo, qutil.Date_yyyyMMdd)
  102. if day1==day2 {
  103. //是否间隔超过六小时
  104. if math.Abs(float64(i1-i2)) >43200.0 {
  105. return true
  106. }else {
  107. return false
  108. }
  109. }else {
  110. return true
  111. }
  112. }
  113. //开标时间区间为一天
  114. func isTheSameDay(i1 int64 ,i2 int64) bool {
  115. if i1==0||i2==0 {
  116. return false
  117. }
  118. timeOne,timeTwo:=i1,i2
  119. day1 := qutil.FormatDateByInt64(&timeOne, qutil.Date_yyyyMMdd)
  120. day2 := qutil.FormatDateByInt64(&timeTwo, qutil.Date_yyyyMMdd)
  121. if day1==day2 {
  122. return true
  123. }
  124. return false
  125. }
  126. //前置0 五要素均相等认为重复
  127. func leadingElementSame(v *Info, info *Info) bool {
  128. isok:= 0
  129. if info.projectname != "" && v.projectname == info.projectname {
  130. isok++
  131. }
  132. if info.buyer != "" && v.buyer == info.buyer {
  133. isok++
  134. }
  135. if info.subtype == "合同" || info.subtype == "验收" || info.subtype == "违规" {
  136. if info.contractnumber != "" && v.contractnumber == info.contractnumber {
  137. isok++
  138. }
  139. }else {
  140. if info.projectcode != "" && v.projectcode == info.projectcode {
  141. isok++
  142. }
  143. }
  144. if info.title != "" && v.title == info.title {
  145. isok++
  146. }
  147. if v.agency == info.agency {
  148. isok++
  149. }
  150. if v.winner == info.winner&&info.winner != "" {
  151. isok++
  152. }
  153. if isok>=5 {
  154. return true
  155. }
  156. return false
  157. }
  158. //buyer的优先级
  159. func buyerIsContinue(v *Info, info *Info) bool {
  160. if !isTheSameDay(info.publishtime,v.publishtime) {
  161. return true
  162. }
  163. if v.title != info.title && v.title != "" && info.title != ""{
  164. return true
  165. }
  166. if v.projectname != info.projectname && v.projectname != "" && info.projectname != ""{
  167. return true
  168. }
  169. //if v.budget != info.budget && v.budget != 0 && info.budget != 0 {
  170. // return true
  171. //}
  172. //if isBidWinningAmount(v.bidamount,info.bidamount) && v.bidamount != 0 && info.bidamount != 0{
  173. // return true
  174. //}
  175. //if deleteExtraSpace(v.winner) != deleteExtraSpace(info.winner) && v.winner != "" && info.winner != "" {
  176. // return true
  177. //}
  178. if v.contractnumber != "" && info.contractnumber != "" && v.contractnumber != info.contractnumber {
  179. return true
  180. }
  181. if v.projectcode != "" && info.projectcode != "" && v.projectcode != info.projectcode {
  182. return true
  183. }
  184. return false
  185. }
  186. //无效数据
  187. func invalidData(d1 string, d2 string, d3 string, d4 string) bool {
  188. var n int
  189. if d1 != "" {
  190. n++
  191. }
  192. if d2 != "" {
  193. n++
  194. }
  195. if d3 != "" {
  196. n++
  197. }
  198. if d4 != "" {
  199. n++
  200. }
  201. if n == 0 {
  202. return true
  203. }
  204. return false
  205. }