Subversion Repositories SmartDukaan

Rev

Rev 34513 | Rev 34930 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 34513 Rev 34629
Line 1... Line 1...
1
package com.spice.profitmandi.service.catalog;
1
package com.spice.profitmandi.service.catalog;
2
 
2
 
3
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
3
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
-
 
4
import com.spice.profitmandi.common.model.BrandAndAddToCartEligibleModel;
4
import com.spice.profitmandi.common.util.Utils;
5
import com.spice.profitmandi.common.util.Utils;
5
import com.spice.profitmandi.dao.entity.catalog.BrandCatalog;
6
import com.spice.profitmandi.dao.entity.catalog.BrandCatalog;
6
import com.spice.profitmandi.dao.entity.catalog.BrandCategory;
7
import com.spice.profitmandi.dao.entity.catalog.BrandCategory;
7
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
8
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.PartnerDealerMapping;
Line 23... Line 24...
23
import java.util.stream.Collectors;
24
import java.util.stream.Collectors;
24
 
25
 
25
@Component
26
@Component
26
public class BrandsServiceImpl implements BrandsService {
27
public class BrandsServiceImpl implements BrandsService {
27
 
28
 
28
	@Autowired
29
    @Autowired
29
	private BrandCategoryRepository brandCategoryRepository;
30
    private BrandCategoryRepository brandCategoryRepository;
30
 
31
 
31
	@Autowired
32
    @Autowired
32
	private BrandsRepository brandCatalogRepository;
33
    private BrandsRepository brandCatalogRepository;
33
 
34
 
34
	@Autowired
35
    @Autowired
35
	private RetailerBlockBrandsRepository retailerBlockBrandsRepository;
36
    private RetailerBlockBrandsRepository retailerBlockBrandsRepository;
36
 
37
 
37
	@Autowired
38
    @Autowired
38
	private FofoStoreRepository fofoStoreRepository;
39
    private FofoStoreRepository fofoStoreRepository;
39
 
40
 
40
	@Autowired
41
    @Autowired
41
	private PartnerOnBoardingPanelRepository partnerOnBoardingPanelRepository;
42
    private PartnerOnBoardingPanelRepository partnerOnBoardingPanelRepository;
42
 
43
 
43
	@Autowired
44
    @Autowired
44
	private PartnerDealerRepository partnerDealerRepository;
45
    private PartnerDealerRepository partnerDealerRepository;
45
 
46
 
46
	@Autowired
47
    @Autowired
47
	private BrandCommitRepository brandCommitRepository;
48
    private BrandCommitRepository brandCommitRepository;
48
 
49
 
49
	@Override
50
    @Override
50
    public List<BrandCatalog> getBrands(int fofoId, String email, int categoryId) throws ProfitMandiBusinessException {
51
    public List<BrandCatalog> getBrands(int fofoId, String email, int categoryId) throws ProfitMandiBusinessException {
51
		List<BrandCatalog> brandsDisplay = this.getBrandsToDisplay(categoryId);
52
        List<BrandCatalog> brandsDisplay = this.getBrandsToDisplay(categoryId);
52
		if (fofoId == Utils.SYSTEM_PARTNER_ID) {
53
        if (fofoId == Utils.SYSTEM_PARTNER_ID) {
53
			return brandsDisplay;
54
            return brandsDisplay;
54
		}
55
        }
55
		List<String> blockedBrands = retailerBlockBrandsRepository.selectAllByRetailer(fofoId).stream()
56
        List<String> blockedBrands = retailerBlockBrandsRepository.selectAllByRetailer(fofoId).stream()
56
				.map(x -> x.getBlockBrands()).collect(Collectors.toList());
57
                .map(x -> x.getBlockBrands()).collect(Collectors.toList());
57
		brandsDisplay = brandsDisplay.stream().filter(x -> !blockedBrands.contains(x.getName()))
58
        brandsDisplay = brandsDisplay.stream().filter(x -> !blockedBrands.contains(x.getName()))
58
				.collect(Collectors.toList());
59
                .collect(Collectors.toList());
59
 
60
 
60
		return brandsDisplay;
61
        return brandsDisplay;
61
	}
62
    }
62
 
63
 
63
	@Override
64
    @Override
64
    public List<BrandCatalog> getBrandsToDisplay(int categoryId) throws ProfitMandiBusinessException {
65
    public List<BrandCatalog> getBrandsToDisplay(int categoryId) throws ProfitMandiBusinessException {
65
		List<BrandCategory> brandCategories = brandCategoryRepository.selectByCategoryId(categoryId).stream()
66
        List<BrandCategory> brandCategories = brandCategoryRepository.selectByCategoryId(categoryId).stream()
66
				.filter(x -> x.isActive()).collect(Collectors.toList());
67
                .filter(x -> x.isActive()).collect(Collectors.toList());
67
 
68
 
68
		Map<Integer, BrandCategory> brandCategoryMap = brandCategories.stream()
69
        Map<Integer, BrandCategory> brandCategoryMap = brandCategories.stream()
69
				.collect(Collectors.toMap(x -> x.getBrandId(), x -> x));
70
                .collect(Collectors.toMap(x -> x.getBrandId(), x -> x));
70
 
71
 
71
		List<Integer> brandIds = brandCategories.stream().map(x -> x.getBrandId()).collect(Collectors.toList());
72
        List<Integer> brandIds = brandCategories.stream().map(x -> x.getBrandId()).collect(Collectors.toList());
72
 
73
 
73
		List<BrandCatalog> brands = brandCatalogRepository.selectByIds(brandIds);
74
        List<BrandCatalog> brands = brandCatalogRepository.selectByIds(brandIds);
74
 
75
 
75
		for (BrandCatalog brand : brands) {
76
        for (BrandCatalog brand : brands) {
76
			brand.setBrandCategory(brandCategoryMap.get(brand.getId()));
77
            brand.setBrandCategory(brandCategoryMap.get(brand.getId()));
77
		}
78
        }
78
		return brands;
79
        return brands;
79
	}
80
    }
80
 
81
 
81
	@Override
82
    @Override
82
	public List<String> partnerIneligibleBrands(int fofoId) throws ProfitMandiBusinessException {
83
    public List<String> partnerIneligibleBrands(int fofoId) throws ProfitMandiBusinessException {
-
 
84
        BrandAndAddToCartEligibleModel brandAndAddToCartEligibleModel = wodcompletBrands(fofoId);
-
 
85
        List<String> requiredBrand = brandAndAddToCartEligibleModel.getWodRequiredBrands();
-
 
86
        List<String> wodCompleteBrands = brandAndAddToCartEligibleModel.getWodCompleteBrands();
-
 
87
        List<String> ineligibleBrands = new ArrayList<>(requiredBrand);
-
 
88
        ineligibleBrands.removeAll(wodCompleteBrands);
-
 
89
        return ineligibleBrands;
-
 
90
    }
83
 
91
 
-
 
92
    @Override
-
 
93
    public BrandAndAddToCartEligibleModel wodcompletBrands(int fofoId) throws ProfitMandiBusinessException {
84
		FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
94
        FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
85
		PartnerOnBoardingPanel partnerOnBoardingPanel = partnerOnBoardingPanelRepository.selectByCode(fofoStore.getCode());
95
        PartnerOnBoardingPanel partnerOnBoardingPanel = partnerOnBoardingPanelRepository.selectByCode(fofoStore.getCode());
86
		List<PartnerDealerMapping> partnerDealerMappingList = new ArrayList<>();
96
        List<PartnerDealerMapping> partnerDealerMappingList = new ArrayList<>();
87
		List<String> wodRequiredBrands = new ArrayList<>();
97
        List<String> wodCompletedBrands = new ArrayList<>();
88
		if (partnerOnBoardingPanel != null) {
98
        if (partnerOnBoardingPanel != null) {
89
			partnerDealerMappingList = partnerDealerRepository.selectByOnboardingId(partnerOnBoardingPanel.getId());
99
            partnerDealerMappingList = partnerDealerRepository.selectByOnboardingId(partnerOnBoardingPanel.getId());
90
			if (partnerDealerMappingList != null && partnerDealerMappingList.size() > 0) {
100
            if (partnerDealerMappingList != null && partnerDealerMappingList.size() > 0) {
91
				//working brands -> Partner only work with brands that having 'Dealer Code'
101
                //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());
102
                wodCompletedBrands = partnerDealerMappingList.stream().filter(x -> x.getBrandCode().trim().length() > 0).map(x -> x.getBrand()).collect(Collectors.toList());
93
			}
103
            }
94
		}
104
        }
95
 
-
 
-
 
105
        BrandAndAddToCartEligibleModel partnerWorkingBrandMappingModel = new BrandAndAddToCartEligibleModel();
-
 
106
        partnerWorkingBrandMappingModel.setWodCompleteBrands(wodCompletedBrands);
96
		//brandsToBeCheck
107
        //brandsToBeCheck
97
		List<String> nocRequiredBrand = brandCommitRepository.selectAllActiveBrand().stream().filter(x -> x.isNocRequired()).map(x -> x.getBrand()).collect(Collectors.toList());
108
        List<String> wodRequiredBrand = brandCommitRepository.selectAllActiveBrand().stream().filter(x -> x.isNocRequired()).map(x -> x.getBrand()).collect(Collectors.toList());
98
		List<String> ineligibleBrands = nocRequiredBrand.stream()
109
        partnerWorkingBrandMappingModel.setWodRequiredBrands(wodRequiredBrand);
99
				.filter(wodRequiredBrands::contains)
110
        return partnerWorkingBrandMappingModel;
100
				.collect(Collectors.toList());
111
    }
101
 
112
 
102
		return ineligibleBrands;
-
 
103
	}
-
 
104
 
113
 
105
}
114
}