Subversion Repositories SmartDukaan

Rev

Rev 23751 | Rev 23761 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 23751 Rev 23755
Line 9... Line 9...
9
import java.util.HashMap;
9
import java.util.HashMap;
10
import java.util.List;
10
import java.util.List;
11
import java.util.Map;
11
import java.util.Map;
12
import java.util.stream.Collectors;
12
import java.util.stream.Collectors;
13
 
13
 
14
import org.slf4j.Logger;
14
import org.apache.logging.log4j.LogManager;
15
import org.slf4j.LoggerFactory;
15
import org.apache.logging.log4j.Logger;
16
import org.springframework.beans.factory.annotation.Autowired;
16
import org.springframework.beans.factory.annotation.Autowired;
17
import org.springframework.beans.factory.annotation.Value;
17
import org.springframework.beans.factory.annotation.Value;
18
import org.springframework.scheduling.annotation.Scheduled;
-
 
19
import org.springframework.stereotype.Component;
18
import org.springframework.stereotype.Component;
20
import org.springframework.transaction.annotation.Transactional;
19
import org.springframework.transaction.annotation.Transactional;
21
 
20
 
22
import com.smartdukaan.cron.monitored.NagiosMonitorTasks;
-
 
23
import com.spice.profitmandi.common.enumuration.RechargeStatus;
21
import com.spice.profitmandi.common.enumuration.RechargeStatus;
24
import com.spice.profitmandi.common.model.RechargeCredential;
22
import com.spice.profitmandi.common.model.RechargeCredential;
25
import com.spice.profitmandi.dao.entity.dtr.DailyRecharge;
23
import com.spice.profitmandi.dao.entity.dtr.DailyRecharge;
26
import com.spice.profitmandi.dao.entity.dtr.RechargeProvider;
24
import com.spice.profitmandi.dao.entity.dtr.RechargeProvider;
27
import com.spice.profitmandi.dao.entity.dtr.RechargeProviderCreditWalletHistory;
25
import com.spice.profitmandi.dao.entity.dtr.RechargeProviderCreditWalletHistory;
Line 112... Line 110...
112
	private DailyRechargeRepository dailyRechargeRepository;
110
	private DailyRechargeRepository dailyRechargeRepository;
113
 
111
 
114
	@Value("${prod}")
112
	@Value("${prod}")
115
	private boolean prod;
113
	private boolean prod;
116
 
114
 
117
	private static final Logger LOGGER = LoggerFactory.getLogger(NagiosMonitorTasks.class);
115
	private static final Logger LOGGER = LogManager.getLogger(ScheduledTasks.class);
118
 
116
 
119
 
117
 
120
	@Scheduled(cron = "1 00 * * * *")
-
 
121
	public void generateDailyRecharge() {
118
	public void generateDailyRecharge() {
122
		List<RechargeProviderCreditWalletHistory> allCreditHistory = rechargeProviderCreditWalletHistoryRepository
119
		List<RechargeProviderCreditWalletHistory> allCreditHistory = rechargeProviderCreditWalletHistoryRepository
123
				.selectAll(0, 2000);
120
				.selectAll(0, 2000);
124
		List<RechargeProvider> rechargeProviders = rechargeProviderRepository.selectAll();
121
		List<RechargeProvider> rechargeProviders = rechargeProviderRepository.selectAll();
125
		rechargeProviders.stream().forEach(x -> x.setAmount(0));
122
		rechargeProviders.stream().forEach(x -> x.setAmount(0));
Line 186... Line 183...
186
			rechargeProviderRepository.persist(x);
183
			rechargeProviderRepository.persist(x);
187
		});
184
		});
188
		LOGGER.info("executio");
185
		LOGGER.info("executio");
189
	}
186
	}
190
 
187
 
191
	@Scheduled(cron = "0 45 * * * *")
-
 
192
	public void reconcileRecharge() throws Exception {
188
	public void reconcileRecharge() throws Exception {
193
		LocalDateTime fromDate = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS).minusDays(30);
189
		LocalDateTime fromDate = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS).minusDays(30);
194
		LocalDateTime toDate = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS);
190
		LocalDateTime toDate = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS);
195
		List<RechargeStatus> nonSuccessRechargeStatuses = new ArrayList<>(Arrays.asList(RechargeStatus.values()));
191
		List<RechargeStatus> nonSuccessRechargeStatuses = new ArrayList<>(Arrays.asList(RechargeStatus.values()));
196
		LOGGER.info("nonSuccessRechargeStatuses {} ", nonSuccessRechargeStatuses);
192
		LOGGER.info("nonSuccessRechargeStatuses {} ", nonSuccessRechargeStatuses);
Line 224... Line 220...
224
			}
220
			}
225
		}
221
		}
226
		LOGGER.info("Reconcile recharge ran successfully");
222
		LOGGER.info("Reconcile recharge ran successfully");
227
	}
223
	}
228
 
224
 
229
	@Scheduled(cron = "0 45 0 * * *")
-
 
230
	public void processScheme() throws Exception {
225
	public void processScheme() throws Exception {
231
		LocalDateTime fromDate = LocalDateTime.now().minusDays(15);
226
		LocalDateTime fromDate = LocalDateTime.now().minusDays(15);
232
		LOGGER.info("Started execution at {}", LocalDateTime.now());
227
		LOGGER.info("Started execution at {}", LocalDateTime.now());
233
		List<Purchase> purchases = purchaseRepository.selectFromPurchaseCompleteDate(fromDate);
228
		List<Purchase> purchases = purchaseRepository.selectFromPurchaseCompleteDate(fromDate);
234
		for (Purchase purchase : purchases) {
229
		for (Purchase purchase : purchases) {
Line 249... Line 244...
249
			}
244
			}
250
		}
245
		}
251
		LOGGER.info("Schemes process successfully.");
246
		LOGGER.info("Schemes process successfully.");
252
	}
247
	}
253
	
248
	
254
	@Scheduled(cron = "0 05 12 1,16 * ?")
-
 
255
	public void processRechargeCashback() throws Throwable {
249
	public void processRechargeCashback() throws Throwable {
256
		int referenceId = (int)Timestamp.valueOf(LocalDateTime.now()).getTime()/1000;
250
		int referenceId = (int)Timestamp.valueOf(LocalDateTime.now()).getTime()/1000;
257
		List<RechargeTransaction> pendingTransactions = rechargeTransactionRepository.getPendingCashBackRehargeTransactions();
251
		List<RechargeTransaction> pendingTransactions = rechargeTransactionRepository.getPendingCashBackRehargeTransactions();
258
		Map<Object, Double> totalRetailerCashbacks = pendingTransactions.stream().collect(Collectors.groupingBy(x->x.getId(), Collectors.summingDouble(x->x.getCommission())));
252
		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()) {
253
		for (Map.Entry<Object, Double>totalRetailerCashback : totalRetailerCashbacks.entrySet()) {