📄 clientaccountaction.java
字号:
package com.bluedot.bank.framework.web.action;
import org.apache.log4j.Logger;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import com.bluedot.bank.framework.dao.AccountDao;
import com.bluedot.bank.framework.dao.ClientDao;
import com.bluedot.bank.framework.dao.ExchangerecordDao;
import com.bluedot.bank.framework.dao.RolesDao;
import com.bluedot.bank.framework.dao.UsersDao;
import com.bluedot.bank.framework.web.actionform.AccountBean;
import com.bluedot.bank.framework.web.actionform.AmendValidatorForm;
import com.bluedot.bank.framework.web.actionform.AutoActionForm;
import com.bluedot.bank.framework.web.actionform.ClientAccountForm;
import com.bluedot.bank.framework.web.actionform.ClientBean;
import com.bluedot.bank.framework.web.actionform.ExchangerecordActionFrom;
import com.bluedot.bank.framework.web.actionform.ExchangerecordBean;
import com.bluedot.bank.framework.web.actionform.RoleQueryActionFrom;
import com.bluedot.bank.framework.web.actionform.RolesBean;
import com.bluedot.bank.framework.web.actionform.ShowClientActionForm;
import com.bluedot.bank.framework.web.actionform.TransferActionFrom;
import com.bluedot.bank.framework.web.actionform.UserLandingActionFrom;
import com.bluedot.bank.framework.web.actionform.UsersBean;
import com.bluedot.bank.framework.web.actionform.UsersLoadBean;
import com.bluedot.bank.framework.web.exception.RegisterException;
public class ClientAccountAction extends DispatchAction {
/**
* Logger for this class
*/
private static final Logger logger = Logger
.getLogger(ClientAccountAction.class);
public ActionForward roleDele(ActionMapping arg0, ActionForm arg1,
HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
// 角色删除
String roleId = arg2.getParameter("roleid");
String mes="";
List<UsersBean> userList = new UsersDao().seleId(roleId);
if(userList.size()!=0){
arg2.setAttribute("mes","此角色已经被使用不允许删除");
return arg0.findForward("error");
}else{
new RolesDao().del(roleId);
mes = "delter succeed!";
}
return new ActionForward(arg0.findForward("ok").getPath() + "?mes="+ mes, true);
}
public ActionForward roleSelect(ActionMapping arg0, ActionForm arg1,
HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
// 角色查询
RoleQueryActionFrom roleQueryActionFrom = (RoleQueryActionFrom) arg1;
List<RolesBean> rolesBeanList = new RolesDao()
.select(roleQueryActionFrom.getSelect(), roleQueryActionFrom
.getText2());
arg2.setAttribute("rolesBeanList", rolesBeanList);
return arg0.findForward("ok");
}
public ActionForward deleteUserInfo(ActionMapping arg0, ActionForm arg1,
HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
// 职工修改
String userId = arg2.getParameter("userid");
new UsersDao().delete(userId);
String mes="del succeed";
return new ActionForward(arg0.findForward("ok").getPath(), true);
}
public ActionForward amendClientInfo(ActionMapping arg0, ActionForm arg1,
HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
// 职工修改
AmendValidatorForm amendValidatorForm = (AmendValidatorForm) arg1;
UsersBean usersBean = new UsersBean();
BeanUtils.copyProperties(usersBean, amendValidatorForm);
new UsersDao().update(usersBean);
String mes="update succeed";
return new ActionForward(arg0.findForward("ok").getPath(), true);
}
public ActionForward selectUserInfo(ActionMapping arg0, ActionForm arg1,
HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
// 用户管理查询用户
String user_id = arg2.getParameter("userid");
// 数字没有用,只是为了方法重复使用
List<UsersBean> userInfo = new UsersDao().select(1, user_id);
UsersBean usersBean = new UsersBean();
usersBean.setUser_id(userInfo.get(0).getUser_id());
usersBean.setUser_describe(userInfo.get(0).getUser_describe());
usersBean.setUser_status(userInfo.get(0).getUser_status());
usersBean.setUserName(userInfo.get(0).getUserName());
usersBean.setChck_time(userInfo.get(0).getChck_time());
usersBean.setCheck_manager(userInfo.get(0).getCheck_manager());
usersBean.setInit_time(userInfo.get(0).getInit_time());
usersBean.setRole_id(userInfo.get(0).getRole_id());
usersBean.setPassword(userInfo.get(0).getPassword());
arg2.setAttribute("userInfo", usersBean);
return arg0.findForward("ok");
}
public ActionForward selectUserManage(ActionMapping arg0, ActionForm arg1,
HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
// 用户管理查询用户
List<UsersBean> userInfo = new UsersDao().select(1, "");
arg2.setAttribute("mes",arg2.getParameter("mes"));
arg2.getSession().setAttribute("userInfo", userInfo);
return arg0.findForward("ok");
}
public ActionForward selectUserLand(ActionMapping arg0, ActionForm arg1,
HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
// 登陆用户验证
UserLandingActionFrom userLandingActionFrom = (UserLandingActionFrom) arg1;
UsersLoadBean list = new UsersDao().select(userLandingActionFrom
.getUserName(), userLandingActionFrom.getPwd());
String pass = "false";
if (list.getUserName()!=null) {
if(list.getUserStatus().equals("active")){
arg2.getSession().setAttribute("treeInfo", list.getUserName());
pass = "true";
arg2.getSession().setAttribute("pass", pass);
if (logger.isDebugEnabled()) {
logger
.debug("selectUserLand(ActionMapping, ActionForm, HttpServletRequest, HttpServletResponse) - 用户登陆成功,取得密钥!");
}
return arg0.findForward("ok");
}else{
arg2.setAttribute("mes", "权限不够!用户可能没激活!");
return arg0.findForward("error");
}
}
arg2.setAttribute("mes", "帐户或者密码错误!");
return arg0.findForward("error");
}
public ActionForward create(ActionMapping arg0, ActionForm arg1,
HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
// 增加用户 帐户
ClientAccountForm caf = (ClientAccountForm) arg1;
AccountBean accountBean = new AccountBean();
BeanUtils.copyProperties(accountBean, caf);
AccountDao accountDao = new AccountDao();
String customer_id = arg2.getParameter("userid");
accountBean.setCustomer_id(customer_id);
accountBean.setBalance("100");
List<AccountBean> list = accountDao.select(accountBean.getType(), "",
accountBean.getCustomer_id());
String mes = "";
if (list.size() > 0) {
mes = "user has been registered! ";
} else {
List<ClientBean> user = new ClientDao().sel("customer_id", customer_id);
if (user.size()<=0) {
throw new RegisterException(MessageFormat.format("ID为{0}的用户数据不存在.",customer_id));
}
accountDao.create(accountBean);
mes = "registered ok!";
}
return new ActionForward(arg0.findForward("userloginok").getPath()
+ "?mes=" + mes, true);
}
public ActionForward select(ActionMapping arg0, ActionForm arg1,
HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
// 查询用户 帐户
ShowClientActionForm scaf = (ShowClientActionForm) arg1;
List<AccountBean> list = new ArrayList<AccountBean>();
arg2.setAttribute("select",scaf.getSelect());
if (scaf.getSelect().equals("all")) {
list = new AccountDao().select();
arg2.setAttribute("List", list);
System.out.println(list.size());
} else {
list = new AccountDao().select(scaf.getSelect(), scaf.getText());
arg2.setAttribute("List", list);
}
return arg0.findForward("ok");
}
public ActionForward update(ActionMapping arg0, ActionForm arg1,
HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
// 更新用户 帐户
AutoActionForm autoActionForm = (AutoActionForm) arg1;
float money1 = Float.valueOf(autoActionForm.getCountLine2());
List<AccountBean> list = new AccountDao().selec("account_id",
autoActionForm.getAccountId2());
String mes = "";
if (list.size() > 0) {
float money3 = 0;
try {
money3 = Float.valueOf(list.get(0).getBalance());
} catch (Exception e) {
throw new RuntimeException(e);
}
if (autoActionForm.getAction().equals("Deposit")) {
// 存钱
new AccountDao().update(autoActionForm.getAccountId2(), "",
money1, 1);
mes = "Deposit money succeed!";
}
if (autoActionForm.getAction().equals("Withdrawal")) {
// 取钱
if (money3 >= money1) {
new AccountDao().update(autoActionForm.getAccountId2(), "",
money1, 0);
mes = "Withdrawal money succeed!";
} else {
mes = "Withdrawal money be defeated,balance lack!";
}
}
} else {
mes = "user not find!";
}
return new ActionForward(arg0.findForward("ok").getPath() + "?mes="
+ mes, true);
}
public ActionForward tranupdate(ActionMapping arg0, ActionForm arg1,
HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
// 用户 帐户 转帐
TransferActionFrom transferActionFrom = (TransferActionFrom) arg1;
float money = Float.valueOf(transferActionFrom.getAction2());
String account_id1 = transferActionFrom.getAccountId1();
String account_id2 = transferActionFrom.getAccountId2();
List<AccountBean> list = new AccountDao().selec("account_id",
account_id2);
String mes = "";
if (list.size() > 0) {
List<AccountBean> list1 = new AccountDao().select("account_id",
account_id1);
if (list1.size() > 0) {
float money1 = Float.valueOf(list1.get(0).getBalance());
if (money1 >= money) {
new AccountDao().update(account_id1, account_id2, money, 0);
mes = "transfer succeed!";
} else {
mes = "transfer be defeated,balance lack!";
}
} else {
mes = "transfer be defeated,user not find!";
}
} else {
mes = "transfer be defeated,user not find!";
}
return new ActionForward(arg0.findForward("ok").getPath() + "?mes="
+ mes, true);
}
public ActionForward tradeselect(ActionMapping arg0, ActionForm arg1,
HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
// 查询用户交易记录
ExchangerecordActionFrom exchangerecordActionFrom = (ExchangerecordActionFrom) arg1;
arg2.setAttribute("select",exchangerecordActionFrom.getSelect());
List<ExchangerecordBean> list = new ExchangerecordDao().select(
exchangerecordActionFrom.getSelect(), exchangerecordActionFrom
.getRecValue2(), exchangerecordActionFrom.getOrder(),
exchangerecordActionFrom.getStartTime2(),
exchangerecordActionFrom.getEndTime2());
arg2.setAttribute("List", list);
return arg0.findForward("ok");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -