package iot import ( "context" "github.com/gogf/gf/v2/errors/gerror" "git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/dao" "git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/library/xgorm/handler" "git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/model" "git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/model/entity" "git.5iot.com/iotlcm-public/iotlcm-admin-svr/internal/service" ) // EnqueueSimCardStatus is intentionally separate from SyncSimCardStatus. It // keeps the tenant/permission-filtered card lookup in Admin, then publishes a // complete routing message so Worker can process it asynchronously. func (s *sIotTSimCardInfo) EnqueueSimCardStatus(ctx context.Context, input *model.SyncSimCardStatusInput) error { if input == nil || input.Iccid == "" { return gerror.New("iccid is required") } var card entity.TSimCardInfo if err := s.Model(ctx, &handler.Option{FilterTenant: true, FilterAuth: true}). Where(dao.TSimCardInfo.Columns().Iccid, input.Iccid). Limit(1). Scan(&card); err != nil { return gerror.Wrap(err, "load card for queued status sync") } if card.Id <= 0 || card.ChanKey == "" { return gerror.New("card not found or channel is empty") } var channel entity.TSimChannels channelQuery := dao.TSimChannels.Ctx(ctx). Where(dao.TSimChannels.Columns().ChanKey, card.ChanKey) if card.TenantId != "" { channelQuery = channelQuery.Where(dao.TSimChannels.Columns().TenantId, card.TenantId) } if err := channelQuery.Limit(1).Scan(&channel); err != nil { return gerror.Wrap(err, "load channel for queued status sync") } if channel.ChanKey == "" || channel.TempKey == "" { return gerror.New("channel template is empty") } return service.SimStatusQueue().EnqueueCard(ctx, model.SimStatusQueueTaskMessage{ CardID: card.Id, ICCID: card.Iccid, MSISDN: card.Msisdn, IMSI: card.Imsi, ChanKey: card.ChanKey, TempKey: channel.TempKey, Operator: channel.Operator, }) }