Subversion Repositories SmartDukaan

Rev

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

Rev 24990 Rev 25247
Line 25... Line 25...
25
 
25
 
26
@Component
26
@Component
27
public class WalletServiceImpl implements WalletService {
27
public class WalletServiceImpl implements WalletService {
28
 
28
 
29
	private static final Logger LOGGER = LogManager.getLogger(WalletServiceImpl.class);
29
	private static final Logger LOGGER = LogManager.getLogger(WalletServiceImpl.class);
-
 
30
	
-
 
31
	private boolean underMaintainance = true;
-
 
32
	ProfitMandiBusinessException pbse = new ProfitMandiBusinessException("Wallet", "Wallet", "Wallet is under maintainance, please try after some time");
30
 
33
 
31
	@Autowired
34
	@Autowired
32
	private UserAccountRepository userAccountRepository;
35
	private UserAccountRepository userAccountRepository;
33
 
36
 
34
	@Autowired
37
	@Autowired
Line 38... Line 41...
38
	private UserWalletHistoryRepository userWalletHistoryRepository;
41
	private UserWalletHistoryRepository userWalletHistoryRepository;
39
 
42
 
40
	@Override
43
	@Override
41
	public void addAmountToWallet(int retailerId, int referenceId, WalletReferenceType referenceType,
44
	public void addAmountToWallet(int retailerId, int referenceId, WalletReferenceType referenceType,
42
			String description, float amount) throws ProfitMandiBusinessException {
45
			String description, float amount) throws ProfitMandiBusinessException {
-
 
46
		if(underMaintainance) {
-
 
47
			throw pbse;
-
 
48
		}
43
		if (amount == 0)
49
		if (amount == 0)
44
			return;
50
			return;
45
		UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
51
		UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
46
		userWallet.setAmount(userWallet.getAmount() + Math.round(amount));
52
		userWallet.setAmount(userWallet.getAmount() + Math.round(amount));
47
		userWalletRepository.persist(userWallet);
53
		userWalletRepository.persist(userWallet);
Line 49... Line 55...
49
	}
55
	}
50
 
56
 
51
	@Override
57
	@Override
52
	public void consumeAmountFromWallet(int retailerId, int referenceId, WalletReferenceType referenceType,
58
	public void consumeAmountFromWallet(int retailerId, int referenceId, WalletReferenceType referenceType,
53
			String description, float amount) throws ProfitMandiBusinessException {
59
			String description, float amount) throws ProfitMandiBusinessException {
-
 
60
		if(underMaintainance) {
-
 
61
			throw pbse;
-
 
62
		}
54
		if (amount == 0)
63
		if (amount == 0)
55
			return;
64
			return;
56
		UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
65
		UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
57
		if (amount > userWallet.getAmount()) {
66
		if (amount > userWallet.getAmount()) {
58
			LOGGER.error("Wallet Balance is insufficient!");
67
			LOGGER.error("Wallet Balance is insufficient!");
Line 64... Line 73...
64
	}
73
	}
65
 
74
 
66
	@Override
75
	@Override
67
	public void rollbackAmountFromWallet(int retailerId, float amountToRollback, int rollbackReference,
76
	public void rollbackAmountFromWallet(int retailerId, float amountToRollback, int rollbackReference,
68
			WalletReferenceType walletReferenceType, String rollbackReason) {
77
			WalletReferenceType walletReferenceType, String rollbackReason) {
-
 
78
		
69
		if (amountToRollback == 0)
79
		if (amountToRollback == 0)
70
			return;
80
			return;
71
		UserWallet userWallet = this.getUserWallet(retailerId);
81
		UserWallet userWallet = this.getUserWallet(retailerId);
72
		userWallet.setAmount(userWallet.getAmount() - Math.round(amountToRollback));
82
		userWallet.setAmount(userWallet.getAmount() - Math.round(amountToRollback));
73
		userWalletRepository.persist(userWallet);
83
		userWalletRepository.persist(userWallet);
Line 90... Line 100...
90
		userWalletHistoryRepository.persist(userWalletHistory);
100
		userWalletHistoryRepository.persist(userWalletHistory);
91
	}
101
	}
92
 
102
 
93
	@Override
103
	@Override
94
	public UserWallet getUserWalletByUserId(int userId) throws ProfitMandiBusinessException {
104
	public UserWallet getUserWalletByUserId(int userId) throws ProfitMandiBusinessException {
-
 
105
		if(underMaintainance) {
-
 
106
			throw pbse;
-
 
107
		}
95
		UserAccount userAccount = userAccountRepository.selectByUserIdType(userId, AccountType.saholic);
108
		UserAccount userAccount = userAccountRepository.selectByUserIdType(userId, AccountType.saholic);
96
		return userWalletRepository.selectByRetailerId(Integer.valueOf(userAccount.getAccountKey()));
109
		return userWalletRepository.selectByRetailerId(Integer.valueOf(userAccount.getAccountKey()));
97
	}
110
	}
98
 
111
 
99
	@Override
112
	@Override
100
	public List<UserWalletHistory> getUserWalletHistoryByUserId(int userId) throws ProfitMandiBusinessException {
113
	public List<UserWalletHistory> getUserWalletHistoryByUserId(int userId) throws ProfitMandiBusinessException {
-
 
114
		if(underMaintainance) {
-
 
115
			throw pbse;
-
 
116
		}
101
		UserWallet userWallet = this.getUserWalletByUserId(userId);
117
		UserWallet userWallet = this.getUserWalletByUserId(userId);
102
		List<UserWalletHistory> userWalletHistories = userWalletHistoryRepository.selectByWalletId(userWallet.getId());
118
		List<UserWalletHistory> userWalletHistories = userWalletHistoryRepository.selectByWalletId(userWallet.getId());
103
		return userWalletHistories;
119
		return userWalletHistories;
104
	}
120
	}
105
 
121
 
106
	@Override
122
	@Override
107
	public List<UserWalletHistory> getUserWalletHistoryByRetailerId(int retailerId)
123
	public List<UserWalletHistory> getUserWalletHistoryByRetailerId(int retailerId)
108
			throws ProfitMandiBusinessException {
124
			throws ProfitMandiBusinessException {
-
 
125
		if(underMaintainance) {
-
 
126
			throw pbse;
-
 
127
		}
109
		UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
128
		UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
110
		return userWalletHistoryRepository.selectByWalletId(userWallet.getId());
129
		return userWalletHistoryRepository.selectByWalletId(userWallet.getId());
111
	}
130
	}
112
 
131
 
113
	@Override
132
	@Override
114
	public long getSizeByRetailerId(int retailerId, LocalDateTime startDateTime, LocalDateTime endDateTime)
133
	public long getSizeByRetailerId(int retailerId, LocalDateTime startDateTime, LocalDateTime endDateTime)
115
			throws ProfitMandiBusinessException {
134
			throws ProfitMandiBusinessException {
-
 
135
		if(underMaintainance) {
-
 
136
			throw pbse;
-
 
137
		}
116
		UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
138
		UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
117
		return userWalletHistoryRepository.selectCountByWalletId(userWallet.getId(), startDateTime, endDateTime);
139
		return userWalletHistoryRepository.selectCountByWalletId(userWallet.getId(), startDateTime, endDateTime);
118
	}
140
	}
119
 
141
 
120
	@Override
142
	@Override
121
	public List<UserWalletHistory> getPaginatedUserWalletHistoryByRetailerId(int retailerId,
143
	public List<UserWalletHistory> getPaginatedUserWalletHistoryByRetailerId(int retailerId,
122
			LocalDateTime startDateTime, LocalDateTime endDateTime, int offset, int limit)
144
			LocalDateTime startDateTime, LocalDateTime endDateTime, int offset, int limit)
123
			throws ProfitMandiBusinessException {
145
			throws ProfitMandiBusinessException {
-
 
146
		if(underMaintainance) {
-
 
147
			throw pbse;
-
 
148
		}
124
		UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
149
		UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
125
		return userWalletHistoryRepository.selectPaginatedByWalletId(userWallet.getId(), startDateTime, endDateTime,
150
		return userWalletHistoryRepository.selectPaginatedByWalletId(userWallet.getId(), startDateTime, endDateTime,
126
				offset, limit);
151
				offset, limit);
127
	}
152
	}
128
 
153
 
Line 137... Line 162...
137
	}
162
	}
138
 
163
 
139
	@Override
164
	@Override
140
	public boolean isExistWalletHistory(int retailerId, int referenceId, WalletReferenceType referenceType)
165
	public boolean isExistWalletHistory(int retailerId, int referenceId, WalletReferenceType referenceType)
141
			throws ProfitMandiBusinessException {
166
			throws ProfitMandiBusinessException {
-
 
167
		if(underMaintainance) {
-
 
168
			throw pbse;
-
 
169
		}
142
		UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
170
		UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
143
		return userWalletHistoryRepository.isExist(userWallet.getId(), referenceType, referenceId);
171
		return userWalletHistoryRepository.isExist(userWallet.getId(), referenceType, referenceId);
144
	}
172
	}
145
 
173
 
146
	@Override
174
	@Override