Subversion Repositories SmartDukaan

Rev

Rev 33119 | Rev 33127 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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());
33122 amit.gupta 32
		Map<Integer, BrandCategory> brandCategoryMap = brandCategories.stream()
33
				.collect(Collectors.toMap(x -> x.getBrandId(), x -> x));
34
 
33119 amit.gupta 35
		List<BrandCatalog> brandCatalogList = brandCatalogRepository.selectByIds(brandIds);
33122 amit.gupta 36
		for (BrandCatalog brand : brandCatalogList) {
37
			brand.setBrandCategory(brandCategoryMap.get(brand.getId()));
38
		}
33119 amit.gupta 39
		return brandCatalogList;
31507 tejbeer 40
	}
41
 
42
	@Override
43
	public List<BrandCatalog> getBrandsToDisplay(int categoryId) {
31536 tejbeer 44
		List<BrandCategory> brandCategories = brandCategoryRepository.selectByCategoryId(categoryId).stream()
45
				.filter(x -> x.isActive()).collect(Collectors.toList());
31507 tejbeer 46
 
47
		Map<Integer, BrandCategory> brandCategoryMap = brandCategories.stream()
48
				.collect(Collectors.toMap(x -> x.getBrandId(), x -> x));
49
 
50
		List<Integer> brandIds = brandCategories.stream().map(x -> x.getBrandId()).collect(Collectors.toList());
51
 
52
		List<BrandCatalog> brands = brandCatalogRepository.selectByIds(brandIds);
53
 
54
		for (BrandCatalog brand : brands) {
55
			brand.setBrandCategory(brandCategoryMap.get(brand.getId()));
56
		}
57
		return brands;
58
	}
59
 
60
}