sync: 对齐小程序 v1.0.2 生产代码并脱敏
This commit is contained in:
@@ -2,7 +2,6 @@ package app
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"git.5iot.com/iotlcm-public/iotlcm-app/internal/dao"
|
||||
@@ -10,23 +9,53 @@ import (
|
||||
"git.5iot.com/iotlcm-public/iotlcm-app/internal/model/entity"
|
||||
|
||||
"github.com/gogf/gf/v2/errors/gerror"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
type appCardChannelInfo struct {
|
||||
ChanKey string
|
||||
ChanName string
|
||||
ChanAlias string
|
||||
TempKey string
|
||||
ChanKey string
|
||||
ChanName string
|
||||
ChanAlias string
|
||||
TempKey string
|
||||
ChanStatus int
|
||||
}
|
||||
|
||||
type appCardChannelAssocRecord struct {
|
||||
Id int64 `orm:"id"`
|
||||
ChannelID string `orm:"channel_id"`
|
||||
MatchType int `orm:"match_type"`
|
||||
Iccid string `orm:"iccid"`
|
||||
IccidStart string `orm:"iccid_start"`
|
||||
IccidEnd string `orm:"iccid_end"`
|
||||
Status int `orm:"status"`
|
||||
func (s *sAppCard) findDiagnosisAssocChannel(ctx context.Context, tenantId string, iccid string) (*appCardChannelInfo, error) {
|
||||
iccid = strings.TrimSpace(iccid)
|
||||
if iccid == "" {
|
||||
return nil, nil
|
||||
}
|
||||
var assoc *struct {
|
||||
ChannelKey string `orm:"channel_id"`
|
||||
}
|
||||
base := g.DB().Model("card_channel_assoc").Ctx(ctx).Fields("channel_id").Where("status", 1)
|
||||
var err error
|
||||
err = base.Clone().Where("match_type", 1).Where("iccid COLLATE utf8mb4_general_ci = ?", iccid).
|
||||
OrderDesc("id").Limit(1).Scan(&assoc)
|
||||
if err != nil {
|
||||
return nil, gerror.Wrap(err, "查询卡通道单卡关联失败")
|
||||
}
|
||||
if assoc == nil || strings.TrimSpace(assoc.ChannelKey) == "" {
|
||||
err = base.Clone().Where("match_type", 2).
|
||||
Where("iccid_start COLLATE utf8mb4_general_ci <= ?", iccid).
|
||||
Where("iccid_end COLLATE utf8mb4_general_ci >= ?", iccid).
|
||||
OrderDesc("id").Limit(1).Scan(&assoc)
|
||||
if err != nil {
|
||||
return nil, gerror.Wrap(err, "查询卡通道号段关联失败")
|
||||
}
|
||||
}
|
||||
if assoc == nil || strings.TrimSpace(assoc.ChannelKey) == "" {
|
||||
return nil, nil
|
||||
}
|
||||
if tenantId = strings.TrimSpace(tenantId); tenantId == "" {
|
||||
tenantId = contexts.GetTenantId(ctx)
|
||||
}
|
||||
channel, err := s.findCardChannelEntityByKey(ctx, tenantId, assoc.ChannelKey)
|
||||
if err != nil || channel != nil || tenantId == "" {
|
||||
return appCardChannelInfoFromEntity(channel), err
|
||||
}
|
||||
channel, err = s.findCardChannelEntityByKey(ctx, "", assoc.ChannelKey)
|
||||
return appCardChannelInfoFromEntity(channel), err
|
||||
}
|
||||
|
||||
func (s *sAppCard) attachCardChannelInfo(ctx context.Context, row *appCardQueryRow) error {
|
||||
@@ -109,128 +138,44 @@ func (s *sAppCard) loadCardChannelInfo(ctx context.Context, tenantId string, icc
|
||||
}
|
||||
|
||||
func (s *sAppCard) loadDiagnosisCardChannelInfo(ctx context.Context, tenantId string, iccid string, legacyChanKey string) (*appCardChannelInfo, error) {
|
||||
iccid = strings.TrimSpace(iccid)
|
||||
tenantId = strings.TrimSpace(tenantId)
|
||||
legacyChanKey = strings.TrimSpace(legacyChanKey)
|
||||
if iccid != "" {
|
||||
info, err := s.findAssocCardChannelInfo(ctx, tenantId, iccid)
|
||||
card, err := queryLegacyDiagnosisCard(ctx, iccid)
|
||||
if err != nil || card == nil {
|
||||
return nil, err
|
||||
}
|
||||
return s.findLegacyCardChannelInfo(ctx, tenantId, card.ChannelKey)
|
||||
}
|
||||
|
||||
// resolveLifecycleCardChannelInfo resolves a writable card operation channel.
|
||||
// Card ownership still comes from the current platform; the legacy database is
|
||||
// only a read-only fallback for the channel code.
|
||||
func (s *sAppCard) resolveLifecycleCardChannelInfo(ctx context.Context, tenantId string, iccid string, currentChanKey string) (*appCardChannelInfo, error) {
|
||||
currentChanKey = strings.TrimSpace(currentChanKey)
|
||||
if currentChanKey != "" {
|
||||
info, err := s.findLegacyCardChannelInfo(ctx, tenantId, currentChanKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if info != nil {
|
||||
if appCardChannelAvailable(info) {
|
||||
return info, nil
|
||||
}
|
||||
}
|
||||
if legacyChanKey == "" {
|
||||
return nil, nil
|
||||
}
|
||||
return s.findLegacyCardChannelInfo(ctx, tenantId, legacyChanKey)
|
||||
}
|
||||
|
||||
func (s *sAppCard) findAssocCardChannelInfo(ctx context.Context, tenantId string, iccid string) (*appCardChannelInfo, error) {
|
||||
if strings.TrimSpace(iccid) == "" {
|
||||
return nil, nil
|
||||
card, err := queryLegacyDiagnosisCard(ctx, strings.TrimSpace(iccid))
|
||||
if err != nil || card == nil || strings.TrimSpace(card.ICCID) != strings.TrimSpace(iccid) {
|
||||
return nil, err
|
||||
}
|
||||
assoc, err := s.resolveCardChannelAssocByIccid(ctx, iccid)
|
||||
info, err := s.findLegacyCardChannelInfo(ctx, tenantId, card.ChannelKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if assoc == nil || strings.TrimSpace(assoc.ChannelID) == "" {
|
||||
if !appCardChannelAvailable(info) {
|
||||
return nil, nil
|
||||
}
|
||||
info, err := s.findCardChannelInfoByRef(ctx, tenantId, assoc.ChannelID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if info == nil || strings.TrimSpace(info.ChanKey) == "" {
|
||||
return nil, gerror.New("卡通道关联已匹配,但未找到对应通道配置")
|
||||
}
|
||||
return info, nil
|
||||
}
|
||||
|
||||
func (s *sAppCard) resolveCardChannelAssocByIccid(ctx context.Context, iccid string) (*appCardChannelAssocRecord, error) {
|
||||
iccid = strings.TrimSpace(iccid)
|
||||
if iccid == "" {
|
||||
return nil, nil
|
||||
}
|
||||
columns := dao.CardChannelAssoc.Columns()
|
||||
|
||||
var exact *appCardChannelAssocRecord
|
||||
err := dao.CardChannelAssoc.Ctx(ctx).
|
||||
Fields(columns.Id, columns.ChannelId, columns.MatchType, columns.Iccid, columns.IccidStart, columns.IccidEnd, columns.Status).
|
||||
Where(columns.Status, 1).
|
||||
Where(columns.MatchType, 1).
|
||||
Where(columns.Iccid+" COLLATE utf8mb4_general_ci = ?", iccid).
|
||||
OrderDesc(columns.Id).
|
||||
Limit(1).
|
||||
Scan(&exact)
|
||||
if err != nil {
|
||||
return nil, gerror.Wrap(err, "查询卡通道单卡关联失败")
|
||||
}
|
||||
if exact != nil && strings.TrimSpace(exact.ChannelID) != "" {
|
||||
return exact, nil
|
||||
}
|
||||
|
||||
var ranged *appCardChannelAssocRecord
|
||||
err = dao.CardChannelAssoc.Ctx(ctx).
|
||||
Fields(columns.Id, columns.ChannelId, columns.MatchType, columns.Iccid, columns.IccidStart, columns.IccidEnd, columns.Status).
|
||||
Where(columns.Status, 1).
|
||||
Where(columns.MatchType, 2).
|
||||
Where(columns.IccidStart+" COLLATE utf8mb4_general_ci <= ? AND "+columns.IccidEnd+" COLLATE utf8mb4_general_ci >= ?", iccid, iccid).
|
||||
OrderDesc(columns.Id).
|
||||
Limit(1).
|
||||
Scan(&ranged)
|
||||
if err != nil {
|
||||
return nil, gerror.Wrap(err, "查询卡通道号段关联失败")
|
||||
}
|
||||
if ranged != nil && strings.TrimSpace(ranged.ChannelID) != "" {
|
||||
return ranged, nil
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (s *sAppCard) findCardChannelInfoByRef(ctx context.Context, tenantId string, channelRef string) (*appCardChannelInfo, error) {
|
||||
channelRef = strings.TrimSpace(channelRef)
|
||||
if channelRef == "" {
|
||||
return nil, nil
|
||||
}
|
||||
if id, err := strconv.ParseInt(channelRef, 10, 64); err == nil && id > 0 {
|
||||
if info, err := s.findCardChannelInfoByID(ctx, tenantId, id); err != nil || info != nil {
|
||||
return info, err
|
||||
}
|
||||
}
|
||||
return s.findLegacyCardChannelInfo(ctx, tenantId, channelRef)
|
||||
}
|
||||
|
||||
func (s *sAppCard) findCardChannelInfoByID(ctx context.Context, tenantId string, channelID int64) (*appCardChannelInfo, error) {
|
||||
if channelID <= 0 {
|
||||
return nil, nil
|
||||
}
|
||||
if tenantId = strings.TrimSpace(tenantId); tenantId == "" {
|
||||
tenantId = contexts.GetTenantId(ctx)
|
||||
}
|
||||
if tenantId != "" {
|
||||
channel, err := s.findCardChannelEntityByID(ctx, tenantId, channelID)
|
||||
if err != nil || channel != nil {
|
||||
return appCardChannelInfoFromEntity(channel), err
|
||||
}
|
||||
}
|
||||
channel, err := s.findCardChannelEntityByID(ctx, "", channelID)
|
||||
return appCardChannelInfoFromEntity(channel), err
|
||||
}
|
||||
|
||||
func (s *sAppCard) findCardChannelEntityByID(ctx context.Context, tenantId string, channelID int64) (*entity.TSimChannels, error) {
|
||||
var channel *entity.TSimChannels
|
||||
mod := dao.TSimChannels.Ctx(ctx).
|
||||
Where(dao.TSimChannels.Columns().Id, channelID)
|
||||
if tenantId = strings.TrimSpace(tenantId); tenantId != "" {
|
||||
mod = mod.Where(dao.TSimChannels.Columns().TenantId, tenantId)
|
||||
}
|
||||
err := mod.Limit(1).Scan(&channel)
|
||||
if err != nil {
|
||||
return nil, gerror.Wrap(err, "查询通道信息失败")
|
||||
}
|
||||
return channel, nil
|
||||
func appCardChannelAvailable(info *appCardChannelInfo) bool {
|
||||
return info != nil && strings.TrimSpace(info.ChanKey) != "" && info.ChanStatus == 0
|
||||
}
|
||||
|
||||
func (s *sAppCard) findLegacyCardChannelInfo(ctx context.Context, tenantId string, chanKey string) (*appCardChannelInfo, error) {
|
||||
@@ -255,7 +200,7 @@ func (s *sAppCard) findCardChannelEntityByKey(ctx context.Context, tenantId stri
|
||||
var channel *entity.TSimChannels
|
||||
mod := dao.TSimChannels.Ctx(ctx).
|
||||
Where(dao.TSimChannels.Columns().ChanKey, chanKey).
|
||||
Fields(dao.TSimChannels.Columns().Id, dao.TSimChannels.Columns().ChanKey, dao.TSimChannels.Columns().ChanName, dao.TSimChannels.Columns().ChanAlias, dao.TSimChannels.Columns().TempKey)
|
||||
Fields(dao.TSimChannels.Columns().Id, dao.TSimChannels.Columns().ChanKey, dao.TSimChannels.Columns().ChanName, dao.TSimChannels.Columns().ChanAlias, dao.TSimChannels.Columns().TempKey, dao.TSimChannels.Columns().ChanStatus)
|
||||
if tenantId = strings.TrimSpace(tenantId); tenantId != "" {
|
||||
mod = mod.Where(dao.TSimChannels.Columns().TenantId, tenantId)
|
||||
}
|
||||
@@ -274,9 +219,10 @@ func appCardChannelInfoFromEntity(channel *entity.TSimChannels) *appCardChannelI
|
||||
return nil
|
||||
}
|
||||
return &appCardChannelInfo{
|
||||
ChanKey: strings.TrimSpace(channel.ChanKey),
|
||||
ChanName: strings.TrimSpace(channel.ChanName),
|
||||
ChanAlias: strings.TrimSpace(channel.ChanAlias),
|
||||
TempKey: strings.TrimSpace(channel.TempKey),
|
||||
ChanKey: strings.TrimSpace(channel.ChanKey),
|
||||
ChanName: strings.TrimSpace(channel.ChanName),
|
||||
ChanAlias: strings.TrimSpace(channel.ChanAlias),
|
||||
TempKey: strings.TrimSpace(channel.TempKey),
|
||||
ChanStatus: channel.ChanStatus,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user