feat(手机号资产关联): AUG26-009 手机号—资产关联、十项上限与后台解绑
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 9m2s
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 9m2s
- 新增成对迁移 000223(tb_phone_asset_association,含有效关系部分唯一索引与 down 守卫)与 000224(解绑导入任务表),不回填历史 - H5:need_bind_phone 三支判定(开关关闭完全短路);已有主号幂等建联;十项上限按手机号 advisory 串行化(含换绑到全新号的并发场景);换绑原子迁移与冲突整单回滚;不写遗留列 - 后台:关联列表、单项/批量解绑、CSV 导入解绑(B1–B16),超管/平台 gate + 资产数据范围复核,三态统一文案 - 读侧:卡/设备列表与详情按页一次 IN 聚合;两类导出补「关联手机号」列并保留历史表头反解兼容 - 脱敏:关联审计走独立动作/资源只写脱敏手机号;访问日志手机号类字段脱敏 - 同步主 Spec openspec/specs/phone-asset-association 并归档 AUG26-009,补齐 requirement-evidence 与入口矩阵,context-health 通过
This commit is contained in:
51
internal/service/asset/resolve_identifier.go
Normal file
51
internal/service/asset/resolve_identifier.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package asset
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gorm.io/gorm"
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/internal/store/postgres"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/constants"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/errors"
|
||||
)
|
||||
|
||||
// ResolveIdentifier 按资产标识定位资产:(资产类型, 资产ID)。
|
||||
// 先查全局标识注册表,再按设备与卡的既有标识回退,与资产详情解析口径一致;
|
||||
// 未命中返回空类型,由调用方按「不可区分」处理。
|
||||
func ResolveIdentifier(
|
||||
ctx context.Context,
|
||||
registry *postgres.AssetIdentifierStore,
|
||||
cardStore *postgres.IotCardStore,
|
||||
deviceStore *postgres.DeviceStore,
|
||||
identifier string,
|
||||
) (string, uint, error) {
|
||||
if registry != nil {
|
||||
record, err := registry.FindByIdentifier(ctx, identifier)
|
||||
if err != nil {
|
||||
return "", 0, errors.Wrap(errors.CodeDatabaseError, err, "查询资产标识失败")
|
||||
}
|
||||
if record != nil {
|
||||
return record.AssetType, record.AssetID, nil
|
||||
}
|
||||
}
|
||||
if deviceStore != nil {
|
||||
device, err := deviceStore.GetByIdentifier(ctx, identifier)
|
||||
if err == nil && device != nil {
|
||||
return constants.AssetTypeDevice, device.ID, nil
|
||||
}
|
||||
if err != nil && err != gorm.ErrRecordNotFound {
|
||||
return "", 0, errors.Wrap(errors.CodeDatabaseError, err, "查询设备失败")
|
||||
}
|
||||
}
|
||||
if cardStore != nil {
|
||||
card, err := cardStore.GetByIdentifier(ctx, identifier)
|
||||
if err == nil && card != nil {
|
||||
return constants.AssetTypeIotCard, card.ID, nil
|
||||
}
|
||||
if err != nil && err != gorm.ErrRecordNotFound {
|
||||
return "", 0, errors.Wrap(errors.CodeDatabaseError, err, "查询卡失败")
|
||||
}
|
||||
}
|
||||
return "", 0, nil
|
||||
}
|
||||
@@ -52,6 +52,7 @@ type Service struct {
|
||||
iotCardService IotCardRefresher
|
||||
gatewayClient *gateway.Client
|
||||
assetIdentifierStore *postgres.AssetIdentifierStore
|
||||
associationStore *postgres.PhoneAssetAssociationStore
|
||||
auditWriter *infraAudit.Writer
|
||||
packageExpiryQuery PackageExpiryResolver
|
||||
}
|
||||
@@ -61,6 +62,11 @@ func (s *Service) SetPackageExpiryQuery(query *packageexpiry.Query) {
|
||||
s.packageExpiryQuery = query
|
||||
}
|
||||
|
||||
// SetPhoneAssetAssociationStore 注入手机号—资产关联 store,供资产详情投影关联手机号。
|
||||
func (s *Service) SetPhoneAssetAssociationStore(store *postgres.PhoneAssetAssociationStore) {
|
||||
s.associationStore = store
|
||||
}
|
||||
|
||||
// New 创建资产服务实例
|
||||
func New(
|
||||
db *gorm.DB,
|
||||
@@ -282,9 +288,29 @@ func (s *Service) buildDeviceResolveResponse(ctx context.Context, device *model.
|
||||
// 查 Redis 保护期
|
||||
resp.DeviceProtectStatus = s.getDeviceProtectStatus(ctx, device.ID)
|
||||
|
||||
// 关联手机号:详情为单资产单次查询,按数据范围返回完整手机号。
|
||||
phones, err := s.resolveAssociatedPhones(ctx, constants.AssetTypeDevice, device.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp.AssociatedPhones = phones
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// resolveAssociatedPhones 读取单项资产当前全部有效关联手机号。
|
||||
// 资产本身已按数据范围解析,关联手机号不额外放行或收紧范围。
|
||||
func (s *Service) resolveAssociatedPhones(ctx context.Context, assetType string, assetID uint) ([]string, error) {
|
||||
if s.associationStore == nil {
|
||||
return nil, errors.New(errors.CodeInternalError, "手机号资产关联查询未初始化")
|
||||
}
|
||||
phones, err := s.associationStore.ListValidByAsset(ctx, assetType, assetID)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(errors.CodeDatabaseError, err, "查询资产关联手机号失败")
|
||||
}
|
||||
return phones, nil
|
||||
}
|
||||
|
||||
// buildCardResolveResponse 构建卡类型的资产解析响应
|
||||
func (s *Service) buildCardResolveResponse(ctx context.Context, card *model.IotCard) (*dto.AssetResolveResponse, error) {
|
||||
resp := &dto.AssetResolveResponse{
|
||||
@@ -341,6 +367,13 @@ func (s *Service) buildCardResolveResponse(ctx context.Context, card *model.IotC
|
||||
// 查套餐系列名称
|
||||
s.fillSeriesName(ctx, resp)
|
||||
|
||||
// 关联手机号:详情为单资产单次查询,按数据范围返回完整手机号。
|
||||
phones, err := s.resolveAssociatedPhones(ctx, constants.AssetTypeIotCard, card.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp.AssociatedPhones = phones
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user