| 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 |
|
| 21867 |
ashik.ali |
7 |
import org.apache.commons.collections.CollectionUtils;
|
| 21801 |
ashik.ali |
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 |
|
| 21867 |
ashik.ali |
41 |
@SuppressWarnings("unchecked")
|
| 21801 |
ashik.ali |
42 |
@Override
|
|
|
43 |
public float getPrice(int itemId, int retailerId) {
|
| 21867 |
ashik.ali |
44 |
float price = Float.MAX_VALUE;
|
| 21801 |
ashik.ali |
45 |
int addressId;
|
|
|
46 |
try {
|
| 21867 |
ashik.ali |
47 |
|
| 21801 |
ashik.ali |
48 |
addressId = retailerRegisteredAddressRepository.selectAddressIdByRetailerId(retailerId);
|
|
|
49 |
Address retailerAddress = addressRepository.selectById(addressId);
|
|
|
50 |
Set<Integer> pinCodeTagIds = tagService.getFofoTagIdsByPinCode(retailerAddress.getPinCode());
|
|
|
51 |
if(pinCodeTagIds.isEmpty()){
|
| 21803 |
amit.gupta |
52 |
return price;
|
| 21801 |
ashik.ali |
53 |
}
|
| 21867 |
ashik.ali |
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 |
}
|
|
|
64 |
List<RetailerTag> retailerTags = retailerTagRepository.selectByTagIds(filterPinCodeTagIds);
|
| 21801 |
ashik.ali |
65 |
if(retailerTags.isEmpty()){
|
| 21803 |
amit.gupta |
66 |
return price;
|
| 21801 |
ashik.ali |
67 |
}
|
|
|
68 |
Set<Integer> retailerTagIds = new HashSet<>();
|
|
|
69 |
for(RetailerTag retailerTag : retailerTags){
|
|
|
70 |
retailerTagIds.add(retailerTag.getTagId());
|
|
|
71 |
}
|
| 21867 |
ashik.ali |
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 |
}
|
|
|
79 |
List<TagListing> tagListings = tagListingRepository.selectByItemIdAndTagIds(itemId, filterUserTagIds);
|
| 21801 |
ashik.ali |
80 |
if(tagListings.isEmpty()){
|
| 21803 |
amit.gupta |
81 |
return price;
|
| 21801 |
ashik.ali |
82 |
}
|
|
|
83 |
for(TagListing tagListing : tagListings){
|
|
|
84 |
if(price > tagListing.getSellingPrice()){
|
|
|
85 |
price = tagListing.getSellingPrice();
|
|
|
86 |
}
|
|
|
87 |
}
|
|
|
88 |
} catch (ProfitMandiBusinessException e) {
|
|
|
89 |
e.printStackTrace();
|
|
|
90 |
}
|
| 21867 |
ashik.ali |
91 |
return price;
|
| 21801 |
ashik.ali |
92 |
}
|
|
|
93 |
|
|
|
94 |
}
|