📄 feequeryaction.java
字号:
/**
* @author tiantian
*
* Jun 11, 2008 9:05:38 AM
*/
package netctoss.reckon.actions;
import global.ModuleMenu;
import global.PageParameters;
import global.RightMenu;
import global.SortMenu;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.Vector;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import netctoss.dao.AdminsDAO;
import netctoss.dao.ModulesDAO;
import netctoss.entities.Adminroles;
import netctoss.entities.Admins;
import netctoss.entities.Modules;
import netctoss.entities.Rights;
import netctoss.entities.Rolerights;
import netctoss.jdbc.entities.Detail;
import netctoss.jdbc.entities.ServReckon;
import netctoss.jdbc.entities.UserReckon;
import netctoss.reckon.dao.FeeDAO;
import netctoss.reckon.dao.FeeDAOImpl;
import netctoss.reckon.forms.FeeQueryCondForm;
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 org.apache.struts.actions.MappingDispatchAction;
/**
* 负责账单查询,与明细查询的逻辑处理
*/
public class FeeQueryAction extends DispatchAction {
private FeeDAO feedao;
private Modules getOperationMenuByRight(Integer id){
ModulesDAO dao= new ModulesDAO();
dao.getSession().flush();
return dao.findById(id);
}
public ActionForward index(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
String moduleid=request.getParameter("moduleid");
if(moduleid!=null){
Modules tmpmodule=getOperationMenuByRight(new Integer(moduleid));
ModuleMenu module=new ModuleMenu();
module.setId(tmpmodule.getId());
module.setName(tmpmodule.getName());
module.setUrl(tmpmodule.getUrl());
request.getSession().setAttribute("module", module);
String adminid=request.getSession().getAttribute("adminid").toString();
//得到该用户的角色->权限->过滤得到
AdminsDAO daoadmin=new AdminsDAO();
//得到管理员
Admins admin=daoadmin.findById(new Integer(adminid));
//存放权限,便于过滤
List<Rights> listallright=new Vector<Rights>();
//得到用户角色集合
Set setadminroles=admin.getAdminroles();
Iterator it=setadminroles.iterator();
//循环找出角色的所有权限
while(it.hasNext()){
Adminroles adminrole=(Adminroles)it.next();
Set setroleright=adminrole.getRoleid().getRolerights();
Iterator itroleright=setroleright.iterator();
while(itroleright.hasNext()){
Rolerights rr=(Rolerights)itroleright.next();
if(rr.getRightid().getModuleid().getId().equals(new Integer(moduleid))){
listallright.add(rr.getRightid());
}
}
}
//这里过滤重复的权限。
Set setrights=new HashSet();
for(Object obj:listallright){
setrights.add(obj);
}
RightMenu[] rm=new RightMenu[setrights.size()];
Object[] obj=setrights.toArray();
for(int i=0;i<obj.length;i++){
rm[i]=new RightMenu();
rm[i].setId(((Rights)obj[i]).getId());
rm[i].setName(((Rights)obj[i]).getName());
rm[i].setUrl(((Rights)obj[i]).getUrl());
}
//权限排序。
Arrays.sort(rm,new SortMenu());
//设置权限菜单到session,便于下步导航
request.getSession().setAttribute("menu", rm);
}
else{
return mapping.findForward("back");
}
//根据提交的方法确定数据处理
return mapping.findForward("goindex");
}
//查询的是总的帐单金额
public ActionForward browse(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
GregorianCalendar gc= new GregorianCalendar();
//向上滚动一个月
gc.add(Calendar.MONTH, -1);
int currentyear=gc.get(Calendar.YEAR);
int currentmonth=gc.get(Calendar.MONTH)+1;
request.setAttribute("years", new int[]{currentyear,currentyear-1,currentyear-2});//显示最近三年
//得到查询的条件
FeeQueryCondForm fqcForm = (FeeQueryCondForm) form;
List<UserReckon> urs =new ArrayList<UserReckon>();
int year = Integer.parseInt(fqcForm.getYear());//查询的年
int month = Integer.parseInt(fqcForm.getMonth());//查询的月
year=year==0?currentyear:year;
month=month==0?currentmonth:month;
request.setAttribute("year", year);
request.setAttribute("month", month);
feedao = new FeeDAOImpl();
//要查询的年月
//得到查询的页面\
String strpage=request.getParameter("page");
//表示没有page参数,就是点击菜单的查询 ,当前页面为0
strpage=strpage==null?"0":strpage;
int currentpage = Integer.parseInt(strpage);//翻页
if(currentpage==0){
//说明是直接查询
//不做任何处理
request.setAttribute("urs", urs);//空的记录//不分页
return mapping.findForward("gobrowsereckon");
}
String name = fqcForm.getName();//用户名
//说明是分页查询,怎样在分页保存查询的条件呢?
currentpage=currentpage<=0?1:currentpage;//保存显示的肯定是第一页
try{
//查询结果<这里应该分页查询>
//根据用户名,年,月查询用户的帐单结果,按业务分组
urs = feedao.getFeeByCondition(name, year, month,currentpage-1);
int totals =urs.size();//总的记录数
int totalpages=totals%PageParameters.ITEMS_EACH_PAGE==0?totals/PageParameters.ITEMS_EACH_PAGE:totals/PageParameters.ITEMS_EACH_PAGE +1;
String pagenav=PageParameters.pageNavigator(totalpages, currentpage, request.getContextPath()+ request.getServletPath()+"?method=browse");
request.setAttribute("pagenav", pagenav);
//保存用户信息
request.setAttribute("urs", urs);
return mapping.findForward("gobrowsereckon");
}catch(Exception e){
//这里应该不管成功还是失败,都应该定向到显示页面。
return mapping.findForward("fail");
}
}
//查询的是每个业务的明细
public ActionForward detailList(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
//FeeQueryCondForm表单的生命周期是session,可以实现多连接明细查询的数据保存.
//该表单中保存原有的查询数据,用户名,年,月.
//并且保存有本次提交的帐务帐号信息,与总的费用
FeeQueryCondForm fqcForm = (FeeQueryCondForm) form;
feedao = new FeeDAOImpl();
List<ServReckon> srs = new ArrayList();
String username = fqcForm.getName();//用户名
String accname=fqcForm.getAccloginname();
int year = Integer.parseInt(fqcForm.getYear());//年月
int month =Integer.parseInt(fqcForm.getMonth());//年月
//总费用,使用querystring传递
double fee = fqcForm.getFeetitle();
int currentpage = 1 ;
currentpage=fqcForm.getPage();
currentpage=currentpage<=0?1:currentpage;
//根据帐务帐号查询
srs = (List<ServReckon>) feedao.getFeeDetail(accname, year, month,currentpage-1);
int totals = feedao.getFeeDetailCount(accname, year, month);
int totalpages=totals%PageParameters.ITEMS_EACH_PAGE==0?totals/PageParameters.ITEMS_EACH_PAGE:totals/PageParameters.ITEMS_EACH_PAGE +1;
String pagenav=PageParameters.pageNavigator(totalpages, currentpage, request.getContextPath()+ request.getServletPath()+"?method=detailList");
request.setAttribute("pagenav", pagenav);
request.setAttribute("srs", srs);//查询结果
request.setAttribute("username", username);//用户名
request.setAttribute("feetitle", fee);
return mapping.findForward("gobrowsereckondetail");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -