/*
 * Generated by MyEclipse Struts
 * Template path: templates/java/JavaClass.vtl
 */
package com.yuntong.action;

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

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

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PiePlot3D;
import org.jfree.chart.servlet.ServletUtilities;
import org.jfree.data.general.DefaultPieDataset;

import com.yuntong.service.Y_IRoleManagerService;

/** 
 * MyEclipse Struts
 * Creation date: 04-13-2007
 * 初始化用户权限
 * XDoclet definition:
 * @struts.action validate="true"
 * @struts.action-forward name="go" path="/Y_YHQX_1.jsp"
 */
public class Y_GoYHQXAction extends Action {
	private Y_IRoleManagerService roleManagerService;
	public Y_IRoleManagerService getRoleManagerService() {
		return roleManagerService;
	}
	public void setRoleManagerService(Y_IRoleManagerService roleManagerService) {
		this.roleManagerService = roleManagerService;
	}
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws IOException {
		//得到所有权限信息
		List list=roleManagerService.findAllRoleInfo();
		//保存权限信息
		HttpSession session=request.getSession();
		session.setAttribute("Y_roinfo",list);
		//得到权限比例信息并生成并图
		List li=roleManagerService.findUserRole();
		DefaultPieDataset defaultpiedataset = new DefaultPieDataset();
		defaultpiedataset.setValue("超级管理员", Double.parseDouble(li.get(0)
				.toString()));
		defaultpiedataset.setValue("收货员", Double.parseDouble(li.get(1)
				.toString()));
		defaultpiedataset.setValue("票物员", Double.parseDouble(li.get(2)
				.toString()));
		defaultpiedataset.setValue("配送员", Double.parseDouble(li.get(3)
				.toString()));
		defaultpiedataset.setValue("财务员", Double.parseDouble(li.get(4)
				.toString()));
		defaultpiedataset.setValue("市场业务员", Double.parseDouble(li.get(5)
				.toString()));
		defaultpiedataset.setValue("数据维护员", Double.parseDouble(li.get(6)
				.toString()));
		defaultpiedataset.setValue("经理", Double.parseDouble(li.get(7)
				.toString()));

		JFreeChart jfreechart = ChartFactory.createPieChart3D("用户权限比例",
				defaultpiedataset, true, false, false);
		PiePlot3D pieplot3d = (PiePlot3D) jfreechart.getPlot();

		String imageFileName2 = ServletUtilities.saveChartAsJPEG(jfreechart,
				410, 372, session);
		//session.setAttribute("image_name2", imageFileName2);
		String URL2 = request.getContextPath() + "/display?filename="
				+ imageFileName2;

		session.setAttribute("image_urqx", URL2);
		return mapping.findForward("go");
	}
}