⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rankadminaction.java

📁 中青会员消费排行榜-最终版 包括基于Struts+Hibernate的前台和简易后台
💻 JAVA
字号:
/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package cn.zqnet8.rank.web.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.actions.DispatchAction;

import cn.zqnet8.rank.dao.RankDao;
import cn.zqnet8.rank.entity.RankInfo;
import cn.zqnet8.rank.entity.RankMonth;
import cn.zqnet8.rank.util.CommonUtil;
import cn.zqnet8.rank.util.EncryptCustNo;
import cn.zqnet8.web.struts.form.SelectRankForm;

/** 
 * MyEclipse Struts
 * Creation date: 03-01-2009
 * 
 * XDoclet definition:
 * @struts.action parameter="oprate" validate="true"
 */
public class RankAdminAction extends DispatchAction {
	
	/*
	 * 初始化管理员界面
	 */
	public ActionForward initAdmin(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			 {
		
		//获取上一月份所有的会员消费情况
		RankDao rd=new RankDao();
		List list=rd.getCurrentMonthRankInfo();
		// 如果没有登录的话,则将查询出来的信息加密显示

		
		//如果没有记录则在session中添加一个能说明没有获取到数据的对象。
		 //将查询出来的各月排行榜的前几名的会员帐号加密。
		if(list==null||list.size()==0){
			request.getSession().setAttribute("notAdd", "notAdd");
		}
		List firstInfo=rd.getFirstCustInfo();
//		for(int i=0;i<firstInfo.size() && i<6;i++){
//			RankInfo ri=(RankInfo)firstInfo.get(i);
//			RankMonth rm=ri.getRankMonth();
//			String year=rm.getMonthDate().substring(0,4);
//			String month=rm.getMonthDate().substring(5);
//			rm.setMonthDate(year+"年"+month+"月");
//			ri.setRankMonth(rm);
//		}
		request.getSession().setAttribute("showCurDate", rd.getCurMonth(true));
		
		
		
		
		
//		System.out.println("list.size:"+list.size());
		request.getSession().setAttribute("firstInfo", firstInfo);

		//将查询出来的本月排行榜的数据放置到session中
		request.getSession().setAttribute("currentMonthRank", list);
		
		return mapping.findForward("adminRankInited");
		
	}
	/*
	 * 通过Ajax调用,通过排行编号,使其领取会员奖励金额
	 */
	public ActionForward getMoney(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
			int rankID=Integer.parseInt(request.getParameter("rankID"));
			RankDao rd=new RankDao();
			System.out.println("领取奖金来了!!!!!:"+rankID);
			PrintWriter out=null;
			try {
				out=response.getWriter();
			} catch (IOException e) {
				e.printStackTrace();
			}
			if(rd.updateRankInfo(rankID)){
				out.print("ok");
			}else{
				out.print("fail");
			}
		return null;
	}
	
	/*
	 * 通过Ajax调用,修改逾期未领的会员的状态值。
	 */
	public ActionForward changeState(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
			String strDate=request.getParameter("strDate");
			RankDao rd=new RankDao();
			PrintWriter out=null;
			try {
				out=response.getWriter();
			} catch (IOException e) {
				e.printStackTrace();
			}
			if(rd.changeToTimeOver(strDate)){
				out.print("ok");
			}else{
				out.print("fail");
			}
		return null;
	}
	/*
	 * 管理员查询功能
	 */
	public ActionForward select(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		SelectRankForm srf=(SelectRankForm)form;
		System.out.println("是否精确查询:"+srf.getChkValue());

		StringBuffer sb=new StringBuffer("from RankInfo where 1=1 ");
		if(srf.getChkValue()==0){
			sb.append(" and custNo like '%"+srf.getCustNo()+"%'");
		}else{
			if(srf.getCustNo().length()==15|| srf.getCustNo().length()==18){
				sb.append(" and custNo='"+srf.getCustNo()+"'");
			}			
		}
		if(srf.getLevelID()!=0){
			sb.append(" and rankLevel.levelId="+srf.getLevelID());
		}
		if(srf.getMonth().equals("0")){
			sb.append(" and rankMonth.monthDate like '"+srf.getYear()+"%'");
		}else{
			sb.append(" and rankMonth.monthDate='"+srf.getYear()+srf.getMonth()+"'");
		}
		sb.append(" order by rankLevel.levelId asc");
		String hql=sb.toString();
		System.out.println("select HQL:"+hql);
		CommonUtil.closeSession();
		List list=CommonUtil.getAllByHQL(hql);
		
		System.out.println("——————————查询完成————————————————————");
		String custNo=srf.getCustNo();
		EncryptCustNo ecn=new EncryptCustNo();
		String [] custNos=null;
		if(null==list||list.size()==0){
			ActionErrors errors=new ActionErrors();
			errors.add("notFind", new ActionMessage("notSelected"));
			super.addErrors(request, errors);
			return mapping.getInputForward();
		}else{
			custNos=new String [list.size()];
			for(int i=0;i<list.size();i++){
				RankInfo ri=(RankInfo)list.get(i);
				//为每一个会员帐号信息加密,并对关键字进行红色标记显示
				custNos[i]=ecn.encryptCustNO(ri.getCustNo()).replaceAll(custNo, "<font color=red>"+custNo+"</font>");
//				RankMonth rankMonth=ri.getRankMonth();
//				StringBuffer sb2=new StringBuffer("");
//				rankMonth.setMonthDate(new StringBuffer().append(rankMonth.getMonthDate().substring(0,4)).append("年").append(rankMonth.getMonthDate().substring(4)).append("月").toString());
//				String year=ri.getRankMonth().getMonthDate().toString().substring(0,4);
//				String month=ri.getRankMonth().getMonthDate().toString().substring(4);
//				rankMonth.setMonthDate(year+"年"+month+"月");
//				ri.setRankMonth(rankMonth);
				
			}
		}
//		CommonUtil.closeSession();
		request.setAttribute("counts", list.size());//查询出来的记录条数
		request.setAttribute("currentMonthRank", list);//查询出来的结果集
		request.setAttribute("custNos", custNos);
		return mapping.findForward("adminSelected");
	}
	
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -