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

📄 saleanalysisaction.java

📁 客户关系管理系统主要管理新老客户的一些信息并可以发现潜在客户
💻 JAVA
字号:
package com.qrsx.qrsxcrm.action;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Iterator;
import java.util.List;

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.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.DefaultPieDataset;

import com.qrsx.qrsxcrm.dao.ClientDAO;
import com.qrsx.qrsxcrm.dao.EmployeeDAO;
import com.qrsx.qrsxcrm.dao.OrderDAO;
import com.qrsx.qrsxcrm.dao.ProductionDAO;
import com.qrsx.qrsxcrm.dao.ProductionTypeDAO;
import com.qrsx.qrsxcrm.form.SaleAnalysisForm;
import com.qrsx.qrsxcrm.model.Client;
import com.qrsx.qrsxcrm.model.Employee;
import com.qrsx.qrsxcrm.model.Order;
import com.qrsx.qrsxcrm.model.Production;
import com.qrsx.qrsxcrm.model.ProductionType;
import com.qrsx.qrsxcrm.web.FreeChartUtils;

public class SaleAnalysisAction extends BaseDispatchAction {
	
	/**
	 * 根据分析生成报表图片
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws IllegalAccessException
	 * @throws InvocationTargetException
	 * @throws IOException
	 */
	public ActionForward query(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws IllegalAccessException, InvocationTargetException,
			Exception {
		String pictureName=(String) request.getSession().getAttribute("userId"); 
		SaleAnalysisForm saForm=(SaleAnalysisForm)form;
		Order order=new Order();
		Production production=new Production();
		OrderDAO odao=new OrderDAO(Order.class);
		ProductionDAO pDao=new ProductionDAO(Production.class);
		DefaultPieDataset dataset_pie = new DefaultPieDataset();		//饼形数据
		DefaultCategoryDataset dataset_cat=new DefaultCategoryDataset();//柱形数据
		
		String radiosb=saForm.getRadiosb();	//得到统计方式
		String orderRd=saForm.getOrderRd();	//负责人 和 客户
		String shape=saForm.getShape();		//图形
		
		if("order".equals(radiosb)){				//订单统计 
			if("orderEmployee".equals(orderRd)){		//按负责人统计
				//检索出所有负责人
				EmployeeDAO eDao=new EmployeeDAO(Employee.class);
				List employees=eDao.findAll("from Employee");
				Iterator it=employees.iterator();
				
				if("pie".equals(shape)){					//饼状图
					while(it.hasNext()){
						Employee employee=(Employee)it.next();
						String employeeId=employee.getId();
						order.setEmployeeId(employeeId);
						List list=odao.findByED(order);
						//组装数据
						dataset_pie.setValue(employee.getEmployeeName(), new Double(list.size()));
					}
					FreeChartUtils fc=new FreeChartUtils("负责人订单数量分布图","c:\\"+pictureName+".gif");
					fc.createPicture(dataset_pie);
				}
				else{										//柱状图
					while(it.hasNext()){
						Employee employee=(Employee)it.next();
						String employeeId=employee.getId();
						order.setEmployeeId(employeeId);
						List list=odao.findByED(order);
						//组装数据
						dataset_cat.addValue(list.size(), "", employee.getEmployeeName());
					}
					FreeChartUtils fc=new FreeChartUtils("负责人订单数量柱状图","c:\\"+pictureName+".gif");
					fc.createPicture(dataset_cat, "负责人", "订单数量");
				}
				
			}
			else{										//按客户查询
				//检索出所有客户
				ClientDAO cDao=new ClientDAO(Client.class);
				List clients=cDao.findAll("from Client");
				Iterator it=clients.iterator();
				if("pie".equals(shape)){					//饼状图
					
					while(it.hasNext()){
						Client client=(Client)it.next();
						String clientId=client.getId();
						order.setClientId(clientId);
						List list=odao.findByED(order);
						//组装数据
						dataset_pie.setValue(client.getClientName(), new Double(list.size()));
					}
					FreeChartUtils fc=new FreeChartUtils("客户订单数量分布图","c:\\"+pictureName+".gif");
					fc.createPicture(dataset_pie);
				}
				else{										//柱状图
					while(it.hasNext()){
						Client client=(Client)it.next();
						String clientId=client.getId();
						order.setClientId(clientId);
						List list=odao.findByED(order);
						//组装数据
						dataset_cat.addValue(list.size(), "", client.getClientName());
					}
					FreeChartUtils fc=new FreeChartUtils("客户订单数量柱状图","c:\\"+pictureName+".gif");
					fc.createPicture(dataset_cat, "客户", "订单数量");
				}
			}
		}
		if("production".equals(radiosb)){			//产品统计(按产品类型)
			//检索所有产品类型
			ProductionTypeDAO ptDao=new ProductionTypeDAO(ProductionType.class);
			List productionTypes=ptDao.findAll("from ProductionType");
			Iterator it=productionTypes.iterator();
			
			if("pie".equals(shape)){					//饼状图
				
				while(it.hasNext()){
					ProductionType productionType=(ProductionType)it.next();
					String productionTypeId=productionType.getId();
					production.setProductionTypeId(productionTypeId);
					List list=pDao.finBypt(production);
					//组装数据
					dataset_pie.setValue(productionType.getName(), new Double(list.size()));
				}
				FreeChartUtils fc=new FreeChartUtils("公司产品类型分布图","c:\\"+pictureName+".gif");
				fc.createPicture(dataset_pie);
			}
			else{										//柱状图
				while(it.hasNext()){
					ProductionType productionType=(ProductionType)it.next();
					String productionTypeId=productionType.getId();
					production.setProductionTypeId(productionTypeId);
					List list=pDao.finBypt(production);
					//组装数据
					dataset_cat.addValue(list.size(), "", productionType.getName());
				}
				FreeChartUtils fc=new FreeChartUtils("公司产品类型柱状图","c:\\"+pictureName+".gif");
				fc.createPicture(dataset_cat, "产品类型", "产品数量");
			}
		}
		return mapping.findForward("query");
	}
	
	
	
	public ActionForward list(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws IllegalAccessException, InvocationTargetException {
		
		return mapping.findForward("list");
	}
}

⌨️ 快捷键说明

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