`

Mysql各种报表查询含实例,日报,周报,月报,时间差自动计算

阅读更多
public List<IReport> retrieve(IReport report) {
		List<IReport> list = new ArrayList<IReport>();
		Map<String, Object> map = new HashMap<String, Object>();

		// 设置结束日期
		if (null != report.getEndTime()) {
			map.put(ReportMeta.PROP_ENDTIME, report.getEndTime());

			// 设置名称
			if (null != report.getName()) {
				map.put(ReportMeta.PROP_NAME, report.getName());

				// 设置问题分类子项(必须有问题分类名称)
				if (null != report.getQid() && report.getQid() > 0) {
					map.put(ReportMeta.PROP_QID, report.getQid());
				}
			}

			// 设置查询几周的数据,默认为本周,查询上周设置为:1L,依次类推
			if (null == report.getQid()) {
				report.setQid(0L);
			}
		}

		String sql = "";
		// 设置正负面的值
		String tendency = "'正面','中性','负面-中','负面-高','负面-低'";
		String hourarea = " " + dayhour + ":00:00";
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd" + hourarea);
		if (map.size() > 0) {
			// 日报数据查询
			if ("daily".equals(report.getType())) {
				sql = "select name,quantity,start_time startTime,end_time endTime from tbl_report "
						+ "where end_time between date_add(:endTime,interval :dayHour hour_second) and :endTime";

				// 日报正负面数据统计
			} else if ("daily_tendency".equals(report.getType())) {
				sql = "select name,quantity,start_time startTime,end_time endTime from tbl_report "
						+ "where end_time between date_add(:endTime,interval :dayHour hour_second) "
						+ "and :endTime and name in (:tendency)";

				// 日报问题分类数据统计
			} else if ("daily_question".equals(report.getType())) {
				sql = "select name,quantity,start_time startTime,end_time endTime from tbl_report "
						+ "where end_time between date_add(:endTime,interval :dayHour hour_second) and :endTime "
						+ "and name in (select content from tbl_keyword where type = '问题分类' and "
						+ "state = 'normal') order by quantity desc";

				// 日报问题分类子类数据统计
			} else if ("daily_question_child".equals(report.getType())) {
				sql = "select name,quantity,start_time startTime,end_time endTime,qid,description,description2 from tbl_report "
						+ "where end_time between date_add(:endTime,interval :dayHour hour_second) and :endTime "
						+ "and name in (select content from tbl_keyword where type = '问题分类子类' and "
						+ "state = 'normal') ";

				// 日报数据查询(周一:上周五15:00~本周一15:00)
			} else if ("daily_monday".equals(report.getType())) {
				sql = "select name,sum(quantity) quantity from tbl_report "
						+ "where end_time between ADDDATE(:endTime,-WEEKDAY(:endTime)-2) "
						+ "and ADDDATE(:endTime,-WEEKDAY(:endTime)) group by name";

				// 日报正负面数据统计(周一:上周五15:00~本周一15:00)
			} else if ("daily_tendency_monday".equals(report.getType())) {
				sql = "select name,sum(quantity) quantity from tbl_report "
						+ "where end_time between ADDDATE(:endTime,-WEEKDAY(:endTime)-2) "
						+ "and ADDDATE(:endTime,-WEEKDAY(:endTime)) and name in (:tendency) group by name";

				// 日报问题分类数据统计(周一:上周五15:00~本周一15:00)
			} else if ("daily_question_monday".equals(report.getType())) {
				sql = "select name,sum(quantity) quantity from tbl_report "
						+ "where end_time between ADDDATE(:endTime,-WEEKDAY(:endTime)-2) "
						+ "and ADDDATE(:endTime,-WEEKDAY(:endTime)) "
						+ "and name in (select content from tbl_keyword where type = '问题分类' and "
						+ "state = 'normal') group by name order by quantity desc";

				// 日报问题分类子类数据统计(周一:上周五15:00~本周一15:00)
			} else if ("daily_question_child_monday".equals(report.getType())) {
				sql = "select name,sum(quantity) quantity,start_time startTime,end_time endTime,qid,description,description2 from tbl_report "
						+ "where end_time between ADDDATE(:endTime,-WEEKDAY(:endTime)-2) "
						+ "and ADDDATE(:endTime,-WEEKDAY(:endTime)) "
						+ "and name in (select content from tbl_keyword where type = '问题分类子类' and "
						+ "state = 'normal') group by name";

				// 周报每天数据
			} else if ("weekly_day".equals(report.getType())) {
				sql = "select name,quantity,start_time startTime,end_time endTime from tbl_report "
						+ "where end_time between "
						+ "(select date_sub(:endTime, interval weekday(:endTime) +:plusDay day)) "
						+ "and (select date_sub(:endTime,interval weekday(:endTime) +:reduceDay day)) "
						+ "order by end_time";

				// 周报所有数据汇总
			} else if ("weekly_count".equals(report.getType())) {
				sql = "select name,sum(quantity) quantity,start_time startTime,end_time endTime from tbl_report where end_time between "
						+ "(select date_sub(:endTime,interval weekday(:endTime) +:plusDay day)) and "
						+ "(select date_sub(:endTime,interval weekday(:endTime) +:reduceDay day)) group by name";

				// 周报正负面数据汇总
			} else if ("weekly_count_tendency".equals(report.getType())) {
				sql = "select name,sum(quantity) quantity from tbl_report where end_time between "
						+ "(select date_sub(:endTime,interval weekday(:endTime) +:plusDay day)) and "
						+ "(select date_sub(:endTime,interval weekday(:endTime) +:reduceDay day)) and "
						+ "name in (:tendency) group by name";

				// 周报每天有效数据汇总(report.name="今日有效数据")
			} else if ("weekly_count_valid".equals(report.getType())) {
				// sql =
				// "select '有效数据' name,sum(quantity) quantity,end_time endTime from tbl_report "
				// +
				// "where end_time between (select date_sub(:endTime,interval weekday(:endTime) +:plusDay day)) "
				// +
				// "and (select date_sub(:endTime,interval weekday(:endTime) +:reduceDay day)) "
				// +
				// "and name in (:tendency) group by end_time order by end_time";
				sql = "select name,quantity,start_time startTime,end_time endTime from tbl_report where end_time between "
						+ "(select date_sub(:endTime,interval weekday(:endTime) +:plusDay day)) "
						+ "and (select date_sub(:endTime,interval weekday(:endTime) +:reduceDay day)) "
						+ "and name = :name group by endTime";

				// 周报问题分类数据汇总
			} else if ("weekly_count_question".equals(report.getType())) {
				sql = "select name,sum(quantity) quantity,start_time startTime,end_time endTime from tbl_report where end_time between "
						+ "(select date_sub(:endTime,interval weekday(:endTime) +:plusDay day)) and "
						+ "(select date_sub(:endTime,interval weekday(:endTime) +:reduceDay day)) and "
						+ "name in (select content from tbl_keyword where type = '问题分类' and "
						+ "state = 'normal') group by name";

				// 周报问题分类子类数据汇总
			} else if ("weekly_count_question_child".equals(report.getType())) {
				sql = "select name,sum(quantity) quantity,qid,description,description2 from tbl_report where end_time between "
						+ "(select date_sub(:endTime,interval weekday(:endTime) +:plusDay day)) and "
						+ "(select date_sub(:endTime,interval weekday(:endTime) +:reduceDay day)) and "
						+ "name in (select content from tbl_keyword where type = '问题分类子类' and "
						+ "state = 'normal') group by name";

				// 月报所用数据汇总
			} else if ("monthly_count".equals(report.getType())) {
				sql = "select name,sum(quantity) quantity from tbl_report where end_time between "
						+ "(select date_add(date_add(last_day(:endTime),interval -1 month),"
						+ "interval +15 hour)) and (select date_add(last_day(:endTime),"
						+ "interval +15 hour)) group by name";

				// 月报正负面数据汇总
			} else if ("monthly_count_tendency".equals(report.getType())) {
				sql = "select name,sum(quantity) quantity from tbl_report where end_time between "
						+ "(select date_add(date_add(last_day(:endTime),interval -1 month),"
						+ "interval +15 hour)) and (select date_add(last_day(:endTime),"
						+ "interval +15 hour)) and name in (:tendency) group by name";

				// 月报问题分类数据汇总
			} else if ("monthly_count_question".equals(report.getType())) {
				sql = "select name,sum(quantity) quantity from tbl_report where end_time between "
						+ "(select date_add(date_add(last_day(:endTime),interval -1 month),"
						+ "interval +15 hour)) and (select date_add(last_day(:endTime),"
						+ "interval +15 hour)) and name in (select content from tbl_keyword where type = '问题分类' and "
						+ "state = 'normal') group by name";

				// 月报问题分类子类数据汇总
			} else if ("monthly_count_question_child".equals(report.getType())) {
				sql = "select name,sum(quantity) quantity,qid,description,description2,description3 from tbl_report where end_time between "
						+ "(select date_add(date_add(last_day(:endTime),interval -1 month),"
						+ "interval +15 hour)) and (select date_add(last_day(:endTime),"
						+ "interval +15 hour)) and name in (select content from tbl_keyword where type = '问题分类子类' and "
						+ "state = 'normal') group by name";

			} else if ("monthly_count_valid".equals(report.getType())) {
				sql = "select name,sum(quantity) quantity,start_time startTime,end_time endTime from tbl_report where end_time between "
						+ "(select date_add(date_add(last_day(:endTime),interval -1 month),"
						+ "interval +15 hour)) and (select date_add(last_day(:endTime),"
						+ "interval +15 hour)) "
						+ "and name = :name";
				// 时间段查询正负面数据汇总
			} else if ("duration_count_tendency".equals(report.getType())) {
				sql = "select name,sum(quantity) quantity from tbl_report where end_time between "
						+ ":startTime and :endTime and name in (:tendency) group by name";

				// 时间段查询问题分类数据汇总
			} else if ("duration_count_question".equals(report.getType())) {
				sql = "select name,sum(quantity) quantity,start_time startTime,end_time endTime from tbl_report where end_time between "
						+ ":startTime and :endTime  and "
						+ "name in (select content from tbl_keyword where type = '问题分类' and "
						+ "state = 'normal') group by name";

				// 时间段查询问题分类子类数据汇总
			} else if ("duration_count_question_child".equals(report.getType())) {
				sql = "select name,sum(quantity) quantity,qid,description,description2 from tbl_report where end_time between "
						+ ":startTime and :endTime  and "
						+ "name in (select content from tbl_keyword where type = '问题分类子类' and "
						+ "state = 'normal') group by name";

				// 日报是否存在
			} else if ("is_exists".equals(report.getType())) {
				sql = "select name from tbl_report where end_time = :endTime";
			}

			sql = sql.replace(
					":startTime",
					"'"
							+ (null != report.getStartTime() ? sdf
									.format(report.getStartTime()) : "") + "'")
					.replace(":endTime",
							"'" + sdf.format(report.getEndTime()) + "'")
					.replace(":dayHour", "'-23:59:59'").replace(":plusDay",
							2 + (7 * report.getQid()) + "").replace(
							":reduceDay", -4 + (7 * report.getQid()) + "")
					.replace(":tendency", tendency).replace(
							":name",
							"'"
									+ (null != report.getName() ? report
											.getName() : "") + "'");
			list = reportDao
					.listQuery(sql, map, QueryStrType.SQL, Report.class);
		}

		return list;
	}
分享到:
评论
1 楼 123qqwe 2016-06-22  
你确定,能被看懂!!!!

相关推荐

    mysql使用实例book-MySQL

    书中会涵盖各种实例,如数据类型的选择、表的建立、数据的插入、查询、更新和删除等。例如,`INSERT INTO table_name (column1, column2) VALUES (value1, value2);`用来插入数据,而`SELECT * FROM table_name ...

    日常工作报告生成器微信小程序源码下载,支持日报,周报,月报,年终终结

    - 支持生成不同周期的工作报告,如日报、周报、月报,满足不同级别的汇报需求,用户无需根据不同时间范围重复编辑内容。 - 年终总结功能为用户提供了一次性回顾全年工作的平台,便于系统性地总结和提炼一年的工作...

    mysql数据自动生成报表软件下载

    MySQL 数据自动生成报表软件是一款基于 MySQL 数据库和 PyQt 框架的应用程序,它能够帮助用户轻松快捷地生成各种报表,以直观的方式展示数据库中的信息。这款 v1.0 版本的软件提供了多种功能,使得数据库管理和数据...

    VB6连接MySQL数据库实例含驱动和源代码

    ADO是微软开发的一套接口,用于访问各种数据源,包括MySQL。在VB6项目中,我们通常会通过引用"Microsoft ActiveX Data Objects x.x Library"来使用ADO。 1. **安装MySQL驱动**:在VB6中连接MySQL,需要MySQL的ODBC...

    水晶报表开发编程实例26个源程序实例

    它允许开发者通过图形化的用户界面来设计复杂的报表,包括数据源的连接、数据字段的选择、报表布局的设定以及各种计算和汇总功能。在这个“水晶报表开发编程实例26个源程序实例”中,我们可以深入学习和掌握水晶报表...

    C#实现Mysql数据库操作实例(含源码)

    在本文中,我们将深入探讨如何使用C#语言来实现对MySQL数据库的操作。C#是一种广泛应用于Windows和Web应用程序开发的强大...无论是初学者还是有经验的开发者,都能从这个实例中受益,提升C#与MySQL数据库的集成能力。

    C#方面水晶报表学习实例

    水晶报表是一种基于数据源的报表设计工具,能够从各种数据库、XML文件或Excel表格等数据源获取数据,并将其组织成易于阅读和分析的报表格式。在C#中,水晶报表通常作为Visual Studio的一个插件,允许开发者在设计...

    PHP+MySQL动态网站开发全程实例

    《PHP+MySQL动态网站开发全程实例》是一本深入浅出的教程,旨在帮助读者掌握使用PHP和MySQL构建动态网站的核心技术。PHP是一种广泛使用的开源脚本语言,特别适合于Web开发,而MySQL则是世界上最流行的开源关系数据库...

    Dynamic+Jasper+Mysql连接生成报表示例

    6. **生成报表**: 使用构建好的`JRDynamicReportBuilder`和`JRDataSource`生成报表实例: ```java JRDynamicFiller filler = JRDynamicFiller.getInstance(JRBeanCollectionDataSource.class.getClassLoader()); ...

    c#各种图形报表开发实例

    C#提供了ADO.NET框架,可以方便地连接到各种数据库,如SQL Server、MySQL等,获取数据并填充到报表中。此外,数据的预处理、聚合和过滤也是报表开发的重要环节,可以使用Linq或者Entity Framework等工具简化这部分...

    数据库MYSQL练习实例

    本练习实例提供了这些操作的具体示例和解答,通过实践这些例子,你可以更好地理解MySQL的语法和功能,并提升数据库操作能力。在实践中遇到问题时,可以参考解答部分找到解决方案,确保每个练习都能得到充分理解和...

    MySQL内核月报

    教程名称:MySQL内核月报课程目录:【】MySQL内核月报2014.08【】MySQL内核月报2014.09【】MySQL内核月报2014.10【】MySQL内核月报2014.11【】MySQL内核月报2014.12【】MySQL内核月报2015.01【】MySQL内核月报2015....

    MySQL常用语法与操作语句实例

    MySQL+PHP常用语法与操作语句实例MySQL+PHP常用语法与操作语句实例MySQL+PHP常用语法与操作语句实例MySQL+PHP常用语法与操作语句实例MySQL+PHP常用语法与操作语句实例MySQL+PHP常用语法与操作语句实例MySQL+PHP常用...

    Mysql的ODBC操作实例 v2

    MySQL的ODBC(Open Database Connectivity)操作实例是一个关键的技术领域,尤其对于开发人员来说,它提供了在不同数据库系统间进行数据交互的能力。本实例主要针对的是使用C++编程语言,并结合Visual Studio 2012...

    mysql实例sql文件

    MySQL是一个广泛使用的开源关系型数据库管理系统(RDBMS),它基于结构化查询语言(SQL)进行数据操作。在本主题中,我们重点关注两个关键文件——`populate.sql`和`create.sql`,它们在MySQL实例中扮演着重要的角色...

    日报表例程

    - 数据库选择:可以选择关系型数据库(如MySQL、PostgreSQL)或非关系型数据库(如MongoDB、Cassandra)来存储日报表数据,视数据结构和查询需求而定。 - 数据模型设计:确保数据模型能支持高效的查询操作,可能...

    iReport web报表开发实例

    iReport是一款强大的开源报表设计工具,它主要用于设计JasperReports报表,这些报表可以在Web应用程序中无缝集成,提供丰富的数据可视化和分析功能。本资源提供的"iReport web报表开发实例"是一份详尽的实践教程,...

    JSP使用水晶报表实例

    在IT行业中,JSP(JavaServer Pages)是一种广泛使用的服务器端脚本...这个实例应该提供了一个基础框架,你可以根据实际需求进行调整和扩展,如增加更多的数据过滤选项、自定义报表样式等,以满足各种业务场景的需求。

    c#2005与mysql连接实例

    在C# 2005开发环境中,与MySQL数据库进行交互是常见的需求。本文将详细介绍如何使用`mysql-connector-net-5.2.5`驱动程序实现C#应用程序与MySQL数据库的连接,并通过提供的示例代码`MySqlDbConn`进行讲解。首先,...

    如何在水晶报表中实现SQL 查询源程序实例,C#.net源代码编写

    报表的数据源可以是各种数据库,如SQL Server、Oracle、MySQL等,也可以是XML文件或自定义数据源。SQL查询在此过程中起到关键作用,它负责从数据库中获取所需数据。 实现步骤如下: 1. **创建水晶报表项目**:在...

Global site tag (gtag.js) - Google Analytics