This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
customerBindingSvc "github.com/break/junhong_cmp_fiber/internal/service/customer_binding"
|
||||
"github.com/break/junhong_cmp_fiber/internal/model"
|
||||
"github.com/break/junhong_cmp_fiber/internal/model/dto"
|
||||
"github.com/break/junhong_cmp_fiber/internal/store/postgres"
|
||||
@@ -26,7 +27,7 @@ type Service struct {
|
||||
packageUsageStore *postgres.PackageUsageStore
|
||||
packageUsageDailyRecordStore *postgres.PackageUsageDailyRecordStore
|
||||
resourceTagStore *postgres.ResourceTagStore
|
||||
personalCustomerDeviceStore *postgres.PersonalCustomerDeviceStore
|
||||
customerBinding *customerBindingSvc.Service
|
||||
logger *zap.Logger
|
||||
}
|
||||
|
||||
@@ -40,7 +41,7 @@ func New(
|
||||
packageUsageStore *postgres.PackageUsageStore,
|
||||
packageUsageDailyRecordStore *postgres.PackageUsageDailyRecordStore,
|
||||
resourceTagStore *postgres.ResourceTagStore,
|
||||
personalCustomerDeviceStore *postgres.PersonalCustomerDeviceStore,
|
||||
customerBinding *customerBindingSvc.Service,
|
||||
logger *zap.Logger,
|
||||
) *Service {
|
||||
return &Service{
|
||||
@@ -53,7 +54,7 @@ func New(
|
||||
packageUsageStore: packageUsageStore,
|
||||
packageUsageDailyRecordStore: packageUsageDailyRecordStore,
|
||||
resourceTagStore: resourceTagStore,
|
||||
personalCustomerDeviceStore: personalCustomerDeviceStore,
|
||||
customerBinding: customerBinding,
|
||||
logger: logger,
|
||||
}
|
||||
}
|
||||
@@ -802,19 +803,8 @@ func (s *Service) validateExchangeAssetsWithTx(ctx context.Context, tx *gorm.DB,
|
||||
}
|
||||
|
||||
func (s *Service) ensureNewAssetBindingAvailableWithTx(ctx context.Context, tx *gorm.DB, oldAsset, newAsset *resolvedExchangeAsset) error {
|
||||
oldKey := exchangeAssetBindingKey(oldAsset)
|
||||
newKey := exchangeAssetBindingKey(newAsset)
|
||||
oldBindCount := int64(0)
|
||||
if oldKey != "" {
|
||||
if err := tx.WithContext(ctx).Model(&model.PersonalCustomerDevice{}).
|
||||
Where("virtual_no = ? AND status = ?", oldKey, constants.StatusEnabled).
|
||||
Count(&oldBindCount).Error; err != nil {
|
||||
return errors.Wrap(errors.CodeDatabaseError, err, "查询旧资产客户绑定失败")
|
||||
}
|
||||
}
|
||||
if oldBindCount > 0 && newKey == "" {
|
||||
return errors.New(errors.CodeExchangeStatusInvalid, "新资产无法承接客户绑定")
|
||||
}
|
||||
// 新资产无虚拟号时不再拦截:Migrate() 已能正确处理无绑定跳过、有绑定迁移到 pci 的情形
|
||||
if newKey == "" {
|
||||
return nil
|
||||
}
|
||||
@@ -831,20 +821,7 @@ func (s *Service) ensureNewAssetBindingAvailableWithTx(ctx context.Context, tx *
|
||||
}
|
||||
|
||||
func (s *Service) switchCustomerBindingWithTx(ctx context.Context, tx *gorm.DB, oldAsset, newAsset *resolvedExchangeAsset) error {
|
||||
oldKey := exchangeAssetBindingKey(oldAsset)
|
||||
if oldKey == "" {
|
||||
return nil
|
||||
}
|
||||
newKey := exchangeAssetBindingKey(newAsset)
|
||||
if newKey == "" {
|
||||
return errors.New(errors.CodeExchangeStatusInvalid, "新资产无法承接客户绑定")
|
||||
}
|
||||
if err := tx.WithContext(ctx).Model(&model.PersonalCustomerDevice{}).
|
||||
Where("virtual_no = ? AND status = ?", oldKey, constants.StatusEnabled).
|
||||
Updates(map[string]any{"virtual_no": newKey, "updated_at": time.Now()}).Error; err != nil {
|
||||
return errors.Wrap(errors.CodeDatabaseError, err, "更新客户绑定关系失败")
|
||||
}
|
||||
return nil
|
||||
return s.customerBinding.Migrate(ctx, tx, oldAsset.AssetType, oldAsset.AssetID, newAsset.AssetType, newAsset.AssetID)
|
||||
}
|
||||
|
||||
func (s *Service) updateAssetStatusesForCompletion(ctx context.Context, tx *gorm.DB, oldAsset, newAsset *resolvedExchangeAsset) error {
|
||||
|
||||
Reference in New Issue
Block a user