| 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.common.util.Utils;
|
|
|
11 |
import com.spice.profitmandi.dao.entity.catalog.BrandCatalog;
|
|
|
12 |
import com.spice.profitmandi.dao.entity.catalog.BrandCategory;
|
|
|
13 |
import com.spice.profitmandi.dao.repository.catalog.BrandCategoryRepository;
|
|
|
14 |
import com.spice.profitmandi.dao.repository.catalog.BrandsRepository;
|
|
|
15 |
import com.spice.profitmandi.dao.repository.dtr.RetailerBlockBrandsRepository;
|
|
|
16 |
|
|
|
17 |
@Component
|
|
|
18 |
public class BrandsServiceImpl implements BrandsService {
|
|
|
19 |
|
|
|
20 |
@Autowired
|
|
|
21 |
private BrandCategoryRepository brandCategoryRepository;
|
|
|
22 |
|
|
|
23 |
@Autowired
|
|
|
24 |
private BrandsRepository brandCatalogRepository;
|
|
|
25 |
|
|
|
26 |
@Autowired
|
|
|
27 |
private RetailerBlockBrandsRepository retailerBlockBrandsRepository;
|
|
|
28 |
|
|
|
29 |
@Override
|
|
|
30 |
public List<BrandCatalog> getBrands(int fofoId, String email, int categoryId) {
|
|
|
31 |
List<BrandCatalog> brandsDisplay = this.getBrandsToDisplay(categoryId);
|
|
|
32 |
if (fofoId == Utils.SYSTEM_PARTNER_ID) {
|
|
|
33 |
return brandsDisplay;
|
|
|
34 |
}
|
|
|
35 |
List<String> blockedBrands = retailerBlockBrandsRepository.selectAllByRetailer(fofoId).stream()
|
|
|
36 |
.map(x -> x.getBlockBrands()).collect(Collectors.toList());
|
|
|
37 |
brandsDisplay = brandsDisplay.stream().filter(x -> !blockedBrands.contains(x.getName()))
|
|
|
38 |
.collect(Collectors.toList());
|
|
|
39 |
|
|
|
40 |
return brandsDisplay;
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
@Override
|
|
|
44 |
public List<BrandCatalog> getBrandsToDisplay(int categoryId) {
|
| 31536 |
tejbeer |
45 |
List<BrandCategory> brandCategories = brandCategoryRepository.selectByCategoryId(categoryId).stream()
|
|
|
46 |
.filter(x -> x.isActive()).collect(Collectors.toList());
|
| 31507 |
tejbeer |
47 |
|
|
|
48 |
Map<Integer, BrandCategory> brandCategoryMap = brandCategories.stream()
|
|
|
49 |
.collect(Collectors.toMap(x -> x.getBrandId(), x -> x));
|
|
|
50 |
|
|
|
51 |
List<Integer> brandIds = brandCategories.stream().map(x -> x.getBrandId()).collect(Collectors.toList());
|
|
|
52 |
|
|
|
53 |
List<BrandCatalog> brands = brandCatalogRepository.selectByIds(brandIds);
|
|
|
54 |
|
|
|
55 |
for (BrandCatalog brand : brands) {
|
|
|
56 |
brand.setBrandCategory(brandCategoryMap.get(brand.getId()));
|
|
|
57 |
}
|
|
|
58 |
return brands;
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
}
|