parent
b693da98fd
commit
19896db778
28 changed files with 559 additions and 416 deletions
@ -1,85 +1,85 @@ |
||||
package org.springblade.desk.energy.util; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.videasoft.configs.EnumConfiger; |
||||
import com.videasoft.configs.XmlConfigReader; |
||||
import jakarta.annotation.PostConstruct; |
||||
import org.springframework.stereotype.Component; |
||||
|
||||
import java.text.MessageFormat; |
||||
import java.util.LinkedHashMap; |
||||
import java.util.Map; |
||||
@Component |
||||
public class Configer { |
||||
private static final Map<String, String> configerMap = new LinkedHashMap(); |
||||
private static final Map<String, EnumConfiger> enumConfigerMap = new LinkedHashMap(); |
||||
|
||||
public Configer() { |
||||
} |
||||
|
||||
public static String getValue(String code) { |
||||
return (String)configerMap.get(code); |
||||
} |
||||
|
||||
public static String getValue(String code, String defaultValue) { |
||||
String v = getValue(code); |
||||
return v == null ? defaultValue : v; |
||||
} |
||||
|
||||
public static String getValue(String id, String[] args) { |
||||
String value = getValue(id); |
||||
if (value != null) { |
||||
value = MessageFormat.format(value, (Object[])args); |
||||
} |
||||
|
||||
return value; |
||||
} |
||||
|
||||
public static EnumConfiger getEnumConfiger(String id) { |
||||
return (EnumConfiger)enumConfigerMap.get(id); |
||||
} |
||||
|
||||
public static String getEnumValue(String id, String code) { |
||||
String enumValue = null; |
||||
EnumConfiger enumConfiger = getEnumConfiger(id); |
||||
if (enumConfiger != null) { |
||||
enumValue = enumConfiger.getEnumValue(code); |
||||
} |
||||
|
||||
return enumValue; |
||||
} |
||||
|
||||
public static String getEnumValue(String id, String code, String[] args) { |
||||
String enumValue = getEnumValue(id, code); |
||||
if (enumValue != null) { |
||||
enumValue = MessageFormat.format(enumValue, (Object[])args); |
||||
} |
||||
|
||||
return enumValue; |
||||
} |
||||
|
||||
public static JSONObject getJsonEnum(String id) { |
||||
JSONObject json = new JSONObject(); |
||||
EnumConfiger enumConfiger = getEnumConfiger(id); |
||||
if (enumConfiger != null) { |
||||
json.putAll(enumConfiger.getOption()); |
||||
} |
||||
|
||||
return json; |
||||
} |
||||
@PostConstruct |
||||
public static void init() { |
||||
XmlConfigReader loader = new XmlConfigReader(); |
||||
configerMap.clear(); |
||||
configerMap.putAll(loader.loadKeyValues()); |
||||
enumConfigerMap.clear(); |
||||
enumConfigerMap.putAll(loader.loadEnumConfigs()); |
||||
} |
||||
|
||||
public static void appendLoad(XmlConfigReader reader) { |
||||
if (reader != null) { |
||||
configerMap.putAll(reader.loadKeyValues()); |
||||
enumConfigerMap.putAll(reader.loadEnumConfigs()); |
||||
} |
||||
} |
||||
} |
||||
//package org.springblade.desk.energy.util;
|
||||
//
|
||||
//import com.alibaba.fastjson.JSONObject;
|
||||
//import com.videasoft.configs.EnumConfiger;
|
||||
//import com.videasoft.configs.XmlConfigReader;
|
||||
//import jakarta.annotation.PostConstruct;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//
|
||||
//import java.text.MessageFormat;
|
||||
//import java.util.LinkedHashMap;
|
||||
//import java.util.Map;
|
||||
//@Component
|
||||
//public class Configer {
|
||||
// private static final Map<String, String> configerMap = new LinkedHashMap();
|
||||
// private static final Map<String, EnumConfiger> enumConfigerMap = new LinkedHashMap();
|
||||
//
|
||||
// public Configer() {
|
||||
// }
|
||||
//
|
||||
// public static String getValue(String code) {
|
||||
// return (String)configerMap.get(code);
|
||||
// }
|
||||
//
|
||||
// public static String getValue(String code, String defaultValue) {
|
||||
// String v = getValue(code);
|
||||
// return v == null ? defaultValue : v;
|
||||
// }
|
||||
//
|
||||
// public static String getValue(String id, String[] args) {
|
||||
// String value = getValue(id);
|
||||
// if (value != null) {
|
||||
// value = MessageFormat.format(value, (Object[])args);
|
||||
// }
|
||||
//
|
||||
// return value;
|
||||
// }
|
||||
//
|
||||
// public static EnumConfiger getEnumConfiger(String id) {
|
||||
// return (EnumConfiger)enumConfigerMap.get(id);
|
||||
// }
|
||||
//
|
||||
// public static String getEnumValue(String id, String code) {
|
||||
// String enumValue = null;
|
||||
// EnumConfiger enumConfiger = getEnumConfiger(id);
|
||||
// if (enumConfiger != null) {
|
||||
// enumValue = enumConfiger.getEnumValue(code);
|
||||
// }
|
||||
//
|
||||
// return enumValue;
|
||||
// }
|
||||
//
|
||||
// public static String getEnumValue(String id, String code, String[] args) {
|
||||
// String enumValue = getEnumValue(id, code);
|
||||
// if (enumValue != null) {
|
||||
// enumValue = MessageFormat.format(enumValue, (Object[])args);
|
||||
// }
|
||||
//
|
||||
// return enumValue;
|
||||
// }
|
||||
//
|
||||
// public static JSONObject getJsonEnum(String id) {
|
||||
// JSONObject json = new JSONObject();
|
||||
// EnumConfiger enumConfiger = getEnumConfiger(id);
|
||||
// if (enumConfiger != null) {
|
||||
// json.putAll(enumConfiger.getOption());
|
||||
// }
|
||||
//
|
||||
// return json;
|
||||
// }
|
||||
// @PostConstruct
|
||||
// public static void init() {
|
||||
// XmlConfigReader loader = new XmlConfigReader();
|
||||
// configerMap.clear();
|
||||
// configerMap.putAll(loader.loadKeyValues());
|
||||
// enumConfigerMap.clear();
|
||||
// enumConfigerMap.putAll(loader.loadEnumConfigs());
|
||||
// }
|
||||
//
|
||||
// public static void appendLoad(XmlConfigReader reader) {
|
||||
// if (reader != null) {
|
||||
// configerMap.putAll(reader.loadKeyValues());
|
||||
// enumConfigerMap.putAll(reader.loadEnumConfigs());
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
@ -1,165 +1,165 @@ |
||||
package org.springblade.desk.energy.util; |
||||
|
||||
import com.videasoft.utils.other.Function; |
||||
import com.videasoft.webframework.common.web.report.HtmlExporterUtil; |
||||
import com.videasoft.webframework.common.web.report.ReportModel; |
||||
import com.videasoft.webframework.configs.ReportInfoReader; |
||||
import jakarta.servlet.ServletOutputStream; |
||||
import jakarta.servlet.http.HttpServletRequest; |
||||
import jakarta.servlet.http.HttpServletResponse; |
||||
import net.sf.jasperreports.engine.JRException; |
||||
import net.sf.jasperreports.engine.JasperExportManager; |
||||
import net.sf.jasperreports.engine.JasperPrint; |
||||
import net.sf.jasperreports.engine.export.ooxml.JRXlsxExporter; |
||||
import net.sf.jasperreports.export.ExporterInput; |
||||
import net.sf.jasperreports.export.OutputStreamExporterOutput; |
||||
import net.sf.jasperreports.export.SimpleExporterInput; |
||||
import net.sf.jasperreports.export.SimpleOutputStreamExporterOutput; |
||||
import org.apache.commons.lang3.StringUtils; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.io.IOException; |
||||
import java.io.OutputStream; |
||||
import java.io.PrintWriter; |
||||
import java.io.UnsupportedEncodingException; |
||||
import java.net.URLEncoder; |
||||
import java.util.HashMap; |
||||
import java.util.Iterator; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
@Service |
||||
public class ExportUtil { |
||||
public void export(String reportId, short exportType, String fileName, Object data, Map<String, Object> params, HttpServletRequest request, HttpServletResponse response) { |
||||
if (params == null) { |
||||
params = new HashMap(); |
||||
} |
||||
|
||||
try { |
||||
Map<String, ReportModel> reports = ReportInfoReader.getReport(); |
||||
JasperPrint jp = JasperReportUtil.getJasperPrint(reportId, data, (Map)params); |
||||
ReportModel rm = (ReportModel)reports.get(reportId); |
||||
if (StringUtils.isBlank(fileName)) { |
||||
fileName = Function.toUtf8String(rm.getReportName()); |
||||
} |
||||
|
||||
if (0 == exportType) { |
||||
fileName = fileName + ".xlsx"; |
||||
fileName= URLEncoder.encode(fileName,"UTF-8"); |
||||
this.exportExcel(jp, fileName, response); |
||||
} else if (1 == exportType) { |
||||
fileName = fileName + ".pdf"; |
||||
fileName= URLEncoder.encode(fileName,"UTF-8"); |
||||
this.exportPdf(jp, fileName, response); |
||||
} else if (3 == exportType) { |
||||
this.exportHtml(jp, response); |
||||
} |
||||
} catch (Exception var12) { |
||||
var12.printStackTrace(); |
||||
} |
||||
|
||||
} |
||||
protected void exportExcel(Object jasperPrint, String fileName, HttpServletResponse response) { |
||||
OutputStream out = null; |
||||
|
||||
try { |
||||
out = this.getExportStream("application/vnd.ms-excel", fileName, response); |
||||
JRXlsxExporter exporter = new JRXlsxExporter(); |
||||
ExporterInput exporterInput = null; |
||||
if (jasperPrint instanceof JasperPrint) { |
||||
exporterInput = new SimpleExporterInput((JasperPrint)jasperPrint); |
||||
} else if (jasperPrint instanceof List) { |
||||
exporterInput = SimpleExporterInput.getInstance((List)jasperPrint); |
||||
} |
||||
|
||||
exporter.setExporterInput(exporterInput); |
||||
OutputStreamExporterOutput exporterOutput = new SimpleOutputStreamExporterOutput(response.getOutputStream()); |
||||
exporter.setExporterOutput(exporterOutput); |
||||
exporter.exportReport(); |
||||
} catch (JRException var20) { |
||||
var20.getMessage(); |
||||
} catch (UnsupportedEncodingException var21) { |
||||
var21.printStackTrace(); |
||||
var21.getMessage(); |
||||
} catch (IOException var22) { |
||||
var22.printStackTrace(); |
||||
var22.getMessage(); |
||||
} finally { |
||||
if (out != null) { |
||||
try { |
||||
out.flush(); |
||||
out.close(); |
||||
} catch (IOException var19) { |
||||
var19.printStackTrace(); |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
} |
||||
private void exportPdf(Object jasperPrint, String fileName, HttpServletResponse response) { |
||||
try { |
||||
OutputStream ouputStream = this.getExportStream("application/pdf", fileName, response); |
||||
if (jasperPrint instanceof JasperPrint) { |
||||
JasperExportManager.exportReportToPdfStream((JasperPrint)jasperPrint, ouputStream); |
||||
} else if (jasperPrint instanceof List) { |
||||
List<JasperPrint> list = (List)jasperPrint; |
||||
if (list != null && list.size() > 0) { |
||||
Iterator var6 = list.iterator(); |
||||
|
||||
while(var6.hasNext()) { |
||||
JasperPrint jp = (JasperPrint)var6.next(); |
||||
JasperExportManager.exportReportToPdfStream(jp, ouputStream); |
||||
} |
||||
} |
||||
} |
||||
|
||||
ouputStream.flush(); |
||||
ouputStream.close(); |
||||
} catch (Exception var8) { |
||||
var8.getMessage(); |
||||
} |
||||
|
||||
} |
||||
protected void exportHtml(Object jasperPrint, HttpServletResponse response) { |
||||
PrintWriter printWriter = null; |
||||
|
||||
try { |
||||
response.setCharacterEncoding("UTF-8"); |
||||
response.setContentType("text/html"); |
||||
printWriter = response.getWriter(); |
||||
HtmlExporterUtil exporter = new HtmlExporterUtil(jasperPrint, printWriter); |
||||
exporter.exportReport(); |
||||
} catch (JRException var9) { |
||||
var9.getMessage(); |
||||
} catch (IOException var10) { |
||||
var10.getMessage(); |
||||
} finally { |
||||
printWriter.close(); |
||||
} |
||||
|
||||
} |
||||
|
||||
protected OutputStream getExportStream(String contentType, String fileName, HttpServletResponse response) { |
||||
String ct = "application/octet-stream"; |
||||
if (contentType != null) { |
||||
ct = contentType; |
||||
} |
||||
|
||||
ServletOutputStream out = null; |
||||
|
||||
try { |
||||
response.setCharacterEncoding("UTF-8"); |
||||
response.setContentType(ct); |
||||
if (fileName != null && fileName.trim().length() > 0) { |
||||
response.setHeader("Content-Disposition", "attachment;filename=" + fileName); |
||||
} |
||||
|
||||
response.setBufferSize(2048); |
||||
out = response.getOutputStream(); |
||||
} catch (IOException var7) { |
||||
var7.getMessage(); |
||||
} |
||||
|
||||
return out; |
||||
} |
||||
} |
||||
//package org.springblade.desk.energy.util;
|
||||
//
|
||||
//import com.videasoft.utils.other.Function;
|
||||
//import com.videasoft.webframework.common.web.report.HtmlExporterUtil;
|
||||
//import com.videasoft.webframework.common.web.report.ReportModel;
|
||||
//import com.videasoft.webframework.configs.ReportInfoReader;
|
||||
//import jakarta.servlet.ServletOutputStream;
|
||||
//import jakarta.servlet.http.HttpServletRequest;
|
||||
//import jakarta.servlet.http.HttpServletResponse;
|
||||
//import net.sf.jasperreports.engine.JRException;
|
||||
//import net.sf.jasperreports.engine.JasperExportManager;
|
||||
//import net.sf.jasperreports.engine.JasperPrint;
|
||||
//import net.sf.jasperreports.engine.export.ooxml.JRXlsxExporter;
|
||||
//import net.sf.jasperreports.export.ExporterInput;
|
||||
//import net.sf.jasperreports.export.OutputStreamExporterOutput;
|
||||
//import net.sf.jasperreports.export.SimpleExporterInput;
|
||||
//import net.sf.jasperreports.export.SimpleOutputStreamExporterOutput;
|
||||
//import org.apache.commons.lang3.StringUtils;
|
||||
//import org.springframework.stereotype.Service;
|
||||
//
|
||||
//import java.io.IOException;
|
||||
//import java.io.OutputStream;
|
||||
//import java.io.PrintWriter;
|
||||
//import java.io.UnsupportedEncodingException;
|
||||
//import java.net.URLEncoder;
|
||||
//import java.util.HashMap;
|
||||
//import java.util.Iterator;
|
||||
//import java.util.List;
|
||||
//import java.util.Map;
|
||||
//@Service
|
||||
//public class ExportUtil {
|
||||
// public void export(String reportId, short exportType, String fileName, Object data, Map<String, Object> params, HttpServletRequest request, HttpServletResponse response) {
|
||||
// if (params == null) {
|
||||
// params = new HashMap();
|
||||
// }
|
||||
//
|
||||
// try {
|
||||
// Map<String, ReportModel> reports = ReportInfoReader.getReport();
|
||||
// JasperPrint jp = JasperReportUtil.getJasperPrint(reportId, data, (Map)params);
|
||||
// ReportModel rm = (ReportModel)reports.get(reportId);
|
||||
// if (StringUtils.isBlank(fileName)) {
|
||||
// fileName = Function.toUtf8String(rm.getReportName());
|
||||
// }
|
||||
//
|
||||
// if (0 == exportType) {
|
||||
// fileName = fileName + ".xlsx";
|
||||
// fileName= URLEncoder.encode(fileName,"UTF-8");
|
||||
// this.exportExcel(jp, fileName, response);
|
||||
// } else if (1 == exportType) {
|
||||
// fileName = fileName + ".pdf";
|
||||
// fileName= URLEncoder.encode(fileName,"UTF-8");
|
||||
// this.exportPdf(jp, fileName, response);
|
||||
// } else if (3 == exportType) {
|
||||
// this.exportHtml(jp, response);
|
||||
// }
|
||||
// } catch (Exception var12) {
|
||||
// var12.printStackTrace();
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// protected void exportExcel(Object jasperPrint, String fileName, HttpServletResponse response) {
|
||||
// OutputStream out = null;
|
||||
//
|
||||
// try {
|
||||
// out = this.getExportStream("application/vnd.ms-excel", fileName, response);
|
||||
// JRXlsxExporter exporter = new JRXlsxExporter();
|
||||
// ExporterInput exporterInput = null;
|
||||
// if (jasperPrint instanceof JasperPrint) {
|
||||
// exporterInput = new SimpleExporterInput((JasperPrint)jasperPrint);
|
||||
// } else if (jasperPrint instanceof List) {
|
||||
// exporterInput = SimpleExporterInput.getInstance((List)jasperPrint);
|
||||
// }
|
||||
//
|
||||
// exporter.setExporterInput(exporterInput);
|
||||
// OutputStreamExporterOutput exporterOutput = new SimpleOutputStreamExporterOutput(response.getOutputStream());
|
||||
// exporter.setExporterOutput(exporterOutput);
|
||||
// exporter.exportReport();
|
||||
// } catch (JRException var20) {
|
||||
// var20.getMessage();
|
||||
// } catch (UnsupportedEncodingException var21) {
|
||||
// var21.printStackTrace();
|
||||
// var21.getMessage();
|
||||
// } catch (IOException var22) {
|
||||
// var22.printStackTrace();
|
||||
// var22.getMessage();
|
||||
// } finally {
|
||||
// if (out != null) {
|
||||
// try {
|
||||
// out.flush();
|
||||
// out.close();
|
||||
// } catch (IOException var19) {
|
||||
// var19.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// private void exportPdf(Object jasperPrint, String fileName, HttpServletResponse response) {
|
||||
// try {
|
||||
// OutputStream ouputStream = this.getExportStream("application/pdf", fileName, response);
|
||||
// if (jasperPrint instanceof JasperPrint) {
|
||||
// JasperExportManager.exportReportToPdfStream((JasperPrint)jasperPrint, ouputStream);
|
||||
// } else if (jasperPrint instanceof List) {
|
||||
// List<JasperPrint> list = (List)jasperPrint;
|
||||
// if (list != null && list.size() > 0) {
|
||||
// Iterator var6 = list.iterator();
|
||||
//
|
||||
// while(var6.hasNext()) {
|
||||
// JasperPrint jp = (JasperPrint)var6.next();
|
||||
// JasperExportManager.exportReportToPdfStream(jp, ouputStream);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// ouputStream.flush();
|
||||
// ouputStream.close();
|
||||
// } catch (Exception var8) {
|
||||
// var8.getMessage();
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// protected void exportHtml(Object jasperPrint, HttpServletResponse response) {
|
||||
// PrintWriter printWriter = null;
|
||||
//
|
||||
// try {
|
||||
// response.setCharacterEncoding("UTF-8");
|
||||
// response.setContentType("text/html");
|
||||
// printWriter = response.getWriter();
|
||||
// HtmlExporterUtil exporter = new HtmlExporterUtil(jasperPrint, printWriter);
|
||||
// exporter.exportReport();
|
||||
// } catch (JRException var9) {
|
||||
// var9.getMessage();
|
||||
// } catch (IOException var10) {
|
||||
// var10.getMessage();
|
||||
// } finally {
|
||||
// printWriter.close();
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//
|
||||
// protected OutputStream getExportStream(String contentType, String fileName, HttpServletResponse response) {
|
||||
// String ct = "application/octet-stream";
|
||||
// if (contentType != null) {
|
||||
// ct = contentType;
|
||||
// }
|
||||
//
|
||||
// ServletOutputStream out = null;
|
||||
//
|
||||
// try {
|
||||
// response.setCharacterEncoding("UTF-8");
|
||||
// response.setContentType(ct);
|
||||
// if (fileName != null && fileName.trim().length() > 0) {
|
||||
// response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
|
||||
// }
|
||||
//
|
||||
// response.setBufferSize(2048);
|
||||
// out = response.getOutputStream();
|
||||
// } catch (IOException var7) {
|
||||
// var7.getMessage();
|
||||
// }
|
||||
//
|
||||
// return out;
|
||||
// }
|
||||
//}
|
||||
|
||||
@ -1,115 +1,115 @@ |
||||
package org.springblade.desk.energy.util; |
||||
|
||||
import com.videasoft.utils.other.Function; |
||||
import com.videasoft.utils.reader.PathReader; |
||||
import com.videasoft.webframework.common.web.report.JasperReportUtils; |
||||
import com.videasoft.webframework.common.web.report.PrintData; |
||||
import com.videasoft.webframework.common.web.report.ReportModel; |
||||
import com.videasoft.webframework.common.web.report.SubReportModel; |
||||
import com.videasoft.webframework.configs.ReportInfoReader; |
||||
import net.sf.jasperreports.engine.JasperFillManager; |
||||
import net.sf.jasperreports.engine.JasperPrint; |
||||
import net.sf.jasperreports.engine.JasperReport; |
||||
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource; |
||||
import net.sf.jasperreports.engine.util.JRLoader; |
||||
import org.slf4j.Logger; |
||||
import org.slf4j.LoggerFactory; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import java.io.InputStream; |
||||
import java.util.*; |
||||
@Service |
||||
public class JasperReportUtil { |
||||
|
||||
|
||||
protected static final Logger logger = LoggerFactory.getLogger(JasperReportUtils.class); |
||||
|
||||
public JasperReportUtil() { |
||||
} |
||||
|
||||
public static final ReportModel getReportModel(String reportId) throws Exception { |
||||
return ReportInfoReader.getReportModel(reportId); |
||||
} |
||||
|
||||
public static final JasperPrint getJasperPrint(String reportId, Object data, Map<String, Object> params) throws Exception { |
||||
ReportModel rm = ReportInfoReader.getReportModel(reportId); |
||||
if (rm == null) { |
||||
throw new Exception("找不到报表模板定义"); |
||||
} else { |
||||
Collection<?> mainData = null; |
||||
if (data instanceof Collection) { |
||||
mainData = (Collection)data; |
||||
} else { |
||||
mainData = new ArrayList(1); |
||||
((List)mainData).add(data); |
||||
} |
||||
|
||||
if (params == null) { |
||||
params = new HashMap(); |
||||
} |
||||
|
||||
JasperReport jr = rm.getJasperRoport(); |
||||
InputStream inputStream = PathReader.class.getResourceAsStream(rm.getTemplatePath()); |
||||
if (inputStream == null) { |
||||
logger.error("读取打印模版:" + rm.getTemplatePath() + "出错,文件可能不存在!"); |
||||
return null; |
||||
} else { |
||||
if (rm.isDebug() || jr == null) { |
||||
jr = (JasperReport) JRLoader.loadObject(inputStream); |
||||
rm.setJasperRoport(jr); |
||||
} |
||||
|
||||
if (rm.getExtParam() != null) { |
||||
((Map)params).putAll(rm.getExtParam()); |
||||
} |
||||
|
||||
((Map)params).put("companyInfo", Configer.getEnumConfiger("company").getOption()); |
||||
SubReportModel subReport = null; |
||||
JasperReport subJS = null; |
||||
ReportModel subRM = null; |
||||
Collection<?> subData = null; |
||||
List<SubReportModel> subReports = rm.getSubReports(); |
||||
if (subReports != null && subReports.size() > 0) { |
||||
for(int i = 0; i < subReports.size(); ++i) { |
||||
subReport = (SubReportModel)subReports.get(i); |
||||
subRM = ReportInfoReader.getReportModel(subReport.getSubReportId()); |
||||
subJS = subRM.getJasperRoport(); |
||||
if (subRM.isDebug() || subJS == null) { |
||||
subJS = (JasperReport)JRLoader.loadObject(PathReader.class.getResourceAsStream(subRM.getTemplatePath())); |
||||
subRM.setJasperRoport(subJS); |
||||
} |
||||
|
||||
subData = (Collection) Function.getPropertyValue(((Map)params).get("jasper_head_data"), subReport.getPropertyName()); |
||||
((Map)params).put("subReport_" + subReport.getJsReportParamName(), subJS); |
||||
((Map)params).put("subData_" + subReport.getDataParamName(), subData != null ? new JRBeanCollectionDataSource(subData) : null); |
||||
} |
||||
} |
||||
JasperPrint jp = JasperFillManager.fillReport(jr, (Map)params, new JRBeanCollectionDataSource((Collection)mainData)); |
||||
mainData = null; |
||||
subData = null; |
||||
if (jp == null) { |
||||
throw new Exception("无法生成导出或打印资源!"); |
||||
} else { |
||||
return jp; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
public static final ArrayList<JasperPrint> getJasperPrints(String reportId, List<PrintData> data, Map<String, Object> pubParamMap) throws Exception { |
||||
ArrayList<JasperPrint> jps = new ArrayList(data.size()); |
||||
|
||||
for(int i = 0; i < data.size(); ++i) { |
||||
PrintData d = (PrintData)data.get(i); |
||||
if (d.getParams() == null) { |
||||
d.setParams(new HashMap()); |
||||
} |
||||
|
||||
d.getParams().putAll(pubParamMap); |
||||
JasperPrint jp = getJasperPrint(reportId, d.getData(), d.getParams()); |
||||
jps.add(jp); |
||||
} |
||||
|
||||
return jps; |
||||
} |
||||
} |
||||
//package org.springblade.desk.energy.util;
|
||||
//
|
||||
//import com.videasoft.utils.other.Function;
|
||||
//import com.videasoft.utils.reader.PathReader;
|
||||
//import com.videasoft.webframework.common.web.report.JasperReportUtils;
|
||||
//import com.videasoft.webframework.common.web.report.PrintData;
|
||||
//import com.videasoft.webframework.common.web.report.ReportModel;
|
||||
//import com.videasoft.webframework.common.web.report.SubReportModel;
|
||||
//import com.videasoft.webframework.configs.ReportInfoReader;
|
||||
//import net.sf.jasperreports.engine.JasperFillManager;
|
||||
//import net.sf.jasperreports.engine.JasperPrint;
|
||||
//import net.sf.jasperreports.engine.JasperReport;
|
||||
//import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
|
||||
//import net.sf.jasperreports.engine.util.JRLoader;
|
||||
//import org.slf4j.Logger;
|
||||
//import org.slf4j.LoggerFactory;
|
||||
//import org.springframework.stereotype.Service;
|
||||
//
|
||||
//import java.io.InputStream;
|
||||
//import java.util.*;
|
||||
//@Service
|
||||
//public class JasperReportUtil {
|
||||
//
|
||||
//
|
||||
// protected static final Logger logger = LoggerFactory.getLogger(JasperReportUtils.class);
|
||||
//
|
||||
// public JasperReportUtil() {
|
||||
// }
|
||||
//
|
||||
// public static final ReportModel getReportModel(String reportId) throws Exception {
|
||||
// return ReportInfoReader.getReportModel(reportId);
|
||||
// }
|
||||
//
|
||||
// public static final JasperPrint getJasperPrint(String reportId, Object data, Map<String, Object> params) throws Exception {
|
||||
// ReportModel rm = ReportInfoReader.getReportModel(reportId);
|
||||
// if (rm == null) {
|
||||
// throw new Exception("找不到报表模板定义");
|
||||
// } else {
|
||||
// Collection<?> mainData = null;
|
||||
// if (data instanceof Collection) {
|
||||
// mainData = (Collection)data;
|
||||
// } else {
|
||||
// mainData = new ArrayList(1);
|
||||
// ((List)mainData).add(data);
|
||||
// }
|
||||
//
|
||||
// if (params == null) {
|
||||
// params = new HashMap();
|
||||
// }
|
||||
//
|
||||
// JasperReport jr = rm.getJasperRoport();
|
||||
// InputStream inputStream = PathReader.class.getResourceAsStream(rm.getTemplatePath());
|
||||
// if (inputStream == null) {
|
||||
// logger.error("读取打印模版:" + rm.getTemplatePath() + "出错,文件可能不存在!");
|
||||
// return null;
|
||||
// } else {
|
||||
// if (rm.isDebug() || jr == null) {
|
||||
// jr = (JasperReport) JRLoader.loadObject(inputStream);
|
||||
// rm.setJasperRoport(jr);
|
||||
// }
|
||||
//
|
||||
// if (rm.getExtParam() != null) {
|
||||
// ((Map)params).putAll(rm.getExtParam());
|
||||
// }
|
||||
//
|
||||
// ((Map)params).put("companyInfo", Configer.getEnumConfiger("company").getOption());
|
||||
// SubReportModel subReport = null;
|
||||
// JasperReport subJS = null;
|
||||
// ReportModel subRM = null;
|
||||
// Collection<?> subData = null;
|
||||
// List<SubReportModel> subReports = rm.getSubReports();
|
||||
// if (subReports != null && subReports.size() > 0) {
|
||||
// for(int i = 0; i < subReports.size(); ++i) {
|
||||
// subReport = (SubReportModel)subReports.get(i);
|
||||
// subRM = ReportInfoReader.getReportModel(subReport.getSubReportId());
|
||||
// subJS = subRM.getJasperRoport();
|
||||
// if (subRM.isDebug() || subJS == null) {
|
||||
// subJS = (JasperReport)JRLoader.loadObject(PathReader.class.getResourceAsStream(subRM.getTemplatePath()));
|
||||
// subRM.setJasperRoport(subJS);
|
||||
// }
|
||||
//
|
||||
// subData = (Collection) Function.getPropertyValue(((Map)params).get("jasper_head_data"), subReport.getPropertyName());
|
||||
// ((Map)params).put("subReport_" + subReport.getJsReportParamName(), subJS);
|
||||
// ((Map)params).put("subData_" + subReport.getDataParamName(), subData != null ? new JRBeanCollectionDataSource(subData) : null);
|
||||
// }
|
||||
// }
|
||||
// JasperPrint jp = JasperFillManager.fillReport(jr, (Map)params, new JRBeanCollectionDataSource((Collection)mainData));
|
||||
// mainData = null;
|
||||
// subData = null;
|
||||
// if (jp == null) {
|
||||
// throw new Exception("无法生成导出或打印资源!");
|
||||
// } else {
|
||||
// return jp;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public static final ArrayList<JasperPrint> getJasperPrints(String reportId, List<PrintData> data, Map<String, Object> pubParamMap) throws Exception {
|
||||
// ArrayList<JasperPrint> jps = new ArrayList(data.size());
|
||||
//
|
||||
// for(int i = 0; i < data.size(); ++i) {
|
||||
// PrintData d = (PrintData)data.get(i);
|
||||
// if (d.getParams() == null) {
|
||||
// d.setParams(new HashMap());
|
||||
// }
|
||||
//
|
||||
// d.getParams().putAll(pubParamMap);
|
||||
// JasperPrint jp = getJasperPrint(reportId, d.getData(), d.getParams());
|
||||
// jps.add(jp);
|
||||
// }
|
||||
//
|
||||
// return jps;
|
||||
// }
|
||||
//}
|
||||
|
||||
Loading…
Reference in new issue