chore: 并入 iotlcm-worker-svr 历史到 worker-svr/(原提交 96f0f4e)

This commit is contained in:
MiFaZhan
2026-11-02 13:28:03 +08:00
422 changed files with 80993 additions and 0 deletions
@@ -0,0 +1,54 @@
package renewchange
import (
"crypto/rand"
"fmt"
"strings"
"time"
"github.com/gogf/gf/v2/errors/gerror"
)
const businessNoAlphabet = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789"
// NextOrderSN returns a production order number before any INSERT is issued.
func NextOrderSN(now time.Time) (string, error) {
suffix, err := randomBusinessNoSuffix(8)
if err != nil {
return "", err
}
return fmt.Sprintf("SO%s%s", now.Format("20060102150405"), suffix), nil
}
func randomBusinessNoSuffix(length int) (string, error) {
if length <= 0 {
return "", gerror.New("business number suffix length must be greater than zero")
}
randomBytes := make([]byte, length)
if _, err := rand.Read(randomBytes); err != nil {
return "", gerror.Wrap(err, "generate business number suffix failed")
}
buf := make([]byte, length)
for i, value := range randomBytes {
buf[i] = businessNoAlphabet[int(value)%len(businessNoAlphabet)]
}
return string(buf), nil
}
// GenerateOrderSn 形如 "yyyyMMddHHmmssfff"+6位随机后缀
func GenerateOrderSn(t *time.Time) string {
now := time.Now()
if t != nil {
now = *t
}
return fmt.Sprintf("%s%06d", now.UTC().Format("20060102150405.000")[0:14], now.Nanosecond()/1000%1000000)
}
// GenerateSubscriptionNo 形如 "SUB" + yyyyMMddHHmmss + 6位后缀
func GenerateSubscriptionNo(prefix string) string {
now := time.Now()
if strings.TrimSpace(prefix) == "" {
prefix = "SUB"
}
return fmt.Sprintf("%s%s%06d", prefix, now.UTC().Format("20060102150405"), now.Nanosecond()/1000%1000000)
}