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

📄 clientanalysisaction.java

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

/**
 * 客户统计分析
 */
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

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

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

import com.qrsx.qrsxcrm.dao.ClientAnalysisDAO;
import com.qrsx.qrsxcrm.dao.ClientDAO;
import com.qrsx.qrsxcrm.dao.ClientTypeDAO;
import com.qrsx.qrsxcrm.form.ClientAnalysisForm;
import com.qrsx.qrsxcrm.model.Client;
import com.qrsx.qrsxcrm.model.ClientType;
import com.qrsx.qrsxcrm.web.FreeChartUtils;

public class ClientAnalysisAction 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,
			IOException {
		String pictureName=(String) request.getSession().getAttribute("userId");  //根据用户的id命名报表图片名称
		ClientAnalysisDAO caDao = new ClientAnalysisDAO(Client.class);
		ClientAnalysisForm caForm = (ClientAnalysisForm) form;
		Client client = new Client();
		DefaultPieDataset dataset = new DefaultPieDataset();			//饼状数据
		DefaultCategoryDataset dataset_cat=new DefaultCategoryDataset();//柱形数据
		
		// 取得用户类型
		ClientTypeDAO ctDao = new ClientTypeDAO(ClientType.class);
		List clientTypes = ctDao.findAll("from ClientType");

		String radiosb = caForm.getRadiosb(); 	// 得到统计范围
		String shape = caForm.getShape(); 		// 得到生成报表的样式

		if ("area".equals(radiosb)) { 				// 按地区分析
			//检索所有客户得到地区集合
			ClientDAO cDao=new ClientDAO(Client.class);
			List list_client=cDao.findAll("from Client");
			Set areas=new HashSet();
			Iterator itclient= list_client.iterator();
			while(itclient.hasNext()){
				Client client1=(Client) itclient.next();
				areas.add(client1.getAddress());
			}
			Iterator it = areas.iterator();
			if("pie".equals(shape)){					//饼状图
				
				while (it.hasNext()) {
					String areaName = it.next().toString();
					List list = caDao.finByArea(areaName);
					dataset.setValue(areaName, new Double(list.size()));
				}
				FreeChartUtils fc = new FreeChartUtils("客户地区分布图", "c:\\"+pictureName+".gif");
				fc.createPicture(dataset);
			}
			else{										//柱状图
				while (it.hasNext()) {
					String areaName = it.next().toString();
					List list = caDao.finByArea(areaName);
					dataset_cat.addValue(list.size(), "", areaName);
				}
				FreeChartUtils fc=new FreeChartUtils("客户地区柱状图","c:\\"+pictureName+".gif");
				fc.createPicture(dataset_cat, "地区", "客户数量");
			}
		}

		if ("clientOrigin".equals(radiosb)) { // 按客户来源分析
			List list1 = caDao.findByOrigin("报纸");
			List list2 = caDao.findByOrigin("广告");
			List list3 = caDao.findByOrigin("网站");
			List list4 = caDao.findByOrigin("新闻");
			
			
			if("pie".equals(shape)){					//饼状图
				dataset.setValue("报纸", new Double(list1.size()));
				dataset.setValue("广告", new Double(list2.size()));
				dataset.setValue("网站", new Double(list3.size()));
				dataset.setValue("新闻", new Double(list4.size()));
				FreeChartUtils fc = new FreeChartUtils("客户来源分析", "c:\\"+pictureName+".gif");
				fc.createPicture(dataset);
			}
			else{										//柱状图
				dataset_cat.addValue(list1.size(), "", "报纸");
				dataset_cat.addValue(list2.size(), "", "广告");
				dataset_cat.addValue(list3.size(), "", "网站");
				dataset_cat.addValue(list4.size(), "", "新闻");
				
				FreeChartUtils fc=new FreeChartUtils("客户来源柱状图","c:\\"+pictureName+".gif");
				fc.createPicture(dataset_cat, "客户来源", "客户数量");
			}
		}
		if ("Type".equals(radiosb)) { // 按客户类型分析
			if("pie".equals(shape)){				//饼状图
				Iterator it = clientTypes.iterator();
				while (it.hasNext()) {
					ClientType ct = (ClientType) it.next();
					String clientTypeId = ct.getId();
					client.setClientTypeId(clientTypeId);
					String clientTypeName = ct.getName();
					List list = caDao.findByED(client);
					dataset.setValue(clientTypeName, new Double(list.size()));
				}
				FreeChartUtils fc = new FreeChartUtils("客户类型分布图", "c:\\"+pictureName+".gif");
				FreeChartUtils.createPicture(dataset);
			}
			else{									//柱状图
				Iterator it = clientTypes.iterator();
				while (it.hasNext()) {
					ClientType ct = (ClientType) it.next();
					String clientTypeId = ct.getId();
					client.setClientTypeId(clientTypeId);
					String clientTypeName = ct.getName();
					List list = caDao.findByED(client);
					//	组装数据
					dataset_cat.addValue(list.size(), "", clientTypeName);
				}
				FreeChartUtils fc=new FreeChartUtils("客户类型柱状图","c:\\"+pictureName+".gif");
				fc.createPicture(dataset_cat, "客户类型", "客户数量");
			}
		}
		return mapping.findForward("query");
	}

	
	
	/**
	 * 
	 * @param mapping
	 * @param form
	 * @param request
	 * @param response
	 * @return
	 * @throws IllegalAccessException
	 * @throws InvocationTargetException
	 */
	public ActionForward list(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws IllegalAccessException, InvocationTargetException {
		Client client = new Client();
		BeanUtils.copyProperties(client, form);
		// 组装客户类型
		ClientTypeDAO ctDao = new ClientTypeDAO(ClientType.class);
		List clientTypes = ctDao.findAll("from ClientType");
		request.setAttribute("clientTypes", clientTypes);

		ClientTypeDAO clientTypeDao = new ClientTypeDAO(ClientType.class);
		// 组装客户类型
		if (client.getClientTypeId() != null
				&& client.getClientTypeId().trim().length() > 0) {
			ClientType clientType = (ClientType) clientTypeDao.findById(
					ClientType.class, client.getClientTypeId());
			client.setClientType(clientType);
		}
		ClientDAO cdao = new ClientDAO(Client.class);
		List list = cdao.findAll("from Client");// 得到总数据

		request.setAttribute("clients", list);

		return mapping.findForward("list");
	}

}

⌨️ 快捷键说明

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