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