| Line 1... |
Line 1... |
| 1 |
package com.smartdukaan.cron.migrations;
|
1 |
package com.smartdukaan.cron.migrations;
|
| 2 |
|
2 |
|
| 3 |
import java.time.LocalDate;
|
3 |
import java.time.LocalDate;
|
| 4 |
import java.time.LocalDateTime;
|
4 |
import java.time.LocalDateTime;
|
| 5 |
import java.time.LocalTime;
|
5 |
import java.time.LocalTime;
|
| - |
|
6 |
import java.util.ArrayList;
|
| 6 |
import java.util.Arrays;
|
7 |
import java.util.Arrays;
|
| 7 |
import java.util.Collections;
|
8 |
import java.util.Collections;
|
| 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.stream.Collectors;
|
13 |
import java.util.stream.Collectors;
|
| 13 |
|
14 |
|
| - |
|
15 |
import org.apache.commons.io.output.ByteArrayOutputStream;
|
| 14 |
import org.apache.commons.lang.StringUtils;
|
16 |
import org.apache.commons.lang.StringUtils;
|
| 15 |
import org.apache.logging.log4j.LogManager;
|
17 |
import org.apache.logging.log4j.LogManager;
|
| 16 |
import org.apache.logging.log4j.Logger;
|
18 |
import org.apache.logging.log4j.Logger;
|
| 17 |
import org.springframework.beans.factory.annotation.Autowired;
|
19 |
import org.springframework.beans.factory.annotation.Autowired;
|
| - |
|
20 |
import org.springframework.core.io.ByteArrayResource;
|
| - |
|
21 |
import org.springframework.mail.javamail.JavaMailSender;
|
| 18 |
import org.springframework.stereotype.Component;
|
22 |
import org.springframework.stereotype.Component;
|
| 19 |
import org.springframework.transaction.annotation.Transactional;
|
23 |
import org.springframework.transaction.annotation.Transactional;
|
| 20 |
|
24 |
|
| - |
|
25 |
import com.spice.profitmandi.common.util.FileUtil;
|
| - |
|
26 |
import com.spice.profitmandi.common.util.Utils;
|
| 21 |
import com.spice.profitmandi.dao.entity.fofo.CurrentInventorySnapshot;
|
27 |
import com.spice.profitmandi.dao.entity.fofo.CurrentInventorySnapshot;
|
| 22 |
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
|
28 |
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
|
| 23 |
import com.spice.profitmandi.dao.entity.fofo.Purchase;
|
29 |
import com.spice.profitmandi.dao.entity.fofo.Purchase;
|
| 24 |
import com.spice.profitmandi.dao.entity.fofo.ScanRecord;
|
30 |
import com.spice.profitmandi.dao.entity.fofo.ScanRecord;
|
| 25 |
import com.spice.profitmandi.dao.entity.transaction.LineItem;
|
31 |
import com.spice.profitmandi.dao.entity.transaction.LineItem;
|
| 26 |
import com.spice.profitmandi.dao.entity.transaction.LineItemImei;
|
32 |
import com.spice.profitmandi.dao.entity.transaction.LineItemImei;
|
| 27 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
33 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
| - |
|
34 |
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
|
| - |
|
35 |
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
|
| 28 |
import com.spice.profitmandi.dao.enumuration.fofo.ScanType;
|
36 |
import com.spice.profitmandi.dao.enumuration.fofo.ScanType;
|
| 29 |
import com.spice.profitmandi.dao.repository.GenericRepository;
|
37 |
import com.spice.profitmandi.dao.repository.GenericRepository;
|
| 30 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
38 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 31 |
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
|
39 |
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
|
| 32 |
import com.spice.profitmandi.dao.repository.fofo.DebitNoteRepository;
|
40 |
import com.spice.profitmandi.dao.repository.fofo.DebitNoteRepository;
|
| Line 35... |
Line 43... |
| 35 |
import com.spice.profitmandi.dao.repository.fofo.ScanRecordRepository;
|
43 |
import com.spice.profitmandi.dao.repository.fofo.ScanRecordRepository;
|
| 36 |
import com.spice.profitmandi.dao.repository.fofo.SchemeInOutRepository;
|
44 |
import com.spice.profitmandi.dao.repository.fofo.SchemeInOutRepository;
|
| 37 |
import com.spice.profitmandi.dao.repository.transaction.LineItemImeisRepository;
|
45 |
import com.spice.profitmandi.dao.repository.transaction.LineItemImeisRepository;
|
| 38 |
import com.spice.profitmandi.dao.repository.transaction.LineItemRepository;
|
46 |
import com.spice.profitmandi.dao.repository.transaction.LineItemRepository;
|
| 39 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
47 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
| - |
|
48 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletHistoryRepository;
|
| - |
|
49 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
|
| 40 |
import com.spice.profitmandi.dao.repository.user.UserRepository;
|
50 |
import com.spice.profitmandi.dao.repository.user.UserRepository;
|
| 41 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
51 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
| 42 |
import com.spice.profitmandi.service.order.OrderService;
|
52 |
import com.spice.profitmandi.service.order.OrderService;
|
| 43 |
import com.spice.profitmandi.service.pricing.PriceDropService;
|
53 |
import com.spice.profitmandi.service.pricing.PriceDropService;
|
| 44 |
import com.spice.profitmandi.service.scheme.SchemeService;
|
54 |
import com.spice.profitmandi.service.scheme.SchemeService;
|
| 45 |
import com.spice.profitmandi.service.transaction.TransactionService;
|
55 |
import com.spice.profitmandi.service.transaction.TransactionService;
|
| 46 |
import com.spice.profitmandi.service.user.RetailerService;
|
56 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 47 |
import com.spice.profitmandi.service.wallet.WalletService;
|
57 |
import com.spice.profitmandi.service.wallet.WalletService;
|
| 48 |
|
58 |
|
| - |
|
59 |
import in.shop2020.model.v1.order.OrderStatus;
|
| 49 |
import in.shop2020.model.v1.order.WalletReferenceType;
|
60 |
import in.shop2020.model.v1.order.WalletReferenceType;
|
| 50 |
|
61 |
|
| 51 |
@Component
|
62 |
@Component
|
| 52 |
@Transactional(rollbackFor = Throwable.class)
|
63 |
@Transactional(rollbackFor = Throwable.class)
|
| 53 |
public class RunOnceTasks {
|
64 |
public class RunOnceTasks {
|
| Line 56... |
Line 67... |
| 56 |
|
67 |
|
| 57 |
@Autowired
|
68 |
@Autowired
|
| 58 |
private LineItemRepository lineItemRepository;
|
69 |
private LineItemRepository lineItemRepository;
|
| 59 |
|
70 |
|
| 60 |
@Autowired
|
71 |
@Autowired
|
| - |
|
72 |
private UserWalletRepository userWalletRepository;
|
| - |
|
73 |
|
| - |
|
74 |
@Autowired
|
| - |
|
75 |
private UserWalletHistoryRepository userWalletHistoryRepository;
|
| - |
|
76 |
|
| - |
|
77 |
@Autowired
|
| 61 |
private UserRepository userRepository;
|
78 |
private UserRepository userRepository;
|
| 62 |
|
79 |
|
| 63 |
@Autowired
|
80 |
@Autowired
|
| 64 |
private WalletService walletService;
|
81 |
private WalletService walletService;
|
| 65 |
|
82 |
|
| Line 67... |
Line 84... |
| 67 |
private InventoryService inventoryService;
|
84 |
private InventoryService inventoryService;
|
| 68 |
|
85 |
|
| 69 |
@Autowired
|
86 |
@Autowired
|
| 70 |
private TransactionService transactionService;
|
87 |
private TransactionService transactionService;
|
| 71 |
|
88 |
|
| 72 |
@Autowired
|
- |
|
| 73 |
private OrderRepository orderRepository;
|
- |
|
| 74 |
|
- |
|
| 75 |
// Service for Tertiary/Partner Orders
|
89 |
// Service for Tertiary/Partner Orders
|
| 76 |
@Autowired
|
90 |
@Autowired
|
| 77 |
private OrderService orderService;
|
91 |
private OrderService orderService;
|
| 78 |
|
92 |
|
| 79 |
@Autowired
|
93 |
@Autowired
|
| Line 108... |
Line 122... |
| 108 |
|
122 |
|
| 109 |
@Autowired
|
123 |
@Autowired
|
| 110 |
private CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
|
124 |
private CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
|
| 111 |
|
125 |
|
| 112 |
@Autowired
|
126 |
@Autowired
|
| - |
|
127 |
private OrderRepository orderRepository;
|
| - |
|
128 |
|
| - |
|
129 |
@Autowired
|
| 113 |
private ScanRecordRepository scanRecordRepository;
|
130 |
private ScanRecordRepository scanRecordRepository;
|
| 114 |
|
131 |
|
| - |
|
132 |
@Autowired
|
| - |
|
133 |
private JavaMailSender mailSender;
|
| - |
|
134 |
|
| 115 |
public void dropCorrection() throws Exception {
|
135 |
public void dropCorrection() throws Exception {
|
| 116 |
|
136 |
|
| 117 |
walletService.rollbackAmountFromWallet(175128034, 274, 4, WalletReferenceType.PRICE_DROP,
|
137 |
walletService.rollbackAmountFromWallet(175128034, 274, 4, WalletReferenceType.PRICE_DROP,
|
| 118 |
"Scheme differential for Price Drop of Rs.712 on Samsung J6 J600GG, on 01-08-2018 for missing 1pc");
|
138 |
"Scheme differential for Price Drop of Rs.712 on Samsung J6 J600GG, on 01-08-2018 for missing 1pc");
|
| 119 |
walletService.rollbackAmountFromWallet(175128034, -259, 4, WalletReferenceType.PRICE_DROP,
|
139 |
walletService.rollbackAmountFromWallet(175128034, -259, 4, WalletReferenceType.PRICE_DROP,
|
| Line 249... |
Line 269... |
| 249 |
quantityToReduce = quantityToReduce - ii.getGoodQuantity();
|
269 |
quantityToReduce = quantityToReduce - ii.getGoodQuantity();
|
| 250 |
ii.setGoodQuantity(0);
|
270 |
ii.setGoodQuantity(0);
|
| 251 |
cis.setAvailability(cis.getAvailability() - ii.getGoodQuantity());
|
271 |
cis.setAvailability(cis.getAvailability() - ii.getGoodQuantity());
|
| 252 |
purchase.setUnfullfilledNonSerializedQuantity(
|
272 |
purchase.setUnfullfilledNonSerializedQuantity(
|
| 253 |
purchase.getUnfullfilledNonSerializedQuantity() + quantityToReduce);
|
273 |
purchase.getUnfullfilledNonSerializedQuantity() + quantityToReduce);
|
| 254 |
LOGGER.info("Rectified {}, {}, {}, {}, {}, {}",
|
274 |
LOGGER.info("Rectified {}, {}, {}, {}, {}, {}", purchase.getPurchaseReference(),
|
| 255 |
purchase.getPurchaseReference(), ii.getId(), ii.getItemId(),
|
- |
|
| 256 |
ii.getInitialQuantity(), ii.getGoodQuantity(),
|
275 |
ii.getId(), ii.getItemId(), ii.getInitialQuantity(),
|
| 257 |
quantityToReduce);
|
276 |
ii.getGoodQuantity(), quantityToReduce);
|
| 258 |
break;
|
277 |
break;
|
| 259 |
}
|
278 |
}
|
| 260 |
}
|
279 |
}
|
| 261 |
}
|
280 |
}
|
| 262 |
}
|
281 |
}
|
| 263 |
}
|
282 |
}
|
| 264 |
}
|
283 |
}
|
| 265 |
}
|
284 |
}
|
| 266 |
}
|
285 |
}
|
| 267 |
//throw new Exception();
|
286 |
// throw new Exception();
|
| - |
|
287 |
}
|
| - |
|
288 |
|
| - |
|
289 |
// Lets work it up for The Mobile Planet
|
| - |
|
290 |
// HRFB002 - 157112773
|
| - |
|
291 |
public void dailyReconciliation() throws Exception {
|
| - |
|
292 |
List<List<?>> rows = new ArrayList<>();
|
| - |
|
293 |
UserWallet uw = userWalletRepository.selectByRetailerId(157112773);
|
| - |
|
294 |
List<UserWalletHistory> walletHistory = userWalletHistoryRepository.selectByWalletId(uw.getId());
|
| - |
|
295 |
Map<LocalDate, List<UserWalletHistory>> dateWiseWalletHistory = walletHistory.stream()
|
| - |
|
296 |
.collect(Collectors.groupingBy(x -> x.getTimestamp().toLocalDate(), Collectors.toList()));
|
| - |
|
297 |
for (Map.Entry<LocalDate, List<UserWalletHistory>> entry : dateWiseWalletHistory.entrySet()) {
|
| - |
|
298 |
LocalDate dateToReconcile = entry.getKey();
|
| - |
|
299 |
List<UserWalletHistory> history = entry.getValue();
|
| - |
|
300 |
rows.add(reconcileOrdersAndWallet(uw.getUserId(), dateToReconcile, history));
|
| - |
|
301 |
}
|
| - |
|
302 |
ByteArrayOutputStream baos = FileUtil.getCSVByteStream(Arrays.asList("Date", "Wallet Total", "Order Total"),
|
| - |
|
303 |
rows);
|
| - |
|
304 |
|
| - |
|
305 |
Utils.sendMailWithAttachment(mailSender, new String[] { "amit.gupta@shop2020.in" }, new String[] {}, "Test",
|
| - |
|
306 |
"test", "File.csv", new ByteArrayResource(baos.toByteArray()));
|
| - |
|
307 |
}
|
| - |
|
308 |
|
| - |
|
309 |
private List<?> reconcileOrdersAndWallet(int fofoId, LocalDate localDate, List<UserWalletHistory> history)
|
| - |
|
310 |
throws Exception {
|
| - |
|
311 |
Map<Integer, Integer> transactionsOnThatDate = history.stream()
|
| - |
|
312 |
.filter(x -> x.getReferenceType().equals(WalletReferenceType.PURCHASE))
|
| - |
|
313 |
.collect(Collectors.groupingBy(x -> x.getReference(), Collectors.summingInt(x -> x.getAmount())));
|
| - |
|
314 |
|
| - |
|
315 |
int walletConsumed = 0;
|
| - |
|
316 |
float totalOrderAmount = 0;
|
| - |
|
317 |
for (int transactionId : transactionsOnThatDate.keySet()) {
|
| - |
|
318 |
walletConsumed -= transactionsOnThatDate.get(transactionId);
|
| - |
|
319 |
List<Order> orders = orderRepository.selectAllByTransactionId(transactionId);
|
| - |
|
320 |
for (Order o : orders) {
|
| - |
|
321 |
if (o.getRefundTimestamp() == null) {
|
| - |
|
322 |
if (Arrays.asList(OrderStatus.PAYMENT_PENDING, OrderStatus.PAYMENT_FAILED)
|
| - |
|
323 |
.contains(o.getStatus())) {
|
| - |
|
324 |
totalOrderAmount -= o.getWalletAmount();
|
| - |
|
325 |
} else {
|
| - |
|
326 |
totalOrderAmount += o.getWalletAmount();
|
| - |
|
327 |
}
|
| - |
|
328 |
} else {
|
| - |
|
329 |
totalOrderAmount -= o.getWalletAmount();
|
| - |
|
330 |
}
|
| - |
|
331 |
}
|
| - |
|
332 |
}
|
| - |
|
333 |
|
| - |
|
334 |
return Arrays.asList(localDate, walletConsumed, totalOrderAmount);
|
| - |
|
335 |
|
| - |
|
336 |
}
|
| - |
|
337 |
|
| - |
|
338 |
private void reconcileDailySchemeIn() {
|
| - |
|
339 |
|
| - |
|
340 |
}
|
| - |
|
341 |
|
| - |
|
342 |
private void reconcileDailySchemeOut() {
|
| - |
|
343 |
|
| 268 |
}
|
344 |
}
|
| 269 |
}
|
345 |
}
|
| 270 |
|
346 |
|