fonchain-fiee/pkg/service/bundle/common/contractNo.go

31 lines
657 B
Go
Raw Normal View History

2025-03-12 02:56:27 +00:00
package common
import (
"fmt"
"strconv"
"time"
)
// GenerateContractNo 生成 contractNo 规则 YYYY-MM-DD-xxxxx xxxxx 是从 00001 开始 自增
func GenerateContractNo(lastContractNo string) string {
prefix := time.Now().Format("2006-01-02") + "-"
if lastContractNo == "" {
2025-03-12 07:58:23 +00:00
return prefix + "00001"
2025-03-12 02:56:27 +00:00
}
suffix := lastContractNo[11:]
suffixInt, _ := strconv.ParseInt(suffix, 10, 64)
if suffixInt >= 99999 {
suffixInt = suffixInt + 1
return prefix + strconv.FormatInt(suffixInt, 10)
} else {
suffixInt = suffixInt + 1
suffix = strconv.FormatInt(suffixInt, 10)
suffix = fmt.Sprintf("%05d", suffixInt)
return prefix + suffix
}
}