Subversion Repositories SmartDukaan

Rev

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

Rev 21801 Rev 21803
Line 1... Line 1...
1
package com.spice.profitmandi.service.pricing;
1
package com.spice.profitmandi.service.pricing;
2
 
2
 
-
 
3
import java.util.Comparator;
3
import java.util.HashSet;
4
import java.util.HashSet;
4
import java.util.List;
5
import java.util.List;
5
import java.util.Set;
6
import java.util.Set;
6
 
7
 
7
import org.springframework.beans.factory.annotation.Autowired;
8
import org.springframework.beans.factory.annotation.Autowired;
Line 39... Line 40...
39
	
40
	
40
	@Override
41
	@Override
41
	public float getPrice(int itemId, int retailerId) {
42
	public float getPrice(int itemId, int retailerId) {
42
		int addressId;
43
		int addressId;
43
		try {
44
		try {
-
 
45
			float price = Float.MAX_VALUE;
44
			addressId = retailerRegisteredAddressRepository.selectAddressIdByRetailerId(retailerId);
46
			addressId = retailerRegisteredAddressRepository.selectAddressIdByRetailerId(retailerId);
45
			Address retailerAddress = addressRepository.selectById(addressId);
47
			Address retailerAddress = addressRepository.selectById(addressId);
46
			Set<Integer> pinCodeTagIds = tagService.getFofoTagIdsByPinCode(retailerAddress.getPinCode());
48
			Set<Integer> pinCodeTagIds = tagService.getFofoTagIdsByPinCode(retailerAddress.getPinCode());
47
			if(pinCodeTagIds.isEmpty()){
49
			if(pinCodeTagIds.isEmpty()){
48
				return 0;
50
				return price;
49
			}
51
			}
50
			List<RetailerTag> retailerTags = retailerTagRepository.selectByTagIds(pinCodeTagIds);
52
			List<RetailerTag> retailerTags = retailerTagRepository.selectByTagIds(pinCodeTagIds);
51
			if(retailerTags.isEmpty()){
53
			if(retailerTags.isEmpty()){
52
				return 0;
54
				return price;
53
			}
55
			}
54
			Set<Integer> retailerTagIds = new HashSet<>();
56
			Set<Integer> retailerTagIds = new HashSet<>();
55
			for(RetailerTag retailerTag : retailerTags){
57
			for(RetailerTag retailerTag : retailerTags){
56
				retailerTagIds.add(retailerTag.getTagId());
58
				retailerTagIds.add(retailerTag.getTagId());
57
			}
59
			}
58
			List<TagListing> tagListings = tagListingRepository.selectByItemIdAndTagIds(itemId, retailerTagIds);
60
			List<TagListing> tagListings = tagListingRepository.selectByItemIdAndTagIds(itemId, retailerTagIds);
59
			if(tagListings.isEmpty()){
61
			if(tagListings.isEmpty()){
60
				return 0;
62
				return price;
61
			}
63
			}
62
			float price = Float.MAX_VALUE;
64
			
63
			for(TagListing tagListing : tagListings){
65
			for(TagListing tagListing : tagListings){
64
				if(price > tagListing.getSellingPrice()){
66
				if(price > tagListing.getSellingPrice()){
65
					price = tagListing.getSellingPrice();
67
					price = tagListing.getSellingPrice();
66
				}
68
				}
67
			}
69
			}
68
			if(price == Float.MAX_VALUE){
-
 
69
				price = 0;
-
 
70
			}
70
			
71
		} catch (ProfitMandiBusinessException e) {
71
		} catch (ProfitMandiBusinessException e) {
72
			// TODO Auto-generated catch block
72
			// TODO Auto-generated catch block
73
			e.printStackTrace();
73
			e.printStackTrace();
74
		}
74
		}
75
		
75