Subversion Repositories SmartDukaan

Rev

Rev 34930 | Rev 35337 | 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
 
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);
57
        brandsDisplay = brandsDisplay.stream().filter(x -> !ineligibleBrands.contains(x.getName()))
34629 tejus.loha 58
                .collect(Collectors.toList());
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
92
    public BrandAndAddToCartEligibleModel wodcompletBrands(int fofoId) throws ProfitMandiBusinessException {
93
        FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
34930 ranu 94
        if(!fofoStore.isInternal()){
95
            PartnerOnBoardingPanel partnerOnBoardingPanel = partnerOnBoardingPanelRepository.selectByCode(fofoStore.getCode());
96
            List<PartnerDealerMapping> partnerDealerMappingList = new ArrayList<>();
97
            List<String> wodCompletedBrands = new ArrayList<>();
98
            if (partnerOnBoardingPanel != null) {
99
                partnerDealerMappingList = partnerDealerRepository.selectByOnboardingId(partnerOnBoardingPanel.getId());
100
                if (partnerDealerMappingList != null && partnerDealerMappingList.size() > 0) {
101
                    //working brands -> Partner only work with brands that having 'Dealer Code'
102
                    wodCompletedBrands = partnerDealerMappingList.stream().filter(x -> x.getBrandCode().trim().length() > 0).map(x -> x.getBrand()).collect(Collectors.toList());
103
                }
34629 tejus.loha 104
            }
34930 ranu 105
            BrandAndAddToCartEligibleModel partnerWorkingBrandMappingModel = new BrandAndAddToCartEligibleModel();
106
            partnerWorkingBrandMappingModel.setWodCompleteBrands(wodCompletedBrands);
107
            //brandsToBeCheck
108
            List<String> wodRequiredBrand = brandCommitRepository.selectAllActiveBrand().stream().filter(x -> x.isNocRequired()).map(x -> x.getBrand()).collect(Collectors.toList());
109
            partnerWorkingBrandMappingModel.setWodRequiredBrands(wodRequiredBrand);
110
            return partnerWorkingBrandMappingModel;
111
        }else {
112
            BrandAndAddToCartEligibleModel model = new BrandAndAddToCartEligibleModel();
113
            List<String> wodRequiredBrand = brandCommitRepository.selectAllActiveBrand().stream().filter(x -> x.isNocRequired()).map(x -> x.getBrand()).collect(Collectors.toList());
114
            model.setWodCompleteBrands(wodRequiredBrand);
115
            model.setWodRequiredBrands(wodRequiredBrand);
116
            return model;
34629 tejus.loha 117
        }
118
    }
34513 ranu 119
 
120
 
31507 tejbeer 121
}