Subversion Repositories SmartDukaan

Rev

Rev 21803 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
21801 ashik.ali 1
package com.spice.profitmandi.service.pricing;
2
 
3
import java.util.HashSet;
4
import java.util.List;
5
import java.util.Set;
6
 
7
import org.springframework.beans.factory.annotation.Autowired;
8
 
9
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
10
import com.spice.profitmandi.dao.entity.fofo.RetailerTag;
11
import com.spice.profitmandi.dao.entity.fofo.TagListing;
12
import com.spice.profitmandi.dao.entity.user.Address;
13
import com.spice.profitmandi.dao.repository.dtr.RetailerRegisteredAddressRepository;
14
import com.spice.profitmandi.dao.repository.fofo.PinCodeTagRepository;
15
import com.spice.profitmandi.dao.repository.fofo.RetailerTagRepository;
16
import com.spice.profitmandi.dao.repository.fofo.TagListingRepository;
17
import com.spice.profitmandi.dao.repository.user.AddressRepository;
18
import com.spice.profitmandi.service.tag.TagService;
19
 
20
public class PricingServiceImpl implements PricingService{
21
 
22
	@Autowired
23
	RetailerRegisteredAddressRepository retailerRegisteredAddressRepository;
24
 
25
	@Autowired
26
	AddressRepository addressRepository;
27
 
28
	@Autowired
29
	PinCodeTagRepository pinCodeTagRepository;
30
 
31
	@Autowired
32
	TagService tagService;
33
 
34
	@Autowired
35
	RetailerTagRepository retailerTagRepository;
36
 
37
	@Autowired
38
	TagListingRepository tagListingRepository;
39
 
40
	@Override
41
	public float getPrice(int itemId, int retailerId) {
42
		int addressId;
43
		try {
44
			addressId = retailerRegisteredAddressRepository.selectAddressIdByRetailerId(retailerId);
45
			Address retailerAddress = addressRepository.selectById(addressId);
46
			Set<Integer> pinCodeTagIds = tagService.getFofoTagIdsByPinCode(retailerAddress.getPinCode());
47
			if(pinCodeTagIds.isEmpty()){
48
				return 0;
49
			}
50
			List<RetailerTag> retailerTags = retailerTagRepository.selectByTagIds(pinCodeTagIds);
51
			if(retailerTags.isEmpty()){
52
				return 0;
53
			}
54
			Set<Integer> retailerTagIds = new HashSet<>();
55
			for(RetailerTag retailerTag : retailerTags){
56
				retailerTagIds.add(retailerTag.getTagId());
57
			}
58
			List<TagListing> tagListings = tagListingRepository.selectByItemIdAndTagIds(itemId, retailerTagIds);
59
			if(tagListings.isEmpty()){
60
				return 0;
61
			}
62
			float price = Float.MAX_VALUE;
63
			for(TagListing tagListing : tagListings){
64
				if(price > tagListing.getSellingPrice()){
65
					price = tagListing.getSellingPrice();
66
				}
67
			}
68
			if(price == Float.MAX_VALUE){
69
				price = 0;
70
			}
71
		} catch (ProfitMandiBusinessException e) {
72
			// TODO Auto-generated catch block
73
			e.printStackTrace();
74
		}
75
 
76
		return 0;
77
	}
78
 
79
}