| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.service.pricing;
|
1 |
package com.spice.profitmandi.service.pricing;
|
| 2 |
|
2 |
|
| - |
|
3 |
import java.util.HashMap;
|
| 3 |
import java.util.HashSet;
|
4 |
import java.util.HashSet;
|
| 4 |
import java.util.List;
|
5 |
import java.util.List;
|
| - |
|
6 |
import java.util.Map;
|
| 5 |
import java.util.Set;
|
7 |
import java.util.Set;
|
| 6 |
|
8 |
|
| 7 |
import org.apache.commons.collections.CollectionUtils;
|
9 |
import org.apache.commons.collections.CollectionUtils;
|
| 8 |
import org.springframework.beans.factory.annotation.Autowired;
|
10 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 9 |
import org.springframework.stereotype.Component;
|
11 |
import org.springframework.stereotype.Component;
|
| Line 40... |
Line 42... |
| 40 |
@Autowired
|
42 |
@Autowired
|
| 41 |
TagListingRepository tagListingRepository;
|
43 |
TagListingRepository tagListingRepository;
|
| 42 |
|
44 |
|
| 43 |
@SuppressWarnings("unchecked")
|
45 |
@SuppressWarnings("unchecked")
|
| 44 |
@Override
|
46 |
@Override
|
| 45 |
public float getPrice(Set<Integer> itemIds, int retailerId) {
|
47 |
public Map<Integer, Float> getPrice(Set<Integer> itemIds, int retailerId) {
|
| 46 |
float price = Float.MAX_VALUE;
|
48 |
Map<Integer, Float> itemIdPrice = this.preparePriceDefaultValues(itemIds);
|
| 47 |
int addressId;
|
49 |
int addressId;
|
| 48 |
try {
|
50 |
try {
|
| 49 |
|
51 |
|
| 50 |
addressId = retailerRegisteredAddressRepository.selectAddressIdByRetailerId(retailerId);
|
52 |
addressId = retailerRegisteredAddressRepository.selectAddressIdByRetailerId(retailerId);
|
| 51 |
Address retailerAddress = addressRepository.selectById(addressId);
|
53 |
Address retailerAddress = addressRepository.selectById(addressId);
|
| 52 |
Set<Integer> pinCodeTagIds = tagService.getFofoTagIdsByPinCode(retailerAddress.getPinCode());
|
54 |
Set<Integer> pinCodeTagIds = tagService.getFofoTagIdsByPinCode(retailerAddress.getPinCode());
|
| 53 |
if(pinCodeTagIds.isEmpty()){
|
55 |
if(pinCodeTagIds.isEmpty()){
|
| 54 |
return price;
|
56 |
return itemIdPrice;
|
| 55 |
}
|
57 |
}
|
| 56 |
Set<Integer> pinPositiveTagIds = tagService.getPinCodePositiveTagIds();
|
58 |
Set<Integer> pinPositiveTagIds = tagService.getPinCodePositiveTagIds();
|
| 57 |
if(pinPositiveTagIds.isEmpty()){
|
59 |
if(pinPositiveTagIds.isEmpty()){
|
| 58 |
return price;
|
60 |
return itemIdPrice;
|
| 59 |
}
|
61 |
}
|
| 60 |
Set<Integer> pinCodeIntersection = (Set<Integer>)CollectionUtils.intersection(pinCodeTagIds, pinPositiveTagIds);
|
62 |
Set<Integer> pinCodeIntersection = (Set<Integer>)CollectionUtils.intersection(pinCodeTagIds, pinPositiveTagIds);
|
| 61 |
Set<Integer> pinCodeUnion = (Set<Integer>) CollectionUtils.union(pinCodeTagIds, pinPositiveTagIds);
|
63 |
Set<Integer> pinCodeUnion = (Set<Integer>) CollectionUtils.union(pinCodeTagIds, pinPositiveTagIds);
|
| 62 |
Set<Integer> filterPinCodeTagIds = (Set<Integer>)CollectionUtils.subtract(pinCodeUnion, pinCodeIntersection);
|
64 |
Set<Integer> filterPinCodeTagIds = (Set<Integer>)CollectionUtils.subtract(pinCodeUnion, pinCodeIntersection);
|
| 63 |
if(filterPinCodeTagIds.isEmpty()){
|
65 |
if(filterPinCodeTagIds.isEmpty()){
|
| 64 |
return price;
|
66 |
return itemIdPrice;
|
| 65 |
}
|
67 |
}
|
| 66 |
List<RetailerTag> retailerTags = retailerTagRepository.selectByTagIds(filterPinCodeTagIds);
|
68 |
List<RetailerTag> retailerTags = retailerTagRepository.selectByTagIds(filterPinCodeTagIds);
|
| 67 |
if(retailerTags.isEmpty()){
|
69 |
if(retailerTags.isEmpty()){
|
| 68 |
return price;
|
70 |
return itemIdPrice;
|
| 69 |
}
|
71 |
}
|
| 70 |
Set<Integer> retailerTagIds = new HashSet<>();
|
72 |
Set<Integer> retailerTagIds = new HashSet<>();
|
| 71 |
for(RetailerTag retailerTag : retailerTags){
|
73 |
for(RetailerTag retailerTag : retailerTags){
|
| 72 |
retailerTagIds.add(retailerTag.getTagId());
|
74 |
retailerTagIds.add(retailerTag.getTagId());
|
| 73 |
}
|
75 |
}
|
| 74 |
Set<Integer> userPositiveTagIds = tagService.getUserPositiveTagIds();
|
76 |
Set<Integer> userPositiveTagIds = tagService.getUserPositiveTagIds();
|
| 75 |
Set<Integer> userIntersection = (Set<Integer>)CollectionUtils.intersection(retailerTagIds, userPositiveTagIds);
|
77 |
Set<Integer> userIntersection = (Set<Integer>)CollectionUtils.intersection(retailerTagIds, userPositiveTagIds);
|
| 76 |
Set<Integer> userUnion = (Set<Integer>)CollectionUtils.union(retailerTagIds, userPositiveTagIds);
|
78 |
Set<Integer> userUnion = (Set<Integer>)CollectionUtils.union(retailerTagIds, userPositiveTagIds);
|
| 77 |
Set<Integer> filterUserTagIds = (Set<Integer>)CollectionUtils.subtract(userUnion, userIntersection);
|
79 |
Set<Integer> filterUserTagIds = (Set<Integer>)CollectionUtils.subtract(userUnion, userIntersection);
|
| 78 |
if(filterUserTagIds.isEmpty()){
|
80 |
if(filterUserTagIds.isEmpty()){
|
| 79 |
return price;
|
81 |
return itemIdPrice;
|
| 80 |
}
|
82 |
}
|
| 81 |
List<TagListing> tagListings = tagListingRepository.selectByItemIdsAndTagIds(itemIds, filterUserTagIds);
|
83 |
List<TagListing> tagListings = tagListingRepository.selectByItemIdsAndTagIds(itemIds, filterUserTagIds);
|
| - |
|
84 |
|
| 82 |
if(tagListings.isEmpty()){
|
85 |
if(tagListings.isEmpty()){
|
| 83 |
return price;
|
86 |
return itemIdPrice;
|
| 84 |
}
|
87 |
}
|
| 85 |
for(TagListing tagListing : tagListings){
|
88 |
for(TagListing tagListing : tagListings){
|
| 86 |
if(price > tagListing.getSellingPrice()){
|
89 |
if(itemIdPrice.get(tagListing.getItemId()) > tagListing.getSellingPrice()){
|
| 87 |
price = tagListing.getSellingPrice();
|
90 |
itemIdPrice.put(tagListing.getItemId(), tagListing.getSellingPrice());
|
| 88 |
}
|
91 |
}
|
| 89 |
}
|
92 |
}
|
| 90 |
} catch (ProfitMandiBusinessException e) {
|
93 |
} catch (ProfitMandiBusinessException e) {
|
| 91 |
e.printStackTrace();
|
94 |
e.printStackTrace();
|
| 92 |
}
|
95 |
}
|
| 93 |
return price;
|
96 |
return itemIdPrice;
|
| - |
|
97 |
}
|
| - |
|
98 |
|
| - |
|
99 |
private Map<Integer, Float> preparePriceDefaultValues(Set<Integer> itemIds){
|
| - |
|
100 |
Map<Integer, Float> itemIdPrice = new HashMap<>(itemIds.size());
|
| - |
|
101 |
for(int itemId : itemIds){
|
| - |
|
102 |
itemIdPrice.put(itemId, Float.MAX_VALUE);
|
| - |
|
103 |
}
|
| - |
|
104 |
return itemIdPrice;
|
| 94 |
}
|
105 |
}
|
| 95 |
|
106 |
|
| 96 |
}
|
107 |
}
|