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

📄 webhitdataset.java

📁 报表工具IReport的例子,实例中包括了生成pdf,html,excel等格式的报表文件.源码中包括了报表和在web上展现的源程序
💻 JAVA
字号:
/*
 * This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 *
 * ---------------------------
 * WebHitDataSet.java
 * ---------------------------
 * (C) Copyright 2002-2004, by Richard Atkinson.
 *
 * Original Author:  Richard Atkinson;
 */
package jfreechart.demo;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;

import com.hhkj.basecommon.BaseBean;

public class WebHitDataSet {
	protected ArrayList data = new ArrayList();

	Connection conn = null;

	Statement stmt = null;

	ResultSet rs = null;

	BaseBean baseBean = new BaseBean();

	public WebHitDataSet() {
	}

	public List getDataList(String beginDateP, String endDataP)
			throws Exception {
		List list = new ArrayList();
		String beginDate = "1970-01-01";
		String endDate = "2050-01-01";
		conn = baseBean.getConnection();
		String sql = "select main_dept,count(projectfile_id) from projectform where ISSUE_DATA between ";
		StringBuffer sqlBuf = new StringBuffer();
		String sqlStr = "";
		sqlBuf.append(sql + "'");
		if (beginDateP == "")
			sqlBuf.append(beginDate);
		else
			sqlBuf.append(beginDateP);
		sqlBuf.append("' and '");
		if (endDataP == "")
			sqlBuf.append(endDate);
		else
			sqlBuf.append(endDataP);
		sqlBuf.append("' group by main_dept");
		sqlStr = sqlBuf.toString();
		System.out.println(sqlStr);
		stmt = conn.createStatement();
		rs = stmt.executeQuery(sqlStr);
		while (rs.next()) {
			list.add(new WebHit(rs.getString(1), rs.getInt(2)));
		}

		return list;
	}

	public ArrayList getDataByHitDate(String filterSection) {
		ArrayList results = new ArrayList();
		HashMap dateMap = new HashMap();
		Iterator iter = this.data.listIterator();
		int currentPosition = 0;
		while (iter.hasNext()) {
			WebHit webHit = (WebHit) iter.next();
			if (filterSection == null ? true : filterSection.equals(webHit
					.getSection())) {
				Integer position = (Integer) dateMap.get(webHit.getHitDate());
				if (position == null) {
					results.add(webHit);
					dateMap.put(webHit.getHitDate(), new Integer(
							currentPosition));
					currentPosition++;
				} else {
					WebHit previousWebHit = (WebHit) results.get(position
							.intValue());
					previousWebHit.setHitCount(previousWebHit.getHitCount()
							+ webHit.getHitCount());
				}
			}

		}
		return results;
	}

	public ArrayList getDataBySection(Date filterHitDate) {
		ArrayList results = new ArrayList();
		HashMap sectionMap = new HashMap();
		Iterator iter = this.data.listIterator();
		int currentPosition = 0;
		while (iter.hasNext()) {
			WebHit webHit = (WebHit) iter.next();
			if (filterHitDate == null ? true : filterHitDate.equals(webHit
					.getHitDate())) {
				Integer position = (Integer) sectionMap
						.get(webHit.getSection());
				System.out.println("position " + position);
				if (position == null) {
					results.add(webHit);
					sectionMap.put(webHit.getSection(), new Integer(
							currentPosition));
					currentPosition++;
				} else {
					System.out.println("position2  " + position.intValue());
					WebHit previousWebHit = (WebHit) results.get(position
							.intValue());
					previousWebHit.setHitCount(previousWebHit.getHitCount()
							+ webHit.getHitCount());
				}
			}
		}
		System.out.println("currentPosition " + currentPosition);
		return results;
	}

	public ArrayList getSections() {
		ArrayList list = new ArrayList();
		list.add("Catalog");
		list.add("Checkout");
		list.add("Tracking");
		list.add("Service");
		return list;
	}

	public static void main(java.lang.String[] args) {
		try {
			WebHitDataSet whDataSet = new WebHitDataSet();
			SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy",
					Locale.UK);
			ArrayList results = whDataSet.getDataBySection(sdf
					.parse("01-Aug-2002"));
			Iterator iter = results.listIterator();
			while (iter.hasNext()) {
				WebHit wh = (WebHit) iter.next();
				System.out.println(wh.getSection() + " - " + wh.getHitCount());
			}
			System.out.println("Finished.");

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static ArrayList getDateList() {
		ArrayList dateList = new ArrayList();
		SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy", Locale.UK);
		try {
			dateList.add(sdf.parse("28-Aug-2002"));
			dateList.add(sdf.parse("27-Aug-2002"));
			dateList.add(sdf.parse("26-Aug-2002"));
			dateList.add(sdf.parse("23-Aug-2002"));
			dateList.add(sdf.parse("22-Aug-2002"));
			dateList.add(sdf.parse("21-Aug-2002"));
			dateList.add(sdf.parse("20-Aug-2002"));
			dateList.add(sdf.parse("19-Aug-2002"));
			dateList.add(sdf.parse("16-Aug-2002"));
			dateList.add(sdf.parse("15-Aug-2002"));
			dateList.add(sdf.parse("14-Aug-2002"));
			dateList.add(sdf.parse("13-Aug-2002"));
			dateList.add(sdf.parse("12-Aug-2002"));
			dateList.add(sdf.parse("09-Aug-2002"));
			dateList.add(sdf.parse("08-Aug-2002"));
			dateList.add(sdf.parse("07-Aug-2002"));
			dateList.add(sdf.parse("06-Aug-2002"));
			dateList.add(sdf.parse("05-Aug-2002"));
			dateList.add(sdf.parse("02-Aug-2002"));
			dateList.add(sdf.parse("01-Aug-2002"));
		} catch (ParseException e) {
			// ignore
		}
		return dateList;
	}

	public static ArrayList getSectionList() {
		ArrayList sectionList = new ArrayList();
		sectionList.add("Catalog");
		sectionList.add("Checkout");
		sectionList.add("Service");
		sectionList.add("Tracking");
		return sectionList;
	}

}

⌨️ 快捷键说明

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