123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- package assist
- import (
- "fmt"
- "git.bvbej.com/bvbej/base-golang/pkg/time_parse"
- "math"
- "math/rand"
- "regexp"
- "strconv"
- "time"
- "unicode"
- )
- func GetOrderNumber() string {
- parse, _ := time.Parse(time_parse.CSTLayout, "2021-06-01 00:00:00")
- hours := time.Now().Sub(parse).Hours()
- day := math.Floor(hours / 24)
- prefix := fmt.Sprintf("%05d", int64(day))
- format := time.Now().Format("") + "%0" + strconv.Itoa(10) + "d"
- n := math.Pow10(10)
- return prefix + fmt.Sprintf(format, rand.New(rand.NewSource(time.Now().UnixNano())).Int63n(int64(n)))
- }
- func StringInArray(str string, strArray []string) bool {
- for _, s := range strArray {
- if str == s {
- return true
- }
- }
- return false
- }
- func Uint64InArray(str uint64, uint64Array []uint64) bool {
- for _, s := range uint64Array {
- if str == s {
- return true
- }
- }
- return false
- }
- func CurrencyDecimal(value float64) float64 {
- value, _ = strconv.ParseFloat(fmt.Sprintf("%.8f", value), 64)
- return value
- }
- func IsChinese(str string) bool {
- var count int
- for _, v := range str {
- if unicode.Is(unicode.Han, v) {
- count++
- break
- }
- }
- return count > 0
- }
- func RandInt(max int) int {
- rand.Seed(time.Now().UnixNano())
- <-time.After(time.Nanosecond)
- return rand.Intn(max)
- }
- func StringUniqueInArray(valueArray []string) []string {
- result := make([]string, 0, len(valueArray))
- temp := map[string]struct{}{}
- for _, item := range valueArray {
- if _, ok := temp[item]; !ok {
- temp[item] = struct{}{}
- result = append(result, item)
- }
- }
- return result
- }
- func Uint64UniqueInArray(valueArray []uint64) []uint64 {
- result := make([]uint64, 0, len(valueArray))
- temp := map[uint64]struct{}{}
- for _, item := range valueArray {
- if _, ok := temp[item]; !ok {
- temp[item] = struct{}{}
- result = append(result, item)
- }
- }
- return result
- }
- func FindIPv4(input string) string {
- partIp := "(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])"
- must := partIp + "\\." + partIp + "\\." + partIp + "\\." + partIp
- matchMe := regexp.MustCompile(must)
- return matchMe.FindString(input)
- }
- func RandString(n int) string {
- var letterRunes = []rune("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
- b := make([]rune, n)
- for i := range b {
- b[i] = letterRunes[RandInt(len(letterRunes))]
- }
- return string(b)
- }
|