feat: 在 IoT 卡和设备列表响应中添加套餐系列名称字段
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 6m2s
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 6m2s
主要变更: - 在 StandaloneIotCardResponse 和 DeviceResponse 中添加 series_name 字段 - 在 iot_card 和 device service 中添加 loadSeriesNames 方法批量加载系列名称 - 更新相关方法以支持 series_name 的填充 其他变更: - 新增 OpenSpec 测试生成和共识锁定 skill - 新增 MCP 配置文件 - 更新 CLAUDE.md 项目规范文档 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -109,10 +109,11 @@ func (s *Service) ListStandalone(ctx context.Context, req *dto.ListStandaloneIot
|
||||
}
|
||||
|
||||
shopMap := s.loadShopNames(ctx, cards)
|
||||
seriesMap := s.loadSeriesNames(ctx, cards)
|
||||
|
||||
list := make([]*dto.StandaloneIotCardResponse, 0, len(cards))
|
||||
for _, card := range cards {
|
||||
item := s.toStandaloneResponse(card, shopMap)
|
||||
item := s.toStandaloneResponse(card, shopMap, seriesMap)
|
||||
list = append(list, item)
|
||||
}
|
||||
|
||||
@@ -141,7 +142,8 @@ func (s *Service) GetByICCID(ctx context.Context, iccid string) (*dto.IotCardDet
|
||||
}
|
||||
|
||||
shopMap := s.loadShopNames(ctx, []*model.IotCard{card})
|
||||
standaloneResp := s.toStandaloneResponse(card, shopMap)
|
||||
seriesMap := s.loadSeriesNames(ctx, []*model.IotCard{card})
|
||||
standaloneResp := s.toStandaloneResponse(card, shopMap, seriesMap)
|
||||
|
||||
return &dto.IotCardDetailResponse{
|
||||
StandaloneIotCardResponse: *standaloneResp,
|
||||
@@ -171,7 +173,30 @@ func (s *Service) loadShopNames(ctx context.Context, cards []*model.IotCard) map
|
||||
return shopMap
|
||||
}
|
||||
|
||||
func (s *Service) toStandaloneResponse(card *model.IotCard, shopMap map[uint]string) *dto.StandaloneIotCardResponse {
|
||||
func (s *Service) loadSeriesNames(ctx context.Context, cards []*model.IotCard) map[uint]string {
|
||||
seriesIDs := make([]uint, 0)
|
||||
seriesIDSet := make(map[uint]bool)
|
||||
|
||||
for _, card := range cards {
|
||||
if card.SeriesID != nil && *card.SeriesID > 0 && !seriesIDSet[*card.SeriesID] {
|
||||
seriesIDs = append(seriesIDs, *card.SeriesID)
|
||||
seriesIDSet[*card.SeriesID] = true
|
||||
}
|
||||
}
|
||||
|
||||
seriesMap := make(map[uint]string)
|
||||
if len(seriesIDs) > 0 {
|
||||
var seriesList []model.PackageSeries
|
||||
s.db.WithContext(ctx).Where("id IN ?", seriesIDs).Find(&seriesList)
|
||||
for _, series := range seriesList {
|
||||
seriesMap[series.ID] = series.SeriesName
|
||||
}
|
||||
}
|
||||
|
||||
return seriesMap
|
||||
}
|
||||
|
||||
func (s *Service) toStandaloneResponse(card *model.IotCard, shopMap map[uint]string, seriesMap map[uint]string) *dto.StandaloneIotCardResponse {
|
||||
resp := &dto.StandaloneIotCardResponse{
|
||||
ID: card.ID,
|
||||
ICCID: card.ICCID,
|
||||
@@ -203,6 +228,10 @@ func (s *Service) toStandaloneResponse(card *model.IotCard, shopMap map[uint]str
|
||||
resp.ShopName = shopMap[*card.ShopID]
|
||||
}
|
||||
|
||||
if card.SeriesID != nil && *card.SeriesID > 0 {
|
||||
resp.SeriesName = seriesMap[*card.SeriesID]
|
||||
}
|
||||
|
||||
return resp
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user