📄 processaccountaction.java
字号:
package com.ebusiness.ebank.action;import java.util.Locale;import java.util.List;import java.util.Iterator;import java.util.Date;import java.sql.Timestamp;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import javax.servlet.http.HttpSession;import org.apache.struts.action.Action;import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionForward;import org.apache.struts.action.ActionMapping;import org.apache.struts.action.ActionMessage;import org.apache.struts.action.ActionErrors;import org.apache.struts.action.ActionMessages;import org.apache.log4j.Logger;import org.apache.log4j.MDC;import org.apache.struts.Globals;import com.ebusiness.ebank.form.CardholderForm;import com.ebusiness.ebank.form.ProcessAccountForm;import com.ebusiness.ebank.servicedelegate.AccountAccessDelegate;import com.ebusiness.ebank.bean.AccountValue;import com.ebusiness.ebank.bean.StatementValue;import com.ebusiness.ebank.bean.ValueList;import com.ebusiness.ebank.security.Functions;import com.ebusiness.ebank.exception.BusinessException;import com.ebusiness.ebank.exception.SystemException;import com.ebusiness.ebank.util.Constants;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2005</p> * <p>Company: eBusiness Inc., All right reserved</p> * @author unascribed * @version 1.0 */public class ProcessAccountAction extends Action{ public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { Logger log = Logger.getLogger(this.getClass()); MDC.put("userid", request.getRemoteUser()); ActionErrors errors = new ActionErrors(); HttpSession session = request.getSession(false); Locale locale = (Locale)session.getAttribute(Globals.LOCALE_KEY); List aList = (List)session.getAttribute(Constants.ACCOUNT_LIST); String action = (String)request.getParameter(Constants.ACCOUNT_ACTION); CardholderForm cardDetails = (CardholderForm)session.getAttribute(Constants.CARDHOLDER_FORM); log.debug("Action: " + action); if (action != null && action.trim() != "") { if (aList == null) { try { aList = AccountAccessDelegate.searchAccount(cardDetails.getClientCardID()).getSearchResults(); session.setAttribute(Constants.ACCOUNT_LIST, aList); } catch (SystemException e) { log.error(e.getMessage(), e); return mapping.findForward("error"); } catch (BusinessException e) { errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("errors.businessException",e.getMessage(locale))); saveErrors(request,errors); return mapping.findForward("failure"); } } return mapping.findForward(action); } ProcessAccountForm accountForm = (ProcessAccountForm)form; action = accountForm.getAction(); log.debug(accountForm.toString()); // default forward String forward="failure"; if ("cancel".equalsIgnoreCase(action)) forward = "cancel"; else { try { AccountValue fromValue; AccountValue toValue; ValueList vList; if (Functions.ACCOUNT_TRANSFER.equals(action)) { fromValue = getAccountValue(aList, accountForm.getFromAccountNo()); toValue = getAccountValue(aList, accountForm.getToAccountNo()); vList = AccountAccessDelegate.transferMoney(fromValue, toValue, Double.parseDouble(accountForm.getAmount())); aList = vList.getSearchResults(); } else if (Functions.ACCOUNT_DEPOSIT.equals(action)) { toValue = getAccountValue(aList, accountForm.getToAccountNo()); log.debug(toValue.toString()); StatementValue sValue = new StatementValue(); sValue.setAccountNo(toValue.getAccountNo()); sValue.setAccountType(toValue.getAccountType()); sValue.setClientCardNo(toValue.getClientCardID()); sValue.setDescription("Web Deposit"); sValue.setDeposit(Double.parseDouble(accountForm.getAmount())); sValue.setBankingDate(new Timestamp(new Date().getTime())); AccountValue aValue = AccountAccessDelegate.deposit(sValue); replaceAccountValue(aList, aValue); } else if (Functions.ACCOUNT_WITHDRAWAL.equals(action)) { fromValue = getAccountValue(aList, accountForm.getFromAccountNo()); log.debug(fromValue.toString()); StatementValue sValue = new StatementValue(); sValue.setAccountNo(fromValue.getAccountNo()); sValue.setAccountType(fromValue.getAccountType()); sValue.setClientCardNo(fromValue.getClientCardID()); sValue.setDescription("Web Withdrawal"); sValue.setWithdrawal(Double.parseDouble(accountForm.getAmount())); sValue.setBankingDate(new Timestamp(new Date().getTime())); AccountValue aValue = AccountAccessDelegate.withdrawal(sValue); replaceAccountValue(aList, aValue); } session.setAttribute(Constants.ACCOUNT_LIST, aList); forward = "accountList"; } catch (SystemException e) { log.error(e.getMessage(),e) ; forward = "error" ; } catch (BusinessException e) { errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("errors.businessException",e.getMessage(locale))); saveErrors(request,errors); forward = "failure" ; } } if (!errors.isEmpty()) { saveErrors(request, errors); forward = "failure" ; } return mapping.findForward(forward); } //Help method to get Account from the account list stored in session object private AccountValue getAccountValue(List aList, String accountNo) throws Exception { AccountValue aValue = null; for (Iterator i = aList.iterator(); i.hasNext();) { aValue = (AccountValue)i.next(); if (aValue.getAccountNo().equals(accountNo)) break; } return aValue; } //Help method to replace the old accountValue from the list private void replaceAccountValue(List aList, AccountValue newValue) throws Exception { AccountValue aValue = null; for (Iterator i = aList.iterator(); i.hasNext();) { aValue = (AccountValue)i.next(); if (aValue.getAccountNo().equals(newValue.getAccountNo())) { aValue = newValue; break; } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -