DownloadExcel --excel导出和下载类
package com.san.report;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.math.BigInteger;
import java.util.List;
import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFClientAnchor;
import org.apache.poi.hssf.usermodel.HSSFPatriarch;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.Region;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
/**
* 简单Excel导出工具
*
* @author shmilyLT
*
* TODO To change the template for this generated type comment go to Window -
* Preferences - Java - Code Style - Code Templates
*/
public class DownloadExcel extends DispatchAction {
/**
* Excel文件下载
* @param mapping
* @param form
* @param request
* @param response
* @return
*/
public ActionForward downloadExcel(ActionMapping mapping, ActionForm form, HttpServletRequest request,HttpServletResponse response) {
HttpSession session = request.getSession();
String outputFile = (String)session.getAttribute("outputFile");
OutputStream os = null;
FileInputStream fis = null;
File file = null;
try {
if(outputFile != null) {
file = new File(outputFile);
fis=new FileInputStream(outputFile);
String contentType = "application/octet-stream;charset=iso8859-1";
response.setContentType(contentType);
StringBuffer contentDisposition = new StringBuffer();
contentDisposition.append("attachment;");
contentDisposition.append("filename=\"");
contentDisposition.append(file.getName());
contentDisposition.append("\"");
response.setHeader("Content-Disposition", new String(
contentDisposition.toString().getBytes(
System.getProperty("file.encoding")), "iso8859-1"));
os=response.getOutputStream();
byte[] b=new byte[1024*2];
int i=0;
while((i=fis.read(b,0,b.length))>0){
//当前线程等待0.1
//Thread.sleep(100);
os.write(b,0,i);
}
}
} catch(Exception e) {
e.printStackTrace();
System.out.println("用户取消操作");
} finally {
try {
if(fis != null) {
fis.close();
}
if(os != null) {
os.close();
}
if(file != null) {
file.delete();
}
} catch(Exception e) {
}
}
return null;
}
/*****************
*
* 异步写入excel文件;
*
*
* ******************/
public static void getExcelObject(ExcelObj obj,HttpServletRequest request,HttpServletResponse response) throws Exception {
try {
if(obj == null) {
return;
}
String excelName = obj.getExcelName();//excel名称
String sheetName = obj.getSheetName();//sheet名称
String imgList1 = obj.getImg1();//图片
String bTitleList1 = obj.getBTitle1();//大标题list
List sTitleList1 = obj.getSTitle1();//小标题list
List objList1 = obj.getObj1();//内容
String imgList2 = obj.getImg2();//图片
String bTitleList2 = obj.getBTitle2();//大标题list
List sTitleList2 = obj.getSTitle2();//小标题list
List objList2 = obj.getObj2();//内容
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet(sheetName);
HSSFRow row = null;
HSSFCell cell = null;
int countX = 0;
int countY = 0;
if(bTitleList1 != null && !"".equals(bTitleList1)) {
row = sheet.createRow(countX);
cell = row.createCell((short)countY);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(bTitleList1);
if(sTitleList1 != null && sTitleList1.size() !=0) {
sheet.addMergedRegion(new Region(countX,(short)countY,countX,(short)(sTitleList1.size()-1)));
}
countX++;
countY = sTitleList1.size();
}
if(sTitleList1 != null && sTitleList1.size() !=0) {
for(int i=0;i<sTitleList1.size();i++) {
row = sheet.createRow(countX);
cell = row.createCell((short)i);
cell.setCellValue((String)sTitleList1.get(i));
}
countX++;
}
if(objList1 != null) {
for(int i=0;i<objList1.size();i++) {
Object[] o = (Object[])objList1.get(i);
for(int j=0;j<2;j++) {
row = sheet.createRow(countX);
cell = row.createCell((short)j);
if(o[j] instanceof String) {
cell.setCellValue((String)o[j]);
} else if(o[j] instanceof java.math.BigInteger) {
cell.setCellValue(((BigInteger)o[j]).toString());
}
//countY++;
}
countX++;
}
}
// ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
// BufferedImage bufferImg = ImageIO.read(new File("c:/123.jpg"));
// ImageIO.write(bufferImg,"jpeg",byteArrayOut);
// HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
// HSSFClientAnchor anchor = new HSSFClientAnchor(0,0,1,1,(short) (countY+2),1,(short)(countY+8),16);
// //HSSFClientAnchor anchor1 = new HSSFClientAnchor(0,0,512,255,(short) 0,15,(short)10,20);
// patriarch.createPicture(anchor , workbook.addPicture(byteArrayOut.toByteArray(),HSSFWorkbook.PICTURE_TYPE_JPEG));
BufferedImage bufferImg =null;
HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
HSSFClientAnchor anchor = new HSSFClientAnchor(0,0,1,1,(short) (countY+2),1,(short)(countY+8),16);
bufferImg = ImageIO.read(new File(imgList1));
ImageIO.write(bufferImg,"jpeg",byteArrayOut);
patriarch.createPicture(anchor , workbook.addPicture(byteArrayOut.toByteArray(),HSSFWorkbook.PICTURE_TYPE_JPEG));
if(objList1 != null && objList1.size() < 16) {
countX = 19;
}
countY =0;
BufferedImage bufferImg1 = null;
ByteArrayOutputStream byteArrayOut1 = new ByteArrayOutputStream();
if(imgList2 !=null && !"".equals(imgList2)){
bufferImg1 = ImageIO.read(new File(imgList2));
ImageIO.write(bufferImg1,"jpeg",byteArrayOut1);
}
int temp = 0;
if(sTitleList2 != null) {
temp = sTitleList2.size();
}
HSSFClientAnchor anchor1 = new HSSFClientAnchor(0,0,1,1,(short) (countY +2 + temp),(countX),(short)(countY+8 + temp),(countX+17));
patriarch.createPicture(anchor1 , workbook.addPicture(byteArrayOut1.toByteArray(),HSSFWorkbook.PICTURE_TYPE_JPEG));
if(bTitleList2 != null && !"".equals(bTitleList2)) {
row = sheet.createRow(countX);
cell = row.createCell((short)countY);
cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(bTitleList2);
if(sTitleList2 != null && sTitleList2.size() !=0) {
sheet.addMergedRegion(new Region(countX,(short)countY,countX,(short)(sTitleList2.size()-1)));
}
countX++;
countY += sTitleList2.size();
}
if(sTitleList2 != null && sTitleList2.size() !=0) {
for(int i=0;i<sTitleList2.size();i++) {
row = sheet.createRow(countX);
cell = row.createCell((short)i);
cell.setCellValue((String)sTitleList2.get(i));
}
countX++;
}
if(objList2 != null) {
for(int i=0;i<objList2.size();i++) {
Object[] o = (Object[])objList2.get(i);
for(int j=0;j<2;j++) {
row = sheet.createRow(countX);
cell = row.createCell((short)j);
if(o[j] instanceof String) {
cell.setCellValue((String)o[j]);
} else if(o[j] instanceof java.math.BigInteger) {
cell.setCellValue(((BigInteger)o[j]).toString());
} else if(o[j] instanceof Integer) {
cell.setCellValue(o[j].toString());
}
//countY++;
}
countX++;
}
}
excelName = InitServlet.sysPath+"exceldown\\"+ excelName+".xls";
FileOutputStream fileOut = new FileOutputStream(excelName);
workbook.write(fileOut);
if(fileOut != null) {
fileOut.close();
}
//文件下载
HttpSession session = request.getSession();
String outputFile = excelName;
session.setAttribute("outputFile", outputFile);
if(null!=imgList1 && !"".equals(imgList1)){
File file=new File(imgList1);
file.delete();
}
if(null!=imgList2 && !"".equals(imgList2)){
File file=new File(imgList2);
file.delete();
}
// OutputStream os = null;
// FileInputStream fis = null;
// File file = null;
// try {
// if(outputFile != null) {
// file = new File(outputFile);
// fis=new FileInputStream(outputFile);
// String contentType = "application/octet-stream;charset=iso8859-1";
// response.setContentType(contentType);
// StringBuffer contentDisposition = new StringBuffer();
// contentDisposition.append("attachment;");
// contentDisposition.append("filename=\"");
// contentDisposition.append(file.getName());
// contentDisposition.append("\"");
// response.setHeader("Content-Disposition", new String(
// contentDisposition.toString().getBytes(
// System.getProperty("file.encoding")), "iso8859-1"));
// os=response.getOutputStream();
// byte[] b=new byte[1024*2];
// int i=0;
// while((i=fis.read(b,0,b.length))>0){
// //当前线程等待0.1
// //Thread.sleep(100);
// os.write(b,0,i);
// }
//
// }
// } catch(Exception e) {
// e.printStackTrace();
// System.out.println("用户取消操作");
// } finally {
// try {
// if(fis != null) {
// fis.close();
// }
// if(os != null) {
// os.close();
// }
// if(file != null) {
// file.delete();
// }
// } catch(Exception e) {
//
// }
//
// }
} catch (Exception e) {
e.printStackTrace();
}
}
public static void getExcelToImg(ExcelObj obj,HttpServletRequest request,HttpServletResponse response) throws Exception {
if(obj == null) {
return;
}
String excelName = obj.getExcelName();//excel名称
String sheetName = obj.getSheetName();//sheet名称
String imgList1 = obj.getImg1();//图片
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet(sheetName);
BufferedImage bufferImg =null;
HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
HSSFClientAnchor anchor = new HSSFClientAnchor(0,0,1,1,(short) 2,2,(short)12,30);
bufferImg = ImageIO.read(new File(imgList1));
ImageIO.write(bufferImg,"jpeg",byteArrayOut);
patriarch.createPicture(anchor , workbook.addPicture(byteArrayOut.toByteArray(),HSSFWorkbook.PICTURE_TYPE_JPEG));
excelName = InitServlet.sysPath+"exceldown\\"+ excelName+".xls";
FileOutputStream fileOut = new FileOutputStream(excelName);
workbook.write(fileOut);
if(fileOut != null) {
fileOut.close();
}
//文件下载
HttpSession session = request.getSession();
String outputFile = excelName;
session.setAttribute("outputFile", outputFile);
File file=new File(imgList1);
file.delete();
}
public static void getExcelToImgAfter(ExcelObj obj) throws Exception {
if(obj == null) {
return;
}
String excelName = obj.getExcelName();//excel名称
String sheetName = obj.getSheetName();//sheet名称
String imgList1 = obj.getImg1();//图片
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet(sheetName);
BufferedImage bufferImg =null;
HSSFPatriarch patriarch = sheet.createDrawingPatriarch();
ByteArrayOutputStream byteArrayOut = new ByteArrayOutputStream();
HSSFClientAnchor anchor = new HSSFClientAnchor(0,0,1,1,(short) 2,2,(short)12,30);
bufferImg = ImageIO.read(new File(imgList1));
ImageIO.write(bufferImg,"jpeg",byteArrayOut);
patriarch.createPicture(anchor , workbook.addPicture(byteArrayOut.toByteArray(),HSSFWorkbook.PICTURE_TYPE_JPEG));
excelName = InitServlet.sysPath+"exceldown\\"+ excelName+".xls";
FileOutputStream fileOut = new FileOutputStream(excelName);
workbook.write(fileOut);
if(fileOut != null) {
fileOut.close();
}
File file=new File(InitServlet.sysPath+"JfreeImg\\"+excelName+".jpeg");
file.delete();
}
}
InitServlet----初始化类
package com.san.report;
import java.io.IOException;
import java.util.List;
import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
/**
* 初始化ApplicationContext
* @author shmilyLT
*
*/
public class InitServlet implements Servlet{
public static ApplicationContext ctx;
public static String sysPath;
public void destroy() {
}
public ServletConfig getServletConfig() {
return null;
}
public String getServletInfo() {
return null;
}
public void init(ServletConfig servlet) throws ServletException {
sysPath = servlet.getServletContext().getRealPath("/");
System.out.println("初始化系统路径成功,当前系统路径为" + sysPath);
}
public void service(ServletRequest arg0, ServletResponse arg1) throws ServletException, IOException {
}
}
PalntInIt --绘图类
package com.san.report;
import java.awt.Color;
import java.awt.Font;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.entity.StandardEntityCollection;
import org.jfree.chart.labels.StandardCategoryItemLabelGenerator;
import org.jfree.chart.plot.CategoryPlot;
import org.jfree.chart.plot.PiePlot;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.renderer.category.BarRenderer;
import org.jfree.chart.renderer.category.LineAndShapeRenderer;
import org.jfree.chart.servlet.ServletUtilities;
import org.jfree.chart.title.TextTitle;
import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.data.general.DefaultPieDataset;
import org.jfree.ui.HorizontalAlignment;
import org.jfree.ui.RectangleEdge;
public class PlantInit {
/*********
*
* @author wuwh
* vlineName代表横坐标标志;
* hlineName代表纵坐标标志名称;
*
* 曲线图的绘制;
* **********/
public static String excelName;
public static String plantCurvesLine(List list,String topName,String vlineName,String hlineName,HttpServletRequest request){
DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();
FileOutputStream fos_jpg = null;
//设置值;
int cont=list.size();
for(int i=0;i<cont;i++){
PlantTo to=(PlantTo) list.get(i);
defaultcategorydataset.addValue(to.getMapValue(), to.getMapname(), to.getMapkey());
}
//绘图到内存
JFreeChart jfreechart1 = ChartFactory.createLineChart(
topName, vlineName, hlineName,
defaultcategorydataset, PlotOrientation.VERTICAL, true, true,
true);
//头信息的设置;
TextTitle texttitle = new TextTitle(topName);
texttitle.setFont(new Font("SansSerif", 0, 10));
texttitle.setPosition(RectangleEdge.BOTTOM);
texttitle.setHorizontalAlignment(HorizontalAlignment.RIGHT);
jfreechart1.addSubtitle(texttitle);
jfreechart1.setBackgroundPaint(Color.decode("#FFCC00"));
CategoryPlot categoryplot = (CategoryPlot) jfreechart1.getPlot();
//设置纵横条的颜色;
categoryplot.setBackgroundPaint(Color.decode("#996600"));
categoryplot.setRangeGridlinePaint(Color.white);
categoryplot.setDomainGridlinePaint(Color.white);
categoryplot.setDomainGridlinesVisible(true);//显示纵线
NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer) categoryplot
.getRenderer();
lineandshaperenderer.setShapesVisible(true);
lineandshaperenderer.setDrawOutlines(true);
lineandshaperenderer.setUseFillPaint(true);
//设置两条曲线的不同颜色;
//jfreechart1.getSubtitleCount()----表示有多少条曲线;
lineandshaperenderer.setSeriesPaint(0, Color.RED);
lineandshaperenderer.setSeriesPaint(1, Color.BLUE);
lineandshaperenderer.setSeriesFillPaint(0, Color.RED);
lineandshaperenderer.setSeriesFillPaint(1, Color.BLUE);
if(null!=request.getAttribute("incont") && ""!=request.getAttribute("incont")){
lineandshaperenderer.setSeriesFillPaint(2, Color.YELLOW);
lineandshaperenderer.setSeriesFillPaint(2, Color.YELLOW);
}
lineandshaperenderer.setBaseLinesVisible(true);
String imageFile_qx=null;
try {
//向内存中绘制出真实的曲线图并且保存在session当中;
imageFile_qx = ServletUtilities.saveChartAsJPEG(jfreechart1,600,450,request.getSession());//设置生成图片,包括图片的大小,长度是500,宽是400
} catch (IOException e) {
e.printStackTrace();
}
String fullpath = InitServlet.sysPath+"JfreeImg\\"+imageFile_qx;
try {
fos_jpg = new FileOutputStream(fullpath);
ChartUtilities.writeChartAsJPEG(fos_jpg,1.0f,jfreechart1,600,450,null);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return imageFile_qx;//图片路径;
}
/******************
*
*
* @author wuwh
* 2D饼图的显示;
*
*
* ***********************/
public static String plant2DLine(List list,HttpServletRequest request,String topname){
DefaultPieDataset dfp=new DefaultPieDataset();//数据池;
FileOutputStream fos_jpg = null;
//向数据池中设置一堆数据,将其填充;
int cont=list.size();
for(int i=0;i<cont;i++){
PlantTo to=(PlantTo) list.get(i);
dfp.setValue(to.getMapkey(), to.getMapValue());
}
JFreeChart a =ChartFactory.createPieChart(topname,dfp, true, true, true);
//设置图形上面的字体,颜色,变化。。。
PiePlot pie=(PiePlot )a.getPlot();
pie.setLabelFont(new Font("SansSerif",Font.BOLD,12));
pie.setNoDataMessage("No data available");
pie.setCircular(true);
pie.setLabelGap(0.01D);//间距
//将缓存中的jfreechart对象用frame的实例显示给用户;
//PrintWriter out = response.getWriter();
ChartRenderingInfo info=new ChartRenderingInfo(new StandardEntityCollection());
String imgaeFileName_2d=null;
try {
imgaeFileName_2d = ServletUtilities.saveChartAsJPEG(a,350,300,info,request.getSession());//设置生成图片,包括图片的大小,长度是500,宽是400
} catch (IOException e) {
e.printStackTrace();
}
String fullpath = InitServlet.sysPath+"JfreeImg\\"+imgaeFileName_2d;
try {
fos_jpg = new FileOutputStream(fullpath);
ChartUtilities.writeChartAsJPEG(fos_jpg,1.0f,a,350,300,null);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
request.setAttribute("image_name_2d", imgaeFileName_2d);//保存图片的名称;
return imgaeFileName_2d;
}
/******************
*
*
* @author wuwh
* 柱状图的显示;
* vlineName代表横坐标标志;
* hlineName代表纵坐标标志名称;
*
* ***********************/
public static String planeReacgLine(List list,String topName,String vlineName,String hlineName,HttpServletRequest request){
/*********柱状图的生成**********/
int cont=list.size();
DefaultCategoryDataset dataset = new DefaultCategoryDataset();
for(int i=0;i<cont;i++){
PlantTo to=(PlantTo) list.get(i);
dataset.addValue(to.getMapValue(),i+"",to.getMapkey());//待补充。。。。。
}
JFreeChart chart=ChartFactory.createBarChart3D(topName, hlineName,vlineName, dataset, PlotOrientation.HORIZONTAL, false, true, false);
CategoryPlot plot = chart.getCategoryPlot();
final BarRenderer renderer1 = (BarRenderer) plot.getRenderer();
renderer1.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
renderer1.setItemMargin(0.01D);// 设置每个柱子之间的距离
plot.setRenderer(renderer1);
String imgaeFileName_RE=null;
try {
imgaeFileName_RE = ServletUtilities.saveChartAsJPEG(chart,600,400,request.getSession());//设置生成图片,包括图片的大小,长度是500,宽是400
} catch (IOException e) {
e.printStackTrace();
}
request.setAttribute("image_name_RE", imgaeFileName_RE);//保存图片的名称;
return imgaeFileName_RE;
}
public static String plantCurvesLineAfter(List list,String topName,String vlineName,String hlineName,String contName,String imgName){
DefaultCategoryDataset defaultcategorydataset = new DefaultCategoryDataset();
FileOutputStream fos_jpg = null;
//设置值;
int cont=list.size();
for(int i=0;i<cont;i++){
PlantTo to=(PlantTo) list.get(i);
defaultcategorydataset.addValue(to.getMapValue(), to.getMapname(), to.getMapkey());
}
//绘图到内存
JFreeChart jfreechart1 = ChartFactory.createLineChart(
topName, vlineName, hlineName,
defaultcategorydataset, PlotOrientation.VERTICAL, true, true,
true);
//头信息的设置;
TextTitle texttitle = new TextTitle(topName);
texttitle.setFont(new Font("SansSerif", 0, 10));
texttitle.setPosition(RectangleEdge.BOTTOM);
texttitle.setHorizontalAlignment(HorizontalAlignment.RIGHT);
jfreechart1.addSubtitle(texttitle);
jfreechart1.setBackgroundPaint(Color.decode("#FFCC00"));
CategoryPlot categoryplot = (CategoryPlot) jfreechart1.getPlot();
//设置纵横条的颜色;
categoryplot.setBackgroundPaint(Color.decode("#996600"));
categoryplot.setRangeGridlinePaint(Color.white);
categoryplot.setDomainGridlinePaint(Color.white);
categoryplot.setDomainGridlinesVisible(true);//显示纵线
NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
LineAndShapeRenderer lineandshaperenderer = (LineAndShapeRenderer) categoryplot
.getRenderer();
lineandshaperenderer.setShapesVisible(true);
lineandshaperenderer.setDrawOutlines(true);
lineandshaperenderer.setUseFillPaint(true);
//设置两条曲线的不同颜色;
//jfreechart1.getSubtitleCount()----表示有多少条曲线;
lineandshaperenderer.setSeriesPaint(0, Color.RED);
lineandshaperenderer.setSeriesPaint(1, Color.BLUE);
lineandshaperenderer.setSeriesFillPaint(0, Color.RED);
lineandshaperenderer.setSeriesFillPaint(1, Color.BLUE);
if(null !=contName && !"".equals(contName)){
lineandshaperenderer.setSeriesPaint(2, Color.yellow);
lineandshaperenderer.setSeriesFillPaint(2, Color.yellow);
}
String imageFile_qx=null;
lineandshaperenderer.setBaseLinesVisible(true);
Calendar calendar=Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm");
try {
Date date=df.parse(calendar.getTime().toLocaleString());
imageFile_qx=imgName+date.toLocaleString().split(" ")[0]+date.toLocaleString().split(" ")[1].split(":")[0]+""+date.toLocaleString().split(" ")[1].split(":")[1]+".jpeg";
excelName=imageFile_qx.split(".jpeg")[0];
} catch (Exception e1) {
e1.printStackTrace();
}
// try {
// //向内存中绘制出真实的曲线图并且保存在session当中;
// imageFile_qx = ServletUtilities.saveChartAsJPEG(jfreechart1,600,450,request.getSession());//设置生成图片,包括图片的大小,长度是500,宽是400
// } catch (IOException e) {
// e.printStackTrace();
// }
String fullpath = InitServlet.sysPath+"JfreeImg\\"+imageFile_qx;
try {
fos_jpg = new FileOutputStream(fullpath);
ChartUtilities.writeChartAsJPEG(fos_jpg,1.0f,jfreechart1,600,450,null);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return fullpath;//图片路径;
}
}
ReportDao--dao类
package com.san.report;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import com.san.pwms.dao.Getdao;
import com.san.tools.hibernate.config.HibernateConfig;
import com.san.tools.hibernate.session.SessionManager2;
public class ReportDao {
private SessionManager2 manager;
private static final String partid="OuLi20050823145928841";
public SessionManager2 getManager() {
return manager;
}
public void setManager(SessionManager2 manager) {
this.manager = manager;
}
public Session getSession(){
Session session=manager.getSession(HibernateConfig.getConfigFile());
return session;
}
/************
* @author wuwh
* 按周统计图;
* sarttime 代表开始时间;
* endtime 代表结束时间;
*
* *************/
public List getWeekList(String sarttime,String endtime ,String party){
Calendar calendar=Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
Session session=this.getSession();//获得session;
List sumList=new ArrayList();
if(null==party || "".equals(party)){
party=partid;
}
StringBuffer strsql=new StringBuffer();
StringBuffer strsql1=new StringBuffer();
StringBuffer strsql2=new StringBuffer();
try {
calendar.setTime(df.parse(sarttime));
String midtime=null;
for(int i=0;i<7;i++){
calendar.setTime(df.parse(sarttime));
calendar.add(Calendar.DATE,i);
calendar.setTime(df.parse(sarttime));
String timenow=calendar.getTime().toLocaleString();
calendar.add(Calendar.DATE,i+1);
String timeend=calendar.getTime().toLocaleString();
if(i==0){
strsql.append("select 'contsum'= case when sum(virusNum) is null then '0' else sum(virusNum) end , '星期"+(i+1)+"' as stattime from HostVirus_Statistic where StartTime>='"+timenow+"' and endtime<'"+timeend+"' and DeptId='"+party+"' ");
strsql1.append("select 'contsum'= case when sum(IDSNum) is null then '0' else sum(IDSNum) end , '星期"+(i+1)+"' as stattime from ObjectiveIP_IDS_Statistic where StartTime>='"+timenow+"' and endtime<'"+timeend+"' and DeptId='"+party+"' ");
strsql2.append("select 'contsum'= case when sum(IDSNum) is null then '0' else sum(IDSNum) end , '星期"+(i+1)+"' as stattime from SourceIP_IDS_Statistic where StartTime>='"+timenow+"' and endtime<'"+timeend+"' and DeptId='"+party+"' ");
}else{
strsql.append("select 'contsum'= case when sum(virusNum) is null then '0' else sum(virusNum) end , '星期"+(i+1)+"' as stattime from HostVirus_Statistic where StartTime>='"+midtime+"' and endtime<'"+timeend+"' and DeptId='"+party+"' ");
strsql1.append("select 'contsum'= case when sum(IDSNum) is null then '0' else sum(IDSNum) end , '星期"+(i+1)+"' as stattime from ObjectiveIP_IDS_Statistic where StartTime>='"+midtime+"' and endtime<'"+timeend+"' and DeptId='"+party+"' ");
strsql2.append("select 'contsum'= case when sum(IDSNum) is null then '0' else sum(IDSNum) end , '星期"+(i+1)+"' as stattime from SourceIP_IDS_Statistic where StartTime>='"+midtime+"' and endtime<'"+timeend+"' and DeptId='"+party+"' ");
}
if(i!=6){
strsql.append(" union all ");
strsql1.append(" union all ");
strsql2.append(" union all ");
}
midtime=timeend;
}
} catch (ParseException e) {
e.printStackTrace();
}
//总体病毒统计;
List listsql =session.createSQLQuery(strsql.toString()).list();
//目的地址IDS病毒统计;
List listsql1=session.createSQLQuery(strsql1.toString()).list();
//源地址IDS病毒统计;
List listsql2=session.createSQLQuery(strsql2.toString()).list();
Getdao.closeSession(session);
if(null!=listsql && !listsql.isEmpty()){
int contstr=listsql.size();
for(int i=0;i<contstr;i++){
Object [] ob=(Object[]) listsql.get(i);
PlantTo to=new PlantTo();
to.setMapValue(Integer.parseInt(ob[0].toString()));//病毒数量
to.setMapname("病毒趋势图");
to.setMapkey(ob[1].toString());//监控时间;/*ob[1].toString()*/
sumList.add(to);
}
}
//目的地址IDS病毒监控;
if(null !=listsql1 && !listsql1.isEmpty()){
int contstr=listsql1.size();
for(int i=0;i<contstr;i++){
Object [] ob=(Object[]) listsql1.get(i);
PlantTo to=new PlantTo();
to.setMapValue(Integer.parseInt(ob[0].toString()));//IDS数量
to.setMapname("目的地址IDS趋势图");
to.setMapkey(ob[1].toString());//监控时间;/*ob[1].toString()*/
sumList.add(to);
}
}
//源地址IDS病毒监控;
if(null !=listsql2 && !listsql2.isEmpty()){
int contstr=listsql2.size();
for(int i=0;i<contstr;i++){
Object [] ob=(Object[]) listsql2.get(i);
PlantTo to=new PlantTo();
to.setMapValue(Integer.parseInt(ob[0].toString()));//IDS数量
to.setMapname("源地址IDS趋势图");
to.setMapkey(ob[1].toString());//监控时间;/*ob[1].toString()*/
sumList.add(to);
}
}
return sumList;
}
/************
* @author wuwh
* 按周统计图;
* sarttime 代表开始时间;
* endtime 代表结束时间;
*
* *************/
public List getWeekList(String sarttime,String endtime ){
Calendar calendar=Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
Session session=this.getSession();//获得session;
List sumList=new ArrayList();
List list=null;
StringBuffer strsql=new StringBuffer();
StringBuffer strsql1=new StringBuffer();
try {
calendar.setTime(df.parse(sarttime));
String midtime=null;
for(int i=0;i<7;i++){
calendar.setTime(df.parse(sarttime));
calendar.add(Calendar.DATE,i);
calendar.setTime(df.parse(sarttime));
String timenow=calendar.getTime().toLocaleString();
calendar.add(Calendar.DATE,i+1);
String timeend=calendar.getTime().toLocaleString();
if(i==0){
strsql.append("select 'contsum'= case when sum(virusNum) is null then '0' else sum(virusNum) end , '星期"+(i+1)+"' as stattime from Virus_Statistic where StartTime>='"+timenow+"' and endtime<'"+timeend+"' ");
strsql1.append("select 'contsum'= case when sum(IDSNum) is null then '0' else sum(IDSNum) end , '星期"+(i+1)+"' as stattime from IDS_Statistic where StartTime>='"+timenow+"' and endtime<'"+timeend+"' ");
}else{
strsql.append("select 'contsum'= case when sum(virusNum) is null then '0' else sum(virusNum) end , '星期"+(i+1)+"' as stattime from Virus_Statistic where StartTime>='"+midtime+"' and endtime<'"+timeend+"' ");
strsql1.append("select 'contsum'= case when sum(IDSNum) is null then '0' else sum(IDSNum) end , '星期"+(i+1)+"' as stattime from IDS_Statistic where StartTime>='"+midtime+"' and endtime<'"+timeend+"' ");
}
if(i!=6){
strsql.append(" union all ");
strsql1.append(" union all ");
}
midtime=timeend;
}
} catch (ParseException e) {
e.printStackTrace();
}
//总体病毒统计;
List listsql =session.createSQLQuery(strsql.toString()).list();
//IDS病毒统计;
List listsql1=session.createSQLQuery(strsql1.toString()).list();
this.closeSession(session);
if(null!=listsql && !listsql.isEmpty()){
int contstr=listsql.size();
for(int i=0;i<contstr;i++){
Object [] ob=(Object[]) listsql.get(i);
PlantTo to=new PlantTo();
to.setMapValue(Integer.parseInt(ob[0].toString()));//病毒数量
to.setMapname("病毒趋势图");
to.setMapkey(ob[1].toString());//监控时间;/*ob[1].toString()*/
sumList.add(to);
}
}
//IDS病毒监控;
if(null !=listsql1 && !listsql1.isEmpty()){
int contstr=listsql1.size();
for(int i=0;i<contstr;i++){
Object [] ob=(Object[]) listsql1.get(i);
PlantTo to=new PlantTo();
to.setMapValue(Integer.parseInt(ob[0].toString()));//IDS数量
to.setMapname("IDS趋势图");
to.setMapkey(ob[1].toString());//监控时间;/*ob[1].toString()*/
sumList.add(to);
}
}
return sumList;
}
/****************
* @author wuwh
* 月统计病毒获取;
*
*
* ***************/
public List getMonthList(String sarttime,String endtime ,String party){
if(null==party || "".equals(party)){
party=partid;
}
Session session=this.getSession();//获得session;
List sumList=new ArrayList();
StringBuffer hsq=new StringBuffer("select sum(virusNum) as contsum ,Convert(varchar(10),StartTime,20) as datetimes from HostVirus_Statistic where 1=1 ");///总体病毒统计;
hsq.append(" and StartTime>='"+sarttime+"' and endtime<='"+endtime+"' and DeptId='"+party+"' ");
hsq.append(" group by Convert(varchar(10),StartTime,20)");
StringBuffer hsq1=new StringBuffer("select sum(IDSNum) as contsum ,Convert(varchar(10),StartTime,20) as datetimes from ObjectiveIP_IDS_Statistic where 1=1 ");//目的地址IDS病毒统计;
hsq1.append(" and StartTime>='"+sarttime+"' and endtime<='"+endtime+"' and DeptId='"+party+"' ");
hsq1.append(" group by Convert(varchar(10),StartTime,20)");
StringBuffer hsq2=new StringBuffer("select sum(IDSNum) as contsum ,Convert(varchar(10),StartTime,20) as datetimes from SourceIP_IDS_Statistic where 1=1 ");//目的地址IDS病毒统计;
hsq2.append(" and StartTime>='"+sarttime+"' and endtime<='"+endtime+"' and DeptId='"+party+"' ");
hsq2.append(" group by Convert(varchar(10),StartTime,20)");
//总体病毒统计;
List list =session.createSQLQuery(hsq.toString()).list();
//目的地址IDS病毒统计;
List list1=session.createSQLQuery(hsq1.toString()).list();
//源地址IDS病毒统计;
List list2=session.createSQLQuery(hsq2.toString()).list();
Getdao.closeSession(session);
if(null!=list && !list.isEmpty()){
int cont=list.size();
for(int i=0;i<cont;i++){
Object [] ob=(Object[]) list.get(i);
PlantTo to=new PlantTo();
to.setMapValue(Integer.parseInt(ob[0].toString()));//病毒数量
to.setMapname("病毒趋势图");
to.setMapkey(ob[1].toString());//监控时间;
sumList.add(to);
}
}
//目的IDS病毒监控;
if(null !=list1 && !list1.isEmpty()){
int cont=list1.size();
for(int i=0;i<cont;i++){
Object [] ob=(Object[]) list1.get(i);
PlantTo to=new PlantTo();
to.setMapValue(Integer.parseInt(ob[0].toString()));//IDS数量
to.setMapname("目的地址IDS趋势图");
to.setMapkey(ob[1].toString());//监控时间;
sumList.add(to);
}
}
//源IDS病毒监控;
if(null !=list2 && !list2.isEmpty()){
int cont=list2.size();
for(int i=0;i<cont;i++){
Object [] ob=(Object[]) list2.get(i);
PlantTo to=new PlantTo();
to.setMapValue(Integer.parseInt(ob[0].toString()));//IDS数量
to.setMapname("源地址IDS趋势图");
to.setMapkey(ob[1].toString());//监控时间;
sumList.add(to);
}
}
return sumList;
}
/****************
* @author wuwh
* 月统计病毒获取;
*
*
* ***************/
public List getMonthList(String sarttime,String endtime ){
Session session=this.getSession();//获得session;
List sumList=new ArrayList();
StringBuffer hsq=new StringBuffer("select sum(virusNum) as contsum ,Convert(varchar(10),StartTime,20) as datetimes from Virus_Statistic where 1=1 ");///总体病毒统计;
hsq.append(" and StartTime>='"+sarttime+"' and endtime<='"+endtime+"' ");
hsq.append(" group by Convert(varchar(10),StartTime,20)");
StringBuffer hsq1=new StringBuffer("select sum(IDSNum) as contsum ,Convert(varchar(10),StartTime,20) as datetimes from IDS_Statistic where 1=1 ");//IDS病毒统计;
hsq1.append(" and StartTime>='"+sarttime+"' and endtime<='"+endtime+"' ");
hsq1.append(" group by Convert(varchar(10),StartTime,20)");
//总体病毒统计;
List list =session.createSQLQuery(hsq.toString()).list();
//IDS病毒统计;
List list1=session.createSQLQuery(hsq1.toString()).list();
this.closeSession(session);
if(null!=list && !list.isEmpty()){
int cont=list.size();
for(int i=0;i<cont;i++){
Object [] ob=(Object[]) list.get(i);
PlantTo to=new PlantTo();
to.setMapValue(Integer.parseInt(ob[0].toString()));//病毒数量
to.setMapname("病毒趋势图");
to.setMapkey(ob[1].toString());//监控时间;
sumList.add(to);
}
}
//IDS病毒监控;
if(null !=list1 && !list1.isEmpty()){
int cont=list1.size();
for(int i=0;i<cont;i++){
Object [] ob=(Object[]) list1.get(i);
PlantTo to=new PlantTo();
to.setMapValue(Integer.parseInt(ob[0].toString()));//IDS数量
to.setMapname("IDS趋势图");
to.setMapkey(ob[1].toString());//监控时间;
sumList.add(to);
}
}
return sumList;
}
/****************
* @author wuwh
* 日统计病毒获取;
*
*
* ***************/
public List getDayList(String sarttime,String endtime ){
Session session=this.getSession();//获得session;
Calendar calendar=Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
StringBuffer strsql=new StringBuffer();
StringBuffer strsql1=new StringBuffer();
try{
calendar.setTime(df.parse(sarttime));
String midtime=null;
for(int i=0;i<24;i++){
calendar.setTime(df.parse(sarttime));
calendar.add(Calendar.HOUR,i);
calendar.setTime(df.parse(sarttime));
String timenow=calendar.getTime().toLocaleString();
calendar.add(Calendar.HOUR,i+1);
String timeend=calendar.getTime().toLocaleString();
if(i==0){
strsql.append("select 'contsum'= case when sum(virusNum) is null then '0' else sum(virusNum) end ,"+(i+1)+" as datetimes from Virus_Statistic where 1=1 and StartTime>='"+timenow+"' and endtime<'"+timeend+"'");///总体病毒统计;;
strsql1.append("select 'contsum'= case when sum(IDSNum) is null then '0' else sum(IDSNum) end ,"+(i+1)+" as datetimes from IDS_Statistic where 1=1 and StartTime>='"+timenow+"' and endtime<'"+timeend+"'");///IDS病毒统计;
}else{
strsql.append("select 'contsum'= case when sum(virusNum) is null then '0' else sum(virusNum) end ,"+(i+1)+" as datetimes from Virus_Statistic where 1=1 and StartTime>='"+midtime+"' and endtime<'"+timeend+"'");///总体病毒统计;;
strsql1.append("select 'contsum'= case when sum(IDSNum) is null then '0' else sum(IDSNum) end,"+(i+1)+" as datetimes from IDS_Statistic where 1=1 and StartTime>='"+midtime+"' and endtime<'"+timeend+"'");///IDS病毒统计;
}
if(i!=23){
strsql.append(" union all ");
strsql1.append(" union all ");
}
midtime=timeend;
}
}catch(Exception ex){
ex.printStackTrace();
}
List sumList=new ArrayList();
//总体病毒统计;
List list =session.createSQLQuery(strsql.toString()).list();
//IDS病毒统计;
List list1=session.createSQLQuery(strsql1.toString()).list();
this.closeSession(session);
if(null!=list && !list.isEmpty()){
int cont=list.size();
for(int i=0;i<cont;i++){
Object [] ob=(Object[]) list.get(i);
PlantTo to=new PlantTo();
if(null==ob[0]){
to.setMapValue(0);//病毒数量
to.setMapname("病毒趋势图");
to.setMapkey("");//监控时间;
}else{
to.setMapValue(Integer.parseInt(ob[0].toString()));//病毒数量
to.setMapname("病毒趋势图");
to.setMapkey(ob[1].toString());//监控时间;
}
sumList.add(to);
}
}
//IDS病毒监控;
if(null !=list1 && !list1.isEmpty()){
int cont=list1.size();
for(int i=0;i<cont;i++){
Object [] ob=(Object[]) list1.get(i);
PlantTo to=new PlantTo();
if(null==ob[0]){
to.setMapValue(0);//病毒数量
to.setMapname("病毒趋势图");
to.setMapkey("");//监控时间;
}else{
to.setMapValue(Integer.parseInt(ob[0].toString()));//IDS数量
to.setMapname("IDS趋势图");
to.setMapkey(ob[1].toString());//监控时间;
}
sumList.add(to);
}
}
return sumList;
}
/****************
* @author wuwh
* 日统计病毒获取;
*
*
* ***************/
public List getDayList(String sarttime,String endtime ,String party){
if(null==party || "".equals(party)){
party=partid;
}
Session session=this.getSession();//获得session;
Calendar calendar=Calendar.getInstance();
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
StringBuffer strsql=new StringBuffer();
StringBuffer strsql1=new StringBuffer();
StringBuffer strsql2=new StringBuffer();
try{
calendar.setTime(df.parse(sarttime));
String midtime=null;
for(int i=0;i<24;i++){
calendar.setTime(df.parse(sarttime));
calendar.add(Calendar.HOUR,i);
calendar.setTime(df.parse(sarttime));
String timenow=calendar.getTime().toLocaleString();
calendar.add(Calendar.HOUR,i+1);
String timeend=calendar.getTime().toLocaleString();
if(i==0){
strsql.append("select 'contsum'= case when sum(virusNum) is null then '0' else sum(virusNum) end ,"+(i+1)+" as datetimes from HostVirus_Statistic where 1=1 and StartTime>='"+timenow+"' and endtime<'"+timeend+"' and DeptId='"+party+"'");///总体病毒统计;
strsql1.append("select 'contsum'= case when sum(IDSNum) is null then '0' else sum(IDSNum) end ,"+(i+1)+" as datetimes from ObjectiveIP_IDS_Statistic where 1=1 and StartTime>='"+timenow+"' and endtime<'"+timeend+"' and DeptId='"+party+"'");//目的地址IDS病毒统计;
strsql2.append("select 'contsum'= case when sum(IDSNum) is null then '0' else sum(IDSNum) end,"+(i+1)+" as datetimes from SourceIP_IDS_Statistic where 1=1 and StartTime>='"+timenow+"' and endtime<'"+timeend+"' and DeptId='"+party+"'");//目的地址IDS病毒统计;
}else{
strsql.append("select 'contsum'= case when sum(virusNum) is null then '0' else sum(virusNum) end ,"+(i+1)+" as datetimes from HostVirus_Statistic where 1=1 and StartTime>='"+midtime+"' and endtime<'"+timeend+"' and DeptId='"+party+"'");///总体病毒统计;
strsql1.append("select 'contsum'= case when sum(IDSNum) is null then '0' else sum(IDSNum) end ,"+(i+1)+" as datetimes from ObjectiveIP_IDS_Statistic where 1=1 and StartTime>='"+midtime+"' and endtime<'"+timeend+"' and DeptId='"+party+"'");//目的地址IDS病毒统计;
strsql2.append("select 'contsum'= case when sum(IDSNum) is null then '0' else sum(IDSNum) end ,"+(i+1)+" as datetimes from SourceIP_IDS_Statistic where 1=1 and StartTime>='"+midtime+"' and endtime<'"+timeend+"' and DeptId='"+party+"'");//目的地址IDS病毒统计;
}
if(i!=23){
strsql.append(" union all ");
strsql1.append(" union all ");
strsql2.append(" union all ");
}
midtime=timeend;
}
}catch(Exception ex){
ex.printStackTrace();
}
List sumList=new ArrayList();
//总体病毒统计;
List list =session.createSQLQuery(strsql.toString()).list();
//目的地址IDS病毒统计;
List list1=session.createSQLQuery(strsql1.toString()).list();
//源地址IDS病毒统计;
List list2=session.createSQLQuery(strsql2.toString()).list();
this.closeSession(session);
if(null!=list && !list.isEmpty()){
int cont=list.size();
for(int i=0;i<cont;i++){
Object [] ob=(Object[]) list.get(i);
PlantTo to=new PlantTo();
to.setMapValue(Integer.parseInt(ob[0].toString()));//病毒数量
to.setMapname("病毒趋势图");
to.setMapkey(ob[1].toString());//监控时间;
sumList.add(to);
}
}
//目的IDS病毒监控;
if(null !=list1 && !list1.isEmpty()){
int cont=list1.size();
for(int i=0;i<cont;i++){
Object [] ob=(Object[]) list1.get(i);
PlantTo to=new PlantTo();
to.setMapValue(Integer.parseInt(ob[0].toString()));//IDS数量
to.setMapname("目的地址IDS趋势图");
to.setMapkey(ob[1].toString());//监控时间;
sumList.add(to);
}
}
//源IDS病毒监控;
if(null !=list2 && !list2.isEmpty()){
int cont=list2.size();
for(int i=0;i<cont;i++){
Object [] ob=(Object[]) list2.get(i);
PlantTo to=new PlantTo();
to.setMapValue(Integer.parseInt(ob[0].toString()));//IDS数量
to.setMapname("源地址IDS趋势图");
to.setMapkey(ob[1].toString());//监控时间;
sumList.add(to);
}
}
return sumList;
}
public void closeSession(Session s) throws HibernateException
{
if (null != s)
s.close();
}
}
RepostQuarz ---业务类
package com.san.report;
import java.io.File;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.quartz.SchedulerException;
import org.quartz.Trigger;
import org.quartz.impl.StdSchedulerFactory;
import org.quartz.Scheduler;
import org.springframework.scheduling.quartz.CronTriggerBean;
import org.springframework.web.servlet.HttpServletBean;
import com.san.report.virusstat.struts.action.VirusStatisticAction;
public class RepostQuarz {
private ReportDao dao;
private String [] getDateList(String dateType){
Calendar calendar=Calendar.getInstance();
Date now=new Date();
String nowtime=now.toLocaleString();
String time []=new String[2];
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
try {
//eg 17号
now=df.parse(nowtime);
if("day".equals(dateType)){
calendar.add(Calendar.DATE, -1);
calendar.setTime(calendar.getTime());
time[1]=calendar.getTime().toLocaleString().split(" ")[0]+" 0:00:00";//则为16号
calendar.add(Calendar.DATE, -1);
time[0]=calendar.getTime().toLocaleString().split(" ")[0]+" 0:00:00";//则为15号;
}else if("week".equals(dateType)){
calendar.set(Calendar.DAY_OF_WEEK,Calendar.MONDAY);
calendar.setTime(calendar.getTime());
calendar.add(Calendar.DATE, -1);
calendar.setTime(calendar.getTime());
time[1]=calendar.getTime().toLocaleString().split(" ")[0]+" 0:00:00";
calendar.add(Calendar.DATE, -6);
time[0]=calendar.getTime().toLocaleString().split(" ")[0]+" 0:00:00";//则为15号;
}else{
calendar.add(Calendar.MONTH, -1);
calendar.setTime(calendar.getTime());
calendar.set(Calendar.DAY_OF_MONTH,1);//设置为1号,当前日期既为本月第一天
time[0]=calendar.getTime().toLocaleString().split(" ")[0]+" 0:00:00";
calendar.add(Calendar.MONTH,1);//月增加1天
calendar.add(Calendar.DAY_OF_MONTH,-1);//日期倒数一日,既得到本月最后一天
time[1]=calendar.getTime().toLocaleString().split(" ")[0]+" 0:00:00";
}
} catch (ParseException e) {
e.printStackTrace();
}
return time;
}
/***************
*
*
* 按每日的一个固定时间导出数据;
*
*
* ***********************/
public void QuarzprintDay(){
String [] time=this.getDateList("day");
List sumList=dao.getDayList(time[0], time[1]);
List sumList1=dao.getDayList(time[0], time[1],"");
String img_url=PlantInit.plantCurvesLineAfter(sumList, "病毒、IDS趋势图","时间", "安全事件指数", "","病毒IDS(日)");
ExcelObj obj=new ExcelObj();
obj.setImg1(img_url);
obj.setSheetName("IDS、病毒综合曲线图");
obj.setExcelName(PlantInit.excelName);
String img_url1=PlantInit.plantCurvesLineAfter(sumList1, "部门病毒、IDS趋势图","时间", "安全事件指数", "cont","部门病毒IDS(日)");
ExcelObj obj1=new ExcelObj();
obj1.setImg1(img_url1);
obj1.setSheetName("部门IDS、病毒综合曲线图");
obj1.setExcelName(PlantInit.excelName);
try {
DownloadExcel.getExcelToImgAfter(obj);
DownloadExcel.getExcelToImgAfter(obj1);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("按每日统计。。。。。。。。。。。。。。");
}
/***************
*
*
* 按每周的一个固定时间导出数据;
*
*
* ***********************/
public void QuarzprintWeek(){
String [] time=this.getDateList("week");
List sumList=dao.getWeekList(time[0], time[1]);
List sumList1=dao.getWeekList(time[0], time[1],"");
String img_url=PlantInit.plantCurvesLineAfter(sumList, "病毒、IDS趋势图","时间", "安全事件指数", "","病毒IDS(周)");
ExcelObj obj=new ExcelObj();
obj.setImg1(img_url);
obj.setSheetName("IDS、病毒综合曲线图(周)");
obj.setExcelName(PlantInit.excelName);
String img_url1=PlantInit.plantCurvesLineAfter(sumList1, "部门病毒、IDS趋势图","时间", "安全事件指数", "cont","部门病毒IDS(周)");
ExcelObj obj1=new ExcelObj();
obj1.setImg1(img_url1);
obj1.setSheetName("部门IDS、病毒综合曲线图(周)");
obj1.setExcelName(PlantInit.excelName);
try {
DownloadExcel.getExcelToImgAfter(obj);
DownloadExcel.getExcelToImgAfter(obj1);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("按每周统计。。。。。。。。。。。。。。");
}
/***************
*
*
* 按每月的一个固定时间导出数据;
*
*
* ***********************/
public void QuarzprintMonth(){
String [] time=this.getDateList("month");
List sumList=dao.getMonthList(time[0], time[1]);
List sumList1=dao.getMonthList(time[0], time[1],"");
String img_url=PlantInit.plantCurvesLineAfter(sumList, "病毒、IDS趋势图","时间", "安全事件指数", "","病毒IDS(月)");
ExcelObj obj=new ExcelObj();
obj.setImg1(img_url);
obj.setSheetName("IDS、病毒综合曲线图(月)");
obj.setExcelName(PlantInit.excelName);
String img_url1=PlantInit.plantCurvesLineAfter(sumList1, "部门病毒、IDS趋势图","时间", "安全事件指数", "cont","部门病毒IDS(月)");
ExcelObj obj1=new ExcelObj();
obj1.setImg1(img_url1);
obj1.setSheetName("部门IDS、病毒综合曲线图(月)");
obj1.setExcelName(PlantInit.excelName);
try {
DownloadExcel.getExcelToImgAfter(obj);
DownloadExcel.getExcelToImgAfter(obj1);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("按每月统计。。。。。。。。。。。。。。");
}
public ReportDao getDao() {
return dao;
}
public void setDao(ReportDao dao) {
this.dao = dao;
}
public static void main(String args []){
File file=new File("D:\\Program Files\\jboss3.2.5\\server\\default\\deploy\\web.war\\exceldown");
String [] str=file.list();
for(int i=0;i<str.length;i++){
String strname=str[i];
String st []=strname.split("-");
String time=st[0].substring(st[0].length()-4)+"-"+st[1]+"-"+st[2].substring(0,2);
if(time.equals("2007-12-17")){
System.out.println(strname);
}
}
//file.delete();
}
}