| 31507 |
tejbeer |
1 |
package com.spice.profitmandi.service.catalog;
|
|
|
2 |
|
| 33243 |
ranu |
3 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 34629 |
tejus.loha |
4 |
import com.spice.profitmandi.common.model.BrandAndAddToCartEligibleModel;
|
| 33127 |
amit.gupta |
5 |
import com.spice.profitmandi.common.util.Utils;
|
| 31507 |
tejbeer |
6 |
import com.spice.profitmandi.dao.entity.catalog.BrandCatalog;
|
|
|
7 |
import com.spice.profitmandi.dao.entity.catalog.BrandCategory;
|
| 34513 |
ranu |
8 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
|
|
9 |
import com.spice.profitmandi.dao.entity.fofo.PartnerDealerMapping;
|
|
|
10 |
import com.spice.profitmandi.dao.entity.fofo.PartnerOnBoardingPanel;
|
| 31507 |
tejbeer |
11 |
import com.spice.profitmandi.dao.repository.catalog.BrandCategoryRepository;
|
|
|
12 |
import com.spice.profitmandi.dao.repository.catalog.BrandsRepository;
|
| 34513 |
ranu |
13 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
|
|
14 |
import com.spice.profitmandi.dao.repository.dtr.PartnerDealerRepository;
|
|
|
15 |
import com.spice.profitmandi.dao.repository.dtr.PartnerOnBoardingPanelRepository;
|
|
|
16 |
import com.spice.profitmandi.dao.repository.onboarding.BrandCommitRepository;
|
| 37143 |
amit |
17 |
import com.spice.profitmandi.common.solr.SolrService;
|
| 33243 |
ranu |
18 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
19 |
import org.springframework.stereotype.Component;
|
| 31507 |
tejbeer |
20 |
|
| 34513 |
ranu |
21 |
import java.util.ArrayList;
|
| 37143 |
amit |
22 |
import java.util.Collection;
|
| 33243 |
ranu |
23 |
import java.util.List;
|
|
|
24 |
import java.util.Map;
|
|
|
25 |
import java.util.stream.Collectors;
|
|
|
26 |
|
| 31507 |
tejbeer |
27 |
@Component
|
|
|
28 |
public class BrandsServiceImpl implements BrandsService {
|
|
|
29 |
|
| 34629 |
tejus.loha |
30 |
@Autowired
|
|
|
31 |
private BrandCategoryRepository brandCategoryRepository;
|
| 31507 |
tejbeer |
32 |
|
| 34629 |
tejus.loha |
33 |
@Autowired
|
|
|
34 |
private BrandsRepository brandCatalogRepository;
|
| 31507 |
tejbeer |
35 |
|
| 34629 |
tejus.loha |
36 |
@Autowired
|
| 37143 |
amit |
37 |
private BlockedBrandService blockedBrandService;
|
| 31507 |
tejbeer |
38 |
|
| 34629 |
tejus.loha |
39 |
@Autowired
|
|
|
40 |
private FofoStoreRepository fofoStoreRepository;
|
| 34513 |
ranu |
41 |
|
| 34629 |
tejus.loha |
42 |
@Autowired
|
|
|
43 |
private PartnerOnBoardingPanelRepository partnerOnBoardingPanelRepository;
|
| 34513 |
ranu |
44 |
|
| 34629 |
tejus.loha |
45 |
@Autowired
|
|
|
46 |
private PartnerDealerRepository partnerDealerRepository;
|
| 34513 |
ranu |
47 |
|
| 34629 |
tejus.loha |
48 |
@Autowired
|
|
|
49 |
private BrandCommitRepository brandCommitRepository;
|
| 34513 |
ranu |
50 |
|
| 34629 |
tejus.loha |
51 |
@Override
|
| 33243 |
ranu |
52 |
public List<BrandCatalog> getBrands(int fofoId, String email, int categoryId) throws ProfitMandiBusinessException {
|
| 34629 |
tejus.loha |
53 |
List<BrandCatalog> brandsDisplay = this.getBrandsToDisplay(categoryId);
|
|
|
54 |
if (fofoId == Utils.SYSTEM_PARTNER_ID) {
|
|
|
55 |
return brandsDisplay;
|
|
|
56 |
}
|
| 35203 |
amit |
57 |
List<String> ineligibleBrands = this.partnerIneligibleBrands(fofoId);
|
| 35337 |
aman |
58 |
brandsDisplay.forEach(x -> x.setTrialBlocked(ineligibleBrands.contains(x.getName())));
|
| 33122 |
amit.gupta |
59 |
|
| 34629 |
tejus.loha |
60 |
return brandsDisplay;
|
|
|
61 |
}
|
| 31507 |
tejbeer |
62 |
|
| 34629 |
tejus.loha |
63 |
@Override
|
| 33243 |
ranu |
64 |
public List<BrandCatalog> getBrandsToDisplay(int categoryId) throws ProfitMandiBusinessException {
|
| 34629 |
tejus.loha |
65 |
List<BrandCategory> brandCategories = brandCategoryRepository.selectByCategoryId(categoryId).stream()
|
|
|
66 |
.filter(x -> x.isActive()).collect(Collectors.toList());
|
| 31507 |
tejbeer |
67 |
|
| 34629 |
tejus.loha |
68 |
Map<Integer, BrandCategory> brandCategoryMap = brandCategories.stream()
|
|
|
69 |
.collect(Collectors.toMap(x -> x.getBrandId(), x -> x));
|
| 31507 |
tejbeer |
70 |
|
| 34629 |
tejus.loha |
71 |
List<Integer> brandIds = brandCategories.stream().map(x -> x.getBrandId()).collect(Collectors.toList());
|
| 31507 |
tejbeer |
72 |
|
| 34629 |
tejus.loha |
73 |
List<BrandCatalog> brands = brandCatalogRepository.selectByIds(brandIds);
|
| 31507 |
tejbeer |
74 |
|
| 34629 |
tejus.loha |
75 |
for (BrandCatalog brand : brands) {
|
|
|
76 |
brand.setBrandCategory(brandCategoryMap.get(brand.getId()));
|
|
|
77 |
}
|
|
|
78 |
return brands;
|
|
|
79 |
}
|
| 31507 |
tejbeer |
80 |
|
| 34629 |
tejus.loha |
81 |
@Override
|
|
|
82 |
public List<String> partnerIneligibleBrands(int fofoId) throws ProfitMandiBusinessException {
|
|
|
83 |
BrandAndAddToCartEligibleModel brandAndAddToCartEligibleModel = wodcompletBrands(fofoId);
|
|
|
84 |
List<String> requiredBrand = brandAndAddToCartEligibleModel.getWodRequiredBrands();
|
|
|
85 |
List<String> wodCompleteBrands = brandAndAddToCartEligibleModel.getWodCompleteBrands();
|
|
|
86 |
List<String> ineligibleBrands = new ArrayList<>(requiredBrand);
|
|
|
87 |
ineligibleBrands.removeAll(wodCompleteBrands);
|
|
|
88 |
return ineligibleBrands;
|
|
|
89 |
}
|
| 34513 |
ranu |
90 |
|
| 34629 |
tejus.loha |
91 |
@Override
|
| 37143 |
amit |
92 |
public List<String> restrictedBrands(int fofoId) throws ProfitMandiBusinessException {
|
|
|
93 |
List<String> restricted = new ArrayList<>(blockedBrandService.getBlockedBrands(fofoId));
|
|
|
94 |
this.loiIneligibleBrands(fofoId).stream().filter(x -> !restricted.contains(x)).forEach(restricted::add);
|
|
|
95 |
return restricted;
|
|
|
96 |
}
|
|
|
97 |
|
|
|
98 |
@Override
|
|
|
99 |
public void applyRestrictedSolrExclusion(Map<String, String> params, int fofoId)
|
|
|
100 |
throws ProfitMandiBusinessException {
|
|
|
101 |
String exclusionFq = SolrService.brandExclusionFq(this.restrictedBrands(fofoId));
|
|
|
102 |
if (exclusionFq == null) {
|
|
|
103 |
return;
|
|
|
104 |
}
|
|
|
105 |
String existingFq = params.get("fq");
|
|
|
106 |
params.put("fq", existingFq == null ? exclusionFq : existingFq + " AND " + exclusionFq);
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
@Override
|
|
|
110 |
public void validateOrderableBrands(int fofoId, Collection<String> brands) throws ProfitMandiBusinessException {
|
|
|
111 |
List<String> ineligibleBrands = this.loiIneligibleBrands(fofoId);
|
|
|
112 |
List<String> offendingBrands = brands.stream().filter(ineligibleBrands::contains).distinct()
|
|
|
113 |
.collect(Collectors.toList());
|
|
|
114 |
if (!offendingBrands.isEmpty()) {
|
|
|
115 |
String message = "Brand ( " + String.join(", ", offendingBrands) + ") is not allowed for this partner";
|
|
|
116 |
throw new ProfitMandiBusinessException("Brand is not allowed", offendingBrands, message);
|
|
|
117 |
}
|
|
|
118 |
blockedBrandService.validateBrandsAllowed(fofoId, brands);
|
|
|
119 |
}
|
|
|
120 |
|
|
|
121 |
// LOI eligibility only applies to real, non-internal partner stores; identities
|
|
|
122 |
// without a fofo_store row degrade to blocked-only restriction.
|
|
|
123 |
private List<String> loiIneligibleBrands(int fofoId) throws ProfitMandiBusinessException {
|
|
|
124 |
if (fofoId == Utils.SYSTEM_PARTNER_ID) {
|
|
|
125 |
return new ArrayList<>();
|
|
|
126 |
}
|
|
|
127 |
FofoStore fofoStore;
|
|
|
128 |
try {
|
|
|
129 |
fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
|
|
|
130 |
} catch (ProfitMandiBusinessException e) {
|
|
|
131 |
return new ArrayList<>();
|
|
|
132 |
}
|
|
|
133 |
if (fofoStore == null || fofoStore.isInternal()) {
|
|
|
134 |
return new ArrayList<>();
|
|
|
135 |
}
|
|
|
136 |
return this.partnerIneligibleBrands(fofoId);
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
@Override
|
| 36482 |
vikas |
140 |
public List<BrandCatalog> getAllActiveBrands() throws ProfitMandiBusinessException {
|
|
|
141 |
List<BrandCategory> brandCategories = brandCategoryRepository.selectAllActive();
|
|
|
142 |
|
|
|
143 |
Map<Integer, BrandCategory> brandCategoryMap = brandCategories.stream()
|
|
|
144 |
.collect(Collectors.toMap(BrandCategory::getBrandId, x -> x, (a, b) -> a));
|
|
|
145 |
|
|
|
146 |
List<Integer> brandIds = brandCategories.stream()
|
|
|
147 |
.map(BrandCategory::getBrandId)
|
|
|
148 |
.distinct()
|
|
|
149 |
.collect(Collectors.toList());
|
|
|
150 |
|
|
|
151 |
if (brandIds.isEmpty()) {
|
|
|
152 |
return new ArrayList<>();
|
|
|
153 |
}
|
|
|
154 |
|
|
|
155 |
List<BrandCatalog> brands = brandCatalogRepository.selectByIds(brandIds);
|
|
|
156 |
for (BrandCatalog brand : brands) {
|
|
|
157 |
brand.setBrandCategory(brandCategoryMap.get(brand.getId()));
|
|
|
158 |
}
|
|
|
159 |
return brands;
|
|
|
160 |
}
|
|
|
161 |
|
|
|
162 |
@Override
|
| 34629 |
tejus.loha |
163 |
public BrandAndAddToCartEligibleModel wodcompletBrands(int fofoId) throws ProfitMandiBusinessException {
|
|
|
164 |
FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
|
| 34930 |
ranu |
165 |
if(!fofoStore.isInternal()){
|
|
|
166 |
PartnerOnBoardingPanel partnerOnBoardingPanel = partnerOnBoardingPanelRepository.selectByCode(fofoStore.getCode());
|
|
|
167 |
List<PartnerDealerMapping> partnerDealerMappingList = new ArrayList<>();
|
|
|
168 |
List<String> wodCompletedBrands = new ArrayList<>();
|
|
|
169 |
if (partnerOnBoardingPanel != null) {
|
|
|
170 |
partnerDealerMappingList = partnerDealerRepository.selectByOnboardingId(partnerOnBoardingPanel.getId());
|
|
|
171 |
if (partnerDealerMappingList != null && partnerDealerMappingList.size() > 0) {
|
|
|
172 |
//working brands -> Partner only work with brands that having 'Dealer Code'
|
| 35800 |
amit |
173 |
wodCompletedBrands = partnerDealerMappingList.stream().filter(x -> x.getBrandCode() != null && x.getBrandCode().trim().length() > 0).map(x -> x.getBrand()).collect(Collectors.toList());
|
| 34930 |
ranu |
174 |
}
|
| 34629 |
tejus.loha |
175 |
}
|
| 34930 |
ranu |
176 |
BrandAndAddToCartEligibleModel partnerWorkingBrandMappingModel = new BrandAndAddToCartEligibleModel();
|
|
|
177 |
partnerWorkingBrandMappingModel.setWodCompleteBrands(wodCompletedBrands);
|
| 36209 |
ranu |
178 |
//brandsToBeCheck - only brands where noc_required = true need dealer code verification
|
|
|
179 |
List<String> wodRequiredBrand = brandCommitRepository.selectAllActiveBrand().stream()
|
|
|
180 |
.filter(x -> x.isNocRequired())
|
|
|
181 |
.map(x -> x.getBrand()).collect(Collectors.toList());
|
| 34930 |
ranu |
182 |
partnerWorkingBrandMappingModel.setWodRequiredBrands(wodRequiredBrand);
|
|
|
183 |
return partnerWorkingBrandMappingModel;
|
|
|
184 |
}else {
|
|
|
185 |
BrandAndAddToCartEligibleModel model = new BrandAndAddToCartEligibleModel();
|
| 36078 |
aman |
186 |
List<String> wodRequiredBrand = brandCommitRepository.selectAllActiveBrand().stream().map(x -> x.getBrand()).collect(Collectors.toList());
|
| 34930 |
ranu |
187 |
model.setWodCompleteBrands(wodRequiredBrand);
|
|
|
188 |
model.setWodRequiredBrands(wodRequiredBrand);
|
|
|
189 |
return model;
|
| 34629 |
tejus.loha |
190 |
}
|
|
|
191 |
}
|
| 34513 |
ranu |
192 |
|
|
|
193 |
|
| 31507 |
tejbeer |
194 |
}
|