Files
servicebase/pkg/helper/NumberHelper.go
2025-11-18 17:48:20 +08:00

372 lines
7.1 KiB
Go

package helper
import (
"encoding/json"
"github.com/anxpp/beego/logs"
"strconv"
"strings"
)
type NumberInfo struct {
Level int
Rule map[string]bool
}
// 计算号码的登记
func Calc(src int64) NumberInfo {
level := 0
rule := make(map[string]bool)
number := strconv.FormatInt(src, 10)
length := len(number)
// 尾号AAA
checkEndAAA := length >= 3 && number[length-1] == number[length-2] && number[length-2] == number[length-3]
if checkEndAAA {
level++
}
rule["EndAAA"] = checkEndAAA
// 尾号ABAB
checkABAB := length >= 4 && number[length-4] == number[length-2] && number[length-3] == number[length-1]
if checkABAB {
level++
}
rule["EndABAB"] = checkABAB
// 尾号AABB
checkAABB := length >= 4 && number[length-4] == number[length-3] && number[length-2] == number[length-1]
if checkAABB {
level++
}
rule["EndAABB"] = checkAABB
// 520
check520 := strings.HasSuffix(number, "520")
if check520 {
level++
}
rule["520"] = check520
// 1314
check1314 := strings.HasSuffix(number, "1314")
if check1314 {
level++
}
rule["1314"] = check1314
// 5201314
check5201314 := strings.HasSuffix(number, "5201314")
if check5201314 {
level++
}
rule["5201314"] = check5201314
// AAA
checkAAA := _checkRepeat(number, 3)
if checkAAA {
level++
}
rule["AAA"] = checkAAA
// AAAA
checkAAAA := _checkRepeat(number, 4)
if checkAAAA {
level++
}
rule["AAAA"] = checkAAAA
// AAAAA
checkAAAAA := _checkRepeat(number, 5)
if checkAAAAA {
level++
level++
}
rule["AAAAA"] = checkAAAAA
// AAAAAA
checkAAAAAA := _checkRepeat(number, 6)
if checkAAAAAA {
level++
}
rule["AAAAAA"] = checkAAAAAA
// AAAAAAA
checkAAAAAAA := _checkRepeat(number, 7)
if checkAAAAAAA {
level++
}
rule["AAAAAAA"] = checkAAAAAAA
// AAAAAAA
checkAAAAAAAA := _checkRepeat(number, 8)
if checkAAAAAAAA {
level++
}
rule["AAAAAAAA"] = checkAAAAAAAA
// ABCABC
checkABCABC := _checkABCABC(number)
if checkABCABC {
level++
}
rule["ABCABC"] = checkABCABC
// AABBCC
checkAABBCC := _checkAABBCC(number)
if checkAABBCC {
level++
}
rule["AABBCC"] = checkAABBCC
// ABABAB
checkABABAB := _checkABABAB(number)
if checkABABAB {
level++
}
rule["ABABAB"] = checkABABAB
// AAABBB
checkAAABBB := _checkAAABBB(number)
if checkAAABBB {
level++
}
rule["AAABBB"] = checkAAABBB
// ABBABB
checkABBABB := _checkABBABB(number)
if checkABBABB {
level++
}
rule["ABBABB"] = checkABBABB
// ABBCBB
checkABBCBB := _checkABBCBB(number)
if checkABBCBB {
level++
}
rule["ABBCBB"] = checkABBCBB
// BBCBBA
checkBBCBBA := _checkBBCBBA(number)
if checkBBCBBA {
level++
}
rule["BBCBBA"] = checkBBCBBA
// AABAAB
checkAABAAB := _checkAABAAB(number)
if checkAABAAB {
level++
}
rule["AABAAB"] = checkAABAAB
// 102030
check102030 := _check102030(number)
if check102030 {
level++
}
rule["102030"] = check102030
// 010203
check010203 := _check010203(number)
if check010203 {
level++
}
rule["010203"] = check010203
// AABBB
checkAABBB := _checkAABBB(number)
if checkAABBB {
level++
}
rule["AABBB"] = checkAABBB
// 123
check123 := _checkIncrease(number, 3)
if check123 {
level++
}
rule["123"] = check123
// 123
check1234 := _checkIncrease(number, 4)
if check1234 {
level++
}
rule["1234"] = check1234
// 123
check12345 := _checkIncrease(number, 5)
if check12345 {
level++
}
rule["12345"] = check12345
// 123
check123456 := _checkIncrease(number, 6)
if check123456 {
level++
}
rule["123456"] = check123456
// 123
check1234567 := _checkIncrease(number, 7)
if check1234567 {
level++
}
rule["1234567"] = check1234567
info := NumberInfo{level, rule}
bytes, _ := json.Marshal(info)
if src%100000 == 0 {
logs.Info(number + ": " + string(bytes))
}
return info
}
func _checkRepeat(number string, length int) bool {
count := 1
old := ' '
for _, ch := range number {
if ch == old {
count++
if count == length {
return true
}
continue
}
old = ch
count = 1
}
return false
}
func _checkIncrease(number string, length int) bool {
count := 0
old := ' '
for _, ch := range number {
if count <= 0 {
count++
if count == length {
return true
}
old = ch
continue
}
if ch == old+1 {
count++
if count == length {
return true
}
old = ch
continue
}
old = ch
count = 0
}
return false
}
func _checkABCABC(number string) bool {
length := len(number)
if length >= 6 {
for i := 3; i < length-2; i++ {
if number[i-3] == number[i] && number[i-2] == number[i+1] && number[i-1] == number[i+2] {
return true
}
}
}
return false
}
func _checkABBABB(number string) bool {
length := len(number)
if length >= 6 {
for i := 3; i < length-2; i++ {
if number[i-3] == number[i] && number[i-2] == number[i+1] && number[i-1] == number[i+2] && number[i-2] == number[i-1] {
return true
}
}
}
return false
}
func _checkABBCBB(number string) bool {
length := len(number)
if length >= 6 {
for i := 3; i < length-2; i++ {
if number[i-2] == number[i-1] && number[i-1] == number[i+1] && number[i+1] == number[i+2] {
return true
}
}
}
return false
}
func _checkBBCBBA(number string) bool {
length := len(number)
if length >= 6 {
for i := 3; i < length-2; i++ {
if number[i-3] == number[i-2] && number[i-2] == number[i] && number[i] == number[i+1] {
return true
}
}
}
return false
}
func _checkAABAAB(number string) bool {
length := len(number)
if length >= 6 {
for i := 3; i < length-2; i++ {
if number[i-3] == number[i] && number[i-3] == number[i-2] && number[i-2] == number[i+1] && number[i-1] == number[i+2] {
return true
}
}
}
return false
}
func _check102030(number string) bool {
length := len(number)
if length >= 6 {
for i := 3; i < length-2; i++ {
if number[i-2] == number[i] && number[i] == number[i+2] && number[i-3]-number[i-1] == number[i-1]-number[i+1] {
return true
}
}
}
return false
}
func _check010203(number string) bool {
length := len(number)
if length >= 6 {
for i := 3; i < length-2; i++ {
if number[i-2]-number[i] == number[i]-number[i+2] && number[i-3] == number[i-1] && number[i-1] == number[i+1] {
return true
}
}
}
return false
}
func _checkAABBCC(number string) bool {
length := len(number)
if length >= 6 {
for i := 3; i < length-2; i++ {
if number[i-3] == number[i-2] && number[i-1] == number[i] && number[i+1] == number[i+2] {
return true
}
}
}
return false
}
func _checkABABAB(number string) bool {
length := len(number)
if length >= 6 {
for i := 3; i < length-2; i++ {
if number[i-3] == number[i-1] && number[i-1] == number[i+1] && number[i-2] == number[i] && number[i] == number[i+2] {
return true
}
}
}
return false
}
func _checkAAABBB(number string) bool {
length := len(number)
if length >= 6 {
for i := 3; i < length-2; i++ {
if number[i-3] == number[i-2] && number[i-2] == number[i-1] && number[i] == number[i+1] && number[i+1] == number[i+2] {
return true
}
}
}
return false
}
func _checkAABBB(number string) bool {
length := len(number)
if length >= 5 {
for i := 3; i < length-2; i++ {
if number[i-3] == number[i-2] && number[i-1] == number[i] && number[i] == number[i+1] {
return true
}
}
}
return false
}