chore: 并入 iotlcm-upstream-chan 历史到 upstream-chan/(原提交 1e74497)

This commit is contained in:
MiFaZhan
2026-11-02 13:28:02 +08:00
192 changed files with 33119 additions and 0 deletions
@@ -0,0 +1,288 @@
package upstreamimpl
import (
"strings"
"git.5iot.com/iotlcm-public/iotlcm-upstream-chan/internal/consts"
"git.5iot.com/iotlcm-public/iotlcm-upstream-chan/internal/model"
"github.com/gogf/gf/v2/util/gconv"
)
func pickSimQueryParam(simKey *model.SimKey) (string, string) {
if simKey == nil {
return "", ""
}
if value := strings.TrimSpace(simKey.ICCID); value != "" {
return "iccid", value
}
if value := strings.TrimSpace(simKey.MSISDN); value != "" {
return "msisdn", value
}
if value := strings.TrimSpace(simKey.IMSI); value != "" {
return "imsi", value
}
return "", ""
}
func ydBasicInfoHasIdentity(iccid, msisdn, imsi string) bool {
return strings.TrimSpace(iccid) != "" || strings.TrimSpace(msisdn) != "" || strings.TrimSpace(imsi) != ""
}
func mapYdStopReasonText(stopReason string) string {
value := strings.TrimSpace(stopReason)
if len(value) == 12 && strings.Trim(value, "02") == "" {
if value == "000000000000" {
return "未停机或系统暂无停机原因"
}
var reasons []string
for _, code := range []struct {
position int
label string
}{
{0, "窄带网商品到期失效停机"},
{1, "机卡分离停机"},
{3, "M2M管理停机"},
{4, "信控双向停机"},
{8, "主动申请双向停机"},
{9, "区域限制管理型停机"},
{10, "强制双向停机"},
} {
if value[code.position] == '2' {
reasons = append(reasons, code.label)
}
}
if len(reasons) > 0 {
if strings.Count(value, "2") == len(reasons) {
return strings.Join(reasons, "、")
}
return strings.Join(reasons, "、") + " (原始码: " + value + ")"
}
}
switch value {
case "":
return "未停机"
case "000000000000":
return "未停机或系统暂无停机原因"
case "000000000020":
return "强制双向停机"
case "000000002000":
return "主动申请双向停机"
case "000020000000":
return "信控双向停机"
case "020000000000":
return "机卡分离停机"
case "000200000000":
return "M2M管理停机"
case "000000000200":
return "区域限制管理型停机"
default:
return value
}
}
func mapYdFrozenStatusText(frozenStatus string) string {
value := strings.TrimSpace(frozenStatus)
switch value {
case "", "0":
return "未冻结"
case "1":
return "已冻结"
default:
return value
}
}
func mapYdOperatingStatus(status string) string {
switch strings.ToUpper(strings.TrimSpace(status)) {
case "1", "01", "ON", "ONLINE":
return "1"
case "0", "00", "OFF", "OFFLINE", "-1":
return "0"
default:
return consts.CardSessionStatusUnknown
}
}
func mapYdDeviceStatus(status string) string {
return mapYdOperatingStatus(status)
}
func mapDxOperatingStatus(status string) string {
switch strings.TrimSpace(status) {
case "0":
// Telecom NQ007: 0 = power on, 1 = power off.
return "1"
case "1":
return "0"
default:
return consts.CardSessionStatusUnknown
}
}
func pickYdCardBindStatus(result map[string]any) string {
if len(result) == 0 {
return ""
}
if value := strings.TrimSpace(toString(result["result"])); value != "" {
switch value {
case "0", "1", "2":
return value
case "OK", "ok":
return "1"
}
}
for _, key := range []string{"bind_status", "bindStatus", "cardBindStatus", "cardBindingType", "status"} {
value := strings.TrimSpace(toString(result[key]))
switch value {
case "0", "1":
return value
case "OK", "ok":
return "1"
}
}
return ""
}
func pickYdCardBindStatusErrorCode(result map[string]any) string {
if len(result) == 0 {
return ""
}
for _, key := range []string{"errorCode", "error_code", "errCode", "errcode"} {
value := strings.TrimSpace(toString(result[key]))
if value != "" {
return value
}
}
return ""
}
func pickYdCardBindStatusErrorDes(result map[string]any) string {
if len(result) == 0 {
return ""
}
for _, key := range []string{"errorDes", "error_des", "errDes", "errMsg", "message"} {
value := strings.TrimSpace(toString(result[key]))
if value != "" {
return value
}
}
return ""
}
func toString(value any) string {
return strings.TrimSpace(gconv.String(value))
}
func mapDxStopTypeListText(stopTypeList []string) string {
if len(stopTypeList) == 0 {
return "未停机"
}
texts := make([]string, 0, len(stopTypeList))
for _, stopType := range stopTypeList {
switch strings.TrimSpace(stopType) {
case "":
continue
case "100000":
texts = append(texts, "申请停机")
case "110000":
texts = append(texts, "挂失停机")
case "120000":
texts = append(texts, "停机保号")
case "130000":
texts = append(texts, "欠费停机")
case "130001":
texts = append(texts, "欠费单停")
case "130002":
texts = append(texts, "欠费双停")
case "140000":
texts = append(texts, "预拆机停机")
case "150000":
texts = append(texts, "违章停机")
case "150001":
texts = append(texts, "未实名制违规停机")
case "160000":
texts = append(texts, "数据异常停机")
case "170000":
texts = append(texts, "局方原因停机")
case "180000":
texts = append(texts, "强制停机")
case "190000":
texts = append(texts, "超范围使用违规停机")
case "200000":
texts = append(texts, "去激活停机")
case "210000":
texts = append(texts, "紧急停机")
case "220000":
texts = append(texts, "安全事件关停")
case "230000":
texts = append(texts, "到期停机")
case "240000":
texts = append(texts, "公免到期停机")
case "250000":
texts = append(texts, "限额管控停机")
case "260000":
texts = append(texts, "欺诈停机")
case "270000":
texts = append(texts, "模组融合停机")
case "280100":
texts = append(texts, "区域限制停机")
default:
texts = append(texts, strings.TrimSpace(stopType))
}
}
if len(texts) == 0 {
return "未停机"
}
return strings.Join(texts, "、")
}
func mapDxRegionLimitStatus(areaLimitType string, areaLimitInfo string) string {
areaLimitType = strings.TrimSpace(areaLimitType)
areaLimitInfo = strings.TrimSpace(areaLimitInfo)
if areaLimitType == "" || areaLimitType == "-1" || areaLimitType == "0" {
if areaLimitInfo == "" {
return "1"
}
}
return "0"
}
func mapDxRegionLimitStatusByOrder(orderStatus string, limitStatus string) string {
orderStatus = strings.TrimSpace(orderStatus)
limitStatus = strings.TrimSpace(limitStatus)
switch {
case orderStatus == "1":
return "2"
case orderStatus == "0" && limitStatus == "0":
return "1"
case orderStatus == "0" && limitStatus == "1":
return "0"
case orderStatus == "0" && limitStatus == "-":
return "2"
default:
return "2"
}
}
func normalizeDxRegionLimitDetails(orderStatus string, limitStatus string, limitType string, limitArea string) (string, string, string) {
if strings.TrimSpace(orderStatus) != "0" {
return "", "", ""
}
switch strings.TrimSpace(limitStatus) {
case "0", "1", "-":
limitStatus = strings.TrimSpace(limitStatus)
default:
limitStatus = ""
}
switch strings.TrimSpace(limitType) {
case "1", "2", "3", "4":
limitType = strings.TrimSpace(limitType)
default:
limitType = ""
}
return limitStatus, limitType, strings.TrimSpace(limitArea)
}