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

📄 pricingaction.java

📁 当时就海底世界没客服热线mkxmykm,xkxtml, xrtlujlnszltrikxrseher
💻 JAVA
字号:
package com.tarena.oss.web.actions;

import java.util.Collection;
import java.util.Map;
import java.util.Set;

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

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.MappingDispatchAction;

import com.tarena.oss.admin.pojo.Admin;
import com.tarena.oss.admin.service.AdminMgmtService;
import com.tarena.oss.pricing.pojo.Pricing;
import com.tarena.oss.pricing.pojo.PricingConditionDTO;
import com.tarena.oss.pricing.service.PricingMgmtService;
import com.tarena.oss.rights.pojo.Rights;
import com.tarena.oss.util.PageParameter;
import com.tarena.oss.util.QueryResult;
import com.tarena.oss.web.forms.PricingCondForm;

public class PricingAction extends MappingDispatchAction {
	private PricingMgmtService service;
	private AdminMgmtService aservice;
	
	//private ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");

	public void setService(PricingMgmtService service) {
		this.service = service;
	}


	public void setAservice(AdminMgmtService aservice) {
		this.aservice = aservice;
	}


	public ActionForward listAll(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		//service = (PricingMgmtService)context.getBean("pricingServiceProxy");
		//Collection<Pricing> ps = service.findAll();
		//request.getSession().setAttribute("PRICINGS", ps);
		
		String page = request.getParameter("page");
		int currentPage = 1;
		if (page != null && !page.equals(""))
			currentPage = Integer.parseInt(page);
		
		QueryResult<Pricing> qr = service.findAll(currentPage, PageParameter.ITEM_EACH_PAGE);
		
		request.getSession().setAttribute("PRICINGS", qr.getData());
		
		int rowCnt = qr.getCounts();
		String pagenav = makePagenav(currentPage, rowCnt, request);
		request.setAttribute("pagenav", pagenav);
		
		int type = Integer.parseInt(request.getParameter("type"));
		if (type == 1)
			return mapping.findForward("list");
		else if (type == 2)
			return mapping.findForward("listforupd");
		else
			return mapping.findForward("listfordel");
			
	}


	public ActionForward listAllByCond(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		//request.setCharacterEncoding("GBK");
		//service = (PricingMgmtService)context.getBean("pricingServiceProxy");
		PricingCondForm pcform = (PricingCondForm)form;
		PricingConditionDTO dto = pcform.getDto();
		//PricingConditionDTO dto = new PricingConditionDTO();
		//dto.setName(pcform.getName());
		String page = request.getParameter("page");
		int currentPage = 1;
		if (page != null && !page.equals(""))
			currentPage = Integer.parseInt(page);
		QueryResult<Pricing> ps =  service.findAllByCondition(dto,currentPage, PageParameter.ITEM_EACH_PAGE);
		request.getSession().setAttribute("PRICINGS", ps);
		
		System.out.println(ps);
		
		int type = Integer.parseInt(request.getParameter("type"));
		if (type == 1)
			return mapping.findForward("list");
		else if (type == 2)
			return mapping.findForward("listforupd");
		else
			return mapping.findForward("listfordel");
			
	}

	public ActionForward listRights(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		Admin admin = (Admin) request.getSession().getAttribute("ADMIN");
		Integer mid = Integer.valueOf(request.getParameter("mid"));
		Set<Rights> rs = aservice.getRightsOfTheModule(admin, mid);
		
		request.getSession().setAttribute("ADMIN_MODULE_RIGHTS", rs);
		
		return mapping.findForward("success");
	}
	
	private String makePagenav(int currentPage, int rowCnt, HttpServletRequest request){
		StringBuffer sb = new StringBuffer();
		int totalPages = 1;
		if (rowCnt % PageParameter.ITEM_EACH_PAGE == 0)
			totalPages = rowCnt / PageParameter.ITEM_EACH_PAGE;
		else
			totalPages = rowCnt / PageParameter.ITEM_EACH_PAGE + 1; 
		
		sb.append(request.getContextPath()).append(request.getServletPath());
		Map<String, String[]> map = request.getParameterMap();
		
		if (map == null || map.size()==0)
			return PageParameter.makePageNavigator(currentPage, totalPages, sb.toString());
		
		sb.append("?");
		for(String key : map.keySet()){
			if (key.equals("page")) continue;
			
			String[] values = map.get(key);
			for(String v : values)
				sb.append(key).append("=").append(v).append("&");
		}

		return PageParameter.makePageNavigator(currentPage, totalPages, sb.substring(0, sb.length()-1));
	}
	
	public ActionForward toaddpricing(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response){
		
		return mapping.findForward("toaddpricing");
	}
	
	public ActionForward addpricing(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		String name = request.getParameter("name");
		String basefeeString = request.getParameter("basefee");
		double baseFee = Double.parseDouble(basefeeString);
		System.out.println("baseFee");
		String ratefeeString = request.getParameter("ratefee");
		double rateFee = Double.parseDouble(ratefeeString);
		String desc = request.getParameter("description");
	    Pricing p = new Pricing();
		p.setName(name);
    	p.setBaseFee(baseFee);
		p.setRateFee(rateFee);
		p.setDesc(desc);
		service.addPricing(p);
		return mapping.findForward("addpricing");
	}

	public ActionForward toupdatepricing(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		int id = Integer.parseInt(request.getParameter("id"));
		Pricing p = service.findPricingById(id);
		System.out.println("P+++++++++" + p);
		request.getSession().setAttribute("PRICING", p);
		service.modifyPricing(p);
		return mapping.findForward("update");
	}
	//zifeishanchu
	public ActionForward todelpricing(ActionMapping mapping,
			ActionForm form, HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		int id = Integer.parseInt(request.getParameter("id"));
		//Pricing p = service.findPricingById(id);
		//System.out.println("P+++++++++" + p);
		service.removePricing(id);
		return mapping.findForward("delete");
	}
}

⌨️ 快捷键说明

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