Files
huang e049080f6c
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m47s
分裂iccid长度
2026-04-21 10:55:12 +08:00

23 lines
692 B
Go
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package utils
// SplitICCID 按 ICCID 长度拆分为双列存储值
//
// 规则:
// - 19 位卡:返回 (iccid, nil)iccid_20 写入 NULL
// - 20 位卡:返回 (iccid[:19], &iccid),两列均有值
// - 其他长度:返回 ("", nil),调用方应将对应卡标记为失败
//
// 注意iccid_20 必须为 *string 而非 stringGORM 才会将 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
}
}