| 26522 |
amit.gupta |
1 |
package com.spice.profitmandi.dao.cart;
|
|
|
2 |
|
| 28653 |
amit.gupta |
3 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 29261 |
amit.gupta |
4 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 26522 |
amit.gupta |
5 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
|
|
6 |
import com.spice.profitmandi.dao.entity.catalog.TagListing;
|
| 29327 |
tejbeer |
7 |
import com.spice.profitmandi.dao.entity.cs.PartnerRegion;
|
|
|
8 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 35170 |
vikas |
9 |
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
|
| 32493 |
amit.gupta |
10 |
import com.spice.profitmandi.dao.entity.inventory.SaholicCISTable;
|
| 26522 |
amit.gupta |
11 |
import com.spice.profitmandi.dao.entity.user.Cart;
|
| 28166 |
tejbeer |
12 |
import com.spice.profitmandi.dao.entity.user.CartLine;
|
| 26522 |
amit.gupta |
13 |
import com.spice.profitmandi.dao.entity.user.User;
|
| 33172 |
tejus.loha |
14 |
import com.spice.profitmandi.dao.model.*;
|
| 29327 |
tejbeer |
15 |
import com.spice.profitmandi.dao.repository.catalog.FocusedModelRepository;
|
| 26522 |
amit.gupta |
16 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 37640 |
amit |
17 |
import com.spice.profitmandi.dao.repository.catalog.CatalogRepository;
|
| 26522 |
amit.gupta |
18 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
| 29327 |
tejbeer |
19 |
import com.spice.profitmandi.dao.repository.cs.PartnerRegionRepository;
|
| 26522 |
amit.gupta |
20 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
|
|
21 |
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
|
| 35170 |
vikas |
22 |
import com.spice.profitmandi.dao.repository.fofo.PartnerTypeChangeService;
|
| 32493 |
amit.gupta |
23 |
import com.spice.profitmandi.dao.repository.inventory.SaholicCISTableRepository;
|
| 29327 |
tejbeer |
24 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
| 28166 |
tejbeer |
25 |
import com.spice.profitmandi.dao.repository.user.CartLineRepository;
|
| 26522 |
amit.gupta |
26 |
import com.spice.profitmandi.dao.repository.user.CartRepository;
|
|
|
27 |
import com.spice.profitmandi.dao.repository.user.UserRepository;
|
| 32493 |
amit.gupta |
28 |
import com.spice.profitmandi.dao.repository.warehouse.BrandRegionMappingRepository;
|
| 29327 |
tejbeer |
29 |
import com.spice.profitmandi.service.NotificationService;
|
| 37143 |
amit |
30 |
import com.spice.profitmandi.service.catalog.BrandsService;
|
| 29327 |
tejbeer |
31 |
import com.spice.profitmandi.service.inventory.FocusedShortageModel;
|
| 28653 |
amit.gupta |
32 |
import com.spice.profitmandi.service.inventory.SaholicInventoryService;
|
| 35140 |
ranu |
33 |
import com.spice.profitmandi.service.inventory.WarehouseIntransitDataModel;
|
| 29327 |
tejbeer |
34 |
import com.spice.profitmandi.service.transaction.TransactionService;
|
| 32493 |
amit.gupta |
35 |
import org.apache.logging.log4j.LogManager;
|
|
|
36 |
import org.apache.logging.log4j.Logger;
|
|
|
37 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
38 |
import org.springframework.stereotype.Component;
|
| 26522 |
amit.gupta |
39 |
|
| 35170 |
vikas |
40 |
import java.time.LocalDate;
|
| 32493 |
amit.gupta |
41 |
import java.time.LocalDateTime;
|
|
|
42 |
import java.util.*;
|
|
|
43 |
import java.util.Map.Entry;
|
|
|
44 |
import java.util.stream.Collectors;
|
|
|
45 |
|
| 28170 |
tejbeer |
46 |
@Component
|
| 26522 |
amit.gupta |
47 |
public class CartServiceImpl implements CartService {
|
|
|
48 |
|
| 31773 |
amit.gupta |
49 |
private static final Set<Integer> tagIds = new HashSet<>(Arrays.asList(4));
|
| 26522 |
amit.gupta |
50 |
|
| 31773 |
amit.gupta |
51 |
private static final Logger logger = LogManager.getLogger(CartServiceImpl.class);
|
| 28653 |
amit.gupta |
52 |
|
| 31773 |
amit.gupta |
53 |
private static final Map<Integer, List<Integer>> focusedModelVariantMap = new HashMap<>();
|
| 29404 |
tejbeer |
54 |
|
| 31773 |
amit.gupta |
55 |
@Autowired
|
|
|
56 |
CartRepository cartRepository;
|
| 26522 |
amit.gupta |
57 |
|
| 31773 |
amit.gupta |
58 |
@Autowired
|
|
|
59 |
CartLineRepository cartLineRepository;
|
| 26522 |
amit.gupta |
60 |
|
| 31773 |
amit.gupta |
61 |
@Autowired
|
|
|
62 |
FofoStoreRepository fofoStoreRepository;
|
| 26522 |
amit.gupta |
63 |
|
| 31773 |
amit.gupta |
64 |
@Autowired
|
|
|
65 |
TagListingRepository tagListingRepository;
|
| 26522 |
amit.gupta |
66 |
|
| 31773 |
amit.gupta |
67 |
@Autowired
|
|
|
68 |
SaholicInventoryService saholicInventoryService;
|
| 26522 |
amit.gupta |
69 |
|
| 31773 |
amit.gupta |
70 |
@Autowired
|
|
|
71 |
UserRepository saholicUserRepository;
|
| 26522 |
amit.gupta |
72 |
|
| 31773 |
amit.gupta |
73 |
@Autowired
|
|
|
74 |
ItemRepository itemRepository;
|
| 28170 |
tejbeer |
75 |
|
| 37283 |
amit |
76 |
@Autowired
|
| 37640 |
amit |
77 |
CatalogRepository catalogRepository;
|
| 26522 |
amit.gupta |
78 |
|
| 37283 |
amit |
79 |
|
| 31773 |
amit.gupta |
80 |
@Autowired
|
|
|
81 |
CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
|
| 29327 |
tejbeer |
82 |
|
| 31773 |
amit.gupta |
83 |
@Autowired
|
|
|
84 |
private FocusedModelRepository focusedModelRepository;
|
| 29327 |
tejbeer |
85 |
|
| 31773 |
amit.gupta |
86 |
@Autowired
|
|
|
87 |
private PartnerRegionRepository partnerRegionRepository;
|
| 29327 |
tejbeer |
88 |
|
| 31773 |
amit.gupta |
89 |
@Autowired
|
|
|
90 |
private TransactionService transactionService;
|
| 29327 |
tejbeer |
91 |
|
| 31773 |
amit.gupta |
92 |
@Autowired
|
| 37143 |
amit |
93 |
private BrandsService brandsService;
|
| 29327 |
tejbeer |
94 |
|
| 31773 |
amit.gupta |
95 |
@Autowired
|
|
|
96 |
private OrderRepository orderRepository;
|
| 29327 |
tejbeer |
97 |
|
| 31773 |
amit.gupta |
98 |
@Autowired
|
|
|
99 |
private NotificationService notificationService;
|
|
|
100 |
@Autowired
|
|
|
101 |
private SaholicCISTableRepository saholicCISTableRepository;
|
| 29327 |
tejbeer |
102 |
|
| 31773 |
amit.gupta |
103 |
@Autowired
|
|
|
104 |
private BrandRegionMappingRepository brandRegionMappingRepository;
|
| 26522 |
amit.gupta |
105 |
|
| 35170 |
vikas |
106 |
@Autowired
|
|
|
107 |
private PartnerTypeChangeService partnerTypeChangeService;
|
|
|
108 |
|
| 31773 |
amit.gupta |
109 |
@Override
|
|
|
110 |
// Unused method
|
|
|
111 |
public CartModel addToCart(int cartId, int itemId, int quantity, float sellingPrice) {
|
|
|
112 |
CartLine cartItem = cartLineRepository.selectByCartItem(cartId, itemId);
|
|
|
113 |
if (cartItem == null) {
|
|
|
114 |
this.createCartItem(cartId, itemId, quantity, sellingPrice);
|
|
|
115 |
} else {
|
|
|
116 |
cartItem.setQuantity(quantity);
|
|
|
117 |
cartItem.setActualPrice(sellingPrice);
|
|
|
118 |
}
|
|
|
119 |
return null;
|
|
|
120 |
}
|
| 26522 |
amit.gupta |
121 |
|
| 31773 |
amit.gupta |
122 |
private void createCartItem(int cartId, int itemId, int quantity, float sellingPrice) {
|
| 37706 |
amit |
123 |
// Cart row first, then lines -- see CartRepository.selectByIdForUpdate.
|
|
|
124 |
cartRepository.selectByIdForUpdate(cartId);
|
| 31773 |
amit.gupta |
125 |
CartLine cartLine = new CartLine();
|
|
|
126 |
cartLine.setActualPrice(sellingPrice);
|
|
|
127 |
cartLine.setCartId(cartId);
|
|
|
128 |
cartLine.setQuantity(quantity);
|
|
|
129 |
// TODO: Estmiate Logic
|
|
|
130 |
cartLine.setEstimate(2);
|
|
|
131 |
cartLineRepository.persist(cartLine);
|
| 26522 |
amit.gupta |
132 |
|
| 31773 |
amit.gupta |
133 |
}
|
| 26522 |
amit.gupta |
134 |
|
| 31773 |
amit.gupta |
135 |
@Override
|
|
|
136 |
public boolean clearCart(int cartId) throws ProfitMandiBusinessException {
|
| 37706 |
amit |
137 |
// Cart row first, then lines -- see CartRepository.selectByIdForUpdate.
|
|
|
138 |
cartRepository.selectByIdForUpdate(cartId);
|
| 31773 |
amit.gupta |
139 |
List<CartLine> cartLines = cartLineRepository.selectAllByCart(cartId);
|
|
|
140 |
cartLines.stream().forEach(cartLine -> cartLineRepository.delete(cartLine));
|
| 35947 |
amit |
141 |
Cart cart = cartRepository.selectById(cartId);
|
| 26522 |
amit.gupta |
142 |
|
| 31773 |
amit.gupta |
143 |
cart.setUpdateTimestamp(LocalDateTime.now());
|
|
|
144 |
cart.setCheckoutTimestamp(null);
|
|
|
145 |
cart.setTotalPrice(0);
|
|
|
146 |
cart.setWalletAmount(0);
|
|
|
147 |
return true;
|
|
|
148 |
}
|
| 26522 |
amit.gupta |
149 |
|
| 31773 |
amit.gupta |
150 |
@Override
|
|
|
151 |
public CartModel getCart(int cartId) {
|
|
|
152 |
// TODO Auto-generated method stub
|
|
|
153 |
return null;
|
|
|
154 |
}
|
| 26522 |
amit.gupta |
155 |
|
| 31773 |
amit.gupta |
156 |
// As of now it only works for Fofo Partners need to be refactored later
|
|
|
157 |
private Map<Integer, Integer> getAvailabilityMap(User user, Set<Integer> itemIds) {
|
|
|
158 |
Map<Integer, Integer> itemAvailabilityMap = new HashMap<>();
|
|
|
159 |
List<TagListing> tags = tagListingRepository.selectByItemIdsAndTagIds(itemIds, tagIds);
|
| 37640 |
amit |
160 |
// Hot deals are brand-driven: catalog.brand = 'Hot Deal'. No date window.
|
|
|
161 |
Set<Integer> hotDealCatalogIds = catalogRepository
|
|
|
162 |
.selectCatalogIdsByBrand(ProfitMandiConstants.HOT_DEAL_BRAND);
|
| 37283 |
amit |
163 |
Map<Integer, Integer> itemCatalogMap = new HashMap<>();
|
|
|
164 |
try {
|
|
|
165 |
for (Item item : itemRepository.selectByIds(itemIds)) {
|
|
|
166 |
itemCatalogMap.put(item.getId(), item.getCatalogItemId());
|
|
|
167 |
}
|
|
|
168 |
} catch (ProfitMandiBusinessException e) {
|
|
|
169 |
logger.error("Could not load items for availability map", e);
|
|
|
170 |
}
|
| 31773 |
amit.gupta |
171 |
tags.stream().forEach(tagListing -> {
|
| 37283 |
amit |
172 |
if (!tagListing.isActive()
|
|
|
173 |
|| hotDealCatalogIds.contains(itemCatalogMap.get(tagListing.getItemId()))) {
|
| 31773 |
amit.gupta |
174 |
// show actual values here
|
|
|
175 |
} else {
|
| 32585 |
amit.gupta |
176 |
itemAvailabilityMap.put(tagListing.getItemId(), 400);
|
| 31773 |
amit.gupta |
177 |
}
|
|
|
178 |
});
|
|
|
179 |
return itemAvailabilityMap;
|
|
|
180 |
}
|
| 26522 |
amit.gupta |
181 |
|
| 31773 |
amit.gupta |
182 |
// As of now it only works for Fofo Partners need to be refactored later
|
| 33244 |
ranu |
183 |
private Map<Integer, Integer> getMinBuyQtyMap(User user, Set<Integer> itemIds) throws ProfitMandiBusinessException {
|
| 31773 |
amit.gupta |
184 |
List<Item> items = itemRepository.selectByIds(itemIds);
|
|
|
185 |
return items.stream().collect(Collectors.toMap(x -> x.getId(), x -> x.getCategoryId() == 10020 ? 1 : 10));
|
|
|
186 |
}
|
| 26522 |
amit.gupta |
187 |
|
| 31773 |
amit.gupta |
188 |
// As of now it only works for Fofo Partners need to be refactored later
|
|
|
189 |
private Map<Integer, Float> getPriceMap(User user, Set<Integer> itemIds) {
|
|
|
190 |
List<TagListing> tags = tagListingRepository.selectByItemIdsAndTagIds(itemIds, tagIds);
|
|
|
191 |
return tags.stream().collect(Collectors.toMap(x -> x.getItemId(), x -> x.getSellingPrice()));
|
| 28653 |
amit.gupta |
192 |
|
| 31773 |
amit.gupta |
193 |
}
|
| 28653 |
amit.gupta |
194 |
|
| 31773 |
amit.gupta |
195 |
@Override
|
|
|
196 |
public CartResponse getCartValidation(int cartId) throws ProfitMandiBusinessException {
|
| 37706 |
amit |
197 |
// This method WRITES (cart.totalPrice, cart_line qty/price, line deletes) despite its
|
|
|
198 |
// name, so it is a mutating path: cart row first, then lines.
|
|
|
199 |
// See CartRepository.selectByIdForUpdate.
|
|
|
200 |
cartRepository.selectByIdForUpdate(cartId);
|
| 31773 |
amit.gupta |
201 |
/*
|
|
|
202 |
* # No need to validate duplicate items since there are only two ways # to add
|
|
|
203 |
* items to a cart and both of them check whether the item being # added is a
|
|
|
204 |
* duplicate of an already existing item.
|
|
|
205 |
*/
|
| 28653 |
amit.gupta |
206 |
|
| 35947 |
amit |
207 |
Cart cart = cartRepository.selectById(cartId);
|
| 31773 |
amit.gupta |
208 |
List<CartLine> cartLines = cartLineRepository.selectAllByCart(cartId);
|
| 28653 |
amit.gupta |
209 |
|
| 31792 |
amit.gupta |
210 |
//User saholicUser = saholicUserRepository.selectByCartId(cartId);
|
| 28653 |
amit.gupta |
211 |
|
| 31773 |
amit.gupta |
212 |
int totalQty = 0;
|
|
|
213 |
double totalAmount = 0;
|
|
|
214 |
CartResponse cartResponse = new CartResponse();
|
|
|
215 |
List<CartMessage> cartMessages = new ArrayList<>();
|
|
|
216 |
List<CartItemResponseModel> cartItemModels = new ArrayList<>();
|
|
|
217 |
cartResponse.setCartMessages(cartMessages);
|
|
|
218 |
cartResponse.setCartItems(cartItemModels);
|
| 28653 |
amit.gupta |
219 |
|
| 31773 |
amit.gupta |
220 |
int cartMessageChanged = 0;
|
|
|
221 |
int cartMessageOOS = 0;
|
|
|
222 |
int cartMessageUndeliverable = 0;
|
| 28653 |
amit.gupta |
223 |
|
| 31773 |
amit.gupta |
224 |
Set<Integer> itemIds = cartLines.stream().map(x -> x.getItemId()).collect(Collectors.toSet());
|
| 31783 |
amit.gupta |
225 |
logger.info("Item ids {}", itemIds);
|
| 31773 |
amit.gupta |
226 |
List<TagListing> tagListings = tagListingRepository.selectByItemIdsAndTagIds(itemIds, tagIds);
|
|
|
227 |
Map<Integer, TagListing> tagListingsMap = tagListings.stream()
|
|
|
228 |
.collect(Collectors.toMap(x -> x.getItemId(), x -> x));
|
| 28653 |
amit.gupta |
229 |
|
| 35493 |
amit |
230 |
// N+1 fix: Pre-fetch all items before the loop
|
|
|
231 |
Map<Integer, Item> itemMap = itemRepository.selectByIds(itemIds).stream()
|
|
|
232 |
.collect(Collectors.toMap(Item::getId, item -> item));
|
|
|
233 |
|
| 31773 |
amit.gupta |
234 |
User user = saholicUserRepository.selectByCartId(cartId);
|
|
|
235 |
FofoStore fs = fofoStoreRepository.selectByRetailerId(user.getId());
|
|
|
236 |
Map<Integer, Integer> warehouseItemQtyMap = saholicInventoryService.getSaholicNetAvailability(fs.getWarehouseId(), new ArrayList<>(itemIds));
|
| 35170 |
vikas |
237 |
PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(fs.getId(), LocalDate.now());
|
| 35140 |
ranu |
238 |
// Get in-transit data for this warehouse
|
|
|
239 |
List<WarehouseIntransitDataModel> warehouseIntransitDataModels =
|
|
|
240 |
saholicInventoryService.getWarehouseIntransistDataList().stream()
|
|
|
241 |
.filter(x -> x.getWarehouseId() == fs.getWarehouseId())
|
|
|
242 |
.collect(Collectors.toList());
|
| 28653 |
amit.gupta |
243 |
|
| 35140 |
ranu |
244 |
// Add in-transit quantities into the map
|
|
|
245 |
for (WarehouseIntransitDataModel intransitData : warehouseIntransitDataModels) {
|
|
|
246 |
if (intransitData.getQty() > 0) {
|
|
|
247 |
int itemId = intransitData.getItemId();
|
|
|
248 |
int existingQty = warehouseItemQtyMap.getOrDefault(itemId, 0);
|
|
|
249 |
warehouseItemQtyMap.put(itemId, existingQty + intransitData.getQty());
|
|
|
250 |
}
|
|
|
251 |
}
|
| 31773 |
amit.gupta |
252 |
cart.setTotalPrice(0);
|
|
|
253 |
int nonAccessoryQuantity = 0;
|
|
|
254 |
for (CartLine cartLine : cartLines) {
|
|
|
255 |
CartItemResponseModel cartItemResponseModel = new CartItemResponseModel();
|
|
|
256 |
int oldEstimate = cartLine.getEstimate();
|
|
|
257 |
int itemId = cartLine.getItemId();
|
| 35493 |
amit |
258 |
// N+1 fix: Use pre-fetched itemMap instead of querying per item
|
|
|
259 |
Item item = itemMap.get(itemId);
|
|
|
260 |
if (item == null) {
|
| 31773 |
amit.gupta |
261 |
logger.info("Error finding item with id {}", itemId);
|
|
|
262 |
cartLineRepository.delete(cartLine);
|
|
|
263 |
continue;
|
|
|
264 |
}
|
| 35493 |
amit |
265 |
cartItemResponseModel.setTitle(item.getItemDescriptionNoColor());
|
| 31773 |
amit.gupta |
266 |
cartItemResponseModel.setItemId(itemId);
|
|
|
267 |
cartItemResponseModel.setQuantity(cartLine.getQuantity());
|
|
|
268 |
cartItemResponseModel.setColor(item.getColor());
|
|
|
269 |
cartItemResponseModel.setCatalogItemId(item.getCatalogItemId());
|
|
|
270 |
cartItemResponseModel.setMinBuyQuantity(1);
|
|
|
271 |
cartItemResponseModel.setQuantityStep(1);
|
| 32588 |
amit.gupta |
272 |
cartItemResponseModel.setMaxQuantity(400);
|
| 31773 |
amit.gupta |
273 |
int currentAvailability = warehouseItemQtyMap.get(itemId) == null ? 0 : warehouseItemQtyMap.get(itemId);
|
|
|
274 |
int oldAvailability = cartLine.getAvailability();
|
|
|
275 |
cartItemResponseModel.setAvailability(currentAvailability);
|
| 28653 |
amit.gupta |
276 |
|
| 31773 |
amit.gupta |
277 |
//Current availability is less than required quantity
|
|
|
278 |
if (currentAvailability < cartLine.getQuantity()) {
|
|
|
279 |
//Current Availability is reduced
|
|
|
280 |
if (oldAvailability > currentAvailability) {
|
|
|
281 |
cartMessageChanged += 1;
|
|
|
282 |
}
|
|
|
283 |
}
|
| 28653 |
amit.gupta |
284 |
|
| 31773 |
amit.gupta |
285 |
//As of now one can buy upto 100 Qty
|
|
|
286 |
if (cartLine.getQuantity() > cartItemResponseModel.getMaxQuantity()) {
|
|
|
287 |
cartMessageChanged +=1;
|
|
|
288 |
cartLine.setQuantity(cartItemResponseModel.getMaxQuantity());
|
|
|
289 |
}
|
| 28653 |
amit.gupta |
290 |
|
| 31773 |
amit.gupta |
291 |
if (item.getCategoryId() == 10006 || item.getCategoryId() == 10010) {
|
|
|
292 |
nonAccessoryQuantity += cartItemResponseModel.getQuantity();
|
|
|
293 |
cartItemResponseModel.setCategoryName("mobile");
|
|
|
294 |
}
|
| 35211 |
vikas |
295 |
if (cartItemResponseModel.getItemId() == ProfitMandiConstants.ITEM_CARRY_BAG) {
|
| 37305 |
ranu |
296 |
if (partnerType.equals(PartnerType.BRONZE)) {
|
| 35214 |
vikas |
297 |
cartLine.setActualPrice(tagListingsMap.get(itemId).getSellingPrice());
|
| 35170 |
vikas |
298 |
cartItemResponseModel.setSellingPrice(cartLine.getActualPrice());
|
|
|
299 |
} else {
|
|
|
300 |
cartItemResponseModel.setSellingPrice(1);
|
| 35214 |
vikas |
301 |
cartLine.setActualPrice(1);
|
| 35170 |
vikas |
302 |
}
|
|
|
303 |
} else {
|
| 35573 |
amit |
304 |
// Check for price mismatch between cart and current TagListing
|
|
|
305 |
TagListing currentTagListing = tagListingsMap.get(itemId);
|
|
|
306 |
if (currentTagListing != null) {
|
|
|
307 |
float cartPrice = cartLine.getActualPrice();
|
|
|
308 |
float currentPrice = currentTagListing.getSellingPrice();
|
| 35574 |
amit |
309 |
|
|
|
310 |
// If cart price is 0 or unset, silently update to current price (client bug)
|
|
|
311 |
if (cartPrice < 0.01f) {
|
|
|
312 |
logger.info("Cart price was 0/unset for itemId {}, setting to current price {}",
|
|
|
313 |
itemId, currentPrice);
|
|
|
314 |
cartLine.setActualPrice(currentPrice);
|
|
|
315 |
}
|
|
|
316 |
// Use tolerance comparison to avoid float precision false positives
|
|
|
317 |
else if (Math.abs(cartPrice - currentPrice) > 0.01f) {
|
| 35573 |
amit |
318 |
cartMessageChanged += 1;
|
|
|
319 |
String priceChangeMsg = String.format("Price updated for %s: Rs. %.2f to Rs. %.2f",
|
|
|
320 |
item.getItemDescriptionNoColor(), cartPrice, currentPrice);
|
|
|
321 |
CartMessage cartMessage = new CartMessage();
|
|
|
322 |
cartMessage.setMessageText(priceChangeMsg);
|
|
|
323 |
cartMessage.setType("PRICE_CHANGED");
|
|
|
324 |
cartMessages.add(cartMessage);
|
|
|
325 |
logger.info("Price mismatch detected for itemId {}: cart price {} vs current price {}",
|
|
|
326 |
itemId, cartPrice, currentPrice);
|
|
|
327 |
// Update cart line with current price
|
|
|
328 |
cartLine.setActualPrice(currentPrice);
|
|
|
329 |
}
|
|
|
330 |
}
|
| 35170 |
vikas |
331 |
cartItemResponseModel.setSellingPrice(cartLine.getActualPrice());
|
|
|
332 |
}
|
| 28653 |
amit.gupta |
333 |
|
| 31773 |
amit.gupta |
334 |
//if (availability > 0) {
|
|
|
335 |
cart.setTotalPrice(cart.getTotalPrice() + (cartLine.getActualPrice() * cartLine.getQuantity()));
|
|
|
336 |
cartItemResponseModel.setQuantity(cartLine.getQuantity());
|
|
|
337 |
cartItemResponseModel.setEstimate(2);
|
|
|
338 |
cartLine.setEstimate(cartItemResponseModel.getEstimate());
|
|
|
339 |
cart.setUpdateTimestamp(LocalDateTime.now());
|
| 28653 |
amit.gupta |
340 |
|
| 28166 |
tejbeer |
341 |
|
| 31773 |
amit.gupta |
342 |
totalAmount += cartLine.getActualPrice() * cartLine.getQuantity();
|
|
|
343 |
totalQty += cartItemResponseModel.getQuantity();
|
|
|
344 |
cartResponse.getCartItems().add(cartItemResponseModel);
|
| 28166 |
tejbeer |
345 |
|
| 31773 |
amit.gupta |
346 |
}
|
|
|
347 |
if (cart.getCheckoutTimestamp() != null) {
|
|
|
348 |
if (cart.getUpdateTimestamp().isBefore(cart.getCheckoutTimestamp())) {
|
|
|
349 |
cart.setCheckoutTimestamp(null);
|
|
|
350 |
}
|
|
|
351 |
}
|
|
|
352 |
cartResponse.setTotalQty(totalQty);
|
|
|
353 |
cartResponse.setTotalAmount(totalAmount);
|
|
|
354 |
cartResponse.setNonAccessoryQuantity(nonAccessoryQuantity);
|
|
|
355 |
cartResponse.setShippingCharge(0);
|
|
|
356 |
cartResponse.setCartMessageChanged(cartMessageChanged);
|
|
|
357 |
cartResponse.setCartMessageOOS(cartMessageOOS);
|
|
|
358 |
cartResponse.setCartMessageUndeliverable(cartMessageUndeliverable);
|
|
|
359 |
cartResponse.setCod(false);
|
|
|
360 |
return cartResponse;
|
|
|
361 |
}
|
| 28653 |
amit.gupta |
362 |
|
| 31773 |
amit.gupta |
363 |
@Override
|
| 37143 |
amit |
364 |
public void addItemsToCart(int cartId, int fofoId, List<CartItem> cartItems) throws ProfitMandiBusinessException {
|
|
|
365 |
List<CartItem> requestedItems = cartItems.stream().filter(x -> x.getQuantity() > 0)
|
|
|
366 |
.collect(Collectors.toList());
|
|
|
367 |
if (!requestedItems.isEmpty()) {
|
|
|
368 |
List<String> requestedBrands = itemRepository
|
|
|
369 |
.selectByIds(requestedItems.stream().map(CartItem::getItemId).collect(Collectors.toSet()))
|
|
|
370 |
.stream().map(Item::getBrand).distinct().collect(Collectors.toList());
|
|
|
371 |
brandsService.validateOrderableBrands(fofoId, requestedBrands);
|
|
|
372 |
}
|
|
|
373 |
this.addItemsToCart(cartId, cartItems);
|
|
|
374 |
}
|
|
|
375 |
|
|
|
376 |
@Override
|
| 31773 |
amit.gupta |
377 |
public void addItemsToCart(int cartId, List<CartItem> cartItems) throws ProfitMandiBusinessException {
|
| 37706 |
amit |
378 |
// Take the cart row BEFORE any line is touched -- see CartRepository.selectByIdForUpdate.
|
|
|
379 |
// Inserting a line shared-locks this same row anyway via line_cart_id_fk, so without this
|
|
|
380 |
// the lock order depends on which statement happens to run first and two concurrent edits
|
|
|
381 |
// to one cart can deadlock.
|
|
|
382 |
cartRepository.selectByIdForUpdate(cartId);
|
| 31773 |
amit.gupta |
383 |
logger.info("cart items {}", cartItems);
|
|
|
384 |
cartItems = cartItems.stream().filter(x -> x.getQuantity() > 0).collect(Collectors.toList());
|
|
|
385 |
Map<Integer, Integer> itemQuantityMap = cartItems.stream()
|
|
|
386 |
.collect(Collectors.toMap(x -> x.getItemId(), x -> x.getQuantity()));
|
|
|
387 |
List<CartLine> cartLines = cartLineRepository.selectAllByCart(cartId);
|
| 31781 |
amit.gupta |
388 |
Map<Integer, CartLine> itemCartLineMap = cartLines.stream().collect(Collectors.toMap(x->x.getItemId(), x->x));
|
| 31773 |
amit.gupta |
389 |
// Delete cartLines with 0 values
|
|
|
390 |
for (CartLine cartLine : cartLines) {
|
|
|
391 |
Integer quantity = itemQuantityMap.get(cartLine.getItemId());
|
|
|
392 |
if (quantity == null || quantity.intValue() == 0) {
|
|
|
393 |
cartLineRepository.delete(cartLine);
|
|
|
394 |
} else {
|
|
|
395 |
cartLine.setQuantity(itemQuantityMap.get(cartLine.getItemId()));
|
|
|
396 |
cartLine.setUpdateTimestapm(LocalDateTime.now());
|
|
|
397 |
}
|
|
|
398 |
}
|
|
|
399 |
for (CartItem cartItem : cartItems) {
|
| 31781 |
amit.gupta |
400 |
if (!itemCartLineMap.containsKey(cartItem.getItemId())) {
|
| 31773 |
amit.gupta |
401 |
CartLine cartLineNew = new CartLine();
|
|
|
402 |
cartLineNew.setItemId(cartItem.getItemId());
|
|
|
403 |
cartLineNew.setQuantity(cartItem.getQuantity());
|
|
|
404 |
cartLineNew.setCartId(cartId);
|
| 32493 |
amit.gupta |
405 |
cartLineNew.setActualPrice((float) cartItem.getSellingPrice());
|
| 31773 |
amit.gupta |
406 |
cartLineNew.setCreateTimestamp(LocalDateTime.now());
|
|
|
407 |
cartLineRepository.persist(cartLineNew);
|
|
|
408 |
}
|
|
|
409 |
}
|
| 29327 |
tejbeer |
410 |
|
| 31773 |
amit.gupta |
411 |
}
|
| 29327 |
tejbeer |
412 |
|
| 31773 |
amit.gupta |
413 |
@Override
|
|
|
414 |
public void addAddressToCart(int cartId, long addressId) throws ProfitMandiBusinessException {
|
| 35947 |
amit |
415 |
Cart cart = cartRepository.selectById(cartId);
|
| 31773 |
amit.gupta |
416 |
cart.setAddressId((int) addressId);
|
| 29404 |
tejbeer |
417 |
|
| 31773 |
amit.gupta |
418 |
}
|
| 29404 |
tejbeer |
419 |
|
| 31773 |
amit.gupta |
420 |
@Override
|
|
|
421 |
public void addShoppingBag(int cartId, long qty) {
|
| 37706 |
amit |
422 |
// Cart row first, then lines -- see CartRepository.selectByIdForUpdate.
|
|
|
423 |
cartRepository.selectByIdForUpdate(cartId);
|
| 31773 |
amit.gupta |
424 |
CartLine cl = new CartLine();
|
|
|
425 |
cl.setItemId(ProfitMandiConstants.ITEM_CARRY_BAG);
|
|
|
426 |
cl.setQuantity((int) qty);
|
|
|
427 |
cl.setCartId(cartId);
|
|
|
428 |
cl.setCreateTimestamp(LocalDateTime.now());
|
|
|
429 |
cl.setDataProtectionAmount(0);
|
|
|
430 |
cl.setEstimate(0);
|
|
|
431 |
cl.setInsuranceAmount(0f);
|
|
|
432 |
cl.setDataProtectionInsurer(0);
|
|
|
433 |
cl.setActualPrice(0.01f);
|
|
|
434 |
cartLineRepository.persist(cl);
|
| 29404 |
tejbeer |
435 |
|
| 31773 |
amit.gupta |
436 |
}
|
| 29404 |
tejbeer |
437 |
|
| 31773 |
amit.gupta |
438 |
@Override
|
|
|
439 |
public CartModel removeFromCart(int cartId, int itemId) {
|
|
|
440 |
// TODO Auto-generated method stub
|
|
|
441 |
return null;
|
|
|
442 |
}
|
| 29327 |
tejbeer |
443 |
|
| 31773 |
amit.gupta |
444 |
@Override
|
|
|
445 |
public List<FocusedShortageModel> focusedModelShortageValidation(int fofoId,
|
|
|
446 |
Map<Integer, Integer> catalogCartQtyMap) throws ProfitMandiBusinessException {
|
| 29327 |
tejbeer |
447 |
|
| 35690 |
amit |
448 |
Map<Integer, Long> inStockItemModel = currentInventorySnapshotRepository.selectSumInMobileStockGroupByCatalog(fofoId).stream()
|
| 31773 |
amit.gupta |
449 |
.collect(Collectors.toMap(x -> x.getCatalogItemId(), x -> x.getQty()));
|
| 29327 |
tejbeer |
450 |
|
| 35690 |
amit |
451 |
Map<Integer, Long> itempendingIndent = transactionService.getInTransitOrders(fofoId).stream()
|
| 31773 |
amit.gupta |
452 |
.collect(Collectors.groupingBy(x -> x.getLineItem().getItem().getCatalogItemId(),
|
|
|
453 |
Collectors.summingLong(x -> (long) x.getLineItem().getQuantity())));
|
| 29327 |
tejbeer |
454 |
|
| 35690 |
amit |
455 |
Map<Integer, Long> grnItemPendingOrders = orderRepository.selectPendingGrnOrders(fofoId).stream()
|
| 31773 |
amit.gupta |
456 |
.collect(Collectors.groupingBy(x -> x.getLineItem().getItem().getCatalogItemId(),
|
|
|
457 |
Collectors.summingLong(x -> (long) x.getLineItem().getQuantity())));
|
| 29327 |
tejbeer |
458 |
|
| 31773 |
amit.gupta |
459 |
FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
|
| 29327 |
tejbeer |
460 |
|
| 37143 |
amit |
461 |
List<String> retailerBlockBrands = brandsService.restrictedBrands(fofoId);
|
| 29327 |
tejbeer |
462 |
|
| 35690 |
amit |
463 |
List<PartnerRegion> partnerRegions = partnerRegionRepository.selectByfofoId(fofoId);
|
|
|
464 |
Map<Integer, Integer> focusedModelMap;
|
| 31773 |
amit.gupta |
465 |
if (partnerRegions.size() > 0) {
|
|
|
466 |
focusedModelMap = focusedModelRepository
|
|
|
467 |
.selectAllByRegionIds(
|
|
|
468 |
partnerRegions.stream().map(x -> x.getRegionId()).collect(Collectors.toList()))
|
|
|
469 |
.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> x.getMinimumQty()));
|
|
|
470 |
} else {
|
|
|
471 |
focusedModelMap = new HashMap<>();
|
|
|
472 |
}
|
| 29327 |
tejbeer |
473 |
|
| 35690 |
amit |
474 |
return focusedModelShortageValidation(fofoId, catalogCartQtyMap, inStockItemModel,
|
|
|
475 |
itempendingIndent, grnItemPendingOrders, fofoStore, retailerBlockBrands, focusedModelMap);
|
|
|
476 |
}
|
|
|
477 |
|
|
|
478 |
@Override
|
|
|
479 |
public List<FocusedShortageModel> focusedModelShortageValidation(int fofoId,
|
|
|
480 |
Map<Integer, Integer> catalogCartQtyMap,
|
|
|
481 |
Map<Integer, Long> inStockItemModel,
|
|
|
482 |
Map<Integer, Long> itempendingIndent,
|
|
|
483 |
Map<Integer, Long> grnItemPendingOrders,
|
|
|
484 |
FofoStore fofoStore,
|
|
|
485 |
List<String> retailerBlockBrands,
|
|
|
486 |
Map<Integer, Integer> focusedModelMap) throws ProfitMandiBusinessException {
|
|
|
487 |
|
|
|
488 |
logger.info("fofoId {}", fofoId);
|
|
|
489 |
|
|
|
490 |
focusedModelVariantMap.put(1022771, Arrays.asList(1022771));
|
|
|
491 |
focusedModelVariantMap.put(1023025, Arrays.asList(1022975, 1022945));
|
|
|
492 |
focusedModelVariantMap.put(1023027, Arrays.asList(1022706));
|
|
|
493 |
focusedModelVariantMap.put(1022976, Arrays.asList(1022744));
|
|
|
494 |
focusedModelVariantMap.put(1023045, Arrays.asList(1022768));
|
|
|
495 |
focusedModelVariantMap.put(1023066, Arrays.asList(1022858));
|
|
|
496 |
|
| 31773 |
amit.gupta |
497 |
Map<Integer, Integer> catalogItemAailabilityMap = new HashMap<>();
|
| 29327 |
tejbeer |
498 |
|
| 31773 |
amit.gupta |
499 |
for (Entry<Integer, Integer> fm : focusedModelMap.entrySet()) {
|
|
|
500 |
List<Item> items = itemRepository.selectAllByCatalogItemId(fm.getKey());
|
|
|
501 |
int allColorNetAvailability = 0;
|
|
|
502 |
for (Item item : items) {
|
|
|
503 |
if (retailerBlockBrands.contains(item.getBrand()))
|
|
|
504 |
continue;
|
|
|
505 |
List<SaholicCISTable> currentAvailability = saholicCISTableRepository.selectByItemWarehouse(item.getId(), fofoStore.getWarehouseId());
|
| 29327 |
tejbeer |
506 |
|
| 31773 |
amit.gupta |
507 |
if (currentAvailability != null) {
|
|
|
508 |
allColorNetAvailability += currentAvailability.stream()
|
|
|
509 |
.collect(Collectors.summingInt(SaholicCISTable::getNetAvailability));
|
|
|
510 |
}
|
|
|
511 |
}
|
|
|
512 |
catalogItemAailabilityMap.put(fm.getKey(), allColorNetAvailability);
|
|
|
513 |
}
|
| 29327 |
tejbeer |
514 |
|
| 31773 |
amit.gupta |
515 |
List<FocusedShortageModel> focusedModelShortageList = new ArrayList<>();
|
| 29327 |
tejbeer |
516 |
|
| 31773 |
amit.gupta |
517 |
for (Entry<Integer, Integer> fm : focusedModelMap.entrySet()) {
|
| 29327 |
tejbeer |
518 |
|
| 31773 |
amit.gupta |
519 |
logger.info("fm {}", fm);
|
| 29404 |
tejbeer |
520 |
|
| 31773 |
amit.gupta |
521 |
long overallStock = (inStockItemModel.get(fm.getKey()) == null ? 0 : inStockItemModel.get(fm.getKey()))
|
|
|
522 |
+ (itempendingIndent.get(fm.getKey()) == null ? 0 : itempendingIndent.get(fm.getKey()))
|
|
|
523 |
+ (grnItemPendingOrders.get(fm.getKey()) == null ? 0 : grnItemPendingOrders.get(fm.getKey()));
|
|
|
524 |
logger.info("overallStock {}", overallStock);
|
| 29404 |
tejbeer |
525 |
|
| 31773 |
amit.gupta |
526 |
// Blocked brands available quantity is discussed to zero
|
|
|
527 |
long warehouseStock = catalogItemAailabilityMap.get(fm.getKey()) == null ? 0
|
|
|
528 |
: catalogItemAailabilityMap.get(fm.getKey());
|
|
|
529 |
logger.info("warehouseStock {}", warehouseStock);
|
| 29404 |
tejbeer |
530 |
|
| 31773 |
amit.gupta |
531 |
long cartValue = catalogCartQtyMap.get(fm.getKey()) == null ? 0 : catalogCartQtyMap.get(fm.getKey());
|
| 29404 |
tejbeer |
532 |
|
| 31773 |
amit.gupta |
533 |
logger.info("cartValue" + cartValue);
|
|
|
534 |
long totalStock = overallStock + cartValue;
|
|
|
535 |
logger.info("totalStock" + totalStock);
|
| 29404 |
tejbeer |
536 |
|
| 31773 |
amit.gupta |
537 |
long shortQty = Math.min(fm.getValue() - totalStock, warehouseStock);
|
|
|
538 |
logger.info("shortQty {}", shortQty);
|
| 29404 |
tejbeer |
539 |
|
| 31773 |
amit.gupta |
540 |
if (shortQty > 0) {
|
|
|
541 |
if (focusedModelVariantMap.get(fm.getKey()) != null) {
|
|
|
542 |
List<Integer> variantCatalogIds = focusedModelVariantMap.get(fm.getKey());
|
|
|
543 |
logger.info("variantCatalogIds {}", variantCatalogIds);
|
| 29404 |
tejbeer |
544 |
|
| 31773 |
amit.gupta |
545 |
int variantAvailability = 0;
|
|
|
546 |
for (Integer vc : variantCatalogIds) {
|
|
|
547 |
long variantOverallStock = (inStockItemModel.get(vc) == null ? 0 : inStockItemModel.get(vc))
|
|
|
548 |
+ (itempendingIndent.get(vc) == null ? 0 : itempendingIndent.get(vc))
|
|
|
549 |
+ (grnItemPendingOrders.get(vc) == null ? 0 : grnItemPendingOrders.get(vc));
|
|
|
550 |
logger.info("variantOverallStock {}", variantOverallStock);
|
| 29404 |
tejbeer |
551 |
|
| 31773 |
amit.gupta |
552 |
// Blocked brands available quantity is discussed to zero
|
|
|
553 |
long variantWarehouseStock = catalogItemAailabilityMap.get(vc) == null ? 0
|
|
|
554 |
: catalogItemAailabilityMap.get(vc);
|
|
|
555 |
logger.info("variantWarehouseStock {}", variantWarehouseStock);
|
| 29404 |
tejbeer |
556 |
|
| 31773 |
amit.gupta |
557 |
long variantCartValue = catalogCartQtyMap.get(vc) == null ? 0 : catalogCartQtyMap.get(vc);
|
| 29404 |
tejbeer |
558 |
|
| 31773 |
amit.gupta |
559 |
logger.info("variantCartValue" + variantCartValue);
|
|
|
560 |
long variantTotalStock = variantOverallStock + variantCartValue;
|
|
|
561 |
logger.info("variantTotalStock" + variantTotalStock);
|
| 29404 |
tejbeer |
562 |
|
| 31773 |
amit.gupta |
563 |
variantAvailability += (int) variantTotalStock;
|
| 29327 |
tejbeer |
564 |
|
| 31773 |
amit.gupta |
565 |
}
|
| 29327 |
tejbeer |
566 |
|
| 31773 |
amit.gupta |
567 |
logger.info("variantAvailability {}", variantAvailability);
|
| 29327 |
tejbeer |
568 |
|
| 31773 |
amit.gupta |
569 |
shortQty = shortQty - variantAvailability;
|
| 29327 |
tejbeer |
570 |
|
| 31773 |
amit.gupta |
571 |
}
|
|
|
572 |
}
|
| 29327 |
tejbeer |
573 |
|
| 31773 |
amit.gupta |
574 |
logger.info("shortQty" + shortQty);
|
| 29327 |
tejbeer |
575 |
|
| 31773 |
amit.gupta |
576 |
if (shortQty > 0) {
|
| 29327 |
tejbeer |
577 |
|
| 31773 |
amit.gupta |
578 |
Map<Integer, Integer> requiredItemQty = new HashMap<>();
|
| 29327 |
tejbeer |
579 |
|
| 31773 |
amit.gupta |
580 |
List<Item> it = itemRepository.selectAllByCatalogItemId(fm.getKey());
|
|
|
581 |
FocusedShortageModel fms = new FocusedShortageModel();
|
|
|
582 |
fms.setShortageQty((int) shortQty);
|
|
|
583 |
fms.setCatalogId(fm.getKey());
|
|
|
584 |
fms.setAvailabitiy(fm.getValue());
|
|
|
585 |
fms.setInStock(overallStock);
|
| 29327 |
tejbeer |
586 |
|
| 31773 |
amit.gupta |
587 |
fms.setItemName(it.get(0).getBrand() + it.get(0).getModelNumber() + it.get(0).getModelName());
|
| 29327 |
tejbeer |
588 |
|
| 31773 |
amit.gupta |
589 |
Map<Integer, Integer> itemQtyMap = new HashMap<>();
|
| 29327 |
tejbeer |
590 |
|
| 31773 |
amit.gupta |
591 |
for (Item i : it) {
|
| 29327 |
tejbeer |
592 |
|
| 31773 |
amit.gupta |
593 |
List<SaholicCISTable> ca = saholicCISTableRepository.selectByItemWarehouse(i.getId(), fofoStore.getWarehouseId());
|
|
|
594 |
if (ca != null) {
|
|
|
595 |
itemQtyMap.put(i.getId(),
|
|
|
596 |
ca.stream().collect(Collectors.summingInt(SaholicCISTable::getNetAvailability)));
|
|
|
597 |
}
|
|
|
598 |
}
|
| 29327 |
tejbeer |
599 |
|
| 31773 |
amit.gupta |
600 |
itemQtyMap = itemQtyMap.entrySet().stream()
|
|
|
601 |
.sorted(Collections.reverseOrder(Map.Entry.comparingByValue())).collect(Collectors
|
|
|
602 |
.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e2, LinkedHashMap::new));
|
| 29327 |
tejbeer |
603 |
|
| 31773 |
amit.gupta |
604 |
for (long i = shortQty; i > 0; i--) {
|
|
|
605 |
if (shortQty == 0) {
|
|
|
606 |
break;
|
|
|
607 |
}
|
| 29327 |
tejbeer |
608 |
|
| 31773 |
amit.gupta |
609 |
for (Entry<Integer, Integer> itemQty : itemQtyMap.entrySet()) {
|
| 29327 |
tejbeer |
610 |
|
| 31773 |
amit.gupta |
611 |
int availbleQty = itemQty.getValue();
|
|
|
612 |
if (availbleQty == 0) {
|
|
|
613 |
break;
|
|
|
614 |
}
|
|
|
615 |
if (requiredItemQty.get(itemQty.getKey()) == null) {
|
|
|
616 |
requiredItemQty.put(itemQty.getKey(), 1);
|
|
|
617 |
availbleQty = availbleQty - 1;
|
|
|
618 |
if (availbleQty != 0) {
|
|
|
619 |
itemQtyMap.put(itemQty.getKey(), availbleQty);
|
|
|
620 |
}
|
|
|
621 |
shortQty -= 1;
|
|
|
622 |
} else {
|
| 29327 |
tejbeer |
623 |
|
| 31773 |
amit.gupta |
624 |
int qty = requiredItemQty.get(itemQty.getKey());
|
| 29327 |
tejbeer |
625 |
|
| 31773 |
amit.gupta |
626 |
requiredItemQty.put(itemQty.getKey(), qty + 1);
|
| 29327 |
tejbeer |
627 |
|
| 31773 |
amit.gupta |
628 |
availbleQty = availbleQty - 1;
|
|
|
629 |
if (availbleQty != 0) {
|
|
|
630 |
itemQtyMap.put(itemQty.getKey(), availbleQty);
|
|
|
631 |
}
|
|
|
632 |
shortQty -= 1;
|
|
|
633 |
}
|
| 29327 |
tejbeer |
634 |
|
| 31773 |
amit.gupta |
635 |
if (shortQty == 0) {
|
|
|
636 |
break;
|
|
|
637 |
}
|
| 29327 |
tejbeer |
638 |
|
| 31773 |
amit.gupta |
639 |
}
|
| 29327 |
tejbeer |
640 |
|
| 31773 |
amit.gupta |
641 |
}
|
| 29327 |
tejbeer |
642 |
|
| 31773 |
amit.gupta |
643 |
Set<CartItem> cartItems = new HashSet<>();
|
|
|
644 |
for (Entry<Integer, Integer> itemQtySet : requiredItemQty.entrySet()) {
|
| 29327 |
tejbeer |
645 |
|
| 31773 |
amit.gupta |
646 |
CartItem ci = new CartItem();
|
|
|
647 |
Item item = itemRepository.selectById(itemQtySet.getKey());
|
|
|
648 |
TagListing tl = tagListingRepository.selectByItemId(item.getId());
|
|
|
649 |
ci.setItemId(item.getId());
|
|
|
650 |
ci.setQuantity(itemQtySet.getValue());
|
|
|
651 |
ci.setSellingPrice(tl.getSellingPrice());
|
|
|
652 |
cartItems.add(ci);
|
|
|
653 |
|
|
|
654 |
}
|
|
|
655 |
fms.setCartItems(cartItems);
|
|
|
656 |
|
|
|
657 |
// fms.setItemQtyAvailability(requiredItemQty);
|
|
|
658 |
|
|
|
659 |
focusedModelShortageList.add(fms);
|
|
|
660 |
|
|
|
661 |
}
|
|
|
662 |
|
|
|
663 |
}
|
|
|
664 |
|
|
|
665 |
logger.info("focusedModelShortageList {}", focusedModelShortageList);
|
|
|
666 |
return focusedModelShortageList;
|
|
|
667 |
}
|
|
|
668 |
|
| 33172 |
tejus.loha |
669 |
@Override
|
|
|
670 |
public UserCart setCartItems(int fofoId, List<CartItem> cartItems) throws ProfitMandiBusinessException {
|
|
|
671 |
User user = saholicUserRepository.selectById(fofoId);
|
|
|
672 |
this.clearCart(user.getActiveCartId());
|
| 37143 |
amit |
673 |
this.addItemsToCart(user.getActiveCartId(), fofoId, cartItems);
|
| 33172 |
tejus.loha |
674 |
|
|
|
675 |
UserCart userCart = new UserCart();
|
|
|
676 |
userCart.setCartId(user.getActiveCartId());
|
|
|
677 |
userCart.setUserId(user.getId());
|
|
|
678 |
return userCart;
|
|
|
679 |
}
|
|
|
680 |
|
| 26522 |
amit.gupta |
681 |
}
|