根据输入日期通过位移方式解决包含当月的前几月自定义函数 http://reportsoft.blog.hexun.com/75077561_d.html
来源:互联网 发布:单片机编程思路 编辑:程序博客网 时间:2024/06/05 13:36
1. 需求概述
A.报表里通常会用到同期比,上年同期比。对有些零售行业的报表可能要求比较高一些,对包含当月的前3,6,12个月的一些同期比,比上年同期等,因此数据的处理和计算起来常规的同期比就更复杂一些。由于会根据当前输入的日期去定位前3,6,12个月的范围, 润乾报表内置的lastmonth只能解决上个月,多个月则需要多层嵌套,这似乎不是较好的实现方法。
B.通过业务逻辑分析,可以得出通过自定义函数利用位移的方式来满足这种数据计算应该会比较方便。
C.对当前月,前3,6,12月范围内的数据进行统计,去年前3,6,12月范围内的数据进行统计,和当前年的进行上年同期比,如图:
整个报表设计预览效果图如下:
样例左半部分:
样例右半部分:
2. 算法实现及调用规则
A.思路:
1.根据当前输入的日期,通过JAVA内置日期函数进行调整,找到要返回前几月的月初,和月末,精确到时分秒.
2.用法:monthBefore(@arg1, -3),monthAfter(@arg1, -3)
如输入arg1为: 2010-09-04,返回结果为:
2010-06-01 00:00:00
2010-06-30 23:59:59
支持正负位移,-3代表包含当月的前3月的条件,前多少月以此类推,通过位移的方式实现比较方便.避免多层嵌套的麻烦.
B:报表设计参数模板上的用法:
自定义函数的登记:
3. 程序说明
A.调用格式:monthAfter(@arg1, -3),返回前几月的月末,精确到时分秒.
package expression;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import com.runqian.base4.util.ReportError;
import com.runqian.report4.model.expression.Expression;
import com.runqian.report4.model.expression.Function;
import com.runqian.report4.model.expression.Variant2;
import com.runqian.report4.usermodel.Context;
public class monthAfter extends Function {
/**
* 解决前3月,6月,12月,月末问题
*/
public Object calculate(Context ctx, boolean inputValue) {
if (this.paramList.size() == 0)
throw new ReportError("该函数需要两个参数!");
// 取得计算表达式
Expression exp1 = (Expression) this.paramList.get(0);
if (exp1 == null)
throw new ReportError("包含有无效参数!");
Object obj1 = Variant2.getValue(exp1.calculate(ctx, inputValue),false,
false);
Expression exp2 = (Expression) this.paramList.get(1);
if (exp2 == null)
throw new ReportError("包含有无效参数!");
Object obj2 = Variant2.getValue(exp2.calculate(ctx, inputValue),false,
false);
return get3MonthAfter(String.valueOf(obj1), Integer.valueOf(String
.valueOf(obj2)));
}
public static String get3MonthAfter(String ri, int ts) {
String monthEnd = "";
try {
Calendar cal = Calendar.getInstance();
SimpleDateFormat s = new SimpleDateFormat("yyyy-MM-dd");
Date d1 = s.parse(ri);
cal.setTime(d1);
cal.add(Calendar.MONTH, ts);
cal.set(Calendar.DATE, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
Date d2 = cal.getTime();
monthEnd = s.format(d2) + " 23:59:59";// 月末
System.out.println(monthEnd);
} catch (Exception e) {
e.printStackTrace();
}
return monthEnd;
- 根据输入日期通过位移方式解决包含当月的前几月自定义函数 http://reportsoft.blog.hexun.com/75077561_d.html
- 根据输入日期通过位移方式解决包含当月的前几月自定义函数
- 根据输入日期通过位移方式解决包含当月的前几月自定义函数
- 根据输入日期通过位移方式解决包含当月的前几月自定义函数
- 根据输入日期通过位移方式解决包含当月的前几月自定义函数
- 根据输入日期通过位移方式解决包含当月的前几月自定义函数
- 根据输入日期通过位移方式解决包含当月的前几月自定义函数
- http://yanghengjun.blog.hexun.com/26226494_d.html
- http://lipingke.blog.hexun.com.tw/39367544_d.html
- DevExpress.XtraCharts.ChartControl控件的简单使用 摘自http://leo43.blog.hexun.com/36926221_d.html
- 创建一个新的Content Provider (转http://zhuyonghui116.blog.hexun.com/48780045_d.html)
- making of success(http://potato.blog.hexun.com/3690350_d.html)
- 华为EC1260-通话短信 http://majszt.blog.hexun.com/33967361_d.html
- 共享内存---shmget shmat shmdt 分享http://fengxue103.blog.hexun.com/32303320_d.html
- 【养生保健】对付身体小毛病27妙招集录http://xixipin.blog.hexun.com/17999918_d.html
- 新的blog网址为http://supercoder.blog.hexun.com/,欢迎光临!!!
- http://blog.hexun.com/lotus_west/default.aspx?page=3
- http://blog.hexun.com/lotus_west/default.aspx?page=3
- 常用软件编译参数
- bean高级特性的学习
- 命令提示符还原MYSQL数据库
- 图像算法图像特征:GLCM 原理理解 及相关
- C# 使用定时任务 之 谈谈定时器(Timer)的使用
- 根据输入日期通过位移方式解决包含当月的前几月自定义函数 http://reportsoft.blog.hexun.com/75077561_d.html
- Using Hadoop’s DistributedCache
- android listview 上下滑动背景变黑的问题解决
- tomcat5.0 java.lang.IllegalArgumentException: javacc,ant,commons-collections,log4j,junit-Extension-N
- .NET,你忘记了么?(三)——关于Array和List的使用
- linux下Nginx+tomcat整合的安装与配置
- poj 1389 线段树+扫描线 求矩形交的面积
- warning: macro `AM_PATH_GLIB_2_0' not found in library 还有 ‘AM_PATH_LIBCRYT’
- 汉字转拼音的代码