| 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;
|
| 31507 |
tejbeer |
16 |
import com.spice.profitmandi.dao.repository.dtr.RetailerBlockBrandsRepository;
|
| 34513 |
ranu |
17 |
import com.spice.profitmandi.dao.repository.onboarding.BrandCommitRepository;
|
| 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;
|
| 33243 |
ranu |
22 |
import java.util.List;
|
|
|
23 |
import java.util.Map;
|
|
|
24 |
import java.util.stream.Collectors;
|
|
|
25 |
|
| 31507 |
tejbeer |
26 |
@Component
|
|
|
27 |
public class BrandsServiceImpl implements BrandsService {
|
|
|
28 |
|
| 34629 |
tejus.loha |
29 |
@Autowired
|
|
|
30 |
private BrandCategoryRepository brandCategoryRepository;
|
| 31507 |
tejbeer |
31 |
|
| 34629 |
tejus.loha |
32 |
@Autowired
|
|
|
33 |
private BrandsRepository brandCatalogRepository;
|
| 31507 |
tejbeer |
34 |
|
| 34629 |
tejus.loha |
35 |
@Autowired
|
|
|
36 |
private RetailerBlockBrandsRepository retailerBlockBrandsRepository;
|
| 31507 |
tejbeer |
37 |
|
| 34629 |
tejus.loha |
38 |
@Autowired
|
|
|
39 |
private FofoStoreRepository fofoStoreRepository;
|
| 34513 |
ranu |
40 |
|
| 34629 |
tejus.loha |
41 |
@Autowired
|
|
|
42 |
private PartnerOnBoardingPanelRepository partnerOnBoardingPanelRepository;
|
| 34513 |
ranu |
43 |
|
| 34629 |
tejus.loha |
44 |
@Autowired
|
|
|
45 |
private PartnerDealerRepository partnerDealerRepository;
|
| 34513 |
ranu |
46 |
|
| 34629 |
tejus.loha |
47 |
@Autowired
|
|
|
48 |
private BrandCommitRepository brandCommitRepository;
|
| 34513 |
ranu |
49 |
|
| 34629 |
tejus.loha |
50 |
@Override
|
| 33243 |
ranu |
51 |
public List<BrandCatalog> getBrands(int fofoId, String email, int categoryId) throws ProfitMandiBusinessException {
|
| 34629 |
tejus.loha |
52 |
List<BrandCatalog> brandsDisplay = this.getBrandsToDisplay(categoryId);
|
|
|
53 |
if (fofoId == Utils.SYSTEM_PARTNER_ID) {
|
|
|
54 |
return brandsDisplay;
|
|
|
55 |
}
|
| 35203 |
amit |
56 |
List<String> ineligibleBrands = this.partnerIneligibleBrands(fofoId);
|
| 35337 |
aman |
57 |
brandsDisplay.forEach(x -> x.setTrialBlocked(ineligibleBrands.contains(x.getName())));
|
| 33122 |
amit.gupta |
58 |
|
| 34629 |
tejus.loha |
59 |
return brandsDisplay;
|
|
|
60 |
}
|
| 31507 |
tejbeer |
61 |
|
| 34629 |
tejus.loha |
62 |
@Override
|
| 33243 |
ranu |
63 |
public List<BrandCatalog> getBrandsToDisplay(int categoryId) throws ProfitMandiBusinessException {
|
| 34629 |
tejus.loha |
64 |
List<BrandCategory> brandCategories = brandCategoryRepository.selectByCategoryId(categoryId).stream()
|
|
|
65 |
.filter(x -> x.isActive()).collect(Collectors.toList());
|
| 31507 |
tejbeer |
66 |
|
| 34629 |
tejus.loha |
67 |
Map<Integer, BrandCategory> brandCategoryMap = brandCategories.stream()
|
|
|
68 |
.collect(Collectors.toMap(x -> x.getBrandId(), x -> x));
|
| 31507 |
tejbeer |
69 |
|
| 34629 |
tejus.loha |
70 |
List<Integer> brandIds = brandCategories.stream().map(x -> x.getBrandId()).collect(Collectors.toList());
|
| 31507 |
tejbeer |
71 |
|
| 34629 |
tejus.loha |
72 |
List<BrandCatalog> brands = brandCatalogRepository.selectByIds(brandIds);
|
| 31507 |
tejbeer |
73 |
|
| 34629 |
tejus.loha |
74 |
for (BrandCatalog brand : brands) {
|
|
|
75 |
brand.setBrandCategory(brandCategoryMap.get(brand.getId()));
|
|
|
76 |
}
|
|
|
77 |
return brands;
|
|
|
78 |
}
|
| 31507 |
tejbeer |
79 |
|
| 34629 |
tejus.loha |
80 |
@Override
|
|
|
81 |
public List<String> partnerIneligibleBrands(int fofoId) throws ProfitMandiBusinessException {
|
|
|
82 |
BrandAndAddToCartEligibleModel brandAndAddToCartEligibleModel = wodcompletBrands(fofoId);
|
|
|
83 |
List<String> requiredBrand = brandAndAddToCartEligibleModel.getWodRequiredBrands();
|
|
|
84 |
List<String> wodCompleteBrands = brandAndAddToCartEligibleModel.getWodCompleteBrands();
|
|
|
85 |
List<String> ineligibleBrands = new ArrayList<>(requiredBrand);
|
|
|
86 |
ineligibleBrands.removeAll(wodCompleteBrands);
|
|
|
87 |
return ineligibleBrands;
|
|
|
88 |
}
|
| 34513 |
ranu |
89 |
|
| 34629 |
tejus.loha |
90 |
@Override
|
| 36482 |
vikas |
91 |
public List<BrandCatalog> getAllActiveBrands() throws ProfitMandiBusinessException {
|
|
|
92 |
List<BrandCategory> brandCategories = brandCategoryRepository.selectAllActive();
|
|
|
93 |
|
|
|
94 |
Map<Integer, BrandCategory> brandCategoryMap = brandCategories.stream()
|
|
|
95 |
.collect(Collectors.toMap(BrandCategory::getBrandId, x -> x, (a, b) -> a));
|
|
|
96 |
|
|
|
97 |
List<Integer> brandIds = brandCategories.stream()
|
|
|
98 |
.map(BrandCategory::getBrandId)
|
|
|
99 |
.distinct()
|
|
|
100 |
.collect(Collectors.toList());
|
|
|
101 |
|
|
|
102 |
if (brandIds.isEmpty()) {
|
|
|
103 |
return new ArrayList<>();
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
List<BrandCatalog> brands = brandCatalogRepository.selectByIds(brandIds);
|
|
|
107 |
for (BrandCatalog brand : brands) {
|
|
|
108 |
brand.setBrandCategory(brandCategoryMap.get(brand.getId()));
|
|
|
109 |
}
|
|
|
110 |
return brands;
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
@Override
|
| 34629 |
tejus.loha |
114 |
public BrandAndAddToCartEligibleModel wodcompletBrands(int fofoId) throws ProfitMandiBusinessException {
|
|
|
115 |
FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
|
| 34930 |
ranu |
116 |
if(!fofoStore.isInternal()){
|
|
|
117 |
PartnerOnBoardingPanel partnerOnBoardingPanel = partnerOnBoardingPanelRepository.selectByCode(fofoStore.getCode());
|
|
|
118 |
List<PartnerDealerMapping> partnerDealerMappingList = new ArrayList<>();
|
|
|
119 |
List<String> wodCompletedBrands = new ArrayList<>();
|
|
|
120 |
if (partnerOnBoardingPanel != null) {
|
|
|
121 |
partnerDealerMappingList = partnerDealerRepository.selectByOnboardingId(partnerOnBoardingPanel.getId());
|
|
|
122 |
if (partnerDealerMappingList != null && partnerDealerMappingList.size() > 0) {
|
|
|
123 |
//working brands -> Partner only work with brands that having 'Dealer Code'
|
| 35800 |
amit |
124 |
wodCompletedBrands = partnerDealerMappingList.stream().filter(x -> x.getBrandCode() != null && x.getBrandCode().trim().length() > 0).map(x -> x.getBrand()).collect(Collectors.toList());
|
| 34930 |
ranu |
125 |
}
|
| 34629 |
tejus.loha |
126 |
}
|
| 34930 |
ranu |
127 |
BrandAndAddToCartEligibleModel partnerWorkingBrandMappingModel = new BrandAndAddToCartEligibleModel();
|
|
|
128 |
partnerWorkingBrandMappingModel.setWodCompleteBrands(wodCompletedBrands);
|
| 36209 |
ranu |
129 |
//brandsToBeCheck - only brands where noc_required = true need dealer code verification
|
|
|
130 |
List<String> wodRequiredBrand = brandCommitRepository.selectAllActiveBrand().stream()
|
|
|
131 |
.filter(x -> x.isNocRequired())
|
|
|
132 |
.map(x -> x.getBrand()).collect(Collectors.toList());
|
| 34930 |
ranu |
133 |
partnerWorkingBrandMappingModel.setWodRequiredBrands(wodRequiredBrand);
|
|
|
134 |
return partnerWorkingBrandMappingModel;
|
|
|
135 |
}else {
|
|
|
136 |
BrandAndAddToCartEligibleModel model = new BrandAndAddToCartEligibleModel();
|
| 36078 |
aman |
137 |
List<String> wodRequiredBrand = brandCommitRepository.selectAllActiveBrand().stream().map(x -> x.getBrand()).collect(Collectors.toList());
|
| 34930 |
ranu |
138 |
model.setWodCompleteBrands(wodRequiredBrand);
|
|
|
139 |
model.setWodRequiredBrands(wodRequiredBrand);
|
|
|
140 |
return model;
|
| 34629 |
tejus.loha |
141 |
}
|
|
|
142 |
}
|
| 34513 |
ranu |
143 |
|
|
|
144 |
|
| 31507 |
tejbeer |
145 |
}
|