| 23755 |
amit.gupta |
1 |
package com.smartdukaan.cron.migrations;
|
|
|
2 |
|
| 23824 |
amit.gupta |
3 |
import java.time.LocalDate;
|
| 23755 |
amit.gupta |
4 |
import java.time.LocalDateTime;
|
| 23824 |
amit.gupta |
5 |
import java.time.LocalTime;
|
| 23755 |
amit.gupta |
6 |
import java.util.Arrays;
|
| 23827 |
amit.gupta |
7 |
import java.util.Collections;
|
| 24002 |
amit.gupta |
8 |
import java.util.HashMap;
|
| 23755 |
amit.gupta |
9 |
import java.util.List;
|
| 24002 |
amit.gupta |
10 |
import java.util.Map;
|
| 23755 |
amit.gupta |
11 |
|
|
|
12 |
import org.apache.commons.lang.StringUtils;
|
|
|
13 |
import org.apache.logging.log4j.LogManager;
|
|
|
14 |
import org.apache.logging.log4j.Logger;
|
|
|
15 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
16 |
import org.springframework.stereotype.Component;
|
|
|
17 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
18 |
|
| 23898 |
amit.gupta |
19 |
import com.spice.profitmandi.dao.entity.fofo.Purchase;
|
| 23824 |
amit.gupta |
20 |
import com.spice.profitmandi.dao.entity.transaction.LineItem;
|
| 23755 |
amit.gupta |
21 |
import com.spice.profitmandi.dao.entity.transaction.LineItemImei;
|
|
|
22 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
| 23899 |
amit.gupta |
23 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 24002 |
amit.gupta |
24 |
import com.spice.profitmandi.dao.repository.fofo.DebitNoteRepository;
|
|
|
25 |
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
|
| 23898 |
amit.gupta |
26 |
import com.spice.profitmandi.dao.repository.fofo.PurchaseRepository;
|
| 24002 |
amit.gupta |
27 |
import com.spice.profitmandi.dao.repository.fofo.SchemeInOutRepository;
|
| 23755 |
amit.gupta |
28 |
import com.spice.profitmandi.dao.repository.transaction.LineItemImeisRepository;
|
| 23824 |
amit.gupta |
29 |
import com.spice.profitmandi.dao.repository.transaction.LineItemRepository;
|
| 23755 |
amit.gupta |
30 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
| 24002 |
amit.gupta |
31 |
import com.spice.profitmandi.dao.repository.user.UserRepository;
|
| 23899 |
amit.gupta |
32 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
|
|
33 |
import com.spice.profitmandi.service.transaction.TransactionService;
|
|
|
34 |
import com.spice.profitmandi.service.user.RetailerService;
|
|
|
35 |
import com.spice.profitmandi.service.wallet.WalletService;
|
| 23755 |
amit.gupta |
36 |
|
| 24002 |
amit.gupta |
37 |
import in.shop2020.model.v1.order.WalletReferenceType;
|
|
|
38 |
|
| 23755 |
amit.gupta |
39 |
@Component
|
|
|
40 |
@Transactional(rollbackFor = Throwable.class)
|
|
|
41 |
public class RunOnceTasks {
|
|
|
42 |
|
|
|
43 |
private static final Logger LOGGER = LogManager.getLogger(RunOnceTasks.class);
|
|
|
44 |
|
|
|
45 |
@Autowired
|
| 23824 |
amit.gupta |
46 |
private LineItemRepository lineItemRepository;
|
| 23905 |
amit.gupta |
47 |
|
|
|
48 |
@Autowired
|
| 24002 |
amit.gupta |
49 |
private UserRepository userRepository;
|
|
|
50 |
|
|
|
51 |
@Autowired
|
| 23899 |
amit.gupta |
52 |
private WalletService walletService;
|
|
|
53 |
|
|
|
54 |
@Autowired
|
|
|
55 |
private InventoryService inventoryService;
|
|
|
56 |
|
|
|
57 |
@Autowired
|
|
|
58 |
private TransactionService transactionService;
|
|
|
59 |
|
|
|
60 |
@Autowired
|
| 23755 |
amit.gupta |
61 |
private OrderRepository orderRepository;
|
| 23767 |
amit.gupta |
62 |
|
| 23755 |
amit.gupta |
63 |
@Autowired
|
| 23899 |
amit.gupta |
64 |
private FofoStoreRepository fofoStoreRepository;
|
|
|
65 |
|
|
|
66 |
@Autowired
|
| 23755 |
amit.gupta |
67 |
private LineItemImeisRepository lineItemImeisRepository;
|
| 24002 |
amit.gupta |
68 |
|
|
|
69 |
@Autowired
|
|
|
70 |
private InventoryItemRepository inventoryItemRepository;
|
| 23901 |
amit.gupta |
71 |
|
| 23898 |
amit.gupta |
72 |
@Autowired
|
| 23899 |
amit.gupta |
73 |
private RetailerService retailerService;
|
| 24002 |
amit.gupta |
74 |
|
|
|
75 |
@Autowired
|
|
|
76 |
private SchemeInOutRepository schemeInOutRepository;
|
|
|
77 |
|
|
|
78 |
@Autowired
|
|
|
79 |
private DebitNoteRepository debitNoteRepository;
|
| 23899 |
amit.gupta |
80 |
|
|
|
81 |
@Autowired
|
| 23898 |
amit.gupta |
82 |
private PurchaseRepository purchaseRepository;
|
| 24002 |
amit.gupta |
83 |
|
|
|
84 |
public void schemeRollback() {
|
|
|
85 |
Map<Integer, Float> fofoIdAmount = new HashMap<>();
|
| 24003 |
amit.gupta |
86 |
fofoIdAmount.put(175135218, 1942f);
|
|
|
87 |
fofoIdAmount.put(175135218, 438f);
|
|
|
88 |
fofoIdAmount.put(175135218, -478f);
|
|
|
89 |
String description = "Price drop/differential rolled out as, they were already returned, Total 2pcs.";
|
| 24002 |
amit.gupta |
90 |
for(Map.Entry<Integer, Float> fofoIdAmountEntry: fofoIdAmount.entrySet()) {
|
|
|
91 |
Integer fofoId=fofoIdAmountEntry.getKey();
|
|
|
92 |
Float amount = fofoIdAmountEntry.getValue();
|
| 24003 |
amit.gupta |
93 |
walletService.rollbackAmountFromWallet(fofoId, amount, 4, WalletReferenceType.PRICE_DROP, description);
|
| 24002 |
amit.gupta |
94 |
}
|
|
|
95 |
}
|
| 23755 |
amit.gupta |
96 |
|
| 23898 |
amit.gupta |
97 |
public void populateGrnTimestamp() {
|
|
|
98 |
List<Purchase> allPurchases = purchaseRepository.selectAll();
|
| 23899 |
amit.gupta |
99 |
for (Purchase p : allPurchases) {
|
| 23898 |
amit.gupta |
100 |
String invoiceNumber = p.getPurchaseReference();
|
| 23899 |
amit.gupta |
101 |
if (p.getCompleteTimestamp() == null) {
|
| 23898 |
amit.gupta |
102 |
LOGGER.info("GRN for invoice {} is delivered but partially Completed.", p.getPurchaseReference());
|
|
|
103 |
} else {
|
|
|
104 |
List<Order> orders = orderRepository.selectByAirwayBillOrInvoiceNumber(invoiceNumber, p.getFofoId());
|
| 23899 |
amit.gupta |
105 |
for (Order order : orders) {
|
| 23902 |
amit.gupta |
106 |
if (order.getPartnerGrnTimestamp() == null) {
|
|
|
107 |
order.setPartnerGrnTimestamp(p.getCompleteTimestamp());
|
| 23898 |
amit.gupta |
108 |
orderRepository.persist(order);
|
|
|
109 |
}
|
|
|
110 |
}
|
|
|
111 |
}
|
|
|
112 |
}
|
| 23899 |
amit.gupta |
113 |
|
| 23898 |
amit.gupta |
114 |
}
|
| 23899 |
amit.gupta |
115 |
|
| 23755 |
amit.gupta |
116 |
public void migarateLineItemsToNewTable() {
|
|
|
117 |
LOGGER.info("Before Migrated LineItems Successfully");
|
| 23824 |
amit.gupta |
118 |
int lineItemImeiId = 0;
|
|
|
119 |
LocalDateTime startDate = null;
|
|
|
120 |
try {
|
|
|
121 |
lineItemImeiId = lineItemImeisRepository.selectMaxId();
|
| 23899 |
amit.gupta |
122 |
LineItem lineItem = lineItemRepository
|
|
|
123 |
.selectById(lineItemImeisRepository.selectById(lineItemImeiId).getLineItemId());
|
| 23824 |
amit.gupta |
124 |
Order order = orderRepository.selectById(lineItem.getOrderId());
|
|
|
125 |
startDate = order.getBillingTimestamp();
|
|
|
126 |
} catch (Exception e) {
|
|
|
127 |
LOGGER.info("Running before first time");
|
| 23826 |
amit.gupta |
128 |
startDate = LocalDateTime.of(LocalDate.of(2017, 7, 1), LocalTime.MIDNIGHT);
|
| 23824 |
amit.gupta |
129 |
}
|
|
|
130 |
List<Order> orders = orderRepository.selectAllByBillingDatesBetween(startDate, LocalDateTime.now());
|
| 23827 |
amit.gupta |
131 |
Collections.reverse(orders);
|
| 23899 |
amit.gupta |
132 |
|
| 23755 |
amit.gupta |
133 |
for (Order order : orders) {
|
| 23824 |
amit.gupta |
134 |
try {
|
| 23767 |
amit.gupta |
135 |
String serialNumbers = order.getLineItem().getSerialNumber();
|
|
|
136 |
if (!StringUtils.isEmpty(serialNumbers)) {
|
|
|
137 |
List<String> serialNumberList = Arrays.asList(serialNumbers.split(","));
|
|
|
138 |
for (String serialNumber : serialNumberList) {
|
|
|
139 |
int lineItemId = order.getLineItem().getId();
|
|
|
140 |
LineItemImei lineItemImei = new LineItemImei();
|
|
|
141 |
lineItemImei.setSerialNumber(serialNumber);
|
|
|
142 |
lineItemImei.setLineItemId(lineItemId);
|
|
|
143 |
lineItemImeisRepository.persist(lineItemImei);
|
|
|
144 |
}
|
|
|
145 |
} else {
|
|
|
146 |
LOGGER.info("Serial Numbers dont exist for Order {}", order.getId());
|
| 23755 |
amit.gupta |
147 |
}
|
| 23824 |
amit.gupta |
148 |
} catch (Exception e) {
|
| 23899 |
amit.gupta |
149 |
LOGGER.info("Error occurred while creating lineitem imei {}, because of {}", order.getId(),
|
|
|
150 |
e.getMessage());
|
| 23755 |
amit.gupta |
151 |
}
|
|
|
152 |
}
|
|
|
153 |
LOGGER.info("Migrated LineItems Successfully");
|
|
|
154 |
}
|
|
|
155 |
}
|