📄 fundaccountaction.java
字号:
package com.fund.client;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForward;
import com.fund.SuperAction;
import com.fund.fund.FundDelegate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import com.fund.fund.FundDto;
import com.fund.sales.SalesDto;
import org.apache.struts.action.DynaActionForm;
/**
*
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2005</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class FundAccountAction extends SuperAction {
/**
* fundAccountDelegate
*/
private FundAccountDelegate fundAccountDelegate = null;
/**
* financialAccountDelegate
*/
private FinancialAccountDelegate financialAccountDelegate = null;
/**
* fundDelegate
*/
private FundDelegate fundDelegate = null;
/**
* FundAccountAction
* @throws Exception e
*/
public FundAccountAction() throws Exception {
super();
fundAccountDelegate = new FundAccountDelegate();
financialAccountDelegate = new FinancialAccountDelegate();
fundDelegate = new FundDelegate();
}
/**
* doExecute
* @param mapping ActionMapping
* @param form ActionForm
* @param request HttpServletRequest
* @param response HttpServletResponse
* @return ActionForward
*/
public ActionForward doExecute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
String parameter = mapping.getParameter();
System.out.println("MAPPING PARAM in fund:" + parameter);
if (parameter.equals("buy")) {
return buy(mapping, form, request, response);
} else if (parameter.equals("ransom")) {
return ransom(mapping, form, request, response);
} else if (parameter.equals("view")) {
return view(mapping, form, request, response);
} else if (parameter.equals("fundList")) {
return getFundList(mapping, form, request, response);
} else { //if(parameter.equals("view"))
return null;
}
}
/**
* buy
* @param mapping ActionMapping
* @param form ActionForm
* @param request HttpServletRequest
* @param response HttpServletResponse
* @return ActionForward
*/
private ActionForward buy(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
String target = "success";
FundAccountForm fundAccountForm = (FundAccountForm) form;
FundAccountDto fundAccountDto = fundAccountForm.getFundAccountDto();
String password = (String) request.getParameter("password");
try {
FinancialAccountDto financingAccountDto = null;
try {
financingAccountDto =
financialAccountDelegate.
financialAccountFindByPrimaryKey(
fundAccountDto.getFinancialAccNo());
} catch (Exception ex) {
throw new Exception("financialAccount.invalid");
}
if (!financingAccountDto.getPassword().equals(password)) {
throw new Exception("financialAccount.password.invalid");
}
if (!financingAccountDto.getStatus().equals("正常")) {
throw new Exception("financialAccount.status.freeze");
}
if (financingAccountDto.getFinancingAmount().doubleValue()
< (fundAccountDto.getTotalPrice().doubleValue() * 1.01)) {
throw new Exception("financingAmount.insufficient");
}
financingAccountDto.setFinancingAmount(new Double(
financingAccountDto.getFinancingAmount().doubleValue()
- (fundAccountDto.getTotalPrice().doubleValue() * 1.01)));
financialAccountDelegate.updateFinancialAccount(
financingAccountDto);
Integer fundAccountNo = fundAccountDelegate.createFundAccount(
fundAccountDto);
saveSuperErrors(request, "fund.add.successful",
String.valueOf(fundAccountNo));
SalesDto sdto = (SalesDto) request.getSession().getAttribute(
"salesDto");
log.info(fundAccountDto.logData(
"FUND PRODUCT BOUGHT by sales having sales no="
+ sdto.getSalesNo()));
} catch (Exception e) {
System.out.println(" Error in buy " + e.getMessage());
target = "failure";
saveSuperErrors(request, e.getMessage());
}
return mapping.findForward(target);
}
/**
* getFundList
* @param mapping ActionMapping
* @param form ActionForm
* @param request HttpServletRequest
* @param response HttpServletResponse
* @return ActionForward
*/
private ActionForward getFundList(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
List fundList = new ArrayList();
FundAccountForm fundAccountActionForm = (FundAccountForm) form;
try {
fundList = Arrays.asList(fundDelegate.fundFindGetNormallFunds());
if (fundAccountActionForm.getFundAccountDto().getFundNo() != null) {
FundDto fundDto = fundDelegate.fundFindByPrimaryKey(
fundAccountActionForm.getFundAccountDto().getFundNo());
fundAccountActionForm.getFundAccountDto().setPrice(fundDto.
getCurrentPrice());
}
request.setAttribute("fundList", fundList);
} catch (Exception e) {
e.printStackTrace();
}
return mapping.findForward("success");
}
/**
* ransom
* @param mapping ActionMapping
* @param form ActionForm
* @param request HttpServletRequest
* @param response HttpServletResponse
* @return ActionForward
*/
private ActionForward ransom(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
String target = "success";
FundAccountForm fundAccountForm = (FundAccountForm) form;
FundAccountDto fundAccountDto = fundAccountForm.getFundAccountDto();
String password = (String) request.getParameter("password");
FundAccountDto fundAccountDto2 = null;
try {
try {
fundAccountDto2 = fundAccountDelegate.
fundAccountFindByPrimaryKey(
fundAccountDto.getFundAccNo());
} catch (Exception e) {
throw new Exception("fundAccount.invalid");
}
System.out.println("fund account no:"
+ fundAccountDto.getFundAccNo());
FinancialAccountDto financingAccountDto =
financialAccountDelegate.financialAccountFindByPrimaryKey(
fundAccountDto2.getFinancialAccNo());
if (!financingAccountDto.getPassword().equals(password)) {
throw new Exception("financialAccount.password.invalid");
}
if (!financingAccountDto.getStatus().equals("正常")) {
throw new Exception("financialAccount.accountfrozen");
}
FundDelegate fundDelegate = new FundDelegate();
FundDto fdto = fundDelegate.fundFindByPrimaryKey(fundAccountDto2.
getFundNo());
if (!fdto.getStatus().equalsIgnoreCase("上市")) {
throw new Exception("fund.status.invalid");
}
//boolean remove = false;
if (fundAccountDto2.getQuantity().intValue()
<
fundAccountDto.getQuantity().intValue()) {
throw new Exception("fundAccount.quantity.insufficient");
}
// Add to client financing account -> fund price with handling fees
financingAccountDto.setFinancingAmount(new Double(
financingAccountDto.getFinancingAmount().doubleValue()
+ (fundAccountDto2.getTotalPrice().doubleValue() * 0.99)));
// Subtract quantity
fundAccountDto2.setQuantity(new Integer(
fundAccountDto2.getQuantity().intValue()
- fundAccountDto.getQuantity().intValue()));
financialAccountDelegate.updateFinancialAccount(
financingAccountDto);
fundAccountDelegate.updateFundAccount(fundAccountDto2);
saveSuperErrors(request, "fund.ransom.successful");
// new change 9/27/2005
FundAccountDto fundAccountDto3 = fundAccountDelegate.
fundAccountFindByPrimaryKey(
fundAccountDto.getFundAccNo());
if (fundAccountDto3.getQuantity().intValue() == 0) {
fundAccountDelegate.removeFundAccount(fundAccountDto3);
}
SalesDto sdto = (SalesDto) request.getSession().getAttribute(
"salesDto");
log.info(fundAccountDto2.logData(
"FUND PRODUCT RANSOMED by sales having sales no="
+ sdto.getSalesNo()));
} catch (Exception e) {
target = "failure";
saveSuperErrors(request, e.getMessage());
}
return mapping.findForward(target);
}
/**
* view
* @param mapping ActionMapping
* @param form ActionForm
* @param request HttpServletRequest
* @param response HttpServletResponse
* @return ActionForward
*/
private ActionForward view(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
String target = "success";
DynaActionForm fundAccountSearchForm = (DynaActionForm) form;
Integer accountNo = (Integer) fundAccountSearchForm.get("accountNo");
FundAccountForm fundAccountForm = new FundAccountForm();
try {
FundAccountDto fundAccountDto = null;
try {
fundAccountDto = fundAccountDelegate.
fundAccountFindByPrimaryKey(
accountNo);
} catch (Exception ex) {
throw new Exception("fundAccount.accountNo.notFound");
}
FundDto fundDto = fundDelegate.fundFindByPrimaryKey(fundAccountDto.
getFundNo());
FinancialAccountDto financialAccountDto = financialAccountDelegate.
financialAccountFindByPrimaryKey(fundAccountDto.
getFinancialAccNo());
fundAccountForm.setFundAccountDto(fundAccountDto);
fundAccountForm.setFinancialAccountDto(financialAccountDto);
fundAccountForm.setFundDto(fundDto);
} catch (Exception e) {
target = "failure";
System.out.println(e.getMessage());
saveSuperErrors(request, e.getMessage());
}
request.setAttribute("fundAccountForm", fundAccountForm);
return mapping.findForward(target);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -