| 31507 |
tejbeer |
1 |
package com.spice.profitmandi.service.catalog;
|
|
|
2 |
|
|
|
3 |
import java.util.List;
|
|
|
4 |
import java.util.Map;
|
|
|
5 |
import java.util.stream.Collectors;
|
|
|
6 |
|
|
|
7 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
8 |
import org.springframework.stereotype.Component;
|
|
|
9 |
|
|
|
10 |
import com.spice.profitmandi.dao.entity.catalog.BrandCatalog;
|
|
|
11 |
import com.spice.profitmandi.dao.entity.catalog.BrandCategory;
|
|
|
12 |
import com.spice.profitmandi.dao.repository.catalog.BrandCategoryRepository;
|
|
|
13 |
import com.spice.profitmandi.dao.repository.catalog.BrandsRepository;
|
|
|
14 |
import com.spice.profitmandi.dao.repository.dtr.RetailerBlockBrandsRepository;
|
|
|
15 |
|
|
|
16 |
@Component
|
|
|
17 |
public class BrandsServiceImpl implements BrandsService {
|
|
|
18 |
|
|
|
19 |
@Autowired
|
|
|
20 |
private BrandCategoryRepository brandCategoryRepository;
|
|
|
21 |
|
|
|
22 |
@Autowired
|
|
|
23 |
private BrandsRepository brandCatalogRepository;
|
|
|
24 |
|
|
|
25 |
@Autowired
|
|
|
26 |
private RetailerBlockBrandsRepository retailerBlockBrandsRepository;
|
|
|
27 |
|
|
|
28 |
@Override
|
| 33119 |
amit.gupta |
29 |
public List<BrandCatalog> getBrands(int categoryId) {
|
|
|
30 |
List<BrandCategory> brandCategories = brandCategoryRepository.selectByCategoryId(categoryId);
|
|
|
31 |
List<Integer> brandIds = brandCategories.stream().map(x->x.getBrandId()).collect(Collectors.toList());
|
|
|
32 |
List<BrandCatalog> brandCatalogList = brandCatalogRepository.selectByIds(brandIds);
|
|
|
33 |
return brandCatalogList;
|
| 31507 |
tejbeer |
34 |
}
|
|
|
35 |
|
|
|
36 |
@Override
|
|
|
37 |
public List<BrandCatalog> getBrandsToDisplay(int categoryId) {
|
| 31536 |
tejbeer |
38 |
List<BrandCategory> brandCategories = brandCategoryRepository.selectByCategoryId(categoryId).stream()
|
|
|
39 |
.filter(x -> x.isActive()).collect(Collectors.toList());
|
| 31507 |
tejbeer |
40 |
|
|
|
41 |
Map<Integer, BrandCategory> brandCategoryMap = brandCategories.stream()
|
|
|
42 |
.collect(Collectors.toMap(x -> x.getBrandId(), x -> x));
|
|
|
43 |
|
|
|
44 |
List<Integer> brandIds = brandCategories.stream().map(x -> x.getBrandId()).collect(Collectors.toList());
|
|
|
45 |
|
|
|
46 |
List<BrandCatalog> brands = brandCatalogRepository.selectByIds(brandIds);
|
|
|
47 |
|
|
|
48 |
for (BrandCatalog brand : brands) {
|
|
|
49 |
brand.setBrandCategory(brandCategoryMap.get(brand.getId()));
|
|
|
50 |
}
|
|
|
51 |
return brands;
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
}
|