Subversion Repositories SmartDukaan

Rev

Rev 22730 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
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);
33
		return userWalletRepository.selectByRetailerId(Integer.valueOf(userAccount.getAccount_key()));
34
	}
35
 
36
	@Override
37
	public List<UserWalletHistory> getUserWalletHistoryByUserId(int userId) throws ProfitMandiBusinessException {
38
		UserWallet userWallet = this.getUserWalletByUserId(userId);
39
		List<UserWalletHistory> userWalletHistories = userWalletHistoryRepository.selectByWalletId(userWallet.getId());
40
		return userWalletHistories;
41
	}
42
 
43
	@Override
44
	public List<UserWalletHistory> getUserWalletHistoryByRetailerId(int retailerId)
45
			throws ProfitMandiBusinessException {
46
		UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
47
		return userWalletHistoryRepository.selectByWalletId(userWallet.getId());
48
	}
49
 
50
	@Override
51
	public long getSizeByRetailerId(int retailerId, LocalDateTime startDateTime, LocalDateTime endDateTime) throws ProfitMandiBusinessException{
52
		UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
53
		return userWalletHistoryRepository.selectCountByWalletId(userWallet.getId(), startDateTime, endDateTime);
54
	}
55
 
56
	@Override
57
	public List<UserWalletHistory> getPaginatedUserWalletHistoryByRetailerId(int retailerId,
58
			LocalDateTime startDateTime, LocalDateTime endDateTime, int offset, int limit)
59
			throws ProfitMandiBusinessException {
60
		UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
61
		return userWalletHistoryRepository.selectPaginatedByWalletId(userWallet.getId(), startDateTime, endDateTime, offset, limit);
62
	}
63
 
64
}