📄 accountaction.java
字号:
/**
* Created by szmx.
* User: hliu
* Date: 2006-4-7
* Time: 9:30:41
* To change this template use File | Settings | File Templates.
*/
package com.szmx.tlms.finance.web;
import com.szmx.framework.base.web.BaseAction;
import com.szmx.framework.base.model.Pagination;
import com.szmx.tlms.finance.service.AccountService;
import com.szmx.tlms.finance.service.FixedAssetsService;
import com.szmx.tlms.finance.model.Account;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.DynaActionForm;
import org.apache.struts.util.MessageResources;
import org.springframework.dao.DataIntegrityViolationException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;
import java.util.HashMap;
/**
* This clas is for Account config.
*/
public class AccountAction extends BaseAction {
/**
* @param mapping
* @param form
* @param request
* @param response
* @return
* @throws Exception
*/
public ActionForward searchAccount(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
if (log.isDebugEnabled()) {
log.debug("Entering 'searchAccount' method");
}
DynaActionForm dynaForm = (DynaActionForm) form;
Map paraMap = new HashMap();
paraMap.put("searchBean", dynaForm.get("searchBean"));
Pagination pageObj = new Pagination(request, "pagination");
AccountService mgr = (AccountService) getBean("accountService");
//test
FixedAssetsService fixedAssetsService=(FixedAssetsService)getBean("fixedAssetsService");
fixedAssetsService.depricationFixedAssets();
Pagination pagination = mgr.getAccounts(pageObj, paraMap);
request.setAttribute("pagination", pagination);
return mapping.findForward("success");
}
public ActionForward initUpdateAccount(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
if (log.isDebugEnabled()) {
log.debug("Entering 'initUpdateEmployee' method");
}
DynaActionForm dynaForm = (DynaActionForm) form;
Account account = (Account) dynaForm.get("accountBean");
AccountService service = (AccountService) getBean("accountService");
try {
account = service.getAccount(account.getId());
} catch (Exception e) {
saveActionErrorMessage(request, "err.admin.employee.get.noExisted", null);
return mapping.findForward("failure");
}
request.setAttribute("accountBean", account);
return mapping.findForward("success");
}
public ActionForward updateAccount(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
if (log.isDebugEnabled()) {
log.debug("Entering 'addAccount' method");
}
DynaActionForm dynaForm = (DynaActionForm) form;
Account account = (Account) dynaForm.get("accountBean");
account.setCompanyId(new Long(1)); //todo bryan: get the company from session
account.populateUpdateBean(new Long(1));//todo bryan: get the user id form session
AccountService accountService = (AccountService) getBean("accountService");
//Get the previous account by the Id.
Account preAccount=accountService.getAccount(account.getId());
//when update a account ,if the Sap code is changed,
//make sure the changed Sap code is not existed in the DateBase.
if (preAccount.getSapAccountCode() != null && !preAccount.getSapAccountCode().equals(account.getSapAccountCode()))
{
//Check if the SAP code is existed in the database.
if (accountService.getAccountsBySAPCode(account) != null && accountService.getAccountsBySAPCode(account).size() != 0)
{ //If so ,return the error message.
request.setAttribute("accountBean", account);
saveActionErrorMessage(request, "error.finance.account.add.dupilcateRecord", null);
}
}
try {
//save the Account obj by accountService
accountService.save(account);
dynaForm.set("accountBean", account);
request.setAttribute("accountBean", account);
} catch (Exception e) {
request.setAttribute("accountBean", account);
saveActionErrorMessage(request,
"error.finance.update.failure",
new String[]{MessageResources.getMessageResources("ApplicationMessages-finance").getMessage("label.account.name")});
//todo bryan: write a method to get the message from source file
return mapping.findForward("failure");
}
saveActionTripMessage(request,
"message.finance.update.success",
new String[]{MessageResources.getMessageResources("ApplicationMessages-finance").getMessage("label.account.name")});
return mapping.findForward("success");
}
public ActionForward initAddAccount(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
if (log.isDebugEnabled()) {
log.debug("Entering 'initAddAccount' method");
}
Account account = new Account();
//Make sure that the textfield on the page is null
request.setAttribute("accountBean", account);
return mapping.findForward("success");
}
public ActionForward removeAccount(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
if (log.isDebugEnabled()) {
log.debug("Entering 'removeEmployee' method");
}
DynaActionForm dynaForm = (DynaActionForm) form;
String[] splitString = (String[]) dynaForm.get("idArr");
AccountService service = (AccountService) getBean("accountService");
try {
service.removeAll(splitString);
saveActionTripMessage(request,
"message.finance.delete.success",
new String[]{MessageResources.getMessageResources("ApplicationMessages-finance").getMessage("label.account.name")});
}
catch (DataIntegrityViolationException e) {
saveActionErrorMessage(request,
"error.finance.delete.failure.useredByOthers", null);
return mapping.findForward("failure");
}
catch (Exception e) {
log.debug(e);
saveActionTripMessage(request,
"error.finance.delete.failure",
new String[]{MessageResources.getMessageResources("ApplicationMessages-finance").getMessage("label.account.name")});
return mapping.findForward("failure");
}
return mapping.findForward("success");
}
public ActionForward addAccount(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
if (log.isDebugEnabled()) {
log.debug("Entering 'addAccount' method");
}
DynaActionForm dynaForm = (DynaActionForm) form;
Account account = (Account) dynaForm.get("accountBean");
//IF the LocalAccountCode level 2 is null,copy the LocalAccountCode level 1's value to it
if (account.getLocalAccountCode2().trim().equals("")) {
account.setLocalAccountCode2(account.getSapAccountCode());
}
account.setCompanyId(new Long(1)); //todo bryan: get the company from session
account.populateCreateBean(new Long(1));//todo bryan: get the user id form session
AccountService accountService = (AccountService) getBean("accountService");
try {
//Test if the SAP code has been used in the local system.
if (accountService.getAccountsBySAPCode(account) != null && accountService.getAccountsBySAPCode(account).size() != 0) {
request.setAttribute("accountBean", account);
saveActionErrorMessage(request, "error.finance.account.add.dupilcateRecord", null);
return mapping.findForward("failure");
}
//IF the SAP CODE not used ,save the record.
accountService.save(account);
dynaForm.set("accountBean", account);
request.setAttribute("accountBean", account);
} catch (Exception e) {
request.setAttribute("accountBean", account);
saveActionErrorMessage(request, "error.finance.add.failure", new String[]{MessageResources.getMessageResources("ApplicationMessages-finance").getMessage("label.account.name")});
e.printStackTrace();//Todo bryan: This will write into the Log file.
return mapping.findForward("failure");
}
saveActionTripMessage(request, "message.finance.add.success", new String[]{MessageResources.getMessageResources("ApplicationMessages-finance").getMessage("label.account.name")});
return mapping.findForward("success");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -