| Line 3... |
Line 3... |
| 3 |
import java.text.MessageFormat;
|
3 |
import java.text.MessageFormat;
|
| 4 |
import java.time.LocalDate;
|
4 |
import java.time.LocalDate;
|
| 5 |
import java.time.LocalDateTime;
|
5 |
import java.time.LocalDateTime;
|
| 6 |
import java.util.ArrayList;
|
6 |
import java.util.ArrayList;
|
| 7 |
import java.util.Arrays;
|
7 |
import java.util.Arrays;
|
| - |
|
8 |
import java.util.Collection;
|
| 8 |
import java.util.HashMap;
|
9 |
import java.util.HashMap;
|
| 9 |
import java.util.HashSet;
|
10 |
import java.util.HashSet;
|
| 10 |
import java.util.List;
|
11 |
import java.util.List;
|
| 11 |
import java.util.Map;
|
12 |
import java.util.Map;
|
| 12 |
import java.util.Set;
|
13 |
import java.util.Set;
|
| - |
|
14 |
import java.util.AbstractMap.SimpleEntry;
|
| 13 |
import java.util.stream.Collectors;
|
15 |
import java.util.stream.Collectors;
|
| 14 |
|
16 |
|
| 15 |
import javax.persistence.criteria.CriteriaBuilder;
|
17 |
import javax.persistence.criteria.CriteriaBuilder;
|
| 16 |
import javax.persistence.criteria.CriteriaQuery;
|
18 |
import javax.persistence.criteria.CriteriaQuery;
|
| 17 |
import javax.persistence.criteria.Predicate;
|
19 |
import javax.persistence.criteria.Predicate;
|
| Line 27... |
Line 29... |
| 27 |
import org.springframework.cache.annotation.Cacheable;
|
29 |
import org.springframework.cache.annotation.Cacheable;
|
| 28 |
import org.springframework.stereotype.Component;
|
30 |
import org.springframework.stereotype.Component;
|
| 29 |
|
31 |
|
| 30 |
import com.spice.profitmandi.common.enumuration.ItemType;
|
32 |
import com.spice.profitmandi.common.enumuration.ItemType;
|
| 31 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
33 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| - |
|
34 |
import com.spice.profitmandi.common.model.CatalogIdAggregateValue;
|
| 32 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
35 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 33 |
import com.spice.profitmandi.common.model.SchemeModel;
|
36 |
import com.spice.profitmandi.common.model.SchemeModel;
|
| 34 |
import com.spice.profitmandi.common.util.StringUtils;
|
37 |
import com.spice.profitmandi.common.util.StringUtils;
|
| 35 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
38 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
| - |
|
39 |
import com.spice.profitmandi.dao.entity.catalog.Offer;
|
| - |
|
40 |
import com.spice.profitmandi.dao.entity.catalog.OfferPartner;
|
| 36 |
import com.spice.profitmandi.dao.entity.catalog.RetailerScheme;
|
41 |
import com.spice.profitmandi.dao.entity.catalog.RetailerScheme;
|
| 37 |
import com.spice.profitmandi.dao.entity.catalog.Scheme;
|
42 |
import com.spice.profitmandi.dao.entity.catalog.Scheme;
|
| 38 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
|
43 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
|
| - |
|
44 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrderItem;
|
| 39 |
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
|
45 |
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
|
| 40 |
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
|
46 |
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
|
| 41 |
import com.spice.profitmandi.dao.entity.fofo.Purchase;
|
47 |
import com.spice.profitmandi.dao.entity.fofo.Purchase;
|
| 42 |
import com.spice.profitmandi.dao.entity.fofo.ScanRecord;
|
48 |
import com.spice.profitmandi.dao.entity.fofo.ScanRecord;
|
| 43 |
import com.spice.profitmandi.dao.entity.fofo.SchemeInOut;
|
49 |
import com.spice.profitmandi.dao.entity.fofo.SchemeInOut;
|
| Line 45... |
Line 51... |
| 45 |
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
|
51 |
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
|
| 46 |
import com.spice.profitmandi.dao.enumuration.catalog.AmountType;
|
52 |
import com.spice.profitmandi.dao.enumuration.catalog.AmountType;
|
| 47 |
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
|
53 |
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
|
| 48 |
import com.spice.profitmandi.dao.enumuration.fofo.ScanType;
|
54 |
import com.spice.profitmandi.dao.enumuration.fofo.ScanType;
|
| 49 |
import com.spice.profitmandi.dao.model.CreateSchemeRequest;
|
55 |
import com.spice.profitmandi.dao.model.CreateSchemeRequest;
|
| - |
|
56 |
import com.spice.profitmandi.dao.repository.GenericRepository;
|
| 50 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
57 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 51 |
import com.spice.profitmandi.dao.repository.catalog.SchemeRepository;
|
58 |
import com.spice.profitmandi.dao.repository.catalog.SchemeRepository;
|
| 52 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
59 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
| 53 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
60 |
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
|
| 54 |
import com.spice.profitmandi.dao.repository.fofo.FofoLineItemRepository;
|
61 |
import com.spice.profitmandi.dao.repository.fofo.FofoLineItemRepository;
|
| Line 413... |
Line 420... |
| 413 |
List<InventoryItem> inventoryItems = inventoryItemRepository.selectByPurchaseId(purchaseId);
|
420 |
List<InventoryItem> inventoryItems = inventoryItemRepository.selectByPurchaseId(purchaseId);
|
| 414 |
|
421 |
|
| 415 |
Set<Integer> itemIds = inventoryItems.stream().map(x -> x.getItemId()).collect(Collectors.toSet());
|
422 |
Set<Integer> itemIds = inventoryItems.stream().map(x -> x.getItemId()).collect(Collectors.toSet());
|
| 416 |
LocalDateTime billingDate = purchaseService.getBillingDateOfPurchase(purchaseId);
|
423 |
LocalDateTime billingDate = purchaseService.getBillingDateOfPurchase(purchaseId);
|
| 417 |
Set<Integer> itemIdsSet = tagListingRepository.selectByItemIdsAndTagIds(itemIds, tagIds).stream()
|
424 |
Set<Integer> itemIdsSet = tagListingRepository.selectByItemIdsAndTagIds(itemIds, tagIds).stream()
|
| 418 |
.filter(x -> x.getEolDate()==null || x.getEolDate().isAfter(billingDate)).map(x -> x.getItemId())
|
425 |
.filter(x -> x.getEolDate() == null || x.getEolDate().isAfter(billingDate)).map(x -> x.getItemId())
|
| 419 |
.collect(Collectors.toSet());
|
426 |
.collect(Collectors.toSet());
|
| 420 |
// Only consider inventory items that were not returned
|
427 |
// Only consider inventory items that were not returned
|
| 421 |
inventoryItems = inventoryItems.stream().filter(x -> itemIdsSet.contains(x.getItemId()))
|
428 |
inventoryItems = inventoryItems.stream().filter(x -> itemIdsSet.contains(x.getItemId()))
|
| 422 |
.filter(x -> !x.getLastScanType().equals(ScanType.PURCHASE_RET_BAD))
|
429 |
.filter(x -> !x.getLastScanType().equals(ScanType.PURCHASE_RET_BAD))
|
| 423 |
.filter(x -> !x.getLastScanType().equals(ScanType.PURCHASE_RET)).collect(Collectors.toList());
|
430 |
.filter(x -> !x.getLastScanType().equals(ScanType.PURCHASE_RET)).collect(Collectors.toList());
|
| Line 543... |
Line 550... |
| 543 |
return;
|
550 |
return;
|
| 544 |
}
|
551 |
}
|
| 545 |
Set<Integer> itemIds = inventoryItems.stream().map(x -> x.getItemId()).collect(Collectors.toSet());
|
552 |
Set<Integer> itemIds = inventoryItems.stream().map(x -> x.getItemId()).collect(Collectors.toSet());
|
| 546 |
|
553 |
|
| 547 |
Set<Integer> itemIdsSet = tagListingRepository.selectByItemIdsAndTagIds(itemIds, tagIds).stream()
|
554 |
Set<Integer> itemIdsSet = tagListingRepository.selectByItemIdsAndTagIds(itemIds, tagIds).stream()
|
| 548 |
.filter(x -> x.getEolDate()==null || x.getEolDate().isAfter(fofoOrder.getCreateTimestamp())).map(x -> x.getItemId())
|
555 |
.filter(x -> x.getEolDate() == null || x.getEolDate().isAfter(fofoOrder.getCreateTimestamp()))
|
| 549 |
.collect(Collectors.toSet());
|
556 |
.map(x -> x.getItemId()).collect(Collectors.toSet());
|
| 550 |
// Only consider inventory items that were not returned
|
557 |
// Only consider inventory items that were not returned
|
| 551 |
inventoryItems = inventoryItems.stream().filter(x -> itemIdsSet.contains(x.getItemId()))
|
558 |
inventoryItems = inventoryItems.stream().filter(x -> itemIdsSet.contains(x.getItemId()))
|
| 552 |
.collect(Collectors.toSet());
|
559 |
.collect(Collectors.toSet());
|
| 553 |
|
560 |
|
| 554 |
if (inventoryItems.size() == 0) {
|
561 |
if (inventoryItems.size() == 0) {
|
| Line 799... |
Line 806... |
| 799 |
* x.getId()).collect(Collectors.toList()));
|
806 |
* x.getId()).collect(Collectors.toList()));
|
| 800 |
*
|
807 |
*
|
| 801 |
* }
|
808 |
* }
|
| 802 |
*/
|
809 |
*/
|
| 803 |
|
810 |
|
| - |
|
811 |
@Override
|
| - |
|
812 |
public List<Scheme> selectSchemeByPartnerType(PartnerType partnerType, int itemId, boolean isAdmin, int offset,
|
| - |
|
813 |
int limit) {
|
| - |
|
814 |
Session session = sessionFactory.getCurrentSession();
|
| - |
|
815 |
CriteriaBuilder cb = session.getCriteriaBuilder();
|
| - |
|
816 |
CriteriaQuery<Scheme> query = cb.createQuery(Scheme.class);
|
| - |
|
817 |
Root<Scheme> scheme = query.from(Scheme.class);
|
| - |
|
818 |
List<PartnerType> pt = new ArrayList<>();
|
| - |
|
819 |
pt.add(PartnerType.ALL);
|
| - |
|
820 |
pt.add(partnerType);
|
| - |
|
821 |
Predicate p1 = cb.in(scheme.get("partnerType")).value(pt);
|
| - |
|
822 |
Predicate p2 = cb.isNotNull(scheme.get("activeTimestamp"));
|
| - |
|
823 |
cb.desc(cb.isNull(scheme.get("expireTimestamp")));
|
| - |
|
824 |
|
| - |
|
825 |
Predicate p3 = null;
|
| - |
|
826 |
Predicate finalPredicate = null;
|
| - |
|
827 |
if (itemId != 0) {
|
| - |
|
828 |
List<Integer> schemeIds = schemeItemRepository.selectSchemeIdByItemId(itemId);
|
| - |
|
829 |
p3 = cb.in(scheme.get("id")).value(schemeIds);
|
| - |
|
830 |
if (!isAdmin) {
|
| - |
|
831 |
|
| - |
|
832 |
finalPredicate = cb.and(p1, p2, p3);
|
| - |
|
833 |
query.where(finalPredicate);
|
| - |
|
834 |
} else {
|
| - |
|
835 |
finalPredicate = cb.and(p1, p3);
|
| - |
|
836 |
query.where(finalPredicate);
|
| - |
|
837 |
}
|
| - |
|
838 |
} else {
|
| - |
|
839 |
|
| - |
|
840 |
if (!isAdmin) {
|
| - |
|
841 |
|
| - |
|
842 |
finalPredicate = cb.and(p1, p2);
|
| - |
|
843 |
query.where(p2);
|
| - |
|
844 |
} else {
|
| - |
|
845 |
query.where(p1);
|
| - |
|
846 |
}
|
| - |
|
847 |
}
|
| - |
|
848 |
query.orderBy(cb.desc(cb.function("isnull", Boolean.class, scheme.get("expireTimestamp"))));
|
| - |
|
849 |
|
| - |
|
850 |
return session.createQuery(query).setFirstResult(offset).setMaxResults(limit).getResultList();
|
| - |
|
851 |
|
| - |
|
852 |
}
|
| - |
|
853 |
|
| - |
|
854 |
@Override
|
| - |
|
855 |
public long selectSchemeCount(PartnerType partnerType, int itemId, boolean isAdmin) {
|
| - |
|
856 |
Session session = sessionFactory.getCurrentSession();
|
| - |
|
857 |
CriteriaBuilder cb = session.getCriteriaBuilder();
|
| - |
|
858 |
CriteriaQuery<Long> query = cb.createQuery(Long.class);
|
| - |
|
859 |
Root<Scheme> scheme = query.from(Scheme.class);
|
| - |
|
860 |
List<PartnerType> pt = new ArrayList<>();
|
| - |
|
861 |
pt.add(PartnerType.ALL);
|
| - |
|
862 |
pt.add(partnerType);
|
| - |
|
863 |
Predicate p1 = cb.in(scheme.get("partnerType")).value(pt);
|
| - |
|
864 |
Predicate p2 = cb.isNotNull(scheme.get("activeTimestamp"));
|
| - |
|
865 |
Predicate finalPredicate = null;
|
| - |
|
866 |
if (itemId != 0) {
|
| - |
|
867 |
List<Integer> schemeIds = schemeItemRepository.selectSchemeIdByItemId(itemId);
|
| - |
|
868 |
Predicate p3 = cb.in(scheme.get("id")).value(schemeIds);
|
| - |
|
869 |
if (!isAdmin) {
|
| - |
|
870 |
|
| - |
|
871 |
finalPredicate = cb.and(p1, p2, p3);
|
| - |
|
872 |
query.select(cb.count(scheme)).where(finalPredicate);
|
| - |
|
873 |
} else {
|
| - |
|
874 |
finalPredicate = cb.and(p1, p3);
|
| - |
|
875 |
query.select(cb.count(scheme)).where(finalPredicate);
|
| - |
|
876 |
}
|
| - |
|
877 |
} else {
|
| - |
|
878 |
if (!isAdmin) {
|
| - |
|
879 |
finalPredicate = cb.and(p1, p2);
|
| - |
|
880 |
query.select(cb.count(scheme)).where(finalPredicate);
|
| - |
|
881 |
|
| - |
|
882 |
} else {
|
| - |
|
883 |
query.select(cb.count(scheme)).where(p1);
|
| - |
|
884 |
|
| - |
|
885 |
}
|
| - |
|
886 |
}
|
| - |
|
887 |
|
| - |
|
888 |
return session.createQuery(query).getSingleResult();
|
| - |
|
889 |
|
| - |
|
890 |
}
|
| - |
|
891 |
|
| 804 |
}
|
892 |
}
|