|
|
|
@ -2,12 +2,14 @@ package com.glxp.api.util;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.json.JSONUtil;
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import net.sf.jasperreports.engine.*;
|
|
|
|
|
import net.sf.jasperreports.engine.export.ooxml.JRDocxExporter;
|
|
|
|
|
import net.sf.jasperreports.engine.query.JsonQueryExecuterFactory;
|
|
|
|
|
import net.sf.jasperreports.engine.util.JRLoader;
|
|
|
|
|
import net.sf.jasperreports.export.SimpleExporterInput;
|
|
|
|
|
import net.sf.jasperreports.export.SimpleOutputStreamExporterOutput;
|
|
|
|
|
import org.apache.commons.lang3.exception.ExceptionUtils;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
@ -27,6 +29,7 @@ import java.util.Map;
|
|
|
|
|
* @author chenqf
|
|
|
|
|
* @date 2021-11-10 22:23
|
|
|
|
|
*/
|
|
|
|
|
@Slf4j
|
|
|
|
|
@Component
|
|
|
|
|
public class JasperUtils {
|
|
|
|
|
private static Logger logger = LoggerFactory.getLogger(JasperUtils.class);
|
|
|
|
@ -43,7 +46,7 @@ public class JasperUtils {
|
|
|
|
|
public static void jasperReport(HttpServletRequest request, HttpServletResponse response, Map<String, Object> data, String jasperResource, String type) throws IOException, JRException {
|
|
|
|
|
try {
|
|
|
|
|
HashMap<String, Object> map = new HashMap<String, Object>();
|
|
|
|
|
logger.error(JSON.toJSONString(data));
|
|
|
|
|
log.error(JSON.toJSONString(data));
|
|
|
|
|
InputStream is = new ByteArrayInputStream(JSONUtil.toJsonStr(data).getBytes(StandardCharsets.UTF_8));
|
|
|
|
|
map.put("JSON_INPUT_STREAM", is); //填充报表数据
|
|
|
|
|
map.put(JsonQueryExecuterFactory.JSON_LOCALE, Locale.ENGLISH);
|
|
|
|
@ -68,14 +71,14 @@ public class JasperUtils {
|
|
|
|
|
os.close();
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
log.error(ExceptionUtils.getStackTrace(e));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void jasperReport(HttpServletRequest request, HttpServletResponse response, String data, String jasperResource, String type) throws IOException, JRException {
|
|
|
|
|
try {
|
|
|
|
|
HashMap<String, Object> map = new HashMap<String, Object>();
|
|
|
|
|
logger.error(JSON.toJSONString(data));
|
|
|
|
|
log.error(JSON.toJSONString(data));
|
|
|
|
|
InputStream is = new ByteArrayInputStream(data.getBytes("UTF-8"));
|
|
|
|
|
map.put("JSON_INPUT_STREAM", is); //填充报表数据
|
|
|
|
|
map.put(JsonQueryExecuterFactory.JSON_LOCALE, Locale.ENGLISH);
|
|
|
|
@ -100,8 +103,7 @@ public class JasperUtils {
|
|
|
|
|
os.close();
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
log.error(ExceptionUtils.getStackTrace(e));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -128,9 +130,7 @@ public class JasperUtils {
|
|
|
|
|
JasperExportManager.exportReportToPdfFile(jasperPrint, filePath);
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
|
|
log.error(ExceptionUtils.getStackTrace(e));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|