| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.dao.cart;
|
1 |
package com.spice.profitmandi.dao.cart;
|
| 2 |
|
2 |
|
| 3 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
3 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 4 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
4 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
| - |
|
5 |
import com.spice.profitmandi.dao.entity.fofo.CurrentInventorySnapshot;
|
| 5 |
import com.spice.profitmandi.dao.entity.fofo.FofoOpeningStock;
|
6 |
import com.spice.profitmandi.dao.entity.fofo.FofoOpeningStock;
|
| 6 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
7 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 7 |
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
|
8 |
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
|
| 8 |
import com.spice.profitmandi.dao.model.PoAndGrnPendingPartnerStockModel;
|
9 |
import com.spice.profitmandi.dao.model.PoAndGrnPendingPartnerStockModel;
|
| 9 |
import com.spice.profitmandi.dao.model.SoldAllCatalogitemQtyByPartnerModel;
|
10 |
import com.spice.profitmandi.dao.model.SoldAllCatalogitemQtyByPartnerModel;
|
| Line 22... |
Line 23... |
| 22 |
import org.hibernate.SessionFactory;
|
23 |
import org.hibernate.SessionFactory;
|
| 23 |
import org.springframework.beans.factory.annotation.Autowired;
|
24 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 24 |
import org.springframework.stereotype.Component;
|
25 |
import org.springframework.stereotype.Component;
|
| 25 |
|
26 |
|
| 26 |
import javax.persistence.TypedQuery;
|
27 |
import javax.persistence.TypedQuery;
|
| - |
|
28 |
import java.time.LocalDate;
|
| 27 |
import java.time.LocalDateTime;
|
29 |
import java.time.LocalDateTime;
|
| - |
|
30 |
import java.time.LocalTime;
|
| 28 |
import java.util.*;
|
31 |
import java.util.*;
|
| 29 |
import java.util.stream.Collectors;
|
32 |
import java.util.stream.Collectors;
|
| 30 |
|
33 |
|
| 31 |
@Component
|
34 |
@Component
|
| 32 |
public class SmartCartServiceImpl implements SmartCartService {
|
35 |
public class SmartCartServiceImpl implements SmartCartService {
|
| Line 118... |
Line 121... |
| 118 |
|
121 |
|
| 119 |
}
|
122 |
}
|
| 120 |
|
123 |
|
| 121 |
@Override
|
124 |
@Override
|
| 122 |
public Set<Integer> getAllItemIdsForSmartCartOfPartner(int fofoId) throws ProfitMandiBusinessException {
|
125 |
public Set<Integer> getAllItemIdsForSmartCartOfPartner(int fofoId) throws ProfitMandiBusinessException {
|
| - |
|
126 |
LocalDateTime todayDate = LocalDate.now().atStartOfDay();
|
| 123 |
List<FofoOpeningStock> fofoOpeningStocks = fofoOpeningStockRepository.selectAllByFofoId(fofoId);
|
127 |
LocalDateTime fortyFiveAgoDate = todayDate.minusDays(45).with(LocalTime.MAX);
|
| 124 |
|
- |
|
| - |
|
128 |
List<SoldAllCatalogitemQtyByPartnerModel> soldAllCatalogitemQtyByPartnerModels = this.getAllSoldCatalogItemByPartner(fofoId,fortyFiveAgoDate,todayDate);
|
| - |
|
129 |
Set<Integer> soldCatalogsIn45Days = soldAllCatalogitemQtyByPartnerModels.stream().map(x->x.getCatalogId()).collect(Collectors.toSet());
|
| 125 |
List<FofoOpeningStock> filteredFofoOpeningStocks = fofoOpeningStocks.stream()
|
130 |
logger.info("soldCatalogsIn45Days {}",soldCatalogsIn45Days);
|
| 126 |
.filter(stock -> stock.getCurrentQty() < stock.getOpeningQty())
|
131 |
List<Item> soldItems = itemRepository.selectAllByCatalogIds(soldCatalogsIn45Days);
|
| 127 |
.collect(Collectors.toList());
|
132 |
Set<Integer> soldItemIds = soldItems.stream().map(x->x.getId()).collect(Collectors.toSet());
|
| 128 |
|
- |
|
| 129 |
logger.info("filteredFofoOpeningStocks {}",filteredFofoOpeningStocks);
|
133 |
List<CurrentInventorySnapshot> currentInventorySnapshots = currentInventorySnapshotRepository.selectByFofoItemIds(fofoId,soldItemIds);
|
| - |
|
134 |
Set<Integer> instockItemIds = currentInventorySnapshots.stream().filter(x -> x.getAvailability() > 0).map(x->x.getItemId()).collect(Collectors.toSet());
|
| 130 |
|
135 |
|
| 131 |
if(filteredFofoOpeningStocks.size() > 0) {
|
136 |
if(instockItemIds.size() > 0) {
|
| 132 |
Set<Integer> filteredCatalogIds = filteredFofoOpeningStocks.stream().map(x -> x.getCatalogId()).collect(Collectors.toSet());
|
137 |
Set<Integer> filteredCatalogIds = itemRepository.selectByIds(instockItemIds).stream().map(x->x.getCatalogItemId()).collect(Collectors.toSet());
|
| 133 |
|
- |
|
| 134 |
|
- |
|
| - |
|
138 |
// this logis has been stop as of now we are not checking that sold catalog is avaialable or not in our stock
|
| 135 |
List<Item> soldItems = itemRepository.selectAllByCatalogIds(filteredCatalogIds);
|
139 |
/*List<Item> soldItems = itemRepository.selectAllByCatalogIds(filteredCatalogIds);
|
| 136 |
|
140 |
|
| 137 |
List<Integer> soldItemIds = soldItems.stream().map(x -> x.getId()).collect(Collectors.toList());
|
141 |
List<Integer> soldItemIds = soldItems.stream().map(x -> x.getId()).collect(Collectors.toList());
|
| 138 |
|
142 |
|
| 139 |
// now logic start for check our (smart dukaan) stock item
|
- |
|
| 140 |
|
- |
|
| 141 |
FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
|
143 |
FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
|
| 142 |
|
144 |
|
| 143 |
Map<Integer, List<WarehouseItemQtyModel>> itemQtyMap = saholicInventoryService.getSaholicStock(fofoStore.getWarehouseId(), soldItemIds);
|
145 |
Map<Integer, List<WarehouseItemQtyModel>> itemQtyMap = saholicInventoryService.getSaholicStock(fofoStore.getWarehouseId(), soldItemIds);
|
| 144 |
|
146 |
|
| 145 |
|
147 |
|
| Line 157... |
Line 159... |
| 157 |
|
159 |
|
| 158 |
return saholictStockCatalogIds;
|
160 |
return saholictStockCatalogIds;
|
| 159 |
} else {
|
161 |
} else {
|
| 160 |
|
162 |
|
| 161 |
return new HashSet<>();
|
163 |
return new HashSet<>();
|
| 162 |
}
|
164 |
}*/
|
| - |
|
165 |
return filteredCatalogIds;
|
| 163 |
} else {
|
166 |
} else {
|
| 164 |
return new HashSet<>();
|
167 |
return new HashSet<>();
|
| 165 |
}
|
168 |
}
|
| 166 |
}
|
169 |
}
|
| 167 |
|
170 |
|