Rev 31536 | Go to most recent revision | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed
package com.spice.profitmandi.service.catalog;import java.util.List;import java.util.Map;import java.util.stream.Collectors;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Component;import com.spice.profitmandi.common.util.Utils;import com.spice.profitmandi.dao.entity.catalog.BrandCatalog;import com.spice.profitmandi.dao.entity.catalog.BrandCategory;import com.spice.profitmandi.dao.repository.catalog.BrandCategoryRepository;import com.spice.profitmandi.dao.repository.catalog.BrandsRepository;import com.spice.profitmandi.dao.repository.dtr.RetailerBlockBrandsRepository;@Componentpublic class BrandsServiceImpl implements BrandsService {@Autowiredprivate BrandCategoryRepository brandCategoryRepository;@Autowiredprivate BrandsRepository brandCatalogRepository;@Autowiredprivate RetailerBlockBrandsRepository retailerBlockBrandsRepository;@Overridepublic List<BrandCatalog> getBrands(int fofoId, String email, int categoryId) {List<BrandCatalog> brandsDisplay = this.getBrandsToDisplay(categoryId);if (fofoId == Utils.SYSTEM_PARTNER_ID) {return brandsDisplay;}List<String> blockedBrands = retailerBlockBrandsRepository.selectAllByRetailer(fofoId).stream().map(x -> x.getBlockBrands()).collect(Collectors.toList());brandsDisplay = brandsDisplay.stream().filter(x -> !blockedBrands.contains(x.getName())).collect(Collectors.toList());return brandsDisplay;}@Overridepublic List<BrandCatalog> getBrandsToDisplay(int categoryId) {List<BrandCategory> brandCategories = brandCategoryRepository.selectByCategoryId(categoryId);Map<Integer, BrandCategory> brandCategoryMap = brandCategories.stream().collect(Collectors.toMap(x -> x.getBrandId(), x -> x));List<Integer> brandIds = brandCategories.stream().map(x -> x.getBrandId()).collect(Collectors.toList());List<BrandCatalog> brands = brandCatalogRepository.selectByIds(brandIds);for (BrandCatalog brand : brands) {brand.setBrandCategory(brandCategoryMap.get(brand.getId()));}return brands;}}