diff --git a/internal/service/asset_allocation_record/service.go b/internal/service/asset_allocation_record/service.go index 05300e9..cd8dc08 100644 --- a/internal/service/asset_allocation_record/service.go +++ b/internal/service/asset_allocation_record/service.go @@ -177,7 +177,8 @@ func (s *Service) loadShopNames(ctx context.Context, shopIDs []uint) map[uint]st } var shops []model.Shop - s.db.WithContext(ctx).Where("id IN ?", shopIDs).Find(&shops) + // 使用 Unscoped() 包含已删除的店铺,确保能显示店铺名称 + s.db.WithContext(ctx).Unscoped().Where("id IN ?", shopIDs).Find(&shops) for _, shop := range shops { result[shop.ID] = shop.ShopName } diff --git a/internal/service/device/service.go b/internal/service/device/service.go index 26c1215..00429f2 100644 --- a/internal/service/device/service.go +++ b/internal/service/device/service.go @@ -426,7 +426,8 @@ func (s *Service) loadShopData(ctx context.Context, devices []*model.Device) map shopMap := make(map[uint]string) if len(shopIDs) > 0 { var shops []model.Shop - s.db.WithContext(ctx).Where("id IN ?", shopIDs).Find(&shops) + // 使用 Unscoped() 包含已删除的店铺,确保能显示店铺名称 + s.db.WithContext(ctx).Unscoped().Where("id IN ?", shopIDs).Find(&shops) for _, shop := range shops { shopMap[shop.ID] = shop.ShopName } diff --git a/internal/service/enterprise/service.go b/internal/service/enterprise/service.go index 505fcaf..6d39908 100644 --- a/internal/service/enterprise/service.go +++ b/internal/service/enterprise/service.go @@ -316,7 +316,8 @@ func (s *Service) List(ctx context.Context, req *dto.EnterpriseListReq) (*dto.En shopMap := make(map[uint]string) if len(shopIDs) > 0 { var shops []model.Shop - s.db.WithContext(ctx).Where("id IN ?", shopIDs).Find(&shops) + // 使用 Unscoped() 包含已删除的店铺,确保能显示店铺名称 + s.db.WithContext(ctx).Unscoped().Where("id IN ?", shopIDs).Find(&shops) for _, shop := range shops { shopMap[shop.ID] = shop.ShopName } diff --git a/internal/service/iot_card/service.go b/internal/service/iot_card/service.go index 4df8eea..8a3cee2 100644 --- a/internal/service/iot_card/service.go +++ b/internal/service/iot_card/service.go @@ -200,7 +200,8 @@ func (s *Service) loadShopNames(ctx context.Context, cards []*model.IotCard) map shopMap := make(map[uint]string) if len(shopIDs) > 0 { var shops []model.Shop - s.db.WithContext(ctx).Where("id IN ?", shopIDs).Find(&shops) + // 使用 Unscoped() 包含已删除的店铺,确保能显示店铺名称 + s.db.WithContext(ctx).Unscoped().Where("id IN ?", shopIDs).Find(&shops) for _, shop := range shops { shopMap[shop.ID] = shop.ShopName }