content: package com.cy.service.impl;
  
  import java.util.List;
  
  import org.springframework.transaction.annotation.Transactional;
  
  import com.cy.dao.interfaces.TransactionDaoInter;
  import com.cy.dao.interfaces.UserDaoInter;
  import com.cy.entity.Account;
  import com.cy.entity.Pager;
  import com.cy.entity.TransactionLog;
  import com.cy.entity.TransactionType;
  import com.cy.service.interfaces.TransactionServiceInter;
  
  @Transactional
  public class TransactionServiceImpl implements TransactionServiceInter {
  
  	private TransactionDaoInter transactionDaoInter;
  	private UserDaoInter userDaoInter;
  	public void setTransactionDaoInter(TransactionDaoInter transactionDaoInter) {
  		this.transactionDaoInter = transactionDaoInter;
  	}
  	public void setUserDaoInter(UserDaoInter userDaoInter) {
  		this.userDaoInter = userDaoInter;
  	}
  	//
  	@Override
  	public boolean deposit(TransactionLog log) {
  		//ӽ׶logлȡ˻
          Account self = log.getAccount();
          //˻  
          //ʹlog.getTr_money()ԻȡĴԭǷװTransactionʵactionձ
          self.setBalance(log.getTr_money()+log.getAccount().getBalance());
          //˻޸
          userDaoInter.updateAccount(self);
          //ݽͻȡ׶
          TransactionType type = transactionDaoInter.getTranactionType("");
          log.setTransactionType(type);
          log.setOtherid(self.getAccountid());
          log.setDatetime(log.getDatetime());
  		//ýӿеaddlogtransaction_logӽ׼¼
          return transactionDaoInter.addLog(log);
  	}
  	//ȡ
  	@Override
  	public boolean withdraw(TransactionLog log) {
  		//ӽ׶logлȡ˻
  		Account self = log.getAccount();
  		 //˻  
          //ʹlog.getTr_money()ԻȡĴԭǷװTransactionʵactionձ
  		self.setBalance(log.getAccount().getBalance()-log.getTr_money());
          //˻޸
  		userDaoInter.updateAccount(self);
          //ݽͻȡ׶
  		TransactionType type = transactionDaoInter.getTranactionType("ȡ");
  		log.setTransactionType(type);
  		log.setOtherid(self.getAccountid());
  		log.setDatetime(log.getDatetime());
  		//ýӿеaddlogtransaction_logӽ׼¼
  		return transactionDaoInter.addLog(log);
  	}
  	//ת
  	@Override
  	public boolean transfer(TransactionLog log) {
  		//ȡԷ˻
  		Account other = userDaoInter.getAccount(log.getOtherid());
          //ȡԼ˻		
  		Account self = log.getAccount();
  		if(other!=null) {
  			//޸ĶԷ˻
  			other.setBalance(other.getBalance()+log.getTr_money());
  			//޸Լ˻
  			self.setBalance(self.getBalance()-log.getTr_money());
  			//¶ԷԼ˻
  			userDaoInter.updateAccount(other);
  			userDaoInter.updateAccount(self);
  			//ݽͻȡ׶
  			TransactionType type = transactionDaoInter.getTranactionType("ת");
  			log.setTransactionType(type);
  			log.setOtherid(log.getOtherid());
  			log.setDatetime(log.getDatetime());
  			//transaction_logӽ׼¼
  			return transactionDaoInter.addLog(log);
  		}
  		return false;
  	}
  	
  	@Override
  	//ȡ׼¼
  	public List getLogs(Account account, int page) {
  		return transactionDaoInter.getLogs(account, page);
  	}
  	@Override
  	//˻Ľ׼¼ʼҳPager
  	//perPagerRowsrowCount
  	public Pager getPagerOfLogs(Account account) {
  		//ӱTransaction_Logлȡ˻صĽ׼¼
  		int count = transactionDaoInter.getCountOfLogs(account);
  		//
  		Pager pager = new Pager();
  		//pagerPerPageRowsԣʾÿҳʾ10¼
  		pager.setPerPageRows(5);
  		//rowCountԣʾ¼
  		pager.setRowCount(count);
  		return pager;
  	}
  }
  