| 31507 |
tejbeer |
1 |
package com.spice.profitmandi.service.catalog;
|
|
|
2 |
|
| 33243 |
ranu |
3 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 33127 |
amit.gupta |
4 |
import com.spice.profitmandi.common.util.Utils;
|
| 31507 |
tejbeer |
5 |
import com.spice.profitmandi.dao.entity.catalog.BrandCatalog;
|
|
|
6 |
import com.spice.profitmandi.dao.entity.catalog.BrandCategory;
|
| 34513 |
ranu |
7 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
|
|
8 |
import com.spice.profitmandi.dao.entity.fofo.PartnerDealerMapping;
|
|
|
9 |
import com.spice.profitmandi.dao.entity.fofo.PartnerOnBoardingPanel;
|
| 31507 |
tejbeer |
10 |
import com.spice.profitmandi.dao.repository.catalog.BrandCategoryRepository;
|
|
|
11 |
import com.spice.profitmandi.dao.repository.catalog.BrandsRepository;
|
| 34513 |
ranu |
12 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
|
|
13 |
import com.spice.profitmandi.dao.repository.dtr.PartnerDealerRepository;
|
|
|
14 |
import com.spice.profitmandi.dao.repository.dtr.PartnerOnBoardingPanelRepository;
|
| 31507 |
tejbeer |
15 |
import com.spice.profitmandi.dao.repository.dtr.RetailerBlockBrandsRepository;
|
| 34513 |
ranu |
16 |
import com.spice.profitmandi.dao.repository.onboarding.BrandCommitRepository;
|
| 33243 |
ranu |
17 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
18 |
import org.springframework.stereotype.Component;
|
| 31507 |
tejbeer |
19 |
|
| 34513 |
ranu |
20 |
import java.util.ArrayList;
|
| 33243 |
ranu |
21 |
import java.util.List;
|
|
|
22 |
import java.util.Map;
|
|
|
23 |
import java.util.stream.Collectors;
|
|
|
24 |
|
| 31507 |
tejbeer |
25 |
@Component
|
|
|
26 |
public class BrandsServiceImpl implements BrandsService {
|
|
|
27 |
|
|
|
28 |
@Autowired
|
|
|
29 |
private BrandCategoryRepository brandCategoryRepository;
|
|
|
30 |
|
|
|
31 |
@Autowired
|
|
|
32 |
private BrandsRepository brandCatalogRepository;
|
|
|
33 |
|
|
|
34 |
@Autowired
|
|
|
35 |
private RetailerBlockBrandsRepository retailerBlockBrandsRepository;
|
|
|
36 |
|
| 34513 |
ranu |
37 |
@Autowired
|
|
|
38 |
private FofoStoreRepository fofoStoreRepository;
|
|
|
39 |
|
|
|
40 |
@Autowired
|
|
|
41 |
private PartnerOnBoardingPanelRepository partnerOnBoardingPanelRepository;
|
|
|
42 |
|
|
|
43 |
@Autowired
|
|
|
44 |
private PartnerDealerRepository partnerDealerRepository;
|
|
|
45 |
|
|
|
46 |
@Autowired
|
|
|
47 |
private BrandCommitRepository brandCommitRepository;
|
|
|
48 |
|
| 31507 |
tejbeer |
49 |
@Override
|
| 33243 |
ranu |
50 |
public List<BrandCatalog> getBrands(int fofoId, String email, int categoryId) throws ProfitMandiBusinessException {
|
| 33127 |
amit.gupta |
51 |
List<BrandCatalog> brandsDisplay = this.getBrandsToDisplay(categoryId);
|
|
|
52 |
if (fofoId == Utils.SYSTEM_PARTNER_ID) {
|
|
|
53 |
return brandsDisplay;
|
|
|
54 |
}
|
|
|
55 |
List<String> blockedBrands = retailerBlockBrandsRepository.selectAllByRetailer(fofoId).stream()
|
|
|
56 |
.map(x -> x.getBlockBrands()).collect(Collectors.toList());
|
|
|
57 |
brandsDisplay = brandsDisplay.stream().filter(x -> !blockedBrands.contains(x.getName()))
|
|
|
58 |
.collect(Collectors.toList());
|
| 33122 |
amit.gupta |
59 |
|
| 33127 |
amit.gupta |
60 |
return brandsDisplay;
|
| 31507 |
tejbeer |
61 |
}
|
|
|
62 |
|
|
|
63 |
@Override
|
| 33243 |
ranu |
64 |
public List<BrandCatalog> getBrandsToDisplay(int categoryId) throws ProfitMandiBusinessException {
|
| 31536 |
tejbeer |
65 |
List<BrandCategory> brandCategories = brandCategoryRepository.selectByCategoryId(categoryId).stream()
|
|
|
66 |
.filter(x -> x.isActive()).collect(Collectors.toList());
|
| 31507 |
tejbeer |
67 |
|
|
|
68 |
Map<Integer, BrandCategory> brandCategoryMap = brandCategories.stream()
|
|
|
69 |
.collect(Collectors.toMap(x -> x.getBrandId(), x -> x));
|
|
|
70 |
|
|
|
71 |
List<Integer> brandIds = brandCategories.stream().map(x -> x.getBrandId()).collect(Collectors.toList());
|
|
|
72 |
|
|
|
73 |
List<BrandCatalog> brands = brandCatalogRepository.selectByIds(brandIds);
|
|
|
74 |
|
|
|
75 |
for (BrandCatalog brand : brands) {
|
|
|
76 |
brand.setBrandCategory(brandCategoryMap.get(brand.getId()));
|
|
|
77 |
}
|
|
|
78 |
return brands;
|
|
|
79 |
}
|
|
|
80 |
|
| 34513 |
ranu |
81 |
@Override
|
|
|
82 |
public List<String> partnerIneligibleBrands(int fofoId) throws ProfitMandiBusinessException {
|
|
|
83 |
|
|
|
84 |
FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
|
|
|
85 |
PartnerOnBoardingPanel partnerOnBoardingPanel = partnerOnBoardingPanelRepository.selectByCode(fofoStore.getCode());
|
|
|
86 |
List<PartnerDealerMapping> partnerDealerMappingList = new ArrayList<>();
|
|
|
87 |
List<String> wodRequiredBrands = new ArrayList<>();
|
|
|
88 |
if (partnerOnBoardingPanel != null) {
|
|
|
89 |
partnerDealerMappingList = partnerDealerRepository.selectByOnboardingId(partnerOnBoardingPanel.getId());
|
|
|
90 |
if (partnerDealerMappingList != null && partnerDealerMappingList.size() > 0) {
|
|
|
91 |
//working brands -> Partner only work with brands that having 'Dealer Code'
|
|
|
92 |
wodRequiredBrands = partnerDealerMappingList.stream().filter(x -> x.getBrandCode().trim().length() == 0).map(x -> x.getBrand()).collect(Collectors.toList());
|
|
|
93 |
}
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
//brandsToBeCheck
|
|
|
97 |
List<String> nocRequiredBrand = brandCommitRepository.selectAllActiveBrand().stream().filter(x -> x.isNocRequired()).map(x -> x.getBrand()).collect(Collectors.toList());
|
|
|
98 |
List<String> ineligibleBrands = nocRequiredBrand.stream()
|
|
|
99 |
.filter(wodRequiredBrands::contains)
|
|
|
100 |
.collect(Collectors.toList());
|
|
|
101 |
|
|
|
102 |
return ineligibleBrands;
|
|
|
103 |
}
|
|
|
104 |
|
| 31507 |
tejbeer |
105 |
}
|