| 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;
|
- |
|
| 4 |
import java.util.HashSet;
|
3 |
import java.util.HashSet;
|
| 5 |
import java.util.List;
|
4 |
import java.util.List;
|
| 6 |
import java.util.Set;
|
5 |
import java.util.Set;
|
| 7 |
|
6 |
|
| - |
|
7 |
import org.apache.commons.collections.CollectionUtils;
|
| 8 |
import org.springframework.beans.factory.annotation.Autowired;
|
8 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 9 |
|
9 |
|
| 10 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
10 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 11 |
import com.spice.profitmandi.dao.entity.fofo.RetailerTag;
|
11 |
import com.spice.profitmandi.dao.entity.fofo.RetailerTag;
|
| 12 |
import com.spice.profitmandi.dao.entity.fofo.TagListing;
|
12 |
import com.spice.profitmandi.dao.entity.fofo.TagListing;
|
| Line 36... |
Line 36... |
| 36 |
RetailerTagRepository retailerTagRepository;
|
36 |
RetailerTagRepository retailerTagRepository;
|
| 37 |
|
37 |
|
| 38 |
@Autowired
|
38 |
@Autowired
|
| 39 |
TagListingRepository tagListingRepository;
|
39 |
TagListingRepository tagListingRepository;
|
| 40 |
|
40 |
|
| - |
|
41 |
@SuppressWarnings("unchecked")
|
| 41 |
@Override
|
42 |
@Override
|
| 42 |
public float getPrice(int itemId, int retailerId) {
|
43 |
public float getPrice(int itemId, int retailerId) {
|
| - |
|
44 |
float price = Float.MAX_VALUE;
|
| 43 |
int addressId;
|
45 |
int addressId;
|
| 44 |
try {
|
46 |
try {
|
| 45 |
float price = Float.MAX_VALUE;
|
47 |
|
| 46 |
addressId = retailerRegisteredAddressRepository.selectAddressIdByRetailerId(retailerId);
|
48 |
addressId = retailerRegisteredAddressRepository.selectAddressIdByRetailerId(retailerId);
|
| 47 |
Address retailerAddress = addressRepository.selectById(addressId);
|
49 |
Address retailerAddress = addressRepository.selectById(addressId);
|
| 48 |
Set<Integer> pinCodeTagIds = tagService.getFofoTagIdsByPinCode(retailerAddress.getPinCode());
|
50 |
Set<Integer> pinCodeTagIds = tagService.getFofoTagIdsByPinCode(retailerAddress.getPinCode());
|
| 49 |
if(pinCodeTagIds.isEmpty()){
|
51 |
if(pinCodeTagIds.isEmpty()){
|
| 50 |
return price;
|
52 |
return price;
|
| 51 |
}
|
53 |
}
|
| - |
|
54 |
Set<Integer> pinPositiveTagIds = tagService.getPinCodePositiveTagIds();
|
| - |
|
55 |
if(pinPositiveTagIds.isEmpty()){
|
| - |
|
56 |
return price;
|
| - |
|
57 |
}
|
| - |
|
58 |
Set<Integer> pinCodeIntersection = (Set<Integer>)CollectionUtils.intersection(pinCodeTagIds, pinPositiveTagIds);
|
| - |
|
59 |
Set<Integer> pinCodeUnion = (Set<Integer>) CollectionUtils.union(pinCodeTagIds, pinPositiveTagIds);
|
| - |
|
60 |
Set<Integer> filterPinCodeTagIds = (Set<Integer>)CollectionUtils.subtract(pinCodeUnion, pinCodeIntersection);
|
| - |
|
61 |
if(filterPinCodeTagIds.isEmpty()){
|
| - |
|
62 |
return price;
|
| - |
|
63 |
}
|
| 52 |
List<RetailerTag> retailerTags = retailerTagRepository.selectByTagIds(pinCodeTagIds);
|
64 |
List<RetailerTag> retailerTags = retailerTagRepository.selectByTagIds(filterPinCodeTagIds);
|
| 53 |
if(retailerTags.isEmpty()){
|
65 |
if(retailerTags.isEmpty()){
|
| 54 |
return price;
|
66 |
return price;
|
| 55 |
}
|
67 |
}
|
| 56 |
Set<Integer> retailerTagIds = new HashSet<>();
|
68 |
Set<Integer> retailerTagIds = new HashSet<>();
|
| 57 |
for(RetailerTag retailerTag : retailerTags){
|
69 |
for(RetailerTag retailerTag : retailerTags){
|
| 58 |
retailerTagIds.add(retailerTag.getTagId());
|
70 |
retailerTagIds.add(retailerTag.getTagId());
|
| 59 |
}
|
71 |
}
|
| - |
|
72 |
Set<Integer> userPositiveTagIds = tagService.getUserPositiveTagIds();
|
| - |
|
73 |
Set<Integer> userIntersection = (Set<Integer>)CollectionUtils.intersection(retailerTagIds, userPositiveTagIds);
|
| - |
|
74 |
Set<Integer> userUnion = (Set<Integer>)CollectionUtils.union(retailerTagIds, userPositiveTagIds);
|
| - |
|
75 |
Set<Integer> filterUserTagIds = (Set<Integer>)CollectionUtils.subtract(userUnion, userIntersection);
|
| - |
|
76 |
if(filterUserTagIds.isEmpty()){
|
| - |
|
77 |
return price;
|
| - |
|
78 |
}
|
| 60 |
List<TagListing> tagListings = tagListingRepository.selectByItemIdAndTagIds(itemId, retailerTagIds);
|
79 |
List<TagListing> tagListings = tagListingRepository.selectByItemIdAndTagIds(itemId, filterUserTagIds);
|
| 61 |
if(tagListings.isEmpty()){
|
80 |
if(tagListings.isEmpty()){
|
| 62 |
return price;
|
81 |
return price;
|
| 63 |
}
|
82 |
}
|
| 64 |
|
- |
|
| 65 |
for(TagListing tagListing : tagListings){
|
83 |
for(TagListing tagListing : tagListings){
|
| 66 |
if(price > tagListing.getSellingPrice()){
|
84 |
if(price > tagListing.getSellingPrice()){
|
| 67 |
price = tagListing.getSellingPrice();
|
85 |
price = tagListing.getSellingPrice();
|
| 68 |
}
|
86 |
}
|
| 69 |
}
|
87 |
}
|
| 70 |
|
- |
|
| 71 |
} catch (ProfitMandiBusinessException e) {
|
88 |
} catch (ProfitMandiBusinessException e) {
|
| 72 |
// TODO Auto-generated catch block
|
- |
|
| 73 |
e.printStackTrace();
|
89 |
e.printStackTrace();
|
| 74 |
}
|
90 |
}
|
| 75 |
|
- |
|
| 76 |
return 0;
|
91 |
return price;
|
| 77 |
}
|
92 |
}
|
| 78 |
|
93 |
|
| 79 |
}
|
94 |
}
|