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