| Line 12... |
Line 12... |
| 12 |
import org.springframework.stereotype.Component;
|
12 |
import org.springframework.stereotype.Component;
|
| 13 |
|
13 |
|
| 14 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
14 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 15 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
15 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 16 |
import com.spice.profitmandi.dao.entity.dtr.UserAccount;
|
16 |
import com.spice.profitmandi.dao.entity.dtr.UserAccount;
|
| - |
|
17 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 17 |
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
|
18 |
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
|
| 18 |
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
|
19 |
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
|
| 19 |
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
|
20 |
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
|
| - |
|
21 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 20 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
22 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
| 21 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletHistoryRepository;
|
23 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletHistoryRepository;
|
| 22 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
|
24 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
|
| 23 |
|
25 |
|
| 24 |
import in.shop2020.model.v1.order.WalletReferenceType;
|
26 |
import in.shop2020.model.v1.order.WalletReferenceType;
|
| Line 37... |
Line 39... |
| 37 |
|
39 |
|
| 38 |
@Autowired
|
40 |
@Autowired
|
| 39 |
private UserWalletRepository userWalletRepository;
|
41 |
private UserWalletRepository userWalletRepository;
|
| 40 |
|
42 |
|
| 41 |
@Autowired
|
43 |
@Autowired
|
| - |
|
44 |
private FofoStoreRepository fofoStoreRepository;
|
| - |
|
45 |
|
| - |
|
46 |
@Autowired
|
| 42 |
private UserWalletHistoryRepository userWalletHistoryRepository;
|
47 |
private UserWalletHistoryRepository userWalletHistoryRepository;
|
| 43 |
|
48 |
|
| 44 |
@Override
|
49 |
@Override
|
| 45 |
public void addAmountToWallet(int retailerId, int referenceId, WalletReferenceType referenceType,
|
50 |
public void addAmountToWallet(int retailerId, int referenceId, WalletReferenceType referenceType,
|
| 46 |
String description, float amount) throws ProfitMandiBusinessException {
|
51 |
String description, float amount) throws ProfitMandiBusinessException {
|
| Line 54... |
Line 59... |
| 54 |
}
|
59 |
}
|
| 55 |
|
60 |
|
| 56 |
@Override
|
61 |
@Override
|
| 57 |
public void consumeAmountFromWallet(int retailerId, int referenceId, WalletReferenceType referenceType,
|
62 |
public void consumeAmountFromWallet(int retailerId, int referenceId, WalletReferenceType referenceType,
|
| 58 |
String description, float amount) throws ProfitMandiBusinessException {
|
63 |
String description, float amount) throws ProfitMandiBusinessException {
|
| 59 |
if (underMaintainance && referenceType.equals(WalletReferenceType.PURCHASE)) {
|
64 |
if ((underMaintainance && referenceType.equals(WalletReferenceType.PURCHASE) || !isActive(retailerId))) {
|
| 60 |
throw pbse;
|
65 |
throw pbse;
|
| 61 |
}
|
66 |
}
|
| 62 |
if (amount == 0)
|
67 |
if (amount == 0)
|
| 63 |
return;
|
68 |
return;
|
| 64 |
UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
|
69 |
UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
|
| Line 101... |
Line 106... |
| 101 |
userWalletHistoryRepository.persist(userWalletHistory);
|
106 |
userWalletHistoryRepository.persist(userWalletHistory);
|
| 102 |
}
|
107 |
}
|
| 103 |
|
108 |
|
| 104 |
@Override
|
109 |
@Override
|
| 105 |
public UserWallet getUserWalletByUserId(int userId) throws ProfitMandiBusinessException {
|
110 |
public UserWallet getUserWalletByUserId(int userId) throws ProfitMandiBusinessException {
|
| - |
|
111 |
UserAccount userAccount = userAccountRepository.selectByUserIdType(userId, AccountType.saholic);
|
| - |
|
112 |
|
| 106 |
if (underMaintainance) {
|
113 |
if (underMaintainance || !isActive(userAccount.getAccountKey())) {
|
| 107 |
throw pbse;
|
114 |
throw pbse;
|
| 108 |
}
|
115 |
}
|
| 109 |
UserAccount userAccount = userAccountRepository.selectByUserIdType(userId, AccountType.saholic);
|
- |
|
| 110 |
return userWalletRepository.selectByRetailerId(Integer.valueOf(userAccount.getAccountKey()));
|
116 |
return userWalletRepository.selectByRetailerId(Integer.valueOf(userAccount.getAccountKey()));
|
| 111 |
}
|
117 |
}
|
| 112 |
|
118 |
|
| 113 |
@Override
|
119 |
@Override
|
| 114 |
public List<UserWalletHistory> getUserWalletHistoryByUserId(int userId) throws ProfitMandiBusinessException {
|
120 |
public List<UserWalletHistory> getUserWalletHistoryByUserId(int userId) throws ProfitMandiBusinessException {
|
| 115 |
if (underMaintainance) {
|
121 |
if (underMaintainance || !isActive(userId)) {
|
| 116 |
throw pbse;
|
122 |
throw pbse;
|
| 117 |
}
|
123 |
}
|
| 118 |
UserWallet userWallet = this.getUserWalletByUserId(userId);
|
124 |
UserWallet userWallet = this.getUserWalletByUserId(userId);
|
| 119 |
List<UserWalletHistory> userWalletHistories = userWalletHistoryRepository.selectByWalletId(userWallet.getId());
|
125 |
List<UserWalletHistory> userWalletHistories = userWalletHistoryRepository.selectByWalletId(userWallet.getId());
|
| 120 |
return userWalletHistories;
|
126 |
return userWalletHistories;
|
| 121 |
}
|
127 |
}
|
| 122 |
|
128 |
|
| - |
|
129 |
private boolean isActive(int userId) {
|
| - |
|
130 |
boolean active = true;
|
| - |
|
131 |
try {
|
| - |
|
132 |
FofoStore fs = fofoStoreRepository.selectByRetailerId(userId);
|
| - |
|
133 |
active = fs.isActive();
|
| - |
|
134 |
} catch (Exception e) {
|
| - |
|
135 |
|
| - |
|
136 |
}
|
| - |
|
137 |
return active;
|
| - |
|
138 |
}
|
| - |
|
139 |
|
| 123 |
@Override
|
140 |
@Override
|
| 124 |
public List<UserWalletHistory> getUserWalletHistoryByRetailerId(int retailerId)
|
141 |
public List<UserWalletHistory> getUserWalletHistoryByRetailerId(int retailerId)
|
| 125 |
throws ProfitMandiBusinessException {
|
142 |
throws ProfitMandiBusinessException {
|
| 126 |
if (underMaintainance) {
|
143 |
if (underMaintainance || !isActive(retailerId)) {
|
| 127 |
throw pbse;
|
144 |
throw pbse;
|
| 128 |
}
|
145 |
}
|
| 129 |
UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
|
146 |
UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
|
| 130 |
return userWalletHistoryRepository.selectByWalletId(userWallet.getId());
|
147 |
return userWalletHistoryRepository.selectByWalletId(userWallet.getId());
|
| 131 |
}
|
148 |
}
|
| Line 142... |
Line 159... |
| 142 |
|
159 |
|
| 143 |
@Override
|
160 |
@Override
|
| 144 |
public List<UserWalletHistory> getPaginatedUserWalletHistoryByRetailerId(int retailerId,
|
161 |
public List<UserWalletHistory> getPaginatedUserWalletHistoryByRetailerId(int retailerId,
|
| 145 |
LocalDateTime startDateTime, LocalDateTime endDateTime, int offset, int limit)
|
162 |
LocalDateTime startDateTime, LocalDateTime endDateTime, int offset, int limit)
|
| 146 |
throws ProfitMandiBusinessException {
|
163 |
throws ProfitMandiBusinessException {
|
| 147 |
if (underMaintainance) {
|
164 |
if (underMaintainance || !isActive(retailerId)) {
|
| 148 |
throw pbse;
|
165 |
throw pbse;
|
| 149 |
}
|
166 |
}
|
| 150 |
UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
|
167 |
UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
|
| 151 |
return userWalletHistoryRepository.selectPaginatedByWalletId(userWallet.getId(), startDateTime, endDateTime,
|
168 |
return userWalletHistoryRepository.selectPaginatedByWalletId(userWallet.getId(), startDateTime, endDateTime,
|
| 152 |
offset, limit);
|
169 |
offset, limit);
|
| Line 163... |
Line 180... |
| 163 |
}
|
180 |
}
|
| 164 |
|
181 |
|
| 165 |
@Override
|
182 |
@Override
|
| 166 |
public boolean isExistWalletHistory(int retailerId, int referenceId, WalletReferenceType referenceType)
|
183 |
public boolean isExistWalletHistory(int retailerId, int referenceId, WalletReferenceType referenceType)
|
| 167 |
throws ProfitMandiBusinessException {
|
184 |
throws ProfitMandiBusinessException {
|
| 168 |
if (underMaintainance) {
|
185 |
if (underMaintainance || !isActive(retailerId)) {
|
| 169 |
throw pbse;
|
186 |
throw pbse;
|
| 170 |
}
|
187 |
}
|
| 171 |
UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
|
188 |
UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
|
| 172 |
return userWalletHistoryRepository.isExist(userWallet.getId(), referenceType, referenceId);
|
189 |
return userWalletHistoryRepository.isExist(userWallet.getId(), referenceType, referenceId);
|
| 173 |
}
|
190 |
}
|