关于中国式报表,有兴趣的可以来看看!
中国式报表的复杂性大家都应该遇到过吧?我开发了一个工具,大家看看怎么样。我先贴一下使用的源代码,大家看看好不好用。先介绍一下基本功能,如果觉的好使,请跟贴支持!
this.branch_no = branch_no;
this.select_date = select_date;
SqlMapSession ss = sqlMap.openSession();
try {
//增加分组名称和汇总关系
this.addGroup("pol_subtype", "[sum:*]");
HashMap paramMap = new HashMap();
paramMap.put("branch_no", branch_no);
paramMap.put("oper_date", select_date);
List item_noList = new ArrayList();
item_noList.add("Y"); //期交
item_noList.add("S"); //十年期
item_noList.add("W"); //趸交
item_noList.add("P"); //续期
item_noList.add("YR"); //期交撤单
item_noList.add("WR"); //趸交撤单
item_noList.add("SR"); //十年期撤单
item_noList.add("T"); //退保
item_noList.add("D"); //标保
paramMap.put("item_noList", item_noList);
StringBuffer expr = new StringBuffer();
//sql 语句为: select a.pol_code code,b.pol_name name,
// case when b.pol_subtype = "A" then "中介代理"
// when b.pol_subtype = "F" then "基金+医疗"
// when b.pol_subtype = "J" then "健康险"
// when b.pol_subtype = "Y" then "意外险"
// when b.pol_subtype = "T" then "团体"
// when b.pol_subtype = "P" then "个险"
// end pol_subtype
// ,item_no,trunc(sum(item_num),0) item_num,trunc(sum(item_amnt),1) sum_amnt
// from mb_year_pol a,pol_code b,branch c,branch d
// where .......
// 现在的目的是将该sql语句取出的结果经下面的关系转换到报表中去
//
//带$开头的表示报表中的列(例如$A1),不带的表示sql语句中的列(例如item_num)
// 报表中的每一列的计算关系很明显
expr.append("$A3=$A3+iif(item_no=='Y',item_num,0)+iif(item_no=='YR',item_num,0);");
expr.append("$A4=$A4+iif(item_no=='Y',sum_amnt,0)+iif(item_no=='YR',sum_amnt,0);");
expr.append("$A6=$A6+iif(item_no=='W',sum_amnt,0)-iif(item_no=='WR',sum_amnt,0);");
expr.append("$A7=$A7+iif(item_no=='W',sum_amnt,0)-iif(item_no=='WR',item_num,0);");
expr.append("$A9=$A9+iif(item_no=='T',sum_amnt,0);");
expr.append("$A10=$A10+iif(item_no=='C',sum_amnt,0);");
expr.append("$A11=$A11+iif(item_no=='D',sum_amnt,0);");
expr.append("$A0=code;");
expr.append("$A1=name;");
List polDataList = null;
try {
polDataList = this.sqlMap.queryForList("get_pol_policy_data", paramMap);
}
catch (SQLException e) {
e.printStackTrace();
}
// 开始转换数据到报表中
data2Report(polDataList, expr.toString());
StringBuffer expr = new StringBuffer();
expr.append("$a0='" + branch_no + "';");
this.setRootSumLogic(expr.toString());
//求汇总
this.mass();
expr = new StringBuffer();
//报表中列与列的运算
expr.append("$a2=$a4+$a8+$a9;");
expr.append("$a5=$a4/$a3;");
for (Iterator iter = getResultList().iterator(); iter.hasNext(); ) {
Object lineData = iter.next();
ExpressionFaced.execute(expr.toString(), lineData, null, null);
}
//报表排序
this.sort("a0", false);
//针对聚合值的排序
sortByGroupValue("pol_subtype", true);
//返回结果
return this.getResultList();