分裂iccid长度
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m47s
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m47s
This commit is contained in:
22
pkg/utils/iccid.go
Normal file
22
pkg/utils/iccid.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package utils
|
||||
|
||||
// SplitICCID 按 ICCID 长度拆分为双列存储值
|
||||
//
|
||||
// 规则:
|
||||
// - 19 位卡:返回 (iccid, nil),iccid_20 写入 NULL
|
||||
// - 20 位卡:返回 (iccid[:19], &iccid),两列均有值
|
||||
// - 其他长度:返回 ("", nil),调用方应将对应卡标记为失败
|
||||
//
|
||||
// 注意:iccid_20 必须为 *string 而非 string,GORM 才会将 nil 写入 SQL NULL
|
||||
// 若使用 string 类型,空字符串 "" 不会被转为 NULL,会破坏 Partial Index 语义
|
||||
func SplitICCID(iccid string) (iccid19 string, iccid20 *string) {
|
||||
switch len(iccid) {
|
||||
case 19:
|
||||
return iccid, nil
|
||||
case 20:
|
||||
prefix := iccid[:19]
|
||||
return prefix, &iccid
|
||||
default:
|
||||
return "", nil
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user