if(templateID==null)
{
result.setFailed(REPORT_TEMPLATE_ID_IS_NULL);
return result;
}
ReportTemplate template = reportTemplateDAO.findById(templateID);
if(template==null)
{
result.setFailed(REPORT_TEMPLATE_NOT_EXIST);
return result;
}
Object timeObject = properties.get("time");//获取前台传的时间
Date queryDatePar;
String queryDateParString;
if(timeObject==null||stringValue(timeObject).equalsIgnoreCase(""))//如果没有传时间
{
queryDatePar = new Date();//默认使用当前时间
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
queryDateParString = sdf.format(queryDatePar);
}
else//传时间,则解析
{
try{
queryDateParString = stringValue(timeObject);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
queryDatePar = sdf.parse(queryDateParString);
}
catch(ParseException e)
{
result.setFailed("Time Format Error!");
return result;
}
}
Object heightObject = properties.get("height");
Object widthObject = properties.get("width");
LazyDynaBean bean = new LazyDynaBean();//bean用来存储最终返回的html code
bean.set("name", template.getName());
bean.set("id", template.getId());
bean.set("time", queryDateParString);//要将时间返回前台
if(heightObject!=null)
bean.set("height", stringValue(heightObject));
if(widthObject!=null)
bean.set("width", stringValue(widthObject));
Object queryStyleObj = properties.get("action");
String queryStyle = null;
if(queryStyleObj==null)//如果前台不传刷新与否,默认不刷新
queryStyle = "unrefresh";
else queryStyle = stringValue(queryStyleObj);
DayReport dayReport = null;
MonthReport monthReport = null;
YearReport yearReport = null;
OtherReport otherReport = null;
//不是以刷新方式查询,则优先查找报表库***_report中是否有
//如有,则直接返回
String reportType = template.getReportType();
if(reportType==null||reportType.equals(""))
{
reportType="other";//默认以other处理
}
if(reportType.equalsIgnoreCase("day"))//日报表
{
DayReportId reportID = new DayReportId(template.getId(),new Timestamp(queryDatePar.getTime()));
dayReport = dayReportDAO.findById(reportID);
if(dayReport!=null&&!queryStyle.equalsIgnoreCase("refresh"))//说明在报表库中找到了该报表,直接返回
{
//不是刷新模式,则直接返回离线库中的值
bean.set("code", dayReport.getCode());
result.setData(bean);
result.setSucceed();
return result;
}
}
else if(reportType.equalsIgnoreCase("month"))//月报表
{
SimpleDateFormat sdfm = new SimpleDateFormat("yyyy-MM");
try {
String mDateString = sdfm.format(queryDatePar);
Date mDate = sdfm.parse(mDateString);//得到的日期是yyyy-MM-1
MonthReportId reportID = new MonthReportId(template.getId(), new Timestamp(mDate.getTime()));
monthReport = monthReportDAO.findById(reportID);
if(monthReport!=null&&!queryStyle.equalsIgnoreCase("refresh"))
{
//不是刷新模式,则直接返回离线库中的值
bean.set("code", monthReport.getCode());
result.setData(bean);
result.setSucceed();
return result;
}
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
result.setFailed("Time Format Error!");
return result;
}
}
else if(reportType.equalsIgnoreCase("year"))//年报表
{
SimpleDateFormat sdfy = new SimpleDateFormat("yyyy");//得到的日期是yyyy-1-1
try {
String yDateString = sdfy.format(queryDatePar);
Date yDate = sdfy.parse(stringValue(yDateString));
YearReportId reportID = new YearReportId(template.getId(), new Timestamp(yDate.getTime()));
yearReport = yearReportDAO.findById(reportID);
if(yearReport!=null&&!queryStyle.equalsIgnoreCase("refresh"))
{
//不是刷新模式,则直接返回离线库中的值
bean.set("code", yearReport.getCode());