| 22550 |
ashik.ali |
1 |
package com.spice.profitmandi.service.wallet;
|
|
|
2 |
|
|
|
3 |
import java.time.LocalDateTime;
|
|
|
4 |
import java.util.List;
|
|
|
5 |
|
|
|
6 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
7 |
import org.springframework.stereotype.Component;
|
|
|
8 |
|
|
|
9 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
10 |
import com.spice.profitmandi.dao.entity.dtr.UserAccounts;
|
|
|
11 |
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
|
|
|
12 |
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
|
|
|
13 |
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
|
|
|
14 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
|
|
15 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletHistoryRepository;
|
|
|
16 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
|
|
|
17 |
|
|
|
18 |
@Component
|
|
|
19 |
public class WalletServiceImpl implements WalletService {
|
|
|
20 |
|
|
|
21 |
@Autowired
|
|
|
22 |
UserAccountRepository userAccountRepository;
|
|
|
23 |
|
|
|
24 |
@Autowired
|
|
|
25 |
UserWalletRepository userWalletRepository;
|
|
|
26 |
|
|
|
27 |
@Autowired
|
|
|
28 |
UserWalletHistoryRepository userWalletHistoryRepository;
|
|
|
29 |
|
|
|
30 |
@Override
|
|
|
31 |
public UserWallet getUserWalletByUserId(int userId) throws ProfitMandiBusinessException {
|
|
|
32 |
UserAccounts userAccount = userAccountRepository.getUserAccountByType(userId, AccountType.saholic);
|
| 22730 |
amit.gupta |
33 |
Integer retailerId = Integer.valueOf(userAccount.getAccount_key());
|
|
|
34 |
try {
|
|
|
35 |
return userWalletRepository.selectByRetailerId(retailerId);
|
|
|
36 |
} catch (ProfitMandiBusinessException pbe) {
|
|
|
37 |
UserWallet uw = new UserWallet();
|
|
|
38 |
uw.setAmount(0);
|
|
|
39 |
uw.setRefundableAmount(0);
|
|
|
40 |
uw.setUserId(retailerId);
|
|
|
41 |
return uw;
|
|
|
42 |
}
|
| 22550 |
ashik.ali |
43 |
}
|
|
|
44 |
|
|
|
45 |
@Override
|
|
|
46 |
public List<UserWalletHistory> getUserWalletHistoryByUserId(int userId) throws ProfitMandiBusinessException {
|
|
|
47 |
UserWallet userWallet = this.getUserWalletByUserId(userId);
|
|
|
48 |
List<UserWalletHistory> userWalletHistories = userWalletHistoryRepository.selectByWalletId(userWallet.getId());
|
|
|
49 |
return userWalletHistories;
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
@Override
|
|
|
53 |
public List<UserWalletHistory> getUserWalletHistoryByRetailerId(int retailerId)
|
|
|
54 |
throws ProfitMandiBusinessException {
|
|
|
55 |
UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
|
|
|
56 |
return userWalletHistoryRepository.selectByWalletId(userWallet.getId());
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
@Override
|
|
|
60 |
public long getSizeByRetailerId(int retailerId, LocalDateTime startDateTime, LocalDateTime endDateTime) throws ProfitMandiBusinessException{
|
|
|
61 |
UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
|
|
|
62 |
return userWalletHistoryRepository.selectCountByWalletId(userWallet.getId(), startDateTime, endDateTime);
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
@Override
|
|
|
66 |
public List<UserWalletHistory> getPaginatedUserWalletHistoryByRetailerId(int retailerId,
|
|
|
67 |
LocalDateTime startDateTime, LocalDateTime endDateTime, int offset, int limit)
|
|
|
68 |
throws ProfitMandiBusinessException {
|
|
|
69 |
UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
|
|
|
70 |
return userWalletHistoryRepository.selectPaginatedByWalletId(userWallet.getId(), startDateTime, endDateTime, offset, limit);
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
}
|