Subversion Repositories SmartDukaan

Rev

Rev 34629 | Rev 35203 | 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;
34930 ranu 22
import java.util.Collections;
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
37
    private RetailerBlockBrandsRepository retailerBlockBrandsRepository;
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
        }
57
        List<String> blockedBrands = retailerBlockBrandsRepository.selectAllByRetailer(fofoId).stream()
58
                .map(x -> x.getBlockBrands()).collect(Collectors.toList());
59
        brandsDisplay = brandsDisplay.stream().filter(x -> !blockedBrands.contains(x.getName()))
60
                .collect(Collectors.toList());
33122 amit.gupta 61
 
34629 tejus.loha 62
        return brandsDisplay;
63
    }
31507 tejbeer 64
 
34629 tejus.loha 65
    @Override
33243 ranu 66
    public List<BrandCatalog> getBrandsToDisplay(int categoryId) throws ProfitMandiBusinessException {
34629 tejus.loha 67
        List<BrandCategory> brandCategories = brandCategoryRepository.selectByCategoryId(categoryId).stream()
68
                .filter(x -> x.isActive()).collect(Collectors.toList());
31507 tejbeer 69
 
34629 tejus.loha 70
        Map<Integer, BrandCategory> brandCategoryMap = brandCategories.stream()
71
                .collect(Collectors.toMap(x -> x.getBrandId(), x -> x));
31507 tejbeer 72
 
34629 tejus.loha 73
        List<Integer> brandIds = brandCategories.stream().map(x -> x.getBrandId()).collect(Collectors.toList());
31507 tejbeer 74
 
34629 tejus.loha 75
        List<BrandCatalog> brands = brandCatalogRepository.selectByIds(brandIds);
31507 tejbeer 76
 
34629 tejus.loha 77
        for (BrandCatalog brand : brands) {
78
            brand.setBrandCategory(brandCategoryMap.get(brand.getId()));
79
        }
80
        return brands;
81
    }
31507 tejbeer 82
 
34629 tejus.loha 83
    @Override
84
    public List<String> partnerIneligibleBrands(int fofoId) throws ProfitMandiBusinessException {
85
        BrandAndAddToCartEligibleModel brandAndAddToCartEligibleModel = wodcompletBrands(fofoId);
86
        List<String> requiredBrand = brandAndAddToCartEligibleModel.getWodRequiredBrands();
87
        List<String> wodCompleteBrands = brandAndAddToCartEligibleModel.getWodCompleteBrands();
88
        List<String> ineligibleBrands = new ArrayList<>(requiredBrand);
89
        ineligibleBrands.removeAll(wodCompleteBrands);
90
        return ineligibleBrands;
91
    }
34513 ranu 92
 
34629 tejus.loha 93
    @Override
94
    public BrandAndAddToCartEligibleModel wodcompletBrands(int fofoId) throws ProfitMandiBusinessException {
95
        FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
34930 ranu 96
        if(!fofoStore.isInternal()){
97
            PartnerOnBoardingPanel partnerOnBoardingPanel = partnerOnBoardingPanelRepository.selectByCode(fofoStore.getCode());
98
            List<PartnerDealerMapping> partnerDealerMappingList = new ArrayList<>();
99
            List<String> wodCompletedBrands = new ArrayList<>();
100
            if (partnerOnBoardingPanel != null) {
101
                partnerDealerMappingList = partnerDealerRepository.selectByOnboardingId(partnerOnBoardingPanel.getId());
102
                if (partnerDealerMappingList != null && partnerDealerMappingList.size() > 0) {
103
                    //working brands -> Partner only work with brands that having 'Dealer Code'
104
                    wodCompletedBrands = partnerDealerMappingList.stream().filter(x -> x.getBrandCode().trim().length() > 0).map(x -> x.getBrand()).collect(Collectors.toList());
105
                }
34629 tejus.loha 106
            }
34930 ranu 107
            BrandAndAddToCartEligibleModel partnerWorkingBrandMappingModel = new BrandAndAddToCartEligibleModel();
108
            partnerWorkingBrandMappingModel.setWodCompleteBrands(wodCompletedBrands);
109
            //brandsToBeCheck
110
            List<String> wodRequiredBrand = brandCommitRepository.selectAllActiveBrand().stream().filter(x -> x.isNocRequired()).map(x -> x.getBrand()).collect(Collectors.toList());
111
            partnerWorkingBrandMappingModel.setWodRequiredBrands(wodRequiredBrand);
112
            return partnerWorkingBrandMappingModel;
113
        }else {
114
            BrandAndAddToCartEligibleModel model = new BrandAndAddToCartEligibleModel();
115
            List<String> wodRequiredBrand = brandCommitRepository.selectAllActiveBrand().stream().filter(x -> x.isNocRequired()).map(x -> x.getBrand()).collect(Collectors.toList());
116
            model.setWodCompleteBrands(wodRequiredBrand);
117
            model.setWodRequiredBrands(wodRequiredBrand);
118
            return model;
34629 tejus.loha 119
        }
120
    }
34513 ranu 121
 
122
 
31507 tejbeer 123
}