📄 rulemanageaction.java
字号:
package com.jn0801.grademanage.action;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
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.jn0801.grademanage.RuleManageInf;
import com.jn0801.grademanage.ScoreRule;
import com.jn0801.grademanage.form.RuleManageForm;
import com.jn0801.login.systemuser.SystemuserBean;
/**
* 分级规则管理的Action类
* @author jzh
*
*/
public class RuleManageAction extends DispatchAction {
private RuleManageInf ruleManageInf;
public RuleManageInf getRuleManageInf() {
return ruleManageInf;
}
public void setRuleManageInf(RuleManageInf ruleManageInf) {
this.ruleManageInf = ruleManageInf;
}
/**
* 显示规则列表
*
* @param mapping
* @param form
* @param request
* @param response
* @return
*/
public ActionForward showRule(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
RuleManageForm ruleManageForm = (RuleManageForm) form;
String rulename = ruleManageForm.getRulename();
String rulebrand = ruleManageForm.getRulebrand();
if(rulebrand!=null && rulebrand.equals("请选择品牌"))
rulebrand = null;
List<ScoreRule> list = this.ruleManageInf.listGradeRule(null,rulename,
rulebrand, request);
request.setAttribute("rulelist", list);
//从数据字典中取得品牌的集合
List brandlist = this.ruleManageInf.listData(new Long(5));
request.setAttribute("brandlist", brandlist);
return mapping.findForward("show");
}
/**
* 添加规则
*
* @param mapping
* @param form
* @param request
* @param response
* @return
*/
public ActionForward addRule(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
RuleManageForm ruleManageForm = (RuleManageForm) form;
ScoreRule scoreRule = new ScoreRule();
try {
BeanUtils.copyProperties(scoreRule, ruleManageForm);
} catch (Exception e) {
e.printStackTrace();
}
String ruleexpression = "";
if (ruleManageForm.getCountgene().equals("消费积分")) {
if (ruleManageForm.getNumtwo() == 0) {
ruleexpression = ruleManageForm.getNumone() + "<=消费积分:"
+ ruleManageForm.getCardtype();
} else {
ruleexpression = ruleManageForm.getNumone() + "<=消费积分<"
+ ruleManageForm.getNumtwo() + ":"
+ ruleManageForm.getCardtype();
}
} else {
ruleexpression = "预存话费>=" + ruleManageForm.getNumone() + "元,且平均ARPU值>="
+ ruleManageForm.getNumthree() + "元:"
+ ruleManageForm.getCardtype();
}
scoreRule.setRuleexpression(ruleexpression);
scoreRule.setChecksign("否");
scoreRule.setFreezesign("否");
if(ruleManageForm.getCardtype().equals("钻石卡")){
scoreRule.setCountmodulus(new Long(1));
}else if(ruleManageForm.getCardtype().equals("银卡")){
scoreRule.setCountmodulus(new Long(2));
}else{
scoreRule.setCountmodulus(new Long(3));
}
HttpSession session = request.getSession();
SystemuserBean systemuserbean = (SystemuserBean) session
.getAttribute("userbean");
String suser = "";
if (systemuserbean != null)
suser = systemuserbean.getUsername();
boolean tag = this.ruleManageInf.saveGradeRule(scoreRule, suser);
PrintWriter out = null;
try {
out = response.getWriter();
} catch (Exception e) {
e.printStackTrace();
}
if (tag) {
out.println("<script>" + "alert('添加成功');"
+ "window.location.href = '" + request.getContextPath()
+ "/ruleManage.do?tag=showRule';" + "</script>");
} else {
out.println("<script>" + "alert('添加失败');"
+ "window.history.back();" + "</script>");
}
out.flush();
if(out!=null)
out.close();
return null;
}
/**
* 删除规则
*
* @param mapping
* @param form
* @param request
* @param response
* @return
*/
public ActionForward deleteRule(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
RuleManageForm ruleManageForm = (RuleManageForm) form;
Long nid = Long.parseLong(request.getParameter("nid"));
boolean tag = this.ruleManageInf.deleteGradeRule(nid);
PrintWriter out = null;
try {
out = response.getWriter();
} catch (Exception e) {
e.printStackTrace();
}
if (tag) {
String url = "ruleManage.do?tag=showRule";
if (request.getParameter("currentpage") != null
&& !request.getParameter("currentpage").equals("")) {
url = url + "¤tpage="
+ request.getParameter("currentpage") + "";
}
if (ruleManageForm.getRulename() != null
&& !ruleManageForm.getRulename().equals("")) {
url = url + "&rulename="
+ ruleManageForm.getRulename() + "";
}
if (ruleManageForm.getRulebrand() != null
&& !ruleManageForm.getRulebrand().equals("")) {
url = url + "&rulebrand="
+ ruleManageForm.getRulebrand() + "";
}
out.println("<script>" + "alert('删除成功');"
+ "window.location.href = '" + url +"';</script>");
} else {
out.println("<script>" + "alert('删除失败');"
+ "window.history.back();" + "</script>");
}
out.flush();
if(out!=null)
out.close();
return null;
}
/**
* 显示添加页面
*
* @param mapping
* @param form
* @param request
* @param response
* @return
*/
public ActionForward add(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
// RuleManageForm ruleManageForm = (RuleManageForm) form;
// 从数据字典中取得卡的集合
List cardlist = this.ruleManageInf.listData(new Long(1));
request.setAttribute("cardlist", cardlist);
//从数据字典中取得品牌的集合
List brandlist = this.ruleManageInf.listData(new Long(5));
request.setAttribute("brandlist", brandlist);
return mapping.findForward("edit");
}
/**
* 显示修改页面
*
* @param mapping
* @param form
* @param request
* @param response
* @return
*/
public ActionForward update(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
RuleManageForm ruleManageForm = (RuleManageForm) form;
Map map = new HashMap();
if (ruleManageForm.getRulebrand() != null
&& !ruleManageForm.getRulebrand().equals("")) {
map.put("search_rulebrand", ruleManageForm.getRulebrand());
}
if (ruleManageForm.getRulename() != null
&& !ruleManageForm.getRulename().equals("")) {
map.put("search_rulename", ruleManageForm.getRulename());
}
if (request.getParameter("currentpage") != null
&& !request.getParameter("currentpage").equals("")) {
map.put("currentpage", request.getParameter("currentpage"));
}
request.setAttribute("map", map);
Long nid = Long.parseLong(request.getParameter("nid"));
ScoreRule scoreRule = this.ruleManageInf.searchGradeRuleById(nid);
try {
BeanUtils.copyProperties(ruleManageForm, scoreRule);
} catch (Exception e) {
e.printStackTrace();
}
// 从数据字典中取得卡的集合
List cardlist = this.ruleManageInf.listData(new Long(1));
request.setAttribute("cardlist", cardlist);
//从数据字典中取得品牌的集合
List brandlist = this.ruleManageInf.listData(new Long(5));
request.setAttribute("brandlist", brandlist);
return mapping.findForward("edit");
}
/**
* 更新规则
*
* @param mapping
* @param form
* @param request
* @param response
* @return
*/
public ActionForward updateRule(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
RuleManageForm ruleManageForm = (RuleManageForm) form;
ScoreRule scoreRule = new ScoreRule();
try {
BeanUtils.copyProperties(scoreRule, ruleManageForm);
} catch (Exception e) {
e.printStackTrace();
}
String ruleexpression = "";
if (ruleManageForm.getCountgene().equals("消费积分")) {
if (ruleManageForm.getNumtwo() == 0) {
ruleexpression = ruleManageForm.getNumone() + "<=消费积分:"
+ ruleManageForm.getCardtype();
} else {
ruleexpression = ruleManageForm.getNumone() + "<=消费积分<"
+ ruleManageForm.getNumtwo() + ":"
+ ruleManageForm.getCardtype();
}
} else {
ruleexpression = "预存话费>=" + ruleManageForm.getNumone() + "元,且平均ARPU值>="
+ ruleManageForm.getNumthree() + "元:"
+ ruleManageForm.getCardtype();
}
scoreRule.setRuleexpression(ruleexpression);
if(ruleManageForm.getCardtype().equals("钻石卡")){
scoreRule.setCountmodulus(new Long(1));
}else if(ruleManageForm.getCardtype().equals("金卡")){
scoreRule.setCountmodulus(new Long(2));
}else{
scoreRule.setCountmodulus(new Long(3));
}
HttpSession session = request.getSession();
SystemuserBean systemuserbean = (SystemuserBean) session
.getAttribute("userbean");
String suser = "";
if (systemuserbean != null)
suser = systemuserbean.getUsername();
boolean tag = this.ruleManageInf.updateGradeRule(scoreRule, suser);
PrintWriter out = null;
try {
out = response.getWriter();
} catch (Exception e) {
e.printStackTrace();
}
if (tag) {
String url = "ruleManage.do?tag=showRule";
if (request.getParameter("currentpage") != null
&& !request.getParameter("currentpage").equals("")) {
url = url + "¤tpage="
+ request.getParameter("currentpage") + "";
}
if (request.getParameter("search_rulename") != null
&& !request.getParameter("search_rulename").equals("")) {
url = url + "&rulename="
+ request.getParameter("search_rulename") + "";
}
if (request.getParameter("search_rulebrand") != null
&& !request.getParameter("search_rulebrand").equals("")) {
url = url + "&rulebrand="
+ request.getParameter("search_rulebrand") + "";
}
out.println("<script>" + "alert('更新成功');"
+ "window.location.href = '" + url +"';</script>");
} else {
out.println("<script>" + "alert('更新失败');"
+ "window.history.back();" + "</script>");
}
out.flush();
if(out!=null)
out.close();
return null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -