package action;
import java.awt.Font;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import jxl.Workbook;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PiePlot;
import org.jfree.chart.title.LegendTitle;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.general.DefaultPieDataset;
import DAO.ScoreDAO;
import DAOImp.ScoreDAOImp;
import Util.getObject;
public class ReportAction extends BaseAction{
Object obj = getObject.getObject("ScoreDAO");
ScoreDAO sd = (ScoreDAOImp)obj;
private String month;
private String year;
private Map<String,Double> srmMap;
private Map<String,Double> sraMap;
private Map<String,Double> rdMap;
private Map<String,Double> rmMap;
private Map<String,Double> ryMap = new HashMap<String,Double>();
private JFreeChart jfchart;
public String srmchar(){
srmMap = sd.srm(month);
DefaultPieDataset dataset = new DefaultPieDataset();
Set<Entry<String,Double>> set = srmMap.entrySet();
List<Entry<String,Double>> list = new ArrayList<Entry<String,Double>>(set);
for(Entry<String,Double> e:list){
dataset.setValue(e.getKey(),e.getValue());
}
jfchart = ChartFactory.createPieChart3D("员工月销售成绩",
dataset,
true,
true,
false
);
jfchart.setTitle(new TextTitle("员工月销售成绩", new Font("黑体", Font.ITALIC,22)));
LegendTitle legend = jfchart.getLegend(0);
legend.setItemFont(new Font("宋体", Font.BOLD, 14));
PiePlot plot = (PiePlot) jfchart.getPlot();
plot.setLabelFont(new Font("隶书", Font.BOLD, 12));
plot.setBackgroundAlpha(0.9f);
plot.setForegroundAlpha(0.50f);
return "srmchar";
}
public String srachar(){
sraMap = sd.sra();
DefaultPieDataset dataset = new DefaultPieDataset();
Set<Entry<String,Double>> set = sraMap.entrySet();
List<Entry<String,Double>> list = new ArrayList<Entry<String,Double>>(set);
for(Entry<String,Double> e:list){
dataset.setValue(e.getKey(),e.getValue());
}
jfchart = ChartFactory.createPieChart3D("员工入职以来销售成绩",
dataset,
true,
true,
false
);
jfchart.setTitle(new TextTitle("员工入职以来销售成绩", new Font("黑体", Font.ITALIC,22)));
LegendTitle legend = jfchart.getLegend(0);
legend.setItemFont(new Font("宋体", Font.BOLD, 14));
PiePlot plot = (PiePlot) jfchart.getPlot();
plot.setLabelFont(new Font("隶书", Font.BOLD, 12));
plot.setBackgroundAlpha(0.9f);
plot.setForegroundAlpha(0.50f);
return "srachar";
}
public String rdchar(){
rdMap = sd.rd(year, month);
DefaultPieDataset dataset = new DefaultPieDataset();
Set<Entry<String,Double>> set = rdMap.entrySet();
List<Entry<String,Double>> list = new ArrayList<Entry<String,Double>>(set);
for(Entry<String,Double> e:list){
dataset.setValue(e.getKey(),e.getValue());
}
jfchart = ChartFactory.createPieChart3D("日销售统计",
dataset,
true,
true,
false
);
jfchart.setTitle(new TextTitle("日销售统计", new Font("黑体", Font.ITALIC,22)));
LegendTitle legend = jfchart.getLegend(0);
legend.setItemFont(new Font("宋体", Font.BOLD, 14));
PiePlot plot = (PiePlot) jfchart.getPlot();
plot.setLabelFont(new Font("隶书", Font.BOLD, 12));
plot.setBackgroundAlpha(0.9f);
plot.setForegroundAlpha(0.50f);
return "rdchar";
}
public String rmchar(){
rmMap = sd.rm(year);
DefaultPieDataset dataset = new DefaultPieDataset();
Set<Entry<String,Double>> set = rmMap.entrySet();
List<Entry<String,Double>> list = new ArrayList<Entry<String,Double>>(set);
for(Entry<String,Double> e:list){
dataset.setValue(e.getKey(),e.getValue());
}
jfchart = ChartFactory.createPieChart3D("月销售统计",
dataset,
true,
true,
false
);
jfchart.setTitle(new TextTitle("月销售统计", new Font("黑体", Font.ITALIC,22)));
LegendTitle legend = jfchart.getLegend(0);
legend.setItemFont(new Font("宋体", Font.BOLD, 14));
PiePlot plot = (PiePlot) jfchart.getPlot();
plot.setLabelFont(new Font("隶书", Font.BOLD, 12));
plot.setBackgroundAlpha(0.9f);
plot.setForegroundAlpha(0.50f);
return "rmchar";
}
public String rychar(){
ryMap = sd.ry();
DefaultPieDataset dataset = new DefaultPieDataset();
Set<Entry<String,Double>> set = ryMap.entrySet();
List<Entry<String,Double>> list = new ArrayList<Entry<String,Double>>(set);
for(Entry<String,Double> e:list){
dataset.setValue(e.getKey(),e.getValue());
}
jfchart = ChartFactory.createPieChart3D("年销售统计",
dataset,
true,
true,
false
);
jfchart.setTitle(new TextTitle("年销售统计", new Font("黑体", Font.ITALIC,22)));
LegendTitle legend = jfchart.getLegend(0);
legend.setItemFont(new Font("宋体", Font.BOLD, 14));
PiePlot plot = (PiePlot) jfchart.getPlot();
plot.setLabelFont(new Font("隶书", Font.BOLD, 12));
plot.setBackgroundAlpha(0.9f);
plot.setForegroundAlpha(0.50f);
return "rychar";
}
public String toRyExcel(){
try{
ryMap = sd.ry();
WritableWorkbook book = Workbook.createWorkbook(new File("E:\\tomcat\\webapps\\lunwen\\excel\\年销售成绩.xls"));
WritableSheet sheet = book.createSheet("年销售成绩", 0);
sheet.addCell(new Label(0,0,"年"));
sheet.addCell(new Label(1,0,"销售额"));
int i=1;
Set<Entry<String,Double>> set = ryMap.entrySet();
List<Entry<String,Double>> list = new ArrayList<Entry<String,Double>>(set);
for(Entry<String,Double> e:list){
sheet.addCell(new Label(0,i,e.getKey()));
sheet.addCell(new Label(1,i,e.getValue()+""));
i++;
}
book.write();
book.close();
}catch(Exception e){
e.printStackTrace();
}
return "ry";
}
public String toRmExcel(){
try{
rmMap = sd.rm(year);
WritableWorkbook book = Workbook.createWorkbook(new File("E:\\tomcat\\webapps\\lunwen\\excel\\月销售成绩.xls"));
WritableSheet sheet = book.createSheet("月销售成绩", 0);
sheet.addCell(new Label(0,0,"月"));
sheet.addCell(new Label(1,0,"销售额"));
int i=1;
Set<Entry<String,Double>> set = rmMap.entrySet();
List<Entry<String,Double>> list = new ArrayList<Entry<String,Double>>(set);
for(Entry<String,Double> e:list){
sheet.addCell(new Label(0,i,e.getKey()));
sheet.addCell(new Label(1,i,e.getValue()+""));
i++;
}
book.write();
book.close();
}catch(Exception e){
e.printStackTrace();
}
return "rm";
}
public String toRdExcel(){
try{
rdMap = sd.rd(year, month);
WritableWorkbook book = Workbook.createWorkbook(new File("E:\\tomcat\\webapps\\lunwen\\excel\\日销售成绩.xls"));
WritableSheet sheet = book.createSheet("日销售成绩", 0);
sheet.addCell(new Label(0,0,"日"));
sheet.addCell(new Label(1,0,"销售额"));
int i=1;
Set<Entry<String,Double>> set = rdMap.entrySet();
List<Entry<String,Double>> list = new ArrayList<Entry<String,Double>>(set);
for(Entry<String,Double> e:list){
sheet.addCell(new Label(0,i,e.getKey()));
sheet.addCell(new Label(1,i,e.getValue()+""));
i++;
}
book.write();
book.close();
}catch(Exception e){
e.printStackTrace();
}
return "rd";
}
public String toSraExcel(){
try{
sraMap = sd.sra();
WritableWorkbook book = Workbook.createWorkbook(new File("E:\\tomcat\\webapps\\lunwen\\excel\\员工入职以来成绩.xls"));
WritableSheet sheet = book.createSheet("员工入职以来成绩", 0);
sheet.addCell(new Label(0,0,"员工姓名"));
sheet.addCell(new Label(1,0,"销售额"));
int i=1;
Set<Entry<String,Double>> set = sraMap.entrySet();
List<Entry<String,Double>> list = new ArrayList<Entry<String,Double>>(set);
for(Entry<String,Double> e:lis