|
|
@@ -130,10 +130,48 @@ func GetResourceSpecificationList(opts models.SearchResourceSpecificationOptions |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
|
|
|
|
return models.NewResourceSpecAndQueueListRes(n, r), nil |
|
|
|
} |
|
|
|
|
|
|
|
//GetAllDistinctResourceSpecification returns specification and queue after distinct |
|
|
|
//totalSize is always 0 here |
|
|
|
func GetAllDistinctResourceSpecification(opts models.SearchResourceSpecificationOptions) (*models.ResourceSpecAndQueueListRes, error) { |
|
|
|
opts.Page = 0 |
|
|
|
opts.PageSize = 1000 |
|
|
|
_, r, err := models.SearchResourceSpecification(opts) |
|
|
|
if err != nil { |
|
|
|
return nil, err |
|
|
|
} |
|
|
|
nr := distinctResourceSpecAndQueue(r) |
|
|
|
return models.NewResourceSpecAndQueueListRes(0, nr), nil |
|
|
|
} |
|
|
|
|
|
|
|
func distinctResourceSpecAndQueue(r []models.ResourceSpecAndQueue) []models.ResourceSpecAndQueue { |
|
|
|
specs := make([]models.ResourceSpecAndQueue, 0, len(r)) |
|
|
|
sourceSpecIdMap := make(map[string]models.ResourceSpecAndQueue, 0) |
|
|
|
for i := 0; i < len(r); i++ { |
|
|
|
spec := r[i] |
|
|
|
if spec.SourceSpecId == "" { |
|
|
|
specs = append(specs, spec) |
|
|
|
continue |
|
|
|
} |
|
|
|
if _, has := sourceSpecIdMap[spec.SourceSpecId]; has { |
|
|
|
//prefer to use on-shelf spec |
|
|
|
if sourceSpecIdMap[spec.SourceSpecId].Status != spec.Status && spec.Status == models.SpecOnShelf { |
|
|
|
for k, v := range specs { |
|
|
|
if v.ResourceSpecification.ID == sourceSpecIdMap[spec.SourceSpecId].ResourceSpecification.ID { |
|
|
|
specs[k] = spec |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
continue |
|
|
|
} |
|
|
|
specs = append(specs, spec) |
|
|
|
sourceSpecIdMap[spec.SourceSpecId] = spec |
|
|
|
} |
|
|
|
return specs |
|
|
|
} |
|
|
|
|
|
|
|
func GetResourceSpecificationScenes(specId int64) ([]models.ResourceSceneBriefRes, error) { |
|
|
|
r, err := models.GetSpecScenes(specId) |
|
|
|
if err != nil { |
|
|
|