| Line 1... |
Line 1... |
| 1 |
package com.smartdukaan.cron.scheduled;
|
1 |
package com.smartdukaan.cron.scheduled;
|
| 2 |
|
2 |
|
| - |
|
3 |
import java.sql.Timestamp;
|
| 3 |
import java.time.LocalDate;
|
4 |
import java.time.LocalDate;
|
| 4 |
import java.time.LocalDateTime;
|
5 |
import java.time.LocalDateTime;
|
| 5 |
import java.time.temporal.ChronoUnit;
|
6 |
import java.time.temporal.ChronoUnit;
|
| 6 |
import java.util.ArrayList;
|
7 |
import java.util.ArrayList;
|
| 7 |
import java.util.Arrays;
|
8 |
import java.util.Arrays;
|
| 8 |
import java.util.HashMap;
|
9 |
import java.util.HashMap;
|
| 9 |
import java.util.List;
|
10 |
import java.util.List;
|
| 10 |
import java.util.Map;
|
11 |
import java.util.Map;
|
| 11 |
import java.util.stream.Collectors;
|
12 |
import java.util.stream.Collectors;
|
| 12 |
|
13 |
|
| 13 |
import javax.servlet.http.HttpServletRequest;
|
- |
|
| 14 |
|
- |
|
| 15 |
import org.slf4j.Logger;
|
14 |
import org.slf4j.Logger;
|
| 16 |
import org.slf4j.LoggerFactory;
|
15 |
import org.slf4j.LoggerFactory;
|
| 17 |
import org.springframework.beans.factory.annotation.Autowired;
|
16 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 18 |
import org.springframework.beans.factory.annotation.Value;
|
17 |
import org.springframework.beans.factory.annotation.Value;
|
| 19 |
import org.springframework.scheduling.annotation.Scheduled;
|
18 |
import org.springframework.scheduling.annotation.Scheduled;
|
| 20 |
import org.springframework.stereotype.Component;
|
19 |
import org.springframework.stereotype.Component;
|
| 21 |
import org.springframework.transaction.annotation.Transactional;
|
20 |
import org.springframework.transaction.annotation.Transactional;
|
| 22 |
import org.springframework.ui.Model;
|
- |
|
| 23 |
|
21 |
|
| 24 |
import com.smartdukaan.cron.monitored.NagiosMonitorTasks;
|
22 |
import com.smartdukaan.cron.monitored.NagiosMonitorTasks;
|
| 25 |
import com.spice.profitmandi.common.enumuration.RechargeStatus;
|
23 |
import com.spice.profitmandi.common.enumuration.RechargeStatus;
|
| 26 |
import com.spice.profitmandi.common.model.RechargeCredential;
|
24 |
import com.spice.profitmandi.common.model.RechargeCredential;
|
| 27 |
import com.spice.profitmandi.common.web.client.RestClient;
|
- |
|
| 28 |
import com.spice.profitmandi.dao.entity.dtr.DailyRecharge;
|
25 |
import com.spice.profitmandi.dao.entity.dtr.DailyRecharge;
|
| 29 |
import com.spice.profitmandi.dao.entity.dtr.RechargeProvider;
|
26 |
import com.spice.profitmandi.dao.entity.dtr.RechargeProvider;
|
| 30 |
import com.spice.profitmandi.dao.entity.dtr.RechargeProviderCreditWalletHistory;
|
27 |
import com.spice.profitmandi.dao.entity.dtr.RechargeProviderCreditWalletHistory;
|
| 31 |
import com.spice.profitmandi.dao.entity.dtr.RechargeTransaction;
|
28 |
import com.spice.profitmandi.dao.entity.dtr.RechargeTransaction;
|
| 32 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
|
29 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
|
| Line 38... |
Line 35... |
| 38 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
|
35 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
|
| 39 |
import com.spice.profitmandi.dao.repository.fofo.PurchaseRepository;
|
36 |
import com.spice.profitmandi.dao.repository.fofo.PurchaseRepository;
|
| 40 |
import com.spice.profitmandi.service.recharge.provider.OxigenRechargeProviderService;
|
37 |
import com.spice.profitmandi.service.recharge.provider.OxigenRechargeProviderService;
|
| 41 |
import com.spice.profitmandi.service.recharge.provider.ThinkWalnutDigitalRechargeProviderService;
|
38 |
import com.spice.profitmandi.service.recharge.provider.ThinkWalnutDigitalRechargeProviderService;
|
| 42 |
import com.spice.profitmandi.service.scheme.SchemeService;
|
39 |
import com.spice.profitmandi.service.scheme.SchemeService;
|
| - |
|
40 |
import com.spice.profitmandi.service.wallet.WalletService;
|
| - |
|
41 |
|
| - |
|
42 |
import in.shop2020.model.v1.order.WalletReferenceType;
|
| 43 |
|
43 |
|
| 44 |
@Component
|
44 |
@Component
|
| 45 |
@Transactional(rollbackFor = Throwable.class)
|
45 |
@Transactional(rollbackFor = Throwable.class)
|
| 46 |
public class ScheduledTasks {
|
46 |
public class ScheduledTasks {
|
| 47 |
|
47 |
|
| Line 93... |
Line 93... |
| 93 |
@Autowired
|
93 |
@Autowired
|
| 94 |
private RechargeProviderCreditWalletHistoryRepository rechargeProviderCreditWalletHistoryRepository;
|
94 |
private RechargeProviderCreditWalletHistoryRepository rechargeProviderCreditWalletHistoryRepository;
|
| 95 |
|
95 |
|
| 96 |
@Autowired
|
96 |
@Autowired
|
| 97 |
private FofoOrderRepository fofoOrderRepository;
|
97 |
private FofoOrderRepository fofoOrderRepository;
|
| - |
|
98 |
|
| - |
|
99 |
@Autowired
|
| - |
|
100 |
private WalletService walletService;
|
| 98 |
|
101 |
|
| 99 |
@Autowired
|
102 |
@Autowired
|
| 100 |
private ThinkWalnutDigitalRechargeProviderService thinkWalnutDigitalRechargeProviderService;
|
103 |
private ThinkWalnutDigitalRechargeProviderService thinkWalnutDigitalRechargeProviderService;
|
| 101 |
|
104 |
|
| 102 |
@Autowired
|
105 |
@Autowired
|
| Line 245... |
Line 248... |
| 245 |
LOGGER.error("Error while processing sale order {} for scheme Out", fofoOrder.getId());
|
248 |
LOGGER.error("Error while processing sale order {} for scheme Out", fofoOrder.getId());
|
| 246 |
}
|
249 |
}
|
| 247 |
}
|
250 |
}
|
| 248 |
LOGGER.info("Schemes process successfully.");
|
251 |
LOGGER.info("Schemes process successfully.");
|
| 249 |
}
|
252 |
}
|
| - |
|
253 |
|
| - |
|
254 |
@Scheduled(cron = "07 15 1,16 * *")
|
| - |
|
255 |
public void processRechargeCashback() throws Throwable {
|
| - |
|
256 |
int referenceId = (int)Timestamp.valueOf(LocalDateTime.now()).getTime()/1000;
|
| - |
|
257 |
List<RechargeTransaction> pendingTransactions = rechargeTransactionRepository.getPendingCashBackRehargeTransactions();
|
| - |
|
258 |
Map<Object, Double> totalRetailerCashbacks = pendingTransactions.stream().collect(Collectors.groupingBy(x->x.getId(), Collectors.summingDouble(x->x.getCommission())));
|
| - |
|
259 |
for (Map.Entry<Object, Double>totalRetailerCashback : totalRetailerCashbacks.entrySet()) {
|
| - |
|
260 |
int retailerId = (Integer)totalRetailerCashback.getKey();
|
| - |
|
261 |
float amount = totalRetailerCashback.getValue().floatValue();
|
| - |
|
262 |
walletService.addAmountToWallet(retailerId, referenceId, WalletReferenceType.CASHBACK, "Recharge Cashback", Math.round(amount));
|
| - |
|
263 |
}
|
| - |
|
264 |
pendingTransactions.forEach(x-> {
|
| - |
|
265 |
x.setCashbackTimestamp(LocalDateTime.now());
|
| - |
|
266 |
x.setCashbackReference(referenceId);
|
| - |
|
267 |
rechargeTransactionRepository.persist(x);
|
| - |
|
268 |
});
|
| - |
|
269 |
LOGGER.info("Cashbacks for Recharge processed Successfully");
|
| - |
|
270 |
}
|
| 250 |
|
271 |
|
| 251 |
}
|
272 |
}
|