| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.service.wallet;
|
1 |
package com.spice.profitmandi.service.wallet;
|
| 2 |
|
2 |
|
| 3 |
import java.time.LocalDateTime;
|
- |
|
| 4 |
import java.util.ArrayList;
|
- |
|
| 5 |
import java.util.HashMap;
|
- |
|
| 6 |
import java.util.List;
|
- |
|
| 7 |
import java.util.Map;
|
- |
|
| 8 |
import java.util.Set;
|
- |
|
| 9 |
import java.util.stream.Collectors;
|
- |
|
| 10 |
|
- |
|
| 11 |
import org.apache.logging.log4j.LogManager;
|
- |
|
| 12 |
import org.apache.logging.log4j.Logger;
|
- |
|
| 13 |
import org.springframework.beans.factory.annotation.Autowired;
|
- |
|
| 14 |
import org.springframework.stereotype.Component;
|
- |
|
| 15 |
|
- |
|
| 16 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
3 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| - |
|
4 |
import com.spice.profitmandi.common.util.FormattingUtils;
|
| 17 |
import com.spice.profitmandi.dao.entity.dtr.UserAccount;
|
5 |
import com.spice.profitmandi.dao.entity.dtr.UserAccount;
|
| 18 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
6 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 19 |
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
|
7 |
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
|
| 20 |
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
|
8 |
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
|
| 21 |
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
|
9 |
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
|
| 22 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
10 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 23 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
11 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
| 24 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletHistoryRepository;
|
12 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletHistoryRepository;
|
| 25 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
|
13 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
|
| 26 |
|
- |
|
| - |
|
14 |
import com.spice.profitmandi.service.NotificationService;
|
| 27 |
import in.shop2020.model.v1.order.WalletReferenceType;
|
15 |
import in.shop2020.model.v1.order.WalletReferenceType;
|
| - |
|
16 |
import org.apache.logging.log4j.LogManager;
|
| - |
|
17 |
import org.apache.logging.log4j.Logger;
|
| - |
|
18 |
import org.springframework.beans.factory.annotation.Autowired;
|
| - |
|
19 |
import org.springframework.stereotype.Component;
|
| - |
|
20 |
|
| - |
|
21 |
import java.time.LocalDateTime;
|
| - |
|
22 |
import java.util.*;
|
| - |
|
23 |
import java.util.stream.Collectors;
|
| 28 |
|
24 |
|
| 29 |
@Component
|
25 |
@Component
|
| 30 |
public class WalletServiceImpl implements WalletService {
|
26 |
public class WalletServiceImpl implements WalletService {
|
| 31 |
|
27 |
|
| 32 |
private static final Logger LOGGER = LogManager.getLogger(WalletServiceImpl.class);
|
28 |
private static final Logger LOGGER = LogManager.getLogger(WalletServiceImpl.class);
|
| Line 48... |
Line 44... |
| 48 |
private FofoStoreRepository fofoStoreRepository;
|
44 |
private FofoStoreRepository fofoStoreRepository;
|
| 49 |
|
45 |
|
| 50 |
@Autowired
|
46 |
@Autowired
|
| 51 |
private UserWalletHistoryRepository userWalletHistoryRepository;
|
47 |
private UserWalletHistoryRepository userWalletHistoryRepository;
|
| 52 |
|
48 |
|
| - |
|
49 |
@Autowired
|
| - |
|
50 |
private NotificationService notificationService;
|
| - |
|
51 |
|
| 53 |
@Override
|
52 |
@Override
|
| 54 |
public void addAmountToWallet(int retailerId, int referenceId, WalletReferenceType referenceType,
|
53 |
public void addAmountToWallet(int retailerId, int referenceId, WalletReferenceType referenceType,
|
| 55 |
String description, float amount, LocalDateTime businessTime) throws ProfitMandiBusinessException {
|
54 |
String description, float amount, LocalDateTime businessTime) throws ProfitMandiBusinessException {
|
| 56 |
if (amount == 0)
|
55 |
if (amount == 0)
|
| 57 |
return;
|
56 |
return;
|
| 58 |
UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
|
57 |
UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
|
| 59 |
int walletAmount = walletService.getWalletAmount(retailerId);
|
58 |
int walletAmount = walletService.getWalletAmount(retailerId);
|
| 60 |
// userWallet = userWalletRepository.selectByIdForUpdate(userWallet.getId());
|
59 |
// userWallet = userWalletRepository.selectByIdForUpdate(userWallet.getId());
|
| 61 |
userWallet.setAmount(walletAmount + Math.round(amount));
|
60 |
userWallet.setAmount(walletAmount + Math.round(amount));
|
| - |
|
61 |
notificationService.sendNotification(retailerId, "walletcredit", "Rs. " + FormattingUtils.formatDecimal(amount) + " credited in SD Wallet", description);
|
| 62 |
this.createUserWalletHistory(Math.round(amount), userWallet.getId(), referenceId, referenceType, description, businessTime);
|
62 |
this.createUserWalletHistory(Math.round(amount), userWallet.getId(), referenceId, referenceType, description, businessTime);
|
| 63 |
}
|
63 |
}
|
| 64 |
|
64 |
|
| 65 |
@Override
|
65 |
@Override
|
| 66 |
public void consumeAmountFromWallet(int retailerId, int referenceId, WalletReferenceType referenceType,
|
66 |
public void consumeAmountFromWallet(int retailerId, int referenceId, WalletReferenceType referenceType,
|