Rev 21870 | Rev 21926 | Go to most recent revision | View as "text/plain" | Blame | Compare with Previous | Last modification | View Log | RSS feed
package com.spice.profitmandi.service.pricing;import java.util.HashSet;import java.util.List;import java.util.Set;import org.apache.commons.collections.CollectionUtils;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Component;import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;import com.spice.profitmandi.dao.entity.fofo.RetailerTag;import com.spice.profitmandi.dao.entity.fofo.TagListing;import com.spice.profitmandi.dao.entity.user.Address;import com.spice.profitmandi.dao.repository.dtr.RetailerRegisteredAddressRepository;import com.spice.profitmandi.dao.repository.fofo.PinCodeTagRepository;import com.spice.profitmandi.dao.repository.fofo.RetailerTagRepository;import com.spice.profitmandi.dao.repository.fofo.TagListingRepository;import com.spice.profitmandi.dao.repository.user.AddressRepository;import com.spice.profitmandi.service.tag.TagService;@Componentpublic class PricingServiceImpl implements PricingService{@AutowiredRetailerRegisteredAddressRepository retailerRegisteredAddressRepository;@AutowiredAddressRepository addressRepository;@AutowiredPinCodeTagRepository pinCodeTagRepository;@AutowiredTagService tagService;@AutowiredRetailerTagRepository retailerTagRepository;@AutowiredTagListingRepository tagListingRepository;@SuppressWarnings("unchecked")@Overridepublic float getPrice(Set<Integer> itemIds, int retailerId) {float price = Float.MAX_VALUE;int addressId;try {addressId = retailerRegisteredAddressRepository.selectAddressIdByRetailerId(retailerId);Address retailerAddress = addressRepository.selectById(addressId);Set<Integer> pinCodeTagIds = tagService.getFofoTagIdsByPinCode(retailerAddress.getPinCode());if(pinCodeTagIds.isEmpty()){return price;}Set<Integer> pinPositiveTagIds = tagService.getPinCodePositiveTagIds();if(pinPositiveTagIds.isEmpty()){return price;}Set<Integer> pinCodeIntersection = (Set<Integer>)CollectionUtils.intersection(pinCodeTagIds, pinPositiveTagIds);Set<Integer> pinCodeUnion = (Set<Integer>) CollectionUtils.union(pinCodeTagIds, pinPositiveTagIds);Set<Integer> filterPinCodeTagIds = (Set<Integer>)CollectionUtils.subtract(pinCodeUnion, pinCodeIntersection);if(filterPinCodeTagIds.isEmpty()){return price;}List<RetailerTag> retailerTags = retailerTagRepository.selectByTagIds(filterPinCodeTagIds);if(retailerTags.isEmpty()){return price;}Set<Integer> retailerTagIds = new HashSet<>();for(RetailerTag retailerTag : retailerTags){retailerTagIds.add(retailerTag.getTagId());}Set<Integer> userPositiveTagIds = tagService.getUserPositiveTagIds();Set<Integer> userIntersection = (Set<Integer>)CollectionUtils.intersection(retailerTagIds, userPositiveTagIds);Set<Integer> userUnion = (Set<Integer>)CollectionUtils.union(retailerTagIds, userPositiveTagIds);Set<Integer> filterUserTagIds = (Set<Integer>)CollectionUtils.subtract(userUnion, userIntersection);if(filterUserTagIds.isEmpty()){return price;}List<TagListing> tagListings = tagListingRepository.selectByItemIdsAndTagIds(itemIds, filterUserTagIds);if(tagListings.isEmpty()){return price;}for(TagListing tagListing : tagListings){if(price > tagListing.getSellingPrice()){price = tagListing.getSellingPrice();}}} catch (ProfitMandiBusinessException e) {e.printStackTrace();}return price;}}